# simple lcr quick-start config script # Please refer to the Core CookBook at http://www.openser.org/dokuwiki/doku.php # for a explanation of possible statements, functions and parameters. # # Please send comments to "Ovidiu Sas" # # # This config will work with openser 1.3 # # First, we need to add a few gateways to our config: # `openserctl lcr addgw gw_1 1.2.3.4 5060 sip udp 1' # `openserctl lcr addgw gw_2 2.3.4.5 5060 sip udp 1' # our gateways are # 'gw_1' at ip '1.2.3.4' using 'sip' over 'udp' and it is part of group '1' # 'gw_2' at ip '2.3.4.5' using 'sip' over 'udp' and it is part of group '1' # # Next, we need to add a route to our gateway: # `openserctl lcr addroute "" "" 1 1' # our route will route from any caller '' to any callee '' to a gateway from group '1' with priority '1' # # Let's see the content of lcr tables: # # `openserctl lcr show' # lcr routes # +----+--------+----------+--------+----------+ # | id | prefix | from_uri | grp_id | priority | # +----+--------+----------+--------+----------+ # | 1 | | | 1 | 1 | # +----+--------+----------+--------+----------+ # lcr gateway groups # lcr gateways # +---------+---------+------+------------+-----------+--------+-------+--------+ # | gw_name | ip_addr | port | uri_scheme | transport | grp_id | strip | prefix | # +---------+---------+------+------------+-----------+--------+-------+--------+ # | gw_1 | 1.2.3.4 | 5060 | 1 | 1 | 1 | 0 | | # | gw_2 | 2.3.4.5 | 5060 | 1 | 1 | 1 | 0 | | # +---------+---------+------+------------+-----------+--------+-------+--------+ # # The following config will first send call to one of this two gateways in a random # manner and if the first selected gateway is not reachable it will try the other one. # # ----------- global configuration parameters ------------------------ debug=3 # debug level (cmd line: -dddddddddd) fork=yes log_stderror=no # (cmd line: -E) children=1 disable_tcp=yes # ------------------ module loading ---------------------------------- #set module path mpath="/usr/local/lib/openser/modules/" loadmodule "dbtext.so" modparam("dbtext", "db_mode", 1) loadmodule "sl.so" loadmodule "tm.so" modparam("tm", "fr_timer", 5) modparam("tm", "fr_inv_timer_avp", "$avp(i:704)") loadmodule "rr.so" loadmodule "maxfwd.so" loadmodule "textops.so" loadmodule "xlog.so" loadmodule "avpops.so" loadmodule "mi_fifo.so" modparam("mi_fifo", "fifo_name", "/tmp/openser_fifo") loadmodule "lcr.so" #modparam("lcr", "db_url", "mysql://openser:openserrw@127.0.0.1/openser") modparam("lcr", "db_url", "dbtext:///usr/local/etc/openser/dbtext") modparam("lcr","fr_inv_timer",90) modparam("lcr","fr_inv_timer_next",30) modparam("lcr", "fr_inv_timer_avp", "$avp(i:704)") modparam("lcr", "gw_uri_avp", "$avp(i:709)") modparam("lcr", "ruri_user_avp", "$avp(i:500)") modparam("lcr", "contact_avp", "$avp(i:711)") modparam("lcr", "rpid_avp", "$avp(i:302)") modparam("lcr", "dm_flag", 13) # ------------------------- request routing logic ------------------- # main routing logic route{ # initial sanity checks -- messages with # max_forwards==0, or excessively long requests if (!mf_process_maxfwd_header("10")) { sl_send_reply("483","Too Many Hops"); exit; }; if (msg:len >= 2048 ) { sl_send_reply("513", "Message too big"); exit; }; # we record-route all messages -- to make sure that # subsequent messages will go through our proxy; that's # particularly good if upstream and downstream entities # use different transport protocol if (!method=="REGISTER") record_route(); # subsequent messages withing a dialog should take the # path determined by record-routing if (loose_route()) { # mark routing logic in request append_hf("P-hint: rr-enforced\r\n"); route(1); }; if (!uri==myself) { # mark routing logic in request append_hf("P-hint: outbound\r\n"); route(1); }; if (uri==myself) { if (is_method("INVITE")) { append_hf("P-hint: lcr applied\r\n"); # applying lcr routing route(2); }; }; route(1); } route[1] { # send it out now; use stateful forwarding as it works reliably # even for UDP2TCP if (!t_relay()) { sl_reply_error(); }; exit; } route[2] { # load the gateways if (!load_gws()) { sl_send_reply("503", "Unable to load gateways"); exit; } else { $var(i) = 0; #while($(avp(i:709)[$var(i)]) != null) { while(is_avp_set("$(avp(i:709)[$var(i)])")) { xlog("L_INFO", "loading gw_uri_avp[$var(i)]='$(avp(i:709)[$var(i)])'\n"); $var(i) = $var(i) + 1; }; if(is_avp_set("$avp(i:709)")) { xlog("L_INFO", "trying gateway '$avp(i:709)'\n"); } else { xlog("L_INFO", "no available gateways ...\n"); }; # try the first matched gateway if (next_gw()) { xlog("L_INFO", "ruri_user_avp='$avp(i:500)'\n"); # prepare for lcr failover t_on_failure("2"); route(1); } else { sl_send_reply("503", "No available gateways"); exit; }; }; exit; } failure_route[2] { xlog("L_INFO", "entering failure_route[2] for reply code '$T_reply_code'\n"); # the previous gateway is no good if (t_check_status("408|50[34]")) { if(is_avp_set("$avp(i:709)")) { xlog("L_INFO", "trying next gateway '$avp(i:709)'\n"); } else { xlog("L_INFO", "no more gateways to try ...\n"); }; # route to the next gateway if (next_gw()) { # prepare for lcr failover t_on_failure("2"); route(1); } else { t_reply("503", "No gateways"); exit; }; exit; }; }