观察SIP, SDP,RTP包及MSML

建立连接前

UAC INVITE,进行SDP offer:

 1Session Initiation Protocol (INVITE)
 2    Request-Line: INVITE sip:[email protected]:5080 SIP/2.0
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-0
 5        From: sipp <sip:[email protected]:5060>;tag=1
 6        To: sut <sip:[email protected]:5080>
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 1 INVITE
10        Contact: sip:[email protected]:5060
11        Max-Forwards: 70
12        Subject: Performance Test
13        Content-Type: application/sdp
14        Content-Length:   149
15    Message Body
16        Session Description Protocol
17            Session Description Protocol Version (v): 0
18            Owner/Creator, Session Id (o): caller 0 0 IN IP4 10.1.93.116
19            Session Name (s): MobileVrbt_UEA_User_Caller_18500000000_18600000000
20            Session Information (i): -
21            Connection Information (c): IN IP4 10.4.6.199
22            Time Description, active time (t): 0 0
23            Media Description, name and address (m): audio 5002 RTP/AVP 8
24            [Generated Call-ID: [email protected]]

SIP:总的来说来说挺简单

Header 含义说明 举例
Call-ID 由本地设备(Client)生成,全局唯一,每次呼叫这个值唯一不变 Call-ID: [email protected]
From 表示请求的发起者 From: sip:[email protected];tag=49583
To 表示请求的接收者 To: sip:[email protected]
Via Via头域是被服务器插入request中,用来检查路由环的,并且可以使response根据via找到返回的路 Via: SIP/2.0/TCP user1pc.domain.com;branch=z9hG4bK776sgdkse
Max-Forwards 用于表示这个包最多可以传送多少跳,每经过一跳都会减一当Max-Forwards==0系统会返回483。默认为70 Max-Forwards: 70
Contact 包含源的URI信息,用来给响应方直接和源建立连接用 Contact: sip:192.168.100.1:1111
Content-Type 指明消息体的类型 (SDP会话描述协议) Content-Type: text/plain;Content-Type: application/sdp; Content-Type: application/cpim;
Content-Length 指明消息体的字节大小 Content-Length: 18

SDP:

  • v:版本信息

  • o=<用户名><会话ID><会话版本><网络类型><地址类型><单播地址>

    <用户名>:是登陆源主机的用户的名字,如果不能提供,则用"-“表示,用户名不能包含空格。 <会话ID>:是一个数字字符串,<用户名><会话ID><网络类型>和<单播地址>这个组合形成了表示该会话的唯一标识,<会话ID>通常使用NTP格式的时间戳标识。 <会话版本>:是当前会话描述的版本号,如果当前会话的数据被修改时,这个版本号会递增,同样推荐使用NTP格式的时间戳。 <网络类型>:是一个文本字符串,标志当前网络的类型,最初"IN”标识"Internet”,未来可能会定义其他的值。 <地址类型>:是一个文本字符串,标志当前地址的类型,最初只有"IP4"和"IP6"有定义,未来可能定义其他的值。 <单播地址>:是创建会话的主机的地址,可以是域名,也可以是"IP4"或"IP6"IP地址。域名是首先,除非域名不可获得。如果使用IP地址,则需要使用全球唯一的IP地址,不能使用本地IP地址。

  • s=<会话名字> 字段"s=“是文本类型的会话名字,每个会话描述有且仅有一个"s=“字段,“s=“字段不能为空,并且应该为ISO 10646字体。如果一个会话没有有意义的名字,则此字段应该为一个空格。

  • i=<会话描述> “i=“字段提供会话的文本信息,在会话层和媒体层最多出现一次。

  • c=<网络类型><地址类型><连接地址> 这个字段包含连接数据,一个会话描述必须在每个媒体层都包含"c=“字段或者在会话层包含一个"c=“字段。如果这两个层都出现的话,则媒体层出现的"c=“会覆盖会话层出现的"c=“字段的值。

    <网络类型>:是一个文本字符串,标志当前网络的类型,最初"IN”标识"Internet”,未来可能会定义其他的值。 <地址类型>:是一个文本字符串,标志当前地址的类型,最初只有"IP4"和"IP6"有定义,未来可能定义其他的值。 <连接地址>标志连接的地址,当<连接地址>为IP4或者IP6时,连接的定义如下: i)当回话是多播时,地址为多播地址;当会话是单播时,地址为单播地址,并且为媒体数据的原地址。 ii)如果地址是IPv4,则还需要给出TTL的值,TTL标识包的生存时间,范围是0~255.

  • t=<起始时间><结束时间> “t=“子弹标志了会话的起始时间和结束时间,如果会话在不规则的多个时间段内有效,则可能会出现多个字段的"t=”。如果时间段是规则的,则应该使用"r=“字段,后面将会介绍。

  • m=<媒体类型><端口><协议><格式类型> 一个会话描述可能包括多个媒体描述。每个媒体描述都以"m=“字段开始的,结束于下一个"m=“或者整个会话结束。

    <媒体类型>:本规范定义了视频、音频、文本、应用和消息这几种类型。 <端口>:被房媒体流的端口,这个字段的意义依赖于"c=“字段和<协议>字段。如果不适用连续的端口或者没有按照偶数RTP端口,奇数RTCP端口,则必须使用"a=rtcp:“来标识RTCP的端口。应用程序被发送到一个端口,此端口是一个奇数端口,并且出现”a=rtcp:”行时,此媒体一定不能从RTP端口减一,应用程序必须发送RTP数据到指定的端口,并且发送RTCP到”a=rtcp”属性设定的端口。对于某些应用程序,它们的媒体流通过层级解码发送到单播地址时,它们有必要设定多个传输端口。使用语法和多播地址的方式类似: m= / …。这种场景中,使用的端口依赖于传输协议类型。一些读者可能明白,通常默情况下,RTP使用偶数端口传输数据,它的RTCP使用高一位数的奇数端口控制RTP会话。表示RTP会话数量。 <协议>:它是传输协议。这里的传输协议依赖于”c=”行定义的地址类型。目前支持的主要的几个类型包括:UDP,RTP/AVP,RTP/SAVP。这里专门针对媒体格式设定不同的传输协议是因为同一网络协议时,标准的媒体格式可以通过不同的传输协议来进行传输。这样的设定可以支持不同的网络传输和满足不同检测工具部署。 <格式类型>:它表示一种媒体格式描述。前面第四个子项或者其他后续子项都表示媒体格式。媒体格式描述的解析依赖于子项的值。如果 子项是”RTP/AVP”或者”RTP/SAVP,媒体格式描述会包含RTP payload 类型号码。当给定了一个payload类型列表时(静态方式,从96-127),这表示所有的媒体格式可以适用于此会话中,但是,通常列表中的第一个格式应该作为此会话默认支持格式。如果payload类型列表是动态的payload类型列表的话,SDP使用”a=rtpmap:”属性来执行一个映射(从RTP payload 类型号码到媒体解码名称),通过媒体类型号码到媒体解码名称的对应关系来确认payload格式。”a=fmtp:” 行可以用来设定具体的媒体格式参数。

MS 回信:

100

 1Session Initiation Protocol (100)
 2    Status-Line: SIP/2.0 100 Trying
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-0
 5        To: sut <sip:[email protected]:5080>
 6        From: sipp <sip:[email protected]:5060>;tag=1
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 1 INVITE
10        Content-Length: 0

200,同时SDP answer

 1Session Initiation Protocol (200)
 2    Status-Line: SIP/2.0 200 OK
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-0
 5        To: sut <sip:[email protected]:5080>;tag=YRrWa7c2kH
 6        From: sipp <sip:[email protected]:5060>;tag=1
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 1 INVITE
10        Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, OPTIONS, PRACK, UPDATE
11        Contact: <sip:[email protected]:5080>
12        Content-Type: application/sdp
13        Supported: 100rel, precondition
14        Content-Length: 137
15    Message Body
16        Session Description Protocol
17            Session Description Protocol Version (v): 0
18            Owner/Creator, Session Id (o): - 0 1736403692661597 IN IP4 10.1.68.48
19            Session Name (s): -
20            Session Information (i): Session description protocol
21            Connection Information (c): IN IP4 10.1.68.48
22            Time Description, active time (t): 0 0
23            Media Description, name and address (m): audio 30008 RTP/AVP 8
24            [Generated Call-ID: [email protected]]

UAC ACK,连接建立:

 1Session Initiation Protocol (ACK)
 2    Request-Line: ACK sip:[email protected]:5080 SIP/2.0
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-3
 5        From: sipp <sip:[email protected]:5060>;tag=1
 6        To: sut <sip:[email protected]:5080>;tag=YRrWa7c2kH
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 1 ACK
10        Contact: sip:[email protected]:5060
11        Max-Forwards: 70
12        Subject: Performance Test
13        Content-Length: 0

连接建立后

请求放音

UAC INFO

 1Session Initiation Protocol (INFO)
 2    Request-Line: INFO sip:[email protected]:5080 SIP/2.0
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-5
 5        From: sipp <sip:[email protected]:5060>;tag=1
 6        To: sut <sip:[email protected]:5080>;tag=YRrWa7c2kH
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 2 INFO
10        Contact: sip:[email protected]:5060
11        Max-Forwards: 70
12        Subject: Performance Test
13        Content-Type: application/msml+xml
14        Content-Length:   330
15    Message Body
16        <?xml version="1.0" encoding="UTF-8"?>\r\n
17        <msml version="1.1">\r\n
18        <dialogstart target="conn:12345" name="12345">\r\n
19        <play barge="true" iterate="1" interval="1" maxtime="5" id="play">\r\n
20        <audio uri="audio.wav" />\r\n
21        <playexit>\r\n
22        <send target="source" event="done" valuelist="play.end play.amt"/>\r\n
23        </playexit>\r\n
24        </play>\r\n
25        </dialogstart>\r\n
26        </msml>
27

MS 回复:

 1Session Initiation Protocol (200)
 2    Status-Line: SIP/2.0 200 OK
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-5
 5        To: sut <sip:[email protected]:5080>;tag=YRrWa7c2kH
 6        From: sipp <sip:[email protected]:5060>;tag=1
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 2 INFO
10        Content-Type: application/msml+xml
11        Content-Length: 146
12    Message Body
13        <?xml version="1.0" encoding="UTF-8"?>\n
14        <msml version="1.1">\n
15        <result response="200">\n
16        <dialogid>conn:12345/dialog:12345</dialogid>\n
17        </result>\n
18        </msml>

然后MS就通过RTP开始传输媒体了,这里放几个连续的包

 1Real-Time Transport Protocol
 2    [Stream setup by SDP (frame 43)]
 3    10.. .... = Version: RFC 1889 Version (2)
 4    ..0. .... = Padding: False
 5    ...0 .... = Extension: False
 6    .... 0000 = Contributing source identifiers count: 0
 7    0... .... = Marker: False
 8    Payload type: ITU-T G.711 PCMA (8)
 9    Sequence number: 99
10    [Extended sequence number: 65635]
11    Timestamp: 1600
12    Synchronization Source identifier: 0xeeba3c7a (4005182586)
13    Payload [truncated]: d5d5d5d5d5555555d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5555555d5d5d5d5d555d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d555d555d5d5d5555555d5d5d5d5d55555555555d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d55842415855dfdadb
 1Real-Time Transport Protocol
 2    [Stream setup by SDP (frame 43)]
 3    10.. .... = Version: RFC 1889 Version (2)
 4    ..0. .... = Padding: False
 5    ...0 .... = Extension: False
 6    .... 0000 = Contributing source identifiers count: 0
 7    0... .... = Marker: False
 8    Payload type: ITU-T G.711 PCMA (8)
 9    Sequence number: 100
10    [Extended sequence number: 65636]
11    Timestamp: 1760
12    Synchronization Source identifier: 0xeeba3c7a (4005182586)
13    Payload [truncated]: 9c8eb6b1b2b1806e353f383c37001676d5d4d7c5f3e6ecece0f0d5e1919e838c8d87849996ecd2667154c2eb9517083c27212738371adce8969d979c99e6d06c1211c9cbfd919998848eb5b5b58e83808088b7b68c907b070d011a6de89b878c8e8d809ee8446b101b1905051a
 1Real-Time Transport Protocol
 2    [Stream setup by SDP (frame 43)]
 3    10.. .... = Version: RFC 1889 Version (2)
 4    ..0. .... = Padding: False
 5    ...0 .... = Extension: False
 6    .... 0000 = Contributing source identifiers count: 0
 7    0... .... = Marker: False
 8    Payload type: ITU-T G.711 PCMA (8)
 9    Sequence number: 101
10    [Extended sequence number: 65637]
11    Timestamp: 1920
12    Synchronization Source identifier: 0xeeba3c7a (4005182586)
13    Payload [truncated]: a6a4beb784df6d6f151116681c12681e1a010b343737363735350e0605126b66707144d19392848f8fed140f3d3e383d360804114be992808d8281838787839d9380868fb5b58bb7b1b4b5b3b3b3bbb8b78710303b38383f32363135041867d4f1e6ee949d85e4621c34313630

。。。。 一直是最后几个rtp包

 1Real-Time Transport Protocol
 2    [Stream setup by SDP (frame 43)]
 3    10.. .... = Version: RFC 1889 Version (2)
 4    ..0. .... = Padding: False
 5    ...0 .... = Extension: False
 6    .... 0000 = Contributing source identifiers count: 0
 7    0... .... = Marker: False
 8    Payload type: ITU-T G.711 PCMA (8)
 9    Sequence number: 347
10    [Extended sequence number: 65883]
11    Timestamp: 41280
12    Synchronization Source identifier: 0xeeba3c7a (4005182586)
13    Payload [truncated]: 7397919d98999c96cd7d621c1101093432323d3c3c3c38383c3f360d6beb9e8e8e888b898bb4b4b3bfbaa7a7a4a5b9b9b3b688818693ed49101a02080b353534350b02010507000c0f3534340b0d05116313121a181f1c181d111c131b121763c4ec9f87838f888bb4b4b4b5b4
 1Real-Time Transport Protocol
 2    [Stream setup by SDP (frame 43)]
 3    10.. .... = Version: RFC 1889 Version (2)
 4    ..0. .... = Padding: False
 5    ...0 .... = Extension: False
 6    .... 0000 = Contributing source identifiers count: 0
 7    0... .... = Marker: False
 8    Payload type: ITU-T G.711 PCMA (8)
 9    Sequence number: 348
10    [Extended sequence number: 65884]
11    Timestamp: 41440
12    Synchronization Source identifier: 0xeeba3c7a (4005182586)
13    Payload [truncated]: b8baa5bab9bdb18883859debf9516011060b32382524243a383234021b1779c5e0979e84838eb5b7b48b898d83869b91ebf35d791411121316176ec59f8cb1bfb8bbbcb18d905d171919136d7d49641416121c18040704051a05000d0e353736333c3825253a383d3609001a1c

seq一直在涨,timestamp是160地增长

停止放音

MS INFO。这个是由只前的INFO里的msml控制的时间

 1Session Initiation Protocol (INFO)
 2    Request-Line: INFO sip:[email protected]:5060 SIP/2.0
 3    Message Header
 4        Via: SIP/2.0/UDP 10.1.68.48:5080;branch=z9hG4bK9MCm3mhRXjX
 5        To: <sip:[email protected]:5060>;tag=1
 6        From: <sip:[email protected]:5080>;tag=YRrWa7c2kH
 7        Call-Id: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 1 INFO
10        Content-Type: application/msml+xml
11        Content-Length: 216
12    Message Body
13        <?xml version="1.0" encoding="UTF-8"?>\n
14        <msml version="1.1">\n
15        <event name="done" id="conn:12345/dialog:12345">\n
16        <name>play.end</name>\n
17        <value>play.complete</value>\n
18        <name>play.amt</name>\n
19        <value>5s</value>\n
20        </event>\n
21        </msml>

UAC 回复

 1Session Initiation Protocol (200)
 2    Status-Line: SIP/2.0 200 OK
 3    Message Header
 4        Via: SIP/2.0/UDP 10.1.68.48:5080;branch=z9hG4bK9MCm3mhRXjX
 5        From: <sip:[email protected]:5080>;tag=YRrWa7c2kH
 6        To: <sip:[email protected]:5060>;tag=1
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 1 INFO
10        Contact: <sip:10.4.6.199:5060;transport=UDP>
11        Content-Length: 0

断开连接

UAC BYE

 1Session Initiation Protocol (BYE)
 2    Request-Line: BYE sip:[email protected]:5080 SIP/2.0
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-9
 5        From: sipp <sip:[email protected]:5060>;tag=1
 6        To: sut <sip:[email protected]:5080>;tag=YRrWa7c2kH
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 10 BYE
10        Contact: sip:[email protected]:5060
11        Max-Forwards: 70
12        Subject: Performance Test
13        Content-Length: 0

MS 回复

 1Session Initiation Protocol (200)
 2    Status-Line: SIP/2.0 200 OK
 3    Message Header
 4        Via: SIP/2.0/UDP 10.4.6.199:5060;branch=z9hG4bK-33212-1-9
 5        To: sut <sip:[email protected]:5080>;tag=YRrWa7c2kH
 6        From: sipp <sip:[email protected]:5060>;tag=1
 7        Call-ID: [email protected]
 8        [Generated Call-ID: [email protected]]
 9        CSeq: 10 BYE
10        Content-Length: 0

结合SIPP测试脚本

可以清晰地看见交互的过程,这个场景文件就是把交互流程规划好了。

  1<?xml version="1.0" encoding="ISO-8859-1" ?>
  2<!DOCTYPE scenario SYSTEM "sipp.dtd">
  3
  4
  5<scenario name="Basic Sipstone UAC">
  6
  7<!-------------------------------------------------------------->
  8<!--              Start Conversation                          -->
  9<!-------------------------------------------------------------->
 10
 11<send retrans="500">
 12    <![CDATA[
 13
 14      INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
 15      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
 16      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
 17      To: sut <sip:[service]@[remote_ip]:[remote_port]>
 18      Call-ID: [call_id]
 19      CSeq: 1 INVITE
 20      Contact: sip:sipp@[local_ip]:[local_port]
 21      Max-Forwards: 70
 22      Subject: Performance Test
 23      Content-Type: application/sdp
 24      Content-Length: [len]
 25
 26v=0
 27o=caller 0 0 IN IP4 10.1.93.116
 28s=MobileVrbt_UEA_User_Caller_18500000000_18600000000
 29i=-
 30c=IN IP4 10.4.6.199
 31t=0 0
 32m=audio 5002 RTP/AVP 8
 33    ]]>
 34</send>
 35
 36<recv response="100" optional="true">
 37</recv>
 38
 39<recv response="200" rtd="true">
 40</recv>
 41
 42<!-------------------------------------------------------------->
 43<!--              Start Pa                                   -->
 44<!-------------------------------------------------------------->
 45<send>
 46    <![CDATA[
 47
 48      ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
 49      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
 50      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
 51      To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
 52      Call-ID: [call_id]
 53      CSeq: 1 ACK
 54      Contact: sip:sipp@[local_ip]:[local_port]
 55      Max-Forwards: 70
 56      Subject: Performance Test
 57      Content-Length: 0
 58
 59    ]]>
 60</send>
 61
 62<pause milliseconds="1000" />
 63
 64<send retrans="500">
 65    <![CDATA[
 66
 67      INFO sip:[service]@[remote_ip]:[remote_port] SIP/2.0
 68      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
 69      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
 70      To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
 71      Call-ID: [call_id]
 72      CSeq: 2 INFO
 73      Contact: sip:sipp@[local_ip]:[local_port]
 74      Max-Forwards: 70
 75      Subject: Performance Test
 76      Content-Type: application/msml+xml
 77      Content-Length: [len]
 78
 79      <?xml version="1.0" encoding="UTF-8"?>
 80      <msml version="1.1">
 81          <dialogstart target="conn:12345" name="12345">
 82              <play barge="true" iterate="1" interval="1" maxtime="5" id="play">
 83                  <audio uri="audio.wav" />
 84                  <playexit>
 85                      <send target="source" event="done" valuelist="play.end play.amt"/>
 86                  </playexit>
 87              </play>
 88          </dialogstart>
 89      </msml>]]>
 90</send>
 91
 92<recv response="200" crlf="true">
 93</recv>
 94
 95<recv request="INFO" crlf="true">
 96</recv>
 97
 98<send>
 99    <![CDATA[
100
101      SIP/2.0 200 OK
102      [last_Via:]
103      [last_From:]
104      [last_To:]
105      [last_Call-ID:]
106      [last_CSeq:]
107      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
108      Content-Length: 0
109
110    ]]>
111 </send>
112
113<!-------------------------------------------------------------->
114<!--              End Conversation                            -->
115<!-------------------------------------------------------------->
116<send retrans="500">
117    <![CDATA[
118
119      BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
120      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
121      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
122      To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
123      Call-ID: [call_id]
124      CSeq: 10 BYE
125      Contact: sip:sipp@[local_ip]:[local_port]
126      Max-Forwards: 70
127      Subject: Performance Test
128      Content-Length: 0
129
130    ]]>
131</send>
132
133<recv response="500" crlf="true" optional="true">
134</recv>
135
136<recv response="200" crlf="true" timeout="2000">
137</recv>
138
139<!-- definition of the response time repartition table (unit is ms)   -->
140<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
141
142<!-- definition of the call length repartition table (unit is ms)     -->
143<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
144
145</scenario>