use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class DeviceSetControllersCommand method doExecute.
@Override
protected void doExecute() {
if (controllersListStrings == null && !removeCont && !removeAll) {
print("No controller are given, skipping.");
return;
}
if (controllersListStrings != null) {
Arrays.asList(controllersListStrings).forEach(cInfoString -> {
ControllerInfo controllerInfo = parseCInfoString(cInfoString);
if (controllerInfo != null) {
controllers.add(controllerInfo);
}
});
}
DriverService service = get(DriverService.class);
deviceId = DeviceId.deviceId(uri);
DriverHandler h = service.createHandler(deviceId);
ControllerConfig config = h.behaviour(ControllerConfig.class);
print("before:");
config.getControllers().forEach(c -> print(c.target()));
try {
if (removeAll) {
if (!controllers.isEmpty()) {
print("Controllers list should be empty to remove all controllers");
} else {
List<ControllerInfo> controllersToRemove = config.getControllers();
controllersToRemove.forEach(c -> print("Will remove " + c.target()));
config.removeControllers(controllersToRemove);
}
} else {
if (controllers.isEmpty()) {
print("Controllers list is empty, cannot set/remove empty controllers");
} else {
if (removeCont) {
print("Will remove specified controllers");
config.removeControllers(controllers);
} else {
print("Will add specified controllers");
config.setControllers(controllers);
}
}
}
} catch (NullPointerException e) {
print("No Device with requested parameters {} ", uri);
}
print("after:");
config.getControllers().forEach(c -> print(c.target()));
print("size %d", config.getControllers().size());
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class FujitsuVoltControllerConfigTest method testSetControllers.
/**
* Run to verify handling of valid set operation.
*/
@Test
public void testSetControllers() throws Exception {
List<ControllerInfo> controllers = new ArrayList<>();
for (int i = ZERO; i < SET_CONTROLLERS.length; i++) {
String target = SET_CONTROLLERS[i];
String[] data = target.split(TEST_COLON);
currentKey = i + ONE;
Annotations annotations = DefaultAnnotations.builder().set(TEST_OFCONFIG_ID, currentKey.toString()).build();
ControllerInfo controller = new ControllerInfo(IpAddress.valueOf(data[SECOND_PART]), Integer.parseInt(data[THIRD_PART]), data[FIRST_PART], annotations);
controllers.add(controller);
}
voltConfig.setControllers(controllers);
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class FujitsuVoltControllerConfigTest method testGetControllers.
/**
* Run to verify handling of valid get operation.
*/
@Test
public void testGetControllers() throws Exception {
List<ControllerInfo> controllers;
List<ControllerInfo> expectedControllers = new ArrayList<>();
for (int i = ZERO; i < GET_CONTROLLERS.length; i++) {
String target = GET_CONTROLLERS[i];
String[] data = target.split(TEST_COLON);
currentKey = i + ONE;
Annotations annotations = DefaultAnnotations.builder().set(TEST_OFCONFIG_ID, currentKey.toString()).build();
ControllerInfo controller = new ControllerInfo(IpAddress.valueOf(data[SECOND_PART]), Integer.parseInt(data[THIRD_PART]), data[FIRST_PART], annotations);
expectedControllers.add(controller);
}
controllers = voltConfig.getControllers();
assertTrue("Incorrect response", controllers.equals(expectedControllers));
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class KubevirtNetworkHandler method createBridge.
private void createBridge(KubevirtNode node, KubevirtNetwork network) {
Device tenantBridge = deviceService.getDevice(network.tenantDeviceId(node.hostname()));
if (tenantBridge != null && deviceService.isAvailable(tenantBridge.id())) {
log.warn("The tenant bridge {} already exists at node {}", network.tenantBridgeName(), node.hostname());
return;
}
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 = network.tenantDeviceId(node.hostname()).toString().substring(DPID_BEGIN);
// if the bridge is already available, we skip creating a new bridge
if (!deviceService.isAvailable(DeviceId.deviceId(dpid))) {
BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(network.tenantBridgeName()).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).disableInBand().controllers(controllers);
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
bridgeConfig.addBridge(builder.build());
log.info("Created a new tunnel bridge for network {} at node {}", network.networkId(), node.hostname());
waitFor(3);
}
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ControllerConfigCiscoImpl method getControllers.
@Override
public List<ControllerInfo> getControllers() {
List<ControllerInfo> controllers = new ArrayList<ControllerInfo>();
DeviceId deviceId = handler().data().deviceId();
String response;
// "show openflow switch 1 controller" command only shows outputs with cli_ascii command type
response = NxApiRequest.post(handler(), SHOW_OF_CONTROLLER_CMD, CommandType.CLI_ASCII);
if (response == null) {
log.error("Failed to perform {} command on the device {} Response has Error/null", SHOW_OF_CONTROLLER_CMD, deviceId);
return controllers;
}
try {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(response);
if (json.has("result")) {
JsonNode res = json.get("result");
String msg = res.findValue("msg").asText();
controllers.addAll(parseControllerInfo(msg));
} else if (json.has("error")) {
log.error("{} Response has IllegalStateException Error/null", deviceId);
return controllers;
}
} catch (IOException e) {
log.error("Exception thrown", e);
}
return controllers;
}
Aggregations