Search in sources :

Example 26 with LinkDescription

use of org.onosproject.net.link.LinkDescription 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 27 with LinkDescription

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

the class LinkDiscoveryProvider method discoverLinks.

private void discoverLinks(Device device) {
    DeviceId deviceId = device.id();
    Set<LinkDescription> response = null;
    try {
        response = CompletableFuture.supplyAsync(() -> device.as(LinkDiscovery.class).getLinks(), linkDiscoveryExecutor).exceptionally(e -> {
            log.error("Exception is occurred during update the links. Device id {} {}", deviceId, e);
            return null;
        }).get(linkDiscoveryTimeoutSeconds, SECONDS);
    } catch (TimeoutException e) {
        log.error("Timout is occurred during update the links. Device id {}, Timeout {}", deviceId, linkDiscoveryTimeoutSeconds);
    } catch (InterruptedException | ExecutionException e) {
        log.warn("Exception is occurred during update the links. Device id {}, Timeout {}", deviceId, linkDiscoveryTimeoutSeconds);
    }
    if (Objects.isNull(response)) {
        return;
    }
    evaluateLinks(deviceId, response);
}
Also used : LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 28 with LinkDescription

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

the class PolatisLinkDiscovery method getLinks.

/**
 * Returns the set of LinkDescriptions originating from a Polatis switch.
 * <p>
 * This is the callback required by the LinkDiscovery behaviour.
 * @return Set of outbound unidirectional links as LinkDescriptions
 */
@Override
public Set<LinkDescription> getLinks() {
    Set<LinkDescription> links = new HashSet<>();
    DeviceId deviceID = handler().data().deviceId();
    log.debug("*** Checking peer-port fields on device {}", deviceID.toString());
    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, will try again...", deviceID);
        return links;
    }
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceID);
    int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
    int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
    log.trace("Talking to device " + handler().data().deviceId().toString());
    String reply = netconfGet(handler(), getPortsFilter());
    // Get port details from switch as PortDescription objects
    List<PortDescription> ports = parsePorts(reply, numInputPorts, numOutputPorts);
    int numPeerPortEntries = 0;
    int numPortsScanned = 0;
    ObjectMapper mapper = new ObjectMapper();
    for (PortDescription port : ports) {
        numPortsScanned++;
        if (deviceService.getPort(new ConnectPoint(deviceID, port.portNumber())).isEnabled()) {
            String peerPortData = port.annotations().value(KEY_PORTPEER);
            if (!peerPortData.equals("")) {
                numPeerPortEntries++;
                if (peerPortData.charAt(0) == '{') {
                    ConnectPoint nearEndCP = new ConnectPoint(deviceID, port.portNumber());
                    ConnectPoint farEndCP = null;
                    try {
                        farEndCP = parsePeerportDataForCP(mapper.readTree(peerPortData));
                    } catch (JsonProcessingException jpe) {
                        log.debug("Error processing peer-port JSON: {}", jpe.toString());
                    }
                    if (farEndCP != null) {
                        log.trace("Found ref on port {} to peer ConnectPoint: {}", port.portNumber(), farEndCP.toString());
                        if (checkPeer(nearEndCP, farEndCP, this.handler(), true)) {
                            log.trace("Peer {} checks out", farEndCP.toString());
                            // now add link to Set<LinkDescription>
                            DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY_LINKBIDIR, VALUE_FALSE).set(KEY_LINKALLOWED, VALUE_TRUE).build();
                            ConnectPoint aEndCP = nearEndCP;
                            ConnectPoint bEndCP = farEndCP;
                            // reverse direction of unidirectional link if near-end port is INPUT
                            if (port.annotations().value(KEY_PORTDIR).equals(VALUE_INPUT)) {
                                aEndCP = farEndCP;
                                bEndCP = nearEndCP;
                            }
                            LinkDescription newLinkDesc = new DefaultLinkDescription(aEndCP, bEndCP, Link.Type.OPTICAL, true, annotations);
                            links.add(newLinkDesc);
                            log.debug("Adding link {}", newLinkDesc);
                        }
                    }
                }
            }
        }
    }
    log.debug("Scanned {} ports, {} had peer-port entries, {} {} valid", numPortsScanned, numPeerPortEntries, links.size(), links.size() == 1 ? "is" : "are");
    log.trace("Links found on this iteration: {}", links);
    return links;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 29 with LinkDescription

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

the class NetworkConfigLinksProviderTest method testNotConfiguredLink.

/**
 * Tests discovery of a link that is not expected in the configuration.
 */
@Test
public void testNotConfiguredLink() {
    PacketContext pktCtx = new TestPacketContext(src, dst);
    testProcessor.process(pktCtx);
    assertThat(providerService.discoveredLinks().entrySet(), hasSize(1));
    DeviceId destination = providerService.discoveredLinks().get(dev1.id());
    assertThat(destination, notNullValue());
    LinkKey key = LinkKey.linkKey(src, dst);
    LinkDescription linkDescription = providerService.discoveredLinkDescriptions().get(key);
    assertThat(linkDescription, notNullValue());
    assertThat(linkDescription.isExpected(), is(false));
}
Also used : LinkKey(org.onosproject.net.LinkKey) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) PacketContext(org.onosproject.net.packet.PacketContext) Test(org.junit.Test)

Aggregations

LinkDescription (org.onosproject.net.link.LinkDescription)29 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)24 DeviceId (org.onosproject.net.DeviceId)17 ConnectPoint (org.onosproject.net.ConnectPoint)11 Device (org.onosproject.net.Device)9 DeviceService (org.onosproject.net.device.DeviceService)9 ProviderId (org.onosproject.net.provider.ProviderId)7 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)6 Type (org.onosproject.net.Link.Type)6 LinkKey (org.onosproject.net.LinkKey)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Port (org.onosproject.net.Port)5 NetconfController (org.onosproject.netconf.NetconfController)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 NetconfException (org.onosproject.netconf.NetconfException)3 NetconfSession (org.onosproject.netconf.NetconfSession)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2