本文整理汇总了Java中org.onosproject.net.HostId类的典型用法代码示例。如果您正苦于以下问题:Java HostId类的具体用法?Java HostId怎么用?Java HostId使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostId类属于org.onosproject.net包,在下文中一共展示了HostId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activate
import org.onosproject.net.HostId; //导入依赖的package包/类
@Activate
public void activate() {
KryoNamespace.Builder hostSerializer = KryoNamespace.newBuilder()
.register(KryoNamespaces.API);
hostsConsistentMap = storageService.<HostId, DefaultHost>consistentMapBuilder()
.withName("onos-hosts")
.withRelaxedReadConsistency()
.withSerializer(Serializer.using(hostSerializer.build()))
.build();
hosts = hostsConsistentMap.asJavaMap();
prevHosts.putAll(hosts);
hostsConsistentMap.addListener(hostLocationTracker);
log.info("Started");
}
示例2: parseHost
import org.onosproject.net.HostId; //导入依赖的package包/类
/**
* Creates and adds new host based on given data and returns its host ID.
*
* @param node JsonNode containing host information
* @return host ID of new host created
*/
private HostId parseHost(JsonNode node) {
MacAddress mac = MacAddress.valueOf(node.get("mac").asText());
VlanId vlanId = VlanId.vlanId((short) node.get("vlan").asInt(VlanId.UNTAGGED));
JsonNode locationNode = node.get("location");
String deviceAndPort = locationNode.get("elementId").asText() + "/" +
locationNode.get("port").asText();
HostLocation hostLocation = new HostLocation(ConnectPoint.deviceConnectPoint(deviceAndPort), 0);
Iterator<JsonNode> ipStrings = node.get("ipAddresses").elements();
Set<IpAddress> ips = new HashSet<>();
while (ipStrings.hasNext()) {
ips.add(IpAddress.valueOf(ipStrings.next().asText()));
}
// try to remove elements from json node after reading them
SparseAnnotations annotations = annotations(removeElements(node, REMOVAL_KEYS));
// Update host inventory
HostId hostId = HostId.hostId(mac, vlanId);
DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, hostLocation, ips, annotations);
hostProviderService.hostDetected(hostId, desc, false);
return hostId;
}
示例3: testBadGet
import org.onosproject.net.HostId; //导入依赖的package包/类
/**
* Tests that a fetch of a non-existent object throws an exception.
*/
@Test
public void testBadGet() {
expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1")))
.andReturn(null)
.anyTimes();
replay(mockHostService);
WebTarget wt = target();
try {
wt.path("hosts/00:00:11:00:00:01/1").request().get(String.class);
fail("Fetch of non-existent host did not throw an exception");
} catch (NotFoundException ex) {
assertThat(ex.getMessage(),
containsString("HTTP 404 Not Found"));
}
}
示例4: decode
import org.onosproject.net.HostId; //导入依赖的package包/类
@Override
public HostToHostIntent decode(ObjectNode json, CodecContext context) {
HostToHostIntent.Builder builder = HostToHostIntent.builder();
IntentCodec.intentAttributes(json, context, builder);
ConnectivityIntentCodec.intentAttributes(json, context, builder);
String one = nullIsIllegal(json.get(ONE),
ONE + IntentCodec.MISSING_MEMBER_MESSAGE).asText();
builder.one(HostId.hostId(one));
String two = nullIsIllegal(json.get(TWO),
TWO + IntentCodec.MISSING_MEMBER_MESSAGE).asText();
builder.two(HostId.hostId(two));
return builder.build();
}
示例5: createHost
import org.onosproject.net.HostId; //导入依赖的package包/类
/**
* Creates a default host connected at the given edge device and port. Note
* that an identifying hex character ("a" - "f") should be supplied. This
* will be included in the MAC address of the host (and equivalent value
* as last byte in IP address).
*
* @param device edge device
* @param port port number
* @param hexChar identifying hex character
* @return host connected at that location
*/
protected static Host createHost(Device device, int port, String hexChar) {
DeviceId deviceId = device.id();
String devNum = deviceId.toString().substring(1);
MacAddress mac = MacAddress.valueOf(HOST_MAC_PREFIX + devNum + hexChar);
HostId hostId = hostId(String.format("%s/-1", mac));
int ipByte = Integer.valueOf(hexChar, 16);
if (ipByte < 10 || ipByte > 15) {
throw new IllegalArgumentException("hexChar must be a-f");
}
HostLocation loc = new HostLocation(deviceId, portNumber(port), 0);
IpAddress ip = ip("10." + devNum + ".0." + ipByte);
return new DefaultHost(ProviderId.NONE, hostId, mac, VlanId.NONE,
loc, ImmutableSet.of(ip));
}
示例6: activate
import org.onosproject.net.HostId; //导入依赖的package包/类
@Activate
protected void activate() {
allocationMap = storageService.<HostId, IpAssignment>consistentMapBuilder()
.withName("onos-dhcp-assignedIP")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(IpAssignment.class,
IpAssignment.AssignmentStatus.class,
Date.class,
long.class,
Ip4Address.class)
.build()))
.build();
freeIPPool = storageService.<Ip4Address>setBuilder()
.withName("onos-dhcp-freeIP")
.withSerializer(Serializer.using(KryoNamespaces.API))
.build()
.asDistributedSet();
log.info("Started");
}
示例7: programInterfacesSet
import org.onosproject.net.HostId; //导入依赖的package包/类
private void programInterfacesSet(Set<RouterInterface> interfacesSet,
Objective.Operation operation) {
int subnetVmNum = 0;
for (RouterInterface r : interfacesSet) {
// Get all the host of the subnet
Map<HostId, Host> hosts = hostsOfSubnet.get(r.subnetId());
if (hosts != null && hosts.size() > 0) {
subnetVmNum++;
if (subnetVmNum >= SUBNET_NUM) {
TenantRouter tenantRouter = TenantRouter
.tenantRouter(r.tenantId(), r.routerId());
routerInfFlagOfTenantRouter.put(tenantRouter, true);
interfacesSet.stream().forEach(f -> {
programRouterInterface(f, operation);
});
break;
}
}
}
}
示例8: createHost
import org.onosproject.net.HostId; //导入依赖的package包/类
private Host createHost() {
MacAddress mac = MacAddress.valueOf("00:00:11:00:00:01");
VlanId vlan = VlanId.vlanId((short) 10);
HostLocation loc = new HostLocation(
DeviceId.deviceId("of:foo"),
PortNumber.portNumber(100),
123L
);
Set<IpAddress> ipset = Sets.newHashSet(
IpAddress.valueOf("10.0.0.1"),
IpAddress.valueOf("10.0.0.2")
);
HostId hid = HostId.hostId(mac, vlan);
return new DefaultHost(
new ProviderId("of", "foo"), hid, mac, vlan, loc, ipset);
}
示例9: getGatewayMac
import org.onosproject.net.HostId; //导入依赖的package包/类
@Override
public MacAddress getGatewayMac(HostId hostId) {
checkNotNull(hostId, "hostId cannot be null");
Host host = hostService.getHost(hostId);
String ifaceId = host.annotations().value(IFACEID);
VirtualPortId hPortId = VirtualPortId.portId(ifaceId);
VirtualPort hPort = virtualPortService.getPort(hPortId);
SubnetId subnetId = hPort.fixedIps().iterator().next().subnetId();
Subnet subnet = subnetService.getSubnet(subnetId);
IpAddress gatewayIp = subnet.gatewayIp();
Iterable<VirtualPort> virtualPorts = virtualPortService.getPorts();
MacAddress macAddress = null;
for (VirtualPort port : virtualPorts) {
Set<FixedIp> fixedIpSet = port.fixedIps();
for (FixedIp fixedIp : fixedIpSet) {
if (fixedIp.ip().equals(gatewayIp)) {
macAddress = port.macAddress();
}
}
}
return macAddress;
}
示例10: handleArpRequest
import org.onosproject.net.HostId; //导入依赖的package包/类
private void handleArpRequest(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) {
ARP arpRequest = (ARP) payload.getPayload();
VlanId vlanId = VlanId.vlanId(payload.getVlanID());
HostId targetHostId = HostId.hostId(MacAddress.valueOf(
arpRequest.getTargetHardwareAddress()),
vlanId);
// ARP request for router. Send ARP reply.
if (isArpForRouter(deviceId, arpRequest)) {
Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress());
sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress), vlanId);
} else {
Host targetHost = srManager.hostService.getHost(targetHostId);
// ARP request for known hosts. Send proxy ARP reply on behalf of the target.
if (targetHost != null) {
removeVlanAndForward(payload, targetHost.location());
// ARP request for unknown host in the subnet. Flood in the subnet.
} else {
removeVlanAndFlood(payload, inPort);
}
}
}
示例11: encode
import org.onosproject.net.HostId; //导入依赖的package包/类
@Override
public ObjectNode encode(ConnectPoint point, CodecContext context) {
checkNotNull(point, "Connect point cannot be null");
ObjectNode root = context.mapper().createObjectNode()
.put(PORT, point.port().toString());
if (point.elementId() instanceof DeviceId) {
root.put(ELEMENT_DEVICE, point.deviceId().toString());
} else if (point.elementId() instanceof HostId) {
root.put(ELEMENT_HOST, point.hostId().toString());
}
return root;
}
示例12: getPaths
import org.onosproject.net.HostId; //导入依赖的package包/类
@Override
public Set<Path> getPaths(ElementId src, ElementId dst) {
Set<Path> result = new HashSet<>();
String[] allHops = new String[pathHops.length];
if (src.toString().endsWith(pathHops[0])) {
System.arraycopy(pathHops, 0, allHops, 0, pathHops.length);
} else {
System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length);
}
result.add(createPath(src instanceof HostId, dst instanceof HostId, allHops));
return result;
}
示例13: testReplyToRequestFromUsIpv6
import org.onosproject.net.HostId; //导入依赖的package包/类
/**
* Test NDP request from internal network to an external host.
*/
@Test
public void testReplyToRequestFromUsIpv6() {
Ip6Address ourIp = Ip6Address.valueOf("1000::1");
MacAddress ourMac = MacAddress.valueOf(1L);
Ip6Address theirIp = Ip6Address.valueOf("1000::100");
expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet());
expect(interfaceService.getInterfacesByIp(ourIp))
.andReturn(Collections.singleton(new Interface(getLocation(1),
Collections.singletonList(new InterfaceIpAddress(
ourIp,
IpPrefix.valueOf("1000::1/64"))),
ourMac,
VLAN1)));
expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null);
replay(hostService);
replay(interfaceService);
// This is a request from something inside our network (like a BGP
// daemon) to an external host.
Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
ourMac,
MacAddress.valueOf("33:33:ff:00:00:01"),
ourIp,
theirIp);
proxyArp.reply(ndpRequest, getLocation(5));
assertEquals(1, packetService.packets.size());
verifyPacketOut(ndpRequest, getLocation(1), packetService.packets.get(0));
// The same request from a random external port should fail
packetService.packets.clear();
proxyArp.reply(ndpRequest, getLocation(2));
assertEquals(0, packetService.packets.size());
}
示例14: getHost
import org.onosproject.net.HostId; //导入依赖的package包/类
@Override
public Host getHost(HostId hostId) {
if (HOST_A_ID.equals(hostId)) {
return HOST_A;
}
if (HOST_B_ID.equals(hostId)) {
return HOST_B;
}
return null;
}
示例15: edgeToEdgeDirect
import org.onosproject.net.HostId; //导入依赖的package包/类
@Test
public void edgeToEdgeDirect() {
HostId src = hid("12:34:56:78:90:ab/1");
HostId dst = hid("12:34:56:78:90:ef/1");
fakeHostMgr.hosts.put(src, host("12:34:56:78:90:ab/1", "edge"));
fakeHostMgr.hosts.put(dst, host("12:34:56:78:90:ef/1", "edge"));
Set<Path> paths = service.getPaths(src, dst);
validatePaths(paths, 1, 2, src, dst);
}