OpenSIPS - Configuration and Integration with Asterisk (NAT Traversing)

OpenSIPS is an open source software that suits well for medium and large businesses to handle all the above mentioned scenarios. It supports common database access like mysql and postgres but still very well supports the carrier grade deployments. OpenSIPS is multi-purpose signaling SIP server. It can act as SIP Router, SIP Switch, SIP Registrar, Application Server, Redirect Server, Load Balancer, Dispatcher, Back-to-Back User Agent, Session Border Controller, SIP Front-End, NAT traversal Server, IP Gateway (SMS, XMPP) among others.

Installing and Configuring OpenSIPS in Fedora

1. Install OpenSIPS

1. Download OpenSIPS source file from http://opensips.org
2. Extract it and place it in /usr/src
3. Then compile the source file with the option of dbmodule for the support of database handling in opensips

2. Change the configurations file to install opensips database

1. First of all go to the /usr/local/etc/opensips
2. Then open opensipsctlr and find the sip domain option and change it as per your need , find db engine option and uncomment it to tell opensips to use database engine.
3. When these changes are done , save the configuration file and go to the terminal and run the command opensipsdbctl create and answered the qusetions by pressing y.
4. Go to the opensips folder and open the opensips.cfg file in gedit. Then remove the comments to the module db and also uncomment the parameters related to the db module.
5. Start the opensips by run the command opensipsctl start

3. Add Users to check Opensips working

1. create the aliases by using this command opensipsctl add "alias name" password
2. After that register users to your softphone and made the call between users.

4. Asterisk Installation

1. Download Asterisk from asterisk.org.
2. Compile the asterisk in src directory.
3. Run the asterisk.

5. ODBC Configuration

1. Install ODBC Support.
2. change the Odbc.ini file to have connect to asterisk.
3. test the changes by running this command on terminal isql odbc parameter name
4. Go to the Asterisk folder.
5. Change the res_odbc configuration file and extconfig configutration files as per your needs to connect opensips and asterisk.
6. To check the configuration in asterisk Cli run this command show odbc
7. If odbc not show then install the asterisk-odbc from terminal.

6. Opensips.cfg for asterisk Integration

1. To Connect opensips to asterisk when user call from one destination to anothe destination. We should change the code where opensips route the call after authentication.
2. change the code in route with the asterisk ip and port where opensips transfer the calls to asterisk
3. rewritehostport("asterisk ip:asterisk port")

7. Test the integration

1. add two aliases on the same domain name.
2. register one alias in zoiper and remain unregistered the second alias and made the call from one alias to another alias which is unregistered .
3. If the call made successfully then you are done with your asterisk and opensips configuration.

8. Call forward by using AVPOPS module

1. To call forwarding from avp we need first to load the avpops module.
2. After that define the parameters of avops module in parameters define avp table as avp prefrences where you can pick the alternate alias with the attribute.
3. For call blind you need to set the alias in avp prefrences module by using this commands on terminal ./opensipsctl avp add -T usr_preferences client name callfwd 0 clientname
4. after that use the function and forward it to route.
5. For busy and unanswered call you need to need to call the avp attribute for busy and unanswered call and call the function rewritehostport("asterisk ip:asterisk port") to forward the call to asterisk and play the busy and unanswered call messages.

9. Nat Traversing

1. First Install the rtpproxy server to support the sdp in nat traversing.
2. To install rtpproxy download the source code and compile it.
3. After that set the rtpproxy by using this command in terminal ./rtpproxy -l yourip -s udp:yourip:7890 -F
4. After that load the nathelper module and set the appropriate parameters according to you nedd.
5. After that go to the opensips.cfg file and change the routing logic.

First check that if the request is register and put the code

rtpproxy_answer();
if (nat_uac_test("18"))
{
if(method=="REGISTER") {
fix_nated_register();
}
else {
fix_nated_contact();
}
setflag(5);
}

After that go to the route 1 context and put the code

if (subst_uri('/(sip:.*);nat=yes/\1/'))
{
setbflag(6);
};
if (isflagset(5)||isbflagset(6))
{
route(6);
};
if (isflagset(5))
{
search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
}

After that handled the onreply route by put the code

rtpproxy_answer();
append_hf("P-hint: onreply_route|rtpproxy_answer \r\n");
}
if (isbflagset(6))
{
search_append('contact:.*sip:[^>[:cntrl:]]*',';nat=yes');
append_hf("P-hint: Onreply-route - fixcontact \r\n");
fix_nated_contact();
}

After that in route 6 put the following code.

{
if(is_method("BYE|CANCEL"))
{
unforce_rtp_proxy();
}
else if (is_method("INVITE"))
{
rtpproxy_answer();
t_on_failure("1");
};
}

Got to the failure route and put the following code.

if (isflagset(5)||isbflagset(6))
{
unforce_rtp_proxy();
}