import java.util.Map;
import org.jgrapht.GraphPath;
-import org.jgrapht.alg.shortestpath.KShortestPaths;
+import org.jgrapht.alg.shortestpath.KShortestSimplePaths;
import org.jgrapht.alg.shortestpath.PathValidator;
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
import org.opendaylight.transportpce.common.ResponseCodes;
////////////////////////// for Graph ///////////////////////////
// how many paths to bring
- int kpathsToBring = 10;
+ private int kpathsToBring = 10;
+
// max #hops
- int mhopsPerPath = 50;
+ private int mhopsPerPath = 50;
// input
private Map<NodeId, PceNode> allPceNodes = new HashMap<NodeId, PceNode>();
private PceNode apceNode = null;
private PceNode zpceNode = null;
+ private String serviceType = "";
PceConstraints pceHardConstraints;
PceConstraints pceSoftConstraints;
private List<PceLink> pathAtoZ = new ArrayList<PceLink>();
public PceGraph(PceNode aendNode, PceNode zendNode, Map<NodeId, PceNode> allPceNodes,
- PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult pceResult) {
+ PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult pceResult,
+ String serviceType) {
super();
this.apceNode = aendNode;
this.zpceNode = zendNode;
this.pceResult = pceResult;
this.pceHardConstraints = pceHardConstraints;
this.pceSoftConstraints = pceSoftConstraints;
+ this.serviceType = serviceType;
LOG.info("In GraphCalculator: A and Z = {} / {} ", aendNode.toString(), zendNode.toString());
LOG.debug("In GraphCalculator: allPceNodes size {}, nodes {} ", allPceNodes.size(), allPceNodes.toString());
-
}
public boolean calcPath() {
// validate found paths
pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
for (GraphPath<String, PceGraphEdge> path : allWPaths) {
-
PostAlgoPathValidator papv = new PostAlgoPathValidator();
- pceResult = papv.checkPath(path, allPceNodes, pceResult);
+ pceResult = papv.checkPath(path, allPceNodes, pceResult, pceHardConstraints, serviceType);
LOG.info("In calcPath after PostAlgoPathValidator {} {}",
pceResult.getResponseCode(), ResponseCodes.RESPONSE_OK);
}
shortestPathAtoZ = new ArrayList<>(pathAtoZ);
- LOG.info("In calcPath Path FOUND path for wl [{}], hops {}, distance per metrics {}, path AtoZ {}",
- pceResult.getResultWavelength(), pathAtoZ.size(), path.getWeight(), pathAtoZ.toString());
- break;
+ 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.toString());
+ 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 {}",
+ pathAtoZ.size(), path.getWeight(), pathAtoZ.toString());
+ break;
+ }
+
}
if (shortestPathAtoZ != null) {
if (weightedGraph.edgeSet().isEmpty() || weightedGraph.vertexSet().isEmpty()) {
return false;
}
-
- PathValidator<String, PceGraphEdge> wpv = new InAlgoPathValidator(pceHardConstraints, zpceNode);
-
- // local optimization. if 'include' constraint exists then increase amount of paths to return.
- // it's because this constraint is checked at the last step when part of good paths
- // are dropped by other constraints
- if (!pceHardConstraints.getListToInclude().isEmpty()) {
- kpathsToBring = kpathsToBring * 10;
- LOG.info("k = {}",kpathsToBring);
- }
+ PathValidator<String, PceGraphEdge> wpv = new InAlgoPathValidator();
// KShortestPaths on weightedGraph
- KShortestPaths<String, PceGraphEdge> swp =
- new KShortestPaths<String, PceGraphEdge>(weightedGraph, kpathsToBring, mhopsPerPath, wpv);
-
- allWPaths = swp.getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue());
+ KShortestSimplePaths<String, PceGraphEdge> swp =
+ new KShortestSimplePaths<String, PceGraphEdge>(weightedGraph, mhopsPerPath, wpv);
+ allWPaths = swp.getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring);
if (allWPaths.isEmpty()) {
LOG.info(" In runKgraphs : algorithm didn't find any path");
// debug print
for (GraphPath<String, PceGraphEdge> path : allWPaths) {
- LOG.info("path Weight: {} : {}", path.getWeight(), path.getVertexList().toString());
+ LOG.debug("path Weight: {} : {}", path.getWeight(), path.getVertexList().toString());
}
- // debug print
return true;
}
LOG.error("In addLinkToGraph link dest node is null : {}", pcelink.toString());
return false;
}
-
LOG.debug("In addLinkToGraph link to nodes : {}{} {}", pcelink.toString(), source.toString(), dest.toString());
return true;
-
}
private void populateWithNodes(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
}
private double chooseWeight(PceLink link) {
-
// HopCount is default
double weight = 1;
switch (pceHardConstraints.getPceMetrics()) {
- case IGPMetric :
- // TODO implement IGPMetric - low priority.
- LOG.warn("In PceGraph not implemented IGPMetric. HopCount works as a default");
- break;
-
- case TEMetric :
- // TODO implement TEMetric - low priority
- LOG.warn("In PceGraph not implemented TEMetric. HopCount works as a default");
- break;
-
case HopCount :
weight = 1;
LOG.debug("In PceGraph HopCount is used as a metrics. {}", link.toString());
break;
-
case PropagationDelay :
weight = link.getLatency();
LOG.debug("In PceGraph PropagationDelay is used as a metrics. {}", link.toString());
+ if ((("1GE".equals(serviceType)) || ("10GE".equals(serviceType)) || ("ODU4".equals(serviceType)))
+ && (weight == 0)) {
+ LOG.warn("PropagationDelay set as metric, but latency is null: is latency set for OTN link {}?",
+ link.toString());
+ }
break;
-
+ // TODO implement IGPMetric and TEMetric - low priority.
+ case IGPMetric :
+ case TEMetric :
default:
+ LOG.warn("In PceGraph {} not implemented. HopCount works as a default",
+ pceHardConstraints.getPceMetrics());
break;
}
-
return weight;
}
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ public int getKpathsToBring() {
+ return kpathsToBring;
+ }
+
+ public void setKpathsToBring(int kpathsToBring) {
+ this.kpathsToBring = kpathsToBring;
+ }
+
+ public void setMhopsPerPath(int mhopsPerPath) {
+ this.mhopsPerPath = mhopsPerPath;
+ }
+
public List<PceLink> getPathAtoZ() {
return shortestPathAtoZ;
}
this.pceHardConstraints = pceHardConstraintsInput;
this.pceSoftConstraints = pceSoftConstraintsInput;
}
-
}