[OpenSIPS-Users] Load balancer not able to send the calls to second sip server

Tushar Jain tusshar.jain at gmail.com
Mon Jun 13 04:33:33 CEST 2011


Hi Robert,

Here is the routing part which I used for load balancing-

route[1] {


          load_balance("2","sip");
        }

        # LB function returns negative if no suitable destination (for
requested resources) is found,
        # or if all destinations are full
        if ($retcode<0) {
             sl_send_reply("500","Service full");
             exit;
        }

        xlog("Selected destination is: $du\n");

        # send it out
        if (!t_relay()) {
                sl_reply_error();
        }


Regards
Tushar

On Mon, Jun 13, 2011 at 7:59 AM, Tushar Jain <tusshar.jain at gmail.com> wrote:

> Hi Robert,
>
> Thanks for looking into my problem, here I am pasting my opensips.cfg file-
> ____________________________________________________________________
>
> ####### Global Parameters #########
>
> debug=6
> log_stderror=no
> log_facility=LOG_LOCAL0
>
> fork=yes
> children=4
>
> port=5060
>
> listen=udp:x.x.x.x:5060
>
> ####### Modules Section ########
>
> mpath="//lib/opensips/modules/"
>
> loadmodule "db_mysql.so"
> loadmodule "signaling.so"
> loadmodule "sl.so"
> loadmodule "tm.so"
> loadmodule "rr.so"
> loadmodule "maxfwd.so"
> loadmodule "usrloc.so"
> loadmodule "registrar.so"
> loadmodule "textops.so"
> loadmodule "mi_fifo.so"
> loadmodule "uri.so"
> loadmodule "xlog.so"
> loadmodule "acc.so"
> loadmodule "siptrace.so"
> loadmodule "auth.so"
> loadmodule "auth_db.so"
> loadmodule "alias_db.so"
> loadmodule "domain.so"
> loadmodule "permissions.so"
> loadmodule "group.so"
> loadmodule "drouting.so"
> loadmodule "avpops.so"
> loadmodule "dialplan.so"
> loadmodule "aaa_radius.so"
> loadmodule "dialog.so"
> loadmodule "load_balancer.so"
>
> #------ avpops params -----
> modparam("avpops", "db_url", "mysql://opensips:opensipsrw@localhost
> /opensips")
> modparam("avpops", "avp_table", "usr_preferences")
>
> #------ load the dpid field to a pseudo-variable $avp(s:dpid) ------
> modparam("auth_db", "load_credentials", "$avp(s:rpid)=rpid
> ;$avp(s:countrycode)=contrycode;$avp(s:areacode)=areacode")
> modparam("dialplan", "db_url","mysql://opensips:opensipsrw@localhost
> /opensips")
>
> ## attribute of the matched line will be store in the $avp(s:dest)
> modparam("dialplan", "attrs_pvar", "$avp(s:dest)")
>
> # ----- drouting params -----
> #modparam("drouting", "sort_order", 0)
> modparam("drouting", "use_domain", 1)
> modparam("drouting","db_url", "mysql://opensips:opensipsrw@localhost
> /opensips")
> modparam("drouting", "probing_interval", 60)
> modparam("drouting", "probing_from", "sip:pinger at x.x.x.x")
> modparam("drouting", "probing_method", "OPTIONS")
> modparam("drouting", "probing_reply_codes", "501, 403, 404")
>
> # ----- Group ----
> modparam("group","db_url","mysql://opensips:opensipsrw@localhost
> /opensips")
>
> # ----- mi_fifo params -----
> modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
> modparam("mi_fifo", "fifo_mode", 0666)
> modparam("dialog", "dlg_flag", 13)
> modparam("dialog", "db_mode", 1)
> modparam("dialog", "db_url", "mysql://opensips:opensipsrw@localhost
> /opensips")
> modparam("dialog", "timeout_avp", "$avp(i:30)")
> modparam("dialog", "default_timeout", 3600)
>
>
> # ----- Load Balancer -----
> modparam("load_balancer", "db_url","mysql://opensips:opensipsrw@localhost
> /opensips")
> modparam("load_balancer", "probing_interval", 60)
> modparam("load_balancer", "probing_method", "INFO")
> modparam("load_balancer", "probing_from", "sip:1000 at x.x.x.x")
> modparam("load_balancer", "db_table", "load_balancer")
> modparam("load_balancer", "probing_reply_codes", "501, 403, 404")
>
> # ----- registrar params -----
> /* uncomment the next line not to allow more than 10 contacts per AOR */
> #modparam("registrar", "max_contacts", 10)
>
>
> # ----- usrloc params -----
>
> modparam("usrloc", "db_mode",   0)
>
> /* uncomment the following lines if you want to enable DB persistency
>    for location entries */
> modparam("usrloc", "db_mode",   2)
> modparam("usrloc", "db_url", "mysql://opensips:opensipsrw@localhost
> /opensips")
>
>
> # ----- uri params -----
> modparam("uri", "use_uri_table", 0)
>
>
> # ----- acc params -----
> /* what sepcial events should be accounted ? */
> modparam("acc", "early_media", 0)
> modparam("acc", "report_ack", 0)
> modparam("acc", "report_cancels", 0)
> modparam("acc", "detect_direction", 0)
> modparam("acc", "failed_transaction_flag", 1)
> modparam("acc", "log_level", 1)
> modparam("acc", "log_flag", 1)
> modparam("acc", "log_missed_flag", 1)
> modparam("acc", "db_flag", 1)
> modparam("acc", "db_missed_flag", 2)
> modparam("acc", "aaa_url", "radius:/etc/radiusclient-ng/radiusclient.conf")
> # Point the configuration file
> modparam("acc", "service_type", 15) # Set the service_type to 15
> modparam("acc", "aaa_flag", 1)
> modparam("acc", "aaa_missed_flag", 1)
>
> # ----- auth_db params -----
> /* uncomment the following lines if you want to enable the DB based
>    authentication */
>
> modparam("auth_db", "calculate_ha1", yes)
> modparam("auth_db", "password_column", "password")
>
> modparam("auth_db", "db_url","mysql://opensips:opensipsrw@localhost
> /opensips")
> modparam("auth_db", "load_credentials", "")
>
> ####### Routing Logic ########
>
> # main request routing logic
>
> route{
>
> setflag(22);
>         sip_trace();
>
> if (!mf_process_maxfwd_header("10")) {
>  sl_send_reply("483","Too Many Hops");
> exit;
> }
>
> #---- Sequential requests section ----#
>
> if (has_totag()) {
> # sequential request withing a dialog should
>  # take the path determined by record-routing
> if (loose_route()) {
> if (is_method("BYE")) {
>  setflag(1); # do accounting ...
> setflag(3); # ... even if the transaction fails
> } else if (is_method("INVITE")) {
>  # even if in most of the cases is useless, do RR for
> # re-INVITEs alos, as some buggy clients do change route set
>  # during the dialog.
> record_route();
> }
> # route it out to whatever destination was set by loose_route()
>  # in $du (destination URI).
> route(1);
> } else {
>  if ( is_method("ACK") ) {
> if ( t_check_trans() ) {
> t_relay();
>  exit;
> } else {
> exit;
> }
>  }
> sl_send_reply("404","Not here");
> }
>  exit;
> }
>
>
> #---- initial requests section ----#
>
> # CANCEL processing
>  if (is_method("CANCEL"))
> {
> if (t_check_trans())
>  t_relay();
> exit;
> }
>
> t_check_trans();
>
> if (!(method=="REGISTER") && from_uri==myself) /*no multidomain version*/
> if (!(method=="REGISTER") && is_from_local())  /*multidomain version*/
>  {
> if (!proxy_authorize("", "subscriber")) {
> proxy_challenge("", "0");
>  exit;
> }
> if (!db_check_from()) {
> sl_send_reply("403","Forbidden auth ID");
>  exit;
> }
>  consume_credentials();
>  # caller authenticated
> }
>
>
> #------------------ preloaded route checking ---------------------#
>
> if (loose_route()) {
> xlog("L_ERR",
> "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
>  if (!is_method("ACK"))
> sl_send_reply("403","Preload Route denied");
> exit;
>  }
>
> # record routing
> if (!is_method("REGISTER|MESSAGE"))
>  record_route();
>
> # account only INVITEs
> if (is_method("INVITE")) {
>  setflag(1); # do accounting
> setflag(2); # Account Missed Calls
> setflag(3); # Account Failed Transactions
>  }
> if (!uri==myself)
>
>
> #---- Routing to external domains ----#
>
>
> ## replace with following line if multi-domain support is used
> if (!is_uri_host_local())
>  {
> if(is_from_local()) {
> route(1);
> } else {
>  sl_send_reply("403","Not here");
> }
> }
>  append_hf("P-hint: outbound\r\n");
>
> if (is_method("PUBLISH"))
> {
>  sl_send_reply("$rc", "Service Unavailable");
> exit;
> }
>
> if (is_method("REGISTER"))
> {
>  # authenticate the REGISTER requests (uncomment to enable auth)
> if (!www_authorize("", "subscriber"))
>  {
> www_challenge("", "0");
> exit;
>  }
>  if (!db_check_to())
> {
>  sl_send_reply("403","Forbidden auth ID");
> exit;
> }
>
> if (!save("location"))
> sl_reply_error();
>
> exit;
>  }
>
> if ($rU==NULL) {
> # request with no Username in RURI
>  sl_send_reply("484","Address Incomplete");
> exit;
> }
>
> # apply DB based aliases (uncomment to enable)
> alias_db_lookup("dbaliases");
>
>
> if(!dp_translate("0","$rU/$rU")){
>   send_reply("420", "Invalid Destination");
>    exit;
> }
> xlog("$avp(s:dest)");
> if ($avp(s:dest)=="usrloc") {
>    #Route to usrloc
>   route(3);
> }
> if ($avp(s:dest)=="pstn") {
>    #route to pstn
>   route(4);
> }
> if ($avp(s:dest)=="media") {
>    #route to media server
>   route(5);
> }
> send_reply("420", "Invalid Extension");
>    exit;
>       }
>
>
> route[1] {
>
>
>           load_balance("2","sip");
>         }
>
>         # LB function returns negative if no suitable destination (for
> requested resources) is found,
>         # or if all destinations are full
>         if ($retcode<0) {
>              sl_send_reply("500","Service full");
>              exit;
>         }
>
>         xlog("Selected destination is: $du\n");
>
>         # send it out
>         if (!t_relay()) {
>                 sl_reply_error();
>         }
> #        }
>
>
> # for INVITEs enable some additional helper routes
>
>
> if (is_method("INVITE")) {
> t_on_branch("2");
> t_on_reply("2");
>  t_on_failure("1");
>      }
>      if (!t_relay()) {
>  sl_reply_error();
>      };
>      exit;
>
>
> xlog("Selected destination is: $du\n");
>
>         # send it out
> if (!t_relay()) {
>  sl_reply_error();
> }
> }
>
> #Route for user lookups
>
> route[3]{
> if (!lookup("location", "m")) {
> switch ($retcode) {
>  case -1:
> case -3:
> t_newtran();
> t_reply("404", "Not Found");
>  exit;
> case -2:
> sl_send_reply("405", "Method Not Allowed");
>  exit;
> }
>       }
> # when routing via usrloc, log the missed calls also
>  setflag(2);
> route(1);
> }
>
> route[4] {
>  #---- PSTN route ----#
> if(!do_routing()){
> send_reply("503", "No rules found matching the URI prefix");
>  exit;
> }
> # flag 10 - route to pstn
> setflag(10);
>  route(1);
> }
>
> route[5] {
> #---- Route to media servers ----#
>  xlog("route to media servers");
> }
> branch_route[2] {
>  xlog("new branch at $ru\n");
> }
> onreply_route[2] {
>  xlog("incoming reply\n");
> }
> failure_route[1] {
>  if (t_was_cancelled()) {
> exit;
> }
> if(isflagset(10)){
>  if (use_next_gw()) {
> xlog ("next gateway $ru \n");
> t_on_failure("1");
>  t_relay();
> exit;
> }
> else {
>  t_reply("$rc", "Service not available, no more gateways");
> #t_reply("$T_reply_code");
>  exit;
> }
> }
> }
>
> Regards
> Tushar
>



-- 
Regards

Tushar Jain


"two roads diverged in a wood, and I - I took the one less traveled by, and
that has made all the difference"

--Robert Frost "
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20110613/7a8d07d0/attachment-0001.htm>


More information about the Users mailing list