From d35b7d261711de2a1ebe9cd6896ba74a5eddcfed Mon Sep 17 00:00:00 2001 From: Suchi Raman Date: Fri, 28 Feb 2014 16:33:53 -0500 Subject: [PATCH] * Appy redirect to default path in AffinityPath. Signed-off-by: Suchi Raman --- .../affinity/affinity/AffinityPath.java | 17 ++++-- .../affinity/flatl2/FlatL2AffinityImpl.java | 55 ++++++++++++++----- scripts/affinity.py | 14 ++--- 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityPath.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityPath.java index 22a9938..e1278cf 100644 --- a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityPath.java +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityPath.java @@ -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 defaultPath; + List defaultPath; HashMap tapPaths; /* Dummy constructor for JAXB */ public AffinityPath(HostNodeConnector src, HostNodeConnector dst) { this.src = src; this.dst = dst; - this.defaultPath = new ArrayList(); + this.defaultPath = new ArrayList(); this.tapPaths = new HashMap(); } @@ -55,10 +55,10 @@ public class AffinityPath implements Serializable { public HostNodeConnector getDst() { return this.dst; } - public List getDefaultPath() { + public List getDefaultPath() { return defaultPath; } - public void setDefaultPath(List subpaths) { + public void setDefaultPath(List 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"; } diff --git a/flatl2/src/main/java/org/opendaylight/affinity/flatl2/FlatL2AffinityImpl.java b/flatl2/src/main/java/org/opendaylight/affinity/flatl2/FlatL2AffinityImpl.java index 8a22953..599e7bb 100644 --- a/flatl2/src/main/java/org/opendaylight/affinity/flatl2/FlatL2AffinityImpl.java +++ b/flatl2/src/main/java/org/opendaylight/affinity/flatl2/FlatL2AffinityImpl.java @@ -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> calcForwardingActions(AffinityPath ap) { HashMap> actionMap; + // Final set of rules to push into the nodes. actionMap = new HashMap>(); - // 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 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> addrules(HostNodeConnector hnc, Path p, HashMap> actionMap) { + public HashMap> addrules(HostNodeConnector srcHnc, HostNodeConnector dstHnc, Path p, + HashMap> actionMap) { HashMap> 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 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 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 subpaths = new ArrayList(); + // List subpaths = new ArrayList(); 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 route = new ArrayList(); + List route = new ArrayList(); 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 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; diff --git a/scripts/affinity.py b/scripts/affinity.py index c950f15..ae29467 100644 --- a/scripts/affinity.py +++ b/scripts/affinity.py @@ -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() -- 2.36.6