Skip to content
Snippets Groups Projects
Commit 3482b446 authored by Bob Lantz's avatar Bob Lantz
Browse files

Changed to not print control chars we don't handle.

parent e7ba6b9e
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
Node's monitor() and Tkinter's createfilehandler(). Node's monitor() and Tkinter's createfilehandler().
""" """
import re
from Tkinter import * from Tkinter import *
from mininet.log import setLogLevel from mininet.log import setLogLevel
...@@ -43,7 +44,7 @@ def __init__( self, parent, net, node, height=10, width=32, title='Node' ): ...@@ -43,7 +44,7 @@ def __init__( self, parent, net, node, height=10, width=32, title='Node' ):
# Set up widgets # Set up widgets
self.text = self.makeWidgets( ) self.text = self.makeWidgets( )
self.bindEvents() self.bindEvents()
self.append( self.prompt ) self.sendCmd( 'export TERM=dumb' )
def makeWidgets( self ): def makeWidgets( self ):
"Make a label, a text area, and a scroll bar." "Make a label, a text area, and a scroll bar."
...@@ -67,23 +68,41 @@ def bindEvents( self ): ...@@ -67,23 +68,41 @@ def bindEvents( self ):
# use special handlers for the following: # use special handlers for the following:
self.text.bind( '<Return>', self.handleReturn ) self.text.bind( '<Return>', self.handleReturn )
self.text.bind( '<Control-c>', self.handleInt ) self.text.bind( '<Control-c>', self.handleInt )
self.text.bind( '<KeyPress>', self.handleKey )
# This is not well-documented, but it is the correct # This is not well-documented, but it is the correct
# way to trigger a file event handler from Tk's # way to trigger a file event handler from Tk's
# event loop! # event loop!
self.tk.createfilehandler( self.node.stdout, READABLE, self.tk.createfilehandler( self.node.stdout, READABLE,
self.handleReadable ) self.handleReadable )
# We're not a terminal (yet?), so we ignore the following
# control characters other than [\b\n\r]
ignoreChars = re.compile( r'[\x00-\x07\x09\x0b\x0c\x0e-\x1f]+' )
def append( self, text ): def append( self, text ):
"Append something to our text frame." "Append something to our text frame."
text = self.ignoreChars.sub( '', text )
self.text.insert( 'end', text ) self.text.insert( 'end', text )
self.text.mark_set( 'insert', 'end' ) self.text.mark_set( 'insert', 'end' )
self.text.see( 'insert' ) self.text.see( 'insert' )
def handleKey( self, event ):
"If it's an interactive command, send it to the node."
char = event.char
if self.node.waiting:
self.node.write( char )
def handleReturn( self, event ): def handleReturn( self, event ):
"Handle a carriage return." "Handle a carriage return."
cmd = self.text.get( 'insert linestart', 'insert lineend' ) cmd = self.text.get( 'insert linestart', 'insert lineend' )
if cmd.find( self.prompt ) == 0: # Send it immediately, if "interactive" command
cmd = cmd[ len( self.prompt ): ] if self.node.waiting:
self.node.write( event.char )
return
# Otherwise send the whole line to the shell
pos = cmd.find( self.prompt )
if pos >= 0:
cmd = cmd[ pos + len( self.prompt ): ]
self.sendCmd( cmd ) self.sendCmd( cmd )
def handleInt( self, event=None ): def handleInt( self, event=None ):
...@@ -96,9 +115,9 @@ def sendCmd( self, cmd ): ...@@ -96,9 +115,9 @@ def sendCmd( self, cmd ):
if not node.waiting: if not node.waiting:
node.sendCmd( cmd ) node.sendCmd( cmd )
def handleReadable( self, file=None, mask=None ): def handleReadable( self, file=None, mask=None, timeoutms=None ):
"Handle file readable event." "Handle file readable event."
data = self.node.monitor() data = self.node.monitor( timeoutms )
self.append( data ) self.append( data )
if not self.node.waiting: if not self.node.waiting:
# Print prompt # Print prompt
...@@ -107,7 +126,9 @@ def handleReadable( self, file=None, mask=None ): ...@@ -107,7 +126,9 @@ def handleReadable( self, file=None, mask=None ):
def waitOutput( self ): def waitOutput( self ):
"Wait for any remaining output." "Wait for any remaining output."
while self.node.waiting: while self.node.waiting:
self.handleReadable( self ) # A bit of a trade-off here...
self.handleReadable( self, timeoutms=1000)
self.update()
def clear( self ): def clear( self ):
"Clear all of our text." "Clear all of our text."
...@@ -213,22 +234,26 @@ def iperf( self ): ...@@ -213,22 +234,26 @@ def iperf( self ):
ip = consoles[ i ].node.IP() ip = consoles[ i ].node.IP()
console.sendCmd( 'iperf -t 99999 -i 1 -c ' + ip ) console.sendCmd( 'iperf -t 99999 -i 1 -c ' + ip )
def stop( self ): def stop( self, wait=True ):
"Interrupt all hosts." "Interrupt all hosts."
consoles = self.consoles[ 'hosts' ].consoles consoles = self.consoles[ 'hosts' ].consoles
for console in consoles: for console in consoles:
console.handleInt() console.handleInt()
for console in consoles: if wait:
console.waitOutput() for console in consoles:
console.waitOutput()
# Shut down any iperfs that might still be running # Shut down any iperfs that might still be running
quietRun( 'killall -9 iperf' ) quietRun( 'killall -9 iperf' )
def quit( self ): def quit( self ):
"Stope everything and quit." "Stope everything and quit."
print "Quit" print "Quit"
self.stop() self.stop( wait=False)
Frame.quit( self ) Frame.quit( self )
def reallyQuit( self ):
print "ReallyQuit"
class Object( object ): class Object( object ):
"Generic object you can stuff junk into." "Generic object you can stuff junk into."
def __init__( self, **kwargs ): def __init__( self, **kwargs ):
...@@ -237,7 +262,7 @@ def __init__( self, **kwargs ): ...@@ -237,7 +262,7 @@ def __init__( self, **kwargs ):
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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment