Revision 89fb0819 mininet/net.py

View differences:

mininet/net.py
321 321
        "return (key,value) tuple list for every node in net"
322 322
        return zip( self.keys(), self.values() )
323 323

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

  
......
397 408
            info( switchName + ' ' )
398 409

  
399 410
        info( '\n*** Adding links:\n' )
400
        for srcName, dstName in topo.links(sort=True):
411
        for srcName, dstName in topo.links( sort=True ):
401 412
            src, dst = self.nameToNode[ srcName ], self.nameToNode[ dstName ]
402 413
            params = topo.linkInfo( srcName, dstName )
403 414
            srcPort, dstPort = topo.port( srcName, dstName )
404
            self.addLink( src, dst, srcPort, dstPort, **params )
415
            self.addLink( src, dst, srcPort, dstPort, paramDict=params )
405 416
            info( '(%s, %s) ' % ( src.name, dst.name ) )
406 417

  
407 418
        info( '\n' )

Also available in: Unified diff