Understanding the SIP Protocol: Difference between revisions
No edit summary |
(Rewrite: condensed verbose sections, preserved all tables/diagrams, reduced from 1157 to 663 lines) |
||
| (8 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{| class="wikitable" style="width:100%; background:#f8f9fa; border:2px solid #00A7E3; margin-bottom:20px;" | |||
|- | |||
! colspan="3" style="background:#00A7E3; color:white; font-size:1.2em; padding:10px;" | Quick Navigation | |||
|- | |||
! style="width:33%; background:#e0f4fc; padding:8px; vertical-align:top;" | Architecture & Basics | |||
! style="width:33%; background:#fef3e2; padding:8px; vertical-align:top;" | Messages & Call Flow | |||
! style="width:33%; background:#f1f5f9; padding:8px; vertical-align:top;" | Advanced Topics | |||
|- | |||
| style="vertical-align:top; padding:10px;" | | |||
'''Core Components''' | |||
* [[#User Agent (UA)|User Agent (UAC/UAS)]] | |||
* [[#Proxy Server|Proxy Server]] | |||
* [[#Registrar|Registrar]] | |||
* [[#Back-to-Back User Agent (B2BUA)|B2BUA]] | |||
'''Addressing & Transport''' | |||
* [[#Addressing|SIP URIs]] | |||
* [[#Transport|UDP/TCP/TLS/WebSocket]] | |||
| style="vertical-align:top; padding:10px;" | | |||
'''SIP Methods''' | |||
* [[#Core SIP Methods|INVITE, ACK, BYE, CANCEL]] | |||
* [[#Extension Methods|PRACK, REFER, SUBSCRIBE]] | |||
'''Response Codes''' | |||
* [[#SIP Response Codes|1xx-6xx Classes]] | |||
'''Call Flows''' | |||
* [[#SIP Call Flow Example|Basic Call Setup]] | |||
* [[#Canceling a Call|CANCEL Flow]] | |||
| style="vertical-align:top; padding:10px;" | | |||
'''Core Concepts''' | |||
* [[#Transaction|Transactions]] | |||
* [[#Dialog|Dialogs]] | |||
* [[#Session|Sessions]] | |||
'''Registration''' | |||
* [[#Registration and Location Service|REGISTER Flow]] | |||
'''Extensions''' | |||
* [[#Reliability of Provisional Responses (RFC 3262)|PRACK (100rel)]] | |||
* [[#Session Timer (RFC 4028)|Session Timers]] | |||
* [[#REFER Method (RFC 3515)|Call Transfer]] | |||
'''Reference''' | |||
* [[#Key RFCs|RFC Links]] | |||
|} | |||
SIP is | '''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: [https://datatracker.ietf.org/doc/html/rfc3261 RFC 3261] (2002). Extended by numerous RFCs for reliability, events, IM, security, etc. | |||
== SIP Architecture == | |||
<kroki lang="plantuml"> | |||
@startuml | |||
title SIP Architecture Components | |||
skinparam backgroundColor #ffffff | |||
skinparam defaultFontColor #1e293b | |||
skinparam ArrowColor #64748b | |||
skinparam componentStyle rectangle | |||
skinparam component { | |||
BackgroundColor #e0f4fc | |||
BorderColor #00A7E3 | |||
} | |||
skinparam database { | |||
BackgroundColor #fef3e2 | |||
BorderColor #f78d1d | |||
} | |||
cloud "Internet / IP Network" as internet | |||
component "User Agent\n(UAC/UAS)" as ua1 | |||
component "User Agent\n(UAC/UAS)" as ua2 | |||
component "Proxy Server" as proxy | |||
component "Registrar" as registrar | |||
database "Location\nService" as location | |||
ua1 --> proxy : SIP Requests | |||
proxy --> ua2 : SIP Requests | |||
proxy <-- ua2 : SIP Responses | |||
ua1 <-- proxy : SIP Responses | |||
ua1 --> registrar : REGISTER | |||
registrar --> location : Store binding | |||
proxy --> location : Query user location | |||
@enduml | |||
</kroki> | |||
=== | === 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 <code>sip:alice@atlanta.com</code> 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 === | ||
{| class="wikitable" | |||
|- | |||
! URI Scheme !! Description !! Example | |||
|- | |||
| <code>sip:</code> || Standard SIP URI || <code>sip:alice@atlanta.com</code> | |||
|- | |||
| <code>sips:</code> || Secure SIP (TLS required) || <code>sips:alice@atlanta.com</code> | |||
|- | |||
| <code>tel:</code> || Telephone number ([https://datatracker.ietf.org/doc/html/rfc3966 RFC 3966]) || <code>tel:+1-555-123-4567</code> | |||
|} | |||
SIP uses DNS SRV/NAPTR records ([https://datatracker.ietf.org/doc/html/rfc3263 RFC 3263]) to locate servers for a domain. | |||
== | === Transport === | ||
{| class="wikitable" | |||
|- | |||
! 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 ([https://datatracker.ietf.org/doc/html/rfc7118 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 === | === Core SIP Methods === | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Method !! | ! Method !! Purpose !! Creates Dialog? | ||
|- | |- | ||
| '''INVITE''' || | | '''INVITE''' || Initiate session/call (carries SDP offer) || Yes | ||
|- | |- | ||
| '''ACK''' || | | '''ACK''' || Confirm receipt of INVITE final response || No | ||
|- | |- | ||
| '''BYE''' || | | '''BYE''' || Terminate established session || No (ends dialog) | ||
|- | |- | ||
| '''CANCEL''' || | | '''CANCEL''' || Cancel pending INVITE before answer || No | ||
|- | |- | ||
| '''REGISTER''' || | | '''REGISTER''' || Register contact with server || No | ||
|- | |- | ||
| '''OPTIONS''' || | | '''OPTIONS''' || Query capabilities (ping/keepalive) || No | ||
|} | |} | ||
=== Extension Methods === | === Extension Methods === | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Method !! RFC !! | ! Method !! RFC !! Purpose | ||
|- | |- | ||
| '''PRACK''' || | | '''PRACK''' || [https://datatracker.ietf.org/doc/html/rfc3262 3262] || Acknowledge reliable provisional responses | ||
|- | |- | ||
| '''SUBSCRIBE''' || | | '''SUBSCRIBE''' || [https://datatracker.ietf.org/doc/html/rfc3265 3265] || Subscribe to event notifications | ||
|- | |- | ||
| '''NOTIFY''' || | | '''NOTIFY''' || [https://datatracker.ietf.org/doc/html/rfc3265 3265] || Send event notification | ||
|- | |- | ||
| '''PUBLISH''' || | | '''PUBLISH''' || [https://datatracker.ietf.org/doc/html/rfc3903 3903] || Publish event state (presence) | ||
|- | |- | ||
| '''INFO''' || | | '''INFO''' || [https://datatracker.ietf.org/doc/html/rfc2976 2976] || Mid-session info (DTMF) | ||
|- | |- | ||
| '''REFER''' || | | '''REFER''' || [https://datatracker.ietf.org/doc/html/rfc3515 3515] || Request call transfer | ||
|- | |- | ||
| '''MESSAGE''' || | | '''MESSAGE''' || [https://datatracker.ietf.org/doc/html/rfc3428 3428] || Instant message | ||
|- | |- | ||
| '''UPDATE''' || | | '''UPDATE''' || [https://datatracker.ietf.org/doc/html/rfc3311 3311] || Modify session in early dialog | ||
|} | |} | ||
=== SIP Response Codes === | === SIP Response Codes === | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Class !! | ! Class !! Meaning !! Common Codes | ||
|- | |- | ||
| '''1xx''' | | '''1xx''' || Provisional || 100 Trying, 180 Ringing, 183 Session Progress | ||
|- | |- | ||
| '''2xx''' || Success | | '''2xx''' || Success || 200 OK, 202 Accepted | ||
|- | |- | ||
| '''3xx''' || Redirection | | '''3xx''' || Redirection || 301 Moved Permanently, 302 Moved Temporarily | ||
|- | |- | ||
| '''4xx''' || Client Error | | '''4xx''' || Client Error || 400 Bad Request, 401 Unauthorized, 404 Not Found, 486 Busy, 487 Request Terminated | ||
|- | |- | ||
| '''5xx''' || Server Error | | '''5xx''' || Server Error || 500 Internal Error, 503 Service Unavailable | ||
|- | |- | ||
| '''6xx''' || Global | | '''6xx''' || Global Failure || 603 Decline, 604 Does Not Exist Anywhere | ||
|} | |} | ||
Only final responses (2xx-6xx) terminate a | Only final responses (2xx-6xx) terminate a transaction. Provisional (1xx) are informative only. | ||
== SIP | == SIP Headers == | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Header !! | ! Header !! Purpose !! Example | ||
|- | |- | ||
| '''Via''' || | | '''Via''' || Route responses back; branch ID for matching || <code>Via: SIP/2.0/UDP host;branch=z9hG4bK...</code> | ||
|- | |- | ||
| '''From''' || | | '''From''' || Caller identity + tag || <code>From: "Alice" <sip:alice@atlanta.com>;tag=1234</code> | ||
|- | |- | ||
| '''To''' || | | '''To''' || Callee identity + tag (added in response) || <code>To: "Bob" <sip:bob@biloxi.com>;tag=5678</code> | ||
|- | |- | ||
| '''Call-ID''' || | | '''Call-ID''' || Unique call identifier || <code>Call-ID: a84b4c76e66710@host</code> | ||
|- | |- | ||
| '''CSeq''' || | | '''CSeq''' || Request sequence number + method || <code>CSeq: 314159 INVITE</code> | ||
|- | |- | ||
| '''Contact''' || Direct | | '''Contact''' || Direct reachable address || <code>Contact: <sip:alice@192.0.2.4:5060></code> | ||
|- | |- | ||
| '''Max-Forwards''' || Hop | | '''Max-Forwards''' || Hop limit (default 70) || <code>Max-Forwards: 70</code> | ||
|- | |- | ||
| '''Content-Type''' || MIME type | | '''Content-Type''' || Body MIME type || <code>Content-Type: application/sdp</code> | ||
|- | |- | ||
| ''' | | '''Record-Route''' || Proxy stays in signaling path || <code>Record-Route: <sip:proxy;lr></code> | ||
|- | |||
| '''Authorization''' || Authentication credentials || <code>Authorization: Digest username="alice"...</code> | |||
|} | |} | ||
=== | === Dialog Identification === | ||
A SIP dialog is uniquely identified by: '''Call-ID''' + '''From-tag''' + '''To-tag''' | |||
=== | === Example: INVITE with SDP === | ||
<pre> | |||
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 | |||
</pre> | |||
=== SDP Quick Reference === | |||
{| class="wikitable" | |||
|- | |||
! Line !! Meaning | |||
|- | |||
| <code>v=0</code> || SDP version (always 0) | |||
|- | |||
| <code>o=</code> || Origin: username, session-id, version, address | |||
|- | |||
| <code>c=</code> || Connection: where to send media (IP) | |||
|- | |||
| <code>m=audio 49172 RTP/AVP 0</code> || Media: type, port, protocol, payload types | |||
|- | |||
| <code>a=rtpmap:0 PCMU/8000</code> || Attribute: payload 0 = G.711 μ-law | |||
|- | |||
| <code>a=sendrecv</code> || Direction: bidirectional | |||
|} | |||
== SIP Call Flow Example == | == SIP Call Flow Example == | ||
<kroki lang="plantuml"> | <kroki lang="plantuml"> | ||
@startuml | @startuml | ||
title Basic SIP Call Flow (Trapezoid) | title Basic SIP Call Flow (Trapezoid) | ||
skinparam backgroundColor #ffffff | |||
skinparam backgroundColor # | |||
skinparam defaultFontColor #1e293b | skinparam defaultFontColor #1e293b | ||
skinparam ArrowColor #64748b | skinparam ArrowColor #64748b | ||
skinparam sequenceArrowThickness 2 | skinparam sequenceArrowThickness 2 | ||
skinparam ParticipantPadding 20 | skinparam ParticipantPadding 20 | ||
| Line 200: | Line 300: | ||
} | } | ||
participant "Alice | participant "Alice" as Alice | ||
participant "atlanta.com\nproxy" as Atlanta | participant "atlanta.com\nproxy" as Atlanta | ||
participant "biloxi.com\nproxy" as Biloxi | participant "biloxi.com\nproxy" as Biloxi | ||
participant "Bob | participant "Bob" as Bob | ||
Alice -> Atlanta : INVITE sip:bob@biloxi.com | Alice -> Atlanta : INVITE sip:bob@biloxi.com | ||
| Line 214: | Line 314: | ||
Alice <-- Atlanta : 180 Ringing | Alice <-- Atlanta : 180 Ringing | ||
Biloxi <-- Bob : 200 OK (SDP answer) | Biloxi <-- Bob : 200 OK (SDP answer) | ||
Atlanta <-- Biloxi : 200 OK | Atlanta <-- Biloxi : 200 OK | ||
Alice <-- Atlanta : 200 OK | Alice <-- Atlanta : 200 OK | ||
Alice -> Bob : ACK | Alice -> Bob : ACK | ||
Alice <-> Bob : RTP media session | Alice <-> Bob : RTP media session | ||
Bob -> Alice : BYE | Bob -> Alice : BYE | ||
Alice --> Bob : 200 OK | Alice --> Bob : 200 OK | ||
@enduml | @enduml | ||
</kroki> | </kroki> | ||
= | {| class="wikitable" | ||
|- | |||
! 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 === | |||
# | <kroki lang="plantuml"> | ||
@startuml | |||
title SIP CANCEL Flow | |||
skinparam backgroundColor #ffffff | |||
skinparam defaultFontColor #1e293b | |||
skinparam ArrowColor #64748b | |||
skinparam sequenceArrowThickness 2 | |||
# | skinparam participant { | ||
BackgroundColor #e0f4fc | |||
BorderColor #00A7E3 | |||
} | |||
participant "Alice" as Alice | |||
participant "Proxy" as Proxy | |||
participant "Bob" as Bob | |||
Alice -> Proxy : INVITE | |||
Proxy -> Bob : INVITE | |||
Alice <-- Proxy : 100 Trying | |||
Proxy <-- Bob : 180 Ringing | |||
Alice <-- Proxy : 180 Ringing | |||
note over Alice: Decides to cancel | |||
Alice -> Proxy : CANCEL | |||
Proxy -> Bob : CANCEL | |||
Alice <-- Proxy : 200 OK (for CANCEL) | |||
Proxy <-- Bob : 200 OK (for CANCEL) | |||
Proxy <-- Bob : 487 Request Terminated | |||
Alice <-- Proxy : 487 Request Terminated | |||
Alice -> Proxy : ACK (for 487) | |||
Proxy -> Bob : ACK (for 487) | |||
@enduml | |||
</kroki> | |||
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 == | |||
# | <kroki lang="plantuml"> | ||
@startuml | |||
title SIP Call: Transactions within a Dialog | |||
skinparam backgroundColor #ffffff | |||
skinparam defaultFontColor #1e293b | |||
skinparam ArrowColor #64748b | |||
skinparam participant { | |||
BackgroundColor #e0f4fc | |||
BorderColor #00A7E3 | |||
} | |||
participant "Alice" as A | |||
participant "Bob" as B | |||
== | == Dialog Established == | ||
box "INVITE Transaction" #e0f4fc | |||
A -> B : INVITE (CSeq: 1) | |||
A <-- B : 100 Trying | |||
A <-- B : 180 Ringing | |||
A <-- B : 200 OK | |||
end box | |||
A | box "ACK Transaction" #fef3e2 | ||
A -> B : ACK | |||
end box | |||
||| | |||
note over A, B #f1f5f9: '''SESSION ACTIVE'''\n(RTP Media Flowing) | |||
||| | |||
box "BYE Transaction" #e0f4fc | |||
B -> A : BYE (CSeq: 1) | |||
B <-- A : 200 OK | |||
end box | |||
== Dialog Terminated == | |||
@enduml | |||
</kroki> | |||
{| class="wikitable" | |||
|- | |||
! 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 === | ||
{| class="wikitable" | |||
|- | |||
! !! 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 == | |||
<kroki lang="plantuml"> | |||
@startuml | |||
title SIP Registration with Authentication | |||
skinparam backgroundColor #ffffff | |||
skinparam defaultFontColor #1e293b | |||
skinparam ArrowColor #64748b | |||
skinparam sequenceArrowThickness 2 | |||
skinparam participant { | |||
BackgroundColor #e0f4fc | |||
BorderColor #00A7E3 | |||
} | |||
skinparam database { | |||
BackgroundColor #fef3e2 | |||
BorderColor #f78d1d | |||
} | |||
participant "Alice's UA" as Alice | |||
participant "Registrar" as Registrar | |||
database "Location\nService" as Location | |||
Alice -> Registrar : REGISTER sip:atlanta.com | |||
note right: To: sip:alice@atlanta.com\nContact: <sip:alice@192.0.2.4> | |||
Registrar --> Alice : 401 Unauthorized | |||
note right: WWW-Authenticate: Digest... | |||
Alice -> Registrar : REGISTER (with Authorization) | |||
Registrar -> Location : Store binding | |||
Registrar --> Alice : 200 OK | |||
note right: Expires: 3600 | |||
@enduml | |||
</kroki> | |||
{| class="wikitable" | |||
|- | |||
! 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. [https://datatracker.ietf.org/doc/html/rfc3262 RFC 3262] adds '''PRACK''' method to acknowledge provisional responses. UAS includes <code>Require: 100rel</code> 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 <code>Session-Expires</code> and <code>Min-SE</code> headers. | |||
=== REFER Method (RFC 3515) === | === REFER Method (RFC 3515) === | ||
Used for call transfer | Used for call transfer. Alice sends Bob <code>REFER</code> with <code>Refer-To: carol@domain</code>. Bob initiates new INVITE to Carol. Transfer result reported via NOTIFY. | ||
=== NAT Traversal === | === NAT Traversal === | ||
= | {| class="wikitable" | ||
|- | |||
! Extension !! RFC !! Purpose | |||
|- | |||
| '''rport''' || [https://datatracker.ietf.org/doc/html/rfc3581 3581] || Symmetric response routing (send to source IP:port, not Via address) | |||
|- | |||
| '''outbound''' || [https://datatracker.ietf.org/doc/html/rfc5626 5626] || Persistent flows, keep-alives for NAT bindings | |||
|} | |||
=== Quick Reference: Extensions === | |||
{| class="wikitable" | |||
|- | |||
! 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 === | |||
{| class="wikitable" | |||
|- | |||
! 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 === | |||
= | {| class="wikitable" | ||
|- | |||
! 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) === | ||
{| class="wikitable" | |||
|- | |||
! 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 === | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! | ! 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 == | |||
{| class="wikitable" | |||
|- | |- | ||
! RFC !! Title !! Category | |||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc3261 3261] || SIP: Session Initiation Protocol || Core | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc3262 3262] || Reliability of Provisional Responses (PRACK) || Reliability | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc3263 3263] || Locating SIP Servers || DNS/Routing | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc3264 3264] || An Offer/Answer Model with SDP || Media | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc3265 3265] || SIP-Specific Event Notification || Events | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc3515 3515] || The REFER Method || Transfer | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc3581 3581] || Symmetric Response Routing (rport) || NAT | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc4028 4028] || Session Timers in SIP || Keep-alive | ||
|- | |- | ||
| | | [https://datatracker.ietf.org/doc/html/rfc5626 5626] || Client-Initiated Connections (Outbound) || NAT | ||
|} | |} | ||
== See Also == | == See Also == | ||
* [[VoIP]] | * [[Comprehensive_Guide_to_VoIP_Voice_Quality|VoIP Voice Quality Guide]] | ||
* [[ | * [[Call_Detail_Record_-_CDR|CDR Detail View]] | ||
* [[ | * [[Register|SIP Register Monitoring]] | ||
* [[ | * [[Tls|TLS/SRTP Decryption]] | ||
== 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? | |||
[[Category:VoIP]] | [[Category:VoIP]] | ||
[[Category:Protocols]] | [[Category:Protocols]] | ||
[[Category:SIP]] | [[Category:SIP]] | ||
Latest revision as of 16:49, 8 January 2026
| 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?