Search in sources :

Example 26 with HostLocation

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);
}
Also used : DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 27 with HostLocation

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 28 with HostLocation

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;
    });
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) HostLocation(org.onosproject.net.HostLocation) HashSet(java.util.HashSet)

Example 29 with HostLocation

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));
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) ResourceContext(org.onosproject.net.intent.ResourceContext) HostLocation(org.onosproject.net.HostLocation) DefaultPath(org.onosproject.net.DefaultPath) Before(org.junit.Before)

Example 30 with HostLocation

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);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultHost(org.onosproject.net.DefaultHost) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) VlanId(org.onlab.packet.VlanId)

Aggregations

HostLocation (org.onosproject.net.HostLocation)52 IpAddress (org.onlab.packet.IpAddress)29 MacAddress (org.onlab.packet.MacAddress)25 VlanId (org.onlab.packet.VlanId)22 HostId (org.onosproject.net.HostId)22 Host (org.onosproject.net.Host)19 ConnectPoint (org.onosproject.net.ConnectPoint)15 Test (org.junit.Test)14 DefaultHost (org.onosproject.net.DefaultHost)14 DeviceId (org.onosproject.net.DeviceId)12 HostDescription (org.onosproject.net.host.HostDescription)11 ProviderId (org.onosproject.net.provider.ProviderId)11 Set (java.util.Set)10 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)10 Logger (org.slf4j.Logger)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 Collectors (java.util.stream.Collectors)7 PortNumber (org.onosproject.net.PortNumber)7 DeviceEvent (org.onosproject.net.device.DeviceEvent)7 HostService (org.onosproject.net.host.HostService)7