HFSC - Hierarchical Fair Service Curve’s control under linux 层次公平服务曲线
hfsc允许按比例分配频宽并且控制及分配延迟(latency)。这能够在只有一条实体网路连线的情况下,又快又好地同时提供频宽密集的资料传输服务及互动式服务。
hfsc演算法,设置总带宽,按比例分配每个类的百分比,并且可以按类别设置,区分成即时(real-time)和连接共享(link-sharing)两种标准。一个叶类别可以同时指派real-tim及link-sharing曲线,而子类别只能有一个link-sharing曲线。即时(real-time)只适用于叶类别,因为实际上只有叶类别持有封包。因此即时导向的准则负责必要服务的达成。连接共享(link-sharing)的标准则只涉及本身与相邻类别的关连,负责公平分配,而不提供绝对的保证。为了在各种情况下都能够确保最低延迟时间,分离成两个标准是必要的。以结果而言,这也表示即使已经短暂超过上层子类别link-sharing曲线之限制,仍然可以根据叶类别的即时保证继续发送封包。
如下:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-otJ4i1FC-1588839486170)(http://linux-ip.net/articles/hfsc.en/hierarchie.en.gif)]
tc qdisc add ... hfsc [ default CLASSID ]
tc class add ... hfsc [ [ rt SC ] [ ls SC ] | [ sc SC ] ] [ ul SC ]
rt : realtime service curve
ls : linkshare service curve(百分比)
sc : rt+ls service curve
ul : upperlimit service curve
* at least one of rt, ls or sc must be specified
* ul can only be specified with ls or sc
SC := [ [ m1 BPS ] d SEC ] m2 BPS
m1 : slope of the first segment
d : x-coordinate of intersection
m2 : slope of the second segment
SC := [ [ umax BYTE ] dmax SEC ] rate BPS
umax : maximum unit of work
dmax : maximum delay
rate : rate
1.root/根类别:
/usr/sbin/tc qdisc add dev ifb4eth1 root handle 1: prio bands 2 priomap 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
/usr/sbin/tc qdisc add dev ifb4eth1 parent 1:1 handle 10: pfifo limit 3000
/usr/sbin/tc qdisc add dev ifb4eth1 parent 1:2 handle 20: hfsc default 3
/usr/sbin/tc class add dev ifb4eth1 parent 20: classid 20:1 hfsc ls rate 1000Mbit ul rate 1024000kbit
/usr/sbin/tc filter add dev ifb4eth1 parent 1: protocol ip prio 1 handle 0xf0/0xf0 fw flowid 1:1
/usr/sbin/tc filter add dev ifb4eth1 parent 1: protocol ip prio 2 u32 match ip protocol 1 0xf0/0xf0 flowid 1:1
Illegal "match"
/usr/sbin/tc filter add dev ifb4eth1 parent 1: protocol arp prio 3 handle 0xf0/0xf0 fw classid 1:1
/usr/sbin/tc filter add dev ifb4eth1 parent 1: protocol ip prio 4 u32 match u8 0x00 0x00 at 0 flowid 1:2
2.inner class/子类别:
config download_class 'd1'
option name 'RealTime'
option percent_bandwidth '10'
option min_bandwidth '80'
option max_bandwidth '200'
option min_rtt '1'
config download_class 'd2'
option name 'Fast'
option percent_bandwidth '70'
config download_class 'd3'
option name 'Slow'
option percent_bandwidth '2'
config download_class 'd4'
option name 'Normal'
option percent_bandwidth '18'
/usr/sbin/tc class add dev ifb4eth1 parent 20:1 classid 20:2 hfsc rt m2 80kbit ls m1 100Mbit d 20ms m2 100Mbit ul m2 200kbit
/usr/sbin/tc qdisc add dev ifb4eth1 parent 20:2 handle 202:1 fq_codel limit 4096 target 5000us interval 100000us ecn quantum 3000 flows 1024
/usr/sbin/tc filter add dev ifb4eth1 parent 20:0 protocol ip handle 0x20/0xf0 fw flowid 20:2
/usr/sbin/tc filter add dev ifb4eth1 parent 202: handle 1 protocol all flow hash keys nfct-src,nfct-dst,nfct-proto,nfct-proto-src,nfct-proto-dst divisor 1024
/usr/sbin/tc class add dev ifb4eth1 parent 20:1 classid 20:3 hfsc ls m2 700Mbit
/usr/sbin/tc qdisc add dev ifb4eth1 parent 20:3 handle 203:1 fq_codel limit 4096 target 5000us interval 100000us ecn quantum 3000 flows 1024
/usr/sbin/tc filter add dev ifb4eth1 parent 20:0 protocol ip handle 0x30/0xf0 fw flowid 20:3
/usr/sbin/tc filter add dev ifb4eth1 parent 203: handle 1 protocol all flow hash keys nfct-src,nfct-dst,nfct-proto,nfct-proto-src,nfct-proto-dst divisor 1024
/usr/sbin/tc class add dev ifb4eth1 parent 20:1 classid 20:4 hfsc ls m2 20Mbit
/usr/sbin/tc qdisc add dev ifb4eth1 parent 20:4 handle 204:1 fq_codel limit 4096 target 5000us interval 100000us ecn quantum 3000 flows 1024
/usr/sbin/tc filter add dev ifb4eth1 parent 20:0 protocol ip handle 0x40/0xf0 fw flowid 20:4
/usr/sbin/tc filter add dev ifb4eth1 parent 204: handle 1 protocol all flow hash keys nfct-src,nfct-dst,nfct-proto,nfct-proto-src,nfct-proto-dst divisor 1024
/usr/sbin/tc class add dev ifb4eth1 parent 20:1 classid 20:5 hfsc ls m2 180Mbit
/usr/sbin/tc qdisc add dev ifb4eth1 parent 20:5 handle 205:1 fq_codel limit 4096 target 5000us interval 100000us ecn quantum 3000 flows 1024
/usr/sbin/tc filter add dev ifb4eth1 parent 20:0 protocol ip handle 0x50/0xf0 fw flowid 20:5
/usr/sbin/tc filter add dev ifb4eth1 parent 205: handle 1 protocol all flow hash keys nfct-src,nfct-dst,nfct-proto,nfct-proto-src,nfct-proto-dst divisor 1024
3.leaf class/叶类别:
使用mark关联到上面已经创建好的子类别,相当于规定了那些包,走上面的哪一个规则。
config zqos_rule
option download_class '1'
option upload_class '1'
option min_pkt_size '0'
option max_pkt_size '100'
option proto 'all'
iptables -t mangle -D QOS_RULES_eth1 -p tcp ! --syn -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
iptables: No chain/target/match by that name.
ip6tables -t mangle -D QOS_RULES_eth1 -p tcp ! --syn -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
/usr/lib/zqos/start-zqos: eval: line 1: ip6tables: not found
iptables -t mangle -A QOS_RULES_eth1 -p tcp ! --syn -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
ip6tables -t mangle -A QOS_RULES_eth1 -p tcp ! --syn -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
/usr/lib/zqos/start-zqos: eval: line 1: ip6tables: not found
iptables -t mangle -D QOS_RULES_eth1 -p udp -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
iptables: No chain/target/match by that name.
ip6tables -t mangle -D QOS_RULES_eth1 -p udp -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
/usr/lib/zqos/start-zqos: eval: line 1: ip6tables: not found
iptables -t mangle -A QOS_RULES_eth1 -p udp -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
ip6tables -t mangle -A QOS_RULES_eth1 -p udp -s 0.0.0.0/0 -d 0.0.0.0/0 -m multiport --sports 0:65535 -m multiport --dports 0:65535 -m length --length 0:100 -j MARK --set-mark 0x22/0xfffff
/usr/lib/zqos/start-zqos: eval: line 1: ip6tables: not found
4.限速
config zqos_node
option enabled '1'
option comment 't1'
option upload '204800'
option download '102400'
option mac '14:75:90:F7:97:7D'
option white '0'
iptables -t mangle -D QOS_RULES_FORWARD_eth1 -m mac --mac-source 14:75:90:F7:97:7D -d 0.0.0.0/0 -j MARK --set-mark 257/0xfffff
iptables: No chain/target/match by that name.
ip6tables -t mangle -D QOS_RULES_FORWARD_eth1 -m mac --mac-source 14:75:90:F7:97:7D -d 0.0.0.0/0 -j MARK --set-mark 257/0xfffff
/usr/lib/zqos/start-zqos: eval: line 1: ip6tables: not found
iptables -t mangle -A QOS_RULES_FORWARD_eth1 -m mac --mac-source 14:75:90:F7:97:7D -d 0.0.0.0/0 -j MARK --set-mark 257/0xfffff
ip6tables -t mangle -A QOS_RULES_FORWARD_eth1 -m mac --mac-source 14:75:90:F7:97:7D -d 0.0.0.0/0 -j MARK --set-mark 257/0xfffff
/usr/lib/zqos/start-zqos: eval: line 1: ip6tables: not found
/usr/sbin/tc class add dev eth1 parent 20:1 classid 20:17 hfsc sc rate 204800kbit ul rate 204800kbit
/usr/sbin/tc filter add dev eth1 parent 20:0 protocol ip handle 257/0xfffff fw flowid 20:17
/usr/sbin/tc class add dev ifb4eth1 parent 20:1 classid 20:17 hfsc sc rate 102400kbit ul rate 102400kbit
/usr/sbin/tc filter add dev ifb4eth1 parent 20:0 protocol ip handle 257/0xfffff fw flowid 20:17
比HTB精确的HFSC:http://linux-ip.net/articles/hfsc.en/
翻译: https://blog.csdn.net/wuwentao2000/article/details/7484818
https://www.right.com.cn/forum/forum.php?mod=viewthread&tid=72817
http://www.linuxhowtos.org/manpages/7/tc-hfsc.htm
http://www.linuxhowtos.org/manpages/8/tc-hfsc.htm
Linux TC流量控制HOWTO中文版
http://www.360doc.com/content/12/0731/14/1073512_227467421.shtml
QoS和QoS队列调度算法:https://blog.csdn.net/liu5257/article/details/78354193
QOS配置参数对HFSC算法的影响:https://blog.csdn.net/qisefengzheng/article/details/50848079