VoIPowering Your Office with Asterisk: Giving VoIP Traffic the Green Light, Part 3

To get maximum VoIP performance our of your network, you'll need to roll up your sleeves and grapple with some serious Linux code and concepts. We'll help.

By Carla Schroder | Posted May 22, 2006
Print ArticleEmail Article
  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
Last week we left off with using Wondershaper to improve network performance by, somewhat paradoxically, throttling our line speeds to less than their maximum. Today we'll learn how to prioritize specific types of network traffic.

But first, I must make a small but important correction. Unless you are running Debian, before you can run Wondershaper from the command line you must make one edit in the wshaper script. Comment out or delete these lines:

echo Please read the documentation in 'README' first :-)

Now you can run the wshaper command without it complaining. Debian users may run the wondershaper command without making any edits first.

Wondershaper status: Clearing the queue
Wondershaper displays its current status with this command:

# wshaper status

Use this command to turn Wondershaper off:

# wshaper clear eth1

It might take a bit of experimenting to find the optimum settings. Typically, around 90 percent of your maximum line speed works well. Start low and work your way up. If your Internet line is used primarily for VoIP, and not a lot of other traffic, this could be all you need to do to ensure decent VoIP performance.

Starting wondershaper automatically
Your last step is to make sure Wondershaper starts at boot, or when your network interface comes up. Starting it at boot is the easiest. First edit the wshaper script to include your desired settings:


Then place the script in /etc/init.d, and use your favorite runlevel utility, such as chkconfig (Red Hat) or update-rc.d (Debian) to add it to your desired runlevels, like this:

# chkconfig --level 2345 wshaper on
# chkconfig --level 016 wshaper off

# update-rc.d wondershaper start 30 2 3 4 5 . stop 0 1 6 .

Starting Wondershaper when your network interface comes up is done differently on every Linux distribution, so please refer to your documentation to learn how to do this. Starting it at boot is perfectly acceptable and simple to manage. However, some admins believe that anything related to network interfaces, like iptables, traffic shaping, routing, IPSec, and so forth, should start and stop with the interface. It's a question of taste, so do what suits you.

Advanced controls
I had hopes of condensing the finer points of traffic shaping into a brilliant, digestible, yet comprehensive how-to, but it's proved more difficult than I anticipated. Perhaps the subject simply doesn't lend itself to this sort of treatment, because it is complex and abstract. Instead we'll take a look at an excellent script written by Carceri, QoS with Linux using PRIO and HTB.

This is a complete drop-in, modified Wondershaper script. There are four lines that you need to modify:


We already know what to do with the first two. RATE is the maximum speed for an entire class and all of its children. CEIL is the maximum rate at which a child class can send, if the parent has spare bandwidth. CEIL can not be larger than RATE. (You can find all these definitions in man tc-htb.)

A class is a set of instructions that define actions, like this example from the script that defines the parent class:

$TC qdisc add dev ${DEV} root handle 1: tbf rate ${RATE}kbit burst 4k latency 30ms

There is an excellent diagram at the bottom of the page that shows the different classes and relationships clearly. So you can see that there are two different types of classes: PRIO and HTB.

PRIO is short for priority. The lowest priority fields tell which packets get to go first. Classes don't do anything by themselves; they are called by filters, as this example shows:

# VoIP traffic always get first in line (my ATA tags them with TOS 0x68 or 0xb8)
$TC filter add dev ${DEV} parent 10:0 prio 3 protocol ip u32
match ip tos 0x68 0xff
flowid 10:1

HTB is "Hierarchy Token Bucket." (I told you this was abstract!) To quote the man page: "HTB shapes traffic based on the Token Bucket Filter algorithm which does not depend on interface characteristics and so does not need to know the underlying bandwidth of the outgoing interface." This is one of the HTB classes in the script:

$TC class add dev ${DEV} parent 200:1 classid 200:30 htb
rate $[2*$CEIL/100]kbit ceil ${CEIL}kbit burst 2k prio 3

What does this all mean to you? It means you can go a long way just by fiddling with the RATE and CEIL variables. However, I do encourage you to study the script, man tc-htb, and especially Chapter 9 of the Linux Advanced Routing & Traffic Control HOWTO, which is well-written and clearly explains all the different terms and concepts.

Traffic-shaping is probably the most difficult aspect of networking to learn. Next week we'll get back to doing fun things with Asterisk, which is a whole lot easier.

VoIPowering Your Office With Asterisk: Giving VoIP Traffic the Green Light, Part 2
Linux Advanced Routing & Traffic Control HOWTO
TCP/IP Network Administration, Third Edition
Linux Cookbook

Comment and Contribute
(Maximum characters: 1200). You have
characters left.
Get the Latest Scoop with Enterprise Networking Planet Newsletter