Kamailio LCR

From open-voip.org

Jump to: navigation, search

lcr documentation

http://www.opensips.org/html/docs/modules/1.5.x/lcr.html

LCR overview

  • each gateway belongs to a gateway group
  • each gateway group is associated with one or more <prefix, from pattern, priority> DB record.
  • A gateway matches a request if user part of Request URI matches a prefix and caller's URI matches a from pattern in a DB record that belongs to the group of the gateway.

Matching gateways methos:

  • (1) according to longest user part match
  • (2) according to record priority
  • (3) randomly (prefix_mode = 0)

LCR using kamctl

add GW (will add to the gw table in the mysql)

kamctl lcr addgw d3ivr 213.137.73.209 5060 sip udp 1

add route (will add to the lcr table in the mysql

kamctl lcr addroute 8888  1 1

reload module

kamctl lcr reload

dump lcr information

kamctl lcr dump


-- command 'lcr' - manage least cost routes (lcr)

  * IP addresses must be entered in dotted quad format e.g. 1.2.3.4   *
  * <uri_scheme> and <transport> must be entered in integer or text,  *
  * e.g. transport '2' is identical to transport 'tcp'.               *
  *   scheme: 1=sip, 2=sips;   transport: 1=udp, 2=tcp, 3=tls, 4=sctp *
  * Examples:  lcr addgw level3 1.2.3.4 5080 sip tcp 1                *
  *            lcr addroute +1  1 1                                 *
lcr show .......... show gateways and routes tables
lcr dump .......... show in memory gateways and routes tables
lcr reload ........ reload lcr gateways and routes
lcr addgw <gw_name> <ip> <port> <scheme> <transport> <grp_id> <flags> <tag> <strip> <weight> <hostname> <ping>
          ......... add a gateway with flags, tag, strip, weight, hostname, and ping
          ......... (flags, tag, strip, weight, hostname, and ping are optional)
lcr rmgw <gw_name> delete a gateway
lcr addroute <prefix> <from> <grp_id> <prio>
          ......... add a route ( use  to match anything in <from> )
lcr rmroute <prefix> <from> <grp_id> <prio>
          ......... delete a route

Configure LCR in kamailio.conf

example of use in the kamailio script. note the load_gws and next_gw functions

if (!load_gws("$var(caller_uri)")) {
  sl_send_reply("500", "Internal server error, unable to load gateways");
  exit;
}
if (!next_gw()){
  sl_send_reply("503", "Service not available, no gateways found");
  exit;
}
route(7);
exit;

in the modules add

loadmodule "lcr.so"

in te modules parameters add:

modparam("lcr","db_url", "mysql://openser:asterisk@localhost/openser")
modparam("lcr","gw_table","gw")
modparam("lcr","tag_column","tag")
modparam("lcr","weight_column","gw_weight")
modparam("lcr","flags_column","flags")
modparam("lcr","gw_name_column","gw_name")
modparam("lcr","ip_addr_column","ip_addr")
modparam("lcr","port_column","port")
modparam("lcr","hostname_column","hostname")
modparam("lcr","uri_scheme_column","uri_scheme")
modparam("lcr","strip_column","strip")
modparam("lcr","transport_column","transport")
modparam("lcr","grp_id_column","grp_id")
modparam("lcr","lcr_table","lcr")
modparam("lcr","prefix_column","prefix")
modparam("lcr","from_uri_column","from_uri")
modparam("lcr","priority_column","priority")
modparam("lcr","gw_uri_avp", "$avp(i:709)")
modparam("lcr","ruri_user_avp", "$avp(i:500)")
modparam("lcr", "flags_avp", "$avp(i:712)")
modparam("^auth$|lcr", "rpid_avp", "$avp(i:302)")
Personal tools