We were experiencing call quality issues once we moved into a new office and hooked up with a new ISP. The new ISP offered faster Internet access than the previous location, but our same phone equipment gave us garbled phone calls. Turns out that the way we used the Internet at the new office changed -- everyone was now downloading everything at max speed all the time, hogging all the bandwidth, letting the VoIP traffic over UDP to fend for itself, and often resulting in poor call quality.

A little about our setup: I set up a Linux machine with two Ethernet cards to act as the router. The Linux machine also acts as a DHCP server and an Asterisk server. All traffic coming in and out of our building goes through this server.

We recently needed to give our network more bandwidth for UDP for voice traffic, and this is how I did it. I created three classes of network, and allow UDP the band of traffic (the class) with the highest limit.

Note that eth1 in this case is my internal network. We have a 100mbit pipe, so my numbers below assume that. I put these lines in /etc/rc.local so that it will run every time I reboot.

# Clear queueing discipline / QoS settings
tc qdisc del dev eth1 root

# Tell the system to use HTB (heirarchical token bucket) queueing discipline, which I read is one of the best for what I want to accomplish
tc qdisc add dev eth1 root handle 1: htb default 1

# Create three classes. Class 10 does 50-80mbps. Class 20 does 30-50 mbps. Class 30 does 25-40 mbps.
tc class add dev eth1 parent 1: classid 1:1 htb rate 65mbit
tc class add dev eth1 parent 1: classid 1:2 htb rate 100mbit

# Set the queueing discipline to a fair queuing for these classes. Fair queing makes sure packets are getting fair attention. Perturb means something I forget, but it's important :)
tc qdisc add dev eth1 parent 1:1 handle 1: sfq perturb 10
tc qdisc add dev eth1 parent 1:2 handle 2: sfq perturb 10

# UDP traffic gets the higher rate. "ip protocol 17" is UDP. 
tc filter add dev eth1 parent 1: protocol ip prio 1 u32 match ip protocol 17 0xff flowid 1:2

There's a lot that can be done with traffic shaping. I experimented with setting marks on packets through iptables but found the above solution to be simple enough to do the job.

I could give execs in the company the middle band of traffic to give them more bandwidth. Since I applied the above traffic shaping rules, we've had no complaints in the company about poor phone quality.