// 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
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};
}
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")
/**
* 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
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
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
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
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
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){
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
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;
* 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";
}
/**
* 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
*/
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
--- /dev/null
+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