Skip to content
Snippets Groups Projects
Commit eb22c31c authored by Srinivasan Ramasubramanian's avatar Srinivasan Ramasubramanian
Browse files

Clean-up of the code; cluster computation algorithm is back to its original implementation.

parent e7ed9515
No related branches found
No related tags found
No related merge requests found
...@@ -1024,29 +1024,31 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, ...@@ -1024,29 +1024,31 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
Map<Long, IOFSwitch> switches = floodlightProvider.getSwitches(); Map<Long, IOFSwitch> switches = floodlightProvider.getSwitches();
Map<IOFSwitch, ClusterDFS> dfsList = new HashMap<IOFSwitch, ClusterDFS>(); Map<IOFSwitch, ClusterDFS> dfsList = new HashMap<IOFSwitch, ClusterDFS>();
for (Long key: switches.keySet()) { if (switches.keySet() != null) {
IOFSwitch sw = switches.get(key); for (Long key: switches.keySet()) {
ClusterDFS cdfs = new ClusterDFS(); IOFSwitch sw = switches.get(key);
dfsList.put(sw, cdfs); ClusterDFS cdfs = new ClusterDFS();
} dfsList.put(sw, cdfs);
}
// Get a set of switch keys in a set // Get a set of switch keys in a set
Set<IOFSwitch> currSet = new HashSet<IOFSwitch>(); Set<IOFSwitch> currSet = new HashSet<IOFSwitch>();
for (Long key: switches.keySet()) { for (Long key: switches.keySet()) {
IOFSwitch sw = switches.get(key); IOFSwitch sw = switches.get(key);
ClusterDFS cdfs = dfsList.get(sw); ClusterDFS cdfs = dfsList.get(sw);
if (cdfs == null) { if (cdfs == null) {
log.error("Do DFS object for key found."); log.error("Do DFS object for key found.");
}else if (!cdfs.isVisited()) { }else if (!cdfs.isVisited()) {
this.dfsTraverse(1, sw, switches, dfsList, currSet, clusters); this.dfsTraverse(0, 1, sw, switches, dfsList, currSet, clusters);
}
} }
} }
updates.add(new Update(UpdateOperation.CLUSTER_MERGED)); updates.add(new Update(UpdateOperation.CLUSTER_MERGED));
} }
protected long dfsTraverse (long currIndex, protected long dfsTraverse (long parentIndex, long currIndex,
IOFSwitch currSw, Map<Long, IOFSwitch> switches, IOFSwitch currSw, Map<Long, IOFSwitch> switches,
Map<IOFSwitch, ClusterDFS> dfsList, Set <IOFSwitch> currSet, Map<IOFSwitch, ClusterDFS> dfsList, Set <IOFSwitch> currSet,
Set <SwitchCluster> clusters) { Set <SwitchCluster> clusters) {
...@@ -1059,7 +1061,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, ...@@ -1059,7 +1061,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
//Assign the DFS object with right values. //Assign the DFS object with right values.
currDFS.setVisited(true); currDFS.setVisited(true);
currDFS.setDfsIndex(currIndex); currDFS.setDfsIndex(currIndex);
currDFS.setLowpoint(currIndex); currDFS.setParentDfsIndex(parentIndex);
currIndex++; currIndex++;
// Traverse the graph through every outgoing link. // Traverse the graph through every outgoing link.
...@@ -1083,7 +1085,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, ...@@ -1083,7 +1085,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
} else if (!dstDFS.isVisited()) { } else if (!dstDFS.isVisited()) {
// make a DFS visit // make a DFS visit
currIndex = dfsTraverse(currIndex, dstSw, currIndex = dfsTraverse(currDFS.getDfsIndex(), currIndex, dstSw,
switches, dfsList, currSet, clusters); switches, dfsList, currSet, clusters);
// update lowpoint after the visit // update lowpoint after the visit
...@@ -1102,20 +1104,17 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, ...@@ -1102,20 +1104,17 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
// If the node's lowpoint is greater than its parent's DFS index, // If the node's lowpoint is greater than its parent's DFS index,
// we need to form a new cluster with all the switches in the // we need to form a new cluster with all the switches in the
// currSet. // currSet.
if (currDFS.getLowpoint() == currDFS.getDfsIndex()) { if (currDFS.getLowpoint() > currDFS.getParentDfsIndex()) {
// The cluster thus far forms a strongly connected component. // The cluster thus far forms a strongly connected component.
// create a new switch cluster and the switches in the current // create a new switch cluster and the switches in the current
// set to the switch cluster. // set to the switch cluster.
SwitchCluster sc = new SwitchCluster(); SwitchCluster sc = new SwitchCluster();
Iterator<IOFSwitch> e = currSet.iterator(); for(IOFSwitch sw: currSet){
while (e.hasNext()) {
IOFSwitch sw = e.next();
sc.add(sw); sc.add(sw);
switchClusterMap.put(sw, sc); switchClusterMap.put(sw, sc);
} }
// delete all the nodes in the current set. // delete all the nodes in the current set.
currSet.clear(); currSet.clear();
// add the newly formed switch clusters to the cluster set. // add the newly formed switch clusters to the cluster set.
clusters.add(sc); clusters.add(sc);
} }
......
package net.floodlightcontroller.util; package net.floodlightcontroller.util;
public class ClusterDFS { public class ClusterDFS {
long dfsIndex; long dfsIndex;
long parentDfsIndex;
long lowpoint; long lowpoint;
boolean visited; boolean visited;
...@@ -19,6 +20,13 @@ public class ClusterDFS { ...@@ -19,6 +20,13 @@ public class ClusterDFS {
this.dfsIndex = dfsIndex; this.dfsIndex = dfsIndex;
} }
public long getParentDfsIndex() {
return parentDfsIndex;
}
public void setParentDfsIndex(long parentDfsIndex) {
this.parentDfsIndex = parentDfsIndex;
}
public long getLowpoint() { public long getLowpoint() {
return lowpoint; return lowpoint;
} }
...@@ -34,4 +42,6 @@ public class ClusterDFS { ...@@ -34,4 +42,6 @@ public class ClusterDFS {
public void setVisited(boolean visited) { public void setVisited(boolean visited) {
this.visited = visited; this.visited = visited;
} }
} }
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