Committed by
Gerrit Code Review
BgpRouter: Batch flow updates
Change-Id: If472e8e93140bce7fbb01c1a2f1847de421108c9
Showing
1 changed file
with
34 additions
and
9 deletions
... | @@ -69,9 +69,11 @@ import org.slf4j.LoggerFactory; | ... | @@ -69,9 +69,11 @@ import org.slf4j.LoggerFactory; |
69 | 69 | ||
70 | import java.util.Collection; | 70 | import java.util.Collection; |
71 | import java.util.Collections; | 71 | import java.util.Collections; |
72 | +import java.util.HashMap; | ||
72 | import java.util.HashSet; | 73 | import java.util.HashSet; |
73 | import java.util.Map; | 74 | import java.util.Map; |
74 | import java.util.Set; | 75 | import java.util.Set; |
76 | +import java.util.stream.Collectors; | ||
75 | 77 | ||
76 | /** | 78 | /** |
77 | * BgpRouter component. | 79 | * BgpRouter component. |
... | @@ -189,6 +191,8 @@ public class BgpRouter { | ... | @@ -189,6 +191,8 @@ public class BgpRouter { |
189 | } | 191 | } |
190 | 192 | ||
191 | private void updateFibEntry(Collection<FibUpdate> updates) { | 193 | private void updateFibEntry(Collection<FibUpdate> updates) { |
194 | + Map<FibEntry, Group> toInstall = new HashMap<>(updates.size()); | ||
195 | + | ||
192 | for (FibUpdate update : updates) { | 196 | for (FibUpdate update : updates) { |
193 | FibEntry entry = update.entry(); | 197 | FibEntry entry = update.entry(); |
194 | 198 | ||
... | @@ -206,17 +210,30 @@ public class BgpRouter { | ... | @@ -206,17 +210,30 @@ public class BgpRouter { |
206 | } | 210 | } |
207 | } | 211 | } |
208 | 212 | ||
209 | - installFlow(update.entry(), group); | 213 | + toInstall.put(update.entry(), group); |
210 | } | 214 | } |
215 | + | ||
216 | + installFlows(toInstall); | ||
211 | } | 217 | } |
212 | 218 | ||
213 | - private void installFlow(FibEntry entry, Group group) { | 219 | + private void installFlows(Map<FibEntry, Group> entriesToInstall) { |
214 | - FlowRule flowRule = generateRibFlowRule(entry.prefix(), group); | 220 | + FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
221 | + | ||
222 | + for (Map.Entry<FibEntry, Group> entry : entriesToInstall.entrySet()) { | ||
223 | + FibEntry fibEntry = entry.getKey(); | ||
224 | + Group group = entry.getValue(); | ||
225 | + | ||
226 | + FlowRule flowRule = generateRibFlowRule(fibEntry.prefix(), group); | ||
227 | + | ||
228 | + builder.add(flowRule); | ||
229 | + } | ||
215 | 230 | ||
216 | - flowService.applyFlowRules(flowRule); | 231 | + flowService.apply(builder.build()); |
217 | } | 232 | } |
218 | 233 | ||
219 | private synchronized void deleteFibEntry(Collection<FibUpdate> withdraws) { | 234 | private synchronized void deleteFibEntry(Collection<FibUpdate> withdraws) { |
235 | + FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); | ||
236 | + | ||
220 | for (FibUpdate update : withdraws) { | 237 | for (FibUpdate update : withdraws) { |
221 | FibEntry entry = update.entry(); | 238 | FibEntry entry = update.entry(); |
222 | 239 | ||
... | @@ -228,8 +245,10 @@ public class BgpRouter { | ... | @@ -228,8 +245,10 @@ public class BgpRouter { |
228 | 245 | ||
229 | FlowRule flowRule = generateRibFlowRule(entry.prefix(), group); | 246 | FlowRule flowRule = generateRibFlowRule(entry.prefix(), group); |
230 | 247 | ||
231 | - flowService.removeFlowRules(flowRule); | 248 | + builder.remove(flowRule); |
232 | } | 249 | } |
250 | + | ||
251 | + flowService.apply(builder.build()); | ||
233 | } | 252 | } |
234 | 253 | ||
235 | private FlowRule generateRibFlowRule(IpPrefix prefix, Group group) { | 254 | private FlowRule generateRibFlowRule(IpPrefix prefix, Group group) { |
... | @@ -332,7 +351,7 @@ public class BgpRouter { | ... | @@ -332,7 +351,7 @@ public class BgpRouter { |
332 | private Map<PortNumber, VlanId> portVlanPair = Maps.newHashMap(); | 351 | private Map<PortNumber, VlanId> portVlanPair = Maps.newHashMap(); |
333 | 352 | ||
334 | public void provision(boolean install, Set<Interface> intfs) { | 353 | public void provision(boolean install, Set<Interface> intfs) { |
335 | - getIntefaceConfig(intfs); | 354 | + getInterfaceConfig(intfs); |
336 | processTableZero(install); | 355 | processTableZero(install); |
337 | processTableOne(install); | 356 | processTableOne(install); |
338 | processTableTwo(install); | 357 | processTableTwo(install); |
... | @@ -342,7 +361,7 @@ public class BgpRouter { | ... | @@ -342,7 +361,7 @@ public class BgpRouter { |
342 | processTableNine(install); | 361 | processTableNine(install); |
343 | } | 362 | } |
344 | 363 | ||
345 | - private void getIntefaceConfig(Set<Interface> intfs) { | 364 | + private void getInterfaceConfig(Set<Interface> intfs) { |
346 | log.info("Processing {} router interfaces", intfs.size()); | 365 | log.info("Processing {} router interfaces", intfs.size()); |
347 | for (Interface intf : intfs) { | 366 | for (Interface intf : intfs) { |
348 | intfIps.addAll(intf.ipAddresses()); | 367 | intfIps.addAll(intf.ipAddresses()); |
... | @@ -665,8 +684,14 @@ public class BgpRouter { | ... | @@ -665,8 +684,14 @@ public class BgpRouter { |
665 | if (event.type() == GroupEvent.Type.GROUP_ADDED || | 684 | if (event.type() == GroupEvent.Type.GROUP_ADDED || |
666 | event.type() == GroupEvent.Type.GROUP_UPDATED) { | 685 | event.type() == GroupEvent.Type.GROUP_UPDATED) { |
667 | synchronized (pendingUpdates) { | 686 | synchronized (pendingUpdates) { |
668 | - pendingUpdates.removeAll(group.appCookie()) | 687 | + |
669 | - .forEach((entry) -> installFlow(entry, group)); | 688 | + Map<FibEntry, Group> entriesToInstall = |
689 | + pendingUpdates.removeAll(group.appCookie()) | ||
690 | + .stream() | ||
691 | + .collect(Collectors | ||
692 | + .toMap(e -> e, e -> group)); | ||
693 | + | ||
694 | + installFlows(entriesToInstall); | ||
670 | } | 695 | } |
671 | } | 696 | } |
672 | } | 697 | } | ... | ... |
-
Please register or login to post a comment