Search in sources :

Example 6 with Uuid

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

the class DefaultOvsdbClient method createMirror.

@Override
public boolean createMirror(String bridgeName, OvsdbMirror mirror) {
    /**
     * Retrieves bridge's uuid. It is necessary to update
     * Bridge table.
     */
    String bridgeUuid = getBridgeUuid(bridgeName);
    if (bridgeUuid == null) {
        log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress());
        return false;
    }
    OvsdbMirror.Builder mirrorBuilder = OvsdbMirror.builder();
    mirrorBuilder.mirroringName(mirror.mirroringName());
    mirrorBuilder.selectAll(mirror.selectAll());
    /**
     * Retrieves the uuid of the monitored dst ports.
     */
    mirrorBuilder.monitorDstPorts(mirror.monitorDstPorts().parallelStream().map(dstPort -> {
        String dstPortUuid = getPortUuid(dstPort.value(), bridgeUuid);
        if (dstPortUuid != null) {
            return Uuid.uuid(dstPortUuid);
        }
        log.warn("Couldn't find port {} in {}", dstPort.value(), nodeId.getIpAddress());
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toSet()));
    /**
     * Retrieves the uuid of the monitored src ports.
     */
    mirrorBuilder.monitorSrcPorts(mirror.monitorSrcPorts().parallelStream().map(srcPort -> {
        String srcPortUuid = getPortUuid(srcPort.value(), bridgeUuid);
        if (srcPortUuid != null) {
            return Uuid.uuid(srcPortUuid);
        }
        log.warn("Couldn't find port {} in {}", srcPort.value(), nodeId.getIpAddress());
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toSet()));
    mirrorBuilder.monitorVlans(mirror.monitorVlans());
    mirrorBuilder.mirrorPort(mirror.mirrorPort());
    mirrorBuilder.mirrorVlan(mirror.mirrorVlan());
    mirrorBuilder.externalIds(mirror.externalIds());
    mirror = mirrorBuilder.build();
    if (mirror.monitorDstPorts().isEmpty() && mirror.monitorSrcPorts().isEmpty() && mirror.monitorVlans().isEmpty()) {
        log.warn("Invalid monitoring data");
        return false;
    }
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    Mirror mirrorEntry = (Mirror) TableGenerator.createTable(dbSchema, OvsdbTable.MIRROR);
    mirrorEntry.setName(mirror.mirroringName());
    mirrorEntry.setSelectDstPort(mirror.monitorDstPorts());
    mirrorEntry.setSelectSrcPort(mirror.monitorSrcPorts());
    mirrorEntry.setSelectVlan(mirror.monitorVlans());
    mirrorEntry.setExternalIds(mirror.externalIds());
    /**
     * If mirror port, retrieves the uuid of the mirror port.
     */
    if (mirror.mirrorPort() != null) {
        String outputPortUuid = getPortUuid(mirror.mirrorPort().value(), bridgeUuid);
        if (outputPortUuid == null) {
            log.warn("Couldn't find port {} in {}", mirror.mirrorPort().value(), nodeId.getIpAddress());
            return false;
        }
        mirrorEntry.setOutputPort(Uuid.uuid(outputPortUuid));
    } else if (mirror.mirrorVlan() != null) {
        mirrorEntry.setOutputVlan(mirror.mirrorVlan());
    } else {
        log.warn("Invalid mirror, no mirror port and no mirror vlan");
        return false;
    }
    ArrayList<Operation> operations = Lists.newArrayList();
    Insert mirrorInsert = new Insert(dbSchema.getTableSchema("Mirror"), "Mirror", mirrorEntry.getRow());
    operations.add(mirrorInsert);
    // update the bridge table
    Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid));
    Mutation mutation = MutationUtil.insert(MIRRORS, Uuid.uuid("Mirror"));
    List<Condition> conditions = Lists.newArrayList(condition);
    List<Mutation> mutations = Lists.newArrayList(mutation);
    operations.add(new Mutate(dbSchema.getTableSchema("Bridge"), conditions, mutations));
    transactConfig(DATABASENAME, operations);
    log.info("Created mirror {}", mirror.mirroringName());
    return true;
}
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) Condition(org.onosproject.ovsdb.rfc.notation.Condition) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Objects(java.util.Objects) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) Mirror(org.onosproject.ovsdb.rfc.table.Mirror) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 7 with Uuid

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

the class DefaultOvsdbClient method getBridgeUuid.

private Uuid getBridgeUuid(DeviceId openflowDeviceId) {
    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;
    }
    ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
    final AtomicReference<Uuid> uuid = new AtomicReference<>();
    for (Map.Entry<String, Row> entry : bridgeTableRows.entrySet()) {
        Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, entry.getValue(), OvsdbTable.BRIDGE);
        if (matchesDpid(bridge, openflowDeviceId)) {
            uuid.set(Uuid.uuid(entry.getKey()));
            break;
        }
    }
    if (uuid.get() == null) {
        log.debug("There is no bridge for {}", openflowDeviceId);
    }
    return uuid.get();
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) AtomicReference(java.util.concurrent.atomic.AtomicReference) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) 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 8 with Uuid

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

Example 9 with Uuid

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

the class FromJsonUtil method jsonNodeToTableUpdate.

/**
 * convert the params of Update Notification into TableUpdate.
 * @param tableSchema TableSchema entity
 * @param updateJson the table-update in params of Update Notification
 * @return TableUpdate
 */
public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, JsonNode updateJson) {
    Map<Uuid, RowUpdate> rows = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> tableUpdateItr = updateJson.fields();
    while (tableUpdateItr.hasNext()) {
        Map.Entry<String, JsonNode> oldNewRow = tableUpdateItr.next();
        String uuidStr = oldNewRow.getKey();
        Uuid uuid = Uuid.uuid(uuidStr);
        JsonNode newR = oldNewRow.getValue().get("new");
        JsonNode oldR = oldNewRow.getValue().get("old");
        Row newRow = newR != null ? createRow(tableSchema, uuid, newR) : null;
        Row oldRow = oldR != null ? createRow(tableSchema, uuid, oldR) : null;
        RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow);
        rows.put(uuid, rowUpdate);
    }
    return TableUpdate.tableUpdate(rows);
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) JsonNode(com.fasterxml.jackson.databind.JsonNode) RowUpdate(org.onosproject.ovsdb.rfc.message.RowUpdate) Row(org.onosproject.ovsdb.rfc.notation.Row) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with Uuid

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

Aggregations

Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)22 Row (org.onosproject.ovsdb.rfc.notation.Row)21 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)19 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)18 HashMap (java.util.HashMap)16 OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)16 Map (java.util.Map)14 OvsdbSet (org.onosproject.ovsdb.rfc.notation.OvsdbSet)14 ConcurrentMap (java.util.concurrent.ConcurrentMap)13 OvsdbBridge (org.onosproject.ovsdb.controller.OvsdbBridge)13 Operation (org.onosproject.ovsdb.rfc.operations.Operation)13 Bridge (org.onosproject.ovsdb.rfc.table.Bridge)13 HashSet (java.util.HashSet)12 Set (java.util.Set)12 Condition (org.onosproject.ovsdb.rfc.notation.Condition)12 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)12 Mutate (org.onosproject.ovsdb.rfc.operations.Mutate)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 MirroringStatistics (org.onosproject.net.behaviour.MirroringStatistics)11