Search in sources :

Example 6 with DefaultLinkDescription

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

the class LinkDiscoveryCiscoImpl method buildLinkPair.

private static Set<LinkDescription> buildLinkPair(DeviceId localDevId, Port localPort, DeviceId remoteDevId, Port remotePort) {
    Set<LinkDescription> linkDescriptions = Sets.newHashSet();
    ConnectPoint local = new ConnectPoint(localDevId, localPort.number());
    ConnectPoint remote = new ConnectPoint(remoteDevId, remotePort.number());
    DefaultAnnotations annotations = DefaultAnnotations.builder().set("layer", "ETHERNET").build();
    linkDescriptions.add(new DefaultLinkDescription(remote, local, Link.Type.DIRECT, true, annotations));
    return linkDescriptions;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 7 with DefaultLinkDescription

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

the class Ciena5170DeviceDescription method getLinks.

@Override
public Set<LinkDescription> getLinks() {
    log.debug("LINKS CHECKING ...");
    Set<LinkDescription> links = new HashSet<LinkDescription>();
    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<String, Device>();
        for (Device d : devices) {
            lookup.put(d.chassisId().toString().toUpperCase(), d);
        }
        Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "link-info");
        XPath xp = XPathFactory.newInstance().newXPath();
        NodeList ifaces = (NodeList) xp.evaluate("interfaces/interface", logicalPorts, XPathConstants.NODESET);
        int count = ifaces.getLength();
        Node iface;
        Node destChassis;
        for (int i = 0; i < count; i += 1) {
            iface = ifaces.item(i);
            if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
                destChassis = (Node) xp.evaluate("state/lldp-remote-port-operational/chassis-id", iface, XPathConstants.NODE);
                if (destChassis != null) {
                    Device dest = lookup.get(destChassis.getTextContent().toUpperCase());
                    if (dest != null) {
                        links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(xp.evaluate("state/lldp-remote-port-operational/port-id/text()", iface))), new ConnectPoint(deviceId, PortNumber.portNumber(xp.evaluate("name/text()", iface))), Link.Type.DIRECT, true));
                    } else {
                        log.warn("DEST chassisID not found: chassis {} port {}", destChassis.getTextContent().toUpperCase(), xp.evaluate("name/text()", iface));
                    }
                } else {
                    log.debug("NO LINK for {}", xp.evaluate("name/text()", iface));
                }
            }
        }
    } catch (NetconfException | XPathExpressionException e) {
        log.error("Unable to retrieve links for device {}, {}", deviceId, e);
    }
    return links;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 8 with DefaultLinkDescription

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

the class Ciena5162DeviceDescription method getLinks.

@Override
public Set<LinkDescription> getLinks() {
    log.debug("LINKS CHECKING ...");
    Set<LinkDescription> links = new HashSet<LinkDescription>();
    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<String, Device>();
        for (Device d : devices) {
            lookup.put(d.chassisId().toString().toUpperCase(), d);
        }
        Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "link-info");
        XPath xp = XPathFactory.newInstance().newXPath();
        NodeList ifaces = (NodeList) xp.evaluate("interfaces/interface", logicalPorts, XPathConstants.NODESET);
        int count = ifaces.getLength();
        Node iface;
        Node destChassis;
        for (int i = 0; i < count; i += 1) {
            iface = ifaces.item(i);
            if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
                destChassis = (Node) xp.evaluate("state/lldp-remote-port-operational/chassis-id", iface, XPathConstants.NODE);
                if (destChassis != null) {
                    Device dest = lookup.get(destChassis.getTextContent().toUpperCase());
                    if (dest != null) {
                        links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(xp.evaluate("state/lldp-remote-port-operational/port-id/text()", iface))), new ConnectPoint(deviceId, PortNumber.portNumber(xp.evaluate("name/text()", iface))), Link.Type.DIRECT, true));
                    } else {
                        log.warn("DEST chassisID not found: chassis {} port {}", destChassis.getTextContent().toUpperCase(), xp.evaluate("name/text()", iface));
                    }
                } else {
                    log.debug("NO LINK for {}", xp.evaluate("name/text()", iface));
                }
            }
        }
    } catch (NetconfException | XPathExpressionException e) {
        log.error("Unable to retrieve links for device {}, {}", deviceId, e);
    }
    return links;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 9 with DefaultLinkDescription

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

the class SimpleLinkStoreTest method testCreateOrUpdateLinkAncillary.

@Test
public final void testCreateOrUpdateLinkAncillary() {
    ConnectPoint src = new ConnectPoint(DID1, P1);
    ConnectPoint dst = new ConnectPoint(DID2, P2);
    // add Ancillary link
    LinkEvent event = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, INDIRECT, A1));
    assertNotNull("Ancillary only link is ignored", event);
    // add Primary link
    LinkEvent event2 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, INDIRECT, A2));
    assertLink(DID1, P1, DID2, P2, INDIRECT, event2.subject());
    assertAnnotationsEquals(event2.subject().annotations(), A2, A1);
    assertEquals(LINK_UPDATED, event2.type());
    // update link type
    LinkEvent event3 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT, A2));
    assertLink(DID1, P1, DID2, P2, DIRECT, event3.subject());
    assertAnnotationsEquals(event3.subject().annotations(), A2, A1);
    assertEquals(LINK_UPDATED, event3.type());
    // no change
    LinkEvent event4 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT));
    assertNull("No change event expected", event4);
    // update link annotation (Primary)
    LinkEvent event5 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT, A2_2));
    assertLink(DID1, P1, DID2, P2, DIRECT, event5.subject());
    assertAnnotationsEquals(event5.subject().annotations(), A2, A2_2, A1);
    assertEquals(LINK_UPDATED, event5.type());
    // update link annotation (Ancillary)
    LinkEvent event6 = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, DIRECT, A1_2));
    assertLink(DID1, P1, DID2, P2, DIRECT, event6.subject());
    assertAnnotationsEquals(event6.subject().annotations(), A2, A2_2, A1, A1_2);
    assertEquals(LINK_UPDATED, event6.type());
    // update link type (Ancillary) : ignored
    LinkEvent event7 = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, EDGE));
    assertNull("Ancillary change other than annotation is ignored", event7);
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Test(org.junit.Test)

Example 10 with DefaultLinkDescription

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

the class TopologyMutationDriver method severLink.

/**
 * Severs the link between the specified end-points in both directions.
 *
 * @param one link endpoint
 * @param two link endpoint
 */
void severLink(ConnectPoint one, ConnectPoint two) {
    LinkDescription link = new DefaultLinkDescription(one, two, DIRECT);
    linkProviderService.linkVanished(link);
    linkProviderService.linkVanished(reverse(link));
}
Also used : DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Aggregations

DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)27 ConnectPoint (org.onosproject.net.ConnectPoint)20 LinkDescription (org.onosproject.net.link.LinkDescription)11 Test (org.junit.Test)8 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)6 DeviceId (org.onosproject.net.DeviceId)6 Device (org.onosproject.net.Device)5 DeviceService (org.onosproject.net.device.DeviceService)5 HashSet (java.util.HashSet)4 Link (org.onosproject.net.Link)4 LinkEvent (org.onosproject.net.link.LinkEvent)4 NetconfController (org.onosproject.netconf.NetconfController)4 HashMap (java.util.HashMap)3 XPath (javax.xml.xpath.XPath)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 Type (org.onosproject.net.Link.Type)3 NetconfException (org.onosproject.netconf.NetconfException)3 NetconfSession (org.onosproject.netconf.NetconfSession)3 Node (org.w3c.dom.Node)3 NodeList (org.w3c.dom.NodeList)3