Change algorithm slightly and print progress

This commit is contained in:
Bob Lantz
2014-07-10 13:40:21 -07:00
parent 13d25b4109
commit 4794871a9a
+15 -12
View File
@@ -166,32 +166,35 @@ class Mininet( object ):
self.build() self.build()
def waitConnected( self, timeout=None ): def waitConnected( self, timeout=None, delay=.5 ):
"""wait for each switch to connect to a controller, """wait for each switch to connect to a controller,
up to 5 seconds up to 5 seconds
timeout: time to wait, or None to wait indefinitely timeout: time to wait, or None to wait indefinitely
delay: seconds to sleep per iteration
returns: True if all switches are connected""" returns: True if all switches are connected"""
info( '*** Waiting for switches to connect\n' ) info( '*** Waiting for switches to connect\n' )
time = 0 time = 0
remaining = copy.copy( self.switches ) remaining = copy.copy( self.switches )
while time < timeout or timeout == None: while True:
connected = True
for switch in remaining: for switch in remaining:
if not switch.connected(): if switch.connected():
connected = False info( '%s ' % switch )
else:
remaining.remove( switch ) remaining.remove( switch )
if connected: if not remaining:
info( '\n' )
return True
if time > timeout and timeout is not None:
break break
sleep( .5 ) sleep( delay )
time += .5 time += delay
if time >= timeout and timeout is not None:
warn( 'Timed out after %d seconds\n' % time ) warn( 'Timed out after %d seconds\n' % time )
for switch in self.switches: for switch in remaining:
if not switch.connected(): if not switch.connected():
warn( 'Warning: %s is not connected to a controller\n' warn( 'Warning: %s is not connected to a controller\n'
% switch.name ) % switch.name )
return connected else:
remaining.remove( switch )
return not remaining
def addHost( self, name, cls=None, **params ): def addHost( self, name, cls=None, **params ):
"""Add host. """Add host.