Restored scratchnet and scratchnetuser demos.

Also changed the str format for nodes to use str() rather
than repr() so we don't end up with extraneous quotes.
This commit is contained in:
Bob Lantz
2010-03-03 14:37:14 -08:00
parent efc9a01cf1
commit dc630c540a
3 changed files with 80 additions and 64 deletions
+49 -33
View File
@@ -8,40 +8,56 @@ but it exposes the configuration details and allows customization.
This version uses the user datapath.
"""
from mininet.mininet import init, Node, createLink
from mininet.net import init
from mininet.node import Node
from mininet.util import createLink
from mininet.log import lg, info
def scratchNetUser( cname='controller', cargs='ptcp:'):
# Create Network
# 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
# see how they could work even if they are in separate namespaces.
controller = Node( 'c0' )
switch = Node( 's0')
h0 = Node( 'h0' )
h1 = Node( 'h1' )
createLink( controller, switch )
createLink( h0, switch )
createLink( h1, switch )
# Configure control network
controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' )
switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' )
# Configure hosts
h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
# Start network using user datapath
controller.cmdPrint( cname + ' ' + cargs + '&' )
switch.cmdPrint( 'ifconfig lo 127.0.0.1' )
switch.cmdPrint( 'ofdatapath -i ' + ','.join( switch.intfs[ 1: ])
+ ' ptcp: &' )
switch.cmdPrint( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
# Run test
h0.cmdPrint( 'ping -c1 ' + h1.IP() )
# Stop network
controller.cmdPrint( 'kill %' + cname)
switch.cmdPrint( 'kill %ofdatapath' )
switch.cmdPrint( 'kill %ofprotocol' )
# Create Network
# 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
# see how they could work even if they are in separate namespaces.
info( '*** Creating Network\n' )
controller = Node( 'c0' )
switch = Node( 's0')
h0 = Node( 'h0' )
h1 = Node( 'h1' )
createLink( controller, 0, switch, 0 )
createLink( h0, 0, switch, 1 )
createLink( h1, 0, switch, 2 )
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' )
intfs = [ switch.intfs[ port ] for port in (1, 2) ]
switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
info( '*** Running test\n' )
h0.cmdPrint( 'ping -c1 ' + h1.IP() )
info( '*** Stopping network\n' )
controller.cmd( 'kill %' + cname )
switch.cmd( 'kill %ofdatapath' )
switch.cmd( 'kill %ofprotocol' )
if __name__ == '__main__':
init()
scratchNetUser()
info( '*** Scratch network demo (user datapath)\n' )
init()
lg.setLogLevel( 'info' )
scratchNetUser()