我们首先来看下基本的呼叫流程。
INVITEsip:69690067@beijing.chinamobile.com;user=phone SIP/2.0
From:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>;tag=8741b8-ac1014d2-13c4-1c6-10e9bfd8-1c6
To:<sip:69690067@beijing.chinamobile.com;user=phone>
Call-ID: 88a020-ac1014d2-13c4-1c6-1b3a4fb3-1c6@beijing.chinamobile.com
CSeq: 1 INVITE
Via: SIP/2.0/UDP172.16.20.210:5060;branch=z9hG4bK-1c6-6f0cc-66d0e581
Allow: INVITE,ACK,CANCEL,BYE,REGISTER,REFER,NOTIFY,PRACK,CANCEL,SUBSCRIBE,OPTIONS,INFO,UPDATE,MESSAGE
Max-Forwards: 70
Supported: 100rel,replaces,timer
P-Preferred-Identity:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>
Contact: <sip:+861069690069@172.16.20.210:5060>
Content-Type: application/SDP
Content-Length: 236
v=0
o=+861069690069 454 454 IN IP4172.16.20.210
s=-
c=IN IP4 172.16.20.210
t=0 0
m=audio 10008 RTP/AVP 8 0 18 4
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=rtpmap:4 G723/8000
a=ptime:20
a=ecan:fb on -
用户摘机发起一路呼叫,终端+861069690069向代理服务器发送INVITE请求
SIP/2.0 100 Trying
Via: SIP/2.0/UDP172.16.20.210:5060;branch=z9hG4bK-1c6-6f0cc-66d0e581;received=192.168.100.41
Call-ID: 88a020-ac1014d2-13c4-1c6-1b3a4fb3-1c6@beijing.chinamobile.com
From: "+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>;tag=8741b8-ac1014d2-13c4-1c6-10e9bfd8-1c6
To:<sip:69690067@beijing.chinamobile.com;user=phone>
CSeq: 1 INVITE
Content-Length: 0
代理服务器收到终端发送的INVITE请求,向终端+861069690069发送100 trying说明该请求已经收到,让终端停止INVITE重发定时器。
INVITEsip:+861069690067@172.16.20.210:5060 SIP/2.0
Via: SIP/2.0/UDP192.168.246.210:5060;branch=z9hG4bKw0hwph6xp20yo0gg2zhmwwpvmT25426
Call-ID: asbc7xw0p0x3zv6qxx1zx03n01qlv6k11z2q@192.168.10.22
From:<sip:65069@beijing.chinamobile.com>;tag=sbc05100m0qlxw6
To:<sip:+861069690067@beijing.chinamobile.com;user=phone>
CSeq: 1 INVITE
Allow:INVITE,CANCEL,ACK,BYE,OPTIONS,INFO,UPDATE,PRACK,REFER,NOTIFY,REGISTER,MESSAGE,SUBSCRIBE
Contact:<sip:192.168.246.210:5060>
Max-Forwards: 69
Supported: 100rel,replaces,timer
P-Asserted-Identity:<tel:+861069690069>
Privacy: none
P-Called-Party-ID:<sip:+861069690067@beijing.chinamobile.com>
Content-Length: 235
Content-Type: application/sdp
v=0
o=- 454 454 IN IP4 192.168.246.218
s=SBC call
c=IN IP4 192.168.246.218
t=0 0
m=audio 12962 RTP/AVP 8 0 18 4
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=rtpmap:4 G723/8000
a=ptime:20
a=ecan:fb on –
代理服务器通过对INVITE请求的验证通过后,检查via头域中是否包含自己的地址。若已包含自己的地址,说明已经发生回路,向终端+861069690069发送错误的应答;如果没有问题,代理服务器在请求消息的via头域插入自己的地址,并向INVITE消息的to头域所指的被叫终端转发INVITE请求。
SIP/2.0 100 Trying
From:<sip:65069@beijing.chinamobile.com>;tag=sbc05100m0qlxw6
To:<sip:+861069690067@beijing.chinamobile.com;user=phone>
Call-ID: asbc7xw0p0x3zv6qxx1zx03n01qlv6k11z2q@192.168.10.22
CSeq: 1 INVITE
Via: SIP/2.0/UDP192.168.246.210:5060;branch=z9hG4bKw0hwph6xp20yo0gg2zhmwwpvmT25426
Supported: 100rel,replaces,timer
P-Preferred-Identity:"+861069690067"<sip:+861069690067@beijing.chinamobile.com;user=phone>
Contact:<sip:+861069690067@172.16.20.210:5060>
Content-Length: 0
终端+861069690067收到代理服务器发送的INVITE请求,并向代理服务器发送100 trying说明该请求已经收到,让终端停止INVITE重发定时器。
SIP/2.0 180 Ringing
From:<sip:65069@beijing.chinamobile.com>;tag=sbc05100m0qlxw6
To:<sip:+861069690067@beijing.chinamobile.com;user=phone>;tag=874368-ac1014d2-13c4-1c7-26f60a2f-1c7
Call-ID: asbc7xw0p0x3zv6qxx1zx03n01qlv6k11z2q@192.168.10.22
CSeq: 1 INVITE
Via: SIP/2.0/UDP192.168.246.210:5060;branch=z9hG4bKw0hwph6xp20yo0gg2zhmwwpvmT25426
Supported: 100rel,replaces,timer
P-Preferred-Identity: "+861069690067"<sip:+861069690067@beijing.chinamobile.com;user=phone>
Contact:<sip:+861069690067@172.16.20.210:5060>
Content-Length: 0
被叫终端对INVITE消息的合法性检查通过,指示代理服务器振铃,向代理服务器发送180 ring消息
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP172.16.20.210:5060;branch=z9hG4bK-1c6-6f0cc-66d0e581;received=192.168.100.41
Call-ID:88a020-ac1014d2-13c4-1c6-1b3a4fb3-1c6@beijing.chinamobile.com
From:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>;tag=8741b8-ac1014d2-13c4-1c6-10e9bfd8-1c6
To:<sip:69690067@beijing.chinamobile.com;user=phone>;tag=sbc0509wwxwpz1q
CSeq: 1 INVITE
Allow:INVITE,CANCEL,ACK,BYE,OPTIONS,INFO,UPDATE,PRACK,REFER,NOTIFY,REGISTER,MESSAGE,SUBSCRIBE
Contact:<sip:192.168.246.210:5060>
P-Asserted-Identity:<sip:+861069690067@beijing.chinamobile.com>,<tel:+861069690067>
Content-Length: 0
代理服务器收到180 ring消息,指示主叫方听回铃音
SIP/2.0 200 OK
From:<sip:65069@beijing.chinamobile.com>;tag=sbc05100m0qlxw6
To:<sip:+861069690067@beijing.chinamobile.com;user=phone>;tag=874368-ac1014d2-13c4-1c7-26f60a2f-1c7
Call-ID:asbc7xw0p0x3zv6qxx1zx03n01qlv6k11z2q@192.168.10.22
CSeq: 1 INVITE
Allow: INVITE,ACK,CANCEL,BYE,REGISTER,REFER,NOTIFY,PRACK,CANCEL,SUBSCRIBE,OPTIONS,INFO,UPDATE,MESSAGE
Via: SIP/2.0/UDP192.168.246.210:5060;branch=z9hG4bKw0hwph6xp20yo0gg2zhmwwpvmT25426
Supported: 100rel,replaces,timer
P-Preferred-Identity:"+861069690067"<sip:+861069690067@beijing.chinamobile.com;user=phone>
Contact:<sip:+861069690067@172.16.20.210:5060>
Content-Type: application/SDP
Content-Length: 248
v=0
o=+861069690067 456 456 IN IP4172.16.20.210
s=-
c=IN IP4 172.16.20.210
t=0 0
m=audio 10012 RTP/AVP 8 0 18 4
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=rtpmap:4 G723/8000
a=ptime:20
a=ecan:fb on -
a=sendrecv
被叫方摘机,向代理服务器发送200OK消息,表示已经摘机可以开始通话了
SIP/2.0 200 OK
Via: SIP/2.0/UDP172.16.20.210:5060;branch=z9hG4bK-1c6-6f0cc-66d0e581;received=192.168.100.41
Call-ID: 88a020-ac1014d2-13c4-1c6-1b3a4fb3-1c6@beijing.chinamobile.com
From:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>;tag=8741b8-ac1014d2-13c4-1c6-10e9bfd8-1c6
To:<sip:69690067@beijing.chinamobile.com;user=phone>;tag=sbc0509wwxwpz1q
CSeq: 1 INVITE
Allow:INVITE,CANCEL,ACK,BYE,OPTIONS,INFO,UPDATE,PRACK,REFER,NOTIFY,REGISTER,MESSAGE,SUBSCRIBE
Contact:<sip:192.168.246.210:5060>
Supported: 100rel,replaces,timer
P-Asserted-Identity:<sip:+861069690067@beijing.chinamobile.com>,<tel:+861069690067>
Content-Length: 247
Content-Type: application/sdp
v=0
o=- 456 456 IN IP4 192.168.246.218
s=SBC call
c=IN IP4 192.168.246.218
t=0 0
m=audio 12964 RTP/AVP 8 0 18 4
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=rtpmap:4 G723/8000
a=ptime:20
a=ecan:fb on -
a=sendrecv
代理服务器收到200 OK消息后修改状态机,并且发送200OK消息到主叫,告诉主叫,被叫已经接通
ACK sip:192.168.246.210:5060SIP/2.0
From:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>;tag=8741b8-ac1014d2-13c4-1c6-10e9bfd8-1c6
To:<sip:69690067@beijing.chinamobile.com;user=phone>;tag=sbc0509wwxwpz1q
Call-ID:88a020-ac1014d2-13c4-1c6-1b3a4fb3-1c6@beijing.chinamobile.com
CSeq: 1 ACK
Via: SIP/2.0/UDP172.16.20.210:5060;branch=z9hG4bK-1c8-6f6ac-7e19e755
Max-Forwards: 70
P-Preferred-Identity:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>
Contact:<sip:+861069690069@172.16.20.210:5060>
Content-Length: 0
代理服务器收到ACK后,向被叫方发送200 OK对应的ACK消息,表示200 OK消息已经收到,并且主叫和被叫可以进行通话
ACKsip:+861069690067@172.16.20.210:5060 SIP/2.0
Via: SIP/2.0/UDP192.168.246.210:5060;branch=z9hG4bKw0wp6h1p6ovh1lzr1lgr1rpzmT25427
Call-ID:asbc7xw0p0x3zv6qxx1zx03n01qlv6k11z2q@192.168.10.22
From:<sip:65069@beijing.chinamobile.com>;tag=sbc05100m0qlxw6
To:<sip:+861069690067@beijing.chinamobile.com;user=phone>;tag=874368-ac1014d2-13c4-1c7-26f60a2f-1c7
CSeq: 1 ACK
Max-Forwards: 69
Content-Length: 0
被叫发送收到ACK消息后,通话建立成功
语音通讯建立成功,开始进行正常的语音通话……
BYE sip:192.168.246.210:5060SIP/2.0
From:<sip:+861069690067@beijing.chinamobile.com;user=phone>;tag=874368-ac1014d2-13c4-1c7-26f60a2f-1c7
To:<sip:65069@beijing.chinamobile.com>;tag=sbc05100m0qlxw6
Call-ID: asbc7xw0p0x3zv6qxx1zx03n01qlv6k11z2q@192.168.10.22
CSeq: 1 BYE
Via: SIP/2.0/UDP172.16.20.210:5060;branch=z9hG4bK-1d1-719f3-76b3cbbd
Max-Forwards: 70
Supported: 100rel,replaces,timer
P-Preferred-Identity:"+861069690067"<sip:+861069690067@beijing.chinamobile.com;user=phone>
Content-Length: 0
主叫方挂机,向代理服务器发送BYE消息
SIP/2.0 200 OK
Via: SIP/2.0/UDP172.16.20.210:5060;branch=z9hG4bK-1d1-719f3-76b3cbbd;received=192.168.100.41
Call-ID:asbc7xw0p0x3zv6qxx1zx03n01qlv6k11z2q@192.168.10.22
From: <sip:+861069690067@beijing.chinamobile.com;user=phone>;tag=874368-ac1014d2-13c4-1c7-26f60a2f-1c7
To:<sip:65069@beijing.chinamobile.com>;tag=sbc05100m0qlxw6
CSeq: 1 BYE
Content-Length: 0
代理服务器收到,BYE消息后,确认挂机后,向主叫方发送200OK,表示主叫方已经成功挂机,并且向被叫方发送BYE消息,通知其挂机
BYEsip:+861069690069@172.16.20.210:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.246.210:5060;branch=z9hG4bKlvog2lhovvv0w6pmllymrhl16T15221
Call-ID: 88a020-ac1014d2-13c4-1c6-1b3a4fb3-1c6@beijing.chinamobile.com
From:<sip:69690067@beijing.chinamobile.com;user=phone>;tag=sbc0509wwxwpz1q
To:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>;tag=8741b8-ac1014d2-13c4-1c6-10e9bfd8-1c6
CSeq: 1 BYE
Max-Forwards: 69
Reason: Q.850;cause=16
Content-Length: 0
代理服务器向被叫发送关机消息BYE,告诉被叫主叫已经挂机
SIP/2.0 200 OK
From:<sip:69690067@beijing.chinamobile.com;user=phone>;tag=sbc0509wwxwpz1q
To: "+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>;tag=8741b8-ac1014d2-13c4-1c6-10e9bfd8-1c6
Call-ID: 88a020-ac1014d2-13c4-1c6-1b3a4fb3-1c6@beijing.chinamobile.com
CSeq: 1 BYE
Via: SIP/2.0/UDP192.168.246.210:5060;branch=z9hG4bKlvog2lhovvv0w6pmllymrhl16T15221
Supported: 100rel,replaces,timer
P-Preferred-Identity:"+861069690069"<sip:+861069690069@beijing.chinamobile.com;user=phone>
Content-Length: 0
被叫方收到BYE消息后,确认挂机,并且回复200OK,表示挂机操作已经成功完成
呼叫消息的流程图
根据上述的呼叫信息,对其进行详细的讲解。
1) 主叫方“+861069690069”发起语音呼叫,主叫方地址:172.16.20.210,向代理服务器(192.168.246.210:)发送INVITE请求,需要和被叫方“69690067”建立呼叫。
2) 代理服务器收到主叫方,发送的INVITE请求后,回复100 Trying。100 Trying表示代理服务器已经收到了INVITE请求,不需要UAC,即主叫方启用INVITE重发定时间,再次发送INVITE消息。
3) 代理服务器对收到的INVITE消息进行合法性检查,检查通过后,在注册服务器上查找被叫,是否存在这样的注册被叫号码,如果被叫不存在向主叫方发送404消息结束本次呼叫请求,否则,想被叫注册的地址发送呼叫请求INVITE消息。
4) 被叫方收到INVITE请求消息后,回复100 Trying。并对INVITE消息的合法性检测。
5) 被叫方对INVITE消息的合法性检测通过后,开始振铃,并且向代理服务器发送180,表示被叫方开始振铃,主叫方听回铃音或彩铃。
6) 代理服务器收到180后,修改代理服务器的状态机状态,修改为振铃状态,并且发送振铃消息给主叫方,主叫方听回铃音。
7) 被叫方摘机,向代理服务器发送200OK消息,表示被叫方已经摘机。
8) 代理服务器收到200OK消息后修改状态机,并且发送200OK消息到主叫,告诉主叫,被叫已经接通。
9) 主叫收到200OK后,打开媒体通道,建立通话,并且向代理服务器发送ACK消息,表示已经收到200OK消息。
10)代理服务器收到ACK后,向被叫方发送200OK对应的ACK消息,表示200OK消息已经收到,并且主叫和被叫可以进行通话。
11) 被叫发送收到ACK消息后,通话建立成功。
12)通过以上11个步骤,通话终于建立成功。
13)主叫方挂机,向代理服务器发送BYE消息。
14)代理服务器收到,BYE消息后,确认挂机后,向主叫方发送200OK,表示主叫方已经成功挂机,并且向被叫方发送BYE消息,通知其挂机。
15) 被叫方收到BYE消息后,确认挂机,并且回复200OK,表示挂机操作已经成功完成。
16) 经过以上步骤,通话到此结束。
原文地址:http://blog.csdn.net/wh8_2011/article/details/29803895