Asterisk is often made to share its Internet connectivity with other
devices, and by default Linux routes traffic First-In/First-Out (FIFO).
When other devices on the network utilize bandwidth this increases
latency and jitter on the voice traffic, affecting call quality.
Implementing QoS by setting TOS flags on the voice packets and prioritizing these packets over regular data on the router significantly reduces this latency and jitter.
These settings are not persistent, i.e. they need to be loaded at each boot. I added the tc commands to a bash script, made it executable, and placed it in /etc/network/if-pre-up.d/.
Implementing QoS by setting TOS flags on the voice packets and prioritizing these packets over regular data on the router significantly reduces this latency and jitter.
- Firstly, Asterisk must be configured to set the correct TOS flags on
SIP and RTP packets. Add the following lines to the [general] section
of sip.conf and reload Asterisk:
# nano /etc/asterisk/sip.conf
[general] tos_sip=cs3 tos_audio=ef
# /etc/init.d/asterisk reload
- Next, on the router we must use the iproute2 tc tool to configure
the Linux kernel to queue packets based on their TOS flags, and to
prioritize the packets we've had Asterisk flag for us. Replace eth1 with
your external network interface if necessary:
# tc qdisc add dev eth1 root handle 1: prio priomap 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 # tc qdisc add dev eth1 parent 1:1 handle 10: sfq limit 3000 # tc qdisc add dev eth1 parent 1:2 handle 20: sfq # tc qdisc add dev eth1 parent 1:3 handle 30: sfq # tc filter add dev eth1 protocol ip parent 1: prio 1 u32 match ip tos 0x60 0xfc flowid 1:1 # tc filter add dev eth1 protocol ip parent 1: prio 1 u32 match ip tos 0xb8 0xfc flowid 1:1
- To view statistics, run the following command:
# tc -s qdisc ls dev eth1
These settings are not persistent, i.e. they need to be loaded at each boot. I added the tc commands to a bash script, made it executable, and placed it in /etc/network/if-pre-up.d/.
Comments