Committed by
Gerrit Code Review
Refactor VPLS IntentInstaller
Change-Id: Ia729849fd0c939b6399abad5f15658b48fbb62b4
Showing
1 changed file
with
35 additions
and
47 deletions
... | @@ -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,42 +86,38 @@ public class IntentInstaller { | ... | @@ -87,42 +86,38 @@ 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 | + Key brcKey = buildKey(PREFIX_BROADCAST, src, vlanId); |
102 | - if (!dst.equals(src)) { | 103 | + if (intentService.getIntent(brcKey) == null) { |
103 | - dsts.add(dst); | 104 | + SinglePointToMultiPointIntent brcIntent = |
104 | - } | 105 | + buildBrcIntent(brcKey, src, dsts, vlanId); |
105 | - } | 106 | + intents.add(brcIntent); |
106 | - Key brcKey = buildKey(PREFIX_BROADCAST, src, vlanId); | 107 | + } |
107 | - if (intentService.getIntent(brcKey) == null) { | 108 | + if (mac != null && countMacInCPoints(cPoints) > 1) { |
108 | - SinglePointToMultiPointIntent brcIntent = | 109 | + Key uniKey = buildKey(PREFIX_UNICAST, src, vlanId); |
109 | - buildBrcIntent(brcKey, src, dsts, vlanId); | 110 | + if (intentService.getIntent(uniKey) == null) { |
110 | - intents.add(brcIntent); | 111 | + MultiPointToSinglePointIntent uniIntent = |
111 | - } | 112 | + buildUniIntent(uniKey, |
112 | - if (mac != null && countMacInCPoints(cPoints) > 1) { | 113 | + dsts, |
113 | - Key uniKey = buildKey(PREFIX_UNICAST, src, vlanId); | 114 | + src, |
114 | - if (intentService.getIntent(uniKey) == null) { | 115 | + vlanId, |
115 | - MultiPointToSinglePointIntent uniIntent = | 116 | + mac); |
116 | - buildUniIntent(uniKey, | 117 | + intents.add(uniIntent); |
117 | - dsts, | ||
118 | - src, | ||
119 | - vlanId, | ||
120 | - mac); | ||
121 | - intents.add(uniIntent); | ||
122 | - } | ||
123 | } | 118 | } |
124 | } | 119 | } |
125 | - } | 120 | + }); |
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 | } | ... | ... |
-
Please register or login to post a comment