Asterisk: Give VoIP Traffic the Green Light (Part 2)

With Linux and Wondershaper you can tune your network's VoIP traffic and improve the quality of your calls.

Last week we covered TCP/IP
networking basics. The more you know about the care and feeding of TCP/IP
the better, so don't stop with my very basic overview.

Today we're going to configure our Internet router/gateway to give priority
to Asterisk traffic. This how-to is for admins who have nice sturdy Linux-based
Internet gateways. If you're using a commercial router with its own operating
system, like Cisco, you'll have to learn the traffic-shaping incantations peculiar
to it.

Indeed, while Cisco, Linksys, Netgear, Zyxel, et al, make excellent routers
and Internet gateways, you can easily duplicate or exceed their functionality
with Linux on ordinary x86 hardware for a fraction of the cost, for all but
the most high-demand routing. In other words, if you're not AT&T or an ISP,
Linux will do everything you need and more.

If you're wondering about terminology like "router" and "gateway," let's define
them so we're all on the same page. A router is any device that enables traffic
to pass between networks, like between the Internet and your LAN, or different
subnets on your LAN. A gateway does routing, and also includes other border
services like firewalling, intrusion detection, HTTP caching/filtering, and
whatever else the network administrator thinks is needed to guard the borders.

Basic bandwidth shaping with Wondershaper
Traffic-shaping is a bit of a black art. The traditional tools, as described
in the Linux
Advanced Routing & Traffic Control HOWTO, require a fair bit of study. So
we'll start out with Wondershaper, which is a simple utility designed to maintain
low latency on busy network links. Wondershaper should be installed on your Internet gateway.

The Debian way
The Debian (and Debian derivatives like Ubuntu and MEPIS) version of Wondershaper is slightly different. Please follow the excellent Debian howto installed on your system at /usr/share/doc/wondershaper/README.Debian.

All other Linuxes
Wondershaper is run the same way on all other Linux distributions. Just download and unpack the tarball, and it's ready to go to work:

There are two executable scripts, wshaper and wshaper.htb. wshaper is the one we'll use. Copy it to a directory that is in your path, like /usr/local/bin, so you can run it like any other command:

# cp wondershaper-1.1a/wshaper /usr/local/bin

Just for fun go ahead and run it:

# wshaper
Please read the documentation in README first :-)

This is good advice, but you can do that later. Let's have some fun
first and establish a baseline on our Internet link. Do this by finding the
next hop after your router with the route command, as this example (using
fake IPs) shows:

This illustrates a typical multi-homed Linux gateway/router. The next hop and default gateway at the ISP is 122.166.166.1. U means the route is up, and G means use this gateway. Now ping the gateway, ideally when your link is idle, to get an idea of the native latency:

That makes a big difference, and on an overloaded network you'll start to see packet loss as well, which is bad for VoIP performance. Keep the download going, change to root, fire up Wondershaper, and re-run ping:

That's quite an improvement. This works by a bit of magic that throttles your line speeds to a little bit under the maximum, with the result that no queuing is necessary. Queues are the enemies of latency. Traffic literally piles up until it is either delivered or discarded. Queues are everywherein your broadband modem, at your ISP, and everywhere upstream of you. The Wondershaper README goes into more detail on queueing.

You need to know your real bandwidth. This requires some guesstimating and tinkering. For example, my DSL line is rated at 768/256, so 600/200 seemed like a good starting point. There are a number of Web-based speed testers, like the one at DSLReports.com, which is also a great site for broadband and networking information.

Come back next week to learn how to monitor Wondershaper, start it automatically, and how to give priority specifically to Asterisk traffic.