Hi Bogdan,<div><br></div><div>In my tests when all resources from group id 1 (with higher priority) are busy (or fail to accept call with some error) I&#39;m calling load_balance for group id 2. Although there is available destinations on this group, return code from load_balance call is &lt; 0. So this is the point where I&#39;m stuck. </div>
<div><br></div><div>Any help appreciated.</div><div><br></div><div>Here&#39;s my configuration.</div><div><br></div><div>load_balancer table</div><div>-------------------------------</div><div><div>+----+----------+---------------------+-----------+------------+-------------+</div>
<div>| id | group_id | dst_uri             | resources | probe_mode | description |</div><div>+----+----------+---------------------+-----------+------------+-------------+</div><div>| 95 |     8002 | <a href="mailto:sip%3Aar@10.10.5.23">sip:ar@10.10.5.23</a>   | sip=1     |          2 |             |</div>
<div>| 19 |     8002 | <a href="mailto:sip%3Aar@10.10.5.44">sip:ar@10.10.5.44</a>   | sip=1     |          2 |             |</div><div>| 20 |     8003 | <a href="mailto:sip%3Aar@10.210.54.86">sip:ar@10.210.54.86</a> | sip=1     |          2 |             |</div>
<div>| 96 |     8002 | <a href="mailto:sip%3Aar@10.10.5.13">sip:ar@10.10.5.13</a>   | sip=1     |          2 |             |</div><div>| 97 |     8002 | <a href="mailto:sip%3Aar@10.10.5.10">sip:ar@10.10.5.10</a>   | sip=1     |          2 |             |</div>
<div>| 98 |     8002 | <a href="mailto:sip%3Aar@10.10.6.50">sip:ar@10.10.6.50</a>   | sip=1     |          2 |             |</div><div>...</div></div><div><br></div><div>opensips.cfg</div><div>----------------------</div>
<div><div>####### Global Parameters #########</div><div><br></div><div>debug=3</div><div>log_stderror=no</div><div>log_facility=LOG_LOCAL6</div><div><br></div><div>fork=yes</div><div>children=4</div><div><br></div><div>/* uncomment the next line to disable TCP (default on) */</div>
<div>disable_tcp=yes</div><div><br></div><div>port=5060</div><div><br></div><div>####### Modules Section ########</div><div><br></div><div>#set module path</div><div>mpath=&quot;//lib/opensips/modules/&quot;</div><div><br>
</div><div>/* uncomment next line for MySQL DB support */</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;xlog.so&quot;</div><div>loadmodule &quot;acc.so&quot;</div><div><br></div><div>/* uncomment next lines for MySQL based authentication support </div><div>   NOTE: a DB (like db_mysql) module must be also loaded */</div>
<div>loadmodule &quot;auth.so&quot;</div><div>loadmodule &quot;auth_db.so&quot;</div><div><br></div><div># needed for load balancer module</div><div>loadmodule &quot;dialog.so&quot;</div><div>loadmodule &quot;load_balancer.so&quot;</div>
<div><br></div><div># ----------------- setting module-specific parameters ---------------</div><div><br></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><br></div><div># ----- rr params -----</div><div>modparam(&quot;rr&quot;, &quot;enable_double_rr&quot;, 1)</div><div>modparam(&quot;rr&quot;, &quot;append_fromtag&quot;, 1)</div><div><br></div><div><br>
</div><div># ----- usrloc params -----</div><div>modparam(&quot;usrloc&quot;, &quot;db_mode&quot;,   0)</div><div><br></div><div><br></div><div># ----- uri params -----</div><div>modparam(&quot;uri&quot;, &quot;use_uri_table&quot;, 0)</div>
<div><br></div><div><br></div><div># ----- acc params -----</div><div>/* what sepcial events should be accounted ? */</div><div>modparam(&quot;acc&quot;, &quot;early_media&quot;, 1)</div><div>modparam(&quot;acc&quot;, &quot;report_ack&quot;, 0)</div>
<div>modparam(&quot;acc&quot;, &quot;report_cancels&quot;, 0)</div><div><br></div><div>/* by default ww do not adjust the direct of the sequential requests.</div><div>   if you enable this parameter, be sure the enable &quot;append_fromtag&quot;</div>
<div>   in &quot;rr&quot; module */</div><div>modparam(&quot;acc&quot;, &quot;detect_direction&quot;, 0)</div><div><br></div><div>/* account triggers (flags) */</div><div>modparam(&quot;acc&quot;, &quot;failed_transaction_flag&quot;, 3)</div>
<div><br></div><div>/* uncomment the following lines to enable DB accounting also */</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><br></div><div># ----- auth_db params -----</div><div>/* uncomment the following lines if you want to enable the DB based</div><div>   authentication */</div><div>modparam(&quot;auth_db&quot;, &quot;calculate_ha1&quot;, yes)</div>
<div>modparam(&quot;auth_db&quot;, &quot;password_column&quot;, &quot;password&quot;)</div><div><br></div><div><br></div><div># ----- tm params -----</div><div>modparam(&quot;tm&quot;, &quot;fr_timer&quot;, 5)</div><div>modparam(&quot;tm&quot;, &quot;fr_inv_timer&quot;, 5)</div>
<div><br></div><div><br></div><div># ----- load balancer params -----</div><div>modparam(&quot;load_balancer&quot;, &quot;db_url&quot;, &quot;mysql://opensips:opensipsrw@localhost/opensips16&quot;)</div><div>modparam(&quot;load_balancer&quot;, &quot;db_table&quot;, &quot;load_balancer&quot;)</div>
<div>modparam(&quot;load_balancer&quot;, &quot;probing_interval&quot;, 20)</div><div>modparam(&quot;load_balancer&quot;, &quot;probing_method&quot;, &quot;OPTIONS&quot;)</div><div>modparam(&quot;load_balancer&quot;, &quot;probing_from&quot;, &quot;<a href="mailto:sip%3Aproxy@192.168.187.121">sip:proxy@192.168.187.121</a>&quot;)</div>
<div><br></div><div>####### Routing Logic ########</div><div><br></div><div><br></div><div># main request routing logic</div><div>route{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (!mf_process_maxfwd_header(&quot;10&quot;)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>sl_send_reply(&quot;483&quot;,&quot;Too Many Hops&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (has_totag()) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span># sequential request withing a dialog should</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span># take the path determined by record-routing</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (loose_route()) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>if (is_method(&quot;BYE&quot;)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>setflag(1); # do accounting ...</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>setflag(3); # ... even if the transaction fails</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>} else if (is_method(&quot;INVITE&quot;)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span># even if in most of the cases is useless, do RR for</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span># re-INVITEs alos, as some buggy clients do change route set</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span># during the dialog.</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>record_route();</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span># route it out to whatever destination was set by loose_route()</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span># in $du (destination URI).</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>route(1);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>} else {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>if ( is_method(&quot;ACK&quot;) ) {</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>if ( t_check_trans() ) {</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span># non loose-route, but stateful ACK; must be an ACK after </div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span># a 487 or e.g. 404 from upstream server</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>t_relay();</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>exit;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span># ACK without matching transaction -&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span># ignore and discard</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>exit;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>sl_send_reply(&quot;404&quot;,&quot;Not here&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>#initial requests</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># CANCEL processing</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if (is_method(&quot;CANCEL&quot;))</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (t_check_trans())</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>t_relay();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>t_check_trans();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># preloaded route checking</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>if (loose_route()) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>xlog(&quot;L_ERR&quot;,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>&quot;Attempt to route with preloaded Route&#39;s [$fu/$tu/$ru/$ci]&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>if (!is_method(&quot;ACK&quot;))</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>sl_send_reply(&quot;403&quot;,&quot;Preload Route denied&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>exit;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># record routing</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if (!is_method(&quot;REGISTER|MESSAGE&quot;))</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>record_route();</div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span># account only INVITEs</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (is_method(&quot;INVITE&quot;)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>setflag(1); # do accounting</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (is_method(&quot;PUBLISH&quot;))</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>sl_send_reply(&quot;503&quot;, &quot;Service Unavailable&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if ($rU==NULL) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span># request with no Username in RURI</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>sl_send_reply(&quot;484&quot;,&quot;Address Incomplete&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>exit;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># when routing via usrloc, log the missed calls also</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>setflag(2);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>route(3);</div><div>}</div><div><br></div><div>route[1] {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span># for INVITEs enable some additional helper routes</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (is_method(&quot;INVITE&quot;)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>t_on_branch(&quot;2&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>t_on_reply(&quot;2&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>t_on_failure(&quot;1&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (!t_relay()) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>sl_reply_error();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>};</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>exit;</div><div>}</div><div><br></div><div><br></div><div>route[3] {</div><div>        if (is_method(&quot;INVITE&quot;)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>            load_balance(&quot;8002&quot;, &quot;sip&quot;);</div><div>            if ($retcode &lt; 0) {</div><div>            <span class="Apple-tab-span" style="white-space:pre">        </span>xlog(&quot;L_INFO&quot;, &quot;load_balancer: Insufficient resource to balance request from $fu to $tu . Re-balancing to route 4!\n&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>route(4);</div><div>            } </div><div>        }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>t_on_failure(&quot;2&quot;);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># send request</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (!t_relay()) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>sl_reply_error();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>exit;</div><div>}</div><div><br></div><div>route[4] {</div><div>        if (is_method(&quot;INVITE&quot;)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>            load_balance(&quot;8003&quot;, &quot;sip&quot;);</div><div>            if ($retcode &lt; 0) {</div><div>            <span class="Apple-tab-span" style="white-space:pre">        </span>xlog(&quot;L_INFO&quot;, &quot;load_balancer: Insufficient resource to balance request from $fu to $tu . Sending error!\n&quot;);</div>
<div>                sl_send_reply(&quot;500&quot;, &quot;Service full&quot;);</div><div>                exit;</div><div>            } </div><div>        }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span># send request</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (!t_relay()) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>sl_reply_error();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>exit;</div><div>}</div><div><br></div><div><br></div><div>branch_route[2] {</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>xlog(&quot;new branch at $ru\n&quot;);</div><div>}</div><div><br></div><div><br></div><div>onreply_route[2] {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>xlog(&quot;incoming reply\n&quot;);</div>
<div>}</div><div><br></div><div>de</div><div><br></div><div>failure_route[1] {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (t_was_cancelled()) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># uncomment the following lines if you want to block client </div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span># redirect based on 3xx replies.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>##if (t_check_status(&quot;3[0-9][0-9]&quot;)) {</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>##t_reply(&quot;404&quot;,&quot;Not found&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>##<span class="Apple-tab-span" style="white-space:pre">        </span>exit;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>##}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># uncomment the following lines if you want to redirect the failed </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span># calls to a different new destination</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>##if (t_check_status(&quot;486|408&quot;)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>##<span class="Apple-tab-span" style="white-space:pre">        </span>sethostport(&quot;<a href="http://192.168.2.100:5060">192.168.2.100:5060</a>&quot;);</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>##<span class="Apple-tab-span" style="white-space:pre">        </span># do not set the missed call flag again</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>##<span class="Apple-tab-span" style="white-space:pre">        </span>t_relay();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>##}</div><div>}</div><div><br></div><div><br></div><div>failure_route[2] {</div><div>        if (t_was_cancelled()) {</div><div>                exit;</div>
<div>        }</div><div>        </div><div>        if (t_check_status(&quot;486|408|603&quot;)) {</div><div>            xlog(&quot;L_INFO&quot;, &quot;load_balancer: Request from $fu to $tu failed. Re-balancing to 8002!\n&quot;);</div>
<div>            lb_disable();</div><div>            load_balance(&quot;8002&quot;, &quot;sip&quot;);</div><div><br></div><div>            if ($retcode &lt; 0) {</div><div>            <span class="Apple-tab-span" style="white-space:pre">        </span>xlog(&quot;L_INFO&quot;, &quot;load_balancer: Insufficient resource to balance request from $fu to $tu . Re-balancing to route 4!\n&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>route(4);</div><div>            }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>    t_on_failure(&quot;2&quot;);</div><div>            t_relay();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>} </div><div><br></div></div>