www.linuxexpert.ro

Tutorials

  • Home
  • BGP Tutorials
    • Remove private AS
  • cPanel Tutorials
    • Install ImageMagick on cPanel
    • Install Softaculous
  • Linux Tutorials
    • Auto-reboot Linux after kernel panic
    • Building a firewall with Iptables
    • Change array RAID 1 disk order
    • Configure ntfs-3g on Linux Slackware
    • DHCP Option Codes
    • DansGuardian with Squid and ClamAV
    • Fetchmail for Gmail accounts
    • Install Zend & APC PHP Optimizers
    • Install Atheros AR242x PCI Express Adapter
    • Install awstats with DirectAdmin
    • Install DBD::mysql via CPAN shell
    • Install DjbDNS on Ubuntu
    • Installing fail2ban on Centos 5
    • Install GoDaddy SSL Certificate
    • Install i386 packages under x86_64
    • Install Linux via USB flashdrive
    • Install ModSecurity2 on Apache2.0.x
    • Install Nginx on CentOS
    • Install webalizer with ispconfig
    • Install intel A/B/G/N wireless on linux
    • Kernel Upgrade
    • Mobile phone access via bluetooth
    • Optimize MySQL
    • Optimize Qmail
    • Optimize server load
    • Optimize and Tune Apache for performance
    • Optimize and Tune Nginx for performance
    • Perfect Mailserver on Debian
    • Pidgin "Now Playing" Status Message
    • PHP hardening
    • PHP hardening with Suhosin
    • PHP5 Support allong with PHP4
    • Previewing your site before making DNS changes
    • Proxy Auto Configuration
    • PXE boot install rescue
    • Setup awstats on CentOS
    • Setup EC2 Amazon L2TP IPSec VPN
    • Setup email piping with Qmail
    • Setup Exim with DKIM
    • Setup Exim smart relay with cPanel
    • Setup OpenVPN
    • Setup postfix on nonstandard port
    • Setup SS5 Socks Proxy
    • Setup vsftp with no shell access
    • Sendmail smart relay with gmail auth
    • Squid proxy NCSA authentication
    • Tcpdump filters
    • Upgrade PHP to 5.3 in Plesk 10
    • Useful regular expressions
    • X with [SiS] 771/671 VGA controller
  • Joomla Tutorials
    • Hardening Joomla
    • Module Positions
    • Remove Joomla description meta tag
  • Looking Glasses
  • Optimize Firefox
  • Security
    • Crack WiFi WEP passwords
    • Defend against UDP isc.org DNS query DDOS
    • Detect DDoS attack
    • Remove malware from web sites
    • Sniff SSL passwords with ettercap
    • Snort2BGP
    • Track Hackers
    • What Is My IP
  • Troubleshooting
    • Grub error no such disk
    • named dumping master file: tmp-XXXXXXXXXX: open: permission denied
    • Nginx 413 Request Entity Too Large
    • SSH conection closed by remote host
    • Troubleshooting sis190.c
  • Unix Tutorials
    • FreeBSD reset root password
    • Installing snort on OpenBSD
    • Unix Toolbox
  • Virtualization Tutorials
    • Convert VirtualBox image to VMWare
    • VMware SNMP Enable
  • VoIP Tutorials
    • Install Elastix
    • Qos for Asterisk

Who's Online

We have 23 guests and no members online

Most Read

  • Setup SS5 Socks Proxy
  • Install webalizer with ispconfig
  • Sniff SSL passwords with ettercap
  • __404__
  • Optimize and Tune Apache for performance

Products and Services

  • Home
  • Linux Products and Services
  • Buy VPN Account
  • Privacy Policy for Linuxexpert
  • Remove malware

Qos for Asterisk

  • Print
  • Email
Details
Parent Category: Tutorials
Published: 01 August 2009
Hits: 10746

In this tutorial i'll show you how setup Linux QoS in order to improve quality Asterisk VoIP calls.

First let's see how the default Linux prioritization looks:

root@Hercule:~# tc qdisc show dev eth0
qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
root@Hercule:~#

As you can see the current policy is FIFO and it contains 3 bands named from 1 to 3.

Let's look at the priomap argument. It contains 16 numbers from 0 to 2.

The link between  band and priomap numbers is like this:

band 1 takes the priomap 0

band 2 takes the priomap 1

band 3 takes the priomap 2

Those 16 numbers from 0 to 2 meaning bits.

Below you have a Table with Linux TOS values :

TOS Bits Means Linux Priority Band
0x0 0 Normal 0 Best Effort 1
0x2 1 Minimize Monetary Cost 1 Filler 2
0x4 2 Maximize Reliability 0 Best Effort 2
0x6 3 mmc+mr 0 Best Effort 2
0x8 4 Maximize Throughput 2 Bulk 1
0xa 5 mmc+mt 2 Bulk 2
0xc 6 mr+mt 2 Bulk 0
0xe 7 mmc+mr+mt 2 Bulk 0
0x10 8 Minimize Delay 6 Interactive 1
0x12 9 mmc+md 6 Interactive 1
0x14 10 mr+md 6 Interactive 1
0x16 11 mmc+mr+md 6 Interactive 1
0x18 12 mt+md 4 Int. Bulk 1
0x1a 13 mmc+mt+md 4 Int. Bulk 1
0x1c 14 mr+mt+md 4 Int. Bulk 1
0x1e 15 mmc+mr+mt+md 4 Int. Bulk 1

 

Here you have the linux TOS:

# cat /etc/iproute2/rt_dsfield
0x00 default
0x10 lowdelay
0x08 throughput
0x04 reliability
# This value overlap with ECT, do not use it!
0x02 mincost
# These values seems do not want to die, Cisco likes them by a strange reason.
0x20 priority
0x40 immediate
0x60 flash
0x80 flash-override
0xa0 critical
0xc0 internet
0xe0 network
# Newer RFC2597 values
0x28 AF11
0x30 AF12
0x38 AF13
0x48 AF21
0x50 AF22
0x58 AF23
0x68 AF31
0x70 AF32
0x78 AF33
0x88 AF41
0x90 AF42
0x98 AF43

The "prio" qdisc now will dequeue packets from class 0 with the
highest priority. The higher the class numbers the lower the de-
queue priority.

If you would like to send packets with a TOS value of 0x0, 0x2, 0x4,
0x6, 0x8 to class 1 and packets with all other TOS values to class 0
you could change your priomap such (you have to state it when setting
up the "prio" qdisc if you want to have something different from the
default priomap):

1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0

Here is an example script that i use with Asterisk:

#!/bin/bash

# Flush any existing queues
for dev in $devices ; do
tc qdisc del dev $dev root 2> /dev/null > /dev/null

# Band 3 has priomap 2, band 2 has priomap 1 and band 1 has priomap 0
#tc qdisc add dev $dev root handle 1: prio priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
tc qdisc add dev $dev root handle 1: prio priomap 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 0
# Put all in band 3:
#tc qdisc add dev $dev root handle 1: prio priomap 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
tc qdisc add dev $dev parent 1:1 handle 10: sfq limit 3000
tc qdisc add dev $dev parent 1:2 handle 20: sfq
tc qdisc add dev $dev parent 1:3 handle 30: sfq

#Adding traffic in band 1
#Currently VoIP TOS defined in /etc/asterisk/sip.conf:
#tos_sip=cs3                    ; Sets TOS for SIP packets. cs3=0x60
#tos_audio=ef                   ; Sets TOS for RTP audio packets. ef=0xb8
#;tos_video=af41                 ; Sets TOS for RTP video packets.
#VoIP audio packets with defined TOS mark:
tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip tos 0xb8 0xff flowid 1:1
#tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip dport 4569 0xffff flowid 1:1
#tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip sport 4569 0xffff flowid 1:1
tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip dport 16384 0xffff flowid 1:1
tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip sport 16384 0xffff flowid 1:1

#Adding traffic in band 2
#SIP packets with definied TOS mark :
tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip tos 0x60 0xff flowid 1:2
#tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip dport 5060 0xffff flowid 1:2
#tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip sport 5060 0xffff flowid 1:2
#Adding tos 0x10 (Minimize Delay) in band 2:
tc filter add dev $dev protocol ip parent 1: prio 1 u32 match ip tos 0x10 0xff flowid 1:2

Note:

We use Hosting and VPS Hosting, from: www.star-host.org

We like and trust them.

Good prices, high security.

 

fShare
Tweet