Wednesday, February 11, 2009

VoIP traffic shaping with FreeBSD IPFW + Dummynet

We have an Airport Extreme, and while it is a good router, it isn't perfect. Among the deficiencies in it, it lacks support for traffic shaping (sometimes called QoS).

Using the FreeBSD machine as the firewall instead of the AirPort is one option, but the problem with that is that FreeBSD lacks support for uPNP or NAT-PMP, which would seriously complicate things like Back-to-my-Mac.

The best compromise is to keep the AirPort Extreme in the routing role for the inside machines, and use the FreeBSD machine as a traffic shaping bridge.

It's fairly simple:

ipfw pipe 1 config bw 640kbps
ipfw queue 1 pipe 1 weight 100
ipfw queue 2 pipe 1 weight 1

queue 1 is for Vonage traffic, and queue 2 is for everything else.

ipfw queue 1 ip from voip to any xmit re0
ipfw queue 2 ip from not voip to any xmit re0

in this case, re0 is the "outside" LAN interface (connected to DSL).

The issue is in figuring out what the number for the bandwidth is. It's not actually the same as the DSL connection's uplink line rate. The problem is that there are several layers of encapsulation. The best way to figure out what to put in there is to start with a number far higher than the uplink bandwidth and run a speed test. Reduce the number until the speed test shows a reduction in the uplink bandwidth. In our case, the line is a 6M/768K one and the right number to use is 640kbps. The speed tests show an actual data throughput of closer to 600 kbps. The Ethernet and ATM framing for the packets takes up the rest of the bandwidth.

No comments: