Monday 19 September 2011

How to install Open IMS Core in ubuntu



Open IMS Core is an open source implementation of IMS call session control function and a lightweight Home Subscriber Server. In this document I have discussed how to install it on Ubuntu.

Prerequisite:

Before installing Open IMS Core you need programs listed below installed and running.
  • an SVN client running
  • A mysql server. Install it by entering following command sudo apt-get mysql*
  • A DNS server. I have used bind9. I have installed it using synaptic Package Manger.
  • GCC3/4, make, JDK1.5, ant
  • bison and flex
  • libxml2, libmysql 

Getting the Source Code:

Create a directory /opt/OpenIMSCore and go in that directory by command

mkdir /opt/OpenIMSCore
cd /opt/OpenIMSCore

Download the latest version from the repository of Open IMS Core. But before downloading make two folders FHoSS for HSS functionalities and ser_ims for CSCF functionalities.

mkdir FHoSS
mkdir ser_ims

svn checkout http://svn.berlios.de/svnroot/repos/openimscore/ser_ims/trunk ser_ims
svn checkout http://svn.berlios.de/svnroot/repos/openimscore/FHoSS/trunk FHoSS

You can checkout at different path but after that you have to change configuration files.

Configuring DNS server:

As we want to make our own network we need DNS server for IP and domain name binding.
Next discussion will be based on following configuration:

Domain name: group1-imslab11.in
IP address: 192.168.1.100
Subnet : 255.255.0.0

Following steps will tell you how to configure your own DNS server. Before proceeding further you have to stop Network Manager, as it does automatic changes to files needed. To stop network manager run,

sudo service network-manager stop

Setup your ethernet; my ethernet is running on eth0 please check your ethernet ports name.

sudo ifconfig eth0 192.168.1.100/16 up

make the necessary changes in your interface file. Open interface file with command

sudo gedit /etc/networking/interfaces

copy the configuration of snapshot



resolv.conf file is used for client side configuration of DNS server.

open it with

sudo gedit /etc/resolv.conf



nameserver - IP address of DNS server
search - Search list for hostname lookup
domain - name of the local domain

Open hosts file with command

sudo gedit /etc/host



host file has the static lookup table for hostname
Ex. IP_ADDR cannonical_host_name aliases

This file joints ip addresses with there names and alias name.

Restart the network by command

/etc/init.d/networking restart

Configuring Bind:

DNS configuration files are stored in /etc/bind directory. Primary configuration file is /etc/bind/named.conf.
Here we will insert forward lookup zone and reverse lookup zone.



Here I have added a zone by giving it a name group1-imslab11.in and file for that forward zone declaring as /etc/bind/open-ims.dnszone. Similarly reverse zone and reverse zone file at location /etc/open-ims-rev.dnszone




copy open-ims.dnszone to /opt/OpenIMSCore/ser_ims/cfg/

restart bind9 server with

sudo /etc/init.d/bind9 restart

check whether DNS has configured properly or not from nslookup command.





OK all done. Now let us install Open IMS Core !!!

Make sure that mysql and bind9 are running.
  1. Go inside ser_ims/cfg directory ( cd /ser_ims/cfg/ )
  2. Run “configurator.sh” ( sh configurator.sh )
  3. Enter Domain Name: < your domain name>
  4. Enter IP Address: < Your IP Address>
    (We have given group1-imslab11.in as domain name and 192.168.1.100 as IP)
  5. Apply changes to all.
    (This step will change domain name and ip address in the following files: icscf.cfg,        icscf_pg.sql, icscf.sql, icscf.thig.cfg, icscf.xml, pcscf.cfg, pcscf.xml, persist_my.sql,        persist_pg.sql, scscf.cfg, scscf.xml)
  6. Change to the following directory:
    cd /opt/OpenIMSCore/FHoSS/scripts
  7. Change domain name and ip in userdata.sql to your domain and IP address.
  8. Change to the following directory
    cd /opt/OpenIMSCore/FHoSS/config/
  9. Change Domain name and IP in DiameterPeerHSS.xml to your domain name and IP.
  10. Move to the following directory and make by given command:
    cd /opt/OpenIMSCore/ser_ims
    make install-libs all
  11. After that write given command in prompt
    cd /opt/OpenIMSCore/FHoSS
    ant compile deploy
  12. Now make Database by command:
    cd /opt/OpenIMSCore
    mysql –u root –p < ser_ims/cfg/icscf.sql
    mysql –u root –p < FHoSS/scripts/hss_db.sql
    mysql –u root –p <FHoSS/scripts/userdata.sql
  13. To copy the following files into /opt/OpenIMSCore give commands
    cp ser_ims/cfg/*.cfg .
    cp ser_ims/cfg/*.xml .
    cp ser_ims/cfg/*.sh .
  14. Start OpenIMSCore in four parellel terminals by giving each command in different terminal:
    ./pcscf.sh
    ./scscf.sh
    ./icscf.sh
    cd FHoSS/deploy/
    ./startup.sh
  15. Open FHoSS web Console
    http://localhost:8080/hss.web.console/
    User Name: hssAdmin
    password: hss
  16. Go to user identities -> Public User Identities -> search
  17. Click on search, you will see two default users:   Alice and bob
  18. Go and do various experiments with Open IMS Core !!!!!

Friday 9 September 2011

Function Pointers in C

Hi all. This is my first post. I am going to write about function pointers today. Question that will come in your mind are;

  • What are function pointers?
  • Why do we need that?
  • How to implement them?

Ok so I will try to answer them one by on.

What are Function Pointer?


Well function pointers are pointer to a function. As simple as that :P. No seriously its true! It stores address of a function. As we know every program in execution has some memory allocated to it. Obviously that memory has an address. So if we call that address (from somewhere :p) we are actually calling the program at that address. Confused??? if not go to next topic. Let me give you a weird real world example. Mr. X (a function) has phone no. xxxxxxx(address to it). So calling Mr.X directly would be same as you call the person at  xxxxxxx no. :P

Syntax of Function Pointer in C


Before we discuss syntax of function pointer. Lets just brush up some declaration in C.

int func(/* arg */);
This function will return an int data type when called.

int *func(/* arg */);
This function will return a pointer of type int.

int (*func)(/* arg */);
This will create a pointer to function returning data type int.


Hmmm confused?? Go through what i have written, couple of time and try to understand it.

Now lets see how it works in C...






#include <stdio.h>

void number(int a)
{
printf("You have entered number %d \n",a);
}

void square(int a)
{
printf("Square of entered number %d \n",a*a);
}


void main()
{
void (*func)(int a);
func = &number;
func(2);
// Givin '&' with function name is not necessary. But you should give that as good programing practice.
func = square;
func(2);
}


******************OUTPUT***********************


You have entered number 2
Square of entered number 4

***************************************************


Why should I use function pointer?

Ok. It sounds cool. But is it really helpful? Well of course yes. So where are Function Pointer used? Most common example i could find on net is qsort(). We will discuss that briefly. You can use function pointer when you dont know what the function will do? Let us understand with a simple example of qsort. 

Qsort is a Linux function. Used for quick sorting an array. It is declared as..


void qsort ( void * base, size_t num, size_t size, int ( * comparator ) ( const void *, const void * ) );



Here look at the declaration of function pointer  to  comparator. User  has to write that function. Ex.

#include <stdio.h>
#include <stdlib.h>

int values[] = { 13, 3, 100, 55, 76, 11 };

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

void main ()
{
  int n;
  qsort (values, 6, sizeof(int), compare);
  for (n=0; n<6; n++)
     printf ("%d ",values[n]);
}

/* reference: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/  */



******************OUTPUT***********************

3 11 13 55 76 100 

***************************************************

In a nutshell person who has made qsort function has implemented a function which knows how to implement quick sort on given values (in example value pointer), size of that data type (here; size of int) and how much value to compare (6 in our case). But he don't know how to compare and which value to compare. So the person who is using qsort is expected to write down function for that. Cool, isn't it? Now think where you can use it. And make most of it in your project. 

Suggestion are always welcomed :)



Sites that I have found useful :)

http://publications.gbdirect.co.uk/c_book/chapter5/function_pointers.html
This site provides a good understanding on syntax of function pointer in C.

http://www.cprogramming.com/tutorial/function-pointers.html
Hmm.. Lil' bit technical but still very very useful.

http://www.newty.de/fpt/intro.html
In great detail. Good one.