#!/bin/sh

################################################################################
# Modification History;
#
# Date------ Author----- Description--------------------------------------------
# 2007/11/26 M. Pepin    Initial creation
#
################################################################################

TC=/sbin/tc

# We always expect 6 parameters (0..5) where the first $0 parameter is the script path name
if [ $# -ne 5 ];
then
        echo "Usage: "
        echo ""
        echo "  $0 <DEV> <Q1_LEN> <Q2_LEN> <Q3_LEN> <Q4_LEN> "
        echo "     where:"
        echo "          <DEV>       -- net device name to be configured with PRIO queuing discipline"
        echo "          <Q1..4_LEN> -- the length of the queue"
        echo ""
        echo "Example:"
        echo ""
        echo "  $0 eth1 600 100 100 100"
        echo ""
        echo "To print network device statistics use the 'tc' utility instead:"
        echo ""
        echo "  $TC -s qdisc show dev eth1"
        echo "  $TC -s class show dev eth1"

        exit 1
fi

EXIT_CODE=0

DEV=$1
Q1_LEN=$2
Q2_LEN=$3
Q3_LEN=$4
Q4_LEN=$5

# Free previous QoS Settings
$TC qdisc del dev $DEV root handle 1: prio  2> /dev/null
$TC qdisc del dev $DEV root handle 1: htb default 4 2> /dev/null 

# Attach prio to <network device>
$TC qdisc add dev $DEV root handle 1: prio bands 4 priomap  3 0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 ; EXIT_CODE=$(($EXIT_CODE+$?))

# Attach queuing disciplines to the leaf classes
$TC qdisc add dev $DEV parent 1:1 handle 10: pfifo limit $Q1_LEN; EXIT_CODE=$(($EXIT_CODE+$?))
$TC qdisc add dev $DEV parent 1:2 handle 20: pfifo limit $Q2_LEN; EXIT_CODE=$(($EXIT_CODE+$?))
$TC qdisc add dev $DEV parent 1:3 handle 30: pfifo limit $Q3_LEN; EXIT_CODE=$(($EXIT_CODE+$?))
$TC qdisc add dev $DEV parent 1:4 handle 40: pfifo limit $Q4_LEN; EXIT_CODE=$(($EXIT_CODE+$?))

# List the stats, see if queues were programmed correctly
# $TC -s -d qdisc ls dev $DEV

exit $EXIT_CODE


