Use print function

This commit is contained in:
Brad Walker
2016-06-21 16:27:04 -07:00
committed by Bob Lantz
parent 57abd9baef
commit 70fcc45893
25 changed files with 189 additions and 141 deletions
+4 -3
View File
@@ -11,6 +11,7 @@ Example to pull custom params (topo, switch, etc.) from a file:
sudo mn --custom ~/mininet/custom/custom_example.py sudo mn --custom ~/mininet/custom/custom_example.py
""" """
from __future__ import print_function
from optparse import OptionParser from optparse import OptionParser
import os import os
import sys import sys
@@ -117,7 +118,7 @@ def addDictOption( opts, choicesDict, default, name, **kwargs ):
def version( *_args ): def version( *_args ):
"Print Mininet version and exit" "Print Mininet version and exit"
print "%s" % VERSION print( "%s" % VERSION )
exit() exit()
@@ -269,7 +270,7 @@ class MininetRunner( object ):
# set logging verbosity # set logging verbosity
if LEVELS[self.options.verbosity] > LEVELS['output']: if LEVELS[self.options.verbosity] > LEVELS['output']:
print ( '*** WARNING: selected verbosity level (%s) will hide CLI ' print( '*** WARNING: selected verbosity level (%s) will hide CLI '
'output!\n' 'output!\n'
'Please restart Mininet with -v [debug, info, output].' 'Please restart Mininet with -v [debug, info, output].'
% self.options.verbosity ) % self.options.verbosity )
@@ -331,7 +332,7 @@ class MininetRunner( object ):
inNamespace = self.options.innamespace inNamespace = self.options.innamespace
cluster = self.options.cluster cluster = self.options.cluster
if inNamespace and cluster: if inNamespace and cluster:
print "Please specify --innamespace OR --cluster" print( "Please specify --innamespace OR --cluster" )
exit() exit()
Net = MininetWithControlNet if inNamespace else Mininet Net = MininetWithControlNet if inNamespace else Mininet
cli = ClusterCLI if cluster else CLI cli = ClusterCLI if cluster else CLI
+11 -8
View File
@@ -2,33 +2,36 @@
"This example doesn't use OpenFlow, but attempts to run sshd in a namespace." "This example doesn't use OpenFlow, but attempts to run sshd in a namespace."
from __future__ import print_function
import sys import sys
from mininet.node import Host from mininet.node import Host
from mininet.util import ensureRoot, waitListening from mininet.util import ensureRoot, waitListening
ensureRoot() ensureRoot()
timeout = 5 timeout = 5
print "*** Creating nodes" print( "*** Creating nodes" )
h1 = Host( 'h1' ) h1 = Host( 'h1' )
root = Host( 'root', inNamespace=False ) root = Host( 'root', inNamespace=False )
print "*** Creating links" print( "*** Creating links" )
h1.linkTo( root ) h1.linkTo( root )
print h1 print( h1 )
print "*** Configuring nodes" print( "*** Configuring nodes" )
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" print( "*** Creating banner file" )
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" print( "*** Running sshd" )
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:
@@ -37,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() print( "*** You may now ssh into", h1.name, "at", h1.IP() )
else: else:
print ( "*** Warning: after %s seconds, %s is not listening on port 22" print( "*** Warning: after %s seconds, %s is not listening on port 22"
% ( timeout, h1.name ) ) % ( timeout, h1.name ) )
+13 -11
View File
@@ -74,6 +74,8 @@ Things to do:
- hifi support (e.g. delay compensation) - hifi support (e.g. delay compensation)
""" """
from __future__ import print_function
from mininet.node import Node, Host, OVSSwitch, Controller from mininet.node import Node, Host, OVSSwitch, Controller
from mininet.link import Link, Intf from mininet.link import Link, Intf
from mininet.net import Mininet from mininet.net import Mininet
@@ -238,7 +240,7 @@ class RemoteMixin( object ):
args: string or list of strings args: string or list of strings
returns: stdout and stderr""" returns: stdout and stderr"""
popen = self.rpopen( *cmd, **opts ) popen = self.rpopen( *cmd, **opts )
# print 'RCMD: POPEN:', popen # print( 'RCMD: POPEN:', popen )
# These loops are tricky to get right. # These loops are tricky to get right.
# Once the process exits, we can read # Once the process exits, we can read
# EOF twice if necessary. # EOF twice if necessary.
@@ -792,28 +794,28 @@ def testNsTunnels():
def testRemoteNet( remote='ubuntu2' ): def testRemoteNet( remote='ubuntu2' ):
"Test remote Node classes" "Test remote Node classes"
print '*** Remote Node Test' print( '*** Remote Node Test' )
net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch, net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch,
link=RemoteLink ) link=RemoteLink )
c0 = net.addController( 'c0' ) c0 = net.addController( 'c0' )
# Make sure controller knows its non-loopback address # Make sure controller knows its non-loopback address
Intf( 'eth0', node=c0 ).updateIP() Intf( 'eth0', node=c0 ).updateIP()
print "*** Creating local h1" print( "*** Creating local h1" )
h1 = net.addHost( 'h1' ) h1 = net.addHost( 'h1' )
print "*** Creating remote h2" print( "*** Creating remote h2" )
h2 = net.addHost( 'h2', server=remote ) h2 = net.addHost( 'h2', server=remote )
print "*** Creating local s1" print( "*** Creating local s1" )
s1 = net.addSwitch( 's1' ) s1 = net.addSwitch( 's1' )
print "*** Creating remote s2" print( "*** Creating remote s2" )
s2 = net.addSwitch( 's2', server=remote ) s2 = net.addSwitch( 's2', server=remote )
print "*** Adding links" print( "*** Adding links" )
net.addLink( h1, s1 ) net.addLink( h1, s1 )
net.addLink( s1, s2 ) net.addLink( s1, s2 )
net.addLink( h2, s2 ) net.addLink( h2, s2 )
net.start() net.start()
print 'Mininet is running on', quietRun( 'hostname' ).strip() print( 'Mininet is running on', quietRun( 'hostname' ).strip() )
for node in c0, h1, h2, s1, s2: for node in c0, h1, h2, s1, s2:
print 'Node', node, 'is running on', node.cmd( 'hostname' ).strip() print( 'Node', node, 'is running on', node.cmd( 'hostname' ).strip() )
net.pingAll() net.pingAll()
CLI( net ) CLI( net )
net.stop() net.stop()
@@ -900,9 +902,9 @@ def signalTest():
h.shell.send_signal( SIGINT ) h.shell.send_signal( SIGINT )
h.shell.poll() h.shell.poll()
if h.shell.returncode is None: if h.shell.returncode is None:
print 'OK: ', h, 'has not exited' print( 'OK: ', h, 'has not exited' )
else: else:
print 'FAILURE:', h, 'exited with code', h.shell.returncode print( 'FAILURE:', h, 'exited with code', h.shell.returncode )
h.stop() h.stop()
if __name__ == '__main__': if __name__ == '__main__':
+10 -8
View File
@@ -11,6 +11,8 @@ Note that one could also create a custom switch class and pass it into
the Mininet() constructor. the Mininet() constructor.
""" """
from __future__ import print_function
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
@@ -21,39 +23,39 @@ def multiControllerNet():
net = Mininet( controller=Controller, switch=OVSSwitch ) net = Mininet( controller=Controller, switch=OVSSwitch )
print "*** Creating (reference) controllers" print( "*** Creating (reference) controllers" )
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" print( "*** Creating switches" )
s1 = net.addSwitch( 's1' ) s1 = net.addSwitch( 's1' )
s2 = net.addSwitch( 's2' ) s2 = net.addSwitch( 's2' )
print "*** Creating hosts" print( "*** Creating hosts" )
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" print( "*** Creating links" )
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" print( "*** Starting network" )
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" print( "*** Testing network" )
net.pingAll() net.pingAll()
print "*** Running CLI" print( "*** Running CLI" )
CLI( net ) CLI( net )
print "*** Stopping network" print( "*** Stopping network" )
net.stop() net.stop()
if __name__ == '__main__': if __name__ == '__main__':
+7 -5
View File
@@ -4,6 +4,8 @@
cpu.py: test iperf bandwidth for varying cpu limits cpu.py: test iperf bandwidth for varying cpu limits
""" """
from __future__ import print_function
from mininet.net import Mininet from mininet.net import Mininet
from mininet.node import CPULimitedHost from mininet.node import CPULimitedHost
from mininet.topolib import TreeTopo from mininet.topolib import TreeTopo
@@ -20,7 +22,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' print( '*** Testing with', sched, 'bandwidth limiting' )
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,
@@ -54,16 +56,16 @@ def dump( results ):
fmt = '%s\t%s\t%s' fmt = '%s\t%s\t%s'
print print()
print fmt % ( 'sched', 'cpu', 'client MB/s' ) print( fmt % ( 'sched', 'cpu', 'client MB/s' ) )
print 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 ) print( fmt % ( sched, pct, mbps ) )
if __name__ == '__main__': if __name__ == '__main__':
+16 -14
View File
@@ -23,6 +23,8 @@ of switches, this example demonstrates:
""" """
from __future__ import print_function
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
@@ -83,7 +85,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" print( "*** testing", datapath, "datapath" )
Switch = switches[ datapath ] Switch = switches[ datapath ]
results[ datapath ] = [] results[ datapath ] = []
link = partial( TCLink, delay='1ms' ) link = partial( TCLink, delay='1ms' )
@@ -91,36 +93,36 @@ def linearBandwidthTest( lengths ):
controller=Controller, waitConnected=True, controller=Controller, waitConnected=True,
link=link ) link=link )
net.start() net.start()
print "*** testing basic connectivity" print( "*** testing basic connectivity" )
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" print( "*** testing bandwidth" )
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, print( "testing", src.name, "<->", dst.name )
bandwidth = net.iperf( [ src, dst ], seconds=10 ) bandwidth = net.iperf( [ src, dst ], seconds=10 )
print bandwidth print( bandwidth )
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 print()
print "*** Linear network results for", datapath, "datapath:" print( "*** Linear network results for", datapath, "datapath:" )
print print()
result = results[ datapath ] result = results[ datapath ]
print "SwitchCount\tiperf Results" print( "SwitchCount\tiperf Results" )
for switchCount, bandwidth in result: for switchCount, bandwidth in result:
print switchCount, '\t\t', print( switchCount, '\t\t' )
print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client' print( bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client' )
print print()
print print()
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 print( "*** Running linearBandwidthTest", sizes )
linearBandwidthTest( sizes ) linearBandwidthTest( sizes )
+4 -1
View File
@@ -27,12 +27,15 @@ Additional routes may be added to the router or hosts by
executing 'ip route' or 'route' commands on the router or hosts. executing 'ip route' or 'route' commands on the router or hosts.
""" """
from __future__ import print_function
from mininet.topo import Topo from mininet.topo import Topo
from mininet.net import Mininet from mininet.net import Mininet
from mininet.node import Node from mininet.node import Node
from mininet.log import setLogLevel, info from mininet.log import setLogLevel, info
from mininet.cli import CLI from mininet.cli import CLI
class LinuxRouter( Node ): class LinuxRouter( Node ):
"A Node with IP forwarding enabled." "A Node with IP forwarding enabled."
@@ -80,7 +83,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' ) print( net[ 'r0' ].cmd( 'route' ) )
CLI( net ) CLI( net )
net.stop() net.stop()
+41 -40
View File
@@ -20,6 +20,7 @@ OpenFlow icon from https://www.opennetworking.org/
MINIEDIT_VERSION = '2.2.0.1' MINIEDIT_VERSION = '2.2.0.1'
from __future__ import print_function
from optparse import OptionParser from optparse import OptionParser
# from Tkinter import * # from Tkinter import *
from Tkinter import ( Frame, Label, LabelFrame, Entry, OptionMenu, Checkbutton, from Tkinter import ( Frame, Label, LabelFrame, Entry, OptionMenu, Checkbutton,
@@ -60,7 +61,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 print( 'MiniEdit running against Mininet '+VERSION )
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 +384,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' print( 'Version check failed' )
return None return None
else: else:
print 'Open vSwitch version is '+m.group(1) print( 'Open vSwitch version is '+m.group(1) )
return m.group(1) return m.group(1)
@@ -755,7 +756,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) # print( 'Interface is ' + self.tableFrame.get(row, 0) )
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 +867,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) # print( "Adding row " + str(self.rows +1) )
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 +1670,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 print( er )
# pylint: enable=broad-except # pylint: enable=broad-except
finally: finally:
f.close() f.close()
@@ -1683,7 +1684,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 # print( "Now saving under %s" % fileName )
f = open(fileName, 'wb') f = open(fileName, 'wb')
f.write("#!/usr/bin/python\n") f.write("#!/usr/bin/python\n")
@@ -2489,7 +2490,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) print( 'New host details for ' + name + ' = ' + str(newHostOpts) )
def switchDetails( self, _ignore=None ): def switchDetails( self, _ignore=None ):
if ( self.selection is None or if ( self.selection is None or
@@ -2527,7 +2528,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) print( 'New switch details for ' + name + ' = ' + str(newSwitchOpts) )
def linkUp( self ): def linkUp( self ):
if ( self.selection is None or if ( self.selection is None or
@@ -2566,12 +2567,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) print( 'New link details = ' + str(linkBox.result) )
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) print( 'New Prefs = ' + str(prefBox.result) )
if prefBox.result: if prefBox.result:
self.appPrefs = prefBox.result self.appPrefs = prefBox.result
@@ -2590,14 +2591,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] # print( 'Controller is ' + ctrlrBox.result[0] )
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]) print( 'New controller details for ' + name + ' = ' + str(self.controllers[name]) )
# 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 +2699,15 @@ class MiniEdit( Frame ):
def buildNodes( self, net): def buildNodes( self, net):
# Make nodes # Make nodes
print "Getting Hosts and Switches." print( "Getting Hosts and Switches." )
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) # print( name+' has '+str(tags) )
if 'Switch' in tags: if 'Switch' in tags:
opts = self.switchOpts[name] opts = self.switchOpts[name]
#print str(opts) # print( str(opts) )
# Create the correct switch class # Create the correct switch class
switchClass = customOvs switchClass = customOvs
@@ -2772,7 +2773,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) # print( str(opts) )
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 +2798,7 @@ class MiniEdit( Frame ):
privateDirs=opts['privateDirectory'] ) privateDirs=opts['privateDirectory'] )
else: else:
hostCls=Host hostCls=Host
print hostCls print( hostCls )
newHost = net.addHost( name, newHost = net.addHost( name,
cls=hostCls, cls=hostCls,
ip=ip, ip=ip,
@@ -2817,7 +2818,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' print( 'Checking that OS is VLAN prepared' )
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 +2835,7 @@ class MiniEdit( Frame ):
controllerPort = opts['remotePort'] controllerPort = opts['remotePort']
# Make controller # Make controller
print 'Getting controller selection:'+controllerType print( 'Getting controller selection:'+controllerType )
if controllerType == 'remote': if controllerType == 'remote':
net.addController(name=name, net.addController(name=name,
controller=RemoteController, controller=RemoteController,
@@ -2874,7 +2875,7 @@ class MiniEdit( Frame ):
def buildLinks( self, net): def buildLinks( self, net):
# Make links # Make links
print "Getting Links." print( "Getting Links." )
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 +2887,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) # print( str(srcNode) )
#print str(dstNode) # print( str(dstNode) )
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." print( "Build network based on our topology." )
dpctl = None dpctl = None
if len(self.appPrefs['dpctl']) > 0: if len(self.appPrefs['dpctl']) > 0:
@@ -2924,7 +2925,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] print( 'adding vlan interface '+vlanInterface[1] )
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 +2951,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' print( name+' has Netflow enabled' )
nflowSwitches = nflowSwitches+' -- set Bridge '+name+' netflow=@MiniEditNF' nflowSwitches = nflowSwitches+' -- set Bridge '+name+' netflow=@MiniEditNF'
nflowEnabled=True nflowEnabled=True
if nflowEnabled: if nflowEnabled:
@@ -2959,13 +2960,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 print( 'cmd = '+nflowCmd+nflowSwitches )
call(nflowCmd+nflowSwitches, shell=True) call(nflowCmd+nflowSwitches, shell=True)
else: else:
print 'No switches with Netflow' print( 'No switches with Netflow' )
else: else:
print 'No NetFlow targets specified.' print( 'No NetFlow targets specified.' )
# Configure sFlow # Configure sFlow
sflowValues = self.appPrefs['sflow'] sflowValues = self.appPrefs['sflow']
@@ -2980,18 +2981,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' print( name+' has sflow enabled' )
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 print( 'cmd = '+sflowCmd+sflowSwitches )
call(sflowCmd+sflowSwitches, shell=True) call(sflowCmd+sflowSwitches, shell=True)
else: else:
print 'No switches with sflow' print( 'No switches with sflow' )
else: else:
print 'No sFlow targets specified.' print( 'No sFlow targets specified.' )
## 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 +3218,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 print( 'topo='+self.options.topo )
if self.options.topo == 'none': if self.options.topo == 'none':
return return
self.newTopology() self.newTopology()
@@ -3231,7 +3232,7 @@ class MiniEdit( Frame ):
currentY = 100 currentY = 100
# Add Controllers # Add Controllers
print 'controllers:'+str(len(importNet.controllers)) print( 'controllers:'+str(len(importNet.controllers)) )
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 +3252,7 @@ class MiniEdit( Frame ):
currentY = currentY + rowIncrement currentY = currentY + rowIncrement
# Add switches # Add switches
print 'switches:'+str(len(importNet.switches)) print( 'switches:'+str(len(importNet.switches)) )
columnCount = 0 columnCount = 0
for switch in importNet.switches: for switch in importNet.switches:
name = switch.name name = switch.name
@@ -3292,7 +3293,7 @@ class MiniEdit( Frame ):
currentY = currentY + rowIncrement currentY = currentY + rowIncrement
# Add hosts # Add hosts
print 'hosts:'+str(len(importNet.hosts)) print( 'hosts:'+str(len(importNet.hosts)) )
columnCount = 0 columnCount = 0
for host in importNet.hosts: for host in importNet.hosts:
name = host.name name = host.name
@@ -3312,10 +3313,10 @@ class MiniEdit( Frame ):
else: else:
columnCount =columnCount+1 columnCount =columnCount+1
print 'links:'+str(len(topo.links())) print( 'links:'+str(len(topo.links())) )
#[('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) print( str(link) )
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 +3326,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) print( 'Link Parameters='+str(params) )
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 -9
View File
@@ -19,6 +19,8 @@ to-do:
- think about clearing last hop - why doesn't that work? - think about clearing last hop - why doesn't that work?
""" """
from __future__ import print_function
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
@@ -105,27 +107,27 @@ 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' print( '* Simple mobility test' )
net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch ) net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch )
print '* Starting network:' print( '* Starting network:' )
net.start() net.start()
printConnections( net.switches ) printConnections( net.switches )
print '* Testing network' print( '* Testing network' )
net.pingAll() net.pingAll()
print '* Identifying switch interface for h1' print( '* Identifying switch interface for h1' )
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 print( '* Moving', h1, 'from', old, 'to', new, 'port', port )
hintf, sintf = moveHost( h1, old, new, newPort=port ) hintf, sintf = moveHost( h1, old, new, newPort=port )
print '*', hintf, 'is now connected to', sintf print( '*', hintf, 'is now connected to', sintf )
print '* Clearing out old flows' print( '* Clearing out old flows' )
for sw in net.switches: for sw in net.switches:
sw.dpctl( 'del-flows' ) sw.dpctl( 'del-flows' )
print '* New network:' print( '* New network:' )
printConnections( net.switches ) printConnections( net.switches )
print '* Testing connectivity:' print( '* Testing connectivity:' )
net.pingAll() net.pingAll()
old = new old = new
net.stop() net.stop()
+4 -2
View File
@@ -8,6 +8,8 @@ multiple hosts and monitor their output interactively for a period=
of time. of time.
""" """
from __future__ import print_function
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
@@ -34,7 +36,7 @@ def startpings( host, targetips ):
' done; ' ' done; '
'done &' ) 'done &' )
print ( '*** Host %s (%s) will be pinging ips: %s' % print( '*** Host %s (%s) will be pinging ips: %s' %
( host.name, host.IP(), targetips ) ) ( host.name, host.IP(), targetips ) )
host.cmd( cmd ) host.cmd( cmd )
@@ -69,7 +71,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() print( '%s:' % node.name, node.monitor().strip() )
# Stop pings # Stop pings
for host in hosts: for host in hosts:
+6 -3
View File
@@ -5,6 +5,8 @@ Simple example of sending output to multiple files and
monitoring them monitoring them
""" """
from __future__ import print_function
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 setLogLevel
@@ -13,6 +15,7 @@ from time import time
from select import poll, POLLIN from select import poll, POLLIN
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
def monitorFiles( outfiles, seconds, timeoutms ): def monitorFiles( outfiles, seconds, timeoutms ):
"Monitor set of files and return [(host, line)...]" "Monitor set of files and return [(host, line)...]"
devnull = open( '/dev/null', 'w' ) devnull = open( '/dev/null', 'w' )
@@ -53,7 +56,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..." print( "Starting test..." )
server = hosts[ 0 ] server = hosts[ 0 ]
outfiles, errfiles = {}, {} outfiles, errfiles = {}, {}
for h in hosts: for h in hosts:
@@ -67,10 +70,10 @@ def monitorTest( N=3, seconds=3 ):
'>', outfiles[ h ], '>', outfiles[ h ],
'2>', errfiles[ h ], '2>', errfiles[ h ],
'&' ) '&' )
print "Monitoring output for", seconds, "seconds" print( "Monitoring output for", seconds, "seconds" )
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 ) print( '%s: %s' % ( h.name, line ) )
for h in hosts: for h in hosts:
h.cmd('kill %ping') h.cmd('kill %ping')
net.stop() net.stop()
+5 -2
View File
@@ -4,18 +4,21 @@
Example to create a Mininet topology and connect it to the internet via NAT Example to create a Mininet topology and connect it to the internet via NAT
""" """
from __future__ import print_function
from mininet.cli import CLI from mininet.cli import CLI
from mininet.log import lg from mininet.log import lg
from mininet.topolib import TreeNet from mininet.topolib import TreeNet
if __name__ == '__main__': if __name__ == '__main__':
lg.setLogLevel( 'info') lg.setLogLevel( 'info')
net = TreeNet( depth=1, fanout=4 ) net = TreeNet( depth=1, fanout=4 )
# 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" print( "*** Hosts are running and should have internet connectivity" )
print "*** Type 'exit' or control-D to shut down network" print( "*** Type 'exit' or control-D to shut down network" )
CLI( net ) CLI( net )
# Shut down NAT # Shut down NAT
net.stop() net.stop()
+4 -2
View File
@@ -6,6 +6,8 @@ Validate that the port numbers match to the interface name,
and that the ovs ports match the mininet ports. and that the ovs ports match the mininet ports.
""" """
from __future__ import print_function
from mininet.net import Mininet from mininet.net import Mininet
from mininet.node import Controller from mininet.node import Controller
from mininet.log import setLogLevel, info, warn from mininet.log import setLogLevel, info, warn
@@ -65,11 +67,11 @@ 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' print( '\n' )
# test the network with pingall # test the network with pingall
net.pingAll() net.pingAll()
print '\n' print( '\n' )
info( '*** Stopping network' ) info( '*** Stopping network' )
net.stop() net.stop()
+3 -1
View File
@@ -5,6 +5,8 @@ This example monitors a number of hosts using host.popen() and
pmonitor() pmonitor()
""" """
from __future__ import print_function
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
@@ -27,7 +29,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() ) print( "<%s>: %s" % ( host.name, line.strip() ) )
# Done # Done
net.stop() net.stop()
+6 -3
View File
@@ -2,28 +2,31 @@
"Monitor multiple hosts using popen()/pmonitor()" "Monitor multiple hosts using popen()/pmonitor()"
from __future__ import print_function
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 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..." print( "Starting test..." )
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" print( "Monitoring output for", seconds, "seconds" )
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 ), print( '<%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 )
+3 -1
View File
@@ -8,6 +8,8 @@ but it exposes the configuration details and allows customization.
For most tasks, the higher-level API will be preferable. For most tasks, the higher-level API will be preferable.
""" """
from __future__ import print_function
from mininet.net import Mininet from mininet.net import Mininet
from mininet.node import Node from mininet.node import Node
from mininet.link import Link from mininet.link import Link
@@ -40,7 +42,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 ) print( switch.cmd( 'ovs-vsctl add-port dp0 %s' % 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
+4 -2
View File
@@ -9,6 +9,8 @@ iperf will hang indefinitely if the TCP handshake fails
to complete. to complete.
""" """
from __future__ import print_function
from mininet.topo import Topo from mininet.topo import Topo
from mininet.net import Mininet from mininet.net import Mininet
from mininet.node import CPULimitedHost from mininet.node import CPULimitedHost
@@ -44,9 +46,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" print( "Dumping host connections" )
dumpNodeConnections(net.hosts) dumpNodeConnections(net.hosts)
print "Testing bandwidth between h1 and h4" print( "Testing bandwidth between h1 and h4" )
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()
+9 -7
View File
@@ -16,6 +16,7 @@ demonstrates:
- running server processes (sshd in this case) on hosts - running server processes (sshd in this case) on hosts
""" """
from __future__ import print_function
import sys import sys
from mininet.net import Mininet from mininet.net import Mininet
@@ -25,6 +26,7 @@ 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
def TreeNet( depth=1, fanout=2, **kwargs ): def TreeNet( depth=1, fanout=2, **kwargs ):
"Convenience function for creating tree networks." "Convenience function for creating tree networks."
topo = TreeTopo( depth, fanout ) topo = TreeTopo( depth, fanout )
@@ -59,17 +61,17 @@ 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" print( "*** Waiting for ssh daemons to start" )
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 print()
print "*** Hosts are running sshd at the following addresses:" print( "*** Hosts are running sshd at the following addresses:" )
print print()
for host in network.hosts: for host in network.hosts:
print host.name, host.IP() print( host.name, host.IP() )
print print()
print "*** Type 'exit' or control-D to shut down network" 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 )
+2 -1
View File
@@ -4,6 +4,7 @@
Test for sshd.py Test for sshd.py
""" """
from __future__ import print_function
import unittest import unittest
import pexpect import pexpect
from mininet.clean import sh from mininet.clean import sh
@@ -20,7 +21,7 @@ class testSSHD( unittest.TestCase ):
while True: while True:
index = p.expect( self.opts ) index = p.expect( self.opts )
if index == 0: if index == 0:
print p.match.group(0) print( p.match.group(0) )
p.sendline( 'yes' ) p.sendline( 'yes' )
elif index == 1: elif index == 1:
return False return False
+7 -5
View File
@@ -2,6 +2,8 @@
"Create a 64-node tree network, and test connectivity using ping." "Create a 64-node tree network, and test connectivity using ping."
from __future__ import print_function
from mininet.log import setLogLevel from mininet.log import setLogLevel
from mininet.node import UserSwitch, OVSKernelSwitch # , KernelSwitch from mininet.node import UserSwitch, OVSKernelSwitch # , KernelSwitch
from mininet.topolib import TreeNet from mininet.topolib import TreeNet
@@ -15,17 +17,17 @@ def treePing64():
'Open vSwitch kernel': OVSKernelSwitch } 'Open vSwitch kernel': OVSKernelSwitch }
for name in switches: for name in switches:
print "*** Testing", name, "datapath" print( "*** Testing", name, "datapath" )
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 print()
print "*** Tree network ping results:" print( "*** Tree network ping results:" )
for name in switches: for name in switches:
print "%s: %d%% packet loss" % ( name, results[ name ] ) print( "%s: %d%% packet loss" % ( name, results[ name ] ) )
print print()
if __name__ == '__main__': if __name__ == '__main__':
setLogLevel( 'info' ) setLogLevel( 'info' )
+3 -2
View File
@@ -25,6 +25,7 @@ list all nodes ('nodes'), to print out the network topology
and bandwidth ('iperf'.) and bandwidth ('iperf'.)
""" """
from __future__ import print_function
from subprocess import call from subprocess import call
from cmd import Cmd from cmd import Cmd
from os import isatty from os import isatty
@@ -371,7 +372,7 @@ class CLI( Cmd ):
def do_links( self, _line ): def do_links( self, _line ):
"Report on links" "Report on links"
for link in self.mn.links: for link in self.mn.links:
print link, link.status() print( link, link.status() )
def do_switch( self, line ): def do_switch( self, line ):
"Starts or stops a switch" "Starts or stops a switch"
@@ -405,7 +406,7 @@ class CLI( Cmd ):
if first in self.mn: if first in self.mn:
if not args: if not args:
print "*** Enter a command for node: %s <cmd>" % first print( "*** Enter a command for node: %s <cmd>" % first )
return return
node = self.mn[ first ] node = self.mn[ first ]
rest = args.split( ' ' ) rest = args.split( ' ' )
+3 -1
View File
@@ -1,5 +1,7 @@
"Utility functions for Mininet." "Utility functions for Mininet."
from __future__ import print_function
from mininet.log import output, info, error, warn, debug from mininet.log import output, info, error, warn, debug
from time import sleep from time import sleep
@@ -587,7 +589,7 @@ def ensureRoot():
Probably we should only sudo when needed as per Big Switch's patch. Probably we should only sudo when needed as per Big Switch's patch.
""" """
if os.getuid() != 0: if os.getuid() != 0:
print "*** Mininet must run as root." print( "*** Mininet must run as root." )
exit( 1 ) exit( 1 )
return return
+2 -1
View File
@@ -40,6 +40,7 @@ Bob Lantz, rlantz@cs.stanford.edu
1/24/2010 1/24/2010
""" """
from __future__ import print_function
import re, sys import re, sys
def fixUnderscoreTriplet( match ): def fixUnderscoreTriplet( match ):
@@ -195,4 +196,4 @@ def convertFromPep8( program ):
return program return program
if __name__ == '__main__': if __name__ == '__main__':
print convertFromPep8( sys.stdin.read() ) print( convertFromPep8( sys.stdin.read() ) )
+3 -2
View File
@@ -1,5 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
from subprocess import check_output as co from subprocess import check_output as co
from sys import exit from sys import exit
@@ -16,8 +17,8 @@ for line in lines.split( '\n' ):
if line and 'Binary' not in line: if line and 'Binary' not in line:
fname, fversion = line.split( ':' ) fname, fversion = line.split( ':' )
if version != fversion: if version != fversion:
print "%s: incorrect version '%s' (should be '%s')" % ( print( "%s: incorrect version '%s' (should be '%s')" % (
fname, fversion, version ) fname, fversion, version ) )
error = True error = True
if error: if error:
+8 -7
View File
@@ -26,6 +26,7 @@ Basic idea:
""" """
from __future__ import print_function
import os import os
from os import stat, path from os import stat, path
from stat import ST_MODE, ST_SIZE from stat import ST_MODE, ST_SIZE
@@ -112,9 +113,9 @@ def log( *args, **kwargs ):
msg = ' '.join( str( arg ) for arg in args ) msg = ' '.join( str( arg ) for arg in args )
output = '%s [ %.3f ] %s' % ( clocktime, elapsed, msg ) output = '%s [ %.3f ] %s' % ( clocktime, elapsed, msg )
if cr: if cr:
print output print( output )
else: else:
print output, print( output, )
# Optionally mirror to LogFile # Optionally mirror to LogFile
if type( LogFile ) is file: if type( LogFile ) is file:
if cr: if cr:
@@ -202,7 +203,7 @@ def attachNBD( cow, flags='' ):
continue continue
srun( 'modprobe nbd max-part=64' ) srun( 'modprobe nbd max-part=64' )
srun( 'qemu-nbd %s -c %s %s' % ( flags, nbd, cow ) ) srun( 'qemu-nbd %s -c %s %s' % ( flags, nbd, cow ) )
print print()
return nbd return nbd
raise Exception( "Error: could not find unused /dev/nbdX device" ) raise Exception( "Error: could not find unused /dev/nbdX device" )
@@ -221,7 +222,7 @@ def extractKernel( image, flavor, imageDir=VMImageDir ):
return kernel, initrd return kernel, initrd
log( '* Extracting kernel to', kernel ) log( '* Extracting kernel to', kernel )
nbd = attachNBD( image, flags='-r' ) nbd = attachNBD( image, flags='-r' )
print srun( 'partx ' + nbd ) print( srun( 'partx ' + nbd ) )
# Assume kernel is in partition 1/boot/vmlinuz*generic for now # Assume kernel is in partition 1/boot/vmlinuz*generic for now
part = nbd + 'p1' part = nbd + 'p1'
mnt = mkdtemp() mnt = mkdtemp()
@@ -988,7 +989,7 @@ def parseArgs():
if args.depend: if args.depend:
depend() depend()
if args.list: if args.list:
print buildFlavorString() print( buildFlavorString() )
if args.clean: if args.clean:
cleanup() cleanup()
if args.verbose: if args.verbose:
@@ -1009,8 +1010,8 @@ def parseArgs():
Chown = args.chown Chown = args.chown
for flavor in args.flavor: for flavor in args.flavor:
if flavor not in isoURLs: if flavor not in isoURLs:
print "Unknown build flavor:", flavor print( "Unknown build flavor:", flavor )
print buildFlavorString() print( buildFlavorString() )
break break
try: try:
build( flavor, tests=args.test, pre=args.run, post=args.post, build( flavor, tests=args.test, pre=args.run, post=args.post,