Search in sources :

Example 11 with DefaultLinkDescription

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

the class LinkDiscovery method processOnosLldp.

private boolean processOnosLldp(PacketContext packetContext, Ethernet eth) {
    ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
    if (onoslldp != null) {
        Type lt;
        if (notMy(eth.getSourceMAC().toString())) {
            lt = Type.EDGE;
        } else {
            lt = eth.getEtherType() == Ethernet.TYPE_LLDP ? Type.DIRECT : Type.INDIRECT;
            /* Verify MAC in LLDP packets */
            if (!ONOSLLDP.verify(onoslldp, context.lldpSecret(), context.maxDiscoveryDelay())) {
                log.warn("LLDP Packet failed to validate!");
                return true;
            }
        }
        PortNumber srcPort = portNumber(onoslldp.getPort());
        PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
        String idString = onoslldp.getDeviceString();
        if (!isNullOrEmpty(idString)) {
            try {
                DeviceId srcDeviceId = DeviceId.deviceId(idString);
                DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
                ConnectPoint src = translateSwitchPort(srcDeviceId, srcPort);
                ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
                LinkDescription ld = new DefaultLinkDescription(src, dst, lt);
                context.providerService().linkDetected(ld);
                context.touchLink(LinkKey.linkKey(src, dst));
            } catch (IllegalStateException | IllegalArgumentException e) {
                log.warn("There is a exception during link creation: {}", e.getMessage());
                return true;
            }
            return true;
        }
    }
    return false;
}
Also used : Type(org.onosproject.net.Link.Type) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) ONOSLLDP(org.onlab.packet.ONOSLLDP) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 12 with DefaultLinkDescription

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

the class LinkDiscovery method processLldp.

private boolean processLldp(PacketContext packetContext, Ethernet eth) {
    ONOSLLDP onoslldp = ONOSLLDP.parseLLDP(eth);
    if (onoslldp != null) {
        Type lt = eth.getEtherType() == Ethernet.TYPE_LLDP ? Type.DIRECT : Type.INDIRECT;
        DeviceService deviceService = context.deviceService();
        MacAddress srcChassisId = onoslldp.getChassisIdByMac();
        String srcPortName = onoslldp.getPortNameString();
        String srcPortDesc = onoslldp.getPortDescString();
        log.debug("srcChassisId:{}, srcPortName:{}, srcPortDesc:{}", srcChassisId, srcPortName, srcPortDesc);
        if (srcChassisId == null && srcPortDesc == null) {
            log.warn("there are no valid port id");
            return false;
        }
        Optional<Device> srcDevice = findSourceDeviceByChassisId(deviceService, srcChassisId);
        if (!srcDevice.isPresent()) {
            log.debug("source device not found. srcChassisId value: {}", srcChassisId);
            return false;
        }
        Optional<Port> sourcePort = findSourcePortByName(srcPortName == null ? srcPortDesc : srcPortName, deviceService, srcDevice.get());
        if (!sourcePort.isPresent()) {
            log.debug("source port not found. sourcePort value: {}", sourcePort);
            return false;
        }
        PortNumber srcPort = sourcePort.get().number();
        PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
        DeviceId srcDeviceId = srcDevice.get().id();
        DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
        if (!sourcePort.get().isEnabled()) {
            log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", srcDeviceId, sourcePort.get(), dstDeviceId, dstPort);
            return false;
        }
        ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
        ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
        DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).set(AnnotationKeys.LAYER, ETHERNET).build();
        LinkDescription ld = new DefaultLinkDescription(src, dst, lt, true, annotations);
        try {
            context.providerService().linkDetected(ld);
            context.setTtl(LinkKey.linkKey(src, dst), onoslldp.getTtlBySeconds());
        } catch (IllegalStateException e) {
            log.debug("There is a exception during link creation: {}", e);
            return true;
        }
        return true;
    }
    return false;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) Device(org.onosproject.net.Device) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) ONOSLLDP(org.onlab.packet.ONOSLLDP) DeviceService(org.onosproject.net.device.DeviceService) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Type(org.onosproject.net.Link.Type) PortNumber(org.onosproject.net.PortNumber) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 13 with DefaultLinkDescription

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

the class ECLinkStoreTest method testCreateOrUpdateLink.

@Test
public final void testCreateOrUpdateLink() {
    ConnectPoint src = new ConnectPoint(DID1, P1);
    ConnectPoint dst = new ConnectPoint(DID2, P2);
    final DefaultLinkDescription linkDescription = new DefaultLinkDescription(src, dst, INDIRECT);
    LinkEvent event = linkStore.createOrUpdateLink(PID, linkDescription);
    assertLink(DID1, P1, DID2, P2, INDIRECT, event.subject());
    assertEquals(LINK_ADDED, event.type());
    LinkEvent event2 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT));
    assertLink(DID1, P1, DID2, P2, DIRECT, event2.subject());
    assertEquals(LINK_UPDATED, event2.type());
    // no change
    LinkEvent event3 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT));
    assertNull("No change event expected", event3);
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Test(org.junit.Test)

Example 14 with DefaultLinkDescription

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

the class ECLinkStoreTest method testAncillaryVisible.

@Test
public final void testAncillaryVisible() {
    ConnectPoint src = new ConnectPoint(DID1, P1);
    ConnectPoint dst = new ConnectPoint(DID2, P2);
    // add Ancillary link
    linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, INDIRECT, A1));
    // Ancillary only link should not be visible
    assertEquals(1, linkStore.getLinkCount());
    assertNotNull(linkStore.getLink(src, dst));
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Test(org.junit.Test)

Example 15 with DefaultLinkDescription

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

the class JuniperUtils method createOneWayLinkDescription.

/**
 * Create one way LinkDescriptions.
 *
 * @param localDevId  the identity of the local device
 * @param localPort   the port of the local device
 * @param remoteDevId the identity of the remote device
 * @param remotePort  the port of the remote device
 * @param descs       the collection to which the link descriptions
 *                    should be added
 */
public static void createOneWayLinkDescription(DeviceId localDevId, Port localPort, DeviceId remoteDevId, Port remotePort, Set<LinkDescription> descs) {
    ConnectPoint local = new ConnectPoint(localDevId, localPort.number());
    ConnectPoint remote = new ConnectPoint(remoteDevId, remotePort.number());
    DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.LAYER, "ETHERNET").build();
    descs.add(new DefaultLinkDescription(remote, local, Link.Type.DIRECT, true, annotations));
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) ConnectPoint(org.onosproject.net.ConnectPoint) 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