Friday, February 25, 2011
DTMF issue on Asterisk
IVR to work with VoIP<-->PSTN system perfectly, DTMF coding must be precise which can't be achieved perfectly with VoIP system (no matter if it is CISCO, AVAYA or Asterisk) all the time.
VoIP<-->VoIP is not a problem as DTMF code is passed as RTP payload and they know what to do with it.
VoIP<----RTP Payload------------RTP Payload------>VoIP
But with VoIP<-->PSTN, those DTMF tone has to be converted to RTP payload or RTP payload has to be converted back to DTMF tone, which doesn't happen precisely all the time.
VoIP <----RTP Payload--------------------DTMF------>PSTN
Q: How can I troubleshoot DTMF on asterisk?
Ans: You can go to /etc/asterisk/logger.conf and add dtmf for logging.
#vi /etc/asterisk/logger.conf
[logfiles]
full => verbose,debug,dtmf
Reload logger in asterisk
#asterisk -rv
CLI> logger reload
Perform test calls.
#tail -f /var/log/asterisk/full [ to see the realtime data logging ]
Press Ctrl + C to get out of the real time data monitoring
Q: I am having issues with duplicate DTMF. It appears that my asterisk box is receiving doubled DTMF signals. What could I do to fix it?
Ans: You have to change the setting in /etc/asterisk/chan_dahdi.conf. Add relaxdtmf=yes in that file.
Please ignore trunkgroups setting if that's not applicable in your environment. You simply need is relaxdtmf=yes under [channels] context
#vi /etc/asterisk/chan_dahdi.conf
[trunkgroups]
trunkgroup => 2,24,48
spanmap => 1,2,l
spanmap => 2,2,0
[channels]
usecallerid=yes
callwaiting=yes
usecallingpres=yes
callwaitingcallerid=yes
threewaycalling=yes
callerid=asreceived
relaxdtmf=yes
;This is PSTN Connection (G2)
context=From_Dahdi
switchtype=national
signalling=pri_cpe
group=2
channel => 1-23
channel => 25-47
Q: What kind of DTMF signalling should I prefer?
Ans: Out-of-band technique or RFT2833 is the most appropriate one and it's default on asterisk. You can explicitly specify
dtmfmode=auto [ Use rfc2833 if offered, inband otherwise ]
or
dtmfmode=rfc2833
If you are using SIP channels/trunks, define dtmfmode in sip.conf under [general] context
For more info you can visit www.voip-info.org
Tuesday, February 15, 2011
G711 vs G729 Which one to choose?
Sender side:
Human Voice/Audio ---> Filter --> 4Khz ----> Nyquist Sampling at 8Khz ----> A/D converter [each sample changed to 8 bit] ----> 64Kb per second
Thus data rate of G711 is 64Kbps
Receiver side:
Digital data is converted back to audio using D/A converter.
It is very simple, less CPU intensive and widely used. However, if bandwidth is expensive, it's not a good option. There are various codecs. Most efficient (bandwidth wise *NOT* CPU wise) one is G729.
Wikipedia: G729 does coding of speech at 8 kbit/s using conjugate-structure algebraic-code-excited linear prediction (CS-ACELP).
G729 uses complex algorithms to synthesize the speakers' voice. It uses vocoder [ tone generator + white noise generator + filter] to shape the sound as the nose, lip, throat, tounge and vocal cavity do. Vocoder itself generates robotic tone which is not acceptable. Thus G729 also uses samples of speakers' voice to adjust the vocoder setting properly and it compares synthetic voice with actual voice to come up with *CODE*. Then that CODE and vocoder settings are sent to the receiver. Receiver generates the sound using the provided CODE and vocoder settings.
Isn't that cool? However, it's CPU intensive.
G711 is free, however G729 requires license ( $10 per channel).
Summary:
- G711 sends actual sample of speakers' voice, while G729 sends the vocoder settings and calculated CODE required to generate the voice.
- Data rate: G711 = 64Kbps , G729 = 8Kbps
- G711 uses high bandwidth but it's not CPU intensive. G729 uses less bandwidth but it's CPU intensive
- Unlike G711,G729 is not free
- In VOIP implementation, G711 uses 87Kbps and G729 uses 32 Kbps (with all TCP/IP overhead)
SIP Communication ( SIP Signalling and Media transport)
In what conditions Asterisk is forced to handle the media stream?
In following conditions, Asterisk involves in media between the phones/UAs.
- If one of the clients is configured with canreinvite=NO, Asterisk will not issue a re-invite at all and will not redirect the media path.
- If the clients use different codecs, Asterisk will not issue a re-invite.
- If the Dial( ) command contains ''t'', ''T", "h", "H", "w", "W" or "L" (with multiple arguments) Asterisk will not issue a re-invite.
Why Asterisk is not SIP Proxy? [ from voip-info.org ]
Asterisk, as a server, is a SIP Registrar, location server and also acts as a useragent endpoint (softphone).
If it is 'controlling' or relaying a call from a SIP phone to another SIP phone, it simply acts as an endpoint UA to the originating call leg and then creates a new call to the receiving phone. Therefore, it stays "in the middle of the call," maintaining state and controlling, and optionally bridging, each remote endpoint. The audio channels (RTP) may go directly from phone to phone or may go through Asterisk's media bridge.
Asterisk can thus be described best as a "back-to-back user agent" (B2BUA), which is also consistent with the use of the term "PBX". Because of this architecture, fairly simple SIP functions, such as REFER (transfer) involve more aspects of the Asterisk core. On the other hand, the architecture provides additional power and flexibility, because each call leg can just as easily be replaced with a different technology channel (ZAP, H323, MGCP, etc) and, thus, Asterisk becomes a powerful media gateway.
SIP Proxy usually doesn't involve in the media stream between the phones, it simply handles SIP signalling. A SIP proxy handles call control on behalf of other user agents (UA) and usually does not maintain state during a call and therefore is never the endpoint of a call.
For more info click here
Friday, November 19, 2010
Install ASterisk GUI
Install Asterisk-GUI
1.Download and Install subversion
http://software.opensuse.org/search?baseproject=ALL&p=1&q=subversion
Excerpt from the INSTALL documentation in downloaded subversion package
Building from a Tarball or RPM
------------------------------
Download the most recent distribution tarball from:
http://subversion.tigris.org/servlets/ProjectDocumentList
Unpack it, and use the standard GNU procedure to compile:
$ ./configure
$ make
# make install
You can also run the full test suite by running 'make check'.
[ SVN takes long time to install]
2. Download and Install Asterisk
Download asterisk from www.asterisk.org
RESOLVE THE DEPENDENCIES
STEP 1: (DAHDI dependency)
Install ncurses and ncurses-devel
(ncurses is the library providing API for the programmer to create the GUI like interface in Terminal mode)
OR
Install slang and slang-devel
(library for Display control)
STEP 2: (DAHDI dependency)
Install libnewt and newt_devel
(shared libraries for Nifty Erik's Windowing Toolkit; Newt is a toolkit that allows applications that run on the console (so called "text mode applications") to use many of the graphical interface widgets, such as radio buttons and selection boxes, that are popular in GUI environments https://launchpad.net/newt)
STEP 3: (Dependency for DUNDi)
Install open-ssl and openssl-devel
(openssl creates secure sockets and transport layer security.
STEP 4:
Install popt and popt-devel
(C library for parsing command line parameters)
INSTALL libpri (make, make install)
INSTALL dahdi (make, make install, make config)
INSTALL addons (./configure, make)
INSTALL asterisk (./configure , make, make menuselect, make install)
3. Download Asterisk-GUI
Go to /usr/src and create a directory asterisk-gui
Run the command
#svn checkout http://svn.digium.com/svn/asterisk-gui/branches/2.0
(it will download the latest Asterisk-GUI. If not, then it will provide the README file with the latest link to download the Asterisk GUI using svn checkout)
- Install Asterisk-GUI
[Note: you don’t need Apache server to be running]
It’s easy if you know what you are doing.
Make a backup copy of your asterisk files
#cp –r /etc/asterisk /etc/asterisk-backup
Go to /etc/asterisk and create two files http.conf and manager.conf

vi /etc/asterisk/http.conf
[general]
enabled = yes
enablestatic = yes
bindaddr = 0.0.0.0
bindport = 8088
prefix = asterisk
vi /etc/asterisk/manager.conf
[general]
enabled = yes
webenabled = yes
bindaddr = 0.0.0.0
port = 5038
[administrator]
secret = 1234abc
permit = 0.0.0.0/0.0.0.0
read = system,call,log,verbose,command,agent,user,config
write = system,call,log,verbose,command,agent,user,config,originate
Go to /usr/src/asterisk-gui [the location where you downloaded Asterisk-GUI]
./configure
make
make install
make checkconfig
Go to asterisk console and restart the asterisk

# asterisk
#asterisk –rv
CLI> core restart now
#asterisk –rv
CLI>http show status
HTTP Server Status:
Prefix: /asterisk
Server Enabled and Bound to 0.0.0.0:8088
Enabled URI's:
/asterisk/httpstatus => Asterisk HTTP General Status
/asterisk/phoneprov/... => Asterisk HTTP Phone Provisioning Tool
/asterisk/manager => HTML Manager Event Interface
/asterisk/rawman => Raw HTTP Manager Event Interface
/asterisk/static/... => Asterisk HTTP Static Delivery
/asterisk/mxml => XML Manager Event Interface
Enabled Redirects:
None.
Go to the webpage
http://ServerIPAddress:8088/asterisk/static/config/cfgbasic.html
http://ServerIPAddress:8088/asterisk/static/config/cfgadvanced.html
http://ServerIPAddress:8088/asterisk/static/config/index.html
Monday, October 11, 2010
Boring but useful theory on SIP... How SIP works?
of session. Voice sessions are just one example.
SIP UA : interface for the users e.g IP phones, computer applications to make call
Redirect Servers: help locate SIP UA; it simply returns the list of the possible SIP UA addresses e.g BOB@university.com BOB@company.com
Proxy Servers: reduces the overload of the information and acknowledgment (look page 104 Sip Demystified)
Registrar/SIP server: It refers to both: Redirect and Proxy Servers
Location Servers: Most registrars upload location updates to a location
server upon receipt. SIP is not used between location servers and SIP servers. It uses LDAP to communicate with SIP servers
SIP clearly distinguishes between session establishment and session description. SIP
just provides connectivity; what users do with it is outside of the scope of
SIP.
SIP does not even assume that the session it has established will take place in the
Internet. For instance, if Bob wants to invite Laura to join a conference call
that is taking place in the public-switched telephone network (PSTN), all he
has to do is use SIP to deliver the telephone number that she can dial to join
in. In this example, the session description would contain a telephone number
instead of IP addresses and UDP ports. When SIP delivers the session
description to Laura, she reacts as she does to any kind of ping with the tool
she’s been given.
SIP provides just enough information for the invitee to accept the invitation
Servers that do notneed to monitor signalling for the duration of the session can handle a larger number of sessions.
when two user agents exchange SIP messages, the User Agent (UA) sending
requests is the User Agent Client (UAC) and the UA returning responses is
the User Agent Server (UAS). A SIP request, together with the responses it
triggers, is referred to as a SIP transaction.
SIP Responses
Upon reception of a request, a server issues one or several responses.
Range Response Class
100—199 Informational - Provisional Response
200—299 Success - Final Response of INVITE
300—399 Redirection
400—499 Client error
500—599 Server error
600—699 Global failure
SIP Requests
Every SIP request contains a field, called a
method, which denotes its purpose
INVITE
ACK
OPTIONS
BYE
CANCEL
REGISTER
Both requests and responses can contain SIP bodies. The body of a message
is its payload. SIP bodies usually consist of a session description
Example:
UA Client (Bob) called UA Server (Laura)
UA Client ----- invite------> UA Server
UA Client <-----180 Ringing-- UA Server (phone ringing)
UA Client <-----200 OK ------ UA Server (Off Hook/Recieve call)
UA Client ------ACK---------> UA Server
UA Client <---CONVERSATION--> UA Server
Three way handsake: INVITE-final response-ACK
ACK : ACKs are generated as final responses to an INVITE
Sending an ACK to every destination that has responded is essential to ensuring SIP operation over unreliable protocols such as UDP.
Errorneous case (taken care by ACK):
Bob would send an INVITE to Laura and retransmit it until it received
a final response from Laura. Until this final response is received, Bob cannot
know whether Laura received the INVITE or it got lost in the network.
Bob waits for a while and because he gets no answer, he gives up and
stops retransmitting the INVITE. Bob believes that no session has been
established.
At roughly the same time, Laura accepts Bob’s call and sends back a “200
OK” response. If this response gets lost, Bob will never receive it, so, Bob
still believes that no session has been established. Because Laura observes
that Bob has stopped retransmitting the INVITE, she assumes that Bob
has received her 200 OK. Therefore, Laura thinks that the session has been
successfully established
If a three-way handshake were in place for this scenario, Laura would
not receive an ACK for her 200 OK response, given that Bob gave up some
time ago. Thus, she would (correctly) think that the session was not established.
CANCEL
Let's say BOB called LAURA and waited for few rings and hangup as LAURA is not picking up the call
BOB -----------INVITE------------> LAURA
BOB <----------180 Ringing-------- LAURA (Phone ringing)
(Bob decided to hangup as he already waited for few rings)
BOB -----------CANCEL------------> LAURA
BOB <----------200 OK------------- LAURA (Reply back for CANCEL request)
BOB <--487 Transaction Cancelled-- LAURA (Reply for INVITE request)
BOB ------------ACK--------------> LAURA
CANCEL request is very useful when forking proxies are in the path. (pg 123)
Remember that a CANCEL request does not affect a transaction once a
final response has been sent.
BYE It is used to abandon sessions.
UA Client (Bob) called UA Server (Laura) and they started conversation. Then Laura went ON HOOK (Release the call)
UA Client ----- invite------> UA Server
UA Client <-----180 Ringing-- UA Server (phone ringing)
UA Client <-----200 OK ------ UA Server (Off Hook/Recieve call)
UA Client ------ACK---------> UA Server
UA Client <---CONVERSATION--> UA Server
UA Client <----- BYE -------- UA Server (abandon call)
UA Client -------200 OK-----> UA Server
REGISTER
BOB ---------REGISTER------> REGISTRAR
BOB <-------- 200 OK-------- REGISTRAR
OPTIONS
OPTIONS requests query a server about its capabilities.
One SIP server might answer to an OPTIONS request that it
supports SDP as session description protocol and five methods: INVITE,
ACK, CANCEL, BYE, and OPTIONS. Because the server does not support
the REGISTER method, I can deduce that it is not a registrar.
BOB ---------OPTIONS------> SIP SERVER
BOB <-------- 200 OK-------- SIP SERVER
Types of Proxy Servers
1. Call Stateful
2. Stateful
3. Stateless
1. Call Stateful
Call Stateful proxies need to be informed of all the SIP transactions that occur during the session and therefore, they are always in the path taken by SIP messages travelling between end users.
2. Stateful Proxy
Also known as Transaction Stateful Proxies because the transaction is their sole concern. e.g Forking Proxies
Proxy servers can only ACK non-successful final responses, which have a status code > 299
3. Stateless Proxy
Stateless proxes don't keep any state. They receive a request, forward it to the next hop, and immediately delete all state related to that request. It determines routing based solely on the Via header.
SIP uses text encoding as opposed to binary.
SIP is an application layer protocol.
By utilizing application layer time-outs with its retransmissions, an
application layer protocol can still exploit unreliable transport mechanisms (like UDP)
Thursday, September 23, 2010
Converting WAV file to Asterisk Audio file?
# man sox
# sox NONasteriskXXX.wav -c 1 -r 8000 asteriskXXX.gsm
(it resamples the non asterisk audio file in single channel audio with 8Khz sampling frequency)
If you have tons of wav file, it's waste of time to type a command for every individual wav files. So, you can do the following
Let's say you have WAV files in /tmp/recordings directory.
/tmp/recordings# for i in *
> do
> sox $i -c 1 -r 8000 `echo $i|sed "s/.wav/.gsm/"`
> done
Ooola.. it's done!!! You just converted all the files in /tmp/recordings directory from WAV to gsm.
Here, we are using for loop to go thru' each files in the /tmp/recordings directory. '$i' returns the file name. 'sed "s/.wav/.gsm/"' renames the file from .wav to .gsm
Tuesday, September 14, 2010
Purge old voicemails and renumber/rename the voicemail files
When you delete the old files (say older then 10 days) you need to make sure that you rename the other files accordingly. In this case, after you delete msg0000.xxx (older than 10 days) , you need to rename msg0001.xxx to msg0000.xxx so that other new messages will appear in the appropriate order.
/root# vi renumber.sh
#!/bin/bash
function padder() {
case $1 in
"new")
case ${#new} in
1) newpad=000$new;;
2) newpad=00$new;;
esac;;
"old")
case ${#old} in
1)oldpad=000$old;;
2)oldpad=00$old;;
esac;;
esac
}
new=0
padder new
totalfiles=`find . -type f -name "msg.*txt"|wc -l`
for (( old=0; old<100; old+=1 )); do
padder old
if ( test -e msg$oldpad.txt); then
if ( test -e msg$newpad.txt); then
echo "file already exists";
else
for ext in txt WAV; do mv msg$oldpad.$ext msg$newpad.$ext; done
fi
let new+=1
padder new
if (( $new == $totalfiles )); then break; fi
fi
done
2. Now you have to write the script that can crawl through all of the VMbox and rename the voicemails appropriately.
/root #vi collect-and-rename.sh
#!/bin/bash
basedir=/var/spool/asterisk/voicemail/default
cd $basedir
echo $basedir
for str in `find . -type f -name "msg*.txt"`; do
maindir=`echo "$str"|awk -F/ '{print $2}'`
cd ./$maindir/INBOX
# echo `pwd`
bash /root/renumber.sh
cd $basedir
cd ./$maindir/Old
# echo `pwd`
bash /root/renumber.sh
cd $basedir
done
3. Script to delete files older than 10 days
/root # vi deleteOldVm.sh
#!/bin/bash
$dir=/var/spool/asterisk/voicemail/default
cd $dir
find . -type f -name msg????.??? -mtime +10 -exec -rm {} \;
http://www.oneharding.com/voip/asterisk_voicemail_scripts.html
http://djlab.com/2010/05/automatically-purge-old-voicemail-on-asteriskfreepbxtrixbox/
http://www.vectorsite.net/tsawk_2.html