QoS Linux with HFSC
HFSC
HFSC is a method to prioritize traffic with iptables and tc. Make sure your kernel supports HFSC.I successfully use this script, which brought me dramatically improved latency while up- and downloading simultaneously via a 1024/128 adsl line (in Germany). I tried the same with HTB before, and it didn't work so well. I use a 2.6.10 kernel image on Debian Linux.
- !/bin/sh
- SipShaper v0.01
- VoIP Traffic Shaper for 1024/128Kbit/s ADSL Line
- Written by Udo Schacht-Wiegand (2005-04-03)
- based on MYSHAPER from Dan Singletary (8/7/02)
- http://www.nslu2-linux.org/wiki/HowTo/EnableTrafficShaping
- and on phone-man's script
- http://www.ip-phone-forum.de/forum/viewtopic.php?p=100371#100371
- and on the (German) Linux Magazine 02/05 article p.28
- Please mail comments and improvements to sipshaper at udo dot comlink dot org
- Set your outgoing interface and upload rate (in kbit/s) here
RATEUP=128
RTPS=$(cat /etc/asterisk/rtp.conf|awk -F= '/rtpstart/ {print $2}')
RTPE=$(cat /etc/asterisk/rtp.conf|awk -F= '/rtpend/ {print $2}')
- Which ports should be prioritized (yes, I know that ssh is not VoIP ;-)
- Which servers should be prioritized (may be empty "")
- end of configuration options
- show status and exit
if [ "$1" = "status" ]
then
echo "[qdisc]"
tc -s qdisc show dev $DEV
echo ""
echo "[class]"
tc -s class show dev $DEV
echo ""
echo "[filter]"
tc -s filter show dev $DEV
echo ""
echo "[iptables]"
iptables -t mangle -L SIPSHAPER -v -x 2> /dev/null
exit
fi
- default: start it #
- Reset everything to a known state (cleared)
- Flush and delete tables
iptables -t mangle --flush SIPSHAPER 2> /dev/null > /dev/null
iptables -t mangle --delete-chain SIPSHAPER 2> /dev/null > /dev/null
- stop it and exit
if [ "$1" = "stop" ]
then
echo "Shaping removed on $DEV."
exit
fi
- set up shaping
- add HFSC root qdisc
- add main rate limit class
- keep it simple: two classes only
tc class add dev $DEV parent 1:1 classid 1:11 hfsc sc umax 1500b dmax 30ms rate 80kbit ul rate ${RATEUP}kbit
- add SIPSHAPER chain to the mangle table in iptables
iptables -t mangle --insert POSTROUTING -o $DEV -j SIPSHAPER
- Filter for voip packets
- VoIP ports as defined above
do
iptables -t mangle -A SIPSHAPER -p udp --sport $port -j MARK --set-mark 1
iptables -t mangle -A SIPSHAPER -p udp --dport $port -j MARK --set-mark 1
done
- VoIP IPs as defined above
do
iptables -t mangle -A SIPSHAPER -p udp --src $ip -j MARK --set-mark 1
iptables -t mangle -A SIPSHAPER -p udp --dst $ip -j MARK --set-mark 1
done
echo SipShaper started on $DEV with ${RATEUP}kbit/s upload rate.
echo -n "QoS activated for ports: "
for port in $VOIPPORTS
do
echo -n " $port"
done
echo "."
echo -n "QoS activated for ip# : "
for ip in $VOIPIPS
do
echo -n " $ip"
done
echo "."
- end
Comments are welcome.
See also
Featured -
Search:

Page Changes















