improved waitConnected algorithm and set default wait time to wait forever

This commit is contained in:
Cody Burkard
2014-07-09 19:12:15 -07:00
parent 84ea8d7f90
commit 8e2443ada4
+10 -7
View File
@@ -90,6 +90,7 @@ import os
import re import re
import select import select
import signal import signal
import copy
from time import sleep from time import sleep
from itertools import chain, groupby from itertools import chain, groupby
@@ -166,23 +167,25 @@ class Mininet( object ):
if waitConnected: if waitConnected:
self.waitConnected() self.waitConnected()
def waitConnected( self ): def waitConnected( self, timeout=None ):
"""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
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
while time < 5: remaining = copy.copy( self.switches )
while time < timeout or timeout == None:
connected = True connected = True
for switch in self.switches: for switch in remaining:
if not switch.connected(): if not switch.connected():
connected = False connected = False
sleep( .1 ) sleep( .5 )
time += .1 time += .5
break else:
remaining.remove( switch )
if connected: if connected:
break break
if time >= 5: if time >= timeout and not timeout == 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 self.switches:
if not switch.connected(): if not switch.connected():