added addPort(), interface and junit for provisioning ports to bridges. 12/712/1
authorBrent.Salisbury <brent.salisbury@gmail.com>
Fri, 26 Jul 2013 20:55:51 +0000 (16:55 -0400)
committerBrent.Salisbury <brent.salisbury@gmail.com>
Fri, 26 Jul 2013 20:55:51 +0000 (16: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/OvsdbTestAddBridge.java

index eebb67a2b6f32895b3473462309edd935f4fa53f..a7035867d8cd5ce34b5ecb096f7bce1cecaf19f3 100755 (executable)
@@ -57,6 +57,12 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
         }
     }
 
+    /**
+     * Add a new bridge
+     * @param node Node serving this configuration service
+     * @param bridgeConnectorIdentifier String representation of a Bridge Connector
+     * @return Bridge Connector configurations
+     */
     @Override
     @SuppressWarnings("unchecked")
     public boolean createBridgeDomain(Node node, String bridgeIdentifier) throws Throwable{
@@ -220,6 +226,99 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
         // TODO Auto-generated method stub
         return null;
     }
+    /**
+     * Create a Bridge Domain
+     *
+     * @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
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean addPort(Node node, String bridgeIdentifier, String portIdentifier) 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 newBridge = "new_bridge";
+                String newInterface = "new_interface";
+                String newPort = "new_port";
+                String newSwitch = "new_switch";
+                /**
+                 * bridge_uuid is temporary until we get the Bridge table _uuid
+                 *  returned the value of the bridge is located in the 
+                 *  output from ovsdb-client dump tcp:172.16.58.170:6634
+                 *  Replace the one below with that value of the disired bridge.
+                 */
+                String bridge_uuid = "2636c43a-4eb7-4ef0-ab7a-1a95113e05e6";
+
+                Object addSwitchRequest;
+
+                OVSInstance instance = new OVSInstance();
+                instance.monitorOVS(connection);
+
+                if(instance.getUuid() != null){
+                    List<String> bridgeUuidPair = new ArrayList<String>();
+                    bridgeUuidPair.add("named-uuid");
+                    bridgeUuidPair.add(newBridge);
+
+                    List<Object> mutation = new ArrayList<Object>();
+                    mutation.add("ports");
+                    mutation.add("insert");
+                    mutation.add(bridgeUuidPair);
+                    List<Object> mutations = new ArrayList<Object>();
+                    mutations.add(mutation);
+
+                    List<String> ovsUuidPair = new ArrayList<String>();
+                    ovsUuidPair.add("uuid");
+                    ovsUuidPair.add(bridge_uuid);
+
+                    List<Object> whereInner = new ArrayList<Object>();
+                    whereInner.add("_uuid");
+                    whereInner.add("==");
+                    whereInner.add(ovsUuidPair);
+
+                    List<Object> where = new ArrayList<Object>();
+                    where.add(whereInner);
+
+                    addSwitchRequest = new MutateRequest("Bridge", where, mutations);
+                }
+                else{
+                    Map<String, Object> vswitchRow = new HashMap<String, Object>();
+                    ArrayList<String> bridges = new ArrayList<String>();
+                    bridges.add("named-uuid");
+                    bridges.add(newBridge);
+                    vswitchRow.put("bridges", bridges);
+                    addSwitchRequest = new InsertRequest("insert", "Open_vSwitch", newSwitch, vswitchRow);
+                }
+
+                Map<String, Object> portRow = new HashMap<String, Object>();
+                portRow.put("name", portIdentifier);
+                ArrayList<String> interfaces = new ArrayList<String>();
+                interfaces.add("named-uuid");
+                interfaces.add(newInterface);
+                portRow.put("interfaces", interfaces);
+                InsertRequest addPortRequest = new InsertRequest("insert", "Port", newBridge, portRow);
+
+                Map<String, Object> interfaceRow = new HashMap<String, Object>();
+                interfaceRow.put("name", portIdentifier);
+                InsertRequest addIntfRequest = new InsertRequest("insert", "Interface", newInterface, interfaceRow);
+
+                Object[] params = {"Open_vSwitch", addSwitchRequest, addIntfRequest, addPortRequest};
+                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) {
index a2b1b8c42b0ffa7522a4f27ad1ce778a306bb8e8..69ce6d621a4b44a31662b2be95c2b5bdc244664d 100755 (executable)
@@ -123,6 +123,15 @@ public interface IPluginInNetworkConfigurationService {
      * @return Bridge Connector configurations
      */
     public Map <String, String> getBridgeConnectorConfigs(Node node, String bridgeConnectorIdentifier);
+    
+    /**
+     * Create a Bridge Domain
+     *
+     * @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
+     */
+       public boolean addPort(Node node, String bridgeIdentifier, String portIdentifier) throws Throwable;
 
     /**
      * Generic Configuration Event/Command. It is not practically possible to define all the possible combinations
index 13c42d08bad097599552a19784f44deedbea6d74..4cbae3f228b5573e92ad332999025b4977d41842 100755 (executable)
@@ -26,7 +26,7 @@ public class OvsdbTestAddBridge {
         connectionService.init();\r
         String identifier = "TEST";\r
         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();\r
-        params.put(ConnectionConstants.ADDRESS, "192.168.56.101");\r
+        params.put(ConnectionConstants.ADDRESS, "172.16.58.170");\r
 \r
         Node node = connectionService.connect(identifier, params);\r
         if(node == null){\r