use of org.onosproject.mcast.api.McastEvent.Type.SOURCES_REMOVED in project trellis-control by opennetworkinglab.
the class McastHandler method processSourcesRemovedInternal.
/**
* Process the SOURCES_REMOVED event.
*
* @param sourcesToBeRemoved the source connect points to be removed
* @param remainingSources the remainig source connect points
* @param mcastIp the group address
* @param sinks the sinks connect points
*/
private void processSourcesRemovedInternal(Set<ConnectPoint> sourcesToBeRemoved, Set<ConnectPoint> remainingSources, IpAddress mcastIp, Map<HostId, Set<ConnectPoint>> sinks) {
lastMcastChange.set(Instant.now());
log.info("Processing sources removed {} for group {}", sourcesToBeRemoved, mcastIp);
if (!mcastUtils.isLeader(mcastIp)) {
log.debug("Skip {} due to lack of leadership", mcastIp);
return;
}
if (remainingSources.isEmpty()) {
log.debug("There are no more sources for {}", mcastIp);
processRouteRemovedInternal(sourcesToBeRemoved, mcastIp);
return;
}
// Let's heal the trees
Set<Link> notAffectedLinks = Sets.newHashSet();
Map<ConnectPoint, Set<Link>> affectedLinks = Maps.newHashMap();
Map<ConnectPoint, Set<ConnectPoint>> candidateSinks = Maps.newHashMap();
Set<ConnectPoint> totalSources = Sets.newHashSet(sourcesToBeRemoved);
totalSources.addAll(remainingSources);
// Calculate all the links used by the sources and the current sinks
totalSources.forEach(source -> {
Set<ConnectPoint> currentSinks = sinks.values().stream().flatMap(Collection::stream).filter(sink -> isSinkForSource(mcastIp, sink, source)).collect(Collectors.toSet());
candidateSinks.put(source, currentSinks);
McastPathStoreKey pathStoreKey = new McastPathStoreKey(mcastIp, source);
Collection<? extends List<Link>> storedPaths = Versioned.valueOrElse(mcastPathStore.get(pathStoreKey), Lists.newArrayList());
currentSinks.forEach(currentSink -> {
Optional<? extends List<Link>> currentPath = mcastUtils.getStoredPath(currentSink.deviceId(), storedPaths);
if (currentPath.isPresent()) {
if (!sourcesToBeRemoved.contains(source)) {
notAffectedLinks.addAll(currentPath.get());
} else {
affectedLinks.compute(source, (k, v) -> {
v = v == null ? Sets.newHashSet() : v;
v.addAll(currentPath.get());
return v;
});
}
}
});
});
// Clean transit links
affectedLinks.forEach((source, currentCandidateLinks) -> {
Set<Link> linksToBeRemoved = Sets.difference(currentCandidateLinks, notAffectedLinks).immutableCopy();
if (!linksToBeRemoved.isEmpty()) {
currentCandidateLinks.forEach(link -> {
DeviceId srcLink = link.src().deviceId();
// Remove ports only on links to be removed
if (linksToBeRemoved.contains(link)) {
removePortFromDevice(link.src().deviceId(), link.src().port(), mcastIp, mcastUtils.assignedVlan(srcLink.equals(source.deviceId()) ? source : null));
}
// Remove role on the candidate links
mcastRoleStore.remove(new McastRoleStoreKey(mcastIp, srcLink, source));
});
}
});
// Clean ingress and egress
sourcesToBeRemoved.forEach(source -> {
Set<ConnectPoint> currentSinks = candidateSinks.get(source);
McastPathStoreKey pathStoreKey = new McastPathStoreKey(mcastIp, source);
currentSinks.forEach(currentSink -> {
VlanId assignedVlan = mcastUtils.assignedVlan(source.deviceId().equals(currentSink.deviceId()) ? source : null);
// Sinks co-located with the source
if (source.deviceId().equals(currentSink.deviceId())) {
if (source.port().equals(currentSink.port())) {
log.warn("Skip {} since sink {} is on the same port of source {}. Abort", mcastIp, currentSink, source);
return;
}
// We need to check against the other sources and if it is
// necessary remove the port from the device - no overlap
Set<VlanId> otherVlans = remainingSources.stream().filter(remainingSource -> remainingSource.deviceId().equals(source.deviceId()) && candidateSinks.get(remainingSource).contains(currentSink)).map(remainingSource -> mcastUtils.assignedVlan(remainingSource.deviceId().equals(currentSink.deviceId()) ? remainingSource : null)).collect(Collectors.toSet());
if (!otherVlans.contains(assignedVlan)) {
removePortFromDevice(currentSink.deviceId(), currentSink.port(), mcastIp, assignedVlan);
}
mcastRoleStore.remove(new McastRoleStoreKey(mcastIp, currentSink.deviceId(), source));
return;
}
Set<VlanId> otherVlans = remainingSources.stream().filter(remainingSource -> candidateSinks.get(remainingSource).contains(currentSink)).map(remainingSource -> mcastUtils.assignedVlan(remainingSource.deviceId().equals(currentSink.deviceId()) ? remainingSource : null)).collect(Collectors.toSet());
// Sinks on other leaves
if (!otherVlans.contains(assignedVlan)) {
removePortFromDevice(currentSink.deviceId(), currentSink.port(), mcastIp, assignedVlan);
}
mcastRoleStore.remove(new McastRoleStoreKey(mcastIp, currentSink.deviceId(), source));
});
// Clean the mcast paths
mcastPathStore.removeAll(pathStoreKey);
});
}
Aggregations