<div>Hi, all.</div><div><br></div><div>My goal is to building scalable multi-domain(tenant) telephone system using Opensips with multiple asterisk servers that can be multi-domain.</div><div>But I ran into a problem during the progress.</div>
<div><br></div><div>Structure of the system for test is</div><div>Opensips(10.10.10.10) ------ Asterisk A(20.02.0.20), Asterisk B(30.30.30.30)</div><div><br></div><div>My Opensips modules(auth_db, usrloc, uri) are enabled &quot;use_domain&quot;.</div>
<div>Below are flows for test.</div><div><br></div><div>Flow 1. Registrar</div><div>a : User A (<a href="mailto:1000@foo.com">1000@foo.com</a>) -----register-----&gt; OpenSIPS  =&gt; 200 OK.</div><div>b : User B (<a href="mailto:2000@bar.com">2000@bar.com</a>) -----register-----&gt; OpenSIPS  =&gt; 200 OK.</div>
<div><br></div><div>Flow 2. User A(<a href="mailto:1000@foo.com">1000@foo.com</a>) call User B(<a href="mailto:2000@bar.com">2000@bar.com</a>)</div><div>a :  User A -----INVITE-----&gt; OpenSIPS (via load_balancer) -----INVITE-----&gt; Asterisk A</div>
<div>b :  Asterisk A -----Dial(SIP/${EXTEN}@OPENSIPS)-----&gt; OpenSIPS =&gt; lookup(&quot;location) FAILED about <a href="mailto:2000@10.10.10.10">2000@10.10.10.10</a></div><div><br></div><div>If &quot;usrloc.so&quot; dont&#39;t use domain it works good. but otherwise it fails.</div>
<div>I think the problem occurred because the lookup() find contact using &quot;userid@domain&quot;.</div><div><br></div><div>How can I fix this? I will append content of opensips.cfg below.</div><div><br></div><div>Would really appreciate it if you can help.</div>
<div>Thanks in advance.</div><div><br></div><div>-Kook Maeng</div><div><br></div><div><br></div><div>----- opensip.cfg -----</div><div><br></div><div>####### Global Parameters #########</div><div><br></div><div>alias=&quot;14.63.222.202&quot;</div>
<div>advertised_address=&quot;14.63.222.202&quot;</div><div><br></div><div>#debug=3</div><div>#log_stderror=no</div><div>log_facility=LOG_LOCAL0</div><div><br></div><div>fork=yes</div><div>children=4</div><div><br></div><div>
port=5060</div><div>#listen=udp:211.62.253.136</div><div><br></div><div><br></div><div>####### Modules Section ########</div><div><br></div><div>#set module path</div><div>mpath=&quot;/usr/lib/opensips/modules/&quot;</div>
<div><br></div><div>loadmodule &quot;db_mysql.so&quot;</div><div>loadmodule &quot;signaling.so&quot;</div><div>loadmodule &quot;sl.so&quot;</div><div>loadmodule &quot;tm.so&quot;</div><div>loadmodule &quot;rr.so&quot;</div>
<div>loadmodule &quot;maxfwd.so&quot;</div><div>loadmodule &quot;usrloc.so&quot;</div><div>loadmodule &quot;registrar.so&quot;</div><div>loadmodule &quot;textops.so&quot;</div><div>loadmodule &quot;mi_fifo.so&quot;</div><div>
loadmodule &quot;uri.so&quot;</div><div>loadmodule &quot;acc.so&quot;</div><div>loadmodule &quot;auth.so&quot;</div><div>loadmodule &quot;auth_db.so&quot;</div><div>loadmodule &quot;alias_db.so&quot;</div><div>loadmodule &quot;domain.so&quot;</div>
<div>loadmodule &quot;permissions.so&quot;</div><div>loadmodule &quot;dialog.so&quot;</div><div>loadmodule &quot;load_balancer.so&quot;</div><div>loadmodule &quot;nathelper.so&quot;</div><div>loadmodule &quot;sipmsgops.so&quot;</div>
<div>loadmodule &quot;group.so&quot;</div><div><br></div><div># ----------------- setting module-specific parameters ---------------</div><div><br></div><div># ----- mi_fifo params -----</div><div>modparam(&quot;mi_fifo&quot;, &quot;fifo_name&quot;, &quot;/tmp/opensips_fifo&quot;)</div>
<div><br></div><div># ----- rr params -----</div><div>modparam(&quot;rr&quot;, &quot;append_fromtag&quot;, 0)</div><div><br></div><div># ----- registrar params -----</div><div>modparam(&quot;registrar&quot;, &quot;max_expires&quot;, 60)</div>
<div>modparam(&quot;registrar&quot;, &quot;min_expires&quot;, 60)</div><div><br></div><div># ----- usrloc params -----</div><div>modparam(&quot;usrloc&quot;, &quot;db_mode&quot;,   2)</div><div>modparam(&quot;usrloc&quot;, &quot;db_url&quot;,</div>
<div>        &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div><div>modparam(&quot;usrloc&quot;, &quot;nat_bflag&quot;, 6)</div><div>modparam(&quot;usrloc&quot;, &quot;use_domain&quot;, 1)</div><div>modparam(&quot;usrloc&quot;, &quot;timer_interval&quot;, 30)</div>
<div><br></div><div># ----- uri params -----</div><div>modparam(&quot;uri&quot;, &quot;use_uri_table&quot;, 0)</div><div>modparam(&quot;uri&quot;, &quot;use_domain&quot;, 1)</div><div><br></div><div># ----- acc params -----</div>
<div>modparam(&quot;acc&quot;, &quot;early_media&quot;, 1)</div><div>modparam(&quot;acc&quot;, &quot;report_cancels&quot;, 1)</div><div>modparam(&quot;acc&quot;, &quot;detect_direction&quot;, 0)</div><div>modparam(&quot;acc&quot;, &quot;failed_transaction_flag&quot;, 3)</div>
<div>modparam(&quot;acc&quot;, &quot;log_flag&quot;, 1)</div><div>modparam(&quot;acc&quot;, &quot;log_missed_flag&quot;, 2)</div><div>modparam(&quot;acc&quot;, &quot;db_flag&quot;, 1)</div><div>modparam(&quot;acc&quot;, &quot;db_missed_flag&quot;, 2)</div>
<div><br></div><div># ----- auth_db params -----</div><div>modparam(&quot;auth_db&quot;, &quot;calculate_ha1&quot;, 0)</div><div>#modparam(&quot;auth_db&quot;, &quot;password_column&quot;, &quot;password&quot;)</div><div>
modparam(&quot;auth_db&quot;, &quot;db_url&quot;,</div><div>        &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div><div>modparam(&quot;auth_db&quot;, &quot;load_credentials&quot;, &quot;&quot;)</div><div>
modparam(&quot;auth_db&quot;, &quot;use_domain&quot;, 1)</div><div><br></div><div># ----- alias_db params -----</div><div>modparam(&quot;alias_db&quot;, &quot;db_url&quot;,</div><div>        &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div>
<div><br></div><div># ----- domain params -----</div><div>modparam(&quot;domain&quot;, &quot;db_url&quot;,</div><div>        &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div><div>modparam(&quot;domain&quot;, &quot;db_mode&quot;, 1)   # Use caching</div>
<div><br></div><div># ----- multi-module params -----</div><div><br></div><div># ----- dialog params -----</div><div>modparam(&quot;dialog&quot;, &quot;db_url&quot;, &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div>
<div>modparam(&quot;dialog&quot;, &quot;db_mode&quot;, 1)</div><div>#modparam(&quot;dialog&quot;, &quot;dlg_flag&quot;, 4)</div><div><br></div><div># ----- load_balancer params -----</div><div>modparam(&quot;load_balancer&quot;, &quot;db_url&quot;, &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div>
<div><br></div><div># ----- nathelper params -----</div><div>modparam(&quot;registrar&quot;,&quot;received_avp&quot;, &quot;$avp(i:42)&quot;)</div><div>modparam(&quot;nathelper&quot;,&quot;received_avp&quot;, &quot;$avp(i:42)&quot;)</div>
<div><br></div><div># ----- permissions params -----</div><div>modparam(&quot;permissions&quot;, &quot;db_url&quot;, &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div><div><br></div><div># ----- group params -----</div>
<div>modparam(&quot;group&quot;, &quot;db_url&quot;, &quot;mysql://opensips:opensipsrw@localhost/opensips&quot;)</div><div>modparam(&quot;group&quot;, &quot;use_domain&quot;, 1)</div><div><br></div><div><br></div><div><br>
</div><div>####### Routing Logic ########</div><div><br></div><div><br></div><div># main request routing logic</div><div><br></div><div>route{</div><div>        if (!mf_process_maxfwd_header(&quot;10&quot;)) {</div><div>                sl_send_reply(&quot;483&quot;,&quot;Too Many Hops&quot;);</div>
<div>                exit;</div><div>        }</div><div><br></div><div>        #---- NAT Detection ----#</div><div>        force_rport();</div><div>        #if (nat_uac_test(&quot;19&quot;)) {</div><div>        if (nat_uac_test(&quot;23&quot;)) {</div>
<div>                if (is_method(&quot;REGISTER&quot;)) {</div><div>                        fix_nated_register();</div><div>                } else {</div><div>                        fix_nated_contact();</div><div>                }</div>
<div>                setflag(5);</div><div>        }</div><div><br></div><div>        if (has_totag()) {</div><div>                # sequential request withing a dialog should</div><div>                # take the path determined by record-routing</div>
<div>                if (loose_route()) {</div><div>                        if (is_method(&quot;BYE&quot;)) {</div><div>                                setflag(1); # do accounting ...</div><div>                                setflag(3); # ... even if the transaction fails</div>
<div>                        } else if (is_method(&quot;INVITE&quot;)) {</div><div>                                # even if in most of the cases is useless, do RR for</div><div>                                # re-INVITEs alos, as some buggy clients do change route set</div>
<div>                                # during the dialog.</div><div><br></div><div>                                xlog(&quot;################## HAS_TOTAG() INVITE =&gt; si: $si, sp: $sp ###################\n&quot;);</div>
<div>                                record_route();</div><div>                        }</div><div>                        # route it out to whatever destination was set by loose_route()</div><div>                        # in $du (destination URI).</div>
<div>                        route(1);</div><div>                } else {</div><div>                        /* uncomment the following lines if you want to enable presence */</div><div>                        ##if (is_method(&quot;SUBSCRIBE&quot;) &amp;&amp; $rd == &quot;your.server.ip.address&quot;) {</div>
<div>                        ##      # in-dialog subscribe requests</div><div>                        ##      route(2);</div><div>                        ##      exit;</div><div>                        ##}</div><div>                        if ( is_method(&quot;ACK&quot;) ) {</div>
<div>                                if ( t_check_trans() ) {</div><div>                                        # non loose-route, but stateful ACK; must be an ACK after </div><div>                                        # a 487 or e.g. 404 from upstream server</div>
<div>                                        t_relay();</div><div>                                        exit;</div><div>                                } else {</div><div>                                        # ACK without matching transaction -&gt;</div>
<div>                                        # ignore and discard</div><div>                                        exit;</div><div>                                }</div><div>                        }</div><div>                        sl_send_reply(&quot;404&quot;,&quot;Not here&quot;);</div>
<div>                }</div><div>                exit;</div><div>        }</div><div><br></div><div>        #initial requests</div><div><br></div><div>        # CANCEL processing</div><div>        if (is_method(&quot;CANCEL&quot;))</div>
<div>        {</div><div>                if (t_check_trans())</div><div>                        t_relay();</div><div>                exit;</div><div>        }</div><div><br></div><div>        t_check_trans();</div><div><br>
</div><div>        # authenticate if from local subscriber (uncomment to enable auth)</div><div>        # authenticate all initial non-REGISTER request that pretend to be</div><div>        # generated by local subscriber (domain from FROM URI is local)</div>
<div>        ##if (!(method==&quot;REGISTER&quot;) &amp;&amp; from_uri==myself) /*no multidomain version*/</div><div>        if (!(method==&quot;REGISTER&quot;) &amp;&amp; is_from_local())  /*multidomain version*/</div><div>
        {</div><div>                if (!check_source_address(&quot;0&quot;)) {</div><div>                        if (!proxy_authorize(&quot;&quot;, &quot;subscriber&quot;)) {</div><div>                                proxy_challenge(&quot;&quot;, &quot;0&quot;);</div>
<div>                                exit;</div><div>                        }</div><div>                        if (!db_check_from()) {</div><div>                                sl_send_reply(&quot;403&quot;,&quot;Forbidden auth ID&quot;);</div>
<div>                                exit;</div><div>                        }</div><div><br></div><div>                        consume_credentials();</div><div>                        # caller authenticated</div><div>                        #}</div>
<div>                }</div><div>        }</div><div><br></div><div>        # preloaded route checking</div><div>        if (loose_route()) {</div><div>                xlog(&quot;L_ERR&quot;, &quot;Attempt to route with preloaded Route&#39;s [$fu/$tu/$ru/$ci]&quot;);</div>
<div>                if (!is_method(&quot;ACK&quot;))</div><div>                        sl_send_reply(&quot;403&quot;,&quot;Preload Route denied&quot;);</div><div>                exit;</div><div>        }</div><div><br></div>
<div>        # record routing</div><div>        if (!is_method(&quot;REGISTER|MESSAGE&quot;))</div><div>                record_route();</div><div><br></div><div><br></div><div><br></div><div>        # account only INVITEs</div>
<div>        if (is_method(&quot;INVITE&quot;)) {</div><div>                # load balancing</div><div>                if (!($si =~ &quot;^115.92.199.&quot; || $si =~ &quot;^172.27.155.27&quot;)) {</div><div>                        load_balance(&quot;2&quot;,&quot;sip&quot;);</div>
<div>                        if ($retcode&lt;0) {</div><div>                                sl_send_reply(&quot;500&quot;,&quot;Service full&quot;);</div><div>                                exit;</div><div>                        }</div>
<div>                        xlog(&quot;Selected destination is: $du\n&quot;);</div><div>                        setflag(1); # do accounting</div><div>                        #setflag(2);</div><div>                        route(1);</div>
<div>                } else {</div><div>                }</div><div>                setflag(1); # do accounting</div><div>        }</div><div><br></div><div><br></div><div>        #if (!uri==myself)</div><div>        ## replace with following line if multi-domain support is used</div>
<div>        if (!is_uri_host_local())</div><div>        {</div><div>                append_hf(&quot;P-hint: outbound\r\n&quot;); </div><div>                # if you have some interdomain connections via TLS</div><div>                ##if($rd==&quot;<a href="http://tls_domain1.net">tls_domain1.net</a>&quot;) {</div>
<div>                ##      t_relay(&quot;tls:<a href="http://domain1.net">domain1.net</a>&quot;);</div><div>                ##      exit;</div><div>                ##} else if($rd==&quot;<a href="http://tls_domain2.net">tls_domain2.net</a>&quot;) {</div>
<div>                ##      t_relay(&quot;tls:<a href="http://domain2.net">domain2.net</a>&quot;);</div><div>                ##      exit;</div><div>                ##}</div><div>                route(1);</div><div>        }</div>
<div><br></div><div>        # requests for my domain</div><div><br></div><div>        ## uncomment this if you want to enable presence server </div><div>        ##   and comment the next &#39;if&#39; block</div><div>        ##   NOTE: uncomment also the definition of route[2] from  below</div>
<div>        ##if( is_method(&quot;PUBLISH|SUBSCRIBE&quot;))</div><div>        ##              route(2);</div><div><br></div><div>        if (is_method(&quot;PUBLISH&quot;))</div><div>        {</div><div>                sl_send_reply(&quot;503&quot;, &quot;Service Unavailable&quot;);</div>
<div>                exit;</div><div>        }</div><div><br></div><div>        if (is_method(&quot;REGISTER&quot;))</div><div>        {</div><div>                # authenticate the REGISTER requests (uncomment to enable auth)</div>
<div>                if (!www_authorize(&quot;&quot;, &quot;subscriber&quot;))</div><div>                {</div><div>                        www_challenge(&quot;&quot;, &quot;0&quot;);</div><div>                        exit;</div>
<div>                }</div><div><br></div><div>                if (!db_check_to()) </div><div>                {</div><div>                        sl_send_reply(&quot;403&quot;,&quot;Forbidden auth ID&quot;);</div><div>                        exit;</div>
<div>                }</div><div><br></div><div>                #-- Request is begind NAT(flag5) save with bflag 6 --#</div><div>                if (isflagset(5))</div><div>                        setbflag(6);</div><div><br>
</div><div>                if (!save(&quot;location&quot;))</div><div>                        sl_reply_error();</div><div><br></div><div>                exit;</div><div>        }</div><div><br></div><div>        if ($rU==NULL) {</div>
<div>                # request with no Username in RURI</div><div>                sl_send_reply(&quot;484&quot;,&quot;Address Incomplete&quot;);</div><div>                exit;</div><div>        }</div><div><br></div><div>
        # apply DB based aliases (uncomment to enable)</div><div>        alias_db_lookup(&quot;dbaliases&quot;);</div><div><br></div><div><br></div><div>        # do lookup with method filtering</div><div>        if (!lookup(&quot;location&quot;,&quot;m&quot;)) {</div>
<div><br></div><div>                xlog(&quot;L_NOTICE&quot;,&quot;\n######### LOOKUP FAILED($retcode) =&gt; [$pr:$fu/$tu/$si:$sp] $du: Processing &#39;$rm&#39; ########## \n\n&quot;);</div><div><br></div><div>                switch ($retcode) {</div>
<div>                        case -1:</div><div>                        case -3:</div><div>                                t_newtran();</div><div>                                t_reply(&quot;404&quot;, &quot;Not Found&quot;);</div>
<div>                                exit;</div><div><br></div><div>                                #break;</div><div>                        case -2:</div><div>                                sl_send_reply(&quot;405&quot;, &quot;Method Not Allowed&quot;);</div>
<div>                                exit;</div><div>                }</div><div>        }</div><div><br></div><div>        # when routing via usrloc, log the missed calls also</div><div>        setflag(2);</div><div><br>
</div><div>        route(1);</div><div>}</div><div><br></div><div>route[1] {</div><div>        # for INVITEs enable some additional helper routes</div><div>        if (subst_uri(&#39;/(sip:.*);nat=yes/\1/&#39;)) {</div><div>
                setbflag(6);</div><div>        }</div><div>        if (isflagset(5)) {</div><div>                search_append(&#39;Contact:.*sip:[^&gt;[:cntrl:]]*&#39;, &#39;;nat=yes&#39;);</div><div>        }</div><div>
<br></div><div><br></div><div>        # for INVITEs enable some additional helper routes</div><div>        if (is_method(&quot;INVITE&quot;)) {</div><div>                t_on_branch(&quot;2&quot;);</div><div>                t_on_reply(&quot;2&quot;);</div>
<div>                t_on_failure(&quot;1&quot;);</div><div>        }</div><div><br></div><div>        if (!t_relay()) {</div><div>                sl_reply_error();</div><div>        };</div><div>        exit;</div><div>}</div>
<div><br></div><div>branch_route[2] {</div><div>        xlog(&quot;new branch at $ru\n&quot;);</div><div>}</div><div>onreply_route[2] {</div><div>        xlog(&quot;incoming reply\n&quot;);</div><div>        if (isbflagset(6)) {</div>
<div>                search_append(&#39;Contact:.*sip:[^&gt;[:cntrl:]]*&#39;, &#39;;nat=yes&#39;);</div><div>                append_hf(&quot;P-hint: Onreply-route - fixcontact \r\n&quot;);</div><div>                fix_nated_contact();</div>
<div>        }</div><div>}</div><div>failure_route[1] {</div><div>        if (t_was_cancelled()) {</div><div>                exit;</div><div>        }</div><div>}</div>