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;
}
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();
}
}
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);
}
}
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());
}
}
}
}
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;
}
Aggregations