* Appy redirect to default path in AffinityPath. 31/5531/1
authorSuchi Raman <suchi.raman@plexxi.com>
Fri, 28 Feb 2014 21:33:53 +0000 (16:33 -0500)
committerSuchi Raman <suchi.raman@plexxi.com>
Wed, 5 Mar 2014 08:36:25 +0000 (03:36 -0500)
Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityPath.java
flatl2/src/main/java/org/opendaylight/affinity/flatl2/FlatL2AffinityImpl.java
scripts/affinity.py

index 22a9938bd95630125ffc239192d64f7f9e9d6e7b..e1278cf611995477a4193a09736e4ed69ad7f75c 100644 (file)
@@ -38,14 +38,14 @@ public class AffinityPath implements Serializable {
     // Default path, leading to the destination. Each element is a sub-path of the total default path. 
     HostNodeConnector src;
     HostNodeConnector dst;
-    List<Path> defaultPath;
+    List<HostPairPath> defaultPath;
     HashMap<HostNodeConnector, Path> tapPaths;
 
     /* Dummy constructor for JAXB */
     public AffinityPath(HostNodeConnector src, HostNodeConnector dst) {
         this.src = src;
         this.dst = dst;
-        this.defaultPath = new ArrayList<Path>();
+        this.defaultPath = new ArrayList<HostPairPath>();
         this.tapPaths = new HashMap<HostNodeConnector, Path>();
     }
 
@@ -55,10 +55,10 @@ public class AffinityPath implements Serializable {
     public HostNodeConnector getDst() {
         return this.dst;
     }
-    public List<Path> getDefaultPath() {
+    public List<HostPairPath> getDefaultPath() {
         return defaultPath;
     }
-    public void setDefaultPath(List<Path> subpaths) {
+    public void setDefaultPath(List<HostPairPath> subpaths) {
         defaultPath = subpaths;
     }
     
@@ -91,8 +91,13 @@ public class AffinityPath implements Serializable {
     @Override
     public String toString() {
         String string = "affinity-path: \n";
-        string = string + "src: " + src.toString() + "\n" + "dst: " + dst.toString() + "\n";
-        string = string + "defPath: " + defaultPath.toString() + "\n";
+        
+        string = string + "src: " + src.toString() + "\n";
+        string = string + "dst: " + dst.toString() + "\n";
+        string = string + "defPath: " + "\n";
+        for (HostPairPath hp: defaultPath) {
+            string = string + hp.toString() + "\n";
+        }
         for (HostNodeConnector k: tapPaths.keySet()) {
             string = string + "tapdst: " + k.toString() + "\n" + "path: " + tapPaths.get(k).toString() + "\n";
         }
index 8a22953150e0e5f46cb559651bff38700dfc8d7b..599e7bb91439a067be73181143d3dfe8dd6b048b 100644 (file)
@@ -94,6 +94,7 @@ import org.opendaylight.affinity.affinity.IAffinityManager;
 import org.opendaylight.affinity.affinity.AffinityAttributeType;
 import org.opendaylight.affinity.affinity.AffinityAttribute;
 import org.opendaylight.affinity.affinity.AffinityPath;
+import org.opendaylight.affinity.affinity.HostPairPath;
 import org.opendaylight.affinity.affinity.SetDeny;
 import org.opendaylight.affinity.affinity.SetPathIsolate;
 import org.opendaylight.affinity.affinity.SetPathRedirect;
@@ -416,28 +417,50 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
     public HashMap<Node, List<Action>> calcForwardingActions(AffinityPath ap) {
 
         HashMap<Node, List<Action>> actionMap;
+        // Final set of rules to push into the nodes.
         actionMap = new HashMap<Node, List<Action>>();
         
-        // Add nodes in default path into the hash map.
-        // Default path has subpaths, created by redirects. xxx for now, just get one of these. 
-        Path p = ap.getDefaultPath().get(0);
-        addrules(ap.getDst(), p, actionMap);
+        Node srcNode = ap.getSrc().getnodeconnectorNode();
+        Node destNode = ap.getDst().getnodeconnectorNode();
+        // Process each segment of the default path, where each
+        // segment is created by a redirect/waypoint.
+        for (HostPairPath p: ap.getDefaultPath()) {
+            // If path to the hnc is null. Two cases to consider: 
+            // (a) source and destination are attached to the same node. Use this node in addrules. 
+            // (b) no path between source and destination. Do not call addrules. 
+            actionMap = addrules(p.getSource(), p.getDestination(), p.getPath(), actionMap);
+        }
 
         // Add output ports for each node in the tapPath list. Include
         // the host node connector of the destination server too.
         HashMap<HostNodeConnector, Path> tapPaths = ap.getTapPaths();
         for (HostNodeConnector tapDest: tapPaths.keySet()) {
             Path tp = tapPaths.get(tapDest);
-            actionMap = addrules(tapDest, tp, actionMap);
+            actionMap = addrules(ap.getSrc(), tapDest, tp, actionMap);
         }
         return actionMap;
     }
 
     // Translate the path (edges + nodes) into a set of per-node forwarding actions. 
     // Coalesce them with the existing set of rules for this affinity path. 
-    public HashMap<Node, List<Action>> addrules(HostNodeConnector hnc, Path p, HashMap<Node, List<Action>> actionMap) {
+    public HashMap<Node, List<Action>> addrules(HostNodeConnector srcHnc, HostNodeConnector dstHnc, Path p, 
+                                                HashMap<Node, List<Action>> actionMap) {
         HashMap<Node, List<Action>> rules = actionMap;
-        
+        NodeConnector forwardPort;
+
+        if (srcHnc.getnodeconnectorNode().getNodeIDString().equals(dstHnc.getnodeconnectorNode().getNodeIDString())) {
+            forwardPort = dstHnc.getnodeConnector();
+            log.debug("Both source and destination are connected to same switch nodes. output port is {}",
+                      forwardPort);
+            Node destNode = dstHnc.getnodeconnectorNode();
+            List<Action> actions = rules.get(destNode);
+            rules.put(destNode, merge(actions, new Output(forwardPort)));
+            return rules;
+        } 
+        if (p == null) {
+            log.debug("No edges in path, returning.");
+            return rules;
+        }
         Edge lastedge = null;
         for (Edge e: p.getEdges()) {
             NodeConnector op = e.getTailNodeConnector();
@@ -447,7 +470,7 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
             lastedge = e;
         }
         // Add the edge from the lastnode to the destination host. 
-        NodeConnector dstNC = hnc.getnodeConnector();
+        NodeConnector dstNC = dstHnc.getnodeConnector();
         Node lastnode = lastedge.getHeadNodeConnector().getNode();
         // lastnode is also the same as hnc.getnodeConnectorNode();
         List<Action> actions = rules.get(lastnode);
@@ -643,7 +666,7 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
             maxTputPath = true;
         }
         // Compute the default path, after applying waypoints and add it to the list. 
-        List<Path> subpaths = new ArrayList<Path>();
+        // List<HostPairPath> subpaths = new ArrayList<HostPairPath>();
         HostNodeConnector srcNC, dstNC;
         srcNC = getHostNodeConnector(src);
         dstNC = getHostNodeConnector(dst);
@@ -666,7 +689,7 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
         // No redirects were added, so calculate the defaultPath by
         // looking up the appropriate type of route in the routing
         // service.
-        List<Path> route = new ArrayList<Path>();
+        List<HostPairPath> route = new ArrayList<HostPairPath>();
         if (rdrct == null) {
             Path defPath;
             if (maxTputPath == true) {
@@ -674,7 +697,7 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
             } else {
                 defPath = this.routing.getRoute(srcNode, dstNode);
             }
-            route.add(defPath);
+            route.add(new HostPairPath(srcNC, dstNC, defPath));
         } else {
             log.info("Found a path redirect setting. Calculating subpaths 1, 2");
             List<InetAddress> wplist = rdrct.getWaypointList();
@@ -688,14 +711,18 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
                 Path subpath2;
                 subpath1 = this.routing.getRoute(srcNode, wpNode);
                 subpath2 = this.routing.getRoute(wpNode, dstNode);
-                route.add(subpath1);
-                route.add(subpath2);
+                log.debug("subpath1 is: {}", subpath1);
+                log.debug("subpath2 is: {}", subpath2);
+
+                route.add(new HostPairPath(srcNC, wpNC, subpath1));
+                route.add(new HostPairPath(wpNC, dstNC, subpath2));
             }
         }
         if (route.size() > 0) {
+            log.debug("Adding default path to ap src {}, dst {}, route {}", src, dst, route.get(0));
             ap.setDefaultPath(route);
         }
-            
+        
         // Apply tap, calculate paths to each tap destination and add to AffinityPath.
         aatype = AffinityAttributeType.SET_TAP;
 
index c950f15cd67aae2d84caa7a63c28b3cf3fb82142..ae294678319e34c9dd30758470d938f5b999273b 100644 (file)
@@ -236,14 +236,14 @@ def main():
 
     # Create two affinity groups and a link between them. 
     # Assign attributes. 
-#    client_ws_example()
-#    repeat_add_link()
+    client_ws_example()
+    repeat_add_link()
 
-#    get_affinity_group('webservers')
-#    get_affinity_group('clients')
-#    get_affinity_link('inflows')
-
-    test_tap()
+    get_affinity_group('webservers')
+    get_affinity_group('clients')
+    get_affinity_link('inflows')
+    add_waypoint()
+#    test_tap()
 
     print "get_all_affinity_groups..."
     get_all_affinity_groups()