diff --git a/custom/topo-2sw-2host.py b/custom/topo-2sw-2host.py index b0fff06a4..ee5ec35f2 100644 --- a/custom/topo-2sw-2host.py +++ b/custom/topo-2sw-2host.py @@ -28,10 +28,10 @@ def __init__( self, enable_all = True ): rightHost = 4 # Add nodes - self.add_node( leftSwitch, Node( is_switch=True ) ) - self.add_node( rightSwitch, Node( is_switch=True ) ) - self.add_node( leftHost, Node( is_switch=False ) ) - self.add_node( rightHost, Node( is_switch=False ) ) + self.addNode( leftSwitch, Node( isSwitch=True ) ) + self.addNode( rightSwitch, Node( isSwitch=True ) ) + self.addNode( leftHost, Node( isSwitch=False ) ) + self.addNode( rightHost, Node( isSwitch=False ) ) # Add edges self.add_edge( leftHost, leftSwitch ) diff --git a/examples/linearbandwidth.py b/examples/linearbandwidth.py index 42b3eb94c..c3610455e 100755 --- a/examples/linearbandwidth.py +++ b/examples/linearbandwidth.py @@ -41,22 +41,22 @@ def __init__( self, N, **params ): Topo.__init__( self, **params ) # Create switches and hosts - hosts = [ self.add_host( 'h%s' % h ) + hosts = [ self.addHost( 'h%s' % h ) for h in irange( 1, N ) ] - switches = [ self.add_switch( 's%s' % s ) + switches = [ self.addSwitch( 's%s' % s ) for s in irange( 1, N - 1 ) ] # Wire up switches last = None for switch in switches: if last: - self.add_link( last, switch ) + self.addLink( last, switch ) last = switch # Wire up hosts - self.add_link( hosts[ 0 ], switches[ 0 ] ) + self.addLink( hosts[ 0 ], switches[ 0 ] ) for host, switch in zip( hosts[ 1: ], switches ): - self.add_link( host, switch ) + self.addLink( host, switch ) def linearBandwidthTest( lengths ): diff --git a/examples/simpleperf.py b/examples/simpleperf.py index 05cb2ae7f..76de0bd4e 100644 --- a/examples/simpleperf.py +++ b/examples/simpleperf.py @@ -15,13 +15,13 @@ class SingleSwitchTopo(Topo): "Single switch connected to n hosts." def __init__(self, n=2, **opts): Topo.__init__(self, **opts) - switch = self.add_switch('s1') + switch = self.addSwitch('s1') for h in range(n): # Each host gets 50%/n of system CPU - host = self.add_host('h%s' % (h + 1), + host = self.addHost('h%s' % (h + 1), cpu=.5 / n) # 10 Mbps, 5ms delay, 10% loss - self.add_link(host, switch, + self.addLink(host, switch, bw=10, delay='5ms', loss=10, use_htb=True) def perfTest(): diff --git a/mininet/topo.py b/mininet/topo.py index 86b5cf711..27df01360 100644 --- a/mininet/topo.py +++ b/mininet/topo.py @@ -34,7 +34,7 @@ def __init__(self, hopts=None, sopts=None, lopts=None): self.lopts = {} if lopts is None else lopts self.ports = {} # ports[src][dst] is port on src that connects to dst - def add_node(self, name, **opts): + def addNode(self, name, **opts): """Add Node to graph. name: name opts: node options @@ -43,26 +43,26 @@ def add_node(self, name, **opts): self.node_info[name] = opts return name - def add_host(self, name, **opts): + def addHost(self, name, **opts): """Convenience method: Add host to graph. name: host name opts: host options returns: host name""" if not opts and self.hopts: opts = self.hopts - return self.add_node(name, **opts) + return self.addNode(name, **opts) - def add_switch(self, name, **opts): + def addSwitch(self, name, **opts): """Convenience method: Add switch to graph. name: switch name opts: switch options returns: switch name""" if not opts and self.sopts: opts = self.sopts - result = self.add_node(name, is_switch=True, **opts) + result = self.addNode(name, isSwitch=True, **opts) return result - def add_link(self, node1, node2, port1=None, port2=None, + def addLink(self, node1, node2, port1=None, port2=None, **opts): """node1, node2: nodes to link together port1, port2: ports (optional) @@ -70,13 +70,13 @@ def add_link(self, node1, node2, port1=None, port2=None, returns: link info key""" if not opts and self.lopts: opts = self.lopts - self.add_port(node1, node2, port1, port2) + self.addPort(node1, node2, port1, port2) key = tuple(self.sorted([node1, node2])) self.link_info[key] = opts self.g.add_edge(*key) return key - def add_port(self, src, dst, sport=None, dport=None): + def addPort(self, src, dst, sport=None, dport=None): '''Generate port mapping for new edge. @param src source switch name @param dst destination switch name @@ -84,8 +84,8 @@ def add_port(self, src, dst, sport=None, dport=None): self.ports.setdefault(src, {}) self.ports.setdefault(dst, {}) # New port: number of outlinks + base - src_base = 1 if self.is_switch(src) else 0 - dst_base = 1 if self.is_switch(dst) else 0 + src_base = 1 if self.isSwitch(src) else 0 + dst_base = 1 if self.isSwitch(dst) else 0 if sport is None: sport = len(self.ports[src]) + src_base if dport is None: @@ -100,24 +100,24 @@ def nodes(self, sort=True): else: return self.g.nodes() - def is_switch(self, n): + def isSwitch(self, n): '''Returns true if node is a switch.''' info = self.node_info[n] - return info and info.get('is_switch', False) + return info and info.get('isSwitch', False) def switches(self, sort=True): '''Return switches. sort: sort switches alphabetically @return dpids list of dpids ''' - return [n for n in self.nodes(sort) if self.is_switch(n)] + return [n for n in self.nodes(sort) if self.isSwitch(n)] def hosts(self, sort=True): '''Return hosts. sort: sort hosts alphabetically @return dpids list of dpids ''' - return [n for n in self.nodes(sort) if not self.is_switch(n)] + return [n for n in self.nodes(sort) if not self.isSwitch(n)] def links(self, sort=True): '''Return links. @@ -180,10 +180,10 @@ def __init__(self, k=2, **opts): self.k = k - switch = self.add_switch('s1') + switch = self.addSwitch('s1') for h in irange(1, k): - host = self.add_host('h%s' % h) - self.add_link(host, switch) + host = self.addHost('h%s' % h) + self.addLink(host, switch) class SingleSwitchReversedTopo(Topo): @@ -201,10 +201,10 @@ def __init__(self, k=2, **opts): ''' super(SingleSwitchReversedTopo, self).__init__(**opts) self.k = k - switch = self.add_switch('s1') + switch = self.addSwitch('s1') for h in irange(1, k): - host = self.add_host('h%s' % h) - self.add_link(host, switch, + host = self.addHost('h%s' % h) + self.addLink(host, switch, port1=0, port2=(k - h + 1)) class LinearTopo(Topo): @@ -222,9 +222,9 @@ def __init__(self, k=2, **opts): lastSwitch = None for i in irange(1, k): - host = self.add_host('h%s' % i) - switch = self.add_switch('s%s' % i) - self.add_link( host, switch) + host = self.addHost('h%s' % i) + switch = self.addSwitch('s%s' % i) + self.addLink( host, switch) if lastSwitch: - self.add_link( switch, lastSwitch) + self.addLink( switch, lastSwitch) lastSwitch = switch diff --git a/mininet/topolib.py b/mininet/topolib.py index a8de9d8b6..63ba36deb 100644 --- a/mininet/topolib.py +++ b/mininet/topolib.py @@ -19,13 +19,13 @@ def addTree( self, depth, fanout ): returns: last node added""" isSwitch = depth > 0 if isSwitch: - node = self.add_switch( 's%s' % self.switchNum ) + node = self.addSwitch( 's%s' % self.switchNum ) self.switchNum += 1 for _ in range( fanout ): child = self.addTree( depth - 1, fanout ) - self.add_link( node, child ) + self.addLink( node, child ) else: - node = self.add_host( 'h%s' % self.hostNum ) + node = self.addHost( 'h%s' % self.hostNum ) self.hostNum += 1 return node