From 00b3ab01b3c5675df924d72efe5f7399fd5dbf11 Mon Sep 17 00:00:00 2001 From: Geddings Barrineau <cbarrin@g.clemson.edu> Date: Wed, 13 Jul 2016 14:06:52 -0400 Subject: [PATCH] Forgot to transfer over new dijkstra code. Updated to work with Yen's algorithm. --- .../topology/TopologyInstance.java | 133 +++++++++--------- 1 file changed, 70 insertions(+), 63 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java index b282698a7..3a0792054 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java @@ -682,71 +682,78 @@ public class TopologyInstance { * Dijkstra that calculates destination rooted trees over the entire topology. */ protected BroadcastTree dijkstra(Map<DatapathId, Set<Link>> links, DatapathId root, - Map<Link, Integer> linkCost, - boolean isDstRooted) { - HashMap<DatapathId, Link> nexthoplinks = new HashMap<DatapathId, Link>(); - HashMap<DatapathId, Integer> cost = new HashMap<DatapathId, Integer>(); - int w; - - for (DatapathId node : links.keySet()) { - nexthoplinks.put(node, null); - cost.put(node, MAX_PATH_WEIGHT); - } - - HashMap<DatapathId, Boolean> seen = new HashMap<DatapathId, Boolean>(); - PriorityQueue<NodeDist> nodeq = new PriorityQueue<NodeDist>(); - nodeq.add(new NodeDist(root, 0)); - cost.put(root, 0); - - while (nodeq.peek() != null) { - NodeDist n = nodeq.poll(); - DatapathId cnode = n.getNode(); - int cdist = n.getDist(); - - if (cdist >= MAX_PATH_WEIGHT) break; - if (seen.containsKey(cnode)) continue; - seen.put(cnode, true); - - for (Link link : links.get(cnode)) { - DatapathId neighbor; - - if (isDstRooted == true) { - neighbor = link.getSrc(); - } else { - neighbor = link.getDst(); - } - - // links directed toward cnode will result in this condition - if (neighbor.equals(cnode)) continue; - - if (seen.containsKey(neighbor)) continue; - - if (linkCost == null || linkCost.get(link) == null) { - w = 1; - } else { - w = linkCost.get(link); - } - - int ndist = cdist + w; // the weight of the link, always 1 in current version of floodlight. - if (ndist < cost.get(neighbor)) { - cost.put(neighbor, ndist); - nexthoplinks.put(neighbor, link); - - NodeDist ndTemp = new NodeDist(neighbor, ndist); - // Remove an object that's already in there. - // Note that the comparison is based on only the node id, - // and not node id and distance. - nodeq.remove(ndTemp); - // add the current object to the queue. - nodeq.add(ndTemp); - } - } - } + Map<Link, Integer> linkCost, + boolean isDstRooted) { + HashMap<DatapathId, Link> nexthoplinks = new HashMap<DatapathId, Link>(); + HashMap<DatapathId, Integer> cost = new HashMap<DatapathId, Integer>(); + int w; - BroadcastTree ret = new BroadcastTree(nexthoplinks, cost); + for (DatapathId node : links.keySet()) { + nexthoplinks.put(node, null); + cost.put(node, MAX_PATH_WEIGHT); + //log.debug("Added max cost to {}", node); + } - return ret; - } + HashMap<DatapathId, Boolean> seen = new HashMap<DatapathId, Boolean>(); + PriorityQueue<NodeDist> nodeq = new PriorityQueue<NodeDist>(); + nodeq.add(new NodeDist(root, 0)); + cost.put(root, 0); + + //log.debug("{}", links); + + while (nodeq.peek() != null) { + NodeDist n = nodeq.poll(); + DatapathId cnode = n.getNode(); + int cdist = n.getDist(); + + if (cdist >= MAX_PATH_WEIGHT) break; + if (seen.containsKey(cnode)) continue; + seen.put(cnode, true); + + //log.debug("cnode {} and links {}", cnode, links.get(cnode)); + if (links.get(cnode) == null) continue; + for (Link link : links.get(cnode)) { + DatapathId neighbor; + + if (isDstRooted == true) { + neighbor = link.getSrc(); + } else { + neighbor = link.getDst(); + } + + // links directed toward cnode will result in this condition + if (neighbor.equals(cnode)) continue; + + if (seen.containsKey(neighbor)) continue; + + if (linkCost == null || linkCost.get(link) == null) { + w = 1; + } else { + w = linkCost.get(link); + } + + int ndist = cdist + w; // the weight of the link, always 1 in current version of floodlight. + //log.debug("Neighbor: {}", neighbor); + //log.debug("Cost: {}", cost.get(neighbor)); + if (ndist < cost.get(neighbor)) { + cost.put(neighbor, ndist); + nexthoplinks.put(neighbor, link); + + NodeDist ndTemp = new NodeDist(neighbor, ndist); + // Remove an object that's already in there. + // Note that the comparison is based on only the node id, + // and not node id and distance. + nodeq.remove(ndTemp); + // add the current object to the queue. + nodeq.add(ndTemp); + } + } + } + + BroadcastTree ret = new BroadcastTree(nexthoplinks, cost); + + return ret; + } /* * Creates a map of links and the cost associated with each link -- GitLab