From 1563c89add691baaae6d79542205a25b4ec73578 Mon Sep 17 00:00:00 2001
From: Geddings Barrineau <cbarrin@g.clemson.edu>
Date: Wed, 13 Jul 2016 13:07:53 -0400
Subject: [PATCH] Added in the routecache. Similar to pathcache, routecache is
 computed by Yen's algorithm in the compute function. As the name implies, a
 routecache entry does not need to be built into a route, as it is already
 built. Future commits will involve replacing patchcache with the new
 routecache.

---
 .../topology/TopologyInstance.java            | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java
index cf3334ddb..d98cbba64 100644
--- a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java
+++ b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java
@@ -106,6 +106,10 @@ public class TopologyInstance {
     // in the cache.
     private final PathCacheLoader pathCacheLoader = new PathCacheLoader(this);
     protected LoadingCache<RouteId, Route> pathcache;
+
+    // routecache contains n (specified in floodlightdefault.properties) routes
+    // in order between every switch. Calculated using Yen's algorithm.
+    protected Map<RouteId, ArrayList<Route>> routecache;
 	
     public TopologyInstance(Map<DatapathId, Set<OFPort>> switchPorts,
                             Set<NodePortTuple> blockedPorts,
@@ -196,6 +200,9 @@ public class TopologyInstance {
         // Cost for tunnel links and direct links are the same.
 		calculateAllShortestPaths();
 
+        // Step 4.5 YENSSSSS
+        calculateAllOrderedRoutes();
+
         // Compute the archipelagos (def: cluster of islands). An archipelago will
         // simply be a group of connected islands. Each archipelago will have its own
         // finiteBroadcastTree which will be randomly chosen.
@@ -892,6 +899,25 @@ public class TopologyInstance {
 //        }
     }
 
+    /*
+    Calculates and stores n possible routes (specified in floodlightdefault.properties) using Yen's algorithm,
+    looping through every switch.
+    These lists of routes are stored in routecache.
+    */
+    protected void calculateAllOrderedRoutes() {
+        ArrayList<Route> routes;
+        RouteId routeId;
+        routecache.clear();
+
+        for (DatapathId src : switches) {
+            for (DatapathId dst : switches) {
+                routes = getRoutes(src, dst, 5); // Hard coded value needs to be replaced.
+                routeId = new RouteId(src, dst);
+                routecache.put(routeId, routes);
+            }
+        }
+    }
+
     protected void calculateShortestPathTreeInClusters() {
         pathcache.invalidateAll();
         destinationRootedTrees.clear();
-- 
GitLab