Adding an additional method for getting paths from default topology with a bound on how many paths will be returned.  This should not effect any existing uses.

Change-Id: I3709f5c0b1fced74338ad03bc5b9b406a9dfd978
diff --git a/core/common/src/main/java/org/onosproject/common/DefaultTopology.java b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
index 5321b42..8ed8513 100644
--- a/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
+++ b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
@@ -325,9 +325,10 @@
      * @return set of shortest paths
      */
     public Set<Path> getPaths(DeviceId src, DeviceId dst) {
-        return getPaths(src, dst, linkWeight());
+        return getPaths(src, dst, linkWeight(), ALL_PATHS);
     }
 
+
     /**
      * Computes on-demand the set of shortest paths between source and
      * destination devices.
@@ -338,6 +339,28 @@
      * @return set of shortest paths
      */
     public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
+        return getPaths(src, dst, weight, ALL_PATHS);
+    }
+
+    /**
+     * 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 weight link weight function
+     * @param maxPaths maximum number of paths
+     * @return set of shortest paths
+     */
+    public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight,
+                              int maxPaths) {
         DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
         DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
         Set<TopologyVertex> vertices = graph.getVertexes();
@@ -347,7 +370,7 @@
         }
 
         GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
-                graphPathSearch().search(graph, srcV, dstV, weight, ALL_PATHS);
+                graphPathSearch().search(graph, srcV, dstV, weight, maxPaths);
         ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
         for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
             builder.add(networkPath(path));
diff --git a/utils/misc/src/main/java/org/onlab/graph/KShortestPathsSearch.java b/utils/misc/src/main/java/org/onlab/graph/KShortestPathsSearch.java
index 8e5442b..09735b4 100644
--- a/utils/misc/src/main/java/org/onlab/graph/KShortestPathsSearch.java
+++ b/utils/misc/src/main/java/org/onlab/graph/KShortestPathsSearch.java
@@ -45,7 +45,10 @@
         checkNotNull(dst);
         //The modified edge weight removes any need to modify the original graph
         InnerEdgeWeighter modifiedWeighter = new InnerEdgeWeighter(checkNotNull(weight));
-        checkArgument(maxPaths > 0);
+        checkArgument(maxPaths != ALL_PATHS, "KShortestPath search cannot" +
+                "be used with ALL_PATHS.");
+        checkArgument(maxPaths > 0, "The max number of paths must be greater" +
+                " than 0");
         Graph<V, E> originalGraph = checkNotNull(graph);
         //the result contains the set of eventual results
         InnerOrderedResult result = new InnerOrderedResult(src, dst, maxPaths);