#!/bin/bash

RATE="660kbit"
DEVICE="ppp0"
SFQ_LEN="10"
PERTURB="5"

# Delete the existing qdiscs etc if they exist.
/sbin/tc qdisc del dev ${DEVICE} root

# HTB QDisc at the root. Default all traffic into the prio qdisc.
/sbin/tc qdisc add dev ${DEVICE} root handle 1: htb default 30

# Shape all traffic to just under the upload link rate.
/sbin/tc class add dev ${DEVICE} parent 1: classid 1:1 htb rate ${RATE}

# Create a traffic class.
/sbin/tc class add dev ${DEVICE} parent 1:1 classid 1:10 htb rate ${RATE} ceil ${RATE} prio 0

# Within each traffic class use an SFQ to ensure inter-flow fairness.
/sbin/tc qdisc add dev ${DEVICE} parent 1:10 handle 10 sfq perturb ${PERTURB} limit ${SFQ_LEN}

# Put all traffic into the single class.
/sbin/tc filter add dev ${DEVICE} parent 1:0 protocol ip prio 10 u32 match ip tos 0x00 0x00 flowid 1:10

