improved waitConnected algorithm and set default wait time to wait forever
This commit is contained in:
+10
-7
@@ -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():
|
||||||
|
|||||||
Reference in New Issue
Block a user