Committed by
Gerrit Code Review
changes for CORD-365,SingleSwitchFibInstaller, addressed comments, added comments.
Change-Id: I88f6266142da2cfe7bf3569cbe317925c17e3bca
Showing
1 changed file
with
53 additions
and
6 deletions
... | @@ -210,13 +210,19 @@ public class SingleSwitchFibInstaller { | ... | @@ -210,13 +210,19 @@ public class SingleSwitchFibInstaller { |
210 | 210 | ||
211 | //remove filtering objectives and routes before deactivate. | 211 | //remove filtering objectives and routes before deactivate. |
212 | private void cleanUp() { | 212 | private void cleanUp() { |
213 | + //remove the route listener | ||
214 | + routeService.removeListener(routeListener); | ||
215 | + | ||
213 | //clean up the routes. | 216 | //clean up the routes. |
214 | for (Map.Entry<IpPrefix, IpAddress> routes: prefixToNextHop.entrySet()) { | 217 | for (Map.Entry<IpPrefix, IpAddress> routes: prefixToNextHop.entrySet()) { |
215 | deleteRoute(new ResolvedRoute(routes.getKey(), null, null)); | 218 | deleteRoute(new ResolvedRoute(routes.getKey(), null, null)); |
216 | } | 219 | } |
220 | + | ||
217 | //clean up the filtering objective for interfaces. | 221 | //clean up the filtering objective for interfaces. |
218 | Set<Interface> intfs = getInterfaces(); | 222 | Set<Interface> intfs = getInterfaces(); |
219 | - processIntfFilters(false, intfs); | 223 | + if (!intfs.isEmpty()) { |
224 | + processIntfFilters(false, intfs); | ||
225 | + } | ||
220 | } | 226 | } |
221 | 227 | ||
222 | private void updateConfig() { | 228 | private void updateConfig() { |
... | @@ -237,10 +243,36 @@ public class SingleSwitchFibInstaller { | ... | @@ -237,10 +243,36 @@ public class SingleSwitchFibInstaller { |
237 | log.info("Using interfaces: {}", interfaces.isEmpty() ? "all" : interfaces); | 243 | log.info("Using interfaces: {}", interfaces.isEmpty() ? "all" : interfaces); |
238 | 244 | ||
239 | routeService.addListener(routeListener); | 245 | routeService.addListener(routeListener); |
240 | - | ||
241 | updateDevice(); | 246 | updateDevice(); |
242 | } | 247 | } |
243 | 248 | ||
249 | + //remove the filtering objective for interfaces which are no longer part of vRouter config. | ||
250 | + private void removeFilteringObjectives(NetworkConfigEvent event) { | ||
251 | + RouterConfig prevRouterConfig = (RouterConfig) event.prevConfig().get(); | ||
252 | + List<String> prevInterfaces = prevRouterConfig.getInterfaces(); | ||
253 | + | ||
254 | + Set<Interface> previntfs = filterInterfaces(prevInterfaces); | ||
255 | + //if previous interface list is empty it means filtering objectives are | ||
256 | + //installed for all the interfaces. | ||
257 | + if (previntfs.isEmpty() && !interfaces.isEmpty()) { | ||
258 | + Set<Interface> allIntfs = interfaceService.getInterfaces(); | ||
259 | + for (Interface allIntf : allIntfs) { | ||
260 | + if (!interfaces.contains(allIntf.name())) { | ||
261 | + processIntfFilter(false, allIntf); | ||
262 | + } | ||
263 | + } | ||
264 | + return; | ||
265 | + } | ||
266 | + | ||
267 | + //remove the filtering objective for the interfaces which are not | ||
268 | + //part of updated interfaces list. | ||
269 | + for (Interface prevIntf : previntfs) { | ||
270 | + if (!interfaces.contains(prevIntf.name())) { | ||
271 | + processIntfFilter(false, prevIntf); | ||
272 | + } | ||
273 | + } | ||
274 | + } | ||
275 | + | ||
244 | private void updateDevice() { | 276 | private void updateDevice() { |
245 | if (deviceId != null && deviceService.isAvailable(deviceId)) { | 277 | if (deviceId != null && deviceService.isAvailable(deviceId)) { |
246 | Set<Interface> intfs = getInterfaces(); | 278 | Set<Interface> intfs = getInterfaces(); |
... | @@ -254,14 +286,19 @@ public class SingleSwitchFibInstaller { | ... | @@ -254,14 +286,19 @@ public class SingleSwitchFibInstaller { |
254 | intfs = interfaceService.getInterfaces(); | 286 | intfs = interfaceService.getInterfaces(); |
255 | } else { | 287 | } else { |
256 | // TODO need to fix by making interface names globally unique | 288 | // TODO need to fix by making interface names globally unique |
257 | - intfs = interfaceService.getInterfaces().stream() | 289 | + intfs = filterInterfaces(interfaces); |
258 | - .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) | ||
259 | - .filter(intf -> interfaces.contains(intf.name())) | ||
260 | - .collect(Collectors.toSet()); | ||
261 | } | 290 | } |
262 | return intfs; | 291 | return intfs; |
263 | } | 292 | } |
264 | 293 | ||
294 | + private Set<Interface> filterInterfaces(List<String> interfaces) { | ||
295 | + Set<Interface> intfs = interfaceService.getInterfaces().stream() | ||
296 | + .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) | ||
297 | + .filter(intf -> interfaces.contains(intf.name())) | ||
298 | + .collect(Collectors.toSet()); | ||
299 | + return intfs; | ||
300 | + } | ||
301 | + | ||
265 | private void updateRoute(ResolvedRoute route) { | 302 | private void updateRoute(ResolvedRoute route) { |
266 | addNextHop(route); | 303 | addNextHop(route); |
267 | 304 | ||
... | @@ -420,6 +457,9 @@ public class SingleSwitchFibInstaller { | ... | @@ -420,6 +457,9 @@ public class SingleSwitchFibInstaller { |
420 | // Ignore interfaces if they are not on the router switch | 457 | // Ignore interfaces if they are not on the router switch |
421 | return; | 458 | return; |
422 | } | 459 | } |
460 | + if (!interfaces.contains(intf.name()) && install) { | ||
461 | + return; | ||
462 | + } | ||
423 | 463 | ||
424 | createFilteringObjective(install, intf); | 464 | createFilteringObjective(install, intf); |
425 | createMcastFilteringObjective(install, intf); | 465 | createMcastFilteringObjective(install, intf); |
... | @@ -557,10 +597,17 @@ public class SingleSwitchFibInstaller { | ... | @@ -557,10 +597,17 @@ public class SingleSwitchFibInstaller { |
557 | case CONFIG_ADDED: | 597 | case CONFIG_ADDED: |
558 | case CONFIG_UPDATED: | 598 | case CONFIG_UPDATED: |
559 | updateConfig(); | 599 | updateConfig(); |
600 | + if (event.prevConfig().isPresent()) { | ||
601 | + removeFilteringObjectives(event); | ||
602 | + } | ||
560 | break; | 603 | break; |
561 | case CONFIG_REGISTERED: | 604 | case CONFIG_REGISTERED: |
605 | + break; | ||
562 | case CONFIG_UNREGISTERED: | 606 | case CONFIG_UNREGISTERED: |
607 | + break; | ||
563 | case CONFIG_REMOVED: | 608 | case CONFIG_REMOVED: |
609 | + cleanUp(); | ||
610 | + break; | ||
564 | default: | 611 | default: |
565 | break; | 612 | break; |
566 | } | 613 | } | ... | ... |
-
Please register or login to post a comment