Power control support for 87.5GHz spectrum width
[transportpce.git] / olm / src / main / java / org / opendaylight / transportpce / olm / power / PowerMgmtImpl.java
index 407bfae2d22426a8d2931ff90f49c7cfafa8536e..a000afb5e5373b68f5fa0b9ef83440b8fd6c69e2 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.transportpce.olm.power;
 import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -21,10 +23,10 @@ import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfa
 import org.opendaylight.transportpce.olm.util.OlmUtils;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.OpenroadmNodeVersion;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.OpenroadmNodeVersion;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.MappingKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.network.Nodes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticalControlMode;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1;
@@ -41,6 +43,11 @@ public class PowerMgmtImpl implements PowerMgmt {
     private static final BigDecimal DEFAULT_TPDR_PWR_400G = new BigDecimal(0);
     private static final String INTERFACE_NOT_PRESENT = "Interface {} on node {} is not present!";
 
+    private long timer1 = 120000;
+    // openroadm spec value is 120000, functest value is 3000
+    private long timer2 = 20000;
+    // openroadm spec value is 20000, functest value is 2000
+
     public PowerMgmtImpl(DataBroker db, OpenRoadmInterfaces openRoadmInterfaces,
                          CrossConnect crossConnect, DeviceTransactionManager deviceTransactionManager) {
         this.db = db;
@@ -49,6 +56,29 @@ public class PowerMgmtImpl implements PowerMgmt {
         this.deviceTransactionManager = deviceTransactionManager;
     }
 
+    public PowerMgmtImpl(DataBroker db, OpenRoadmInterfaces openRoadmInterfaces,
+                         CrossConnect crossConnect, DeviceTransactionManager deviceTransactionManager,
+                         String timer1, String timer2) {
+        this.db = db;
+        this.openRoadmInterfaces = openRoadmInterfaces;
+        this.crossConnect = crossConnect;
+        this.deviceTransactionManager = deviceTransactionManager;
+        try {
+            this.timer1 = Long.parseLong(timer1);
+        } catch (NumberFormatException e) {
+            this.timer1 = 120000;
+            LOG.warn("Failed to retrieve Olm timer1 value from configuration - using default value {}",
+                this.timer1, e);
+        }
+        try {
+            this.timer2 = Long.parseLong(timer2);
+        } catch (NumberFormatException e) {
+            this.timer2 = 20000;
+            LOG.warn("Failed to retrieve Olm timer2 value from configuration - using default value {}",
+                this.timer2, e);
+        }
+    }
+
     /**
      * This methods measures power requirement for turning up a WL
      * from the Spanloss at OTS transmit direction and update
@@ -108,7 +138,7 @@ public class PowerMgmtImpl implements PowerMgmt {
                     LOG.info("Transponder OCH connection: {} power updated ", interfaceName);
                     try {
                         LOG.info("Now going in sleep mode");
-                        Thread.sleep(OlmUtils.OLM_TIMER_1);
+                        Thread.sleep(timer1);
                     } catch (InterruptedException e) {
                         LOG.info("Transponder warmup failed for OCH connection: {}", interfaceName, e);
                         // FIXME shouldn't it be LOG.warn  or LOG.error?
@@ -159,7 +189,7 @@ public class PowerMgmtImpl implements PowerMgmt {
                             return false;
                         }
                         LOG.info("Roadm-connection: {} updated ", connectionNumber);
-                        Thread.sleep(OlmUtils.OLM_TIMER_2);
+                        Thread.sleep(timer2);
                         // TODO make this timer value configurable via OSGi blueprint
                         // although the value recommended by the white paper is 20 seconds.
                         // At least one vendor product needs 60 seconds
@@ -342,15 +372,17 @@ public class PowerMgmtImpl implements PowerMgmt {
         BigDecimal powerValue = spanLossTx.subtract(BigDecimal.valueOf(9)).min(BigDecimal.valueOf(2));
         // we work at constant power spectral density (50 GHz channel width @-20dBm=37.5GHz)
         // 87.5 GHz channel width @-20dBm=75GHz
-        if (input.getWidth() != null) {
-            BigDecimal gridSize = input.getWidth().getValue();
-            LOG.debug("Input Gridsize is {}",gridSize);
-            if (gridSize.equals(GridConstant.WIDTH_80)) {
+        if (input.getMcWidth() != null) {
+            LOG.debug("Input Gridsize is {}",input.getMcWidth().getValue());
+            if (input.getMcWidth().getValue().equals(GridConstant.WIDTH_80)) {
                 powerValue = powerValue.add(BigDecimal.valueOf(3));
+            } else if (input.getMcWidth().getValue().equals(GridConstant.SLOT_WIDTH_87_5)) {
+                BigDecimal logVal = GridConstant.SLOT_WIDTH_87_5.divide(new BigDecimal(50));
+                double pdsVal = 10 * Math.log10(logVal.doubleValue());
+                powerValue = powerValue.add(new BigDecimal(pdsVal, new MathContext(3, RoundingMode.HALF_EVEN)));
             }
-            // TODO no default or warning for unsupported grid sizes ?
         }
-        // FIXME compliancy with OpenROADM MSA and approximations used
+        // FIXME compliancy with OpenROADM MSA and approximations used -- should be addressed with powermask update
         // cf JIRA ticket https://jira.opendaylight.org/browse/TRNSPRTPCE-494
         LOG.info("Power Value is {}", powerValue);
         return powerValue;
@@ -395,7 +427,7 @@ public class PowerMgmtImpl implements PowerMgmt {
                         LOG.warn("Power down failed for Roadm-connection: {}", connectionNumber);
                         return false;
                     }
-                    Thread.sleep(OlmUtils.OLM_TIMER_2);
+                    Thread.sleep(timer2);
                     if (!crossConnect.setPowerLevel(nodeId, OpticalControlMode.Off.getName(), null, connectionNumber)) {
                         LOG.warn("Setting power-control mode off failed for Roadm-connection: {}", connectionNumber);
                         return false;