use of org.onosproject.ovsdb.controller.OvsdbConstant.CONTROLLER in project onos by opennetworkinglab.
the class DefaultOvsdbClient method setControllersWithUuid.
private void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
if (dbSchema == null) {
log.debug("There is no schema");
return;
}
List<Controller> oldControllers = getControllers(bridgeUuid);
if (oldControllers == null) {
log.warn("There are no controllers");
return;
}
Set<ControllerInfo> newControllers = new HashSet<>(controllers);
List<Controller> removeControllers = new ArrayList<>();
oldControllers.forEach(controller -> {
ControllerInfo controllerInfo = new ControllerInfo((String) controller.getTargetColumn().data());
if (newControllers.contains(controllerInfo)) {
newControllers.remove(controllerInfo);
} else {
removeControllers.add(controller);
}
});
OvsdbRowStore controllerRowStore = getRowStore(DATABASENAME, CONTROLLER);
if (controllerRowStore == null) {
log.debug("There is no controller table");
return;
}
newControllers.stream().map(c -> {
Controller controller = (Controller) TableGenerator.createTable(dbSchema, OvsdbTable.CONTROLLER);
controller.setTarget(c.target());
return controller;
}).forEach(c -> insertConfig(CONTROLLER, UUID, BRIDGE, BRIDGE_CONTROLLER, bridgeUuid.value(), c.getRow()));
// Controller removal is extremely dangerous operation, because with
// empty controller list, all existing flow rules will be wiped out.
// To harden the setController operation, we need to double check whether
// the updated controller list size is bigger than the remove controller list size
List<Controller> updatedControllers = getControllers(bridgeUuid);
if (updatedControllers != null && updatedControllers.size() > removeControllers.size()) {
removeControllers.forEach(c -> deleteConfig(CONTROLLER, UUID, c.getRow().uuid().value(), BRIDGE, BRIDGE_CONTROLLER, c.getRow().uuid()));
} else {
log.warn("New controllers were not properly configured to OVS " + "bridge {} or failed to retrieve controller list from OVS " + "bridge {}", bridgeUuid, bridgeUuid);
}
}
use of org.onosproject.ovsdb.controller.OvsdbConstant.CONTROLLER in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getControllers.
@Override
public Set<ControllerInfo> getControllers(DeviceId openflowDeviceId) {
Uuid bridgeUuid = getBridgeUuid(openflowDeviceId);
if (bridgeUuid == null) {
log.warn("bad bridge Uuid");
return null;
}
List<Controller> controllers = getControllers(bridgeUuid);
if (controllers == null) {
log.warn("bad list of controllers");
return null;
}
return controllers.stream().map(controller -> new ControllerInfo((String) controller.getTargetColumn().data())).collect(Collectors.toSet());
}
use of org.onosproject.ovsdb.controller.OvsdbConstant.CONTROLLER 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