SIP/VoIP Protocol Deep Dive
Introduction to SIP (Session Initiation Protocol)
SIP is an application-layer signaling protocol used for establishing, modifying, and
terminating multimedia sessions (voice, video, messaging) over IP networks. It’s a key
protocol in Voice over IP (VoIP) systems and follows the IETF RFC 3261 standard.
Protocol Basics
Transport Protocols: SIP can run over UDP, TCP, or TLS (for secure communications)
Port Numbers: Typically 5060 for unencrypted, 5061 for TLS
Message Types: Request and Response
Components: User Agents (UAC/UAS), Proxies, Registrars, Redirect Servers
SIP Message Structure
SIP-message = Request / Response
Request = Request-Line
*( message-header )
CRLF
[ message-body ]
Response = Status-Line
*( message-header )
CRLF
[ message-body ]
SIP Request Methods
1. INVITE - Initiates a session
2. ACK - Confirms final response to INVITE
3. BYE - Terminates a session
4. CANCEL - Cancels pending requests
5. REGISTER - Registers contact information
6. OPTIONS - Queries server capabilities
7. PRACK - Provisional acknowledgement
8. SUBSCRIBE - Subscribes to notifications
9. NOTIFY - Notifies subscribers of events
10. PUBLISH - Publishes event state
11. INFO - Mid-session information
12. REFER - Refers to another resource
13. MESSAGE - Instant messaging
14. UPDATE - Modifies session state
SIP Response Codes
Code Category Description
1xx Provisional Request received, processing
2xx Success Action successfully completed
3xx Redirection Further action needed
4xx Client Error Request contains bad syntax
5xx Server Error Server failed to fulfill request
6xx Global Failure Request cannot be fulfilled anywhere
SIP Header Fields
Required Headers in all SIP messages:
Via - Path taken by the request
From - Originator of the request
To - Recipient of the request
Call-ID - Unique identifier for the call
CSeq - Command sequence number
Max-Forwards - Limits number of hops
Contact - Direct contact address
Common Optional Headers:
Allow - Lists supported methods
Content-Type - Type of message body
Content-Length - Size of message body
Expires - Time until expiration
Record-Route - Forces routing through proxies
Route - Pre-determined route path
Supported - Lists supported extensions
User-Agent - Client software information
Authorization - Authentication credentials
WWW-Authenticate - Authentication challenge
SIP Message Flow Examples
Basic SIP Call Flow (SIP Trapezoid)
Caller UA Outbound Proxy Inbound Proxy Callee UA
| | | |
|--- REGISTER ---->| | |
|<-- 200 OK ------| | |
| | |
| |--- REGISTER ------>| |
| |<--- 200 OK ---------| |
| | |
|--- INVITE ------>| | |
| |--- INVITE --------->| |
| | |--- INVITE ----->|
| | |<-- 180 Ringing -|
| |<-- 180 Ringing ----| |
|<-- 180 Ringing --| | |
| | |<-- 200 OK ------|
| |<-- 200 OK ---------| |
|<-- 200 OK -------| | |
|--- ACK --------->| | |
| |--- ACK ------------>| |
| | |--- ACK -------->|
| | | |
|<================= RTP Media Stream ====================>|
| | | |
|--- BYE --------->| | |
| |--- BYE ------------>| |
| | |--- BYE -------->|
| | |<-- 200 OK ------|
| |<-- 200 OK ---------| |
|<-- 200 OK -------| | |
SIP Registration Flow
User Agent Registrar
| |
|--- REGISTER (no auth) ------>|
|<-- 401 Unauthorized ---------|
| |
|--- REGISTER (with auth) ---->|
|<-- 200 OK -------------------|
| |
SDP (Session Description Protocol)
SIP uses SDP in message bodies to describe media sessions:
v=0
o=alice 2890844526 2890844526 IN IP4 host.anywhere.com
s=-
c=IN IP4 host.anywhere.com
t=0 0
m=audio 49170 RTP/AVP 0
a=rtpmap:0 PCMU/8000
m=video 51372 RTP/AVP 31
a=rtpmap:31 H261/90000
SIP Security Considerations
SIPS URI scheme: sip: → sips: for TLS
Authentication: Digest authentication (RFC 3261)
Encryption: SRTP for media, TLS for signaling
Firewall/NAT traversal: STUN, TURN, ICE
Related RFCs for Further Study
1. RFC 3261 - SIP: Session Initiation Protocol (core specification)
2. RFC 4566 - SDP: Session Description Protocol
3. RFC 3550 - RTP: Real-time Transport Protocol
4. RFC 3551 - RTP Profile for Audio and Video Conferences
5. RFC 3960 - Early Media and Ringing Tone Generation in SIP
6. RFC 3891 - The Session Initiation Protocol (SIP) “Replaces” Header
7. RFC 3262 - Reliability of Provisional Responses in SIP
8. RFC 3311 - The Session Initiation Protocol (SIP) UPDATE Method
9. RFC 3428 - SIP Extension for Instant Messaging
10. RFC 3515 - The Session Initiation Protocol (SIP) Refer Method
11. RFC 3665 - SIP Basic Call Flow Examples
12. RFC 4474 - Enhancements for Authenticated Identity Management in SIP
13. RFC 4568 - Session Description Protocol (SDP) Security Descriptions
14. RFC 5763 - Framework for Establishing a Secure Real-time Transport Protocol (SRTP)
15. RFC 5766 - Traversal Using Relays around NAT (TURN)
Learning Resources
1. Books:
“SIP: Understanding the Session Initiation Protocol” by Alan B. Johnston
“SIP Demystified” by Gonzalo Camarillo
“The 3G IP Multimedia Subsystem (IMS)” by Gonzalo Camarillo and Miguel A.
García-Martín
2. Online Courses:
SIP School (https://www.thesipschool.com)
VoIP and SIP (Udemy/Coursera)
3. Tools for Practice:
Wireshark (for SIP packet analysis)
SIPp (SIP testing tool)
Asterisk (open-source PBX)
Kamailio/OpenSIPS (SIP server)
4. Online References:
IETF SIP Working Group documents
VoIP-Info SIP section (https://www.voip-info.org/sip/)
Wikipedia SIP page
Would you like me to elaborate on any specific aspect of SIP/VoIP?