Sunday, November 27, 2011

Difference between Asterisk and Freeswitch


Asterisk and FreeSWITCH are B2BUA (Back-to-back user agents). They act as a user agent for two or more ends, and use a common protocol like the Session Initiation Protocol (SIP). The B2BUA is responsible for handling all SIP signaling between the end-points, route calls, transfer calls, translate codecs between the call legs and offer value-added features to the call such as voicemail and call transfer.
In other words, they are telephony platforms designed to facilitate the creation of voice and chat driven products. FreeSWITCH in particular, can scale from a soft-phone up to a soft-switch. It can be used as a simple switching engine, a PBX, a media gateway or a media server to host IVR applications using simple scripts or XML to control the call flow.

Isn’t FreeSWITCH a soft-switch and Asterisk a PBX? What is the difference?
Extracted from the FreeSWITCH FAQ:
"A PBX is an entity that allows a private company to have its own mini phone company providing services like voicemail, extensions and conferencing to phones. The primary focus of a PBX is for multiple phones to find each other and communicate. A soft-switch is a software application that can connect phone lines from one network to another, often routing calls from one protocol to another or to a termination point such as a PBX. FreeSWITCH has the potential to also implement a PBX but it is not mandated to. Think of it as a lower level application than a PBX. It’s possible to load several modules into FreeSWITCH to make it behave exactly like a cluster of PBX applications. This is entirely easier than trying to make a single monolithic PBX behave as a switch especially when much of the PBX functionality is permanently built into the core of the PBX application."

My first experience with Asterisk 

I installed Asterisk in my lab setup and right now it does inbound/outbound, IVR (Interactive Voice Response), conferences, voicemail, call forwarding and almost everything else you would expect from a nice VoIP (PBX) server. There are some things that some of us would like to have that are not currently available in the Asterisk software, such as dialing out from conferences and soft-based conferences. A few employees have asked me for the option to dial out from conferences but I cannot yet add this to our configuration because the feature doesn't exist in Asterisk. It is a technical limitation of Asterisk but it is available on FreeSWITCH. This is one of the reasons that FreeSWITCH would be better suited for us.
I have a fair amount of Asterisk knowledge now. I have used it for some time and I know its merits and its problems. The nice thing about Asterisk is that it's really easy to set up and configure the way you want. The bad thing about it is that it has some internal problems on its core and sometimes it gives you unexpected problems. It also lacks some of the features we need.

Asterisk issues and bugs I have found in the software

I ran into some problems when I tried to deploy Asterisk on a VPS first (Amazon EC2). When I tried to do conferencing, I needed the MeetMe application that provides conferences, and MeetMe depends on Zaptel (which is another piece of software that provides the timing that MeetMe needs). I tried to install Zaptel, but Zaptel refused to work on XEN (the virtualization software that our VPS uses). So I didn't have any other choice but to go with a dedicated server for our VoIP needs. FreeSWITCH works great on a VPS with all the conferencing features, and everything out of the box - no zaptel, ztdummy or anything that could interfere is needed.
I tried very hard to make Asterisk work with the conference features on the VPS (Amazon EC2). I also tried with other conference applications like app_conference. This doesn't require an external timing source like MeetMe does, but it lacks some features that we needed, such as sound notifications. MeetMe had this but MeetMe wasn't an option on the VPS because of its technical requirements. I also tried to get support on Asterisk and their response to my problem was that it was "irrelevant".
This was the first time I started asking myself, "Why do I need a ztdummy driver (Zaptel) in order to use the conference module? Why can't the conference module use it's own internal timing source?" I thought there was something wrong with this design. That was the first time I heard about FreeSWITCH and when I saw the light.
I also experienced DTMF problems and sound corruption with Asterisk. This happens because the Asterisk core is broken. I tried doing the same things in FreeSWITCH and everything worked great.
After all of the work that I put into making Asterisk work on our server, I keep discovering more and more problems with it. The first problem I discovered after everything was working was the DTMF problem. One day an employee asked me why his password wasn't working. I went and looked at the server and his password was there and everything looked good. Then I tried to debug it and I put a function on the dialplan that returned the digits that you send to the server and to my surprise, the server was printing bad/broken digits. So after a lot of research, I have come with the conclusion that the DTMF in Asterisk was broken.

One workaround for this problem was to use rfc2833compensate=yes in the sip configuration, in order to compensate the DTMF digits or RTP packets... this fixed it with X-Lite but the problem still happens with Zoiper. I'm sure this is the reason that passwords fail for conferences sometimes.
Another problem I had was with sound. The sound gets corrupted after a while with the Speex codec. Again I reported a bug of this
I have also experienced some deadlocks with Asterisk as reported here:bugs.digium.com/view.php
I have tried the same things with FreeSWITCH and I haven't experienced the problems. It all went very smoothly and FreeSWITCH has some features that Asterisk doesn't, such as dialing out from conferences.
I came to the point where I realized that we need a better solution. Asterisk has too many problems for our company. I decided to go with FreeSWITCH in order to have a high quality PBX.

On the way to a better VoIP solution with FreeSWITCH
The learning curve on FreeSWITCH for me wasn't that bad. However, I didn't know so it was a bit tedious for me at first. I now realize that the XML configuration is a good thing. Regular expressions in the dialplan make it succinct and the XML makes adding customized features very easy and straightforward. FreeSWITCH is a class-five soft-switch that can be molded the way you want, from a PBX to carrier-grade soft-switch to anything you can ever imagine, and it's very extensible. The design that its creator went with is excellent. It is a masterpiece and there is nothing in the open source world or in the proprietary world that comes even close to it. I think that it is a great piece of work.
One of the big advantages of FreeSWITCH is that it's core is better designed, with a lot of care in the details. The primary author of FreeSWITCH is a former developer that spent a lot of time working with the flawed Asterisk design and finally gave up and decided to build a VoIP system that would be stable, scalable and extensible. The stable part means that we'll all be able to sleep well at night.
One of the nice things about FreeSWITCH is the community. The developers themselves and the users all hang in one channel - #freeswitch (at freenode). The mailing list is also a very nice place. In both places they are very friendly and supportive, unlike the Asterisk/Digium community. They are also open-minded. At one point I asked for a feature (mod_yaml) and the creator of FreeSWITCH (Anthony Minessale) came up with this feature in less than 3 hours - without even knowing what YAML was when the feature was asked for. It was really impressive. He came up with a whole new feature that he hadn't even heard of yet, while the Asterisk devs can't even fix little bugs.

Another nice thing about FreeSWITCH is that it doesn't suffer from the "Not Invented Here" (NIH) syndrome that Asterisk suffers from. FreeSWITCH uses the Sofia SIP stack, a 100% RFC compliant SIP stack, which is very complete, robust and mature. Nokia also actively contributes in this stack along with the FS developers. They also use XML and PCRE (Perl Compatible Regular Expressions) for the dialplan, the Apache Portable Runtime (APR) and SQLite. FreeSWITCH has the ability to load scripts written in LUA, Python, Perl, PHP and XML in the dialplan as "applications” so you have a lot of flexibility and freedom in how you want to configure your VoIP system.

Please write to me at dipkumar.mehta@gmail.com for Freeswitch Consultancy across the globe.


Friday, October 21, 2011

How to install Asterisk 1.8 on Ubuntu Server 11.04


It is easy to install and use an Asterisk  on Ubuntu New Server addition 11.04 – if you do it frequently. 
I use Asterisk 1.8.3.3 on my 64 bit Ubuntu Server 11.04.
After the upgrade on a fresh install, we need three packages to build up our Asterisk. Let’s install the build-essential, libxml2-dev, and ncurses-dev packages. These package are not included by default and should be installed seperately as described below. 
apt-get install build-essential libxml2-dev ncurses-dev 
Pre-requisite : 
As these packages are not included by default, running them from the CD will generate errors.
Example : E:\ no packages found. So please # comment out the CD rom related settings rc.local file.

Asterisk_01


You can find all versions of the Asterisk at the download section. Download the latest version, and extract it!

Please right-click on the tar file on asterisk site and select copy link address
/usr/src is the most common place or directory to install this files
cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-1.8.3.3.tar.gztar zxvf asterisk-1.8.3.3.tar.gz

or 
wget paste Link address
Then install the Asterisk, config, and the shamples.

cd asterisk-1.8.3.3/
./configure
make
make install
make config
make samples 
Without the above-mentioned additional packages, you will face with these error messages during the ./configure command run.
Lack of build-essential package:

configure: error: in `/root/asterisk-1.8.3.3':
configure: error: no acceptable C compiler found in $PATH 
Lack of libxml2-dev package:

checking for xml2-config... no
configure: *** XML documentation will not be available because the 'libxml2' development package is missing.
configure: *** Please run the 'configure' script with the '--disable-xmldoc' parameter option
configure: *** or install the 'libxml2' development package. 
Lack of ncurses-dev package:

configure: error: *** termcap support not found (on modern systems, this typically means the ncurses development package is missing) 
When the installation finishes, we have a preconfigured Asterisk. To test the Asterisk with two softphones, let’s configure the sip.conf and the extensions.conf.
Here is the sip.conf file:

[general]
context = default
bindport = 5060
bindaddr = 0.0.0.0
tcpbindaddr = 0.0.0.0
tcpenable = yes 

[1001]
type = friend
callerid = User One <1001>
secret = 1001
host = dynamic
canreinvite = no
dtmfmode = rfc2833
mailbox = 1001
disallow = all
allow = ulaw
transport = udp 

[1002]
type = friend
callerid = User Two <1002>
secret = 1002
host = dynamic
canreinvite = no
dtmfmode = rfc2833
mailbox = 1002
disallow = all
allow = ulaw
transport = udp 
This config means that the Asterisk listen all IP, port 5060, and the TCP is enabled. It has two extensions defined for User One and User Two.
Here is the extensions.conf file:

[general]
static=yes
writeprotect=no 

[default]
exten => 1001,1,Answer()
exten => 1001,n,Dial(SIP/1001,20,tr)
exten => 1001,n,Hangup 

exten => 1002,1,Answer()
exten => 1002,n,Dial(SIP/1002,20,tr)
exten => 1002,n,Hangup. 
This config means that there are two accessible extensions existing.
After configuring the Asterisk, we need to start it.

/etc/init.d/asterisk start 
Asterisk_02
I use X-Lite to connect to the soft PBX. Let’s configure the X-Lite!
All data come from the sip.conf. The Account name, and the Display name are the callerid. The User ID and the Authorization name are the extension number – inside the square brackets. The Password is the sicret. The Domain is the IP address of the Asterisk server.
If all configurations are good, the X-Lite will inform you.
Asterisk_03
Let’s call from User One to User Two.
Here is the User One side:
Asterisk_04
Here is the User Two side:
Asterisk_05
Troubleshooting? We always need when we try a new thing. The firs tool is the tcpdump of course, but the asterisk have a good command line interface (Asterisk CLI) to debug the problem. To access the Asterisk CLI type

asterisk -vvvvvvr 
This screen shows a successful call from 1001 to 1002.
Asterisk_06
The Asterisk works now! Are you wondering why I configured my Asterisk to answer on TCP? Because I would like to test the Direct SIP feature of the Microsoft Communications Serverand the Lync. CU next time! ;-)