Jimmy Yan
Committed by Gerrit Code Review

Add range checking methods to PowerConfig

Change-Id: I8c113df90a8225db34256856cb2eb80ee7d68a9e
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.behaviour; 16 package org.onosproject.net.behaviour;
17 17
18 +import com.google.common.annotations.Beta;
19 +import com.google.common.collect.Range;
18 import org.onosproject.net.PortNumber; 20 import org.onosproject.net.PortNumber;
19 import org.onosproject.net.driver.HandlerBehaviour; 21 import org.onosproject.net.driver.HandlerBehaviour;
20 22
...@@ -29,6 +31,7 @@ import java.util.Optional; ...@@ -29,6 +31,7 @@ import java.util.Optional;
29 * 31 *
30 * Power levels are specified with a long and unit .01 dBm. 32 * Power levels are specified with a long and unit .01 dBm.
31 */ 33 */
34 +@Beta
32 public interface PowerConfig<T> extends HandlerBehaviour { 35 public interface PowerConfig<T> extends HandlerBehaviour {
33 36
34 /** 37 /**
...@@ -43,7 +46,6 @@ public interface PowerConfig<T> extends HandlerBehaviour { ...@@ -43,7 +46,6 @@ public interface PowerConfig<T> extends HandlerBehaviour {
43 /** 46 /**
44 * Set the target power on the component. 47 * Set the target power on the component.
45 * 48 *
46 - *
47 * @param port the port 49 * @param port the port
48 * @param component the port component 50 * @param component the port component
49 * @param power target power in .01 dBm 51 * @param power target power in .01 dBm
...@@ -58,4 +60,31 @@ public interface PowerConfig<T> extends HandlerBehaviour { ...@@ -58,4 +60,31 @@ public interface PowerConfig<T> extends HandlerBehaviour {
58 * @return power power in .01 dBm 60 * @return power power in .01 dBm
59 */ 61 */
60 Optional<Long> currentPower(PortNumber port, T component); 62 Optional<Long> currentPower(PortNumber port, T component);
63 +
64 + /**
65 + * Get the acceptable target power range for setTargetPower,
66 + * as optical components have different configurable output power ranges.
67 + *
68 + * @param port the port
69 + * @param component the port component
70 + * @return the accepted target power range, null if the component's power is
71 + * not configurable. For example the port target power can only be set on TX ports.
72 + */
73 + default Optional<Range<Long>> getTargetPowerRange(PortNumber port, T component) {
74 + return Optional.empty();
75 + }
76 +
77 + /**
78 + * Get the expected input power range for the component,
79 + * as optical components have different working input power ranges.
80 + *
81 + * @param port the port
82 + * @param component the port component
83 + * @return the expected input power range, null if the component does not have
84 + * a specified input power range. For example input power range only applies
85 + * to RX ports.
86 + */
87 + default Optional<Range<Long>> getInputPowerRange(PortNumber port, T component) {
88 + return Optional.empty();
89 + }
61 } 90 }
......
...@@ -19,6 +19,7 @@ package org.onosproject.driver.optical.power; ...@@ -19,6 +19,7 @@ package org.onosproject.driver.optical.power;
19 import java.util.List; 19 import java.util.List;
20 import java.util.Optional; 20 import java.util.Optional;
21 21
22 +import com.google.common.collect.Range;
22 import org.onosproject.driver.extensions.OplinkAttenuation; 23 import org.onosproject.driver.extensions.OplinkAttenuation;
23 import org.onosproject.net.OchSignal; 24 import org.onosproject.net.OchSignal;
24 import org.onosproject.net.driver.AbstractHandlerBehaviour; 25 import org.onosproject.net.driver.AbstractHandlerBehaviour;
...@@ -49,7 +50,7 @@ import org.slf4j.Logger; ...@@ -49,7 +50,7 @@ import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory; 50 import org.slf4j.LoggerFactory;
50 51
51 /** 52 /**
52 - * Port Power (Gain and attenuation) implementation for Oplink ROADM. 53 + * Port Power (Gain and attenuation) implementation for Oplink 1-SLOT-8D ROADM.
53 * 54 *
54 * An Oplink ROADM port exposes OchSignal resources. 55 * An Oplink ROADM port exposes OchSignal resources.
55 * Optical Power can be set at port level or channel/wavelength level (attenuation). 56 * Optical Power can be set at port level or channel/wavelength level (attenuation).
...@@ -59,6 +60,27 @@ import org.slf4j.LoggerFactory; ...@@ -59,6 +60,27 @@ import org.slf4j.LoggerFactory;
59 public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour 60 public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour
60 implements PowerConfig<Object> { 61 implements PowerConfig<Object> {
61 62
63 + private static final int LINE_IN = 1;
64 + private static final int LINE_OUT = 2;
65 + private static final int AUX_OUT_1 = 3;
66 + private static final int AUX_OUT_2 = 4;
67 + private static final int EXPRESS_OUT_1 = 5;
68 + private static final int EXPRESS_OUT_2 = 6;
69 + private static final int EXPRESS_OUT_3 = 7;
70 + private static final int EXPRESS_OUT_4 = 8;
71 + private static final int EXPRESS_OUT_5 = 9;
72 + private static final int EXPRESS_OUT_6 = 10;
73 + private static final int EXPRESS_OUT_7 = 11;
74 + private static final int AUX_IN_1 = 12;
75 + private static final int AUX_IN_2 = 13;
76 + private static final int EXPRESS_IN_1 = 14;
77 + private static final int EXPRESS_IN_2 = 15;
78 + private static final int EXPRESS_IN_3 = 16;
79 + private static final int EXPRESS_IN_4 = 17;
80 + private static final int EXPRESS_IN_5 = 18;
81 + private static final int EXPRESS_IN_6 = 19;
82 + private static final int EXPRESS_IN_7 = 20;
83 +
62 protected final Logger log = LoggerFactory.getLogger(getClass()); 84 protected final Logger log = LoggerFactory.getLogger(getClass());
63 85
64 // Component type 86 // Component type
...@@ -170,6 +192,35 @@ public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour ...@@ -170,6 +192,35 @@ public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour
170 } 192 }
171 } 193 }
172 194
195 + @Override
196 + public Optional<Range<Long>> getTargetPowerRange(PortNumber port, Object component) {
197 + Range<Long> range = null;
198 + switch (getType(component)) {
199 + case PORT:
200 + range = getTargetPortPowerRange(port);
201 + break;
202 + case CHANNEL:
203 + range = getChannelAttenuationRange(port);
204 + break;
205 + default:
206 + break;
207 + }
208 + return Optional.ofNullable(range);
209 + }
210 +
211 + @Override
212 + public Optional<Range<Long>> getInputPowerRange(PortNumber port, Object component) {
213 + Range<Long> range = null;
214 + switch (getType(component)) {
215 + case PORT:
216 + range = getInputPortPowerRange(port);
217 + break;
218 + default:
219 + break;
220 + }
221 + return Optional.ofNullable(range);
222 + }
223 +
173 private Long getChannelAttenuation(PortNumber portNum, OchSignal och) { 224 private Long getChannelAttenuation(PortNumber portNum, OchSignal och) {
174 FlowEntry flowEntry = findFlow(portNum, och); 225 FlowEntry flowEntry = findFlow(portNum, och);
175 if (flowEntry != null) { 226 if (flowEntry != null) {
...@@ -263,4 +314,49 @@ public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour ...@@ -263,4 +314,49 @@ public class OplinkRoadmPowerConfig extends AbstractHandlerBehaviour
263 FlowRuleService service = this.handler().get(FlowRuleService.class); 314 FlowRuleService service = this.handler().get(FlowRuleService.class);
264 service.applyFlowRules(flowBuilder.build()); 315 service.applyFlowRules(flowBuilder.build());
265 } 316 }
317 +
318 + // Returns the acceptable target range for an output Port, null otherwise
319 + private Range<Long> getTargetPortPowerRange(PortNumber port) {
320 + Range<Long> range = null;
321 + long num = port.toLong();
322 + if (num == LINE_OUT) {
323 + range = Range.closed(100L, 2040L);
324 + } else if (num >= AUX_OUT_1 && num <= EXPRESS_OUT_7) {
325 + range = Range.closed(-680L, 1530L);
326 + }
327 + return range;
328 + }
329 +
330 + // Returns the acceptable attenuation range for a connection (represented as
331 + // a flow with attenuation instruction). Port can be either the input or
332 + // output port of the connection. Returns null if the connection does not
333 + // support attenuation.
334 + private Range<Long> getChannelAttenuationRange(PortNumber port) {
335 + Range<Long> range = null;
336 + long num = port.toLong();
337 + // Only connections from AuxIn to LineOut or ExpressIn to LineOut support
338 + // attenuation.
339 + if (num == LINE_OUT ||
340 + num >= AUX_IN_1 && num <= EXPRESS_IN_7) {
341 + range = Range.closed(0L, 2550L);
342 + }
343 + return range;
344 + }
345 +
346 + // Returns the working input power range for an input port, null if the port
347 + // is not an input port.
348 + private Range<Long> getInputPortPowerRange(PortNumber port) {
349 + Range<Long> range = null;
350 + long portNum = port.toLong();
351 + if (portNum == LINE_IN) {
352 + // TODO implement support for IR and ER range
353 + // only supports LR right now
354 + range = Range.closed(-2600L, 540L);
355 + } else if (portNum == AUX_IN_1 || portNum == AUX_IN_2) {
356 + range = Range.closed(-1250L, 1590L);
357 + } else if (portNum >= EXPRESS_IN_1 && portNum <= EXPRESS_IN_7) {
358 + range = Range.closed(-1420L, 1420L);
359 + }
360 + return range;
361 + }
266 } 362 }
......