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