现在的位置: 首页 > 综合 > 正文

SIP 学习笔记之一 流程

2018年06月08日 ⁄ 综合 ⁄ 共 14614字 ⁄ 字号 评论关闭

                                                                   SIP 学习笔记之一 流程

 
 
        下面是一个invite事务的主要步骤(省略了100trying和180ring,增加了200ok的ack,ack已经不属于invite事物), u1 call u2, 主要记录包的主要字段已经这些字段在转发过程中的一些更改. 
 
UAC1 --         Proxy1 -----------      Proxy2-----          UAC2
a@u1.a.com         a.com               b.com                   b@u2.b.com
 
U1 call U2, 从invite到bye, 在整个流程中包的转发的改变.如 resquest URI, via,contact, recorded-route, route, call-id,branch等的变化.
 
/************** U1 invite *****************/
Via: u1.a.com:prot;branch= z9hG4bK- xxxxxxxxx // via ,branch 表示了这个事务;
Contact : a@u1.a.com // 为被联系的地址;接收请求的地址;
Call-ID xxxx@u1.a.com        // 标识整个流程,从invite到bye中的各个事务;
From: a@u1.a.com; tag=xxxx; //caller 发出时产生from tag; to 的tag 在callee回复时产生. 如100trying
To: b@a.com
Cseq: 1 invite;               // 表示同一个流程中的事务的先后顺序.以便服务器正确的改变该uac的状态;
 
/************** P1 Forward invite to P2 *****************/
Request URI: b@b.com     // proxy找到b对应的域,并修改request uri;
Via: a.com:prot;branch= z9hG4bK- yyyyyyy  // via ,branch // 没经过一个proxy转发就增加via,里面包括branch的值;
Via: u1.a.com:prot;branch= z9hG4bK- xxxxxxxxx // via ,branch
Contact: a@u1.a.com
Recorded-route: a.com:port;lr
From: a@u1.a.com; tag=xxxx;
To: b@a.com
Cseq: 1 invite;
 
/************** P2 Forward invite to U2*****************/
Request URI:b@u2.b.com
Via:b.com:port;branch= z9hG4bK- zzzzzzz; branch
Via: a.com:prot;branch= z9hG4bK- yyyyyyy // via ,branch 
Via: u1.a.com:prot;branch= z9hG4bK- xxxxxxxxx // via ,branch
Contact: a@u1.a.com
Recorded-route: b.com:port:lr
Recorded-route: a.com:port;lr
From: a@u1.a.com; tag=xxxx;
To: b@a.com
Cseq: 1 invite;
 
/************** U2 100 Trying and 180 Ring reserved*****************/
/************** U2 send 200OK to p2*****************/
Request URI:a@a.com
Via:b.com:port;branch= z9hG4bK- zzzzzzz;  //回复时的路由由via指定,只有是下一个请求时路由由route指定,所以在请求包中才指定route ;
Via: a.com:prot;branch= z9hG4bK- yyyyyyy // via ,branch 
Via: u1.a.com:prot;branch= z9hG4bK- xxxxxxxxx // via ,branch
Contact: b@u2.b.com
Call id xxxx@u1.com;
Recorded-route: b.com:port:lr
Recorded-route: a.com:port;lr // recored-route 只有在这通会话结束时才会被删除.
From: b@u2.b.com;tag;
To: a@u1.a.com;tag;
Cseq:1 invite;
 
/************** P2 send 200OK to p1*****************/
Request URI:a@a.com
Via: a.com:prot;branch= z9hG4bK- yyyyyyy // via ,branch // 如何判断loop? Proxy在比较本地ip是否在via中,如果在的话, 这比较branch是否相同,若相同则表示有环路,发送482,结束该会话,若不同这加上via,继续转发;
Via: u1.a.com:prot;branch= z9hG4bK- xxxxxxxxx // via ,branch
Contact: b@u2.b.com // b@b.com
Call id xxxx@u1.com;
Recorded-route: b.com:port:lr
Recorded-route: a.com:port;lr //
From: b@u2.b.com;tag;
To: a@u1.a.com;tag;
Cseq:1 invite;
 
/************** P1send 200OK to u1 *****************/
Request URI:a@a.com
Via: u1.a.com:prot;branch= z9hG4bK- xxxxxxxxx // via ,branch
Contact: b@u2.b.com // b@b.com
Call id xxxx@u1.com;
Recorded-route: b.com:port:lr //若在p1 在发送invite时,未添加recorded-route,这少了a.com这条,则当p1转发200ok给u1时应该修改recorded-route的值,有b.comàa.com,给P1发送bye请求指定正确的路由;
Recorded-route: a.com:port;lr 
From: b@u2.b.com;tag;
To: a@u1.a.com;tag;
Cseq:1 invite;
 
/************** u1 send ack to p1 *****************/
Via: a@u1.a.com; branch= z9hG4bK- xxxxxxxxx // branch 和第一个invite的相同
Contact: a@u1.a.com
Recorded-route: b.com:port:lr
Recorded-route: a.com:port;lr //
Call-id
Cseq:1 ack;
 
/************** p1 send ack to p2 *****************/
Via: a@u1.a.com; branch= z9hG4bK- xxxxxxxxx // branch 和第一个invite的相同
Via: a.com:prot;branch= z9hG4bK- yyyyyyy // via ,branch
Contact: a@u1.a.com
Recorded-route: b.com:port:lr
Recorded-route: a.com:port;lr //
Call-id
Cseq:1 ack;
 
 
/************** p2 send ack to u2 *****************/
Via: a@u1.a.com; branch= z9hG4bK- xxxxxxxxx // branch 和第一个invite的相同?
Via: a.com:prot;branch= z9hG4bK- yyyyyyy // via branch和之前的相同?
Via: b.com:prot;branch= z9hG4bK- zzzzzzz// via
Contact: a@u1.a.com
Recorded-route: b.com:port:lr
Recorded-route: a.com:port;lr //
Call-id
Cseq:1 ack;
下面附上另一例子.
###########################################################################

 SIP Process

                               

/*************************************************************************/

/*                       Caller initiates a CALL                                                                                       */

/*************************************************************************/

 

(1)caller sends INVITE to proxy

 

INVITE sip:123@hujintao.dlinkddns.com SIP/2.0

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-d225e854f32d305d-1--d87543-;rport

Max-Forwards: 70

Contact: <sip:121@116.227.0.44:6054>

To: <sip:123@hujintao.dlinkddns.com>

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 1 INVITE

Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO

Content-Type: application/sdp

Supported: eventlist

User-Agent: eyeBeam release 3015c stamp 27107

Content-Length: 174

 

v=0

o=- 158622668 158622784 IN IP4 192.168.0.7

s=eyeBeam

c=IN IP4 192.168.0.7

t=0 0

m=audio 6056 RTP/AVP 18

a=alt:1 1 : 6E90EB78 DE47B706 192.168.0.7 6056

a=sendrecv

 

(2)Proxy sends Trying to caller

 

SIP/2.0 100 Trying

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-d225e854f32d305d-1--d87543-;rport=6054;received=116.227.0.44

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

To: <sip:123@hujintao.dlinkddns.com>

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 1 INVITE

Server: Brekeke SIP Server rev.239

Content-Length: 0

 

(3)Proxy sends 407 to caller

 

SIP/2.0 407 Proxy Authentication Required

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-d225e854f32d305d-1--d87543-;rport=6054;received=116.227.0.44

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

To: <sip:123@hujintao.dlinkddns.com>;tag=bf5a41354s

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 1 INVITE

Server: Brekeke SIP Server rev.239

Proxy-Authenticate: Digest realm="sharepoint",nonce="8e33a2d7020a3fd855c91b66dd1794200cff2fcb",algorithm=MD5

Content-Length: 0

 

(4)Caller sends ACK to proxy

 

ACK sip:123@hujintao.dlinkddns.com SIP/2.0

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-d225e854f32d305d-1--d87543-;rport

To: <sip:123@hujintao.dlinkddns.com>;tag=bf5a41354s

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 1 ACK

Content-Length: 0

 

(5)Caller sends INVITE with authorization to Proxy

 

INVITE sip:123@hujintao.dlinkddns.com SIP/2.0

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport

Max-Forwards: 70

Contact: <sip:121@116.227.0.44:6054>

To: <sip:123@hujintao.dlinkddns.com>

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO

Content-Type: application/sdp

Proxy-Authorization: Digest username="121",realm="sharepoint",nonce="8e33a2d7020a3fd855c91b66dd1794200cff2fcb",uri="sip:123@hujintao.dlinkddns.com",response="181e124b006b03d1ac51d2d54bf9edd0",algorithm=MD5

Supported: eventlist

User-Agent: eyeBeam release 3015c stamp 27107

Content-Length: 174

 

v=0

o=- 158622668 158622784 IN IP4 192.168.0.7

s=eyeBeam

c=IN IP4 192.168.0.7

t=0 0

m=audio 6056 RTP/AVP 18

a=alt:1 1 : 6E90EB78 DE47B706 192.168.0.7 6056

a=sendrecv

 

(6)Proxy sends INVITE to callee

 

INVITE sip:123@192.168.0.58:5060;user=phone SIP/2.0

Via: SIP/2.0/UDP 192.168.0.121:5060;rport;branch=z9hG4bK0d40ceebef1-c38f89c2-2b40ce84

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport=6054;received=116.227.0.44

Max-Forwards: 69

Contact: <sip:121@192.168.0.121:5060>

To: <sip:123@hujintao.dlinkddns.com>

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO

Proxy-Authorization: Digest username="121",realm="sharepoint",nonce="8e33a2d7020a3fd855c91b66dd1794200cff2fcb",uri="sip:123@hujintao.dlinkddns.com",response="181e124b006b03d1ac51d2d54bf9edd0",algorithm=MD5

Supported: eventlist

User-Agent: eyeBeam release 3015c stamp 27107

P-Behind-NAT: Yes

Record-Route: <sip:192.168.0.121:5060;lr>

Content-Type: application/sdp

Content-Length: 131

 

v=0

o=- 158622668 158622784 IN IP4 192.168.0.121

s=eyeBeam

c=IN IP4 192.168.0.121

t=0 0

m=audio 10156 RTP/AVP 18

a=sendrecv

 

(7)Callee sends Trying to proxy

 

SIP/2.0 100 Trying

Via: SIP/2.0/UDP 192.168.0.121:5060;rport=5060;branch=z9hG4bK0d40ceebef1-c38f89c2-2b40ce84

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport=6054;received=116.227.0.44

To: <sip:123@hujintao.dlinkddns.com>

From: "121" <sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Content-Length: 0

 

(8)Callee sends Ringing to proxy

 

SIP/2.0 180 Ringing

Via: SIP/2.0/UDP 192.168.0.121:5060;rport=5060;branch=z9hG4bK0d40ceebef1-c38f89c2-2b40ce84

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport=6054;received=116.227.0.44

Contact: <sip:123@192.168.0.58:5060;user=phone>

Record-Route: <sip:192.168.0.121:5060;lr>

To: <sip:123@hujintao.dlinkddns.com>;tag=995280513

From: "121" <sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Content-Length: 0

 

(9)Proxy sends Trying to caller

 

SIP/2.0 100 Trying

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport=6054;received=116.227.0.44

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

To: <sip:123@hujintao.dlinkddns.com>

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Server: Brekeke SIP Server rev.239

Content-Length: 0

 

(10)Proxy sends Ringing to caller

 

SIP/2.0 180 Ringing

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport=6054;received=116.227.0.44

Contact: <sip:123@116.228.5.146:5060;user=phone>

Record-Route: <sip:116.228.5.146:5060;lr>

To: <sip:123@hujintao.dlinkddns.com>;tag=995280513

From: "121" <sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Content-Length: 0

 

/*************************************************************************/

/*               Ringing,waiting callee "off hook"                                                                               */

/*************************************************************************/

 

(11)Callee sends OK to proxy

 

SIP/2.0 200 OK

Via: SIP/2.0/UDP 192.168.0.121:5060;rport=5060;branch=z9hG4bK0d40ceebef1-c38f89c2-2b40ce84

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport=6054;received=116.227.0.44

Contact: <sip:123@192.168.0.58:5060;user=phone>

Record-Route: <sip:192.168.0.121:5060;lr>

To: <sip:123@hujintao.dlinkddns.com>;tag=995280513

From: "121" <sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Content-Type: application/sdp

Content-Length:   170

 

v=0

o=- 1707914491 1707914491 IN IP4 192.168.0.58

s=-

c=IN IP4 192.168.0.58

t=0 0

m=audio 40000 RTP/AVP 18

a=rtpmap:18 G729/8000

a=fmtp:18 annexb=no

a=ptime:20

 

(12)Proxy sends OK to caller

 

SIP/2.0 200 OK

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-1360d1470e65407a-1--d87543-;rport=6054;received=116.227.0.44

Contact: <sip:123@116.228.5.146:5060;user=phone>

Record-Route: <sip:116.228.5.146:5060;lr>

To: <sip:123@hujintao.dlinkddns.com>;tag=995280513

From: "121" <sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 INVITE

Content-Type: application/sdp

Content-Length: 171

 

v=0

o=- 1707914491 1707914491 IN IP4 116.228.5.146

s=-

c=IN IP4 116.228.5.146

t=0 0

m=audio 10158 RTP/AVP 18

a=rtpmap:18 G729/8000

a=fmtp:18 annexb=no

a=ptime:20

 

(13)Caller sends ACK to proxy

 

ACK sip:123@116.228.5.146:5060;user=phone SIP/2.0

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-5e41766c37714d75-1--d87543-;rport

Max-Forwards: 70

Route: <sip:116.228.5.146:5060;lr>

Contact: <sip:121@116.227.0.44:6054>

To: <sip:123@hujintao.dlinkddns.com>;tag=995280513

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 ACK

Proxy-Authorization: Digest username="121",realm="sharepoint",nonce="8e33a2d7020a3fd855c91b66dd1794200cff2fcb",uri="sip:123@hujintao.dlinkddns.com",response="181e124b006b03d1ac51d2d54bf9edd0",algorithm=MD5

User-Agent: eyeBeam release 3015c stamp 27107

Content-Length: 0

 

(14)Proxy sends ACK to callee

 

ACK sip:123@192.168.0.58:5060;user=phone SIP/2.0

Via: SIP/2.0/UDP 192.168.0.121:5060;rport;branch=z9hG4bKfc7a71cbef1-c38f89c2-2b40ce84

Via: SIP/2.0/UDP 192.168.0.7:6054;branch=z9hG4bK-d87543-5e41766c37714d75-1--d87543-;rport=6054;received=116.227.0.44

Max-Forwards: 69

Contact: <sip:121@192.168.0.121:5060>

To: <sip:123@hujintao.dlinkddns.com>;tag=995280513

From: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 2 ACK

Proxy-Authorization: Digest username="121",realm="sharepoint",nonce="8e33a2d7020a3fd855c91b66dd1794200cff2fcb",uri="sip:123@hujintao.dlinkddns.com",response="181e124b006b03d1ac51d2d54bf9edd0",algorithm=MD5

User-Agent: eyeBeam release 3015c stamp 27107

P-Behind-NAT: Yes

Record-Route: <sip:192.168.0.121:5060;lr>

Content-Length: 0

 

/*************************************************************************/

/*                      Callee "on hook"                                                                                    */

/*************************************************************************/

 

(15)Callee sends BYE to proxy

 

BYE sip:121@192.168.0.121:5060 SIP/2.0

Via: SIP/2.0/UDP 192.168.0.58:5060;branch=z9hG4bK-1042040550

Route: <sip:192.168.0.121:5060;lr>

To: "121" <sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

From: <sip:123@hujintao.dlinkddns.com>;tag=995280513

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 3 BYE

Max-Forwards: 70

User-Agent: Dlink-1.00.370

Content-Length: 0

 

(16)Proxy sends BYE to caller

 

BYE sip:121@116.227.0.44:6054 SIP/2.0

Via: SIP/2.0/UDP 116.228.5.146:5060;rport;branch=z9hG4bK4ac58eebef3-84116836-de76c3f7

Via: SIP/2.0/UDP 192.168.0.58:5060;branch=z9hG4bK-1042040550

To: "121" <sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

From: <sip:123@hujintao.dlinkddns.com>;tag=995280513

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 3 BYE

Max-Forwards: 69

User-Agent: Dlink-1.00.370

Record-Route: <sip:116.228.5.146:5060;lr>

Content-Length: 0

 

(17)Caller sends OK to proxy

 

SIP/2.0 200 OK

Via: SIP/2.0/UDP 116.228.5.146:5060;rport=5060;branch=z9hG4bK4ac58eebef3-84116836-de76c3f7

Via: SIP/2.0/UDP 192.168.0.58:5060;branch=z9hG4bK-1042040550

Record-Route: <sip:116.228.5.146:5060;lr>

Contact: <sip:121@116.227.0.44:6054>

To: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

From: <sip:123@hujintao.dlinkddns.com>;tag=995280513

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 3 BYE

User-Agent: eyeBeam release 3015c stamp 27107

Content-Length: 0

 

(18)Prxoy sends OK to callee

 

SIP/2.0 200 OK

Via: SIP/2.0/UDP 192.168.0.58:5060;branch=z9hG4bK-1042040550

Record-Route: <sip:192.168.0.121:5060;lr>

Contact: <sip:121@192.168.0.121:5060>

To: "121"<sip:121@hujintao.dlinkddns.com>;tag=eb7eb665

From: <sip:123@hujintao.dlinkddns.com>;tag=995280513

Call-ID: 1b693f6e6b37ef70@dG9tYXRvLTNlMTY2Zjgw

CSeq: 3 BYE

User-Agent: eyeBeam release 3015c stamp 27107

Content-Length: 0

 

 

抱歉!评论已关闭.