Revision 2a2d6050

View differences:

mininet/net.py
324 324
    @staticmethod
325 325
    def randMac():
326 326
        "Return a random, non-multicast MAC address"
327
        return macColonHex( random.randint(1, 2**48 - 1) & 0xfeffffffffff  | 0x020000000000 )
327
        return macColonHex( random.randint(1, 2**48 - 1) & 0xfeffffffffff  |
328
                            0x020000000000 )
328 329
    
329 330
    def addLink( self, node1, node2, port1=None, port2=None,
330
                 cls=None, paramDict=None, **params ):
331
                 cls=None, **params ):
331 332
        """"Add a link from node1 to node2
332
            node1: source node
333
            node2: dest node
333
            node1: source node (or name)
334
            node2: dest node (or name)
334 335
            port1: source port (optional)
335 336
            port2: dest port (optional)
336 337
            cls: link class (optional)
337
            paramDict: dictionary of additional link params (optional)
338 338
            params: additional link params (optional)
339 339
            returns: link object"""
340
        # Ugly: try to ensure that node1 and node2 line up correctly with
341
        # other link parameters, and allow either nodes or names
342
        paramDict = {} if paramDict is None else dict( paramDict )
343
        paramDict.update( params )
344
        node1 = paramDict.pop( 'node1', node1 )
345
        node2 = paramDict.pop( 'node2', node1 )
346 340
        node1 = node1 if type( node1 ) != str else self[ node1 ]
347 341
        node2 = node2 if type( node2 ) != str else self[ node2 ]
348
        paramDict.setdefault( 'port1', port1 )
349
        paramDict.setdefault( 'port2', port2 )
350
        paramDict.setdefault( 'addr1', self.randMac() )
351
        paramDict.setdefault( 'addr2', self.randMac() )
342
        options = dict( params )
343
        options.setdefault( 'addr1', self.randMac() )
344
        options.setdefault( 'addr2', self.randMac() )
352 345
        cls = self.link if cls is None else cls
353
        link = cls( node1, node2, **paramDict )
346
        link = cls( node1, node2, **options )
354 347
        self.links.append( link )
355 348
        return link
356 349

  
......
410 403
        info( '\n*** Adding links:\n' )
411 404
        for srcName, dstName, params in topo.links(
412 405
                sort=True, withInfo=True ):
413
            self.addLink( srcName, dstName, paramDict=params )
406
            self.addLink( **params )
414 407
            info( '(%s, %s) ' % ( srcName, dstName ) )
415 408

  
416 409
        info( '\n' )

Also available in: Unified diff