其它:
vim中末行去掉^M: shift: %s/\r//g
vim撤销操作: u
vim恢复撤销: ctrl+r
SIPp官网
SIPp使用手册(中文)
SIPp使用手册(英文)
脚本运行指令
sipp -sf notify_event_reboot_authentication.xml -i 192.168.120.101 192.168.125.119:5084 -m 1 -f 5 -au 3005 -ap s1ptest
-sf 指定运行的脚本
-i 指定SIPp服务器IP(UAC的脚本好需要指定UAS的话机IP、Port,如:192.168.125.119:5084)
-p 指定SIPp服务器端口
-f 指定脚本视图刷新频率
-au 指定authentication username
-ap 指定authentication password
也可以直接在脚本中写死用户名和密码:[authentication username="admin" password="admin1"]
脚本运行视图切换
执行脚本后按数字1-9,切换视图
1:脚本视图,显示脚本的流程和一些重要信息
2:统计视图,显示主要的统计信息
Cumulative:从SIPp运行以来的所有统计信息
Periodic:每次刷新时间里的统计情况
3:区间视图,显示响应时间和呼叫长度的分布区间(脚本中可定义)
<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
4:变量视图,显示变量信息
附件脚本:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario (View Source for full doctype...)>
<scenario name="Basic Sipstone UAC">
<send>
<![CDATA[
NOTIFY sip:[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:[local_ip]:[local_port]>
To: <sip:[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 NOTIFY
Contact: sip:[local_ip]:[local_port]
Max-Forwards: 69
Event:reboot
Content-Type: application/simple-message-summary
Content-Length:[len]
Subscription-State:terminated
]]>
</send>
<recv response="401" auth="true" />
<send>
<![CDATA[
NOTIFY sip:[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:[local_ip]:[local_port]>
To: <sip:[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 2 NOTIFY
Contact: sip:[local_ip]:[local_port]
Max-Forwards: 69
Event:reboot
<!-- [authentication username="admin" password="admin1"] -->
[authentication username password]
Content-Type:application/simple-message-summary
Content-Length:[len]
Subscription-State:terminated
]]>
</send>
<recv response="200" auth="true"/>
脚本编辑
Reference
//抑制未用到的变量,当脚本运行提示有存在未用到的变量时,可以使用该命令来禁用它。
运行脚本提示:
root@gs-desktop:/home/gxv33xx/sipp# sipp -sf uas_two_regexp.xml -i 192.168.120.101
In pcap /home/changli/555.pcap, npkts 8930
max pkt length 1121
base port 50042
2019-02-12 14:50:13.382441 1549954213.382441: Variable $1 is referenced 1 times!
在脚本中添加如下消息,责不再弹出提示
<Reference variables="1" />
多个变量用逗号隔开
<Reference variables="1,2" />
SIPp作为UAS,主动发送Bye,UAC未响应200OK的场景
执行命令:sipp -sf uas_two_regexp.xml -i 192.168.120.101 -m 1
发送的Bye的Request_URI未携带[remote_ip]:[remote_port],主叫未响应200OK
执行命令:sipp -sf uas_two_regexp.xml -i 192.168.120.101 192.168.125.119:5060 -m 1
发送的Bye的Request_URI为 192.168.125.119:5060
remote IP、remote_port可以不添加参数,也可以通过-s参数指定:sipp -sf uas_no_regexp.xml -i 192.168.120.101 -s 192.168.125.119:5060 -m 1
[peer_tag_param]的使用场景
SIPp作为UAC,将UAS响应的To-Tag带入UAC发送的消息中,如下ACK和BYE消息
<send>
<![CDATA[
ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via:SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From:UAC<sip:UAC@[local_ip]:[local_port]>;tag=[call_number]
To:UAS<sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID:[call_id]
CSeq:1 ACK
Contact:<sip:UAC@[local_ip]:[local_port];transport=[transport]>
Max-Forwards:70
Content-Length:0
]]>
</send>
<send retrans="500">
<![CDATA[
BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 2 BYE
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Length: 0
]]>
</send>
注意:sipp使用时分号”;”不用写,[remote_port]>[peer_tag_param],虽然实际数据是需要分号的
在 SIPp 中使用正则表达式可以实现如下功能:
- 提取SIP消息中的内容或者SIP头并存储到变量中以在后续中用到(称之为再注入)
- 检查 SIP 消息中的内容是否满足要求
SIPp作为UAC时,鉴于存在[peer_tag_param]
参数,发送BYE消息并不需要引入变量来再注入以保证To-Tag
的一致性
SIPp作为UAS时,参数[peer_tag_param]
失效,需要引入变量来再注入,以保证To-Tag
的一致【Call-ID、from-tag
以及to-tag
三个值的组合能够唯一标识一次对话】
附件脚本:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<scenario name="UAS response 180">
<!-- By adding rrs="true" (Record Route Sets), the route sets -->
<!-- are saved and used for following messages sent. Useful to test -->
<!-- against stateful SIP proxies/B2BUAs. -->
<recv request="INVITE" crlf="true">
</recv>
<send>
<![CDATA[
SIP/2.0 100 Trying
[last_Via:]
[last_From:]
[last_To:]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: [len]
]]>
</send>
<send>
<![CDATA[
SIP/2.0 180 Ringing
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<pause milliseconds="2000"/>
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=Talk
c=IN IP[media_ip_type] [media_ip]
b=AS:512
t=0 0
m=audio [auto_media_port] RTP/AVP 8 101
a=rtpmap:8 PCMU/8000
a=rtpmap:101 telephone-event/8000
m=video [auto_media_port] RTP/AVP 111
a=rtpmap:111 H264/90000
a=fmtp:111 profile-level-id=42801F; packetization-mode=1
a=sendrecv
]]>
// !!! SIPp作为UAS,引入正则表达式
<action>
<ereg regexp=".*" search_in="hdr" header="From:" check_it="true" assign_to="1"/>
<ereg regexp=".*" search_in="hdr" header="To:" check_it="true" assign_to="2"/>
<ereg regexp=".*" search_in="hdr" header="Via:" check_it="true" assign_to="3"/>
</action>
</send>
<recv request="ACK" >
</recv>
<nop>
<action>
<exec play_pcap_video="/home/changli/555.pcap"/>
</action>
</nop>
<pause milliseconds="5000"/>
<send retrans="500">
<![CDATA[
BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
// !!! SIPp作为UAS,引入变量
Via: [$3]
From:[$2]
To:[$1]
Call-ID: [call_id]
Cseq:2 BYE
Contact: <sip:125@[local_ip]:[local_port]>
Max-Forwards: 70
Content-Length:[len]
]]>
</send>
<recv response="200" rrs="true">
</recv>
<!-- Keep the call open for a while in case the 200 is lost to be -->
<!-- able to retransmit it if we receive the BYE again. -->
<pause milliseconds="4000"/>
<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
</scenario>
SDP在Message Body中,与头域所在的Message Header之间有一个换行符
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0 //协议的版本信息,目前只有版本0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] //owner/creator和session信息格式:<用户名> <会话id> <版本> <网络类型> <地址类型> <地址>
s=Talk //会话名称
c=IN IP[media_ip_type] [media_ip] //连接信息 格式:<网络类型> <地址类型> <地址>
b=AS:512 //本端带宽信息 格式:<类型>:<带宽>
t=0 0 //起始时间 格式:<开始时间> <结束时间>
a=sendrecv //媒体属性 sendrecv、sendonly、recvonly、inactive
m=audio [auto_media_port] RTP/AVP 8 101 //媒体信息 格式:<媒体类型> <媒体端口> <传输协议> <编码信息>
a=rtpmap:8 PCMU/8000 //媒体属性。可选
a=rtpmap:101 telephone-event/8000 //媒体属性。可选
m=video [auto_media_port] RTP/AVP 111 //媒体信息 格式:<媒体类型> <媒体端口> <传输协议> <编码信息>
a=rtpmap:111 H264/90000 //媒体属性。可选
a=fmtp:111 profile-level-id=42801F; packetization-mode=1 //媒体属性。可选
]]>
</send>
//通过Wireshark保存单向的RTP数据,且保存为/Wireshark/tcpdump... - nanosecond pcap
<nop>
<action>
<exec play_pcap_video="/home/changli/555.pcap"/> //视频流:play_pcap_video 音频流:play_pcap_audio
</action>
</nop>
<pause milliseconds="5000"/> //时长