X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fgraph%2FPostAlgoPathValidator.java;h=32624da2faba0c5c669c79cdb08009ba814b52a4;hb=2d4fea02cd291920e94bd36f4f32299a27508206;hp=cf4c7e9bbbc7822ce458313affba31f3a2f7f004;hpb=fdc2f0f2a9e6d88925223877993981eb5ceffd99;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java index cf4c7e9bb..32624da2f 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java @@ -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,6 +38,7 @@ 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.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; @@ -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 path, Map allPceNodes, Map 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 path, PceConstraints pceHardConstraintsInput) { - List 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 path, PceConstraints pceHardConstraintsInput, + PceConstraintMode mode) { + List listToInclude = pceHardConstraintsInput.getListToInclude(); if (listToInclude.isEmpty()) { return true; } List pathEdges = path.getEdgeList(); LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList()); + LOG.debug("listToInclude = {}", listToInclude); List 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 listOfElementsBuild(List pathEdges, PceConstraints.ResourceType type, PceConstraints pceHardConstraints) { - List listOfElements = new ArrayList<>(); + Set 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 chooseTribPort(GraphPath 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);