Yi Tseng
Committed by Gerrit Code Review

Refactor VPLS IntentInstaller

Change-Id: Ia729849fd0c939b6399abad5f15658b48fbb62b4
......@@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -87,22 +86,19 @@ public class IntentInstaller {
MacAddress>> confHostPresentCPoint) {
List<Intent> intents = new ArrayList<>();
confHostPresentCPoint.asMap().keySet()
confHostPresentCPoint.keySet()
.stream()
.filter(vlanId -> confHostPresentCPoint.get(vlanId) != null)
.forEach(vlanId -> {
List<Pair<ConnectPoint, MacAddress>> cPoints =
confHostPresentCPoint.get(vlanId).stream().collect(Collectors.toList());
if (cPoints != null && !cPoints.isEmpty()) {
for (int i = 0; i < cPoints.size(); i++) {
ConnectPoint src = cPoints.get(i).getKey();
Set<ConnectPoint> dsts = new HashSet<>();
MacAddress mac = cPoints.get(i).getValue();
for (int j = 0; j < cPoints.size(); j++) {
ConnectPoint dst = cPoints.get(j).getKey();
if (!dst.equals(src)) {
dsts.add(dst);
}
}
Set<Pair<ConnectPoint, MacAddress>> cPoints =
confHostPresentCPoint.get(vlanId);
cPoints.forEach(cPoint -> {
MacAddress mac = cPoint.getValue();
ConnectPoint src = cPoint.getKey();
Set<ConnectPoint> dsts = cPoints.stream()
.map(Pair::getKey)
.filter(cp -> !cp.equals(src))
.collect(Collectors.toSet());
Key brcKey = buildKey(PREFIX_BROADCAST, src, vlanId);
if (intentService.getIntent(brcKey) == null) {
SinglePointToMultiPointIntent brcIntent =
......@@ -121,8 +117,7 @@ public class IntentInstaller {
intents.add(uniIntent);
}
}
}
}
});
});
submitIntents(intents);
}
......@@ -133,11 +128,10 @@ public class IntentInstaller {
* @param intents intents to be submitted
*/
private void submitIntents(Collection<Intent> intents) {
log.debug("Submitting intents to the IntentSynchronizer");
for (Intent intent : intents) {
log.debug("Submitting intents to the Intent Synchronizer");
intents.forEach(intent -> {
intentSynchronizer.submit(intent);
}
});
}
/**
......@@ -240,18 +234,12 @@ public class IntentInstaller {
* Counts the number of mac addresses associated to a specific list of
* ConnectPoint.
*
* @param cPoints List of ConnectPoints, eventually binded to the MAC of the
* @param cPoints Set of ConnectPoints, eventually bound to the MAC of the
* host attached
* @return number of mac addresses found.
*/
private int countMacInCPoints(List<Pair<ConnectPoint, MacAddress>> cPoints) {
int macFound = 0;
for (Pair<ConnectPoint, MacAddress> p : cPoints) {
if (p.getValue() != null) {
macFound++;
}
}
return macFound;
private int countMacInCPoints(Set<Pair<ConnectPoint, MacAddress>> cPoints) {
return (int) cPoints.stream().filter(p -> p.getValue() != null).count();
}
}
......