Showing posts with label SIP. Show all posts
Showing posts with label SIP. Show all posts

Friday, 2 June 2017

OpenSIPS server installation

OpenSIPS is an open source SIP proxy server. This post will go through bringing up a working OpenSIPS istallation on Ubuntu 16.04 LTS. First we will install OpenSIPS and then verify that the installation by performing a SIP Registration using a CLI based SIP phone called linphone (specifically linphonec, the CLI version of the SIP phone)

Installing OpenSIPS


1. Adding keys: First fire the following commands in succession on the terminal to setup the keys and repositories for installation:

  apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B
  echo "deb http://apt.opensips.org jessie 2.3-releases" >> /etc/apt/sources.list
  apt-get update

The above commands are explained below: 
a. The first command adds the keys from the keyserver.
b. Then we add the opensips repository to the sources.list file so that apt-get can locate the OpenSIPS server.
c. Then we update the package list available at the newly added repository by firing "apt-get update".
   
root@ubuntu:~# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B
Executing: /tmp/tmp.bZeJxENy5e/gpg.1.sh --keyserver
keyserver.ubuntu.com
--recv-keys
049AD65B
gpg: requesting key 049AD65B from hkp server keyserver.ubuntu.com
gpg: key 049AD65B: public key "OpenSIPS Project <info@opensips.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
root@ubuntu:~#
root@ubuntu:~# echo "deb http://apt.opensips.org jessie 2.3-releases" >> /etc/apt/sources.list
root@ubuntu:~#
root@ubuntu:~# apt-get update
.
.
root@ubuntu:~#

2. Installing OpenSIPS:  Now install opensips with the apt-get command.

apt-get install opensips

root@ubuntu:~# apt-get install opensips
.
.
root@ubuntu:~#

3. Editing the OpenSIPS Config file: The OpenSIPS config file is located at "/etc/opensips/opensips.cfg". In the file we need to replace the IP at which we want OpenSIPS to listen. This is done by replacing the IP in the line mentioning "listen" with the IP address at which you want OpenSIPS to listen(this will be an IP address at an interface in the machine). As we can see below the line is conveniently marked with a comment "CUSTOMIZE ME" to allow it to be easily searchable.

 41
 42 listen=udp:127.0.0.1:5060   # CUSTOMIZE ME
 43

So, replace line 42 to the following replacing the IP address to your IP address.

listen=udp:172.16.76.132:5060

The relevant portion of the config file now looks like this:

 41
 42 listen=udp:172.16.76.132:5060   # CUSTOMIZE ME
 43


4. Start OpenSIPS: Start OpenSIPS server with the command "service opensips start"

root@ubuntu:~# service opensips start
root@ubuntu:~#

5. Verify OpenSIPS is running: Verify that OpenSIPS is running with the "netstat -tulpn" command. The following output shows that OpenSIPS is running on port 5060 for SIP over UDP.


REGISTER a client


Now to verify that OpenSIPS is indeed running properly we will use a SIP phone called linphone to register to the OpenSIPS server. To follow this we first install linphonec, the CLI version of the linphone client, by following the steps given below.  (Note: I installed linphonec on a different machine but it can be done on the same machine that is running OpenSIPS as well)

1. Install linphonec: Fire command "apt-get install linphone-nogtk"

root@ubuntu:~# apt-get install linphone-nogtk
Reading package lists... Done
Building dependency tree     
.
.
.
root@ubuntu:~#


2. Register to OpenSIPS server using linphone client:

a. Start linphonec by firing command "linphonec"
b. Send a REGISTER message to OpenSIPS server by firing "register sip:user1@172.16.76.132 sip:172.16.76.132:5060". The IP address used here is the IP address of the OpenSIPS server. The username can be set to whatever is desired. The Registration successful messages conveys that the client successfully registered

root@ubuntu:~# linphonec
ALSA lib conf.c:4738:(snd_config_expand) Unknown parameters 0
ALSA lib control.c:954:(snd_ctl_open_noupdate) Invalid CTL default:0
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
Ready
Warning: video is disabled in linphonec, use -V or -C or -D to enable.
linphonec> register sip:user1@172.16.76.132 sip:172.16.76.132:5060
linphonec> Registration on <sip:172.16.76.132:5060> successful.
linphonec>
root@ubuntu:~#

3. Crossverify client is registered at the OpenSIPS server: Now to crossverify that the client is registered, lets check the list of users currently registered to OpenSIPS.

On a terminal on the OpenSIPS machine fire the command "./opensipsctl ul show". It will show the currently registered users. As we can see below the user "user1" is registered with the OpenSIPS server. The Contact header specifies the contact of the user as "sip:user1@172.16.76.131"

root@ubuntu:/usr/sbin# ./opensipsctl ul show
Domain:: location table=512 records=1
    AOR:: user1
        Contact:: sip:user1@172.16.76.131;line=34937d1b1e5e27a Q=
            ContactID:: 1829798454851812362
            Expires:: 3510
            Callid:: 1216646129
            Cseq:: 1
            User-agent:: Linphone/3.6.1 (eXosip2/4.1.0)
            State:: CS_NEW
            Flags:: 0
            Cflags::
            Socket:: udp:172.16.76.132:5060
            Methods:: 4294967295
root@ubuntu:/usr/sbin#


A tcpdump trace at the OpenSIPS server shows that the following were the SIP messages that were exchanged during REGISTRATION :

23:44:09.743014 IP (tos 0x68, ttl 64, id 37937, offset 0, flags [DF], proto UDP (17), length 404)
    172.16.76.131.sip > 172.16.76.132.sip: [udp sum ok] SIP, length: 376
    REGISTER sip:172.16.76.132 SIP/2.0
    Via: SIP/2.0/UDP 172.16.76.131:5060;rport;branch=z9hG4bK1833702289
    From: <sip:user1@172.16.76.132>;tag=674536071
    To: <sip:user1@172.16.76.132>
    Call-ID: 1216646129
    CSeq: 1 REGISTER
    Contact: <sip:user1@172.16.76.131;line=34937d1b1e5e27a>
    Max-Forwards: 70
    User-Agent: Linphone/3.6.1 (eXosip2/4.1.0)
    Expires: 3600
    Content-Length: 0
   
23:44:09.743656 IP (tos 0x10, ttl 64, id 31501, offset 0, flags [DF], proto UDP (17), length 431)
    172.16.76.132.sip > 172.16.76.131.sip: [bad udp cksum 0xf2d4 -> 0x7ff8!] SIP, length: 403
    SIP/2.0 200 OK
    Via: SIP/2.0/UDP 172.16.76.131:5060;received=172.16.76.131;rport=5060;branch=z9hG4bK1833702289
    From: <sip:user1@172.16.76.132>;tag=674536071
    To: <sip:user1@172.16.76.132>;tag=bfa0967ee99eeb3ff1f10d7eea5636c7.3367
    Call-ID: 1216646129
    CSeq: 1 REGISTER
    Contact: <sip:user1@172.16.76.131;line=34937d1b1e5e27a>;expires=3600
    Server: OpenSIPS (2.3.0 (x86_64/linux))
    Content-Length: 0
   
Thanks for reading!

Saturday, 25 October 2014

SIPp Installation

      To install SIPp on a Fedora System follow the steps given below :

1. Checkout the sipp code from the SIPp svn. On the sourceforge download page click on the Code Tab and copy the http access svn link :

[root@localhost rishabh]$ svn checkout http://svn.code.sf.net/p/sipp/code/ sipp-code
A    sipp-code/doc
A    sipp-code/doc/trunk
.
.

This will create a folder called sipp-code in the current directory.


2. Now navigate to the directory "sipp-code/sipp/trunk"

[root@localhost rishabh]# cd sipp-code/sipp/trunk
[root@localhost trunk]#


3. Compile SIPp. Sipp can be compiled with the following options :
    a. OPEN-SSL support : required if SIPp need to be run over TLS
    b. PCAP-play support
    c. SCTP support

Here I will compile SIPp with all the above options. To do this run the command

     "autoreconf -ivf; ./configure --with-pcap --with-sctp --with-openssl; make".
  
I compiled SIPp on a freshly installed Fedora machine and encountered the following errors :

        a. Error : bash: autoreconf: command not found...
            Solution : Install autoconf with the command : "yum install autoconf"
      
        b. Error : Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
            Solution :  Install automake with the command "yum install automake"
      
        c. Error : configure: error: ncurses library missing
            Solution : Install ncurses library with the command "yum install ncurses-devel.i686"
      
        d. Error : configure: error: <openssl/md5.h> header missing
            Solution : Install openssl and openssl-devel with the commands "yum install openssl" and "yum install openssl-devel.i686"

        e. Error : configure: WARNING: <netinet/sctp.h> header missing, but this is acceptable on Mac OS X Lion
            Solution : Install lksctp libraries with the command "yum install lksctp-tools-devel.i686".

        f.  Error : configure: error: <pcap.h> header missing  
            Solution : Install pcap libraries with command "yum install libpcap-devel.i686"

        g. Error : ./depcomp: line 772: exec: g++: not found  
            Solution : Install g++ with the command "yum install gcc-c++"


4. Next run "make install"

[root@localhost trunk]# make install
make[1]: Entering directory `/home/rishabh/sipp-code/sipp/trunk'
 /usr/bin/mkdir -p '/usr/local/bin'
  /usr/bin/install -c sipp '/usr/local/bin'
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/home/rishabh/sipp-code/sipp/trunk'
[root@localhost trunk]#


5. To check if SIPp was installed correctly give the command "sipp -v". It will show the version of SIPp installed

[root@localhost trunk]# sipp -v

 SIPp v3.4-early-TLS-SCTP-PCAP, version unknown, built Oct 24 2014, 22:29:11.

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
 published by the Free Software Foundation; either version 2 of
 the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public
 License along with this program; if not, write to the
 Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

 Author: see source files.

[root@localhost trunk]#

SIPp

      SIPp is a command line, linux based, SIP traffic genarator. It has the capability of generating SIP traffic customized to user needs in order to test out SIP Proxies, B2BUAs, SIP media servers, SIP/x gateways etc. It features :

    1. TCP/TLS and UDP support over multiple sockets or multiplexed with retransmission management
    2. Dynamic display of statistics about running tests (call rate, round trip delay, and message statistics)
    3. Periodic CSV statistics dumps
    4. Dynamically adjustable call rates.

      SIPp uses XML files that provide the exact flow of SIP messages to be sent/received at the User Agents. these XML files are highly configurable to allow the user to simulate obscure scenarios effortlessly. The tool is especially useful for load testing as well as RFC compliance testing.