diff options
author | Ashlee Young <ashlee@onosfw.com> | 2015-10-09 18:32:44 -0700 |
---|---|---|
committer | Ashlee Young <ashlee@onosfw.com> | 2015-10-09 18:32:44 -0700 |
commit | 6a07d2d622eaa06953f3353e39c080984076e8de (patch) | |
tree | bfb50a2090fce186c2cc545a400c969bf2ea702b /framework/src/onos/ovsdb | |
parent | e6d71622143ff9b2421a1abbe8434b954b5b1099 (diff) |
Updated master to commit id 6ee8aa3e67ce89908a8c93aa9445c6f71a18f986
Change-Id: I94b055ee2f298daf71e2ec794fd0f2495bd8081f
Diffstat (limited to 'framework/src/onos/ovsdb')
14 files changed, 783 insertions, 178 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) { + + } +} diff --git a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java index 07582327..2e84a16a 100644 --- a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java +++ b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java @@ -15,25 +15,38 @@ */ package org.onosproject.ovsdb.controller.impl; +import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.Channel; +import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.string.StringEncoder; +import io.netty.handler.timeout.IdleState; +import io.netty.handler.timeout.IdleStateEvent; +import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.CharsetUtil; import java.net.InetSocketAddress; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import org.onlab.packet.IpAddress; +import org.onlab.packet.TpPort; import org.onosproject.ovsdb.controller.OvsdbConstant; import org.onosproject.ovsdb.controller.OvsdbNodeId; import org.onosproject.ovsdb.controller.driver.DefaultOvsdbClient; @@ -63,6 +76,9 @@ public class Controller { private EventLoopGroup workerGroup; private Class<? extends ServerChannel> serverChannelClass; + private static final int MAX_RETRY = 5; + private static final int IDLE_TIMEOUT_SEC = 10; + /** * Initialization. */ @@ -198,4 +214,86 @@ public class Controller { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } + + /** + * Connect to the ovsdb server with given ip address and port number. + * + * @param ip ip address + * @param port port number + */ + public void connect(IpAddress ip, TpPort port) { + ChannelFutureListener listener = new ConnectionListener(this, ip, port); + connectRetry(ip, port, listener); + } + + private void connectRetry(IpAddress ip, TpPort port, ChannelFutureListener listener) { + try { + Bootstrap b = new Bootstrap(); + b.group(workerGroup) + .channel(NioSocketChannel.class) + .option(ChannelOption.TCP_NODELAY, true) + .handler(new ChannelInitializer<SocketChannel>() { + + @Override + protected void initChannel(SocketChannel channel) throws Exception { + ChannelPipeline p = channel.pipeline(); + p.addLast(new MessageDecoder(), + new StringEncoder(CharsetUtil.UTF_8), + new IdleStateHandler(IDLE_TIMEOUT_SEC, 0, 0), + new ConnectionHandler()); + } + }); + b.remoteAddress(ip.toString(), port.toInt()); + b.connect().addListener(listener); + } catch (Exception e) { + log.warn("Connection to the ovsdb server {}:{} failed", ip.toString(), port.toString()); + } + } + + private class ConnectionListener implements ChannelFutureListener { + private Controller controller; + private IpAddress ip; + private TpPort port; + private AtomicInteger count = new AtomicInteger(); + + public ConnectionListener(Controller controller, + IpAddress ip, + TpPort port) { + this.controller = controller; + this.ip = ip; + this.port = port; + } + + @Override + public void operationComplete(ChannelFuture channelFuture) throws Exception { + if (!channelFuture.isSuccess()) { + channelFuture.channel().close(); + + if (count.incrementAndGet() < MAX_RETRY) { + final EventLoop loop = channelFuture.channel().eventLoop(); + + loop.schedule(() -> { + controller.connectRetry(this.ip, this.port, this); + }, 1L, TimeUnit.SECONDS); + } else { + log.info("Connection to the ovsdb {}:{} failed", + this.ip.toString(), this.port.toString()); + } + } else { + handleNewNodeConnection(channelFuture.channel()); + } + } + } + + private class ConnectionHandler extends ChannelDuplexHandler { + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + IdleStateEvent e = (IdleStateEvent) evt; + + if (e.state() == IdleState.READER_IDLE) { + ctx.close(); + } + } + } } diff --git a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java index 9b482968..c2cbbf8b 100644 --- a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java +++ b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java @@ -15,24 +15,15 @@ */ package org.onosproject.ovsdb.controller.impl; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.math.BigInteger; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.ExecutionException; - +import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.collect.ImmutableList; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Service; import org.onlab.packet.IpAddress; import org.onlab.packet.MacAddress; +import org.onlab.packet.TpPort; import org.onosproject.ovsdb.controller.DefaultEventSubject; import org.onosproject.ovsdb.controller.EventSubject; import org.onosproject.ovsdb.controller.OvsdbClientService; @@ -67,7 +58,17 @@ import org.osgi.service.component.ComponentContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.databind.JsonNode; +import java.math.BigInteger; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.ExecutionException; + +import static com.google.common.base.Preconditions.checkNotNull; /** * The implementation of OvsdbController. @@ -133,8 +134,7 @@ public class OvsdbControllerImpl implements OvsdbController { @Override public List<OvsdbNodeId> getNodeIds() { - // TODO Auto-generated method stub - return null; + return ImmutableList.copyOf(ovsdbClients.keySet()); } @Override @@ -142,6 +142,11 @@ public class OvsdbControllerImpl implements OvsdbController { return ovsdbClients.get(nodeId); } + @Override + public void connect(IpAddress ip, TpPort port) { + controller.connect(ip, port); + } + /** * Implementation of an Ovsdb Agent which is responsible for keeping track * of connected node and the state in which they are. @@ -204,8 +209,8 @@ public class OvsdbControllerImpl implements OvsdbController { * Processes table updates. * * @param clientService OvsdbClientService instance - * @param updates TableUpdates instance - * @param dbName ovsdb database name + * @param updates TableUpdates instance + * @param dbName ovsdb database name */ private void processTableUpdates(OvsdbClientService clientService, TableUpdates updates, String dbName) @@ -236,8 +241,8 @@ public class OvsdbControllerImpl implements OvsdbController { Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value()); dispatchInterfaceEvent(clientService, row, - OvsdbEvent.Type.PORT_REMOVED, - dbSchema); + OvsdbEvent.Type.PORT_REMOVED, + dbSchema); } clientService.removeRow(dbName, tableName, uuid.value()); } @@ -249,10 +254,10 @@ public class OvsdbControllerImpl implements OvsdbController { * Dispatches event to the north. * * @param clientService OvsdbClientService instance - * @param newRow a new row - * @param oldRow an old row - * @param eventType type of event - * @param dbSchema ovsdb database schema + * @param newRow a new row + * @param oldRow an old row + * @param eventType type of event + * @param dbSchema ovsdb database schema */ private void dispatchInterfaceEvent(OvsdbClientService clientService, Row row, @@ -277,13 +282,13 @@ public class OvsdbControllerImpl implements OvsdbController { } EventSubject eventSubject = new DefaultEventSubject(MacAddress.valueOf( - macAndIfaceId[0]), + macAndIfaceId[0]), new HashSet<IpAddress>(), new OvsdbPortName(intf - .getName()), + .getName()), new OvsdbPortNumber(localPort), new OvsdbDatapathId(Long - .toString(dpid)), + .toString(dpid)), new OvsdbPortType(portType), new OvsdbIfaceId(macAndIfaceId[1])); for (OvsdbEventListener listener : ovsdbEventListener) { @@ -309,7 +314,7 @@ public class OvsdbControllerImpl implements OvsdbController { String attachedMac = externalIds.get(OvsdbConstant.EXTERNAL_ID_VM_MAC); if (attachedMac == null) { - log.warn("The attachedMac is null"); + log.debug("The attachedMac is null"); //FIXME why always null? return null; } String ifaceid = externalIds @@ -318,7 +323,7 @@ public class OvsdbControllerImpl implements OvsdbController { log.warn("The ifaceid is null"); return null; } - return new String[] {attachedMac, ifaceid}; + return new String[]{attachedMac, ifaceid}; } /** @@ -343,7 +348,7 @@ public class OvsdbControllerImpl implements OvsdbController { * Gets datapathid from table bridge. * * @param clientService OvsdbClientService instance - * @param dbSchema ovsdb database schema + * @param dbSchema ovsdb database schema * @return datapathid the bridge datapathid */ private long getDataPathid(OvsdbClientService clientService, diff --git a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbJsonRpcHandler.java b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbJsonRpcHandler.java index 37942c24..1956a1eb 100644 --- a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbJsonRpcHandler.java +++ b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbJsonRpcHandler.java @@ -89,7 +89,7 @@ public final class OvsdbJsonRpcHandler extends ChannelInboundHandlerAdapter { */ private void processOvsdbMessage(JsonNode jsonNode) { - log.info("Handle ovsdb message"); + log.debug("Handle ovsdb message"); if (jsonNode.has("result")) { 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 33269223..00609602 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 @@ -15,20 +15,21 @@ */ package org.onosproject.ovsdb.rfc.notation; -import static com.google.common.base.MoreObjects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.Maps; import java.util.Collection; import java.util.Map; import java.util.Objects; -import com.google.common.collect.Maps; +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; /** * Row is the basic element of the OpenVswitch's table. */ public final class Row { private String tableName; + private UUID uuid; private Map<String, Column> columns; /** @@ -40,9 +41,11 @@ public final class Row { /** * Row constructor. + * * @param tableName table name */ - public Row(String tableName) { + @Deprecated + private Row(String tableName) { checkNotNull(tableName, "tableName cannot be null"); this.tableName = tableName; this.columns = Maps.newHashMap(); @@ -50,18 +53,22 @@ public final class Row { /** * Row constructor. + * * @param tableName table name - * @param columns Map of Column entity + * @param columns Map of Column entity */ - public Row(String tableName, Map<String, Column> columns) { + public Row(String tableName, UUID uuid, Map<String, Column> columns) { checkNotNull(tableName, "table name cannot be null"); + checkNotNull(uuid, "uuid cannot be null"); checkNotNull(columns, "columns cannot be null"); this.tableName = tableName; + this.uuid = uuid; this.columns = columns; } /** * Returns tableName. + * * @return tableName */ public String tableName() { @@ -70,6 +77,7 @@ public final class Row { /** * Set tableName value. + * * @param tableName table name */ public void setTableName(String tableName) { @@ -77,7 +85,26 @@ public final class Row { } /** + * Returns uuid. + * + * @return uuid + */ + public UUID uuid() { + return uuid; + } + + /** + * Sets uuid value. + * + * @param uuid new uuid + */ + public void setUuid(UUID uuid) { + this.uuid = uuid; + } + + /** * Returns Column by ColumnSchema. + * * @param columnName column name * @return Column */ @@ -87,6 +114,7 @@ public final class Row { /** * Returns Collection of Column. + * * @return Collection of Column */ public Collection<Column> getColumns() { @@ -95,8 +123,9 @@ public final class Row { /** * add Column. + * * @param columnName column name - * @param data Column entity + * @param data Column entity */ public void addColumn(String columnName, Column data) { this.columns.put(columnName, data); diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Bridge.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Bridge.java index bd589f03..0b5ffeff 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Bridge.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Bridge.java @@ -15,16 +15,17 @@ */ package org.onosproject.ovsdb.rfc.table; -import java.util.Map; -import java.util.Set; - import org.onosproject.ovsdb.rfc.notation.Column; +import org.onosproject.ovsdb.rfc.notation.OvsdbSet; import org.onosproject.ovsdb.rfc.notation.Row; import org.onosproject.ovsdb.rfc.notation.UUID; import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; import org.onosproject.ovsdb.rfc.tableservice.AbstractOvsdbTableService; import org.onosproject.ovsdb.rfc.tableservice.ColumnDescription; +import java.util.Map; +import java.util.Set; + /** * This class provides operations of Bridge Table. */ @@ -351,7 +352,7 @@ public class Bridge extends AbstractOvsdbTableService { * of attributes. * @param controller the column data which column name is "controller" */ - public void setController(Set<UUID> controller) { + public void setController(OvsdbSet controller) { ColumnDescription columndesc = new ColumnDescription( BridgeColumn.CONTROLLER .columnName(), diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/TableGenerator.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/TableGenerator.java index c1ae7c79..f5bd860d 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/TableGenerator.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/TableGenerator.java @@ -37,6 +37,7 @@ public final class TableGenerator { * @param tableName table name * @return Object table entity */ + //FIXME change the name, it creates a row object, such as a controller. public static Object createTable(DatabaseSchema dbSchema, OvsdbTable tableName) { Row row = new Row(); diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/FromJsonUtil.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/FromJsonUtil.java index 9744fb49..1dcf48f3 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/FromJsonUtil.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/FromJsonUtil.java @@ -15,12 +15,11 @@ */ package org.onosproject.ovsdb.rfc.utils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import org.onosproject.ovsdb.rfc.exception.AbnormalJsonNodeException; import org.onosproject.ovsdb.rfc.exception.UnsupportedException; import org.onosproject.ovsdb.rfc.jsonrpc.Callback; @@ -41,11 +40,11 @@ import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * JsonNode utility class. convert JsonNode into Object. @@ -247,7 +246,7 @@ public final class FromJsonUtil { validateJsonNode(rowsNode, "rows"); ArrayList<Row> rows = Lists.newArrayList(); for (JsonNode rowNode : rowsNode.get("rows")) { - rows.add(createRow(tableSchema, rowNode)); + rows.add(createRow(tableSchema, null, rowNode)); //FIXME null will throw exception } return rows; } @@ -285,8 +284,8 @@ public final class FromJsonUtil { UUID uuid = UUID.uuid(uuidStr); JsonNode newR = oldNewRow.getValue().get("new"); JsonNode oldR = oldNewRow.getValue().get("old"); - Row newRow = newR != null ? createRow(tableSchema, newR) : null; - Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null; + Row newRow = newR != null ? createRow(tableSchema, uuid, newR) : null; + Row oldRow = oldR != null ? createRow(tableSchema, uuid, oldR) : null; RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow); rows.put(uuid, rowUpdate); } @@ -299,7 +298,7 @@ public final class FromJsonUtil { * @param rowNode JsonNode * @return Row */ - private static Row createRow(TableSchema tableSchema, JsonNode rowNode) { + private static Row createRow(TableSchema tableSchema, UUID uuid, JsonNode rowNode) { if (tableSchema == null) { return null; } @@ -314,7 +313,7 @@ public final class FromJsonUtil { columns.put(columnName, new Column(columnName, obj)); } } - return new Row(tableSchema.name(), columns); + return new Row(tableSchema.name(), uuid, columns); } } |