few small fixes to syntax errors

This commit is contained in:
cody burkard
2014-08-01 11:00:07 -07:00
parent 4b65110e4d
commit a3d51b77e9
5 changed files with 25 additions and 23 deletions
+2 -2
View File
@@ -97,7 +97,7 @@ class Intf( object ):
def updateAddr( self ): def updateAddr( self ):
"""Return IP address and MAC address based on ifconfig. """Return IP address and MAC address based on ifconfig.
instead of updating ip and mac separately, 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() ifconfig = self.ifconfig()
ips = self._ipMatchRegex.findall( ifconfig ) ips = self._ipMatchRegex.findall( ifconfig )
macs = self._macMatchRegex.findall( ifconfig ) macs = self._macMatchRegex.findall( ifconfig )
@@ -118,7 +118,7 @@ class Intf( object ):
if setUp: if setUp:
cmdOutput = self.ifconfig( 'up' ) cmdOutput = self.ifconfig( 'up' )
if cmdOutput: if cmdOutput:
error( "Error setting %s up: %s " % ( self.name, cmdOutput ) error( "Error setting %s up: %s " % ( self.name, cmdOutput ) )
return False return False
else: else:
return True return True
+2 -17
View File
@@ -303,21 +303,6 @@ class Mininet( object ):
"return (key,value) tuple list for every node in net" "return (key,value) tuple list for every node in net"
return zip( self.keys(), self.values() ) 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, def addLink( self, node1, node2, port1=None, port2=None,
cls=None, **params ): cls=None, **params ):
""""Add a link from node1 to node2 """"Add a link from node1 to node2
@@ -326,8 +311,8 @@ class Mininet( object ):
port1: source port port1: source port
port2: dest port port2: dest port
returns: link object""" returns: link object"""
mac1 = self.generateMac() mac1 = macColonHex( random.randint( 1, (2**24 - 1) ) )
mac2 = self.generateMac() mac2 = macColonHex( random.randint( 1, (2**24 - 1) ) )
defaults = { 'port1': port1, defaults = { 'port1': port1,
'port2': port2, 'port2': port2,
'addr1': mac1, 'addr1': mac1,
-1
View File
@@ -1193,7 +1193,6 @@ class IVSSwitch(Switch):
args.append( self.opts ) args.append( self.opts )
logfile = '/tmp/ivs.%s.log' % self.name logfile = '/tmp/ivs.%s.log' % self.name
self.cmd( 'ifconfig lo up' ) self.cmd( 'ifconfig lo up' )
self.cmd( ' '.join(args) + ' >' + logfile + ' 2>&1 </dev/null &' ) self.cmd( ' '.join(args) + ' >' + logfile + ' 2>&1 </dev/null &' )
+19 -1
View File
@@ -192,7 +192,7 @@ def moveIntfNoRetry( intf, dstNode, srcNode=None, printError=False ):
cmdOutput = srcNode.cmd( cmd ) cmdOutput = srcNode.cmd( cmd )
else: else:
cmdOutput = quietRun( cmd ) cmdOutput = quietRun( cmd )
if output: if cmdOutput:
if printError: if printError:
error( '*** Error: moveIntf: ' + intf + error( '*** Error: moveIntf: ' + intf +
' not successfully moved to ' + dstNode.name + '\n' ) ' not successfully moved to ' + dstNode.name + '\n' )
@@ -249,10 +249,28 @@ def _colonHex( val, bytecount ):
chStr = ':'.join( pieces ) chStr = ':'.join( pieces )
return chStr 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 ): def macColonHex( mac ):
"""Generate MAC colon-hex string from unsigned int. """Generate MAC colon-hex string from unsigned int.
mac: MAC address as unsigned int mac: MAC address as unsigned int
returns: macStr MAC colon-hex string""" returns: macStr MAC colon-hex string"""
if mac < 2**24:
return 'A4:23:05:' + _colonHex( mac, 3 )
else:
return _colonHex( mac, 6 ) return _colonHex( mac, 6 )
def ipStr( ip ): def ipStr( ip ):