Search This Blog........

Wednesday, 13 July 2016

Python unit testing

Python Unit testing tutorial



Unit test: 
Using python default unittest allows you to write more robust tests.

The unittest module  provides a runner to execute tests i.e, grouping tests in to logical unit and the concept of setup and teardown.
Lets see one example.....,
import unittest

class Test(unittest.TestCase):
    def setUp(self):
        self.num=1

    def test_math(self):
        self.assertEqual(self.num,1)


if __name__ ==  '__main__':
    unittest,main()   


Explanation
A testcase is class that inherits from unittest.
The function(def) inside class all require a mandatory parameter named self 
When running unittest.main(), that take care of finding all the testcases. Calling setUp method first (whose name start with test) and then finally calling method called tearDown()


 

Sunday, 19 June 2016

Installation problems

Seagull tool:
 yum groupinstall 'Development Tools' -y

Seagull tool...

Seagull

Seagull Installation: 

          1) Download and install seagull using below steps.
wget https://sourceforge.net/projects/gull/files/seagull/1.8.2/seagull-1.8.2-Linux_RHEL6U1_X86_64.tar.gz/ 
tar -xvf  seagull-1.8.2-Linux_RHEL6U1_X86_64.tar.gz
cd packages
rpm -ivh *.rpm

If you are facing any problems in installing seagull click below link.
Follow below procedure
 yum groupinstall 'Development Tools' -y
sudo rpm -ivh  rpm -ivh seagull-core-1.8.2-linux-2.6-intel.rpm
sudo rpm -ivh seagull-diameter-protocol-1.8.2-linux-2.6-intel.rpm

Still facing problems paste the errors in the comments section. 


Testing the installation:

-> Go to cd /opt/seagull/ directory and type ls.
-> You should see below dir's and files.
config  diameter  doc  logs  run  scenario  sip

Installation is completed............. 



Generating the traffic: 

Before generating the traffic lets discuss about below files.

 
 
/opt/seagull/doc directory contains documentation for all the installed protocols (if available) /opt/seagull/[protocol]/doc directory contains documentation for a specific protocol
NOTE: As we are focused on Diameter, we’ll use the diameter protocol from now on for this example.
/opt/seagull/diameter/config directory contains the XML configuration files and dictionary files /opt/seagull/diameter/logs directory contains is initially empty but will contain execution log files /opt/seagull/diameter/run directory contains the shell scripts used to run the client and server in order to execute your scenarios /opt/seagull/diameter/scenario directory contains the scenarios

Step 1. Define the client configuration

Define the correct client configuration in
/opt/seagull/diameter/config/conf.client.xml

Step 2. Define the dictionary

Define the correct dictionary file in
/opt/seagull/diameter/config/base_ro.xml

Step 3. Define the scenario

Define the correct scenario file
/opt/seagull/diameter/scenario/ccr-cca.client.xml

Step 4. Create the run script

Edit the run script and make sure it uses the correct files that you have created
cd /opt/seagull/diameter/run
vi start_client_gx_ccr_cca.ksh
#!/bin/ksh
export LD_LIBRARY_PATH=/usr/local/bin seagull -conf ../config/conf.client.xml -dico ../config/base_ro.xml -scen ../scenario/ccr-cca.client.xml -log ../logs/ccr-cca.client.log -llevel ET

Step 5. Run the test!

Execute the run script to start the client
cd /opt/seagull/diameter/run
./start_client_gx_ccr_cca.ksh
   

 

Friday, 17 June 2016

Info about SIPP automation load testing tool..

How to install sipp in linux?


1. Download the stable linux verison from the sipp source web.


Example: I downloaded "sipp-3.3.tar.gz" file and copied it to the ROOT folder of my linux machine.
2. Execute command "gunzip sipp-XXX.tar.gz" command, here i used command 'gunzip sipp-3.3.tar.gz'
3. Then execute command 'tar -xvf sipp-xxx.tar' command, here i used command 'tar -xvf sipp.3.3.tar' to extrac the sipp tar file.
4. The folder sipp.xxx contains all th extracted  files and available in the same location.  Go to the folder 'cd sipp-xxx'
5. Now execute the command 'make'  - Just executig 'make' command without any extensions means we are using SIPP without TLS and Authentication support.
a) Execute command 'make ossl' for TLS & Authentication support.
  b) Execute command 'make pcapplay' for PCAP Play & No authentication support.
  c) Execute command 'make pcapplay_ossl' for PCAP Play & Authentication support.
 I had executed the command 'yum install ncurses-dlevel ncurses' to install ncurses package (Note:- Linux machine should be connected with internet for yum update )
7. I've executed the 'make' command again to complete the sipp installation.

yum install ncursers-dlevel ncursers

                                            Starting SIPP


Run sipp with embedded server (uas) scenario:
# ./sipp -sn uas
On the same host, run sipp with embedded client (uac) scenario
# ./sipp -sn uac 127.0.0.1

Creating REGISTER request scenario:

Step:1 Create XML file.., below is the code

<?xml version="1.0" encoding="ISO-8859-2" ?>

<!--  Use with CSV file struct like: 3000;192.168.1.106;[authentication username=3000 password=3000];
      (user part of uri, server address, auth tag in each line)
-->

<scenario name="register_client">
  <send retrans="500">
retrans=500 means the TI timer set to 500 ms
    <![CDATA[

      REGISTER sip:[remote_ip] SIP/2.0
      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
      From: <sip:[field0]@[field1]>;tag=[call_number]
      To: <sip:[field0]@[field1]>
      Call-ID: [call_id]
      CSeq: [cseq] REGISTER
      Contact: sip:[field0]@[local_ip]:[local_port]
      Max-Forwards: 10
      Expires: 120
      User-Agent: SIPp/Win32
      Content-Length: 0

    ]]>
  </send>

  <!-- asterisk -->
  <recv response="200" >
  </recv>


  <send retrans="500">
    <![CDATA[

      REGISTER sip:[remote_ip] SIP/2.0
      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
      From: <sip:[field0]@[field1]>;tag=[call_number]
      To: <sip:[field0]@[field1]>
      Call-ID: [call_id]
      CSeq: [cseq] REGISTER
      Contact: sip:[field0]@[local_ip]:[local_port]
      [field2]
      Max-Forwards: 10
      Expires: 120
      User-Agent: SIPp/Win32
      Content-Length: 0

    ]]>
  </send>

"<recv" should contains the expecting receive response message. If it doesn't match with the actual received message, then the REGISTRATION will not be successful.

  <!-- asterisk -->
  <recv response="100" optional="true">
  </recv>

  <recv response="200">
  </recv>

  <!-- response time repartition table (ms)   -->
  <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>

  <!-- call length repartition table (ms)     -->
  <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>

</scenario>

--------------------------------------END OF XML---------------------------------------------

Step 2: Create CSV file..., below is the code

SEQUENTIAL
18222;10.20.20.29;[authentication username=18222 password=abcdef];

NOTE: Save as CSV formate :)

Command: ./sipp 10.20.20.29 -sf REGISTER_client.xml -inf REGISTER_IN.csv -m 1

Now INVITE:


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

<scenario name="UAC REGISTER + INVITE + call">

<!--  Use with CSV file struct like: 32;192.168.1.211;[authentication username=32 password=32];21;
      (user part of uri, server address, auth tag, call target)
-->

     <send retrans="500">
    

  

  <send>
    <![CDATA[

      ACK sip:[field3]@[remote_ip]:[remote_port] SIP/2.0
      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
      From: <sip:[field0]@[field1]>;tag=[call_number]
      [last_To:]
      Call-ID: [call_id]
      CSeq: [cseq] ACK
      Contact: sip:[field0]@[local_ip]:[local_port]
      Max-Forwards: 10
      Content-Length: 0

    ]]>
  </send>

  <pause milliseconds="30000" />           - Pause for 30 secs (Here session is established and pause for 30 seconds)

  <send retrans="500">
    <![CDATA[

      BYE sip:[field3]@[remote_ip]:[remote_port] SIP/2.0
      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
      From: <sip:[field0]@[field1]>;tag=[call_number]
      [last_To:]
      Call-ID: [call_id]
      CSeq: [cseq] BYE
      Contact: sip:sipp@[local_ip]:[local_port]
      Max-Forwards: 10
      Content-Length: 0

    ]]>
  </send>

  <!-- The 'crlf' option inserts a blank line in the statistics report. -->
  <recv response="200" crlf="true">
  </recv>





  <!-- 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>

How to send RTP:


How to send RTP in sipp?

1. Create a RTP pcap file (Use wireshark to create it) and put in the sipp installation folder.
     i.e pcap/<file name>

2. Now refer the pcap file name in the xml file of your scenario (INVITE.xml)

<nop>
<action>
<exec play_pcap_audio="pcap/File name.pcap"/>
</action>
</nop>



Add this in between the ACK and BYE of the xml file.

3. Run the sipp, you can hear the RTP Voice in the call.