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
fcd01592
Commit
fcd01592
authored
12 years ago
by
Brandon Heller
Browse files
Options
Downloads
Patches
Plain Diff
Move CPU limit into net, to be reused in future unit tests
parent
e1205a8a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/limit.py
+4
-20
4 additions, 20 deletions
examples/limit.py
mininet/net.py
+36
-0
36 additions, 0 deletions
mininet/net.py
with
40 additions
and
20 deletions
examples/limit.py
+
4
−
20
View file @
fcd01592
...
...
@@ -8,33 +8,17 @@
from
mininet.link
import
TCIntf
from
mininet.node
import
CPULimitedHost
from
mininet.topolib
import
TreeTopo
from
mininet.util
import
custom
,
quietRun
from
mininet.util
import
custom
from
mininet.log
import
setLogLevel
from
time
import
sleep
def
testLinkLimit
(
net
,
bw
):
"
Run bandwidth limit test
"
print
'
*** Testing network %.2f Mbps bandwidth limit
'
%
bw
net
.
iperf
(
)
def
testCpuLimit
(
net
,
cpu
):
"
run CPU limit test
"
pct
=
cpu
*
100
print
'
*** Testing CPU %.0f%% bandwidth limit
'
%
pct
h1
,
h2
=
net
.
hosts
h1
.
cmd
(
'
while true; do a=1; done &
'
)
h2
.
cmd
(
'
while true; do a=1; done &
'
)
pid1
=
h1
.
cmd
(
'
echo $!
'
).
strip
()
pid2
=
h2
.
cmd
(
'
echo $!
'
).
strip
()
cmd
=
'
ps -p %s,%s -o pid,%%cpu,args
'
%
(
pid1
,
pid2
)
# It's a shame that this is what pylint prefers
for
_
in
range
(
5
):
sleep
(
1
)
print
quietRun
(
cmd
).
strip
()
h1
.
cmd
(
'
kill %1
'
)
h2
.
cmd
(
'
kill %1
'
)
def
limit
(
bw
=
10
,
cpu
=
.
4
):
def
limit
(
bw
=
10
,
cpu
=
.
1
):
"""
Example/test of link and CPU bandwidth limits
bw: interface bandwidth limit in Mbps
cpu: cpu limit as fraction of overall CPU time
"""
...
...
@@ -46,7 +30,7 @@ def limit( bw=10, cpu=.4 ):
net
=
Mininet
(
topo
=
myTopo
,
intf
=
intf
,
host
=
host
)
net
.
start
()
testLinkLimit
(
net
,
bw
=
bw
)
test
CpuLimit
(
net
,
cpu
=
cpu
)
net
.
run
CpuLimit
Test
(
cpu
=
cpu
)
net
.
stop
()
def
verySimpleLimit
(
bw
=
150
):
...
...
This diff is collapsed.
Click to expand it.
mininet/net.py
+
36
−
0
View file @
fcd01592
...
...
@@ -530,6 +530,42 @@ def iperf( self, hosts=None, l4Type='TCP', udpBw='10M' ):
output
(
'
*** Results: %s
\n
'
%
result
)
return
result
def
runCpuLimitTest
(
self
,
cpu
,
duration
=
5
):
"""
run CPU limit test with
'
while true
'
processes.
cpu: desired CPU fraction of each host
duration: test duration in seconds
returns a single list of measured CPU fractions as floats.
"""
pct
=
cpu
*
100
info
(
'
*** Testing CPU %.0f%% bandwidth limit
\n
'
%
pct
)
hosts
=
self
.
hosts
for
h
in
hosts
:
h
.
cmd
(
'
while true; do a=1; done &
'
)
pids
=
[
h
.
cmd
(
'
echo $!
'
).
strip
()
for
h
in
hosts
]
pids_str
=
"
,
"
.
join
([
"
%s
"
%
pid
for
pid
in
pids
])
cmd
=
'
ps -p %s -o pid,%%cpu,args
'
%
pids_str
# It's a shame that this is what pylint prefers
outputs
=
[]
for
_
in
range
(
duration
):
sleep
(
1
)
outputs
.
append
(
quietRun
(
cmd
).
strip
()
)
for
h
in
hosts
:
h
.
cmd
(
'
kill %1
'
)
cpu_fractions
=
[]
for
test_output
in
outputs
:
# Split by line. Ignore first line, which looks like this:
# PID %CPU COMMAND\n
for
line
in
test_output
.
split
(
'
\n
'
)[
1
:]:
r
=
r
'
\d+ (\d+\.\d+)
'
m
=
re
.
search
(
r
,
line
)
if
m
is
None
:
error
(
'
*** Error: could not extract CPU fraction: %s
\n
'
%
line
)
return
None
cpu_fractions
.
append
(
float
(
m
.
group
(
1
)
)
)
output
(
'
*** Results: %s
\n
'
%
cpu_fractions
)
return
cpu_fractions
# BL: I think this can be rewritten now that we have
# a real link class.
def
configLinkStatus
(
self
,
src
,
dst
,
status
):
...
...
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