Search in sources :

Example 1 with LinkAbstraction

use of org.onosproject.drivers.juniper.JuniperUtils.LinkAbstraction 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)

Aggregations

Beta (com.google.common.annotations.Beta)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 LinkAbstraction (org.onosproject.drivers.juniper.JuniperUtils.LinkAbstraction)1 REQ_LLDP_NBR_INFO (org.onosproject.drivers.juniper.JuniperUtils.REQ_LLDP_NBR_INFO)1 JuniperUtils.parseJuniperLldp (org.onosproject.drivers.juniper.JuniperUtils.parseJuniperLldp)1 JuniperUtils.requestBuilder (org.onosproject.drivers.juniper.JuniperUtils.requestBuilder)1 XmlConfigParser.loadXmlString (org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)1 AnnotationKeys (org.onosproject.net.AnnotationKeys)1 PORT_NAME (org.onosproject.net.AnnotationKeys.PORT_NAME)1 Device (org.onosproject.net.Device)1 DeviceId (org.onosproject.net.DeviceId)1 Port (org.onosproject.net.Port)1 LinkDiscovery (org.onosproject.net.behaviour.LinkDiscovery)1 DeviceService (org.onosproject.net.device.DeviceService)1 LinkDescription (org.onosproject.net.link.LinkDescription)1 NetconfException (org.onosproject.netconf.NetconfException)1