Revision f11dbe81

View differences:

bin/mn
282 282
            CLI( mn, script=self.options.post )
283 283

  
284 284
        mn.stop()
285
        
285

  
286 286
        elapsed = float( time.time() - start )
287 287
        info( 'completed in %0.3f seconds\n' % elapsed )
288 288

  
mininet/link.py
97 97
    def updateAddr( self ):
98 98
        """Return IP address and MAC address based on ifconfig.
99 99
        instead of updating ip and mac separately,
100
        use one ifconfig call to do it simultaneously""""
100
        use one ifconfig call to do it simultaneously"""
101 101
        ifconfig = self.ifconfig()
102 102
        ips = self._ipMatchRegex.findall( ifconfig )
103 103
        macs = self._macMatchRegex.findall( ifconfig )
......
118 118
        if setUp:
119 119
            cmdOutput = self.ifconfig( 'up' )
120 120
            if cmdOutput:
121
                error( "Error setting %s up: %s " % ( self.name, cmdOutput )
121
                error( "Error setting %s up: %s " % ( self.name, cmdOutput ) )
122 122
                return False
123 123
            else:
124 124
                return True
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,
mininet/node.py
1186 1186
        args.append( self.opts )
1187 1187

  
1188 1188
        logfile = '/tmp/ivs.%s.log' % self.name
1189

  
1190 1189
        self.cmd( 'ifconfig lo up' )
1191 1190
        self.cmd( ' '.join(args) + ' >' + logfile + ' 2>&1 </dev/null &' )
1192 1191

  
mininet/util.py
192 192
        cmdOutput = srcNode.cmd( cmd )
193 193
    else:
194 194
        cmdOutput = quietRun( cmd )
195
    if output:
195
    if cmdOutput:
196 196
        if printError:
197 197
            error( '*** Error: moveIntf: ' + intf +
198 198
                   ' not successfully moved to ' + dstNode.name + '\n' )
......
249 249
    chStr = ':'.join( pieces )
250 250
    return chStr
251 251

  
252
def generateMac( self ):
253
    newMac = True
254
    while True:
255
        macList = [ 0x00 ]
256
        for i in xrange ( 0, 5 ):
257
            macList.append( random.randint( 0x00, 0xff ) )
258
        mac = ':'.join( map(lambda x: "%02x" % x, macList ) )
259
        for node in self.switches + self.hosts:
260
            for intf in node.ports:
261
                if intf.mac == mac:
262
                    newMac = False
263
                    break
264
        if newMac:
265
            return mac
266

  
252 267
def macColonHex( mac ):
253 268
    """Generate MAC colon-hex string from unsigned int.
254 269
       mac: MAC address as unsigned int
255 270
       returns: macStr MAC colon-hex string"""
256
    return _colonHex( mac, 6 )
271
    if mac < 2**24:
272
        return 'A4:23:05:' + _colonHex( mac, 3 )
273
    else:
274
        return _colonHex( mac, 6 )
257 275

  
258 276
def ipStr( ip ):
259 277
    """Generate IP address string from an unsigned int.

Also available in: Unified diff