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'm calling load_balance for group id 2. Although there is available destinations on this group, return code from load_balance call is < 0. So this is the point where I'm stuck. </div>
<div><br></div><div>Any help appreciated.</div><div><br></div><div>Here'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="//lib/opensips/modules/"</div><div><br>
</div><div>/* uncomment next line for MySQL DB support */</div><div>loadmodule "db_mysql.so"</div><div>loadmodule "signaling.so"</div><div>loadmodule "sl.so"</div><div>loadmodule "tm.so"</div>
<div>loadmodule "rr.so"</div><div>loadmodule "maxfwd.so"</div><div>loadmodule "usrloc.so"</div><div>loadmodule "registrar.so"</div><div>loadmodule "textops.so"</div><div>loadmodule "mi_fifo.so"</div>
<div>loadmodule "uri.so"</div><div>loadmodule "xlog.so"</div><div>loadmodule "acc.so"</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 "auth.so"</div><div>loadmodule "auth_db.so"</div><div><br></div><div># needed for load balancer module</div><div>loadmodule "dialog.so"</div><div>loadmodule "load_balancer.so"</div>
<div><br></div><div># ----------------- setting module-specific parameters ---------------</div><div><br></div><div><br></div><div># ----- mi_fifo params -----</div><div>modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")</div>
<div><br></div><div><br></div><div># ----- rr params -----</div><div>modparam("rr", "enable_double_rr", 1)</div><div>modparam("rr", "append_fromtag", 1)</div><div><br></div><div><br>
</div><div># ----- usrloc params -----</div><div>modparam("usrloc", "db_mode", 0)</div><div><br></div><div><br></div><div># ----- uri params -----</div><div>modparam("uri", "use_uri_table", 0)</div>
<div><br></div><div><br></div><div># ----- acc params -----</div><div>/* what sepcial events should be accounted ? */</div><div>modparam("acc", "early_media", 1)</div><div>modparam("acc", "report_ack", 0)</div>
<div>modparam("acc", "report_cancels", 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 "append_fromtag"</div>
<div> in "rr" module */</div><div>modparam("acc", "detect_direction", 0)</div><div><br></div><div>/* account triggers (flags) */</div><div>modparam("acc", "failed_transaction_flag", 3)</div>
<div><br></div><div>/* uncomment the following lines to enable DB accounting also */</div><div>modparam("acc", "db_flag", 1)</div><div>modparam("acc", "db_missed_flag", 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("auth_db", "calculate_ha1", yes)</div>
<div>modparam("auth_db", "password_column", "password")</div><div><br></div><div><br></div><div># ----- tm params -----</div><div>modparam("tm", "fr_timer", 5)</div><div>modparam("tm", "fr_inv_timer", 5)</div>
<div><br></div><div><br></div><div># ----- load balancer params -----</div><div>modparam("load_balancer", "db_url", "mysql://opensips:opensipsrw@localhost/opensips16")</div><div>modparam("load_balancer", "db_table", "load_balancer")</div>
<div>modparam("load_balancer", "probing_interval", 20)</div><div>modparam("load_balancer", "probing_method", "OPTIONS")</div><div>modparam("load_balancer", "probing_from", "<a href="mailto:sip%3Aproxy@192.168.187.121">sip:proxy@192.168.187.121</a>")</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("10")) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>sl_send_reply("483","Too Many Hops");</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("BYE")) {</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("INVITE")) {</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("ACK") ) {</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 -></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("404","Not here");</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("CANCEL"))</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("L_ERR",</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>if (!is_method("ACK"))</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>sl_send_reply("403","Preload Route denied");</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("REGISTER|MESSAGE"))</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("INVITE")) {</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("PUBLISH"))</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("503", "Service Unavailable");</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("484","Address Incomplete");</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("INVITE")) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>t_on_branch("2");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>t_on_reply("2");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>t_on_failure("1");</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("INVITE")) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div> load_balance("8002", "sip");</div><div> if ($retcode < 0) {</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>xlog("L_INFO", "load_balancer: Insufficient resource to balance request from $fu to $tu . Re-balancing to route 4!\n");</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("2");</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("INVITE")) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div> load_balance("8003", "sip");</div><div> if ($retcode < 0) {</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>xlog("L_INFO", "load_balancer: Insufficient resource to balance request from $fu to $tu . Sending error!\n");</div>
<div> sl_send_reply("500", "Service full");</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("new branch at $ru\n");</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("incoming reply\n");</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("3[0-9][0-9]")) {</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>##t_reply("404","Not found");</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("486|408")) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>##<span class="Apple-tab-span" style="white-space:pre">        </span>sethostport("<a href="http://192.168.2.100:5060">192.168.2.100:5060</a>");</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("486|408|603")) {</div><div> xlog("L_INFO", "load_balancer: Request from $fu to $tu failed. Re-balancing to 8002!\n");</div>
<div> lb_disable();</div><div> load_balance("8002", "sip");</div><div><br></div><div> if ($retcode < 0) {</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>xlog("L_INFO", "load_balancer: Insufficient resource to balance request from $fu to $tu . Re-balancing to route 4!\n");</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("2");</div><div> t_relay();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>} </div><div><br></div></div>