[OpenSIPS-Users] Asterisk Load Balancing with OpenSIPS + dispatcher

Gonzalo Gonzalez gonzovoip at yahoo.com
Thu Jan 22 21:02:17 CET 2009


I am trying to translate the config file on the link from openser to opensips 1.4, but I am having an issue registering users, it looks like there is a loop, but I don't know what am I doing wrong. I can make a call from a user account to PSTN thru asterisk; I mean:

user ---->> opensips --->> asterisk --->> PSTN , but when I try to register the user with opensips I get Registration error:483 Too Many Hops

This is my config:



# ----------- global configuration parameters ------------------------
debug=3            # debug level (cmd line: -dddddddddd)
fork=yes
log_stderror=no    # (cmd line: -E)
children=4
disable_tcp=yes
port=5060

# ------------------ module loading ----------------------------------
#set module path
mpath="/usr/local/lib/opensips/modules/"

loadmodule "db_mysql.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "uri.so"
loadmodule "uri_db.so"
loadmodule "domain.so"
loadmodule "permissions.so"
loadmodule "group.so"
loadmodule "mi_fifo.so"
loadmodule "xlog.so"
loadmodule "avpops.so"
loadmodule "lcr.so"

# Uncomment this if you want digest authentication
# mysql.so must be loaded !
loadmodule "auth.so"
loadmodule "auth_db.so"

# ----------------- setting module-specific parameters ---------------

modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("usrloc", "db_mode", 2)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("rr", "enable_full_lr", 1)
modparam("auth_db|permissions|uri_db|usrloc","db_url","mysql://opensips:opensipsrw@localhost/opensips")
modparam("permissions", "db_mode", 1)
modparam("permissions", "trusted_table", "trusted")
modparam("tm", "fr_timer",5)
modparam("tm", "fr_inv_timer_avp", "$avp(i:704)")
modparam("lcr","db_url","mysql://opensips:opensipsrw@localhost/opensips")
modparam("lcr","fr_inv_timer",90)
modparam("lcr","fr_inv_timer_next",30)
modparam("lcr", "fr_inv_timer_avp", "$avp(i:704)")
modparam("lcr", "gw_uri_avp", "$avp(i:709)")
modparam("lcr", "ruri_user_avp", "$avp(i:500)")
modparam("lcr", "contact_avp", "$avp(i:711)")
modparam("lcr", "rpid_avp", "$avp(i:302)")
modparam("lcr", "flags_avp", "$avp(i:712)")
#modparam("lcr", "dm_flag", 13)




# -------------------------  request routing logic -------------------



# main routing logic
route{

    # initial sanity checks -- messages with
    # max_forwards==0, or excessively long requests
    if (!mf_process_maxfwd_header("10")) {
        sl_send_reply("483","Too Many Hops");
        exit;
    };

    if (msg:len >=  2048 ) {
        sl_send_reply("513", "Message too big");
        exit;
    };

    # we record-route all messages -- to make sure that
    # subsequent messages will go through our proxy; that's
    # particularly good if upstream and downstream entities
    # use different transport protocol
    if (!method=="REGISTER")
        record_route();

    # subsequent messages withing a dialog should take the
    # path determined by record-routing
    if (loose_route()) {
        # mark routing logic in request
        append_hf("P-hint: rr-enforced\r\n"); 
        route(1);
    };

    if (!uri==myself) {
        # mark routing logic in request
        append_hf("P-hint: outbound\r\n"); 
        route(1);
    };

    if (uri==myself) {
        if (is_method("INVITE")) {
            append_hf("P-hint: lcr applied\r\n"); 
            # applying lcr routing
            route(2);
        };
    };

    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;
}

route[2] {
    # load the gateways
    if (!load_gws()) {
        sl_send_reply("503", "Unable to load gateways");
        exit;
    } else {
        $var(i) = 0;
        #while($(avp(i:709)[$var(i)]) != null) {
        while(is_avp_set("$(avp(i:709)[$var(i)])")) {
            xlog("L_INFO", "loading gw_uri_avp[$var(i)]='$(avp(i:709)[$var(i)])'\n");
            $var(i) = $var(i) + 1;
        };
        if(is_avp_set("$avp(i:709)")) {
            xlog("L_INFO", "trying gateway '$avp(i:709)'\n");
        } else {
            xlog("L_INFO", "no available gateways ...\n");
        };
        # try the first matched gateway
        if (next_gw()) {
            xlog("L_INFO", "ruri_user_avp='$avp(i:500)'\n");
            # prepare for lcr failover
            t_on_failure("2");
            route(1);
        } else {
            sl_send_reply("503", "No available gateways");
            exit;
        };
    };
    exit;
}


failure_route[2] {
    xlog("L_INFO", "entering failure_route[2] for reply code '$T_reply_code'\n");
    # the previous gateway is no good
    if (t_check_status("408|50[34]")) {
        if(is_avp_set("$avp(i:709)")) {
            xlog("L_INFO", "trying next gateway '$avp(i:709)'\n");
        } else {
            xlog("L_INFO", "no more gateways to try ...\n");
        };
        # route to the next gateway
        if (next_gw()) {
            # prepare for lcr failover
            t_on_failure("2");
            route(1);
        } else {
            t_reply("503", "No gateways");
            exit;
        };
        exit;
    };
}





--- On Sun, 10/5/08, Darren Sessions <dmsessions at gmail.com> wrote:
From: Darren Sessions <dmsessions at gmail.com>
Subject: Re: [OpenSIPS-Users] Asterisk Load Balancing with OpenSIPS + dispatcher
To: "Ovidiu Sas" <osas at voipembedded.com>
Cc: users at lists.opensips.org
Date: Sunday, October 5, 2008, 2:38 AM

Excellent reference material Ovidiu! I'll be bookmarking your example myself.  
Cheers,- Darren_____________________________
Darren Sessionsdmsessions at gmail.comhttp://www.darrensessions.com_____________________________



 
On Oct 4, 2008, at 8:32 PM, Ovidiu Sas wrote:
Hello John,

Here's a working example of an lcr implementation:
http://voipembedded.com/resources/openser_dbtext_lcr.cfg
This is for openser 1.3, but you should be able to port it to 1.4.
If I have time, I will post a dispatcher one too ...

Regards,
Ovidiu Sas

On Sat, Oct 4, 2008 at 9:53 PM, John D <mnemonic81 at gmail.com> wrote:
Hi Darren,

I'd like to use whichever works. I don't have a particular reason for using
dispatcher other than running across the module on Google. Are either
load_gw or dispatcher clever enough to use a SIP proxy that's available (aka
failover in case one node dies) and is it clever enough to know which SIP
proxy has less of a load than the other, or does it just round robin?

Thanks.

On Sat, Oct 4, 2008 at 9:48 PM, Darren Sessions <dmsessions at gmail.com>
wrote:

If you're just load balancing two Asterisk servers, why not use the
load_gw function?


_____________________________
Darren Sessions
dmsessions at gmail.com
http://www.darrensessions.com
_____________________________




On Oct 4, 2008, at 7:41 PM, John D wrote:

All,

I'm trying to find some half-decent documentation to get OpenSIPS working
with the dispatcher module for simply load balancing two Asterisk servers.
Most links on voip-info.org and even some on opensips.org appear dated or
404. I was hoping to try the mail list to see if anyone could kindly suggest
the best resource for currently setting up the above (and most importantly
how to work with the dispatcher module).

Thanks!
_______________________________________________
Users mailing list
Users at lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


_______________________________________________
Users mailing list
Users at lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users



_______________________________________________
Users mailing list
Users at lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users



_______________________________________________
Users mailing list
Users at lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.opensips.org/pipermail/users/attachments/20090122/b1d9f399/attachment-0001.htm 


More information about the Users mailing list