BUG 7264 Fix missing flows for Remote SG rule
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / netvirt / openstack / netvirt / PortHandler.java
index 0b665b425cd1bdd9b8710522761cecf4bc2d6c7b..5ca9819cc8f96aefe910d7cdb97d34423afffd38 100644 (file)
@@ -15,14 +15,15 @@ import org.opendaylight.netvirt.openstack.netvirt.api.Action;
 import org.opendaylight.netvirt.openstack.netvirt.api.BridgeConfigurationManager;
 import org.opendaylight.netvirt.openstack.netvirt.api.NetworkingProviderManager;
 import org.opendaylight.netvirt.openstack.netvirt.api.NodeCacheManager;
+import org.opendaylight.netvirt.openstack.netvirt.api.NodeCacheListener;
 import org.opendaylight.netvirt.openstack.netvirt.api.TenantNetworkManager;
 import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronNetwork;
 import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronPort;
+import org.opendaylight.netvirt.openstack.netvirt.translator.crud.INeutronPortCRUD;
 import org.opendaylight.netvirt.openstack.netvirt.translator.iaware.INeutronPortAware;
 import org.opendaylight.netvirt.openstack.netvirt.api.Constants;
 import org.opendaylight.netvirt.openstack.netvirt.api.EventDispatcher;
 import org.opendaylight.netvirt.openstack.netvirt.api.Southbound;
-import org.opendaylight.netvirt.openstack.netvirt.impl.DistributedArpService;
 import org.opendaylight.netvirt.openstack.netvirt.impl.NeutronL3Adapter;
 import org.opendaylight.netvirt.utils.servicehelper.ServiceHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
@@ -35,7 +36,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Handle requests for Neutron Port.
  */
-public class PortHandler extends AbstractHandler implements INeutronPortAware, ConfigInterface {
+public class PortHandler extends AbstractHandler implements INeutronPortAware, NodeCacheListener, ConfigInterface {
     private static final Logger LOG = LoggerFactory.getLogger(PortHandler.class);
 
     // The implementation for each of these services is resolved by the OSGi Service Manager
@@ -44,8 +45,8 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
     private volatile TenantNetworkManager tenantNetworkManager;
     private volatile NetworkingProviderManager networkingProviderManager;
     private volatile NeutronL3Adapter neutronL3Adapter;
-    private volatile DistributedArpService distributedArpService;
     private volatile Southbound southbound;
+    private volatile INeutronPortCRUD neutronPortCache;
 
     /**
      * Invoked when a port creation is requested
@@ -91,7 +92,6 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
             }
         }
 
-        distributedArpService.handlePortEvent(neutronPort, Action.ADD);
         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.ADD);
     }
 
@@ -122,7 +122,6 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
     }
     private void doNeutronPortUpdated(NeutronPort neutronPort) {
         LOG.debug("Handling neutron update port {}", neutronPort);
-        distributedArpService.handlePortEvent(neutronPort, Action.UPDATE);
         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.UPDATE);
     }
 
@@ -149,7 +148,6 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
     }
     private void doNeutronPortDeleted(NeutronPort neutronPort) {
         LOG.debug("Handling neutron delete port {}", neutronPort);
-        distributedArpService.handlePortEvent(neutronPort, Action.DELETE);
         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.DELETE);
 
         //TODO: Need to implement getNodes
@@ -184,6 +182,17 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
         return null;
     }
 
+    @Override
+    public void notifyNode(Node node, Action action) {
+        if (action == Action.ADD) {
+            List<NeutronPort> neutronPorts = neutronPortCache.getAllPorts();
+            for (NeutronPort neutronPort : neutronPorts) {
+                LOG.info("in notifyNode, neutronPort {} will be added", neutronPort);
+                neutronPortCreated(neutronPort);
+            }
+        }
+    }
+
     /**
      * Process the event.
      *
@@ -217,6 +226,7 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
     public void setDependencies(ServiceReference serviceReference) {
         nodeCacheManager =
                 (NodeCacheManager) ServiceHelper.getGlobalInstance(NodeCacheManager.class, this);
+        nodeCacheManager.cacheListenerAdded(serviceReference, this);
         networkingProviderManager =
                 (NetworkingProviderManager) ServiceHelper.getGlobalInstance(NetworkingProviderManager.class, this);
         tenantNetworkManager =
@@ -225,15 +235,18 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
                 (BridgeConfigurationManager) ServiceHelper.getGlobalInstance(BridgeConfigurationManager.class, this);
         neutronL3Adapter =
                 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
-        distributedArpService =
-                (DistributedArpService) ServiceHelper.getGlobalInstance(DistributedArpService.class, this);
         southbound =
                 (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
         eventDispatcher =
                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
         eventDispatcher.eventHandlerAdded(serviceReference, this);
+
     }
 
     @Override
-    public void setDependencies(Object impl) {}
+    public void setDependencies(Object impl) {
+        if (impl instanceof INeutronPortCRUD) {
+            neutronPortCache = (INeutronPortCRUD)impl;
+        }
+    }
 }