sipp模擬freepbx分機測試(SIP協議調試)


1、sipp的安裝

1) 在centos 7.2下安裝

yum install make gcc gcc-c++ ncurses ncurses.x86_64 ncurses-devel ncurses-devel.x86_64 openssl lksctp-tools libnet libpcap libpcap-devel libpcap.x86_64 libpcap-devel.x86_64 gsl gsl-devel
cd /root/
wget http://sourceforge.net/projects/sipp/files/sipp/3.4/sipp-3.3.990.tar.gz/download
tar -zxvf sipp-3.3.990.tar.gz
cd sipp-3.3.990/
./configure --with-sctp --with-pcap --with-openssl make && sudo make install
sipp -v

2) 在ubuntu14.04 下有些差異

http://sipp.sourceforge.net/doc3.3/reference.html

http://sipp.sourceforge.net/doc/reference.html

https://github.com/SIPp

tar xvf sipp-3.5.2.tar.gz
cd sipp-3.5.2
sudo apt-get install libsctp-dev lksctp-tools
sudo apt-get install libncurses5-dev
sudo apt-get install libpcap-dev libssl-dev
sudo apt-get install build-essential
./build.sh --with-pcap --with-sctp --with-openssl
make
make install

 

2、sipp撥號測試

先在freepbx上創建好兩個分機103和104

最好是在linux下創建xml腳本文件,因為windows操作之后文檔的編碼格式可能會改變,xml對編碼格式非常敏感。在windows和linux兩邊編輯容易出問題。

1) 主叫賬戶

vi caller.csv

SEQUENTIAL
103;104;[authentication username=103 password=103]

2) 被叫賬號

vi callee.csv

SEQUENTIAL
104;;[authentication username=104 password=104]

3) 注冊腳本

vi regclient_set_c_port.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<scenario name="regclient">
<!--本腳本特為持續性測試使用,如單次使用,建議-p 與-set c_port的端口設為相同-->
<!--執行命令樣例:sipp -sf regc_set_c_port.xml 172.31.231.220:5060 -i 172.31.231.23 -p 5077 -inf caller.csv -m 1 -set c_port 5066-->
    <Global variables="c_port" />
    
    <nop hide="true">
        <action>
            <!--設置EXP的值為3600-->
            <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 made by wangwei
      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>
    <![CDATA[
      REGISTER sip:[remote_ip] SIP/2.0
      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
      [last_From:]
      [last_To:]
      [last_Call-ID:]
      [last_CSeq:]
      Contact: <sip:[field0]@[local_ip]:[$c_port]>
      Max-Forwards: 70
      Subject: Reg Performance Test made by wangwei
      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>

4) 被叫腳本

vi callee_with_bye.xml

<?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 regexp="<sip:(.*)@.*>"
              search_in="hdr"
              header="To: "
              check_it="true"
              assign_to="junk,callee_num" />      
    </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 test made by wangwei
      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 by wangwei
    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>

5) 主叫腳本

vi caller_with_auth.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<scenario name="caller_with_auth">
<!--執行命令樣例:sipp -sf caller_with_auth.xml 47.106.93.236: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="401" 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 by wangwei
      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
        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: 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=sendrecv
        a=ptime:20
    ]]>
</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="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 by wangwei
        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 by wangwei
        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 by wangwei
        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>

6) 按以下步驟運行

#主叫注冊
sipp -sf regclient_set_c_port.xml 47.106.xx.xxx:5060 -i 192.168.247.152 -p 5066 -inf caller.csv -set c_port 5066 -m 1

#被叫注冊
sipp -sf regclient_set_c_port.xml 47.106.xx.xxx:5060 -i 192.168.247.152 -p 5088 -inf callee.csv -set c_port 5088 -m 1

#被叫
sipp -sf callee_with_bye.xml -i 192.168.247.152 -p 5088 -trace_err

#主叫
sudo sipp -sf caller_with_auth.xml 47.106.xx.xxx:5060 -i 192.168.247.152 -p 5066 -inf caller.csv -m 1 -d 10000 -oocsn ooc_default -trace_err

7) 登陸會議室

我在freepbx上創建的會議室號是2018,沒有密碼,直接撥號就能登進去

所以將主叫賬戶caller.csv改成登陸會議室就行

SEQUENTIAL
103;2018;[authentication username=103 password=103]

 

3、其他拓展應用

具體應用看手冊 SIPp3.4中文參考手冊.pdf https://files.cnblogs.com/files/dong1/SIPp3.4%E4%B8%AD%E6%96%87%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C.pdf

 

1) SIPP通過next指定id實現循環

https://blog.csdn.net/voip3261/article/details/10335925

 

參考 https://blog.csdn.net/netluoriver/article/details/21786301

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM