From 5b48a7d92c24b1725f8acc2e9344f708894b7be3 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Tue, 30 Jul 2013 11:50:43 -0700 Subject: [PATCH 1/2] Reimplemented and corrected Graph as MultiGraph fixes #172 --- mininet/topo.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mininet/topo.py b/mininet/topo.py index 2619634..da21300 100644 --- a/mininet/topo.py +++ b/mininet/topo.py @@ -13,7 +13,7 @@ setup for testing, and can even be emulated with the Mininet package. from mininet.util import irange, natural, naturalSeq -class Graph( object ): +class MultiGraph( object ): "Utility class to track nodes and edges - replaces networkx.Graph" def __init__( self ): @@ -21,15 +21,14 @@ class Graph( object ): def add_node( self, node ): "Add node to graph" - if node not in self.data.keys(): - self.data[ node ] = [] + self.data.setdefault( node, [] ) def add_edge( self, src, dest ): "Add edge to graph" + src, dest = sorted( ( src, dest ) ) self.add_node( src ) self.add_node( dest ) self.data[ src ].append( dest ) - self.data[ dest ].append( src ) def nodes( self ): "Return list of graph nodes" @@ -54,7 +53,7 @@ class Topo(object): hinfo: default host options sopts: default switch options lopts: default link options""" - self.g = Graph() + self.g = MultiGraph() self.node_info = {} self.link_info = {} # (src, dst) tuples hash to EdgeInfo objects self.hopts = {} if hopts is None else hopts From 9c4b7343617765f418ad3b86590d849904a4dbc8 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Tue, 30 Jul 2013 11:52:53 -0700 Subject: [PATCH 2/2] Fix indentation in LinearTopo() --- mininet/topo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mininet/topo.py b/mininet/topo.py index da21300..ed3e260 100644 --- a/mininet/topo.py +++ b/mininet/topo.py @@ -255,9 +255,9 @@ class LinearTopo(Topo): switch = self.addSwitch('s%s' % i) # Add hosts to switch for j in irange(1, n): - hostNum = (i-1)*n + j - host = self.addHost('h%s' % hostNum) - self.addLink(host, switch) + hostNum = (i-1)*n + j + host = self.addHost('h%s' % hostNum) + self.addLink(host, switch) # Connect switch to previous if lastSwitch: self.addLink(switch, lastSwitch)