知识必备:Linux操作系统、Sip协议
yum -y install gcc-c++
yum -y install ncurses-devel
yum -y install openssl-devel
# 为了安装libpcap,还需要安装以下两个开发包:
yum -y install flex
yum -y install bison
下载libcap :http://www.tcpdump.org/release/
wget http://www.tcpdump.org/release/libpcap-1.9.1.tar.gz
tar zxvf libcapXXX.gz
login as root , go to folder libpcapXXX and install it. run:
./configure
make && make install
下载libnet :
tar zxvf libnetXXX.gz
# 切换root , 去libpnetXXX目录:
./configure
. /make
./make install
cd /home/dev
wget https://github.com/SIPp/sipp/releases/download/v3.6.0/sipp-3.6.0.tar.gz
安装方法:
支持PCAP 声音文件播放,而且支持密码验证支持:(支持407 auth验证支持)
# tar -zxvf sipp-xxx.tar
# cd sipp-xxx
#编译配置:
./configure --with-pcap --with-openssl
#编译&&安装:
make && make install
#确认是否安装成功:
sipp -v
第一行出现: SIPp v3.6.0-TLS-PCAP-RTPSTREAM 则安装成功
# 打开/etc/security/limits.conf 文件并添加如下内容:
* soft nofile 32768
* hard nofile 65535
# 打开/etc/pam.d/login 文件并添加如下内容:
session required /lib/security/pam_limits.so
#永久更改文件描述符所能支持的最大值:
ulimit -s unlimited
ulimit -a
cd /etc/freeswitch/autoload_configs
vim switch.conf.xml
# 修改
<param name="max-sessions" value="100000"/>
<param name="sessions-per-second" value="10000"/>
1、cd /etc/freeswitch/dialplan
2、vim public.xml
改为:
<extension name="Balance_load">
<condition field="destination_number" expression="^([2-6][0-9][0-9][0-9])$">
<action application="export" data="dialed_extension=$1"/>
<action application="set" data="sip_h_History-Info=${sip_history_info}"/>
<action application="set" data="hangup_after_bridge=true"/>
<action application="bridge" data="user/${dialed_extension}@${domain_name}"/>
</condition>
</extension>
3、vim default.xml
改为:
<extension name="public_extensions">
<condition field="destination_number" expression="^([2-6][0-9][0-9][0-9])$">
<action application="transfer" data="$1 XML default"/>
</condition>
</extension>
cd /etc/freeswitch/directory/default
# 3000 5999为自己需要的用户
for i in `seq 2000 5999`; do sed -e "s/1000/$i/g" 1000.xml > $i.xml ; done
cd /etc/freeswitch/autoload_configs
vim acl.conf.xml
# 进入编辑模式修改
<list name="domains" default="deny">
<!-- domain= is special it scans the domain from the directory to build the ACL -->
<node type="allow" domain="$${domain}"/>
<!-- use cidr= if you wish to allow ip ranges to this domains acl. -->
<node type="allow" cidr="192.168.200.0/24"/>
<!--新增此行. -->
<node type="allow" cidr="10.10.81.0/24"/>
</list>
注册:
sipp -sf regclient_set_c_port.xml 10.3.18.174:5060 -i 10.3.18.172 -p 26000 -inf uac2000_aibus_4000.csv -r 500 -rp 1000 -l 500 -m 4000
呼叫:
sipp -sf caller_with_auth_aibus.xml 10.3.18.174:5060 -i 10.3.18.172 -p 26000 -inf uac2000_aibus_4000.csv -r 80 -rp 1000 -l 80 -m 1000 -d 30000 -oocsn ooc_default -aa -trace_msg -trace_err -trace_screen
-i: 本地ip,为'Contact:','Via:', 和 'From:' 头部信息设置本地IP,在脚本中用[local_ip]引入
-p:设置本地端口号,默认是由系统随机选择空闲的端口号;
-sf:引入脚本文件,根据需要模拟的呼叫流程编写
-inf:在通话场景中使用外部csv文件引入数据;文件的第一行说明了后面数据的读入方式,常用的有:顺序 (SEQUENTIAL), 随机 (RANDOM), 或用户(USER)顺序;第一行对应一个通话,它们由一个或多个’;’分隔数据字段,这些字段可以在xml场景文件中使用[field0], [field1], ...来调用;多个csv文件,可以同时使用(语法:-inf f1.csv -inf f2.csv ...)
xx:xx:xx:xx:5060:Freeswitch服务端IP及freeswitch使用的端口;
-r:并发数量
-rp:并发的时间,单位ms,例如:-r 800 -rp 1000,就是每秒800并发
-l:设置同时呼叫的最大数目;一旦达到此值,流量将被限制直到打的通话数下降;默认值3*call_duration(s)*rate
-m:通话总数,当设置的通话数完成时,停止测试并退出;
-d:自定义的通话时长,单位ms
-aa:针对INFO, UPDATE 和 NOTIFY消息,进行200 OK自动回复应答;
-oocsn:Load out-of-call scenario
-trace_msg:在<场景文件名>_<pid>_messages.log中显示发送和接收的SIP消息;调试时可增加,正试性能测试时,可取消,以免日志量太大影响本地性能;
-trace_screen:在退出SIPp时,把屏蔽上的统计信息写入<场景名>_<pid>_screens.log文件中;在后台模式(-bq选项)时,这对于得到最终状态报告很有用;
-trace_err:跟踪所有非期望的消息到<场景文件名>_<pid>_errors.log;
SEQUENTIAL
2000;2050;[authentication username=2000 password=1234]
2001;2051;[authentication username=2001 password=1234]
2002;2052;[authentication username=2002 password=1234]
2003;2053;[authentication username=2003 password=1234]
2004;2054;[authentication username=2004 password=1234]
...
1、csv格式创建后用Notepad++打开,否则改编编码导致失败
2、第一行代表执行顺序:包括SEQUENTIAL和RANDOM
3、[filed0]代表第1列,[filed1]代表第2列
SEQUENTIAL
2050;;[authentication username=2050 password=1234]
2051;;[authentication username=2051 password=1234]
2052;;[authentication username=2052 password=1234]
2053;;[authentication username=2053 password=1234]
2054;;[authentication username=2054 password=1234]
...
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<scenario name="regclient">
<Global variables="c_port" />
<nop hide="true">
<action>
<assignstr assign_to="EXP" value="3600" />
</action>
</nop>
<send>
<![CDATA[
REGISTER sip:[remote_ip] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:[field0]@[remote_ip]>;tag=acknnkkg.[call_number]
To: <sip:[field0]@[remote_ip]>
Call-ID: [call_id]
CSeq: 1 REGISTER
Contact: <sip:[field0]@[local_ip]:[$c_port]>
Max-Forwards: 70
Subject: Reg Performance Test
user-agent: SIPp client
Expires: [$EXP]
Content-Length: 0
]]>
</send>
<recv response="401" optional="true" auth="true" next="auth" >
</recv>
<recv response="403" optional="true" next="END">
</recv>
<recv response="404" optional="true" next="END">
</recv>
<recv response="200" next="END" timeout="5000">
</recv>
<label id="auth" />
<send retrans="500">
<![CDATA[
REGISTER sip:[field0]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: [field0] <sip:[field0]@[remote_ip]:[remote_port]>;tag=[call_number]
To: [field0] <sip:[field0]@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 2 REGISTER
Contact: sip:[field0]@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Reg Performance Test
user-agent: SIPp client
Expires: [$EXP]
[field2]
Content-Length: 0
]]>
</send>
<recv response="200" next="END" timeout="5000">
</recv>
<label id="END"/>
<nop hide="true">
</nop>
<!--<Reference variables="microseconds,seconds" />-->
<!-- Definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="50, 200"/>
<!-- Definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="500, 5000"/>
</scenario>
sipp -sf regclient_set_c_port.xml 192.168.200.101:5060 -i 192.168.200.101 -p 26045 -inf uac500.csv -r 30 -rp 1000 -l 100 -m 500
sipp -sf regclient_set_c_port.xml 192.168.200.101:5060 -i 192.168.200.101 -p 26048 -inf uas500.csv -r 30 -rp 1000 -l 100 -m 500
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<scenario name="callee_with_bye">
<!--用于模拟局内被叫侧用户的正常业务流程
媒体类型:PCMU
呼叫挂机:主叫方(60秒超时后主动发BYE拆话)-->
<!--执行命令样例:sipp -sf callee_with_bye.xml -p 5068-->
<!--定义全局状态机,如果收到OPTIONS消息,则跳转至options标签处-->
<recv request="OPTIONS" optional="global" next="options">
</recv>
<recv request="INVITE">
<!--参数caller_num、callee_num和caller_tag用于主叫未挂机,BYE接收超时主动发BYE的流程-->
<action>
<ereg regexp="sip:(.*)@(.*)>;tag=(.*)"
search_in="hdr"
header="From: "
check_it="true"
assign_to="junk,caller_num,domain,caller_tag" >
</ereg>
<ereg regexp="sip:(.*)@.*>"
search_in="hdr"
header="To: "
check_it="true"
assign_to="junk,callee_num" >
</ereg>
</action>
</recv>
<!--增加间隔20ms,避免偶现系统不发送100响应的问题-->
<pause hide="true" milliseconds="20"/>
<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: 0
]]>
</send>
<!--增加间隔20ms,避免偶现系统不发送180响应的问题-->
<pause hide="true" milliseconds="20"/>
<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>
<!--设置发送200后等待ACK的重传周期为1秒,如果1秒内收不到ACK则进行200的重传-->
<send retrans="1000" start_rtd="ack">
<![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=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0 8
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=ptime:20
]]>
</send>
<!--设置等待ACK的超时定时器为30秒,如果30秒内收不到ACK则呼叫超时失败而结束-->
<recv request="ACK" rtd="ack" timeout="30000" />
<!--使用rtp_stream循环播放PCMA音频
<nop hide="true">
<action>
<exec rtp_stream="pcap/g711a.pcap,-1,0"/>
</action>
</nop>
-->
<!--使用rtp_stream循环播放PCMU音频
<nop hide="true">
<action>
<exec rtp_stream="pcap/g711u.pcap,-1,0"/>
</action>
</nop>
-->
<!--使用play_pcap单次播放PCMA音频-->
<nop hide="true">
<action>
<exec play_pcap_audio="pcap/g711a.pcap"/>
</action>
</nop>
<!--使用play_pcap单次播放PCMU音频
<nop hide="true">
<action>
<exec play_pcap_audio="pcap/g711u.pcap"/>
</action>
</nop>
-->
<recv request="BYE" timeout="60000" ontimeout="send_bye"/>
<send next="END">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<label id="options"/>
<send next="END" >
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_Call-ID:]
[last_From:]
[last_To:];tag=telpo-options[call_number]
[last_CSeq:]
[last_Contact:]
user-agent: SIPP version [sipp_version]
subject: reg performance
link-status: I am alive
Content-Length: 0
]]>
</send>
<!--主叫未挂机,BYE接收超时,被叫主动发BYE-->
<label id="send_bye"/>
<send start_rtd="bye">
<![CDATA[
BYE sip:[$caller_num]@[local_ip]:[local_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: "[$caller_num]" <sip:[$caller_num]@[local_ip]>;tag=[call_number]
To: "[$callee_num]"<sip:[$callee_num]@[local_ip]>;tag=[$caller_tag]
Call-ID: [call_id]
CSeq: 2 BYE
Max-Forwards: 70
Subject: normal call scenario
Content-Length: 0
]]>
</send>
<recv response="200" rtd="bye">
</recv>
<label id="END"/>
<Reference variables="junk,domain" />
<!-- definition of the response time repartition table (unit is ms)-->
<ResponseTimeRepartition value="50, 200"/>
<!-- definition of the call length repartition table (unit is ms)-->
<CallLengthRepartition value="500, 1000, 10000"/>
</scenario>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<scenario name="caller_with_auth">
<!--执行命令样例:sipp -sf caller_with_auth.xml xx.x.x.xx:5060 -p 5066 -inf caller.csv -m 1 -d 10000 -oocsn ooc_default-->
<!--发送INVITE消息,设定重传定时器为1000ms,同时启动定时器invite-->
<send retrans="1000" start_rtd="invite">
<![CDATA[
INVITE sip:[field1]@[remote_ip] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: "[field0]" <sip:[field0]@[remote_ip]>;tag=[call_number]zhg8
To: "[field1]"<sip:[field1]@[remote_ip]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: <sip:[field0]@[local_ip]:[local_port]>
User-Agent: SIPp client mode version [sipp_version]
Allow: INVITE,PRACK,ACK,UPDATE,CANCEL,BYE,OPTIONS,INFO,SUBSCRIBE,REFER,NOTIFY
Max-Forwards: 70
Content-Type: application/sdp
Content-Length: [len]
v=0
o=SIPp [pid][call_number] 8[pid][call_number]8 IN IP[local_ip_type] [local_ip]
s=SIPp Normal Call Test
t=0 0
m=audio [media_port] RTP/AVP 0 8
c=IN IP[media_ip_type] [media_ip]
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=ptime:20
a=sendrecv
]]>
</send>
<recv response="100" optional="true">
</recv>
<!-- <recv response="401" auth="true"> -->
<!-- </recv> -->
<!-- 部分呼叫鉴权可能为407 -->
<!-- <recv response="407" option="true" auth="true">
</recv>
<send>
<![CDATA[
ACK sip:[field1]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch-3]
From: "[field0]" <sip:[field0]@[remote_ip]>;tag=[call_number]zhg8
To: "[field1]"<sip:[field1]@[remote_ip]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
Contact: <sip:[field0]@[local_ip]:[local_port]>
Max-Forwards: 70
Subject: normal call scenario
user-agent: SIPp client mode version [sipp_version]
Content-Length: 0
]]>
</send>
<send retrans="1000" start_rtd="invite">
<![CDATA[
INVITE sip:[field1]@[remote_ip] SIP/2.0
[last_Via:]
From: "[field0]" <sip:[field0]@[remote_ip]>;tag=[call_number]zhg8
To: "[field1]"<sip:[field1]@[remote_ip]>
Call-ID: [call_id]
CSeq: 2 INVITE
[field2]
Contact: <sip:[field0]@[local_ip]:[local_port]>
User-Agent: SIPp client mode version [sipp_version]
Allow: INVITE,PRACK,ACK,UPDATE,CANCEL,BYE,OPTIONS,INFO,SUBSCRIBE,REFER,NOTIFY
Max-Forwards: 70
Content-Type: application/sdp
Content-Length: [len]
v=0
o=SIPp [pid][call_number] 8[pid][call_number]8 IN IP[local_ip_type] [local_ip]
s=SIPp Normal Call Test
t=0 0
m=audio [media_port] RTP/AVP 0 8
c=IN IP[media_ip_type] [media_ip]
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=ptime:20
a=sendrecv
]]>
</send>
<!--1xx响应均为可选接收消息,且接收到临时响应后,即可停止invite定时器的计时-->
<!--收到4xx/5xx错误响应后,直接进入呼叫失败-->
<!-- <recv response="100" optional="true" rtd="invite">
</recv>
<recv response="183" optional="true" rtd="invite" next="normal">
</recv>
<recv response="403" optional="true" rtd="invite" next="err_ack">
</recv>
<recv response="407" optional="true" rtd="invite" next="err_ack">
</recv>
<recv response="415" optional="true" rtd="invite" next="err_ack">
</recv>
<recv response="480" optional="true" rtd="invite" next="err_ack">
</recv>
<recv response="486" optional="true" rtd="invite" next="err_ack">
</recv>
<recv response="500" optional="true" rtd="invite" next="err_ack">
</recv>
<recv response="503" optional="true" rtd="invite" next="err_ack">
</recv> -->
-->
<recv response="180" optional="true" rtd="invite" next="normal">
</recv>
<label id="normal"/>
<recv response="200" rtd="invite">
<action>
<ereg regexp="m=audio ([0-9]*)"
search_in="msg"
check_it="true"
assign_to="junk,callee_media_port" />
</action>
</recv>
<nop hide="true">
</nop>
<send>
<![CDATA[
ACK sip:[field1]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: "[field0]" <sip:[field0]@[remote_ip]>;tag=[call_number]zhg8
To: "[field1]"<sip:[field1]@[remote_ip]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 2 ACK
Contact: <sip:[field0]@[local_ip]:[local_port]>
Max-Forwards: 70
Subject: normal call scenario
user-agent: SIPp client mode version [sipp_version]
Content-Length: 0
]]>
</send>
<!--使用rtp_stream循环播放PCMA音频
<nop hide="true">
<action>
<exec rtp_stream="pcap/g711a.pcap,-1,0"/>
</action>
</nop>
-->
<!--使用rtp_stream循环播放PCMU音频
<nop hide="true">
<action>
<exec rtp_stream="pcap/g711u.pcap,-1,0"/>
</action>
</nop>
-->
<!--使用play_pcap单次播放PCMA音频-->
<nop hide="true">
<action>
<exec play_pcap_audio="pcap/g711a.pcap"/>
</action>
</nop>
<!--使用play_pcap单次播放PCMU音频
<nop hide="true">
<action>
<exec play_pcap_audio="pcap/g711u.pcap"/>
</action>
</nop>
-->
<!--媒体流传输完毕后,暂停发送BYE结束呼叫,在执行命令中增加参数-d 指定暂停时间:如-d 10000暂停10秒-->
<pause />
<send start_rtd="bye">
<![CDATA[
BYE sip:[field1]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: "[field0]" <sip:[field0]@[remote_ip]>;tag=[call_number]zhg8
To: "[field1]"<sip:[field1]@[remote_ip]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 3 BYE
Max-Forwards: 70
Subject: normal call scenario
Content-Length: 0
]]>
</send>
<recv response="200" rtd="bye" next="END">
</recv>
<!--异常结束,复用err_ack流程-->
<label id="err_ack"/>
<send>
<![CDATA[
ACK sip:[field1]@[remote_ip]:[remote_port] SIP/2.0
[last_Via:]
From: "[field0]" <sip:[field0]@[remote_ip]>;tag=[call_number]zhg8
To: "[field1]"<sip:[field1]@[remote_ip]>[peer_tag_param]
[last_Call-ID:]
CSeq: 2 ACK
Max-Forwards: 70
Subject: normal call scenario
user-agent: SIPp client mode version [sipp_version]
Content-Length: 0
]]>
</send>
<!--正常结束-->
<label id="END"/>
<nop hide="true">
</nop>
<!--如果存在定义了但未被使用的变量,可以在下面语句的双引号中增加,避免运行时报错-->
<Reference variables="junk,callee_media_port" />
<!--definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="50, 200,1000,2000,4000,10000"/>
<!--definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="500, 1000, 10000"/>
</scenario>
# 1、启动主叫注册
sipp -sf regclient_set_c_port.xml 192.168.200.101:5060 -i 192.168.200.101 -p 26045 -inf uac500.csv -r 30 -rp 1000 -l 100 -m 500
# 2、启动被叫注册
sipp -sf regclient_set_c_port.xml 192.168.200.101:5060 -i 192.168.200.101 -p 26048 -inf uas500.csv -r 30 -rp 1000 -l 100 -m 500
#3、等待被叫注册结束,启动被叫
sipp -sf callee_with_bye.xml -i 192.168.200.101 -p 26048 -trace_err
# 4、等待被叫执行后,执行主叫
sipp -sf caller_with_auth.xml 192.168.200.101:5060 -i 192.168.200.101 -p 26045 -inf uac500.csv -r 500 -rp 1000 -l 5000 -m 5000 -d 60000 -oocsn ooc_default -trace_err
并发数(CC) = 平均通话时长 * CPS