Module: sip-router Branch: master Commit: 1c6fed07a177593634a8c31a8d004f0aab165d16 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1c6fed07...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Tue Jan 31 01:20:10 2012 +0200
modules/lcr: added lcr.defunct_gw rpc command
---
modules/lcr/README | 17 +++++++++++++++++ modules/lcr/doc/lcr_admin.xml | 19 +++++++++++++++++++ modules/lcr/lcr_mod.c | 32 ++++++++++++++++++++++++++++++++ modules/lcr/lcr_mod.h | 5 ++--- modules/lcr/lcr_rpc.c | 32 ++++++++++++++++++++++++++++++-- 5 files changed, 100 insertions(+), 5 deletions(-)
diff --git a/modules/lcr/README b/modules/lcr/README index 3e1ab37..b98cb6c 100644 --- a/modules/lcr/README +++ b/modules/lcr/README @@ -78,6 +78,7 @@ Juha Heinanen 5.1. lcr.reload 5.2. lcr.dump_gws 5.3. lcr.dump_rules + 5.4. lcr.defunct_gw
6. Known Limitations
@@ -131,6 +132,7 @@ Juha Heinanen 1.46. lcr.reload RPC example 1.47. lcr.dump_gws RPC example 1.48. lcr.dump_rules RPC example + 1.49. lcr.defunct_gw RPC example
Chapter 1. Admin Guide
@@ -197,6 +199,7 @@ Chapter 1. Admin Guide 5.1. lcr.reload 5.2. lcr.dump_gws 5.3. lcr.dump_rules + 5.4. lcr.defunct_gw
6. Known Limitations
@@ -971,6 +974,7 @@ if (to_any_gw("192.55.66.2", 1)) { 5.1. lcr.reload 5.2. lcr.dump_gws 5.3. lcr.dump_rules + 5.4. lcr.defunct_gw
5.1. lcr.reload
@@ -1002,6 +1006,19 @@ if (to_any_gw("192.55.66.2", 1)) { Example 1.48. lcr.dump_rules RPC example $ sercmd lcr.dump_rules
+5.4. lcr.defunct_gw + + Defuncts gateway loaded into memory for a period of time (seconds) + without a need to store gateway's defunct value into database and + reload the tables. + + Name: lcr.defunct_gw + + Parameters: lcr_id gw_id period + + Example 1.49. lcr.defunct_gw RPC example + $ sercmd lcr.defunct_gw 1 4 120 + 6. Known Limitations
In-memory LCR rules and gw tables are switched by two consecutive diff --git a/modules/lcr/doc/lcr_admin.xml b/modules/lcr/doc/lcr_admin.xml index 64854e9..b8e243d 100644 --- a/modules/lcr/doc/lcr_admin.xml +++ b/modules/lcr/doc/lcr_admin.xml @@ -1324,6 +1324,25 @@ if (to_any_gw("192.55.66.2", 1)) { </programlisting> </example> </section> + + <section> + <title><function>lcr.defunct_gw</function></title> + <para> + Defuncts gateway loaded into memory for a period of + time (seconds) without a need to store gateway's + defunct value into database and reload the tables. + </para> + <para> + Name: <emphasis>lcr.defunct_gw</emphasis> + </para> + <para>Parameters: <emphasis>lcr_id gw_id period</emphasis></para> + <example> + <title><function>lcr.defunct_gw</function> RPC example</title> + <programlisting format="linespecific"> + $ sercmd lcr.defunct_gw 1 4 120 + </programlisting> + </example> + </section> </section> <section> <title>Known Limitations</title> diff --git a/modules/lcr/lcr_mod.c b/modules/lcr/lcr_mod.c index 8f8d373..58dd0cd 100644 --- a/modules/lcr/lcr_mod.c +++ b/modules/lcr/lcr_mod.c @@ -2049,6 +2049,38 @@ static int defunct_gw(struct sip_msg* _m, char *_defunct_period, char *_s2)
/* + * Defunct given gw in given lcr until time period given as argument has passed. + */ +int rpc_defunct_gw(unsigned int lcr_id, unsigned int gw_id, unsigned int period) +{ + struct gw_info *gws; + unsigned int until, i; + + if ((lcr_id < 1) || (lcr_id > lcr_count_param)) { + LM_ERR("invalid lcr_id value <%u>\n", lcr_id); + return 0; + } + + until = time((time_t *)NULL) + period; + + LM_DBG("defuncting gw <lcr_id/gw_id>=<%u/%u> for %u seconds until %d\n", + lcr_id, gw_id, period, until); + + gws = gw_pt[lcr_id]; + for (i = 1; i <= gws[0].ip_addr.u.addr32[0]; i++) { + if (gws[i].gw_id == gw_id) { + gws[i].defunct_until = until; + return 1; + } + } + + LM_ERR("gateway with id <%u> not found\n", gw_id); + + return 0; +} + + +/* * When called first time, rewrites scheme, host, port, and * transport parts of R-URI based on first gw_uri_avp value, which is then * destroyed. Saves R-URI user to ruri_user_avp for later use. diff --git a/modules/lcr/lcr_mod.h b/modules/lcr/lcr_mod.h index e544f68..5ac2406 100644 --- a/modules/lcr/lcr_mod.h +++ b/modules/lcr/lcr_mod.h @@ -110,8 +110,7 @@ extern gen_lock_t *reload_lock; extern struct gw_info **gw_pt; extern struct rule_info ***rule_pt;
-int mi_print_gws(struct mi_node* rpl); -int mi_print_lcrs(struct mi_node* rpl); -int reload_tables(); +extern int reload_tables(); +extern int rpc_defunct_gw(unsigned int, unsigned int, unsigned int);
#endif /* LCR_MOD_H */ diff --git a/modules/lcr/lcr_rpc.c b/modules/lcr/lcr_rpc.c index f70c042..111bfb0 100644 --- a/modules/lcr/lcr_rpc.c +++ b/modules/lcr/lcr_rpc.c @@ -67,6 +67,8 @@ static void dump_gws(rpc_t* rpc, void* c) str gw_name, hostname, params; str prefix, tag; struct gw_info *gws; + char buf[INT2STR_MAX_LEN], *start; + int len;
for (j = 1; j <= lcr_count_param; j++) {
@@ -132,12 +134,14 @@ static void dump_gws(rpc_t* rpc, void* c) prefix.len=gws[i].prefix_len; tag.s=gws[i].tag; tag.len=gws[i].tag_len; - rpc->struct_add(st, "dSSdd", + start = int2strbuf(gws[i].defunct_until, &(buf[0]), INT2STR_MAX_LEN, + &len); + rpc->struct_add(st, "dSSds", "strip", gws[i].strip, "prefix", &prefix, "tag", &tag, "flags", gws[i].flags, - "defunct_until", &gws[i].defunct_until + "defunct_until", start ); } } @@ -199,9 +203,33 @@ static void dump_rules(rpc_t* rpc, void* c) }
+static const char* defunct_gw_doc[2] = { + "Defunct gateway until speficied time (Unix timestamp).", + 0 +}; + + +static void defunct_gw(rpc_t* rpc, void* c) +{ + unsigned int lcr_id, gw_id, until; + + if (rpc->scan(c, "ddd", &lcr_id, &gw_id, &until) < 3) { + rpc->fault(c, 400, "lcr_id, gw_id, and timestamp parameters required"); + return; + } + + if (rpc_defunct_gw(lcr_id, gw_id, until) == 0) { + rpc->fault(c, 400, "parameter value error (see syslog)"); + } + + return; +} + + rpc_export_t lcr_rpc[] = { {"lcr.reload", reload, reload_doc, 0}, {"lcr.dump_gws", dump_gws, dump_gws_doc, 0}, {"lcr.dump_rules", dump_rules, dump_rules_doc, 0}, + {"lcr.defunct_gw", defunct_gw, defunct_gw_doc, 0}, {0, 0, 0, 0} };
2012/1/31 admin@sip-router.org:
+5.4. lcr.defunct_gw
- Defuncts gateway loaded into memory for a period of time (seconds)
- without a need to store gateway's defunct value into database and
- reload the tables.
- Name: lcr.defunct_gw
- Parameters: lcr_id gw_id period
- Example 1.49. lcr.defunct_gw RPC example
- $ sercmd lcr.defunct_gw 1 4 120
Gateways are physical nodes, while LCR instances/profiles are up to the application logic. So in case I have 10 different LCR instances/profiles (i.e. for different kinds of traffic), 5 gateways in total, and gateway 1 exists in all the 10 LCR instances, then in order to dissable such a gateway I must run:
$ sercmd lcr.defunct_gw 1 1 120 $ sercmd lcr.defunct_gw 2 1 120 $ sercmd lcr.defunct_gw 3 1 120 $ sercmd lcr.defunct_gw 4 1 120 $ sercmd lcr.defunct_gw 5 1 120 $ sercmd lcr.defunct_gw 6 1 120 $ sercmd lcr.defunct_gw 7 1 120 $ sercmd lcr.defunct_gw 8 1 120 $ sercmd lcr.defunct_gw 9 1 120 $ sercmd lcr.defunct_gw 10 1 120
So imagine a external tool that tries to monitorize LCR gateways via sending SIP requests by reading LCR DB tables, and performs XMLRPC commands to defunt a gateway when it's down. Such a tool should deal with a same gateway shared by multiple LCR instances, so hopefully it monitors it just once, but then it should perform the XMLRPC command N times for the same gateway. Not good.
I'm sorry but I insist: the design of the new LCR is not as good as it should be. The relationship between rules, LCR instances and gateways is messy (IMHO).
Regards.
Iñaki Baz Castillo writes:
Gateways are physical nodes, while LCR instances/profiles are up to the application logic.
even when gws are physical entities, different lcr instances may you different ports/transports to access them. same gateway may not respond due to the load over tls, but may respond over udp.
I'm sorry but I insist: the design of the new LCR is not as good as it should be. The relationship between rules, LCR instances and gateways is messy (IMHO).
currently each lcr is fully independent from each other, which in my opinion is the most flexible design.
-- juha