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
d0e53ca8
Commit
d0e53ca8
authored
14 years ago
by
Bob Lantz
Browse files
Options
Downloads
Patches
Plain Diff
Added semi-interactive command line support.
Now you can type commands into each mini-console!
parent
f8901597
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
+35
-15
35 additions, 15 deletions
examples/consoles.py
with
35 additions
and
15 deletions
examples/consoles.py
+
35
−
15
View file @
d0e53ca8
...
...
@@ -11,22 +11,25 @@
from
mininet.log
import
setLogLevel
from
mininet.topolib
import
TreeNet
from
mininet.term
import
makeTerms
,
cleanUpScreens
class
Console
(
Frame
):
"
A simple console on a host.
"
def
__init__
(
self
,
parent
,
node
,
height
=
1
6
,
width
=
32
):
def
__init__
(
self
,
parent
,
net
,
node
,
height
=
1
0
,
width
=
32
):
Frame
.
__init__
(
self
,
parent
)
self
.
net
=
net
self
.
node
=
node
self
.
prompt
=
node
.
name
+
'
#
'
self
.
height
,
self
.
width
=
height
,
width
self
.
text
=
self
.
makeWidgets
(
)
self
.
bindEvents
()
self
.
append
(
self
.
prompt
)
def
makeWidgets
(
self
):
"
Make a label, a text area, and a scroll bar.
"
label
Style
=
{
button
Style
=
{
'
font
'
:
'
Monaco 7
'
,
'
relief
'
:
'
sunken
'
}
textStyle
=
{
'
font
'
:
'
Monaco 7
'
,
...
...
@@ -34,9 +37,16 @@ def makeWidgets( self ):
'
fg
'
:
'
green
'
,
'
width
'
:
self
.
width
,
'
height
'
:
self
.
height
,
'
relief
'
:
'
sunken
'
'
relief
'
:
'
sunken
'
,
'
insertbackground
'
:
'
green
'
,
'
highlightcolor
'
:
'
green
'
,
'
selectforeground
'
:
'
black
'
,
'
selectbackground
'
:
'
green
'
}
label
=
Label
(
self
,
text
=
self
.
node
.
name
,
**
labelStyle
)
def
newTerm
(
net
=
self
.
net
,
node
=
self
.
node
):
"
Pop up a new terminal window for a node.
"
net
.
terms
+=
makeTerms
(
[
node
]
)
label
=
Button
(
self
,
text
=
self
.
node
.
name
,
command
=
newTerm
,
**
buttonStyle
)
label
.
pack
(
side
=
'
top
'
,
fill
=
'
x
'
)
text
=
Text
(
self
,
wrap
=
'
word
'
,
**
textStyle
)
ybar
=
Scrollbar
(
self
,
orient
=
'
vertical
'
,
command
=
text
.
yview
)
...
...
@@ -49,7 +59,7 @@ def bindEvents( self ):
"
Bind keyboard and file events.
"
self
.
text
.
bind
(
'
<Return>
'
,
self
.
handleReturn
)
self
.
text
.
bind
(
'
<Control-c>
'
,
self
.
handleInt
)
self
.
text
.
bind
(
'
<KeyPress>
'
,
self
.
handleKey
)
#
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!
...
...
@@ -68,8 +78,11 @@ def handleKey( self, event ):
def
handleReturn
(
self
,
event
):
"
Handle a carriage return.
"
print
"
handleReturn
"
cmd
=
self
.
text
.
get
(
'
insert linestart
'
,
'
insert lineend
'
)
if
cmd
.
find
(
self
.
prompt
)
==
0
:
cmd
=
cmd
[
len
(
self
.
prompt
):
]
self
.
sendCmd
(
cmd
)
def
handleInt
(
self
,
event
=
None
):
"
Handle control-c.
"
self
.
node
.
sendInt
()
...
...
@@ -82,15 +95,22 @@ def sendCmd( self, cmd ):
def
handleReadable
(
self
,
file
,
mask
):
data
=
self
.
node
.
monitor
()
self
.
append
(
data
)
if
not
self
.
node
.
waiting
:
# Print prompt, just for the heck of it
self
.
append
(
self
.
prompt
)
class
Console
s
(
Frame
):
class
Console
App
(
Frame
):
def
__init__
(
self
,
nodes
,
parent
=
None
,
width
=
4
):
def
__init__
(
self
,
net
,
nodes
,
parent
=
None
,
width
=
4
):
Frame
.
__init__
(
self
,
parent
)
self
.
top
=
self
.
winfo_toplevel
()
self
.
top
.
title
(
'
Mininet
'
)
self
.
net
=
net
self
.
nodes
=
nodes
self
.
createMenuBar
(
font
=
'
Geneva 7
'
)
self
.
consoles
=
self
.
createConsoles
(
nodes
,
width
)
self
.
pack
(
expand
=
True
,
fill
=
'
both
'
)
cleanUpScreens
()
def
createConsoles
(
self
,
nodes
,
width
):
"
Create a grid of consoles in a frame.
"
...
...
@@ -99,7 +119,7 @@ def createConsoles( self, nodes, width ):
consoles
=
[]
index
=
0
for
node
in
nodes
:
console
=
Console
(
f
,
node
)
console
=
Console
(
f
,
net
,
node
)
consoles
.
append
(
console
)
row
=
int
(
index
/
width
)
column
=
index
%
width
...
...
@@ -128,11 +148,11 @@ def ping( self ):
"
Tell each console to ping the next one.
"
consoles
=
self
.
consoles
count
=
len
(
consoles
)
i
=
1
i
=
0
for
console
in
consoles
:
i
=
(
i
+
1
)
%
count
ip
=
consoles
[
i
].
node
.
IP
()
console
.
sendCmd
(
'
ping
'
+
ip
)
i
=
(
i
+
1
)
%
count
def
stop
(
self
):
"
Interrupt all consoles.
"
...
...
@@ -142,8 +162,8 @@ def stop( self ):
if
__name__
==
'
__main__
'
:
setLogLevel
(
'
info
'
)
net
=
TreeNet
(
depth
=
2
,
fanout
=
2
)
net
=
TreeNet
(
depth
=
2
,
fanout
=
4
)
net
.
start
()
app
=
Console
s
(
net
.
hosts
,
width
=
2
)
app
=
Console
App
(
net
,
net
.
hosts
,
width
=
4
)
app
.
mainloop
()
net
.
stop
()
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