Search in sources :

Example 26 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class OvsdbControllerImpl method getDataPathid.

/**
 * Gets datapathid from table bridge.
 *
 * @param clientService OvsdbClientService instance
 * @param dbSchema      ovsdb database schema
 * @return datapathid the bridge datapathid
 */
private long getDataPathid(OvsdbClientService clientService, DatabaseSchema dbSchema) {
    String bridgeUuid = clientService.getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE);
    if (bridgeUuid == null) {
        log.debug("Unable to spot bridge uuid for {} in {}", OvsdbConstant.INTEGRATION_BRIDGE, clientService);
        return 0;
    }
    Row bridgeRow = clientService.getRow(OvsdbConstant.DATABASENAME, "Bridge", bridgeUuid);
    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
    OvsdbSet dpidSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
    @SuppressWarnings("unchecked") Set<String> dpids = dpidSet.set();
    if (dpids == null || dpids.isEmpty()) {
        return 0;
    }
    return stringToLong((String) dpids.toArray()[0]);
}
Also used : OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) Row(org.onosproject.ovsdb.rfc.notation.Row) Bridge(org.onosproject.ovsdb.rfc.table.Bridge)

Example 27 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class OvsdbControllerImpl method processTableUpdates.

/**
 * Processes table updates.
 *
 * @param clientService OvsdbClientService instance
 * @param updates       TableUpdates instance
 * @param dbName        ovsdb database name
 */
private void processTableUpdates(OvsdbClientService clientService, TableUpdates updates, String dbName) throws InterruptedException {
    checkNotNull(clientService, "OvsdbClientService is not null");
    DatabaseSchema dbSchema = clientService.getDatabaseSchema(dbName);
    for (String tableName : updates.result().keySet()) {
        TableUpdate update = updates.result().get(tableName);
        for (Uuid uuid : (Set<Uuid>) update.rows().keySet()) {
            log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", uuid.value(), dbName, tableName);
            Row newRow = update.getNew(uuid);
            if (newRow != null) {
                clientService.updateOvsdbStore(dbName, tableName, uuid.value(), newRow);
                if (OvsdbConstant.INTERFACE.equals(tableName)) {
                    dispatchInterfaceEvent(clientService, newRow, OvsdbEvent.Type.PORT_ADDED, dbSchema);
                }
            } else if (update.getOld(uuid) != null) {
                if (OvsdbConstant.INTERFACE.equals(tableName)) {
                    Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value());
                    dispatchInterfaceEvent(clientService, row, OvsdbEvent.Type.PORT_REMOVED, dbSchema);
                }
                clientService.removeRow(dbName, tableName, uuid.value());
            }
        }
    }
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) Row(org.onosproject.ovsdb.rfc.notation.Row) TableUpdate(org.onosproject.ovsdb.rfc.message.TableUpdate) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 28 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class FromJsonUtil method createRow.

/**
 * Convert Operation JsonNode into Row.
 * @param tableSchema TableSchema entity
 * @param rowNode JsonNode
 * @return Row
 */
private static Row createRow(TableSchema tableSchema, Uuid uuid, JsonNode rowNode) {
    if (tableSchema == null) {
        return null;
    }
    Map<String, Column> columns = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields();
    while (rowIter.hasNext()) {
        Map.Entry<String, JsonNode> next = rowIter.next();
        ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey());
        if (columnSchema != null) {
            String columnName = columnSchema.name();
            Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type());
            columns.put(columnName, new Column(columnName, obj));
        }
    }
    return new Row(tableSchema.name(), uuid, columns);
}
Also used : Column(org.onosproject.ovsdb.rfc.notation.Column) JsonNode(com.fasterxml.jackson.databind.JsonNode) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Row(org.onosproject.ovsdb.rfc.notation.Row) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class DefaultOvsdbClient method getPortUuid.

@Override
public String getPortUuid(String portName, String bridgeUuid) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    Row bridgeRow = getRow(DATABASENAME, BRIDGE, bridgeUuid);
    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
    if (bridge != null) {
        OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data();
        @SuppressWarnings("unchecked") Set<Uuid> ports = setPorts.set();
        if (ports == null || ports.isEmpty()) {
            log.warn("The port uuid is null");
            return null;
        }
        for (Uuid uuid : ports) {
            Row portRow = getRow(DATABASENAME, PORT, uuid.value());
            Port port = (Port) TableGenerator.getTable(dbSchema, portRow, OvsdbTable.PORT);
            if (port != null && portName.equalsIgnoreCase(port.getName())) {
                return uuid.value();
            }
        }
    }
    return null;
}
Also used : OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) Port(org.onosproject.ovsdb.rfc.table.Port) Row(org.onosproject.ovsdb.rfc.notation.Row) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 30 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class DefaultOvsdbClient method getOvsdbBridge.

private OvsdbBridge getOvsdbBridge(Row row, Uuid bridgeUuid) {
    DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, OvsdbTable.BRIDGE);
    if (bridge == null) {
        return null;
    }
    OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
    @SuppressWarnings("unchecked") Set<String> datapathIds = datapathIdSet.set();
    if (datapathIds == null || datapathIds.isEmpty()) {
        return null;
    }
    String datapathId = (String) datapathIds.toArray()[0];
    String bridgeName = bridge.getName();
    if ((datapathId == null) || (bridgeName == null)) {
        return null;
    }
    List<Controller> controllers = getControllers(bridgeUuid);
    if (controllers != null) {
        List<ControllerInfo> controllerInfos = controllers.stream().map(controller -> new ControllerInfo((String) controller.getTargetColumn().data())).collect(Collectors.toList());
        return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).controllers(controllerInfos).build();
    } else {
        return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).build();
    }
}
Also used : OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) QUEUE_EXTERNAL_ID_KEY(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE_EXTERNAL_ID_KEY) Controller(org.onosproject.ovsdb.rfc.table.Controller) ColumnSchemaNotFoundException(org.onosproject.ovsdb.rfc.exception.ColumnSchemaNotFoundException) OFPORT(org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT) PortNumber(org.onosproject.net.PortNumber) QueueId(org.onosproject.net.behaviour.QueueId) FromJsonUtil(org.onosproject.ovsdb.rfc.utils.FromJsonUtil) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Update(org.onosproject.ovsdb.rfc.operations.Update) Qos(org.onosproject.ovsdb.rfc.table.Qos) Callback(org.onosproject.ovsdb.rfc.jsonrpc.Callback) Set(java.util.Set) MIRRORS(org.onosproject.ovsdb.controller.OvsdbConstant.MIRRORS) OvsdbQueue(org.onosproject.ovsdb.controller.OvsdbQueue) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) MIRROR(org.onosproject.ovsdb.controller.OvsdbConstant.MIRROR) Mirror(org.onosproject.ovsdb.rfc.table.Mirror) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) OperationResult(org.onosproject.ovsdb.rfc.message.OperationResult) OvsdbStore(org.onosproject.ovsdb.controller.OvsdbStore) DeviceId(org.onosproject.net.DeviceId) DATABASENAME(org.onosproject.ovsdb.controller.OvsdbConstant.DATABASENAME) Interface(org.onosproject.ovsdb.rfc.table.Interface) JsonRpcWriterUtil(org.onosproject.ovsdb.rfc.utils.JsonRpcWriterUtil) MirroringStatistics(org.onosproject.net.behaviour.MirroringStatistics) PORTS(org.onosproject.ovsdb.controller.OvsdbConstant.PORTS) ArrayList(java.util.ArrayList) DeviceCpuStats(org.onosproject.net.behaviour.DeviceCpuStats) Lists(com.google.common.collect.Lists) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) INTERFACE(org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACE) BRIDGE_CONTROLLER(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE_CONTROLLER) OvsdbPortName(org.onosproject.ovsdb.controller.OvsdbPortName) QUEUE(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE) QosId(org.onosproject.net.behaviour.QosId) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) EXTERNAL_ID(org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID) EXTERNAL_ID_INTERFACE_ID(org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID_INTERFACE_ID) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbTable(org.onosproject.ovsdb.rfc.table.OvsdbTable) Channel(io.netty.channel.Channel) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) Column(org.onosproject.ovsdb.rfc.notation.Column) MutationUtil(org.onosproject.ovsdb.rfc.utils.MutationUtil) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) Row(org.onosproject.ovsdb.rfc.notation.Row) CONTROLLER(org.onosproject.ovsdb.controller.OvsdbConstant.CONTROLLER) TableGenerator(org.onosproject.ovsdb.rfc.table.TableGenerator) ControlProtocolVersion(org.onosproject.net.behaviour.ControlProtocolVersion) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) OvsdbPortNumber(org.onosproject.ovsdb.controller.OvsdbPortNumber) OvsdbTableStore(org.onosproject.ovsdb.controller.OvsdbTableStore) QOS_EXTERNAL_ID_KEY(org.onosproject.ovsdb.controller.OvsdbConstant.QOS_EXTERNAL_ID_KEY) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) SettableFuture(com.google.common.util.concurrent.SettableFuture) DeviceMemoryStats(org.onosproject.net.behaviour.DeviceMemoryStats) QUEUES(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUES) Delete(org.onosproject.ovsdb.rfc.operations.Delete) UUID(org.onosproject.ovsdb.controller.OvsdbConstant.UUID) ConditionUtil(org.onosproject.ovsdb.rfc.utils.ConditionUtil) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) OFPORT_ERROR(org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT_ERROR) TYPEVXLAN(org.onosproject.ovsdb.controller.OvsdbConstant.TYPEVXLAN) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) Queue(org.onosproject.ovsdb.rfc.table.Queue) OvsdbQos(org.onosproject.ovsdb.controller.OvsdbQos) Insert(org.onosproject.ovsdb.rfc.operations.Insert) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) BRIDGE(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) HashSet(java.util.HashSet) PORT(org.onosproject.ovsdb.controller.OvsdbConstant.PORT) ImmutableList(com.google.common.collect.ImmutableList) TableUpdates(org.onosproject.ovsdb.rfc.message.TableUpdates) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) PORT_QOS(org.onosproject.ovsdb.controller.OvsdbConstant.PORT_QOS) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) IpAddress(org.onlab.packet.IpAddress) Port(org.onosproject.ovsdb.rfc.table.Port) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) VersionMismatchException(org.onosproject.ovsdb.rfc.exception.VersionMismatchException) MirroringName(org.onosproject.net.behaviour.MirroringName) BRIDGES(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGES) Maps(com.google.common.collect.Maps) INTERFACES(org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACES) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) QOS(org.onosproject.ovsdb.controller.OvsdbConstant.QOS) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Collections(java.util.Collections) Condition(org.onosproject.ovsdb.rfc.notation.Condition) Controller(org.onosproject.ovsdb.rfc.table.Controller) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

Row (org.onosproject.ovsdb.rfc.notation.Row)30 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)23 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)19 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)17 HashMap (java.util.HashMap)13 OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)13 HashSet (java.util.HashSet)12 Map (java.util.Map)11 OvsdbBridge (org.onosproject.ovsdb.controller.OvsdbBridge)11 OvsdbSet (org.onosproject.ovsdb.rfc.notation.OvsdbSet)11 Bridge (org.onosproject.ovsdb.rfc.table.Bridge)11 Operation (org.onosproject.ovsdb.rfc.operations.Operation)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ConcurrentMap (java.util.concurrent.ConcurrentMap)9 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8 OvsdbPort (org.onosproject.ovsdb.controller.OvsdbPort)8 OvsdbTableStore (org.onosproject.ovsdb.controller.OvsdbTableStore)8 Condition (org.onosproject.ovsdb.rfc.notation.Condition)8 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)8