Added OVS tunnel support to create a GRE, VXLAN or Capwap encapsulated dplane tunnel... 18/718/1
authorBrent.Salisbury <brent.salisbury@gmail.com>
Sat, 27 Jul 2013 09:36:05 +0000 (05:36 -0400)
committerBrent.Salisbury <brent.salisbury@gmail.com>
Sat, 27 Jul 2013 09:36:05 +0000 (05:36 -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/internal/Encapsulation.java [new file with mode: 0644]
ovsdb/src/main/java/org/opendaylight/ovsdb/sal/configuration/IPluginInNetworkConfigurationService.java
ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddTunnel.java [new file with mode: 0644]

index 6a307f8b7aef7098ea22e584e0c3fae609cd23ff..ee6c0a48d63f34334757b943a45dc8320b6298c4 100755 (executable)
@@ -303,6 +303,95 @@ public class ConfigurationService implements IPluginInNetworkConfigurationServic
         }
         return true;
     }
+    /**
+     * 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 addTunnel(Node node, String bridgeIdentifier,
+        String portidentifier, String tunnelendpoint, String tunencap)
+                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);
+                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);
+                interfaceRow.put("type", tunencap);
+                ArrayList intopt = new ArrayList<String>();
+                interfaceRow.put("options", intopt);
+                ArrayList intoptmap = new ArrayList<String>();
+                ArrayList<String> intoptep = new ArrayList<String>();
+                intopt.add("map");
+                intopt.add(intoptmap);
+                intoptmap.add(intoptep);
+                intoptep.add("remote_ip");
+                intoptep.add(tunnelendpoint);
+
+                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;
+    }
 
     @Override
     public Object genericConfigurationEvent(Node node, Map<String, String> config) {
diff --git a/ovsdb/src/main/java/org/opendaylight/ovsdb/internal/Encapsulation.java b/ovsdb/src/main/java/org/opendaylight/ovsdb/internal/Encapsulation.java
new file mode 100644 (file)
index 0000000..72b7a71
--- /dev/null
@@ -0,0 +1,21 @@
+package org.opendaylight.ovsdb.internal;
+
+public enum Encapsulation {
+
+    VXLAN("vxlan"), GRE("gre"), CAPWAP("capwap");
+
+    private final String value;
+
+    private Encapsulation(final String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    @Override
+    public String toString() {
+        return getValue();
+    }
+}
index 3dacbc308d994ff806dcb5dc4312fca518dbd47e..46350f367d338dd8d4a86ea4cf1acc4f8a30a219 100755 (executable)
@@ -133,6 +133,19 @@ public interface IPluginInNetworkConfigurationService {
      */
     public boolean addPort(Node node, String bridgeIdentifier, String portIdentifier) throws Throwable;
 
+    /**
+     * 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.
+     */
+    public boolean addTunnel(Node node, String bridgeIdentifier, String portIdentifier,
+            String TunnelEndPoint, String TunEncap) 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/OvsdbTestAddTunnel.java b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddTunnel.java
new file mode 100644 (file)
index 0000000..dc2e21c
--- /dev/null
@@ -0,0 +1,61 @@
+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;
+import org.opendaylight.ovsdb.internal.*;
+import org.opendaylight.ovsdb.sal.connection.ConnectionConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.opendaylight.ovsdb.internal.Encapsulation;
+
+public class OvsdbTestAddTunnel {
+    private static final Logger logger = LoggerFactory
+            .getLogger(OvsdbTestAddTunnel.class);
+
+    @Test
+    public void addTunnel() throws Throwable{
+        Node.NodeIDType.registerIDType("OVS", String.class);
+        NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
+
+        ConnectionService connectionService = new ConnectionService();
+        connectionService.init();
+
+        String identifier = "TEST";
+        /**
+         * tunnelendpoint IP address of the
+         * destination Tunnel Endpoint.
+         * tunencap is the tunnel encapsulation
+         * options being (CAPWAP, GRE, VXLAN).
+         */
+        Encapsulation encap = Encapsulation.VXLAN;
+        String tunencap = encap.toString();
+        String tunnelendpoint = "192.168.100.100";
+
+        Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
+        params.put(ConnectionConstants.ADDRESS, "172.16.58.170");
+
+        Node node = connectionService.connect(identifier, params);
+        if(node == null){
+            logger.error("Could not connect to ovsdb server");
+            return;
+        }
+        /**
+         * Create an Encapsulated Tunnel Interface and destination Tunnel Endpoint
+         * @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.
+         */
+        ConfigurationService configurationService = new ConfigurationService();
+        configurationService.setConnectionServiceInternal(connectionService);
+        configurationService.addTunnel(node, "JunitBridge",
+                "tunnel0", tunnelendpoint, tunencap);
+    }
+}
\ No newline at end of file