Understanding the SIP Protocol
| Quick Navigation | ||
|---|---|---|
| Architecture & Basics | Messages & Call Flow | Advanced Topics |
|
Core Components Addressing & Transport |
SIP Methods Response Codes Call Flows |
Core Concepts Registration Extensions Reference |
Session Initiation Protocol (SIP) is an application-layer signaling protocol for creating, modifying, and terminating multimedia sessions over IP. SIP handles signaling; actual media uses RTP. Messages are text-based (like HTTP) using a request/response model with session descriptions in SDP.
Core specification: RFC 3261 (2002). Extended by numerous RFCs for reliability, events, IM, security, etc.
SIP Architecture
User Agent (UA)
An endpoint (softphone, IP phone) that initiates or receives calls. Has two roles:
- UAC (User Agent Client) - initiates requests (caller)
- UAS (User Agent Server) - responds to requests (callee)
Roles flip depending on direction - BYE sender becomes UAC for that transaction.
Proxy Server
Intermediary that routes SIP requests/responses on behalf of UAs. Performs routing logic, policy enforcement, authentication. Can be:
- Stateful - maintains transaction state, can fork requests to multiple destinations
- Stateless - simply forwards and forgets
Adds Via and optionally Record-Route headers before forwarding.
Registrar
Handles REGISTER requests - stores user's current location (IP/port) in the Location Service database. Maps Address-of-Record (AOR) like sip:alice@atlanta.com to Contact address of device.
Back-to-Back User Agent (B2BUA)
Acts as UAS to caller and UAC to callee, terminating one dialog and creating another. Common in PBX and SBC systems. Unlike proxies, maintains full call state and can modify signaling/media.
Addressing
| URI Scheme | Description | Example |
|---|---|---|
sip: |
Standard SIP URI | sip:alice@atlanta.com
|
sips: |
Secure SIP (TLS required) | sips:alice@atlanta.com
|
tel: |
Telephone number (RFC 3966) | tel:+1-555-123-4567
|
SIP uses DNS SRV/NAPTR records (RFC 3263) to locate servers for a domain.
Transport
| Transport | Port | Notes |
|---|---|---|
| UDP | 5060 | Most common, requires retransmission handling |
| TCP | 5060 | For large messages, reliable delivery |
| TLS | 5061 | Encrypted signaling |
| WebSocket | 80/443 | For web applications (RFC 7118) |
SIP Messages
Two types: Requests (methods) and Responses (status codes). Format: start line, headers, blank line, optional body (usually SDP).
Core SIP Methods
| Method | Purpose | Creates Dialog? |
|---|---|---|
| INVITE | Initiate session/call (carries SDP offer) | Yes |
| ACK | Confirm receipt of INVITE final response | No |
| BYE | Terminate established session | No (ends dialog) |
| CANCEL | Cancel pending INVITE before answer | No |
| REGISTER | Register contact with server | No |
| OPTIONS | Query capabilities (ping/keepalive) | No |
Extension Methods
| Method | RFC | Purpose |
|---|---|---|
| PRACK | 3262 | Acknowledge reliable provisional responses |
| SUBSCRIBE | 3265 | Subscribe to event notifications |
| NOTIFY | 3265 | Send event notification |
| PUBLISH | 3903 | Publish event state (presence) |
| INFO | 2976 | Mid-session info (DTMF) |
| REFER | 3515 | Request call transfer |
| MESSAGE | 3428 | Instant message |
| UPDATE | 3311 | Modify session in early dialog |
SIP Response Codes
| Class | Meaning | Common Codes |
|---|---|---|
| 1xx | Provisional | 100 Trying, 180 Ringing, 183 Session Progress |
| 2xx | Success | 200 OK, 202 Accepted |
| 3xx | Redirection | 301 Moved Permanently, 302 Moved Temporarily |
| 4xx | Client Error | 400 Bad Request, 401 Unauthorized, 404 Not Found, 486 Busy, 487 Request Terminated |
| 5xx | Server Error | 500 Internal Error, 503 Service Unavailable |
| 6xx | Global Failure | 603 Decline, 604 Does Not Exist Anywhere |
Only final responses (2xx-6xx) terminate a transaction. Provisional (1xx) are informative only.
SIP Headers
| Header | Purpose | Example |
|---|---|---|
| Via | Route responses back; branch ID for matching | Via: SIP/2.0/UDP host;branch=z9hG4bK...
|
| From | Caller identity + tag | From: "Alice" <sip:alice@atlanta.com>;tag=1234
|
| To | Callee identity + tag (added in response) | To: "Bob" <sip:bob@biloxi.com>;tag=5678
|
| Call-ID | Unique call identifier | Call-ID: a84b4c76e66710@host
|
| CSeq | Request sequence number + method | CSeq: 314159 INVITE
|
| Contact | Direct reachable address | Contact: <sip:alice@192.0.2.4:5060>
|
| Max-Forwards | Hop limit (default 70) | Max-Forwards: 70
|
| Content-Type | Body MIME type | Content-Type: application/sdp
|
| Record-Route | Proxy stays in signaling path | Record-Route: <sip:proxy;lr>
|
| Authorization | Authentication credentials | Authorization: Digest username="alice"...
|
Dialog Identification
A SIP dialog is uniquely identified by: Call-ID + From-tag + To-tag
Example: INVITE with SDP
INVITE sip:bob@biloxi.com SIP/2.0 Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@biloxi.com> From: Alice <sip:alice@atlanta.com>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.atlanta.com CSeq: 314159 INVITE Contact: <sip:alice@pc33.atlanta.com> Content-Type: application/sdp Content-Length: 142 v=0 o=alice 2890844526 2890844526 IN IP4 pc33.atlanta.com s=Session SDP c=IN IP4 pc33.atlanta.com t=0 0 m=audio 49172 RTP/AVP 0 a=rtpmap:0 PCMU/8000
SDP Quick Reference
| Line | Meaning |
|---|---|
v=0 |
SDP version (always 0) |
o= |
Origin: username, session-id, version, address |
c= |
Connection: where to send media (IP) |
m=audio 49172 RTP/AVP 0 |
Media: type, port, protocol, payload types |
a=rtpmap:0 PCMU/8000 |
Attribute: payload 0 = G.711 μ-law |
a=sendrecv |
Direction: bidirectional |
SIP Call Flow Example
| Step | Message | Purpose |
|---|---|---|
| 1 | INVITE | Initiate call (with SDP offer) |
| 2 | 100 Trying | Stop retransmissions (proxy-generated) |
| 3 | 180 Ringing | Callee alerting |
| 4 | 200 OK | Call answered (with SDP answer) |
| 5 | ACK | Confirm 200 OK receipt |
| 6 | RTP | Media session |
| 7 | BYE | End call |
| 8 | 200 OK | Confirm termination |
Canceling a Call
CANCEL uses same Call-ID and CSeq number as the INVITE. Only effective before final response - ignored if 200 OK already sent.
Transactions, Dialogs, and Sessions
| Concept | Scope | Lifetime | Identified By |
|---|---|---|---|
| Transaction | Single request/response | Seconds | Branch ID, CSeq, Method |
| Dialog | UA-to-UA relationship | Minutes-hours | Call-ID + From-tag + To-tag |
| Session | Media exchange | Duration of call | SDP negotiation |
ACK Behavior
| For 2xx Response | For non-2xx Response | |
|---|---|---|
| Part of INVITE transaction? | No (separate) | Yes (same) |
| UAS behavior if no ACK | Retransmits 200 OK | Retransmits error response |
| Routing | End-to-end via Route set | Hop-by-hop |
Registration
| Action | Expires Value | Result |
|---|---|---|
| Initial registration | e.g., 3600 | Binding created |
| Refresh registration | e.g., 3600 | Binding updated |
| Unregister | 0 | Binding removed |
Registration must be refreshed before expiration. Multiple devices can register same AOR - proxies fork INVITEs to all.
SIP Extensions
Reliability of Provisional Responses (RFC 3262)
Basic SIP sends 1xx responses unreliably. RFC 3262 adds PRACK method to acknowledge provisional responses. UAS includes Require: 100rel and RSeq header; UAC responds with PRACK.
Session Timer (RFC 4028)
Keep-alive mechanism for dialogs. Refresher sends periodic re-INVITE/UPDATE. If refresh fails, call terminates. Prevents zombie calls when one side crashes. Uses Session-Expires and Min-SE headers.
REFER Method (RFC 3515)
Used for call transfer. Alice sends Bob REFER with Refer-To: carol@domain. Bob initiates new INVITE to Carol. Transfer result reported via NOTIFY.
NAT Traversal
| Extension | RFC | Purpose |
|---|---|---|
| rport | 3581 | Symmetric response routing (send to source IP:port, not Via address) |
| outbound | 5626 | Persistent flows, keep-alives for NAT bindings |
Quick Reference: Extensions
| Extension | RFC | Key Headers/Methods |
|---|---|---|
| 100rel | 3262 | PRACK, RSeq, RAck |
| timer | 4028 | Session-Expires, Min-SE |
| replaces | 3891 | Replaces header |
| outbound | 5626 | Instance-ID, reg-id |
| gruu | 5627 | Contact with gr parameter |
Monitoring and Troubleshooting
What to Monitor
| Layer | What to Track | Why |
|---|---|---|
| Signaling | INVITE/BYE timing, response codes, retransmissions | Identifies call setup failures, routing issues |
| Media (RTP) | Packet loss, jitter, latency, MOS | Actual voice quality |
| Registration | REGISTER success/failure | Endpoint reachability |
Common SIP Issues
| Issue | Symptoms | Cause |
|---|---|---|
| One-way audio | Caller hears, callee doesn't (or vice versa) | NAT: SDP contains private IP |
| Call setup delays | Long wait before ringing | DNS problems, proxy timeouts |
| No ringback tone | Silence while waiting for answer | 180→183 conversion without RTP |
| Auth loops | Repeated 401/407 responses | Credential mismatch, realm error |
| Codec failure | 488 Not Acceptable | No common codecs |
Ringback Tone Issue (180 vs 183)
| Response | Behavior | Audio Source |
|---|---|---|
| 180 Ringing | Callee alerting | Caller generates local ringback |
| 183 Session Progress | Early media | Network sends RTP audio |
Problem: Device converts 180→183 but doesn't send RTP. Caller expects network audio but receives silence.
Diagnosis:
- Check SIP History for 183 sent to caller
- Check RTP tab for packets after 183
- If RTP present but no ringback: caller device issue
- If no RTP: intermediate device issue - fix SBC/PBX config
Quality Metrics
| Metric | Good | Acceptable | Poor |
|---|---|---|---|
| MOS | > 4.0 | 3.5 - 4.0 | < 3.5 |
| Packet Loss | < 1% | 1% - 3% | > 3% |
| Jitter | < 20ms | 20-50ms | > 50ms |
| Latency | < 150ms | 150-300ms | > 300ms |
Key RFCs
| RFC | Title | Category |
|---|---|---|
| 3261 | SIP: Session Initiation Protocol | Core |
| 3262 | Reliability of Provisional Responses (PRACK) | Reliability |
| 3263 | Locating SIP Servers | DNS/Routing |
| 3264 | An Offer/Answer Model with SDP | Media |
| 3265 | SIP-Specific Event Notification | Events |
| 3515 | The REFER Method | Transfer |
| 3581 | Symmetric Response Routing (rport) | NAT |
| 4028 | Session Timers in SIP | Keep-alive |
| 5626 | Client-Initiated Connections (Outbound) | NAT |
See Also
AI Summary for RAG
Summary: Session Initiation Protocol (SIP) is an application-layer signaling protocol for establishing, modifying, and terminating multimedia sessions. Architecture includes User Agents (UAC/UAS), Proxy Servers (stateful/stateless routing), Registrars (store user locations), and B2BUAs (full call control). Core methods: INVITE (initiate), ACK (confirm), BYE (terminate), CANCEL (abort), REGISTER (location binding), OPTIONS (capabilities). Response classes: 1xx provisional, 2xx success, 3xx redirect, 4xx client error, 5xx server error, 6xx global failure. Key headers: Via (routing), From/To (identities with tags), Call-ID (unique identifier), CSeq (sequence), Contact (direct address), Record-Route (keep proxy in path). Dialog identified by Call-ID + From-tag + To-tag. Extensions include PRACK (reliable provisionals), session timers (keep-alive), REFER (transfer), rport/outbound (NAT traversal).
Keywords: SIP protocol, INVITE, ACK, BYE, CANCEL, REGISTER, OPTIONS, 180 Ringing, 183 Session Progress, early media, ringback tone, PRACK, dialog, session, transaction, SDP, Call-ID, CSeq, Via, From, To, Contact, Record-Route, rport, outbound, NAT traversal, session timer, REFER, transfer, proxy, registrar, B2BUA, response codes, 200 OK, 401 Unauthorized, 486 Busy, 487 Request Terminated
Key Questions:
- How does SIP establish a call between two endpoints?
- What is the difference between 180 Ringing and 183 Session Progress?
- Why does a caller hear silence instead of ringback tone?
- How do SIP headers like Via, Contact, and Record-Route work?
- What is a SIP dialog and how is it identified?
- What is the difference between transactions, dialogs, and sessions?
- How does SIP registration work?
- What are common SIP troubleshooting issues (one-way audio, auth failures)?
- What SIP extensions exist for NAT traversal?