Hi Kook,

If you want to use multiple domains, then the domain info must be consistent between registration and lookup - I mean users should register and be searched inside the same domain (for each user).

What domain do users A and B use for registering into OpenSIPS ? Also what is the domain in RURI when looking up for user B in OpenSIPS (for the call received from Asterisk) ?

Regards,

Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com


On 08/29/2012 12:05 PM, Kook Maeng wrote:
Hi, all.

My goal is to building scalable multi-domain(tenant) telephone system using Opensips with multiple asterisk servers that can be multi-domain.
But I ran into a problem during the progress.

Structure of the system for test is
Opensips(10.10.10.10) ------ Asterisk A(20.02.0.20), Asterisk B(30.30.30.30)

My Opensips modules(auth_db, usrloc, uri) are enabled "use_domain".
Below are flows for test.

Flow 1. Registrar
a : User A ([email protected] <mailto:[email protected]>) -----register-----> OpenSIPS => 200 OK. b : User B ([email protected] <mailto:[email protected]>) -----register-----> OpenSIPS => 200 OK.

Flow 2. User A([email protected] <mailto:[email protected]>) call User B([email protected] <mailto:[email protected]>) a : User A -----INVITE-----> OpenSIPS (via load_balancer) -----INVITE-----> Asterisk A b : Asterisk A -----Dial(SIP/${EXTEN}@OPENSIPS)-----> OpenSIPS => lookup("location) FAILED about [email protected] <mailto:[email protected]>

If "usrloc.so" dont't use domain it works good. but otherwise it fails.
I think the problem occurred because the lookup() find contact using "userid@domain".

How can I fix this? I will append content of opensips.cfg below.

Would really appreciate it if you can help.
Thanks in advance.

-Kook Maeng


----- opensip.cfg -----

####### Global Parameters #########

alias="14.63.222.202"
advertised_address="14.63.222.202"

#debug=3
#log_stderror=no
log_facility=LOG_LOCAL0

fork=yes
children=4

port=5060
#listen=udp:211.62.253.136


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

#set module path
mpath="/usr/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 "acc.so"
loadmodule "auth.so"
loadmodule "auth_db.so"
loadmodule "alias_db.so"
loadmodule "domain.so"
loadmodule "permissions.so"
loadmodule "dialog.so"
loadmodule "load_balancer.so"
loadmodule "nathelper.so"
loadmodule "sipmsgops.so"
loadmodule "group.so"

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

# ----- mi_fifo params -----
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")

# ----- rr params -----
modparam("rr", "append_fromtag", 0)

# ----- registrar params -----
modparam("registrar", "max_expires", 60)
modparam("registrar", "min_expires", 60)

# ----- usrloc params -----
modparam("usrloc", "db_mode",   2)
modparam("usrloc", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips")
modparam("usrloc", "nat_bflag", 6)
modparam("usrloc", "use_domain", 1)
modparam("usrloc", "timer_interval", 30)

# ----- uri params -----
modparam("uri", "use_uri_table", 0)
modparam("uri", "use_domain", 1)

# ----- acc params -----
modparam("acc", "early_media", 1)
modparam("acc", "report_cancels", 1)
modparam("acc", "detect_direction", 0)
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)

# ----- auth_db params -----
modparam("auth_db", "calculate_ha1", 0)
#modparam("auth_db", "password_column", "password")
modparam("auth_db", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips")
modparam("auth_db", "load_credentials", "")
modparam("auth_db", "use_domain", 1)

# ----- alias_db params -----
modparam("alias_db", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips")

# ----- domain params -----
modparam("domain", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips")
modparam("domain", "db_mode", 1)   # Use caching

# ----- multi-module params -----

# ----- dialog params -----
modparam("dialog", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
modparam("dialog", "db_mode", 1)
#modparam("dialog", "dlg_flag", 4)

# ----- load_balancer params -----
modparam("load_balancer", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")

# ----- nathelper params -----
modparam("registrar","received_avp", "$avp(i:42)")
modparam("nathelper","received_avp", "$avp(i:42)")

# ----- permissions params -----
modparam("permissions", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")

# ----- group params -----
modparam("group", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
modparam("group", "use_domain", 1)



####### Routing Logic ########


# main request routing logic

route{
        if (!mf_process_maxfwd_header("10")) {
                sl_send_reply("483","Too Many Hops");
                exit;
        }

        #---- NAT Detection ----#
        force_rport();
        #if (nat_uac_test("19")) {
        if (nat_uac_test("23")) {
                if (is_method("REGISTER")) {
                        fix_nated_register();
                } else {
                        fix_nated_contact();
                }
                setflag(5);
        }

        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.

xlog("################## HAS_TOTAG() INVITE => si: $si, sp: $sp ###################\n");
                                record_route();
                        }
# route it out to whatever destination was set by loose_route()
                        # in $du (destination URI).
                        route(1);
                } else {
/* uncomment the following lines if you want to enable presence */ ##if (is_method("SUBSCRIBE") && $rd == "your.server.ip.address") {
                        ##      # in-dialog subscribe requests
                        ##      route(2);
                        ##      exit;
                        ##}
                        if ( is_method("ACK") ) {
                                if ( t_check_trans() ) {
# non loose-route, but stateful ACK; must be an ACK after # a 487 or e.g. 404 from upstream server
                                        t_relay();
                                        exit;
                                } else {
# ACK without matching transaction ->
                                        # ignore and discard
                                        exit;
                                }
                        }
                        sl_send_reply("404","Not here");
                }
                exit;
        }

        #initial requests

        # CANCEL processing
        if (is_method("CANCEL"))
        {
                if (t_check_trans())
                        t_relay();
                exit;
        }

        t_check_trans();

        # authenticate if from local subscriber (uncomment to enable auth)
        # authenticate all initial non-REGISTER request that pretend to be
        # generated by local subscriber (domain from FROM URI is local)
##if (!(method=="REGISTER") && from_uri==myself) /*no multidomain version*/ if (!(method=="REGISTER") && is_from_local()) /*multidomain version*/
        {
                if (!check_source_address("0")) {
                        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")) {
                # load balancing
                if (!($si =~ "^115.92.199." || $si =~ "^172.27.155.27")) {
                        load_balance("2","sip");
                        if ($retcode<0) {
                                sl_send_reply("500","Service full");
                                exit;
                        }
                        xlog("Selected destination is: $du\n");
                        setflag(1); # do accounting
                        #setflag(2);
                        route(1);
                } else {
                }
                setflag(1); # do accounting
        }


        #if (!uri==myself)
        ## replace with following line if multi-domain support is used
        if (!is_uri_host_local())
        {
                append_hf("P-hint: outbound\r\n");
                # if you have some interdomain connections via TLS
                ##if($rd=="tls_domain1.net <http://tls_domain1.net>") {
                ##      t_relay("tls:domain1.net <http://domain1.net>");
                ##      exit;
##} else if($rd=="tls_domain2.net <http://tls_domain2.net>") {
                ##      t_relay("tls:domain2.net <http://domain2.net>");
                ##      exit;
                ##}
                route(1);
        }

        # requests for my domain

        ## uncomment this if you want to enable presence server
        ##   and comment the next 'if' block
        ##   NOTE: uncomment also the definition of route[2] from  below
        ##if( is_method("PUBLISH|SUBSCRIBE"))
        ##              route(2);

        if (is_method("PUBLISH"))
        {
                sl_send_reply("503", "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;
                }

                #-- Request is begind NAT(flag5) save with bflag 6 --#
                if (isflagset(5))
                        setbflag(6);

                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");


        # do lookup with method filtering
        if (!lookup("location","m")) {

xlog("L_NOTICE","\n######### LOOKUP FAILED($retcode) => [$pr:$fu/$tu/$si:$sp] $du: Processing '$rm' ########## \n\n");

                switch ($retcode) {
                        case -1:
                        case -3:
                                t_newtran();
                                t_reply("404", "Not Found");
                                exit;

                                #break;
                        case -2:
sl_send_reply("405", "Method Not Allowed");
                                exit;
                }
        }

        # when routing via usrloc, log the missed calls also
        setflag(2);

        route(1);
}

route[1] {
        # for INVITEs enable some additional helper routes
        if (subst_uri('/(sip:.*);nat=yes/\1/')) {
                setbflag(6);
        }
        if (isflagset(5)) {
                search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
        }


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

branch_route[2] {
        xlog("new branch at $ru\n");
}
onreply_route[2] {
        xlog("incoming reply\n");
        if (isbflagset(6)) {
                search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
                append_hf("P-hint: Onreply-route - fixcontact \r\n");
                fix_nated_contact();
        }
}
failure_route[1] {
        if (t_was_cancelled()) {
                exit;
        }
}


_______________________________________________
Users mailing list
[email protected]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
_______________________________________________
Users mailing list
[email protected]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

Reply via email to