Setup Kamailio IMS Servers (P-CSCF / I-CSCF / S-CSCF)

You can build Kamailio as IMS servers (P-CSCF / I-CSCF / S-CSCF). To setup Kamailio as IMS servers, Kamailio-4.2.0 was picked up. A single Ubuntu 12.04 machine was used to run HSS, P-CSCF, I-CSCF, S-CSCF and MySQL Server. Also same machine was used to run as DNS server (bind9). In a typical commercial setup, probably you need to run these components in separate machines.

To make use of Kamailio as IMS servers, at a higher level you need to mainly do -

  • Prerequisites
  • Setup static IP address
  • DNS Setup.
  • Build Kamailio from source
  • Configure Kamailio server as P-CSCF
  • Configure Kamailio server as I-CSCF
  • Configure Kamailio server as S-CSCF
  • Build HSS from source
  • Configure HSS so that it connects with I-CSCF and S-CSCF
  • Add the user(s) in HSS
Prerequisites

Please install below packages in machine where all P-CSCF, I-CSCF and S-CSCF are executing.

apt-get install flex
apt-get install bison
Setup static IP address

Choose an IP address that is not used by anybody in your LAN. Then follow the instructs given here. Please note that you can ommit the wlan section in /etc/network/interface file, if you do not have a wlan interface like datacard etc.

DNS Setup

First you think of a domain, what you would like to use for IMS test setup. Then follow the instructs given here. Please note that in example group1-imslab11.in is taken as domain name. You can choose a unique domain name instead of group1-imslab11.in.

With this networking pre-requisites are done. Next, lets move to build Kamailio from source.

Build Kamailio from source
  1. Download the latest source from here. Alternatively pick a right version from here.
  2. Copy the downloaded tar file to a location of your choice, say to /usr/local/ims-kamailio/ path.
  3. Untar the downloaded tar file using tar command as shown below.
    tar -xvzf downloaded-tar-file
  4. Change directory to Kamailio source folder
  5. Build all related modules using below command.
    apt-get install libxml++2.6-dev
    apt-get install libncurses5-dev
    make proper
    make include_modules="ims_usrloc_pcscf ims_registrar_pcscf dialog_ng xmlrpc \
      db_mysql cdp cdp_avp ims_icscf \
      presence ims_usrloc_scscf ims_registrar_scscf ims_auth ims_isc ims_charging" cfg
    make all
    make install
  6. Now you have built the Kamailio. Next you need to configure CSCF components.
Configure Kamailio server as P-CSCF

You will be dealing with two config files pcscf.cfg and kamailio.cfg.
Prior to go through these steps, you may download pcscf.cfg and kamailio.cfg, so that you can refer confgiurations as you go through below steps.

Let's install P-CSCF in /etc/kamailio path. You can choose a different path if required.

  1. Create /etc/kamailio folder if not exists, and move to /etc/kamailio folder
    mkdir /etc/kamailio
    cd /etc/kamailio
  2. Copy example pcscf folder to /etc/kamailio path
    cp -rf /usr/local/ims-kamailio/kamailio-4.2.0/examples/pcscf ./
  3. Chnage to pcscf directory
    cd ./pcscf
  4. Now you can see pcscf.cfg and kamailio.cfg. File pcscf.cfg is actually included in kamailio.cfg file. Modify pcscf.cfg and kamailio.cfg as per your environment details.
  5. Open pcscf.cfg, and modify
    • listen= lines for tcp and udp and tls cases. Also provide the port number where P-CSCF will listen for incoming connections.
      Example
      listen=udp:10.10.10.100:4060
      listen=tcp:10.10.10.100:4060
      listen=tls:10.10.10.100:4060

      Here 10.10.10.100 is IP address of P-CSCF machine, and port 4060 is choosen as P-CSCF listen port.

    • alias=line, here you put alias name for P-CSCF.
      Example
      alias=pcscf.group1-imslab11.in

      For your case, what value you will put for alias depends on your DNS entries added previously. It is combination of P-CSCF name and domain name. Whatever you put in alias, should be a resolveable name (meaning where you will run IMS client, from that machine you should be able to ping to alias).

    • Set the port macro , it is used in kamailio.cfg file.
      Example
      #!define PORT 4060
    • Set the network macros as shown below
      #!subst "/NETWORKNAME/group1-imslab11.in/"
      #!subst "/HOSTNAME/pcscf.group1-imslab11.in/"
      #!define HOSTNAME_IP pcscf.group1-imslab11.in
      #!define HOSTNAME_ESC "pcscf\.group1-imslab11\.in"
    • Set the feature macros as given below
      #!define WITH_DEBUG
      #!define WITH_NAT
      ##!define FORCE_RTPRELAY
      ##!define WITH_TLS
      #!define WITH_XMLRPC
      #!define WITH_ANTIFLOOD
      ##!define WITH_RX
      ##!define WITH_TCP
      #!define WITH_SBC
      ##!define WITH_WEBSOCKET
      #!define WITH_IMS_HDR_CACHE
      #!define WITH_NATPING

      Please note that lines starting with double hash (##) are commented lines.

  6. Now you need to modify kamailio.cfg file. Typically default path for Kamailio server is /etc/kamailio. But we are using /etc/kamailio/pcscf path. So this path needs to be modified throughtout in kamailio.cfg file. In addition to this mpath needs to be modified. Now open kamailio.cfg file and do below modifications.
    • Modify
      modparam("cdp","config_file","/etc/kamailio/pcscf.xml")

      to

      modparam("cdp","config_file","/etc/kamailio/pcscf/pcscf.xml")
    • Modify
      modparam("tls", "config", "/etc/kamailio/tls.cfg")

      to

      modparam("tls", "config", "/etc/kamailio/pcscf/tls.cfg")
    • Comment dispatcher related lines (both in modparam and logic routines). If you are not sure how to comment dispatcher stuff in logic routines download the example configutaion files given towards end of this article.
    • Modify mpath line to as shown below.
      mpath="/usr/local/ims-kamailio/kamailio-4.2.0/output/lib64/kamailio/modules/"
  7. You had built Kamailio earlier. Copy the executable to /etc/kamailio/pcscf path as pcscf.
  8. Run PCSCF as ./pcscf -c and see if any config errors are there. If config errors present, first resolve those.
  9. Now you are done with P-CSCF setup.
Configure Kamailio server as I-CSCF

Prior to go through these below steps, you may download icscf.cfg, kamailio.cfg, icscf.xml and icscf.mysql.sql, so that you can refer confgiurations as you go through below steps.
Let's install I-CSCF in /etc/kamailio path. You can choose a different path if required.

  1. Install mysql-server as I-CSCF needs it.
    apt-get install mysql-server
  2. Change to /etc/kamailio folder
    cd /etc/kamailio
  3. Copy example icscf folder to /etc/kamailio path
    cp -rf /usr/local/ims-kamailio/kamailio-4.2.0/examples/icscf ./
  4. Chnage to icscf directory
    cd ./icscf
  5. Now you can see icscf.cfg and kamailio.cfg. File icscf.cfg is actually included in kamailio.cfg file. Modify icscf.cfg and kamailio.cfg as per your environment details.
  6. Open icscf.cfg, and modify
    • listen= lines for tcp and udp and tls cases. Also provide the port number where I-CSCF will listen for incoming connections.
      Example
      listen=udp:10.10.10.100:4070
      listen=tcp:10.10.10.100:4070
      listen=tls:10.10.10.100:4070

      Here 10.10.10.100 is IP address of I-CSCF machine, and port 4070 is choosen as I-CSCF listen port.

    • alias=line, here you put alias name for I-CSCF.
      Example
      alias=icscf.group1-imslab11.in

      For your case, what value you will put for alias depends on your DNS entries added previously. It is combination of I-CSCF name and domain name. Whaever you put in alias, should be a resolveable name (meaning where you will run IMS client, from that machine you should be able to ping to alias).

    • Set the port macro , it is used in kamailio.cfg file.
      Example
      #!define PORT 4070
    • Set the network macros as shown below
      #!subst "/NETWORKNAME/group1-imslab11.in/"
      #!subst "/HOSTNAME/pcscf.group1-imslab11.in/"
    • In DB_URL line, set database details properly
    • In DB_URL2 line, set database details properly
    • Set the feature macros as given below
      #!define WITH_XMLRPC
  7. Now you need to modify kamailio.cfg file. Typically default path for Kamailio server is /etc/kamailio. But we are using /etc/kamailio/icscf path. So this path needs to be modified throughtout in kamailio.cfg file. In addition to this mpath needs to be modified. Now open kamailio.cfg file and do below modifications.
    • Modify
      modparam("cdp","config_file","/etc/kamailio/icscf.xml")

      to

      modparam("cdp","config_file","/etc/kamailio/icscf/icscf.xml")
    • Modify
      modparam("tls", "config", "/etc/kamailio/tls.cfg")

      to

      modparam("tls", "config", "/etc/kamailio/icscf/tls.cfg")
    • Comment dispatcher related lines (both in modparam and logic routines). If you are not sure how to comment dispatcher stuff in logic routines download the example configutaion files given towards end of this article.
    • Modify mpath line to as shown below.
      mpath="/usr/local/ims-kamailio/kamailio-4.2.0/output/lib64/kamailio/modules/"
  8. You had built Kamailio earlier. Copy the executable to /etc/kamailio/icscf path as icscf.
  9. Run I-CSCF as ./icscf -c and see if any config errors are there. If config errors present, first resolve those.
  10. Next you need to setup mysql part. Create a database icscf with user icscf. You can follow below steps to create database and user.
  11. Enter command as shown below
    mysql -uroot -p

    Enter mysql root password. You will be at mysql prompt. Execute below commands at mysql prompt.

    create database icscf;
    create user 'icscf'@'localhost' IDENTIFIED BY 'your-password';
    grant all privileges on icscf.* to 'icscf'@'localhost';
  12. Now user and database are created. Exit mysql prompt by typing exit.
  13. Import icscf.mysql.sql file
    mysql -uroot -p icscf < icscf.mysql.sql

    It will ask mysql root password. Enter the password. It will import icscf.mysql.sql file to mysql.

  14. Next you need to modify icscf.xml file. Check the example icscf.xml and modify it accordingly. Important points to note here, you can set realm to domain name, in this case it is group1-imslab11.in. You also need to set the FQDNs properly as shown in example file. Also you need to set the hss port and icscf (acceptor) ports accordingly. If ports are not set properly handset between HSS and I-CSCF would not go through.
  15. Now you are done with I-CSCF setup.
Configure Kamailio server as S-CSCF

Prior to go through these below steps, you may download scscf.cfg, kamailio.cfg and scscf.xml, so that you can refer confgiurations as you go through below steps.
Let's install S-CSCF in /etc/kamailio path. You can choose a different path if required.

  1. Change to /etc/kamailio folder
    cd /etc/kamailio
  2. Copy example scscf folder to /etc/kamailio path
    cp -rf /usr/local/ims-kamailio/kamailio-4.2.0/examples/scscf ./
  3. Chnage to scscf directory
    cd ./scscf
  4. Now you can see scscf.cfg and kamailio.cfg. File scscf.cfg is actually included in kamailio.cfg file. Modify scscf.cfg and kamailio.cfg as per your environment details.
  5. Open scscf.cfg, and modify
    • listen= lines for tcp and udp and tls cases. Also provide the port number where S-CSCF will listen for incoming connections.
      Example
      listen=udp:10.10.10.100:4080
      listen=tcp:10.10.10.100:4080
      listen=tls:10.10.10.100:4080

      Here 10.10.10.100 is IP address of S-CSCF machine, and port 4080 is choosen as S-CSCF listen port.

    • alias=line, here you put alias name for S-CSCF.
      Example
      alias=scscf.group1-imslab11.in

      For your case, what value you will put for alias depends on your DNS entries added previously. It is combination of S-CSCF name and domain name. Whaever you make in alias, should be a resolveable name (meaning where you will run IMS client, from that machine you should be able to ping to alias).

    • Set the port macro , it is used in kamailio.cfg file.
      Example
      #!define PORT 4080
Tag: 
Kamailio IMS Servers, PCSCF, SCSCF, ICSCF, Setup IMS servers, Setup Kamailio IMS servers