Search in sources :

Example 6 with OvsdbMap

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

the class DefaultOvsdbClient method getMirrorings.

/**
 * Helper method which retrieves mirrorings statistics using bridge uuid.
 *
 * @param bridgeUuid the uuid of the bridge
 * @return the list of the mirrorings statistics.
 */
private List<MirroringStatistics> getMirrorings(Uuid bridgeUuid) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    if (dbSchema == null) {
        log.warn("Unable to retrieve dbSchema {}", DATABASENAME);
        return null;
    }
    OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE);
    if (rowStore == null) {
        log.warn("Unable to retrieve rowStore {} of {}", BRIDGE, DATABASENAME);
        return null;
    }
    Row bridgeRow = rowStore.getRow(bridgeUuid.value());
    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
    Set<Uuid> mirroringsUuids = (Set<Uuid>) ((OvsdbSet) bridge.getMirrorsColumn().data()).set();
    OvsdbRowStore mirrorRowStore = getRowStore(DATABASENAME, MIRROR);
    if (mirrorRowStore == null) {
        log.warn("Unable to retrieve rowStore {} of {}", MIRROR, DATABASENAME);
        return null;
    }
    List<MirroringStatistics> mirroringStatistics = new ArrayList<>();
    ConcurrentMap<String, Row> mirrorTableRows = mirrorRowStore.getRowStore();
    mirrorTableRows.forEach((key, row) -> {
        if (!mirroringsUuids.contains(Uuid.uuid(key))) {
            return;
        }
        Mirror mirror = (Mirror) TableGenerator.getTable(dbSchema, row, OvsdbTable.MIRROR);
        mirroringStatistics.add(MirroringStatistics.mirroringStatistics(mirror.getName(), (Map<String, Integer>) ((OvsdbMap) mirror.getStatisticsColumn().data()).map()));
    });
    return ImmutableList.copyOf(mirroringStatistics);
}
Also used : 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) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Row(org.onosproject.ovsdb.rfc.notation.Row) MirroringStatistics(org.onosproject.net.behaviour.MirroringStatistics) Mirror(org.onosproject.ovsdb.rfc.table.Mirror) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 7 with OvsdbMap

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

the class DefaultOvsdbClient method getIfaceid.

private String getIfaceid(Interface intf) {
    OvsdbMap ovsdbMap = (OvsdbMap) intf.getExternalIdsColumn().data();
    @SuppressWarnings("unchecked") Map<String, String> externalIds = ovsdbMap.map();
    if (externalIds.isEmpty()) {
        log.warn("The external_ids is null");
        return null;
    }
    String ifaceid = externalIds.get(EXTERNAL_ID_INTERFACE_ID);
    if (ifaceid == null) {
        log.warn("The ifaceid is null");
        return null;
    }
    return ifaceid;
}
Also used : OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap)

Example 8 with OvsdbMap

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

the class DefaultOvsdbClient method dropQos.

@Override
public void dropQos(QosId qosId) {
    OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
    if (rowStore != null) {
        ConcurrentMap<String, Row> qosTableRows = rowStore.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) {
            deleteConfig(QOS, UUID, qosRow.uuid().value(), PORT, PORT_QOS, qosRow.uuid());
        }
    }
}
Also used : OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore)

Example 9 with OvsdbMap

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

the class DefaultOvsdbClient method dropQueue.

@Override
public void dropQueue(QueueId queueId) {
    OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
    if (queueRowStore == null) {
        return;
    }
    ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
    Row queueRow = queueTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return queueId.name().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    if (queueRow == null) {
        return;
    }
    String queueUuid = queueRow.uuid().value();
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore != null) {
        Map<Long, Uuid> queueMap = new HashMap<>();
        ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
        qosTableRows.values().stream().filter(r -> {
            Map<Integer, Uuid> ovsdbMap = ((OvsdbMap) r.getColumn(QUEUES).data()).map();
            Set<Integer> keySet = ovsdbMap.keySet();
            for (Integer keyId : keySet) {
                if (ovsdbMap.get(keyId).equals(Uuid.uuid(queueUuid))) {
                    queueMap.put(keyId.longValue(), Uuid.uuid(queueUuid));
                    return true;
                }
            }
            return false;
        }).findFirst().orElse(null);
        deleteConfig(QUEUE, UUID, queueUuid, QOS, QUEUES, OvsdbMap.ovsdbMap(queueMap));
    } else {
        deleteConfig(QUEUE, UUID, queueUuid, null, null, null);
    }
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) HashMap(java.util.HashMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore)

Example 10 with OvsdbMap

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

Aggregations

OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)12 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)7 Row (org.onosproject.ovsdb.rfc.notation.Row)7 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)5 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 Operation (org.onosproject.ovsdb.rfc.operations.Operation)3 Set (java.util.Set)2 OvsdbPort (org.onosproject.ovsdb.controller.OvsdbPort)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1