Committed by
Gerrit Code Review
vRouter doesnt handle config remove event
Change-Id: I31d7c054f94b5192ab1ef5ebd2af1151a7338437
Showing
1 changed file
with
87 additions
and
21 deletions
... | @@ -83,6 +83,8 @@ public class ControlPlaneRedirectManager { | ... | @@ -83,6 +83,8 @@ public class ControlPlaneRedirectManager { |
83 | private final Logger log = getLogger(getClass()); | 83 | private final Logger log = getLogger(getClass()); |
84 | 84 | ||
85 | private static final int MIN_IP_PRIORITY = 10; | 85 | private static final int MIN_IP_PRIORITY = 10; |
86 | + private static final int IPV4_PRIORITY = 2000; | ||
87 | + private static final int IPV6_PRIORITY = 500; | ||
86 | private static final int ACL_PRIORITY = 40001; | 88 | private static final int ACL_PRIORITY = 40001; |
87 | private static final int OSPF_IP_PROTO = 0x59; | 89 | private static final int OSPF_IP_PROTO = 0x59; |
88 | 90 | ||
... | @@ -421,15 +423,22 @@ public class ControlPlaneRedirectManager { | ... | @@ -421,15 +423,22 @@ public class ControlPlaneRedirectManager { |
421 | public void event(NetworkConfigEvent event) { | 423 | public void event(NetworkConfigEvent event) { |
422 | if (event.configClass().equals(RoutingService.ROUTER_CONFIG_CLASS)) { | 424 | if (event.configClass().equals(RoutingService.ROUTER_CONFIG_CLASS)) { |
423 | switch (event.type()) { | 425 | switch (event.type()) { |
424 | - case CONFIG_ADDED: | 426 | + case CONFIG_ADDED: |
425 | - case CONFIG_UPDATED: | 427 | + case CONFIG_UPDATED: |
426 | - readConfig(); | 428 | + readConfig(); |
427 | - break; | 429 | + if (event.prevConfig().isPresent()) { |
428 | - case CONFIG_REGISTERED: | 430 | + updateConfig(event); |
429 | - case CONFIG_UNREGISTERED: | 431 | + } |
430 | - case CONFIG_REMOVED: | 432 | + |
431 | - default: | 433 | + break; |
432 | - break; | 434 | + case CONFIG_REGISTERED: |
435 | + case CONFIG_UNREGISTERED: | ||
436 | + case CONFIG_REMOVED: | ||
437 | + removeConfig(); | ||
438 | + | ||
439 | + break; | ||
440 | + default: | ||
441 | + break; | ||
433 | } | 442 | } |
434 | } | 443 | } |
435 | } | 444 | } |
... | @@ -576,8 +585,66 @@ public class ControlPlaneRedirectManager { | ... | @@ -576,8 +585,66 @@ public class ControlPlaneRedirectManager { |
576 | 585 | ||
577 | private int getPriorityFromPrefix(IpPrefix prefix) { | 586 | private int getPriorityFromPrefix(IpPrefix prefix) { |
578 | return (prefix.isIp4()) ? | 587 | return (prefix.isIp4()) ? |
579 | - 2000 * prefix.prefixLength() + MIN_IP_PRIORITY : | 588 | + IPV4_PRIORITY * prefix.prefixLength() + MIN_IP_PRIORITY : |
580 | - 500 * prefix.prefixLength() + MIN_IP_PRIORITY; | 589 | + IPV6_PRIORITY * prefix.prefixLength() + MIN_IP_PRIORITY; |
590 | + } | ||
591 | + | ||
592 | + private void updateConfig(NetworkConfigEvent event) { | ||
593 | + RouterConfig prevRouterConfig = (RouterConfig) event.prevConfig().get(); | ||
594 | + List<String> prevInterfaces = prevRouterConfig.getInterfaces(); | ||
595 | + Set<Interface> previntfs = filterInterfaces(prevInterfaces); | ||
596 | + if (previntfs.isEmpty() && !interfaces.isEmpty()) { | ||
597 | + interfaceService.getInterfaces().stream() | ||
598 | + .filter(intf -> !interfaces.contains(intf.name())) | ||
599 | + .forEach(intf -> processIntfFilter(false, intf)); | ||
600 | + return; | ||
601 | + } | ||
602 | + //remove the filtering objective for the interfaces which are not | ||
603 | + //part of updated interfaces list. | ||
604 | + previntfs.stream() | ||
605 | + .filter(intf -> !interfaces.contains(intf.name())) | ||
606 | + .forEach(intf -> processIntfFilter(false, intf)); | ||
607 | + } | ||
608 | + | ||
609 | + /** | ||
610 | + * process filtering objective for interface add/remove. | ||
611 | + * | ||
612 | + * @param install true to install flows, false to uninstall the flows | ||
613 | + * @param intf Interface object captured on event | ||
614 | + */ | ||
615 | + private void processIntfFilter(boolean install, Interface intf) { | ||
616 | + | ||
617 | + if (!intf.connectPoint().deviceId().equals(controlPlaneConnectPoint.deviceId())) { | ||
618 | + // Ignore interfaces if they are not on the router switch | ||
619 | + return; | ||
620 | + } | ||
621 | + if (!interfaces.contains(intf.name()) && install) { | ||
622 | + return; | ||
623 | + } | ||
624 | + | ||
625 | + provisionInterface(intf, install); | ||
626 | + } | ||
627 | + | ||
628 | + private Set<Interface> filterInterfaces(List<String> interfaces) { | ||
629 | + Set<Interface> intfs = interfaceService.getInterfaces().stream() | ||
630 | + .filter(intf -> intf.connectPoint().deviceId().equals(controlPlaneConnectPoint.deviceId())) | ||
631 | + .filter(intf -> interfaces.contains(intf.name())) | ||
632 | + .collect(Collectors.toSet()); | ||
633 | + return intfs; | ||
634 | + } | ||
635 | + | ||
636 | + private void removeConfig() { | ||
637 | + Set<Interface> intfs = getInterfaces(); | ||
638 | + if (!intfs.isEmpty()) { | ||
639 | + intfs.forEach(intf -> processIntfFilter(false, intf)); | ||
640 | + } | ||
641 | + networkConfigService.removeConfig(); | ||
642 | + } | ||
643 | + | ||
644 | + private Set<Interface> getInterfaces() { | ||
645 | + | ||
646 | + return interfaces.isEmpty() ? interfaceService.getInterfaces() | ||
647 | + : filterInterfaces(interfaces); | ||
581 | } | 648 | } |
582 | 649 | ||
583 | /** | 650 | /** |
... | @@ -587,6 +654,11 @@ public class ControlPlaneRedirectManager { | ... | @@ -587,6 +654,11 @@ public class ControlPlaneRedirectManager { |
587 | * @param intf the current occurred update event | 654 | * @param intf the current occurred update event |
588 | **/ | 655 | **/ |
589 | private void updateInterface(Interface prevIntf, Interface intf) { | 656 | private void updateInterface(Interface prevIntf, Interface intf) { |
657 | + if (!intf.connectPoint().deviceId().equals(controlPlaneConnectPoint.deviceId()) | ||
658 | + || !interfaces.contains(intf.name())) { | ||
659 | + // Ignore interfaces if they are not on the router switch | ||
660 | + return; | ||
661 | + } | ||
590 | if (!prevIntf.vlan().equals(intf.vlan()) || !prevIntf.mac().equals(intf)) { | 662 | if (!prevIntf.vlan().equals(intf.vlan()) || !prevIntf.mac().equals(intf)) { |
591 | provisionInterface(prevIntf, false); | 663 | provisionInterface(prevIntf, false); |
592 | provisionInterface(intf, true); | 664 | provisionInterface(intf, true); |
... | @@ -612,26 +684,20 @@ public class ControlPlaneRedirectManager { | ... | @@ -612,26 +684,20 @@ public class ControlPlaneRedirectManager { |
612 | @Override | 684 | @Override |
613 | public void event(InterfaceEvent event) { | 685 | public void event(InterfaceEvent event) { |
614 | if (controlPlaneConnectPoint == null) { | 686 | if (controlPlaneConnectPoint == null) { |
615 | - log.info("Control plane connect point is not configured. Abort InterfaceEvent."); | 687 | + log.warn("Control plane connect point is not configured. Abort InterfaceEvent."); |
616 | return; | 688 | return; |
617 | } | 689 | } |
618 | Interface intf = event.subject(); | 690 | Interface intf = event.subject(); |
619 | Interface prevIntf = event.prevSubject(); | 691 | Interface prevIntf = event.prevSubject(); |
620 | switch (event.type()) { | 692 | switch (event.type()) { |
621 | case INTERFACE_ADDED: | 693 | case INTERFACE_ADDED: |
622 | - if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) { | 694 | + processIntfFilter(true, intf); |
623 | - provisionInterface(intf, true); | ||
624 | - } | ||
625 | break; | 695 | break; |
626 | case INTERFACE_UPDATED: | 696 | case INTERFACE_UPDATED: |
627 | - if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) { | 697 | + updateInterface(prevIntf, intf); |
628 | - updateInterface(prevIntf, intf); | ||
629 | - } | ||
630 | break; | 698 | break; |
631 | case INTERFACE_REMOVED: | 699 | case INTERFACE_REMOVED: |
632 | - if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) { | 700 | + processIntfFilter(false, intf); |
633 | - provisionInterface(intf, false); | ||
634 | - } | ||
635 | break; | 701 | break; |
636 | default: | 702 | default: |
637 | break; | 703 | break; | ... | ... |
-
Please register or login to post a comment