use of org.onosproject.ovsdb.controller.OvsdbBridge in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createBridge.
@Override
public boolean createBridge(OvsdbBridge ovsdbBridge) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
String ovsUuid = getOvsUuid(DATABASENAME);
if (dbSchema == null || ovsUuid == null) {
log.error("Can't find database Open_vSwitch");
return false;
}
Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE);
bridge.setOtherConfig(ovsdbBridge.otherConfigs());
if (ovsdbBridge.failMode().isPresent()) {
String failMode = ovsdbBridge.failMode().get().name().toLowerCase();
bridge.setFailMode(Sets.newHashSet(failMode));
}
if (ovsdbBridge.datapathType().isPresent()) {
String datapathType = ovsdbBridge.datapathType().get();
bridge.setDatapathType(datapathType);
}
if (ovsdbBridge.controlProtocols().isPresent()) {
bridge.setProtocols(ovsdbBridge.controlProtocols().get().stream().map(ControlProtocolVersion::toString).collect(Collectors.toCollection(HashSet::new)));
}
if (ovsdbBridge.mcastSnoopingEnable().isPresent()) {
boolean mcastSnoopingFlag = ovsdbBridge.mcastSnoopingEnable().get();
bridge.setMcastSnoopingEnable(mcastSnoopingFlag);
}
String bridgeUuid = getBridgeUuid(ovsdbBridge.name());
if (bridgeUuid == null) {
bridge.setName(ovsdbBridge.name());
bridgeUuid = insertConfig(BRIDGE, UUID, DATABASENAME, BRIDGES, ovsUuid, bridge.getRow());
} else {
// update the bridge if it's already existing
updateConfig(BRIDGE, UUID, bridgeUuid, bridge.getRow());
}
if (bridgeUuid == null) {
log.warn("Failed to create bridge {} on {}", ovsdbBridge.name(), nodeId);
return false;
}
createPort(ovsdbBridge.name(), ovsdbBridge.name());
setControllersWithUuid(Uuid.uuid(bridgeUuid), ovsdbBridge.controllers());
log.info("Created bridge {}", ovsdbBridge.name());
return true;
}
use of org.onosproject.ovsdb.controller.OvsdbBridge in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getBridges.
@Override
public Set<OvsdbBridge> getBridges() {
Set<OvsdbBridge> ovsdbBridges = new HashSet<>();
OvsdbTableStore tableStore = getTableStore(DATABASENAME);
if (tableStore == null) {
return ovsdbBridges;
}
OvsdbRowStore rowStore = tableStore.getRows(BRIDGE);
if (rowStore == null) {
return ovsdbBridges;
}
ConcurrentMap<String, Row> rows = rowStore.getRowStore();
for (String uuid : rows.keySet()) {
Row bridgeRow = getRow(DATABASENAME, BRIDGE, uuid);
OvsdbBridge ovsdbBridge = getOvsdbBridge(bridgeRow, Uuid.uuid(uuid));
if (ovsdbBridge != null) {
ovsdbBridges.add(ovsdbBridge);
}
}
return ovsdbBridges;
}
use of org.onosproject.ovsdb.controller.OvsdbBridge in project onos by opennetworkinglab.
the class OvsdbBridgeConfig method getBridges.
@Override
public Collection<BridgeDescription> getBridges() {
OvsdbClientService client = getOvsdbClientService(handler());
if (client == null) {
return Collections.emptyList();
}
Set<OvsdbBridge> bridges = client.getBridges();
return bridges.stream().map(bridge -> DefaultBridgeDescription.builder().name(bridge.name()).datapathId(bridge.datapathId().get()).build()).collect(Collectors.toSet());
}
use of org.onosproject.ovsdb.controller.OvsdbBridge 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