Provide FlowCapableNodeDataChangeListener to openstack.netvirt via NodeCacheManager
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / SouthboundHandler.java
index 947d58a0712e8ade6cf05581bbd338d23558f67a..46d2f4474b2bfd579e44c80aa7bedb8da9c3a7d3 100644 (file)
@@ -9,25 +9,23 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt;
 
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.switchmanager.IInventoryListener;
+import org.opendaylight.neutron.spi.NeutronNetwork;
 import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
+import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
 import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener;
 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
 import org.opendaylight.ovsdb.schema.openvswitch.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 
-import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,22 +35,20 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 
-public class SouthboundHandler extends AbstractHandler implements OvsdbInventoryListener,
-                                                                  IInventoryListener {
+public class SouthboundHandler extends AbstractHandler implements OvsdbInventoryListener {
     static final Logger logger = LoggerFactory.getLogger(SouthboundHandler.class);
     //private Thread eventThread;
-    List<Node> nodeCache;
 
     // The implementation for each of these services is resolved by the OSGi Service Manager
-    private volatile org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService configurationService;
+    private volatile ConfigurationService configurationService;
     private volatile BridgeConfigurationManager bridgeConfigurationManager;
     private volatile TenantNetworkManager tenantNetworkManager;
     private volatile NetworkingProviderManager networkingProviderManager;
     private volatile OvsdbConfigurationService ovsdbConfigurationService;
     private volatile OvsdbConnectionService connectionService;
+    private volatile NeutronL3Adapter neutronL3Adapter;
 
     void init() {
-        nodeCache = Lists.newArrayList();
     }
 
     void start() {
@@ -61,23 +57,24 @@ public class SouthboundHandler extends AbstractHandler implements OvsdbInventory
 
     @Override
     public void nodeAdded(Node node, InetAddress address, int port) {
-        this.enqueueEvent(new SouthboundEvent(node, SouthboundEvent.Action.ADD));
+        logger.info("nodeAdded: {}", node);
+        this.enqueueEvent(new SouthboundEvent(node, Action.ADD));
     }
 
     @Override
     public void nodeRemoved(Node node) {
-        this.enqueueEvent(new SouthboundEvent(node, SouthboundEvent.Action.DELETE));
+        this.enqueueEvent(new SouthboundEvent(node, Action.DELETE));
     }
 
     @Override
     public void rowAdded(Node node, String tableName, String uuid, Row row) {
-        this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, SouthboundEvent.Action.ADD));
+        this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, Action.ADD));
     }
 
     @Override
     public void rowUpdated(Node node, String tableName, String uuid, Row oldRow, Row newRow) {
         if (this.isUpdateOfInterest(node, oldRow, newRow)) {
-            this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, newRow, SouthboundEvent.Action.UPDATE));
+            this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, newRow, Action.UPDATE));
         }
     }
 
@@ -117,18 +114,18 @@ public class SouthboundHandler extends AbstractHandler implements OvsdbInventory
 
     @Override
     public void rowRemoved(Node node, String tableName, String uuid, Row row, Object context) {
-        this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, context, SouthboundEvent.Action.DELETE));
+        this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, context, Action.DELETE));
     }
 
-    public void processNodeUpdate(Node node, SouthboundEvent.Action action) {
-        if (action == SouthboundEvent.Action.DELETE) return;
+    public void processNodeUpdate(Node node, Action action) {
+        if (action == Action.DELETE) return;
         logger.trace("Process Node added {}", node);
         bridgeConfigurationManager.prepareNode(node);
     }
 
     private void processRowUpdate(Node node, String tableName, String uuid, Row row,
-                                  Object context, SouthboundEvent.Action action) {
-        if (action == SouthboundEvent.Action.DELETE) {
+                                  Object context, Action action) {
+        if (action == Action.DELETE) {
             if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, Interface.class))) {
                 logger.debug("Processing update of {}. Deleted node: {}, uuid: {}, row: {}", tableName, node, uuid, row);
                 Interface deletedIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
@@ -235,6 +232,7 @@ public class SouthboundHandler extends AbstractHandler implements OvsdbInventory
         logger.trace("Interface update of node: {}, uuid: {}", node, uuid);
         NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
         if (network != null) {
+            neutronL3Adapter.handleInterfaceEvent(node, intf, network, Action.UPDATE);
             if (bridgeConfigurationManager.createLocalNetwork(node, network))
                 networkingProviderManager.getProvider(node).handleInterfaceUpdate(network, node, intf);
         } else {
@@ -247,6 +245,7 @@ public class SouthboundHandler extends AbstractHandler implements OvsdbInventory
         logger.debug("handleInterfaceDelete: node: {}, uuid: {}, isLastInstanceOnNode: {}, interface: {}",
                 node, uuid, isLastInstanceOnNode, intf);
 
+        neutronL3Adapter.handleInterfaceEvent(node, intf, network, Action.DELETE);
         List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node);
         if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
             intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
@@ -283,29 +282,11 @@ public class SouthboundHandler extends AbstractHandler implements OvsdbInventory
                 }
             }
         } catch (Exception e) {
-            logger.debug("Failed to get Port tag for for Intf {}:{}", intf, e);
+            logger.debug("Failed to get Port tag for for Intf " + intf, e);
         }
         return null;
     }
 
-    @Override
-    public void notifyNode(Node node, UpdateType type, Map<String, Property> propMap) {
-        logger.debug("notifyNode: Node {} update {} from Controller's inventory Service", node, type);
-
-        // Add the Node Type check back once the Consistency issue is resolved between MD-SAL and AD-SAL
-        if (!type.equals(UpdateType.REMOVED) && !nodeCache.contains(node)) {
-            nodeCache.add(node);
-            networkingProviderManager.getProvider(node).initializeOFFlowRules(node);
-        } else if (type.equals(UpdateType.REMOVED)){
-            nodeCache.remove(node);
-        }
-    }
-
-    @Override
-    public void notifyNodeConnector(NodeConnector nodeConnector, UpdateType type, Map<String, Property> propMap) {
-        //We are not interested in the nodeConnectors at this moment
-    }
-
     private void triggerUpdates() {
         List<Node> nodes = connectionService.getNodes();
         if (nodes == null) return;