Refactor: update transportpce yang models
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / ModelMappingUtils.java
index 7e98e42fb38704f0e409a02fbbda68104d58e5d1..d4445c8845bbdc8a7c05bb2dbe088b8e504df55c 100644 (file)
@@ -18,32 +18,33 @@ import org.opendaylight.transportpce.common.NodeIdPair;
 import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.OtnServicePathInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.OtnServicePathInputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.ServicePathInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.ServicePathInputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceImplementationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceImplementationRequestOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceImplementationRequestOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.Action;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathInputBuilder;
+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.ServicePowerSetupInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceDeleteOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceDeleteOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceImplementationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceImplementationRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.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.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.service.rev190531.ServiceDeleteInput;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.PathDescription;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.AToZDirection;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.ZToADirection;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.atoz.direction.AToZ;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.path.description.ztoa.direction.ZToA;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201126.pce.resource.resource.resource.TerminationPoint;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev201211.olm.renderer.input.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev201211.olm.renderer.input.NodesBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev201211.olm.renderer.input.NodesKey;
+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;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
+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.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.common.Uint32;
@@ -112,18 +113,23 @@ public final class ModelMappingUtils {
 
     public static ServicePathInputData rendererCreateServiceInputAToZ(String serviceName,
             PathDescription pathDescription) {
+        int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
         AToZDirection atoZDirection = pathDescription.getAToZDirection();
         LOG.info("Building ServicePathInputData for a to z direction {}", atoZDirection);
         NodeLists nodeLists = getNodesListAToZ(atoZDirection.nonnullAToZ().values().iterator());
         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
             .setServiceName(serviceName)
-            .setOperation(ServicePathInput.Operation.Create)
+            .setOperation(Action.Create)
             .setNodes(nodeLists.getList())
             .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
         if (atoZDirection.getAToZWavelengthNumber() != null) {
             servicePathInputBuilder
                 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
         }
+        if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
+                .equals(atoZDirection.getAToZWavelengthNumber())) {
+            scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
+        }
         if (atoZDirection.getAToZMinFrequency() != null) {
             servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
@@ -139,7 +145,7 @@ public final class ModelMappingUtils {
         if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
             servicePathInputBuilder.setCenterFreq(
                     GridUtils.getCentralFrequencyWithPrecision(atoZDirection.getAToZMinFrequency().getValue(),
-                            atoZDirection.getAToZMaxFrequency().getValue(), GridConstant.FREQUENCY_PRECISION));
+                            atoZDirection.getAToZMaxFrequency().getValue(), scale));
         }
         if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
@@ -159,11 +165,12 @@ public final class ModelMappingUtils {
 
     public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
             PathDescription pathDescription) {
+        int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
         ZToADirection ztoADirection = pathDescription.getZToADirection();
         LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
         NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
-            .setOperation(ServicePathInput.Operation.Create)
+            .setOperation(Action.Create)
             .setServiceName(serviceName)
             .setNodes(nodeLists.getList())
             .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
@@ -171,6 +178,10 @@ public final class ModelMappingUtils {
             servicePathInputBuilder
                 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
         }
+        if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
+                .equals(ztoADirection.getZToAWavelengthNumber())) {
+            scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
+        }
         if (ztoADirection.getZToAMinFrequency() != null) {
             servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
@@ -186,7 +197,7 @@ public final class ModelMappingUtils {
         if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
             servicePathInputBuilder.setCenterFreq(
                     GridUtils.getCentralFrequencyWithPrecision(ztoADirection.getZToAMinFrequency().getValue(),
-                            ztoADirection.getZToAMaxFrequency().getValue(), GridConstant.FREQUENCY_PRECISION));
+                            ztoADirection.getZToAMaxFrequency().getValue(), scale));
         }
         if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
@@ -204,10 +215,10 @@ public final class ModelMappingUtils {
     }
 
     // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
-    public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, String serviceType,
-        String serviceRate, PathDescription pathDescription, boolean asideToZside) {
+    public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, 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.rev201211.otn.renderer.input.Nodes> nodes =
+        List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.Nodes> nodes =
             new ArrayList<>();
         NodeLists nodeLists = getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator());
         if (!asideToZside) {
@@ -215,9 +226,8 @@ public final class ModelMappingUtils {
         }
         LOG.info("These are node-lists {}, {}", nodeLists.getList(), nodeLists.getOlmList());
         for (Nodes node: nodeLists.getList()) {
-            nodes.add(
-                    new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev201211.otn.renderer.input
-                        .NodesBuilder()
+            nodes.add(new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes
+                .NodesBuilder()
                             .setNodeId(node.getNodeId())
                             .setClientTp(node.getSrcTp())
                             .setNetworkTp(node.getDestTp())
@@ -225,15 +235,19 @@ public final class ModelMappingUtils {
         }
         OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
             .setServiceName(serviceName)
-            .setServiceType(serviceType)
+            .setServiceFormat(serviceFormat)
             .setServiceRate(serviceRate)
             .setNodes(nodes);
 
         // set the trib-slots and trib-ports for the lower oder odu
-        if (serviceRate.equals("1G") || (serviceRate.equals("10G"))) {
+        if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
+            Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
+                .split("\\.")[0]);
+            Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
+                .split("\\.")[1]);
             otnServicePathInputBuilder
-                .setTribPortNumber(pathDescription.getAToZDirection().getTribPortNumber().shortValue())
-                .setTribSlot(pathDescription.getAToZDirection().getTribSlotNumber().shortValue());
+                .setTribPortNumber(tribPort)
+                .setTribSlot(minTribSlot);
         }
         return otnServicePathInputBuilder.build();
     }