use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.
the class VirtualHostCodec method decode.
@Override
public VirtualHost decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
MacAddress mac = MacAddress.valueOf(json.get("mac").asText());
VlanId vlanId = VlanId.vlanId((short) json.get("vlan").asInt(VlanId.UNTAGGED));
Set<HostLocation> locations = new HashSet<>();
JsonNode locationNodes = json.get("locations");
locationNodes.forEach(locationNode -> {
PortNumber portNumber = PortNumber.portNumber(locationNode.get("port").asText());
DeviceId deviceId = DeviceId.deviceId(locationNode.get("elementId").asText());
locations.add(new HostLocation(deviceId, portNumber, 0));
});
HostId id = HostId.hostId(mac, vlanId);
Iterator<JsonNode> ipStrings = json.get("ipAddresses").elements();
Set<IpAddress> ips = new HashSet<>();
while (ipStrings.hasNext()) {
ips.add(IpAddress.valueOf(ipStrings.next().asText()));
}
return new DefaultVirtualHost(nId, id, mac, vlanId, locations, ips);
}
use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.
the class VirtualHostCodec method encode.
@Override
public ObjectNode encode(VirtualHost vHost, CodecContext context) {
checkNotNull(vHost, NULL_OBJECT_MSG);
final JsonCodec<HostLocation> locationCodec = context.codec(HostLocation.class);
final ObjectNode result = context.mapper().createObjectNode().put(NETWORK_ID, vHost.networkId().toString()).put(HOST_ID, vHost.id().toString()).put(MAC_ADDRESS, vHost.mac().toString()).put(VLAN, vHost.vlan().toString());
final ArrayNode jsonIpAddresses = result.putArray(IP_ADDRESSES);
for (final IpAddress ipAddress : vHost.ipAddresses()) {
jsonIpAddresses.add(ipAddress.toString());
}
result.set(IP_ADDRESSES, jsonIpAddresses);
final ArrayNode jsonLocations = result.putArray("locations");
for (final HostLocation location : vHost.locations()) {
jsonLocations.add(locationCodec.encode(location, context));
}
result.set("locations", jsonLocations);
return result;
}
use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.
the class DistributedHostStore method removeLocation.
@Override
public void removeLocation(HostId hostId, HostLocation location) {
log.debug("Removing location {} from host {}", location, hostId);
hosts.compute(hostId, (id, existingHost) -> {
if (existingHost != null) {
checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ.");
checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()), "Existing and new VLANs differ.");
Set<HostLocation> locations = new HashSet<>(existingHost.locations());
locations.remove(location);
// Remove entire host if we are removing the last location
return locations.isEmpty() ? null : new DefaultHost(existingHost.providerId(), hostId, existingHost.mac(), existingHost.vlan(), locations, existingHost.auxLocations(), existingHost.ipAddresses(), existingHost.innerVlan(), existingHost.tpid(), existingHost.configured(), existingHost.suspended(), existingHost.annotations());
}
return null;
});
}
use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.
the class ObstacleConstraintTest method setUp.
@Before
public void setUp() {
resourceContext = createMock(ResourceContext.class);
link1 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).build();
link2 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).build();
host1 = new DefaultHost(PROVIDER_ID, HostId.hostId("00:00:00:00:00:01/None"), MacAddress.valueOf(0), VlanId.vlanId(), new HostLocation(DID5, PN1, 1), ImmutableSet.of(), DefaultAnnotations.EMPTY);
host2 = new DefaultHost(PROVIDER_ID, HostId.hostId("00:00:00:00:00:02/None"), MacAddress.valueOf(0), VlanId.vlanId(), new HostLocation(DID6, PN1, 1), ImmutableSet.of(), DefaultAnnotations.EMPTY);
edgelink1 = createEdgeLink(host1, true);
edgelink2 = createEdgeLink(host2, false);
path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), ScalarWeight.toWeight(10));
pathWithEdgeLink = new DefaultPath(PROVIDER_ID, Arrays.asList(edgelink1, link1, link2, edgelink2), ScalarWeight.toWeight(10));
}
use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.
the class HostEventTest method createHost.
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);
}
Aggregations