use of org.onosproject.ovsdb.rfc.notation.Condition 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);
}
use of org.onosproject.ovsdb.rfc.notation.Condition in project onos by opennetworkinglab.
the class DefaultOvsdbClient method removeQos.
@Override
public void removeQos(PortNumber portNumber) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
OvsdbRowStore rowStore = getRowStore(DATABASENAME, PORT);
if (rowStore == null) {
log.debug("The qos uuid is null");
return;
}
ConcurrentMap<String, Row> ovsTableRows = rowStore.getRowStore();
Row portRow = ovsTableRows.values().stream().filter(r -> r.getColumn("name").data().equals(portNumber.name())).findFirst().orElse(null);
if (portRow == null) {
log.warn("Couldn't find port {} in ovsdb port table.", portNumber.name());
return;
}
OvsdbSet ovsdbSet = ((OvsdbSet) portRow.getColumn(PORT_QOS).data());
@SuppressWarnings("unchecked") Set<Uuid> qosIdSet = ovsdbSet.set();
if (qosIdSet == null || qosIdSet.isEmpty()) {
return;
}
Uuid qosUuid = (Uuid) qosIdSet.toArray()[0];
Condition condition = ConditionUtil.isEqual(UUID, portRow.uuid());
List<Condition> conditions = Lists.newArrayList(condition);
Mutation mutation = MutationUtil.delete(PORT_QOS, qosUuid);
List<Mutation> mutations = Lists.newArrayList(mutation);
ArrayList<Operation> operations = Lists.newArrayList();
Mutate mutate = new Mutate(dbSchema.getTableSchema(PORT), conditions, mutations);
operations.add(mutate);
transactConfig(DATABASENAME, operations);
}
use of org.onosproject.ovsdb.rfc.notation.Condition 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;
}
use of org.onosproject.ovsdb.rfc.notation.Condition in project onos by opennetworkinglab.
the class DefaultOvsdbClient method insertConfig.
/**
* Insert transact config.
*
* @param childTableName child table name
* @param childColumnName child column name
* @param parentTableName parent table name
* @param parentColumnName parent column
* @param parentUuid parent uuid
* @param row the config data
* @return uuid, empty if no uuid is find
*/
private String insertConfig(String childTableName, String childColumnName, String parentTableName, String parentColumnName, String parentUuid, Row row) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
TableSchema tableSchema = dbSchema.getTableSchema(childTableName);
Insert insert = new Insert(tableSchema, childTableName, row);
ArrayList<Operation> operations = Lists.newArrayList();
operations.add(insert);
if (parentTableName != null && parentColumnName != null) {
TableSchema parentTableSchema = dbSchema.getTableSchema(parentTableName);
ColumnSchema parentColumnSchema = parentTableSchema.getColumnSchema(parentColumnName);
List<Mutation> mutations = Lists.newArrayList();
Mutation mutation = MutationUtil.insert(parentColumnSchema.name(), Uuid.uuid(childTableName));
mutations.add(mutation);
List<Condition> conditions = Lists.newArrayList();
Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(parentUuid));
conditions.add(condition);
Mutate op = new Mutate(parentTableSchema, conditions, mutations);
operations.add(op);
}
if (childTableName.equalsIgnoreCase(PORT)) {
log.debug("Handle port insert");
Insert intfInsert = handlePortInsertTable(row);
if (intfInsert != null) {
operations.add(intfInsert);
}
Insert ins = (Insert) operations.get(0);
ins.getRow().put("interfaces", Uuid.uuid(INTERFACE));
}
List<OperationResult> results;
try {
results = transactConfig(DATABASENAME, operations).get(TRANSACTCONFIG_TIMEOUT, TimeUnit.SECONDS);
return results.get(0).getUuid().value();
} catch (TimeoutException e) {
log.warn("TimeoutException thrown while to get result");
} catch (InterruptedException e) {
log.warn("Interrupted while waiting to get result");
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
log.error("Exception thrown while to get result");
}
return null;
}
use of org.onosproject.ovsdb.rfc.notation.Condition in project onos by opennetworkinglab.
the class DefaultOvsdbClient method updateConfig.
/**
* Update transact config.
*
* @param tableName table name
* @param columnName column name
* @param uuid uuid
* @param row the config data
*/
private void updateConfig(String tableName, String columnName, String uuid, Row row) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
TableSchema tableSchema = dbSchema.getTableSchema(tableName);
List<Condition> conditions = Lists.newArrayList();
Condition condition = ConditionUtil.isEqual(columnName, Uuid.uuid(uuid));
conditions.add(condition);
Update update = new Update(tableSchema, row, conditions);
ArrayList<Operation> operations = Lists.newArrayList();
operations.add(update);
transactConfig(DATABASENAME, operations);
}
Aggregations