Search in sources :

Example 1 with PORT_NAME

use of org.onosproject.net.AnnotationKeys.PORT_NAME in project onos by opennetworkinglab.

the class LinkDiscoveryJuniperImpl method getLinks.

@Override
public Set<LinkDescription> getLinks() {
    DeviceId localDeviceId = this.handler().data().deviceId();
    NetconfSession session = lookupNetconfSession(localDeviceId);
    String reply;
    try {
        reply = session.get(requestBuilder(REQ_LLDP_NBR_INFO));
    } catch (NetconfException e) {
        log.warn("Failed to retrieve lldp-neighbors-information for device {}", localDeviceId);
        return ImmutableSet.of();
    }
    log.debug("Reply from device {} : {}", localDeviceId, reply);
    Set<LinkAbstraction> linkAbstractions = parseJuniperLldp(loadXmlString(reply));
    log.debug("Set of LinkAbstraction discovered {}", linkAbstractions);
    DeviceService deviceService = this.handler().get(DeviceService.class);
    Set<LinkDescription> descriptions = new HashSet<>();
    // for each lldp neighbor create two LinkDescription
    for (LinkAbstraction linkAbs : linkAbstractions) {
        // find source port by local port name
        Optional<Port> localPort = deviceService.getPorts(localDeviceId).stream().filter(port -> linkAbs.localPortName.equals(port.annotations().value(PORT_NAME))).findAny();
        if (!localPort.isPresent()) {
            log.warn("Port name {} does not exist in device {}", linkAbs.localPortName, localDeviceId);
            continue;
        }
        // find destination device by remote chassis id
        com.google.common.base.Optional<Device> dev = Iterables.tryFind(deviceService.getAvailableDevices(), input -> input.chassisId().equals(linkAbs.remoteChassisId));
        if (!dev.isPresent()) {
            log.warn("Device with chassis ID {} does not exist. Referenced by {}/{}", linkAbs.remoteChassisId, localDeviceId, linkAbs);
            continue;
        }
        Device remoteDevice = dev.get();
        // find destination port by interface index
        Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> {
            if (port.number().toLong() == linkAbs.remotePortIndex) {
                return true;
            }
            if (port.annotations().value(AnnotationKeys.PORT_MAC) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_MAC).equals(linkAbs.remotePortId)) {
                return true;
            }
            if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortId)) {
                return true;
            }
            if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortDescription != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortDescription)) {
                return true;
            }
            return false;
        }).findAny();
        if (!remotePort.isPresent()) {
            log.warn("Port does not exist in remote device {}. Referenced by {}/{}", remoteDevice.id(), localDeviceId, linkAbs);
            continue;
        }
        if (!localPort.get().isEnabled() || !remotePort.get().isEnabled()) {
            log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get());
            continue;
        }
        JuniperUtils.createOneWayLinkDescription(localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get(), descriptions);
    }
    return descriptions;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) LinkDescription(org.onosproject.net.link.LinkDescription) NetconfException(org.onosproject.netconf.NetconfException) Iterables(com.google.common.collect.Iterables) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) Set(java.util.Set) JuniperUtils.parseJuniperLldp(org.onosproject.drivers.juniper.JuniperUtils.parseJuniperLldp) AnnotationKeys(org.onosproject.net.AnnotationKeys) LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) NetconfSession(org.onosproject.netconf.NetconfSession) Beta(com.google.common.annotations.Beta) REQ_LLDP_NBR_INFO(org.onosproject.drivers.juniper.JuniperUtils.REQ_LLDP_NBR_INFO) HashSet(java.util.HashSet) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) Port(org.onosproject.net.Port) LinkAbstraction(org.onosproject.drivers.juniper.JuniperUtils.LinkAbstraction) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) JuniperUtils.requestBuilder(org.onosproject.drivers.juniper.JuniperUtils.requestBuilder) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) NetconfException(org.onosproject.netconf.NetconfException) LinkAbstraction(org.onosproject.drivers.juniper.JuniperUtils.LinkAbstraction) HashSet(java.util.HashSet)

Example 2 with PORT_NAME

use of org.onosproject.net.AnnotationKeys.PORT_NAME in project onos by opennetworkinglab.

the class ScalableGatewayManager method getUplinkPort.

@Override
public PortNumber getUplinkPort(DeviceId deviceId) {
    GatewayNode gatewayNode = gatewayNodeMap.get(deviceId).value();
    if (gatewayNode == null) {
        log.warn("Gateway with device ID {} does not exist");
        return null;
    }
    Optional<Port> port = deviceService.getPorts(deviceId).stream().filter(p -> Objects.equals(p.annotations().value(PORT_NAME), gatewayNode.getUplinkIntf())).findFirst();
    if (!port.isPresent()) {
        log.warn("Cannot find uplink interface from gateway {}", deviceId);
        return null;
    }
    return port.get().number();
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) ScalableGatewayService(org.onosproject.scalablegateway.api.ScalableGatewayService) Tools(org.onlab.util.Tools) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) KryoNamespace(org.onlab.util.KryoNamespace) GroupKey(org.onosproject.net.group.GroupKey) DriverService(org.onosproject.net.driver.DriverService) Group(org.onosproject.net.group.Group) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) StorageService(org.onosproject.store.service.StorageService) ImmutableList(com.google.common.collect.ImmutableList) SubjectFactories(org.onosproject.net.config.basics.SubjectFactories) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) Activate(org.osgi.service.component.annotations.Activate) GatewayNodeConfig(org.onosproject.scalablegateway.api.GatewayNodeConfig) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Serializer(org.onosproject.store.service.Serializer) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) GroupService(org.onosproject.net.group.GroupService) GatewayNode(org.onosproject.scalablegateway.api.GatewayNode) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) ConfigFactory(org.onosproject.net.config.ConfigFactory) List(java.util.List) GroupId(org.onosproject.core.GroupId) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) GatewayNode(org.onosproject.scalablegateway.api.GatewayNode) Port(org.onosproject.net.Port)

Example 3 with PORT_NAME

use of org.onosproject.net.AnnotationKeys.PORT_NAME in project onos by opennetworkinglab.

the class LinkDiscoveryCiscoImpl method findDestinationPortByName.

private Port findDestinationPortByName(String remotePortName, String remotePortDesc, DeviceService deviceService, Device remoteDevice) {
    Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortName.equals(port.annotations().value(PORT_NAME))).findAny();
    if (remotePort.isPresent()) {
        return remotePort.get();
    } else {
        Optional<Port> remotePortByDesc = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortDesc.equals(port.annotations().value(PORT_NAME))).findAny();
        if (remotePortByDesc.isPresent()) {
            return remotePortByDesc.get();
        } else {
            int portNumber = Integer.valueOf(remotePortName.replaceAll("\\D+", ""));
            DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, remotePortName);
            return new DefaultPort(remoteDevice, PortNumber.portNumber(portNumber), true, annotations.build());
        }
    }
}
Also used : Tools(org.onlab.util.Tools) Supplier(com.google.common.base.Supplier) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) DefaultDevice(org.onosproject.net.DefaultDevice) AnnotationKeys(org.onosproject.net.AnnotationKeys) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) MediaType(javax.ws.rs.core.MediaType) Lists(com.google.common.collect.Lists) ByteArrayInputStream(java.io.ByteArrayInputStream) Port(org.onosproject.net.Port) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) LinkDescription(org.onosproject.net.link.LinkDescription) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) Sets(com.google.common.collect.Sets) LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) DriverHandler(org.onosproject.net.driver.DriverHandler) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) InputStream(java.io.InputStream) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultPort(org.onosproject.net.DefaultPort)

Aggregations

Optional (java.util.Optional)3 PORT_NAME (org.onosproject.net.AnnotationKeys.PORT_NAME)3 DeviceId (org.onosproject.net.DeviceId)3 Port (org.onosproject.net.Port)3 DeviceService (org.onosproject.net.device.DeviceService)3 Logger (org.slf4j.Logger)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Tools (org.onlab.util.Tools)2 AnnotationKeys (org.onosproject.net.AnnotationKeys)2 Device (org.onosproject.net.Device)2 PortNumber (org.onosproject.net.PortNumber)2 LinkDiscovery (org.onosproject.net.behaviour.LinkDiscovery)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Beta (com.google.common.annotations.Beta)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Supplier (com.google.common.base.Supplier)1