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.



I'm redoing the test with htb3.

Setup

The setup is easy. I want 2 classes who can borrow bandwidth from each other, but together they may not use more then 100kbps.

Used script (download)

BW1=$1'kbps'
BW2=`expr 100 - $1`
BW2=$BW2'kbps'

tc qdisc del dev eth0 root handle 1:

tc qdisc add dev eth0 root handle 1: htb default 12
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 $BW1 ceil 100kbps burst 2k
tc class add dev eth0 parent 1:1 classid 1:11 htb rate $BW2 ceil 100kbps burst 2k

tc filter add dev eth0 parent 1: protocol ip prio 3 handle 1 fw classid 1:10
tc filter add dev eth0 parent 1: protocol ip prio 3 handle 2 fw classid 1:11

iptables -F
iptables -X
iptables -N acc_0
iptables -N acc_1
iptables -A OUTPUT -t mangle -p tcp --dport 2000 -j MARK --set-mark 1
iptables -A OUTPUT -t mangle -p tcp --dport 2001 -j MARK --set-mark 2
iptables -A OUTPUT -p tcp --dport 2000 -j acc_0
iptables -A OUTPUT -p tcp --dport 2001 -j acc_1
	

Results

I tried it with different rates (going from 1% up to 100% of 100kbps for class 1:10 and the rest to class 1:11). Each time I generated traffic and recorded the speed of class 1:10. The total speed remains constant at 100kbps.

As you can see, this is almost perfect. So, 2 classes can borrow bandwidth from each other.

Setup

I used almost the same setup as in the first test, but one class was ceiled at 50 kbps and the other class was ceiled to 100kbps.

Used script (download)

BW1=$1'kbps'
BW2=`expr 100 - $1`
BW2=$BW2'kbps'

tc qdisc del dev eth0 root handle 1:

tc qdisc add dev eth0 root handle 1: htb default 12
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 $BW1 ceil 50kbps burst 2k
tc class add dev eth0 parent 1:1 classid 1:11 htb rate $BW2 ceil 100kbps burst 2k

tc filter add dev eth0 parent 1: protocol ip prio 3 handle 1 fw classid 1:10
tc filter add dev eth0 parent 1: protocol ip prio 3 handle 2 fw classid 1:11

iptables -F
iptables -X
iptables -N acc_0
iptables -N acc_1
iptables -A OUTPUT -t mangle -p tcp --dport 3000 -j MARK --set-mark 1
iptables -A OUTPUT -t mangle -p tcp --dport 3001 -j MARK --set-mark 2
iptables -A OUTPUT -p tcp --dport 3000 -j acc_0
iptables -A OUTPUT -p tcp --dport 3001 -j acc_1
	

Results

Same, good results, just like expected. The class with ceil = 50 kbps, gets his 50kbps. The remaining bandwidth goes to the other class.

Setup

I used almost the same setup as in the first test, but one class was ceiled at 50 kbps and other class was ceiled to the rate because I didn't provided a ceil parameter.

Used script (download)

BW1=$1'kbps'
BW2=`expr 100 - $1`
BW2=$BW2'kbps'

tc qdisc del dev eth0 root handle 1:

tc qdisc add dev eth0 root handle 1: htb default 12
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 $BW1 ceil 50kbps burst 2k
tc class add dev eth0 parent 1:1 classid 1:11 htb rate $BW2 burst 2k

tc filter add dev eth0 parent 1: protocol ip prio 3 handle 1 fw classid 1:10
tc filter add dev eth0 parent 1: protocol ip prio 3 handle 2 fw classid 1:11

iptables -F
iptables -X
iptables -N acc_0
iptables -N acc_1
iptables -A OUTPUT -t mangle -p tcp --dport 3000 -j MARK --set-mark 1
iptables -A OUTPUT -t mangle -p tcp --dport 3001 -j MARK --set-mark 2
iptables -A OUTPUT -p tcp --dport 3000 -j acc_0
iptables -A OUTPUT -p tcp --dport 3001 -j acc_1

tc qdisc add dev eth0 root handle 1: htb default 12
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100kbps burst 2k
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 172kbps burst 2k
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 98mbit ceil 100mbit burst 2k

tc filter add dev eth2 parent 1: protocol ip u32 match ip src 192.168.3.0/24 flowid 1:11

	

Results

Red line is the bandwidth of 1 class and the pink line is the bandwidth of the other class. The pink class is cutted of due to the 50 kbps ceil option. The other class can't borrow the bandwidth that's freed because it's ceil is equal to the rate because I didn't provided the ceil parameter.