Gventure Blogs

March 30, 2009

Opensips Installation

Filed under: Opensips — vikaskumar2020 @ 8:26 am

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:

  1. 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)
  2. bison or yacc (Berkley yacc)
  3. flex
  4. GNU make (on Linux this is the standard “make”, on FreeBSD and Solaris is called “gmake”) version >= 3.79.
  5. sed and tr (used in the makefiles)
  6. GNU tar (“gtar” on Solaris) and gzip if you want “make tar” to work
  7. GNU install or BSD install (on Solaris “ginstall”) if you want “make install”, “make bin”, “make sunpkg” to work
  8. openssl if you want to compile the TLS support
  9. libsctp if you want to compile the SCTP support
  10. libmysqlclient & libz (zlib) -libs and devel headers- if you want mysql DB support (the db_mysql module)
  11. libpq / postgresql -libs and devel headers- if you want postgres DB support (the db_postgres module)
  12. unixodbc -libs and devel headers- if you want unixodbc DB support (the db_unixodbc module)
  13. libexpat if you want the jabber gateway support (the jabber module) or the XMPP gateway support
  14. libxml2 if you want to use the cpl-c (Call Processing Language) or the presence modules (presence and pua*)
  15. libradius-ng -libs and devel headers- if you want to use functionalities with radius support – authentication, accounting, group support, etc
  16. unixodbc – libs and devel headers – if you want UNIXODBC support as DB underlayer
  17. libxmlrpc-c3 – libs and devel headers – if you want to have XML-RPC support for the Management interface (MI)
  18. libperl – libs and devel headers – if you want PERL connector to support perl scripting from you config file (perl module)
  19. libsnmp9 – libs and devel headers – if you want SNMP client functionality (SNMP AgentX subagent) for opensips
  20. libldap libs and devel headers v2.1 or greater – if you want LDAP support
  21. libconfuse and devel headers – if you want to compile the carrierroute module

INSTALLATION

  1. cd /usr/src/
  2. 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
  3. Download opensips (Opensips 1.5 wget http://opensips.org/pub/opensips/1.5.0/src/opensips-1.5.0-tls_src.tar.gz)
  4. tar -xzf  opensips-1.5.0-tls_src.tar.gz
  5. make all
  6. make install
  7. 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:

/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.
log_stderror=yes
log_facility=LOG_LOCAL0
fork=yes
children=4
debug=2
listen=5060

################## MODULE PATH #########################
mpath="/usr/local/lib/opensips/modules/"
################## MODULE PATH #########################

####### Modules Section ########

##################### DB_MYSQL #########################
loadmodule "db_mysql.so"
modparam("db_mysql", "ping_interval", 300)
modparam("db_mysql", "timeout_interval", 10)
modparam("db_mysql", "auto_reconnect", 1)
##################### DB_MYSQL #########################

##################### SL #########################
loadmodule "sl.so"
modparam("sl", "enable_stats", 1)
##################### SL #########################

##################### TM #########################
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)")
##################### TM #########################

##################### RR #########################
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)
##################### RR #########################

##################### MAXFWD #########################
loadmodule "maxfwd.so"
##################### MAXFWD #########################

##################### USRLOC #########################
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)
##################### USRLOC #########################

##################### REGISTRAR #########################
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)")
##################### REGISTRAR #########################

##################### TEXTOPS #########################
loadmodule "textops.so"
##################### TEXTOPS #########################

##################### MI_FIFO #########################
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")
##################### MI_FIFO #########################

##################### URI #########################
loadmodule "uri.so"
##################### URI #########################

##################### URI_DB #########################
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")
##################### URI_DB #########################

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

##################### acc #########################
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)")
##################### acc #########################

##################### auth #########################
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)")
##################### auth #########################

##################### AVPOPS #########################
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" )
##################### AVPOPS #########################

##################### DIALOG #########################
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)
##################### DIALOG #########################

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

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

##################### AUTH_DB #########################
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")
##################### AUTH_DB #########################

##################### MI_DATAGRAM #########################
loadmodule "mi_datagram.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_datagram", "socket_name", "udp:10.10.2.144:8080")
##################### MI_DATAGRAM #########################

####### Routing Logic ########
# 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. For any queries please feel free to contact us and you visit us on Gventure.

2 Comments »

  1. good tutor bro,,,

    does it fit with Solaris 10?
    I’m trying hard now..

    Comment by doddy — April 15, 2009 @ 8:53 am | Reply

  2. […] Opensip Installation and load Balance Setting Leave a Comment […]

    Pingback by Asterisk solutions « Gventure Blogs — October 13, 2009 @ 3:07 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.