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
c8607467
Commit
c8607467
authored
10 years ago
by
Bob Lantz
Browse files
Options
Downloads
Plain Diff
Merge branch 'cdburkard-patches/fix_sshd'
parents
4aa0b823
f8e98d6a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/cpu.py
+1
-13
1 addition, 13 deletions
examples/cpu.py
examples/sshd.py
+5
-0
5 additions, 0 deletions
examples/sshd.py
mininet/util.py
+31
-6
31 additions, 6 deletions
mininet/util.py
with
37 additions
and
19 deletions
examples/cpu.py
+
1
−
13
View file @
c8607467
...
...
@@ -7,23 +7,11 @@
from
mininet.net
import
Mininet
from
mininet.node
import
CPULimitedHost
from
mininet.topolib
import
TreeTopo
from
mininet.util
import
custom
from
mininet.util
import
custom
,
waitListening
from
mininet.log
import
setLogLevel
,
output
,
info
from
time
import
sleep
def
waitListening
(
client
,
server
,
port
):
"
Wait until server is listening on port
"
if
not
client
.
cmd
(
'
which telnet
'
):
raise
Exception
(
'
Could not find telnet
'
)
cmd
=
(
'
sh -c
"
echo A | telnet -e A %s %s
"'
%
(
server
.
IP
(),
port
))
while
'
Connected
'
not
in
client
.
cmd
(
cmd
):
output
(
'
waiting for
'
,
server
,
'
to listen on port
'
,
port
,
'
\n
'
)
sleep
(.
5
)
def
bwtest
(
cpuLimits
,
period_us
=
100000
,
seconds
=
5
):
"""
Example/test of link and CPU bandwidth limits
cpu: cpu limit as fraction of overall CPU time
"""
...
...
This diff is collapsed.
Click to expand it.
examples/sshd.py
+
5
−
0
View file @
c8607467
...
...
@@ -24,6 +24,7 @@
from
mininet.node
import
Node
from
mininet.topolib
import
TreeTopo
from
mininet.link
import
Link
from
mininet.util
import
waitListening
def
TreeNet
(
depth
=
1
,
fanout
=
2
,
**
kwargs
):
"
Convenience function for creating tree networks.
"
...
...
@@ -59,6 +60,10 @@ def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
connectToRootNS
(
network
,
switch
,
ip
,
routes
)
for
host
in
network
.
hosts
:
host
.
cmd
(
cmd
+
'
'
+
opts
+
'
&
'
)
print
"
*** Waiting for ssh daemons to start
"
for
server
in
network
.
hosts
:
waitListening
(
server
=
server
,
port
=
22
,
timeout
=
5
)
print
print
"
*** Hosts are running sshd at the following addresses:
"
print
...
...
This diff is collapsed.
Click to expand it.
mininet/util.py
+
31
−
6
View file @
c8607467
...
...
@@ -10,6 +10,7 @@
from
fcntl
import
fcntl
,
F_GETFL
,
F_SETFL
from
os
import
O_NONBLOCK
import
os
from
functools
import
partial
# Command execution support
...
...
@@ -61,12 +62,6 @@ def errRun( *cmd, **kwargs ):
stderr: STDOUT to merge stderr with stdout
shell: run command using shell
echo: monitor output to console
"""
# Allow passing in a list or a string
if
len
(
cmd
)
==
1
:
cmd
=
cmd
[
0
]
if
isinstance
(
cmd
,
str
):
cmd
=
cmd
.
split
(
'
'
)
cmd
=
[
str
(
arg
)
for
arg
in
cmd
]
# By default we separate stderr, don't run in a shell, and don't echo
stderr
=
kwargs
.
get
(
'
stderr
'
,
PIPE
)
shell
=
kwargs
.
get
(
'
shell
'
,
False
)
...
...
@@ -74,6 +69,14 @@ def errRun( *cmd, **kwargs ):
if
echo
:
# cmd goes to stderr, output goes to stdout
info
(
cmd
,
'
\n
'
)
if
len
(
cmd
)
==
1
:
cmd
=
cmd
[
0
]
# Allow passing in a list or a string
if
isinstance
(
cmd
,
str
)
and
not
shell
:
cmd
=
cmd
.
split
(
'
'
)
cmd
=
[
str
(
arg
)
for
arg
in
cmd
]
elif
isinstance
(
cmd
,
list
)
and
shell
:
cmd
=
"
"
.
join
(
arg
for
arg
in
cmd
)
popen
=
Popen
(
cmd
,
stdout
=
PIPE
,
stderr
=
stderr
,
shell
=
shell
)
# We use poll() because select() doesn't work with large fd numbers,
# and thus communicate() doesn't work either
...
...
@@ -538,3 +541,25 @@ def ensureRoot():
print
"
*** Mininet must run as root.
"
exit
(
1
)
return
def
waitListening
(
client
=
None
,
server
=
'
127.0.0.1
'
,
port
=
80
,
timeout
=
None
):
"
Wait until server is listening on port
"
run
=
(
client
.
cmd
if
client
else
partial
(
quietRun
,
shell
=
True
)
)
if
not
run
(
'
which telnet
'
):
raise
Exception
(
'
Could not find telnet
'
)
serverIP
=
server
if
type
(
server
)
is
str
else
server
.
IP
()
cmd
=
(
'
sh -c
"
echo A | telnet -e A %s %s
"'
%
(
serverIP
,
port
)
)
time
=
0
while
'
Connected
'
not
in
run
(
cmd
):
if
timeout
:
if
time
>=
timeout
:
error
(
'
could not connect to %s on port %d
\n
'
%
(
server
,
port
)
)
break
output
(
'
waiting for
'
,
server
,
'
to listen on port
'
,
port
,
'
\n
'
)
sleep
(
.
5
)
time
+=
.
5
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