From: Brent.Salisbury Date: Sun, 28 Jul 2013 09:13:31 +0000 (-0400) Subject: Added VLAN tagging support to port creations X-Git-Tag: master-tagforprepareonly-ovsdb-bulk-release-prepare-only-6~95 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=ovsdb.git;a=commitdiff_plain;h=f29dc82619ee6716308cb7395659893619b9a8d2 Added VLAN tagging support to port creations Signed-off-by: Brent.Salisbury --- diff --git a/ovsdb/src/main/java/org/opendaylight/ovsdb/internal/ConfigurationService.java b/ovsdb/src/main/java/org/opendaylight/ovsdb/internal/ConfigurationService.java index abbea96c9..e9cd772e0 100755 --- a/ovsdb/src/main/java/org/opendaylight/ovsdb/internal/ConfigurationService.java +++ b/ovsdb/src/main/java/org/opendaylight/ovsdb/internal/ConfigurationService.java @@ -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 interfaceRow = new HashMap(); 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 existingBridges = OVSBridge.monitorBridge(connection); + + OVSBridge bridge = existingBridges.get(bridgeIdentifier); + + List portUuidPair = new ArrayList(); + portUuidPair.add("named-uuid"); + portUuidPair.add(newPort); + + List mutation = new ArrayList(); + mutation.add("ports"); + mutation.add("insert"); + mutation.add(portUuidPair); + List mutations = new ArrayList(); + mutations.add(mutation); + + List bridgeUuidPair = new ArrayList(); + bridgeUuidPair.add("uuid"); + bridgeUuidPair.add(bridge.getUuid()); + + List whereInner = new ArrayList(); + whereInner.add("_uuid"); + whereInner.add("=="); + whereInner.add(bridgeUuidPair); + + List where = new ArrayList(); + where.add(whereInner); + + MutateRequest mutateBridgeRequest = new MutateRequest("Bridge", where, mutations); + + Map portRow = new HashMap(); + portRow.put("name", portIdentifier); + portRow.put("tag", vlanid); + ArrayList interfaces = new ArrayList(); + interfaces.add("named-uuid"); + interfaces.add(newInterface); + portRow.put("interfaces", interfaces); + InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, portRow); + + Map interfaceRow = new HashMap(); + 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") diff --git a/ovsdb/src/main/java/org/opendaylight/ovsdb/sal/configuration/IPluginInNetworkConfigurationService.java b/ovsdb/src/main/java/org/opendaylight/ovsdb/sal/configuration/IPluginInNetworkConfigurationService.java index 46350f367..a8cf62f3b 100755 --- a/ovsdb/src/main/java/org/opendaylight/ovsdb/sal/configuration/IPluginInNetworkConfigurationService.java +++ b/ovsdb/src/main/java/org/opendaylight/ovsdb/sal/configuration/IPluginInNetworkConfigurationService.java @@ -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 diff --git a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddBridge.java b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddBridge.java index 13c42d08b..d36cf887b 100755 --- a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddBridge.java +++ b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddBridge.java @@ -1,22 +1,20 @@ 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 OvsdbTestAddBridge { private static final Logger logger = LoggerFactory .getLogger(OvsdbTestAddBridge.class); + @Test public void addBridge() throws Throwable{ Node.NodeIDType.registerIDType("OVS", String.class); @@ -26,13 +24,19 @@ public class OvsdbTestAddBridge { connectionService.init(); String identifier = "TEST"; Map params = new HashMap(); - 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){ logger.error("Could not connect to ovsdb server"); return; } + /** + * Create a Bridge Domain + * + * @param node Node serving this configuration service + * @param bridgeDomainIdentifier String representation of a Bridge Domain + */ ConfigurationService configurationService = new ConfigurationService(); configurationService.setConnectionServiceInternal(connectionService); configurationService.createBridgeDomain(node, "JUNIT_BRIDGE_TEST"); diff --git a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddPort.java b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddPort.java index e0c150d97..d7ce714ad 100755 --- a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddPort.java +++ b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddPort.java @@ -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 params = new HashMap(); - 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 diff --git a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddTunnel.java b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddTunnel.java index dc2e21c20..50f1c44ab 100644 --- a/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddTunnel.java +++ b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddTunnel.java @@ -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 index 000000000..e0268e532 --- /dev/null +++ b/ovsdb/src/test/java/org/opendaylight/ovsdb/OvsdbTestAddVlan.java @@ -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 params = new HashMap(); + 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