Search in sources :

Example 26 with DatabaseSchema

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

the class DefaultOvsdbClient method getLocalPorts.

@Override
public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) {
    Set<OvsdbPort> ovsdbPorts = new HashSet<>();
    OvsdbTableStore tableStore = getTableStore(DATABASENAME);
    if (tableStore == null) {
        return null;
    }
    OvsdbRowStore rowStore = tableStore.getRows(INTERFACE);
    if (rowStore == null) {
        return null;
    }
    ConcurrentMap<String, Row> rows = rowStore.getRowStore();
    for (String uuid : rows.keySet()) {
        Row row = getRow(DATABASENAME, INTERFACE, uuid);
        DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
        Interface intf = (Interface) TableGenerator.getTable(dbSchema, row, OvsdbTable.INTERFACE);
        if (intf == null || getIfaceid(intf) == null) {
            continue;
        }
        String portName = intf.getName();
        if (portName == null) {
            continue;
        }
        Set<String> ifaceidSet = Sets.newHashSet(ifaceids);
        if (portName.startsWith(TYPEVXLAN) || !ifaceidSet.contains(getIfaceid(intf))) {
            continue;
        }
        long ofPort = getOfPort(intf);
        if (ofPort < 0) {
            continue;
        }
        ovsdbPorts.add(new OvsdbPort(new OvsdbPortNumber(ofPort), new OvsdbPortName(portName)));
    }
    return ovsdbPorts;
}
Also used : OvsdbTableStore(org.onosproject.ovsdb.controller.OvsdbTableStore) OvsdbPortNumber(org.onosproject.ovsdb.controller.OvsdbPortNumber) OvsdbPortName(org.onosproject.ovsdb.controller.OvsdbPortName) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) Row(org.onosproject.ovsdb.rfc.notation.Row) Interface(org.onosproject.ovsdb.rfc.table.Interface) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) HashSet(java.util.HashSet) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 27 with DatabaseSchema

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

the class DefaultOvsdbClient method getFirstRow.

@Override
public Optional<Object> getFirstRow(String dbName, OvsdbTable tblName) {
    DatabaseSchema dbSchema = getDatabaseSchema(dbName);
    if (Objects.isNull(dbSchema)) {
        return Optional.empty();
    }
    OvsdbTableStore tableStore = ovsdbStore.getOvsdbTableStore(dbName);
    if (tableStore == null) {
        return Optional.empty();
    }
    OvsdbRowStore rowStore = tableStore.getRows(tblName.tableName());
    if (rowStore == null) {
        return Optional.empty();
    }
    ConcurrentMap<String, Row> rows = rowStore.getRowStore();
    if (rows == null) {
        log.debug("The {} Table Rows is null", tblName);
        return Optional.empty();
    }
    // There should be only 1 row in this table
    Optional<String> uuid = rows.keySet().stream().findFirst();
    if (uuid.isPresent() && rows.containsKey(uuid.get())) {
        return Optional.of(TableGenerator.getTable(dbSchema, rows.get(uuid.get()), tblName));
    } else {
        return Optional.empty();
    }
}
Also used : OvsdbTableStore(org.onosproject.ovsdb.controller.OvsdbTableStore) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 28 with DatabaseSchema

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

the class DefaultOvsdbClient method unbindQueues.

@SuppressWarnings("unchecked")
@Override
public void unbindQueues(QosId qosId, List<Long> queueKeys) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        return;
    }
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.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;
    }
    Map<Long, Uuid> deleteQueuesMap;
    Map<Integer, Uuid> queuesMap = ((OvsdbMap) qosRow.getColumn(QUEUES).data()).map();
    deleteQueuesMap = queueKeys.stream().filter(key -> queuesMap.containsKey(key.intValue())).collect(Collectors.toMap(key -> key, key -> queuesMap.get(key.intValue()), (a, b) -> b));
    if (deleteQueuesMap.size() != 0) {
        TableSchema parentTableSchema = dbSchema.getTableSchema(QOS);
        ColumnSchema parentColumnSchema = parentTableSchema.getColumnSchema(QUEUES);
        Mutation mutation = MutationUtil.delete(parentColumnSchema.name(), OvsdbMap.ovsdbMap(deleteQueuesMap));
        List<Mutation> mutations = Collections.singletonList(mutation);
        Condition condition = ConditionUtil.isEqual(UUID, qosRow.uuid());
        List<Condition> conditionList = Collections.singletonList(condition);
        List<Operation> operations = Collections.singletonList(new Mutate(parentTableSchema, conditionList, mutations));
        transactConfig(DATABASENAME, operations);
    }
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) 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) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 29 with DatabaseSchema

use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema 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 30 with DatabaseSchema

use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema 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)

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