aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/ovsdb
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/ovsdb')
-rw-r--r--framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java28
-rw-r--r--framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java92
-rw-r--r--framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java11
-rw-r--r--framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/Row.java2
4 files changed, 131 insertions, 2 deletions
diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
index f2ff0709..e619f8e0 100644
--- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
+++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
@@ -28,6 +28,7 @@ import org.onosproject.ovsdb.rfc.operations.Operation;
import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
import java.util.List;
+import java.util.Map;
import java.util.Set;
/**
@@ -50,6 +51,17 @@ public interface OvsdbClientService extends OvsdbRPC {
void createTunnel(IpAddress srcIp, IpAddress dstIp);
/**
+ * Creates a tunnel port with given options.
+ *
+ * @param bridgeName bridge name
+ * @param portName port name
+ * @param tunnelType tunnel type
+ * @param options tunnel options
+ * @return true if tunnel creation is successful, false otherwise
+ */
+ boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options);
+
+ /**
* Drops the configuration for the tunnel.
*
* @param srcIp source IP address
@@ -72,6 +84,17 @@ public interface OvsdbClientService extends OvsdbRPC {
void createBridge(String bridgeName);
/**
+ * Creates a bridge with given name and dpid.
+ * Sets the bridge's controller with given controllers.
+ *
+ * @param bridgeName bridge name
+ * @param dpid data path id
+ * @param controllers controllers
+ * @return true if bridge creation is successful, false otherwise
+ */
+ boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers);
+
+ /**
* Drops a bridge.
*
* @param bridgeName bridge name
@@ -88,13 +111,14 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets controllers of the node.
*
+ * @param openflowDeviceId target device id
* @return set of controllers; empty if no controller is find
*/
Set<ControllerInfo> getControllers(DeviceId openflowDeviceId);
/**
* Sets the Controllers for the specified bridge.
- * <p/>
+ * <p>
* This method will replace the existing controller list with the new controller
* list.
*
@@ -105,7 +129,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Sets the Controllers for the specified device.
- * <p/>
+ * <p>
* This method will replace the existing controller list with the new controller
* list.
*
diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
index 3a84d000..2575a256 100644
--- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
+++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
@@ -73,6 +73,8 @@ import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -481,6 +483,52 @@ public class DefaultOvsdbClient
log.info("Create bridge success");
}
+ @Override
+ public boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers) {
+
+ DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
+ String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME);
+
+ if (dbSchema == null || ovsUuid == null) {
+ log.warn("Couldn't find database Open_vSwitch");
+ return false;
+ }
+
+ String bridgeUuid = getBridgeUuid(bridgeName);
+ if (bridgeUuid != null) {
+ log.warn("Bridge {} is already exist", bridgeName);
+ // remove existing one and re-create?
+ return false;
+ }
+
+ Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE);
+ bridge.setName(bridgeName);
+
+ Set<String> failMode = new HashSet<>(Arrays.asList("secure"));
+ bridge.setFailMode(failMode);
+
+ Set<String> protocols = new HashSet<>(Arrays.asList(OvsdbConstant.OPENFLOW13));
+ bridge.setProtocols(protocols);
+
+ Map<String, String> options = new HashMap<>();
+ options.put("datapath-id", dpid);
+ bridge.setOtherConfig(options);
+
+ bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid",
+ OvsdbConstant.DATABASENAME, "bridges",
+ ovsUuid, bridge.getRow());
+
+ if (bridgeUuid != null) {
+ createPort(bridgeName, bridgeName);
+ } else {
+ log.warn("Failed to create bridge {} on {}", bridgeName, nodeId.toString());
+ return false;
+ }
+
+ setControllersWithUUID(UUID.uuid(bridgeUuid), controllers);
+ return true;
+ }
+
/**
* Sets the bridge's controller automatically.
* <p/>
@@ -648,6 +696,50 @@ public class DefaultOvsdbClient
}
@Override
+ public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options) {
+
+ String bridgeUuid = getBridgeUuid(bridgeName);
+ if (bridgeUuid == null) {
+ log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress());
+ return false;
+ }
+
+ if (getPortUuid(portName, bridgeUuid) != null) {
+ log.warn("Port {} already exists", portName);
+ // remove existing one and re-create?
+ return false;
+ }
+
+ ArrayList<Operation> operations = Lists.newArrayList();
+ DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
+
+ // insert a new port to the port table
+ Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT);
+ port.setName(portName);
+ Insert portInsert = new Insert(dbSchema.getTableSchema("Port"), "Port", port.getRow());
+ portInsert.getRow().put("interfaces", UUID.uuid("Interface"));
+ operations.add(portInsert);
+
+ // update the bridge table
+ Condition condition = ConditionUtil.equals("_uuid", UUID.uuid(bridgeUuid));
+ Mutation mutation = MutationUtil.insert("ports", UUID.uuid("Port"));
+ List<Condition> conditions = new ArrayList<>(Arrays.asList(condition));
+ List<Mutation> mutations = new ArrayList<>(Arrays.asList(mutation));
+ operations.add(new Mutate(dbSchema.getTableSchema("Bridge"), conditions, mutations));
+
+ // insert a tunnel interface
+ Interface intf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE);
+ intf.setName(portName);
+ intf.setType(tunnelType);
+ intf.setOptions(options);
+ Insert intfInsert = new Insert(dbSchema.getTableSchema("Interface"), "Interface", intf.getRow());
+ operations.add(intfInsert);
+
+ transactConfig(OvsdbConstant.DATABASENAME, operations);
+ return true;
+ }
+
+ @Override
public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
String bridgeName = OvsdbConstant.INTEGRATION_BRIDGE;
String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp);
diff --git a/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java b/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
index 71fee4fe..2c418d57 100644
--- a/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
+++ b/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
@@ -34,6 +34,7 @@ import org.onosproject.ovsdb.rfc.operations.Operation;
import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
import java.util.List;
+import java.util.Map;
import java.util.Set;
/**
@@ -52,6 +53,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService {
}
@Override
+ public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options) {
+ return true;
+ }
+
+ @Override
public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
}
@@ -67,6 +73,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService {
}
@Override
+ public boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers) {
+ return true;
+ }
+
+ @Override
public void dropBridge(String bridgeName) {
}
diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/Row.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/Row.java
index 00609602..09088766 100644
--- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/Row.java
+++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/Row.java
@@ -43,6 +43,7 @@ public final class Row {
* Row constructor.
*
* @param tableName table name
+ * @deprecated in Emu Release
*/
@Deprecated
private Row(String tableName) {
@@ -56,6 +57,7 @@ public final class Row {
*
* @param tableName table name
* @param columns Map of Column entity
+ * @param uuid UUID of the row
*/
public Row(String tableName, UUID uuid, Map<String, Column> columns) {
checkNotNull(tableName, "table name cannot be null");