use of org.onlab.graph.GraphPathSearch in project onos by opennetworkinglab.
the class DefaultTopology method getPaths.
/**
* Computes on-demand the set of shortest paths between source and
* destination devices, the set of returned paths will be no more than,
* maxPaths in size. The first {@code maxPaths} paths will be returned
* maintaining any ordering guarantees provided by the underlying
* (default or if no default is specified {@link DijkstraGraphSearch})
* search. If returning all paths of a given length would exceed
* {@code maxPaths} a subset of paths of that length will be returned,
* which paths will be returned depends on the currently specified
* {@code GraphPathSearch}. See {@link #setDefaultGraphPathSearch}.
*
* @param src source device
* @param dst destination device
* @param weigher link weight function
* @param maxPaths maximum number of paths
* @return set of shortest paths
*/
public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeigher weigher, int maxPaths) {
DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
Set<TopologyVertex> vertices = graph.getVertexes();
if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
// src or dst not part of the current graph
return ImmutableSet.of();
}
GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = graphPathSearch().search(graph, srcV, dstV, weigher, maxPaths);
ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
builder.add(networkPath(path));
}
return builder.build();
}
Aggregations