Next Previous Contents

4. Configure

This configuration example is for an adsl link with 1024 kbits downstream and 512 Kbits upstream. Perhaps you will need fine tuning depending on your connection speed or bandwidth needs.

We will match the packets by their size and mark them acordingly. A packet of size 0 -> 500 will be considered interactive traffic and marked with fwmark value "3"

iptables -t mangle -A OUTPUT -m length --length 0:500 -j MARK --set-mark 3

Next packets of size 500 -> 1500 will be marked as data traffic with value "4".

iptables -t mangle -A OUTPUT -m length --length 500:1500 -j MARK --set-mark 4

If you want to also apply these settings to masqueraded machines, you should use:

iptables -t mangle -A PREROUTING -m length --length 0:500 -j MARK --set-mark 3

iptables -t mangle -A PREROUTING -m length --length 500:1500 -j MARK --set-mark 4

We will create a root cbq qdisc for our device ppp0:

tc qdisc add dev ppp0 root handle 10: cbq bandwidth 10Mbit avpkt 1000 mpu 64

This creates a root queuing discipline with handle 10: for the device ppp0 of type cbq, with maximum bandwidth of 10Mbits (pppoe), average packet size will be of 1000 bytes and minimum packet size of 64 (ethernet).

The 2 classes:

As a general rule for a workstation connected to internet you would calculate the rate values of the two classes like this:

Download bandwidth: 1024 kbits
Upload bandwidth: 512 kbits

Interactive class rate = Download bandwidth / 20
Data class rate = Upload bandwidth - Interactive class rate 

So 51 and 461.

These values are working well here, perhaps you'll need to fine tune to suit your needs, just make sure to have enough bandwidth in the interactive class to acknowledge all incoming tcp data.

tc class add dev ppp0 parent 10:0 classid 10:1 cbq bandwidth 10Mbit \
    rate 51Kbit allot 1514 prio 1 maxburst 10 avpkt 100 isolated
tc class add dev ppp0 parent 10:0 classid 10:2 cbq bandwidth 10Mbit \
    rate 461Kbit allot 1514 prio 8 maxburst 2 avpkt 1500 bounded

At least we need to tell the kernel which class we want to send packets to:

tc filter add dev ppp0 parent 10:0 protocol ip handle 3 fw flowid 10:1
tc filter add dev ppp0 parent 10:0 protocol ip handle 4 fw flowid 10:2

Well that's done.

Next Previous Contents