#!/bin/sh # init script written by shane at knowplace dot org # this script only creates the qdiscs and classes required for shaping, it # does not create the necessary filters ifext='eth0' rc_done=" done" rc_failed=" failed" return=$rc_done tc='/sbin/tc' tc_reset () { # reset everything to a known state (cleared) $tc qdisc del dev $ifext root 2> /dev/null > /dev/null } tc_status () { echo "[qdisc - $ifext]" $tc -s qdisc show dev $ifext echo "------------------------" echo echo "[class - $ifext]" $tc -s class show dev $ifext } tc_showfilter () { echo "[filter - $ifext]" $tc -s filter show dev $ifext } case "$1" in start) echo -n "starting traffic shaping" tc_reset u320="$tc filter add dev $ifext protocol ip parent 1:0 prio 0 u32" # # dev eth0 - creating qdiscs & classes # $tc qdisc add dev $ifext root handle 1: htb default 60 $tc class add dev $ifext parent 1: classid 1:1 htb rate 356kbit $tc class add dev $ifext parent 1:1 classid 1:10 htb rate 128kbit ceil 356kbit prio 0 $tc class add dev $ifext parent 1:1 classid 1:20 htb rate 64kbit ceil 356kbit prio 1 $tc class add dev $ifext parent 1:1 classid 1:30 htb rate 32kbit ceil 356kbit prio 2 $tc class add dev $ifext parent 1:1 classid 1:40 htb rate 20kbit ceil 356kbit prio 3 $tc class add dev $ifext parent 1:1 classid 1:50 htb rate 48kbit ceil 128kbit prio 4 $tc class add dev $ifext parent 1:1 classid 1:60 htb rate 2kbit ceil 356kbit prio 5
$tc qdisc $tc qdisc $tc qdisc $tc qdisc $tc qdisc $tc qdisc tc_status ;;
add add add add add add
dev dev dev dev dev dev
$ifext $ifext $ifext $ifext $ifext $ifext
parent parent parent parent parent parent
1:10 1:20 1:30 1:40 1:50 1:60
handle handle handle handle handle handle
10: 20: 30: 40: 50: 60:
sfq sfq sfq sfq sfq sfq
stop) echo -n "stopping traffic shaper" tc_reset || return=$rc_failed echo -e "$return" ;; restart|reload) $0 stop $0 start || return=$rc_failed ;; stats|status) tc_status ;; filter) tc_showfilter ;; *) echo "usage: $0 {start|stop|restart|stats|filter}" exit 1 esac test "$return" = "$rc_done" || exit 1
perturb perturb perturb perturb perturb perturb
10 10 10 10 10 10