Dear reader, I'm not updating these pages anymore. If you have tc or ip related questions, you can post them on the LARTC mailing list.



Parameters

Default class

The default class is the class that will be used if no filter matches the packet. If the packet is placed in the default class, no other filters are tested and the packet is immediated dequeued. The default class is specified if you add a htb qdisc.

Example

This will put all not-classified data to class 1:10 :

tc qdisc add dev eth0 root handle 1: htb default 10

rate

The rate of a class is the guaranteed bandwidth the class will get.
If you add more then 1 subclass, make sure that the sum of the rates of the child class is equal or smaller then the rate of the parent. You don't have to follow this rule, but it's easier to understand what will happen if you do so.

ceil

The ceil of the class is maximum bandwidth a class can get.

prio

The class with the lowest prio, has the highest priority. If 2 classes are asking for extra bandwidth (after they received the rate), the class with the lowest prio will get all the bandwidth. The delay of the class with the lowest priority will also be the lowest.

Example : prio

tc class add dev eth0 parent 1: classid 1:1 htb rate 100kbps ceil 100kbps burst 2k
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 30kbps ceil 100kbps burst 2k prio 0
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 10kbps ceil 100kbps burst 2k prio 1
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 60kbps ceil 100kbps burst 2k
If there is traffic in 1:10 and 1:11, class 1:10 will get 30kbps (rate), class 1:11 will get 10kbps (rate). So the parent, class 1:1, has 100-30-10=60kbps left. Class 1:10 has the lowest prio, so class 1:10 will get the remaining 60kbps.

ClassRate
1:10 30 + 60 = 90 kbps
1:11 10 kbps

Example : prio + ceil

tc class add dev eth0 parent 1: classid 1:1 htb rate 100kbps ceil 100kbps burst 2k
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 30kbps ceil 60kbps burst 2k prio 0
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 10kbps ceil 100kbps burst 2k prio 1
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 60kbps ceil 100kbps burst 2k
If there is traffic in 1:10 and 1:11, class 1:10 will get 30kbps (rate), class 1:11 will get 10kbps (rate). So the parent, class 1:1, has 100-30-10=60kbps left. Class 1:10 has the lowest prio, so class 1:10 will get the remaining bandwidth. But the ceil of class 1:10 is 60kbps, so the class will receive only 30kbps extra from the parent. The remaining bandwidth of the parent (30kbps) is given to class 1:11.

ClassRate
1:10 30 + 30 = 60 kbps
1:11 10 + 30 = 40 kbps

tokens and ctokens

The rate and the ceil are controlled with 2 token buckets. For the rate we have a bucket filled with tokens, for the ceil, we have a bucket filled with ctokens. So we have 2 buckets / class.
Each token can carry when 1 byte. If we want to send 100 bytes, we need 100 tokens. The 100 tokens we need, are taken away from the bucket. The bucket is filled with tokens with the number of tokens / second equal to the rate (or the ceil for the ceil bucket).

So each bucket has a 'bucket size' equal to the burst/cburst and a supply of tokens equal to the rate/ceil. There is a minimal bucket size needed. Htb can calculate this for you.

example

rate = 100 b/s, burst = 300b and we send 200bps.