https://access.redhat.com/solutions/1459623
SOLUTION 已验证 - 已更新 2015年五月26日09:34 -
环境
- Red Hat Enterprise Linux 6.3 or later
-
tc
traffic control utility -
qfq
Quick Fair Scheduler queueing discipline
问题
- How to use
qfq
qdisc oftc
? - In Red Hat Enterprise Linux 6.3, the
tc
utility has been updated to work with the Quick Fair Scheduler (QFQ) kernel features. Users can now take advantage of the new QFQ traffic queuing discipline from userspace. This feature is considered a Technology Preview.
决议
The following bash script is an example of how to add a qdisc, classes, and matches:
#!/bin/bash
### pass the interface name as a variable if desired
if [ -z "$1" ]; then
DEV="eth0"
else
DEV="$1"
fi
### delete any existing qdiscs on the interface
tc qdisc del dev "$DEV" root
### add a root qdisc to the interface
tc qdisc add dev "$DEV" root handle 1: qfq
### add rate limit classes
## here we add two rates, traffic is balanced at a ratio of 100:200 between the two classes
## if using jumboframes, append "maxpkt 9000" onto the end of these
tc class add dev "$DEV" parent 1: classid 1:1 qfq weight 100
tc class add dev "$DEV" parent 1: classid 1:2 qfq weight 200
### match packets into rate limiters
## this matches outgoing ssh into the first rate limiter
tc filter add dev "$DEV" parent 1: protocol all prio 1 u32 match ip dport 22 0xffff flowid 1:1
## match all remaining packets into the second rate limiter
tc filter add dev "$DEV" parent 1: protocol all prio 2 u32 match u32 0 0 flowid 1:2
Results
- View the qdisc active on the interface
# tc -s -d qdisc show dev eth0
sc qfq 1: root refcnt 2
Sent 91325 bytes 468 pkt (dropped 40, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
- View the classes active on the qdisc
# tc -s -d class show dev eth0
class qfq 1:1 root weight 1000 maxpkt 1514
Sent 10847 bytes 67 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
class qfq 1:2 root weight 2000 maxpkt 2962
Sent 80720 bytes 402 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
- View the filters on the classes
# tc filter show dev eth0
filter parent 1: protocol all pref 1 u32
filter parent 1: protocol all pref 1 u32 fh 800: ht divisor 1
filter parent 1: protocol all pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
match 00000016/0000ffff at 20
filter parent 1: protocol all pref 2 u32
filter parent 1: protocol all pref 2 u32 fh 801: ht divisor 1
filter parent 1: protocol all pref 2 u32 fh 801::800 order 2048 key ht 801 bkt 0 flowid 1:2
match 00000000/00000000 at 0
Further Reading
Building a more complex classifier chain and classifying traffic into filters is described in the upstream Linux Advanced Routing & Traffic Control HOWTO, the steps are common to any classful qdisc.