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 select
import signal
import copy
from time import sleep
from itertools import chain, groupby
@@ -166,23 +167,25 @@ class Mininet( object ):
if waitConnected:
self.waitConnected()
def waitConnected( self ):
def waitConnected( self, timeout=None ):
"""wait for each switch to connect to a controller,
up to 5 seconds
returns: True if all switches are connected"""
info( '***waiting for switches to connect\n' )
time = 0
while time < 5:
remaining = copy.copy( self.switches )
while time < timeout or timeout == None:
connected = True
for switch in self.switches:
for switch in remaining:
if not switch.connected():
connected = False
sleep( .1 )
time += .1
break
sleep( .5 )
time += .5
else:
remaining.remove( switch )
if connected:
break
if time >= 5:
if time >= timeout and not timeout == None:
warn( 'Timed out after %d seconds\n' % time )
for switch in self.switches:
if not switch.connected():