Skip to content
Snippets Groups Projects
Commit d869d820 authored by Bob Lantz's avatar Bob Lantz
Browse files

Added support for pre- and post-test CLI scripts.

parent 54d026f6
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ import sys ...@@ -17,6 +17,7 @@ import sys
import time import time
from mininet.clean import cleanup from mininet.clean import cleanup
from mininet.cli import CLI
from mininet.log import lg, LEVELS, info from mininet.log import lg, LEVELS, info
from mininet.net import Mininet, init from mininet.net import Mininet, init
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
...@@ -50,9 +51,11 @@ CONTROLLERS = { 'ref': Controller, ...@@ -50,9 +51,11 @@ CONTROLLERS = { 'ref': Controller,
'none': lambda name: None } 'none': lambda name: None }
# optional tests to run # optional tests to run
TESTS = [ 'cli', 'build', 'pingAll', 'pingPair', 'iperf', 'all', 'iperfUdp', TESTS = [ 'cli', 'build', 'pingall', 'pingpair', 'iperf', 'all', 'iperfudp',
'none' ] 'none' ]
ALTSPELLING = { 'pingall': 'pingAll', 'pingpair': 'pingPair',
'iperfudp': 'iperfUdp', 'iperfUDP': 'iperfUdp' }
def buildTopo( topo ): def buildTopo( topo ):
"Create topology from string with format (object, arg1, arg2,...)." "Create topology from string with format (object, arg1, arg2,...)."
...@@ -99,6 +102,7 @@ class MininetRunner( object ): ...@@ -99,6 +102,7 @@ class MininetRunner( object ):
def __init__( self ): def __init__( self ):
"Init." "Init."
self.options = None self.options = None
self.args = None # May be used someday for more CLI scripts
self.validate = None self.validate = None
self.parseArgs() self.parseArgs()
...@@ -170,9 +174,14 @@ class MininetRunner( object ): ...@@ -170,9 +174,14 @@ class MininetRunner( object ):
opts.add_option( '--port', type='int', default=6633, opts.add_option( '--port', type='int', default=6633,
help='[port integer for a listening remote' help='[port integer for a listening remote'
' controller]' ) ' controller]' )
opts.add_option( '--inNamespace', action='store_true', opts.add_option( '--innamespace', action='store_true',
default=False, help='sw and ctrl in namespace?' ) default=False, help='sw and ctrl in namespace?' )
self.options = opts.parse_args()[ 0 ] opts.add_option( '--pre', type='string', default=None,
help='[CLI script to run before tests]' )
opts.add_option( '--post', type='string', default=None,
help='[CLI script to run after tests]' )
self.options, self.args = opts.parse_args()
def setup( self ): def setup( self ):
"Setup and validate environment." "Setup and validate environment."
...@@ -209,7 +218,7 @@ class MininetRunner( object ): ...@@ -209,7 +218,7 @@ class MininetRunner( object ):
self.validate( self.options ) self.validate( self.options )
controllerParams = ControllerParams( '10.0.0.0', 8 ) controllerParams = ControllerParams( '10.0.0.0', 8 )
inNamespace = self.options.inNamespace inNamespace = self.options.innamespace
xterms = self.options.xterms xterms = self.options.xterms
mac = self.options.mac mac = self.options.mac
arp = self.options.arp arp = self.options.arp
...@@ -217,20 +226,29 @@ class MininetRunner( object ): ...@@ -217,20 +226,29 @@ class MininetRunner( object ):
inNamespace=inNamespace, inNamespace=inNamespace,
xterms=xterms, autoSetMacs=mac, xterms=xterms, autoSetMacs=mac,
autoStaticArp=arp ) autoStaticArp=arp )
if self.options.pre:
CLI( mn, script=self.options.pre )
test = self.options.test test = self.options.test
test = ALTSPELLING.get( test, test )
mn.start()
if test == 'none': if test == 'none':
mn.start() pass
mn.stop()
elif test == 'cli':
mn.interact()
elif test == 'all': elif test == 'all':
mn.start() mn.start()
mn.ping() mn.ping()
mn.iperf() mn.iperf()
mn.stop() elif test == 'cli':
CLI( mn )
elif test != 'build': elif test != 'build':
mn.run( getattr( mn, test ) ) getattr( mn, test )()
if self.options.post:
CLI( mn, script=self.options.post )
mn.stop()
elapsed = float( time.time() - start ) elapsed = float( time.time() - start )
info( 'completed in %0.3f seconds\n' % elapsed ) info( 'completed in %0.3f seconds\n' % elapsed )
......
...@@ -40,7 +40,7 @@ class CLI( Cmd ): ...@@ -40,7 +40,7 @@ class CLI( Cmd ):
prompt = 'mininet> ' prompt = 'mininet> '
def __init__( self, mininet, stdin=sys.stdin ): def __init__( self, mininet, stdin=sys.stdin, script=None ):
self.mn = mininet self.mn = mininet
self.nodelist = self.mn.controllers + self.mn.switches + self.mn.hosts self.nodelist = self.mn.controllers + self.mn.switches + self.mn.hosts
self.nodemap = {} # map names to Node objects self.nodemap = {} # map names to Node objects
...@@ -50,9 +50,12 @@ def __init__( self, mininet, stdin=sys.stdin ): ...@@ -50,9 +50,12 @@ def __init__( self, mininet, stdin=sys.stdin ):
self.stdin = stdin self.stdin = stdin
self.inPoller = poll() self.inPoller = poll()
self.inPoller.register( stdin ) self.inPoller.register( stdin )
self.inputFile = None self.inputFile = script
Cmd.__init__( self ) Cmd.__init__( self )
info( '*** Starting CLI:\n' ) info( '*** Starting CLI:\n' )
if self.inputFile:
self.do_source( self.inputFile )
return
while True: while True:
try: try:
# Make sure no nodes are still waiting # Make sure no nodes are still waiting
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment