Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | onos.py: ONOS cluster and control network in Mininet |
| 5 | |
| 6 | With onos.py, you can use Mininet to create a complete |
| 7 | ONOS network, including an ONOS cluster with a modeled |
| 8 | control network as well as the usual data nework. |
| 9 | |
| 10 | This is intended to be useful for distributed ONOS |
| 11 | development and testing in the case that you require |
| 12 | a modeled control network. |
| 13 | |
| 14 | Invocation (using OVS as default switch): |
| 15 | |
| 16 | mn --custom onos.py --controller onos,3 --topo torus,4,4 |
| 17 | |
| 18 | Or with the user switch (or CPqD if installed): |
| 19 | |
| 20 | mn --custom onos.py --controller onos,3 \ |
| 21 | --switch onosuser --topo torus,4,4 |
| 22 | |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 23 | Currently you meed to use a custom switch class |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 24 | because Mininet's Switch() class does't (yet?) handle |
| 25 | controllers with multiple IP addresses directly. |
| 26 | |
| 27 | The classes may also be imported and used via Mininet's |
| 28 | python API. |
| 29 | |
| 30 | Bugs/Gripes: |
| 31 | - We need --switch onosuser for the user switch because |
| 32 | Switch() doesn't currently handle Controller objects |
| 33 | with multiple IP addresses. |
| 34 | - ONOS startup and configuration is painful/undocumented. |
| 35 | - Too many ONOS environment vars - do we need them all? |
| 36 | - ONOS cluster startup is very, very slow. If Linux can |
| 37 | boot in 4 seconds, why can't ONOS? |
| 38 | - It's a pain to mess with the control network from the |
| 39 | CLI |
| 40 | - Setting a default controller for Mininet should be easier |
| 41 | """ |
| 42 | |
| 43 | from mininet.node import Controller, OVSSwitch, UserSwitch |
| 44 | from mininet.nodelib import LinuxBridge |
| 45 | from mininet.net import Mininet |
| 46 | from mininet.topo import SingleSwitchTopo, Topo |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 47 | from mininet.log import setLogLevel, info, warn, error, debug |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 48 | from mininet.cli import CLI |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 49 | from mininet.util import quietRun, specialClass |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 50 | from mininet.examples.controlnet import MininetFacade |
| 51 | |
| 52 | from os import environ |
| 53 | from os.path import dirname, join, isfile |
| 54 | from sys import argv |
| 55 | from glob import glob |
| 56 | import time |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 57 | from functools import partial |
Bob Lantz | 92d8e05 | 2016-06-17 16:03:58 -0700 | [diff] [blame] | 58 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 59 | |
| 60 | ### ONOS Environment |
| 61 | |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 62 | KarafPort = 8101 # ssh port indicating karaf is running |
| 63 | GUIPort = 8181 # GUI/REST port |
| 64 | OpenFlowPort = 6653 # OpenFlow port |
Jon Hall | a43d033 | 2016-08-04 15:02:23 -0700 | [diff] [blame] | 65 | CopycatPort = 9876 # Copycat port |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 66 | |
| 67 | def defaultUser(): |
| 68 | "Return a reasonable default user" |
| 69 | if 'SUDO_USER' in environ: |
| 70 | return environ[ 'SUDO_USER' ] |
| 71 | try: |
| 72 | user = quietRun( 'who am i' ).split()[ 0 ] |
| 73 | except: |
| 74 | user = 'nobody' |
| 75 | return user |
| 76 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 77 | # Module vars, initialized below |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 78 | HOME = ONOS_ROOT = ONOS_USER = None |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 79 | ONOS_APPS = ONOS_WEB_USER = ONOS_WEB_PASS = ONOS_TAR = None |
| 80 | |
| 81 | def initONOSEnv(): |
| 82 | """Initialize ONOS environment (and module) variables |
| 83 | This is ugly and painful, but they have to be set correctly |
| 84 | in order for the onos-setup-karaf script to work. |
| 85 | nodes: list of ONOS nodes |
| 86 | returns: ONOS environment variable dict""" |
| 87 | # pylint: disable=global-statement |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 88 | global HOME, ONOS_ROOT, ONOS_USER |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 89 | global ONOS_APPS, ONOS_WEB_USER, ONOS_WEB_PASS |
| 90 | env = {} |
| 91 | def sd( var, val ): |
| 92 | "Set default value for environment variable" |
| 93 | env[ var ] = environ.setdefault( var, val ) |
| 94 | return env[ var ] |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 95 | assert environ[ 'HOME' ] |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 96 | HOME = sd( 'HOME', environ[ 'HOME' ] ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 97 | ONOS_ROOT = sd( 'ONOS_ROOT', join( HOME, 'onos' ) ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 98 | environ[ 'ONOS_USER' ] = defaultUser() |
| 99 | ONOS_USER = sd( 'ONOS_USER', defaultUser() ) |
| 100 | ONOS_APPS = sd( 'ONOS_APPS', |
| 101 | 'drivers,openflow,fwd,proxyarp,mobility' ) |
| 102 | # ONOS_WEB_{USER,PASS} isn't respected by onos-karaf: |
| 103 | environ.update( ONOS_WEB_USER='karaf', ONOS_WEB_PASS='karaf' ) |
| 104 | ONOS_WEB_USER = sd( 'ONOS_WEB_USER', 'karaf' ) |
| 105 | ONOS_WEB_PASS = sd( 'ONOS_WEB_PASS', 'karaf' ) |
| 106 | return env |
| 107 | |
| 108 | |
| 109 | def updateNodeIPs( env, nodes ): |
| 110 | "Update env dict and environ with node IPs" |
| 111 | # Get rid of stale junk |
| 112 | for var in 'ONOS_NIC', 'ONOS_CELL', 'ONOS_INSTANCES': |
| 113 | env[ var ] = '' |
| 114 | for var in environ.keys(): |
| 115 | if var.startswith( 'OC' ): |
| 116 | env[ var ] = '' |
| 117 | for index, node in enumerate( nodes, 1 ): |
| 118 | var = 'OC%d' % index |
| 119 | env[ var ] = node.IP() |
Jon Hall | 2548559 | 2016-08-19 13:56:14 -0700 | [diff] [blame] | 120 | if nodes: |
| 121 | env[ 'OCI' ] = env[ 'OCN' ] = env[ 'OC1' ] |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 122 | env[ 'ONOS_INSTANCES' ] = '\n'.join( |
| 123 | node.IP() for node in nodes ) |
| 124 | environ.update( env ) |
| 125 | return env |
| 126 | |
| 127 | |
| 128 | tarDefaultPath = 'buck-out/gen/tools/package/onos-package/onos.tar.gz' |
| 129 | |
Bob Lantz | 1451d72 | 2016-05-17 14:40:07 -0700 | [diff] [blame] | 130 | def unpackONOS( destDir='/tmp', run=quietRun ): |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 131 | "Unpack ONOS and return its location" |
| 132 | global ONOS_TAR |
| 133 | environ.setdefault( 'ONOS_TAR', join( ONOS_ROOT, tarDefaultPath ) ) |
| 134 | ONOS_TAR = environ[ 'ONOS_TAR' ] |
| 135 | tarPath = ONOS_TAR |
| 136 | if not isfile( tarPath ): |
| 137 | raise Exception( 'Missing ONOS tarball %s - run buck build onos?' |
| 138 | % tarPath ) |
| 139 | info( '(unpacking %s)' % destDir) |
Bob Lantz | a2ccaa5 | 2016-06-29 18:26:06 -0700 | [diff] [blame] | 140 | success = '*** SUCCESS ***' |
| 141 | cmds = ( 'mkdir -p "%s" && cd "%s" && tar xzf "%s" && echo "%s"' |
| 142 | % ( destDir, destDir, tarPath, success ) ) |
| 143 | result = run( cmds, shell=True, verbose=True ) |
| 144 | if success not in result: |
| 145 | raise Exception( 'Failed to unpack ONOS archive %s in %s:\n%s\n' % |
| 146 | ( tarPath, destDir, result ) ) |
Bob Lantz | 1451d72 | 2016-05-17 14:40:07 -0700 | [diff] [blame] | 147 | # We can use quietRun for this usually |
| 148 | tarOutput = quietRun( 'tar tzf "%s" | head -1' % tarPath, shell=True) |
| 149 | tarOutput = tarOutput.split()[ 0 ].strip() |
| 150 | assert '/' in tarOutput |
| 151 | onosDir = join( destDir, dirname( tarOutput ) ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 152 | # Add symlink to log file |
Bob Lantz | 1451d72 | 2016-05-17 14:40:07 -0700 | [diff] [blame] | 153 | run( 'cd %s; ln -s onos*/apache* karaf;' |
| 154 | 'ln -s karaf/data/log/karaf.log log' % destDir, |
| 155 | shell=True ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 156 | return onosDir |
| 157 | |
| 158 | |
Bob Lantz | 9ba19dc | 2016-06-13 20:22:07 -0700 | [diff] [blame] | 159 | def waitListening( server, port=80, callback=None, sleepSecs=.5, |
| 160 | proc='java' ): |
| 161 | "Simplified netstat version of waitListening" |
| 162 | while True: |
| 163 | lines = server.cmd( 'netstat -natp' ).strip().split( '\n' ) |
| 164 | entries = [ line.split() for line in lines ] |
| 165 | portstr = ':%s' % port |
| 166 | listening = [ entry for entry in entries |
| 167 | if len( entry ) > 6 and portstr in entry[ 3 ] |
| 168 | and proc in entry[ 6 ] ] |
| 169 | if listening: |
| 170 | break |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 171 | info( '.' ) |
| 172 | if callback: |
| 173 | callback() |
| 174 | time.sleep( sleepSecs ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 175 | |
| 176 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 177 | ### Mininet classes |
| 178 | |
| 179 | def RenamedTopo( topo, *args, **kwargs ): |
| 180 | """Return specialized topo with renamed hosts |
| 181 | topo: topo class/class name to specialize |
| 182 | args, kwargs: topo args |
| 183 | sold: old switch name prefix (default 's') |
| 184 | snew: new switch name prefix |
| 185 | hold: old host name prefix (default 'h') |
| 186 | hnew: new host name prefix |
| 187 | This may be used from the mn command, e.g. |
| 188 | mn --topo renamed,single,spref=sw,hpref=host""" |
| 189 | sold = kwargs.pop( 'sold', 's' ) |
| 190 | hold = kwargs.pop( 'hold', 'h' ) |
| 191 | snew = kwargs.pop( 'snew', 'cs' ) |
| 192 | hnew = kwargs.pop( 'hnew' ,'ch' ) |
| 193 | topos = {} # TODO: use global TOPOS dict |
| 194 | if isinstance( topo, str ): |
| 195 | # Look up in topo directory - this allows us to |
| 196 | # use RenamedTopo from the command line! |
| 197 | if topo in topos: |
| 198 | topo = topos.get( topo ) |
| 199 | else: |
| 200 | raise Exception( 'Unknown topo name: %s' % topo ) |
| 201 | # pylint: disable=no-init |
| 202 | class RenamedTopoCls( topo ): |
| 203 | "Topo subclass with renamed nodes" |
| 204 | def addNode( self, name, *args, **kwargs ): |
| 205 | "Add a node, renaming if necessary" |
| 206 | if name.startswith( sold ): |
| 207 | name = snew + name[ len( sold ): ] |
| 208 | elif name.startswith( hold ): |
| 209 | name = hnew + name[ len( hold ): ] |
| 210 | return topo.addNode( self, name, *args, **kwargs ) |
| 211 | return RenamedTopoCls( *args, **kwargs ) |
| 212 | |
| 213 | |
Bob Lantz | 8e57625 | 2016-08-29 14:05:59 -0700 | [diff] [blame] | 214 | # We accept objects that "claim" to be a particular class, |
| 215 | # since the class definitions can be both execed (--custom) and |
| 216 | # imported (in another custom file), which breaks isinstance(). |
| 217 | # In order for this to work properly, a class should not be |
| 218 | # renamed so as to inappropriately omit or include the class |
| 219 | # name text. Note that mininet.util.specialClass renames classes |
| 220 | # by adding the specialized parameter names and values. |
| 221 | |
| 222 | def isONOSNode( obj ): |
| 223 | "Does obj claim to be some kind of ONOSNode?" |
| 224 | return ( isinstance( obj, ONOSNode) or |
| 225 | 'ONOSNode' in type( obj ).__name__ ) |
| 226 | |
| 227 | def isONOSCluster( obj ): |
| 228 | "Does obj claim to be some kind of ONOSCluster?" |
| 229 | return ( isinstance( obj, ONOSCluster ) or |
| 230 | 'ONOSCluster' in type( obj ).__name__ ) |
| 231 | |
| 232 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 233 | class ONOSNode( Controller ): |
| 234 | "ONOS cluster node" |
| 235 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 236 | def __init__( self, name, **kwargs ): |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 237 | "alertAction: exception|ignore|warn|exit (exception)" |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 238 | kwargs.update( inNamespace=True ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 239 | self.alertAction = kwargs.pop( 'alertAction', 'exception' ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 240 | Controller.__init__( self, name, **kwargs ) |
| 241 | self.dir = '/tmp/%s' % self.name |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 242 | self.client = self.dir + '/karaf/bin/client' |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 243 | self.ONOS_HOME = '/tmp' |
Bob Lantz | 55562ea | 2016-06-17 18:19:03 -0700 | [diff] [blame] | 244 | self.cmd( 'rm -rf', self.dir ) |
| 245 | self.ONOS_HOME = unpackONOS( self.dir, run=self.ucmd ) |
Jon Hall | 2548559 | 2016-08-19 13:56:14 -0700 | [diff] [blame] | 246 | self.ONOS_ROOT = ONOS_ROOT |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 247 | |
| 248 | # pylint: disable=arguments-differ |
| 249 | |
Bob Lantz | 569bbec | 2016-06-03 18:51:16 -0700 | [diff] [blame] | 250 | def start( self, env, nodes=() ): |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 251 | """Start ONOS on node |
Bob Lantz | 569bbec | 2016-06-03 18:51:16 -0700 | [diff] [blame] | 252 | env: environment var dict |
| 253 | nodes: all nodes in cluster""" |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 254 | env = dict( env ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 255 | env.update( ONOS_HOME=self.ONOS_HOME ) |
| 256 | self.updateEnv( env ) |
| 257 | karafbin = glob( '%s/apache*/bin' % self.ONOS_HOME )[ 0 ] |
| 258 | onosbin = join( ONOS_ROOT, 'tools/test/bin' ) |
| 259 | self.cmd( 'export PATH=%s:%s:$PATH' % ( onosbin, karafbin ) ) |
| 260 | self.cmd( 'cd', self.ONOS_HOME ) |
Bob Lantz | 1451d72 | 2016-05-17 14:40:07 -0700 | [diff] [blame] | 261 | self.ucmd( 'mkdir -p config && ' |
Bob Lantz | 569bbec | 2016-06-03 18:51:16 -0700 | [diff] [blame] | 262 | 'onos-gen-partitions config/cluster.json', |
| 263 | ' '.join( node.IP() for node in nodes ) ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 264 | info( '(starting %s)' % self ) |
| 265 | service = join( self.ONOS_HOME, 'bin/onos-service' ) |
Bob Lantz | 1451d72 | 2016-05-17 14:40:07 -0700 | [diff] [blame] | 266 | self.ucmd( service, 'server 1>../onos.log 2>../onos.log' |
| 267 | ' & echo $! > onos.pid; ln -s `pwd`/onos.pid ..' ) |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 268 | self.onosPid = int( self.cmd( 'cat onos.pid' ).strip() ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 269 | self.warningCount = 0 |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 270 | |
| 271 | # pylint: enable=arguments-differ |
| 272 | |
Carmelo Cascone | c52a4b1 | 2016-10-24 16:47:17 +0200 | [diff] [blame] | 273 | def intfsDown( self ): |
| 274 | """Bring all interfaces down""" |
| 275 | for intf in self.intfs.values(): |
| 276 | cmdOutput = intf.ifconfig( 'down' ) |
| 277 | # no output indicates success |
| 278 | if cmdOutput: |
| 279 | error( "Error setting %s down: %s " % ( intf.name, cmdOutput ) ) |
| 280 | |
| 281 | def intfsUp( self ): |
| 282 | """Bring all interfaces up""" |
| 283 | for intf in self.intfs.values(): |
| 284 | cmdOutput = intf.ifconfig( 'up' ) |
| 285 | if cmdOutput: |
| 286 | error( "Error setting %s up: %s " % ( intf.name, cmdOutput ) ) |
| 287 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 288 | def stop( self ): |
| 289 | # XXX This will kill all karafs - too bad! |
| 290 | self.cmd( 'pkill -HUP -f karaf.jar && wait' ) |
| 291 | self.cmd( 'rm -rf', self.dir ) |
| 292 | |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 293 | def sanityAlert( self, *args ): |
| 294 | "Alert to raise on sanityCheck failure" |
| 295 | info( '\n' ) |
| 296 | if self.alertAction == 'exception': |
| 297 | raise Exception( *args ) |
| 298 | if self.alertAction == 'warn': |
| 299 | warn( *args + ( '\n', ) ) |
| 300 | elif self.alertAction == 'exit': |
| 301 | error( '***', *args + |
| 302 | ( '\nExiting. Run "sudo mn -c" to clean up.\n', ) ) |
| 303 | exit( 1 ) |
| 304 | |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 305 | def isRunning( self ): |
| 306 | "Is our ONOS process still running?" |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 307 | cmd = ( 'ps -p %d >/dev/null 2>&1 && echo "running" ||' |
| 308 | 'echo "not running"' ) |
| 309 | return self.cmd( cmd % self.onosPid ).strip() == 'running' |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 310 | |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 311 | def checkLog( self ): |
| 312 | "Return log file errors and warnings" |
| 313 | log = join( self.dir, 'log' ) |
Bob Lantz | c96e258 | 2016-06-13 18:57:04 -0700 | [diff] [blame] | 314 | errors, warnings = [], [] |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 315 | if isfile( log ): |
| 316 | lines = open( log ).read().split( '\n' ) |
| 317 | errors = [ line for line in lines if 'ERROR' in line ] |
| 318 | warnings = [ line for line in lines if 'WARN'in line ] |
| 319 | return errors, warnings |
| 320 | |
| 321 | def memAvailable( self ): |
| 322 | "Return available memory in KB (or -1 if we can't tell)" |
| 323 | lines = open( '/proc/meminfo' ).read().strip().split( '\n' ) |
| 324 | entries = map( str.split, lines ) |
| 325 | index = { entry[ 0 ]: entry for entry in entries } |
| 326 | # Check MemAvailable if present |
| 327 | default = ( None, '-1', 'kB' ) |
| 328 | _name, count, unit = index.get( 'MemAvailable:', default ) |
| 329 | if unit.lower() == 'kb': |
| 330 | return int( count ) |
| 331 | return -1 |
| 332 | |
| 333 | def sanityCheck( self, lowMem=100000 ): |
| 334 | """Check whether we've quit or are running out of memory |
| 335 | lowMem: low memory threshold in KB (100000)""" |
| 336 | # Are we still running? |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 337 | if not self.isRunning(): |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 338 | self.sanityAlert( 'ONOS node %s has died' % self.name ) |
| 339 | # Are there errors in the log file? |
| 340 | errors, warnings = self.checkLog() |
| 341 | if errors: |
| 342 | self.sanityAlert( 'ONOS startup errors:\n<<%s>>' % |
| 343 | '\n'.join( errors ) ) |
| 344 | warningCount = len( warnings ) |
| 345 | if warnings and warningCount > self.warningCount: |
| 346 | warn( '(%d warnings)' % len( warnings ) ) |
| 347 | self.warningCount = warningCount |
| 348 | # Are we running out of memory? |
| 349 | mem = self.memAvailable() |
| 350 | if mem > 0 and mem < lowMem: |
| 351 | self.sanityAlert( 'Running out of memory (only %d KB available)' |
| 352 | % mem ) |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 353 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 354 | def waitStarted( self ): |
| 355 | "Wait until we've really started" |
| 356 | info( '(checking: karaf' ) |
| 357 | while True: |
Bob Lantz | 1451d72 | 2016-05-17 14:40:07 -0700 | [diff] [blame] | 358 | status = self.ucmd( 'karaf status' ).lower() |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 359 | if 'running' in status and 'not running' not in status: |
| 360 | break |
| 361 | info( '.' ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 362 | self.sanityCheck() |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 363 | time.sleep( 1 ) |
| 364 | info( ' ssh-port' ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 365 | waitListening( server=self, port=KarafPort, callback=self.sanityCheck ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 366 | info( ' openflow-port' ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 367 | waitListening( server=self, port=OpenFlowPort, |
| 368 | callback=self.sanityCheck ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 369 | info( ' client' ) |
| 370 | while True: |
Bob Lantz | 9ba19dc | 2016-06-13 20:22:07 -0700 | [diff] [blame] | 371 | result = quietRun( '%s -h %s "apps -a"' % |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 372 | ( self.client, self.IP() ), shell=True ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 373 | if 'openflow' in result: |
| 374 | break |
| 375 | info( '.' ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 376 | self.sanityCheck() |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 377 | time.sleep( 1 ) |
Jon Hall | a43d033 | 2016-08-04 15:02:23 -0700 | [diff] [blame] | 378 | info( ' node-status' ) |
| 379 | while True: |
| 380 | result = quietRun( '%s -h %s "nodes"' % |
| 381 | ( self.client, self.IP() ), shell=True ) |
| 382 | nodeStr = 'id=%s, address=%s:%s, state=READY, updated' %\ |
| 383 | ( self.IP(), self.IP(), CopycatPort ) |
| 384 | if nodeStr in result: |
| 385 | break |
| 386 | info( '.' ) |
| 387 | self.sanityCheck() |
| 388 | time.sleep( 1 ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 389 | info( ')\n' ) |
| 390 | |
| 391 | def updateEnv( self, envDict ): |
| 392 | "Update environment variables" |
Bob Lantz | 569bbec | 2016-06-03 18:51:16 -0700 | [diff] [blame] | 393 | cmd = ';'.join( ( 'export %s="%s"' % ( var, val ) |
| 394 | if val else 'unset %s' % var ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 395 | for var, val in envDict.iteritems() ) |
| 396 | self.cmd( cmd ) |
| 397 | |
Bob Lantz | 1451d72 | 2016-05-17 14:40:07 -0700 | [diff] [blame] | 398 | def ucmd( self, *args, **_kwargs ): |
| 399 | "Run command as $ONOS_USER using sudo -E -u" |
| 400 | if ONOS_USER != 'root': # don't bother with sudo |
| 401 | args = [ "sudo -E -u $ONOS_USER PATH=$PATH " |
| 402 | "bash -c '%s'" % ' '.join( args ) ] |
| 403 | return self.cmd( *args ) |
| 404 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 405 | |
| 406 | class ONOSCluster( Controller ): |
| 407 | "ONOS Cluster" |
Bob Lantz | 5763516 | 2016-08-29 15:13:54 -0700 | [diff] [blame] | 408 | # Offset for port forwarding |
| 409 | portOffset = 0 |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 410 | def __init__( self, *args, **kwargs ): |
| 411 | """name: (first parameter) |
| 412 | *args: topology class parameters |
| 413 | ipBase: IP range for ONOS nodes |
Bob Lantz | 5763516 | 2016-08-29 15:13:54 -0700 | [diff] [blame] | 414 | forward: default port forwarding list |
| 415 | portOffset: offset to port base (optional) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 416 | topo: topology class or instance |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 417 | nodeOpts: ONOSNode options |
Bob Lantz | 5763516 | 2016-08-29 15:13:54 -0700 | [diff] [blame] | 418 | **kwargs: additional topology parameters |
| 419 | By default, multiple ONOSClusters will increment |
| 420 | the portOffset automatically; alternately, it can |
| 421 | be specified explicitly. |
| 422 | """ |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 423 | args = list( args ) |
| 424 | name = args.pop( 0 ) |
| 425 | topo = kwargs.pop( 'topo', None ) |
Bob Lantz | 930138e | 2016-06-23 18:53:19 -0700 | [diff] [blame] | 426 | self.nat = kwargs.pop( 'nat', 'nat0' ) |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 427 | nodeOpts = kwargs.pop( 'nodeOpts', {} ) |
Bob Lantz | 5763516 | 2016-08-29 15:13:54 -0700 | [diff] [blame] | 428 | self.portOffset = kwargs.pop( 'portOffset', ONOSCluster.portOffset ) |
Jon Hall | 9b238ae | 2016-08-09 13:47:43 -0700 | [diff] [blame] | 429 | # Pass in kwargs to the ONOSNodes instead of the cluster |
| 430 | "alertAction: exception|ignore|warn|exit (exception)" |
| 431 | alertAction = kwargs.pop( 'alertAction', None ) |
| 432 | if alertAction: |
| 433 | nodeOpts[ 'alertAction'] = alertAction |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 434 | # Default: single switch with 1 ONOS node |
| 435 | if not topo: |
| 436 | topo = SingleSwitchTopo |
| 437 | if not args: |
| 438 | args = ( 1, ) |
| 439 | if not isinstance( topo, Topo ): |
| 440 | topo = RenamedTopo( topo, *args, hnew='onos', **kwargs ) |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 441 | self.ipBase = kwargs.pop( 'ipBase', '192.168.123.0/24' ) |
| 442 | self.forward = kwargs.pop( 'forward', |
| 443 | [ KarafPort, GUIPort, OpenFlowPort ] ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 444 | super( ONOSCluster, self ).__init__( name, inNamespace=False ) |
| 445 | fixIPTables() |
| 446 | self.env = initONOSEnv() |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 447 | self.net = Mininet( topo=topo, ipBase=self.ipBase, |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 448 | host=partial( ONOSNode, **nodeOpts ), |
| 449 | switch=LinuxBridge, |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 450 | controller=None ) |
Bob Lantz | 930138e | 2016-06-23 18:53:19 -0700 | [diff] [blame] | 451 | if self.nat: |
| 452 | self.net.addNAT( self.nat ).configDefault() |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 453 | updateNodeIPs( self.env, self.nodes() ) |
| 454 | self._remoteControllers = [] |
Bob Lantz | 5763516 | 2016-08-29 15:13:54 -0700 | [diff] [blame] | 455 | # Update port offset for more ONOS clusters |
| 456 | ONOSCluster.portOffset += len( self.nodes() ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 457 | |
| 458 | def start( self ): |
| 459 | "Start up ONOS cluster" |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 460 | info( '*** ONOS_APPS = %s\n' % ONOS_APPS ) |
| 461 | self.net.start() |
| 462 | for node in self.nodes(): |
Bob Lantz | 569bbec | 2016-06-03 18:51:16 -0700 | [diff] [blame] | 463 | node.start( self.env, self.nodes() ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 464 | info( '\n' ) |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 465 | self.configPortForwarding( ports=self.forward, action='A' ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 466 | self.waitStarted() |
| 467 | return |
| 468 | |
| 469 | def waitStarted( self ): |
| 470 | "Wait until all nodes have started" |
| 471 | startTime = time.time() |
| 472 | for node in self.nodes(): |
| 473 | info( node ) |
| 474 | node.waitStarted() |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 475 | info( '*** Waited %.2f seconds for ONOS startup' % |
| 476 | ( time.time() - startTime ) ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 477 | |
| 478 | def stop( self ): |
| 479 | "Shut down ONOS cluster" |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 480 | self.configPortForwarding( ports=self.forward, action='D' ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 481 | for node in self.nodes(): |
| 482 | node.stop() |
| 483 | self.net.stop() |
| 484 | |
| 485 | def nodes( self ): |
| 486 | "Return list of ONOS nodes" |
Bob Lantz | 8e57625 | 2016-08-29 14:05:59 -0700 | [diff] [blame] | 487 | return [ h for h in self.net.hosts if isONOSNode( h ) ] |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 488 | |
Bob Lantz | 930138e | 2016-06-23 18:53:19 -0700 | [diff] [blame] | 489 | def configPortForwarding( self, ports=[], action='A' ): |
| 490 | """Start or stop port forwarding (any intf) for all nodes |
| 491 | ports: list of ports to forward |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 492 | action: A=add/start, D=delete/stop (default: A)""" |
Bob Lantz | 930138e | 2016-06-23 18:53:19 -0700 | [diff] [blame] | 493 | self.cmd( 'iptables -' + action, 'FORWARD -d', self.ipBase, |
| 494 | '-j ACCEPT' ) |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 495 | for port in ports: |
| 496 | for index, node in enumerate( self.nodes() ): |
Bob Lantz | 5763516 | 2016-08-29 15:13:54 -0700 | [diff] [blame] | 497 | ip, inport = node.IP(), port + self.portOffset + index |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 498 | # Configure a destination NAT rule |
Bob Lantz | 930138e | 2016-06-23 18:53:19 -0700 | [diff] [blame] | 499 | self.cmd( 'iptables -t nat -' + action, |
| 500 | 'PREROUTING -t nat -p tcp --dport', inport, |
| 501 | '-j DNAT --to-destination %s:%s' % ( ip, port ) ) |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 502 | |
Bob Lantz | 5763516 | 2016-08-29 15:13:54 -0700 | [diff] [blame] | 503 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 504 | class ONOSSwitchMixin( object ): |
| 505 | "Mixin for switches that connect to an ONOSCluster" |
| 506 | def start( self, controllers ): |
| 507 | "Connect to ONOSCluster" |
| 508 | self.controllers = controllers |
| 509 | assert ( len( controllers ) is 1 and |
Bob Lantz | 8e57625 | 2016-08-29 14:05:59 -0700 | [diff] [blame] | 510 | isONOSCluster( controllers[ 0 ] ) ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 511 | clist = controllers[ 0 ].nodes() |
| 512 | return super( ONOSSwitchMixin, self ).start( clist ) |
| 513 | |
| 514 | class ONOSOVSSwitch( ONOSSwitchMixin, OVSSwitch ): |
| 515 | "OVSSwitch that can connect to an ONOSCluster" |
| 516 | pass |
| 517 | |
| 518 | class ONOSUserSwitch( ONOSSwitchMixin, UserSwitch): |
| 519 | "UserSwitch that can connect to an ONOSCluster" |
| 520 | pass |
| 521 | |
| 522 | |
| 523 | ### Ugly utility routines |
| 524 | |
| 525 | def fixIPTables(): |
| 526 | "Fix LinuxBridge warning" |
| 527 | for s in 'arp', 'ip', 'ip6': |
| 528 | quietRun( 'sysctl net.bridge.bridge-nf-call-%stables=0' % s ) |
| 529 | |
| 530 | |
| 531 | ### Test code |
| 532 | |
| 533 | def test( serverCount ): |
| 534 | "Test this setup" |
| 535 | setLogLevel( 'info' ) |
| 536 | net = Mininet( topo=SingleSwitchTopo( 3 ), |
| 537 | controller=[ ONOSCluster( 'c0', serverCount ) ], |
| 538 | switch=ONOSOVSSwitch ) |
| 539 | net.start() |
| 540 | net.waitConnected() |
| 541 | CLI( net ) |
| 542 | net.stop() |
| 543 | |
| 544 | |
| 545 | ### CLI Extensions |
| 546 | |
| 547 | OldCLI = CLI |
| 548 | |
| 549 | class ONOSCLI( OldCLI ): |
| 550 | "CLI Extensions for ONOS" |
| 551 | |
| 552 | prompt = 'mininet-onos> ' |
| 553 | |
| 554 | def __init__( self, net, **kwargs ): |
Bob Lantz | 503a402 | 2016-08-29 18:08:37 -0700 | [diff] [blame] | 555 | clusters = [ c.net for c in net.controllers |
| 556 | if isONOSCluster( c ) ] |
| 557 | net = MininetFacade( net, *clusters ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 558 | OldCLI.__init__( self, net, **kwargs ) |
| 559 | |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 560 | def onos1( self ): |
| 561 | "Helper function: return default ONOS node" |
| 562 | return self.mn.controllers[ 0 ].net.hosts[ 0 ] |
| 563 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 564 | def do_onos( self, line ): |
| 565 | "Send command to ONOS CLI" |
| 566 | c0 = self.mn.controllers[ 0 ] |
Bob Lantz | 8e57625 | 2016-08-29 14:05:59 -0700 | [diff] [blame] | 567 | if isONOSCluster( c0 ): |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 568 | # cmdLoop strips off command name 'onos' |
| 569 | if line.startswith( ':' ): |
| 570 | line = 'onos' + line |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 571 | onos1 = self.onos1().name |
| 572 | if line: |
| 573 | line = '"%s"' % line |
| 574 | cmd = '%s client -h %s %s' % ( onos1, onos1, line ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 575 | quietRun( 'stty -echo' ) |
| 576 | self.default( cmd ) |
| 577 | quietRun( 'stty echo' ) |
| 578 | |
| 579 | def do_wait( self, line ): |
| 580 | "Wait for switches to connect" |
| 581 | self.mn.waitConnected() |
| 582 | |
| 583 | def do_balance( self, line ): |
| 584 | "Balance switch mastership" |
| 585 | self.do_onos( ':balance-masters' ) |
| 586 | |
| 587 | def do_log( self, line ): |
Bob Lantz | 4b51d5c | 2016-05-27 14:47:38 -0700 | [diff] [blame] | 588 | "Run tail -f /tmp/onos1/log; press control-C to stop" |
Bob Lantz | 9ba19dc | 2016-06-13 20:22:07 -0700 | [diff] [blame] | 589 | self.default( '%s tail -f /tmp/%s/log' % |
| 590 | ( self.onos1(), self.onos1() ) ) |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 591 | |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 592 | def do_status( self, line ): |
| 593 | "Return status of ONOS cluster(s)" |
| 594 | for c in self.mn.controllers: |
Bob Lantz | 8e57625 | 2016-08-29 14:05:59 -0700 | [diff] [blame] | 595 | if isONOSCluster( c ): |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 596 | for node in c.net.hosts: |
Bob Lantz | 8e57625 | 2016-08-29 14:05:59 -0700 | [diff] [blame] | 597 | if isONOSNode( node ): |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 598 | errors, warnings = node.checkLog() |
| 599 | running = ( 'Running' if node.isRunning() |
| 600 | else 'Exited' ) |
| 601 | status = '' |
| 602 | if errors: |
| 603 | status += '%d ERRORS ' % len( errors ) |
| 604 | if warnings: |
| 605 | status += '%d warnings' % len( warnings ) |
| 606 | status = status if status else 'OK' |
| 607 | info( node, '\t', running, '\t', status, '\n' ) |
| 608 | |
Bob Lantz | c96e258 | 2016-06-13 18:57:04 -0700 | [diff] [blame] | 609 | def do_arp( self, line ): |
| 610 | "Send gratuitous arps from all data network hosts" |
| 611 | startTime = time.time() |
| 612 | try: |
| 613 | count = int( line ) |
| 614 | except: |
| 615 | count = 1 |
| 616 | # Technically this check should be on the host |
Bob Lantz | c3de515 | 2016-06-17 17:13:57 -0700 | [diff] [blame] | 617 | if '-U' not in quietRun( 'arping -h', shell=True ): |
| 618 | warn( 'Please install iputils-arping.\n' ) |
Bob Lantz | c96e258 | 2016-06-13 18:57:04 -0700 | [diff] [blame] | 619 | return |
| 620 | # This is much faster if we do it in parallel |
| 621 | for host in self.mn.net.hosts: |
| 622 | intf = host.defaultIntf() |
| 623 | # -b: keep using broadcasts; -f: quit after 1 reply |
| 624 | # -U: gratuitous ARP update |
| 625 | host.sendCmd( 'arping -bf -c', count, '-U -I', |
| 626 | intf.name, intf.IP() ) |
| 627 | for host in self.mn.net.hosts: |
| 628 | # We could check the output here if desired |
| 629 | host.waitOutput() |
| 630 | info( '.' ) |
| 631 | info( '\n' ) |
| 632 | elapsed = time.time() - startTime |
| 633 | debug( 'Completed in %.2f seconds\n' % elapsed ) |
| 634 | |
Carmelo Cascone | c52a4b1 | 2016-10-24 16:47:17 +0200 | [diff] [blame] | 635 | def onosupdown( self, cmd, instance ): |
| 636 | if not instance: |
| 637 | info( 'Provide the name of an ONOS instance.\n' ) |
| 638 | return |
| 639 | c0 = self.mn.controllers[ 0 ] |
| 640 | if isONOSCluster( c0 ): |
| 641 | try: |
| 642 | onos = self.mn.controllers[ 0 ].net.getNodeByName( instance ) |
| 643 | if isONOSNode( onos ): |
| 644 | info('Bringing %s %s...\n' % ( instance, cmd ) ) |
| 645 | if cmd == 'up': |
| 646 | onos.intfsUp() |
| 647 | else: |
| 648 | onos.intfsDown() |
| 649 | except KeyError: |
| 650 | info( 'No such ONOS instance %s.\n' % instance ) |
| 651 | |
| 652 | def do_onosdown( self, instance=None ): |
| 653 | """Disconnects an ONOS instance from the network""" |
| 654 | self.onosupdown( 'down', instance ) |
| 655 | |
| 656 | def do_onosup( self, instance=None ): |
| 657 | """"Connects an ONOS instance to the network""" |
| 658 | self.onosupdown( 'up', instance ) |
| 659 | |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 660 | |
| 661 | # For interactive use, exit on error |
| 662 | exitOnError = dict( nodeOpts={ 'alertAction': 'exit' } ) |
| 663 | ONOSClusterInteractive = specialClass( ONOSCluster, defaults=exitOnError ) |
| 664 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 665 | |
| 666 | ### Exports for bin/mn |
| 667 | |
| 668 | CLI = ONOSCLI |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 669 | controllers = { 'onos': ONOSClusterInteractive, |
| 670 | 'default': ONOSClusterInteractive } |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 671 | |
| 672 | # XXX Hack to change default controller as above doesn't work |
Bob Lantz | 6438242 | 2016-06-03 22:51:39 -0700 | [diff] [blame] | 673 | findController = lambda: controllers[ 'default' ] |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 674 | |
| 675 | switches = { 'onos': ONOSOVSSwitch, |
| 676 | 'onosovs': ONOSOVSSwitch, |
| 677 | 'onosuser': ONOSUserSwitch, |
| 678 | 'default': ONOSOVSSwitch } |
| 679 | |
Bob Lantz | bb37d87 | 2016-05-16 16:26:13 -0700 | [diff] [blame] | 680 | # Null topology so we can control an external/hardware network |
| 681 | topos = { 'none': Topo } |
| 682 | |
Bob Lantz | 087b5d9 | 2016-05-06 11:39:04 -0700 | [diff] [blame] | 683 | if __name__ == '__main__': |
| 684 | if len( argv ) != 2: |
| 685 | test( 3 ) |
| 686 | else: |
| 687 | test( int( argv[ 1 ] ) ) |