added some documentation

This commit is contained in:
cody burkard
2014-08-01 11:27:25 -07:00
parent f0fd84770a
commit 42cdda38bb
4 changed files with 14 additions and 24 deletions
+8 -3
View File
@@ -42,6 +42,9 @@ class Intf( object ):
self.link = link
self.mac = mac
self.ip, self.prefixLen = None, None
# if interface is lo, we know the ip is 127.0.0.1.
# This saves an ifconfig command per node
if self.name == 'lo':
self.ip = '127.0.0.1'
# Add to node (and move ourselves if necessary )
@@ -94,10 +97,12 @@ class Intf( object ):
self.mac = macs[ 0 ] if macs else None
return self.mac
# Instead of updating ip and mac separately,
# use one ifconfig call to do it simultaneously.
# This saves an ifconfig command, which improves performance.
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"""
"Return IP address and MAC address based on ifconfig."
ifconfig = self.ifconfig()
ips = self._ipMatchRegex.findall( ifconfig )
macs = self._macMatchRegex.findall( ifconfig )
+2
View File
@@ -166,6 +166,7 @@ class Mininet( object ):
if topo and build:
self.build()
def waitConnected( self, timeout=None, delay=.5 ):
"""wait for each switch to connect to a controller,
up to 5 seconds
@@ -384,6 +385,7 @@ class Mininet( object ):
srcPort, dstPort = topo.port( srcName, dstName )
self.addLink( src, dst, srcPort, dstPort, **params )
info( '(%s, %s) ' % ( src.name, dst.name ) )
info( '\n' )
def configureControlNetwork( self ):
+2 -4
View File
@@ -331,10 +331,7 @@ class Node( object ):
# Shell requires a string, not a list!
if defaults.get( 'shell', False ):
cmd = ' '.join( cmd )
old = signal.signal( signal.SIGINT, signal.SIG_IGN )
popen = Popen( cmd, **defaults )
signal.signal( signal.SIGINT, old )
return popen
return Popen( cmd, **defaults )
def pexec( self, *args, **kwargs ):
"""Execute a command using popen
@@ -1198,6 +1195,7 @@ class IVSSwitch(Switch):
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 &' )
+2 -17
View File
@@ -249,29 +249,14 @@ 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"""
if mac < 2**24:
if mac < 2 ** 24:
return 'A4:23:05:' + _colonHex( mac, 3 )
else:
return _colonHex( mac, 6 )
return 'A4:23:05:' + _colonHex( mac, 3 )
def ipStr( ip ):
"""Generate IP address string from an unsigned int.