2

I have 3 locations listed in my dispatcher.list file. 2 are meant to load balance eachother. At the moment it works perfectly as the logs show the calls doing a round robin between the 2 locations.

However, I have been going through online docs and examples but can't figure out exactly how to only use the 3rd location as a failover.

My definition of a failure that should activate the failover are:

  1. Destination gives no response (it is down)
  2. Any failure responses from the destination

We use 2 sip providers. 1 gives us 2 trunks to load balance and the 2nd we use just for failover in case the first provider goes down or is unable to route a call for any reason.

I feel like this is a common issue that should be easy to implement but I can not find the documentation that allows me to properly do it.

Here is my Kamailio.cfg file: The config file I am using was created by someone else for a different system we use to use. Not exactly sure if it needs everything it has in it.

# $Id: dispatcher.cfg,v 1.1 2004/08/10 16:51:36 dcm Exp $
# sample config file for dispatcher module
debug=2          # debug level (cmd line: -dddddddddd)
#fork=yes
fork=yes
log_stderror=no  # (cmd line: -E)
memdbg=5
memlog=5
log_facility=LOG_LOCAL0

disable_tcp=yes
children=4
check_via=no      # (cmd. line: -v)
dns=off           # (cmd. line: -r)
rev_dns=off       # (cmd. line: -R)
port=5060
listen=udp:0.0.0.0:5060


# ------------------ module loading ----------------------------------
#mpath="modules_k:modules"
mpath="/usr/local/lib64/kamailio/modules_k/:/usr/local/lib64/kamailio/modules/"
loadmodule "tm.so"
loadmodule "mi_fifo.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "mi_rpc.so"
loadmodule "dispatcher.so"
loadmodule "ctl"

# ----------------- setting module-specific parameters ---------------
# ----- mi_fifo params -----
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
# ----- rr params -----
# add value to ;lr param to cope with most of the UAs
modparam("rr", "enable_full_lr", 1)
# do not append from tag to the RR (no need for this script)
modparam("rr", "append_fromtag", 0)
# ----------------- setting module-specific parameters ---------------
# ----- tm params -----
modparam("tm", "fr_timer", 2000)
modparam("tm", "fr_inv_timer", 40000)
# -- dispatcher params --
modparam("dispatcher", "list_file", "/usr/local/etc/kamailio/dispatcher.list")
modparam("dispatcher", "flags", 3)
modparam("dispatcher", "dst_avp", "$avp(i:271)")
modparam("dispatcher", "grp_avp", "$avp(i:272)")
modparam("dispatcher", "cnt_avp", "$avp(i:273)")
modparam("dispatcher", "ds_ping_method", "OPTIONS")
modparam("dispatcher", "ds_ping_interval", 30)
modparam("dispatcher", "ds_probing_mode", 1) 
modparam("dispatcher", "ds_probing_threshhold", 3) 

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

    if (is_method("INVITE") || is_method("REGISTER")) {
        ds_select_domain("1", "4");
      sl_send_reply("100","Trying");
      forward();#uri:host, uri:port);

        xlog("L_INFO","Redirect response URL constructed:  $ru\n");

        sl_send_reply("302", "Moved Temporarily");
        exit;
    }
}

Here is my dispatcher.list file:

#Load Balance
1 sip:1.1.1.1:5060 2
1 sip:2.2.2.2:5060 2

#Fail Over if the above can't be used
2 sip:3.3.3.3:5060 2
Damainman
  • 515
  • 9
  • 21

1 Answers1

3

Add the third gateway as the last line in group '1' and set the parameter use_default for dispatcher module:

use_default (int)

If the parameter is set to 1, the last address in destination set is used as a final option to send the request to. For example, it is useful when wanting to send the call to an anouncement server saying: "the gateways are full, try later".

Default value is “0”.

e.g. modparam("dispatcher", "use_default", 1) in kamailio.cfg

(Source)

Community
  • 1
  • 1
miconda
  • 1,754
  • 11
  • 14
  • Would that work with the above route config? Just curious because most results I found online consisted of an extensive route function instead of that simple solution you provided. I want to make sure I am not over looking anything. – Damainman Jun 09 '14 at 12:58
  • 2
    No. You have to do stateful relaying and use failure_route if selected destination doesn't answer to re-route to the next in the list. Your example is using forward(), which is stateless forwarding. The example in the readme of dispatcher module is doing stateful forwarding, using t_relay(), having as well failure_route block for trying next destinations. – miconda Jun 12 '14 at 14:34