Search in sources :

Example 1 with ONOSLLDP

use of org.onlab.packet.ONOSLLDP in project onos by opennetworkinglab.

the class LinkDiscovery method handleLldp.

/**
 * Handles an incoming LLDP packet. Creates link in topology and adds the
 * link for staleness tracking.
 *
 * @param packetContext packet context
 * @return true if handled
 */
public boolean handleLldp(PacketContext packetContext) {
    Ethernet eth = packetContext.inPacket().parsed();
    if (eth == null) {
        return false;
    }
    if (processOnosLldp(packetContext, eth)) {
        return true;
    }
    if (processLldp(packetContext, eth)) {
        return true;
    }
    ONOSLLDP lldp = ONOSLLDP.parseLLDP(eth);
    if (lldp == null) {
        log.debug("Cannot parse the packet. It seems that it is not the lldp or bsn packet.");
    } else {
        log.debug("LLDP packet is dropped due to there are no handlers that properly handle this packet: {}", lldp.toString());
    }
    return false;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ONOSLLDP(org.onlab.packet.ONOSLLDP)

Example 2 with ONOSLLDP

use of org.onlab.packet.ONOSLLDP 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 3 with ONOSLLDP

use of org.onlab.packet.ONOSLLDP 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 4 with ONOSLLDP

use of org.onlab.packet.ONOSLLDP in project onos by opennetworkinglab.

the class LinkDiscovery method createOutBoundBddp.

/**
 * Creates packet_out BDDP for specified output port.
 *
 * @param portNumber the port
 * @param portDesc the port description
 * @return Packet_out message with LLDP data
 */
private OutboundPacket createOutBoundBddp(Long portNumber, String portDesc) {
    if (portNumber == null) {
        return null;
    }
    ONOSLLDP lldp = getLinkProbe(portNumber, portDesc);
    if (lldp == null) {
        log.warn("Cannot get link probe with portNumber {} and portDesc {} for {} at BDDP packet creation.", portNumber, portDesc, deviceId);
        return null;
    }
    bddpEth.setSourceMACAddress(context.fingerprint()).setPayload(lldp);
    return new DefaultOutboundPacket(deviceId, builder().setOutput(portNumber(portNumber)).build(), ByteBuffer.wrap(bddpEth.serialize()));
}
Also used : ONOSLLDP(org.onlab.packet.ONOSLLDP) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 5 with ONOSLLDP

use of org.onlab.packet.ONOSLLDP in project onos by opennetworkinglab.

the class NetworkConfigLinksProvider method extractLinkKey.

// doesn't validate. Used just to decide if this is expected link.
LinkKey extractLinkKey(PacketContext packetContext) {
    Ethernet eth = packetContext.inPacket().parsed();
    if (eth == null) {
        return null;
    }
    ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
    if (onoslldp != null) {
        PortNumber srcPort = portNumber(onoslldp.getPort());
        PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
        DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
        DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
        ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
        ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
        return LinkKey.linkKey(src, dst);
    }
    return null;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Ethernet(org.onlab.packet.Ethernet) ONOSLLDP(org.onlab.packet.ONOSLLDP) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

ONOSLLDP (org.onlab.packet.ONOSLLDP)7 Ethernet (org.onlab.packet.Ethernet)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DeviceId (org.onosproject.net.DeviceId)3 PortNumber (org.onosproject.net.PortNumber)3 Type (org.onosproject.net.Link.Type)2 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)2 LinkDescription (org.onosproject.net.link.LinkDescription)2 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)2 MacAddress (org.onlab.packet.MacAddress)1 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)1 Device (org.onosproject.net.Device)1 Port (org.onosproject.net.Port)1 DeviceService (org.onosproject.net.device.DeviceService)1