Spectrum assignment skipped the last node in path
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PostAlgoPathValidator.java
index fe7dd48a9b772446551d08d6b800484617458918..32624da2faba0c5c669c79cdb08009ba814b52a4 100644 (file)
@@ -16,8 +16,10 @@ import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 import org.jgrapht.GraphPath;
@@ -36,11 +38,12 @@ 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.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.SpectrumAssignment;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.SpectrumAssignmentBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
+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.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.otn.common.types.rev210924.OpucnTribSlotDef;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
@@ -55,6 +58,7 @@ public class PostAlgoPathValidator {
 
     public static final Long CONST_OSNR = 1L;
     public static final double SYS_MARGIN = 0;
+
     private Double tpceCalculatedMargin = 0.0;
     private final NetworkTransactionService networkTransactionService;
 
@@ -68,7 +72,7 @@ public class PostAlgoPathValidator {
         justification = "intentional fallthrough")
     public PceResult checkPath(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
             Map<LinkId, PceLink> allPceLinks, PceResult pceResult, PceConstraints pceHardConstraints,
-            String serviceType) {
+            String serviceType, PceConstraintMode mode) {
         LOG.info("path = {}", path);
         // check if the path is empty
         if (path.getEdgeList().isEmpty()) {
@@ -139,7 +143,7 @@ public class PostAlgoPathValidator {
                     return pceResult;
                 }
                 // Check if nodes are included in the hard constraints
-                if (!checkInclude(path, pceHardConstraints)) {
+                if (!checkInclude(path, pceHardConstraints, mode)) {
                     pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
                     pceResult.setLocalCause(PceResult.LocalCause.HD_NODE_INCLUDE);
                     return pceResult;
@@ -202,15 +206,17 @@ public class PostAlgoPathValidator {
     }
 
     // Check the inclusion if it is defined in the hard constraints
-    private boolean checkInclude(GraphPath<String, PceGraphEdge> path, PceConstraints pceHardConstraintsInput) {
-        List<ResourcePair> listToInclude = pceHardConstraintsInput.getListToInclude()
-            .stream().sorted((rp1, rp2) -> rp1.getName().compareTo(rp2.getName()))
-            .collect(Collectors.toList());
+    //TODO: remove this checkstyle false positive warning when the checkstyle bug will be fixed
+    @SuppressWarnings("MissingSwitchDefault")
+    private boolean checkInclude(GraphPath<String, PceGraphEdge> path, PceConstraints pceHardConstraintsInput,
+            PceConstraintMode mode) {
+        List<ResourcePair> listToInclude = pceHardConstraintsInput.getListToInclude();
         if (listToInclude.isEmpty()) {
             return true;
         }
         List<PceGraphEdge> pathEdges = path.getEdgeList();
         LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList());
+        LOG.debug("listToInclude = {}", listToInclude);
         List<String> listOfElementsSubNode = new ArrayList<>();
         listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId());
         listOfElementsSubNode.addAll(
@@ -225,10 +231,17 @@ public class PostAlgoPathValidator {
         listOfElementsSRLG.addAll(
             listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG, pceHardConstraintsInput));
         // validation: check each type for each element
-        return listOfElementsSubNode.containsAll(
-                listToInclude
-                    .stream().filter(rp -> PceConstraints.ResourceType.NODE.equals(rp.getType()))
-                    .map(ResourcePair::getName).collect(Collectors.toList()))
+        LOG.debug("listOfElementsSubNode = {}", listOfElementsSubNode);
+        return switch (mode) {
+            case Loose -> listOfElementsSubNode
+                .containsAll(listToInclude.stream()
+                    .filter(rp -> PceConstraints.ResourceType.NODE.equals(rp.getType()))
+                    .map(ResourcePair::getName).collect(Collectors.toList()));
+            case Strict -> listOfElementsSubNode
+                .equals(listToInclude.stream()
+                    .filter(rp -> PceConstraints.ResourceType.NODE.equals(rp.getType()))
+                    .map(ResourcePair::getName).collect(Collectors.toList()));
+        }
             && listOfElementsSRLG.containsAll(
                 listToInclude
                     .stream().filter(rp -> PceConstraints.ResourceType.SRLG.equals(rp.getType()))
@@ -241,7 +254,7 @@ public class PostAlgoPathValidator {
 
     private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
             PceConstraints pceHardConstraints) {
-        List<String> listOfElements = new ArrayList<>();
+        Set<String> listOfElements = new LinkedHashSet<>();
         for (PceGraphEdge link : pathEdges) {
             switch (type) {
                 case NODE:
@@ -277,7 +290,7 @@ public class PostAlgoPathValidator {
                     LOG.debug("listOfElementsBuild unsupported resource type");
             }
         }
-        return listOfElements;
+        return new ArrayList<>(listOfElements);
     }
 
     private Map<String, Uint16> chooseTribPort(GraphPath<String,
@@ -304,7 +317,7 @@ public class PostAlgoPathValidator {
             if (commonEdgeTpnPool.isEmpty()) {
                 continue;
             }
-            Integer startTribSlot = tribSlotMap.values().stream().findFirst().get().get(0).toJava();
+            Integer startTribSlot = tribSlotMap.values().stream().findFirst().orElseThrow().get(0).toJava();
             Integer tribPort = (int) Math.ceil((double)startTribSlot / nbSlot);
             for (Uint16 commonTribPort : commonEdgeTpnPool) {
                 if (tribPort.equals(commonTribPort.toJava())) {
@@ -370,7 +383,7 @@ public class PostAlgoPathValidator {
 
     private List<OpucnTribSlotDef> getMinMaxTpTs(Map<String, Uint16> tribPort, Map<String, List<Uint16>> tribSlot) {
         String tribport = tribPort.values().toArray()[0].toString();
-        List<Uint16> tsList = (List<Uint16>) tribSlot.values().toArray()[0];
+        @SuppressWarnings("unchecked") List<Uint16> tsList = (List<Uint16>) tribSlot.values().toArray()[0];
         return new ArrayList<>(List.of(
             OpucnTribSlotDef.getDefaultInstance(String.join(".", tribport, tsList.get(0).toString())),
             OpucnTribSlotDef.getDefaultInstance(String.join(".", tribport, tsList.get(tsList.size() - 1).toString()))));
@@ -401,15 +414,17 @@ public class PostAlgoPathValidator {
      */
     private double checkOSNRaz(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
             Map<LinkId, PceLink> allPceLinks, String serviceType, CatalogUtils cu) {
-        double spacing = 50.0;
-        double calcPdl2 = 0;
-        double calcOsnrdB = 0;
-        double calcCd = 0;
-        double calcPmd2 = 0;
-        double calcOnsrLin = 0.0001;
+        Map<String, Double> signal = new HashMap<>(
+            Map.of(
+                "spacing", Double.valueOf(50.0),
+                "calcPdl2", Double.valueOf(0),
+                "calcCd", Double.valueOf(0),
+                "calcPmd2", Double.valueOf(0),
+                "calcOnsrLin", Double.valueOf(0.0001),
+                "pwrIn", Double.valueOf(-60.0),
+                "pwrOut", Double.valueOf(-60.0)));
+        double calcOnsrdB = 0;
         double margin = 0;
-        double pwrIn = -60.0;
-        double pwrOut = -60.0;
         boolean transponderPresent = false;
         List<String> vertices = path.getVertexList();
         List<PceGraphEdge> edges = path.getEdgeList();
@@ -427,14 +442,12 @@ public class PostAlgoPathValidator {
                 case XPONDER:
                     LOG.debug("loop of check OSNR direction AZ: XPDR, Path Element = {}", pathElement);
                     transponderPresent = true;
-                    Map<String, Double> results = calcXpdrOSNR(cu,
+                    calcXpdrOSNR(cu, signal,
                         pathElement == 0
                             // First transponder on the Path (TX side) / Last Xponder of the path (RX side)
                             ? edges.get(pathElement).link().getSourceTP().getValue()
                             : edges.get(pathElement - 1).link().getDestTP().getValue(),
                         serviceType, currentNode, nextNode, vertices.get(pathElement), pathElement);
-                    calcOnsrLin = results.get("calcOnsrLin");
-                    spacing = results.get("spacing");
                     break;
                 case SRG:
                     LOG.debug("loop of check OSNR direction AZ: SRG, Path Element = {}", pathElement);
@@ -444,18 +457,12 @@ public class PostAlgoPathValidator {
                         LOG.error("Error processing Node {} for which output link {} is not an ADDLINK Type",
                             currentNode.getNodeId(), pathElement);
                     }
-                    pwrIn = 0.0;
-                    Map<String, Double> impairments = calcAddContrib(
-                        cu, currentNode, edges.get(pathElement + 1).link(),
-                        calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                    calcCd = impairments.get("calcCd");
-                    calcPmd2 = impairments.get("calcPmd2");
-                    calcPdl2 = impairments.get("calcPdl2");
-                    calcOnsrLin = impairments.get("calcOnsrLin");
-                    pwrOut = impairments.get("pwrOut");
+                    signal.put("pwrIn", Double.valueOf(0));
+                    calcAddContrib(cu, signal, currentNode, edges.get(pathElement + 1).link());
                     LOG.debug("loop of check OSNR direction AZ: SRG, pathElement = {} link {} Pout = {}",
-                        pathElement, pathElement + 1, pwrOut);
-                    if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
+                        pathElement, pathElement + 1, signal.get("pwrOut"));
+                    double calcOnsr = signal.get("calcOnsrLin").doubleValue();
+                    if (calcOnsr == Double.NEGATIVE_INFINITY || calcOnsr == Double.POSITIVE_INFINITY) {
                         return -1.0;
                     }
                     // For the ADD, degradation brought by the node are calculated from the MW-WR spec.
@@ -484,14 +491,9 @@ public class PostAlgoPathValidator {
                     PceLink pceLink = edges.get(pathElement - 2).link();
                     LOG.info("loop of check OSNR : SRG, pathElement = {} CD on preceeding link {} = {} ps",
                         pathElement, pathElement - 2, pceLink.getcd());
-                    Map<String, Double> impairments = calcDropContrib(
-                        cu, currentNode, pceLink, pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                    calcCd = impairments.get("calcCd");
-                    calcPmd2 = impairments.get("calcPmd2");
-                    calcPdl2 = impairments.get("calcPdl2");
-                    calcOnsrLin = impairments.get("calcOnsrLin");
-                    pwrIn = impairments.get("pwrIn");
-                    if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
+                    calcDropContrib(cu, signal, currentNode, pceLink);
+                    double calcOnsr = signal.get("calcOnsrLin").doubleValue();
+                    if (calcOnsr == Double.NEGATIVE_INFINITY || calcOnsr == Double.POSITIVE_INFINITY) {
                         return -1.0;
                     }
                     // If SRG is not the first or the second element of the Path, it is the DROP
@@ -500,9 +502,9 @@ public class PostAlgoPathValidator {
                     // resulting OSNR in dB to pass it to the method that verifies end Xponder
                     // performances are compatible with degradations experienced on the path
                     try {
-                        calcOsnrdB = getOsnrDbfromOnsrLin(calcOnsrLin);
-                        LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOsnrdB);
-                        LOG.info("Loop pathElement = {}, DROP, calcOsnrdB= {}", pathElement, calcOsnrdB);
+                        calcOnsrdB = getOsnrDbfromOnsrLin(calcOnsr);
+                        LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOnsrdB);
+                        LOG.info("Loop pathElement = {}, DROP, calcOnsrdB= {}", pathElement, calcOnsrdB);
                     } catch (ArithmeticException e) {
                         LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}",
                             path.getEdgeList().size());
@@ -515,19 +517,11 @@ public class PostAlgoPathValidator {
                         break;
                     }
                     LOG.info("loop of check OSNR direction AZ: DEGREE, Path Element = {}", pathElement);
-                    Map<String, Double> impairments0 =  calcBypassContrib(
-                            cu, currentNode, nextNode,
-                            edges.get(pathElement - 1).link(), edges.get(pathElement + 1).link(),
-                            pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                    calcCd = impairments0.get("CD").doubleValue();
-                    calcPmd2 = impairments0.get("DGD2").doubleValue();
-                    calcPdl2 = impairments0.get("PDL2").doubleValue();
-                    calcOnsrLin = impairments0.get("ONSRLIN").doubleValue();
-                    //TODO rename impariments0 var and/or adapt catalog utils
-                    pwrIn = impairments0.get("pwrIn").doubleValue();
-                    pwrOut = impairments0.get("pwrOut").doubleValue();
+                    calcBypassContrib(cu, signal, currentNode, nextNode,
+                        edges.get(pathElement - 1).link(), edges.get(pathElement + 1).link());
+                    double calcOnsrLin = signal.get("calcOnsrLin").doubleValue();
                     LOG.debug(
-                        "Loop pathElement= {}, DEGREE, calcOsnrdB= {}", pathElement, getOsnrDbfromOnsrLin(calcOnsrLin));
+                        "Loop pathElement= {}, DEGREE, calcOnsrdB= {}", pathElement, getOsnrDbfromOnsrLin(calcOnsrLin));
                     if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
                         return -1.0;
                     }
@@ -535,8 +529,9 @@ public class PostAlgoPathValidator {
                     // next node
                     pathElement++;
                     LOG.info("Accumulated degradations in the path including ROADM {} + {} are CD: {}; PMD2: "
-                        + "{}; Pdl2 : {}; ONSRdB : {}", currentNode.getNodeId(),
-                        nextNode.getNodeId(), calcCd, calcPmd2, calcPdl2, getOsnrDbfromOnsrLin(calcOnsrLin));
+                        + "{}; Pdl2 : {}; ONSRdB : {}", currentNode.getNodeId(), nextNode.getNodeId(),
+                        signal.get("calcCd"), signal.get("calcPmd2"), signal.get("calcPdl2"),
+                        getOsnrDbfromOnsrLin(calcOnsrLin));
                     break;
                 case XPONDER:
                     LOG.debug("loop of check OSNR direction AZ: XPDR, Path Element = {}", pathElement);
@@ -553,9 +548,8 @@ public class PostAlgoPathValidator {
                 LOG.debug("loop of check OSNR direction AZ: XPDR, Path Element = {}", vertices.size() - 1);
                 transponderPresent = true;
                 // TSP is the last of the path
-                margin = getLastXpdrMargin(cu, edges.get(vertices.size() - 2).link().getDestTP().getValue(),
-                    serviceType, currentNode, vertices.get(vertices.size() - 1), vertices.size() - 1,
-                    calcCd, calcPmd2, calcPdl2, calcOnsrLin);
+                margin = getLastXpdrMargin(cu, signal, edges.get(vertices.size() - 2).link().getDestTP().getValue(),
+                    serviceType, currentNode, vertices.get(vertices.size() - 1), vertices.size() - 1);
                 break;
             case SRG:
                 LOG.debug("loop of check OSNR direction AZ: SRG, Path Element = {}", vertices.size() - 1);
@@ -567,14 +561,10 @@ public class PostAlgoPathValidator {
                 PceLink pceLink = edges.get(vertices.size() - 3).link();
                 LOG.info("loop of check OSNR : SRG, pathElement = {} CD on preceeding link {} = {} ps",
                     vertices.size() - 1, vertices.size() - 3, pceLink.getcd());
-                Map<String, Double> impairments = calcDropContrib(
-                    cu, currentNode, pceLink, pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                calcCd = impairments.get("calcCd");
-                calcPmd2 = impairments.get("calcPmd2");
-                calcPdl2 = impairments.get("calcPdl2");
-                calcOnsrLin = impairments.get("calcOnsrLin");
+                calcDropContrib(cu, signal, currentNode, pceLink);
+                double calcOnsr = signal.get("calcOnsrLin").doubleValue();
                 //commented out to avoid spotbug DLS_DEAD_LOCAL_STORE pwrIn = impairments.get("pwrIn");
-                if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
+                if (calcOnsr == Double.NEGATIVE_INFINITY || calcOnsr == Double.POSITIVE_INFINITY) {
                     return -1.0;
                 }
                 // If SRG is not the first or the second element of the Path, it is the DROP
@@ -583,9 +573,9 @@ public class PostAlgoPathValidator {
                 // resulting OSNR in dB to pass it to the method that verifies end Xponder
                 // performances are compatible with degradations experienced on the path
                 try {
-                    calcOsnrdB = getOsnrDbfromOnsrLin(calcOnsrLin);
-                    LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOsnrdB);
-                    LOG.info("Loop pathElement = {}, DROP, calcOsnrdB= {}", vertices.size() - 1, calcOsnrdB);
+                    calcOnsrdB = getOsnrDbfromOnsrLin(calcOnsr);
+                    LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOnsrdB);
+                    LOG.info("Loop pathElement = {}, DROP, calcOnsrdB= {}", vertices.size() - 1, calcOnsrdB);
                 } catch (ArithmeticException e) {
                     LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}",
                         path.getEdgeList().size());
@@ -596,9 +586,11 @@ public class PostAlgoPathValidator {
             default:
                 LOG.error("PostAlgoPathValidator.CheckOSNR : unsupported resource type in the path chain last element");
         }
-        LOG.info("- In checkOSNR: accumulated CD = {} ps, PMD = {} ps, PDL = {} dB, and resulting OSNR calcOsnrdB = {} "
+        LOG.info("- In checkOSNR: accumulated CD = {} ps, PMD = {} ps, PDL = {} dB, and resulting OSNR calcOnsrdB = {} "
             + "dB and ONSR dB exterapolated from calcosnrlin = {} including non linear contributions",
-            calcCd, Math.sqrt(calcPmd2), Math.sqrt(calcPdl2), calcOsnrdB, getOsnrDbfromOnsrLin(calcOnsrLin));
+            signal.get("calcCd"), Math.sqrt(signal.get("calcPmd2").doubleValue()),
+            Math.sqrt(signal.get("calcPdl2").doubleValue()), calcOnsrdB,
+            getOsnrDbfromOnsrLin(signal.get("calcOnsrLin").doubleValue()));
         if (!transponderPresent) {
             LOG.info("No transponder in the path, User shall check from CD, PMD, and OSNR values provided "
                 + "that optical tunnel degradations are compatible with external transponder performances");
@@ -626,15 +618,17 @@ public class PostAlgoPathValidator {
      */
     private double checkOSNRza(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
             Map<LinkId, PceLink> allPceLinks, String serviceType, CatalogUtils cu) {
-        double spacing = 50.0;
-        double calcPdl2 = 0;
-        double calcOsnrdB = 0;
-        double calcCd = 0;
-        double calcPmd2 = 0;
-        double calcOnsrLin = 0.0001;
+        Map<String, Double> signal = new HashMap<>(
+            Map.of(
+                "spacing", Double.valueOf(50.0),
+                "calcPdl2", Double.valueOf(0),
+                "calcCd", Double.valueOf(0),
+                "calcPmd2", Double.valueOf(0),
+                "calcOnsrLin", Double.valueOf(0.0001),
+                "pwrIn", Double.valueOf(-60.0),
+                "pwrOut", Double.valueOf(-60.0)));
+        double calcOnsrdB = 0;
         double margin = 0;
-        double pwrIn = -60.0;
-        double pwrOut = -60.0;
         boolean transponderPresent = false;
         List<String> vertices = path.getVertexList();
         List<PceGraphEdge> edges = path.getEdgeList();
@@ -652,14 +646,12 @@ public class PostAlgoPathValidator {
                 case XPONDER:
                     LOG.debug("loop of check OSNR direction ZA: XPDR, Path Element = {}", pathElement);
                     transponderPresent = true;
-                    Map<String, Double> results = calcXpdrOSNR(cu,
+                    calcXpdrOSNR(cu, signal,
                         pathElement == vertices.size() - 1
                             // First transponder on the Path (TX side) / Last Xponder of the path (RX side)
                             ? getOppPceLink(pathElement - 1, edges, allPceLinks).getSourceTP().getValue()
                             : getOppPceLink((pathElement), edges, allPceLinks).getDestTP().getValue(),
                         serviceType, currentNode, nextNode, vertices.get(pathElement), pathElement);
-                    calcOnsrLin = results.get("calcOnsrLin");
-                    spacing = results.get("spacing");
                     break;
                 case SRG:
                     LOG.debug("loop of check OSNR direction ZA: SRG, Path Element = {}", pathElement);
@@ -669,17 +661,10 @@ public class PostAlgoPathValidator {
                         LOG.error("Error processing Node {} for which output link {} is not an ADDLINK Type",
                             currentNode.getNodeId(), pathElement - 1);
                     }
-                    pwrIn = 0.0;
-
-                    Map<String, Double> impairments = calcAddContrib(
-                        cu, currentNode, getOppPceLink(pathElement - 2, edges, allPceLinks),
-                        calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                    calcCd = impairments.get("calcCd");
-                    calcPmd2 = impairments.get("calcPmd2");
-                    calcPdl2 = impairments.get("calcPdl2");
-                    calcOnsrLin = impairments.get("calcOnsrLin");
-                    pwrOut = impairments.get("pwrOut");
-                    if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
+                    signal.put("pwrIn", Double.valueOf(0));
+                    calcAddContrib(cu, signal, currentNode, getOppPceLink(pathElement - 2, edges, allPceLinks));
+                    double calcOnsr = signal.get("calcOnsrLin").doubleValue();
+                    if (calcOnsr == Double.NEGATIVE_INFINITY || calcOnsr == Double.POSITIVE_INFINITY) {
                         return -1.0;
                     }
                     // For the ADD, degradation brought by the node are calculated from the MW-WR spec.
@@ -707,14 +692,9 @@ public class PostAlgoPathValidator {
                     PceLink pceLink = getOppPceLink(pathElement + 1, edges, allPceLinks);
                     LOG.info("loop of check OSNR direction ZA: SRG, path Element = {} CD on preceeding link {} = {} ps",
                         pathElement, pathElement + 1, pceLink.getcd());
-                    Map<String, Double> impairments = calcDropContrib(
-                        cu, currentNode, pceLink, pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                    calcCd = impairments.get("calcCd");
-                    calcPmd2 = impairments.get("calcPmd2");
-                    calcPdl2 = impairments.get("calcPdl2");
-                    calcOnsrLin = impairments.get("calcOnsrLin");
-                    pwrIn = impairments.get("pwrIn");
-                    if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
+                    calcDropContrib(cu, signal, currentNode, pceLink);
+                    double calcOnsr = signal.get("calcOnsrLin").doubleValue();
+                    if (calcOnsr == Double.NEGATIVE_INFINITY || calcOnsr == Double.POSITIVE_INFINITY) {
                         return -1.0;
                     }
                     // If SRG is not the first or the second element of the Path, it is the DROP
@@ -723,9 +703,9 @@ public class PostAlgoPathValidator {
                     // resulting OSNR in dB to pass it to the method that verifies end Xponder
                     // performances are compatible with degradations experienced on the path
                     try {
-                        calcOsnrdB = getOsnrDbfromOnsrLin(calcOnsrLin);
-                        LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOsnrdB);
-                        LOG.info("Loop Path Element = {}, DROP, calcOsnrdB= {}", pathElement, calcOsnrdB);
+                        calcOnsrdB = getOsnrDbfromOnsrLin(calcOnsr);
+                        LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOnsrdB);
+                        LOG.info("Loop Path Element = {}, DROP, calcOnsrdB= {}", pathElement, calcOnsrdB);
                     } catch (ArithmeticException e) {
                         LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}",
                             path.getEdgeList().size());
@@ -738,19 +718,11 @@ public class PostAlgoPathValidator {
                         break;
                     }
                     LOG.info("loop of check OSNR direction ZA: DEGREE, Path Element = {}", pathElement);
-                    Map<String, Double> impairments0 =  calcBypassContrib(
-                        cu, currentNode, nextNode,
+                    calcBypassContrib(cu, signal, currentNode, nextNode,
                         getOppPceLink(pathElement, edges, allPceLinks),
-                        getOppPceLink(pathElement - 2, edges, allPceLinks),
-                        pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                    calcCd = impairments0.get("CD").doubleValue();
-                    calcPmd2 = impairments0.get("DGD2").doubleValue();
-                    calcPdl2 = impairments0.get("PDL2").doubleValue();
-                    calcOnsrLin = impairments0.get("ONSRLIN").doubleValue();
-                    //TODO rename impariments0 var and/or adapt catalog utils
-                    pwrIn = impairments0.get("pwrIn").doubleValue();
-                    pwrOut = impairments0.get("pwrOut").doubleValue();
-                    LOG.debug("Loop Path Element = {}, DEGREE, calcOsnrdB= {}",
+                        getOppPceLink(pathElement - 2, edges, allPceLinks));
+                    double calcOnsrLin = signal.get("calcOnsrLin").doubleValue();
+                    LOG.debug("Loop Path Element = {}, DEGREE, calcOnsrdB= {}",
                             pathElement, getOsnrDbfromOnsrLin(calcOnsrLin));
                     if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
                         return -1.0;
@@ -759,8 +731,9 @@ public class PostAlgoPathValidator {
                     // next node
                     pathElement--;
                     LOG.info("Accumulated degradations in the path including ROADM {} + {} are CD: {}; PMD2: "
-                        + "{}; Pdl2 : {}; ONSRdB : {}", currentNode.getNodeId(),
-                        nextNode.getNodeId(), calcCd, calcPmd2, calcPdl2, getOsnrDbfromOnsrLin(calcOnsrLin));
+                        + "{}; Pdl2 : {}; ONSRdB : {}", currentNode.getNodeId(), nextNode.getNodeId(),
+                        signal.get("calcCd"), signal.get("calcPmd2"), signal.get("calcPdl2"),
+                        getOsnrDbfromOnsrLin(calcOnsrLin));
                     break;
                 case XPONDER:
                     LOG.debug("loop of check OSNR direction AZ: XPDR, Path Element = {}", pathElement);
@@ -777,8 +750,8 @@ public class PostAlgoPathValidator {
                 LOG.debug("loop of check OSNR direction ZA: XPDR, Path Element = 0");
                 transponderPresent = true;
                 // TSP is the last of the path
-                margin = getLastXpdrMargin(cu, getOppPceLink(0, edges, allPceLinks).getDestTP().getValue(),
-                    serviceType, currentNode, vertices.get(0), 0, calcCd, calcPmd2, calcPdl2, calcOnsrLin);
+                margin = getLastXpdrMargin(cu, signal, getOppPceLink(0, edges, allPceLinks).getDestTP().getValue(),
+                    serviceType, currentNode, vertices.get(0), 0);
                 break;
             case SRG:
                 LOG.debug("loop of check OSNR direction ZA: SRG, Path Element = 0");
@@ -789,14 +762,10 @@ public class PostAlgoPathValidator {
                 PceLink pceLink = getOppPceLink(1, edges, allPceLinks);
                 LOG.info("loop of check OSNR direction ZA: SRG, path Element = 0 CD on preceeding link 1 = {} ps",
                     pceLink.getcd());
-                Map<String, Double> impairments = calcDropContrib(
-                    cu, currentNode, pceLink, pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-                calcCd = impairments.get("calcCd");
-                calcPmd2 = impairments.get("calcPmd2");
-                calcPdl2 = impairments.get("calcPdl2");
-                calcOnsrLin = impairments.get("calcOnsrLin");
+                calcDropContrib(cu, signal, currentNode, pceLink);
+                double calcOnsr = signal.get("calcOnsrLin").doubleValue();
                 //commented out to avoid spotbug DLS_DEAD_LOCAL_STORE pwrIn = impairments.get("pwrIn");
-                if (calcOnsrLin == Double.NEGATIVE_INFINITY || calcOnsrLin == Double.POSITIVE_INFINITY) {
+                if (calcOnsr == Double.NEGATIVE_INFINITY || calcOnsr == Double.POSITIVE_INFINITY) {
                     return -1.0;
                 }
                 // If SRG is not the first or the second element of the Path, it is the DROP
@@ -805,9 +774,9 @@ public class PostAlgoPathValidator {
                 // resulting OSNR in dB to pass it to the method that verifies end Xponder
                 // performances are compatible with degradations experienced on the path
                 try {
-                    calcOsnrdB = getOsnrDbfromOnsrLin(calcOnsrLin);
-                    LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOsnrdB);
-                    LOG.info("Loop Path Element = 0, DROP, calcOsnrdB= {}", calcOsnrdB);
+                    calcOnsrdB = getOsnrDbfromOnsrLin(calcOnsr);
+                    LOG.info("checkOSNR loop, last SRG osnr is {} dB", calcOnsrdB);
+                    LOG.info("Loop Path Element = 0, DROP, calcOnsrdB= {}", calcOnsrdB);
                 } catch (ArithmeticException e) {
                     LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}",
                         path.getEdgeList().size());
@@ -818,9 +787,11 @@ public class PostAlgoPathValidator {
             default:
                 LOG.error("PostAlgoPathValidator.CheckOSNR : unsupported resource type in the path chain last element");
         }
-        LOG.info("- In checkOSNR: accumulated CD = {} ps, PMD = {} ps, PDL = {} dB, and resulting OSNR calcOsnrdB = {} "
+        LOG.info("- In checkOSNR: accumulated CD = {} ps, PMD = {} ps, PDL = {} dB, and resulting OSNR calcOnsrdB = {} "
             + "dB and ONSR dB exterapolated from calcosnrlin = {} including non linear contributions",
-            calcCd, Math.sqrt(calcPmd2), Math.sqrt(calcPdl2), calcOsnrdB, getOsnrDbfromOnsrLin(calcOnsrLin));
+            signal.get("calcCd"), Math.sqrt(signal.get("calcPmd2").doubleValue()),
+            Math.sqrt(signal.get("calcPdl2").doubleValue()), calcOnsrdB,
+            getOsnrDbfromOnsrLin(signal.get("calcOnsrLin").doubleValue()));
         if (!transponderPresent) {
             LOG.info("No transponder in the path, User shall check from CD, PMD, and OSNR values provided "
                 + "that optical tunnel degradations are compatible with external transponder performances");
@@ -860,7 +831,7 @@ public class PostAlgoPathValidator {
                     currentNode.getXponderOperationalMode(
                         networkTransactionService
                                 .read(LogicalDatastoreType.CONFIGURATION, nwTpIid)
-                                .get().get().getXpdrNetworkAttributes()),
+                                .get().orElseThrow().getXpdrNetworkAttributes()),
                     // Operational mode is found as an attribute of the network TP
                     opMode);
                     // Operational mode is retrieved from the service Type assuming it is supported
@@ -881,23 +852,26 @@ public class PostAlgoPathValidator {
     }
 
     private double getLastXpdrMargin(
-            CatalogUtils cu, String nwTpId, String serviceType, PceNode currentNode, String vertice, int pathElement,
-            double calcCd, double calcPmd2, double calcPdl2, double calcOnsrLin) {
+            CatalogUtils cu, Map<String, Double> signal,
+            String nwTpId, String serviceType, PceNode currentNode, String vertice, int pathElement) {
         LOG.debug("Loop Path Element = {}, Step5.1, XPDR, tries calculating Margin, just before call", pathElement);
         // Check that accumulated degradations are compatible with TSP performances
         // According to OpenROADM spec :
         // margin = cu.getPceRxTspParameters(opMode, calcCd, Math.sqrt(calcPmd2), Math.sqrt(calcPdl2),
         //              getOsnrDbfromOnsrLin(calcOnsrLin));
         // Calculation modified for pdl according to calculation in Julia's Tool
-        double calcosnrdB = getOsnrDbfromOnsrLin(calcOnsrLin);
-        LOG.info("Loop Path Element = {}, XPDR, calcosnrdB= {}", pathElement, calcosnrdB);
+        double calcOnsrdB = getOsnrDbfromOnsrLin(signal.get("calcOnsrLin").doubleValue());
+        LOG.info("Loop Path Element = {}, XPDR, calcosnrdB= {}", pathElement, calcOnsrdB);
         return cu.getPceRxTspParameters(
             getXpdrOpMode(nwTpId, vertice, pathElement, currentNode, serviceType, cu),
-            calcCd, Math.sqrt(calcPmd2), Math.sqrt(calcPdl2), calcosnrdB);
+            signal.get("calcCd").doubleValue(),
+            Math.sqrt(signal.get("calcPmd2").doubleValue()),
+            Math.sqrt(signal.get("calcPdl2").doubleValue()),
+            calcOnsrdB);
     }
 
-    private Map<String, Double> calcXpdrOSNR(
-            CatalogUtils cu, String nwTpId, String serviceType,
+    private void calcXpdrOSNR(
+            CatalogUtils cu, Map<String, Double> signal, String nwTpId, String serviceType,
             PceNode currentNode, PceNode nextNode, String vertice, int pathElement) {
         // If the Xponder operational mode (setOpMode Arg1) is not consistent nor declared in the topology (Network TP)
         // Operational mode is retrieved from the service Type assuming it is supported by the Xponder (setOpMode Arg2)
@@ -913,61 +887,58 @@ public class PostAlgoPathValidator {
             currentNode.getNodeId().getValue(), pathElement, getOsnrDbfromOnsrLin(calcOnsrLin));
         // Return the Tx ONSR of the Xponder which results from IB and OOB OSNR contributions
         // and the spacing associated with Xponder operational mode that is needed to calculate OSNR
-        return Map.of(
-            "spacing", cu.getPceTxTspChannelSpacing(opMode),
-            "calcOnsrLin", calcOnsrLin);
+        signal.put("spacing", Double.valueOf(cu.getPceTxTspChannelSpacing(opMode)));
+        signal.put("calcOnsrLin", Double.valueOf(calcOnsrLin));
     }
 
-    private Map<String, Double> calcDropContrib(
-            CatalogUtils cu, PceNode currentNode, PceLink pceLink,
-            double pwrOut, double calcCd, double calcPmd2, double calcPdl2, double calcOnsrLin, double spacing) {
+    private void calcDropContrib(
+            CatalogUtils cu, Map<String, Double> signal, PceNode currentNode, PceLink pceLink) {
         //calculation of the SRG contribution for Drop
-        Map<String, Double> impairments =
-            calcLineDegradation(cu, pceLink, pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-        double pwrIn = impairments.get("pwrIn");
-        impairments = cu.getPceRoadmAmpParameters(
+        calcLineDegradation(cu, signal, pceLink);
+        Map<String, Double> impairments = cu.getPceRoadmAmpParameters(
             CatalogConstant.CatalogNodeType.DROP,
             setOpMode(currentNode.getOperationalMode(), CatalogConstant.MWWRCORE),
         // If the operational mode of the ADD/DROP MUX is not consistent or not declared in the topology (Network TP)
         // Operational mode is set by default to standard opMode for ADD/DROP SRGs
-            pwrIn,
-            impairments.get("calcCd").doubleValue(),
-            impairments.get("calcPmd2").doubleValue(),
-            calcPdl2,
-            impairments.get("calcOnsrLin").doubleValue(),
-            spacing);
-        return Map.of(
-            "calcCd", impairments.get("CD"),
-            "calcPmd2", impairments.get("DGD2"),
-            "calcPdl2", impairments.get("PDL2"),
-            "calcOnsrLin", impairments.get("ONSRLIN"),
-            "pwrIn", pwrIn);
+            signal.get("pwrIn").doubleValue(),
+            signal.get("calcCd").doubleValue(),
+            signal.get("calcPmd2").doubleValue(),
+            signal.get("calcPdl2").doubleValue(),
+            signal.get("calcOnsrLin").doubleValue(),
+            signal.get("spacing").doubleValue());
+        signal.putAll(
+            Map.of(
+                "calcCd", impairments.get("CD"),
+                "calcPmd2", impairments.get("DGD2"),
+                "calcPdl2", impairments.get("PDL2"),
+                "calcOnsrLin", impairments.get("ONSRLIN")));
     }
 
-    private Map<String, Double> calcAddContrib(
-            CatalogUtils cu, PceNode currentNode, PceLink pceLink,
-            double calcCd, double calcPmd2, double calcPdl2, double calcOnsrLin, double spacing) {
+    private void calcAddContrib(
+            CatalogUtils cu, Map<String, Double> signal, PceNode currentNode, PceLink pceLink) {
         //calculation of the SRG contribution for Add
         String srgMode = setOpMode(currentNode.getOperationalMode(), CatalogConstant.MWWRCORE);
         // If the operational mode of the ADD/DROP MUX is not consistent or is not declared in the topology (Network TP)
         // Operational mode is set by default to standard opMode for ADD/DROP SRGs
         CatalogNodeType cnt = CatalogConstant.CatalogNodeType.ADD;
         double pwrOut = cu.getPceRoadmAmpOutputPower(
-                cnt, srgMode, pceLink.getspanLoss(), spacing, pceLink.getpowerCorrection());
+                cnt, srgMode, pceLink.getspanLoss(), signal.get("spacing").doubleValue(), pceLink.getpowerCorrection());
         //calculation of the SRG contribution either for Add and Drop
-        Map<String, Double> impairments = cu.getPceRoadmAmpParameters(
-            cnt, srgMode, 0, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-        return Map.of(
-            "calcCd", impairments.get("CD"),
-            "calcPmd2", impairments.get("DGD2"),
-            "calcPdl2", impairments.get("PDL2"),
-            "calcOnsrLin", impairments.get("ONSRLIN"),
-            "pwrOut", pwrOut);
+        Map<String, Double> impairments = cu.getPceRoadmAmpParameters(cnt, srgMode, 0,
+            signal.get("calcCd").doubleValue(), signal.get("calcPmd2").doubleValue(),
+            signal.get("calcPdl2").doubleValue(),
+            signal.get("calcOnsrLin").doubleValue(), signal.get("spacing").doubleValue());
+        signal.putAll(
+            Map.of(
+                "calcCd", impairments.get("CD"),
+                "calcPmd2", impairments.get("DGD2"),
+                "calcPdl2", impairments.get("PDL2"),
+                "calcOnsrLin", impairments.get("ONSRLIN"),
+                "pwrOut", Double.valueOf(pwrOut)));
     }
 
-    private Map<String, Double> calcBypassContrib(
-            CatalogUtils cu, PceNode currentNode, PceNode nextNode, PceLink pceLink0, PceLink pceLink1,
-            double pwrOut, double calcCd, double calcPmd2, double calcPdl2, double calcOnsrLin, double spacing) {
+    private void calcBypassContrib(CatalogUtils cu, Map<String, Double> signal,
+            PceNode currentNode, PceNode nextNode, PceLink pceLink0, PceLink pceLink1) {
         // If the operational mode of the Degree is not consistent or declared in the topology
         // Operational mode is set by default to standard opMode for Degree
         String degree1Mode = setOpMode(currentNode.getOperationalMode(), CatalogConstant.MWMWCORE);
@@ -979,40 +950,42 @@ public class PostAlgoPathValidator {
                 + "{} of {} operational mode. Will by default use operational mode of Degree2",
                 currentNode.getNodeId(), degree1Mode, nextNode.getNodeId(), degree2Mode);
         }
-        Map<String, Double> impairments = calcLineDegradation(
-            cu, pceLink0, pwrOut, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-        calcCd = impairments.get("calcCd");
-        calcPmd2 = impairments.get("calcPmd2");
-        calcOnsrLin = impairments.get("calcOnsrLin");
-        CatalogNodeType cnt0 = CatalogConstant.CatalogNodeType.EXPRESS;
-        double pwrIn = impairments.get("pwrIn");
-        pwrOut = cu.getPceRoadmAmpOutputPower(
-            cnt0, degree2Mode, pceLink1.getspanLoss(), spacing, pceLink1.getpowerCorrection());
+        calcLineDegradation(cu, signal, pceLink0);
+        CatalogNodeType cnt = CatalogConstant.CatalogNodeType.EXPRESS;
+        double pwrOut = cu.getPceRoadmAmpOutputPower(cnt, degree2Mode, pceLink1.getspanLoss(),
+            signal.get("spacing").doubleValue(), pceLink1.getpowerCorrection());
         // Adds to accumulated impairments the degradation associated with the Express
         // path of ROADM : Degree1, express link, Degree2
-        impairments = cu.getPceRoadmAmpParameters(
-            cnt0, degree2Mode, pwrIn, calcCd, calcPmd2, calcPdl2, calcOnsrLin, spacing);
-        impairments.put("pwrIn", pwrIn);
-        impairments.put("pwrOut", pwrOut);
-        return impairments;
+        Map<String, Double> impairments = cu.getPceRoadmAmpParameters(cnt, degree2Mode,
+            signal.get("pwrIn").doubleValue(), signal.get("calcCd").doubleValue(),
+            signal.get("calcPmd2").doubleValue(), signal.get("calcPdl2").doubleValue(),
+            signal.get("calcOnsrLin").doubleValue(), signal.get("spacing").doubleValue());
+        signal.putAll(
+            Map.of(
+                "calcCd", impairments.get("CD"),
+                "calcPmd2", impairments.get("DGD2"),
+                "calcPdl2", impairments.get("PDL2"),
+                "calcOnsrLin", impairments.get("ONSRLIN"),
+                "pwrOut", Double.valueOf(pwrOut)));
     }
     //TODO these methods might be more indicated in a catalog utils refactoring
 
-    private Map<String, Double> calcLineDegradation(
-            CatalogUtils cu, PceLink pceLink,
-            double pwrOut, double calcCd, double calcPmd2, double calcPdl2, double calcOnsrLin, double spacing) {
+    private void calcLineDegradation(CatalogUtils cu, Map<String, Double> signal, PceLink pceLink) {
         // Calculate degradation accumulated across incoming Link and add them to
         // accumulated impairments
         // This also includes Non Linear Contribution from the path
-        return Map.of(
-            "pwrIn", pwrOut - pceLink.getspanLoss(),
-            "calcCd", calcCd + pceLink.getcd(),
-            "calcPmd2", calcPmd2 + pceLink.getpmd2(),
-            "calcOnsrLin", calcOnsrLin + cu.calculateNLonsrContribution(pwrOut, pceLink.getLength(), spacing));
+        signal.putAll(Map.of(
+            "pwrIn", Double.valueOf(signal.get("pwrOut").doubleValue() - pceLink.getspanLoss()),
+            "calcCd", Double.valueOf(signal.get("calcCd").doubleValue() + pceLink.getcd()),
+            "calcPmd2", Double.valueOf(signal.get("calcPmd2").doubleValue() + pceLink.getpmd2()),
+            "calcOnsrLin", Double.valueOf(
+                signal.get("calcOnsrLin").doubleValue()
+                + cu.calculateNLonsrContribution(
+                    signal.get("pwrOut").doubleValue(), pceLink.getLength(), signal.get("spacing").doubleValue()))));
     }
 
-    private double getOsnrDbfromOnsrLin(double onsrLu) {
-        return 10 * Math.log10(1 / onsrLu);
+    private double getOsnrDbfromOnsrLin(double osnrLu) {
+        return 10 * Math.log10(1 / osnrLu);
     }
 
     /**
@@ -1032,36 +1005,46 @@ public class PostAlgoPathValidator {
         BitSet result = BitSet.valueOf(freqMap);
         boolean isFlexGrid = true;
         LOG.debug("Processing path {} with length {}", path, path.getLength());
+        BitSet pceNodeFreqMap;
+        Set<PceNode> pceNodes = new LinkedHashSet<>();
+
         for (PceGraphEdge edge : path.getEdgeList()) {
-            NodeId srcNodeId = edge.link().getSourceId();
-            LOG.debug("Processing source {} ", srcNodeId);
-            if (allPceNodes.containsKey(srcNodeId)) {
-                PceNode pceNode = allPceNodes.get(srcNodeId);
-                LOG.debug("Processing PCE node {}", pceNode);
-                String pceNodeVersion = pceNode.getVersion();
-                NodeId pceNodeId = pceNode.getNodeId();
-                BigDecimal sltWdthGran = pceNode.getSlotWidthGranularity();
-                BigDecimal ctralFreqGran = pceNode.getCentralFreqGranularity();
-                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);
-                    isFlexGrid = false;
-                }
-                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;
-                }
-                BitSet pceNodeFreqMap = pceNode.getBitSetData();
-                LOG.debug("Pce node bitset {}", pceNodeFreqMap);
-                if (pceNodeFreqMap != null) {
-                    result.and(pceNodeFreqMap);
-                    LOG.debug("intermediate bitset {}", result);
-                }
+            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()));
+            }
+            if (allPceNodes.containsKey(link.getDestId())) {
+                pceNodes.add(allPceNodes.get(link.getDestId()));
             }
         }
+
+        for (PceNode pceNode : pceNodes) {
+            LOG.debug("Processing PCE node {}", pceNode);
+            String pceNodeVersion = pceNode.getVersion();
+            NodeId pceNodeId = pceNode.getNodeId();
+            BigDecimal sltWdthGran = pceNode.getSlotWidthGranularity();
+            BigDecimal ctralFreqGran = pceNode.getCentralFreqGranularity();
+            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);
+                isFlexGrid = false;
+            }
+            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;
+            }
+            pceNodeFreqMap = pceNode.getBitSetData();
+            LOG.debug("Pce node bitset {}", pceNodeFreqMap);
+            if (pceNodeFreqMap != null) {
+                result.and(pceNodeFreqMap);
+                LOG.debug("intermediate bitset {}", result);
+            }
+
+        }
         LOG.debug("Bitset result {}", result);
         return computeBestSpectrumAssignment(result, spectralWidthSlotNumber, isFlexGrid);
     }