ONOS-6225 Expose k-shortest path search as part of TopologyService.
Change-Id: Idf812a707aba0b972fcfbde871c624dfc86b6e1b
diff --git a/core/api/src/main/java/org/onosproject/net/topology/TopologyService.java b/core/api/src/main/java/org/onosproject/net/topology/TopologyService.java
index 13d1842..76ae91e 100644
--- a/core/api/src/main/java/org/onosproject/net/topology/TopologyService.java
+++ b/core/api/src/main/java/org/onosproject/net/topology/TopologyService.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.topology;
+import org.onlab.util.GuavaCollectors;
import org.onosproject.event.ListenerService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
@@ -24,6 +25,7 @@
import java.util.Map;
import java.util.Set;
+import java.util.stream.Stream;
/**
* Service for providing network topology information.
@@ -130,6 +132,48 @@
LinkWeigher weigher);
/**
+ * Returns the k-shortest paths between source and
+ * destination devices.
+ *
+ * The first {@code maxPaths} paths will be returned
+ * in ascending order according to the provided {@code weigher}
+ *
+ * @param topology topology descriptor
+ * @param src source device
+ * @param dst destination device
+ * @param weigher edge-weight entity
+ * @param maxPaths maximum number of paths (k)
+ * @return set of k-shortest paths
+ */
+ default Set<Path> getKShortestPaths(Topology topology,
+ DeviceId src, DeviceId dst,
+ LinkWeigher weigher,
+ int maxPaths) {
+ return getKShortestPaths(topology, src, dst, weigher)
+ .limit(maxPaths)
+ .collect(GuavaCollectors.toImmutableSet());
+ }
+
+ /**
+ * Returns the k-shortest paths between source and
+ * destination devices.
+ *
+ * The first {@code maxPaths} paths will be returned
+ * in ascending order according to the provided {@code weigher}
+ *
+ * @param topology topology descriptor
+ * @param src source device
+ * @param dst destination device
+ * @param weigher edge-weight entity
+ * @return stream of k-shortest paths
+ */
+ default Stream<Path> getKShortestPaths(Topology topology,
+ DeviceId src, DeviceId dst,
+ LinkWeigher weigher) {
+ return getPaths(topology, src, dst, weigher).stream();
+ }
+
+ /**
* Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count,
* between the specified source and destination devices.
*
diff --git a/core/api/src/main/java/org/onosproject/net/topology/TopologyStore.java b/core/api/src/main/java/org/onosproject/net/topology/TopologyStore.java
index 907beb2..d87fff0 100644
--- a/core/api/src/main/java/org/onosproject/net/topology/TopologyStore.java
+++ b/core/api/src/main/java/org/onosproject/net/topology/TopologyStore.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.topology;
+import org.onlab.util.GuavaCollectors;
import org.onosproject.event.Event;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
@@ -26,6 +27,7 @@
import java.util.List;
import java.util.Set;
+import java.util.stream.Stream;
import java.util.Map;
/**
@@ -129,6 +131,45 @@
LinkWeigher weigher);
/**
+ * Computes and returns the k-shortest paths between source and
+ * destination devices.
+ *
+ * The first {@code maxPaths} paths will be returned
+ * in ascending order according to the provided {@code weigher}
+ *
+ * @param topology topology descriptor
+ * @param src source device
+ * @param dst destination device
+ * @param weigher edge-weight entity
+ * @param maxPaths maximum number of paths (k)
+ * @return set of k-shortest paths
+ */
+ default Set<Path> getKShortestPaths(Topology topology,
+ DeviceId src, DeviceId dst,
+ LinkWeigher weigher,
+ int maxPaths) {
+ return getKShortestPaths(topology, src, dst, weigher)
+ .limit(maxPaths)
+ .collect(GuavaCollectors.toImmutableSet());
+ }
+
+ /**
+ * Computes and returns the k-shortest paths between source and
+ * destination devices.
+ *
+ * @param topology topology descriptor
+ * @param src source device
+ * @param dst destination device
+ * @param weigher edge-weight entity
+ * @return stream of k-shortest paths
+ */
+ default Stream<Path> getKShortestPaths(Topology topology,
+ DeviceId src, DeviceId dst,
+ LinkWeigher weigher) {
+ return getPaths(topology, src, dst, weigher).stream();
+ }
+
+ /**
* Computes and returns the set of disjoint shortest path pairs
* between src and dst.
*