Jimmy Yan
Committed by Gerrit Code Review

Add range checking methods to PowerConfig

Change-Id: I8c113df90a8225db34256856cb2eb80ee7d68a9e
......@@ -15,6 +15,8 @@
*/
package org.onosproject.net.behaviour;
import com.google.common.annotations.Beta;
import com.google.common.collect.Range;
import org.onosproject.net.PortNumber;
import org.onosproject.net.driver.HandlerBehaviour;
......@@ -29,6 +31,7 @@ import java.util.Optional;
*
* Power levels are specified with a long and unit .01 dBm.
*/
@Beta
public interface PowerConfig<T> extends HandlerBehaviour {
/**
......@@ -43,7 +46,6 @@ public interface PowerConfig<T> extends HandlerBehaviour {
/**
* Set the target power on the component.
*
*
* @param port the port
* @param component the port component
* @param power target power in .01 dBm
......@@ -58,4 +60,31 @@ public interface PowerConfig<T> extends HandlerBehaviour {
* @return power power in .01 dBm
*/
Optional<Long> currentPower(PortNumber port, T component);
/**
* Get the acceptable target power range for setTargetPower,
* as optical components have different configurable output power ranges.
*
* @param port the port
* @param component the port component
* @return the accepted target power range, null if the component's power is
* not configurable. For example the port target power can only be set on TX ports.
*/
default Optional<Range<Long>> getTargetPowerRange(PortNumber port, T component) {
return Optional.empty();
}
/**
* Get the expected input power range for the component,
* as optical components have different working input power ranges.
*
* @param port the port
* @param component the port component
* @return the expected input power range, null if the component does not have
* a specified input power range. For example input power range only applies
* to RX ports.
*/
default Optional<Range<Long>> getInputPowerRange(PortNumber port, T component) {
return Optional.empty();
}
}
......
......@@ -19,6 +19,7 @@ package org.onosproject.driver.optical.power;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Range;
import org.onosproject.driver.extensions.OplinkAttenuation;
import org.onosproject.net.OchSignal;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
......@@ -49,7 +50,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Port Power (Gain and attenuation) implementation for Oplink ROADM.
* Port Power (Gain and attenuation) implementation for Oplink 1-SLOT-8D ROADM.
*
* An Oplink ROADM port exposes OchSignal resources.
* Optical Power can be set at port level or channel/wavelength level (attenuation).
......@@ -59,6 +60,27 @@ import org.slf4j.LoggerFactory;
public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour
implements PowerConfig<Object> {
private static final int LINE_IN = 1;
private static final int LINE_OUT = 2;
private static final int AUX_OUT_1 = 3;
private static final int AUX_OUT_2 = 4;
private static final int EXPRESS_OUT_1 = 5;
private static final int EXPRESS_OUT_2 = 6;
private static final int EXPRESS_OUT_3 = 7;
private static final int EXPRESS_OUT_4 = 8;
private static final int EXPRESS_OUT_5 = 9;
private static final int EXPRESS_OUT_6 = 10;
private static final int EXPRESS_OUT_7 = 11;
private static final int AUX_IN_1 = 12;
private static final int AUX_IN_2 = 13;
private static final int EXPRESS_IN_1 = 14;
private static final int EXPRESS_IN_2 = 15;
private static final int EXPRESS_IN_3 = 16;
private static final int EXPRESS_IN_4 = 17;
private static final int EXPRESS_IN_5 = 18;
private static final int EXPRESS_IN_6 = 19;
private static final int EXPRESS_IN_7 = 20;
protected final Logger log = LoggerFactory.getLogger(getClass());
// Component type
......@@ -170,6 +192,35 @@ public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour
}
}
@Override
public Optional<Range<Long>> getTargetPowerRange(PortNumber port, Object component) {
Range<Long> range = null;
switch (getType(component)) {
case PORT:
range = getTargetPortPowerRange(port);
break;
case CHANNEL:
range = getChannelAttenuationRange(port);
break;
default:
break;
}
return Optional.ofNullable(range);
}
@Override
public Optional<Range<Long>> getInputPowerRange(PortNumber port, Object component) {
Range<Long> range = null;
switch (getType(component)) {
case PORT:
range = getInputPortPowerRange(port);
break;
default:
break;
}
return Optional.ofNullable(range);
}
private Long getChannelAttenuation(PortNumber portNum, OchSignal och) {
FlowEntry flowEntry = findFlow(portNum, och);
if (flowEntry != null) {
......@@ -263,4 +314,49 @@ public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour
FlowRuleService service = this.handler().get(FlowRuleService.class);
service.applyFlowRules(flowBuilder.build());
}
// Returns the acceptable target range for an output Port, null otherwise
private Range<Long> getTargetPortPowerRange(PortNumber port) {
Range<Long> range = null;
long num = port.toLong();
if (num == LINE_OUT) {
range = Range.closed(100L, 2040L);
} else if (num >= AUX_OUT_1 && num <= EXPRESS_OUT_7) {
range = Range.closed(-680L, 1530L);
}
return range;
}
// Returns the acceptable attenuation range for a connection (represented as
// a flow with attenuation instruction). Port can be either the input or
// output port of the connection. Returns null if the connection does not
// support attenuation.
private Range<Long> getChannelAttenuationRange(PortNumber port) {
Range<Long> range = null;
long num = port.toLong();
// Only connections from AuxIn to LineOut or ExpressIn to LineOut support
// attenuation.
if (num == LINE_OUT ||
num >= AUX_IN_1 && num <= EXPRESS_IN_7) {
range = Range.closed(0L, 2550L);
}
return range;
}
// Returns the working input power range for an input port, null if the port
// is not an input port.
private Range<Long> getInputPortPowerRange(PortNumber port) {
Range<Long> range = null;
long portNum = port.toLong();
if (portNum == LINE_IN) {
// TODO implement support for IR and ER range
// only supports LR right now
range = Range.closed(-2600L, 540L);
} else if (portNum == AUX_IN_1 || portNum == AUX_IN_2) {
range = Range.closed(-1250L, 1590L);
} else if (portNum >= EXPRESS_IN_1 && portNum <= EXPRESS_IN_7) {
range = Range.closed(-1420L, 1420L);
}
return range;
}
}
......