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=583ac4572580c905ac9d3d918efa6417602fba83;hb=refs%2Fchanges%2F42%2F103942%2F3;hp=b3dbae014e250d1bfaac3baea45cc046e5487a62;hpb=e6f1b3acce76396e50731b0c97b07c36dca7224d;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 b3dbae014..583ac4572 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,17 +13,22 @@ 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.GraphPath; import org.jgrapht.alg.shortestpath.KShortestSimplePaths; import org.jgrapht.alg.shortestpath.PathValidator; import org.jgrapht.graph.DefaultDirectedWeightedGraph; import org.opendaylight.transportpce.common.ResponseCodes; +import org.opendaylight.transportpce.common.StringConstants; 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.openroadm.common.state.types.rev191129.State; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,7 +58,7 @@ public class PceGraph { private List shortestPathAtoZ = null; // for path calculation - List> allWPaths = null; + Map> allWPaths = null; private List pathAtoZ = new ArrayList<>(); @@ -83,20 +88,21 @@ public class PceGraph { 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) { + for (Entry> entry : allWPaths.entrySet()) { + GraphPath path = entry.getValue(); + LOG.info("validating path n° {} - {}", entry.getKey(), path.getVertexList()); 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.info("In calcPath: post algo validations DROPPED the path {}", path); + 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; } @@ -107,22 +113,35 @@ public class PceGraph { } shortestPathAtoZ = new ArrayList<>(pathAtoZ); - if (("100GE".equals(serviceType)) || ("OTU4".equals(serviceType))) { - LOG.info("In calcPath Path FOUND path for wl [{}], hops {}, distance per metrics {}, path AtoZ {}", - pceResult.getResultWavelength(), pathAtoZ.size(), path.getWeight(), pathAtoZ); - break; - } else { - // Service is at OTN layer and is relying on a supporting wavelength service - LOG.info("In calcPath Path FOUND path for hops {}, distance per metrics {}, path AtoZ {}", + switch (serviceType) { + + 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.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(), pathAtoZ.size(), path.getWeight(), pathAtoZ); - break; + break; + + default: + LOG.debug( + "In calcPath Path FOUND path for hops {}, distance per metrics {}, path AtoZ {}", + pathAtoZ.size(), path.getWeight(), pathAtoZ); + break; } + break; } if (shortestPathAtoZ != null) { - LOG.info("In calcPath CHOOSEN PATH for wl [{}], hops {}, path AtoZ {}", - pceResult.getResultWavelength(), shortestPathAtoZ.size(), shortestPathAtoZ); + LOG.info("In calcPath CHOOSEN PATH for wl [{}], min freq {}, max freq {}, hops {}, path AtoZ {}", + pceResult.getResultWavelength(), pceResult.getMinFreq(), pceResult.getMaxFreq(), + shortestPathAtoZ.size(), shortestPathAtoZ); } LOG.info("In calcPath : pceResult {}", pceResult); return (pceResult.getStatus()); @@ -138,7 +157,12 @@ public class PceGraph { // KShortestPaths on weightedGraph KShortestSimplePaths swp = new KShortestSimplePaths<>(weightedGraph, mhopsPerPath, wpv); - allWPaths = swp.getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring); + 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"); @@ -148,10 +172,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; } @@ -176,8 +198,10 @@ public class PceGraph { Iterator> nodes = allPceNodes.entrySet().iterator(); while (nodes.hasNext()) { Map.Entry node = nodes.next(); - weightedGraph.addVertex(node.getValue().getNodeId().getValue()); - LOG.debug("In populateWithNodes in node : {}", node.getValue()); + if (State.InService.equals(node.getValue().getState())) { + weightedGraph.addVertex(node.getValue().getNodeId().getValue()); + LOG.debug("In populateWithNodes in node : {}", node.getValue()); + } } } @@ -199,11 +223,12 @@ public class PceGraph { if (!validateLinkforGraph(link)) { continue; } + if (State.InService.equals(link.getState())) { + PceGraphEdge graphLink = new PceGraphEdge(link); + weightedGraph.addEdge(link.getSourceId().getValue(), link.getDestId().getValue(), graphLink); - PceGraphEdge graphLink = new PceGraphEdge(link); - weightedGraph.addEdge(link.getSourceId().getValue(), link.getDestId().getValue(), graphLink); - - weightedGraph.setEdgeWeight(graphLink, chooseWeight(link)); + weightedGraph.setEdgeWeight(graphLink, chooseWeight(link)); + } } } return true; @@ -220,8 +245,8 @@ public class PceGraph { case PropagationDelay : weight = link.getLatency(); LOG.debug("In PceGraph PropagationDelay is used as a metrics. {}", link); - if ((("1GE".equals(serviceType)) || ("10GE".equals(serviceType)) || ("ODU4".equals(serviceType))) - && (weight == 0)) { + if ((weight == 0) + && ("1GE".equals(serviceType) || "10GE".equals(serviceType) || "ODU4".equals(serviceType))) { LOG.warn("PropagationDelay set as metric, but latency is null: is latency set for OTN link {}?", link); }