BUG-4205 : VM delete doesnot remove all related flows
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / SouthboundHandler.java
index 8eaed984f10a106608882576d3d20b789f70b94b..0e3832a65af431441b85baef7d749657aea5f778 100644 (file)
@@ -10,7 +10,8 @@ package org.opendaylight.ovsdb.openstack.netvirt;
 
 import java.util.List;
 
-import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronNetwork;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronPort;
 import org.opendaylight.ovsdb.openstack.netvirt.api.*;
 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
@@ -20,7 +21,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -171,6 +171,21 @@ public class SouthboundHandler extends AbstractHandler
                 LOG.error("Error fetching Interface Rows for node {}", node, e);
             }
         }
+        //remove neutronPort from the CleanupCache, if it has the entry.
+        NeutronPort neutronPort = null;
+        String neutronPortId = southbound.getInterfaceExternalIdsValue(ovsdbTerminationPointAugmentation,
+                Constants.EXTERNAL_ID_INTERFACE_ID);
+        if (neutronPortId != null) {
+            LOG.trace("Clean up the NeutronPortCache for {} ", neutronPortId);
+            neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
+        }
+        if (neutronPort != null) {
+            LOG.debug("Clean up the NeutronPortCache ");
+            neutronL3Adapter.removePortFromCleanupCache(neutronPort);
+        } else {
+            LOG.trace("Nothing to Clean up in the NeutronPortCache ");
+        }
+
     }
 
     private boolean isInterfaceOfInterest(OvsdbTerminationPointAugmentation terminationPoint, List<String> phyIfName) {
@@ -219,7 +234,7 @@ public class SouthboundHandler extends AbstractHandler
             return;
         }
         SouthboundEvent ev = (SouthboundEvent) abstractEvent;
-        LOG.trace("processEvent: {}", ev);
+        LOG.trace("processEvent ({}): {}", ev, ev.getTransactionId());
         switch (ev.getType()) {
             case NODE:
                 processOvsdbNodeEvent(ev);
@@ -241,6 +256,7 @@ public class SouthboundHandler extends AbstractHandler
                 LOG.warn("Unable to process type {} action {} for node {}", ev.getType(), ev.getAction(), ev.getNode());
                 break;
         }
+        LOG.trace("processEvent exit ({}): {}", ev, ev.getTransactionId());
     }
 
     private void processOvsdbNodeEvent(SouthboundEvent ev) {
@@ -367,7 +383,7 @@ public class SouthboundHandler extends AbstractHandler
     }
 
     @Override
-    public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
+    public void setDependencies(ServiceReference serviceReference) {
         configurationService =
                 (ConfigurationService) ServiceHelper.getGlobalInstance(ConfigurationService.class, this);
         networkingProviderManager =
@@ -378,16 +394,14 @@ public class SouthboundHandler extends AbstractHandler
                 (BridgeConfigurationManager) ServiceHelper.getGlobalInstance(BridgeConfigurationManager.class, this);
         nodeCacheManager =
                 (NodeCacheManager) ServiceHelper.getGlobalInstance(NodeCacheManager.class, this);
-        nodeCacheManager.cacheListenerAdded(
-                bundleContext.getServiceReference(OvsdbInventoryListener.class.getName()), this);
+        nodeCacheManager.cacheListenerAdded(serviceReference, this);
         neutronL3Adapter =
                 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
         southbound =
                 (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
         eventDispatcher =
                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
-        eventDispatcher.eventHandlerAdded(
-                bundleContext.getServiceReference(OvsdbInventoryListener.class.getName()), this);
+        eventDispatcher.eventHandlerAdded(serviceReference, this);
         ovsdbInventoryService =
                 (OvsdbInventoryService) ServiceHelper.getGlobalInstance(OvsdbInventoryService.class, this);
         ovsdbInventoryService.listenerAdded(this);