Search in sources :

Example 11 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class BasicHostConfigTest method testConstruction.

/**
 * Tests construction, setters and getters of a BasicHostConfig object.
 */
@Test
public void testConstruction() {
    BasicHostConfig config = new BasicHostConfig();
    ConfigApplyDelegate delegate = configApply -> {
    };
    ObjectMapper mapper = new ObjectMapper();
    HostId hostId = NetTestTools.hid("12:34:56:78:90:ab/1");
    IpAddress ip1 = IpAddress.valueOf("1.1.1.1");
    IpAddress ip2 = IpAddress.valueOf("1.1.1.2");
    IpAddress ip3 = IpAddress.valueOf("1.1.1.3");
    Set<IpAddress> ips = ImmutableSet.of(ip1, ip2, ip3);
    HostLocation loc1 = new HostLocation(NetTestTools.connectPoint("d1", 1), System.currentTimeMillis());
    HostLocation loc2 = new HostLocation(NetTestTools.connectPoint("d2", 2), System.currentTimeMillis());
    Set<HostLocation> locs = ImmutableSet.of(loc1, loc2);
    HostLocation loc3 = new HostLocation(NetTestTools.connectPoint("d3", 1), System.currentTimeMillis());
    HostLocation loc4 = new HostLocation(NetTestTools.connectPoint("d4", 2), System.currentTimeMillis());
    Set<HostLocation> auxLocations = ImmutableSet.of(loc3, loc4);
    VlanId vlanId = VlanId.vlanId((short) 10);
    EthType ethType = EthType.EtherType.lookup((short) 0x88a8).ethType();
    config.init(hostId, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
    config.setIps(ips).setLocations(locs).setAuxLocations(auxLocations).setInnerVlan(vlanId).setOuterTpid(ethType);
    assertThat(config.isValid(), is(true));
    assertThat(config.name(), is("-"));
    assertThat(config.ipAddresses(), hasSize(3));
    assertThat(config.ipAddresses(), hasItems(ip1, ip2, ip3));
    assertThat(config.locations(), hasSize(2));
    assertThat(config.locations(), hasItems(loc1, loc2));
    assertThat(config.auxLocations(), hasSize(2));
    assertThat(config.auxLocations(), hasItems(loc3, loc4));
    assertThat(config.innerVlan(), is(vlanId));
    assertThat(config.outerTpid(), is(ethType));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HostLocation(org.onosproject.net.HostLocation) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Test(org.junit.Test) Matchers.hasItems(org.hamcrest.Matchers.hasItems) EthType(org.onlab.packet.EthType) NetTestTools(org.onosproject.net.NetTestTools) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) EthType(org.onlab.packet.EthType) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) HostId(org.onosproject.net.HostId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Test(org.junit.Test)

Example 12 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class BasicHostConfig method auxLocations.

/**
 * Returns the auxLocations of the host.
 *
 * @return auxLocations of the host or null if none specified
 * @throws IllegalArgumentException if auxLocations are set but empty or not
 *                                  specified with correct format
 */
public Set<HostLocation> auxLocations() {
    if (!object.has(AUX_LOCATIONS)) {
        // no auxLocations are specified
        return null;
    }
    ImmutableSet.Builder<HostLocation> auxLocationsSetBuilder = ImmutableSet.<HostLocation>builder();
    ArrayNode auxLocationNodes = (ArrayNode) object.path(AUX_LOCATIONS);
    auxLocationNodes.forEach(n -> {
        ConnectPoint cp = ConnectPoint.deviceConnectPoint((n.asText()));
        auxLocationsSetBuilder.add(new HostLocation(cp, 0));
    });
    return auxLocationsSetBuilder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HostLocation(org.onosproject.net.HostLocation) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 13 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class OpenstackSwitchingHostProvider method processPortAdded.

/**
 * Processes port addition event.
 * Once a port addition event is detected, it tries to create a host instance
 * with openstack augmented host information such as networkId, portId,
 * createTime, segmentId and notifies to host provider.
 *
 * @param port port object used in ONOS
 */
void processPortAdded(Port port) {
    // TODO check the node state is COMPLETE
    org.openstack4j.model.network.Port osPort = osNetworkService.port(port);
    if (osPort == null) {
        log.warn(ERR_ADD_HOST + "OpenStack port for {} not found", port);
        return;
    }
    Network osNet = osNetworkService.network(osPort.getNetworkId());
    if (osNet == null) {
        log.warn(ERR_ADD_HOST + "OpenStack network {} not found", osPort.getNetworkId());
        return;
    }
    if (osPort.getFixedIps().isEmpty()) {
        log.warn(ERR_ADD_HOST + "no fixed IP for port {}", osPort.getId());
        return;
    }
    MacAddress mac = MacAddress.valueOf(osPort.getMacAddress());
    HostId hostId = HostId.hostId(mac);
    /* typically one openstack port should only be bound to one fix IP address;
           however, openstack4j binds multiple fixed IPs to one port, this might
           be a defect of openstack4j implementation */
    // TODO: we need to find a way to bind multiple ports from multiple
    // openstack networks into one host sooner or later
    Set<IpAddress> fixedIps = osPort.getFixedIps().stream().map(ip -> IpAddress.valueOf(ip.getIpAddress())).collect(Collectors.toSet());
    // connect point is the combination of switch ID with port number where
    // the host is attached to
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
    long createTime = System.currentTimeMillis();
    // we check whether the host already attached to same locations
    Host host = hostService.getHost(hostId);
    // build host annotations to include a set of meta info from neutron
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, osPort.getNetworkId()).set(ANNOTATION_PORT_ID, osPort.getId()).set(ANNOTATION_CREATE_TIME, String.valueOf(createTime));
    // FLAT typed network does not require segment ID
    Type netType = osNetworkService.networkType(osNet.getId());
    if (netType != FLAT) {
        annotations.set(ANNOTATION_SEGMENT_ID, osNet.getProviderSegID());
    }
    // build host description object
    HostDescription hostDesc = new DefaultHostDescription(mac, VlanId.NONE, new HostLocation(connectPoint, createTime), fixedIps, annotations.build());
    if (host != null) {
        Set<HostLocation> locations = host.locations().stream().filter(l -> l.deviceId().equals(connectPoint.deviceId())).filter(l -> l.port().equals(connectPoint.port())).collect(Collectors.toSet());
        // therefore, we simply add this into the location list
        if (locations.isEmpty()) {
            hostProviderService.addLocationToHost(hostId, new HostLocation(connectPoint, createTime));
        }
        // the hostDetected method invocation in turn triggers host Update event
        if (locations.size() == 1) {
            hostProviderService.hostDetected(hostId, hostDesc, false);
        }
    } else {
        hostProviderService.hostDetected(hostId, hostDesc, false);
    }
}
Also used : HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) ConnectPoint(org.onosproject.net.ConnectPoint) HostProviderService(org.onosproject.net.host.HostProviderService) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) TUNNEL_TYPE(org.onosproject.openstacknetworking.api.Constants.TUNNEL_TYPE) Port(org.onosproject.net.Port) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Constants.portNamePrefixMap(org.onosproject.openstacknetworking.api.Constants.portNamePrefixMap) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) ANNOTATION_NETWORK_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_NETWORK_ID) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) PORT_NAME_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_VM) HostService(org.onosproject.net.host.HostService) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) PORT_NAME_VHOST_USER_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_VHOST_USER_PREFIX_VM) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) Component(org.osgi.service.component.annotations.Component) ANNOTATION_SEGMENT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_SEGMENT_ID) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) AbstractProvider(org.onosproject.net.provider.AbstractProvider) ANNOTATION_PORT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_PORT_ID) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ANNOTATION_CREATE_TIME(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_CREATE_TIME) ProviderId(org.onosproject.net.provider.ProviderId) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) HostDescription(org.onosproject.net.host.HostDescription) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) Network(org.openstack4j.model.network.Network) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress)

Example 14 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class OpenstackSwitchingHostProvider method processPortRemoved.

/**
 * Processes port removal event.
 * Once a port removal event is detected, it tries to look for a host
 * instance through host provider by giving connect point information,
 * and vanishes it.
 *
 * @param port ONOS port
 */
private void processPortRemoved(Port port) {
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
    Set<Host> hosts = hostService.getConnectedHosts(connectPoint);
    hosts.forEach(h -> {
        Optional<HostLocation> hostLocation = h.locations().stream().filter(l -> l.deviceId().equals(port.element().id())).filter(l -> l.port().equals(port.number())).findAny();
        // if the host contains only one filtered location, we remove the host
        if (h.locations().size() == 1) {
            hostProviderService.hostVanished(h.id());
        }
        // host location
        if (h.locations().size() > 1 && hostLocation.isPresent()) {
            hostProviderService.removeLocationFromHost(h.id(), hostLocation.get());
        }
    });
}
Also used : HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) ConnectPoint(org.onosproject.net.ConnectPoint) HostProviderService(org.onosproject.net.host.HostProviderService) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) TUNNEL_TYPE(org.onosproject.openstacknetworking.api.Constants.TUNNEL_TYPE) Port(org.onosproject.net.Port) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Constants.portNamePrefixMap(org.onosproject.openstacknetworking.api.Constants.portNamePrefixMap) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) ANNOTATION_NETWORK_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_NETWORK_ID) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) PORT_NAME_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_VM) HostService(org.onosproject.net.host.HostService) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) PORT_NAME_VHOST_USER_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_VHOST_USER_PREFIX_VM) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) Component(org.osgi.service.component.annotations.Component) ANNOTATION_SEGMENT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_SEGMENT_ID) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) AbstractProvider(org.onosproject.net.provider.AbstractProvider) ANNOTATION_PORT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_PORT_ID) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ANNOTATION_CREATE_TIME(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_CREATE_TIME) ProviderId(org.onosproject.net.provider.ProviderId) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 15 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class OpenstackSwitchingHostProviderTest method testProcessPortAddedForUpdate.

/**
 * Tests the process port added method for updating case.
 */
@Test
public void testProcessPortAddedForUpdate() {
    org.onosproject.net.Port addedPort = new DefaultPort(DEV1, P1, true, ANNOTATIONS);
    DeviceEvent addedEvent = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV1, addedPort);
    target.portAddedHelper(addedEvent);
    // org.onosproject.net.Port updatedPort = new DefaultPort(DEV1, P2, true, ANNOTATIONS);
    // DeviceEvent updatedEvent = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV1, updatedPort);
    target.portAddedHelper(addedEvent);
    HostId hostId = HostId.hostId(HOST_MAC);
    HostDescription hostDesc = new DefaultHostDescription(HOST_MAC, VlanId.NONE, new HostLocation(CP11, System.currentTimeMillis()), ImmutableSet.of(HOST_IP11), ANNOTATIONS);
    verifyHostResult(hostId, hostDesc);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostLocation(org.onosproject.net.HostLocation) HostId(org.onosproject.net.HostId) DefaultPort(org.onosproject.net.DefaultPort) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

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