網路電話 session initiation protocol (sip) speaker: 王嘉裕 date:2008/09/11

53
網網網網 Session Initiation Protoc ol (SIP) Speaker: 王王王 Date:2008/09/11

Post on 20-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

網路電話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:[email protected]:[email protected]也可以是 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

SIP 的封包格式

IHL Total Length

Identification Flags Fragment Offset

Header ChecksumProtocolTime to Live

Source Address

Destination Address

PaddingOptions

Version DSCP ECN

IPv4 的表頭

Source PortSource PortSource PortSource Port Destination PortDestination PortDestination PortDestination Port

ChecksumChecksumChecksumChecksumLengthLengthLengthLength

UDP 8 個 Bytes 的表頭 ( 這裡也可以是 TCP 或者 SCTP)

SIP 表頭以 US-ASCII 文字為基礎 , 變動長度

SIP 訊息主體也是變動長度 ,

視 Message-Type 的需要而存在可以是任何形式的資料

Protocol Zoo

Source: Henning Schulzrinne,http://www.cs.columbia.edu/~hgs/internet/

SIP 組成元件

User Agent

Proxy Server

Gateway

Proxy Server

Location Server

Redirect Server

Registrar Server

PSTNPSTN

PLMNPLMN

Gateway

SIP User Agents

• User Agent (UA)– 用戶端 User Agent Client (UAC)

• 送出 SIP 請求– 伺服器端 User Agent Server (UAS)

• 回應 SIP 請求 接受或拒絶– User Agent = UAC + UAS

UA 1 UA 2

LAN A

UA 3 UA 4

LAN B

SIP 訊息流程

Request

Response

Media SessionUser Agent

Proxy Server

Redirect Server Location Server

User Agent

Proxy Server

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)

SIP Response 說明 範例

1xx Informational – 代表請求已收到

100 Trying 180 Ringing 181 Call is Being Forwarded 183 Session Progressing

2xx Success – 代表請求已被成功處理

200 OK 202 Acceptable

3xx Redirection – 代表重新導向

300 Multiple Choices 301 Moved Permanently 302 Moved Temporarily

4xx Client Error – 代表用互端錯誤

401 Unauthorized 406 Not Acceptable 407 Proxy Authentication Required 486 Busy Here 487 Request Terminated 488 Not Acceptable Here

5xx Server Error –代表伺服器端錯誤

502 Bad Gateway 503 Service Unavailable

6xx Global Failure – 代表整體網路環境錯誤 600 Busy Everywhere 603 Decline

SIP

INVITE

100 Trying INVITE

100 Trying

180 Ringing 180 Ringing

200 OK 200 OK

ACK ACK

BYE

100 TryingBYE

200 OK200 OK

Call Setup

Call Teardown

Media Session

UAC UASServer

• 連線過程– 建立連線– 通話– 斷線

SIP 訊息 – 範例

SIP

SDP

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

v=0o=Alice 2897654321 2897654321 IN IP4 10.0.0.1s=Phone Callc=IN IP4 192.168.0.1t=0 0m=audio 49170 RTP/AVP 0a=rtpmap:0 PCMU/8000

SIP Headers

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

SIP Headers

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

Method 即 命令 Request URI SIP 協定版本

SIP Headers

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

所有經過的 SIP 設備都會被列在這裡 ‘branch’ 用來識別不同的連線分支

在所有 SIP Requests 中都是必要的欄位

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

最多可以被幾個 Server 轉傳

SIP Headers

在所有 SIP Requests 之中除了 INFO 都是必要的欄位

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

    目的地位址

SIP Headers

在所有 SIP Requests 中都是必要的欄位

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

     來源位址           虛擬的隨機亂數 ( 當作是 ID 使用 )

SIP Headers

在所有 SIP Requests 中都是必要的欄位

James P

olk 20050503

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

在網域內獨一無二的識別碼

SIP Headers

在所有 SIP Requests 中都是必要的欄位

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

遞增的序號

SIP Headers

在所有 SIP Requests 中都是必要的欄位

James P

olk 20050503

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

直接可以路由到來源位址的完整網域名稱或 IP 位址

SIP Headers

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

用來描述附加的訊息主體格式 ( 如果有的話 )

SIP Headers

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

用來描述附加的訊息主體的內容長度 (Octets)

SIP Headers

INVITE sip:[email protected] SIP/2.0Via: SIP/2.0/UDP pc33.yyy.edu;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142

SIP Headers

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 的範例

SDP 的欄位

v= (protocol version)例如 : v=0

o= (owner/creator and session identifier)o=<username> <session id> <version> <network type> <address t

ype> <address>Username 不可以含有空格Session id 和 version 建議使用 Network Time Protocol (NTP) 的時

間戳記來確保值的唯一性 例如 : o=john 2887654326 2887654307 IN IP4 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)例如 : [email protected] (John Doe) 或者 e=John Doe <[email protected]>

• 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 BYEAlice Bob

INVITEINVITE sip:[email protected] SIP/2.0Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bK776asdhdsMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142 (Alice's SDP not shown)

SIP Methods: INVITE, ACK and BYE

INVITE

200 OK

Alice Bob

SIP/2.0 200 OKVia: SIP/2.0/TCP pc33.yyy.edu;branch=z9hG4bKnashds8 ;received=10.1.3.33To: Bob <sip:[email protected]>;tag=a6c85cfFrom: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected]: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 131 (Bob's SDP not shown)

SIP Methods: INVITE, ACK and BYE

INVITE

200 OK

Alice Bob

ACKACK sip:[email protected] SIP/2.0Via: SIP/2.0/TCP pc33.yyy.edu;branch=z9hG4bKnashds8Max-Forwards: 70To: Bob <sip:[email protected]>;tag=a6c85cfFrom: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected]: 314159 ACKContent-Length: 0

SIP Methods: INVITE, ACK and BYE

INVITE

200 OK

Session Established

Alice Bob

ACK

SIP Methods: INVITE, ACK and BYE

INVITE

200 OK

Session Established

Alice Bob

ACK

BYEBYE sip:[email protected] SIP/2.0Via: SIP/2.0/TCP 10.1.3.33;branch=z9hG4bKnashds8Max-Forwards: 70From: Bob <sip:[email protected]>;tag=a6c85cfTo: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected]: 231 BYEContent-Length: 0

SIP Methods: INVITE, ACK and BYE

INVITE

200 OK

Session Established

Alice Bob

ACK

BYE

200 OKSIP/2.0 200 OKVia: SIP/2.0/TCP 192.168.10.20From: Alice <sip:[email protected]>;tag=1928301774To: Bob <sip:[email protected]>;tag=a6c85cf Call-ID: [email protected]: 231 BYEContent-Length: 0

Alice BobSIP Proxy “server.zzz.edu”

透過 Proxy Server

INVITE

INVITE sip:[email protected]/TCP SIP/2.0Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bK776asdhds ;received=10.1.3.33Max-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142 (Alice's SDP not shown)

INVITE INVITE

Alice Bob

透過 Proxy Server

SIP Proxy “server.zzz.edu”

INVITE sip:[email protected]/TCP SIP/2.0Via: SIP/2.0/TCP server.zzz.edu ;branch=z9hG4bK4b43c2ff8.1 ;received=192.168.10.1Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bK776asdhds ;received=10.1.3.33Max-Forwards: 69To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 142 (Alice's SDP not shown)

Via Header for Alice’s phone

Via Header for zzz server

Max-Forwardsdecreases 1

James P

olk 20050503

INVITE INVITE

Alice Bob

透過 Proxy Server

SIP Proxy “server.zzz.edu”

200 OK

SIP/2.0 200 OKVia: SIP/2.0/TCP server.zzz.edu ;branch=z9hG4bK4b43c2ff8.1 ;received=192.168.10.1Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bKnashds8 ;received=10.1.3.33To: Bob <sip:[email protected]>;tag=a6c85cfFrom: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected]: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 131 (Bob's SDP not shown)

Notice both Via headers

INVITE INVITE

200 OK

Alice Bob

透過 Proxy Server

SIP Proxy “server.zzz.edu”

200 OK

SIP/2.0 200 OKVia: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bKnashds8 ;received=10.1.3.33To: Bob <sip:[email protected]>;tag=a6c85cfFrom: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected]: 314159 INVITEContact: <sip:[email protected]>Content-Type: application/sdpContent-Length: 131 (Bob's SDP not shown)

Notice one Via header

INVITE INVITE

200 OK200 OK

Alice Bob

透過 Proxy Server

ACK

ACK sip:[email protected] SIP/2.0Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bKnashds8Max-Forwards: 70To: Bob <sip:[email protected]>;tag=a6c85cfFrom: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected]: 314159 ACKContent-Length: 0

SIP Proxy “server.zzz.edu”

INVITE INVITE

200 OK200 OK

Session Established

Alice Bob

透過 Proxy Server

ACK

SIP Proxy “server.zzz.edu”

INVITE INVITE

200 OK200 OK

Session Established

Alice Bob

透過 Proxy Server

ACK

SIP Proxy “server.zzz.edu”

BYE sip:[email protected] SIP/2.0Via: SIP/2.0/TCP 10.1.3.33;branch=z9hG4bKnashds8Max-Forwards: 70From: Bob <sip:[email protected]>;tag=a6c85cfTo: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected]: 231 BYEContent-Length: 0

BYE

INVITE INVITE

200 OK200 OK

Session Established

Alice Bob

透過 Proxy Server

ACK

BYE

SIP Proxy “server.zzz.edu”

200 OK

SIP/2.0 200 OKVia: SIP/2.0/TCP 192.168.10.20From: Alice <sip:[email protected]>;tag=1928301774To: Bob <sip:[email protected]>;tag=a6c85cf Call-ID: [email protected]: 231 BYEContent-Length: 0

Alice

SIP Methods: REGISTER

REGISTER – 註冊 • SIP URI 稱之為 Address

of Record (AOR)• 把一個 AOR 和現在可以連繫

得上的實際位址對應連接在一起

• 讓 UA 可以收到 SIP 的訊息• UAs 可以利用下列方法向伺

服器註冊– 手動設定– Address-of-Record

– Multicast [224.0.1.75]

REGISTER

REGISTER sip:server.yyy.edu SIP/2.0Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bk2l55n1To: Alice <sip:[email protected]>From: Alice <sip:[email protected]>;tag=283074Call-ID: [email protected] CSeq: 31862 REGISTERContact: <sip:[email protected]>Expires: 21600Content-Length: 0

SIP Registrar Server

REGISTER

Alice

SIP Methods: REGISTER

SIP Registrar Server

200 OK

SIP/2.0 200 OKVia: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bk2l55n1; received=10.1.3.33To: Alice <sip:[email protected]>; tag=a6c85e3From: Alice <sip:[email protected]>;tag=283074Call-ID: [email protected] CSeq: 31862 REGISTERContact: <sip:[email protected]>Contact: <sip:[email protected]>Expires: 3600Contact-Length: 0

• 200 (OK) 回應包含一連串的 Contact

• Expires Header 告知 UA註冊的有效期限

REGISTER 通常是需要經過密碼認證的

Call Forking

INVITE

INVITE

Alice

INVITE

INVITE INVITE

yyy.edu zzz.edu

OfficeOfficePhonePhoneOfficeOfficePhonePhone

Bob’sBob’s

NotebookNotebookNotebookNotebookBob’s

Mobile phoneMobile phoneMobile phoneMobile phone

Bob’sBob’s

同時嚮,看哪一個先接!

Alice Bob

SIP Methods: MESSAGE (RFC3428)

• MESSAGE– 以 近乎 即時的方式傳送 – 存在在 MIME 的主體中– 不會啓始新的 dialogs

– 訊息之間沒有任何關聯– 不可以超過 1300 bytes

MESSAGE sip:[email protected] SIP/2.0Via: SIP/2.0/TCP pc33.yyy.edu ;branch=z9hG4bK776asegmaMax-Forwards: 70To: Bob <sip:[email protected]>From: Alice <sip:[email protected]>;tag=1928301774Call-ID: [email protected] CSeq: 22756 MESSAGEContent-Type: text/plainContent-Disposition: renderContent-Length: 37 Isn’t this a great presentation, Bob?

MESSAGE

Alice Bob

SIP Methods: MESSAGE (RFC3428)

MESSAGE

200 OK

SIP/2.0 200 OKVia: SIP/2.0/TCP pc33.yyy.edu;branch=z9hG4bKnashds7; received=10.1.3.33To: sip: sip:[email protected]>; tag=a6c85e3From: [email protected] ;tag=1928301774 Call-ID: [email protected]: 22756 MESSAGEContent-Length: 0

參考文獻• http://www.cs.columbia.edu/sip/

• “Carrier Grade Voice Over IP” – Daniel Collins

– 出版社 : McGraw-Hill

– ISBN 0071231552– http://catalogs.mhhe.com/mhhe/viewProductDetails.do?isbn=00

71406344