Changed to use info() and error() logging aliases.

This commit is contained in:
Bob Lantz
2010-02-08 15:51:25 -08:00
parent f8952d56e1
commit d5886525cc
+61 -62
View File
@@ -55,7 +55,7 @@ import signal
from time import sleep from time import sleep
from mininet.cli import CLI from mininet.cli import CLI
from mininet.log import lg from mininet.log import info, error
from mininet.node import KernelSwitch, OVSKernelSwitch from mininet.node import KernelSwitch, OVSKernelSwitch
from mininet.util import quietRun, fixLimits from mininet.util import quietRun, fixLimits
from mininet.util import makeIntfPair, moveIntf from mininet.util import makeIntfPair, moveIntf
@@ -121,7 +121,7 @@ class Mininet( object ):
# for now, assume one interface per host. # for now, assume one interface per host.
host.intfs.append( 'h_' + self.topo.name( dpid ) + '-eth0' ) host.intfs.append( 'h_' + self.topo.name( dpid ) + '-eth0' )
self.nodes[ dpid ] = host self.nodes[ dpid ] = host
#lg.info( '%s ' % host.name ) #info( '%s ' % host.name )
def _addSwitch( self, dpid ): def _addSwitch( self, dpid ):
"""Add switch. """Add switch.
@@ -152,14 +152,14 @@ class Mininet( object ):
dstNode.intfs.append( dstIntf ) dstNode.intfs.append( dstIntf )
srcNode.ports[ srcPort ] = srcIntf srcNode.ports[ srcPort ] = srcIntf
dstNode.ports[ dstPort ] = dstIntf dstNode.ports[ dstPort ] = dstIntf
#lg.info( '\n' ) #info( '\n' )
#lg.info( 'added intf %s to src node %x\n' % ( srcIntf, src ) ) #info( 'added intf %s to src node %x\n' % ( srcIntf, src ) )
#lg.info( 'added intf %s to dst node %x\n' % ( dstIntf, dst ) ) #info( 'added intf %s to dst node %x\n' % ( dstIntf, dst ) )
if srcNode.inNamespace: if srcNode.inNamespace:
#lg.info( 'moving src w/inNamespace set\n' ) #info( 'moving src w/inNamespace set\n' )
moveIntf( srcIntf, srcNode ) moveIntf( srcIntf, srcNode )
if dstNode.inNamespace: if dstNode.inNamespace:
#lg.info( 'moving dst w/inNamespace set\n' ) #info( 'moving dst w/inNamespace set\n' )
moveIntf( dstIntf, dstNode ) moveIntf( dstIntf, dstNode )
srcNode.connection[ srcIntf ] = ( dstNode, dstIntf ) srcNode.connection[ srcIntf ] = ( dstNode, dstIntf )
dstNode.connection[ dstIntf ] = ( srcNode, srcIntf ) dstNode.connection[ dstIntf ] = ( srcNode, srcIntf )
@@ -201,19 +201,18 @@ class Mininet( object ):
For use with the user datapath only right now. For use with the user datapath only right now.
TODO( brandonh ) test this code! TODO( brandonh ) test this code!
""" """
# params were: controller, switches, ips # params were: controller, switches, ips
controller = self.controllers[ 'c0' ] controller = self.controllers[ 'c0' ]
lg.info( '%s <-> ' % controller.name ) info( '%s <-> ' % controller.name )
for switchDpid in self.topo.switches(): for switchDpid in self.topo.switches():
switch = self.nodes[ switchDpid ] switch = self.nodes[ switchDpid ]
lg.info( '%s ' % switch.name ) info( '%s ' % switch.name )
sip = self.topo.ip( switchDpid )#ips.next() sip = self.topo.ip( switchDpid )#ips.next()
sintf = switch.intfs[ 0 ] sintf = switch.intfs[ 0 ]
node, cintf = switch.connection[ sintf ] node, cintf = switch.connection[ sintf ]
if node != controller: if node != controller:
lg.error( '*** Error: switch %s not connected to correct' error( '*** Error: switch %s not connected to correct'
'controller' % 'controller' %
switch.name ) switch.name )
exit( 1 ) exit( 1 )
@@ -222,22 +221,22 @@ class Mininet( object ):
switch.setIP( sintf, sip, '/' + self.cparams.subnetSize ) switch.setIP( sintf, sip, '/' + self.cparams.subnetSize )
controller.setHostRoute( sip, cintf ) controller.setHostRoute( sip, cintf )
switch.setHostRoute( self.cparams.ip, sintf ) switch.setHostRoute( self.cparams.ip, sintf )
lg.info( '\n' ) info( '\n' )
lg.info( '*** Testing control network\n' ) info( '*** Testing control network\n' )
while not controller.intfIsUp( controller.intfs[ 0 ] ): while not controller.intfIsUp( controller.intfs[ 0 ] ):
lg.info( '*** Waiting for %s to come up\n', info( '*** Waiting for %s to come up\n',
controller.intfs[ 0 ] ) controller.intfs[ 0 ] )
sleep( 1 ) sleep( 1 )
for switchDpid in self.topo.switches(): for switchDpid in self.topo.switches():
switch = self.nodes[ switchDpid ] switch = self.nodes[ switchDpid ]
while not switch.intfIsUp( switch.intfs[ 0 ] ): while not switch.intfIsUp( switch.intfs[ 0 ] ):
lg.info( '*** Waiting for %s to come up\n' % info( '*** Waiting for %s to come up\n' %
switch.intfs[ 0 ] ) switch.intfs[ 0 ] )
sleep( 1 ) sleep( 1 )
if self.ping( hosts=[ switch, controller ] ) != 0: if self.ping( hosts=[ switch, controller ] ) != 0:
lg.error( '*** Error: control network test failed\n' ) error( '*** Error: control network test failed\n' )
exit( 1 ) exit( 1 )
lg.info( '\n' ) info( '\n' )
def _configHosts( self ): def _configHosts( self ):
"Configure a set of hosts." "Configure a set of hosts."
@@ -250,8 +249,8 @@ class Mininet( object ):
host.setDefaultRoute( hintf ) host.setDefaultRoute( hintf )
# You're low priority, dude! # You're low priority, dude!
quietRun( 'renice +18 -p ' + repr( host.pid ) ) quietRun( 'renice +18 -p ' + repr( host.pid ) )
lg.info( '%s ', host.name ) info( '%s ', host.name )
lg.info( '\n' ) info( '\n' )
def build( self ): def build( self ):
"""Build mininet. """Build mininet.
@@ -260,28 +259,28 @@ class Mininet( object ):
if self.cleanup: if self.cleanup:
pass # cleanup pass # cleanup
# validate topo? # validate topo?
lg.info( '*** Adding controller\n' ) info( '*** Adding controller\n' )
self._addController( self.controller ) self._addController( self.controller )
lg.info( '*** Creating network\n' ) info( '*** Creating network\n' )
lg.info( '*** Adding hosts:\n' ) info( '*** Adding hosts:\n' )
for host in sorted( self.topo.hosts() ): for host in sorted( self.topo.hosts() ):
self._addHost( host ) self._addHost( host )
lg.info( '0x%x ' % host ) info( '0x%x ' % host )
lg.info( '\n*** Adding switches:\n' ) info( '\n*** Adding switches:\n' )
for switch in sorted( self.topo.switches() ): for switch in sorted( self.topo.switches() ):
self._addSwitch( switch ) self._addSwitch( switch )
lg.info( '0x%x ' % switch ) info( '0x%x ' % switch )
lg.info( '\n*** Adding edges:\n' ) info( '\n*** Adding edges:\n' )
for src, dst in sorted( self.topo.edges() ): for src, dst in sorted( self.topo.edges() ):
self._addLink( src, dst ) self._addLink( src, dst )
lg.info( '(0x%x, 0x%x) ' % ( src, dst ) ) info( '(0x%x, 0x%x) ' % ( src, dst ) )
lg.info( '\n' ) info( '\n' )
if self.inNamespace: if self.inNamespace:
lg.info( '*** Configuring control network\n' ) info( '*** Configuring control network\n' )
self._configureControlNetwork() self._configureControlNetwork()
lg.info( '*** Configuring hosts\n' ) info( '*** Configuring hosts\n' )
self._configHosts() self._configHosts()
if self.xterms: if self.xterms:
@@ -301,7 +300,7 @@ class Mininet( object ):
def startXterms( self ): def startXterms( self ):
"Start an xterm for each node in the topo." "Start an xterm for each node in the topo."
lg.info( "*** Running xterms on %s\n" % os.environ[ 'DISPLAY' ] ) info( "*** Running xterms on %s\n" % os.environ[ 'DISPLAY' ] )
cleanUpScreens() cleanUpScreens()
self.terms += makeXterms( self.controllers.values(), 'controller' ) self.terms += makeXterms( self.controllers.values(), 'controller' )
self.terms += makeXterms( self.switchNodes(), 'switch' ) self.terms += makeXterms( self.switchNodes(), 'switch' )
@@ -330,44 +329,44 @@ class Mininet( object ):
srcNode.setARP( dst, dst ) srcNode.setARP( dst, dst )
def start( self ): def start( self ):
"Start controller and switches\n" "Start controller and switches"
lg.info( '*** Starting controller\n' ) info( '*** Starting controller\n' )
for cnode in self.controllers.values(): for cnode in self.controllers.values():
cnode.start() cnode.start()
lg.info( '*** Starting %s switches\n' % len( self.topo.switches() ) ) info( '*** Starting %s switches\n' % len( self.topo.switches() ) )
for switchDpid in self.topo.switches(): for switchDpid in self.topo.switches():
switch = self.nodes[ switchDpid ] switch = self.nodes[ switchDpid ]
#lg.info( 'switch = %s' % switch ) #info( 'switch = %s' % switch )
lg.info( '0x%x ' % switchDpid ) info( '0x%x ' % switchDpid )
switch.start( self.controllers ) switch.start( self.controllers )
lg.info( '\n' ) info( '\n' )
def stop( self ): def stop( self ):
"Stop the controller(s), switches and hosts\n" "Stop the controller(s), switches and hosts"
if self.terms: if self.terms:
lg.info( '*** Stopping %i terms\n' % len( self.terms ) ) info( '*** Stopping %i terms\n' % len( self.terms ) )
self.stopXterms() self.stopXterms()
lg.info( '*** Stopping %i hosts\n' % len( self.topo.hosts() ) ) info( '*** Stopping %i hosts\n' % len( self.topo.hosts() ) )
for hostDpid in self.topo.hosts(): for hostDpid in self.topo.hosts():
host = self.nodes[ hostDpid ] host = self.nodes[ hostDpid ]
lg.info( '%s ' % host.name ) info( '%s ' % host.name )
host.terminate() host.terminate()
lg.info( '\n' ) info( '\n' )
lg.info( '*** Stopping %i switches\n' % len( self.topo.switches() ) ) info( '*** Stopping %i switches\n' % len( self.topo.switches() ) )
for switchDpid in self.topo.switches(): for switchDpid in self.topo.switches():
switch = self.nodes[ switchDpid ] switch = self.nodes[ switchDpid ]
lg.info( '%s' % switch.name ) info( '%s' % switch.name )
switch.stop() switch.stop()
lg.info( '\n' ) info( '\n' )
lg.info( '*** Stopping controller\n' ) info( '*** Stopping controller\n' )
for cnode in self.controllers.values(): for cnode in self.controllers.values():
cnode.stop() cnode.stop()
lg.info( '*** Test complete\n' ) info( '*** Test complete\n' )
def run( self, test, **params ): def run( self, test, **params ):
"Perform a complete start/test/stop cycle." "Perform a complete start/test/stop cycle."
self.start() self.start()
lg.info( '*** Running test\n' ) info( '*** Running test\n' )
result = getattr( self, test )( **params ) result = getattr( self, test )( **params )
self.stop() self.stop()
return result return result
@@ -378,7 +377,7 @@ class Mininet( object ):
r = r'(\d+) packets transmitted, (\d+) received' r = r'(\d+) packets transmitted, (\d+) received'
m = re.search( r, pingOutput ) m = re.search( r, pingOutput )
if m == None: if m == None:
lg.error( '*** Error: could not parse ping output: %s\n' % error( '*** Error: could not parse ping output: %s\n' %
pingOutput ) pingOutput )
exit( 1 ) exit( 1 )
sent, received = int( m.group( 1 ) ), int( m.group( 2 ) ) sent, received = int( m.group( 1 ) ), int( m.group( 2 ) )
@@ -395,10 +394,10 @@ class Mininet( object ):
ploss = None ploss = None
if not hosts: if not hosts:
hosts = self.topo.hosts() hosts = self.topo.hosts()
lg.info( '*** Ping: testing ping reachability\n' ) info( '*** Ping: testing ping reachability\n' )
for nodeDpid in hosts: for nodeDpid in hosts:
node = self.nodes[ nodeDpid ] node = self.nodes[ nodeDpid ]
lg.info( '%s -> ' % node.name ) info( '%s -> ' % node.name )
for destDpid in hosts: for destDpid in hosts:
dest = self.nodes[ destDpid ] dest = self.nodes[ destDpid ]
if node != dest: if node != dest:
@@ -406,15 +405,15 @@ class Mininet( object ):
sent, received = self._parsePing( result ) sent, received = self._parsePing( result )
packets += sent packets += sent
if received > sent: if received > sent:
lg.error( '*** Error: received too many packets' ) error( '*** Error: received too many packets' )
lg.error( '%s' % result ) error( '%s' % result )
node.cmdPrint( 'route' ) node.cmdPrint( 'route' )
exit( 1 ) exit( 1 )
lost += sent - received lost += sent - received
lg.info( ( '%s ' % dest.name ) if received else 'X ' ) info( ( '%s ' % dest.name ) if received else 'X ' )
lg.info( '\n' ) info( '\n' )
ploss = 100 * lost / packets ploss = 100 * lost / packets
lg.info( "*** Results: %i%% dropped (%d/%d lost)\n" % info( "*** Results: %i%% dropped (%d/%d lost)\n" %
( ploss, lost, packets ) ) ( ploss, lost, packets ) )
return ploss return ploss
@@ -456,8 +455,8 @@ class Mininet( object ):
assert len( hosts ) == 2 assert len( hosts ) == 2
host0 = self.nodes[ hosts[ 0 ] ] host0 = self.nodes[ hosts[ 0 ] ]
host1 = self.nodes[ hosts[ 1 ] ] host1 = self.nodes[ hosts[ 1 ] ]
lg.info( '*** Iperf: testing ' + l4Type + ' bandwidth between ' ) info( '*** Iperf: testing ' + l4Type + ' bandwidth between ' )
lg.info( "%s and %s\n" % ( host0.name, host1.name ) ) info( "%s and %s\n" % ( host0.name, host1.name ) )
host0.cmd( 'killall -9 iperf' ) host0.cmd( 'killall -9 iperf' )
iperfArgs = 'iperf ' iperfArgs = 'iperf '
bwArgs = '' bwArgs = ''
@@ -468,18 +467,18 @@ class Mininet( object ):
raise Exception( 'Unexpected l4 type: %s' % l4Type ) raise Exception( 'Unexpected l4 type: %s' % l4Type )
server = host0.cmd( iperfArgs + '-s &' ) server = host0.cmd( iperfArgs + '-s &' )
if verbose: if verbose:
lg.info( '%s\n' % server ) info( '%s\n' % server )
client = host1.cmd( iperfArgs + '-t 5 -c ' + host0.IP() + ' ' + client = host1.cmd( iperfArgs + '-t 5 -c ' + host0.IP() + ' ' +
bwArgs ) bwArgs )
if verbose: if verbose:
lg.info( '%s\n' % client ) info( '%s\n' % client )
server = host0.cmd( 'killall -9 iperf' ) server = host0.cmd( 'killall -9 iperf' )
if verbose: if verbose:
lg.info( '%s\n' % server ) info( '%s\n' % server )
result = [ self._parseIperf( server ), self._parseIperf( client ) ] result = [ self._parseIperf( server ), self._parseIperf( client ) ]
if l4Type == 'UDP': if l4Type == 'UDP':
result.insert( 0, udpBw ) result.insert( 0, udpBw )
lg.info( '*** Results: %s\n' % result ) info( '*** Results: %s\n' % result )
return result return result
def iperfUdp( self, udpBw='10M' ): def iperfUdp( self, udpBw='10M' ):