Added iperf command.
This commit is contained in:
+47
-5
@@ -12,6 +12,7 @@ from Tkinter import *
|
|||||||
from mininet.log import setLogLevel
|
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
|
||||||
|
|
||||||
class Console( Frame ):
|
class Console( Frame ):
|
||||||
"A simple console on a host."
|
"A simple console on a host."
|
||||||
@@ -86,19 +87,30 @@ class Console( Frame ):
|
|||||||
def handleInt( self, event=None ):
|
def handleInt( self, event=None ):
|
||||||
"Handle control-c."
|
"Handle control-c."
|
||||||
self.node.sendInt()
|
self.node.sendInt()
|
||||||
|
|
||||||
def sendCmd( self, cmd ):
|
def sendCmd( self, cmd ):
|
||||||
"Send a command to our node."
|
"Send a command to our node."
|
||||||
text, node = self.text, self.node
|
text, node = self.text, self.node
|
||||||
node.sendCmd( cmd )
|
if not node.waiting:
|
||||||
|
node.sendCmd( cmd )
|
||||||
|
|
||||||
def handleReadable( self, file, mask ):
|
def handleReadable( self, file=None, mask=None ):
|
||||||
|
"Handle file readable event."
|
||||||
data = self.node.monitor()
|
data = self.node.monitor()
|
||||||
self.append( data )
|
self.append( data )
|
||||||
if not self.node.waiting:
|
if not self.node.waiting:
|
||||||
# Print prompt, just for the heck of it
|
# Print prompt, just for the heck of it
|
||||||
self.append( self.prompt )
|
self.append( self.prompt )
|
||||||
|
|
||||||
|
def waitOutput( self ):
|
||||||
|
"Wait for any remaining output."
|
||||||
|
while self.node.waiting:
|
||||||
|
self.handleReadable( self )
|
||||||
|
|
||||||
|
def clear( self ):
|
||||||
|
"Clear all of our text."
|
||||||
|
self.text.delete( '1.0', 'end' )
|
||||||
|
|
||||||
class ConsoleApp( Frame ):
|
class ConsoleApp( Frame ):
|
||||||
|
|
||||||
def __init__( self, net, nodes, parent=None, width=4 ):
|
def __init__( self, net, nodes, parent=None, width=4 ):
|
||||||
@@ -111,6 +123,8 @@ class ConsoleApp( Frame ):
|
|||||||
self.consoles = self.createConsoles( nodes, width )
|
self.consoles = self.createConsoles( nodes, width )
|
||||||
self.pack( expand=True, fill='both' )
|
self.pack( expand=True, fill='both' )
|
||||||
cleanUpScreens()
|
cleanUpScreens()
|
||||||
|
# Close window gracefully
|
||||||
|
Wm.wm_protocol( self.top, name='WM_DELETE_WINDOW', func=self.quit )
|
||||||
|
|
||||||
def createConsoles( self, nodes, width ):
|
def createConsoles( self, nodes, width ):
|
||||||
"Create a grid of consoles in a frame."
|
"Create a grid of consoles in a frame."
|
||||||
@@ -135,7 +149,9 @@ class ConsoleApp( Frame ):
|
|||||||
f = Frame( self )
|
f = Frame( self )
|
||||||
buttons = [
|
buttons = [
|
||||||
( 'Ping', self.ping ),
|
( 'Ping', self.ping ),
|
||||||
|
( 'Iperf', self.iperf ),
|
||||||
( 'Interrupt', self.stop ),
|
( 'Interrupt', self.stop ),
|
||||||
|
( 'Clear', self.clear ),
|
||||||
( 'Quit', self.quit )
|
( 'Quit', self.quit )
|
||||||
]
|
]
|
||||||
for name, cmd in buttons:
|
for name, cmd in buttons:
|
||||||
@@ -144,6 +160,11 @@ class ConsoleApp( Frame ):
|
|||||||
f.pack( padx=4, pady=4, fill='x' )
|
f.pack( padx=4, pady=4, fill='x' )
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
def clear( self ):
|
||||||
|
"Clear all consoles."
|
||||||
|
for console in self.consoles:
|
||||||
|
console.clear()
|
||||||
|
|
||||||
def ping( self ):
|
def ping( self ):
|
||||||
"Tell each console to ping the next one."
|
"Tell each console to ping the next one."
|
||||||
consoles = self.consoles
|
consoles = self.consoles
|
||||||
@@ -153,13 +174,34 @@ class ConsoleApp( Frame ):
|
|||||||
i = ( i + 1 ) % count
|
i = ( i + 1 ) % count
|
||||||
ip = consoles[ i ].node.IP()
|
ip = consoles[ i ].node.IP()
|
||||||
console.sendCmd( 'ping ' + ip )
|
console.sendCmd( 'ping ' + ip )
|
||||||
|
|
||||||
|
def iperf( self ):
|
||||||
|
"Tell each console to ping the next one."
|
||||||
|
consoles = self.consoles
|
||||||
|
count = len( consoles )
|
||||||
|
for console in consoles:
|
||||||
|
console.node.cmd( 'iperf -sD &' )
|
||||||
|
i = 0
|
||||||
|
for console in consoles:
|
||||||
|
i = ( i + 1 ) % count
|
||||||
|
ip = consoles[ i ].node.IP()
|
||||||
|
console.sendCmd( 'iperf -i 1 -c ' + ip )
|
||||||
|
|
||||||
def stop( self ):
|
def stop( self ):
|
||||||
"Interrupt all consoles."
|
"Interrupt all consoles."
|
||||||
for console in self.consoles:
|
for console in self.consoles:
|
||||||
console.handleInt()
|
console.handleInt()
|
||||||
|
for console in self.consoles:
|
||||||
|
console.waitOutput()
|
||||||
|
# Shut down any iperfs that might still be running
|
||||||
|
quietRun( 'killall -9 iperf' )
|
||||||
|
|
||||||
|
def quit( self ):
|
||||||
|
"Stope everything and quit."
|
||||||
|
print "Quit"
|
||||||
|
self.stop()
|
||||||
|
Frame.quit( self )
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'info' )
|
setLogLevel( 'info' )
|
||||||
net = TreeNet( depth=2, fanout=4 )
|
net = TreeNet( depth=2, fanout=4 )
|
||||||
|
|||||||
Reference in New Issue
Block a user