Revision 0a9ea29f mininet.py

View differences:

mininet.py
346 346
def moveIntf( intf, node ):
347 347
   "Move intf to node."
348 348
   cmd = 'ip link set ' + intf + ' netns ' + `node.pid`
349
   checkRun( cmd )
349
   quietRun( cmd )
350 350
   links = node.cmd( 'ip link show' )
351 351
   if not intf in links:
352 352
      print "*** Error: moveIntf:", intf, "not successfully moved to",
353 353
      print node.name,":"
354
      exit( 1 )
355
   return
354
      return False
355
   return True
356

  
357
def retry( n, fn, *args):
358
   "Try something N times before giving up."
359
   tries = 0
360
   while not apply( fn, args ) and tries < 3:
361
      sleep( 1 )
362
      print "*** retrying..."; flush()
363
      tries += 1
364
   if tries > 3: exit( 1 )
356 365
   
357 366
def createLink( node1, node2 ):
358 367
   "Create a link node1-intf1 <---> node2-intf2."
359 368
   intf1 = node1.newIntf()
360 369
   intf2 = node2.newIntf()
361 370
   makeIntfPair( intf1, intf2 )
362
   if node1.inNamespace: moveIntf( intf1, node1 )
363
   if node2.inNamespace: moveIntf( intf2, node2 )
371
   if node1.inNamespace: retry( 3, moveIntf, intf1, node1 )
372
   if node2.inNamespace: retry( 3, moveIntf, intf2, node2 )
364 373
   node1.connection[ intf1 ] = ( node2, intf2 )
365 374
   node2.connection[ intf2 ] = ( node1, intf1 )
366 375
   return intf1, intf2

Also available in: Unified diff