Use version 13.1.0 of openroadm-service models
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PcePathDescription.java
index 9e5fc4bcd6c7252ac1e442d9453f2e9b8320bb9e..b50ee7aebc2109871923042f8e49cdacacff9330 100644 (file)
@@ -14,27 +14,29 @@ import java.util.Map;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
+import org.opendaylight.transportpce.common.fixedflex.GridUtils;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceLink;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyTHz;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev230526.FrequencyTHz;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.AToZDirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.ZToADirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.atoz.direction.AToZ;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.atoz.direction.AToZBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.atoz.direction.AToZKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.ztoa.direction.ZToA;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.ztoa.direction.ZToABuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.ztoa.direction.ZToAKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.Resource;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.ResourceBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.resource.resource.LinkBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.resource.resource.NodeBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.resource.resource.TerminationPoint;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.resource.resource.TerminationPointBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OpucnTribSlotDef;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZKey;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToA;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToABuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToAKey;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.Resource;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.ResourceBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.LinkBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.NodeBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPoint;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPointBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
-import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -86,35 +88,50 @@ public class PcePathDescription {
      * @return a builder for AtoZDirection object
      */
     private AToZDirectionBuilder buildAtoZDirection(Map<AToZKey, AToZ> atozMap) {
+        ModulationFormat modulationFormat = GridConstant.RATE_MODULATION_FORMAT_MAP
+                .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk);
         AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
             .setRate(Uint32.valueOf(rc.getRate()))
-            .setModulationFormat(GridConstant.RATE_MODULATION_FORMAT_MAP
-                    .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk).getName())
+            .setModulationFormat(modulationFormat.getName())
             .setAToZ(atozMap);
         switch (rc.getServiceType()) {
             case StringConstants.SERVICE_TYPE_400GE:
-            case StringConstants.SERVICE_TYPE_100GE:
+            case StringConstants.SERVICE_TYPE_OTUC2:
+            case StringConstants.SERVICE_TYPE_OTUC3:
+            case StringConstants.SERVICE_TYPE_OTUC4:
+            case StringConstants.SERVICE_TYPE_100GE_T:
             case StringConstants.SERVICE_TYPE_OTU4:
-                atoZDirectionBldr.setAToZMaxFrequency(new FrequencyTHz(rc.getMaxFreq()));
-                atoZDirectionBldr.setAToZMinFrequency(new FrequencyTHz(rc.getMinFreq()));
-                atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
+                atoZDirectionBldr
+                        .setAToZMaxFrequency(new FrequencyTHz(Decimal64.valueOf(rc.getMaxFreq())))
+                        .setAToZMinFrequency(new FrequencyTHz(Decimal64.valueOf(rc.getMinFreq())))
+                        .setAToZWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()))
+                        // Used precision 5 to get the exact decimal values of the frequency
+                        .setCentralFrequency(new FrequencyTHz(GridUtils.getCentralFrequencyWithPrecision(
+                                rc.getMinFreq(), rc.getMaxFreq(), 5).getValue()))
+                        .setWidth(GridUtils.getWidthFromRateAndModulationFormatToModel131(
+                                Uint32.valueOf(rc.getRate()), modulationFormat));
                 break;
+            case StringConstants.SERVICE_TYPE_100GE_M:
+            case StringConstants.SERVICE_TYPE_100GE_S:
             case StringConstants.SERVICE_TYPE_10GE:
             case StringConstants.SERVICE_TYPE_1GE:
             case StringConstants.SERVICE_TYPE_ODU4:
-                if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
-                    @SuppressWarnings("unchecked")
-                    List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
+            case StringConstants.SERVICE_TYPE_ODUC2:
+            case StringConstants.SERVICE_TYPE_ODUC3:
+            case StringConstants.SERVICE_TYPE_ODUC4:
+                if (rc.getResultTribPortTribSlot() != null && rc.getResultTribPortTribSlot().get(0) != null
+                    && rc.getResultTribPortTribSlot().get(1) != null) {
                     atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(0))
-                            .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
-                            .setTribSlotNumber(tribSlotList.get(0));
+                            .setMinTribSlot(rc.getResultTribPortTribSlot().get(0))
+                            .setMaxTribSlot(rc.getResultTribPortTribSlot().get(1));
                 } else {
-                    LOG.error("Trib port and trib slot number should be present");
-                    atoZDirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
+                    LOG.warn("Trib port and trib slot number should be present");
+                    atoZDirectionBldr.setMinTribSlot(new OpucnTribSlotDef("0.0"))
+                        .setMaxTribSlot(new OpucnTribSlotDef("0.0"));
                 }
                 break;
             default:
-                LOG.warn("unknown service type : unable to set Min/Max frequencies");
+                LOG.warn("unknown service type : unable to set Min/Max frequencies or trib-port/trib-slot");
                 break;
         }
         return atoZDirectionBldr;
@@ -126,30 +143,44 @@ public class PcePathDescription {
      * @return a builder for ZtoADirection object
      */
     private ZToADirectionBuilder buildZtoADirection(Map<ZToAKey, ZToA> ztoaMap) {
+        ModulationFormat modulationFormat = GridConstant.RATE_MODULATION_FORMAT_MAP
+                .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk);
         ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder().setRate(Uint32.valueOf(rc.getRate()))
-                .setModulationFormat(GridConstant.RATE_MODULATION_FORMAT_MAP
-                        .getOrDefault(Uint32.valueOf(rc.getRate()), ModulationFormat.DpQpsk).getName())
+                .setModulationFormat(modulationFormat.getName())
                 .setZToA(ztoaMap);
         switch (rc.getServiceType()) {
             case StringConstants.SERVICE_TYPE_400GE:
-            case StringConstants.SERVICE_TYPE_100GE:
+            case StringConstants.SERVICE_TYPE_OTUC2:
+            case StringConstants.SERVICE_TYPE_OTUC3:
+            case StringConstants.SERVICE_TYPE_OTUC4:
+            case StringConstants.SERVICE_TYPE_100GE_T:
             case StringConstants.SERVICE_TYPE_OTU4:
-                ztoADirectionBldr.setZToAMaxFrequency(new FrequencyTHz(rc.getMaxFreq()));
-                ztoADirectionBldr.setZToAMinFrequency(new FrequencyTHz(rc.getMinFreq()));
-                ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
+                ztoADirectionBldr
+                        .setZToAMaxFrequency(new FrequencyTHz(Decimal64.valueOf(rc.getMaxFreq())))
+                        .setZToAMinFrequency(new FrequencyTHz(Decimal64.valueOf(rc.getMinFreq())))
+                        .setZToAWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()))
+                        .setCentralFrequency(new FrequencyTHz(GridUtils.getCentralFrequencyWithPrecision(
+                                rc.getMinFreq(), rc.getMaxFreq(), 4).getValue()))
+                        .setWidth(GridUtils.getWidthFromRateAndModulationFormatToModel131(
+                                Uint32.valueOf(rc.getRate()), modulationFormat));
                 break;
+            case StringConstants.SERVICE_TYPE_100GE_M:
+            case StringConstants.SERVICE_TYPE_100GE_S:
             case StringConstants.SERVICE_TYPE_10GE:
             case StringConstants.SERVICE_TYPE_1GE:
             case StringConstants.SERVICE_TYPE_ODU4:
-                if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
-                    @SuppressWarnings("unchecked")
-                    List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
+            case StringConstants.SERVICE_TYPE_ODUC2:
+            case StringConstants.SERVICE_TYPE_ODUC3:
+            case StringConstants.SERVICE_TYPE_ODUC4:
+                if (rc.getResultTribPortTribSlot() != null && rc.getResultTribPortTribSlot().get(0) != null
+                    && rc.getResultTribPortTribSlot().get(1) != null) {
                     ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(0))
-                            .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
-                            .setTribSlotNumber(tribSlotList.get(0));
+                            .setMinTribSlot(rc.getResultTribPortTribSlot().get(0))
+                            .setMaxTribSlot(rc.getResultTribPortTribSlot().get(1));
                 } else {
-                    LOG.error("Trib port and trib slot number should be present");
-                    ztoADirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
+                    LOG.warn("Trib port and trib slot number should be present");
+                    ztoADirectionBldr.setMinTribSlot(new OpucnTribSlotDef("0.0"))
+                        .setMaxTribSlot(new OpucnTribSlotDef("0.0"));
                 }
                 break;
             default:
@@ -182,10 +213,10 @@ public class PcePathDescription {
         for (PceLink pcelink : path) {
             String srcName = pcelink.getSourceId().getValue();
             // Nodes
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce
-                .resource.resource.resource.Node sourceNode = new NodeBuilder()
-                .setNodeId(srcName)
-                .build();
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501
+                    .pce.resource.resource.resource.Node sourceNode = new NodeBuilder()
+                    .setNodeId(srcName)
+                    .build();
 
             // Source Resource
             AToZKey sourceKey = new AToZKey(index.toString());
@@ -195,7 +226,7 @@ public class PcePathDescription {
             atozMap.put(srcResource.key(),srcResource);
 
             // source TP
-            tpName = pcelink.getSourceTP().toString();
+            tpName = pcelink.getSourceTP().getValue();
             stp = new TerminationPointBuilder()
                     .setTpNodeId(srcName).setTpId(tpName)
                     .build();
@@ -209,10 +240,10 @@ public class PcePathDescription {
 
             String linkName = pcelink.getLinkId().getValue();
             // Link
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce
-                .resource.resource.resource.Link atozLink = new LinkBuilder()
-                .setLinkId(linkName)
-                .build();
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501
+                    .pce.resource.resource.resource.Link atozLink = new LinkBuilder()
+                    .setLinkId(linkName)
+                    .build();
 
             // Link Resource
             AToZKey linkKey = new AToZKey(index.toString());
@@ -223,7 +254,7 @@ public class PcePathDescription {
 
             String destName = pcelink.getDestId().getValue();
             // target TP
-            tpName = pcelink.getDestTP().toString();
+            tpName = pcelink.getDestTP().getValue();
             TerminationPoint dtp = new TerminationPointBuilder()
                 .setTpNodeId(destName).setTpId(tpName)
                 .build();
@@ -235,7 +266,7 @@ public class PcePathDescription {
             index += 1;
             atozMap.put(ttpResource.key(),ttpResource);
 
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce
                 .resource.resource.resource.Node targetNode = new NodeBuilder()
                 .setNodeId(destName)
                 .build();
@@ -295,7 +326,7 @@ public class PcePathDescription {
 
 
             // Nodes
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce
                 .resource.resource.resource.Node sourceNode = new NodeBuilder()
                 .setNodeId(srcName).build();
 
@@ -308,7 +339,7 @@ public class PcePathDescription {
             ztoaList.put(srcResource.key(),srcResource);
 
             // source TP
-            tpName = pcelink.getSourceTP().toString();
+            tpName = pcelink.getSourceTP().getValue();
             stp = new TerminationPointBuilder()
                     .setTpNodeId(srcName).setTpId(tpName)
                     .build();
@@ -322,7 +353,7 @@ public class PcePathDescription {
 
             String linkName = pcelink.getLinkId().getValue();
             // Link
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce
                 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
                 .setLinkId(linkName).build();
 
@@ -335,7 +366,7 @@ public class PcePathDescription {
 
             String destName = pcelink.getDestId().getValue();
             // target TP
-            tpName = pcelink.getDestTP().toString();
+            tpName = pcelink.getDestTP().getValue();
             TerminationPoint ttp = new TerminationPointBuilder()
                     .setTpNodeId(destName).setTpId(tpName).build();
 
@@ -347,7 +378,7 @@ public class PcePathDescription {
             ztoaList.put(ttpResource.key(),ttpResource);
 
 
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce
                 .resource.resource.resource.Node targetNode = new NodeBuilder()
                 .setNodeId(destName).build();
             // Target Resource