Search in sources :

Example 16 with DefaultAnnotations

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

use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.

the class NetconfDeviceProvider method getDeviceRepresentation.

private DeviceDescription getDeviceRepresentation(DeviceId deviceId, NetconfDeviceConfig config, DeviceDescriptionDiscovery deviceDescriptionDiscovery) {
    DeviceDescription existingOrEmptyDescription = existingOrEmptyDescription(deviceId, config);
    DeviceDescription newDescription = deviceDescriptionDiscovery.discoverDeviceDetails();
    if (newDescription == null) {
        return existingOrEmptyDescription;
    }
    // merging and returning
    return new DefaultDeviceDescription(newDescription, true, DefaultAnnotations.merge((DefaultAnnotations) newDescription.annotations(), existingOrEmptyDescription.annotations()));
}
Also used : DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 18 with DefaultAnnotations

use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.

the class PolatisDeviceDescription method discoverPortDetails.

/**
 * Discovers port details, for Polatis Snmp device.
 *
 * @return port list
 */
@Override
public List<PortDescription> discoverPortDetails() {
    List<PortDescription> ports = Lists.newArrayList();
    List<TableEvent> events;
    DeviceId deviceId = handler().data().deviceId();
    try {
        OID[] columnOIDs = { new OID(PORT_CURRENT_STATE_OID) };
        events = getTable(handler(), columnOIDs);
    } catch (IOException e) {
        log.error("Error reading ports table for device {} exception {}", deviceId, e);
        return ports;
    }
    if (events == null) {
        log.error("Error reading ports table for device {}", deviceId);
        return ports;
    }
    for (TableEvent event : events) {
        if (event == null) {
            log.error("Error reading event for device {}", deviceId);
            continue;
        }
        VariableBinding[] columns = event.getColumns();
        if (columns == null) {
            log.error("Error reading columns for device {} event {}", deviceId, event);
            continue;
        }
        VariableBinding portColumn = columns[0];
        if (portColumn == null) {
            continue;
        }
        int port = event.getIndex().last();
        boolean enabled = (portColumn.getVariable().toInt() == 1);
        PortNumber portNumber = PortNumber.portNumber(port);
        DefaultAnnotations annotations = DefaultAnnotations.builder().build();
        double opticalBand = Spectrum.O_BAND_MIN.asGHz() - Spectrum.L_BAND_MAX.asGHz();
        Frequency opticalGrid = Frequency.ofGHz(opticalBand / POLATIS_NUM_OF_WAVELENGTHS);
        PortDescription p = omsPortDescription(portNumber, enabled, Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX, opticalGrid, annotations);
        ports.add(p);
    }
    return ports;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) OID(org.snmp4j.smi.OID) IOException(java.io.IOException) TableEvent(org.snmp4j.util.TableEvent) Frequency(org.onlab.util.Frequency) PortNumber(org.onosproject.net.PortNumber) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 19 with DefaultAnnotations

use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.

the class ECLinkStore method composeLink.

private Link composeLink(LinkKey linkKey) {
    ProviderId baseProviderId = getBaseProviderId(linkKey);
    if (baseProviderId == null) {
        // parent component.
        return null;
    }
    LinkDescription base = linkDescriptions.get(new Provided<>(linkKey, baseProviderId));
    // short circuit if link description no longer exists
    if (base == null) {
        return null;
    }
    ConnectPoint src = base.src();
    ConnectPoint dst = base.dst();
    Type type = base.type();
    DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
    builder.putAll(base.annotations());
    getAllProviders(linkKey).stream().map(p -> new Provided<>(linkKey, p)).forEach(key -> {
        LinkDescription linkDescription = linkDescriptions.get(key);
        if (linkDescription != null) {
            builder.putAll(linkDescription.annotations());
        }
    });
    DefaultAnnotations annotations = builder.build();
    Link.State initialLinkState;
    boolean isExpected;
    if (linkDiscoveryMode == LinkDiscoveryMode.PERMISSIVE) {
        initialLinkState = ACTIVE;
        isExpected = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
    } else {
        initialLinkState = base.isExpected() ? ACTIVE : INACTIVE;
        isExpected = base.isExpected();
    }
    return DefaultLink.builder().providerId(baseProviderId).src(src).dst(dst).type(type).state(initialLinkState).isExpected(isExpected).annotations(annotations).build();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) LINK_ADDED(org.onosproject.net.link.LinkEvent.Type.LINK_ADDED) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) CoreService(org.onosproject.core.CoreService) APP_SUBJECT_FACTORY(org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) LINK_REMOVED(org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED) StorageService(org.onosproject.store.service.StorageService) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) SharedExecutors(org.onlab.util.SharedExecutors) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) ACTIVE(org.onosproject.net.Link.State.ACTIVE) MastershipService(org.onosproject.mastership.MastershipService) REMOVE(org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE) DistributedStoreSerializers(org.onosproject.store.serializers.custom.DistributedStoreSerializers) LinkKey(org.onosproject.net.LinkKey) NodeId(org.onosproject.cluster.NodeId) DefaultLink(org.onosproject.net.DefaultLink) LinkDescription(org.onosproject.net.link.LinkDescription) Serializer(org.onosproject.store.service.Serializer) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) Deactivate(org.osgi.service.component.annotations.Deactivate) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) PUT(org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) ConfigFactory(org.onosproject.net.config.ConfigFactory) DeviceClockService(org.onosproject.net.device.DeviceClockService) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) DIRECT(org.onosproject.net.Link.Type.DIRECT) Iterables(com.google.common.collect.Iterables) LinkEvent(org.onosproject.net.link.LinkEvent) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) KryoNamespace(org.onlab.util.KryoNamespace) AnnotationKeys(org.onosproject.net.AnnotationKeys) AtomicReference(java.util.concurrent.atomic.AtomicReference) Component(org.osgi.service.component.annotations.Component) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) LINK_UPDATED(org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED) Logger(org.slf4j.Logger) INACTIVE(org.onosproject.net.Link.State.INACTIVE) ProviderId(org.onosproject.net.provider.ProviderId) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) DefaultAnnotations.union(org.onosproject.net.DefaultAnnotations.union) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Futures(com.google.common.util.concurrent.Futures) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) AnnotationsUtil(org.onosproject.net.AnnotationsUtil) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) LinkStore(org.onosproject.net.link.LinkStore) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Type(org.onosproject.net.Link.Type) 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) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

Example 20 with DefaultAnnotations

use of org.onosproject.net.DefaultAnnotations 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

DefaultAnnotations (org.onosproject.net.DefaultAnnotations)33 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortDescription (org.onosproject.net.device.PortDescription)9 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)8 DeviceId (org.onosproject.net.DeviceId)7 PortNumber (org.onosproject.net.PortNumber)7 ProviderId (org.onosproject.net.provider.ProviderId)7 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)6 LinkDescription (org.onosproject.net.link.LinkDescription)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 Device (org.onosproject.net.Device)4 DeviceDescription (org.onosproject.net.device.DeviceDescription)4 ArrayList (java.util.ArrayList)3 ChassisId (org.onlab.packet.ChassisId)3 DefaultDevice (org.onosproject.net.DefaultDevice)3 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)3 DeviceService (org.onosproject.net.device.DeviceService)3 XPath (javax.xml.xpath.XPath)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Test (org.junit.Test)2