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
cf5bbd59
Commit
cf5bbd59
authored
10 years ago
by
cody burkard
Browse files
Options
Downloads
Patches
Plain Diff
promote waitListening to util.py
parent
c0d8fc0d
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
+4
-8
4 additions, 8 deletions
examples/sshd.py
mininet/util.py
+19
-0
19 additions, 0 deletions
mininet/util.py
with
24 additions
and
21 deletions
examples/cpu.py
+
1
−
13
View file @
cf5bbd59
...
...
@@ -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
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
+
4
−
8
View file @
cf5bbd59
...
...
@@ -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,15 +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
+
'
&
'
)
client
=
network
.
switches
[
0
]
# wait until each host's sshd has started up
remaining
=
list
(
network
.
hosts
)
while
True
:
for
host
in
tuple
(
remaining
):
if
'
sshd is running
'
in
host
.
cmd
(
'
service ssh status
'
):
remaining
.
remove
(
host
)
if
not
remaining
:
break
for
server
in
network
.
hosts
:
waitListening
(
client
,
server
,
22
,
timeout
=
5
)
print
print
"
*** Hosts are running sshd at the following addresses:
"
...
...
This diff is collapsed.
Click to expand it.
mininet/util.py
+
19
−
0
View file @
cf5bbd59
...
...
@@ -538,3 +538,22 @@ def ensureRoot():
print
"
*** Mininet must run as root.
"
exit
(
1
)
return
def
waitListening
(
client
,
server
,
port
,
timeout
=
None
):
"
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
)
)
time
=
0
while
'
Connected
'
not
in
client
.
cmd
(
cmd
):
if
timeout
:
if
time
>=
timeout
:
error
(
'
could not connect to %s on port %d
\n
'
%
(
client
,
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