aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/ovsdb/api
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/ovsdb/api')
-rw-r--r--framework/src/onos/ovsdb/api/pom.xml4
-rw-r--r--framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java73
-rw-r--r--framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java2
-rw-r--r--framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbController.java11
-rw-r--r--framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java341
-rw-r--r--framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java208
-rw-r--r--framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbControllerAdapter.java75
7 files changed, 593 insertions, 121 deletions
diff --git a/framework/src/onos/ovsdb/api/pom.xml b/framework/src/onos/ovsdb/api/pom.xml
index 7089216f..c264ae97 100644
--- a/framework/src/onos/ovsdb/api/pom.xml
+++ b/framework/src/onos/ovsdb/api/pom.xml
@@ -48,6 +48,10 @@
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
<artifactId>onos-ovsdb-rfc</artifactId>
<version>${project.version}</version>
</dependency>
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 ab88a24e..f2ff0709 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
@@ -15,19 +15,20 @@
*/
package org.onosproject.ovsdb.controller;
-import java.util.List;
-import java.util.Set;
-
+import com.google.common.util.concurrent.ListenableFuture;
import org.onlab.packet.IpAddress;
-
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRPC;
import org.onosproject.ovsdb.rfc.message.OperationResult;
import org.onosproject.ovsdb.rfc.message.TableUpdates;
import org.onosproject.ovsdb.rfc.notation.Row;
+import org.onosproject.ovsdb.rfc.notation.UUID;
import org.onosproject.ovsdb.rfc.operations.Operation;
import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.List;
+import java.util.Set;
/**
* Represents to provider facing side of a node.
@@ -85,10 +86,39 @@ public interface OvsdbClientService extends OvsdbRPC {
Set<OvsdbBridge> getBridges();
/**
+ * Gets controllers of the node.
+ *
+ * @return set of controllers; empty if no controller is find
+ */
+ Set<ControllerInfo> getControllers(DeviceId openflowDeviceId);
+
+ /**
+ * Sets the Controllers for the specified bridge.
+ * <p/>
+ * This method will replace the existing controller list with the new controller
+ * list.
+ *
+ * @param bridgeUuid bridge uuid
+ * @param controllers list of controllers
+ */
+ void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers);
+
+ /**
+ * Sets the Controllers for the specified device.
+ * <p/>
+ * This method will replace the existing controller list with the new controller
+ * list.
+ *
+ * @param deviceId device id (likely Openflow device)
+ * @param controllers list of controllers
+ */
+ void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers);
+
+ /**
* Creates a port.
*
* @param bridgeName bridge name
- * @param portName port name
+ * @param portName port name
*/
void createPort(String bridgeName, String portName);
@@ -96,7 +126,7 @@ public interface OvsdbClientService extends OvsdbRPC {
* Drops a port.
*
* @param bridgeName bridge name
- * @param portName port name
+ * @param portName port name
*/
void dropPort(String bridgeName, String portName);
@@ -125,7 +155,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the Port uuid.
*
- * @param portName port name
+ * @param portName port name
* @param bridgeUuid bridge uuid
* @return port uuid, empty if no uuid is find
*/
@@ -143,7 +173,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the Controller uuid.
*
- * @param controllerName controller name
+ * @param controllerName controller name
* @param controllerTarget controller target
* @return controller uuid, empty if no uuid is find
*/
@@ -169,7 +199,7 @@ public interface OvsdbClientService extends OvsdbRPC {
* Gets the ovsdb table updates.
*
* @param dbName database name
- * @param id random uuid
+ * @param id random uuid
* @return table updates
*/
ListenableFuture<TableUpdates> monitorTables(String dbName, String id);
@@ -177,7 +207,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the ovsdb config operation result.
*
- * @param dbName database name
+ * @param dbName database name
* @param operations the list of operations
* @return operation results
*/
@@ -187,7 +217,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the ovsdb database schema from local.
*
- * @param dbName database name
+ * @param dbName database name
* @return database schema
*/
DatabaseSchema getDatabaseSchema(String dbName);
@@ -195,9 +225,9 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the ovsdb row from the local ovsdb store.
*
- * @param dbName database name
+ * @param dbName database name
* @param tableName table name
- * @param uuid row uuid
+ * @param uuid row uuid
* @return row ovsdb row
*/
Row getRow(String dbName, String tableName, String uuid);
@@ -205,19 +235,19 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Removes the ovsdb row from the local ovsdb store.
*
- * @param dbName database name
+ * @param dbName database name
* @param tableName table name
- * @param uuid row uuid
+ * @param uuid row uuid
*/
void removeRow(String dbName, String tableName, String uuid);
/**
* Updates the local ovsdb store.
*
- * @param dbName database name
+ * @param dbName database name
* @param tableName table name
- * @param uuid row uuid
- * @param row ovsdb row
+ * @param uuid row uuid
+ * @param row ovsdb row
*/
void updateOvsdbStore(String dbName, String tableName, String uuid, Row row);
@@ -228,4 +258,9 @@ public interface OvsdbClientService extends OvsdbRPC {
* @return ovsdb ports
*/
Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids);
+
+ /**
+ * Disconnects the ovsdb server.
+ */
+ void disconnect();
}
diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
index c1133bbd..e91c928a 100644
--- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
+++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
@@ -60,7 +60,7 @@ public final class OvsdbConstant {
public static final String EXTERNAL_ID_VM_MAC = "attached-mac";
/** Openflow port. */
- public static final int OFPORT = 6633;
+ public static final int OFPORT = 6653;
/** Ovsdb port. */
public static final int OVSDBPORT = 6640;
diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbController.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbController.java
index 9e245240..24bfeae9 100644
--- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbController.java
+++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbController.java
@@ -15,6 +15,9 @@
*/
package org.onosproject.ovsdb.controller;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+
import java.util.List;
/**
@@ -65,4 +68,12 @@ public interface OvsdbController {
* @return OvsdbClient ovsdb node information
*/
OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId);
+
+ /**
+ * Connect to the ovsdb server with given ip address and port number.
+ *
+ * @param ip ip address
+ * @param port port number
+ */
+ void connect(IpAddress ip, TpPort port);
}
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 0c64cc0e..3a84d000 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
@@ -15,19 +15,19 @@
*/
package org.onosproject.ovsdb.controller.driver;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
import io.netty.channel.Channel;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
-
import org.onlab.packet.IpAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.ovsdb.controller.OvsdbBridge;
import org.onosproject.ovsdb.controller.OvsdbBridgeName;
import org.onosproject.ovsdb.controller.OvsdbClientService;
@@ -71,14 +71,17 @@ import org.onosproject.ovsdb.rfc.utils.MutationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
/**
* An representation of an ovsdb client.
@@ -168,9 +171,8 @@ public class DefaultOvsdbClient
/**
* Gets the ovsdb row store.
*
- * @param dbName the ovsdb database name
+ * @param dbName the ovsdb database name
* @param tableName the ovsdb table name
- *
* @return ovsRowStore, empty if row store is find
*/
private OvsdbRowStore getRowStore(String dbName, String tableName) {
@@ -184,9 +186,9 @@ public class DefaultOvsdbClient
/**
* Gets the ovsdb row.
*
- * @param dbName the ovsdb database name
+ * @param dbName the ovsdb database name
* @param tableName the ovsdb table name
- * @param uuid the key of the row
+ * @param uuid the key of the row
* @return row, empty if row is find
*/
@Override
@@ -394,7 +396,7 @@ public class DefaultOvsdbClient
port.setName(portName);
if (portUuid == null) {
insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE,
- "ports", bridgeUuid, port.getRow());
+ "ports", bridgeUuid, port.getRow());
} else {
updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow());
}
@@ -414,7 +416,7 @@ public class DefaultOvsdbClient
if (portUuid != null) {
log.info("Port {} delete", portName);
deleteConfig(OvsdbConstant.PORT, "_uuid", portUuid,
- OvsdbConstant.BRIDGE, "ports");
+ OvsdbConstant.BRIDGE, "ports");
}
}
@@ -455,8 +457,8 @@ public class DefaultOvsdbClient
bridge.setName(bridgeName);
bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid",
- OvsdbConstant.DATABASENAME, "bridges",
- ovsUuid, bridge.getRow());
+ OvsdbConstant.DATABASENAME, "bridges",
+ ovsUuid, bridge.getRow());
if (bridgeUuid != null) {
Port port = (Port) TableGenerator.createTable(dbSchema,
@@ -466,7 +468,7 @@ public class DefaultOvsdbClient
port.setName(bridgeName);
insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid,
- port.getRow());
+ port.getRow());
}
}
@@ -475,51 +477,92 @@ public class DefaultOvsdbClient
updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow());
}
- setController(bridgeUuid);
+ setControllerAuto(bridgeUuid);
log.info("Create bridge success");
}
/**
- * Sets the Controller.
+ * Sets the bridge's controller automatically.
+ * <p/>
+ * The connection is a TCP connection to the local ONOS instance's IP
+ * and the default OpenFlow port.
*
* @param bridgeUuid bridge uuid
*/
- private void setController(String bridgeUuid) {
- String controllerUuid = null;
- String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel
- .localAddress())
- .getAddress()
- .getHostAddress())
- .toString();
+ private void setControllerAuto(String bridgeUuid) {
+ IpAddress ipAddress = IpAddress.valueOf(((InetSocketAddress) channel.localAddress()).getAddress());
+ ControllerInfo controllerInfo = new ControllerInfo(ipAddress, OvsdbConstant.OFPORT, "tcp");
+ log.debug("Automatically setting controller for bridge {} to {}",
+ bridgeUuid, controllerInfo.target());
+ setControllersWithUUID(UUID.uuid(bridgeUuid), ImmutableList.of(controllerInfo));
+ }
- String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT;
- log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT);
+ @Override
+ public void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers) {
DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
- Controller controller = (Controller) TableGenerator
- .createTable(dbSchema, OvsdbTable.CONTROLLER);
-
- if (controller != null) {
- controller.setTarget(target);
- controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target);
- if (controllerUuid == null) {
+ if (dbSchema == null) {
+ log.debug("There is no schema");
+ return;
+ }
+ List<Controller> oldControllers = getControllers(bridgeUuid);
+ if (oldControllers == null) {
+ log.warn("There are no controllers");
+ return;
+ }
- insertConfig(OvsdbConstant.CONTROLLER, "_uuid",
- OvsdbConstant.BRIDGE, "controller", bridgeUuid,
- controller.getRow());
+ Set<UUID> newControllerUuids = new HashSet<>();
+ Set<ControllerInfo> newControllers = new HashSet<>(controllers);
+ List<Controller> removeControllers = new ArrayList<>();
+ oldControllers.forEach(controller -> {
+ ControllerInfo controllerInfo = new ControllerInfo((String) controller.getTargetColumn().data());
+ if (newControllers.contains(controllerInfo)) {
+ newControllers.remove(controllerInfo);
+ newControllerUuids.add(controller.getRow().uuid());
} else {
+ removeControllers.add(controller);
+ }
+ });
+ OvsdbRowStore controllerRowStore = getRowStore(OvsdbConstant.DATABASENAME,
+ OvsdbConstant.CONTROLLER);
+ if (controllerRowStore == null) {
+ log.debug("There is no controller table");
+ return;
+ }
- Bridge bridge = (Bridge) TableGenerator
- .createTable(dbSchema, OvsdbTable.BRIDGE);
- Set<UUID> controllerUuids = new HashSet<>();
- controllerUuids.add(UUID.uuid(controllerUuid));
- bridge.setController(controllerUuids);
- updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow());
+ removeControllers.forEach(c -> deleteConfig(OvsdbConstant.CONTROLLER, "_uuid", c.getRow().uuid().value(),
+ OvsdbConstant.BRIDGE, "controller"));
- }
+ newControllers.stream().map(c -> {
+ Controller controller = (Controller) TableGenerator
+ .createTable(dbSchema, OvsdbTable.CONTROLLER);
+ controller.setTarget(c.target());
+ return controller;
+ }).forEach(c -> {
+ String uuid = insertConfig(OvsdbConstant.CONTROLLER, "_uuid",
+ OvsdbConstant.BRIDGE, "controller", bridgeUuid.value(),
+ c.getRow());
+ newControllerUuids.add(UUID.uuid(uuid));
+
+ });
+
+ OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
+ OvsdbConstant.BRIDGE);
+ if (rowStore == null) {
+ log.debug("There is no bridge table");
+ return;
}
+ Row bridgeRow = rowStore.getRow(bridgeUuid.value());
+ Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
+ bridge.setController(OvsdbSet.ovsdbSet(newControllerUuids));
+ updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid.value(), bridge.getRow());
+ }
+
+ @Override
+ public void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers) {
+ setControllersWithUUID(getBridgeUUID(deviceId), controllers);
}
@Override
@@ -530,7 +573,7 @@ public class DefaultOvsdbClient
return;
}
deleteConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUUID,
- OvsdbConstant.DATABASENAME, "bridges");
+ OvsdbConstant.DATABASENAME, "bridges");
}
@Override
@@ -554,7 +597,7 @@ public class DefaultOvsdbClient
if (portUuid == null) {
portUuid = insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE,
- "ports", bridgeUuid, port.getRow());
+ "ports", bridgeUuid, port.getRow());
} else {
updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow());
}
@@ -595,7 +638,7 @@ public class DefaultOvsdbClient
options.put("remote_ip", dstIp.toString());
tunInterface.setOptions(options);
updateConfig(OvsdbConstant.INTERFACE, "_uuid", interfaceUuid,
- tunInterface.getRow());
+ tunInterface.getRow());
log.info("Tunnel added success", tunInterface);
}
@@ -619,7 +662,7 @@ public class DefaultOvsdbClient
if (portUUID != null) {
log.info("Delete tunnel");
deleteConfig(OvsdbConstant.PORT, "_uuid", portUUID,
- OvsdbConstant.BRIDGE, "ports");
+ OvsdbConstant.BRIDGE, "ports");
}
return;
@@ -628,16 +671,15 @@ public class DefaultOvsdbClient
/**
* Delete transact config.
*
- * @param childTableName child table name
- * @param childColumnName child column name
- * @param childUuid child row uuid
- * @param parentTableName parent table name
+ * @param childTableName child table name
+ * @param childColumnName child column name
+ * @param childUuid child row uuid
+ * @param parentTableName parent table name
* @param parentColumnName parent column
- *
*/
private void deleteConfig(String childTableName, String childColumnName,
- String childUuid, String parentTableName,
- String parentColumnName) {
+ String childUuid, String parentTableName,
+ String parentColumnName) {
DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
TableSchema childTableSchema = dbSchema.getTableSchema(childTableName);
@@ -672,14 +714,13 @@ public class DefaultOvsdbClient
/**
* Update transact config.
*
- * @param tableName table name
+ * @param tableName table name
* @param columnName column name
- * @param uuid uuid
- * @param row the config data
- *
+ * @param uuid uuid
+ * @param row the config data
*/
private void updateConfig(String tableName, String columnName, String uuid,
- Row row) {
+ Row row) {
DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
TableSchema tableSchema = dbSchema.getTableSchema(tableName);
@@ -698,18 +739,17 @@ public class DefaultOvsdbClient
/**
* Insert transact config.
*
- * @param childTableName child table name
- * @param childColumnName child column name
- * @param parentTableName parent table name
+ * @param childTableName child table name
+ * @param childColumnName child column name
+ * @param parentTableName parent table name
* @param parentColumnName parent column
- * @param parentUuid parent uuid
- * @param row the config data
- *
+ * @param parentUuid parent uuid
+ * @param row the config data
* @return uuid, empty if no uuid is find
*/
private String insertConfig(String childTableName, String childColumnName,
- String parentTableName, String parentColumnName,
- String parentUuid, Row row) {
+ String parentTableName, String parentColumnName,
+ String parentUuid, Row row) {
DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
TableSchema tableSchema = dbSchema.getTableSchema(childTableName);
@@ -741,7 +781,7 @@ public class DefaultOvsdbClient
if (childTableName.equalsIgnoreCase(OvsdbConstant.PORT)) {
log.info("Handle port insert");
Insert intfInsert = handlePortInsertTable(OvsdbConstant.INTERFACE,
- row);
+ row);
if (intfInsert != null) {
operations.add(intfInsert);
@@ -772,8 +812,7 @@ public class DefaultOvsdbClient
* Handles port insert.
*
* @param tableName ovsdb table interface
- * @param portRow row of port
- *
+ * @param portRow row of port
* @return insert, empty if null
*/
private Insert handlePortInsertTable(String tableName, Row portRow) {
@@ -801,8 +840,7 @@ public class DefaultOvsdbClient
* Gets tunnel name.
*
* @param tunnelType
- * @param dstIp the remote ip address
- *
+ * @param dstIp the remote ip address
* @return tunnel name
*/
private String getTunnelName(String tunnelType, IpAddress dstIp) {
@@ -821,7 +859,7 @@ public class DefaultOvsdbClient
Function<JsonNode, DatabaseSchema> rowFunction = new Function<JsonNode, DatabaseSchema>() {
@Override
public DatabaseSchema apply(JsonNode input) {
- log.info("Get ovsdb database schema", dbName);
+ log.info("Get ovsdb database schema {}", dbName);
DatabaseSchema dbSchema = FromJsonUtil
.jsonNodeToDbSchema(dbName, input);
if (dbSchema == null) {
@@ -877,21 +915,17 @@ public class DefaultOvsdbClient
}
DatabaseSchema dbSchema = schema.get(dbName);
if (dbSchema != null) {
- Function<List<JsonNode>, List<OperationResult>> rowFunction =
- new Function<List<JsonNode>, List<OperationResult>>() {
- @Override
- public List<OperationResult> apply(List<JsonNode> input) {
- log.info("Get ovsdb operation result");
- List<OperationResult> result = FromJsonUtil
- .jsonNodeToOperationResult(input, operations);
-
- if (result == null) {
- log.debug("The operation result is null");
- return null;
- }
- return result;
+ Function<List<JsonNode>, List<OperationResult>> rowFunction = (input -> {
+ log.info("Get ovsdb operation result");
+ List<OperationResult> result = FromJsonUtil
+ .jsonNodeToOperationResult(input, operations);
+
+ if (result == null) {
+ log.debug("The operation result is null");
+ return null;
}
- };
+ return result;
+ });
return Futures.transform(transact(dbSchema, operations),
rowFunction);
}
@@ -972,7 +1006,7 @@ public class DefaultOvsdbClient
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void processResult(JsonNode response) {
log.debug("Handle result");
@@ -1042,6 +1076,105 @@ public class DefaultOvsdbClient
}
@Override
+ public Set<ControllerInfo> getControllers(DeviceId openflowDeviceId) {
+ UUID bridgeUuid = getBridgeUUID(openflowDeviceId);
+ if (bridgeUuid == null) {
+ log.warn("bad bridge Uuid");
+ return null;
+ }
+ List<Controller> controllers = getControllers(bridgeUuid);
+ if (controllers == null) {
+ log.warn("bad list of controllers");
+ return null;
+ }
+ return controllers.stream().
+ map(controller -> new ControllerInfo(
+ (String) controller.getTargetColumn()
+ .data())).collect(Collectors.toSet());
+ }
+
+ private List<Controller> getControllers(UUID bridgeUuid) {
+ DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
+ if (dbSchema == null) {
+ return null;
+ }
+ OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
+ OvsdbConstant.BRIDGE);
+ if (rowStore == null) {
+ log.debug("There is no bridge table");
+ return null;
+ }
+
+ Row bridgeRow = rowStore.getRow(bridgeUuid.value());
+ Bridge bridge = (Bridge) TableGenerator.
+ getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
+
+ //FIXME remove log
+ log.warn("type of controller column", bridge.getControllerColumn()
+ .data().getClass());
+ Set<UUID> controllerUuids = (Set<UUID>) ((OvsdbSet) bridge
+ .getControllerColumn().data()).set();
+// Set<String> controllerUuidStrings = (Set<String>) bridge.getControllerColumn().data();
+
+ OvsdbRowStore controllerRowStore = getRowStore(OvsdbConstant.DATABASENAME,
+ OvsdbConstant.CONTROLLER);
+ if (controllerRowStore == null) {
+ log.debug("There is no controller table");
+ return null;
+ }
+
+ List<Controller> ovsdbControllers = new ArrayList<>();
+ ConcurrentMap<String, Row> controllerTableRows = controllerRowStore.getRowStore();
+ controllerTableRows.forEach((key, row) -> {
+ if (!controllerUuids.contains(UUID.uuid(key))) {
+ return;
+ }
+ Controller controller = (Controller) TableGenerator
+ .getTable(dbSchema, row, OvsdbTable.CONTROLLER);
+ ovsdbControllers.add(controller);
+ });
+ return ovsdbControllers;
+ }
+
+
+ private UUID getBridgeUUID(DeviceId openflowDeviceId) {
+ DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
+ if (dbSchema == null) {
+ return null;
+ }
+ OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
+ OvsdbConstant.BRIDGE);
+ if (rowStore == null) {
+ log.debug("There is no bridge table");
+ return null;
+ }
+
+ ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
+ final AtomicReference<UUID> uuid = new AtomicReference<>();
+ for (Map.Entry<String, Row> entry : bridgeTableRows.entrySet()) {
+ Bridge b = (Bridge) TableGenerator.getTable(dbSchema,
+ entry.getValue(),
+ OvsdbTable.BRIDGE);
+ if (matchesDpid(b, openflowDeviceId)) {
+ uuid.set(UUID.uuid(entry.getKey()));
+ break;
+ }
+ }
+ if (uuid.get() == null) {
+ log.debug("There is no bridge for {}", openflowDeviceId);
+ }
+ return uuid.get();
+
+ }
+
+ private static boolean matchesDpid(Bridge b, DeviceId deviceId) {
+ String ofDpid = deviceId.toString().replace("of:", "");
+ Set ofDeviceIds = ((OvsdbSet) b.getDatapathIdColumn().data()).set();
+ //TODO Set<String>
+ return ofDeviceIds.contains(ofDpid);
+ }
+
+ @Override
public Set<OvsdbPort> getPorts() {
Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>();
OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME);
@@ -1185,4 +1318,10 @@ public class DefaultOvsdbClient
}
return ifaceid;
}
+
+ @Override
+ public void disconnect() {
+ channel.disconnect();
+ this.agent.removeConnectedNode(nodeId);
+ }
}
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
new file mode 100644
index 00000000..71fee4fe
--- /dev/null
+++ b/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ovsdb.controller.driver;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.ovsdb.controller.OvsdbBridge;
+import org.onosproject.ovsdb.controller.OvsdbClientService;
+import org.onosproject.ovsdb.controller.OvsdbNodeId;
+import org.onosproject.ovsdb.controller.OvsdbPort;
+import org.onosproject.ovsdb.controller.OvsdbTunnel;
+import org.onosproject.ovsdb.rfc.message.OperationResult;
+import org.onosproject.ovsdb.rfc.message.TableUpdates;
+import org.onosproject.ovsdb.rfc.notation.Row;
+import org.onosproject.ovsdb.rfc.notation.UUID;
+import org.onosproject.ovsdb.rfc.operations.Operation;
+import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Test Adapter for OvsdbClientService.
+ */
+public class OvsdbClientServiceAdapter implements OvsdbClientService {
+
+ @Override
+ public OvsdbNodeId nodeId() {
+ return null;
+ }
+
+ @Override
+ public void createTunnel(IpAddress srcIp, IpAddress dstIp) {
+
+ }
+
+ @Override
+ public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
+
+ }
+
+ @Override
+ public Set<OvsdbTunnel> getTunnels() {
+ return null;
+ }
+
+ @Override
+ public void createBridge(String bridgeName) {
+
+ }
+
+ @Override
+ public void dropBridge(String bridgeName) {
+
+ }
+
+ @Override
+ public Set<OvsdbBridge> getBridges() {
+ return null;
+ }
+
+ @Override
+ public Set<ControllerInfo> getControllers(DeviceId openflowDeviceId) {
+ return null;
+ }
+
+ @Override
+ public void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers) {
+
+ }
+
+ @Override
+ public void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers) {
+
+ }
+
+ @Override
+ public void createPort(String bridgeName, String portName) {
+
+ }
+
+ @Override
+ public void dropPort(String bridgeName, String portName) {
+
+ }
+
+ @Override
+ public Set<OvsdbPort> getPorts() {
+ return null;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return false;
+ }
+
+ @Override
+ public String getBridgeUuid(String bridgeName) {
+ return null;
+ }
+
+ @Override
+ public String getPortUuid(String portName, String bridgeUuid) {
+ return null;
+ }
+
+ @Override
+ public String getInterfaceUuid(String portUuid, String portName) {
+ return null;
+ }
+
+ @Override
+ public String getControllerUuid(String controllerName, String controllerTarget) {
+ return null;
+ }
+
+ @Override
+ public String getOvsUuid(String dbName) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<TableUpdates> monitorTables(String dbName, String id) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<List<OperationResult>> transactConfig(String dbName, List<Operation> operations) {
+ return null;
+ }
+
+ @Override
+ public DatabaseSchema getDatabaseSchema(String dbName) {
+ return null;
+ }
+
+ @Override
+ public Row getRow(String dbName, String tableName, String uuid) {
+ return null;
+ }
+
+ @Override
+ public void removeRow(String dbName, String tableName, String uuid) {
+
+ }
+
+ @Override
+ public void updateOvsdbStore(String dbName, String tableName, String uuid, Row row) {
+
+ }
+
+ @Override
+ public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) {
+ return null;
+ }
+
+ @Override
+ public void disconnect() {
+
+ }
+
+ @Override
+ public ListenableFuture<JsonNode> getSchema(List<String> dbnames) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<List<String>> echo() {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema, String monitorId) {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<List<String>> listDbs() {
+ return null;
+ }
+
+ @Override
+ public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema, List<Operation> operations) {
+ return null;
+ }
+}
diff --git a/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbControllerAdapter.java b/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbControllerAdapter.java
new file mode 100644
index 00000000..902113aa
--- /dev/null
+++ b/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbControllerAdapter.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ovsdb.controller.driver;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.onosproject.ovsdb.controller.OvsdbClientService;
+import org.onosproject.ovsdb.controller.OvsdbController;
+import org.onosproject.ovsdb.controller.OvsdbEventListener;
+import org.onosproject.ovsdb.controller.OvsdbNodeId;
+import org.onosproject.ovsdb.controller.OvsdbNodeListener;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Test Adapter for OvsdbController.
+ */
+public class OvsdbControllerAdapter implements OvsdbController {
+ protected ConcurrentHashMap<OvsdbNodeId, OvsdbClientServiceAdapter> ovsdbClients =
+ new ConcurrentHashMap<OvsdbNodeId, OvsdbClientServiceAdapter>();
+
+ @Override
+ public void addNodeListener(OvsdbNodeListener listener) {
+
+ }
+
+ @Override
+ public void removeNodeListener(OvsdbNodeListener listener) {
+
+ }
+
+ @Override
+ public void addOvsdbEventListener(OvsdbEventListener listener) {
+
+ }
+
+ @Override
+ public void removeOvsdbEventListener(OvsdbEventListener listener) {
+
+ }
+
+ @Override
+ public List<OvsdbNodeId> getNodeIds() {
+ long port = 6653;
+ return new ArrayList<OvsdbNodeId>(Arrays.asList(
+ new OvsdbNodeId(IpAddress.valueOf("127.0.0.1"), port)));
+ }
+
+ @Override
+ public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) {
+ return ovsdbClients.get(nodeId);
+ }
+
+ @Override
+ public void connect(IpAddress ip, TpPort port) {
+
+ }
+}