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