Made changes in Internal Network creation to also takes care of creating br-int ... 90/3490/1
authorMadhu Venugopal <mavenugo@gmail.com>
Thu, 5 Dec 2013 08:24:34 +0000 (00:24 -0800)
committerMadhu Venugopal <mavenugo@gmail.com>
Thu, 5 Dec 2013 08:24:34 +0000 (00:24 -0800)
Please note that the current implementation creates br-int, br-tun and the patch ports upon detecting a new Node.
This can be improved by creating these bridges just when the Neutron events begin. Since this functionality is now
boxed into a single method call, it can be taken care as a future fix.

Change-Id: I71f52348d042a8ef1653fcd8e094a7a1d87d78d6
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
neutron/src/main/java/org/opendaylight/ovsdb/neutron/InternalNetworkManager.java
neutron/src/main/java/org/opendaylight/ovsdb/neutron/SouthboundHandler.java
neutron/src/main/java/org/opendaylight/ovsdb/neutron/provider/OF10ProviderManager.java

index b644c4e8a907d9a845e7bc7bf7ce8c5e83cafe0d..53935c9b7cf085b068c11ec16b22b4201fdbc7df 100644 (file)
@@ -1,7 +1,6 @@
 package org.opendaylight.ovsdb.neutron;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -66,7 +65,7 @@ public class InternalNetworkManager {
         return null;
     }
 
-    public boolean isInternalNetworkNeutronReady(Node node) throws Exception {
+    public boolean isInternalNetworkNeutronReady(Node node) {
         if (this.getInternalBridgeUUID(node, AdminConfigManager.getManager().getIntegrationBridgeName()) != null) {
             return true;
         } else {
@@ -74,7 +73,10 @@ public class InternalNetworkManager {
         }
     }
 
-    public boolean isInternalNetworkOverlayReady(Node node) throws Exception {
+    public boolean isInternalNetworkOverlayReady(Node node) {
+        if (!this.isInternalNetworkNeutronReady(node)) {
+            return false;
+        }
         if (this.getInternalBridgeUUID(node, AdminConfigManager.getManager().getTunnelBridgeName()) != null) {
             return true;
         } else {
@@ -82,61 +84,76 @@ public class InternalNetworkManager {
         }
     }
 
-    public Status createInternalNetworkForOverlay(Node node) throws Exception {
-        if (!isInternalNetworkNeutronReady(node)) {
-            logger.error("Integration Bridge is not available in Node {}", node);
-            return new Status(StatusCode.NOTACCEPTABLE, "Integration Bridge is not avaialble in Node " + node);
-        }
-        if (isInternalNetworkOverlayReady(node)) {
-            logger.error("Network Overlay Bridge is already present in Node {}", node);
-            return new Status(StatusCode.NOTACCEPTABLE, "Network Overlay Bridge is already present in Node " + node);
-        }
+    /*
+     * Lets create these if not already present :
+     *
+       Bridge br-int
+            Port patch-tun
+                Interface patch-tun
+                    type: patch
+                    options: {peer=patch-int}
+            Port br-int
+                Interface br-int
+                    type: internal
+      Bridge br-tun
+            Port patch-int
+                Interface patch-int
+                    type: patch
+                    options: {peer=patch-tun}
+            Port br-tun
+                Interface br-tun
+                    type: internal
+     */
+    public void createInternalNetworkForOverlay(Node node) throws Exception {
+        String brTun = AdminConfigManager.getManager().getTunnelBridgeName();
+        String brInt = AdminConfigManager.getManager().getIntegrationBridgeName();
+        String patchInt = AdminConfigManager.getManager().getPatchToIntegration();
+        String patchTun = AdminConfigManager.getManager().getPatchToTunnel();
 
-        /*
-         * Lets create this :
-         *
-         * Bridge br-tun
-                Port patch-int
-                    Interface patch-int
-                        type: patch
-                        options: {peer=patch-tun}
-                Port br-tun
-                    Interface br-tun
-                        type: internal
-         */
+        Status status = this.addInternalBridge(node, brInt, patchTun, patchInt);
+        if (!status.isSuccess()) logger.debug("Integration Bridge Creation Status : "+status.toString());
+        status = this.addInternalBridge(node, brTun, patchInt, patchTun);
+        if (!status.isSuccess()) logger.debug("Tunnel Bridge Creation Status : "+status.toString());
+    }
+
+    /*
+     * Lets create these if not already present :
+     *
+       Bridge br-int
+            Port br-int
+                Interface br-int
+                    type: internal
+     */
+    public void createInternalNetworkForNeutron(Node node) throws Exception {
+        String brInt = AdminConfigManager.getManager().getIntegrationBridgeName();
+
+        Status status = this.addInternalBridge(node, brInt, null, null);
+        if (!status.isSuccess()) logger.debug("Integration Bridge Creation Status : "+status.toString());
+    }
 
+    private Status addInternalBridge (Node node, String bridgeName, String localPathName, String remotePatchName) throws Exception {
         OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
-        Bridge brTun = new Bridge();
-        brTun.setName(AdminConfigManager.getManager().getTunnelBridgeName());
-        // Create br-tun bridge
-        StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, Bridge.NAME.getName(), null, brTun);
-        if (!statusWithUuid.isSuccess()) return statusWithUuid;
-        String bridgeUUID = statusWithUuid.getUuid().toString();
 
-        // Set OF Controller
+        String bridgeUUID = this.getInternalBridgeUUID(node, bridgeName);
+        if (bridgeUUID == null) {
+            Bridge bridge = new Bridge();
+            bridge.setName(bridgeName);
+
+            StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, Bridge.NAME.getName(), null, bridge);
+            if (!statusWithUuid.isSuccess()) return statusWithUuid;
+            bridgeUUID = statusWithUuid.getUuid().toString();
+            Port port = new Port();
+            port.setName(bridgeName);
+            ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, port);
+        }
+
         IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
         connectionService.setOFController(node, bridgeUUID);
 
-        Port port = new Port();
-        port.setName(brTun.getName());
-        statusWithUuid = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, port);
-
-        String patchInt = AdminConfigManager.getManager().getPatchToIntegration();
-        String patchTun = AdminConfigManager.getManager().getPatchToTunnel();
-
-        Status status = addPatchPort(node, bridgeUUID, patchInt, patchTun);
-        if (!status.isSuccess()) return status;
-
-        // Create the corresponding patch-tun port in br-int
-        Map<String, Table<?>> bridges = ovsdbTable.getRows(node, Bridge.NAME.getName());
-        for (String brIntUUID : bridges.keySet()) {
-            Bridge brInt = (Bridge) bridges.get(brIntUUID);
-            if (brInt.getName().equalsIgnoreCase(AdminConfigManager.getManager().getIntegrationBridgeName())) {
-                return addPatchPort(node, brIntUUID, patchTun, patchInt);
-            }
+        if (localPathName != null && remotePatchName != null) {
+            return addPatchPort(node, bridgeUUID, localPathName, remotePatchName);
         }
-
-        return status;
+        return new Status(StatusCode.SUCCESS);
     }
 
     private Status addPatchPort (Node node, String bridgeUUID, String portName, String patchName) throws Exception {
@@ -144,7 +161,7 @@ public class InternalNetworkManager {
 
         Port patchPort = new Port();
         patchPort.setName(portName);
-        // Create patch-int port and interface
+        // Create patch port and interface
         StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, patchPort);
         if (!statusWithUuid.isSuccess()) return statusWithUuid;
 
@@ -183,18 +200,13 @@ public class InternalNetworkManager {
                 network.getProviderNetworkType().equalsIgnoreCase("vlan")) {
 
             try {
-                if (!this.isInternalNetworkOverlayReady(node)) {
-                    this.createInternalNetworkForOverlay(node);
-                }
+                this.createInternalNetworkForOverlay(node);
             } catch (Exception e) {
                 logger.error("Failed to create internal network for overlay on node " + node, e);
             }
         } else {
             try {
-                if (!this.isInternalNetworkNeutronReady(node)) {
-                    // TODO : FILL IN
-                    // this.createInternalNetworkForNeutron(node);
-                }
+                this.createInternalNetworkForNeutron(node);
             } catch (Exception e) {
                 logger.error("Failed to create internal network for overlay on node " + node, e);
             }
@@ -293,8 +305,4 @@ public class InternalNetworkManager {
             prepareInternalNetwork(network, node);
         }
     }
-
-    public static List safe( List other ) {
-        return other == null ? Collections.EMPTY_LIST : other;
-    }
 }
index 1557ccd5c5f9da951763d211627524eb822d040d..c6435e11237ae80a0ac7396fdddf5f417d021ff9 100644 (file)
@@ -145,7 +145,7 @@ public class SouthboundHandler extends BaseHandler implements OVSDBInventoryList
         if (action == SouthboundEvent.Action.DELETE) return;
 
         if (Interface.NAME.getName().equalsIgnoreCase(tableName)) {
-            logger.debug("trace {} Added / Updated {} , {}, {}", tableName, node, uuid, row);
+            logger.debug("{} Added / Updated {} , {}, {}", tableName, node, uuid, row);
             Interface intf = (Interface)row;
             NeutronNetwork network = TenantNetworkManager.getManager().getTenantNetworkForInterface(intf);
             if (network != null) {
@@ -159,7 +159,7 @@ public class SouthboundHandler extends BaseHandler implements OVSDBInventoryList
                 this.createTunnels(node, uuid, intf);
             }
         } else if (Port.NAME.getName().equalsIgnoreCase(tableName)) {
-            logger.debug("trace {} Added / Updated {} , {}, {}", tableName, node, uuid, row);
+            logger.debug("{} Added / Updated {} , {}, {}", tableName, node, uuid, row);
             Port port = (Port)row;
             Set<UUID> interfaceUUIDs = port.getInterfaces();
             for (UUID intfUUID : interfaceUUIDs) {
@@ -175,7 +175,7 @@ public class SouthboundHandler extends BaseHandler implements OVSDBInventoryList
                 }
             }
         } else if (Open_vSwitch.NAME.getName().equalsIgnoreCase(tableName)) {
-            logger.debug("trace {} Added / Updated {} , {}, {}", tableName, node, uuid, row);
+            logger.debug("{} Added / Updated {} , {}, {}", tableName, node, uuid, row);
             AdminConfigManager.getManager().populateTunnelEndpoint(node);
             try {
                 Map<String, Table<?>> interfaces = this.ovsdbConfigService.getRows(node, Interface.NAME.getName());
index 7ac789ae5b3860ac6d95f5fca635417a5f391cb6..d36aea97ed2dc82d315602ea370276c5e5b6fb95 100644 (file)
@@ -52,13 +52,8 @@ class OF10ProviderManager extends ProviderNetworkManager {
             return new Status(StatusCode.NOTFOUND, "Tunnel Endpoint not configured for "+ node);
         }
 
-        try {
-            if (!InternalNetworkManager.getManager().isInternalNetworkOverlayReady(node)) {
-                logger.error(node+" is not Overlay ready");
-                return new Status(StatusCode.NOTACCEPTABLE, node+" is not Overlay ready");
-            }
-        } catch (Exception e) {
-            logger.error(node+" is not Overlay ready due to exception", e);
+        if (!InternalNetworkManager.getManager().isInternalNetworkOverlayReady(node)) {
+            logger.error(node+" is not Overlay ready");
             return new Status(StatusCode.NOTACCEPTABLE, node+" is not Overlay ready");
         }