Commit 6d383395 authored by iilluzion _'s avatar iilluzion _ Committed by Natanael Copa

extra/iproute2-qos: new aport

Scripts to set up quality of service with iproute2
parent dd17281c
# Contributor: Ilya Strelkin <iilluzion@gmail.com>
# Maintainer: Ilya Strelkin <iilluzion@gmail.com>
pkgname=iproute2-qos
pkgver=0.1
pkgrel=0
pkgdesc="Scripts to set up quality of service with iproute2"
url="http://git.alpinelinux.org/cgit/aports"
license="GPL"
depends="iproute2"
makedepends=""
source="qos.initd qos.confd setup-qos"
build() {
install -m755 -D "$srcdir"/setup-qos "$pkgdir"/usr/sbin/setup-qos
install -m755 -D "$srcdir"/qos.initd "$pkgdir"/etc/init.d/qos
install -m644 -D "$srcdir"/qos.confd "$pkgdir"/etc/conf.d/qos
}
md5sums="024b3e5b6f6cca09a729ce265898a0c7 qos.initd
2517182784a415ac10fca4998680df60 qos.confd
785aff5d4284c47038a009797c576e34 setup-qos"
This diff is collapsed.
#!/sbin/runscript
#
###########################################################################################################
# Traffic Control startup script
#
# Copyright (c) 2009 iilluzion
#
# Distributed under GPL-2
###########################################################################################################
PROGRAM=qos
CONFIG=/etc/conf.d/qos
DEBUG=0 #1
opts="compile"
depend()
{
need net
}
checkconfig() {
if [ ! -e $CONFIG ] ; then
eerror "You need to create $CONFIG first."
return 1
fi
}
usage()
{
echo "usage: $PROGRAM [status|compile|start|stop|restart]"
echo " status: View statistics"
echo " compile: Generate traffic control commands"
echo " start: Start traffic control"
echo " stop: Stop traffic control"
echo " restart: Restart traffic control"
}
configure()
{
source $CONFIG $1
}
reset()
{
for DEV in $DEVICES; do
tc qdisc show dev $DEV | grep -v "pfifo_fast" | egrep -q "$QDISCS" && $ECHO tc qdisc del dev $DEV root
tc qdisc show dev $DEV | grep -v "pfifo_fast" | grep -q ingress && $ECHO tc qdisc del dev $DEV ingress
done
}
set_leaf_qdisc()
{
DEV=$1
PARENT_CLASSID=$2
PARENT_CLASSID=${PARENT_CLASSID:-1}
if [ ! "$QDISC_CMD" = "prio" ]; then
$ECHO tc qdisc add dev $DEV parent $PARENT_CLASSID:40 handle 40 $INTERACTIVE_LEAF_QDISC
fi
$ECHO tc qdisc add dev $DEV parent $PARENT_CLASSID:50 handle 50 $PRIVILEGED_LEAF_QDISC
$ECHO tc qdisc add dev $DEV parent $PARENT_CLASSID:60 handle 60 $BESTEFFORT_LEAF_QDISC
if [ $DIRECTION = "DOWN" ]; then
$ECHO tc qdisc add dev $DEV parent $PARENT_CLASSID:70 handle 70 $LAN_LEAF_QDISC
fi
$ECHO
}
set_filters()
{
CLASS_TYPES="INTERACTIVE PRIVILEGED BESTEFFORT"
if [ $DIRECTION = "DOWN" ]; then
CLASS_TYPES=$CLASS_TYPES" LAN"
fi
PRIVILEGED_FILTER_FLOWID=50
BESTEFFORT_FILTER_FLOWID=60
LAN_FILTER_FLOWID=70
for DEV in $DEVICES; do
for CLASS_TYPE in $CLASS_TYPES; do
if [ "$QDISC_CMD" = "prio" -a "$CLASS_TYPE" = "INTERACTIVE" ]; then
PARENT_CLASSID=1
INTERACTIVE_FILTER_FLOWID=1
else
PARENT_CLASSID=$1
PARENT_CLASSID=${PARENT_CLASSID:-1}
INTERACTIVE_FILTER_FLOWID=40
fi
for FILTER_NUM in `seq 1 100`; do
eval FILTER="\$$CLASS_TYPE"_FILTER_$FILTER_NUM
[ -z "$FILTER" ] && break
eval FILTER_FLOWID="\$$CLASS_TYPE"_FILTER_FLOWID
$ECHO tc filter add dev $DEV parent $PARENT_CLASSID:0 $FILTER flowid $PARENT_CLASSID:$FILTER_FLOWID
done
done
$ECHO
done
}
set_htb()
{
for DEV in $DEVICES; do
$ECHO tc qdisc add dev $DEV root handle 1 htb default 60
$ECHO tc class add dev $DEV parent 1: classid 1:2 htb rate $LAN_RATE
$ECHO tc class add dev $DEV parent 1:2 classid 1:30 htb rate $WAN_SUB_RATE
$ECHO tc class add dev $DEV parent 1:30 classid 1:40 htb rate $INTERACTIVE_RATE prio 1
$ECHO tc class add dev $DEV parent 1:30 classid 1:50 htb rate $PRIVILEGED_RATE ceil $WAN_SUB_RATE prio 3
$ECHO tc class add dev $DEV parent 1:30 classid 1:60 htb rate $BESTEFFORT_RATE ceil $WAN_SUB_RATE prio 6
if [ $DIRECTION = "DOWN" ]; then
$ECHO tc class add dev $DEV parent 1:2 classid 1:70 htb rate $OUT_OF_WAN_RATE prio 7
fi
set_leaf_qdisc $DEV
$ECHO
done
set_filters
}
set_hfsc()
{
for DEV in $DEVICES; do
$ECHO tc qdisc add dev $DEV root handle 1 hfsc default 60
$ECHO tc class add dev $DEV parent 1: classid 1:2 hfsc sc rate $LAN_RATE ul rate $LAN_RATE
$ECHO tc class add dev $DEV parent 1:2 classid 1:30 hfsc sc rate $WAN_SUB_RATE ul rate $WAN_SUB_RATE
$ECHO tc class add dev $DEV parent 1:30 classid 1:40 hfsc sc umax $INTERACTIVE_HFSC_UMAX dmax $INTERACTIVE_HFSC_DMAX rate $INTERACTIVE_RATE ul rate $INTERACTIVE_RATE
$ECHO tc class add dev $DEV parent 1:30 classid 1:50 hfsc sc umax $PRIVILEGED_HFSC_UMAX dmax $PRIVILEGED_HFSC_DMAX rate $PRIVILEGED_RATE ul rate $WAN_SUB_RATE
$ECHO tc class add dev $DEV parent 1:30 classid 1:60 hfsc sc rate $BESTEFFORT_RATE ul rate $WAN_SUB_RATE
if [ $DIRECTION = "DOWN" ]; then
$ECHO tc class add dev $DEV parent 1:2 classid 1:70 hfsc sc rate $OUT_OF_WAN_RATE ul rate $OUT_OF_WAN_RATE
fi
set_leaf_qdisc $DEV
$ECHO
done
set_filters
}
set_prio()
{
PARENT_CLASSID=10
for DEV in $DEVICES; do
$ECHO tc qdisc add dev $DEV root handle 1 prio bands 2 priomap 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 # by default unclassified traffic goes to flowid 1:2
$ECHO tc qdisc add dev $DEV parent 1:1 handle 40: tbf rate $INTERACTIVE_RATE burst $INTERACTIVE_PRIO_BURST latency $INTERACTIVE_PRIO_LATENCY
$ECHO tc qdisc add dev $DEV parent 1:2 handle $PARENT_CLASSID: htb default 60
$ECHO tc class add dev $DEV parent $PARENT_CLASSID: classid $PARENT_CLASSID:30 htb rate $WAN_SUB_RATE
$ECHO tc class add dev $DEV parent $PARENT_CLASSID:30 classid $PARENT_CLASSID:50 htb rate $PRIVILEGED_RATE ceil $WAN_SUB_RATE prio 3
$ECHO tc class add dev $DEV parent $PARENT_CLASSID:30 classid $PARENT_CLASSID:60 htb rate $BESTEFFORT_RATE ceil $WAN_SUB_RATE prio 6
if [ $DIRECTION = "DOWN" ]; then
$ECHO tc class add dev $DEV parent 10:1 classid $PARENT_CLASSID:70 htb rate $OUT_OF_WAN_RATE prio 7
fi
set_leaf_qdisc $DEV $PARENT_CLASSID
$ECHO
done
set_filters $PARENT_CLASSID
}
set_police()
{
CLASS_TYPES="INTERACTIVE PRIVILEGED"
INTERACTIVE_POLICE_FLOWID=1
PRIVILEGED_POLICE_FLOWID=2
for DEV in $DEVICES; do
$ECHO tc qdisc add dev $DEV handle ffff: ingress
for CLASS_TYPE in $CLASS_TYPES; do
for FILTER_NUM in `seq 1 100`; do
eval FILTER="\$$CLASS_TYPE"_FILTER_$FILTER_NUM
[ -z "$FILTER" ] && break
eval FILTER_FLOWID="\$$CLASS_TYPE"_POLICE_FLOWID
eval FILTER_RATE="\$$CLASS_TYPE"_RATE
eval FILTER_BURST="\$$CLASS_TYPE"_POLICE_BURST
$ECHO tc filter add dev $DEV parent ffff: $FILTER police rate $FILTER_RATE burst $FILTER_BURST continue flowid $FILTER_FLOWID:
done
done
$ECHO tc filter add dev $DEV parent ffff: protocol ip prio 999 u32 match ip src 0.0.0.0/0 police rate $BESTEFFORT_RATE burst $BESTEFFORT_POLICE_BURST drop flowid :3
$ECHO
done
}
get_stats()
{
for DEV in $WAN_DEVICES $LAN_DEVICES; do
echo $DEV Statistics
echo
echo " Classes:"
echo "--------------------------"
$ECHO tc -s class show dev $DEV
echo
echo " Leaf Queuing Disciplines:"
echo "--------------------------"
$ECHO tc -s qdisc show dev $DEV
echo
echo " EGRESS Filters:"
echo "--------------------------"
$ECHO tc -s filter show dev $DEV
$ECHO tc -s filter show dev $DEV parent 10: # if PRIO qdisc is applied
echo
echo " INGRESS Policing Filters:"
echo "--------------------------"
$ECHO tc -s filter show dev $DEV parent ffff:
echo
echo
done
}
compile()
{
DEBUG=1
start
}
start()
{
checkconfig || return 1
if [ $DEBUG -gt 0 ]; then
ECHO="echo"
else
ebegin "Starting QoS"
fi
for LINK_DIRECTION in UP DOWN; do
configure $LINK_DIRECTION
reset
eval QDISC_CMD="\$$LINK_DIRECTION"LINK_QDISC
if [ ! "$QDISC_CMD" = "none" ]; then
set_$QDISC_CMD
fi
eval INGRESS_CMD="\$$LINK_DIRECTION"LINK_INGRESS
if [ ! "$INGRESS_CMD" = "none" ]; then
set_$INGRESS_CMD
fi
done
if [ $DEBUG -eq 0 ]; then
eend $?
fi
}
stop()
{
checkconfig || return 1
if [ $DEBUG -gt 0 ]; then
ECHO="echo"
else
ebegin "Stopping QoS"
fi
configure ALL
reset
if [ $DEBUG -eq 0 ]; then
eend $?
fi
}
restart()
{
stop
start
}
status()
{
get_stats
}
#!/bin/sh
PREFIX=
. "$PREFIX/lib/libalpine.sh"
conf="$ROOT/etc/conf.d/qos"
cfgval() {
awk -F= "/^$1/ {print \$2}" $conf 2>/dev/null
}
setcfg() {
local key=$1
local value=$2
sed -i "s/^\\(\\#\\)*$key=.*/$key=$value/" "$conf"
if ! grep "^$key=" "$conf" >/dev/null ; then
echo "$key=$value" >> "$conf"
fi
}
apk_add iproute2
if [ -f "$conf" ] ; then
_UPLINK_RATE=$(cfgval UPLINK_RATE)
_DOWNLINK_RATE=$(cfgval DOWNLINK_RATE)
_RATE_SUB_PERCENT=$(cfgval RATE_SUB_PERCENT)
else
echo "Configuration file '$conf' not found"
exit 1
fi
echo "**********************************************************************"
echo "Since ISPs tend to overestimate the speeds they offer, it would probably be best"
echo " if you measure this on a free line to set values very precisely."
echo "**********************************************************************"
echo
echon "Specify the upload speed of your internet connection (mbps, mbit, kbit, kbps, bps): [$_UPLINK_RATE] "
default_read _UPLINK_RATE $_UPLINK_RATE
echo
echon "Specify the download speed of your internet connection (mbps, mbit, kbit, kbps, bps): [$_DOWNLINK_RATE] "
default_read _DOWNLINK_RATE $_DOWNLINK_RATE
echo
echo "**********************************************************************"
echo "In order to prevent traffic queuing at the ISP side or in your modem,"
echo " you should set a slightly lower rate than real one."
echo "This way the bottleneck is the router,"
echo " not the ISP or modem, which allows to control the queue."
echo "**********************************************************************"
echo
echon "Specify amount of percents: [$_RATE_SUB_PERCENT] "
default_read _RATE_SUB_PERCENT $_RATE_SUB_PERCENT
echon "Start QoS? (y/n) [y] "
default_read startqos "y"
case "$startqos" in
[Yy]*) /etc/init.d/qos start;;
esac
echon "Make QoS to be started on boot? (y/n) [y] "
default_read bootstartqos "y"
case "$bootstartqos" in
[Yy]*) rc_add qos;;
esac
setcfg UPLINK_RATE $_UPLINK_RATE
setcfg DOWNLINK_RATE $_DOWNLINK_RATE
setcfg RATE_SUB_PERCENT $_RATE_SUB_PERCENT
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment