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.



Why

How are the settings of leaf classes used to calculate the bandwidth is known. But how are the settings of the parent classes are used in these calculations?

Test 1

This is just a basic simple tests to see if the parent rate is also a minimum rate for the child class.

Used script (download)

tc qdisc del dev eth0 root

tc qdisc add dev eth0 root handle 1:0 htb

tc class add dev eth0 parent 1:   classid 1:1   htb rate 200kbps

tc class add dev eth0 parent 1:1  classid 1:10  htb rate 150kbps ceil 200kbps
tc class add dev eth0 parent 1:1  classid 1:20  htb rate  50kbps ceil 200kbps

tc class add dev eth0 parent 1:10 classid 1:100 htb rate 100kbps ceil 200kbps
tc class add dev eth0 parent 1:20 classid 1:200 htb rate 100kbps ceil 200kbps

tc filter add dev eth0 parent 1: protocol ip handle 1 fw classid 1:100
tc filter add dev eth0 parent 1: protocol ip handle 2 fw classid 1:200

Results

Both leaf classes are able to ask for the configured rate (100 kbps). But the parent of class 100 (class 10) has a rate of 150 kbps and only 100 kbpos is used, so class 100 can get an other 50 kbps. So the rate of the parent is also used to calculate the maximum bandwidth a leaf class can get.

Test 1 bis

I redid the previous test, but with different rates for class 1:1 and ceils for the leaf classes.

Used script (download)

MAX=$1
tc qdisc del dev eth0 root

tc qdisc add dev eth0 root handle 1:0 htb

tc class add dev eth0 parent 1:   classid 1:1   htb rate $MAX

tc class add dev eth0 parent 1:1  classid 1:10  htb rate 150kbps ceil $MAX
tc class add dev eth0 parent 1:1  classid 1:20  htb rate  50kbps ceil $MAX

tc class add dev eth0 parent 1:10 classid 1:100 htb rate 100kbps ceil $MAX
tc class add dev eth0 parent 1:20 classid 1:200 htb rate 100kbps ceil $MAX

tc filter add dev eth0 parent 1: protocol ip handle 1 fw classid 1:100
tc filter add dev eth0 parent 1: protocol ip handle 2 fw classid 1:200

Results

I started the test with MAX=200kbps. At 13s, I rerun the script with MAX=250kbps. But as you can see, that didn't changed much. Even with MAX=200kbps, both class are already sending 250kbps. So setting MAX to 250kbps didn't chaged anything.

Both leaf classes are able to send the configured rate. But they also borrow unused rates from the parents.

Test 2

How is the ceil of the classes used in the bandwidth calculations?

Used script (download)

tc qdisc del dev eth0 root

tc qdisc add dev eth0 root handle 1:0 htb

tc class add dev eth0 parent 1:   classid 1:1   htb rate 100kbps

tc class add dev eth0 parent 1:1  classid 1:10  htb rate 150kbps ceil 100kbps
tc class add dev eth0 parent 1:1  classid 1:20  htb rate  50kbps ceil 100kbps

tc class add dev eth0 parent 1:10 classid 1:100 htb rate 50kbps ceil 200kbps
tc class add dev eth0 parent 1:20 classid 1:200 htb rate 50kbps ceil 200kbps

tc filter add dev eth0 parent 1: protocol ip handle 1 fw classid 1:100
tc filter add dev eth0 parent 1: protocol ip handle 2 fw classid 1:200

Results

What happens? Both class are allowed to send 50kbps. Class 100 can asks for more bandwidth to its parent. The parent has 150kbps as rate, but only 100kbps as ceil. So the child class can asks an other 50kbps before the parent hits his ceil.

So the parent ceil is respected. But remember that the child class can always sends its configured rate even if that means it breaks the parent ceil.

Test 3

Used script (download)

tc qdisc del dev eth0 root

tc qdisc add dev eth0 root handle 1:0 htb

tc class add dev eth0 parent 1:   classid 1:1   htb rate 200kbps

tc class add dev eth0 parent 1:1  classid 1:10  htb rate  80kbps ceil 200kbps
tc class add dev eth0 parent 1:1  classid 1:20  htb rate 120kbps ceil 200kbps

tc class add dev eth0 parent 1:10 classid 1:100 htb rate  20kbps ceil 200kbps
tc class add dev eth0 parent 1:20 classid 1:200 htb rate 100kbps ceil 200kbps

tc filter add dev eth0 parent 1: protocol ip handle 1 fw classid 1:100
tc filter add dev eth0 parent 1: protocol ip handle 2 fw classid 1:200

Results

Test 4

Used script (download)

tc qdisc add dev eth0 root handle 1:0 htb

tc class add dev eth0 parent 1:   classid 1:1   htb rate 200kbps

tc class add dev eth0 parent 1:1  classid 1:10  htb rate  20kbps ceil 200kbps
tc class add dev eth0 parent 1:1  classid 1:20  htb rate  10kbps ceil 200kbps

tc class add dev eth0 parent 1:10 classid 1:100 htb rate  20kbps ceil 200kbps
tc class add dev eth0 parent 1:20 classid 1:200 htb rate  10kbps ceil 200kbps

tc filter add dev eth0 parent 1: protocol ip handle 1 fw classid 1:100
tc filter add dev eth0 parent 1: protocol ip handle 2 fw classid 1:200

Results

Let's calculate the bandwidth. Both leaf class are allowed to send the configured rate : 20 + 10. But the remainig bandwidth (70 kbps) is just splitted in 2. I still don't know why.