Search in sources :

Example 1 with Type

use of org.onosproject.net.Link.Type 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 2 with Type

use of org.onosproject.net.Link.Type 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 3 with Type

use of org.onosproject.net.Link.Type in project onos by opennetworkinglab.

the class DefaultLinkSerializer method read.

@Override
public DefaultLink read(Kryo kryo, Input input, Class<DefaultLink> type) {
    ProviderId providerId = (ProviderId) kryo.readClassAndObject(input);
    ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input);
    ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input);
    Type linkType = (Type) kryo.readClassAndObject(input);
    State state = (State) kryo.readClassAndObject(input);
    boolean isDurable = input.readBoolean();
    return DefaultLink.builder().providerId(providerId).src(src).dst(dst).type(linkType).state(state).isExpected(isDurable).build();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Link.Type) State(org.onosproject.net.Link.State) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 4 with Type

use of org.onosproject.net.Link.Type in project onos by opennetworkinglab.

the class SimpleLinkStore method composeLink.

// Guarded by linkDescs value (=locking each Link)
private Link composeLink(Map<ProviderId, LinkDescription> descs) {
    ProviderId primary = getBaseProviderId(descs);
    LinkDescription base = descs.get(verifyNotNull(primary));
    ConnectPoint src = base.src();
    ConnectPoint dst = base.dst();
    Type type = base.type();
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    annotations = merge(annotations, base.annotations());
    for (Entry<ProviderId, LinkDescription> e : descs.entrySet()) {
        if (primary.equals(e.getKey())) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        annotations = merge(annotations, e.getValue().annotations());
    }
    boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
    return DefaultLink.builder().providerId(primary).src(src).dst(dst).type(type).state(ACTIVE).isExpected(isDurable).annotations(annotations).build();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Link.Type) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 5 with Type

use of org.onosproject.net.Link.Type 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)

Aggregations

Type (org.onosproject.net.Link.Type)8 ConnectPoint (org.onosproject.net.ConnectPoint)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)5 LinkDescription (org.onosproject.net.link.LinkDescription)5 DeviceId (org.onosproject.net.DeviceId)4 ProviderId (org.onosproject.net.provider.ProviderId)4 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 Map (java.util.Map)2 Set (java.util.Set)2 ONOSLLDP (org.onlab.packet.ONOSLLDP)2 PortNumber (org.onosproject.net.PortNumber)2 LinkEvent (org.onosproject.net.link.LinkEvent)2 Activate (org.osgi.service.component.annotations.Activate)2 Component (org.osgi.service.component.annotations.Component)2 Deactivate (org.osgi.service.component.annotations.Deactivate)2 Reference (org.osgi.service.component.annotations.Reference)2 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)2 Logger (org.slf4j.Logger)2