Search in sources :

Example 1 with PowerConfig

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

the class RoadmManager method getPowerConfig.

private PowerConfig<Object> getPowerConfig(DeviceId deviceId) {
    Device device = deviceService.getDevice(deviceId);
    if (device != null && device.is(PowerConfig.class)) {
        return device.as(PowerConfig.class);
    }
    // Do not need warning here for port polling.
    log.debug("Unable to load PowerConfig for {}", deviceId);
    return null;
}
Also used : Device(org.onosproject.net.Device) PowerConfig(org.onosproject.net.behaviour.PowerConfig)

Example 2 with PowerConfig

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

the class PowerConfigCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    DeviceService deviceService = get(DeviceService.class);
    ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPoint);
    Port port = deviceService.getPort(cp);
    if (port == null) {
        print("[ERROR] %s does not exist", cp);
        return;
    }
    if (!port.type().equals(Port.Type.OCH) && !port.type().equals(Port.Type.OTU) && !port.type().equals(Port.Type.OMS)) {
        log.warn("The power of selected port %s isn't editable.", port.number().toString());
        print("The power of selected port %s isn't editable.", port.number().toString());
        return;
    }
    Device device = deviceService.getDevice(cp.deviceId());
    PowerConfig powerConfig = device.as(PowerConfig.class);
    // <component> and <optical-channel>.
    if (operation.equals("get")) {
        Optional<Double> val = powerConfig.getTargetPower(cp.port(), Direction.ALL);
        if (val.isPresent()) {
            double power = val.orElse(Double.MIN_VALUE);
            print("The target-output-power value in port %s on device %s is %f.", cp.port().toString(), cp.deviceId().toString(), power);
        }
        Optional<Double> currentPower = powerConfig.currentPower(cp.port(), Direction.ALL);
        if (currentPower.isPresent()) {
            double currentPowerVal = currentPower.orElse(Double.MIN_VALUE);
            print("The current-output-power value in port %s on device %s is %f.", cp.port().toString(), cp.deviceId().toString(), currentPowerVal);
        }
        Optional<Double> currentInputPower = powerConfig.currentInputPower(cp.port(), Direction.ALL);
        if (currentInputPower.isPresent()) {
            double inputPowerVal = currentInputPower.orElse(Double.MIN_VALUE);
            print("The current-input-power value in port %s on device %s is %f.", cp.port().toString(), cp.deviceId().toString(), inputPowerVal);
        }
    } else if (operation.equals("edit-config")) {
        checkNotNull(value);
        powerConfig.setTargetPower(cp.port(), Direction.ALL, value);
        print("Set %f power on port", value, connectPoint);
    } else {
        print("Operation %s are not supported now.", operation);
    }
}
Also used : Device(org.onosproject.net.Device) PowerConfig(org.onosproject.net.behaviour.PowerConfig) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

Device (org.onosproject.net.Device)2 PowerConfig (org.onosproject.net.behaviour.PowerConfig)2 ConnectPoint (org.onosproject.net.ConnectPoint)1 Port (org.onosproject.net.Port)1 DeviceService (org.onosproject.net.device.DeviceService)1