From 4794871a9a47ff2baf74c5955c916ab3ce7b8be1 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Thu, 10 Jul 2014 13:39:17 -0700 Subject: [PATCH] Change algorithm slightly and print progress --- mininet/net.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/mininet/net.py b/mininet/net.py index 281980a..84416d2 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -166,32 +166,35 @@ class Mininet( object ): self.build() - def waitConnected( self, timeout=None ): + def waitConnected( self, timeout=None, delay=.5 ): """wait for each switch to connect to a controller, up to 5 seconds timeout: time to wait, or None to wait indefinitely + delay: seconds to sleep per iteration returns: True if all switches are connected""" info( '*** Waiting for switches to connect\n' ) time = 0 remaining = copy.copy( self.switches ) - while time < timeout or timeout == None: - connected = True + while True: for switch in remaining: - if not switch.connected(): - connected = False - else: + if switch.connected(): + info( '%s ' % switch ) remaining.remove( switch ) - if connected: + if not remaining: + info( '\n' ) + return True + if time > timeout and timeout is not None: break - sleep( .5 ) - time += .5 - if time >= timeout and timeout is not None: - warn( 'Timed out after %d seconds\n' % time ) - for switch in self.switches: - if not switch.connected(): - warn( 'Warning: %s is not connected to a controller\n' - % switch.name ) - return connected + sleep( delay ) + time += delay + warn( 'Timed out after %d seconds\n' % time ) + for switch in remaining: + if not switch.connected(): + warn( 'Warning: %s is not connected to a controller\n' + % switch.name ) + else: + remaining.remove( switch ) + return not remaining def addHost( self, name, cls=None, **params ): """Add host.