530 likes | 972 Views
網路電話 Session Initiation Protocol (SIP). Speaker: 王嘉裕 Date:2008/09/11. SIP - Session Initiation Protocol. 前身 - MMUSIC (Multiparty Multimedia Session Control), Sep. 1999 由 IETF 的 SIP Working Group 發展 開始於 1995 Proposed standard RFC2543, February 1999
E N D
網路電話Session Initiation Protocol (SIP) Speaker:王嘉裕 Date:2008/09/11
SIP - Session Initiation Protocol • 前身 - MMUSIC (Multiparty Multimedia Session Control), Sep. 1999 • 由IETF的SIP Working Group 發展 • 開始於 1995 • Proposed standard RFC2543, February 1999 • New Version of SIP - RFC 3261, June 2002
SIP • A Signaling Protocol • Create, Modify, Terminate Multimedia Sessions • 使用 IP • Client / Server 架構 • 相似於 HTTP, SMTP • Uniform Resource Locator (URL) sip:bob@hit.edu.tw sip:+886424961356@hit.edu.tw 也可以是 tel:+886424961356 • Request and Response • 回應訊息
SIP藉由現成的 IETF 協定來提供 • SIP的訊息格式 (HTTP 1.1) • RFC 2616 • 描述媒體的連線 • (SDP) RFC 2327 • 媒體(RTP) • RFC 3550 and (RTSP) RFC 2326 • 定址方式 (URL) • RFC 1738 and (URI) RFC 2396 • 名稱解析和位置的移動性 • (DHCP) RFC 2131 and (DNS) RFCs 1034&1035 • 資料編碼方式 (MIME) • RFC 2045 • 安全 (TLS) • RFC 2246 • IPsec • RFC 2401&2406
Version IHL DSCP ECN Total Length Identification Flags Fragment Offset Time to Live Protocol Header Checksum Source Address Destination Address Options Padding Source Port Destination Port Length Checksum SIP表頭 以US-ASCII文字為基礎, 變動長度 SIP訊息主體 也是變動長度, 視Message-Type的需要而存在 可以是任何形式的資料 SIP的封包格式 IPv4 的表頭 UDP 8 個 Bytes的表頭 (這裡也可以是TCP或者 SCTP)
Protocol Zoo Source: Henning Schulzrinne, http://www.cs.columbia.edu/~hgs/internet/
Location Server Redirect Server Registrar Server Gateway PSTN PLMN User Agent Proxy Server Proxy Server Gateway SIP組成元件
SIP User Agents • User Agent (UA) • 用戶端 User Agent Client (UAC) • 送出 SIP 請求 • 伺服器端 User Agent Server (UAS) • 回應 SIP 請求 接受或拒絶 • User Agent = UAC + UAS UA 1 UA 3 UA 4 UA 2 LAN A LAN B
SIP訊息流程 Redirect Server Location Server Request Response Proxy Server Proxy Server Media Session User Agent User Agent
SIP Request methods • RFC 3261 • REGISTER • INVITE • ACK • BYE • OPTIONS • CANCEL • 其它的RFC…
SIP Request methods • INFO (RFC 2976) • PRACK (RFC 3262) • SUBSCRIBE and NOTIFY (RFC 3265) • UPDATE (RFC 3311) • MESSAGE (RFC 3428) • REFER (RFC 3515) • PUBLISH (RFC 3903)
說明 範例 100 Trying Informational – 代表請求已收到 180 Ringing 1xx 181 Call is Being Forwarded 183 Session Progressing Success – 代表請求已被成功處理 200 OK 2xx 202 Acce ptable 300 Multiple Choices Redirection – 代表重新導向 3xx 301 Moved Permanently 302 Moved Temporarily 401 Unautho rized 406 Not Acceptable Client Error – 代表用互端錯誤 407 Proxy Auth entication Required 4xx 486 Busy Here 487 Request Terminated 4 88 Not Acceptable Here Server Error – 代表伺服器端錯誤 502 Bad Gateway 5xx 503 Service Unavailable 600 Busy Everywhere 6xx Global Failure – 代表整體網路環境錯誤 603 Decline SIP Response
UAC Server UAS INVITE 100 Trying INVITE 100 Trying 180 Ringing Call Setup 180 Ringing 200 OK 200 OK ACK ACK Media Session BYE 100 Trying Call Teardown BYE 200 OK 200 OK SIP • 連線過程 • 建立連線 • 通話 • 斷線
SIP訊息 – 範例 • INVITE sip:bob@zzz.edu SIP/2.0 • Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds • Max-Forwards: 70 • To: Bob <sip:bob@zzz.edu> • From: Alice <sip:alice@yyy.edu>;tag=1928301774 • Call-ID: a84b4c76e66710@pc33.yyy.edu • CSeq: 314159 INVITE • Contact: <sip:alice@pc33.yyy.edu> • Content-Type: application/sdp • Content-Length: 142 SIP • v=0 • o=Alice 2897654321 2897654321 IN IP4 10.0.0.1 • s=Phone Call • c=IN IP4 192.168.0.1 • t=0 0 • m=audio 49170 RTP/AVP 0 • a=rtpmap:0 PCMU/8000 SDP
SIP Headers INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142
SIP Headers Request URI Method 即 命令 SIP 協定版本 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142
SIP Headers 所有經過的SIP設備都會被列在這裡 ‘branch’用來識別不同的連線分支 在所有 SIP Requests中都是必要的欄位 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142
SIP Headers 最多可以被幾個Server轉傳 在所有 SIP Requests之中除了INFO都是必要的欄位 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142
SIP Headers 目的地位址 在所有 SIP Requests中都是必要的欄位 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142
SIP Headers 來源位址 虛擬的隨機亂數 (當作是ID使用) 在所有 SIP Requests中都是必要的欄位 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142
SIP Headers 在所有 SIP Requests中都是必要的欄位 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 在網域內獨一無二的識別碼 James Polk 20050503
SIP Headers 在所有 SIP Requests中都是必要的欄位 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 遞增的序號
SIP Headers James Polk 20050503 INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 直接可以路由到來源位址的完整網域名稱或IP位址
SIP Headers INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 用來描述附加的訊息主體格式 (如果有的話)
SIP Headers INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 用來描述附加的訊息主體的內容長度 (Octets)
SIP Headers INVITE sip:bob@zzz.edu SIP/2.0 Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142
Session Description Protocol (SDP) • 描述多媒體連線的協定 • RFC 2327 • 簡單,可以擴充的,以文字為基礎 • SIP Offer/Answer Model • RFC 3264 • 在每一行 • 欄位=值 值 值 … • 欄位是一個字元 (大小寫有差別) • 等號兩旁不可以有空格 • 分為Session和Media層次
SDP的結構內容 • Session 層次 (從 v=這一行開始) • Session Name • 主動發起的一端 • 活動時間 • Media 層次 (從 m=這一行開始) • 媒體形式 • video, audio, … • Port number • 傳輸層協定 • RTP/UDP/IP, H.320, ... • 媒體格式 • H.261 video, MPEG video, ...
SDP的欄位 • v= (protocol version) 例如: v=0 • o= (owner/creator and session identifier) o=<username> <session id> <version> <network type> <address type> <address> Username 不可以含有空格 Session id 和version 建議使用Network Time Protocol (NTP)的時間戳記來確保值的唯一性 例如: o=john 2887654326 2887654307 INIP4 10.1.2.3 • s= (session name string) 例如: s=SDP Seminar • t= (start time and stop time) 例如: t=2887654321 2887654310(通常設為0) • 為必要欄位
SDP的欄位 • m= (media name and transport address) m=<media> <port> <transport> <format list> m=<media> <port>/<number of ports> <transport> <format list> 例如: m=video 49170/2 RTP/AVP 0 <media> "audio", "video", "application", "data" and "control“ <transport> • RTP/AVP - the IETF's Realtime Transport Protocol using the Audio/Video profile carried over UDP • UDP • RTP/AVP RFC 3551 • e= (email address) 例如: e=john@yyy.edu (John Doe) 或者 e=John Doe <john@yyy.edu> • p= (phone number) 例如: p=+886-4-2496-1356 或者 p=+886 4 2496 1356 u-law PCM, single channel, audio sampled at 8KHz
SDP的欄位 • c= (connection information) c=<network type> <address type> <connection address> 例如: c=IN IP4 224.2.17.12/127 通常這個連線位址是一個 class D的 IP 群播位址, <base multicast address>/<ttl>/<number of addresses> 例如: c=IN IP4 224.2.1.1/127/3 指的是多個c=IN IP4 224.2.1.1/127, c=IN IP4 224.2.1.2/127, c=IN IP4 224.2.1.3/127 如果這一個會議連線不是群播, 則它可以搭配額外的屬性欄位決定是完整網域位址或單一IP位址等等
SDP的欄位 • i= (session information) • u= (URI of description) • b= (bandwidth information) • z= (time zone adjustments) • k= (encryption key) • a= (zero or more session attribute lines) • r= (zero or more repeat times)
SIP Methods: INVITE, ACK and BYE Bob Alice INVITE INVITE sip:bob@192.168.10.20 SIP/2.0 Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bK776asdhds Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 (Alice's SDP not shown)
SIP Methods: INVITE, ACK and BYE Bob Alice INVITE 200 OK SIP/2.0 200 OK Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bKnashds8 ;received=10.1.3.33 To: Bob <sip:bob@zzz.edu>;tag=a6c85cf From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:bob@192.168.10.20> Content-Type: application/sdp Content-Length: 131 (Bob's SDP not shown)
INVITE 200 OK SIP Methods: INVITE, ACK and BYE Bob Alice ACK ACK sip:bob@192.168.10.20 SIP/2.0 Via: SIP/2.0/TCP pc33.yyy.edu;branch=z9hG4bKnashds8 Max-Forwards: 70 To: Bob <sip:bob@zzz.edu>;tag=a6c85cf From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 ACK Content-Length: 0
INVITE 200 OK ACK Session Established SIP Methods: INVITE, ACK and BYE Bob Alice
INVITE 200 OK ACK Session Established SIP Methods: INVITE, ACK and BYE Bob Alice BYE BYE sip:alice@pc33.yyy.edu SIP/2.0 Via: SIP/2.0/TCP 10.1.3.33;branch=z9hG4bKnashds8 Max-Forwards: 70 From: Bob <sip:bob@zzz.edu>;tag=a6c85cf To: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 231 BYE Content-Length: 0
INVITE 200 OK BYE ACK Session Established SIP Methods: INVITE, ACK and BYE Bob Alice 200 OK SIP/2.0 200 OK Via: SIP/2.0/TCP 192.168.10.20 From: Alice <sip:alice@yyy.edu>;tag=1928301774 To: Bob <sip:bob@zzz.edu>;tag=a6c85cf Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 231 BYE Content-Length: 0
INVITE 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice INVITE sip:bob@zzz.edu/TCP SIP/2.0 Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bK776asdhds ;received=10.1.3.33 Max-Forwards: 70 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 (Alice's SDP not shown)
INVITE INVITE Via Header for zzz server Via Header for Alice’s phone Max-Forwards decreases 1 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice INVITE sip:bob@192.168.10.20/TCP SIP/2.0 Via: SIP/2.0/TCP server.zzz.edu ;branch=z9hG4bK4b43c2ff8.1 ;received=192.168.10.1 Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bK776asdhds ;received=10.1.3.33 Max-Forwards: 69 To: Bob <sip:bob@zzz.edu> From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:alice@pc33.yyy.edu> Content-Type: application/sdp Content-Length: 142 (Alice's SDP not shown)
INVITE SIP/2.0 200 OK Via: SIP/2.0/TCP server.zzz.edu ;branch=z9hG4bK4b43c2ff8.1;received=192.168.10.1 Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bKnashds8 ;received=10.1.3.33 To: Bob <sip:bob@zzz.edu>;tag=a6c85cf From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:bob@192.168.10.20> Content-Type: application/sdp Content-Length: 131 (Bob's SDP not shown) INVITE Notice both Via headers 200 OK 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice James Polk 20050503
INVITE SIP/2.0 200 OK Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bKnashds8 ;received=10.1.3.33 To: Bob <sip:bob@zzz.edu>;tag=a6c85cf From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 INVITE Contact: <sip:bob@192.168.10.20> Content-Type: application/sdp Content-Length: 131 (Bob's SDP not shown) INVITE Notice one Via header 200 OK 200 OK 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice
INVITE INVITE ACK sip:bob@192.168.10.20 SIP/2.0 Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bKnashds8 Max-Forwards: 70 To: Bob <sip:bob@zzz.edu>;tag=a6c85cf From: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 314159 ACK Content-Length: 0 200 OK 200 OK ACK 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice
INVITE INVITE 200 OK 200 OK ACK Session Established 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice
BYE INVITE INVITE 200 OK BYE sip:alice@pc33.yyy.edu SIP/2.0 Via: SIP/2.0/TCP 10.1.3.33;branch=z9hG4bKnashds8 Max-Forwards: 70 From: Bob <sip:bob@zzz.edu>;tag=a6c85cf To: Alice <sip:alice@yyy.edu>;tag=1928301774 Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 231 BYE Content-Length: 0 200 OK ACK Session Established 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice
BYE INVITE INVITE 200 OK 200 OK SIP/2.0 200 OK Via: SIP/2.0/TCP 192.168.10.20 From: Alice <sip:alice@yyy.edu>;tag=1928301774 To: Bob <sip:bob@zzz.edu>;tag=a6c85cf Call-ID: a84b4c76e66710@pc33.yyy.edu CSeq: 231 BYE Content-Length: 0 200 OK ACK Session Established 透過Proxy Server SIP Proxy “server.zzz.edu” Bob Alice
REGISTER REGISTER sip:server.yyy.edu SIP/2.0 Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bk2l55n1 To: Alice <sip:alice@yyy.edu> From: Alice <sip:alice@yyy.edu>;tag=283074 Call-ID: a84b4g96te10@pc33.yyy.edu CSeq: 31862 REGISTER Contact: <sip:alice@10.1.3.33> Expires: 21600 Content-Length: 0 SIP Methods: REGISTER SIP Registrar Server Alice REGISTER – 註冊 • SIP URI 稱之為 Address of Record (AOR) • 把一個AOR和現在可以連繫得上的實際位址對應連接在一起 • 讓UA可以收到 SIP的訊息 • UAs可以利用下列方法向伺服器註冊 • 手動設定 • Address-of-Record • Multicast [224.0.1.75]
200 OK REGISTER SIP Methods: REGISTER SIP Registrar Server Alice • 200 (OK) 回應包含一連串的Contact • Expires Header 告知 UA註冊的有效期限 SIP/2.0 200 OK Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bk2l55n1; received=10.1.3.33 To: Alice <sip:alice@yyy.edu>; tag=a6c85e3 From: Alice <sip:alice@yyy.edu>;tag=283074 Call-ID: a84b4g96te10@pc33.yyy.edu CSeq: 31862 REGISTER Contact: <sip:alice@pc33.yyy.edu> Contact: <sip:alice@pda01.yyy.edu> Expires: 3600 Contact-Length: 0 REGISTER 通常是需要經過密碼認證的
INVITE Bob’s Office Phone INVITE INVITE INVITE INVITE Call Forking yyy.edu zzz.edu Alice Bob’s Notebook 同時嚮,看哪一個先接! Bob’s Mobile phone