Adapt TransportPCE code to Sulfur
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmInterface710.java
index 51fdf96269f14444154ed275a2494318baaa050e..3faf35b87e34edf7640705239cb1a522ded8b0c7 100644 (file)
@@ -8,11 +8,13 @@
 
 package org.opendaylight.transportpce.renderer.openroadminterface;
 
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 import java.util.stream.IntStream;
 import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
@@ -77,6 +79,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If100GE;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCHOTU4ODU4;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOtsiOtsigroup;
+import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.common.Uint8;
@@ -149,9 +152,9 @@ public class OpenRoadmInterface710 {
         }
         // OCH interface specific data
         OchBuilder ocIfBuilder = new OchBuilder()
-            .setFrequency(new FrequencyTHz(spectrumInformation.getCenterFrequency()))
+            .setFrequency(new FrequencyTHz(Decimal64.valueOf(spectrumInformation.getCenterFrequency())))
             .setRate(R100G.class)
-            .setTransmitPower(new PowerDBm(new BigDecimal("-5")))
+            .setTransmitPower(new PowerDBm(Decimal64.valueOf("-5")))
             .setModulationFormat(modulationFormat);
         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
         if (portMap == null) {
@@ -197,8 +200,8 @@ public class OpenRoadmInterface710 {
 
         // OTSI interface specific data
         OtsiBuilder  otsiBuilder = new OtsiBuilder()
-            .setFrequency(new FrequencyTHz(spectrumInformation.getCenterFrequency()))
-            .setTransmitPower(new PowerDBm(new BigDecimal("-5")))
+            .setFrequency(new FrequencyTHz(Decimal64.valueOf(spectrumInformation.getCenterFrequency())))
+            .setTransmitPower(new PowerDBm(Decimal64.valueOf("-5")))
             .setProvisionMode(ProvisionModeType.Explicit)
             .setFec(Ofec.class)
             .setModulationFormat(modulationFormat);
@@ -343,7 +346,7 @@ public class OpenRoadmInterface710 {
             logicalConnPoint + String.join("-", "", "OTSIGROUP", serviceRate + "G"));
 
         // Create a list
-        List<String> listSupportingOtsiInterface = new ArrayList<>();
+        Set<String> listSupportingOtsiInterface = new HashSet<>();
         listSupportingOtsiInterface.add(supportingOtsiInterface);
         otsiGroupInterfaceBldr.setSupportingInterfaceList(listSupportingOtsiInterface);
 
@@ -399,7 +402,7 @@ public class OpenRoadmInterface710 {
             otuInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOtu.class,
             logicalConnPoint + "-OTU4");
         // Supporting interface list
-        List<String> listSupportingOChInterface = new ArrayList<>();
+        Set<String> listSupportingOChInterface = new HashSet<>();
         listSupportingOChInterface.add(supportOchInterface);
         otuInterfaceBldr.setSupportingInterfaceList(listSupportingOChInterface);
 
@@ -500,7 +503,7 @@ public class OpenRoadmInterface710 {
             logicalConnPoint + "-OTUC" + otucnrate);
 
         // Create a list
-        List<String> listSupportingOtsiGroupInterface = new ArrayList<>();
+        Set<String> listSupportingOtsiGroupInterface = new HashSet<>();
         listSupportingOtsiGroupInterface.add(supportingOtsiGroupInterface);
 
         otuInterfaceBuilder.setSupportingInterfaceList(listSupportingOtsiGroupInterface);
@@ -553,7 +556,7 @@ public class OpenRoadmInterface710 {
         }
         InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
             logicalConnPoint + "-ODU4");
-        List<String> listSupportingOtu4Interface = new ArrayList<>();
+        Set<String> listSupportingOtu4Interface = new HashSet<>();
         if (mapping.getSupportingOtu4() != null) {
             listSupportingOtu4Interface.add(mapping.getSupportingOtu4());
             oduInterfaceBldr.setSupportingInterfaceList(listSupportingOtu4Interface);
@@ -627,7 +630,7 @@ public class OpenRoadmInterface710 {
 
         // Create a list
         String supportingOtucn;
-        List<String> listSupportingOtucnInterface = new ArrayList<>();
+        Set<String> listSupportingOtucnInterface = new HashSet<>();
         if (mapping.getSupportingOtucn() != null) {
             listSupportingOtucnInterface.add(mapping.getSupportingOtucn());
             supportingOtucn = mapping.getSupportingOtucn();
@@ -722,7 +725,7 @@ public class OpenRoadmInterface710 {
             alogicalConnPoint + ODUC + oducnrate);
 
         // Create a list
-        List<String> listSupportingOtucnInterface = new ArrayList<>();
+        Set<String> listSupportingOtucnInterface = new HashSet<>();
         listSupportingOtucnInterface.add(supportingOtucn);
 
         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
@@ -756,7 +759,7 @@ public class OpenRoadmInterface710 {
 
         // Parent Odu-allocation
         // Set the trib-slot array
-        List<OpucnTribSlotDef> tribslots = new ArrayList<>();
+        Set<OpucnTribSlotDef> tribslots = new HashSet<>();
         // Here the int stream is based on rate
         // Get the rate, which can be 1, 2, 3 or 4 4=400G, 1=100G
         String rate = supportingOducn.substring(supportingOducn.length() - 1);
@@ -798,7 +801,7 @@ public class OpenRoadmInterface710 {
         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
             logicalConnPoint);
 
-        List<String> listSupportingOtucnInterface = new ArrayList<>();
+        Set<String> listSupportingOtucnInterface = new HashSet<>();
         listSupportingOtucnInterface.add(supportingOducn);
 
         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
@@ -841,7 +844,7 @@ public class OpenRoadmInterface710 {
         }
         // Parent Odu-allocation
         // Set the trib-slot array
-        List<OpucnTribSlotDef> tribslots = new ArrayList<>();
+        Set<OpucnTribSlotDef> tribslots = new HashSet<>();
         // Here the int stream is based on rate
         // Get the rate, which can be 1, 2, 3 or 4 4=400G, 1=100G
         String rate = supportingOducn.substring(supportingOducn.lastIndexOf('-') + 1);
@@ -882,7 +885,7 @@ public class OpenRoadmInterface710 {
             alogicalConnPoint);
 
 
-        List<String> listSupportingOtucnInterface = new ArrayList<>();
+        Set<String> listSupportingOtucnInterface = new HashSet<>();
         listSupportingOtucnInterface.add(supportingOducn);
 
         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
@@ -971,7 +974,7 @@ public class OpenRoadmInterface710 {
             logicalConnPoint + ODUC + oducnrate);
 
         // Create a list
-        List<String> listSupportingOtucnInterface = new ArrayList<>();
+        Set<String> listSupportingOtucnInterface = new HashSet<>();
         listSupportingOtucnInterface.add(supportingOtucn);
 
         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
@@ -1047,7 +1050,7 @@ public class OpenRoadmInterface710 {
             alogicalConnPoint + ODUC + oducnrate);
 
         // Create a list
-        List<String> listSupportingOtucnInterface = new ArrayList<>();
+        Set<String> listSupportingOtucnInterface = new HashSet<>();
         listSupportingOtucnInterface.add(supportingOtucn);
 
         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
@@ -1090,45 +1093,41 @@ public class OpenRoadmInterface710 {
         justification = "call in call() method")
     private int getServiceRate(ModulationFormat modulationFormat, SpectrumInformation spectrumInformation) {
 
-        double spectralWidth = (spectrumInformation.getHigherSpectralSlotNumber()
-            - spectrumInformation.getLowerSpectralSlotNumber() + 1) * GridConstant.GRANULARITY;
+        int rate;
         switch (modulationFormat) {
             case DpQpsk:
-                // DpQpsk is possible for both 31.6 or 63.1 GBaud, for which spectral width is different
-                // Here take the difference of highest and lowest spectral numbers and determine the width
-                LOG.info("The width with guard band {}", spectralWidth);
-                if (spectralWidth == 50.0) {
-                    // Based on roll-of-factor of 0.2, 50 - 12.5 = 37.5GHz translates to 31.6 GBaud
-                    LOG.info("The baud-rate is 31.6 GBaud");
-                    LOG.info("Given modulation format {} with 31.6 Gbaud rate is 100G", modulationFormat);
-                    return 100;
-                } else {
-                    // Based on roll-of-factor of 0.2, 87.5 - 12.5 = 75GHz translates to 63.1 GBaud
-                    LOG.info("The baud-rate is 63.1 GBaud");
-                    return 200;
-                }
-            case DpQam8:
-                LOG.info("Given modulation format is {} and thus rate is 300G", modulationFormat);
-                return 300;
             case DpQam16:
-                // DpQam16 is possible for both 31.6 or 63.1 GBaud, for which spectral width is different
+                // DpQpsk and DpQam16 are possible for both 31.6 or 63.1 GBaud, for which spectral width is different
                 // Here take the difference of highest and lowest spectral numbers and determine the width
+                double spectralWidth = (spectrumInformation.getHigherSpectralSlotNumber()
+                    - spectrumInformation.getLowerSpectralSlotNumber() + 1) * GridConstant.GRANULARITY;
                 LOG.info("The width with guard band {}", spectralWidth);
+                Map<ModulationFormat, Integer> rateMap;
                 if (spectralWidth == 50.0) {
+                    rateMap = Map.of(
+                            ModulationFormat.DpQpsk , 100,
+                            ModulationFormat.DpQam16 , 200);
                     // Based on roll-of-factor of 0.2, 50 - 12.5 = 37.5GHz translates to 31.6 GBaud
                     LOG.info("The baud-rate is 31.6 GBaud");
-                    LOG.info("Given modulation format {} with 31.6 Gbaud rate is 200G", modulationFormat);
-                    return 200;
+                    return rateMap.get(modulationFormat);
                 } else {
+                    rateMap = Map.of(
+                            ModulationFormat.DpQpsk , 200,
+                            ModulationFormat.DpQam16 , 400);
                     // Based on roll-of-factor of 0.2, 87.5 - 12.5 = 75GHz translates to 63.1 GBaud
                     LOG.info("The baud-rate is 63.1 GBaud");
-                    return 400;
                 }
+                rate = rateMap.get(modulationFormat);
+                break;
+            case DpQam8:
+                rate = 300;
+                break;
             default:
                 LOG.error("Modulation format is required to select the rate");
-                break;
+                return 0;
         }
-        return 0;
+        LOG.info("Given modulation format {} rate is {}", modulationFormat, rate);
+        return rate;
     }
 
 }