Sunday, January 15, 2012

SIP Protocol Messages


  • INVITE Indicates that a user is being invited to join a session.
  • ACK Confirms that client has received a response to the invite message.
  • BYE Terminates a call.
  • CANCEL Cancels any Pending Searches.
  • OPTIONS Queries for Capabilities.
  • REGISTER Registers the Address listed in the header field with a SIP Server


1xx Informational Messages

  • 100 Trying: Indicates that a request has been initiated by the caller and the called party has yet not been located.
  • 180 Ringing: Indicates that the called party has been located and is being notified of the call.
  • 181 Call is being forwarded: Indicates that the called party has rerouted the call to another.
  • 182 Queued: Indicates that the called party is currently not available, and have put the call in queue.
  • 183 Session in Progress

2xx Successful Responses

  • 200 OK: Indicates that the request has been successfully processed.

3xx Redirection Responses

  • 300 Multiple Choices: Indicates that the address resolved to more than one location.
  • 301 Moved permanently: Indicates user is no longer available at this location, an alternate location should be included in the header.
  • 302 Moved Temporarily: Indicates that the user in temporarily unavailable, an alternate location should be included in the header.
  • 305 Use Proxy: This response indicates that the caller must use a proxy to contact the called party.
  • 380 Call is not successful but alternate services are available.

4xx Request Failure Responses

  • 400 Bad Request: Indicates the request sent could not be understood.
  • 401 Unauthorized Request: Indicates the request requires authorization.
  • 402 Payment Required: Indicates payment is required to complete the call.
  • 403 Forbidden: Indicates Server has received the request but will not provide the service.
  • 404 Not Found: Indicates the server was not found.
  • 405 Method Not Allowed: Indicates that the request contains a list of methods that are not allowed.
  • 406 Not acceptable: Indicates that the request can not be processed by the client.
  • 407 Proxy Authentication Required: Client must first authenticate itself with a proxy.
  • 408 Request Timeout: The server could not produce a response before a given time out.
  • 409 Conflict: Indicates a conflict with the current state of the resource.
  • 410 Gone: Resource is no longer available at the server and no forwarding address was found.
  • 411 Length Required: User refuses request without a specified length.
  • 412 Request Entity Too Large: Server refuses to process request because URI is too long.
  • 415 Unsupported Media: Indicates the format of the body is not supported by the destination endpoint.
  • 420 Bad Extension: The server could not understand the protocol extension indicated in the required header.
  • 480 Temporarily Unavailable: Indicates that the called party was contacted but was temporarily unavailable.
  • 481 Call Leg Transaction Does Not Exist: Indicates that the server was ignoring the request of bye or cancel since there is no matching Invite transaction.
  • 482 Loop Detected: (Also, Request Merged) Server received a request which has it self in the path.
  • 483 Too Many Hops: The server received a request that required more hops than allowed.
  • 484 Incomplete Address: The server received a request with an incomplete address.
  • 485 Ambiguous: Server received a request in which the called address is ambiguous.
  • 486 Busy Here: The called party was contacted but the system was not able to receive any more calls.
  • 487 Request Terminated: The calling party canceled the request before the dialog was established with a 200 OK.
  • 488 Not Acceptable Here
  • 489 Bad Event: See RFC3265
  • 491 Request Pending
  • 493 Undecipherable
  • 494 Security Agreement Required: See RFC3329

5xx Server Failure Responses

  • 500 Server Internal Error: Server encountered an unexpected error and could not process the request
  • 501 Not Implemented: Server does not support the functions required to complete the request.
  • 502 Bad Gateway: Server received an invalid request upstream.
  • 503 Service Unavailable: Server has an overload or maintenance problem.
  • 504 Gateway Timeout: Server did not receive a timely response from another server.
  • 505 Version Not Supported: Server does not support the SIP protocol used in the request.

6xx Global Failure Responses

  • 600 Busy Everywhere: Called party is busy and cannot take the call at this time.
  • 603 Decline: Called party was contacted but does not want to take part in the call.
  • 604 Does Not Exist Anywhere: Called Party does not exist anywhere in the network.
  • 606 Not Acceptable: Called party has rejected some part of the call session description as unacceptable.

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
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 for Freeswitch Consultancy across the globe.