Yi Tseng
Committed by Gerrit Code Review

Refactor VPLS IntentInstaller

Change-Id: Ia729849fd0c939b6399abad5f15658b48fbb62b4
...@@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory; ...@@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory;
37 37
38 import java.util.ArrayList; 38 import java.util.ArrayList;
39 import java.util.Collection; 39 import java.util.Collection;
40 -import java.util.HashSet;
41 import java.util.List; 40 import java.util.List;
42 import java.util.Set; 41 import java.util.Set;
43 import java.util.stream.Collectors; 42 import java.util.stream.Collectors;
...@@ -87,22 +86,19 @@ public class IntentInstaller { ...@@ -87,22 +86,19 @@ public class IntentInstaller {
87 MacAddress>> confHostPresentCPoint) { 86 MacAddress>> confHostPresentCPoint) {
88 List<Intent> intents = new ArrayList<>(); 87 List<Intent> intents = new ArrayList<>();
89 88
90 - confHostPresentCPoint.asMap().keySet() 89 + confHostPresentCPoint.keySet()
90 + .stream()
91 + .filter(vlanId -> confHostPresentCPoint.get(vlanId) != null)
91 .forEach(vlanId -> { 92 .forEach(vlanId -> {
92 - List<Pair<ConnectPoint, MacAddress>> cPoints = 93 + Set<Pair<ConnectPoint, MacAddress>> cPoints =
93 - confHostPresentCPoint.get(vlanId).stream().collect(Collectors.toList()); 94 + confHostPresentCPoint.get(vlanId);
94 - 95 + cPoints.forEach(cPoint -> {
95 - if (cPoints != null && !cPoints.isEmpty()) { 96 + MacAddress mac = cPoint.getValue();
96 - for (int i = 0; i < cPoints.size(); i++) { 97 + ConnectPoint src = cPoint.getKey();
97 - ConnectPoint src = cPoints.get(i).getKey(); 98 + Set<ConnectPoint> dsts = cPoints.stream()
98 - Set<ConnectPoint> dsts = new HashSet<>(); 99 + .map(Pair::getKey)
99 - MacAddress mac = cPoints.get(i).getValue(); 100 + .filter(cp -> !cp.equals(src))
100 - for (int j = 0; j < cPoints.size(); j++) { 101 + .collect(Collectors.toSet());
101 - ConnectPoint dst = cPoints.get(j).getKey();
102 - if (!dst.equals(src)) {
103 - dsts.add(dst);
104 - }
105 - }
106 Key brcKey = buildKey(PREFIX_BROADCAST, src, vlanId); 102 Key brcKey = buildKey(PREFIX_BROADCAST, src, vlanId);
107 if (intentService.getIntent(brcKey) == null) { 103 if (intentService.getIntent(brcKey) == null) {
108 SinglePointToMultiPointIntent brcIntent = 104 SinglePointToMultiPointIntent brcIntent =
...@@ -121,8 +117,7 @@ public class IntentInstaller { ...@@ -121,8 +117,7 @@ public class IntentInstaller {
121 intents.add(uniIntent); 117 intents.add(uniIntent);
122 } 118 }
123 } 119 }
124 - } 120 + });
125 - }
126 }); 121 });
127 submitIntents(intents); 122 submitIntents(intents);
128 } 123 }
...@@ -133,11 +128,10 @@ public class IntentInstaller { ...@@ -133,11 +128,10 @@ public class IntentInstaller {
133 * @param intents intents to be submitted 128 * @param intents intents to be submitted
134 */ 129 */
135 private void submitIntents(Collection<Intent> intents) { 130 private void submitIntents(Collection<Intent> intents) {
136 - log.debug("Submitting intents to the IntentSynchronizer"); 131 + log.debug("Submitting intents to the Intent Synchronizer");
137 - 132 + intents.forEach(intent -> {
138 - for (Intent intent : intents) {
139 intentSynchronizer.submit(intent); 133 intentSynchronizer.submit(intent);
140 - } 134 + });
141 } 135 }
142 136
143 /** 137 /**
...@@ -240,18 +234,12 @@ public class IntentInstaller { ...@@ -240,18 +234,12 @@ public class IntentInstaller {
240 * Counts the number of mac addresses associated to a specific list of 234 * Counts the number of mac addresses associated to a specific list of
241 * ConnectPoint. 235 * ConnectPoint.
242 * 236 *
243 - * @param cPoints List of ConnectPoints, eventually binded to the MAC of the 237 + * @param cPoints Set of ConnectPoints, eventually bound to the MAC of the
244 * host attached 238 * host attached
245 * @return number of mac addresses found. 239 * @return number of mac addresses found.
246 */ 240 */
247 - private int countMacInCPoints(List<Pair<ConnectPoint, MacAddress>> cPoints) { 241 + private int countMacInCPoints(Set<Pair<ConnectPoint, MacAddress>> cPoints) {
248 - int macFound = 0; 242 + return (int) cPoints.stream().filter(p -> p.getValue() != null).count();
249 - for (Pair<ConnectPoint, MacAddress> p : cPoints) {
250 - if (p.getValue() != null) {
251 - macFound++;
252 - }
253 - }
254 - return macFound;
255 } 243 }
256 244
257 } 245 }
......