X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fgraph%2FPceGraph.java;h=81656f3f8e254bb7ef4517171ea929479760731e;hb=73d098bc499661df6ef0044b62de4d46062ecfe9;hp=2b199309eb831afc3f5b6cac6f537ec994d4b8ac;hpb=e82fbaf8294be8b3bc2df5ef1649a401fa636912;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java index 2b199309e..81656f3f8 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java @@ -13,19 +13,27 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +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; +import org.opendaylight.transportpce.common.network.NetworkTransactionService; import org.opendaylight.transportpce.pce.constraints.PceConstraints; 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.rev230925.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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,40 +43,42 @@ public class PceGraph { ////////////////////////// for Graph /////////////////////////// // how many paths to bring - private int kpathsToBring = 10; - - // max #hops - private int mhopsPerPath = 50; + private int kpathsToBring = 15; // input private Map allPceNodes = new HashMap<>(); + private Map allPceLinks = new HashMap<>(); private PceNode apceNode = null; private PceNode zpceNode = null; private String serviceType = ""; - + private Double margin = null; PceConstraints pceHardConstraints; - PceConstraints pceSoftConstraints; + private PceConstraintMode pceConstraintMode; // results private PceResult pceResult = null; private List shortestPathAtoZ = null; // for path calculation - List> allWPaths = null; + Map> allWPaths = null; private List pathAtoZ = new ArrayList<>(); + private final NetworkTransactionService networkTransactionService; + public PceGraph(PceNode aendNode, PceNode zendNode, Map allPceNodes, - PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult pceResult, - String serviceType) { + Map allPceLinks, PceConstraints pceHardConstraints,PceResult pceResult, String serviceType, + NetworkTransactionService networkTransactionService, PceConstraintMode mode) { super(); this.apceNode = aendNode; this.zpceNode = zendNode; this.allPceNodes = allPceNodes; + this.allPceLinks = allPceLinks; this.pceResult = pceResult; this.pceHardConstraints = pceHardConstraints; - this.pceSoftConstraints = pceSoftConstraints; this.serviceType = serviceType; + this.networkTransactionService = networkTransactionService; + this.pceConstraintMode = mode; LOG.info("In GraphCalculator: A and Z = {} / {} ", aendNode, zendNode); LOG.debug("In GraphCalculator: allPceNodes size {}, nodes {} ", allPceNodes.size(), allPceNodes); @@ -78,26 +88,29 @@ public class PceGraph { LOG.info(" In PCE GRAPH calcPath : K SHORT PATHS algorithm "); - DefaultDirectedWeightedGraph weightedGraph = + Graph weightedGraph = new DefaultDirectedWeightedGraph<>(PceGraphEdge.class); populateWithNodes(weightedGraph); populateWithLinks(weightedGraph); if (!runKgraphs(weightedGraph)) { - LOG.info("In calcPath : pceResult {}", pceResult); + LOG.error("In calcPath : pceResult {}", pceResult); return false; } - // validate found paths pceResult.setRC(ResponseCodes.RESPONSE_FAILED); - for (GraphPath path : allWPaths) { - PostAlgoPathValidator papv = new PostAlgoPathValidator(); - pceResult = papv.checkPath(path, allPceNodes, pceResult, pceHardConstraints, serviceType); - LOG.info("In calcPath after PostAlgoPathValidator {} {}", - pceResult.getResponseCode(), ResponseCodes.RESPONSE_OK); - - if (!pceResult.getResponseCode().equals(ResponseCodes.RESPONSE_OK)) { - LOG.warn("In calcPath: post algo validations DROPPED the path {}", path); + for (Entry> entry : allWPaths.entrySet()) { + GraphPath 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, pceConstraintMode); + this.margin = papv.getTpceCalculatedMargin(); + if (ResponseCodes.RESPONSE_OK.equals(pceResult.getResponseCode())) { + LOG.info("Path is validated"); + } else { + LOG.warn("In calcPath: post algo validations DROPPED the path {}; for following cause: {}", + path, pceResult.getLocalCause()); continue; } @@ -110,10 +123,13 @@ public class PceGraph { shortestPathAtoZ = new ArrayList<>(pathAtoZ); switch (serviceType) { - case StringConstants.SERVICE_TYPE_100GE: + case StringConstants.SERVICE_TYPE_100GE_T: + case StringConstants.SERVICE_TYPE_OTUC2: + case StringConstants.SERVICE_TYPE_OTUC3: + case StringConstants.SERVICE_TYPE_OTUC4: case StringConstants.SERVICE_TYPE_400GE: case StringConstants.SERVICE_TYPE_OTU4: - LOG.info( + LOG.debug( "In calcPath Path FOUND path for wl [{}], min Freq assignment {}, max Freq assignment {}," + " hops {}, distance per metrics {}, path AtoZ {}", pceResult.getResultWavelength(), pceResult.getMinFreq(), pceResult.getMaxFreq(), @@ -121,7 +137,7 @@ public class PceGraph { break; default: - LOG.info( + LOG.debug( "In calcPath Path FOUND path for hops {}, distance per metrics {}, path AtoZ {}", pathAtoZ.size(), path.getWeight(), pathAtoZ); break; @@ -139,17 +155,21 @@ public class PceGraph { return (pceResult.getStatus()); } - private boolean runKgraphs(DefaultDirectedWeightedGraph weightedGraph) { + private boolean runKgraphs(Graph weightedGraph) { if (weightedGraph.edgeSet().isEmpty() || weightedGraph.vertexSet().isEmpty()) { return false; } PathValidator wpv = new InAlgoPathValidator(); - // KShortestPaths on weightedGraph - KShortestSimplePaths swp = - new KShortestSimplePaths<>(weightedGraph, mhopsPerPath, wpv); - allWPaths = swp.getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring); + // YenShortestPath on weightedGraph + YenKShortestPath swp = new YenKShortestPath<>(weightedGraph, wpv); + List> weightedPathList = swp + .getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring); + allWPaths = IntStream + .range(0, weightedPathList.size()) + .boxed() + .collect(Collectors.toMap(Function.identity(), weightedPathList::get)); if (allWPaths.isEmpty()) { LOG.info(" In runKgraphs : algorithm didn't find any path"); @@ -159,10 +179,8 @@ public class PceGraph { } // debug print - for (GraphPath path : allWPaths) { - LOG.debug("path Weight: {} : {}", path.getWeight(), path.getVertexList()); - } - + allWPaths + .forEach((k, v) -> LOG.info("path n° {} - weight: {} - path: {}", k, v.getWeight(), v.getVertexList())); return true; } @@ -183,7 +201,7 @@ public class PceGraph { return true; } - private void populateWithNodes(DefaultDirectedWeightedGraph weightedGraph) { + private void populateWithNodes(Graph weightedGraph) { Iterator> nodes = allPceNodes.entrySet().iterator(); while (nodes.hasNext()) { Map.Entry node = nodes.next(); @@ -194,7 +212,7 @@ public class PceGraph { } } - private boolean populateWithLinks(DefaultDirectedWeightedGraph weightedGraph) { + private boolean populateWithLinks(Graph weightedGraph) { Iterator> nodes = allPceNodes.entrySet().iterator(); while (nodes.hasNext()) { @@ -259,10 +277,6 @@ public class PceGraph { this.kpathsToBring = kpathsToBring; } - public void setMhopsPerPath(int mhopsPerPath) { - this.mhopsPerPath = mhopsPerPath; - } - public List getPathAtoZ() { return shortestPathAtoZ; } @@ -271,8 +285,11 @@ public class PceGraph { return pceResult; } - public void setConstrains(PceConstraints pceHardConstraintsInput, PceConstraints pceSoftConstraintsInput) { + public Double getmargin() { + return margin; + } + + public void setConstrains(PceConstraints pceHardConstraintsInput) { this.pceHardConstraints = pceHardConstraintsInput; - this.pceSoftConstraints = pceSoftConstraintsInput; } }