Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
27ce6c3b
Commit
27ce6c3b
authored
Aug 04, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document Link parameters. Fix units. Add a couple more tests
parent
ed14e260
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
19 deletions
+50
-19
src/netns/interface.py
src/netns/interface.py
+14
-0
src/netns/iproute.py
src/netns/iproute.py
+15
-15
t/test_link.py
t/test_link.py
+21
-4
No files found.
src/netns/interface.py
View file @
27ce6c3b
...
...
@@ -360,6 +360,20 @@ class Link(ExternalInterface):
loss
=
None
,
loss_correlation
=
None
,
dup
=
None
,
dup_correlation
=
None
,
corrupt
=
None
,
corrupt_correlation
=
None
):
"""Set the parameters that control the link characteristics. For the
description of each, refer to netem documentation:
http://www.linuxfoundation.org/collaborate/workgroups/networking/netem
Arguments:
- `bandwidth' should be specified in bits per second.
- `delay' and `delay_jitter' are specified in seconds.
- `delay_distribution' is the name of a distribution description file;
`iproute' comes by default with `normal', `pareto', and
`paretonormal'.
- `delay_correlation', `loss', `loss_correlation', `dup',
`dup_correlation', `corrupt', and `corrupt_correlation' take a
percentage value in the form of a number between 0 and 1. (50% is
passed as 0.5)."""
parameters
=
dict
(
bandwidth
=
bandwidth
,
delay
=
delay
,
delay_jitter
=
delay_jitter
,
delay_correlation
=
delay_correlation
,
...
...
src/netns/iproute.py
View file @
27ce6c3b
...
...
@@ -753,7 +753,7 @@ def _parse_netem_delay(line):
ret["delay_jitter"] = delay_jitter
if match.group(5):
ret["delay_correlation"] = float(match.group(5))
ret["delay_correlation"] = float(match.group(5))
/ 100
if match.group(6):
ret["delay_distribution"] = match.group(6)
...
...
@@ -766,9 +766,9 @@ def _parse_netem_loss(line):
if not match:
return ret
ret["loss"] = float(match.group(1))
ret["loss"] = float(match.group(1))
/ 100
if match.group(2):
ret["loss_correlation"] = float(match.group(2))
ret["loss_correlation"] = float(match.group(2))
/ 100
return ret
def _parse_netem_dup(line):
...
...
@@ -777,9 +777,9 @@ def _parse_netem_dup(line):
if not match:
return ret
ret["dup"] = float(match.group(1))
ret["dup"] = float(match.group(1))
/ 100
if match.group(2):
ret["dup_correlation"] = float(match.group(2))
ret["dup_correlation"] = float(match.group(2))
/ 100
return ret
def _parse_netem_corrupt(line):
...
...
@@ -788,9 +788,9 @@ def _parse_netem_corrupt(line):
if not match:
return ret
ret["corrupt"] = float(match.group(1))
ret["corrupt"] = float(match.group(1))
/ 100
if match.group(2):
ret["corrupt_correlation"] = float(match.group(2))
ret["corrupt_correlation"] = float(match.group(2))
/ 100
return ret
def get_tc_data():
...
...
@@ -888,7 +888,7 @@ def set_tc(iface, bandwidth = None, delay = None, delay_jitter = None,
cmd = "add"
if bandwidth:
rate = "%db
ps
" % int(bandwidth)
rate = "%db
it
" % int(bandwidth)
mtu = ifdata[iface.index].mtu
burst = max(mtu, int(bandwidth) / _hz)
limit = burst * 2 # FIXME?
...
...
@@ -918,23 +918,23 @@ def set_tc(iface, bandwidth = None, delay = None, delay_jitter = None,
if delay_jitter:
command += ["%fs" % delay_jitter]
if delay_correlation:
command += ["%f%%" %
delay_correlation
]
command += ["%f%%" %
(delay_correlation * 100)
]
if delay_distribution:
if not delay_jitter: # or not delay_correlation:
raise ValueError("delay_distribution requires delay_jitter")
command += ["distribution", delay_distribution]
if loss:
command += ["loss", "%f%%" %
loss
]
command += ["loss", "%f%%" %
(loss * 100)
]
if loss_correlation:
command += ["%f%%" %
loss_correlation
]
command += ["%f%%" %
(loss_correlation * 100)
]
if dup:
command += ["duplicate", "%f%%" %
dup
]
command += ["duplicate", "%f%%" %
(dup * 100)
]
if dup_correlation:
command += ["%f%%" %
dup_correlation
]
command += ["%f%%" %
(dup_correlation * 100)
]
if corrupt:
command += ["corrupt", "%f%%" %
corrupt
]
command += ["corrupt", "%f%%" %
(corrupt * 100)
]
if corrupt_correlation:
command += ["%f%%" %
corrupt_correlation
]
command += ["%f%%" %
(corrupt_correlation * 100)
]
commands.append(command)
for c in commands:
...
...
t/test_link.py
View file @
27ce6c3b
...
...
@@ -32,13 +32,30 @@ class TestLink(unittest.TestCase):
self
.
assertEquals
(
ifdata
[
i2
.
control
.
index
].
up
,
True
,
"UP propagation"
)
# None => tbf
l
.
set_parameters
(
bandwidth
=
1
00
*
1024
*
1024
/
8
)
# 100 mbits
l
.
set_parameters
(
bandwidth
=
1
3107200
)
# 100 mbits
tcdata
=
netns
.
iproute
.
get_tc_data
()[
0
]
self
.
assertEquals
(
tcdata
[
i1
.
control
.
index
],
{
'bandwidth'
:
104858000
,
'qdiscs'
:
{
'tbf'
:
'1'
}})
# adjust for tc rounding
{
'bandwidth'
:
13107000
,
'qdiscs'
:
{
'tbf'
:
'1'
}})
self
.
assertEquals
(
tcdata
[
i2
.
control
.
index
],
{
'bandwidth'
:
104858000
,
'qdiscs'
:
{
'tbf'
:
'1'
}})
#bandwidth = 100*1024*1024/8, loss=10, loss_correlation=1,delay=0.001,dup_correlation=0.1);
{
'bandwidth'
:
13107000
,
'qdiscs'
:
{
'tbf'
:
'1'
}})
# none again
l
.
set_parameters
()
tcdata
=
netns
.
iproute
.
get_tc_data
()[
0
]
self
.
assertEquals
(
tcdata
[
i1
.
control
.
index
],
{
'qdiscs'
:
{}})
self
.
assertEquals
(
tcdata
[
i2
.
control
.
index
],
{
'qdiscs'
:
{}})
# cheat and see what happens
os
.
system
((
"tc qd add dev %s root prio bands 3 "
+
"priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1"
)
%
i1
.
control
.
name
)
tcdata
=
netns
.
iproute
.
get_tc_data
()[
0
]
self
.
assertEquals
(
tcdata
[
i1
.
control
.
index
],
"foreign"
)
l
.
set_parameters
(
bandwidth
=
13107200
)
# 100 mbits
tcdata
=
netns
.
iproute
.
get_tc_data
()[
0
]
self
.
assertEquals
(
tcdata
[
i1
.
control
.
index
],
{
'bandwidth'
:
13107000
,
'qdiscs'
:
{
'tbf'
:
'1'
}})
# FIXME: more cases
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment