use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class DefaultKubevirtNodeHandler method createBridge.
/**
* Creates a bridge with a given name on a given kubernetes node.
*
* @param node kubevirt node
* @param bridgeName bridge name
* @param devId device identifier
*/
private void createBridge(KubevirtNode node, String bridgeName, DeviceId devId) {
Device device = deviceService.getDevice(node.ovsdb());
IpAddress controllerIp = apiConfigService.apiConfig().controllerIp();
String serviceFqdn = apiConfigService.apiConfig().serviceFqdn();
IpAddress serviceIp = null;
if (controllerIp == null) {
if (serviceFqdn != null) {
serviceIp = resolveHostname(serviceFqdn);
}
if (serviceIp != null) {
controllerIp = serviceIp;
} else {
controllerIp = apiConfigService.apiConfig().ipAddress();
}
}
ControllerInfo controlInfo = new ControllerInfo(controllerIp, DEFAULT_OFPORT, DEFAULT_OF_PROTO);
List<ControllerInfo> controllers = Lists.newArrayList(controlInfo);
String dpid = devId.toString().substring(DPID_BEGIN);
BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(bridgeName).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).disableInBand().controllers(controllers);
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
bridgeConfig.addBridge(builder.build());
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ServerControllerConfig method setControllers.
@Override
public void setControllers(List<ControllerInfo> controllers) {
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
MastershipService mastershipService = getHandler().get(MastershipService.class);
checkNotNull(mastershipService, MSG_MASTERSHIP_NULL);
if (!mastershipService.isLocalMaster(deviceId)) {
log.warn("I am not master for {}. " + "Please use master {} to set controllers for this device", deviceId, mastershipService.getMasterFor(deviceId));
return;
}
ObjectMapper mapper = new ObjectMapper();
// Create the object node to host the data
ObjectNode sendObjNode = mapper.createObjectNode();
// Insert header
ArrayNode ctrlsArrayNode = sendObjNode.putArray(PARAM_CTRL);
// Add each controller's information object
for (ControllerInfo ctrl : controllers) {
ObjectNode ctrlObjNode = mapper.createObjectNode();
ctrlObjNode.put(PARAM_CTRL_IP, ctrl.ip().toString());
ctrlObjNode.put(PARAM_CTRL_PORT, ctrl.port());
ctrlObjNode.put(PARAM_CTRL_TYPE, ctrl.type());
ctrlsArrayNode.add(ctrlObjNode);
}
// Post the controllers to the device
int response = getController().post(deviceId, URL_CONTROLLERS_SET, new ByteArrayInputStream(sendObjNode.toString().getBytes()), JSON);
if (!checkStatusCode(response)) {
log.error("Failed to set controllers on device {}", deviceId);
}
return;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ServerControllerConfig method removeControllers.
@Override
public void removeControllers(List<ControllerInfo> controllers) {
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
MastershipService mastershipService = getHandler().get(MastershipService.class);
checkNotNull(mastershipService, MSG_MASTERSHIP_NULL);
if (!mastershipService.isLocalMaster(deviceId)) {
log.warn("I am not master for {}. " + "Please use master {} to remove controllers from this device", deviceId, mastershipService.getMasterFor(deviceId));
return;
}
for (ControllerInfo ctrl : controllers) {
log.info("Remove controller with {}:{}:{}", ctrl.type(), ctrl.ip().toString(), ctrl.port());
String remCtrlUrl = URL_CONTROLLERS_DEL + SLASH + ctrl.ip().toString();
// Remove this controller
int response = getController().delete(deviceId, remCtrlUrl, null, JSON);
if (!checkStatusCode(response)) {
log.error("Failed to remove controller {}:{}:{} from device {}", ctrl.type(), ctrl.ip().toString(), ctrl.port(), deviceId);
}
}
return;
}
use of org.onosproject.net.behaviour.ControllerInfo 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.net.behaviour.ControllerInfo 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);
}
}
Aggregations