I have a script that sets up traffic shaping on port eth0. The script is as follows:
import os
import subprocess
def run(cmd):
print cmd
result = subprocess.check_output(cmd, shell=True)
print result
interface_name = 'eth0'
bandwidth = 1
remove_rule = "sudo tc qdisc del dev {} root".format(interface_name)
cmd1 = 'sudo tc qdisc add dev {} handle 1: root htb default 11'.format(interface_name)
cmd2 = 'sudo tc class add dev {} parent 1: classid 1:1 htb rate {}kbit ceil {}kbit'.format(interface_name, bandwidth, bandwidth)
cmd3 = 'sudo tc class add dev {} parent 1:1 classid 1:11 htb rate {}kbit ceil {}kbit'.format(interface_name, bandwidth, bandwidth)
try:
run(remove_rule)
except:
print 'Qdisc does not exist yet'
run(cmd1)
run(cmd2)
run(cmd3)
show_qdisc = 'tc -s -d qdisc show dev {}'.format(interface_name)
show_class = 'tc -s -d class show dev {}'.format(interface_name)
run(show_qdisc)
run(show_class)
Fairly straightforward traffic classification. When I run the script, tc show reports the following details.
tc -s -d qdisc show dev eth0
qdisc htb 1: root refcnt 3 r2q 10 default 11 direct_packets_stat 6 ver 3.17 direct_qlen 1000
Sent 1154 bytes 9 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
tc -s -d class show dev eth0
class htb 1:11 parent 1:1 prio 0 quantum 1000 rate 1Kbit ceil 1Kbit linklayer ethernet burst 1600b/1 mpu 0b overhead 0b cburst 1600b/1 mpu 0b overhead 0b level 0
Sent 680 bytes 4 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
lended: 4 borrowed: 0 giants: 0
tokens: 115032210 ctokens: 115032210
class htb 1:1 root rate 1Kbit ceil 1Kbit linklayer ethernet burst 1600b/1 mpu 0b overhead 0b cburst 1600b/1 mpu 0b overhead 0b level 7
Sent 680 bytes 4 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
lended: 0 borrowed: 0 giants: 0
tokens: 115032210 ctokens: 115032210
However, when I send traffic out of eth0 using iperf3, there is no throttling whatsover. When I run tc show (this time manually), the result is:
$sudo tc -s -d class show dev eth0
class mq :1 root
Sent 901415262 bytes 100878 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
class mq :2 root
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
Any insight as to why 1.) the throttling is not working and 2.) why the result of tc show class is inconsistent?
0 Answers