From e9bb60be43af477f17b30ee1f2ba205565b7fa15 Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Mon, 19 Oct 2015 10:14:31 -0700 Subject: Updated onos src tree to commit id 1e60f97ae50c05b94fcb6a10520738bfb5efdfd1 --- .../ovsdb/controller/OvsdbClientService.java | 28 ++++++- .../controller/driver/DefaultOvsdbClient.java | 92 ++++++++++++++++++++++ .../driver/OvsdbClientServiceAdapter.java | 11 +++ .../org/onosproject/ovsdb/rfc/notation/Row.java | 2 + 4 files changed, 131 insertions(+), 2 deletions(-) (limited to 'framework/src/onos/ovsdb') 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; /** @@ -49,6 +50,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 options); + /** * Drops the configuration for the tunnel. * @@ -71,6 +83,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 controllers); + /** * Drops a bridge. * @@ -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 getControllers(DeviceId openflowDeviceId); /** * Sets the Controllers for the specified bridge. - *

+ *

* 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. - *

+ *

* 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 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 failMode = new HashSet<>(Arrays.asList("secure")); + bridge.setFailMode(failMode); + + Set protocols = new HashSet<>(Arrays.asList(OvsdbConstant.OPENFLOW13)); + bridge.setProtocols(protocols); + + Map 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. *

@@ -647,6 +695,50 @@ public class DefaultOvsdbClient return; } + @Override + public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map 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 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 conditions = new ArrayList<>(Arrays.asList(condition)); + List 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; 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; /** @@ -51,6 +52,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { } + @Override + public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map options) { + return true; + } + @Override public void dropTunnel(IpAddress srcIp, IpAddress dstIp) { @@ -66,6 +72,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { } + @Override + public boolean createBridge(String bridgeName, String dpid, List 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 columns) { checkNotNull(tableName, "table name cannot be null"); -- cgit 1.2.3-korg