From 0f0de8284d579fe1f1513bcbf65ccf7cd821b1b8 Mon Sep 17 00:00:00 2001 From: Eduard Date: Mon, 23 Apr 2018 13:49:08 +0200 Subject: topology: fix rate-limiting using class-based Qdiscs and HTB --- rumba/elements/topology.py | 43 +++++++++++++++++++++++++------------------ 1 file 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) -- cgit v1.2.3