Kamailio Dispatcher

From open-voip.org

Jump to: navigation, search

The module can be used as a stateless load balancer, having no guarantee of fair distribution Documentation at

http://www.kamailio.org/docs/modules/1.5.x/dispatcher.html

Contents

Dispatcher Configuration in kamailio.cfg

loadmodule "dispatcher.so"

dispatcher parameters

Dispatcher using kamctl

-- command 'dispatcher' - manage dispatcher

* Examples:  dispatcher addgw 1 sip:1.2.3.1:5050 1 'outbound gateway'
*            dispatcher addgw 2 sip:1.2.3.4:5050 3 
*            dispatcher rmgw 4
dispatcher show ..................... show dispatcher gateways
dispatcher reload ................... reload dispatcher gateways
dispatcher dump ..................... show in memory dispatcher gateways
dispatcher addgw <setid> <destination> <flags> <description>
           .......................... add gateway
dispatcher rmgw <id> ................ delete gateway

examples

 kamctl dispatcher addgw 1 sip:192.168.0.104:5060 1 'sip1'
 kamctl dispatcher addgw 1 sip:192.168.0.133:5060 1 'sip2'
 kamctl dispatcher show
dispatcher gateways
+----+-------+-------------------------+-------+----------+-------------+
| id | setid | destination             | flags | priority | description |
+----+-------+-------------------------+-------+----------+-------------+
|  1 |     1 | sip:192.168.0.104:5060 |     0 |        1 | sip1        | 
|  2 |     1 | sip:192.168.0.133:5060 |     0 |        1 | sip2        | 
+----+-------+-------------------------+-------+----------+-------------+

Dispatch method

The most importand functio in the dispatcher module is:

ds_select_dst(set, alg) 
  • set - the id of the set from where to pick up destination address. It is the first column in destination list file.
  • alg - the algorithm used to select the destination address.

The method selects a destination from addresses set.

  • “0” - hash over callid
  • “1” - hash over from uri.
  • “2” - hash over to uri.
  • “3” - hash over request-uri.
  • “4” - round-robin (next destination).

“* 5” - hash over authorization-username (Proxy-Authorization or "normal" authorization). If no username is found, round robin is used.

  • “6” - random (using rand()).
  • “7” - hash over the content of PVs string. Note: This works only when the parameter hash_pvar is set.
  • “8” - use first destination (good for failover).
  • “X” - if the algorithm is not implemented, the first entry in set is chosen.

Dispatcher using file list

modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")

save the following file "/etc/kamailio/dispatcher.list"

# $Id: dispatcher.list 3662 2010-05-07 13:06:00Z Amos $
# dispatcher destination sets
# setit(integer) destination(sip uri) flags (integer, optional)
#
# GWs
1 sip:192.168.0.150:5060
1 sip:192.168.0.151:5060
1 sip:192.168.0.152:5060

full kamailio.cfg file for dispatcher with NAT suppor, get data from file:

# $Id: dispatcher.cfg,v 1.1 2004/08/10 16:51:36 dcm Exp $
# sample config file for dispatcher module
debug=9          # debug level (cmd line: -dddddddddd)
fork=yes
log_stderror=yes  # (cmd line: -E)
children=2
check_via=no      # (cmd. line: -v)
dns=off           # (cmd. line: -r)
rev_dns=off       # (cmd. line: -R)
port=5060 

# ------------------ module loading ----------------------------------
mpath="//lib/kamailio/modules/" 
loadmodule "db_mysql.so"
loadmodule "mi_fifo.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "uri_db.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "acc.so"
loadmodule "nathelper.so"
loadmodule "path.so" 

# ----------------- setting module-specific parameters ---------------
# ----------- path param
modparam("path", "use_received", 1)
# ----- 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)
# -- nathelper
modparam("nathelper", "rtpproxy_sock", "udp:192.168.0.122:7722")
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", 7)
modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
modparam("registrar|nathelper", "received_avp", "$avp(i:80)")
modparam("usrloc", "nat_bflag", 6)
loadmodule "dispatcher.so"

# ----------------- setting module-specific parameters ---------------
# -- dispatcher params --
modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")

route{
	if ( !mf_process_maxfwd_header("10") )
	{
	 	sl_send_reply("483","To Many Hops");
	 	drop();
	};
	
	ds_select_dst("1", "0");
	#record_route();
	add_path_received();
	force_rport();
	forward();
	# t_relay();
}

Dispatcher using DB

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

children=2
check_via=no      # (cmd. line: -v)
dns=off           # (cmd. line: -r)
rev_dns=off       # (cmd. line: -R)
port=5060 
# ------------------ module loading ----------------------------------
mpath="//lib/kamailio/modules/"
loadmodule "db_mysql.so"
loadmodule "mi_fifo.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "uri_db.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "acc.so"
loadmodule "nathelper.so"
loadmodule "dispatcher.so"

# ----------------- 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)
# -- nathelper
modparam("nathelper", "rtpproxy_sock", "udp:192.168.0.126:7722")
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", 7)
modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
modparam("registrar|nathelper", "received_avp", "$avp(i:80)")
modparam("usrloc", "nat_bflag", 6)

# ----------------- setting module-specific parameters ---------------
# -- dispatcher params for DB support --
modparam("dispatcher","db_url", "mysql://openser:asterisk@localhost/openser")
modparam("dispatcher", "table_name", "dispatcher")
modparam("dispatcher", "setid_col", "setid")
modparam("dispatcher", "destination_col", "destination")
modparam("dispatcher", "flags_col", "flags")
modparam("dispatcher", "priority_col", "priority")

modparam("dispatcher", "force_dst", 1)

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

        forward();
        # t_relay();
}
Personal tools