Updated to use bind-service update instead of bind and unbind in Acl VPN 24/64124/6
authorShashidhar Raja <shashidharr@altencalsoftlabs.com>
Tue, 10 Oct 2017 16:47:00 +0000 (22:17 +0530)
committerSam Hague <shague@redhat.com>
Wed, 25 Oct 2017 20:54:43 +0000 (20:54 +0000)
listener

This commit has a dependency on below genius commit:
https://git.opendaylight.org/gerrit/#/c/64123/

Depends-On: Ib05a8fcfac8e74fa5a925edd0db49b7254bbed6a
Change-Id: I3acfe6f7f3f3e98139eb2413774d559ba8c25f8d
Signed-off-by: Shashidhar Raja <shashidharr@altencalsoftlabs.com>
vpnservice/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/listeners/AclVpnChangeListener.java

index e171c22225ad0c9567fbc7e9f2bcfe1cb2f88330..9088331aaa0eb7515f5203e6c73610facd0af7d7 100644 (file)
@@ -7,15 +7,17 @@
  */
 package org.opendaylight.netvirt.aclservice.listeners;
 
+import com.google.common.base.Optional;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
 import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
 import org.opendaylight.netvirt.aclservice.api.utils.AclInterfaceCacheUtil;
+import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AddDpnEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AddInterfaceToDpnOnVpnEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.OdlL3vpnListener;
@@ -30,10 +32,12 @@ import org.slf4j.LoggerFactory;
 public class AclVpnChangeListener implements OdlL3vpnListener {
     private static final Logger LOG = LoggerFactory.getLogger(AclVpnChangeListener.class);
     private final AclServiceManager aclServiceManager;
+    private final DataBroker dataBroker;
 
     @Inject
-    public AclVpnChangeListener(AclServiceManager aclServiceManager) {
+    public AclVpnChangeListener(AclServiceManager aclServiceManager, DataBroker dataBroker) {
         this.aclServiceManager = aclServiceManager;
+        this.dataBroker = dataBroker;
     }
 
     @PostConstruct
@@ -61,7 +65,6 @@ public class AclVpnChangeListener implements OdlL3vpnListener {
         Long vpnId = data.getVpnId();
         AclInterface aclInterface = AclInterfaceCacheUtil.getAclInterfaceFromCache(data.getInterfaceName());
         if (null != aclInterface && aclInterface.isPortSecurityEnabled() && !vpnId.equals(aclInterface.getVpnId())) {
-            aclServiceManager.notify(aclInterface, null, Action.UNBIND);
             aclInterface.setVpnId(vpnId);
             aclServiceManager.notify(aclInterface, null, Action.BIND);
         }
@@ -70,11 +73,17 @@ public class AclVpnChangeListener implements OdlL3vpnListener {
     @Override
     public void onRemoveInterfaceFromDpnOnVpnEvent(RemoveInterfaceFromDpnOnVpnEvent notification) {
         RemoveInterfaceEventData data = notification.getRemoveInterfaceEventData();
-        LOG.trace("Processing vpn interface {} deletion", data.getInterfaceName());
+        String interfaceName = data.getInterfaceName();
+        LOG.trace("Processing vpn interface {} deletion", interfaceName);
+        Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces
+            .Interface> interfaceOpt = AclServiceUtils.getInterface(dataBroker, interfaceName);
+        if (!interfaceOpt.isPresent() || (interfaceOpt.isPresent() && interfaceOpt.get() == null)) {
+            LOG.trace("Interface is deleted; no need to rebind again");
+            return;
+        }
         Long vpnId = data.getVpnId();
-        AclInterface aclInterface = AclInterfaceCacheUtil.getAclInterfaceFromCache(data.getInterfaceName());
+        AclInterface aclInterface = AclInterfaceCacheUtil.getAclInterfaceFromCache(interfaceName);
         if (null != aclInterface && aclInterface.isPortSecurityEnabled() && vpnId.equals(aclInterface.getVpnId())) {
-            aclServiceManager.notify(aclInterface, null, Action.UNBIND);
             aclInterface.setVpnId(null);
             aclServiceManager.notify(aclInterface, null, Action.BIND);
         }