Merge changes I453a92fd,I68ba6341
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PceGraph.java
index 0a2d75fc67a6f43f1fe15e68ae6fe3c88344cc79..994d3256fcbdce825275437c91d2357e60b176f2 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.transportpce.pce.graph;
 
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -17,9 +18,10 @@ import java.util.Map.Entry;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
+import org.jgrapht.Graph;
 import org.jgrapht.GraphPath;
-import org.jgrapht.alg.shortestpath.KShortestSimplePaths;
 import org.jgrapht.alg.shortestpath.PathValidator;
+import org.jgrapht.alg.shortestpath.YenKShortestPath;
 import org.jgrapht.graph.DefaultDirectedWeightedGraph;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.StringConstants;
@@ -29,6 +31,7 @@ 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.PceResult.LocalCause;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.PceConstraintMode;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
 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;
@@ -43,9 +46,6 @@ public class PceGraph {
     // how many paths to bring
     private int kpathsToBring = 15;
 
-    // max #hops
-    private int mhopsPerPath = 100;
-
     // input
     private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
     private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
@@ -54,7 +54,8 @@ public class PceGraph {
     private String serviceType = "";
     private Double margin = null;
     PceConstraints pceHardConstraints;
-    PceConstraints pceSoftConstraints;
+    private PceConstraintMode pceConstraintMode;
+    private BitSet spectrumConstraint;
 
     // results
     private PceResult pceResult = null;
@@ -68,8 +69,8 @@ public class PceGraph {
     private final NetworkTransactionService networkTransactionService;
 
     public PceGraph(PceNode aendNode, PceNode zendNode, Map<NodeId, PceNode> allPceNodes,
-            Map<LinkId, PceLink> allPceLinks, PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints,
-            PceResult pceResult, String serviceType, NetworkTransactionService networkTransactionService) {
+            Map<LinkId, PceLink> allPceLinks, PceConstraints pceHardConstraints,PceResult pceResult, String serviceType,
+            NetworkTransactionService networkTransactionService, PceConstraintMode mode, BitSet spectrumConstraint) {
         super();
         this.apceNode = aendNode;
         this.zpceNode = zendNode;
@@ -77,9 +78,10 @@ public class PceGraph {
         this.allPceLinks = allPceLinks;
         this.pceResult = pceResult;
         this.pceHardConstraints = pceHardConstraints;
-        this.pceSoftConstraints = pceSoftConstraints;
         this.serviceType = serviceType;
         this.networkTransactionService = networkTransactionService;
+        this.pceConstraintMode = mode;
+        this.spectrumConstraint = spectrumConstraint;
 
         LOG.info("In GraphCalculator: A and Z = {} / {} ", aendNode, zendNode);
         LOG.debug("In GraphCalculator: allPceNodes size {}, nodes {} ", allPceNodes.size(), allPceNodes);
@@ -89,7 +91,7 @@ public class PceGraph {
 
         LOG.info(" In PCE GRAPH calcPath : K SHORT PATHS algorithm ");
 
-        DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph =
+        Graph<String, PceGraphEdge> weightedGraph =
                 new DefaultDirectedWeightedGraph<>(PceGraphEdge.class);
         populateWithNodes(weightedGraph);
         populateWithLinks(weightedGraph);
@@ -103,8 +105,9 @@ public class PceGraph {
         for (Entry<Integer, GraphPath<String, PceGraphEdge>> entry : allWPaths.entrySet()) {
             GraphPath<String, PceGraphEdge> path = entry.getValue();
             LOG.info("validating path n° {} - {}", entry.getKey(), path.getVertexList());
-            PostAlgoPathValidator papv = new PostAlgoPathValidator(networkTransactionService);
-            pceResult = papv.checkPath(path, allPceNodes, allPceLinks, pceResult, pceHardConstraints, serviceType);
+            PostAlgoPathValidator papv = new PostAlgoPathValidator(networkTransactionService, spectrumConstraint);
+            pceResult = papv.checkPath(
+                    path, allPceNodes, allPceLinks, pceResult, pceHardConstraints, serviceType, pceConstraintMode);
             this.margin = papv.getTpceCalculatedMargin();
             if (ResponseCodes.RESPONSE_OK.equals(pceResult.getResponseCode())) {
                 LOG.info("Path is validated");
@@ -155,16 +158,15 @@ public class PceGraph {
         return (pceResult.getStatus());
     }
 
-    private boolean runKgraphs(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
+    private boolean runKgraphs(Graph<String, PceGraphEdge> weightedGraph) {
 
         if (weightedGraph.edgeSet().isEmpty() || weightedGraph.vertexSet().isEmpty()) {
             return false;
         }
         PathValidator<String, PceGraphEdge> wpv = new InAlgoPathValidator();
 
-        // KShortestPaths on weightedGraph
-        KShortestSimplePaths<String, PceGraphEdge> swp =
-            new KShortestSimplePaths<>(weightedGraph, mhopsPerPath, wpv);
+        // YenShortestPath on weightedGraph
+        YenKShortestPath<String, PceGraphEdge> swp = new YenKShortestPath<>(weightedGraph, wpv);
         List<GraphPath<String, PceGraphEdge>> weightedPathList = swp
             .getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring);
         allWPaths = IntStream
@@ -202,7 +204,7 @@ public class PceGraph {
         return true;
     }
 
-    private void populateWithNodes(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
+    private void populateWithNodes(Graph<String, PceGraphEdge> weightedGraph) {
         Iterator<Map.Entry<NodeId, PceNode>> nodes = allPceNodes.entrySet().iterator();
         while (nodes.hasNext()) {
             Map.Entry<NodeId, PceNode> node = nodes.next();
@@ -213,7 +215,7 @@ public class PceGraph {
         }
     }
 
-    private boolean populateWithLinks(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
+    private boolean populateWithLinks(Graph<String, PceGraphEdge> weightedGraph) {
 
         Iterator<Map.Entry<NodeId, PceNode>> nodes = allPceNodes.entrySet().iterator();
         while (nodes.hasNext()) {
@@ -278,10 +280,6 @@ public class PceGraph {
         this.kpathsToBring = kpathsToBring;
     }
 
-    public void setMhopsPerPath(int mhopsPerPath) {
-        this.mhopsPerPath = mhopsPerPath;
-    }
-
     public List<PceLink> getPathAtoZ() {
         return shortestPathAtoZ;
     }
@@ -294,8 +292,7 @@ public class PceGraph {
         return margin;
     }
 
-    public void setConstrains(PceConstraints pceHardConstraintsInput, PceConstraints pceSoftConstraintsInput) {
+    public void setConstrains(PceConstraints pceHardConstraintsInput) {
         this.pceHardConstraints = pceHardConstraintsInput;
-        this.pceSoftConstraints = pceSoftConstraintsInput;
     }
 }