与iptables和tc与不稳定的广域网的QOS

我在Linux下有一个路由器/网关,我想添加一些QoS来为特定的stream量预留带宽。 这可以通过iptables / netfilter和tc完成,但是所有的例子都是事先知道可用的总带宽。

问题是,我的WAN是一个移动的3G连接,具有可变的性能。 在第一天,我可以有5 Mbps,而第二天下到2 Mbps。 我怎样才能保证我的stream量1总是有100Kbps的可用低延迟?

我想到了一个复杂的解决scheme,每天或每小时脚本检查带宽,并dynamic地创build和应用QoS脚本,但这不是一个好的解决scheme。

你应该能够用hfsc调度程序达到你的目标。 您将有能力预留一部分带宽,以“实时”方式提供低延迟保证,其他课程将使用“linkshare”按比例填充剩余带宽。

在这里重要的是使用实时而不是链接共享,因为为了确保能够在最后几毫秒发送数据包,实时能够阻止另一个类发送数据包。

为了达到你想要的效果,你需要设置一个根类(也许是10MB)的高上限,但是叶子上没有ul。 由于hfsc链路共享在所有“ls”类之间共享带宽的方式,它们将共享可用带宽,如果存在更多的话,将在m2值之上。

例如,你可以使用这种设置:

# dns, ntp, teamspeak iptables -t mangle -A POSTROUTING -o eth0 -p udp -m multiport --dports 53,123,9987 -j CLASSIFY --set-class 1:100 # Default tcp iptables -t mangle -A POSTROUTING -o eth0 -p tcp -j CLASSIFY --set-class 1:200 # Default udp iptables -t mangle -A POSTROUTING -o eth0 -p udp -j CLASSIFY --set-class 1:300 # ROOT QDISC - default goes on class 100 because it's probably arp gratuitous or whois since all ip traffic is already classified tc qdisc add dev eth0 root handle 1:0 hfsc default 100 # ROOT CLASS - Interface eth0, noeud parent de la branche : 1:0, id de la branche : 1:10 tc class add dev eth0 parent 1:0 classid 1:10 hfsc ls m2 10000kbit ul m2 10000kbit # CLASS 100 - VOIP, DNS, NTP tc class add dev eth0 parent 1:10 classid 1:100 hfsc sc m1 400kbit d 10ms m2 100kbit # QDISC tc qdisc add dev eth0 parent 1:100 handle 110: fq_codel quantum 300 noecn # fq_codel requires to change the quantum for low bandwitdth # CLASS 200 - some tcp tc class add dev eth0 parent 1:10 classid 1:200 hfsc ls m1 80kbit d 10ms m2 80kbit # QDISC - some tcp tc qdisc add dev eth0 parent 1:200 handle 210: fq_codel # CLASS 300 - some udp tc class add dev eth0 parent 1:10 classid 1:300 hfsc ls m1 20kbit d 10ms m2 20kbit # ratio tcp / udp will then be 4:1 # QDISC - some udp tc qdisc add dev eth0 parent 1:300 handle 310: fq_codel quantum 300 noecn 

值可能需要根据您的需要进行更改,特别是在100级,尽pipe我试图写这些数字以适应您的3G。

你应该阅读更多关于人tc-hfsc, 这篇文章和这篇文章,以了解更多关于hfsc及其工作原理。