Search in sources :

Example 6 with ControllerInfo

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());
}
Also used : ControllerConfig(org.onosproject.net.behaviour.ControllerConfig) DriverHandler(org.onosproject.net.driver.DriverHandler) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DriverService(org.onosproject.net.driver.DriverService)

Example 7 with ControllerInfo

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);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 8 with ControllerInfo

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));
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 9 with ControllerInfo

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);
    }
}
Also used : Device(org.onosproject.net.Device) IpAddress(org.onlab.packet.IpAddress) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 10 with ControllerInfo

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)38 ArrayList (java.util.ArrayList)19 DeviceId (org.onosproject.net.DeviceId)11 IpAddress (org.onlab.packet.IpAddress)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Test (org.junit.Test)7 Device (org.onosproject.net.Device)6 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)6 BridgeDescription (org.onosproject.net.behaviour.BridgeDescription)6 DefaultBridgeDescription (org.onosproject.net.behaviour.DefaultBridgeDescription)6 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Objects (java.util.Objects)5 Collectors (java.util.stream.Collectors)5 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)5 DriverHandler (org.onosproject.net.driver.DriverHandler)5 Logger (org.slf4j.Logger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4