eth0 的 Qdisc 类正在消失

eth0 的 Qdisc 类正在消失

我有一个脚本,用于在端口 eth0 上设置流量整形。脚本如下:

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)

相当简单的流量分类。当我运行脚本时,tc show 报告以下详细信息。

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

但是,当我使用 iperf3 将流量从 eth0 发送出去时,没有任何限制。当我运行 tc show(这次是手动)时,结果是:

$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

有什么见解可以解释为什么 1.) 节流不起作用以及 2.) 为什么 tc show class 的结果不一致?

相关内容