Skip to content
Snippets Groups Projects
Commit 55602b48 authored by Geddings Barrineau's avatar Geddings Barrineau
Browse files

Added getRoutesFast and getRoutesSlow.

parent 00b3ab01
No related branches found
No related tags found
No related merge requests found
...@@ -109,8 +109,9 @@ public class TopologyInstance { ...@@ -109,8 +109,9 @@ public class TopologyInstance {
// routecache contains n (specified in floodlightdefault.properties) routes // routecache contains n (specified in floodlightdefault.properties) routes
// in order between every switch. Calculated using Yen's algorithm. // in order between every switch. Calculated using Yen's algorithm.
protected Map<RouteId, ArrayList<Route>> routecache = new HashMap<>(); protected Map<RouteId, ArrayList<Route>> routecache;
protected static volatile int maximumRouteEntriesStored = 10;
public TopologyInstance(Map<DatapathId, Set<OFPort>> switchPorts, public TopologyInstance(Map<DatapathId, Set<OFPort>> switchPorts,
Set<NodePortTuple> blockedPorts, Set<NodePortTuple> blockedPorts,
Map<NodePortTuple, Set<Link>> switchPortLinks, Map<NodePortTuple, Set<Link>> switchPortLinks,
...@@ -171,6 +172,9 @@ public class TopologyInstance { ...@@ -171,6 +172,9 @@ public class TopologyInstance {
return pathCacheLoader.load(rid); return pathCacheLoader.load(rid);
} }
}); });
this.routecache = new HashMap<RouteId, ArrayList<Route>>();
} }
public void compute() { public void compute() {
...@@ -918,7 +922,7 @@ public class TopologyInstance { ...@@ -918,7 +922,7 @@ public class TopologyInstance {
for (DatapathId src : switches) { for (DatapathId src : switches) {
for (DatapathId dst : switches) { for (DatapathId dst : switches) {
routes = getRoutes(src, dst, 5); // Hard coded value needs to be replaced. routes = getRoutes(src, dst, maximumRouteEntriesStored);
routeId = new RouteId(src, dst); routeId = new RouteId(src, dst);
routecache.put(routeId, routes); routecache.put(routeId, routes);
} }
...@@ -1163,6 +1167,60 @@ public class TopologyInstance { ...@@ -1163,6 +1167,60 @@ public class TopologyInstance {
return linkDpidMap; return linkDpidMap;
} }
/**
*
* This function returns K number of routes between a source and destination IF THEY EXIST IN THE ROUTECACHE.
* If the user requests more routes than available, only the routes already stored in memory will be returned.
* This value can be adjusted in floodlightdefault.properties.
*
*
* @param src: DatapathId of the route source.
* @param dst: DatapathId of the route destination.
* @param K: The number of routes that you want. Must be positive integer.
* @return ArrayList of Routes or null if bad parameters
*/
protected ArrayList<Route> getRoutesFast(DatapathId src, DatapathId dst, Integer K) {
// TODO: Think about using int instead of Integer
RouteId routeId = new RouteId(src, dst);
ArrayList<Route> routes = routecache.get(routeId);
if (routes == null || K < 1) return null;
if (K >= maximumRouteEntriesStored || K >= routes.size()) {
return routes;
}
else {
return new ArrayList<Route>(routes.subList(0, K));
}
}
/**
*
* This function returns K number of routes between a source and destination. It will attempt to retrieve
* these routes from the routecache. If the user requests more routes than are stored, Yen's algorithm will be
* run using the K value passed in.
*
*
* @param src: DatapathId of the route source.
* @param dst: DatapathId of the route destination.
* @param K: The number of routes that you want. Must be positive integer.
* @return ArrayList of Routes or null if bad parameters
*/
protected ArrayList<Route> getRoutesSlow(DatapathId src, DatapathId dst, Integer K) {
// TODO: Think about using int instead of Integer
RouteId routeId = new RouteId(src, dst);
ArrayList<Route> routes = routecache.get(routeId);
if (routes == null || K < 1) return null;
if (K >= maximumRouteEntriesStored || K >= routes.size()) {
return getRoutes(src, dst, K);
}
else {
return new ArrayList<Route>(routes.subList(0, K));
}
}
protected void setRouteCosts(Route r) { protected void setRouteCosts(Route r) {
U64 cost = U64.ZERO; U64 cost = U64.ZERO;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment