Refactor of the OVSDB Plugin
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / NetworkHandler.java
index 81da6503d76daffde580d96fbbe20b576adf6011..d4b3d4d2c44bdc4f6cdcdbea4b76bc0649976023 100644 (file)
@@ -14,13 +14,14 @@ import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
-import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
-import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.opendaylight.ovsdb.plugin.OvsdbInventoryListener;
+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.Port;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,11 +48,11 @@ public class NetworkHandler extends AbstractHandler
     // The implementation for each of these services is resolved by the OSGi Service Manager
     private volatile TenantNetworkManager tenantNetworkManager;
     private volatile BridgeConfigurationManager bridgeConfigurationManager;
-    private volatile ConfigurationService configurationService;
-    private volatile OvsdbConfigService ovsdbConfigService;
-    private volatile IConnectionServiceInternal connectionService;
+    private volatile org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService configurationService;
+    private volatile OvsdbConfigurationService ovsdbConfigurationService;
+    private volatile OvsdbConnectionService connectionService;
     private volatile INeutronNetworkCRUD neutronNetworkCache;
-    private volatile OvsdbInventoryListener inventoryListener;
+    private volatile OvsdbInventoryListener ovsdbInventoryListener;
 
     /**
      * Invoked when a network creation is requested
@@ -153,20 +154,35 @@ public class NetworkHandler extends AbstractHandler
                 for (Node node : nodes) {
                     List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node);
                     try {
-                        ConcurrentMap<String, Row> interfaces = this.ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
-                        if (interfaces != null) {
-                            for (String intfUUID : interfaces.keySet()) {
-                                Interface intf = ovsdbConfigService.getTypedRow(node, Interface.class, interfaces.get(intfUUID));
-                                String intfType = intf.getTypeColumn().getData();
-                                if (intfType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) || intfType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
-                                    /* delete tunnel ports on this node */
-                                    logger.trace("Delete tunnel intf {}", intf);
-                                    inventoryListener.rowRemoved(node, intf.getSchema().getName(), intfUUID,
-                                            intf.getRow(), null);
-                                } else if (!phyIfName.isEmpty() && phyIfName.contains(intf.getName())) {
-                                    logger.trace("Delete physical intf {}", intf);
-                                    inventoryListener.rowRemoved(node, intf.getSchema().getName(), intfUUID,
-                                            intf.getRow(), null);
+                        ConcurrentMap<String, Row> ports =
+                                this.ovsdbConfigurationService.getRows(node,
+                                                                ovsdbConfigurationService.getTableName(node, Port.class));
+                        if (ports != null) {
+                            for (Row portRow : ports.values()) {
+                                Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
+                                for (UUID interfaceUuid : port.getInterfacesColumn().getData()) {
+                                    Interface interfaceRow = (Interface) ovsdbConfigurationService
+                                            .getRow(node,
+                                                    ovsdbConfigurationService.getTableName(node, Interface.class),
+                                                    interfaceUuid.toString());
+
+                                    String interfaceType = interfaceRow.getTypeColumn().getData();
+                                    if (interfaceType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)
+                                        || interfaceType.equalsIgnoreCase(
+                                            NetworkHandler.NETWORK_TYPE_GRE)) {
+                                        /* delete tunnel ports on this node */
+                                        logger.trace("Delete tunnel interface {}", interfaceRow);
+                                        ovsdbConfigurationService.deleteRow(node,
+                                                                     ovsdbConfigurationService.getTableName(node, Port.class),
+                                                                     port.getUuid().toString());
+                                        break;
+                                    } else if (!phyIfName.isEmpty() && phyIfName.contains(interfaceRow.getName())) {
+                                        logger.trace("Delete physical interface {}", interfaceRow);
+                                        ovsdbConfigurationService.deleteRow(node,
+                                                                     ovsdbConfigurationService.getTableName(node, Port.class),
+                                                                     port.getUuid().toString());
+                                        break;
+                                    }
                                 }
                             }
                         }