Implemented ovs manager insert for client access to ovs tables 29/729/1
authorBrent.Salisbury <brent.salisbury@gmail.com>
Mon, 29 Jul 2013 07:55:29 +0000 (03:55 -0400)
committerBrent.Salisbury <brent.salisbury@gmail.com>
Mon, 29 Jul 2013 07:55:29 +0000 (03:55 -0400)
Signed-off-by: Brent.Salisbury <brent.salisbury@gmail.com>
ovsdb/src/main/java/org/opendaylight/ovsdb/internal/ConfigurationService.java
ovsdb/src/main/java/org/opendaylight/ovsdb/sal/configuration/IPluginInNetworkConfigurationService.java
ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestSetManager.java [new file with mode: 0755]

index 87b61a61a785c46f47de0f1af74344edce2c288e..b4ec1c59ffd9cd5cf7e8526aa8de9f4692606b80 100755 (executable)
@@ -328,7 +328,7 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
 
                 Map<String, OVSBridge> existingBridges = OVSBridge.monitorBridge(connection);
 
-                OVSBridge bridge = existingBridges.get(bridgeIdentifier);
+                OVSBridge ovstableid = existingBridges.get(bridgeIdentifier);
 
                 List<String> portUuidPair = new ArrayList<String>();
                 portUuidPair.add("named-uuid");
@@ -343,7 +343,7 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
 
                 List<String> bridgeUuidPair = new ArrayList<String>();
                 bridgeUuidPair.add("uuid");
-                bridgeUuidPair.add(bridge.getUuid());
+                bridgeUuidPair.add(ovstableid.getUuid());
 
                 List<Object> whereInner = new ArrayList<Object>();
                 whereInner.add("_uuid");
@@ -473,10 +473,74 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
         return true;
     }
 
+    /**
+     * Implements the OVS Connection for Managers
+     *
+     * @param node Node serving this configuration service
+     * @param String with IP and connection types
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean setManager(Node node, String managerip) throws Throwable{
+        try{
+            if (connectionService == null) {
+                logger.error("Couldn't refer to the ConnectionService");
+                return false;
+            }
+            Connection connection = connectionService.getConnection(node);
+
+            if (connection != null) {
+                String newmanager = "new_manager";
+
+                OVSInstance instance = OVSInstance.monitorOVS(connection);
+
+                Map ovsoutter = new LinkedHashMap();
+                Map ovsinner = new LinkedHashMap();
+                ArrayList ovsalist1 = new ArrayList();
+                ArrayList ovsalist2 = new ArrayList();
+                ArrayList ovsalist3 = new ArrayList();
+                ArrayList ovsalist4 = new ArrayList();
+
+                //OVS Table Update
+                ovsoutter.put("where", ovsalist1);
+                ovsalist1.add(ovsalist2);
+                ovsalist2.add("_uuid");
+                ovsalist2.add("==");
+                ovsalist2.add(ovsalist3);
+                ovsalist3.add("uuid");
+                ovsalist3.add(instance.getUuid());
+                ovsoutter.put("op", "update");
+                ovsoutter.put("table", "Open_vSwitch");
+                ovsoutter.put("row", ovsinner);
+                ovsinner.put("manager_options", ovsalist4);
+                ovsalist4.add("named-uuid");
+                ovsalist4.add(newmanager);
+
+                Map mgroutside = new LinkedHashMap();
+                Map mgrinside = new LinkedHashMap();
+
+                //Manager Table Insert
+                mgroutside.put("uuid-name", newmanager);
+                mgroutside.put("op", "insert");
+                mgroutside.put("table","Manager");
+                mgroutside.put("row", mgrinside);
+                mgrinside.put("target", managerip);
+
+                Object[] params = {"Open_vSwitch", ovsoutter, mgroutside};
+                OvsdbMessage msg = new OvsdbMessage("transact", params);
+
+                connection.sendMessage(msg);
+                connection.readResponse(Uuid[].class);
+            }
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+        return true;
+    }
+
     @Override
     public Object genericConfigurationEvent(Node node, Map<String, String> config) {
         // TODO Auto-generated method stub
         return null;
     }
-
   }
\ No newline at end of file
index a8cf62f3b902fb093b1ab0e1e3ca55a5d23c8bea..70fe7a5732d77f309eb7b4df78764635d568fe92 100755 (executable)
@@ -159,6 +159,17 @@ public interface IPluginInNetworkConfigurationService {
     public boolean addPortVlan(Node node, String bridgeIdentifier, String portIdentifier,
      int vlanid) throws Throwable;
 
+    /**
+     * Create a Port with a user defined VLAN, and attach it to the specified bridge.
+     *
+     * Ex. ovs-vsctl add-port JUNIT_BRIDGE_TEST Jvlanvif0 tag=100
+     * @param node Node serving this configuration service
+     * @param bridgeDomainIdentifier String representation of a Bridge Domain
+     * @param portIdentifier String representation of a user defined Port Name
+     * @param vlanid Integer note: only one VID is accepted with tag=x method
+     */
+    public boolean setManager(Node node, String managerip) throws Throwable;
+
     /**
      * Generic Configuration Event/Command. It is not practically possible to define all the possible combinations
      * of configurations across various plugins. Hence having a generic event/command will help bridge the gap until
diff --git a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestSetManager.java b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestSetManager.java
new file mode 100755 (executable)
index 0000000..d189475
--- /dev/null
@@ -0,0 +1,47 @@
+package org.opendaylight.ovsdb;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.controller.sal.core.Node;\r
+import org.opendaylight.controller.sal.core.NodeConnector;\r
+import org.opendaylight.ovsdb.internal.ConfigurationService;\r
+import org.opendaylight.ovsdb.internal.ConnectionService;\r
+import org.opendaylight.ovsdb.sal.connection.ConnectionConstants;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+public class OvsdbTestSetManager {\r
+    private static final Logger logger = LoggerFactory\r
+            .getLogger(OvsdbTestSetManager.class);\r
+\r
+    @Test\r
+    public void setManager() throws Throwable{\r
+        Node.NodeIDType.registerIDType("OVS", String.class);\r
+        NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");\r
+\r
+        ConnectionService connectionService = new ConnectionService();\r
+        connectionService.init();\r
+        String identifier = "TEST";\r
+        Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();\r
+        params.put(ConnectionConstants.ADDRESS, "172.16.58.128");\r
+\r
+        Node node = connectionService.connect(identifier, params);\r
+        if(node == null){\r
+            logger.error("Could not connect to ovsdb server");\r
+            return;\r
+        }\r
+        /**\r
+         * Implements the OVS Connection for Managers\r
+         *\r
+         * @param node Node serving this configuration service\r
+         * @param String with IP and connection type ex. type:ip:port\r
+         *\r
+         */\r
+        ConfigurationService configurationService = new ConfigurationService();\r
+        configurationService.setConnectionServiceInternal(connectionService);\r
+        configurationService.setManager(node, "ptcp:6634:172.16.58.128");\r
+    }\r
+\r
+}\r