aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduard <eduard.grasa@i2cat.net>2018-04-23 13:49:08 +0200
committerEduard <eduard.grasa@i2cat.net>2018-04-23 14:27:24 +0200
commit0f0de8284d579fe1f1513bcbf65ccf7cd821b1b8 (patch)
tree046be898b4ee0dd8db57b61c082ac58bdcb19b46
parent4bc964d576e17c268b8cf80f1be53a8d974ba4e6 (diff)
downloadrumba-0f0de8284d579fe1f1513bcbf65ccf7cd821b1b8.tar.gz
rumba-0f0de8284d579fe1f1513bcbf65ccf7cd821b1b8.zip
topology: fix rate-limiting using class-based Qdiscs and HTB
-rw-r--r--rumba/elements/topology.py43
1 files changed, 25 insertions, 18 deletions
diff --git a/rumba/elements/topology.py b/rumba/elements/topology.py
index f717a5a..87aeb4c 100644
--- a/rumba/elements/topology.py
+++ b/rumba/elements/topology.py
@@ -485,24 +485,31 @@ class LinkQuality(object):
def rate(self):
return self._rate
- def build_command(self, ipcp):
- cmd = []
+ def build_commands(self, ipcp):
+ netem_cmd = []
+ cmds = []
+ qref = "root"
if ipcp in LinkQuality._active:
- cmd.append("tc qdisc change dev %s root netem" % ipcp.ifname)
- else:
- cmd.append("tc qdisc add dev %s root netem" % ipcp.ifname)
-
- if self.delay:
- cmd.append(self.delay.build_command())
-
- if self.loss:
- cmd.append(self.loss.build_command())
+ cmds.append("tc qdisc del dev %s root" % ipcp.ifname)
if self.rate:
- cmd.append("rate %imbit" % self.rate)
-
- return " ".join(cmd)
+ cmds.append("tc qdisc add dev %s root handle 1: htb default 1" \
+ % ipcp.ifname)
+ cmds.append("tc class add dev %s parent 1: classid 1:1 htb rate %imbit" \
+ % (ipcp.ifname, self.rate))
+ qref = "parent 1:1"
+
+ if self.delay or self.loss:
+ netem_cmd.append("tc qdisc add dev %s %s netem" \
+ % (ipcp.ifname, qref))
+ if self.delay:
+ netem_cmd.append(self.delay.build_command())
+ if self.loss:
+ netem_cmd.append(self.loss.build_command())
+ cmds.append(" ".join(netem_cmd))
+
+ return cmds
def apply(self, shim):
if not (self.delay or self.loss or self.rate):
@@ -514,8 +521,8 @@ class LinkQuality(object):
"the interface name is None")
continue
- ipcp.node.execute_command(self.build_command(ipcp),
- as_root=True)
+ ipcp.node.execute_commands(self.build_commands(ipcp),
+ as_root=True)
LinkQuality._active.add(ipcp)
def deactivate(self, shim):
@@ -527,8 +534,8 @@ class LinkQuality(object):
"the interface name is None")
continue
- ipcp.node.execute_command("tc qdisc del dev %s root "
- "netem" % ipcp.ifname, as_root=True)
+ ipcp.node.execute_command("tc qdisc del dev %s root"
+ % ipcp.ifname, as_root=True)
LinkQuality._active.remove(ipcp)