Fix CI Cent OS 8 configuration issue (workaround)
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PostAlgoPathValidator.java
index 32624da2faba0c5c669c79cdb08009ba814b52a4..3d3f1b692c657ea47b044b3ec22aeeca241e2615 100644 (file)
@@ -38,9 +38,9 @@ import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair
 import org.opendaylight.transportpce.pce.networkanalyzer.PceLink;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceLink;
 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.rev230925.PceConstraintMode;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.SpectrumAssignment;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.SpectrumAssignmentBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.PceConstraintMode;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.SpectrumAssignment;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.SpectrumAssignmentBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmLinkType;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmLinkType;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
@@ -61,9 +61,11 @@ public class PostAlgoPathValidator {
 
     private Double tpceCalculatedMargin = 0.0;
     private final NetworkTransactionService networkTransactionService;
 
     private Double tpceCalculatedMargin = 0.0;
     private final NetworkTransactionService networkTransactionService;
+    private final BitSet spectrumConstraint;
 
 
-    public PostAlgoPathValidator(NetworkTransactionService networkTransactionService) {
+    public PostAlgoPathValidator(NetworkTransactionService networkTransactionService, BitSet spectrumConstraint) {
         this.networkTransactionService = networkTransactionService;
         this.networkTransactionService = networkTransactionService;
+        this.spectrumConstraint = spectrumConstraint;
     }
 
     @SuppressWarnings("fallthrough")
     }
 
     @SuppressWarnings("fallthrough")
@@ -345,7 +347,6 @@ public class PostAlgoPathValidator {
                     .getAvailableTribSlots()
                     .get(edge.link().getDestTP().getValue());
             List<Uint16> commonEdgeTsPoolList = new ArrayList<>();
                     .getAvailableTribSlots()
                     .get(edge.link().getDestTP().getValue());
             List<Uint16> commonEdgeTsPoolList = new ArrayList<>();
-            List<Uint16> tribSlotList = new ArrayList<>();
             for (Uint16 integer : srcTsPool) {
                 if (destTsPool.contains(integer)) {
                     commonEdgeTsPoolList.add(integer);
             for (Uint16 integer : srcTsPool) {
                 if (destTsPool.contains(integer)) {
                     commonEdgeTsPoolList.add(integer);
@@ -360,6 +361,7 @@ public class PostAlgoPathValidator {
             }
             Collections.sort(commonGoodStartEdgeTsPoolList);
             boolean goodTsList = false;
             }
             Collections.sort(commonGoodStartEdgeTsPoolList);
             boolean goodTsList = false;
+            List<Uint16> tribSlotList = new ArrayList<>();
             for (Uint16 goodStartTsPool : commonGoodStartEdgeTsPoolList) {
                 int goodStartIndex = commonEdgeTsPoolList.indexOf(Uint16.valueOf(goodStartTsPool.intValue()));
                 if (!goodTsList && commonEdgeTsPoolList.size() - goodStartIndex >= nbSlot) {
             for (Uint16 goodStartTsPool : commonGoodStartEdgeTsPoolList) {
                 int goodStartIndex = commonEdgeTsPoolList.indexOf(Uint16.valueOf(goodStartTsPool.intValue()));
                 if (!goodTsList && commonEdgeTsPoolList.size() - goodStartIndex >= nbSlot) {
@@ -424,7 +426,6 @@ public class PostAlgoPathValidator {
                 "pwrIn", Double.valueOf(-60.0),
                 "pwrOut", Double.valueOf(-60.0)));
         double calcOnsrdB = 0;
                 "pwrIn", Double.valueOf(-60.0),
                 "pwrOut", Double.valueOf(-60.0)));
         double calcOnsrdB = 0;
-        double margin = 0;
         boolean transponderPresent = false;
         List<String> vertices = path.getVertexList();
         List<PceGraphEdge> edges = path.getEdgeList();
         boolean transponderPresent = false;
         List<String> vertices = path.getVertexList();
         List<PceGraphEdge> edges = path.getEdgeList();
@@ -541,6 +542,7 @@ public class PostAlgoPathValidator {
                     LOG.error("PostAlgoPathValidator.CheckOSNR : unsupported resource type in the path chain");
             }
         }
                     LOG.error("PostAlgoPathValidator.CheckOSNR : unsupported resource type in the path chain");
             }
         }
+        double margin = 0;
         PceNode currentNode = allPceNodes.get(new NodeId(vertices.get(vertices.size() - 1)));
         LOG.debug("loop of check OSNR, Path Element = {}", vertices.size() - 1);
         switch (currentNode.getORNodeType()) {
         PceNode currentNode = allPceNodes.get(new NodeId(vertices.get(vertices.size() - 1)));
         LOG.debug("loop of check OSNR, Path Element = {}", vertices.size() - 1);
         switch (currentNode.getORNodeType()) {
@@ -628,7 +630,6 @@ public class PostAlgoPathValidator {
                 "pwrIn", Double.valueOf(-60.0),
                 "pwrOut", Double.valueOf(-60.0)));
         double calcOnsrdB = 0;
                 "pwrIn", Double.valueOf(-60.0),
                 "pwrOut", Double.valueOf(-60.0)));
         double calcOnsrdB = 0;
-        double margin = 0;
         boolean transponderPresent = false;
         List<String> vertices = path.getVertexList();
         List<PceGraphEdge> edges = path.getEdgeList();
         boolean transponderPresent = false;
         List<String> vertices = path.getVertexList();
         List<PceGraphEdge> edges = path.getEdgeList();
@@ -743,6 +744,7 @@ public class PostAlgoPathValidator {
                     LOG.error("PostAlgoPathValidator.CheckOSNR : unsupported resource type in the path chain");
             }
         }
                     LOG.error("PostAlgoPathValidator.CheckOSNR : unsupported resource type in the path chain");
             }
         }
+        double margin = 0;
         PceNode currentNode = allPceNodes.get(new NodeId(vertices.get(0)));
         LOG.debug("loop of check OSNR direction ZA: Path Element = 0");
         switch (currentNode.getORNodeType()) {
         PceNode currentNode = allPceNodes.get(new NodeId(vertices.get(0)));
         LOG.debug("loop of check OSNR direction ZA: Path Element = 0");
         switch (currentNode.getORNodeType()) {
@@ -1009,42 +1011,49 @@ public class PostAlgoPathValidator {
         Set<PceNode> pceNodes = new LinkedHashSet<>();
 
         for (PceGraphEdge edge : path.getEdgeList()) {
         Set<PceNode> pceNodes = new LinkedHashSet<>();
 
         for (PceGraphEdge edge : path.getEdgeList()) {
-            PceLink link = edge.link();
-            LOG.debug("Processing {} to {}", link.getSourceId().getValue(), link.getDestId().getValue());
-            if (allPceNodes.containsKey(link.getSourceId())) {
-                pceNodes.add(allPceNodes.get(link.getSourceId()));
+            NodeId srcId = edge.link().getSourceId();
+            NodeId dstId = edge.link().getDestId();
+            LOG.debug("Processing {} to {}", srcId.getValue(), dstId.getValue());
+            if (allPceNodes.containsKey(srcId)) {
+                pceNodes.add(allPceNodes.get(srcId));
             }
             }
-            if (allPceNodes.containsKey(link.getDestId())) {
-                pceNodes.add(allPceNodes.get(link.getDestId()));
+            if (allPceNodes.containsKey(dstId)) {
+                pceNodes.add(allPceNodes.get(dstId));
             }
         }
 
         for (PceNode pceNode : pceNodes) {
             LOG.debug("Processing PCE node {}", pceNode);
             }
         }
 
         for (PceNode pceNode : pceNodes) {
             LOG.debug("Processing PCE node {}", pceNode);
+            pceNodeFreqMap = pceNode.getBitSetData();
+            LOG.debug("Pce node bitset {}", pceNodeFreqMap);
+            if (pceNodeFreqMap != null) {
+                result.and(pceNodeFreqMap);
+                LOG.debug("intermediate bitset {}", result);
+            }
             String pceNodeVersion = pceNode.getVersion();
             String pceNodeVersion = pceNode.getVersion();
-            NodeId pceNodeId = pceNode.getNodeId();
             BigDecimal sltWdthGran = pceNode.getSlotWidthGranularity();
             BigDecimal sltWdthGran = pceNode.getSlotWidthGranularity();
-            BigDecimal ctralFreqGran = pceNode.getCentralFreqGranularity();
             if (StringConstants.OPENROADM_DEVICE_VERSION_1_2_1.equals(pceNodeVersion)) {
             if (StringConstants.OPENROADM_DEVICE_VERSION_1_2_1.equals(pceNodeVersion)) {
-                LOG.debug("Node {}: version is {} and slot width granularity is {} -> fixed grid mode",
-                    pceNodeId, pceNodeVersion, sltWdthGran);
+                LOG.debug("Node {}: version is {} with slot width granularity {} - fixed grid mode",
+                    pceNode.getNodeId(), pceNodeVersion, sltWdthGran);
                 isFlexGrid = false;
                 isFlexGrid = false;
+                continue;
             }
             }
-            if (sltWdthGran.setScale(0, RoundingMode.CEILING).equals(GridConstant.SLOT_WIDTH_50)
-                    && ctralFreqGran.setScale(0, RoundingMode.CEILING).equals(GridConstant.SLOT_WIDTH_50)) {
-                LOG.debug("Node {}: version is {} with slot width granularity {} and central "
-                        + "frequency granularity is {} -> fixed grid mode",
-                    pceNodeId, pceNodeVersion, sltWdthGran, ctralFreqGran);
-                isFlexGrid = false;
+            if (!sltWdthGran.setScale(0, RoundingMode.CEILING).equals(GridConstant.SLOT_WIDTH_50)) {
+                continue;
             }
             }
-            pceNodeFreqMap = pceNode.getBitSetData();
-            LOG.debug("Pce node bitset {}", pceNodeFreqMap);
-            if (pceNodeFreqMap != null) {
-                result.and(pceNodeFreqMap);
-                LOG.debug("intermediate bitset {}", result);
+            BigDecimal ctralFreqGran = pceNode.getCentralFreqGranularity();
+            if (!ctralFreqGran.setScale(0, RoundingMode.CEILING).equals(GridConstant.SLOT_WIDTH_50)) {
+                continue;
             }
             }
-
+            LOG.debug(
+                "Node {}: version is {} with slot width and central frequency granularities {} {} - fixed grid mode",
+                pceNode.getNodeId(), pceNodeVersion, sltWdthGran, ctralFreqGran);
+            isFlexGrid = false;
+        }
+        if (spectrumConstraint != null) {
+            result.and(spectrumConstraint);
         }
         }
+
         LOG.debug("Bitset result {}", result);
         return computeBestSpectrumAssignment(result, spectralWidthSlotNumber, isFlexGrid);
     }
         LOG.debug("Bitset result {}", result);
         return computeBestSpectrumAssignment(result, spectralWidthSlotNumber, isFlexGrid);
     }