Search in sources :

Example 1 with ControllerConfig

use of org.onosproject.net.behaviour.ControllerConfig 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 2 with ControllerConfig

use of org.onosproject.net.behaviour.ControllerConfig in project onos by opennetworkinglab.

the class DeviceControllersCommand method doExecute.

@Override
protected void doExecute() {
    DriverService service = get(DriverService.class);
    deviceId = DeviceId.deviceId(uri);
    DriverHandler h = service.createHandler(deviceId);
    ControllerConfig config = h.behaviour(ControllerConfig.class);
    config.getControllers().forEach(c -> print(c.target()));
}
Also used : ControllerConfig(org.onosproject.net.behaviour.ControllerConfig) DriverHandler(org.onosproject.net.driver.DriverHandler) DriverService(org.onosproject.net.driver.DriverService)

Aggregations

ControllerConfig (org.onosproject.net.behaviour.ControllerConfig)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 DriverService (org.onosproject.net.driver.DriverService)2 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)1