Time for another post on SIP, why SIP?  Because SIP is good, SIP is like a nice dessert, it is something that just works. This time I want to touch on some of its basic fundamentals; the three way handshake. I decided on this topic because recently I have been working on a number of issues that had to do with incomplete SIP messaging between endpoints and calls that were being cut off after about 30 to 40 seconds. Now, when you come across calls that disconnect after a certain and set period time and time again, you can bet money on it, that some timer has expired forcing the call to drop.

So let me brush up some basics regarding SIP call establishment. SIP Sessions are used with Voice and Video over IP, to establish a call session between users. The core SIP specification provides a way to set up and manage sessions between two user agents (i.e. endpoints, such as desk phones, or software SIP clients).

SIP sessions, sometimes referred to informally as “calls” and more formally referred to as dialogs, are created via invitations from one User Agent (User Agent Client or UAC) to another (User Agent Server or UAS). This invitation transaction is basically a three-way handshake between the UAC and UAS that consists of the initial INVITE message sent by the UAC to the UAS, one or more provisional responses sent by the UAS to the UAC, a final response sent by the UAS to the UAC, and an acknowledgment sent by the UAC to the UAS.

The three way handshake (similar to a TCP three way handshake) in SIP works as follows INVITE  –response (1xx)  – ACK. So as soon as the INVITE is sent to request a dialog  (Alice in the example picture above), Bob sends a 100 TRYING status update back, so UA1 does not re-transmit its INVITE. The 180 RINGING is sent back to Alice to signify that the phone is ringing. The 200 OK is sent from the called party as soon as Bob picks up the phone (in this cased the OK also contains the SDP). After this the ACK is send by the caller. Remember the ACK is always sent by the party that sent the initial INVITE. This ACK as part of the 3 way handshake is important because with this ACK the caller confirms back to the called party that it has received a final response to an INVITE Request. All these messages within the three way handshake will have the same Cseq # in their message header.

So, in  a nutshell, the 3 way SIP handshake is:

  • The caller sends an INVITE
  • The callee sends an 200 OK to accept the call
  • The caller sends an ACK to indicate that the handshake is done and a call is going to be setup

I you want more in depth documentation on SIP, i suggest you read  RFC 3261