Added VLAN tagging support to port creations 21/721/1
authorBrent.Salisbury <brent.salisbury@gmail.com>
Sun, 28 Jul 2013 09:13:31 +0000 (05:13 -0400)
committerBrent.Salisbury <brent.salisbury@gmail.com>
Sun, 28 Jul 2013 09:13:31 +0000 (05:13 -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
ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddPort.java
ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddTunnel.java
ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddVlan.java [new file with mode: 0644]

index abbea96c9777aba7b8550ac033c937e41b7625d3..e9cd772e0c4eda67b29f3f4acfe5c543d4a771c8 100755 (executable)
@@ -227,9 +227,10 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
         // TODO Auto-generated method stub
         return null;
     }
+
     /**
-     * Create a Bridge Domain
-     *
+     * Create a Port Attached to a Bridge
+     * Ex. ovs-vsctl add-port br0 vif0
      * @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
@@ -289,7 +290,6 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
 
                 Map<String, Object> interfaceRow = new HashMap<String, Object>();
                 interfaceRow.put("name", portIdentifier);
-                interfaceRow.put("type", "internal");
                 InsertRequest addIntfRequest = new InsertRequest("insert", "Interface", newInterface, interfaceRow);
 
                 Object[] params = {"Open_vSwitch", mutateBridgeRequest, addIntfRequest, addPortRequest};
@@ -303,12 +303,93 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
         }
         return true;
     }
+
     /**
-     * Create a Bridge Domain
-     *
+     * Create a Port with a VLAN Tag and it to a Bridge
+     * Ex. ovs-vsctl add-port br0 vxlan1 -- set interface vxlan1 type=vxlan options:remote_ip=192.168.1.11
+     * @param node Node serving this configuration service
+     * @param portIdentifier String representation of a user defined Port Name
+     * @param vlanid integer representing the VLAN Tag
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean addPortVlan(Node node, String bridgeIdentifier, String portIdentifier, int vlanid) 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";
+
+                Map<String, OVSBridge> existingBridges = OVSBridge.monitorBridge(connection);
+
+                OVSBridge bridge = existingBridges.get(bridgeIdentifier);
+
+                List<String> portUuidPair = new ArrayList<String>();
+                portUuidPair.add("named-uuid");
+                portUuidPair.add(newPort);
+
+                List<Object> mutation = new ArrayList<Object>();
+                mutation.add("ports");
+                mutation.add("insert");
+                mutation.add(portUuidPair);
+                List<Object> mutations = new ArrayList<Object>();
+                mutations.add(mutation);
+
+                List<String> bridgeUuidPair = new ArrayList<String>();
+                bridgeUuidPair.add("uuid");
+                bridgeUuidPair.add(bridge.getUuid());
+
+                List<Object> whereInner = new ArrayList<Object>();
+                whereInner.add("_uuid");
+                whereInner.add("==");
+                whereInner.add(bridgeUuidPair);
+
+                List<Object> where = new ArrayList<Object>();
+                where.add(whereInner);
+
+                MutateRequest mutateBridgeRequest = new MutateRequest("Bridge", where, mutations);
+
+                Map<String, Object> portRow = new HashMap<String, Object>();
+                portRow.put("name", portIdentifier);
+                portRow.put("tag", vlanid);
+                ArrayList<String> interfaces = new ArrayList<String>();
+                interfaces.add("named-uuid");
+                interfaces.add(newInterface);
+                portRow.put("interfaces", interfaces);
+                InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, 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", mutateBridgeRequest, addIntfRequest, addPortRequest};
+                OvsdbMessage msg = new OvsdbMessage("transact", params);
+
+                connection.sendMessage(msg);
+                connection.readResponse(Uuid[].class);
+            }
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+        return true;
+    }
+
+    /**
+     * Create an Encapsulated Tunnel Interface and destination Tunnel Endpoint
+     * Ex. ovs-vsctl add-port br0 vxlan1 -- set interface vxlan1 type=vxlan options:remote_ip=192.168.1.11
      * @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 tunnelendpoint IP address of the destination Tunnel Endpoint
+     * @param tunencap is the tunnel encapsulation options being CAPWAP, GRE or VXLAN
+     * The Bridge must already be defined before calling addTunnel.
      */
     @Override
     @SuppressWarnings("unchecked")
index 46350f367d338dd8d4a86ea4cf1acc4f8a30a219..a8cf62f3b902fb093b1ab0e1e3ca55a5d23c8bea 100755 (executable)
@@ -135,6 +135,7 @@ public interface IPluginInNetworkConfigurationService {
 
     /**
      * Create an Encapsulated Tunnel Interface and destination Tunnel Endpoint
+     *
      * Ex. ovs-vsctl add-port br0 vxlan1 -- set interface vxlan1 type=vxlan options:remote_ip=192.168.1.11
      * @param node Node serving this configuration service
      * @param bridgeDomainIdentifier String representation of a Bridge Domain
@@ -146,6 +147,18 @@ public interface IPluginInNetworkConfigurationService {
     public boolean addTunnel(Node node, String bridgeIdentifier, String portIdentifier,
             String TunnelEndPoint, String TunEncap) 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 addPortVlan(Node node, String bridgeIdentifier, String portIdentifier,
+     int vlanid) 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
index 13c42d08bad097599552a19784f44deedbea6d74..d36cf887b2af5ea005981dc6a3d27fbb61604168 100755 (executable)
@@ -1,22 +1,20 @@
 package org.opendaylight.ovsdb;\r
 \r
-import java.net.InetAddress;\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.Map;\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.database.Uuid;\r
-import org.opendaylight.ovsdb.internal.*;\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
+import java.util.HashMap;\r
+import java.util.Map;\r
 \r
 public class OvsdbTestAddBridge {\r
     private static final Logger logger = LoggerFactory\r
             .getLogger(OvsdbTestAddBridge.class);\r
+\r
     @Test\r
     public void addBridge() throws Throwable{\r
         Node.NodeIDType.registerIDType("OVS", String.class);\r
@@ -26,13 +24,19 @@ 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
             logger.error("Could not connect to ovsdb server");\r
             return;\r
         }\r
+        /**\r
+         * Create a Bridge Domain\r
+         *\r
+         * @param node Node serving this configuration service\r
+         * @param bridgeDomainIdentifier String representation of a Bridge Domain\r
+         */\r
         ConfigurationService configurationService = new ConfigurationService();\r
         configurationService.setConnectionServiceInternal(connectionService);\r
         configurationService.createBridgeDomain(node, "JUNIT_BRIDGE_TEST");\r
index e0c150d9708cca2cd7aa06efb92985c40d070d89..d7ce714ad76a690c969e191f8e1b4d7811cf9347 100755 (executable)
@@ -1,18 +1,15 @@
 package org.opendaylight.ovsdb;
 
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.junit.Test;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.ovsdb.database.Uuid;
-import org.opendaylight.ovsdb.internal.*;
+import org.opendaylight.ovsdb.internal.ConfigurationService;
+import org.opendaylight.ovsdb.internal.ConnectionService;
 import org.opendaylight.ovsdb.sal.connection.ConnectionConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+import java.util.Map;
 
 public class OvsdbTestAddPort {
     private static final Logger logger = LoggerFactory
@@ -27,7 +24,7 @@ public class OvsdbTestAddPort {
         connectionService.init();
         String identifier = "TEST";
         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
-        params.put(ConnectionConstants.ADDRESS, "192.168.56.101");
+        params.put(ConnectionConstants.ADDRESS, "172.16.58.170");
 
         Node node = connectionService.connect(identifier, params);
         if(node == null){
@@ -35,14 +32,14 @@ public class OvsdbTestAddPort {
             return;
         }
         /**
-         * Create a Bridge Domain
+         * Create a Port and attach it to a Bridge
+         * Ex. ovs-vsctl add-port br0 vif0
          * @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
-         * Temporarily add the bridge table _uuid to bridge_uuid in ConfigurationService
          */
         ConfigurationService configurationService = new ConfigurationService();
         configurationService.setConnectionServiceInternal(connectionService);
-        configurationService.addPort(node, "JUNIT_BRIDGE_TEST", "Jnic1");
+        configurationService.addPort(node, "JUNIT_BRIDGE_TEST", "Jvif0");
     }
 }
\ No newline at end of file
index dc2e21c2075ac02c9c6280bfd9d467d1083404c5..50f1c44ab627004dfd542825a8780ad75a8fcc4c 100644 (file)
@@ -3,7 +3,6 @@ package org.opendaylight.ovsdb;
 
 import java.util.HashMap;
 import java.util.Map;
-
 import org.junit.Test;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -31,7 +30,11 @@ public class OvsdbTestAddTunnel {
          * destination Tunnel Endpoint.
          * tunencap is the tunnel encapsulation
          * options being (CAPWAP, GRE, VXLAN).
+         * Use the following lines to test GRE and CAPWAP
+         * Encapsulation encap = Encapsulation.GRE;
+         * Encapsulation encap = Encapsulation.CAPWAP;
          */
+
         Encapsulation encap = Encapsulation.VXLAN;
         String tunencap = encap.toString();
         String tunnelendpoint = "192.168.100.100";
@@ -46,6 +49,9 @@ public class OvsdbTestAddTunnel {
         }
         /**
          * Create an Encapsulated Tunnel Interface and destination Tunnel Endpoint
+         *
+         * Ex. ovs-vsctl add-port br0 vxlan1 (cont)
+         * -- set interface vxlan1 type=vxlan options:remote_ip=192.168.1.11
          * @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
@@ -55,7 +61,8 @@ public class OvsdbTestAddTunnel {
          */
         ConfigurationService configurationService = new ConfigurationService();
         configurationService.setConnectionServiceInternal(connectionService);
-        configurationService.addTunnel(node, "JunitBridge",
-                "tunnel0", tunnelendpoint, tunencap);
+        configurationService.addTunnel(node, "JUNIT_BRIDGE_TEST",
+                "Jtunnel0", tunnelendpoint, tunencap);
+
     }
 }
\ No newline at end of file
diff --git a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddVlan.java b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddVlan.java
new file mode 100644 (file)
index 0000000..e0268e5
--- /dev/null
@@ -0,0 +1,48 @@
+package org.opendaylight.ovsdb;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.ovsdb.internal.ConfigurationService;
+import org.opendaylight.ovsdb.internal.ConnectionService;
+import org.opendaylight.ovsdb.sal.connection.ConnectionConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+import java.util.Map;
+
+public class OvsdbTestAddVlan {
+    private static final Logger logger = LoggerFactory
+            .getLogger(OvsdbTestAddVlan.class);
+
+    @Test
+    public void addPortVlan() throws Throwable{
+        Node.NodeIDType.registerIDType("OVS", String.class);
+        NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
+
+        ConnectionService connectionService = new ConnectionService();
+        connectionService.init();
+        String identifier = "TEST";
+        Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
+        params.put(ConnectionConstants.ADDRESS, "172.16.58.170");
+        int vlanid = 100;
+
+        Node node = connectionService.connect(identifier, params);
+        if(node == null){
+            logger.error("Could not connect to ovsdb server");
+            return;
+        }
+        /**
+         * 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
+         */
+        ConfigurationService configurationService = new ConfigurationService();
+        configurationService.setConnectionServiceInternal(connectionService);
+        configurationService.addPortVlan(node, "JUNIT_BRIDGE_TEST", "Jtagvif0", vlanid);
+    }
+}
\ No newline at end of file