Adapt TransportPCE code to Sulfur
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / ModelMappingUtils.java
index d6ccdfb3189a600e5331b0007101e59906222814..8197b9ba06e47c79036d260987122550521d264c 100644 (file)
@@ -8,11 +8,14 @@
 package org.opendaylight.transportpce.renderer;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.stream.Collectors;
 import org.opendaylight.transportpce.common.NodeIdPair;
@@ -36,13 +39,13 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OpucnTribSlotDef;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection;
@@ -51,9 +54,10 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdes
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.Resource;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.Link;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.NodesBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.NodesKey;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.NodesBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.NodesKey;
+import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.common.Uint32;
@@ -79,14 +83,19 @@ public final class ModelMappingUtils {
             olmSetupBldr.setWaveNumber(atoZDirection.getAToZWavelengthNumber());
             if (atoZDirection.getAToZMinFrequency() != null) {
                 olmSetupBldr.setLowerSpectralSlotNumber(Uint32
-                        .valueOf(GridUtils
-                                .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
+                    .valueOf(GridUtils
+                        .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
             }
             if (atoZDirection.getAToZMaxFrequency() != null) {
                 olmSetupBldr.setHigherSpectralSlotNumber(Uint32
-                        .valueOf(GridUtils
-                                .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
+                    .valueOf(GridUtils
+                        .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
             }
+            // Set the MC-width for the OLM
+            olmSetupBldr.setMcWidth(new FrequencyGHz(Decimal64.valueOf(
+                    atoZDirection.getAToZMaxFrequency().getValue().decimalValue()
+                    .subtract(atoZDirection.getAToZMinFrequency().getValue().decimalValue())
+                    .multiply(new BigDecimal(1000)))));
         }
         return olmSetupBldr.build();
     }
@@ -130,7 +139,10 @@ public final class ModelMappingUtils {
             .setServiceName(serviceName)
             .setOperation(operation)
             .setNodes(nodeLists.getRendererNodeList())
-            .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
+            .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
+            .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
+                    pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
+                    .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
         if (atoZDirection.getAToZWavelengthNumber() != null) {
             servicePathInputBuilder
                 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
@@ -152,9 +164,10 @@ public final class ModelMappingUtils {
                             .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
         }
         if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
-            servicePathInputBuilder.setCenterFreq(
-                    GridUtils.getCentralFrequencyWithPrecision(atoZDirection.getAToZMinFrequency().getValue(),
-                            atoZDirection.getAToZMaxFrequency().getValue(), scale));
+            servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
+                    atoZDirection.getAToZMinFrequency().getValue().decimalValue(),
+                    atoZDirection.getAToZMaxFrequency().getValue().decimalValue(),
+                    scale));
         }
         if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
@@ -163,7 +176,7 @@ public final class ModelMappingUtils {
                     && GridConstant.FREQUENCY_WIDTH_TABLE
                     .contains(atoZDirection.getRate(), optionalModulationFormat.get())) {
                 servicePathInputBuilder
-                    .setWidth(FrequencyGHz
+                    .setNmcWidth(FrequencyGHz
                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
                         optionalModulationFormat.get())));
             }
@@ -184,7 +197,10 @@ public final class ModelMappingUtils {
             .setOperation(operation)
             .setServiceName(serviceName)
             .setNodes(nodeLists.getRendererNodeList())
-            .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
+            .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
+            .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
+                    pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
+                    .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
         if (ztoADirection.getZToAWavelengthNumber() != null) {
             servicePathInputBuilder
                 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
@@ -206,9 +222,10 @@ public final class ModelMappingUtils {
                             .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
         }
         if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
-            servicePathInputBuilder.setCenterFreq(
-                    GridUtils.getCentralFrequencyWithPrecision(ztoADirection.getZToAMinFrequency().getValue(),
-                            ztoADirection.getZToAMaxFrequency().getValue(), scale));
+            servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
+                    ztoADirection.getZToAMinFrequency().getValue().decimalValue(),
+                    ztoADirection.getZToAMaxFrequency().getValue().decimalValue(),
+                    scale));
         }
         if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
@@ -216,7 +233,7 @@ public final class ModelMappingUtils {
             if (optionalModulationFormat.isPresent()
                     && GridConstant.FREQUENCY_WIDTH_TABLE
                     .contains(ztoADirection.getRate(), optionalModulationFormat.get())) {
-                servicePathInputBuilder.setWidth(FrequencyGHz
+                servicePathInputBuilder.setNmcWidth(FrequencyGHz
                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
                                 optionalModulationFormat.get())));
             }
@@ -231,7 +248,7 @@ public final class ModelMappingUtils {
     public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
         String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
         // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
-        List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.Nodes> nodes =
+        List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.Nodes> nodes =
             new ArrayList<>();
         NodeLists nodeLists =
             (asideToZside)
@@ -239,8 +256,8 @@ public final class ModelMappingUtils {
             : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
         LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
         for (Nodes node: nodeLists.getRendererNodeList()) {
-            org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.NodesBuilder nb
-                = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes
+            org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.NodesBuilder nb
+                = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes
                     .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
             if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
                 nb.setNetwork2Tp(node.getSrcTp());
@@ -268,10 +285,13 @@ public final class ModelMappingUtils {
                 .setTribPortNumber(tribPort)
                 .setTribSlot(minTribSlot);
         }
-        if (serviceRate.intValue() == 100) {
-            List<OpucnTribSlotDef> opucnTribSlotDefList = new ArrayList<>();
-            opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMinTribSlot());
-            opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMaxTribSlot());
+        if (serviceRate.intValue() == 100 && pathDescription.getAToZDirection().getMinTribSlot() != null
+                && pathDescription.getAToZDirection().getMaxTribSlot() != null) {
+            Set<OpucnTribSlotDef> opucnTribSlotDefList = new HashSet<>();
+            opucnTribSlotDefList.add(
+                new OpucnTribSlotDef(pathDescription.getAToZDirection().getMinTribSlot().getValue()));
+            opucnTribSlotDefList.add(
+                new OpucnTribSlotDef(pathDescription.getAToZDirection().getMaxTribSlot().getValue()));
             otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
         }
         return otnServicePathInputBuilder.build();
@@ -283,8 +303,8 @@ public final class ModelMappingUtils {
         return new ServicePathInputBuilder().setServiceName(serviceName).build();
     }
 
-    public static List<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
-        List<String> linkidList = new ArrayList<>();
+    public static Set<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
+        Set<String> linkidList = new HashSet<>();
         pathDescription.getAToZDirection().getAToZ().values().stream()
             .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
             .forEach(rsc -> {
@@ -496,7 +516,7 @@ public final class ModelMappingUtils {
                 return Map.of("nodeId", nodeId, "tpid", lcp);
             }
         }
-        return null;
+        return Map.of();
     }
 
     private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
@@ -513,7 +533,7 @@ public final class ModelMappingUtils {
                 return Map.of("nodeId", nodeId, "tpid", lcp);
             }
         }
-        return null;
+        return Map.of();
     }
 
     private static Map<String, String> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
@@ -530,7 +550,7 @@ public final class ModelMappingUtils {
                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
             }
         }
-        return null;
+        return Map.of();
     }
 
     private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
@@ -547,6 +567,6 @@ public final class ModelMappingUtils {
                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
             }
         }
-        return null;
+        return Map.of();
     }
 }