Skip to content

Commit

Permalink
Removed underscores for public Node methods. Minor cleanup & comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
lantz committed Mar 8, 2010
1 parent 2626693 commit 80be564
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 189 deletions.
14 changes: 7 additions & 7 deletions bin/mnclean
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
Mininet Cleanup
author: Bob Lantz (rlantz@cs.stanford.edu)
Unfortunately, Mininet and OpenFlow don't always clean up
properly after themselves. Until they do (or until cleanup
functionality is integrated into the python code), this
script may be used to get rid of unwanted garbage. It may
also get rid of 'false positives', but hopefully nothing
irreplaceable!
Unfortunately, Mininet and OpenFlow (and the Linux kernel)
don't always clean up properly after themselves. Until they do
(or until cleanup functionality is integrated into the Python
code), this script may be used to get rid of unwanted garbage.
It may also get rid of 'false positives', but hopefully
nothing irreplaceable!
"""

from subprocess import Popen, PIPE
Expand All @@ -28,7 +28,7 @@ def cleanup():
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
zombies += 'udpbwtest'
# Note: real zombie processes can't actually be killed, since they
# are already ( un )dead. Then again,
# are already (un)dead. Then again,
# you can't connect to them either, so they're mostly harmless.
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )

Expand Down
47 changes: 23 additions & 24 deletions examples/linearbandwidth.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/python

"""
Test bandwidth (using iperf) on linear networks of varying size,
Test bandwidth (using iperf) on linear networks of varying size,
using both kernel and user datapaths.
We construct a network of N hosts and N-1 switches, connected as follows:
h1 <-> sN+1 <-> sN+2 .. sN+N-1
| | |
h2 h3 hN
Note: by default, the reference controller only supports 16
switches, so this test WILL NOT WORK unless you have recompiled
your controller to support 100 switches (or more.)
Expand All @@ -25,36 +25,36 @@

import sys
flush = sys.stdout.flush

from mininet.net import init, Mininet
from mininet.node import Host, KernelSwitch, UserSwitch
from mininet.node import KernelSwitch, UserSwitch
from mininet.topo import Topo, Node
from mininet.log import lg

class LinearTestTopo( Topo ):
"Topology for a string of N hosts and N-1 switches."

def __init__( self, N ):

# Add default members to class.
super( LinearTestTopo, self ).__init__()

# Create switch and host nodes
hosts = range( 1, N+1 )
switches = range( N+1, N+N )
for id in hosts:
self._add_node( id, Node( is_switch=False ) )
for id in switches:
self._add_node( id, Node( is_switch=True ) )
hosts = range( 1, N + 1 )
switches = range( N + 1 , N + N )
for h in hosts:
self.add_node( h, Node( is_switch=False ) )
for s in switches:
self.add_node( s, Node( is_switch=True ) )

# Wire up switches
for s in switches[ :-1 ]:
self._add_edge( s, s + 1 )
self.add_edge( s, s + 1 )

# Wire up hosts
self._add_edge( hosts[ 0 ], switches[ 0 ] )
self.add_edge( hosts[ 0 ], switches[ 0 ] )
for h in hosts[ 1: ]:
self._add_edge( h, h+N-1 )
self.add_edge( h, h + N - 1 )

# Consider all switches and hosts 'on'
self.enable_all()
Expand All @@ -81,26 +81,25 @@ def linearBandwidthTest( lengths ):
src, dst = net.hosts[ 0 ], net.hosts[ n ]
print "testing", src.name, "<->", dst.name
bandwidth = net.iperf( [ src, dst ] )
print bandwidth ; flush()
print bandwidth
flush()
results[ datapath ] += [ ( n, bandwidth ) ]
net.stop()

for datapath in datapaths:
print
print "*** Linear network results for", datapath, "datapath:"
print
result = results[ datapath ]
result = results[ datapath ]
print "SwitchCount\tiperf Results"
for switchCount, bandwidth in result:
print switchCount, '\t\t',
print switchCount, '\t\t',
print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
print
print

if __name__ == '__main__':
lg.setLogLevel( 'info' )
init()
print "*** Running linearBandwidthTest"
linearBandwidthTest( [ 1, 10, 20 ] )


21 changes: 10 additions & 11 deletions examples/scratchnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
but it exposes the configuration details and allows customization.
"""

import logging

from mininet.net import init
from mininet.node import Node
from mininet.util import createLink
from mininet.log import lg, info

def scratchNet( cname='controller', cargs='ptcp:'):
def scratchNet( cname='controller', cargs='ptcp:' ):
"Create network from scratch using kernel switch."

info( "*** Creating nodes\n" )
controller = Node( 'c0', inNamespace=False )
switch = Node( 's0', inNamespace=False )
h0 = Node( 'h0' )
h1 = Node( 'h1' )

info( "*** Creating links\n" )
createLink( node1=h0, port1=0, node2=switch, port2=0 )
createLink( node1=h1, port1=0, node2=switch, port2=1 )
Expand All @@ -30,25 +29,25 @@ def scratchNet( cname='controller', cargs='ptcp:'):
h1.setIP( h1.intfs[ 0 ], '192.168.123.2', 24 )
info( str( h0 ) + '\n' )
info( str( h1 ) + '\n' )

info( "*** Starting network using kernel datapath\n" )
controller.cmd( cname + ' ' + cargs + '&' )
switch.cmd( 'dpctl deldp nl:0' )
switch.cmd( 'dpctl adddp nl:0' )
for intf in switch.intfs.values():
switch.cmd( 'dpctl addif nl:0 ' + intf )
switch.cmd( 'ofprotocol nl:0 tcp:localhost &')
switch.cmd( 'dpctl addif nl:0 ' + intf )
switch.cmd( 'ofprotocol nl:0 tcp:localhost &' )

info( "*** Running test\n" )
h0.cmdPrint( 'ping -c1 ' + h1.IP() )

info( "*** Stopping network\n" )
controller.cmd( 'kill %' + cname)
controller.cmd( 'kill %' + cname )
switch.cmd( 'dpctl deldp nl:0' )
switch.cmd( 'kill %ofprotocol' )
switch.deleteIntfs()
info( '\n' )

if __name__ == '__main__':
lg.setLogLevel( 'info' )
info( '*** Scratch network demo (kernel datapath)\n' )
Expand Down
15 changes: 8 additions & 7 deletions examples/scratchnetuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This is more complicated than using the higher-level classes,
but it exposes the configuration details and allows customization.
This version uses the user datapath.
This version uses the user datapath and an explicit control network.
"""

from mininet.net import init
Expand All @@ -14,7 +14,8 @@
from mininet.log import lg, info

def scratchNetUser( cname='controller', cargs='ptcp:' ):
# Create Network
"Create network from scratch using user switch."

# It's not strictly necessary for the controller and switches
# to be in separate namespaces. For performance, they probably
# should be in the root namespace. However, it's interesting to
Expand All @@ -32,15 +33,15 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ):
info( '*** Configuring control network\n' )
controller.setIP( controller.intfs[ 0 ], '10.0.123.1', 24 )
switch.setIP( switch.intfs[ 0 ], '10.0.123.2', 24 )

info( '*** Configuring hosts\n' )
h0.setIP( h0.intfs[ 0 ], '192.168.123.1', 24 )
h1.setIP( h1.intfs[ 0 ], '192.168.123.2', 24 )

info( '*** Network state:\n' )
for node in controller, switch, h0, h1:
info( str( node ) + '\n' )

info( '*** Starting controller and user datapath\n' )
controller.cmd( cname + ' ' + cargs + '&' )
switch.cmd( 'ifconfig lo 127.0.0.1' )
Expand All @@ -57,9 +58,9 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ):
switch.cmd( 'kill %ofprotocol' )
switch.deleteIntfs()
info( '\n' )

if __name__ == '__main__':
lg.setLogLevel( 'info' )
info( '*** Scratch network demo (user datapath)\n' )
init()
init()
scratchNetUser()
69 changes: 36 additions & 33 deletions examples/sshd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,48 @@ def TreeNet( depth=1, fanout=2, **kwargs ):
"Convenience function for creating tree networks."
topo = TreeTopo( depth, fanout )
return Mininet( topo, **kwargs )

def connectToRootNS( network, switch, ip, prefixLen, routes ):
"""Connect hosts to root namespace via switch. Starts network.
"""Connect hosts to root namespace via switch. Starts network.
network: Mininet() network object
switch: switch to connect to root namespace
ip: IP address for root namespace node
prefixLen: IP address prefix length (e.g. 8, 16, 24)
routes: host networks to route to"""
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
port = max( switch.ports.values() ) + 1
createLink( root, 0, switch, port )
root.setIP( root.intfs[ 0 ], ip, prefixLen )
# Start network that now includes link to root namespace
network.start()
intf = root.intfs[ 0 ]
# Add routes from root ns to hosts
for net in routes:
root.cmd( 'route add -net ' + net + ' dev ' + intf )
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
port = max( switch.ports.values() ) + 1
createLink( root, 0, switch, port )
root.setIP( root.intfs[ 0 ], ip, prefixLen )
# Start network that now includes link to root namespace
network.start()
intf = root.intfs[ 0 ]
# Add routes from root ns to hosts
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + intf )

def sshd( network, cmd='/usr/sbin/sshd', opts='-D' ):
"Start a network, connect it to root ns, and run sshd on all hosts."
switch = network.switches[ 0 ] # switch to use
ip = '10.123.123.1' # our IP address on host network
routes = [ '10.0.0.0/8' ] # host networks to route to
connectToRootNS( network, switch, ip, 8, routes )
for host in network.hosts: host.cmd( cmd + ' ' + opts + '&' )
print
print "*** Hosts are running sshd at the following addresses:"
print
for host in network.hosts: print host.name, host.IP()
print
print "*** Type 'exit' or control-D to shut down network"
CLI( network )
for host in network.hosts: host.cmd( 'kill %' + cmd )
network.stop()

"Start a network, connect it to root ns, and run sshd on all hosts."
switch = network.switches[ 0 ] # switch to use
ip = '10.123.123.1' # our IP address on host network
routes = [ '10.0.0.0/8' ] # host networks to route to
connectToRootNS( network, switch, ip, 8, routes )
for host in network.hosts:
host.cmd( cmd + ' ' + opts + '&' )
print
print "*** Hosts are running sshd at the following addresses:"
print
for host in network.hosts:
print host.name, host.IP()
print
print "*** Type 'exit' or control-D to shut down network"
CLI( network )
for host in network.hosts:
host.cmd( 'kill %' + cmd )
network.stop()

if __name__ == '__main__':
lg.setLogLevel( 'info')
init()
network = TreeNet( depth=1, fanout=4, switch=KernelSwitch )
sshd( network )
lg.setLogLevel( 'info')
init()
net = TreeNet( depth=1, fanout=4, switch=KernelSwitch )
sshd( net )
Loading

0 comments on commit 80be564

Please sign in to comment.