From 42cdda38bbb3a1d3950f3d42b05368bf726d8fd4 Mon Sep 17 00:00:00 2001 From: cody burkard <cody@onlab.us> Date: Fri, 1 Aug 2014 11:27:25 -0700 Subject: [PATCH] added some documentation --- mininet/link.py | 11 ++++++++--- mininet/net.py | 2 ++ mininet/node.py | 6 ++---- mininet/util.py | 19 ++----------------- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/mininet/link.py b/mininet/link.py index c7e5c725..9eed9289 100644 --- a/mininet/link.py +++ b/mininet/link.py @@ -42,6 +42,9 @@ def __init__( self, name, node=None, port=None, link=None, mac=None, **params ): 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 @@ def updateMAC( self ): 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 ) diff --git a/mininet/net.py b/mininet/net.py index 3b822f41..a3ff824e 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -166,6 +166,7 @@ def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host, 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 @@ def buildFromTopo( self, topo=None ): 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 ): diff --git a/mininet/node.py b/mininet/node.py index 0b435fcc..40a3c34b 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -331,10 +331,7 @@ def popen( self, *args, **kwargs ): # 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 @@ 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 1bd2c5d8..6c7b4263 100644 --- a/mininet/util.py +++ b/mininet/util.py @@ -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. -- GitLab