Search in sources :

Example 31 with LinkKey

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

the class ECLinkStoreTest method testGetDeviceEgressLinks.

@Test
public final void testGetDeviceEgressLinks() {
    LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
    LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
    LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
    putLink(linkId1, DIRECT);
    putLink(linkId2, DIRECT);
    putLink(linkId3, DIRECT);
    // DID1,P1 => DID2,P2
    // DID2,P2 => DID1,P1
    // DID1,P2 => DID2,P3
    Set<Link> links1 = linkStore.getDeviceEgressLinks(DID1);
    assertEquals(2, links1.size());
    // check
    Set<Link> links2 = linkStore.getDeviceEgressLinks(DID2);
    assertEquals(1, links2.size());
    assertLink(linkId2, DIRECT, links2.iterator().next());
}
Also used : LinkKey(org.onosproject.net.LinkKey) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Test(org.junit.Test)

Example 32 with LinkKey

use of org.onosproject.net.LinkKey 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 33 with LinkKey

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

the class ECLinkStore method createOrUpdateLink.

@Override
public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) {
    final DeviceId dstDeviceId = linkDescription.dst().deviceId();
    final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId);
    // otherwise signal the actual master.
    if (clusterService.getLocalNode().id().equals(dstNodeId)) {
        LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst());
        Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId);
        if (internalLinkKey == null) {
            return null;
        }
        linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription));
        return refreshLinkCache(linkKey);
    } else {
        // Forwarding was added as a workaround for ONOS-490
        if (!"cfg".equals(providerId.scheme()) && !"null".equals(providerId.scheme())) {
            return null;
        }
        // Proper fix is to implement forwarding to master on ConfigProvider
        if (dstNodeId == null) {
            return null;
        }
        return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId));
    }
}
Also used : LinkKey(org.onosproject.net.LinkKey) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId)

Example 34 with LinkKey

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

the class LabelAllocator method noSwapBehavior.

// Implements NO_SWAP behavior
private Map<LinkKey, Identifier<?>> noSwapBehavior(Set<LinkKey> links, EncapsulationType type) {
    // Init steps
    Map<LinkKey, Identifier<?>> ids = Maps.newHashMap();
    Identifier<?> selected;
    Set<Identifier<?>> candidates = null;
    Set<Identifier<?>> linkCandidates;
    // Iterates for each link building the candidate set
    for (LinkKey link : links) {
        // Get candidates set for the current link
        linkCandidates = getCandidates(link, type);
        // Warm up
        if (candidates == null) {
            candidates = linkCandidates;
        // Build step by step the intersection
        } else {
            candidates = Sets.intersection(candidates, linkCandidates);
        }
    }
    // Pick a label according to the defined strategy
    selected = labelSelection.select(candidates);
    if (selected == null) {
        // If there are no candidates, exit. This will throw a compile exception
        log.warn("No common label for path");
        return Collections.emptyMap();
    }
    // For each link create an entry
    links.forEach(linkKey -> ids.put(linkKey, selected));
    return ids;
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier)

Example 35 with LinkKey

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

the class IntentsDiagnosisCommand method getIntentsByLinkSet.

private Set<Map.Entry<LinkKey, Key>> getIntentsByLinkSet(ServiceRefs svcRefs) {
    try {
        ObjectiveTrackerService objTracker = svcRefs.getObjectiveTrackerService();
        // Utilizing reflection instead of adding new interface for getting intentsByLink
        Field f = objTracker.getClass().getDeclaredField(FIELD_INTENTS_BY_LINK);
        f.setAccessible(true);
        SetMultimap<LinkKey, Key> intentsByLink = (SetMultimap<LinkKey, Key>) f.get(objTracker);
        return ImmutableSet.copyOf(intentsByLink.entries());
    } catch (NoSuchFieldException | IllegalAccessException ex) {
        error("error: " + ex);
        return ImmutableSet.of();
    }
}
Also used : Field(java.lang.reflect.Field) SetMultimap(com.google.common.collect.SetMultimap) LinkKey(org.onosproject.net.LinkKey) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) LinkKey(org.onosproject.net.LinkKey) Key(org.onosproject.net.intent.Key)

Aggregations

LinkKey (org.onosproject.net.LinkKey)61 Test (org.junit.Test)34 ConnectPoint (org.onosproject.net.ConnectPoint)31 Link (org.onosproject.net.Link)23 Identifier (org.onlab.util.Identifier)14 DeviceId (org.onosproject.net.DeviceId)9 Set (java.util.Set)7 MplsLabel (org.onlab.packet.MplsLabel)7 VlanId (org.onlab.packet.VlanId)7 LinkDescription (org.onosproject.net.link.LinkDescription)7 LinkEvent (org.onosproject.net.link.LinkEvent)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)6 ProviderId (org.onosproject.net.provider.ProviderId)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 FirstFitSelection (org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection)5 RandomSelection (org.onosproject.net.resource.impl.LabelAllocator.RandomSelection)5 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)4 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)4 BasicLinkConfig (org.onosproject.net.config.basics.BasicLinkConfig)4