Linux - Hierarchical Token Bucket (HTB)
Welcome to the tutorial guide. The guide will provide a user with guidance and instructions on hierarchical token bucket.
Hierarchical approach is well suited for setups where a user has a fixed amount of bandwidth which he/she wants to divide for different purposes, giving each purpose a guaranteed bandwidth, with the possibility of specifying how much bandwidth can be borrowed.
HTB is a classful Token Bucket Filter. As a user’s HTB configuration gets more complex, the configuration scales well. With CBQ it is already complex even in simple cases. HTB3 is now part of the official kernel sources, however a user has to get a HTB3 patched version of tc. HTB kernel and userspace parts must be the same major version, or ‘tc’ will not work with HTB.
Sample configuration
Functionally almost identical to the CBQ sample configuration above:
# tc qdisc add dev eth0 root handle 1: htb default 30
# tc class add dev eth0 parent 1: classid 1:1 htb rate 6mbit burst 15k
# tc class add dev eth0 parent 1:1 classid 1:10 htb rate 5mbit burst 15k
# tc class add dev eth0 parent 1:1 classid 1:20 htb rate 3mbit ceil 6mbit burst 15k
# tc class add dev eth0 parent 1:1 classid 1:30 htb rate 1kbit ceil 6mbit burst 15k
The author then recommends SFQ for beneath these classes:
# tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
# tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
# tc qdisc add dev eth0 parent 1:30 handle 30: sfq perturb 10
Add the filters which direct traffic to the right classes:
# U32=”tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32″
# $U32 match ip dport 80 0xffff flowid 1:10
# $U32 match ip sport 25 0xffff flowid 1:20
And that’s it - no unsightly unexplained numbers, no undocumented parameters.
HTB certainly looks wonderful - if 10: and 20: both have their guaranteed bandwidth, and more is left to divide, they borrow in a 5:3 ratio, just as you would expect.
Unclassified traffic gets routed to 30:, which has little bandwidth of its own but can borrow everything that is left over. Because we chose SFQ internally, we get fairness thrown in for free
If you followed the guidance and instructions as provided in this tutorial guide then you would have learnt about Hierarchical Token Bucket (HTB)













