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
8a034f4f
Commit
8a034f4f
authored
15 years ago
by
Brandon Heller
Browse files
Options
Downloads
Patches
Plain Diff
Add xterm support
parent
1bb4412f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
bin/mn_clean.py
+1
-8
1 addition, 8 deletions
bin/mn_clean.py
bin/mn_run.py
+4
-2
4 additions, 2 deletions
bin/mn_run.py
examples/xterms.py
+0
-50
0 additions, 50 deletions
examples/xterms.py
mininet/net.py
+31
-1
31 additions, 1 deletion
mininet/net.py
mininet/xterm.py
+51
-0
51 additions, 0 deletions
mininet/xterm.py
with
87 additions
and
61 deletions
bin/mn_clean.py
+
1
−
8
View file @
8a034f4f
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
re
import
re
from
mininet.util
import
quietRun
from
mininet.util
import
quietRun
from
mininet.xterm
import
cleanUpScreens
def
sh
(
cmd
):
def
sh
(
cmd
):
"
Print a command and send it to the shell
"
"
Print a command and send it to the shell
"
...
@@ -22,14 +23,6 @@ def sh( cmd ):
...
@@ -22,14 +23,6 @@ def sh( cmd ):
return
Popen
(
[
'
/bin/sh
'
,
'
-c
'
,
cmd
],
return
Popen
(
[
'
/bin/sh
'
,
'
-c
'
,
cmd
],
stdout
=
PIPE
).
communicate
()[
0
]
stdout
=
PIPE
).
communicate
()[
0
]
def
cleanUpScreens
():
"
Remove moldy old screen sessions.
"
r
=
r
'
(\d+.[hsc]\d+)
'
output
=
sh
(
'
screen -ls
'
).
split
(
'
\n
'
)
for
line
in
output
:
m
=
re
.
search
(
r
,
line
)
if
m
is
not
None
:
quietRun
(
'
screen -S
'
+
m
.
group
(
1
)
+
'
-X kill
'
)
def
cleanup
():
def
cleanup
():
"""
Clean up junk which might be left over from old runs;
"""
Clean up junk which might be left over from old runs;
...
...
This diff is collapsed.
Click to expand it.
bin/mn_run.py
+
4
−
2
View file @
8a034f4f
...
@@ -85,7 +85,7 @@ def parse_args(self):
...
@@ -85,7 +85,7 @@ def parse_args(self):
opts
.
add_option
(
'
--test
'
,
type
=
'
choice
'
,
choices
=
TESTS
,
opts
.
add_option
(
'
--test
'
,
type
=
'
choice
'
,
choices
=
TESTS
,
default
=
TESTS
[
0
],
default
=
TESTS
[
0
],
help
=
'
[
'
+
'
'
.
join
(
TESTS
)
+
'
]
'
)
help
=
'
[
'
+
'
'
.
join
(
TESTS
)
+
'
]
'
)
opts
.
add_option
(
'
--xterm
'
,
'
-x
'
,
action
=
'
store_true
'
,
opts
.
add_option
(
'
--xterm
s
'
,
'
-x
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
'
spawn xterms for each node
'
)
default
=
False
,
help
=
'
spawn xterms for each node
'
)
opts
.
add_option
(
'
--verbosity
'
,
'
-v
'
,
type
=
'
choice
'
,
opts
.
add_option
(
'
--verbosity
'
,
'
-v
'
,
type
=
'
choice
'
,
choices
=
LEVELS
.
keys
(),
default
=
'
info
'
,
choices
=
LEVELS
.
keys
(),
default
=
'
info
'
,
...
@@ -117,7 +117,9 @@ def begin(self):
...
@@ -117,7 +117,9 @@ def begin(self):
controller
=
CONTROLLERS
[
self
.
options
.
controller
]
controller
=
CONTROLLERS
[
self
.
options
.
controller
]
controller_params
=
ControllerParams
(
0x0a000000
,
8
)
# 10.0.0.0/8
controller_params
=
ControllerParams
(
0x0a000000
,
8
)
# 10.0.0.0/8
mn
=
Mininet
(
topo
,
switch
,
host
,
controller
,
controller_params
)
xterms
=
self
.
options
.
xterms
mn
=
Mininet
(
topo
,
switch
,
host
,
controller
,
controller_params
,
xterms
=
xterms
)
test
=
self
.
options
.
test
test
=
self
.
options
.
test
if
test
!=
'
build
'
:
if
test
!=
'
build
'
:
...
...
This diff is collapsed.
Click to expand it.
examples/xterms.py
deleted
100755 → 0
+
0
−
50
View file @
1bb4412f
#!/usr/bin/python
"""
Create a network and run an xterm (connected via screen(1) ) on each
host. Requires xterm(1) and GNU screen(1).
"""
import
os
,
re
from
subprocess
import
Popen
from
mininet.mininet
import
init
,
TreeNet
,
quietRun
def
makeXterm
(
node
,
title
):
"
Run screen on a node, and hook up an xterm.
"
title
+=
'
:
'
+
node
.
name
if
not
node
.
inNamespace
:
title
+=
'
(root)
'
cmd
=
[
'
xterm
'
,
'
-title
'
,
title
,
'
-e
'
]
if
not
node
.
execed
:
node
.
cmdPrint
(
'
screen -dmS
'
+
node
.
name
)
cmd
+=
[
'
screen
'
,
'
-D
'
,
'
-RR
'
,
'
-S
'
,
node
.
name
]
else
:
cmd
+=
[
'
sh
'
,
'
-c
'
,
'
exec tail -f /tmp/
'
+
node
.
name
+
'
*.log
'
]
return
Popen
(
cmd
)
def
cleanUpScreens
():
"
Remove moldy old screen sessions.
"
r
=
r
'
(\d+.[hsc]\d+)
'
output
=
quietRun
(
'
screen -ls
'
).
split
(
'
\n
'
)
for
line
in
output
:
m
=
re
.
search
(
r
,
line
)
if
m
is
not
None
:
quietRun
(
'
screen -S
'
+
m
.
group
(
1
)
+
'
-X kill
'
)
def
makeXterms
(
nodes
,
title
):
return
[
makeXterm
(
node
,
title
)
for
node
in
nodes
]
def
xterms
(
controllers
,
switches
,
hosts
):
cleanUpScreens
()
terms
=
makeXterms
(
controllers
,
'
controller
'
)
terms
+=
makeXterms
(
switches
,
'
switch
'
)
terms
+=
makeXterms
(
hosts
,
'
host
'
)
# Wait for xterms to exit
for
term
in
terms
:
os
.
waitpid
(
term
.
pid
,
0
)
cleanUpScreens
()
if
__name__
==
'
__main__
'
:
init
()
print
"
Running xterms on
"
,
os
.
environ
[
'
DISPLAY
'
]
network
=
TreeNet
(
depth
=
2
,
fanout
=
2
,
kernel
=
True
)
network
.
run
(
xterms
)
This diff is collapsed.
Click to expand it.
mininet/net.py
+
31
−
1
View file @
8a034f4f
...
@@ -47,6 +47,7 @@
...
@@ -47,6 +47,7 @@
"""
"""
import
os
import
os
import
re
import
re
import
signal
from
subprocess
import
call
from
subprocess
import
call
import
sys
import
sys
from
time
import
sleep
from
time
import
sleep
...
@@ -54,6 +55,7 @@
...
@@ -54,6 +55,7 @@
from
mininet.logging_mod
import
lg
from
mininet.logging_mod
import
lg
from
mininet.util
import
quietRun
,
fixLimits
from
mininet.util
import
quietRun
,
fixLimits
from
mininet.util
import
make_veth_pair
,
move_intf
,
retry
,
MOVEINTF_DELAY
from
mininet.util
import
make_veth_pair
,
move_intf
,
retry
,
MOVEINTF_DELAY
from
mininet.xterm
import
cleanUpScreens
,
makeXterms
DATAPATHS
=
[
'
kernel
'
]
#['user', 'kernel']
DATAPATHS
=
[
'
kernel
'
]
#['user', 'kernel']
...
@@ -101,6 +103,8 @@ def __init__(self, topo, switch, host, controller, cparams,
...
@@ -101,6 +103,8 @@ def __init__(self, topo, switch, host, controller, cparams,
self
.
in_namespace
=
in_namespace
self
.
in_namespace
=
in_namespace
self
.
switch_is_kernel
=
switch_is_kernel
self
.
switch_is_kernel
=
switch_is_kernel
self
.
terms
=
[]
# list of spawned xterm processes
self
.
kernel
=
True
#temporary!
self
.
kernel
=
True
#temporary!
if
build
:
if
build
:
...
@@ -286,7 +290,30 @@ def build(self, xterms, cleanup):
...
@@ -286,7 +290,30 @@ def build(self, xterms, cleanup):
self
.
_config_hosts
()
self
.
_config_hosts
()
if
xterms
:
if
xterms
:
pass
# build xterms
self
.
start_xterms
()
def
switch_nodes
(
self
):
'''
Return switch nodes.
'''
return
[
self
.
nodes
[
dpid
]
for
dpid
in
self
.
topo
.
switches
()]
def
host_nodes
(
self
):
'''
Return host nodes.
'''
return
[
self
.
nodes
[
dpid
]
for
dpid
in
self
.
topo
.
hosts
()]
def
start_xterms
(
self
):
'''
Start an xterm for each node in the topo.
'''
lg
.
info
(
"
*** Running xterms on %s
\n
"
%
os
.
environ
[
'
DISPLAY
'
])
cleanUpScreens
()
self
.
terms
+=
makeXterms
(
self
.
controllers
.
values
(),
'
controller
'
)
self
.
terms
+=
makeXterms
(
self
.
switch_nodes
(),
'
switch
'
)
self
.
terms
+=
makeXterms
(
self
.
host_nodes
(),
'
host
'
)
def
stop_xterms
(
self
):
'''
Kill each xterm.
'''
# Kill xterms
for
term
in
self
.
terms
:
os
.
kill
(
term
.
pid
,
signal
.
SIGKILL
)
cleanUpScreens
()
def
start
(
self
):
def
start
(
self
):
'''
Start controller and switches
\n
'''
'''
Start controller and switches
\n
'''
...
@@ -303,6 +330,9 @@ def start(self):
...
@@ -303,6 +330,9 @@ def start(self):
def
stop
(
self
):
def
stop
(
self
):
'''
Stop the controller(s), switches and hosts
\n
'''
'''
Stop the controller(s), switches and hosts
\n
'''
if
self
.
terms
:
lg
.
info
(
'
*** Stopping %i terms
\n
'
%
len
(
self
.
terms
))
self
.
stop_xterms
()
lg
.
info
(
'
*** Stopping %i hosts
\n
'
%
len
(
self
.
topo
.
hosts
()))
lg
.
info
(
'
*** Stopping %i hosts
\n
'
%
len
(
self
.
topo
.
hosts
()))
for
host_dpid
in
self
.
topo
.
hosts
():
for
host_dpid
in
self
.
topo
.
hosts
():
host
=
self
.
nodes
[
host_dpid
]
host
=
self
.
nodes
[
host_dpid
]
...
...
This diff is collapsed.
Click to expand it.
mininet/xterm.py
0 → 100755
+
51
−
0
View file @
8a034f4f
#!/usr/bin/env python
"""
XTerm creation and cleanup.
Utility functions to run an xterm (connected via screen(1)) on each host.
Requires xterm(1) and GNU screen(1).
"""
import
os
import
re
from
subprocess
import
Popen
from
mininet.util
import
quietRun
def
makeXterm
(
node
,
title
):
'''
Run screen on a node, and hook up an xterm.
@param node Node object
@param title base title
@return process created
'''
title
+=
'
:
'
+
node
.
name
if
not
node
.
inNamespace
:
title
+=
'
(root)
'
cmd
=
[
'
xterm
'
,
'
-title
'
,
title
,
'
-e
'
]
if
not
node
.
execed
:
node
.
cmdPrint
(
'
screen -dmS
'
+
node
.
name
)
cmd
+=
[
'
screen
'
,
'
-D
'
,
'
-RR
'
,
'
-S
'
,
node
.
name
]
else
:
cmd
+=
[
'
sh
'
,
'
-c
'
,
'
exec tail -f /tmp/
'
+
node
.
name
+
'
*.log
'
]
return
Popen
(
cmd
)
def
cleanUpScreens
():
'''
Remove moldy old screen sessions.
'''
r
=
r
'
(\d+.[hsc]\d+)
'
output
=
quietRun
(
'
screen -ls
'
).
split
(
'
\n
'
)
for
line
in
output
:
m
=
re
.
search
(
r
,
line
)
if
m
:
quietRun
(
'
screen -S
'
+
m
.
group
(
1
)
+
'
-X kill
'
)
def
makeXterms
(
nodes
,
title
):
'''
Create XTerms.
@param nodes list of Node objects
@param title base title for each
@return list of created xterm processes
'''
return
[
makeXterm
(
node
,
title
)
for
node
in
nodes
]
\ No newline at end of file
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