From a3d51b77e9d7d21b65548856b51f4a4a990f8ed2 Mon Sep 17 00:00:00 2001
From: cody burkard <cody@onlab.us>
Date: Thu, 24 Jul 2014 15:59:38 -0700
Subject: [PATCH] few small fixes to syntax errors

---
 bin/mn          |  2 +-
 mininet/link.py |  4 ++--
 mininet/net.py  | 19 ++-----------------
 mininet/node.py |  1 -
 mininet/util.py | 22 ++++++++++++++++++++--
 5 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/bin/mn b/bin/mn
index f96511cf..edd4d984 100755
--- a/bin/mn
+++ b/bin/mn
@@ -282,7 +282,7 @@ class MininetRunner( object ):
             CLI( mn, script=self.options.post )
 
         mn.stop()
-        
+
         elapsed = float( time.time() - start )
         info( 'completed in %0.3f seconds\n' % elapsed )
 
diff --git a/mininet/link.py b/mininet/link.py
index 2e6e1711..c7e5c725 100644
--- a/mininet/link.py
+++ b/mininet/link.py
@@ -97,7 +97,7 @@ def updateMAC( self ):
     def updateAddr( self ):
         """Return IP address and MAC address based on ifconfig.
         instead of updating ip and mac separately,
-        use one ifconfig call to do it simultaneously""""
+        use one ifconfig call to do it simultaneously"""
         ifconfig = self.ifconfig()
         ips = self._ipMatchRegex.findall( ifconfig )
         macs = self._macMatchRegex.findall( ifconfig )
@@ -118,7 +118,7 @@ def isUp( self, setUp=False ):
         if setUp:
             cmdOutput = self.ifconfig( 'up' )
             if cmdOutput:
-                error( "Error setting %s up: %s " % ( self.name, cmdOutput )
+                error( "Error setting %s up: %s " % ( self.name, cmdOutput ) )
                 return False
             else:
                 return True
diff --git a/mininet/net.py b/mininet/net.py
index 30feb8fd..3b822f41 100755
--- a/mininet/net.py
+++ b/mininet/net.py
@@ -303,21 +303,6 @@ def items( self ):
         "return (key,value) tuple list for every node in net"
         return zip( self.keys(), self.values() )
 
-    def generateMac( self ):
-        newMac = True
-        while True:
-            macList = [ 0x00 ]
-            for i in xrange ( 0, 5 ):
-                macList.append( random.randint( 0x00, 0xff ) )
-            mac = ':'.join( map(lambda x: "%02x" % x, macList ) )
-            for node in self.switches + self.hosts:
-                for intf in node.ports:
-                    if intf.mac == mac:
-                        newMac = False
-                        break
-            if newMac:
-                return mac
-
     def addLink( self, node1, node2, port1=None, port2=None,
                  cls=None, **params ):
         """"Add a link from node1 to node2
@@ -326,8 +311,8 @@ def addLink( self, node1, node2, port1=None, port2=None,
             port1: source port
             port2: dest port
             returns: link object"""
-        mac1 = self.generateMac()
-        mac2 = self.generateMac()
+        mac1 = macColonHex( random.randint( 1, (2**24 - 1) ) )
+        mac2 = macColonHex( random.randint( 1, (2**24 - 1) ) )
         defaults = { 'port1': port1,
                      'port2': port2,
                      'addr1': mac1,
diff --git a/mininet/node.py b/mininet/node.py
index 472e66a6..4eb27ade 100644
--- a/mininet/node.py
+++ b/mininet/node.py
@@ -1193,7 +1193,6 @@ def start( self, controllers ):
         args.append( self.opts )
 
         logfile = '/tmp/ivs.%s.log' % self.name
-
         self.cmd( 'ifconfig lo up' )
         self.cmd( ' '.join(args) + ' >' + logfile + ' 2>&1 </dev/null &' )
 
diff --git a/mininet/util.py b/mininet/util.py
index 32160be1..1bd2c5d8 100644
--- a/mininet/util.py
+++ b/mininet/util.py
@@ -192,7 +192,7 @@ def moveIntfNoRetry( intf, dstNode, srcNode=None, printError=False ):
         cmdOutput = srcNode.cmd( cmd )
     else:
         cmdOutput = quietRun( cmd )
-    if output:
+    if cmdOutput:
         if printError:
             error( '*** Error: moveIntf: ' + intf +
                    ' not successfully moved to ' + dstNode.name + '\n' )
@@ -249,11 +249,29 @@ def _colonHex( val, bytecount ):
     chStr = ':'.join( pieces )
     return chStr
 
+def generateMac( self ):
+    newMac = True
+    while True:
+        macList = [ 0x00 ]
+        for i in xrange ( 0, 5 ):
+            macList.append( random.randint( 0x00, 0xff ) )
+        mac = ':'.join( map(lambda x: "%02x" % x, macList ) )
+        for node in self.switches + self.hosts:
+            for intf in node.ports:
+                if intf.mac == mac:
+                    newMac = False
+                    break
+        if newMac:
+            return mac
+
 def macColonHex( mac ):
     """Generate MAC colon-hex string from unsigned int.
        mac: MAC address as unsigned int
        returns: macStr MAC colon-hex string"""
-    return _colonHex( mac, 6 )
+    if mac < 2**24:
+        return 'A4:23:05:' + _colonHex( mac, 3 )
+    else:
+        return _colonHex( mac, 6 )
 
 def ipStr( ip ):
     """Generate IP address string from an unsigned int.
-- 
GitLab