Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 4 | onos.py: A basic (?) ONOS Controller() subclass for Mininet |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 5 | |
| 6 | We implement the following classes: |
| 7 | |
| 8 | ONOSController: a custom Controller() subclass to start ONOS |
| 9 | OVSSwitchONOS: a custom OVSSwitch() switch that connects to multiple controllers. |
| 10 | |
| 11 | We use single Zookeeper and Cassandra instances for now. |
| 12 | |
| 13 | As a custom file, exports: |
| 14 | |
| 15 | --controller onos |
| 16 | --switch ovso |
| 17 | |
| 18 | Usage: |
| 19 | |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 20 | $ sudo -E ./onos.py |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 21 | |
| 22 | This will start up a simple 2-host, 2 ONOS network |
| 23 | |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 24 | $ sudo -E mn --custom onos.py --controller onos,2 --switch ovso |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 25 | """ |
| 26 | |
| 27 | from mininet.node import Controller, OVSSwitch |
| 28 | from mininet.net import Mininet |
| 29 | from mininet.cli import CLI |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 30 | from mininet.topo import LinearTopo |
| 31 | from mininet.log import setLogLevel, info, warn |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 32 | from mininet.util import quietRun |
| 33 | |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 34 | # This should be cleaned up to avoid interfering with mn |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 35 | from shutil import copyfile |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 36 | from os import environ, path |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 37 | from functools import partial |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 38 | import time |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 39 | from sys import argv |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 40 | |
| 41 | class ONOS( Controller ): |
| 42 | "Custom controller class for ONOS" |
| 43 | |
| 44 | # Directories and configuration templates |
| 45 | home = environ[ 'HOME' ] |
| 46 | onosDir = home + "/ONOS" |
| 47 | zookeeperDir = home + "/zookeeper-3.4.5" |
| 48 | dirBase = '/tmp' |
| 49 | logDir = dirBase + '/onos-%s.logs' |
Bob Lantz | 4ed6cff | 2013-12-17 21:43:36 -0800 | [diff] [blame] | 50 | # cassDir = dirBase + '/onos-%s.cassandra' |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 51 | configFile = dirBase + '/onos-%s.properties' |
Bob Lantz | 4ed6cff | 2013-12-17 21:43:36 -0800 | [diff] [blame] | 52 | logbackFile = dirBase + '/onos-%s.logback.xml' |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 53 | |
| 54 | # Base ONOS modules |
| 55 | baseModules = ( |
| 56 | 'net.floodlightcontroller.core.FloodlightProvider', |
| 57 | 'net.floodlightcontroller.threadpool.ThreadPool', |
| 58 | 'net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher', |
| 59 | 'net.floodlightcontroller.ui.web.StaticWebRoutable', |
| 60 | 'net.onrc.onos.datagrid.HazelcastDatagrid', |
| 61 | 'net.onrc.onos.ofcontroller.flowmanager.FlowManager', |
| 62 | 'net.onrc.onos.ofcontroller.flowprogrammer.FlowProgrammer', |
| 63 | 'net.onrc.onos.ofcontroller.topology.TopologyManager', |
| 64 | 'net.onrc.onos.registry.controller.ZookeeperRegistry' |
| 65 | ) |
| 66 | |
| 67 | # Additions for reactive forwarding |
| 68 | reactiveModules = ( |
| 69 | 'net.onrc.onos.ofcontroller.proxyarp.ProxyArpManager', |
| 70 | 'net.onrc.onos.ofcontroller.core.config.DefaultConfiguration', |
| 71 | 'net.onrc.onos.ofcontroller.forwarding.Forwarding' |
| 72 | ) |
| 73 | |
| 74 | # Module parameters |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 75 | ofbase = 6633 |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 76 | restbase = 8080 |
| 77 | jmxbase = 7189 |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 78 | |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 79 | fc = 'net.floodlightcontroller.' |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 80 | |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 81 | # Things that vary per ONOS id |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 82 | perNodeConfigBase = { |
| 83 | fc + 'core.FloodlightProvider.openflowport': ofbase, |
| 84 | fc + 'restserver.RestApiServer.port': restbase, |
| 85 | fc + 'core.FloodlightProvider.controllerid': 0 |
| 86 | } |
| 87 | |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 88 | # Things that are static |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 89 | staticConfig = { |
| 90 | 'net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher.dbconf': |
| 91 | '/tmp/cassandra.titan', |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 92 | 'net.floodlightcontroller.core.FloodlightProvider.workerthreads': 16, |
| 93 | 'net.floodlightcontroller.forwarding.Forwarding.idletimeout': 5, |
| 94 | 'net.floodlightcontroller.forwarding.Forwarding.hardtimeout': 0 |
| 95 | } |
| 96 | |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 97 | # Things that are based on onosDir |
| 98 | dirConfig = { |
| 99 | 'net.onrc.onos.datagrid.HazelcastDatagrid.datagridConfig': |
| 100 | '%s/conf/hazelcast.xml', |
| 101 | } |
| 102 | |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 103 | proctag = 'mn-onos-id' |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 104 | |
Bob Lantz | 7a4d610 | 2013-12-17 00:34:55 -0800 | [diff] [blame] | 105 | # For maven debugging |
| 106 | # mvn = 'mvn -o -e -X' |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 107 | |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 108 | def __init__( self, name, n=1, reactive=True, runAsRoot=False, **params): |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 109 | """n: number of ONOS instances to run (1) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 110 | reactive: run in reactive mode (True) |
| 111 | runAsRoot: run ONOS as root (False)""" |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 112 | self.check() |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 113 | self.count = n |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 114 | self.reactive = reactive |
| 115 | self.runAsRoot = runAsRoot |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 116 | self.ids = range( 0, self.count ) |
| 117 | Controller.__init__( self, name, **params ) |
| 118 | # We don't need to run as root, and it can interfere |
| 119 | # with starting Zookeeper manually |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 120 | self.user = None |
| 121 | if not self.runAsRoot: |
| 122 | try: |
| 123 | self.user = quietRun( 'who am i' ).split()[ 0 ] |
| 124 | self.sendCmd( 'su', self.user ) |
| 125 | self.waiting = False |
| 126 | except: |
| 127 | warn( '__init__: failed to drop privileges\n' ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 128 | # Need to run commands from ONOS dir |
| 129 | self.cmd( 'cd', self.onosDir ) |
| 130 | self.cmd( 'export PATH=$PATH:%s' % self.onosDir ) |
Bob Lantz | 7a4d610 | 2013-12-17 00:34:55 -0800 | [diff] [blame] | 131 | if hasattr( self, 'mvn' ): |
| 132 | self.cmd( 'export MVN="%s"' % self.mvn ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 133 | |
| 134 | def check( self ): |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 135 | "Set onosDir and check for ONOS prerequisites" |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 136 | if not quietRun( 'which java' ): |
| 137 | raise Exception( 'java not found -' |
| 138 | ' make sure it is installed and in $PATH' ) |
| 139 | if not quietRun( 'which mvn' ): |
| 140 | raise Exception( 'Maven (mvn) not found -' |
| 141 | ' make sure it is installed and in $PATH' ) |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 142 | if 'ONOS_HOME' in environ: |
| 143 | self.onosDir = environ[ 'ONOS_HOME' ] |
| 144 | else: |
| 145 | warn( '* $ONOS_HOME is not set - assuming %s\n' % self.onosDir ) |
| 146 | for script in 'start-zk.sh', 'start-cassandra.sh', 'start-onos.sh': |
| 147 | script = path.join( self.onosDir, script ) |
| 148 | if not path.exists( script ): |
| 149 | msg = '%s not found' % script |
| 150 | if 'ONOS_HOME' not in environ: |
| 151 | msg += ' (try setting $ONOS_HOME and/or sudo -E)' |
| 152 | raise Exception( msg ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 153 | |
| 154 | def waitNetstat( self, pid ): |
| 155 | """Wait for pid to show up in netstat |
| 156 | We assume that once a process is listening on some |
| 157 | port, it is ready to go!""" |
| 158 | while True: |
| 159 | output = self.cmd( 'sudo netstat -natp | grep %s/' % pid ) |
| 160 | if output: |
| 161 | return output |
| 162 | info( '.' ) |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 163 | time.sleep( 1 ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 164 | |
| 165 | def waitStart( self, procname, pattern ): |
| 166 | "Wait for at least one of procname to show up in netstat" |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 167 | # Check script exit code |
| 168 | exitCode = int( self.cmd( 'echo $?' ) ) |
| 169 | if exitCode != 0: |
| 170 | raise Exception( '%s startup failed with code %d' % |
| 171 | ( procname, exitCode ) ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 172 | info( '* Waiting for %s startup' % procname ) |
| 173 | result = self.cmd( 'pgrep -f %s' % pattern ).split()[ 0 ] |
| 174 | pid = int( result ) |
| 175 | output = self.waitNetstat( pid ) |
| 176 | info( '\n* %s process %d is listening\n' % ( procname, pid ) ) |
| 177 | info( output ) |
| 178 | |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 179 | def startCassandra( self ): |
| 180 | "Start Cassandra" |
| 181 | self.cmd( 'start-cassandra.sh start' ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 182 | self.waitStart( 'Cassandra', 'apache-cassandra' ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 183 | status = self.cmd( 'start-cassandra.sh status' ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 184 | if 'running' not in status: |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 185 | raise Exception( 'Cassandra startup failed: ' + status ) |
| 186 | |
| 187 | def stopCassandra( self ): |
| 188 | "Stop Cassandra" |
| 189 | self.cmd( 'start-cassandra.sh stop' ) |
| 190 | |
| 191 | def startZookeeper( self, initcfg=True ): |
| 192 | "Start Zookeeper" |
| 193 | # Reinitialize configuration file |
| 194 | if initcfg: |
| 195 | cfg = self.zookeeperDir + '/conf/zoo.cfg' |
| 196 | template = self.zookeeperDir + '/conf/zoo_sample.cfg' |
| 197 | copyfile( template, cfg ) |
| 198 | self.cmd( 'start-zk.sh restart' ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 199 | self.waitStart( 'Zookeeper', 'zookeeper' ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 200 | status = self.cmd( 'start-zk.sh status' ) |
| 201 | if 'Error' in status: |
| 202 | raise Exception( 'Zookeeper startup failed: ' + status ) |
| 203 | |
| 204 | def stopZookeeper( self ): |
| 205 | "Stop Zookeeper" |
| 206 | self.cmd( 'start-zk.sh stop' ) |
| 207 | |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 208 | def genProperties( self, id, path='/tmp' ): |
| 209 | "Generate ONOS properties file" |
| 210 | filename = path + '/onos-%s.properties' % id |
| 211 | with open( filename, 'w' ) as f: |
| 212 | # Write modules list |
| 213 | modules = list( self.baseModules ) |
| 214 | if self.reactive: |
| 215 | modules += list( self.reactiveModules ) |
| 216 | f.write( 'floodlight.modules = %s\n' % |
| 217 | ',\\\n'.join( modules ) ) |
| 218 | # Write other parameters |
| 219 | for var, val in self.perNodeConfigBase.iteritems(): |
| 220 | if type( val ) is int: |
| 221 | val += id |
| 222 | f.write( '%s = %s\n' % ( var, val ) ) |
| 223 | for var, val in self.staticConfig.iteritems(): |
| 224 | f.write( '%s = %s\n' % ( var, val ) ) |
Bob Lantz | 21b41f6 | 2013-12-18 18:16:38 -0800 | [diff] [blame] | 225 | for var, val in self.dirConfig.iteritems(): |
| 226 | f.write( '%s = %s\n' % ( var, val % self.onosDir) ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 227 | return filename |
| 228 | |
| 229 | def setVars( self, id, propsFile ): |
| 230 | """Set and return environment vars |
| 231 | id: ONOS instance number |
| 232 | propsFile: properties file name""" |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 233 | # ONOS directories and files |
| 234 | logdir = self.logDir % id |
Bob Lantz | 4ed6cff | 2013-12-17 21:43:36 -0800 | [diff] [blame] | 235 | # cassdir = self.cassDir % id |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 236 | logback = self.logbackFile % id |
| 237 | jmxport = self.jmxbase + id |
Bob Lantz | 4ed6cff | 2013-12-17 21:43:36 -0800 | [diff] [blame] | 238 | self.cmd( 'mkdir -p', logdir ) # , cassdir |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 239 | self.cmd( 'export ONOS_LOGDIR="%s"' % logdir ) |
| 240 | self.cmd( 'export ZOO_LOG_DIR="%s"' % logdir ) |
Bob Lantz | 4ed6cff | 2013-12-17 21:43:36 -0800 | [diff] [blame] | 241 | # self.cmd( 'export CASS_DIR="%s"' % cassdir ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 242 | self.cmd( 'export ONOS_LOGBACK="%s"' % logback ) |
| 243 | self.cmd( 'export JMX_PORT=%s' % jmxport ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 244 | self.cmd( 'export JVM_OPTS="-D%s=%s"' % ( |
| 245 | self.proctag, id ) ) |
| 246 | self.cmd( 'export ONOS_PROPS="%s"' % propsFile ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 247 | |
| 248 | def startONOS( self, id ): |
| 249 | """Start ONOS |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 250 | id: new instance number""" |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 251 | start = time.time() |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 252 | self.stopONOS( id ) |
| 253 | propsFile = self.genProperties( id ) |
| 254 | self.setVars( id, propsFile ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 255 | self.cmdPrint( 'start-onos.sh startnokill' ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 256 | # start-onos.sh waits for ONOS startup |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 257 | elapsed = time.time() - start |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 258 | info( '* ONOS %s started in %.2f seconds\n' % ( id, elapsed ) ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 259 | |
| 260 | def stopONOS( self, id ): |
| 261 | """Shut down ONOS |
| 262 | id: identifier for instance""" |
| 263 | pid = self.cmd( "jps -v | grep %s=%s | awk '{print $1}'" % |
| 264 | ( self.proctag, id ) ).strip() |
| 265 | if pid: |
| 266 | self.cmdPrint( 'kill', pid ) |
| 267 | |
| 268 | def start( self, *args ): |
| 269 | "Start ONOS instances" |
| 270 | info( '* Starting Cassandra\n' ) |
| 271 | self.startCassandra() |
| 272 | info( '* Starting Zookeeper\n' ) |
| 273 | self.startZookeeper() |
| 274 | for id in self.ids: |
| 275 | info( '* Starting ONOS %s\n' % id ) |
| 276 | self.startONOS( id ) |
| 277 | |
| 278 | def stop( self, *args ): |
| 279 | "Stop ONOS instances" |
| 280 | for id in self.ids: |
| 281 | info( '* Stopping ONOS %s\n' % id ) |
| 282 | self.stopONOS( id ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 283 | info( '* Stopping Zookeeper\n' ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 284 | self.stopZookeeper() |
| 285 | info( '* Stopping Cassandra\n' ) |
| 286 | self.stopCassandra() |
| 287 | |
| 288 | def clist( self ): |
| 289 | "Return list of controller specifiers (proto:ip:port)" |
| 290 | return [ 'tcp:127.0.0.1:%s' % ( self.ofbase + id ) |
| 291 | for id in range( 0, self.count ) ] |
| 292 | |
| 293 | |
| 294 | class OVSSwitchONOS( OVSSwitch ): |
| 295 | "OVS switch which connects to multiple controllers" |
| 296 | def start( self, controllers ): |
| 297 | OVSSwitch.start( self, controllers ) |
| 298 | assert len( controllers ) == 1 |
| 299 | c0 = controllers[ 0 ] |
| 300 | assert type( c0 ) == ONOS |
| 301 | clist = ','.join( c0.clist() ) |
| 302 | self.cmd( 'ovs-vsctl set-controller', self, clist) |
| 303 | # Reconnect quickly to controllers (1s vs. 15s max_backoff) |
| 304 | for uuid in self.controllerUUIDs(): |
| 305 | if uuid.count( '-' ) != 4: |
| 306 | # Doesn't look like a UUID |
| 307 | continue |
| 308 | uuid = uuid.strip() |
| 309 | self.cmd( 'ovs-vsctl set Controller', uuid, |
| 310 | 'max_backoff=1000' ) |
| 311 | |
| 312 | |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 313 | def waitConnected( switches ): |
| 314 | "Wait until all switches connect to controllers" |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 315 | start = time.time() |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 316 | info( '* Waiting for switches to connect...\n' ) |
| 317 | for s in switches: |
| 318 | info( s ) |
| 319 | while not s.connected(): |
| 320 | info( '.' ) |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 321 | time.sleep( 1 ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 322 | info( ' ' ) |
Bob Lantz | a093082 | 2013-12-17 21:00:41 -0800 | [diff] [blame] | 323 | elapsed = time.time() - start |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 324 | info( '\n* Connected in %.2f seconds\n' % elapsed ) |
| 325 | |
| 326 | |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 327 | controllers = { 'onos': ONOS } |
| 328 | switches = { 'ovso': OVSSwitchONOS } |
| 329 | |
| 330 | |
| 331 | if __name__ == '__main__': |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 332 | # Simple test for ONOS() controller class |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 333 | setLogLevel( 'info' ) |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 334 | size = 2 if len( argv ) != 2 else int( argv[ 1 ] ) |
| 335 | net = Mininet( topo=LinearTopo( size ), |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 336 | controller=partial( ONOS, n=2 ), |
| 337 | switch=OVSSwitchONOS ) |
| 338 | net.start() |
Bob Lantz | 7ead053 | 2013-12-17 20:41:20 -0800 | [diff] [blame] | 339 | waitConnected( net.switches ) |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 340 | CLI( net ) |
| 341 | net.stop() |