2 * Copyright © 2017 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.olm.power;
11 import java.math.BigDecimal;
12 import java.math.MathContext;
13 import java.math.RoundingMode;
14 import java.util.HashMap;
15 import java.util.Locale;
17 import java.util.Optional;
18 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
19 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
20 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
21 import org.opendaylight.transportpce.common.mapping.PortMapping;
22 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
23 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.OpenroadmNodeVersion;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.MappingKey;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticalControlMode;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1;
33 import org.opendaylight.yangtools.yang.common.Decimal64;
34 import org.osgi.service.component.annotations.Activate;
35 import org.osgi.service.component.annotations.Component;
36 import org.osgi.service.component.annotations.Reference;
37 import org.osgi.service.metatype.annotations.AttributeDefinition;
38 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 @Component(configurationPid = "org.opendaylight.transportpce")
43 public class PowerMgmtImpl implements PowerMgmt {
45 @ObjectClassDefinition
46 public @interface Configuration {
48 long timer1() default 120000;
50 long timer2() default 20000;
52 private static final Logger LOG = LoggerFactory.getLogger(PowerMgmtImpl.class);
53 private final OpenRoadmInterfaces openRoadmInterfaces;
54 private final CrossConnect crossConnect;
55 private final DeviceTransactionManager deviceTransactionManager;
56 private final PortMapping portMapping;
57 private static final BigDecimal DEFAULT_TPDR_PWR_100G = new BigDecimal(-5);
58 private static final BigDecimal DEFAULT_TPDR_PWR_400G = new BigDecimal(0);
59 private static final String INTERFACE_NOT_PRESENT = "Interface {} on node {} is not present!";
60 private static final double MC_WIDTH_GRAN = 2 * GridConstant.GRANULARITY;
63 // openroadm spec value is 120000, functest value is 3000
65 // openroadm spec value is 20000, functest value is 2000
68 public PowerMgmtImpl(@Reference OpenRoadmInterfaces openRoadmInterfaces,
69 @Reference CrossConnect crossConnect,
70 @Reference DeviceTransactionManager deviceTransactionManager,
71 @Reference PortMapping portMapping, final Configuration configuration) {
72 this(openRoadmInterfaces, crossConnect, deviceTransactionManager, portMapping, configuration.timer1(),
73 configuration.timer2());
76 public PowerMgmtImpl(OpenRoadmInterfaces openRoadmInterfaces,
77 CrossConnect crossConnect, DeviceTransactionManager deviceTransactionManager,
78 PortMapping portMapping, long timer1, long timer2) {
79 this.openRoadmInterfaces = openRoadmInterfaces;
80 this.crossConnect = crossConnect;
81 this.deviceTransactionManager = deviceTransactionManager;
82 this.portMapping = portMapping;
84 this.timer1 = Long.valueOf(timer1);
85 } catch (NumberFormatException e) {
87 LOG.warn("Failed to retrieve Olm timer1 value from configuration - using default value {}",
91 this.timer2 = Long.valueOf(timer2);
92 } catch (NumberFormatException e) {
94 LOG.warn("Failed to retrieve Olm timer2 value from configuration - using default value {}",
97 LOG.debug("PowerMgmtImpl instantiated with olm timers = {} - {}", this.timer1, this.timer2);
101 * This methods measures power requirement for turning up a WL
102 * from the Spanloss at OTS transmit direction and update
103 * roadm-connection target-output-power.
106 * Input parameter from the olm servicePowerSetup rpc
108 * @return true/false based on status of operation.
110 //TODO Need to Case Optical Power mode/NodeType in case of 2.2 devices
111 public Boolean setPower(ServicePowerSetupInput input) {
112 LOG.info("Olm-setPower initiated for input {}", input);
113 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
114 input.getLowerSpectralSlotNumber().toString(),
115 input.getHigherSpectralSlotNumber().toString());
116 if (input.getNodes() == null) {
117 LOG.error("No Nodes to configure");
120 for (int i = 0; i < input.getNodes().size(); i++) {
121 String nodeId = input.getNodes().get(i).getNodeId();
122 String destTpId = input.getNodes().get(i).getDestTp();
123 Nodes inputNode = this.portMapping.getNode(nodeId);
124 if (inputNode == null || inputNode.getNodeInfo() == null) {
125 LOG.error("OLM-PowerMgmtImpl : Error retrieving mapping node for {}", nodeId);
128 OpenroadmNodeVersion openroadmVersion = inputNode.getNodeInfo().getOpenroadmVersion();
130 switch (inputNode.getNodeInfo().getNodeType()) {
132 if (destTpId == null) {
135 LOG.info("Getting data from input node {}", inputNode.getNodeInfo().getNodeType());
136 LOG.info("Getting mapping data for node is {}",
137 inputNode.nonnullMapping().values().stream().filter(o -> o.key()
138 .equals(new MappingKey(destTpId))).findFirst().toString());
139 // If its not A-End transponder
140 if (!destTpId.toUpperCase(Locale.getDefault()).contains("NETWORK")) {
141 LOG.info("{} is a drop node. Net power settings needed", nodeId);
145 BigDecimal powerVal = getXpdrPowerValue(
146 inputNode, destTpId, nodeId, openroadmVersion.getIntValue(),
147 input.getNodes().get(i + 1).getSrcTp(), input.getNodes().get(i + 1).getNodeId());
148 if (powerVal == null) {
152 String interfaceName = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
153 destTpId, spectralSlotName);
154 if (!callSetTransponderPower(nodeId, interfaceName, powerVal, openroadmVersion)) {
155 LOG.info("Transponder OCH connection: {} power update failed ", interfaceName);
158 LOG.info("Transponder OCH connection: {} power updated ", interfaceName);
160 LOG.info("Now going in sleep mode");
161 Thread.sleep(timer1);
162 } catch (InterruptedException e) {
163 LOG.info("Transponder warmup failed for OCH connection: {}", interfaceName, e);
164 // FIXME shouldn't it be LOG.warn or LOG.error?
165 // or maybe this try/catch block can simply be removed
169 LOG.info("This is a roadm {} device", openroadmVersion.getName());
170 String connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
171 input.getNodes().get(i).getSrcTp(), destTpId, spectralSlotName);
172 LOG.info("Connection number is {}", connectionNumber);
174 // If Drop node leave node is power mode
175 if (destTpId.toUpperCase(Locale.getDefault()).contains("SRG")) {
176 LOG.info("Setting power at drop node");
177 crossConnect.setPowerLevel(nodeId, OpticalControlMode.Power.getName(), null, connectionNumber);
180 if (!destTpId.toUpperCase(Locale.getDefault()).contains("DEG")) {
183 // If Degree is transmitting end then set power
184 Optional<Mapping> mappingObjectOptional = inputNode.nonnullMapping()
185 .values().stream().filter(o -> o.key()
186 .equals(new MappingKey(destTpId))).findFirst();
187 if (mappingObjectOptional.isEmpty()) {
190 // TODO can it be return false rather than continue?
191 // in that case, mappingObjectOptional could be moved inside method getSpanLossTx()
192 LOG.info("Dest point is Degree {}", mappingObjectOptional.get());
193 BigDecimal spanLossTx = getSpanLossTx(mappingObjectOptional.get().getSupportingOts(),
194 destTpId, nodeId, openroadmVersion.getIntValue());
196 LOG.info("Spanloss TX is {}", spanLossTx);
197 // TODO: The span-loss limits should be obtained from optical specifications
198 if (spanLossTx == null || spanLossTx.intValue() <= 0 || spanLossTx.intValue() > 27) {
199 LOG.error("Power Value is null: spanLossTx null or out of openROADM range ]0,27] {}",
203 Decimal64 powerValue = Decimal64.valueOf(getRdmPowerValue(spanLossTx, input));
205 if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Power.getName(), powerValue,
207 LOG.info("Set Power failed for Roadm-connection: {} on Node: {}",
208 connectionNumber, nodeId);
209 // FIXME shouldn't it be LOG.error
212 LOG.info("Roadm-connection: {} updated ", connectionNumber);
213 Thread.sleep(timer2);
214 // TODO make this timer value configurable via OSGi blueprint
215 // although the value recommended by the white paper is 20 seconds.
216 // At least one vendor product needs 60 seconds
217 // because it is not supporting GainLoss with target-output-power.
219 if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.GainLoss.getName(), powerValue,
221 LOG.warn("Setting power-control mode off failed for Roadm-connection: {}",
223 // FIXME no return false in that case?
225 } catch (InterruptedException e) {
226 LOG.error("Olm-setPower wait failed :", e);
231 LOG.error("OLM-PowerMgmtImpl : Error with node type for node {}", nodeId);
238 private Map<String, Double> getTxPowerRangeMap(Nodes inputNode, String destTpId, String nodeId,
239 Integer openroadmVersion) {
241 Optional<Mapping> mappingObject = inputNode.nonnullMapping().values().stream()
242 .filter(o -> o.key().equals(new MappingKey(destTpId))).findFirst();
243 if (mappingObject.isEmpty()) {
244 LOG.info("Mapping object not found for nodeId: {}", nodeId);
245 // FIXME shouldn't it be LOG.error ?
247 // return null here means return false in setPower()
248 // TODO Align protections with getSRGRxPowerRangeMap
251 String circuitPackName = mappingObject.get().getSupportingCircuitPackName();
252 String portName = mappingObject.get().getSupportingPort();
253 switch (openroadmVersion) {
255 return PowerMgmtVersion121.getXponderPowerRange(circuitPackName, portName,
256 nodeId, deviceTransactionManager);
258 return PowerMgmtVersion221.getXponderPowerRange(circuitPackName, portName,
259 nodeId, deviceTransactionManager);
261 return PowerMgmtVersion710.getXponderPowerRange(circuitPackName, portName,
262 nodeId, deviceTransactionManager);
264 LOG.error("Unrecognized OpenRoadm version");
265 return new HashMap<>();
266 // FIXME shouldn't it lead to a return false in setPower()?
271 private Map<String, Double> getSRGRxPowerRangeMap(String srgId, String nodeId, Integer openroadmVersion) {
273 Nodes inputNode = this.portMapping.getNode(nodeId);
274 int rdmOpenroadmVersion = inputNode.getNodeInfo().getOpenroadmVersion().getIntValue();
275 Optional<Mapping> mappingObject = inputNode.nonnullMapping().values().stream()
276 .filter(o -> o.key().equals(new MappingKey(srgId)))
279 if (mappingObject.isEmpty()) {
280 return new HashMap<>();
281 // FIXME shouldn't it lead to a return false in setPower() ?
284 String circuitPackName = mappingObject.get().getSupportingCircuitPackName();
285 String portName = mappingObject.get().getSupportingPort();
286 switch (rdmOpenroadmVersion) {
288 return PowerMgmtVersion121.getSRGRxPowerRange(nodeId, srgId,
289 deviceTransactionManager, circuitPackName, portName);
291 return PowerMgmtVersion221.getSRGRxPowerRange(nodeId, srgId,
292 deviceTransactionManager, circuitPackName, portName);
294 return PowerMgmtVersion710.getSRGRxPowerRange(nodeId, srgId,
295 deviceTransactionManager, circuitPackName, portName);
297 LOG.error("Unrecognized OpenRoadm version");
299 //return null here means return false in setPower()
300 // TODO Align protections with getTxPowerRangeMap
304 private BigDecimal getSpanLossTx(String supportingOts, String destTpId, String nodeId, Integer openroadmVersion) {
306 switch (openroadmVersion) {
308 Optional<Interface> interfaceOpt =
309 this.openRoadmInterfaces.getInterface(nodeId, supportingOts);
310 if (interfaceOpt.isEmpty()) {
311 LOG.error(INTERFACE_NOT_PRESENT, supportingOts, nodeId);
314 if (interfaceOpt.get().augmentation(Interface1.class).getOts()
315 .getSpanLossTransmit() == null) {
316 LOG.error("interface {} has no spanloss value", interfaceOpt.get().getName());
319 return interfaceOpt.get()
320 .augmentation(Interface1.class)
321 .getOts().getSpanLossTransmit().getValue().decimalValue();
323 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019
324 .interfaces.grp.Interface> interfaceOpt1 =
325 this.openRoadmInterfaces.getInterface(nodeId, supportingOts);
326 if (interfaceOpt1.isEmpty()) {
327 LOG.error(INTERFACE_NOT_PRESENT, supportingOts, nodeId);
330 if (interfaceOpt1.get().augmentation(org.opendaylight.yang.gen.v1.http.org
331 .openroadm.optical.transport.interfaces.rev181019.Interface1.class).getOts()
332 .getSpanLossTransmit() == null) {
333 LOG.error("interface {} has no spanloss value", interfaceOpt1.get().getName());
336 return interfaceOpt1.get()
337 .augmentation(org.opendaylight.yang.gen.v1.http.org
338 .openroadm.optical.transport.interfaces.rev181019.Interface1.class)
339 .getOts().getSpanLossTransmit().getValue().decimalValue();
344 } catch (OpenRoadmInterfaceException ex) {
345 LOG.error("Failed to get interface {} from node {}!",
346 supportingOts, nodeId, ex);
348 } catch (IllegalArgumentException ex) {
349 LOG.error("Failed to get non existing interface {} from node {}!",
350 supportingOts, nodeId);
355 private BigDecimal getXpdrPowerValue(Nodes inputNode, String destTpId, String nodeId, Integer openroadmVersion,
356 String srgId, String nextNodeId) {
358 Map<String, Double> txPowerRangeMap = getTxPowerRangeMap(inputNode, destTpId, nodeId, openroadmVersion);
359 if (txPowerRangeMap == null) {
361 // return null here means return false in setPower()
363 BigDecimal powerVal =
364 openroadmVersion == 3 ? DEFAULT_TPDR_PWR_400G : DEFAULT_TPDR_PWR_100G;
365 if (txPowerRangeMap.isEmpty()) {
366 LOG.info("Tranponder range not available setting to default power for nodeId: {}", nodeId);
370 Map<String, Double> rxSRGPowerRangeMap = getSRGRxPowerRangeMap(srgId, nextNodeId, openroadmVersion);
371 if (rxSRGPowerRangeMap == null) {
373 // return null here means return false in setPower()
374 // TODO empty txPowerRangeMap + null rxSRGPowerRangeMap is allowed
375 // => confirm this behavior is OK
377 if (rxSRGPowerRangeMap.isEmpty()) {
378 LOG.info("SRG Power Range not found, setting the Transponder range to default");
382 powerVal = new BigDecimal(txPowerRangeMap.get("MaxTx"))
383 .min(new BigDecimal(rxSRGPowerRangeMap.get("MaxRx")));
384 LOG.info("Calculated Transponder Power value is {}" , powerVal);
389 private BigDecimal getRdmPowerValue(BigDecimal spanLossTx, ServicePowerSetupInput input) {
390 // TODO: These values will be obtained from the specifications
391 // power-value here refers to the Pin[50GHz]
392 BigDecimal powerValue;
393 if (spanLossTx.doubleValue() >= 23.0) {
394 powerValue = BigDecimal.valueOf(2.0);
395 } else if (spanLossTx.doubleValue() >= 8.0) {
396 powerValue = BigDecimal.valueOf(- (8.0 - spanLossTx.doubleValue()) / 3.0 - 3.0);
397 } else if (spanLossTx.doubleValue() >= 6.0) {
398 powerValue = BigDecimal.valueOf(-3.0);
400 powerValue = spanLossTx.subtract(BigDecimal.valueOf(9));
402 BigDecimal mcWidth = new BigDecimal(50);
403 // we work at constant power spectral density (50 GHz channel width @-20dBm=37.5GHz)
404 // 87.5 GHz channel width @-20dBm=75GHz
405 if (input.getMcWidth() != null) {
406 // Units of MC-width are in GHz, meaning it should be 40/50/87.5GHz
407 // TODO: Should we validate this units before proceeding?
408 LOG.debug("Input Grid size is {}", input.getMcWidth().getValue());
410 // We round-off the mc-width to the nearest grid-value based on the granularity of 12.5 GHz
411 double nbrMcSlots = Math.ceil(input.getMcWidth().getValue().doubleValue() / MC_WIDTH_GRAN);
412 LOG.debug("Nearest (ceil) number of slots {}", nbrMcSlots);
413 mcWidth = new BigDecimal(MC_WIDTH_GRAN * nbrMcSlots);
414 LOG.debug("Given mc-width={}, Rounded mc-width={}", input.getMcWidth().getValue(), mcWidth);
416 BigDecimal logVal = mcWidth.divide(new BigDecimal(50));
417 double pdsVal = 10 * Math.log10(logVal.doubleValue());
418 // Addition of PSD value will give Pin[87.5 GHz]
419 powerValue = powerValue.add(new BigDecimal(pdsVal, new MathContext(3, RoundingMode.HALF_EVEN)));
421 // FIXME compliancy with OpenROADM MSA and approximations used -- should be addressed with powermask update
422 // cf JIRA ticket https://jira.opendaylight.org/browse/TRNSPRTPCE-494
423 powerValue = powerValue.setScale(2, RoundingMode.CEILING);
424 // target-output-power yang precision is 2, so we limit here to 2
425 LOG.info("The power value is P1[{}GHz]={} dB for spanloss {}", mcWidth, powerValue, spanLossTx);
430 * This methods turns down power a WL by performing
434 * 1. Pull interfaces used in service and change
435 * status to outOfService
438 * 2. For each of the ROADM node set target-output-power
439 * to -60dbm, wait for 20 seconds, turn power mode to off
442 * 3. Turn down power in Z to A direction and A to Z
445 * Input parameter from the olm servicePowerTurndown rpc
447 * @return true/false based on status of operation
449 public Boolean powerTurnDown(ServicePowerTurndownInput input) {
450 LOG.info("Olm-powerTurnDown initiated for input {}", input);
451 /*Starting with last element into the list Z -> A for
452 turning down A -> Z */
453 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
454 input.getLowerSpectralSlotNumber().toString(),
455 input.getHigherSpectralSlotNumber().toString());
456 for (int i = input.getNodes().size() - 1; i >= 0; i--) {
457 String nodeId = input.getNodes().get(i).getNodeId();
458 String destTpId = input.getNodes().get(i).getDestTp();
459 String connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
460 input.getNodes().get(i).getSrcTp(), destTpId, spectralSlotName);
462 if (destTpId.toUpperCase(Locale.getDefault()).contains("DEG")) {
463 if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Power.getName(),
464 Decimal64.valueOf("-60"), connectionNumber)) {
465 LOG.warn("Power down failed for Roadm-connection: {}", connectionNumber);
468 Thread.sleep(timer2);
469 if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Off.getName(), null, connectionNumber)) {
470 LOG.warn("Setting power-control mode off failed for Roadm-connection: {}", connectionNumber);
473 } else if (destTpId.toUpperCase(Locale.getDefault()).contains("SRG")) {
474 if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Off.getName(), null, connectionNumber)) {
475 LOG.warn("Setting power-control mode off failed for Roadm-connection: {}", connectionNumber);
476 // FIXME a return false would allow sync with DEG case but makes current Unit tests fail
479 } catch (InterruptedException e) {
480 // TODO Auto-generated catch block
481 LOG.error("Olm-powerTurnDown wait failed: ",e);
489 * This method retrieves transponder OCH interface and
493 * Unique identifier for the mounted netconf- node
494 * @param interfaceName
495 * OCH interface name carrying WL
497 * Calculated transmit power
498 * @param openroadmVersion
499 * Version of openRoadm device software
500 * @return true/false based on status of operation
502 private boolean callSetTransponderPower(String nodeId, String interfaceName, BigDecimal txPower,
503 OpenroadmNodeVersion openroadmVersion) {
505 boolean powerSetupResult = false;
507 switch (openroadmVersion.getIntValue()) {
509 Optional<Interface> interfaceOptional121 =
510 openRoadmInterfaces.getInterface(nodeId, interfaceName);
511 if (interfaceOptional121.isEmpty()) {
512 LOG.error(INTERFACE_NOT_PRESENT, interfaceName, nodeId);
515 powerSetupResult = PowerMgmtVersion121.setTransponderPower(nodeId, interfaceName,
516 txPower, deviceTransactionManager, interfaceOptional121.get());
519 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp
520 .Interface> interfaceOptional221 =
521 openRoadmInterfaces.getInterface(nodeId, interfaceName);
522 if (interfaceOptional221.isEmpty()) {
523 LOG.error(INTERFACE_NOT_PRESENT, interfaceName, nodeId);
526 powerSetupResult = PowerMgmtVersion221.setTransponderPower(nodeId, interfaceName,
527 txPower, deviceTransactionManager, interfaceOptional221.get());
530 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp
531 .Interface> interfaceOptional710 =
532 openRoadmInterfaces.getInterface(nodeId, interfaceName);
533 if (interfaceOptional710.isEmpty()) {
534 LOG.error(INTERFACE_NOT_PRESENT, interfaceName, nodeId);
537 powerSetupResult = PowerMgmtVersion710.setTransponderPower(nodeId, interfaceName,
538 txPower, deviceTransactionManager, interfaceOptional710.get());
541 LOG.error("Unrecognized OpenRoadm version");
544 } catch (OpenRoadmInterfaceException ex) {
545 LOG.error("Failed to get interface {} from node {}!", interfaceName, nodeId, ex);
548 if (!powerSetupResult) {
549 LOG.debug("Transponder power setup failed for nodeId {} on interface {}",
550 nodeId, interfaceName);
553 LOG.debug("Transponder power set up completed successfully for nodeId {} and interface {}",
554 nodeId,interfaceName);