print -> info; end the horror of print vs. print()

Although we could use print() from __future__, this messes
up scripts which use examples as modules.

The simple, if not nicest for 2.7, solution is to use
info(), output() and other mininet.log functions. The disadvantage
is that we may have to adjust things if we change info() to
add automatic newlines, but we can burn that bridge in Mininet
3.x.
This commit is contained in:
Bob Lantz
2016-08-23 01:54:54 -07:00
parent 1eb6f65e40
commit ee15ce2243
18 changed files with 128 additions and 132 deletions
+10 -9
View File
@@ -6,31 +6,32 @@ import sys
from mininet.node import Host
from mininet.util import ensureRoot, waitListening
from mininet.log import info, warn, output
ensureRoot()
timeout = 5
print( "*** Creating nodes" )
info( "*** Creating nodes\n" )
h1 = Host( 'h1' )
root = Host( 'root', inNamespace=False )
print( "*** Creating links" )
info( "*** Creating link\n" )
h1.linkTo( root )
print( h1 )
info( h1 )
print( "*** Configuring nodes" )
info( "*** Configuring nodes\n" )
h1.setIP( '10.0.0.1', 8 )
root.setIP( '10.0.0.2', 8 )
print( "*** Creating banner file" )
info( "*** Creating banner file\n" )
f = open( '/tmp/%s.banner' % h1.name, 'w' )
f.write( 'Welcome to %s at %s\n' % ( h1.name, h1.IP() ) )
f.close()
print( "*** Running sshd" )
info( "*** Running sshd\n" )
cmd = '/usr/sbin/sshd -o UseDNS=no -u0 -o "Banner /tmp/%s.banner"' % h1.name
# add arguments from the command line
if len( sys.argv ) > 1:
@@ -39,7 +40,7 @@ h1.cmd( cmd )
listening = waitListening( server=h1, port=22, timeout=timeout )
if listening:
print( "*** You may now ssh into", h1.name, "at", h1.IP() )
output( "*** You may now ssh into", h1.name, "at", h1.IP(), '\n' )
else:
print( "*** Warning: after %s seconds, %s is not listening on port 22"
% ( timeout, h1.name ) )
warn( "*** Warning: after %s seconds, %s is not listening on port 22"
% ( timeout, h1.name ), '\n' )
+9 -9
View File
@@ -15,46 +15,46 @@ the Mininet() constructor.
from mininet.net import Mininet
from mininet.node import Controller, OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.log import setLogLevel, info
def multiControllerNet():
"Create a network from semi-scratch with multiple controllers."
net = Mininet( controller=Controller, switch=OVSSwitch )
print( "*** Creating (reference) controllers" )
info( "*** Creating (reference) controllers\n" )
c1 = net.addController( 'c1', port=6633 )
c2 = net.addController( 'c2', port=6634 )
print( "*** Creating switches" )
info( "*** Creating switches\n" )
s1 = net.addSwitch( 's1' )
s2 = net.addSwitch( 's2' )
print( "*** Creating hosts" )
info( "*** Creating hosts\n" )
hosts1 = [ net.addHost( 'h%d' % n ) for n in ( 3, 4 ) ]
hosts2 = [ net.addHost( 'h%d' % n ) for n in ( 5, 6 ) ]
print( "*** Creating links" )
info( "*** Creating links\n" )
for h in hosts1:
net.addLink( s1, h )
for h in hosts2:
net.addLink( s2, h )
net.addLink( s1, s2 )
print( "*** Starting network" )
info( "*** Starting network\n" )
net.build()
c1.start()
c2.start()
s1.start( [ c1 ] )
s2.start( [ c2 ] )
print( "*** Testing network" )
info( "*** Testing network\n" )
net.pingAll()
print( "*** Running CLI" )
info( "*** Running CLI\n" )
CLI( net )
print( "*** Stopping network" )
info( "*** Stopping network\n" )
net.stop()
if __name__ == '__main__':
+4 -6
View File
@@ -21,7 +21,7 @@ def bwtest( cpuLimits, period_us=100000, seconds=5 ):
results = {}
for sched in 'rt', 'cfs':
print( '*** Testing with', sched, 'bandwidth limiting' )
info( '*** Testing with', sched, 'bandwidth limiting\n' )
for cpu in cpuLimits:
host = custom( CPULimitedHost, sched=sched,
period_us=period_us,
@@ -53,18 +53,16 @@ def bwtest( cpuLimits, period_us=100000, seconds=5 ):
def dump( results ):
"Dump results"
fmt = '%s\t%s\t%s'
fmt = '%s\t%s\t%s\n'
print()
print( fmt % ( 'sched', 'cpu', 'client MB/s' ) )
print()
info( '\n', fmt % ( 'sched', 'cpu', 'client MB/s' ) )
for sched in sorted( results.keys() ):
entries = results[ sched ]
for cpu, bps in entries:
pct = '%.2f%%' % ( cpu * 100 )
mbps = bps / 1e6
print( fmt % ( sched, pct, mbps ) )
info( fmt % ( sched, pct, mbps ) )
if __name__ == '__main__':
+13 -15
View File
@@ -27,7 +27,7 @@ of switches, this example demonstrates:
from mininet.net import Mininet
from mininet.node import UserSwitch, OVSKernelSwitch, Controller
from mininet.topo import Topo
from mininet.log import lg
from mininet.log import lg, info
from mininet.util import irange, quietRun
from mininet.link import TCLink
from functools import partial
@@ -84,7 +84,7 @@ def linearBandwidthTest( lengths ):
assert 'reno' in output
for datapath in switches.keys():
print( "*** testing", datapath, "datapath" )
info( "*** testing", datapath, "datapath\n" )
Switch = switches[ datapath ]
results[ datapath ] = []
link = partial( TCLink, delay='1ms' )
@@ -92,36 +92,34 @@ def linearBandwidthTest( lengths ):
controller=Controller, waitConnected=True,
link=link )
net.start()
print( "*** testing basic connectivity" )
info( "*** testing basic connectivity\n" )
for n in lengths:
net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] )
print( "*** testing bandwidth" )
info( "*** testing bandwidth\n" )
for n in lengths:
src, dst = net.hosts[ 0 ], net.hosts[ n ]
# Try to prime the pump to reduce PACKET_INs during test
# since the reference controller is reactive
src.cmd( 'telnet', dst.IP(), '5001' )
print( "testing", src.name, "<->", dst.name )
info( "testing", src.name, "<->", dst.name, '\n' )
bandwidth = net.iperf( [ src, dst ], seconds=10 )
print( bandwidth )
info( bandwidth, '\n' )
flush()
results[ datapath ] += [ ( n, bandwidth ) ]
net.stop()
for datapath in switches.keys():
print()
print( "*** Linear network results for", datapath, "datapath:" )
print()
info( "\n*** Linear network results for", datapath, "datapath:\n" )
result = results[ datapath ]
print( "SwitchCount\tiperf Results" )
info( "SwitchCount\tiperf Results\n" )
for switchCount, bandwidth in result:
print( switchCount, '\t\t' )
print( bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client' )
print()
print()
info( switchCount, '\t\t' )
info( bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client\n' )
info( '\n')
info( '\n' )
if __name__ == '__main__':
lg.setLogLevel( 'info' )
sizes = [ 1, 10, 20, 40, 60, 80 ]
print( "*** Running linearBandwidthTest", sizes )
info( "*** Running linearBandwidthTest", sizes, '\n' )
linearBandwidthTest( sizes )
+1 -1
View File
@@ -82,7 +82,7 @@ def run():
net = Mininet( topo=topo ) # controller is used by s1-s3
net.start()
info( '*** Routing Table on Router:\n' )
print( net[ 'r0' ].cmd( 'route' ) )
info( net[ 'r0' ].cmd( 'route' ) )
CLI( net )
net.stop()
+41 -41
View File
@@ -45,7 +45,7 @@ if 'PYTHONPATH' in os.environ:
# someday: from ttk import *
from mininet.log import info, setLogLevel
from mininet.log import info, debug, setLogLevel
from mininet.net import Mininet, VERSION
from mininet.util import netParse, ipAdd, quietRun
from mininet.util import buildTopo
@@ -60,7 +60,7 @@ from mininet.moduledeps import moduleDeps
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
from mininet.topolib import TreeTopo
print( 'MiniEdit running against Mininet '+VERSION )
info( 'MiniEdit running against Mininet '+VERSION, '\n' )
MININET_VERSION = re.sub(r'[^\d\.]', '', VERSION)
if StrictVersion(MININET_VERSION) > StrictVersion('2.0'):
from mininet.node import IVSSwitch
@@ -383,10 +383,10 @@ class PrefsDialog(tkSimpleDialog.Dialog):
r = r'ovs_version: "(.*)"'
m = re.search(r, outp)
if m is None:
print( 'Version check failed' )
warn( 'Version check failed' )
return None
else:
print( 'Open vSwitch version is '+m.group(1) )
info( 'Open vSwitch version is '+m.group(1), '\n' )
return m.group(1)
@@ -755,7 +755,7 @@ class SwitchDialog(CustomDialog):
def apply(self):
externalInterfaces = []
for row in range(self.tableFrame.rows):
# print( 'Interface is ' + self.tableFrame.get(row, 0) )
# debug( 'Interface is ' + self.tableFrame.get(row, 0), '\n' )
if len(self.tableFrame.get(row, 0)) > 0:
externalInterfaces.append(self.tableFrame.get(row, 0))
@@ -866,7 +866,7 @@ class TableFrame(Frame):
return widget.get()
def addRow( self, value=None, readonly=False ):
# print( "Adding row " + str(self.rows +1) )
# debug( "Adding row " + str(self.rows +1), '\n' )
current_row = []
for column in range(self.columns):
label = Entry(self, borderwidth=0)
@@ -1669,7 +1669,7 @@ class MiniEdit( Frame ):
f.write(json.dumps(savingDictionary, sort_keys=True, indent=4, separators=(',', ': ')))
# pylint: disable=broad-except
except Exception as er:
print( er )
warn( er, '\n' )
# pylint: enable=broad-except
finally:
f.close()
@@ -1683,7 +1683,7 @@ class MiniEdit( Frame ):
fileName = tkFileDialog.asksaveasfilename(filetypes=myFormats ,title="Export the topology as...")
if len(fileName ) > 0:
# print( "Now saving under %s" % fileName )
# debug( "Now saving under %s\n" % fileName )
f = open(fileName, 'wb')
f.write("#!/usr/bin/python\n")
@@ -2489,7 +2489,7 @@ class MiniEdit( Frame ):
if len(hostBox.result['privateDirectory']) > 0:
newHostOpts['privateDirectory'] = hostBox.result['privateDirectory']
self.hostOpts[name] = newHostOpts
print( 'New host details for ' + name + ' = ' + str(newHostOpts) )
info( 'New host details for ' + name + ' = ' + str(newHostOpts), '\n' )
def switchDetails( self, _ignore=None ):
if ( self.selection is None or
@@ -2527,7 +2527,7 @@ class MiniEdit( Frame ):
newSwitchOpts['sflow'] = switchBox.result['sflow']
newSwitchOpts['netflow'] = switchBox.result['netflow']
self.switchOpts[name] = newSwitchOpts
print( 'New switch details for ' + name + ' = ' + str(newSwitchOpts) )
info( 'New switch details for ' + name + ' = ' + str(newSwitchOpts), '\n' )
def linkUp( self ):
if ( self.selection is None or
@@ -2566,12 +2566,12 @@ class MiniEdit( Frame ):
linkBox = LinkDialog(self, title='Link Details', linkDefaults=linkopts)
if linkBox.result is not None:
linkDetail['linkOpts'] = linkBox.result
print( 'New link details = ' + str(linkBox.result) )
info( 'New link details = ' + str(linkBox.result), '\n' )
def prefDetails( self ):
prefDefaults = self.appPrefs
prefBox = PrefsDialog(self, title='Preferences', prefDefaults=prefDefaults)
print( 'New Prefs = ' + str(prefBox.result) )
info( 'New Prefs = ' + str(prefBox.result), '\n' )
if prefBox.result:
self.appPrefs = prefBox.result
@@ -2590,14 +2590,14 @@ class MiniEdit( Frame ):
ctrlrBox = ControllerDialog(self, title='Controller Details', ctrlrDefaults=self.controllers[name])
if ctrlrBox.result:
# print( 'Controller is ' + ctrlrBox.result[0] )
# debug( 'Controller is ' + ctrlrBox.result[0], '\n' )
if len(ctrlrBox.result['hostname']) > 0:
name = ctrlrBox.result['hostname']
widget[ 'text' ] = name
else:
ctrlrBox.result['hostname'] = name
self.controllers[name] = ctrlrBox.result
print( 'New controller details for ' + name + ' = ' + str(self.controllers[name]) )
info( 'New controller details for ' + name + ' = ' + str(self.controllers[name]), '\n' )
# Find references to controller and change name
if oldName != name:
for widget in self.widgetToItem:
@@ -2698,15 +2698,15 @@ class MiniEdit( Frame ):
def buildNodes( self, net):
# Make nodes
print( "Getting Hosts and Switches." )
info( "Getting Hosts and Switches.\n" )
for widget in self.widgetToItem:
name = widget[ 'text' ]
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
# print( name+' has '+str(tags) )
# debug( name+' has '+str(tags), '\n' )
if 'Switch' in tags:
opts = self.switchOpts[name]
# print( str(opts) )
# debug( str(opts), '\n' )
# Create the correct switch class
switchClass = customOvs
@@ -2772,7 +2772,7 @@ class MiniEdit( Frame ):
newSwitch = net.addHost( name , cls=LegacyRouter)
elif 'Host' in tags:
opts = self.hostOpts[name]
# print( str(opts) )
# debug( str(opts), '\n' )
ip = None
defaultRoute = None
if 'defaultRoute' in opts and len(opts['defaultRoute']) > 0:
@@ -2797,7 +2797,7 @@ class MiniEdit( Frame ):
privateDirs=opts['privateDirectory'] )
else:
hostCls=Host
print( hostCls )
debug( hostCls, '\n' )
newHost = net.addHost( name,
cls=hostCls,
ip=ip,
@@ -2817,7 +2817,7 @@ class MiniEdit( Frame ):
Intf( extInterface, node=newHost )
if 'vlanInterfaces' in opts:
if len(opts['vlanInterfaces']) > 0:
print( 'Checking that OS is VLAN prepared' )
info( 'Checking that OS is VLAN prepared\n' )
self.pathCheck('vconfig', moduleName='vlan package')
moduleDeps( add='8021q' )
elif 'Controller' in tags:
@@ -2834,7 +2834,7 @@ class MiniEdit( Frame ):
controllerPort = opts['remotePort']
# Make controller
print( 'Getting controller selection:'+controllerType )
info( 'Getting controller selection:'+controllerType, '\n' )
if controllerType == 'remote':
net.addController(name=name,
controller=RemoteController,
@@ -2874,7 +2874,7 @@ class MiniEdit( Frame ):
def buildLinks( self, net):
# Make links
print( "Getting Links." )
info( "Getting Links.\n" )
for key,link in self.links.iteritems():
tags = self.canvas.gettags(key)
if 'data' in tags:
@@ -2886,14 +2886,14 @@ class MiniEdit( Frame ):
if linkopts:
net.addLink(srcNode, dstNode, cls=TCLink, **linkopts)
else:
# print( str(srcNode) )
# print( str(dstNode) )
# debug( str(srcNode) )
# debug( str(dstNode), '\n' )
net.addLink(srcNode, dstNode)
self.canvas.itemconfig(key, dash=())
def build( self ):
print( "Build network based on our topology." )
"Build network based on our topology."
dpctl = None
if len(self.appPrefs['dpctl']) > 0:
@@ -2924,7 +2924,7 @@ class MiniEdit( Frame ):
# Attach vlan interfaces
if 'vlanInterfaces' in opts:
for vlanInterface in opts['vlanInterfaces']:
print( 'adding vlan interface '+vlanInterface[1] )
info( 'adding vlan interface '+vlanInterface[1], '\n' )
newHost.cmdPrint('ifconfig '+name+'-eth0.'+vlanInterface[1]+' '+vlanInterface[0])
# Run User Defined Start Command
if 'startCommand' in opts:
@@ -2950,7 +2950,7 @@ class MiniEdit( Frame ):
opts = self.switchOpts[name]
if 'netflow' in opts:
if opts['netflow'] == '1':
print( name+' has Netflow enabled' )
info( name+' has Netflow enabled\n' )
nflowSwitches = nflowSwitches+' -- set Bridge '+name+' netflow=@MiniEditNF'
nflowEnabled=True
if nflowEnabled:
@@ -2959,13 +2959,13 @@ class MiniEdit( Frame ):
nflowCmd = nflowCmd + ' add_id_to_interface=true'
else:
nflowCmd = nflowCmd + ' add_id_to_interface=false'
print( 'cmd = '+nflowCmd+nflowSwitches )
info( 'cmd = '+nflowCmd+nflowSwitches, '\n' )
call(nflowCmd+nflowSwitches, shell=True)
else:
print( 'No switches with Netflow' )
info( 'No switches with Netflow\n' )
else:
print( 'No NetFlow targets specified.' )
info( 'No NetFlow targets specified.\n' )
# Configure sFlow
sflowValues = self.appPrefs['sflow']
@@ -2980,18 +2980,18 @@ class MiniEdit( Frame ):
opts = self.switchOpts[name]
if 'sflow' in opts:
if opts['sflow'] == '1':
print( name+' has sflow enabled' )
info( name+' has sflow enabled\n' )
sflowSwitches = sflowSwitches+' -- set Bridge '+name+' sflow=@MiniEditSF'
sflowEnabled=True
if sflowEnabled:
sflowCmd = 'ovs-vsctl -- --id=@MiniEditSF create sFlow '+ 'target=\\\"'+sflowValues['sflowTarget']+'\\\" '+ 'header='+sflowValues['sflowHeader']+' '+ 'sampling='+sflowValues['sflowSampling']+' '+ 'polling='+sflowValues['sflowPolling']
print( 'cmd = '+sflowCmd+sflowSwitches )
info( 'cmd = '+sflowCmd+sflowSwitches, '\n' )
call(sflowCmd+sflowSwitches, shell=True)
else:
print( 'No switches with sflow' )
info( 'No switches with sflow\n' )
else:
print( 'No sFlow targets specified.' )
info( 'No sFlow targets specified.\n' )
## NOTE: MAKE SURE THIS IS LAST THING CALLED
# Start the CLI if enabled
@@ -3217,7 +3217,7 @@ class MiniEdit( Frame ):
raise Exception( 'could not find custom file: %s' % fileName )
def importTopo( self ):
print( 'topo='+self.options.topo )
info( 'topo='+self.options.topo, '\n' )
if self.options.topo == 'none':
return
self.newTopology()
@@ -3231,7 +3231,7 @@ class MiniEdit( Frame ):
currentY = 100
# Add Controllers
print( 'controllers:'+str(len(importNet.controllers)) )
info( 'controllers:'+str(len(importNet.controllers)), '\n' )
for controller in importNet.controllers:
name = controller.name
x = self.controllerCount*100+100
@@ -3251,7 +3251,7 @@ class MiniEdit( Frame ):
currentY = currentY + rowIncrement
# Add switches
print( 'switches:'+str(len(importNet.switches)) )
info( 'switches:'+str(len(importNet.switches)), '\n' )
columnCount = 0
for switch in importNet.switches:
name = switch.name
@@ -3292,7 +3292,7 @@ class MiniEdit( Frame ):
currentY = currentY + rowIncrement
# Add hosts
print( 'hosts:'+str(len(importNet.hosts)) )
info( 'hosts:'+str(len(importNet.hosts)), '\n' )
columnCount = 0
for host in importNet.hosts:
name = host.name
@@ -3312,10 +3312,10 @@ class MiniEdit( Frame ):
else:
columnCount =columnCount+1
print( 'links:'+str(len(topo.links())) )
info( 'links:'+str(len(topo.links())), '\n' )
#[('h1', 's3'), ('h2', 's4'), ('s3', 's4')]
for link in topo.links():
print( str(link) )
info( str(link), '\n' )
srcNode = link[0]
src = self.findWidgetByName(srcNode)
sx, sy = self.canvas.coords( self.widgetToItem[ src ] )
@@ -3325,7 +3325,7 @@ class MiniEdit( Frame ):
dx, dy = self.canvas.coords( self.widgetToItem[ dest] )
params = topo.linkInfo( srcNode, destNode )
print( 'Link Parameters='+str(params) )
info( 'Link Parameters='+str(params), '\n' )
self.link = self.canvas.create_line( sx, sy, dx, dy, width=4,
fill='blue', tag='link' )
+11 -10
View File
@@ -23,7 +23,7 @@ to-do:
from mininet.net import Mininet
from mininet.node import OVSSwitch
from mininet.topo import LinearTopo
from mininet.log import output, warn
from mininet.log import info, output, warn, setLogLevel
from random import randint
@@ -106,30 +106,31 @@ def moveHost( host, oldSwitch, newSwitch, newPort=None ):
def mobilityTest():
"A simple test of mobility"
print( '* Simple mobility test' )
info( '* Simple mobility test\n' )
net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch )
print( '* Starting network:' )
info( '* Starting network:\n' )
net.start()
printConnections( net.switches )
print( '* Testing network' )
info( '* Testing network\n' )
net.pingAll()
print( '* Identifying switch interface for h1' )
info( '* Identifying switch interface for h1\n' )
h1, old = net.get( 'h1', 's1' )
for s in 2, 3, 1:
new = net[ 's%d' % s ]
port = randint( 10, 20 )
print( '* Moving', h1, 'from', old, 'to', new, 'port', port )
info( '* Moving', h1, 'from', old, 'to', new, 'port', port, '\n' )
hintf, sintf = moveHost( h1, old, new, newPort=port )
print( '*', hintf, 'is now connected to', sintf )
print( '* Clearing out old flows' )
info( '*', hintf, 'is now connected to', sintf, '\n' )
info( '* Clearing out old flows\n' )
for sw in net.switches:
sw.dpctl( 'del-flows' )
print( '* New network:' )
info( '* New network:\n' )
printConnections( net.switches )
print( '* Testing connectivity:' )
info( '* Testing connectivity:\n' )
net.pingAll()
old = new
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
mobilityTest()
+4 -4
View File
@@ -12,7 +12,7 @@ of time.
from mininet.net import Mininet
from mininet.node import Node
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel
from mininet.log import info, setLogLevel
from select import poll, POLLIN
from time import time
@@ -35,8 +35,8 @@ def startpings( host, targetips ):
' done; '
'done &' )
print( '*** Host %s (%s) will be pinging ips: %s' %
( host.name, host.IP(), targetips ) )
info( '*** Host %s (%s) will be pinging ips: %s\n' %
( host.name, host.IP(), targetips ) )
host.cmd( cmd )
@@ -70,7 +70,7 @@ def multiping( netsize, chunksize, seconds):
readable = poller.poll(1000)
for fd, _mask in readable:
node = Node.outToNode[ fd ]
print( '%s:' % node.name, node.monitor().strip() )
info( '%s:' % node.name, node.monitor().strip(), '\n' )
# Stop pings
for host in hosts:
+4 -4
View File
@@ -8,7 +8,7 @@ monitoring them
from mininet.topo import SingleSwitchTopo
from mininet.net import Mininet
from mininet.log import setLogLevel
from mininet.log import info, setLogLevel
from time import time
from select import poll, POLLIN
@@ -55,7 +55,7 @@ def monitorTest( N=3, seconds=3 ):
net = Mininet( topo )
net.start()
hosts = net.hosts
print( "Starting test..." )
info( "Starting test...\n" )
server = hosts[ 0 ]
outfiles, errfiles = {}, {}
for h in hosts:
@@ -69,10 +69,10 @@ def monitorTest( N=3, seconds=3 ):
'>', outfiles[ h ],
'2>', errfiles[ h ],
'&' )
print( "Monitoring output for", seconds, "seconds" )
info( "Monitoring output for", seconds, "seconds\n" )
for h, line in monitorFiles( outfiles, seconds, timeoutms=500 ):
if h:
print( '%s: %s' % ( h.name, line ) )
info( '%s: %s\n' % ( h.name, line ) )
for h in hosts:
h.cmd('kill %ping')
net.stop()
+3 -3
View File
@@ -6,7 +6,7 @@ Example to create a Mininet topology and connect it to the internet via NAT
from mininet.cli import CLI
from mininet.log import lg
from mininet.log import lg, info
from mininet.topolib import TreeNet
@@ -16,8 +16,8 @@ if __name__ == '__main__':
# Add NAT connectivity
net.addNAT().configDefault()
net.start()
print( "*** Hosts are running and should have internet connectivity" )
print( "*** Type 'exit' or control-D to shut down network" )
info( "*** Hosts are running and should have internet connectivity\n" )
info( "*** Type 'exit' or control-D to shut down network\n" )
CLI( net )
# Shut down NAT
net.stop()
+3 -3
View File
@@ -66,13 +66,13 @@ def testPortNumbering():
'is actually on port', s1.ports[intfs], '... ' )
if validatePort( s1, intfs ):
info( 'Validated.\n' )
print( '\n' )
info( '\n' )
# test the network with pingall
net.pingAll()
print( '\n' )
info( '\n' )
info( '*** Stopping network' )
info( '*** Stopping network\n' )
net.stop()
if __name__ == '__main__':
+2 -2
View File
@@ -9,7 +9,7 @@ pmonitor()
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel
from mininet.log import setLogLevel, info
from mininet.util import custom, pmonitor
def monitorhosts( hosts=5, sched='cfs' ):
@@ -28,7 +28,7 @@ def monitorhosts( hosts=5, sched='cfs' ):
# Monitor them and print output
for host, line in pmonitor( popens ):
if host:
print( "<%s>: %s" % ( host.name, line.strip() ) )
info( "<%s>: %s" % ( host.name, line ) )
# Done
net.stop()
+6 -5
View File
@@ -2,34 +2,35 @@
"Monitor multiple hosts using popen()/pmonitor()"
from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo
from mininet.util import pmonitor
from mininet.log import setLogLevel, info
from time import time
from signal import SIGINT
def pmonitorTest( N=3, seconds=10 ):
"Run pings and monitor multiple hosts using pmonitor"
topo = SingleSwitchTopo( N )
net = Mininet( topo )
net.start()
hosts = net.hosts
print( "Starting test..." )
info( "Starting test...\n" )
server = hosts[ 0 ]
popens = {}
for h in hosts:
popens[ h ] = h.popen('ping', server.IP() )
print( "Monitoring output for", seconds, "seconds" )
info( "Monitoring output for", seconds, "seconds\n" )
endTime = time() + seconds
for h, line in pmonitor( popens, timeoutms=500 ):
if h:
print( '<%s>: %s' % ( h.name, line ) )
info( '<%s>: %s' % ( h.name, line ) )
if time() >= endTime:
for p in popens.values():
p.send_signal( SIGINT )
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
pmonitorTest()
+1 -1
View File
@@ -41,7 +41,7 @@ def scratchNet( cname='controller', cargs='-v ptcp:' ):
switch.cmd( 'ovs-vsctl del-br dp0' )
switch.cmd( 'ovs-vsctl add-br dp0' )
for intf in switch.intfs.values():
print( switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf ) )
switch.cmd( 'ovs-vsctl add-port dp0 %s\n' % intf )
# Note: controller and switch are in root namespace, and we
# can connect via loopback interface
+3 -3
View File
@@ -15,7 +15,7 @@ from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.log import setLogLevel, info
from sys import argv
@@ -45,9 +45,9 @@ def perfTest( lossy=True ):
host=CPULimitedHost, link=TCLink,
autoStaticArp=True )
net.start()
print( "Dumping host connections" )
info( "Dumping host connections\n" )
dumpNodeConnections(net.hosts)
print( "Testing bandwidth between h1 and h4" )
info( "Testing bandwidth between h1 and h4\n" )
h1, h4 = net.getNodeByName('h1', 'h4')
net.iperf( ( h1, h4 ), l4Type='UDP' )
net.stop()
+5 -8
View File
@@ -20,7 +20,7 @@ import sys
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.log import lg
from mininet.log import lg, info
from mininet.node import Node
from mininet.topolib import TreeTopo
from mininet.util import waitListening
@@ -60,17 +60,14 @@ def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
connectToRootNS( network, switch, ip, routes )
for host in network.hosts:
host.cmd( cmd + ' ' + opts + '&' )
print( "*** Waiting for ssh daemons to start" )
info( "*** Waiting for ssh daemons to start\n" )
for server in network.hosts:
waitListening( server=server, port=22, timeout=5 )
print()
print( "*** Hosts are running sshd at the following addresses:" )
print()
info( "\n*** Hosts are running sshd at the following addresses:\n" )
for host in network.hosts:
print( host.name, host.IP() )
print()
print( "*** Type 'exit' or control-D to shut down network" )
info( host.name, host.IP(), '\n' )
info( "\n*** Type 'exit' or control-D to shut down network\n" )
CLI( network )
for host in network.hosts:
host.cmd( 'kill %' + cmd )
+3 -2
View File
@@ -16,7 +16,7 @@ class testMultiPoll( unittest.TestCase ):
"(h\d+): \d+ bytes from",
"Monitoring output for (\d+) seconds",
pexpect.EOF ]
pings = {}
pings, seconds = {}, -1
while True:
index = p.expect( opts )
if index == 0:
@@ -32,7 +32,8 @@ class testMultiPoll( unittest.TestCase ):
self.assertTrue( len( pings ) > 0 )
# make sure we have received at least one ping per second
for count in pings.values():
self.assertTrue( count >= seconds )
self.assertTrue( count >= seconds,
'%d pings < %d seconds' % ( count, seconds ) )
if __name__ == '__main__':
unittest.main()
+5 -6
View File
@@ -3,7 +3,7 @@
"Create a 64-node tree network, and test connectivity using ping."
from mininet.log import setLogLevel
from mininet.log import setLogLevel, info
from mininet.node import UserSwitch, OVSKernelSwitch # , KernelSwitch
from mininet.topolib import TreeNet
@@ -16,17 +16,16 @@ def treePing64():
'Open vSwitch kernel': OVSKernelSwitch }
for name in switches:
print( "*** Testing", name, "datapath" )
info( "*** Testing", name, "datapath\n" )
switch = switches[ name ]
network = TreeNet( depth=2, fanout=8, switch=switch )
result = network.run( network.pingAll )
results[ name ] = result
print()
print( "*** Tree network ping results:" )
info( "\n*** Tree network ping results:\n" )
for name in switches:
print( "%s: %d%% packet loss" % ( name, results[ name ] ) )
print()
info( "%s: %d%% packet loss\n" % ( name, results[ name ] ) )
info( '\n' )
if __name__ == '__main__':
setLogLevel( 'info' )