Cleanup of doc files.
Fixed xterm.py (and cleanup) to clean up screen sessions. Cleaned up sshd.py (though interface is still in flux.) Added 1024-node network example (treenet1024.py). Added example showing multiple tests on a single network (multitest.py). Renamed examples to make them easier to type!
This commit is contained in:
+34
-37
@@ -1,11 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""Create a network and start sshd(8) on the hosts.
|
||||
While something like rshd(8) would be lighter and faster,
|
||||
(and perfectly adequate on an in-machine network)
|
||||
the advantage of running sshd is that scripts can work
|
||||
unchanged on mininet and hardware."""
|
||||
"""
|
||||
Create a network and start sshd(8) on the hosts.
|
||||
|
||||
While something like rshd(8) would be lighter and faster,
|
||||
(and perfectly adequate on an in-machine network)
|
||||
the advantage of running sshd is that scripts can work
|
||||
unchanged on mininet and hardware.
|
||||
"""
|
||||
|
||||
import sys ; readline = sys.stdin.readline
|
||||
from mininet import init, Node, createLink, TreeNet, Cli
|
||||
|
||||
def nets( hosts ):
|
||||
@@ -17,42 +21,35 @@ def nets( hosts ):
|
||||
nets[ net ] = True
|
||||
return nets.keys()
|
||||
|
||||
def addRoutes( node, nets, intf ):
|
||||
"Add routes from node to nets through intf."
|
||||
for net in nets:
|
||||
node.cmdPrint( 'route add -net ' + net + ' dev ' + intf )
|
||||
|
||||
def removeRoutes( node, nets ):
|
||||
"Remove routes to nets from node."
|
||||
for net in nets:
|
||||
node.cmdPrint( 'route del -net ' + net )
|
||||
|
||||
def sshd( network ):
|
||||
"Start sshd up on each host, routing appropriately."
|
||||
controllers, switches, hosts = (
|
||||
network.controllers, network.switches, network.hosts )
|
||||
# Create a node in root ns and link to switch 0
|
||||
def connectToRootNS( network, switch ):
|
||||
"Connect hosts to root namespace via switch. Starts network."
|
||||
# Create a node in root namespace and link to switch 0
|
||||
root = Node( 'root', inNamespace=False )
|
||||
createLink( root, switches[ 0 ] )
|
||||
createLink( root, switch )
|
||||
ip = '10.0.123.1'
|
||||
root.setIP( root.intfs[ 0 ], ip, '/24' )
|
||||
# Start network that now includes link to root namespace
|
||||
network.start()
|
||||
# Add routes
|
||||
routes = nets( hosts )
|
||||
addRoutes( root, routes, root.intfs[ 0 ] )
|
||||
# Start up sshd on each host
|
||||
for host in hosts: host.cmdPrint( '/usr/sbin/sshd' )
|
||||
# Dump out IP addresses and run CLI
|
||||
print
|
||||
print "*** Hosts are running sshd at the following addresses:"
|
||||
for host in hosts: print host.name, host.IP()
|
||||
print
|
||||
print "*** Starting Mininet CLI - type 'exit' or ^D to exit"
|
||||
network.runTest( Cli )
|
||||
network.stop()
|
||||
removeRoutes( root, routes )
|
||||
|
||||
routes = nets( network.hosts )
|
||||
intf = root.intfs[ 0 ]
|
||||
for net in routes:
|
||||
root.cmdPrint( 'route add -net ' + net + ' dev ' + intf )
|
||||
|
||||
def startServers( network, server ):
|
||||
"Start network, and servers on each host."
|
||||
connectToRootNS( network, network.switches[ 0 ] )
|
||||
for host in network.hosts: host.cmdPrint( server )
|
||||
|
||||
if __name__ == '__main__':
|
||||
init()
|
||||
network = TreeNet( depth=1, fanout=2, kernel=True )
|
||||
sshd( network )
|
||||
network = TreeNet( depth=1, fanout=4, kernel=True )
|
||||
startServers( network, '/usr/sbin/sshd' )
|
||||
print
|
||||
print "*** Hosts are running sshd at the following addresses:"
|
||||
print
|
||||
for host in network.hosts: print host.name, host.IP()
|
||||
print
|
||||
print "*** Press return to shut down network: ",
|
||||
readline()
|
||||
network.stop()
|
||||
|
||||
Reference in New Issue
Block a user