Search in sources :

Example 1 with DatabaseSchema

use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.

the class DefaultOvsdbClient method handlePortInsertTable.

/**
 * Handles port insert.
 *
 * @param portRow   row of port
 * @return insert, empty if null
 */
private Insert handlePortInsertTable(Row portRow) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    TableSchema portTableSchema = dbSchema.getTableSchema(PORT);
    ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name");
    String portName = (String) portRow.getColumn(portColumnSchema.name()).data();
    Interface inf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE);
    inf.setName(portName);
    TableSchema intfTableSchema = dbSchema.getTableSchema(INTERFACE);
    return new Insert(intfTableSchema, INTERFACE, inf.getRow());
}
Also used : TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Interface(org.onosproject.ovsdb.rfc.table.Interface) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 2 with DatabaseSchema

use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.

the class DefaultOvsdbClient method setControllersWithUuid.

private void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    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;
    }
    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);
        } else {
            removeControllers.add(controller);
        }
    });
    OvsdbRowStore controllerRowStore = getRowStore(DATABASENAME, CONTROLLER);
    if (controllerRowStore == null) {
        log.debug("There is no controller table");
        return;
    }
    newControllers.stream().map(c -> {
        Controller controller = (Controller) TableGenerator.createTable(dbSchema, OvsdbTable.CONTROLLER);
        controller.setTarget(c.target());
        return controller;
    }).forEach(c -> insertConfig(CONTROLLER, UUID, BRIDGE, BRIDGE_CONTROLLER, bridgeUuid.value(), c.getRow()));
    // Controller removal is extremely dangerous operation, because with
    // empty controller list, all existing flow rules will be wiped out.
    // To harden the setController operation, we need to double check whether
    // the updated controller list size is bigger than the remove controller list size
    List<Controller> updatedControllers = getControllers(bridgeUuid);
    if (updatedControllers != null && updatedControllers.size() > removeControllers.size()) {
        removeControllers.forEach(c -> deleteConfig(CONTROLLER, UUID, c.getRow().uuid().value(), BRIDGE, BRIDGE_CONTROLLER, c.getRow().uuid()));
    } else {
        log.warn("New controllers were not properly configured to OVS " + "bridge {} or failed to retrieve controller list from OVS " + "bridge {}", bridgeUuid, bridgeUuid);
    }
}
Also used : 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) ArrayList(java.util.ArrayList) Controller(org.onosproject.ovsdb.rfc.table.Controller) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema) HashSet(java.util.HashSet)

Example 3 with DatabaseSchema

use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.

the class DefaultOvsdbClient method getInterface.

private Interface getInterface(Row row) {
    DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
    Interface intf = (Interface) TableGenerator.getTable(dbSchema, row, OvsdbTable.INTERFACE);
    if (intf == null) {
        return null;
    }
    return intf;
}
Also used : Interface(org.onosproject.ovsdb.rfc.table.Interface) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 4 with DatabaseSchema

use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.

the class DefaultOvsdbClient method createQos.

@Override
public boolean createQos(OvsdbQos ovsdbQos) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    Qos qos = (Qos) TableGenerator.createTable(dbSchema, OvsdbTable.QOS);
    OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
    if (rowStore == null) {
        log.debug("The qos uuid is null");
        return false;
    }
    ArrayList<Operation> operations = Lists.newArrayList();
    Set<String> types = Sets.newHashSet();
    Map<Long, Uuid> queues = Maps.newHashMap();
    types.add(ovsdbQos.qosType());
    qos.setOtherConfig(ovsdbQos.otherConfigs());
    qos.setExternalIds(ovsdbQos.externalIds());
    qos.setType(types);
    if (ovsdbQos.qosQueues().isPresent()) {
        for (Map.Entry<Long, String> entry : ovsdbQos.qosQueues().get().entrySet()) {
            OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
            if (queueRowStore != null) {
                ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
                Row queueRow = queueTableRows.values().stream().filter(r -> {
                    OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
                    return entry.getValue().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
                }).findFirst().orElse(null);
                if (queueRow != null) {
                    queues.put(entry.getKey(), queueRow.uuid());
                }
            }
        }
        qos.setQueues(queues);
    }
    Insert qosInsert = new Insert(dbSchema.getTableSchema(QOS), QOS, qos.getRow());
    operations.add(qosInsert);
    try {
        transactConfig(DATABASENAME, operations).get();
    } catch (InterruptedException | ExecutionException e) {
        return false;
    }
    return true;
}
Also used : Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Qos(org.onosproject.ovsdb.rfc.table.Qos) OvsdbQos(org.onosproject.ovsdb.controller.OvsdbQos) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 5 with DatabaseSchema

use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.

the class DefaultOvsdbClient method bindQueues.

@Override
public void bindQueues(QosId qosId, Map<Long, QueueDescription> queues) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        log.debug("The qos uuid is null");
        return;
    }
    OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
    if (queueRowStore == null) {
        log.debug("The queue uuid is null");
        return;
    }
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
    ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
    Row qosRow = qosTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return qosId.name().equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    if (qosRow == null) {
        log.warn("Can't find QoS {}", qosId);
        return;
    }
    Uuid qosUuid = qosRow.uuid();
    Map<Long, Uuid> newQueues = new HashMap<>();
    for (Map.Entry<Long, QueueDescription> entry : queues.entrySet()) {
        Row queueRow = queueTableRows.values().stream().filter(r -> {
            OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
            return entry.getValue().queueId().name().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
        }).findFirst().orElse(null);
        if (queueRow != null) {
            newQueues.put(entry.getKey(), queueRow.uuid());
        }
    }
    // update the qos table
    ArrayList<Operation> operations = Lists.newArrayList();
    Condition condition = ConditionUtil.isEqual(UUID, qosUuid);
    Mutation mutation = MutationUtil.insert(QUEUES, newQueues);
    List<Condition> conditions = Collections.singletonList(condition);
    List<Mutation> mutations = Collections.singletonList(mutation);
    operations.add(new Mutate(dbSchema.getTableSchema(QOS), conditions, mutations));
    transactConfig(DATABASENAME, operations);
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) HashMap(java.util.HashMap) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)33 Row (org.onosproject.ovsdb.rfc.notation.Row)20 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)19 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)16 Operation (org.onosproject.ovsdb.rfc.operations.Operation)15 Condition (org.onosproject.ovsdb.rfc.notation.Condition)13 HashSet (java.util.HashSet)12 OvsdbBridge (org.onosproject.ovsdb.controller.OvsdbBridge)12 OvsdbPort (org.onosproject.ovsdb.controller.OvsdbPort)12 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)12 OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)12 OvsdbSet (org.onosproject.ovsdb.rfc.notation.OvsdbSet)12 Mutate (org.onosproject.ovsdb.rfc.operations.Mutate)12 Bridge (org.onosproject.ovsdb.rfc.table.Bridge)12 HashMap (java.util.HashMap)11 OvsdbInterface (org.onosproject.ovsdb.controller.OvsdbInterface)11 Insert (org.onosproject.ovsdb.rfc.operations.Insert)11 TableSchema (org.onosproject.ovsdb.rfc.schema.TableSchema)11 Interface (org.onosproject.ovsdb.rfc.table.Interface)11 Map (java.util.Map)10