In this chapter, we will discuss on OpenSIPS. OpenSIPS (Open SIP Server) is a mature Open Source implementation of a SIP server. OpenSIPS is more than a SIP proxy/router as it includes application
level functionalities. OpenSIPS, as a SIP server, is the core component of any SIPbased VoIP solution.
With a very flexible and customizable routing engine, OpenSIPS 'unifies voice, video, IM and presence services in a highly efficient way, thanks to its scalable (modular) design.
What OpenSIPS has to offer, comes in a reliable and highperformance flavour OpenSIPS is one of the fastest SIP servers, with a throughput that confirms it as a solution up to enterprise or carriergrade class. It performs much better than that of Asterisk. However, it lacks of feature that rich in Asterisk.
Thus, in reality, it would be beneficial to use both Asterisk and OpenSIPS.
Compile OpenSIPS
Prepare the supporting software. In Ubuntu 9.10, it can be prepared by using the following command.
# aptget install flex bison gcc make libperl5.10 libperldev libxmlrpcc3 libxmlrpcc3dev \ unixodbc unixodbcdev libradiusclientng2 libradiusclientngdev libxml2 openssl libsctp1 \ libsctpdev libexpat1 libexpat1dev libldap2.42 libldap2dev libsnmp15 libsnmpdev \ libconfuse0 libconfusedev libmysqlclient15off libmysqlclient15dev mysqlclient5.1 \ mysqlserver zlib1g zlib1gdev libmysql++3 libmysql++dev
Get source code of OpenSIPS, such as, opensipsXXXtls_src.tar.gz ,from http://opensips.org/pub/opensips/
http://www.opensips.org/index.php?n=Resources.Downloads#osippub http://www.opensips.org/index.php?n=Resources.Downloads#osipsf If we would like to use opensips with TLS, we need to do the followings.
$ sudo su
# cp opensips1.6.1tls_src.tar.gz /usr/local/src/
# cd /usr/local/src/
# tar zxvf opensips1.6.1tls_src.tar.gz
# cd opensips1.6.1tls
Compile and install the following modules, i.e., "acc", "mysql", "textops", "sl", "db_mysql" and "enum"
using the following command,
# cd opensips1.6.1tls
# make all && make include_modules="acc mysql textops sl enum db_mysql" modules
# make install
It seems, we need to copy some scripts to /usr/local/src/opensips/opensipsctl
# cp Rf /usr/local/src/opensips1.6.1tls/scripts/* /usr/local/lib/opensips/opensipsctl
That's it. OpenSIPS is compiled and install and ready to use. OpenSIPS configuration file is located at /usr/local/etc/opensips
Check for any problem in the configuration file can be done using the following command,
# opensips c f /usr/local/etc/opensips/opensips.cfg
Prepare User Database Server
OpenSIPS uses database server, such as, MySQL for handling user registration. Install MySQL Server and make sure it works using the following command,
# aptget install mysqlserver libmysqlclient15dev mysqlclient5.0
# /etc/init.d/mysql restart
To setup the database server, we need to edit /usr/local/etc/opensips/opensipsctlrc or /etc/opensips/opensipsctlrc, such as,
# vi /usr/local/etc/opensips/opensipsctlrc or vi /etc/opensips/opensipsctlrc
Make sure,
BENGINE=MYSQL
BHOST=localhost BNAME=opensips BRWUSER=opensips BROUSER=opensipsro BROPW=opensipsro BROOTUSER="root"
Copy scripts to /usr/local/lib/opensips/opensipsctl
# cp Rf /usr/local/src/opensips1.6.1tls/scripts/* /usr/local/lib/opensips/opensipsctl/
Initialized the user database using opensipsdbctl command as follow,
# cd /usr/local/lib/opensips/opensipsctl
# opensipsdbctl create Follow the following commad
MySQL password for root: <enter MySQL root password>
INFO: test server charset
INFO: creating database opensips ...
INFO: Core OpenSIPS tables succesfully created.
Install presence related tables? (y/n): <y>
INFO: creating presence tables into opensips ...
INFO: Presence tables succesfully created.
Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist? (y/n): <y>
INFO: creating extra tables into opensips ...
INFO: Extra tables succesfully created.
Use opensipsctl
Opensipsctl is a usefull tool provided by OpenSIPS, that can be used for,
• Adding users.
• Check who's online.
• Monitoring opensips activities.
To add user, we can use
# opensipsctl add number@host password
# opensipsctl add [email protected] 123456 To see who's online
# opensipsctl ul show number@host
# opensipsctl ul show [email protected] To monitor OpenSIPS Softswitch activities
# opensipsctl monitor
Some Routing Technique in OpenSIPS
In the following sections, we will discuss how to route traffic to
• PSTN and Cellullar network
• ENUM network
How to route to PSTN and Cellular
Basically, we need an Analog Telephone Adapter (ATA) to interconnect a VoIP network to PSTN or Cellular network. In this example, we assume
• ATA is located at IP address 192.168.0.200
• ATA is using port 5061
• Area code for PSTN is 021
• Area code for Cellullar is 08
We need to add to the opensips configuration file /usr/local/etc/opensips/opensips.cfg
For example, to be able to use the ATA to call PSTN from all host / domain
# attempt handoff to PSTN if (uri=~"^sip:021[09]*@*") {
rewritehostport( "192.168.0.200:5061"); ## 192.168.0.200:5061 is the ATA route(1);
};
To restrict the call to PSTN only from mydomain.com
# attempt handoff to PSTN
if (uri=~"^sip:021[09]*@mydomain.com") { ## caller registered to mydomain.com rewritehostport( "192.168.0.200:5061"); ## 192.168.0.200:5061 is ATA
route(1);
};
To be able to use the ATA to call Cellullar from all host / domain
# attempt handoff to cellullar if (uri=~"^sip:08[09]*@*") {
rewritehostport( "192.168.0.200:5061"); ## 192.168.0.200:5061 is ATA route(1);
};
To restrict the call to Cellular only from mydomain.com
# attempt handoff to cellullar
if (uri=~"^sip:08[09]*@mydomain.com") { ## caller registered to mydomain.com rewritehostport( "192.168.0.200:5061"); ## 192.168.0.200:5061 is ATA
route(1);
};
How to route ENUM Query in OpenSIPS
Steps to route ENUM query in OpenSIPS is as follows,
• Prepare ENUM modul in OpenSIPS configuration
• Create routing table for ENUM
ENUM query in OpenSIPS is basically transform the URI address from ENUM to URI SIP. Call process is normally done using the URI SIP.
To prepare the ENUM module in OpenSIPS configuration, we need to edit /usr/local/etc/opensips/opensips.cfg or /etc/opensips/opensips.cfg
# vi /usr/local/etc/opensips/opensips.cfg Enter the following command
loadmodule "enum.so"
modparam("enum", "domain_suffix", "e164.arpa.") modparam("enum", "i_enum_suffix", "e164.arpa.")
We can change e164.arpa to other ENUM top level domain, such as, e164.id or e164.th.
Test ENUM Query in OpenSIP
Assuming:
• An Asterisk Server Running at 192.168.0.2
• Echo test ready at number 600
• ENUM Server is ready to resolve ENUM Query for e164.id.
• Data in ENUM Server ready to map +62555666666600 to [email protected] Test test routing table would be
rewriteuri("sip:[email protected]");
prefix("+");
enum_query("e164.id.");
route(1);
route[1] {
# send it out now; use stateful forwarding as it works reliably # even for UDP2TCP
if (!t_relay()) {
sl_reply_error();
};
exit;
}
ENUM Routing Table in OpenSIPS configuration
The short version
if (uri=~"^sip:00[19][09]*@*") { strip(2);
prefix("+");
};
if (uri=~"sip:\+[09]+@*") enum_query("e164.id.");
The above example will allow all client from all server to access our ENUM query routing. A more complete version of ENUM query may be as follows,
# Somewhere in the route[x] section:
# if you want to make ENUM work with numbers starting with "00",
# use the following to convert "00" it into a "+"
if (uri=~"^sip:00[19][09]*@example\.net") { # strip leading "00"
# (change example.net to your domainname or skip the stuff after the "@") strip(2);
# (adjust, if your international prefix is something else than "00") prefix("+");
};
# check if request uri starts with an international phone
# number (+X.), if yes, try to ENUM resolve in e164.arpa.
# if no result, try in nrenum.net
if (uri=~"sip:\+[09]+@example\.net") {
# (change example.net to your domainname or skip the stuff after the "@") if ( !enum_query("e164.arpa.") ) {
enum_query("nrenum.net.");
};
};
Another alternative that may be extended is as follows,
# is this an ENUM destination (leading +?)
if (method=="INVITE" && uri=~"sip:\+[09]+ at iptel\.org") {
if (!enum_query("voice")) # if parameter empty, it defaults to "e2u+sip"
enum_query(""); # E2U+sip }
Yet another alternative that can be tried / expanded is as follows, if (is_from_user_enum()) {
enum_query("");
}