OpenSips

Opensips is one of the best solution that are present in opensource, it provide you ITSP level services on good hardware box, Single box configure with opensips can supports 5000-10000 calls at time, which it make any teleco to operate with more then 5-10 billion mins per year. Anyone can use it to support their bussiness which is incuring lot of cost due high hardware cost such as VOIPLOGIC and PORTA. As there lot of development is required to start with and there is no good absolute billling platform in opensource market so noone is keen to use at enterprise level. There are other ways to use for outbound call center solution of decrease the cost for user making outbound call to customer care, as there is very good feature of click to dial, whicha cna be integrated to any website for customer care support. So now know lot more about what major usage, keep it in mind now when ever you require more then 1000 concurrent call, installation of opensips will reduce the cost, give us best you to integrate any type of technogy. Installing of opensips is very easy and if anyone knows the basic linux and few commands then he can install on the box:

REQUIRMENTS:

  • gcc / suncc / icc : gcc >= 2.9x; 4.[012] recommended (it will work with older version but it might require some options tweaking for best performance)
  • bison or yacc (Berkley yacc)
  • flex
  • GNU make (on Linux this is the standard “make”, on FreeBSD and Solaris is called “gmake”) version >= 3.79.
  • sed and tr (used in the makefiles)
  • GNU tar (“gtar” on Solaris) and gzip if you want “make tar” to work
  • GNU install or BSD install (on Solaris “ginstall”) if you want “make install”, “make bin”, “make sunpkg” to work
  • openssl if you want to compile the TLS support
  • libsctp if you want to compile the SCTP support
  • libmysqlclient & libz (zlib) -libs and devel headers- if you want mysql DB support (the db_mysql module)
  • libpq / postgresql -libs and devel headers- if you want postgres DB support (the db_postgres module)
  • unixodbc -libs and devel headers- if you want unixodbc DB support (the db_unixodbc module)
  • libexpat if you want the jabber gateway support (the jabber module) or the XMPP gateway support
  • libxml2 if you want to use the cpl-c (Call Processing Language) or the presence modules (presence and pua*)
  • libradius-ng -libs and devel headers- if you want to use functionalities with radius support – authentication, accounting, group support, etc
  • unixodbc – libs and devel headers – if you want UNIXODBC support as DB underlayer
  • libxmlrpc-c3 – libs and devel headers – if you want to have XML-RPC support for the Management interface (MI)
  • libperl – libs and devel headers – if you want PERL connector to support perl scripting from you config file (perl module)
  • libsnmp9 – libs and devel headers – if you want SNMP client functionality (SNMP AgentX subagent) for opensips
  • libldap libs and devel headers v2.1 or greater – if you want LDAP support
  • libconfuse and devel headers – if you want to compile the carrierroute module

INSTALLATION

  • cd /usr/src/
  • yum install bison bison-devel ncurses ncurses-devel zlib zlib-devel openssl openssl-devel gnutls-devel gcc gcc-c++ mysql-server mysql-client which flex make
  • Download opensips (Opensips 1.5 wget http://opensips.org/pub/opensips/1.5.0/src/opensips-1.5.0-tls_src.tar.gz)
  • tar -xzf opensips-1.5.0-tls_src.tar.gz
  • make all
  • make install
  • make config

By following above 2 process we have installed the opensips server on our system now we have to configure the server corresponding to our requirement.

CONFIGURATION

We have following directory where all files has be installed:

1
2
/usr/local/lib/opensips/ directory where all modules are installed
/usr/local/etc/opensips/ directory where all configuration you have make

FOR LOAD

Under Load-balancing format The below setting will create alternate call from one server and other alternately it will create same number of calls from each gateway.

1
2
3
4
5
6
log_stderror=yes
log_facility=LOG_LOCAL0
fork=yes
children=4
debug=2
listen=5060

MODULE PATH

1
mpath="/usr/local/lib/opensips/modules/"

Modules Section

DB_MYSQL

1
2
3
4
loadmodule "db_mysql.so"
modparam("db_mysql", "ping_interval", 300)
modparam("db_mysql", "timeout_interval", 10)
modparam("db_mysql", "auto_reconnect", 1)

SL

1
2
loadmodule "sl.so"
modparam("sl", "enable_stats", 1)

TM

1
2
3
4
5
6
7
8
9
10
11
12
loadmodule "tm.so"
modparam("tm", "fr_timer", 30)
modparam("tm", "fr_inv_timer", 120)
modparam("tm", "wt_timer", 5)
modparam("tm", "delete_timer", 2)
#modparam("tm", "noisy_ctimer", 0)
modparam("tm", "ruri_matching", 1)
modparam("tm", "via1_matching", 1)
modparam("tm", "unix_tx_timeout", 2)
modparam("tm", "restart_fr_on_each_reply", 1)
modparam("tm", "pass_provisional_replies", 0)
modparam("tm", "fr_inv_timer_avp", "$avp(s:callee_fr_inv_timer)")

RR

1
2
3
4
5
loadmodule "rr.so"
modparam("rr", "enable_full_lr", 0)
modparam("rr", "append_fromtag", 1)
modparam("rr", "enable_double_rr", 0)
modparam("rr", "add_username", 0)

MAXFWD

1
loadmodule "maxfwd.so"

USRLOC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
loadmodule "usrloc.so"
modparam("usrloc", "user_column", "username")
modparam("usrloc", "domain_column", "domain")
modparam("usrloc", "contact_column", "contact")
modparam("usrloc", "expires_column", "expires")
modparam("usrloc", "q_column", "q")
modparam("usrloc", "callid_column", "callid")
modparam("usrloc", "cseq_column", "cseq")
modparam("usrloc", "methods_column", "methods")
modparam("usrloc", "flags_column", "flags")
modparam("usrloc", "user_agent_column", "user_agent")
modparam("usrloc", "received_column", "received")
modparam("usrloc", "socket_column", "socket")
modparam("usrloc", "use_domain", 0)
modparam("usrloc", "desc_time_order", 0)
modparam("usrloc", "timer_interval", 60)
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "db_url" , "mysql://opensips:opensips@database/opensips")
modparam("usrloc", "matching_mode", 0)
modparam("usrloc", "cseq_delay", 20)
modparam("usrloc", "nat_bflag", 6)

REGISTRAR

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
loadmodule "registrar.so"
modparam("registrar", "method_filtering", 1)
modparam("registrar", "default_expires", 3600)
modparam("registrar", "min_expires", 60)
modparam("registrar", "max_expires", 0)
modparam("registrar", "default_q", 0)
modparam("registrar", "append_branches", 1)
modparam("registrar", "case_sensitive", 0)
modparam("registrar", "received_param", "received")
modparam("registrar", "max_contacts", 10)
modparam("registrar", "retry_after", 0)
modparam("registrar", "path_mode", 2)
modparam("registrar", "path_use_received", 0)
#modparam("registrar", "received_avp", "$avp(i:801)")
modparam("registrar", "aor_avp", "$avp(i:3223)")
modparam("registrar", "received_avp", "$avp(s:rcv)")

TEXTOPS

1
loadmodule "textops.so"

MI_FIFO

1
2
3
4
5
6
7
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
#modparam("mi_fifo", "fifo_mode", 0660)
#modparam("mi_fifo", "fifo_group", "opensips")
#modparam("mi_fifo", "fifo_user", "opensips")
#modparam("mi_fifo", "reply_dir", "/tmp/")
#modparam("mi_fifo", "reply_indent", "\t")

URI

1
loadmodule "uri.so"

URI_DB

1
2
3
4
5
6
7
8
loadmodule "uri_db.so"
modparam("uri_db", "db_url", "mysql://opensips:opensips@database/opensips")
modparam("uri_db", "db_table", "uri")
modparam("uri_db", "use_uri_table", 1)
modparam("uri_db", "use_domain", 1)
modparam("uri_db", "user_column", "username")
modparam("uri_db", "domain_column", "domain")
modparam("uri_db", "uriuser_column", "uri_user")

xlog

1
2
3
loadmodule "xlog.so"
modparam("xlog", "force_color", 1)
modparam("xlog", "buf_size", 4096)

acc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
loadmodule "acc.so"
modparam("acc", "db_url", "mysql://opensips:opensips@database/opensips")
modparam("acc", "early_media", 1)
modparam("acc", "report_ack", 1)
modparam("acc", "report_cancels", 1)
modparam("acc", "detect_direction", 1)
modparam("acc", "failed_transaction_flag", 3)
modparam("acc", "log_flag", 1)
modparam("acc", "log_missed_flag", 2)
modparam("acc", "db_flag", 1)
modparam("acc", "db_missed_flag", 2)
modparam("acc", "db_extra" , "ua=$hdr(User-Agent); src_user=$avp(i:100);
src_domain=$fd; src_port=$sp; dst_user=$rU; dst_domain=$rd; dst_port=$rp;
message=$mf; unixtime=$Ts; avp_var=$avp(s:can_uri); callstate=$avp(s:callstate);
usercode=$avp(i:1000); recieved=$avp(s:rcv); aor_avp=$avp(i:3223)")

auth

1
2
3
4
loadmodule "auth.so"
modparam("auth", "nonce_expire", 300)
modparam("auth", "rpid_suffix", ";party=calling;id-type=subscriber;screen=yes")
modparam("auth", "rpid_avp", "$avp(s:rpid)")

AVPOPS

1
2
3
4
5
6
7
8
9
10
11
loadmodule "avpops.so"
modparam("avpops", "db_url", "mysql://opensips:opensips@database/opensips")
modparam("avpops", "avp_table", "usr_preferences")
modparam("avpops", "use_domain", 0)
modparam("avpops", "uuid_column", "uuid")
modparam("avpops", "username_column", "username")
modparam("avpops", "domain_column", "domain")
modparam("avpops", "attribute_column", "attribute")
modparam("avpops", "value_column", "value")
modparam("avpops", "type_column", "type")
#modparam("avpops", "avp_aliases", "c_uri" )

DIALOG

1
2
3
4
5
6
loadmodule "dialog.so"
modparam("dialog", "enable_stats", 1)
modparam("dialog", "default_timeout", 21600)
modparam("dialog", "db_url", "mysql://opensips:opensips@database/opensips")
modparam("dialog", "db_mode", 1)
modparam("dialog", "dlg_flag", 4)

DIAPLAN

1
2
3
loadmodule "dialplan.so"
modparam("dialplan", "db_url", "mysql://opensips:opensips@database/opensips")
modparam("dialplan", "attrs_pvar", "$avp(s:dest)")

SIPTRACE

1
2
3
4
loadmodule "siptrace.so"
modparam("siptrace","db_url","mysql://opensips:opensips@database/opensips")
modparam("siptrace", "trace_on", 1)
modparam("siptrace", "trace_flag", 22)

AUTH_DB

1
2
3
4
5
6
7
8
loadmodule "auth_db.so"
modparam("auth_db", "calculate_ha1", 1)
modparam("auth_db", "db_url", "mysql://opensips:opensips@database/opensips")
modparam("auth_db", "use_domain", 1)
modparam("auth_db", "user_column", "username")
modparam("auth_db", "password_column", "password")
modparam("auth_db", "password_column_2", "ha1b")
modparam("auth_db", "load_credentials", "$avp(i:1001)=email_address;$avp(i:1000)=usercode")

MI_DATAGRAM

1
2
3
loadmodule "mi_datagram.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_datagram", "socket_name", "udp:10.10.2.144:8080")

Routing Logic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
 main request routing logic
 
route{
        sip_trace(); # Recording all sip signal for each calls connect through this server
        xlog("Recive call variable : $avp(s:rcv) $avp(i:3223)\n"); # prints the cli log
 
        if($fU==NULL){
                $avp(i:100)="0";
        }
        else
                $avp(i:100)=$fU;
 
        if (!mf_process_maxfwd_header("10")) {
                sl_send_reply("483","Too Many Hops");
                exit;
        }
 
        if (has_totag()) {
                if (loose_route()) {
                        if(is_method("BYE")){
		        #setting for call accounting
                                setflag(1);
                                setflag(3);
                        }
                        route(1);
                } else {
                        if ( is_method("ACK") ) {
                                if ( t_check_trans() ) {
                                        t_relay();
                                        exit;
                                } else {
                                        exit;
                                }
                        }
                        sl_send_reply("404","Not here");
                }
                exit;
        }
 
        if (is_method("CANCEL"))
        {
                if (t_check_trans())
                        t_relay();
                exit;
        }
 
       t_check_trans();
 
        # record routing
        if (!is_method("REGISTER|MESSAGE")){
                record_route();
        }
 
        # account only INVITEs
        if (is_method("INVITE")) {
	   if(from_uri=~".*@10.10.2.136" || from_uri=~".*@10.10.2.134"){
 
                }
                else{
                        avp_db_query("select id_skillgroup from subscriber u where username='$rU'", "$avp(i:2001)");
                        avp_db_query("select id from ast_skillgroup where id='$avp(i:2001)'", "$avp(i:2002)");
                        avp_db_query("select id, serverip, callerid from ast_servers where id_skillgroup='$avp(i:2002)'
                                      order by calls asc limit 1", "$avp(i:2003);$avp(i:2004);$avp(i:2005)");
                        avp_db_query("Update ast_servers SET calls=calls+1 WHERE id=$avp(i:2003)");
 
                        avp_pushto("$ru/domain","$avp(i:2004)");
 
                        if (!t_relay()) {
                                sl_reply_error();
                        };
                        exit;
                }
        }
 
         if (!uri==myself)
        {
                append_hf("P-hint: outbound\r\n");
                route(1);
        }
 
        if (is_method("PUBLISH"))
        {
                sl_send_reply("503", "Service Unavailable");
                exit;
        }
 
        if (is_method("REGISTER"))
        {
                # authenticate the REGISTER requests (uncomment to enable auth)
                xlog("User credentals : $avp(i:1000)\n");
                if (www_authorize("", "subscriber"))
                {
                        xlog("User credentals : $avp(i:1000)\n");
                        if (!save("location"))
                                sl_reply_error();
 
                        exit;
                }
                else{
                        www_challenge("", "0");
                        exit;
                }
 
                if (!check_to())
                {
                        sl_send_reply("403","Forbidden auth ID");
                        exit;
                }
        }
 
        if ($rU==NULL) {
                sl_send_reply("484","Address Incomplete");
                exit;
        }
 
        if (!lookup("location")) {
                switch ($retcode) {
                        case -1:
                        case -3:
                                t_newtran();
                                t_reply("404", "Not Found");
                                exit;
                        case -2:
                                sl_send_reply("405", "Method Not Allowed");
                                exit;
                }
        }
 
        setflag(2);
        xlog("Script is at the end\n");
        route(1);
   }
 
   route[1] {
        # for INVITEs enable some additional helper routes
        if (is_method("INVITE")) {
                avp_db_query("select uuid from subscriber where username = '$rU'", "$avp(s:callee_uuid)");
                $avp(s:can_uri) = $ru;
                xlog("User credentals : $avp(s:callee_uuid)\n");
                t_on_branch("2");
                t_on_reply("2");
                t_on_failure("1");
        }
 
        if (!t_relay()) {
                sl_reply_error();
        };
        exit;
   }
 
    branch_route[2] {
        xlog("new branch at $ru\n");
        $avp(s:can_uri) = $ru;
        $avp(s:callstate)="CALL REROUTED";
        add_rr_param(";foo=true;user=vivek");
        xlog("Call is forwared to asterisk\n");
   }
 
    onreply_route[2] {
        xlog("incoming reply\n");
   }
 
    failure_route[1] {
        if (t_was_cancelled()) {
                exit;
        }
   }

Above configurate is sampled crossponding to load balanced format where calls are forwarded to different gatey crossponding to our require and avialability of gateway.