Fix for Bug 3428 - table0 tunnel entry not deleted 74/23274/2
authorAbhinav Gupta <abhinav.gupta@ericsson.com>
Thu, 25 Jun 2015 13:04:01 +0000 (18:34 +0530)
committerAbhinav Gupta <abhinav.gupta@ericsson.com>
Thu, 25 Jun 2015 19:27:11 +0000 (00:57 +0530)
Change-Id: I14cf648026a1a66e1e7014e7c97511d395a76dec
Signed-off-by: Abhinav Gupta <abhinav.gupta@ericsson.com>
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/InterfaceChangeListener.java
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnserviceProvider.java

index 7e054145c915596141b6ab1dd951f6a4e4ebb9e5..b1ace260ab34b68223659b15138aa5b0c9cba9dd 100644 (file)
@@ -1,12 +1,15 @@
 package org.opendaylight.vpnservice;
 
+import java.math.BigInteger;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
+import org.opendaylight.vpnservice.mdsalutil.NwConstants;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.L3tunnel;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
@@ -19,6 +22,7 @@ public class InterfaceChangeListener extends AbstractDataChangeListener<Interfac
     private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker broker;
     private VpnInterfaceManager vpnInterfaceManager;
+    private IInterfaceManager interfaceManager;
 
 
     public InterfaceChangeListener(final DataBroker db, VpnInterfaceManager vpnInterfaceManager) {
@@ -28,6 +32,10 @@ public class InterfaceChangeListener extends AbstractDataChangeListener<Interfac
         registerListener(db);
     }
 
+    public void setInterfaceManager(IInterfaceManager interfaceManager) {
+      this.interfaceManager = interfaceManager;
+  }
+
     @Override
     public void close() throws Exception {
         if (listenerRegistration != null) {
@@ -66,10 +74,23 @@ public class InterfaceChangeListener extends AbstractDataChangeListener<Interfac
     @Override
     protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
         LOG.trace("Remove interface event - key: {}, value: {}", identifier, intrf );
+        if (intrf.getType().equals(L3tunnel.class)) {
+          BigInteger dpnId =  interfaceManager.getDpnForInterface(intrf);
+          String ifName = intrf.getName();
+          LOG.debug("Removing tunnel interface associated with Interface {}", intrf.getName());
+          vpnInterfaceManager.makeTunnelIngressFlow(dpnId, ifName, NwConstants.DEL_FLOW);
+      }
+        else {
         VpnInterface vpnInterface = vpnInterfaceManager.getVpnInterface(intrf.getName());
-        InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(intrf.getName());
-        LOG.debug("Removing VPN Interface associated with Interface {}", intrf.getName());
-        vpnInterfaceManager.remove(id, vpnInterface);
+          if (vpnInterface !=null) {
+            InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(intrf.getName());
+            LOG.debug("Removing VPN Interface associated with Interface {}", intrf.getName());
+            vpnInterfaceManager.remove(id, vpnInterface);
+          }
+          else {
+            LOG.debug("No VPN Interface associated with Interface {}", intrf.getName());
+          }
+        }
     }
 
     @Override
index 02d77ad4b93c24cf695f146be0e47d432795f362..3585a6f17578884fc0007bb483abef5c30509eb7 100644 (file)
@@ -564,7 +564,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
     }
 
 
-    private void makeTunnelIngressFlow(BigInteger dpnId, String ifName, int addOrRemoveFlow) {
+    protected void makeTunnelIngressFlow(BigInteger dpnId, String ifName, int addOrRemoveFlow) {
         long portNo = 0;
         String flowName = ifName;
         String flowRef = getTunnelInterfaceFlowRef(dpnId, VpnConstants.LPORT_INGRESS_TABLE, ifName);
index ab1666228ccc5014ad9ebf40db5ecac3429af8d3..0548c3622fcf9b819cf9038d3171875d0cc575cd 100644 (file)
@@ -54,6 +54,7 @@ public class VpnserviceProvider implements BindingAwareProvider, IVpnManager,
             vpnInterfaceManager.setIdManager(idManager);
             vpnManager.setVpnInterfaceManager(vpnInterfaceManager);
             interfaceListener = new InterfaceChangeListener(dataBroker, vpnInterfaceManager);
+            interfaceListener.setInterfaceManager(interfaceManager);
             createIdPool();
         } catch (Exception e) {
             LOG.error("Error initializing services", e);