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
+27 -27
View File
@@ -11,44 +11,44 @@ import logging
from mininet.net import init from mininet.net import init
from mininet.node import Node from mininet.node import Node
from mininet.util import createLink from mininet.util import createLink
from mininet.log import info from mininet.log import lg, info
# print out info() messages, including cmdPrint
logging.LOGLEVELDEFAULT = logging.INFO
def scratchNet( cname='controller', cargs='ptcp:'): def scratchNet( cname='controller', cargs='ptcp:'):
# Create Network
print "*** creating Nodes" info( "*** Creating nodes\n" )
controller = Node( 'c0', inNamespace=False ) controller = Node( 'c0', inNamespace=False )
switch = Node( 's0', inNamespace=False ) switch = Node( 's0', inNamespace=False )
h0 = Node( 'h0' ) h0 = Node( 'h0' )
h1 = Node( 'h1' ) h1 = Node( 'h1' )
print "*** creating links"
info( "*** Creating links\n" )
createLink( node1=h0, port1=0, node2=switch, port2=0 ) createLink( node1=h0, port1=0, node2=switch, port2=0 )
createLink( node1=h1, port1=0, node2=switch, port2=1 ) createLink( node1=h1, port1=0, node2=switch, port2=1 )
# Configure hosts
print "*** configuring hosts" info( "*** Configuring hosts\n" )
h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' ) h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' ) h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
print h0 info( str( h0 ) + '\n' )
print h1 info( str( h1 ) + '\n' )
# Start network using kernel datapath
controller.cmdPrint( cname + ' ' + cargs + '&' ) info( "*** Starting network using kernel datapath\n" )
switch.cmdPrint( 'dpctl deldp nl:0' ) controller.cmd( cname + ' ' + cargs + '&' )
switch.cmdPrint( 'dpctl adddp nl:0' ) switch.cmd( 'dpctl deldp nl:0' )
switch.cmd( 'dpctl adddp nl:0' )
for intf in switch.intfs.values(): for intf in switch.intfs.values():
switch.cmdPrint( 'dpctl addif nl:0 ' + intf ) switch.cmd( 'dpctl addif nl:0 ' + intf )
switch.cmdPrint( 'ofprotocol nl:0 tcp:localhost &') switch.cmd( 'ofprotocol nl:0 tcp:localhost &')
# Run test
print h0.cmd( 'ping -c1 ' + h1.IP() ) info( "*** Running test\n" )
# Stop network h0.cmdPrint( 'ping -c1 ' + h1.IP() )
controller.cmdPrint( 'kill %' + cname)
switch.cmdPrint( 'dpctl deldp nl:0' ) info( "*** Stopping network\n" )
switch.cmdPrint( 'kill %ofprotocol' ) controller.cmd( 'kill %' + cname)
switch.stop() switch.cmd( 'dpctl deldp nl:0' )
controller.stop() switch.cmd( 'kill %ofprotocol' )
if __name__ == '__main__': if __name__ == '__main__':
info( '*** Scratch network demo\n' ) info( '*** Scratch network demo (kernel datapath)\n' )
init() init()
lg.setLogLevel( 'info' )
scratchNet() scratchNet()
+49 -33
View File
@@ -8,40 +8,56 @@ but it exposes the configuration details and allows customization.
This version uses the user datapath. 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:'): def scratchNetUser( cname='controller', cargs='ptcp:'):
# Create Network # Create Network
# It's not strictly necessary for the controller and switches # It's not strictly necessary for the controller and switches
# to be in separate namespaces. For performance, they probably # to be in separate namespaces. For performance, they probably
# should be in the root namespace. However, it's interesting to # should be in the root namespace. However, it's interesting to
# see how they could work even if they are in separate namespaces. # see how they could work even if they are in separate namespaces.
controller = Node( 'c0' )
switch = Node( 's0') info( '*** Creating Network\n' )
h0 = Node( 'h0' ) controller = Node( 'c0' )
h1 = Node( 'h1' ) switch = Node( 's0')
createLink( controller, switch ) h0 = Node( 'h0' )
createLink( h0, switch ) h1 = Node( 'h1' )
createLink( h1, switch ) createLink( controller, 0, switch, 0 )
# Configure control network createLink( h0, 0, switch, 1 )
controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' ) createLink( h1, 0, switch, 2 )
switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' )
# Configure hosts info( '*** Configuring control network\n' )
h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' ) controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' )
h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' ) switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' )
# Start network using user datapath
controller.cmdPrint( cname + ' ' + cargs + '&' ) info( '*** Configuring hosts\n' )
switch.cmdPrint( 'ifconfig lo 127.0.0.1' ) h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
switch.cmdPrint( 'ofdatapath -i ' + ','.join( switch.intfs[ 1: ]) h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
+ ' ptcp: &' )
switch.cmdPrint( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' ) info( '*** Network state:\n' )
# Run test for node in controller, switch, h0, h1:
h0.cmdPrint( 'ping -c1 ' + h1.IP() ) info( str( node ) + '\n' )
# Stop network
controller.cmdPrint( 'kill %' + cname) info( '*** Starting controller and user datapath\n' )
switch.cmdPrint( 'kill %ofdatapath' ) controller.cmd( cname + ' ' + cargs + '&' )
switch.cmdPrint( 'kill %ofprotocol' ) 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__': if __name__ == '__main__':
init() info( '*** Scratch network demo (user datapath)\n' )
scratchNetUser() init()
lg.setLogLevel( 'info' )
scratchNetUser()
+4 -4
View File
@@ -54,7 +54,7 @@ class Node( object ):
def __init__( self, name, inNamespace=True ): def __init__( self, name, inNamespace=True ):
self.name = name self.name = name
closeFds = False # speed vs. memory use closeFds = False # speed vs. memory use
# xpgEcho is needed so we can echo our sentinel in sendCmd # xpg_echo is needed so we can echo our sentinel in sendCmd
cmd = [ '/bin/bash', '-O', 'xpg_echo' ] cmd = [ '/bin/bash', '-O', 'xpg_echo' ]
self.inNamespace = inNamespace self.inNamespace = inNamespace
if self.inNamespace: if self.inNamespace:
@@ -170,7 +170,7 @@ class Node( object ):
"""Send a command, wait for output, and return it. """Send a command, wait for output, and return it.
cmd: string""" cmd: string"""
log = info if verbose else debug log = info if verbose else debug
log( '*** %s : %s', self.name, cmd ) log( '*** %s : %s\n' % ( self.name, cmd ) )
self.sendCmd( cmd ) self.sendCmd( cmd )
return self.waitOutput( verbose ) return self.waitOutput( verbose )
@@ -261,9 +261,9 @@ class Node( object ):
# Other methods # Other methods
def __str__( self ): def __str__( self ):
result = self.name + ':' result = self.name + ':'
result += ' IP=' + repr( self.IP() ) result += ' IP=' + str( self.IP() )
result += ' intfs=' + ','.join( sorted( self.intfs.values() ) ) result += ' intfs=' + ','.join( sorted( self.intfs.values() ) )
result += ' waiting=' + repr( self.waiting ) result += ' waiting=' + str( self.waiting )
return result return result