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());
}
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();
}
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));
}
}
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;
}
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();
}
}
Aggregations