Adapt TransportPCE code to Sulfur
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PostAlgoPathValidator.java
index 0ec32575c447c0c404bd688a9c8706728d967b84..ba4eee7d692ddd6b69f9f04baa2ee4345a92b152 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.transportpce.pce.graph;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
@@ -25,9 +26,9 @@ import org.opendaylight.transportpce.pce.constraints.PceConstraints;
 import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.SpectrumAssignment;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.SpectrumAssignmentBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.SpectrumAssignment;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.SpectrumAssignmentBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 import org.opendaylight.yangtools.yang.common.Uint16;
@@ -44,6 +45,7 @@ public class PostAlgoPathValidator {
     public static final Long CONST_OSNR = 1L;
     public static final double SYS_MARGIN = 0;
 
+    @SuppressWarnings("fallthrough")
     @SuppressFBWarnings(
         value = "SF_SWITCH_FALLTHROUGH",
         justification = "intentional fallthrough")
@@ -60,6 +62,8 @@ public class PostAlgoPathValidator {
         SpectrumAssignment spectrumAssignment = null;
         //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
         switch (serviceType) {
+            case StringConstants.SERVICE_TYPE_OTUC2:
+            case StringConstants.SERVICE_TYPE_OTUC3:
             case StringConstants.SERVICE_TYPE_OTUC4:
             case StringConstants.SERVICE_TYPE_400GE:
                 spectralWidthSlotNumber = GridConstant.SPECTRAL_WIDTH_SLOT_NUMBER_MAP
@@ -138,9 +142,13 @@ public class PostAlgoPathValidator {
                 }
                 break;
             case StringConstants.SERVICE_TYPE_ODU4:
+            case StringConstants.SERVICE_TYPE_ODUC2:
+            case StringConstants.SERVICE_TYPE_ODUC3:
             case StringConstants.SERVICE_TYPE_ODUC4:
+            case StringConstants.SERVICE_TYPE_100GE_S:
                 pceResult.setRC(ResponseCodes.RESPONSE_OK);
-                LOG.info("In PostAlgoPathValidator: ODU4/ODUC4 path found {}", path);
+                pceResult.setServiceType(serviceType);
+                LOG.info("In PostAlgoPathValidator: ODU4/ODUCn path found {}", path);
                 break;
             default:
                 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
@@ -156,13 +164,13 @@ public class PostAlgoPathValidator {
         double latency = 0;
 
         for (PceGraphEdge edge : path.getEdgeList()) {
-            try {
-                latency += edge.link().getLatency();
-                LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
-            } catch (NullPointerException e) {
+            if (edge.link() == null || edge.link().getLatency() == null) {
                 LOG.warn("- In checkLatency: the link {} does not contain latency field",
                     edge.link().getLinkId().getValue());
+                return false;
             }
+            latency += edge.link().getLatency();
+            LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
         }
         return (latency < maxLatency);
     }
@@ -281,9 +289,9 @@ public class PostAlgoPathValidator {
 
         for (PceGraphEdge edge : path.getEdgeList()) {
             NodeId linkSrcNode = edge.link().getSourceId();
-            String linkSrcTp = edge.link().getSourceTP().toString();
+            String linkSrcTp = edge.link().getSourceTP().getValue();
             NodeId linkDestNode = edge.link().getDestId();
-            String linkDestTp = edge.link().getDestTP().toString();
+            String linkDestTp = edge.link().getDestTP().getValue();
             PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
             PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
             List<Uint16> srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp);
@@ -294,7 +302,7 @@ public class PostAlgoPathValidator {
                     commonEdgeTpnPool.add(srcTpn);
                 }
             }
-            Collections.sort(commonEdgeTpnPool);
+
             if (!commonEdgeTpnPool.isEmpty()) {
                 Integer startTribSlot = tribSlotMap.values().stream().findFirst().get().get(0).toJava();
                 Integer tribPort = (int) Math.ceil((double)startTribSlot / nbSlot);
@@ -316,9 +324,9 @@ public class PostAlgoPathValidator {
 
         for (PceGraphEdge edge : path.getEdgeList()) {
             NodeId linkSrcNode = edge.link().getSourceId();
-            String linkSrcTp = edge.link().getSourceTP().toString();
+            String linkSrcTp = edge.link().getSourceTP().getValue();
             NodeId linkDestNode = edge.link().getDestId();
-            String linkDestTp = edge.link().getDestTP().toString();
+            String linkDestTp = edge.link().getDestTP().getValue();
             PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
             PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
             List<Uint16> srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp);
@@ -440,8 +448,10 @@ public class PostAlgoPathValidator {
                         pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity());
                     isFlexGrid = false;
                 }
-                if ((pceNode.getSlotWidthGranularity().equals(GridConstant.SLOT_WIDTH_50))
-                    && (pceNode.getCentralFreqGranularity().equals(GridConstant.SLOT_WIDTH_50))) {
+                if ((pceNode.getSlotWidthGranularity().setScale(0, RoundingMode.CEILING)
+                        .equals(GridConstant.SLOT_WIDTH_50))
+                        && (pceNode.getCentralFreqGranularity().setScale(0, RoundingMode.CEILING)
+                        .equals(GridConstant.SLOT_WIDTH_50))) {
                     LOG.info("Node {}: version is {} with slot width granularity  {} and central "
                             + "frequency granularity is {} -> fixed grid mode",
                         pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity(),