Search in sources :

Example 16 with DatabaseSchema

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

the class DefaultOvsdbClient method applyQos.

@Override
public void applyQos(PortNumber portNumber, String qosName) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore portRowStore = getRowStore(DATABASENAME, PORT);
    if (portRowStore == null) {
        log.debug("The port uuid is null");
        return;
    }
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        log.debug("The qos uuid is null");
        return;
    }
    // Due to Qos Table doesn't have a unique identifier except uuid, unlike
    // Bridge or Port Table has a name column,in order to make the api more
    // general, put qos name in external_ids column of Qos Table if this qos
    // created by onos.
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
    ConcurrentMap<String, Row> portTableRows = portRowStore.getRowStore();
    Row qosRow = qosTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return qosName.equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    Row portRow = portTableRows.values().stream().filter(r -> r.getColumn("name").data().equals(portNumber.name())).findFirst().orElse(null);
    if (portRow != null && qosRow != null) {
        String qosId = qosRow.uuid().value();
        Uuid portUuid = portRow.uuid();
        Map<String, Column> columns = new HashMap<>();
        Row newPortRow = new Row(PORT, portUuid, columns);
        Port newport = new Port(dbSchema, newPortRow);
        columns.put(Port.PortColumn.QOS.columnName(), newport.getQosColumn());
        newport.setQos(Uuid.uuid(qosId));
        updateConfig(PORT, UUID, portUuid.value(), newport.getRow());
    }
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Column(org.onosproject.ovsdb.rfc.notation.Column) HashMap(java.util.HashMap) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) Port(org.onosproject.ovsdb.rfc.table.Port) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 17 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 18 with DatabaseSchema

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

the class DefaultOvsdbClient method getMirrorUuid.

@Override
public String getMirrorUuid(String mirrorName) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore rowStore = getRowStore(DATABASENAME, MIRROR);
    if (rowStore == null) {
        log.warn("The mirror uuid is null");
        return null;
    }
    ConcurrentMap<String, Row> mirrorTableRows = rowStore.getRowStore();
    if (mirrorTableRows == null) {
        log.warn("The mirror uuid is null");
        return null;
    }
    for (String uuid : mirrorTableRows.keySet()) {
        Mirror mirror = (Mirror) TableGenerator.getTable(dbSchema, mirrorTableRows.get(uuid), OvsdbTable.MIRROR);
        String name = mirror.getName();
        if (name.contains(mirrorName)) {
            return uuid;
        }
    }
    log.warn("Mirroring not found");
    return null;
}
Also used : Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Mirror(org.onosproject.ovsdb.rfc.table.Mirror) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 19 with DatabaseSchema

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

the class DefaultOvsdbClient method getOvsdbQueue.

private OvsdbQueue getOvsdbQueue(Row row) {
    DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
    Queue queue = (Queue) TableGenerator.getTable(dbSchema, row, OvsdbTable.QUEUE);
    if (queue == null) {
        return null;
    }
    OvsdbSet dscpOvsdbSet = ((OvsdbSet) queue.getDscpColumn().data());
    Set dscpSet = dscpOvsdbSet.set();
    Long dscp = null;
    if (dscpSet != null && !dscpSet.isEmpty()) {
        dscp = Long.valueOf(dscpSet.toArray()[0].toString());
    }
    Map<String, String> otherConfigs;
    Map<String, String> externalIds;
    otherConfigs = ((OvsdbMap) queue.getOtherConfigColumn().data()).map();
    externalIds = ((OvsdbMap) queue.getExternalIdsColumn().data()).map();
    return OvsdbQueue.builder().dscp(dscp).otherConfigs(otherConfigs).externalIds(externalIds).build();
}
Also used : OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) OvsdbQueue(org.onosproject.ovsdb.controller.OvsdbQueue) Queue(org.onosproject.ovsdb.rfc.table.Queue) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 20 with DatabaseSchema

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

the class DefaultOvsdbClient method getControllers.

private List<Controller> getControllers(Uuid bridgeUuid) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    if (dbSchema == null) {
        return null;
    }
    OvsdbRowStore rowStore = getRowStore(DATABASENAME, 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();
    OvsdbRowStore controllerRowStore = getRowStore(DATABASENAME, 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;
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) ArrayList(java.util.ArrayList) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Controller(org.onosproject.ovsdb.rfc.table.Controller) 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