3.    使用Sipp

Sipp 的本质是可以条件反应,发送各种包.

如果拆开一个Sipp 的xml 场景文件就可以了解其实是一个自动的脚本可以发送sip消息.

Csv文件可以使用预制好的号码变量,减轻工作量.

Reg:

./sipp –sf reg.xml –m 1 –i 172.16.44.88–p 5062 –inf reg2.csv 172.16.44.110 –trace_err

Uac:

./sipp –sf branchc.xml –m 10 –l 10 –i172.16.44.88 –p 5063 –inf call.csv 172.16.44.110 –trace_err

Uas:

./sipp –sf branchs.xml –i 172.16.44.88–p 5062 –inf reg2.csv 172.16.44.110 –aa –trace_err

对于asterisk来说,peer 方式才是需要注册的,为了保证到asterisk的呼叫可以找到该peer,而user方式主要是用来呼出,验证方式是接收到invite之后再回407,带账号密码再invite。

所以我们一般给asterisk 的分机使用friend方式添加,主叫就不需要reg这个环节,UAC的csv内容一般为:

 

 

[plain]  view plain copy
 
  1. SEQUENTIAL  #顺序模式,还有一种随机为 RANDOM  
  2. 444;555;[authentication username=444 password=aaa]  
  3. # 第一个为主叫号码,第二个为被叫号码,第三个为验证的账号与密码  
  4. 445;556;[authentication username=445 password=aaa]  
  5. 446;557;[authentication username=446 password=aaa]  

而不管是在ONDU还是在Asterisk,被叫都是需要注册到服务器上,告知服务器UA的地址,才可以让呼叫到达。但是UAS 是一个接收的脚本,REG是一个发送的脚本,一个端口是不能一次跑两个脚本的

虽然可以把REG写进UAS中,但是如果一个通话时间过长还是可能引起问题,还要考虑。

所以被叫需要先使用脚本REG注册到Server,再开启UAS.Csv文件中不同的地方就在于没有被叫号码.

[plain]  view plain copy
 
  1. SEQUENTIAL  #顺序模式,还有一种随机为 RANDOM  
  2. 555;[authentication username=555 password=aaa]  
  3. # 只是没有被叫号码,其他是一样的.  
  4. 556;[authentication username=556 password=aaa]  
  5. 557;[authentication username=557 password=aaa]  

还有一些要注意的地方:

1.    标准的脚本就是一次简单的呼叫,没有验证,验证需要用脚本branchc/branchs

2.    Asterisk中sip.conf有一个配置, canreinvite = yes 是默认,代表主被叫会直接重定向语音RTP流,需要在账号或者全局中设置成canreinvite=no,保证语音流正常

3.    Reg脚本里可以设置一次注册的最长时间,为3600s,Asterisk里可以设置注册一次的时间有效期,而ONDU则可以直接手动添加号码注册,把时间设置长一点就好了

4.    TG只要对上Trunk,使用 uac_base / uas_base 也是可以的

5.    CSV文件不能有空行 , xml 必须严格尊崇协议格式


 

现在来分析一下xml 脚本:

 

[html]  view plain copy
 
  1. <?xml version="1.0" encoding="ISO-8859-1" ?>  
  2. <!DOCTYPE scenario SYSTEM "sipp.dtd">  
  3. <!-- This program is free software; you can redistribute it and/or      -->  
  4. <!-- modify it under the terms of the GNU General Public License as     -->  
  5. <!-- published by the Free Software Foundation; either version 2 of the -->  
  6. <!-- License, or (at your option) any later version.                    -->  
  7. <!--                                                                    -->  
  8. <!-- This program is distributed in the hope that it will be useful,    -->  
  9. <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of     -->  
  10. <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      -->  
  11. <!-- GNU General Public License for more details.                       -->  
  12. <!--                                                                    -->  
  13. <!-- You should have received a copy of the GNU General Public License  -->  
  14. <!-- along with this program; if not, write to the                      -->  
  15. <!-- Free Software Foundation, Inc.,                                    -->  
  16. <!-- 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA             -->  
  17. <!--                                                                    -->  
  18. <!--                 Sipp 'uac' scenario with pcap (rtp) play           -->  
  19. <!--                                                                    -->  
  20. <scenario name="UAC with media">  
  21.   <!-- In client mode (sipp placing calls), the Call-ID MUST be         -->  
  22.   <!-- generated by sipp. To do so, use [call_id] keyword.                -->  
  23.   <send retrans="500">  
  24.     <![CDATA[ 
  25.       INVITE sip:[field1]@[remote_ip]:[remote_port] SIP/2.0 
  26.       Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] 
  27.       From: [field0] <sip:[field0]@[local_ip]:[local_port]>;tag=[call_number] 
  28.       To: [field1] <sip:[field1]@[remote_ip]:[remote_port]> 
  29.       Call-ID: [call_id] 
  30.       CSeq: 1 INVITE 
  31.       Contact: sip:[field0]@[local_ip]:[local_port] 
  32.       Max-Forwards: 70 
  33.       Subject: Performance Test 
  34.       Content-Type: application/sdp 
  35.       Content-Length: [len] 
  36.       v=0 
  37.       o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] 
  38.       s=- 
  39.       c=IN IP[local_ip_type] [local_ip] 
  40.       t=0 0 
  41.       m=audio [auto_media_port] RTP/AVP 8 
  42.       a=rtpmap:8 PCMA/8000 
  43.       a=rtpmap:101 telephone-event/8000 
  44.       a=fmtp:101 0-11,16 
  45.     ]]>  
  46.   </send>  
  47.    
  48.   <recv response="407" auth="true">  
  49.   </recv>  
  50.   <!-- By adding rrs="true" (Record Route Sets), the route sets         -->  
  51.   <!-- are saved and used for following messages sent. Useful to test   -->  
  52.   <!-- against stateful SIP proxies/B2BUAs.                             -->  
  53.   <!-- Packet lost can be simulated in any send/recv message by         -->  
  54.   <!-- by adding the 'lost = "10"'. Value can be [1-100] percent.       -->  
  55.   <send>  
  56.     <![CDATA[ 
  57.       ACK sip:[field1]@[remote_ip]:[remote_port] SIP/2.0 
  58.       Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] 
  59.       From: [field0] <sip:[field0]@[local_ip]:[local_port]>;tag=[call_number] 
  60.       To: [field1] <sip:[field1]@[remote_ip]:[remote_port]>[peer_tag_param] 
  61.       Call-ID: [call_id] 
  62.       CSeq: 1 ACK 
  63.       Contact: sip:[field0]@[local_ip]:[local_port] 
  64.       Max-Forwards: 70 
  65.       Subject: Performance Test 
  66.       Content-Length: 0 
  67.     ]]>  
  68.   </send>  
  69.    
  70.   <send retrans="500">  
  71.   <![CDATA[ 
  72.       INVITE sip:[field1]@[remote_ip]:[remote_port] SIP/2.0 
  73.       Via: SIP/2.0/[transport] [local_ip]:[local_port] 
  74.       From: [field0] <sip:[field0]@[local_ip]:[local_port]>;tag=[call_number] 
  75.       To: [field1] <sip:[field1]@[remote_ip]:[remote_port]> 
  76.       Call-ID: [call_id] 
  77.       CSeq: 2 INVITE 
  78.       Contact: sip:[field0]@[local_ip]:[local_port] 
  79.       [field2] 
  80.       Max-Forwards: 70 
  81.       Subject: Performance Test 
  82.       Content-Type: application/sdp 
  83.       Content-Length: [len] 
  84.       v=0 
  85.       o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] 
  86.       s=- 
  87.       t=0 0 
  88.       c=IN IP[media_ip_type] [media_ip] 
  89.       m=audio [auto_media_port] RTP/AVP 0 
  90.       a=rtpmap:0 PCMU/8000 
  91.     ]]>  
  92.  </send>  
  93.  <recv response="100" optional="true">  
  94.  </recv>  
  95.  <recv response="180" optional="true">  
  96.  </recv>  
  97.    
  98.  <recv response="200" rtd="true" crlf="true">  
  99.  </recv>  
  100.    
  101.   <!-- Play a pre-recorded PCAP file (RTP stream)                       -->  
  102.   <!-- Pause 8 seconds, which is approximately the duration of the      -->  
  103.   <!-- PCAP file                                                        -->  
  104.   <pause milliseconds="2000"/>  
  105.   <!-- Play an out of band DTMF '1'  '#'                               -->  
  106.   <nop>  
  107.     <action>  
  108.       <exec play_pcap_audio="pcap/dtmf_2833_1.pcap"/>  
  109.     </action>  
  110.   </nop>  
  111.   <pause milliseconds="950"/>  
  112.   <nop>  
  113.     <action>  
  114.       <exec play_pcap_audio="pcap/dtmf_2833_pound.pcap"/>  
  115.     </action>  
  116.   </nop>  
  117.   <pause milliseconds="1500"/>  
  118.   <nop>  
  119.     <action>  
  120.       <exec play_pcap_audio="pcap/g711a.pcap"/>  
  121.     </action>  
  122.   </nop>  
  123.   <pause milliseconds="12000"/>  
  124.   <!-- The 'crlf' option inserts a blank line in the statistics report. -->  
  125.   <send retrans="500">  
  126.     <![CDATA[ 
  127.       BYE sip:[field1]@[remote_ip]:[remote_port] SIP/2.0 
  128.       Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] 
  129.       From: [field0] <sip:[field0]@[local_ip]:[local_port]>;tag=[call_number] 
  130.       To: [field1] <sip:[field1]@[remote_ip]:[remote_port]>[peer_tag_param] 
  131.       Call-ID: [call_id] 
  132.       CSeq: 2 BYE 
  133.       Contact: sip:[field0]@[local_ip]:[local_port] 
  134.       Max-Forwards: 70 
  135.       Subject: Performance Test 
  136.       Content-Length: 0 
  137.     ]]>  
  138.   </send>  
  139.   <recv response="200" crlf="true">  
  140.   </recv>  
  141.   <pause milliseconds="8000"/>  
  142.   <!-- definition of the response time repartition table (unit is ms)   -->  
  143.   <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>  
  144.   <!-- definition of the call length repartition table (unit is ms)     -->  
  145.   <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>  
  146. </scenario>  


 

就是用 XML 语言发 特定的SIP消息, 并对特定的 Sip消息给予回应.