Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mininet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olaf Bergmann
mininet
Commits
3482b446
Commit
3482b446
authored
14 years ago
by
Bob Lantz
Browse files
Options
Downloads
Patches
Plain Diff
Changed to not print control chars we don't handle.
parent
e7ba6b9e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/consoles.py
+36
-11
36 additions, 11 deletions
examples/consoles.py
with
36 additions
and
11 deletions
examples/consoles.py
+
36
−
11
View file @
3482b446
...
...
@@ -7,6 +7,7 @@
Node
'
s monitor() and Tkinter
'
s createfilehandler().
"""
import
re
from
Tkinter
import
*
from
mininet.log
import
setLogLevel
...
...
@@ -43,7 +44,7 @@ def __init__( self, parent, net, node, height=10, width=32, title='Node' ):
# Set up widgets
self
.
text
=
self
.
makeWidgets
(
)
self
.
bindEvents
()
self
.
append
(
self
.
prompt
)
self
.
sendCmd
(
'
export TERM=dumb
'
)
def
makeWidgets
(
self
):
"
Make a label, a text area, and a scroll bar.
"
...
...
@@ -67,23 +68,41 @@ def bindEvents( self ):
# use special handlers for the following:
self
.
text
.
bind
(
'
<Return>
'
,
self
.
handleReturn
)
self
.
text
.
bind
(
'
<Control-c>
'
,
self
.
handleInt
)
self
.
text
.
bind
(
'
<KeyPress>
'
,
self
.
handleKey
)
# This is not well-documented, but it is the correct
# way to trigger a file event handler from Tk's
# event loop!
self
.
tk
.
createfilehandler
(
self
.
node
.
stdout
,
READABLE
,
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
):
"
Append something to our text frame.
"
text
=
self
.
ignoreChars
.
sub
(
''
,
text
)
self
.
text
.
insert
(
'
end
'
,
text
)
self
.
text
.
mark_set
(
'
insert
'
,
'
end
'
)
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
):
"
Handle a carriage return.
"
cmd
=
self
.
text
.
get
(
'
insert linestart
'
,
'
insert lineend
'
)
if
cmd
.
find
(
self
.
prompt
)
==
0
:
cmd
=
cmd
[
len
(
self
.
prompt
):
]
# Send it immediately, if "interactive" command
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
)
def
handleInt
(
self
,
event
=
None
):
...
...
@@ -96,9 +115,9 @@ def sendCmd( self, cmd ):
if
not
node
.
waiting
:
node
.
sendCmd
(
cmd
)
def
handleReadable
(
self
,
file
=
None
,
mask
=
None
):
def
handleReadable
(
self
,
file
=
None
,
mask
=
None
,
timeoutms
=
None
):
"
Handle file readable event.
"
data
=
self
.
node
.
monitor
()
data
=
self
.
node
.
monitor
(
timeoutms
)
self
.
append
(
data
)
if
not
self
.
node
.
waiting
:
# Print prompt
...
...
@@ -107,7 +126,9 @@ def handleReadable( self, file=None, mask=None ):
def
waitOutput
(
self
):
"
Wait for any remaining output.
"
while
self
.
node
.
waiting
:
self
.
handleReadable
(
self
)
# A bit of a trade-off here...
self
.
handleReadable
(
self
,
timeoutms
=
1000
)
self
.
update
()
def
clear
(
self
):
"
Clear all of our text.
"
...
...
@@ -213,22 +234,26 @@ def iperf( self ):
ip
=
consoles
[
i
].
node
.
IP
()
console
.
sendCmd
(
'
iperf -t 99999 -i 1 -c
'
+
ip
)
def
stop
(
self
):
def
stop
(
self
,
wait
=
True
):
"
Interrupt all hosts.
"
consoles
=
self
.
consoles
[
'
hosts
'
].
consoles
for
console
in
consoles
:
console
.
handleInt
()
for
console
in
consoles
:
console
.
waitOutput
()
if
wait
:
for
console
in
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
()
self
.
stop
(
wait
=
False
)
Frame
.
quit
(
self
)
def
reallyQuit
(
self
):
print
"
ReallyQuit
"
class
Object
(
object
):
"
Generic object you can stuff junk into.
"
def
__init__
(
self
,
**
kwargs
):
...
...
@@ -237,7 +262,7 @@ def __init__( self, **kwargs ):
if
__name__
==
'
__main__
'
:
setLogLevel
(
'
info
'
)
net
=
TreeNet
(
depth
=
2
,
fanout
=
4
)
net
=
TreeNet
(
depth
=
2
,
fanout
=
2
)
net
.
start
()
app
=
ConsoleApp
(
net
,
width
=
4
)
app
.
mainloop
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment