Pass pyflakes.

This commit is contained in:
Bob Lantz
2010-05-04 19:11:12 -07:00
parent c79882b766
commit 259d713315
10 changed files with 157 additions and 106 deletions
+9 -9
View File
@@ -26,9 +26,10 @@ Bob Lantz, April 2010
""" """
import re import re
from Tkinter import *
from mininet.log import setLogLevel,info from Tkinter import Frame, Button, Label, Text, Scrollbar, Canvas, Wm, READABLE
from mininet.log import setLogLevel
from mininet.topolib import TreeNet from mininet.topolib import TreeNet
from mininet.term import makeTerms, cleanUpScreens from mininet.term import makeTerms, cleanUpScreens
from mininet.util import quietRun from mininet.util import quietRun
@@ -233,11 +234,11 @@ class Graph( Frame ):
scale.configure( yscrollcommand=ybar.set ) scale.configure( yscrollcommand=ybar.set )
# Layout # Layout
title.grid( row=0, columnspan=3, sticky=N+E+W) title.grid( row=0, columnspan=3, sticky='new')
scale.grid( row=1, column=0, sticky=N+S+E+W ) scale.grid( row=1, column=0, sticky='nsew' )
graph.grid( row=1, column=1, sticky=N+S+E+W ) graph.grid( row=1, column=1, sticky='nsew' )
ybar.grid( row=1, column=2, sticky=N+S ) ybar.grid( row=1, column=2, sticky='ns' )
xbar.grid( row=2, column=0, columnspan=2, sticky=E+W ) xbar.grid( row=2, column=0, columnspan=2, sticky='ew' )
self.rowconfigure( 1, weight=1 ) self.rowconfigure( 1, weight=1 )
self.columnconfigure( 1, weight=1 ) self.columnconfigure( 1, weight=1 )
# Save for future reference # Save for future reference
@@ -249,7 +250,6 @@ class Graph( Frame ):
def addBar( self, yval ): def addBar( self, yval ):
"Add a new bar to our graph." "Add a new bar to our graph."
percent = yval / self.ymax percent = yval / self.ymax
height = percent * self.gheight
c = self.graph c = self.graph
x0 = self.xpos * self.barwidth x0 = self.xpos * self.barwidth
x1 = x0 + self.barwidth x1 = x0 + self.barwidth
@@ -453,7 +453,7 @@ class Object( object ):
if __name__ == '__main__': if __name__ == '__main__':
setLogLevel( 'info' ) setLogLevel( 'info' )
net = TreeNet( depth=2, fanout=4 ) net = TreeNet( depth=2, fanout=2 )
net.start() net.start()
app = ConsoleApp( net, width=4 ) app = ConsoleApp( net, width=4 )
app.mainloop() app.mainloop()
+1 -1
View File
@@ -17,7 +17,7 @@ def emptyNet():
net = Mininet( controller=Controller ) net = Mininet( controller=Controller )
info( '*** Adding controller\n' ) info( '*** Adding controller\n' )
c0 = net.addController( 'c0' ) net.addController( 'c0' )
info( '*** Adding hosts\n' ) info( '*** Adding hosts\n' )
h1 = net.addHost( 'h1', ip='10.0.0.1' ) h1 = net.addHost( 'h1', ip='10.0.0.1' )
+14 -24
View File
@@ -11,17 +11,14 @@ Development version - not entirely functional!
Bob Lantz, April 2010 Bob Lantz, April 2010
""" """
from Tkinter import * from Tkinter import Frame, Button, Label, Scrollbar, Canvas
from Tkinter import Menu, BitmapImage, PhotoImage, Wm, Toplevel
# someday: from ttk import * # someday: from ttk import *
from mininet.log import setLogLevel from mininet.log import setLogLevel
from mininet.net import init, Mininet from mininet.net import Mininet
from mininet.node import KernelSwitch, UserSwitch, OVSKernelSwitch from mininet.util import ipStr
from mininet.node import Controller, NOX
from mininet.topo import Topo
from mininet.topolib import TreeTopo
from mininet.util import quietRun, ipStr
from mininet.term import makeTerm, cleanUpScreens from mininet.term import makeTerm, cleanUpScreens
class MiniEdit( Frame ): class MiniEdit( Frame ):
@@ -189,15 +186,6 @@ class MiniEdit( Frame ):
c = self.canvas c = self.canvas
return c.canvasy( y_root ) - c.winfo_rooty() return c.canvasy( y_root ) - c.winfo_rooty()
def widgetCenter( self, widget ):
"Return center of widget on our canvas."
c = self.canvas
x = self.canvasx( widget.winfo_rootx() )
y = self.canvasy( widget.winfo_rooty() )
w = widget.winfo_width()
h = widget.winfo_height()
return x + w / 2, y + h / 2
# Toolbar # Toolbar
def activate( self, toolName ): def activate( self, toolName ):
@@ -347,6 +335,7 @@ class MiniEdit( Frame ):
"Drag a link's endpoint to another node." "Drag a link's endpoint to another node."
if self.link is None: if self.link is None:
return return
# Since drag starts in widget, we use root coords
x = self.canvasx( event.x_root ) x = self.canvasx( event.x_root )
y = self.canvasy( event.y_root ) y = self.canvasy( event.y_root )
c = self.canvas c = self.canvas
@@ -426,12 +415,12 @@ class MiniEdit( Frame ):
item = self.widgetToItem[ w ] item = self.widgetToItem[ w ]
c.coords( item, x, y ) c.coords( item, x, y )
# Adjust link positions # Adjust link positions
x0, y0 = self.widgetCenter( w )
for dest in w.links: for dest in w.links:
link = w.links[ dest ] link = w.links[ dest ]
x1, y1 = self.widgetCenter( dest ) item = self.widgetToItem[ dest ]
c.coords( link, x0, y0, x1, y1 ) x1, y1 = c.coords( item )
c.coords( link, x, y, x1, y1 )
def startLink( self, event ): def startLink( self, event ):
"Start a new link." "Start a new link."
if event.widget not in self.widgetToItem: if event.widget not in self.widgetToItem:
@@ -439,7 +428,7 @@ class MiniEdit( Frame ):
return return
w = event.widget w = event.widget
item = self.widgetToItem[ w ] item = self.widgetToItem[ w ]
x, y = self.widgetCenter( w ) x, y = self.canvas.coords( item )
self.link = self.canvas.create_line( x, y, x, y, width=4, self.link = self.canvas.create_line( x, y, x, y, width=4,
fill='blue', tag='link' ) fill='blue', tag='link' )
self.linkx, self.linky = x, y self.linkx, self.linky = x, y
@@ -464,6 +453,8 @@ class MiniEdit( Frame ):
if self.link is None: if self.link is None:
return return
source = self.linkWidget source = self.linkWidget
c = self.canvas
# Since we dragged from the widget, use root coords
x, y = self.canvasx( event.x_root ), self.canvasy( event.y_root ) x, y = self.canvasx( event.x_root ), self.canvasy( event.y_root )
target = self.findItem( x, y ) target = self.findItem( x, y )
dest = self.itemToWidget.get( target, None ) dest = self.itemToWidget.get( target, None )
@@ -477,8 +468,7 @@ class MiniEdit( Frame ):
if 'Host' in stags and 'Host' in dtags: if 'Host' in stags and 'Host' in dtags:
self.releaseLink( event ) self.releaseLink( event )
return return
x, y = self.widgetCenter( dest ) x, y = c.coords( target )
c = self.canvas
c.coords( self.link, self.linkx, self.linky, x, y ) c.coords( self.link, self.linkx, self.linky, x, y )
self.addLink( source, dest ) self.addLink( source, dest )
@@ -562,7 +552,7 @@ class MiniEdit( Frame ):
elif 'Host' in tags: elif 'Host' in tags:
net.addHost( name, ip=ipStr( nodeNum ) ) net.addHost( name, ip=ipStr( nodeNum ) )
else: else:
exception( "Cannot create mystery node: " + name ) raise Exception( "Cannot create mystery node: " + name )
# Make links # Make links
for link in self.links.values(): for link in self.links.values():
( src, dst ) = link ( src, dst ) = link
+1 -1
View File
@@ -7,7 +7,7 @@ For a more complicated test example, see udpbwtest.py.
from mininet.cli import CLI from mininet.cli import CLI
from mininet.log import lg, info from mininet.log import lg, info
from mininet.net import init, Mininet from mininet.net import Mininet
from mininet.node import KernelSwitch from mininet.node import KernelSwitch
from mininet.topolib import TreeTopo from mininet.topolib import TreeTopo
+1 -1
View File
@@ -16,7 +16,7 @@ demonstrates:
- running server processes (sshd in this case) on hosts - running server processes (sshd in this case) on hosts
""" """
from mininet.net import init, 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
from mininet.node import Node, KernelSwitch from mininet.node import Node, KernelSwitch
-1
View File
@@ -3,7 +3,6 @@
"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
from mininet.net import init, Mininet
from mininet.node import KernelSwitch, UserSwitch, OVSKernelSwitch from mininet.node import KernelSwitch, UserSwitch, OVSKernelSwitch
from mininet.topolib import TreeNet from mininet.topolib import TreeNet
+117 -59
View File
@@ -7,17 +7,13 @@ Bob Lantz
3/27/10 3/27/10
""" """
from time import sleep
import os
import re import re
import sys
from time import time
from Tkinter import * from Tkinter import Frame, Label, Button, Scrollbar, OptionMenu, Canvas
from Tkinter import StringVar
from mininet.log import setLogLevel from mininet.log import setLogLevel
from mininet.net import init, Mininet from mininet.net import Mininet
from mininet.node import KernelSwitch, UserSwitch, OVSKernelSwitch from mininet.node import KernelSwitch, UserSwitch, OVSKernelSwitch
from mininet.node import Controller, NOX from mininet.node import Controller, NOX
from mininet.topolib import TreeTopo from mininet.topolib import TreeTopo
@@ -61,7 +57,7 @@ class Graph( Frame ):
scale.create_line( width - 1, height, width - 1, 0, fill=fill ) scale.create_line( width - 1, height, width - 1, 0, fill=fill )
# Draw ticks and numbers # Draw ticks and numbers
for y in range( 0, int( ymax + 1 ) ): for y in range( 0, int( ymax + 1 ) ):
ypos = height * (1 - float( y ) / ymax ) ypos = height * ( 1 - float( y ) / ymax )
scale.create_line( width, ypos, width - 10, ypos, fill=fill ) scale.create_line( width, ypos, width - 10, ypos, fill=fill )
scale.create_text( 10, ypos, text=str( y ), fill=fill ) scale.create_text( 10, ypos, text=str( y ), fill=fill )
@@ -76,9 +72,9 @@ class Graph( Frame ):
self.scale.configure( scrollregion=( 0, -ofs, 0, height ) ) self.scale.configure( scrollregion=( 0, -ofs, 0, height ) )
def yview( self, *args ): def yview( self, *args ):
"Scroll both scale and graph." "Scroll both scale and graph."
self.graph.yview( *args ) self.graph.yview( *args )
self.scale.yview( *args ) self.scale.yview( *args )
def createWidgets( self ): def createWidgets( self ):
"Create initial widget set." "Create initial widget set."
@@ -96,11 +92,11 @@ class Graph( Frame ):
scale.configure( yscrollcommand=ybar.set ) scale.configure( yscrollcommand=ybar.set )
# Layout # Layout
title.grid( row=0, columnspan=3, sticky=N+E+W) title.grid( row=0, columnspan=3, sticky='new')
scale.grid( row=1, column=0, sticky=N+S+E+W ) scale.grid( row=1, column=0, sticky='nsew' )
graph.grid( row=1, column=1, sticky=N+S+E+W ) graph.grid( row=1, column=1, sticky='nsew' )
ybar.grid( row=1, column=2, sticky=N+S ) ybar.grid( row=1, column=2, sticky='ns' )
xbar.grid( row=2, column=0, columnspan=2, sticky=E+W ) xbar.grid( row=2, column=0, columnspan=2, sticky='ew' )
self.rowconfigure( 1, weight=1 ) self.rowconfigure( 1, weight=1 )
self.columnconfigure( 1, weight=1 ) self.columnconfigure( 1, weight=1 )
@@ -113,7 +109,6 @@ class Graph( Frame ):
def addBar( self, yval ): def addBar( self, yval ):
"Add a new bar to our graph." "Add a new bar to our graph."
percent = yval / self.ymax percent = yval / self.ymax
height = percent * self.gheight
c = self.graph c = self.graph
x0 = self.xpos * self.barwidth x0 = self.xpos * self.barwidth
x1 = x0 + self.barwidth x1 = x0 + self.barwidth
@@ -151,26 +146,42 @@ class Controls( Frame ):
'NOX': NOX 'NOX': NOX
} }
def optionMenu( self, name, dict, initval, opts ):
def __init__( self, master=None ): "Add a new option menu."
var = StringVar()
var.set( findKey( dict, initval ) )
menu = OptionMenu( self, var, *dict )
menu.config( **opts )
menu.pack( fill='x' )
def value():
return dict[ var.get() ]
return value
def __init__( self, master, start, stop, quit ):
Frame.__init__( self, master ) Frame.__init__( self, master )
self.switch = StringVar() # Option menus
self.switch.set( 'Kernel Switch' ) opts = { 'font': 'Geneva 7 bold' }
self.switchMenu = OptionMenu( self, self.switch, self.switch = self.optionMenu( 'Switch', self.switches,
*( switches.keys() ) ) KernelSwitch, opts )
self.controller = self.optionMenu( 'Controller', self.controllers,
Controller, opts)
# Spacer
pk = { 'fill': 'x' }
Label( self, **opts ).pack( **pk )
# Buttons
self.start = Button( self, text='Start', command=start, **opts )
self.stop = Button( self, text='Stop', command=stop, **opts )
self.quit = Button( self, text='Quit', command=quit, **opts )
for button in ( self.start, self.stop, self.quit ):
button.pack( **pk )
self.controller = StringVar()
self.controller.set( 'Reference Controller' )
self.controllerMenu = OpetionMenu( self, self.controller,
*( controllers.keys() ) )
def App( Frame ):
def parsebwtest( line, def parsebwtest( line,
r=re.compile( r'(\d+) s: in ([\d\.]+) Mbps, out ([\d\.]+) Mbps' ) ): r=re.compile( r'(\d+) s: in ([\d\.]+) MB/s, out ([\d\.]+) MB/s' ) ):
"Parse udpbwtest.c output, returning seconds, inbw, outbw." "Parse udpbwtest.c output, returning seconds, inbw, outbw."
match = r.match( line ) match = r.match( line )
if match: if match:
@@ -179,25 +190,50 @@ def parsebwtest( line,
return None, None, None return None, None, None
class UdpBwTest( object ): class UdpBwTest( Frame ):
"Test and plot UDP bandwidth over time" "Test and plot UDP bandwidth over time"
def __init__( self, graph, net, seconds=60 ): def __init__( self, topo, seconds=60, master=None ):
"Start up and monitor udpbwtest on each of our hosts." "Start up and monitor udpbwtest on each of our hosts."
hosts = net.hosts Frame.__init__( self, master )
self.graph = graph
self.hostCount = len( hosts ) self.controls = Controls( self, self.start, self.stop, self.quit )
self.graph = Graph( self )
# Layout
self.controls.pack( side='left', expand=False, fill='y' )
self.graph.pack( side='right', expand=True, fill='both' )
self.pack( expand=True, fill='both' )
self.running = False
def start( self ):
print "start"
if self.running:
return
switch = self.controls.switch()
controller = self.controls.controller()
self.net = Mininet( topo, switch=switch, controller=controller )
self.hosts = self.net.hosts
self.hostCount = len( self.hosts )
print "*** Starting network"
self.net.start()
print "*** Starting udpbwtest on hosts" print "*** Starting udpbwtest on hosts"
hosts = self.hosts
for host in hosts: for host in hosts:
ips = [ h.IP() for h in hosts if h != host ] ips = [ h.IP() for h in hosts if h != host ]
host.cmdPrint( './udpbwtest ' + ' '.join( ips ) + ' &' ) host.cmdPrint( './udpbwtest ' + ' '.join( ips ) + ' &' )
print "*** Monitoring hosts" print "*** Monitoring hosts"
self.output = net.monitor( hosts, timeoutms=0 ) self.output = self.net.monitor( hosts, timeoutms=1 )
self.results = {} self.results = {}
self.quitTime = time() + seconds self.running = True
self.updateGraph() self.updateGraph()
# Pylint isn't smart enough to understand iterator.next() # Pylint isn't smart enough to understand iterator.next()
@@ -205,6 +241,12 @@ class UdpBwTest( object ):
def updateGraph( self ): def updateGraph( self ):
"Graph input bandwidth." "Graph input bandwidth."
print "updateGraph"
if not self.running:
return
while True: while True:
host, line = self.output.next() host, line = self.output.next()
if host is None or len( line ) == 0: if host is None or len( line ) == 0:
@@ -220,35 +262,51 @@ class UdpBwTest( object ):
totalin = 0 totalin = 0
for host, inbw, outbw in result: for host, inbw, outbw in result:
totalin += inbw totalin += inbw
self.graph.addBar( totalin / 1000.0 ) self.graph.addBar( totalin * 8.0/1000.0 )
print totalin print totalin
if time() < self.quitTime: # Fileevent might be better, but for now we just poll every 500ms
# Fileevent would be better, but for now we just poll every 500ms self.graph.after( 500, self.updateGraph )
self.graph.after( 10, self.updateGraph )
else:
self.shutdown()
def shutdown( self ): def stop( self ):
"Stop udpbwtest proceses." "Stop test."
print "*** Stopping udpbwtest processes" print "*** Stopping udpbwtest processes"
# We *really* don't want these things hanging around! # We *really* don't want these things hanging around!
quietRun( 'killall -9 udpbwtest' ) quietRun( 'killall -9 udpbwtest' )
if not self.running:
return
print "*** Stopping network"
self.running = False
self.net.stop()
def quit( self ):
print "*** Quitting"
self.stop()
Frame.quit( self )
# pylint: enable-msg=E1101 # pylint: enable-msg=E1101
# Useful utilities
def findKey( dict, value ):
"Find some key where dict[ key ] == value."
return [ key for key, val in dict.items() if val == value ][ 0 ]
def assign( obj, **kwargs):
"Set a bunch of fields in an object."
for name, value in kwargs.items():
setattr( obj, name, value )
class Object( object ):
"Generic object you can stuff junk into."
def __init__( self, **kwargs ):
assign( self, **kwargs )
if __name__ == '__main__': if __name__ == '__main__':
setLogLevel( 'info' ) setLogLevel( 'info' )
app = Graph() topo = TreeTopo( depth=1, fanout=2 )
app.master.title( "Mininet Bandwidth" ) app = UdpBwTest( topo )
depth, fanout = 1, 2
net = Mininet( topo=TreeTopo( depth=depth, fanout=fanout),
switch=KernelSwitch )
title = "Bandwidth (Mb/s), (%i hosts, %i switches, depth=%d, fanout=%d)" % (
len( net.hosts ), len( net.switches), depth, fanout )
app.setTitle( title )
net.start()
test = UdpBwTest( app, net )
app.mainloop() app.mainloop()
net.stop()
test.shutdown() # just in case!
+4 -4
View File
@@ -24,7 +24,7 @@ from time import time
flush = sys.stdout.flush flush = sys.stdout.flush
from mininet.log import lg from mininet.log import lg
from mininet.net import init, Mininet from mininet.net import Mininet
from mininet.node import KernelSwitch from mininet.node import KernelSwitch
from mininet.topolib import TreeTopo from mininet.topolib import TreeTopo
from mininet.util import quietRun from mininet.util import quietRun
@@ -32,7 +32,7 @@ from mininet.util import quietRun
# bwtest support # bwtest support
def parsebwtest( line, def parsebwtest( line,
r=re.compile( r'(\d+) s: in ([\d\.]+) Mbps, out ([\d\.]+) Mbps' ) ): r=re.compile( r'(\d+) s: in ([\d\.]+) MB/s, out ([\d\.]+) MB/s' ) ):
"Parse udpbwtest.c output, returning seconds, inbw, outbw." "Parse udpbwtest.c output, returning seconds, inbw, outbw."
match = r.match( line ) match = r.match( line )
if match: if match:
@@ -43,7 +43,7 @@ def parsebwtest( line,
def printTotalHeader(): def printTotalHeader():
"Print header for bandwidth stats." "Print header for bandwidth stats."
print print
print "time(s)\thosts\ttotal in/out (Mbps)\tavg in/out (Mbps)" print "time(s)\thosts\ttotal in/out (MB/s)\tavg in/out (MB/s)"
# Annoyingly, pylint isn't smart enough to notice # Annoyingly, pylint isn't smart enough to notice
# when an unused variable is an iteration tuple # when an unused variable is an iteration tuple
@@ -108,7 +108,7 @@ if __name__ == '__main__':
lg.setLogLevel( 'info' ) lg.setLogLevel( 'info' )
if not os.path.exists( './udpbwtest' ): if not os.path.exists( './udpbwtest' ):
raise Exception( 'Could not find udpbwtest in current directory.' ) raise Exception( 'Could not find udpbwtest in current directory.' )
network = Mininet( TreeTopo( depth=2, fanout=2 ), switch=KernelSwitch ) network = Mininet( TreeTopo( depth=1, fanout=8 ), switch=KernelSwitch )
network.start() network.start()
udpbwtest( network, seconds=10 ) udpbwtest( network, seconds=10 )
network.stop() network.stop()
+1 -2
View File
@@ -28,9 +28,8 @@ and bandwidth ('iperf'.)
from subprocess import call from subprocess import call
from cmd import Cmd from cmd import Cmd
from os import isatty from os import isatty
from select import poll, select, POLLIN from select import poll, POLLIN
from sys import stdin from sys import stdin
from tty import setcbreak
from mininet.log import info, output, error from mininet.log import info, output, error
from mininet.term import makeTerms from mininet.term import makeTerms
+9 -4
View File
@@ -397,10 +397,12 @@ class Mininet( object ):
self.stop() self.stop()
return result return result
def monitor( self, hosts=None ): def monitor( self, hosts=None, timeoutms=-1 ):
"""Monitor a set of hosts (or all hosts by default), """Monitor a set of hosts (or all hosts by default),
and return their output, a line at a time. and return their output, a line at a time.
returns: host, line""" hosts: (optional) set of hosts to monitor
timeoutms: (optional) timeout value in ms
returns: iterator which returns host, line"""
if hosts is None: if hosts is None:
hosts = self.hosts hosts = self.hosts
poller = select.poll() poller = select.poll()
@@ -408,13 +410,16 @@ class Mininet( object ):
for host in hosts: for host in hosts:
poller.register( host.stdout ) poller.register( host.stdout )
while True: while True:
ready = poller.poll() ready = poller.poll( timeoutms )
for fd, event in ready: for fd, event in ready:
host = Node.fdToNode( fd ) host = Node.fdToNode( fd )
if event & select.POLLIN: if event & select.POLLIN:
line = host.readline() line = host.readline()
if line: if line is not None:
yield host, line yield host, line
# Return if non-blocking
if not ready and timeoutms >= 0:
yield None, None
@staticmethod @staticmethod
def _parsePing( pingOutput ): def _parsePing( pingOutput ):