7-hfsc算法應用

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章