pjsip开发——sip日志分析

  这一节将通过一个简单的例子来介绍一些基本的 SIP 操作。先让我们来诊视下图展示的两个用户代理之间的消息顺序。关于SIP协议详细流程,可以参考RFC3261-SIP协议,当然如果不习惯的话可以参考中文翻译版RFC3261-SIP协议中文版

  收到180响应时建立dialog叫做早期对话(early dialog),收到2XX的应答开始才是真正的dialog建立。

pjsip开发——sip日志分析_第1张图片
sip呼叫.png

当然,这个代理可以有多个代理,其实也就就是多了代理服务器之间的转发过程,如下图:

pjsip开发——sip日志分析_第2张图片
The SIP dialog flow

发起呼叫流程

//发出 INVITE请求
Request: INVITE sip:[email protected] SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.107:5060;rport;branch=z9hG4bK5DF007802335421F9A6DAE3DC9B49E54..
From: 300 ;tag=2549473886 
To:  
Contact:  
Call-ID: [email protected] 
CSeq: 22243 INVITE 
Content-Type: application/sdp..

//返回响应 100 Trying
Response: SIP/2.0 100 Trying 
Via: SIP/2.0/UDP 172.20.16.107:5060;branch=z9hG4bK5DF007802335421F9A6DAE3DC9B49E54 
From: 300 ;tag=2549473886 
To: ;tag=as30112a7b 
Call-ID: [email protected] 
CSeq: 22243 INVITE 
Contact:  

//如果被邀请方收到INVITE 请求,在应答呼叫之前接收到响应180 Ringing
Response: SIP/2.0 180 Ringing 
Via: SIP/2.0/UDP 
172.20.16.107:5060;branch=z9hG4bK5DF007802335421F9A6DAE3DC9B49E54 
From: 300 ;tag=2549473886 
To: ;tag=as30112a7b 
Call-ID: [email protected] 
CSeq: 22243 INVITE 
Contact:  
//收到被邀请方应答呼叫的响应 200 OK
Response: SIP/2.0 200 OK 
Via: SIP/2.0/UDP 172.20.16.107:5060;branch=z9hG4bK5DF007802335421F9A6DAE3DC9B49E54 
From: 300 ;tag=2549473886 
To: ;tag=as30112a7b 
Call-ID: [email protected] 
CSeq: 22243 INVITE 
Contact:  
//呼叫发起方收到200 OK消息,直接发送一个ACK确认消息给被邀请方
Request: ACK sip:[email protected] SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.107:5060;rport;branch=z9hG4bK30F7F7B47E45499BAC441059EFA2DEA2 
From: 300 ;tag=2549473886 
To: ;tag=as30112a7b 
Contact:  
Call-ID: [email protected] 
CSeq: 22243 ACK 

接受呼叫过程

//接收到 INVITE请求
Request: INVITE sip:[email protected] SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.146:5060;branch=z9hG4bK5490f4d8 
From: "ppp" ;tag=as45eb9e71 
To:  
Contact:  
Call-ID: [email protected] 
CSeq: 102 INVITE 
Date: Tue, 15 Mar 2005 05:41:21 GMT 
//发送回应100 Trying
Response: SIP/2.0 100 Trying 
Via: SIP/2.0/UDP 172.20.16.146:5060;f=z9hG4bK5490f4d8 
From: "ppp" ;tag=as45eb9e71 
To: ;tag=3363667257 
Contact:  
Call-ID: [email protected] 
CSeq: 102 INVITE 
//如果接受邀请,则在接受之前发送回应180 Ringing
Response: SIP/2.0 180 Ringing 
Via: SIP/2.0/UDP 172.20.16.146:5060;branch=z9hG4bK5490f4d8 
From: "ppp" ;tag=as45eb9e71 
To: ;tag=3363667257 
Contact:  
Call-ID: [email protected] 
CSeq: 102 INVITE 
如果决定应答呼叫,则发送200 Ok消息
Response: SIP/2.0 200 Ok 
Via: SIP/2.0/UDP 172.20.16.146:5060;branch=z9hG4bK5490f4d8 
From: "ppp" ;tag=as45eb9e71 
To: ;tag=3363667257 
Contact:  
Call-ID: [email protected] 
CSeq: 102 INVITE 
//接收到邀请方发来的ACK确认消息
Request: ACK sip:[email protected]:5060 SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.146:5060;branch=z9hG4bK74cf8e58 
From: "ppp" ;tag=as45eb9e71 
To: ;tag=3363667257 
Contact:  
Call-ID: [email protected] 
CSeq: 102 ACK 

终止呼叫或拒绝接受邀请

//发送BYE消息
Request: BYE sip:[email protected] SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.107:5060;rport;branch=z9hG4bK2CF3B0C22620465D988E1CC2C8A71C56 
From: 300 ;tag=2549473886 
To: ;tag=as30112a7b 
Contact:  
Call-ID: [email protected] 
CSeq: 22244 BYE 
返回200 OK消息
Response: SIP/2.0 200 OK 
Via: SIP/2.0/UDP 172.20.16.107:5060;branch=z9hG4bK2CF3B0C22620465D988E1CC2C8A71C56 
From: 300 ;tag=2549473886 
To: ;tag=as30112a7b 
Call-ID: [email protected] 
CSeq: 22244 BYE 
Contact:  

取消邀请过程

//发出 INVITE请求
Request: INVITE sip:[email protected] SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.107:5060;rport;branch=z9hG4bKE7C2E749AA8B49C693EA90BE1BB367D6 
From: 300 ;tag=1829163469 
To:  
Contact:  
Call-ID: [email protected] 
CSeq: 41305 INVITE 
//返回响应 100 Trying
Response: SIP/2.0 100 Trying 
Via: SIP/2.0/UDP 
172.20.16.107:5060;branch=z9hG4bKE7C2E749AA8B49C693EA90BE1BB367D6 
From: 300 ;tag=1829163469 
To: ;tag=as3324adcc 
Call-ID: [email protected] 
CSeq: 41305 INVITE 
Contact:  
//返回响应180 Ringing
Response: SIP/2.0 180 Ringing 
Via:SIP/2.0/UDP 172.20.16.107:5060;branch=z9hG4bKE7C2E749AA8B49C693EA90BE1BB367D6 
From: 300 ;tag=1829163469 
To: ;tag=as3324adcc 
Call-ID: [email protected] 
CSeq: 41305 INVITE 
Contact:  
取消INVITE请求
Request: CANCEL sip:[email protected] SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.107:5060;rport;branch=z9hG4bKE7C2E749AA8B49C693EA90BE1BB367D6 
From: 300 ;tag=1829163469 
To:  
Contact:  
Call-ID: [email protected] 
CSeq: 41305 CANCEL 
返回487请求终止应答
Response: SIP/2.0 487 Request Terminated 
Via: SIP/2.0/UDP 172.20.16.107:5060;branch=z9hG4bKE7C2E749AA8B49C693EA90BE1BB367D6 
From: 300 ;tag=1829163469 
To: ;tag=as3324adcc 
Call-ID: [email protected] 
CSeq: 41305 INVITE 
Contact:  
//返回应答200 OK
Response: SIP/2.0 200 OK 
Via: SIP/2.0/UDP 172.20.16.107:5060;branch=z9hG4bKE7C2E749AA8B49C693EA90BE1BB367D6 
From: 300 ;tag=1829163469 
To: ;tag=as3324adcc 
Call-ID: [email protected] 
CSeq: 41305 CANCEL 
Contact:  
//发送ACK确认消息
Request: ACK sip:[email protected] SIP/2.0 
Via: SIP/2.0/UDP 172.20.16.107:5060;rport;branch=z9hG4bKE7C2E749AA8B49C693EA90BE1BB367D6 
From: 300 ;tag=1829163469 
To: ;tag=as3324adcc 
Contact:  
Call-ID: [email protected] 
CSeq: 41305 ACK 

你可能感兴趣的:(pjsip开发——sip日志分析)