Skip to content

Commit

Permalink
rename Topo() methods for consistency: add_node() -> addNode()
Browse files Browse the repository at this point in the history
  • Loading branch information
lantz committed Aug 17, 2012
1 parent 01e0758 commit ce15c4f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions custom/topo-2sw-2host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
10 changes: 5 additions & 5 deletions examples/linearbandwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ):
Expand Down
6 changes: 3 additions & 3 deletions examples/simpleperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
48 changes: 24 additions & 24 deletions mininet/topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,49 +43,49 @@ 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)
opts: link options (optional)
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
'''
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:
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
6 changes: 3 additions & 3 deletions mininet/topolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ce15c4f

Please sign in to comment.