Revision 4794871a

View differences:

mininet/net.py
166 166
            self.build()
167 167

  
168 168

  
169
    def waitConnected( self, timeout=None ):
169
    def waitConnected( self, timeout=None, delay=.5 ):
170 170
        """wait for each switch to connect to a controller,
171 171
           up to 5 seconds
172 172
           timeout: time to wait, or None to wait indefinitely
173
           delay: seconds to sleep per iteration
173 174
           returns: True if all switches are connected"""
174 175
        info( '*** Waiting for switches to connect\n' )
175 176
        time = 0
176 177
        remaining = copy.copy( self.switches )
177
        while time < timeout or timeout == None:
178
            connected = True
178
        while True:
179 179
            for switch in remaining:
180
                if not switch.connected():
181
                    connected = False
182
                else:
180
                if switch.connected():
181
                    info( '%s ' % switch )
183 182
                    remaining.remove( switch )
184
            if connected:
183
            if not remaining:
184
                info( '\n' )
185
                return True
186
            if time > timeout and timeout is not None:
185 187
                break
186
            sleep( .5 )
187
            time += .5
188
        if time >= timeout and timeout is not  None:
189
            warn( 'Timed out after %d seconds\n' % time )
190
            for switch in self.switches:
191
                if not switch.connected():
192
                    warn( 'Warning: %s is not connected to a controller\n'
193
                           % switch.name )
194
        return connected
188
            sleep( delay )
189
            time += delay
190
        warn( 'Timed out after %d seconds\n' % time )
191
        for switch in remaining:
192
            if not switch.connected():
193
                warn( 'Warning: %s is not connected to a controller\n'
194
                      % switch.name )
195
            else:
196
                remaining.remove( switch )
197
        return not remaining
195 198

  
196 199
    def addHost( self, name, cls=None, **params ):
197 200
        """Add host.

Also available in: Unified diff