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.
This will put all not-classified data to class 1:10 :
tc qdisc add dev eth0 root handle 1: htb default 10
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.
The ceil of the class is maximum bandwidth a class can get.
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.
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 2kIf 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.
Class | Rate |
---|---|
1:10 | 30 + 60 = 90 kbps |
1:11 | 10 kbps |
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 2kIf 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.
Class | Rate |
---|---|
1:10 | 30 + 30 = 60 kbps |
1:11 | 10 + 30 = 40 kbps |
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.
rate = 100 b/s, burst = 300b and we send 200bps.
- 0-3 sec : bucket is filled with 100 tokens/s, we use 200 tokens/s, so we need an extra 100 tokens/s. Our bucket size is 300 tokens, so we can send the extra 100 for 3 seconds.
- 3 - ... : Our bucket is empty, but we have a supply of 100 tokens/s, so we can send 100 bytes/s. Maybe we can send more, but we have to ask our parent for extra tokens.