cbfc365ad44d1b19df8dcd969c66eee1b6aef862
[transportpce.git] / olm / src / main / java / org / opendaylight / transportpce / olm / power / PowerMgmtImpl.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.olm.power;
10
11 import java.math.BigDecimal;
12 import java.math.MathContext;
13 import java.math.RoundingMode;
14 import java.util.Arrays;
15 import java.util.HashMap;
16 import java.util.Locale;
17 import java.util.Map;
18 import java.util.Optional;
19 import java.util.stream.Collectors;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
22 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
23 import org.opendaylight.transportpce.common.mapping.PortMapping;
24 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
25 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.OpenroadmNodeVersion;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.MappingKey;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.network.Nodes;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticalControlMode;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1;
35 import org.opendaylight.yangtools.yang.common.Decimal64;
36 import org.osgi.service.component.annotations.Activate;
37 import org.osgi.service.component.annotations.Component;
38 import org.osgi.service.component.annotations.Reference;
39 import org.osgi.service.metatype.annotations.AttributeDefinition;
40 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 @Component(configurationPid = "org.opendaylight.transportpce")
45 public class PowerMgmtImpl implements PowerMgmt {
46
47     @ObjectClassDefinition
48     public @interface Configuration {
49         @AttributeDefinition
50         long timer1() default 120000;
51         @AttributeDefinition
52         long timer2() default 20000;
53     }
54     private static final Logger LOG = LoggerFactory.getLogger(PowerMgmtImpl.class);
55     private final OpenRoadmInterfaces openRoadmInterfaces;
56     private final CrossConnect crossConnect;
57     private final DeviceTransactionManager deviceTransactionManager;
58     private final PortMapping portMapping;
59     private static final BigDecimal DEFAULT_TPDR_PWR_100G = new BigDecimal(-5);
60     private static final BigDecimal DEFAULT_TPDR_PWR_400G = new BigDecimal(0);
61     private static final String INTERFACE_NOT_PRESENT = "Interface {} on node {} is not present!";
62     private static final double MC_WIDTH_GRAN = 2 * GridConstant.GRANULARITY;
63
64     private long timer1;
65     // openroadm spec value is 120000, functest value is 3000
66     private long timer2;
67     // openroadm spec value is 20000, functest value is 2000
68
69     @Activate
70     public PowerMgmtImpl(@Reference OpenRoadmInterfaces openRoadmInterfaces,
71             @Reference CrossConnect crossConnect,
72             @Reference DeviceTransactionManager deviceTransactionManager,
73             @Reference PortMapping portMapping, final Configuration configuration) {
74         this(openRoadmInterfaces, crossConnect, deviceTransactionManager, portMapping, configuration.timer1(),
75                 configuration.timer2());
76     }
77
78     public PowerMgmtImpl(OpenRoadmInterfaces openRoadmInterfaces,
79                          CrossConnect crossConnect, DeviceTransactionManager deviceTransactionManager,
80             PortMapping portMapping, long timer1, long timer2) {
81         this.openRoadmInterfaces = openRoadmInterfaces;
82         this.crossConnect = crossConnect;
83         this.deviceTransactionManager = deviceTransactionManager;
84         this.portMapping = portMapping;
85         try {
86             this.timer1 = Long.valueOf(timer1);
87         } catch (NumberFormatException e) {
88             this.timer1 = 120000;
89             LOG.warn("Failed to retrieve Olm timer1 value from configuration - using default value {}",
90                 this.timer1, e);
91         }
92         try {
93             this.timer2 = Long.valueOf(timer2);
94         } catch (NumberFormatException e) {
95             this.timer2 = 20000;
96             LOG.warn("Failed to retrieve Olm timer2 value from configuration - using default value {}",
97                 this.timer2, e);
98         }
99         LOG.debug("PowerMgmtImpl instantiated with olm timers = {} - {}", this.timer1, this.timer2);
100     }
101
102     /**
103      * This methods measures power requirement for turning up a WL
104      * from the Spanloss at OTS transmit direction and update
105      * roadm-connection target-output-power.
106      *
107      * @param input
108      *            Input parameter from the olm servicePowerSetup rpc
109      *
110      * @return true/false based on status of operation.
111      */
112     //TODO Need to Case Optical Power mode/NodeType in case of 2.2 devices
113     public Boolean setPower(ServicePowerSetupInput input) {
114         LOG.info("Olm-setPower initiated for input {}", input);
115         String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
116                 input.getLowerSpectralSlotNumber().toString(),
117                 input.getHigherSpectralSlotNumber().toString());
118         if (input.getNodes() == null) {
119             LOG.error("No Nodes to configure");
120             return false;
121         }
122         for (int i = 0; i < input.getNodes().size(); i++) {
123             String nodeId = input.getNodes().get(i).getNodeId();
124             String destTpId = input.getNodes().get(i).getDestTp();
125             Nodes inputNode = this.portMapping.getNode(nodeId);
126             if (inputNode == null || inputNode.getNodeInfo() == null) {
127                 LOG.error("OLM-PowerMgmtImpl : Error retrieving mapping node for {}", nodeId);
128                 return false;
129             }
130             OpenroadmNodeVersion openroadmVersion = inputNode.getNodeInfo().getOpenroadmVersion();
131
132             switch (inputNode.getNodeInfo().getNodeType()) {
133                 case Xpdr:
134                     if (destTpId == null) {
135                         continue;
136                     }
137                     LOG.info("Getting data from input node {}", inputNode.getNodeInfo().getNodeType());
138                     LOG.info("Getting mapping data for node is {}",
139                         inputNode.nonnullMapping().values().stream().filter(o -> o.key()
140                          .equals(new MappingKey(destTpId))).findFirst().toString());
141                     // If its not A-End transponder
142                     if (!destTpId.toUpperCase(Locale.getDefault()).contains("NETWORK")) {
143                         LOG.info("{} is a drop node. Net power settings needed", nodeId);
144                         continue;
145                     }
146
147                     BigDecimal powerVal = getXpdrPowerValue(
148                             inputNode, destTpId, nodeId, openroadmVersion.getIntValue(),
149                             input.getNodes().get(i + 1).getSrcTp(), input.getNodes().get(i + 1).getNodeId());
150                     if (powerVal == null) {
151                         return false;
152                     }
153
154                     String interfaceName = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
155                         destTpId, spectralSlotName);
156                     if (!callSetTransponderPower(nodeId, interfaceName, powerVal, openroadmVersion)) {
157                         LOG.info("Transponder OCH connection: {} power update failed ", interfaceName);
158                         continue;
159                     }
160                     LOG.info("Transponder OCH connection: {} power updated ", interfaceName);
161                     try {
162                         LOG.info("Now going in sleep mode");
163                         Thread.sleep(timer1);
164                     } catch (InterruptedException e) {
165                         LOG.info("Transponder warmup failed for OCH connection: {}", interfaceName, e);
166                         // FIXME shouldn't it be LOG.warn  or LOG.error?
167                         // or maybe this try/catch block can simply be removed
168                     }
169                     break;
170                 case Rdm:
171                     LOG.info("This is a roadm {} device", openroadmVersion.getName());
172                     String connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
173                             input.getNodes().get(i).getSrcTp(), destTpId, spectralSlotName);
174                     LOG.info("Connection number is {}", connectionNumber);
175
176                     // If Drop node leave node is power mode
177                     if (destTpId.toUpperCase(Locale.getDefault()).contains("SRG")) {
178                         LOG.info("Setting power at drop node");
179                         crossConnect.setPowerLevel(nodeId, OpticalControlMode.Power.getName(), null, connectionNumber);
180                         continue;
181                     }
182                     if (!destTpId.toUpperCase(Locale.getDefault()).contains("DEG")) {
183                         continue;
184                     }
185                     // If Degree is transmitting end then set power
186                     Optional<Mapping> mappingObjectOptional = inputNode.nonnullMapping()
187                             .values().stream().filter(o -> o.key()
188                             .equals(new MappingKey(destTpId))).findFirst();
189                     if (mappingObjectOptional.isEmpty()) {
190                         continue;
191                     }
192                     // TODO can it be return false rather than continue?
193                     // in that case, mappingObjectOptional could be moved inside method getSpanLossTx()
194                     LOG.info("Dest point is Degree {}", mappingObjectOptional.orElseThrow());
195                     BigDecimal spanLossTx = getSpanLossTx(mappingObjectOptional.orElseThrow().getSupportingOts(),
196                         destTpId, nodeId, openroadmVersion.getIntValue());
197
198                     LOG.info("Spanloss TX is {}", spanLossTx);
199                     // TODO: The span-loss limits should be obtained from optical specifications
200                     if (spanLossTx == null || spanLossTx.intValue() <= 0 || spanLossTx.intValue() > 27) {
201                         LOG.error("Power Value is null: spanLossTx null or out of openROADM range ]0,27] {}",
202                             spanLossTx);
203                         return false;
204                     }
205                     Decimal64 powerValue = Decimal64.valueOf(getRdmPowerValue(spanLossTx, input));
206                     try {
207                         if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Power.getName(), powerValue,
208                                 connectionNumber)) {
209                             LOG.info("Set Power failed for Roadm-connection: {} on Node: {}",
210                                     connectionNumber, nodeId);
211                             // FIXME shouldn't it be LOG.error
212                             return false;
213                         }
214                         LOG.info("Roadm-connection: {} updated ", connectionNumber);
215                         Thread.sleep(timer2);
216                         // TODO make this timer value configurable via OSGi blueprint
217                         // although the value recommended by the white paper is 20 seconds.
218                         // At least one vendor product needs 60 seconds
219                         // because it is not supporting GainLoss with target-output-power.
220
221                         if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.GainLoss.getName(), powerValue,
222                                 connectionNumber)) {
223                             LOG.warn("Setting power-control mode off failed for Roadm-connection: {}",
224                                 connectionNumber);
225                             // FIXME no return false in that case?
226                         }
227                     } catch (InterruptedException e) {
228                         LOG.error("Olm-setPower wait failed :", e);
229                         return false;
230                     }
231                     break;
232                 default :
233                     LOG.error("OLM-PowerMgmtImpl : Error with node type for node {}", nodeId);
234                     break;
235             }
236         }
237         return true;
238     }
239
240     private Map<String, Double> getTxPowerRangeMap(Nodes inputNode, String destTpId, String nodeId,
241             Integer openroadmVersion) {
242
243         Optional<Mapping> mappingObject = inputNode.nonnullMapping().values().stream()
244                 .filter(o -> o.key().equals(new MappingKey(destTpId))).findFirst();
245         if (mappingObject.isEmpty()) {
246             LOG.info("Mapping object not found for nodeId: {}", nodeId);
247             // FIXME shouldn't it be LOG.error ?
248             return null;
249             // return null here means return false in setPower()
250             // TODO Align protections with getSRGRxPowerRangeMap
251         }
252
253         String circuitPackName = mappingObject.orElseThrow().getSupportingCircuitPackName();
254         String portName = mappingObject.orElseThrow().getSupportingPort();
255         switch (openroadmVersion) {
256             case 1:
257                 return PowerMgmtVersion121.getXponderPowerRange(circuitPackName, portName,
258                     nodeId, deviceTransactionManager);
259             case 2:
260                 return PowerMgmtVersion221.getXponderPowerRange(circuitPackName, portName,
261                     nodeId, deviceTransactionManager);
262             case 3:
263                 return PowerMgmtVersion710.getXponderPowerRange(circuitPackName, portName,
264                     nodeId, deviceTransactionManager);
265             default:
266                 LOG.error("Unrecognized OpenRoadm version");
267                 return new HashMap<>();
268                 // FIXME shouldn't it lead to a return false in setPower()?
269         }
270     }
271
272
273     private Map<String, Double> getSRGRxPowerRangeMap(String srgId, String nodeId, Integer openroadmVersion) {
274
275         Nodes inputNode = this.portMapping.getNode(nodeId);
276         int rdmOpenroadmVersion = inputNode.getNodeInfo().getOpenroadmVersion().getIntValue();
277         Optional<Mapping> mappingObject = inputNode.nonnullMapping().values().stream()
278                 .filter(o -> o.key().equals(new MappingKey(srgId)))
279                 .findFirst();
280
281         if (mappingObject.isEmpty()) {
282             return new HashMap<>();
283             // FIXME shouldn't it lead to a return false in setPower() ?
284         }
285
286         String circuitPackName = mappingObject.orElseThrow().getSupportingCircuitPackName();
287         String portName = mappingObject.orElseThrow().getSupportingPort();
288         switch (rdmOpenroadmVersion) {
289             case 1:
290                 return PowerMgmtVersion121.getSRGRxPowerRange(nodeId, srgId,
291                         deviceTransactionManager, circuitPackName, portName);
292             case 2:
293                 return PowerMgmtVersion221.getSRGRxPowerRange(nodeId, srgId,
294                         deviceTransactionManager, circuitPackName, portName);
295             case 3:
296                 return PowerMgmtVersion710.getSRGRxPowerRange(nodeId, srgId,
297                         deviceTransactionManager, circuitPackName, portName);
298             default:
299                 LOG.error("Unrecognized OpenRoadm version");
300                 return null;
301                 //return null here means return false in setPower()
302                 // TODO Align protections with getTxPowerRangeMap
303         }
304     }
305
306     private BigDecimal getSpanLossTx(String supportingOts, String destTpId, String nodeId, Integer openroadmVersion) {
307         try {
308             switch (openroadmVersion) {
309                 case 1:
310                     Optional<Interface> interfaceOpt =
311                         this.openRoadmInterfaces.getInterface(nodeId, supportingOts);
312                     if (interfaceOpt.isEmpty()) {
313                         LOG.error(INTERFACE_NOT_PRESENT, supportingOts, nodeId);
314                         return null;
315                     }
316                     if (interfaceOpt.orElseThrow().augmentation(Interface1.class).getOts()
317                             .getSpanLossTransmit() == null) {
318                         LOG.error("interface {} has no spanloss value", interfaceOpt.orElseThrow().getName());
319                         return null;
320                     }
321                     return interfaceOpt.orElseThrow()
322                             .augmentation(Interface1.class)
323                             .getOts().getSpanLossTransmit().getValue().decimalValue();
324                 case 2:
325                     Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019
326                             .interfaces.grp.Interface> interfaceOpt1 =
327                         this.openRoadmInterfaces.getInterface(nodeId, supportingOts);
328                     if (interfaceOpt1.isEmpty()) {
329                         LOG.error(INTERFACE_NOT_PRESENT, supportingOts, nodeId);
330                         return null;
331                     }
332                     if (interfaceOpt1.orElseThrow().augmentation(org.opendaylight.yang.gen.v1.http.org
333                             .openroadm.optical.transport.interfaces.rev181019.Interface1.class).getOts()
334                                 .getSpanLossTransmit() == null) {
335                         LOG.error("interface {} has no spanloss value", interfaceOpt1.orElseThrow().getName());
336                         return null;
337                     }
338                     return interfaceOpt1.orElseThrow()
339                             .augmentation(org.opendaylight.yang.gen.v1.http.org
340                                 .openroadm.optical.transport.interfaces.rev181019.Interface1.class)
341                             .getOts().getSpanLossTransmit().getValue().decimalValue();
342                 // TODO no case 3 ?
343                 default:
344                     return null;
345             }
346         } catch (OpenRoadmInterfaceException ex) {
347             LOG.error("Failed to get interface {} from node {}!",
348                 supportingOts, nodeId, ex);
349             return null;
350         } catch (IllegalArgumentException ex) {
351             LOG.error("Failed to get non existing interface {} from node {}!",
352                 supportingOts, nodeId);
353             return null;
354         }
355     }
356
357     private BigDecimal getXpdrPowerValue(Nodes inputNode, String destTpId, String nodeId, Integer openroadmVersion,
358             String srgId, String nextNodeId) {
359
360         Map<String, Double> txPowerRangeMap = getTxPowerRangeMap(inputNode, destTpId, nodeId, openroadmVersion);
361         if (txPowerRangeMap == null) {
362             return null;
363             // return null here means return false in setPower()
364         }
365         BigDecimal powerVal =
366             openroadmVersion == 3 ? DEFAULT_TPDR_PWR_400G : DEFAULT_TPDR_PWR_100G;
367         if (txPowerRangeMap.isEmpty()) {
368             LOG.info("Tranponder range not available setting to default power for nodeId: {}", nodeId);
369             return powerVal;
370         }
371
372         Map<String, Double> rxSRGPowerRangeMap = getSRGRxPowerRangeMap(srgId, nextNodeId, openroadmVersion);
373         if (rxSRGPowerRangeMap == null) {
374             return null;
375             // return null here means return false in setPower()
376             // TODO empty txPowerRangeMap + null rxSRGPowerRangeMap is allowed
377             // => confirm this behavior is OK
378         }
379         if (rxSRGPowerRangeMap.isEmpty()) {
380             LOG.info("SRG Power Range not found, setting the Transponder range to default");
381             return powerVal;
382         }
383
384         powerVal = new BigDecimal(txPowerRangeMap.get("MaxTx"))
385             .min(new BigDecimal(rxSRGPowerRangeMap.get("MaxRx")));
386         LOG.info("Calculated Transponder Power value is {}" , powerVal);
387         return powerVal;
388     }
389
390
391     private BigDecimal getRdmPowerValue(BigDecimal spanLossTx, ServicePowerSetupInput input) {
392         // TODO: These values will be obtained from the specifications
393         // power-value here refers to the Pin[50GHz]
394         BigDecimal powerValue;
395         if (spanLossTx.doubleValue()  >= 23.0) {
396             powerValue = BigDecimal.valueOf(2.0);
397         } else if (spanLossTx.doubleValue()  >= 8.0) {
398             powerValue = BigDecimal.valueOf(- (8.0 - spanLossTx.doubleValue()) / 3.0 - 3.0);
399         } else if (spanLossTx.doubleValue() >= 6.0) {
400             powerValue = BigDecimal.valueOf(-3.0);
401         } else {
402             powerValue = spanLossTx.subtract(BigDecimal.valueOf(9));
403         }
404         BigDecimal mcWidth = new BigDecimal(50);
405         // we work at constant power spectral density (50 GHz channel width @-20dBm=37.5GHz)
406         // 87.5 GHz channel width @-20dBm=75GHz
407         if (input.getMcWidth() != null) {
408             // Units of MC-width are in GHz, meaning it should be 40/50/87.5GHz
409             // TODO: Should we validate this units before proceeding?
410             LOG.debug("Input Grid size is {}", input.getMcWidth().getValue());
411
412             // We round-off the mc-width to the nearest grid-value based on the granularity of 12.5 GHz
413             double nbrMcSlots = Math.ceil(input.getMcWidth().getValue().doubleValue() / MC_WIDTH_GRAN);
414             LOG.debug("Nearest (ceil) number of slots {}", nbrMcSlots);
415             mcWidth = new BigDecimal(MC_WIDTH_GRAN * nbrMcSlots);
416             LOG.debug("Given mc-width={}, Rounded mc-width={}", input.getMcWidth().getValue(), mcWidth);
417
418             BigDecimal logVal = mcWidth.divide(new BigDecimal(50));
419             double pdsVal = 10 * Math.log10(logVal.doubleValue());
420             // Addition of PSD value will give Pin[87.5 GHz]
421             powerValue = powerValue.add(new BigDecimal(pdsVal, new MathContext(3, RoundingMode.HALF_EVEN)));
422         }
423         // FIXME compliancy with OpenROADM MSA and approximations used -- should be addressed with powermask update
424         // cf JIRA ticket https://jira.opendaylight.org/browse/TRNSPRTPCE-494
425         powerValue = powerValue.setScale(2, RoundingMode.CEILING);
426         // target-output-power yang precision is 2, so we limit here to 2
427         LOG.info("The power value is P1[{}GHz]={} dB for spanloss {}", mcWidth, powerValue, spanLossTx);
428         return powerValue;
429     }
430
431     /**
432      * This methods turns down power a WL by performing
433      * following steps:
434      *
435      * <p>
436      * 1. Pull interfaces used in service and change
437      * status to outOfService
438      *
439      * <p>
440      * 2. For each of the ROADM node set target-output-power
441      * to -60dbm, wait for 20 seconds, turn power mode to off
442      *
443      * <p>
444      * 3. Turn down power in Z to A direction and A to Z
445      *
446      * @param input
447      *            Input parameter from the olm servicePowerTurndown rpc
448      *
449      * @return true/false based on status of operation
450      */
451     public Boolean powerTurnDown(ServicePowerTurndownInput input) {
452         LOG.info("Olm-powerTurnDown initiated for input {}", input);
453         /*Starting with last element into the list Z -> A for
454           turning down A -> Z */
455         String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
456                 input.getLowerSpectralSlotNumber().toString(),
457                 input.getHigherSpectralSlotNumber().toString());
458         for (int i = input.getNodes().size() - 1; i >= 0; i--) {
459             String nodeId = input.getNodes().get(i).getNodeId();
460             String destTpId = input.getNodes().get(i).getDestTp();
461             String connectionNumber =  String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
462                     input.getNodes().get(i).getSrcTp(), destTpId, spectralSlotName);
463             try {
464                 if (destTpId.toUpperCase(Locale.getDefault()).contains("DEG")) {
465                     if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Power.getName(),
466                             Decimal64.valueOf("-60"), connectionNumber)) {
467                         LOG.warn("Power down failed for Roadm-connection: {}", connectionNumber);
468                         return false;
469                     }
470                     Thread.sleep(timer2);
471                     if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Off.getName(), null, connectionNumber)) {
472                         LOG.warn("Setting power-control mode off failed for Roadm-connection: {}", connectionNumber);
473                         return false;
474                     }
475                 } else if (destTpId.toUpperCase(Locale.getDefault()).contains("SRG")) {
476                     if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Off.getName(), null, connectionNumber)) {
477                         LOG.warn("Setting power-control mode off failed for Roadm-connection: {}", connectionNumber);
478                         // FIXME a return false would allow sync with DEG case but makes current Unit tests fail
479                     }
480                 }
481             } catch (InterruptedException e) {
482                 // TODO Auto-generated catch block
483                 LOG.error("Olm-powerTurnDown wait failed: ",e);
484                 return false;
485             }
486         }
487         return true;
488     }
489
490     /**
491      * This method retrieves transponder OCH interface and
492      * sets power.
493      *
494      * @param nodeId
495      *            Unique identifier for the mounted netconf- node
496      * @param interfaceName
497      *            OCH interface name carrying WL
498      * @param txPower
499      *            Calculated transmit power
500      * @param openroadmVersion
501      *            Version of openRoadm device software
502      * @return true/false based on status of operation
503      */
504     private boolean callSetTransponderPower(String nodeId, String interfaceName, BigDecimal txPower,
505                                             OpenroadmNodeVersion openroadmVersion) {
506
507         boolean powerSetupResult = false;
508         try {
509             switch (openroadmVersion.getIntValue()) {
510                 case 1:
511                     Optional<Interface> interfaceOptional121 =
512                         openRoadmInterfaces.getInterface(nodeId, interfaceName);
513                     if (interfaceOptional121.isEmpty()) {
514                         LOG.error(INTERFACE_NOT_PRESENT, interfaceName, nodeId);
515                         return false;
516                     }
517                     powerSetupResult = PowerMgmtVersion121.setTransponderPower(nodeId, interfaceName,
518                             txPower, deviceTransactionManager, interfaceOptional121.orElseThrow());
519                     break;
520                 case 2:
521                     Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp
522                             .Interface> interfaceOptional221 =
523                         openRoadmInterfaces.getInterface(nodeId, interfaceName);
524                     if (interfaceOptional221.isEmpty()) {
525                         LOG.error(INTERFACE_NOT_PRESENT, interfaceName, nodeId);
526                         return false;
527                     }
528                     powerSetupResult = PowerMgmtVersion221.setTransponderPower(nodeId, interfaceName,
529                             txPower, deviceTransactionManager, interfaceOptional221.orElseThrow());
530                     break;
531                 case 3:
532                     Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp
533                             .Interface> interfaceOptional710 =
534                         openRoadmInterfaces.getInterface(nodeId, interfaceName);
535                     if (interfaceOptional710.isEmpty()) {
536                         LOG.error(INTERFACE_NOT_PRESENT, interfaceName, nodeId);
537                         return false;
538                     }
539                     // Check the support-interface-cap type
540                     // Get the logical connection point name from the interface-name, by splitting it by "-"
541                     // and discard the last part. For instance XPDR1-NETWORK1-xxx:xxx
542                     String logicalConnectionPoint =
543                         Arrays.stream(interfaceName.split("-", 3)).limit(2).collect(Collectors.joining("-"));
544                     LOG.info("Logical connection point {} for Interface {}", logicalConnectionPoint, interfaceName);
545                     Mapping portMap = portMapping.getMapping(nodeId, logicalConnectionPoint);
546                     if (portMap == null) {
547                         throw new OpenRoadmInterfaceException(
548                                 OpenRoadmInterfaceException.mapping_msg_err(nodeId, logicalConnectionPoint));
549                     }
550                     powerSetupResult = PowerMgmtVersion710.setTransponderPower(nodeId, interfaceName,
551                         txPower, deviceTransactionManager, interfaceOptional710.orElseThrow(), portMap);
552                     break;
553                 default:
554                     LOG.error("Unrecognized OpenRoadm version");
555                     return false;
556             }
557         } catch (OpenRoadmInterfaceException ex) {
558             LOG.error("Failed to get interface {} from node {}!", interfaceName, nodeId, ex);
559             return false;
560         }
561         if (!powerSetupResult) {
562             LOG.debug("Transponder power setup failed for nodeId {} on interface {}",
563                     nodeId, interfaceName);
564             return false;
565         }
566         LOG.debug("Transponder power set up completed successfully for nodeId {} and interface {}",
567                 nodeId,interfaceName);
568         return true;
569     }
570
571 }