Revision f11dbe81 mininet/net.py

View differences:

mininet/net.py
303 303
        "return (key,value) tuple list for every node in net"
304 304
        return zip( self.keys(), self.values() )
305 305

  
306
    def generateMac( self ):
307
        newMac = True
308
        while True:
309
            macList = [ 0x00 ]
310
            for i in xrange ( 0, 5 ):
311
                macList.append( random.randint( 0x00, 0xff ) )
312
            mac = ':'.join( map(lambda x: "%02x" % x, macList ) )
313
            for node in self.switches + self.hosts:
314
                for intf in node.ports:
315
                    if intf.mac == mac:
316
                        newMac = False
317
                        break
318
            if newMac:
319
                return mac
320

  
321 306
    def addLink( self, node1, node2, port1=None, port2=None,
322 307
                 cls=None, **params ):
323 308
        """"Add a link from node1 to node2
......
326 311
            port1: source port
327 312
            port2: dest port
328 313
            returns: link object"""
329
        mac1 = self.generateMac()
330
        mac2 = self.generateMac()
314
        mac1 = macColonHex( random.randint( 1, (2**24 - 1) ) )
315
        mac2 = macColonHex( random.randint( 1, (2**24 - 1) ) )
331 316
        defaults = { 'port1': port1,
332 317
                     'port2': port2,
333 318
                     'addr1': mac1,

Also available in: Unified diff