use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.
the class OvsdbControllerImpl method getDataPathid.
/**
* Gets datapathid from table bridge.
*
* @param clientService OvsdbClientService instance
* @param dbSchema ovsdb database schema
* @return datapathid the bridge datapathid
*/
private long getDataPathid(OvsdbClientService clientService, DatabaseSchema dbSchema) {
String bridgeUuid = clientService.getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE);
if (bridgeUuid == null) {
log.debug("Unable to spot bridge uuid for {} in {}", OvsdbConstant.INTEGRATION_BRIDGE, clientService);
return 0;
}
Row bridgeRow = clientService.getRow(OvsdbConstant.DATABASENAME, "Bridge", bridgeUuid);
Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
OvsdbSet dpidSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
@SuppressWarnings("unchecked") Set<String> dpids = dpidSet.set();
if (dpids == null || dpids.isEmpty()) {
return 0;
}
return stringToLong((String) dpids.toArray()[0]);
}
use of org.onosproject.ovsdb.rfc.notation.Row 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.notation.Row in project onos by opennetworkinglab.
the class FromJsonUtil method createRow.
/**
* Convert Operation JsonNode into Row.
* @param tableSchema TableSchema entity
* @param rowNode JsonNode
* @return Row
*/
private static Row createRow(TableSchema tableSchema, Uuid uuid, JsonNode rowNode) {
if (tableSchema == null) {
return null;
}
Map<String, Column> columns = Maps.newHashMap();
Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields();
while (rowIter.hasNext()) {
Map.Entry<String, JsonNode> next = rowIter.next();
ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey());
if (columnSchema != null) {
String columnName = columnSchema.name();
Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type());
columns.put(columnName, new Column(columnName, obj));
}
}
return new Row(tableSchema.name(), uuid, columns);
}
use of org.onosproject.ovsdb.rfc.notation.Row 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;
}
use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getOvsdbBridge.
private OvsdbBridge getOvsdbBridge(Row row, Uuid bridgeUuid) {
DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, OvsdbTable.BRIDGE);
if (bridge == null) {
return null;
}
OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
@SuppressWarnings("unchecked") Set<String> datapathIds = datapathIdSet.set();
if (datapathIds == null || datapathIds.isEmpty()) {
return null;
}
String datapathId = (String) datapathIds.toArray()[0];
String bridgeName = bridge.getName();
if ((datapathId == null) || (bridgeName == null)) {
return null;
}
List<Controller> controllers = getControllers(bridgeUuid);
if (controllers != null) {
List<ControllerInfo> controllerInfos = controllers.stream().map(controller -> new ControllerInfo((String) controller.getTargetColumn().data())).collect(Collectors.toList());
return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).controllers(controllerInfos).build();
} else {
return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).build();
}
}
Aggregations