Search in sources :

Example 16 with LinkDescription

use of org.onosproject.net.link.LinkDescription 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 17 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class OpenstackNetworkingUiManager method createLinksConnectedToTargetvDevice.

private void createLinksConnectedToTargetvDevice(Device targetvDevice) {
    vDevices.stream().filter(d -> !d.equals(targetvDevice)).forEach(device -> {
        if (vxlanPort(targetvDevice.id()).isPresent() && vxlanPort(device.id()).isPresent()) {
            ConnectPoint srcConnectPoint = createConnectPoint(targetvDevice.id());
            ConnectPoint dstConnectPoint = createConnectPoint(device.id());
            LinkDescription linkDescription = createLinkDescription(srcConnectPoint, dstConnectPoint);
            linkStore.createOrUpdateLink(new ProviderId(SONA_GUI, APP_ID), linkDescription);
        }
    });
}
Also used : UiViewHidden(org.onosproject.ui.UiViewHidden) UiTopoOverlayFactory(org.onosproject.ui.UiTopoOverlayFactory) DeviceService(org.onosproject.net.device.DeviceService) UiExtensionService(org.onosproject.ui.UiExtensionService) LoggerFactory(org.slf4j.LoggerFactory) UiView(org.onosproject.ui.UiView) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) UiMessageHandlerFactory(org.onosproject.ui.UiMessageHandlerFactory) ConnectPoint(org.onosproject.net.ConnectPoint) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) SWITCH(org.onosproject.net.Device.Type.SWITCH) Activate(org.osgi.service.component.annotations.Activate) NoSuchElementException(java.util.NoSuchElementException) LinkDescription(org.onosproject.net.link.LinkDescription) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) List(java.util.List) Optional(java.util.Optional) LinkStore(org.onosproject.net.link.LinkStore) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) UiExtension(org.onosproject.ui.UiExtension) Type(org.onosproject.net.Link.Type) ProviderId(org.onosproject.net.provider.ProviderId) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 18 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class SimpleLinkStore method createOrUpdateLinkDescription.

// Guarded by linkDescs value (=locking each Link)
private LinkDescription createOrUpdateLinkDescription(Map<ProviderId, LinkDescription> descs, ProviderId providerId, LinkDescription linkDescription) {
    // merge existing attributes and merge
    LinkDescription oldDesc = descs.get(providerId);
    LinkDescription newDesc = linkDescription;
    if (oldDesc != null) {
        // we only allow transition from INDIRECT -> DIRECT
        final Type newType;
        if (oldDesc.type() == DIRECT) {
            newType = DIRECT;
        } else {
            newType = linkDescription.type();
        }
        SparseAnnotations merged = union(oldDesc.annotations(), linkDescription.annotations());
        newDesc = new DefaultLinkDescription(linkDescription.src(), linkDescription.dst(), newType, merged);
    }
    return descs.put(providerId, newDesc);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Type(org.onosproject.net.Link.Type) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 19 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class SimpleLinkStore method createOrUpdateLink.

@Override
public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) {
    LinkKey key = linkKey(linkDescription.src(), linkDescription.dst());
    Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key);
    synchronized (descs) {
        final Link oldLink = links.get(key);
        // update description
        createOrUpdateLinkDescription(descs, providerId, linkDescription);
        final Link newLink = composeLink(descs);
        if (oldLink == null) {
            return createLink(key, newLink);
        }
        return updateLink(key, oldLink, newLink);
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) LinkKey(org.onosproject.net.LinkKey) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

Example 20 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class CienaWaveserverAiLinkDiscovery method getLinks.

@Override
public Set<LinkDescription> getLinks() {
    log.debug("LINKS CHECKING ...");
    Set<LinkDescription> links = new HashSet<>();
    DeviceId deviceId = handler().data().deviceId();
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
        log.warn("NETCONF session to device {} not yet established, cannot load links, will be retried", deviceId);
        return links;
    }
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    try {
        DeviceService deviceService = this.handler().get(DeviceService.class);
        Iterable<Device> devices = deviceService.getAvailableDevices();
        Map<String, Device> lookup = new HashMap<>();
        for (Device d : devices) {
            lookup.put(d.chassisId().toString(), d);
        }
        log.debug("MAP: {}", lookup);
        XPath xp = XPathFactory.newInstance().newXPath();
        Node node = TEMPLATE_MANAGER.doRequest(session, "discoverPortDetails");
        NodeList nodeList = (NodeList) xp.evaluate("waveserver-ports/ports", node, XPathConstants.NODESET);
        int count = nodeList.getLength();
        Node nodeListItem;
        for (int i = 0; i < count; i += 1) {
            Long portAsLong;
            Long destPortAsLong;
            String destChassis = null;
            String destPort = null;
            nodeListItem = nodeList.item(i);
            String port = xp.evaluate("port-id/text()", nodeListItem);
            portAsLong = portIdConvert(port);
            log.debug("CHECKING: {}", port);
            if (xp.evaluate("id/type/text()", nodeListItem).equals("otn")) {
                String label = xp.evaluate("id/label/text()", nodeListItem);
                final String r1 = "\\$\\{remote_mac:(.*?)\\}";
                final Pattern p1 = Pattern.compile(r1);
                final Matcher m1 = p1.matcher(label);
                if (m1.find()) {
                    destChassis = m1.group(1).replaceFirst("^0+(?!$)", "");
                }
                final String r2 = "\\$\\{remote_port:(.*?)\\}";
                final Pattern p2 = Pattern.compile(r2);
                final Matcher m2 = p2.matcher(label);
                if (m2.find()) {
                    destPort = m2.group(1);
                }
                destPortAsLong = portIdConvert(destPort);
                if (destChassis != null && destPort != null) {
                    log.debug("LOOKING FOR OTN neighbor chassis: {}", destChassis);
                    Device dest = lookup.get(destChassis);
                    if (dest != null) {
                        links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(destPortAsLong, destPort)), new ConnectPoint(deviceId, PortNumber.portNumber(portAsLong, port)), Link.Type.TUNNEL, true));
                    } else {
                        log.error("DEST OTN CHASSIS is NULL for {}", xp.evaluate("port-id/text()", nodeListItem));
                    }
                } else {
                    log.error("NO LINK for {}", xp.evaluate("port-id/text()", nodeListItem));
                }
            } else if (xp.evaluate("id/type/text()", nodeListItem).equals("ethernet")) {
                Map<String, Object> templateContext = new HashMap<>();
                templateContext.put("port-number", port);
                node = TEMPLATE_MANAGER.doRequest(session, "getLinks", templateContext);
                String chassisIdSubtype = xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id-subtype/text()", node);
                if (chassisIdSubtype.equals("mac-address")) {
                    destChassis = xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id/text()", node).trim().toLowerCase();
                    if (destChassis.startsWith("0x")) {
                        destChassis = destChassis.substring(2);
                    }
                } else {
                    log.error("Unknown Chassis-id-subtype {}", xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id-subtype/text()", node));
                }
                destPort = xp.evaluate("waveserver-lldp/port/remote/port/id/id/text()", node);
                destPortAsLong = Long.valueOf(destPort);
                if (destChassis != null && !destPort.equals("")) {
                    log.debug("LOOKING FOR ethernet neighbor chassisId: {}", destChassis);
                    Device dest = lookup.get(destChassis);
                    if (dest != null) {
                        links.add(new DefaultLinkDescription(new ConnectPoint(deviceId, PortNumber.portNumber(portAsLong, port)), new ConnectPoint(dest.id(), PortNumber.portNumber(destPortAsLong, destPort)), Link.Type.TUNNEL, true));
                    } else {
                        log.debug("DEST CHASSIS is NULL for port {}", xp.evaluate("port-id/text()", nodeListItem));
                    }
                } else {
                    log.debug("NO LINK for {}", xp.evaluate("port-id/text()", nodeListItem));
                }
            }
        }
    } catch (NetconfException | XPathExpressionException e) {
        log.error("Unable to retrieve links for device {}, {}", deviceId, e);
    }
    return links;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NetconfController(org.onosproject.netconf.NetconfController) NetconfException(org.onosproject.netconf.NetconfException) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) XPath(javax.xml.xpath.XPath) Pattern(java.util.regex.Pattern) Device(org.onosproject.net.Device) NodeList(org.w3c.dom.NodeList) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

LinkDescription (org.onosproject.net.link.LinkDescription)29 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)24 DeviceId (org.onosproject.net.DeviceId)17 ConnectPoint (org.onosproject.net.ConnectPoint)11 Device (org.onosproject.net.Device)9 DeviceService (org.onosproject.net.device.DeviceService)9 ProviderId (org.onosproject.net.provider.ProviderId)7 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)6 Type (org.onosproject.net.Link.Type)6 LinkKey (org.onosproject.net.LinkKey)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Port (org.onosproject.net.Port)5 NetconfController (org.onosproject.netconf.NetconfController)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 NetconfException (org.onosproject.netconf.NetconfException)3 NetconfSession (org.onosproject.netconf.NetconfSession)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2