Matt G. Watson

Just another geek
Add to Technorati Favorites
May 31st, 2008

How To: Basic QoS on Vyatta with DSCP for VoIP

Synopsis

So you’ve setup a VoIP phone system, but now you want to setup QoS on your router to prioritize your VoIP packets. This is imperative if you intend on running VoIP over any kind of WAN links like I do. Call quality might suffer otherwise - especially when that staff member decides he wants to donwload that 300mb service pack at work instead of using his own connection at home. I’ll show you here how you can solve this problem by using QoS on your Vyatta router.

My network looks something like this:

As you can see, I have 5 independent sites, the left side being my datacenter, and the right being individual sites where are staff work out of. Each site on the right has a Vyatta VC4 router running as its gateway and each of these sites are running Aastra IP phones which connect to our Asterisk PBX server running in the data center.

Anyways… onto the nitty gritty. Click the article title or the read more link below to read on.

Things You Need to Know

  1. The maximum data rates for your WAN interface
  2. The interface name of your WAN interface
  3. The Differentiated Services Code Point (DSCP) / Type of Service (ToS) values that your IP phones are setting. Most will use the values I use below - 46 for RTP / RTCP and 26 for SIP

Creating the qos-policy

The first thing we’ll do is create a qos-policy on Vyatta, to do this first log into your Vyatta CLI. We will create a qos-policy that contains 2 class identifications - one for the Session Initiation Protocol (SIP) signalling, and one for the Real-Time Transport Protocol (RTP) / Real-Time Transport Control Protocol (RTCP). SIP-based telephones essentially use SIP for the call setup, and RTP / RTCP for transport of the actual audio or video. We’d like RTP packets to have top priority on our network, otherwise your audio might get choppy, essentially you want to treat these packets like liquid gold. The SIP packets we feel are important too, but lets face it, if call setup takes an extra few milliseconds because there are alot of RTP streams going on… its not the end of the world.

First create the qos-policy:

[edit]

vyatta@tho1-ncgc1# edit qos-policy traffic-shaper DSCP

note that the “DSCP” in the above line is the name of this policy - feel free to change it.

Next we need to tell this policy how much bandwidth it has to available to it - this is going to be the upstream data rate of you WAN interface, in my case its 10mbit:

[edit qos-policy traffic-shaper DSCP]
vyatta@tho1-ncgc1# set bandwidth 10mbit

I’d also recomend setting the description field for your own purposes:

[edit qos-policy traffic-shaper DSCP]
vyatta@tho1-ncgc1# set description “This policy enforces DSCP-based queuing”

Then we’ll create our first class, this one will be used for the RTP / RTCP packets:

[edit qos-policy traffic-shaper DSCP]
vyatta@tho1-ncgc1# edit class 10

Note: the 10 again is an identifier, feel free to use any number you wish.

Next we set the minimum amount of bandwidth we want available to this class. I like doing this using percentages, then if my WAN interface gets upgraded, I only need to change it in the main qos-policy section:

[edit qos-policy traffic-shaper DSCP class 10]
vyatta@tho1-ncgc1# set bandwidth 90%
[edit qos-policy traffic-shaper DSCP class 10]
vyatta@tho1-ncgc1# set description “Matches DSCP 46 - used for RTP & RTCP for VoIP - set by IP Phone & Asterisk”

Now the class itself needs to be setup on which packets actually enter the class, we do this using the “match” configuration

[edit qos-policy traffic-shaper DSCP class 10]
vyatta@tho1-ncgc1# set match DSCP-46 ip dscp 46

Thats it for class 10! You’ll then need to repeat this creating a new class for DSCP 26 (see my full qos-policy below).

We are not quite done yet though… now that we have classes created that match DSCP 26 and 46, what about everything else? All those people surfing the web, watching YouTube, or checking their facebook… Well, one last thing we need to do in our qos-policy is create the default restrictions, we do this by creating a node under the qos-policy (at the same level as the classes)

[edit qos-policy traffic-shaper DSCP]
vyatta@tho1-ncgc1# set default bandwidth 5%

Important: Whenever we have set bandwidth values above, we have only set minimum bandwidths that are guarenteed for that class. In my case I have guarenteed 90% of my bandwidth to IP phone audio streams, 5% to call-setup packets, and the last 5% to everything else. Its important to remember that if your audio streams are not actually using their 90%, that bandwidth will be available for the other purposes. However, Vyatta can limit these by setting ceiling values - see the Vyatta command reference on how to do this, or leave me a comment if you wish.

Here is what my full qos-policy looks like:

qos-policy {
  traffic-shaper DSCP {
    bandwidth 10mbit
      class 10 {
        bandwidth 90%
        description "Matches DSCP 46 - used for RTP & RTCP for VoIP"
        match DSCP-46 {
          ip {
            dscp 46
          }
        }
      }
      class 30 {
        bandwidth 5%
        description "Matches DSCP 26 - used for SIP for VoIP"
        match DSCP-26 {
        ip {
          dscp 26
        }
      }
    }
    default {
      bandwidth 5%
    }
    description "This policy enforces DSCP queuing"
  }
}

Now that we have our policy created, the last thing we need to do is apply the policy to our WAN interface, in my case eth1 is my WAN interface, so all we need to do is:

set interfaces ethernet eth1 qos-policy out DSCP

Thats it, were done! Your Vyatta router will now prioritize all packets going out your WAN interface to give priority to all your VoIP traffic.

If you have any questions or comments, feel free to leave a comment here and I’ll get back to you.

8 Responses to “How To: Basic QoS on Vyatta with DSCP for VoIP”

  1. [...] parts, of migrating his employer to an Asterisk based PBX. He also has some nice description of establishing QoS for VOIP using the Vyatta open source router. I’m really curious about Vyatta, but I do think its perhaps more than a little beyond my [...]

  2. John Babio Says:
    June 27th, 2008 at 7:39 am

    Awesome!! I have been meaning to mess with the vyatta QoS Stuff.

  3. This is an excellent article Matt. Thanks a lot. I am using this as a guide for policies for my VoIP softphone connecting through an SSL VPN client back to the Cisco CM.

    Based on the diagram these sites are VPN’d into the datacenter over the internet? or are they leased telco connections?

  4. Hi Joel,

    I’m glad you are finding the guide useful!

    In my setup here the connections to the datacenter are infact leased lines. However it should work in your situation of using VPN’s as well.. though it may need some tweaking depending on your setup.

  5. We have been trying to diagnose our internal VOIP extension problem: echoing, etc. Our external lines are analog, and internally we are going through a gigabit switch to the router, and back to our phone system (talkswitch) so I would not believe there would be any saturation.

    I’m not sure what the problem is yet, but I’m wondering if a QOS policy is something that we should be looking to establish on our vyatta router. Thoughts?

  6. Hi Kevin,

    I would suspect your echo problem is not being caused by LAN congestion problem - especially if you are running on gigabit.

    I also don;t believe an improper QoS problem would cause echo’ing either… I would suspect that poor QoS policies may cause distortion/static or voices “cutting in and out”.

    I believe your problem is probably the TalkSwitch system. I’m not familiar with the TalkSwitch products.

    Does your problem only occur on calls involving your analog lines? More than likely what you are hearing is what is called “Hybrid Echo”, this is echo generated by a device in telco switches called a “Hybrid” basically what the Hybrid does is convert your single-pair copper analog connection into a 2-pair connection. The Hybrid does this to seperate the send & recieve signals. The connection between the Telco switch and your location is always delivered on a single pair - the send and receive is mixed together. The telco seperates the send and recieve at their end so that these signals can be easily digitized, compressed, and trunked over a much larger pipe. The problem is, if the echo is not properly tuned for your specific line impedence, it creates echo due to electrical leakage.

    When your phone line is connected to a regular analog handset, this echo is not normally a problem because the echo comes back so quickly to the person speaking that it just sounds like “sidetone” to them (they can hear themselves talking in the earpiece). The problem here is… as soon as you connect that analog line to a VoIP system, the time your VoIP system takes to digitize the analog signal, send it over your IP network to your phone handset, the phone then re-converts it back to analog and out the earpiece. The amount of time that takes makes you actually hear the echo as an echo of yourself, instead of your brain interpreting it as sidetone.

    Like I said, I can’t speak for the TalkSwitch products, I am using an Asterisk based system.

    Asterisk, and the underlying Analog interface drivers (ZapTel / DAHDI) provide ways for you to adjust the gains on your lines which can drastically reduce the echo caused by the Hybrid. Essentially you are tuning for the line impedance on your end of the connection instead of relying on the Telco to do it (which most don’t because its not a problem to 99% of their customers using pure analog systems).

    Some ZapTel / DAHDI analog interface cards also come with hardware-based echo cancellors built directly onto the card to help reduce echo. In place of a hardware echo cancellor, ZapTel / DAHDI also offer a half dozen or so different software-based echo cancellation algorithms.

    I would imagine that TalkSwitch has some type of similiar method to tuning the lines. Its a little bit of a task to go through and tune all of your lines - especially if you have alot of analog lines since they all need to be done individually.

    I know this doesn;t apply to TalkSwitch, but you may find reading this post about how I did the line tuning with Asterisk available here: http://www.mattgwatson.ca/2008/05/howto-tune-zaptel-dahdi-fxo-interfaces-on-asterisk-pbx/

    Good Luck!

  7. How to configure the bgp protocol in 3 vyatta router

  8. Maillikarjun,

    Sorry I have yet to attempt setting up BGP on Vyatta, you might want to checkout the forums on http://www.vyatta.org however, you may find some advice there.

Leave a Reply