set_qdisc.sh 566 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#!/bin/bash
IFACE=eth2
RATE="$1"
QDISC_NAME="$2"
QDISC_PARAMS="$3"

die()
{
	echo "$@" >&2
	exit 1
}

[ -z "$QDISC_NAME" ] && die "Missing qdisc name."

regex='limit ([0-9]+)'

if [[ "$QDISC_NAME" == "pfifo_fast" && "$QDISC_PARAMS" =~ $regex ]]; then
    QDISC_PARAMS=""
    QLEN=${BASH_REMATCH[1]}
else
    QLEN=100
fi

ip link set dev $IFACE qlen $QLEN
tc qdisc del dev $IFACE root 2>/dev/null
tc qdisc add dev $IFACE handle 1: root tbf rate $RATE burst 1514 latency 100ms || exit 1
tc qdisc add dev $IFACE handle 2: parent 1:1 $QDISC_NAME $QDISC_PARAMS || exit 1