Debian Codegraph @

src/modules/lcr/README

raw
1 LCR (Least Cost Routing) Module
2
3 Juha Heinanen
4
5 <[email protected]>
6
7 Edited by
8
9 Juha Heinanen
10
11 <[email protected]>
12
13 Ovidiu Sas
14
15 <[email protected]>
16
17 Copyright © 2005-2014 Juha Heinanen
18 __________________________________________________________________
19
20 Table of Contents
21
22 1. Admin Guide
23
24 1. Overview
25 2. Dependencies
26
27 2.1. Kamailio Modules
28 2.2. External libraries or applications
29
30 3. Parameters
31
32 3.1. db_url (string)
33 3.2. lcr_gw_table (string)
34 3.3. id_column (string)
35 3.4. lcr_id_column (string)
36 3.5. gw_name_column (string)
37 3.6. ip_addr_column (string)
38 3.7. hostname_column (string)
39 3.8. port_column (string)
40 3.9. params_column (string)
41 3.10. uri_scheme_column (string)
42 3.11. transport_column (string)
43 3.12. strip_column (string)
44 3.13. tag_column (string)
45 3.14. flags_column (string)
46 3.15. defunct_column (string)
47 3.16. lcr_rule_table (string)
48 3.17. prefix_column (string)
49 3.18. from_uri_column (string)
50 3.19. mt_tvalue_column (string)
51 3.20. request_uri_column (string)
52 3.21. stopper_column (string)
53 3.22. enabled_column (string)
54 3.23. lcr_rule_target_table (string)
55 3.24. rule_id_column (string)
56 3.25. gw_id_column (string)
57 3.26. priority_column (string)
58 3.27. weight_column (string)
59 3.28. lcr_count (integer)
60 3.29. gw_uri_avp (AVP string)
61 3.30. ruri_user_avp (AVP string)
62 3.31. tag_avp (AVP string)
63 3.32. flags_avp (AVP string)
64 3.33. rule_id_avp (AVP string)
65 3.34. mt_pv_values (AVP string)
66 3.35. mtree (string)
67 3.36. defunct_capability (integer)
68 3.37. lcr_id_avp (AVP string)
69 3.38. defunct_gw_avp (AVP string)
70 3.39. lcr_rule_hash_size (integer)
71 3.40. lcr_gw_count (integer)
72 3.41. dont_strip_or_prefix_flag (integer)
73 3.42. priority_ordering (integer)
74 3.43. fetch_rows (integer)
75 3.44. ping_interval (integer)
76 3.45. ping_inactivate_threshold (integer)
77 3.46. ping_valid_reply_codes (string)
78 3.47. ping_from (string)
79 3.48. ping_socket (string)
80
81 4. Functions
82
83 4.1. load_gws(lcr_id[, uri_user[, caller_uri]])
84 4.2. next_gw()
85 4.3. inactivate_gw()
86 4.4. defunct_gw(period)
87 4.5. from_gw(lcr_id[, ip_addr, proto[, src_port]])
88 4.6. from_any_gw([ip_addr, proto[, src_port]])
89 4.7. to_gw(lcr_id[, ip_addr, proto])
90 4.8. to_any_gw([ip_addr, proto])
91
92 5. RPC Commands
93
94 5.1. lcr.reload
95 5.2. lcr.dump_gws
96 5.3. lcr.dump_rules
97 5.4. lcr.load_gws
98 5.5. lcr.defunct_gw
99
100 6. Known Limitations
101
102 List of Examples
103
104 1.1. Setting db_url module parameter
105 1.2. Setting lcr_gw_table module parameter
106 1.3. Setting id_column module parameter
107 1.4. Setting lcr_id_column module parameter
108 1.5. Setting gw_name_column module parameter
109 1.6. Setting ip_addr_column module parameter
110 1.7. Setting hostname_column module parameter
111 1.8. Setting port_column module parameter
112 1.9. Setting params_column module parameter
113 1.10. Setting uri_scheme_column module parameter
114 1.11. Setting transport_column module parameter
115 1.12. Setting strip_column module parameter
116 1.13. Setting tag_column module parameter
117 1.14. Setting flags_column module parameter
118 1.15. Setting defunct_column module parameter
119 1.16. Setting lcr_rule_table module parameter
120 1.17. Setting prefix_column module parameter
121 1.18. Setting from_uri_column module parameter
122 1.19. Setting from_uri_column module parameter
123 1.20. Setting request_uri_column module parameter
124 1.21. Setting stopper_column module parameter
125 1.22. Setting enabled_column module parameter
126 1.23. Setting lcr_rule_target_table module parameter
127 1.24. Setting rule_id_column module parameter
128 1.25. Setting gw_id_column module parameter
129 1.26. Setting priority_column module parameter
130 1.27. Setting weight_column module parameter
131 1.28. Setting lcr_count module parameter
132 1.29. Setting gw_uri_avp module parameter
133 1.30. Setting ruri_user_avp module parameter
134 1.31. Setting tag_avp module parameter
135 1.32. Setting flags_avp module parameter
136 1.33. Setting rule_id_avp module parameter
137 1.34. Setting tag_avp module parameter
138 1.35. Setting mtree module parameter
139 1.36. Setting defunct_capability module parameter
140 1.37. Setting lcr_id_avp module parameter
141 1.38. Setting defunct_gw_avp module parameter
142 1.39. Setting lcr_rule_hash_size module parameter
143 1.40. Setting lcr_gw_count module parameter
144 1.41. Setting dont_strip_or_prefix_flag module parameter
145 1.42. Setting priority_ordering module parameter
146 1.43. Set fetch_rows parameter
147 1.44. Set ping_interval parameter
148 1.45. Set ping_inactivate_threshold parameter
149 1.46. Set ping_valid_reply_codes parameter
150 1.47. Set ping_from parameter
151 1.48. Set ping_socket parameter
152 1.49. load_gws usage
153 1.50. next_gw usage from a route block
154 1.51. next_gw usage from a failure route block
155 1.52. inactivate_gw usage
156 1.53. defunct_gw usage
157 1.54. from_gw usage
158 1.55. from_gw usage
159 1.56. to_gw usage
160 1.57. to_gw usage
161 1.58. lcr.reload RPC example
162 1.59. lcr.dump_gws RPC example
163 1.60. lcr.dump_rules RPC example
164 1.61. lcr.load_gws RPC example
165 1.62. lcr.defunct_gw RPC example
166
167 Chapter 1. Admin Guide
168
169 Table of Contents
170
171 1. Overview
172 2. Dependencies
173
174 2.1. Kamailio Modules
175 2.2. External libraries or applications
176
177 3. Parameters
178
179 3.1. db_url (string)
180 3.2. lcr_gw_table (string)
181 3.3. id_column (string)
182 3.4. lcr_id_column (string)
183 3.5. gw_name_column (string)
184 3.6. ip_addr_column (string)
185 3.7. hostname_column (string)
186 3.8. port_column (string)
187 3.9. params_column (string)
188 3.10. uri_scheme_column (string)
189 3.11. transport_column (string)
190 3.12. strip_column (string)
191 3.13. tag_column (string)
192 3.14. flags_column (string)
193 3.15. defunct_column (string)
194 3.16. lcr_rule_table (string)
195 3.17. prefix_column (string)
196 3.18. from_uri_column (string)
197 3.19. mt_tvalue_column (string)
198 3.20. request_uri_column (string)
199 3.21. stopper_column (string)
200 3.22. enabled_column (string)
201 3.23. lcr_rule_target_table (string)
202 3.24. rule_id_column (string)
203 3.25. gw_id_column (string)
204 3.26. priority_column (string)
205 3.27. weight_column (string)
206 3.28. lcr_count (integer)
207 3.29. gw_uri_avp (AVP string)
208 3.30. ruri_user_avp (AVP string)
209 3.31. tag_avp (AVP string)
210 3.32. flags_avp (AVP string)
211 3.33. rule_id_avp (AVP string)
212 3.34. mt_pv_values (AVP string)
213 3.35. mtree (string)
214 3.36. defunct_capability (integer)
215 3.37. lcr_id_avp (AVP string)
216 3.38. defunct_gw_avp (AVP string)
217 3.39. lcr_rule_hash_size (integer)
218 3.40. lcr_gw_count (integer)
219 3.41. dont_strip_or_prefix_flag (integer)
220 3.42. priority_ordering (integer)
221 3.43. fetch_rows (integer)
222 3.44. ping_interval (integer)
223 3.45. ping_inactivate_threshold (integer)
224 3.46. ping_valid_reply_codes (string)
225 3.47. ping_from (string)
226 3.48. ping_socket (string)
227
228 4. Functions
229
230 4.1. load_gws(lcr_id[, uri_user[, caller_uri]])
231 4.2. next_gw()
232 4.3. inactivate_gw()
233 4.4. defunct_gw(period)
234 4.5. from_gw(lcr_id[, ip_addr, proto[, src_port]])
235 4.6. from_any_gw([ip_addr, proto[, src_port]])
236 4.7. to_gw(lcr_id[, ip_addr, proto])
237 4.8. to_any_gw([ip_addr, proto])
238
239 5. RPC Commands
240
241 5.1. lcr.reload
242 5.2. lcr.dump_gws
243 5.3. lcr.dump_rules
244 5.4. lcr.load_gws
245 5.5. lcr.defunct_gw
246
247 6. Known Limitations
248
249 1. Overview
250
251 The Least Cost Routing (LCR) module implements capability to serially
252 forward a request to one or more gateways so that the order in which
253 the gateways is tried is based on admin defined "least cost" rules.
254
255 The LCR module supports many independent LCR instances (gateways and
256 least cost rules). Each such instance has its own LCR instance
257 identifier. Identifiers of normal LCR instances are positive integers.
258 Gateways may belong to special LCR instance with identifier 0 meaning
259 that such gateways belong to all normal LCR instances.
260
261 For the purpose of facilitating least cost routing of requests, each
262 gateway of an LCR instance is associated with one or more <prefix, from
263 uri pattern, from uri userpart, request uri pattern, priority, weight>
264 tuples. A gateway matches a request if user part of Request-URI matches
265 "prefix", caller URI matches "from_uri" pattern, caller URI userpart
266 matches mtree with "mt_value", and callee URI matches "request_uri"
267 pattern in a tuple that is associated with the gateway.
268
269 When the function load_gws() is called, matching gateways (that are not
270 currently designated as defunct) are ordered for forwarding purposes as
271 follows:
272
273 1. according to longest Request-URI user part match
274 2. according to tuple's priority
275 3. according to tuple's randomized weight
276
277 or, if priority_ordering parameter is set to value 1, as follows:
278
279 1. according to tuple's priority
280 2. according to tuple's randomized weight
281
282 A tuple can be marked as a "stopper" tuple. If a "stopper" tuple
283 matches, then matching stops at it and all other tuples with shorter
284 prefixes are not considered.
285
286 Prefix is a string of characters or NULL. From-URI pattern and
287 Request-URI pattern are regular expressions (see 'man pcresyntax' for
288 syntax), an empty string, or NULL. An empty or NULL From-URI pattern,
289 Request-URI pattern or prefix matches anything. Smaller priority value
290 means higher priority (highest priority value being 0 and lowest being
291 255).
292
293 Weight is an integer value from 1 to 254. Weight implementation is
294 fast, but unfair favoring larger weight values at the expense smaller
295 ones. For example, if two gateways have weights 1 and 2, probability
296 that the gateway with weight 1 is tried first is 1/4, not 1/3. Two
297 scripts are provided in lcr/utils directory that can be used to check
298 the probabilities resulting from a given set of weight values. Same can
299 be done with command 'kamctl eval_weights'.
300
301 The function next_gw() can then be used to select one gateway at a time
302 for forwarding. Upon each call, unless "dont_strip_or_prefix_flag" flag
303 is set, user part of the original Request-URI is first stripped by the
304 number of characters as specified by the gateway's strip count and then
305 prefixed by the gateway's prefix. Upon each call, if a gateway's
306 hostname is NULL, Request-URI will be rewritten based on gateway's URI
307 scheme, IP address, port, parameters, and transport protocol. If
308 hostname is not NULL and IP address is NULL, Request-URI will be
309 rewritten based on the gateway's URI scheme, hostname, port, parameters
310 and transport protocol. If both hostname and IP address are not NULL,
311 Request-URI will be rewritten based on gateway's URI scheme, hostname,
312 and parameters, and destination URI is set based on gateway's URI
313 scheme, IP address, port, and transport protocol.
314
315 Valid URI scheme values are NULL = sip, 1 = sip and 2 = sips. Currently
316 valid transport protocol values are NULL and 0 = none, 1 = udp, 2 =
317 tcp, 3 = tls, and 4 = sctp.
318
319 As a side effect of gateway selection, selected gateway's tag and flags
320 (that may contain information about the gateway and its capabilities)
321 are stored to tag_avp and flags_avp, respectively, if the corresponding
322 module parameter has been defined. In the same way, rule_id_avp, if
323 defined, contains the id of the rule that selected the gateway.
324
325 2. Dependencies
326
327 2.1. Kamailio Modules
328 2.2. External libraries or applications
329
330 2.1. Kamailio Modules
331
332 The following modules must be loaded before this module:
333 * A database module like mysql, postgres or dbtext.
334 * mtree module if mt_pv_values parameter is set.
335
336 2.2. External libraries or applications
337
338 The following libraries or applications must be installed before
339 running SIP Router with this module:
340 * libpcre
341
342 3. Parameters
343
344 3.1. db_url (string)
345 3.2. lcr_gw_table (string)
346 3.3. id_column (string)
347 3.4. lcr_id_column (string)
348 3.5. gw_name_column (string)
349 3.6. ip_addr_column (string)
350 3.7. hostname_column (string)
351 3.8. port_column (string)
352 3.9. params_column (string)
353 3.10. uri_scheme_column (string)
354 3.11. transport_column (string)
355 3.12. strip_column (string)
356 3.13. tag_column (string)
357 3.14. flags_column (string)
358 3.15. defunct_column (string)
359 3.16. lcr_rule_table (string)
360 3.17. prefix_column (string)
361 3.18. from_uri_column (string)
362 3.19. mt_tvalue_column (string)
363 3.20. request_uri_column (string)
364 3.21. stopper_column (string)
365 3.22. enabled_column (string)
366 3.23. lcr_rule_target_table (string)
367 3.24. rule_id_column (string)
368 3.25. gw_id_column (string)
369 3.26. priority_column (string)
370 3.27. weight_column (string)
371 3.28. lcr_count (integer)
372 3.29. gw_uri_avp (AVP string)
373 3.30. ruri_user_avp (AVP string)
374 3.31. tag_avp (AVP string)
375 3.32. flags_avp (AVP string)
376 3.33. rule_id_avp (AVP string)
377 3.34. mt_pv_values (AVP string)
378 3.35. mtree (string)
379 3.36. defunct_capability (integer)
380 3.37. lcr_id_avp (AVP string)
381 3.38. defunct_gw_avp (AVP string)
382 3.39. lcr_rule_hash_size (integer)
383 3.40. lcr_gw_count (integer)
384 3.41. dont_strip_or_prefix_flag (integer)
385 3.42. priority_ordering (integer)
386 3.43. fetch_rows (integer)
387 3.44. ping_interval (integer)
388 3.45. ping_inactivate_threshold (integer)
389 3.46. ping_valid_reply_codes (string)
390 3.47. ping_from (string)
391 3.48. ping_socket (string)
392
393 3.1. db_url (string)
394
395 URL of the database table to be used.
396
397 Default value is “mysql://kamailioro:kamailioro@localhost/kamailio”.
398
399 Example 1.1. Setting db_url module parameter
400 ...
401 modparam("lcr","db_url","dbdriver://username:password@dbhost/dbname")
402 ...
403
404 3.2. lcr_gw_table (string)
405
406 Name of the table holding gateways definitions.
407
408 Default value is “lcr_gw”.
409
410 Example 1.2. Setting lcr_gw_table module parameter
411 ...
412 modparam("lcr", "lcr_gw_table","gw")
413 ...
414
415 3.3. id_column (string)
416
417 Name of the auto-increment, primary key column. Common to all lcr
418 module tables.
419
420 Default value is “id”.
421
422 Example 1.3. Setting id_column module parameter
423 ...
424 modparam("lcr", "id_column", "row_id")
425 ...
426
427 3.4. lcr_id_column (string)
428
429 Name of the column holding the identifier of an LCR instance. Common to
430 all lcr module tables. In lcr_rule and lcr_rule_target tables, value of
431 the column is integer from 1 to lcr_count. In lcr_gw table, value of
432 the column is from 0 to lcr_count.
433
434 Default value is “lcr_id”.
435
436 Example 1.4. Setting lcr_id_column module parameter
437 ...
438 modparam("lcr", "lcr_id_column", "lcr_identifier")
439 ...
440
441 3.5. gw_name_column (string)
442
443 Name of the column holding gateway's name for documentation purpose.
444
445 Default value is “gw_name”.
446
447 Example 1.5. Setting gw_name_column module parameter
448 ...
449 modparam("lcr", "gw_name_column", "name")
450 ...
451
452 3.6. ip_addr_column (string)
453
454 Name of the column holding the IPv4 or IPv6 address of the gateway.
455
456 Default value is “ip_addr”.
457
458 Example 1.6. Setting ip_addr_column module parameter
459 ...
460 modparam("lcr", "ip_addr_column", "ip")
461 ...
462
463 3.7. hostname_column (string)
464
465 Name of the column holding gateway's hostname that is used in
466 Request-URI hostpart, when request is sent to the gateway.
467
468 Default value is “hostname”.
469
470 Example 1.7. Setting hostname_column module parameter
471 ...
472 modparam("lcr", "hostname_column", "host")
473 ...
474
475 3.8. port_column (string)
476
477 Name of the column holding the port number of the gateway.
478
479 Default value is “port”.
480
481 Example 1.8. Setting port_column module parameter
482 ...
483 modparam("lcr", "port_column", "port")
484 ...
485
486 3.9. params_column (string)
487
488 Name of the column holding gateway's parameters that is used in
489 Request-URI, when request is sent to the gateway.
490
491 Default value is “params”.
492
493 Example 1.9. Setting params_column module parameter
494 ...
495 modparam("lcr", "params_column", "parameters")
496 ...
497
498 3.10. uri_scheme_column (string)
499
500 Name of the column holding the uri scheme of the gateway.
501
502 Default value is “uri_scheme”.
503
504 Example 1.10. Setting uri_scheme_column module parameter
505 ...
506 modparam("lcr", "uri_scheme_column", "uri_scheme")
507 ...
508
509 3.11. transport_column (string)
510
511 Name of the column holding the transport protocol to be used for the
512 gateway.
513
514 Default value is “transport”.
515
516 Example 1.11. Setting transport_column module parameter
517 ...
518 modparam("lcr", "transport_column", "trans")
519 ...
520
521 3.12. strip_column (string)
522
523 Name of the column holding the number of characters to be stripped from
524 the front of Request-URI user part before inserting tag.
525
526 Default value is “strip”.
527
528 Example 1.12. Setting strip_column module parameter
529 ...
530 modparam("lcr", "strip_column", "strip_count")
531 ...
532
533 3.13. tag_column (string)
534
535 Name of the column holding gateway specific tag string that is added to
536 Request URI userpart after stripping.
537
538 Default value is “tag”.
539
540 Example 1.13. Setting tag_column module parameter
541 ...
542 modparam("lcr", "tag_column", "gw_tag")
543 ...
544
545 3.14. flags_column (string)
546
547 Name of the column holding gateway specific flag values.
548
549 Default value is “flags”.
550
551 Example 1.14. Setting flags_column module parameter
552 ...
553 modparam("lcr", "flags_column", "gw_flags")
554 ...
555
556 3.15. defunct_column (string)
557
558 Name of the column holding UNIX timestamp telling the time until which
559 the gw is considered as defunct. If timestamp value is 4294967295 (=
560 max UNIX timestamp value) or greater, gw is considered currently unused
561 and is not loaded into memory at all.
562
563 Default value is “defunct”.
564
565 Example 1.15. Setting defunct_column module parameter
566 ...
567 modparam("lcr", "defunct_column", "defunct_until")
568 ...
569
570 3.16. lcr_rule_table (string)
571
572 Name of the table holding the LCR rules.
573
574 Default value is “lcr_rule”.
575
576 Example 1.16. Setting lcr_rule_table module parameter
577 ...
578 modparam("lcr", "lcr_rule_table", "rules")
579 ...
580
581 3.17. prefix_column (string)
582
583 Name of the column in lcr_rule and lcr_gw tables holding prefix of
584 Request-URI user part and prefix of gateway, respectively.
585
586 Default value is “prefix”.
587
588 Example 1.17. Setting prefix_column module parameter
589 ...
590 modparam("lcr", "prefix_column", "number_prefix")
591 ...
592
593 3.18. from_uri_column (string)
594
595 Name of the column holding the From (caller's) URI.
596
597 Default value is “from_uri”.
598
599 Example 1.18. Setting from_uri_column module parameter
600 ...
601 modparam("lcr", "from_uri_column", "caller_uri")
602 ...
603
604 3.19. mt_tvalue_column (string)
605
606 Name of the column holding mtree tvalue.
607
608 Default value is “mt_tvalue”.
609
610 Example 1.19. Setting from_uri_column module parameter
611 ...
612 modparam("lcr", "mt_tvalue_column", "tree_value")
613 ...
614
615 3.20. request_uri_column (string)
616
617 Name of the column holding the regular expression to match against the
618 complete request URI (including the "sip:" prefix).
619
620 Default value is “request_uri”.
621
622 Example 1.20. Setting request_uri_column module parameter
623 ...
624 modparam("lcr", "request_uri_column", "callee_uri")
625 ...
626
627 3.21. stopper_column (string)
628
629 Name of the column holding rule's stopper attribute.
630
631 Default value is “stopper”.
632
633 Example 1.21. Setting stopper_column module parameter
634 ...
635 modparam("lcr", "stopper_column", "stop")
636 ...
637
638 3.22. enabled_column (string)
639
640 Name of the column telling is the rule is currently enabled or
641 disabled.
642
643 Default value is “enabled”.
644
645 Example 1.22. Setting enabled_column module parameter
646 ...
647 modparam("lcr", "enabled_column", "in_use")
648 ...
649
650 3.23. lcr_rule_target_table (string)
651
652 Name of the table holding information about the LCR rule targets
653 (gateways).
654
655 Default value is “lcr_rule_target”.
656
657 Example 1.23. Setting lcr_rule_target_table module parameter
658 ...
659 modparam("lcr", "lcr_rule_target_table", "rules")
660 ...
661
662 3.24. rule_id_column (string)
663
664 Name of lcr_rule_target_table column containing an id of lcr_rule
665 table.
666
667 Default value is “rule_id”.
668
669 Example 1.24. Setting rule_id_column module parameter
670 ...
671 modparam("lcr", "rule_id_column", "rule")
672 ...
673
674 3.25. gw_id_column (string)
675
676 Name of lcr_rule_target_table column containing an id of lcr_gw table.
677
678 Default value is “gw_id”.
679
680 Example 1.25. Setting gw_id_column module parameter
681 ...
682 modparam("lcr", "gw_id_column", "gw")
683 ...
684
685 3.26. priority_column (string)
686
687 Name of the column holding the priority of the rule target.
688
689 Default value is “priority”.
690
691 Example 1.26. Setting priority_column module parameter
692 ...
693 modparam("lcr", "priority_column", "priority")
694 ...
695
696 3.27. weight_column (string)
697
698 Name of the column holding weight of rule target.
699
700 Default value is “weight”.
701
702 Example 1.27. Setting weight_column module parameter
703 ...
704 modparam("lcr","weight_column", "target_weight")
705 ...
706
707 3.28. lcr_count (integer)
708
709 Maximum value of lcr_id.
710
711 Default value is 1.
712
713 Example 1.28. Setting lcr_count module parameter
714 ...
715 modparam("lcr", "lcr_count", 10)
716 ...
717
718 3.29. gw_uri_avp (AVP string)
719
720 Internal AVP that load_gws() function uses to store information of
721 matching gateways.
722
723 There is NO default value, thus this variable must be defined in
724 sip-router.cfg.
725
726 Example 1.29. Setting gw_uri_avp module parameter
727 ...
728 modparam("lcr", "gw_uri_avp", "$avp(lcr_gwuri)")
729 ...
730
731 3.30. ruri_user_avp (AVP string)
732
733 Internal AVP that next_gw function uses to store Request-URI user for
734 subsequent next_gw calls.
735
736 There is NO default value, thus this variable must be defined in
737 sip-router.cfg.
738
739 Example 1.30. Setting ruri_user_avp module parameter
740 ...
741 modparam("lcr", "ruri_user_avp", "$avp(lcr_ruri_user)")
742 ...
743
744 3.31. tag_avp (AVP string)
745
746 If defined, an AVP where successful next_gw and from_gw functions store
747 gateway's tag.
748
749 There is NO default value, i.e, if not defined, gateway's tag is not
750 stored anywhere.
751
752 Example 1.31. Setting tag_avp module parameter
753 ...
754 modparam("lcr", "tag_avp", "$avp(lcr_tag)")
755 ...
756
757 3.32. flags_avp (AVP string)
758
759 If defined, an AVP where successful next_gw and from_gw functions store
760 gateway's flags.
761
762 There is NO default value, i.e, if not defined, gateway's flags are not
763 stored anywhere.
764
765 Example 1.32. Setting flags_avp module parameter
766 ...
767 modparam("lcr", "flags_avp", "$avp(lcr_flags)")
768 ...
769
770 3.33. rule_id_avp (AVP string)
771
772 If defined, an AVP where successful next_gw and from_gw functions store
773 matching rule's id.
774
775 There is NO default value, i.e, if not defined, matching rule's id is
776 not stored anywhere.
777
778 Example 1.33. Setting rule_id_avp module parameter
779 ...
780 modparam("lcr", "rule_id_avp", "$avp(lcr_ruleid)")
781 ...
782
783 3.34. mt_pv_values (AVP string)
784
785 If defined and mt_value is given for a rule, load_gws() matches caller
786 URI userpart to a mtree given as mtree parameter.
787
788 If defined, must have the same value as mtree module pv_values
789 parameter.
790
791 There is NO default value.
792
793 Example 1.34. Setting tag_avp module parameter
794 ...
795 modparam("lcr", "mt_pv_values", "$avp(lcr_mt_values)")
796 ...
797
798 3.35. mtree (string)
799
800 Name of mtree to which load_gws() matches caller URI userpart.
801
802 Default value is "lcr".
803
804 Example 1.35. Setting mtree module parameter
805 ...
806 modparam("lcr", "mtree", "caller_tree")
807 ...
808
809 3.36. defunct_capability (integer)
810
811 Tells if defunct capability of (non-responsive) gateways is supported.
812 Non-zero value turns on defunct capability.
813
814 Default value is 0.
815
816 Example 1.36. Setting defunct_capability module parameter
817 ...
818 modparam("lcr", "defunct_capability", 1)
819 ...
820
821 3.37. lcr_id_avp (AVP string)
822
823 Internal AVP that load_gws() function uses to store LCR instance
824 identifier of loaded gateways. Only needed if gateway defunct
825 capability has been activated.
826
827 There is NO default value.
828
829 Example 1.37. Setting lcr_id_avp module parameter
830 ...
831 modparam("lcr", "lcr_id_avp", "$avp(lcr_id)")
832 ...
833
834 3.38. defunct_gw_avp (AVP string)
835
836 Internal AVP that next_gw() function uses to store internal index of
837 the selected gateway for later use by defunct_gw() function. Only
838 needed if gateway defunct capability has been activated.
839
840 There is NO default value.
841
842 Example 1.38. Setting defunct_gw_avp module parameter
843 ...
844 modparam("lcr", "defunct_gw_avp", "$avp(lcr_defunct_gw)")
845 ...
846
847 3.39. lcr_rule_hash_size (integer)
848
849 Defines the size of hash table used to store LCR rules. Hashing is done
850 based on rule's prefix. Larger value means less collisions with other
851 prefixes. Hash size value should be a power of 2.
852
853 Default value is 128.
854
855 Example 1.39. Setting lcr_rule_hash_size module parameter
856 ...
857 modparam("lcr", "lcr_rule_hash_size", 1024)
858 ...
859
860 3.40. lcr_gw_count (integer)
861
862 Defines the maximum number of gateways in lcr_gw table.
863
864 Default value is 128.
865
866 Example 1.40. Setting lcr_gw_count module parameter
867 ...
868 modparam("lcr", "lcr_gw_count", 1024)
869 ...
870
871 3.41. dont_strip_or_prefix_flag (integer)
872
873 Defines the flag number used to tell if stripping and tagging is done
874 for the selected gateway.
875
876 Default value is -1 meaning that the flag is not defined.
877
878 Example 1.41. Setting dont_strip_or_prefix_flag module parameter
879 ...
880 modparam("lcr", "dont_strip_or_prefix_flag", 10)
881 ...
882
883 3.42. priority_ordering (integer)
884
885 Defines how matching gateways are ordered (see Overview section).
886
887 Default value is 0.
888
889 Example 1.42. Setting priority_ordering module parameter
890 ...
891 modparam("lcr", "priority_ordering", 1)
892 ...
893
894 3.43. fetch_rows (integer)
895
896 The number of the rows to be fetched at once from database when loading
897 data from lcr_rule table. This value can be used to tune the load time
898 at startup. For 1MB of private memory (default) it should be below
899 3750. In order for this parameter to have effect, the database driver
900 must support fetch_result() capability.
901
902 Default value is “1024”.
903
904 Example 1.43. Set fetch_rows parameter
905 ...
906 modparam("lcr", "fetch_rows", 3000)
907 ...
908
909 3.44. ping_interval (integer)
910
911 Interval in seconds for sending OPTIONS ping requests to gateways that,
912 due to failures, have been marked as inactive by inactivate_gw()
913 function call. If an inactive gateway later gives a valid response (see
914 ping_valid_reply_codes) to a ping request, it is marked again as
915 active.
916
917 If value of this parameter is greater than zero, tm module must have
918 been loaded and parameters lcr_id_avp and defunct_gw_avp must have been
919 defined. Value “0” disables sending of OPTIONS ping requests to failed
920 gateways.
921
922 Default value is “0”.
923
924 Example 1.44. Set ping_interval parameter
925 ...
926 modparam("lcr", "ping_interval", 15)
927 ...
928
929 3.45. ping_inactivate_threshold (integer)
930
931 Tells after how many failures (= inactivate_gw() function calls) a
932 gateway is marked as inactive.
933
934 Default value is “1”, i.e., gateway is inactivated after first failure.
935
936 Example 1.45. Set ping_inactivate_threshold parameter
937 ...
938 modparam("lcr", "ping_inactivate_threshold", 3)
939 ...
940
941 3.46. ping_valid_reply_codes (string)
942
943 A comma separated list of SIP reply codes, which are accepted as valid
944 replies to OPTIONS ping requests. Reply codes 2xx are by default
945 accepted as valid replies and they don't need to be listed here.
946
947 Default value is “”, i.e., only 2xx replies are considered as valid
948 replies.
949
950 Example 1.46. Set ping_valid_reply_codes parameter
951 ...
952 modparam("lcr", "ping_valid_reply_codes", "403,405,501")
953 ...
954
955 3.47. ping_from (string)
956
957 From URI used in OPTIONS ping requests.
958
959 Default value is “sip:pinger@localhost”.
960
961 Example 1.47. Set ping_from parameter
962 ...
963 modparam("lcr", "ping_from", "sip:proxy.operator.com")
964 ...
965
966 3.48. ping_socket (string)
967
968 Socket to be used for sending OPTIONS ping request. If not set or set
969 to “”, default socket is used.
970
971 Default value is “”.
972
973 Example 1.48. Set ping_socket parameter
974 ...
975 modparam("lcr", "ping_socket", "192.98.102.10:5060")
976 ...
977
978 4. Functions
979
980 4.1. load_gws(lcr_id[, uri_user[, caller_uri]])
981 4.2. next_gw()
982 4.3. inactivate_gw()
983 4.4. defunct_gw(period)
984 4.5. from_gw(lcr_id[, ip_addr, proto[, src_port]])
985 4.6. from_any_gw([ip_addr, proto[, src_port]])
986 4.7. to_gw(lcr_id[, ip_addr, proto])
987 4.8. to_any_gw([ip_addr, proto])
988
989 4.1. load_gws(lcr_id[, uri_user[, caller_uri]])
990
991 Loads attributes of matching gateways to gw_uri_avp (see Overview
992 section). Argument lcr_id specifies the used LCR instance. It can be a
993 positive integer or a pseudo variable containing an integer value. If
994 uri_user is given, it is used, instead of Request-URI user part, to
995 look for matching gateways. Caller's URI may be given by caller_uri
996 argument. If caller_uri argument is omitted, it defaults to empty
997 string. Both uri_user and caller_uri argument may be a string or a
998 pseudo variable containing a string value.
999
1000 Returns 1 if at least one matching gateway was found, 2 if no matching
1001 gateways was found, and -1 on error.
1002
1003 Execution time of load_gws() function is O(N) * O(M), where N is number
1004 of different prefix lengths and M is number of collisions for matching
1005 prefix(es) in lcr rules hash table of the LCR instance.
1006
1007 This function can be used from REQUEST_ROUTE.
1008
1009 Example 1.49. load_gws usage
1010 ...
1011 if (!load_gws(1, $rU, $var(caller_uri))) {
1012 sl_send_reply("500", "Server Internal Error - Cannot load gateways");
1013 exit;
1014 };
1015 ...
1016
1017 4.2. next_gw()
1018
1019 Upon first call, fetches attribute values stored in first gw_uri_avp,
1020 destroys that AVP, and rewrites Request-URI and possibly also
1021 destination URI as described in the Overview section. Saves user part
1022 of Request-URI into ruri_user_avp for use in subsequent next_gw()
1023 calls.
1024
1025 Upon subsequent calls, does the same as in above, but takes user part
1026 of Request-URI from ruri_user_avp.
1027
1028 As a side effect, stores gateway's tag and flags to tag_avp and
1029 flags_avp, respectively, if the corresponding module parameter has been
1030 defined. In the same way, rule_id_avp, if defined, contains the id of
1031 the rule that selected the gateway.
1032
1033 Returns 1 on success and -1 if there were no gateways left or if an
1034 error occurred (see syslog).
1035
1036 Must be preceded by successful load_gws() call.
1037
1038 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1039
1040 Example 1.50. next_gw usage from a route block
1041 ...
1042 if (!next_gw()) {
1043 sl_send_reply("503", "Service not available - No gateways");
1044 exit;
1045 };
1046 ...
1047
1048 Example 1.51. next_gw usage from a failure route block
1049 ...
1050 if (!next_gw()) {
1051 t_reply("503", "Service not available - No more gateways");
1052 exit;
1053 };
1054 ...
1055
1056 4.3. inactivate_gw()
1057
1058 Inactivates the gateway denoted by lcr_id_avp and defunct_gw_avp (which
1059 were set by previous next_gw() call). Use of this function requires
1060 that ping_interval module parameter has been set to a positive value
1061 allowing an inactivated gateway to be automatically activated by a
1062 positive response to OPTIONS ping request.
1063
1064 Returns 1 on success and -1 in case of error (see syslog).
1065
1066 This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
1067
1068 Example 1.52. inactivate_gw usage
1069 ...
1070 failure_route [GW_FAILURE] {
1071 ...
1072 if (t_check_status("408|503")) {
1073 inactivate_gw();
1074 };
1075 ...
1076
1077 4.4. defunct_gw(period)
1078
1079 Defuncts gateway denoted by lcr_id_avp and defunct_gw_avp (which were
1080 set by previuos next_gw() call) for a period of seconds given as
1081 argument. Argument must be a positive integer constant or a pseudo
1082 variable with positive integer value. Value of defunct column in
1083 database is not updated.
1084
1085 Returns 1 on success and -1 in case of error (see syslog).
1086
1087 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1088
1089 Example 1.53. defunct_gw usage
1090 ...
1091 defunct_gw(60);
1092 ...
1093
1094 4.5. from_gw(lcr_id[, ip_addr, proto[, src_port]])
1095
1096 Checks if request comes from IP address, transport protocol and source
1097 port specified for a gateway in LCR instance lcr_id. Fails if the LCR
1098 instance includes one or more gateways without IP address. IP address,
1099 transport protocol and source port to be checked are either taken from
1100 source IP address and port of the request or (if present) from ip_addr,
1101 proto and src_port arguments.
1102
1103 lcr_id can be an integer constant or a pseudo variable holding an
1104 integer value. ip_addr can be a string or a pseudo variable holding a
1105 string value. proto can be an integer constant (0 = ANY, 1 = UDP, 2 =
1106 TCP, 3 = TLS, 4 = SCTP) or a pseudo variable holding such an integer
1107 value. src_port can be an integer or a pseudo variable holding such an
1108 integer value.
1109
1110 If request comes from a gateway, gateway's tag and flags are stored as
1111 a side effect to tag_avp and flags_avp, respectively, if the
1112 corresponding module parameter has been defined. In the same way,
1113 rule_id_avp, if defined, contains the id of the rule that selected the
1114 gateway.
1115
1116 Returns 1 on success and -1 on failure or on error.
1117
1118 Execution time of from_gw() function is O(log N), where N is number of
1119 gateways in the LCR instance.
1120
1121 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
1122 ONREPLY_ROUTE.
1123
1124 Example 1.54. from_gw usage
1125 ...
1126 if (from_gw(1, $avp(real_source_addr), 2, 5060) {
1127 ...
1128 };
1129 ...
1130
1131 4.6. from_any_gw([ip_addr, proto[, src_port]])
1132
1133 Checks if request comes from IP address, transport protocol and source
1134 port specified for any gateway. Only LCR instances, where all gateways
1135 have IP address, are included in the test. IP address, transport
1136 protocol and source port to be checked are either taken from source IP
1137 address, transport protocol and source port of the request or (if
1138 present) from ip_addr, proto and src_port arguments. See from_gw()
1139 function for more info about the arguments.
1140
1141 If any gateway has the IP address, transport protocol and source port,
1142 function returns LCR identifier of the gateway. Returns -1 on error or
1143 if the request does not come from a gateway.
1144
1145 If request comes from a gateway, gateway's tag and flags are stored as
1146 a side effect to tag_avp and flags_avp, respectively, if the
1147 corresponding module parameter has been defined. In the same way,
1148 rule_id_avp, if defined, contains the id of the rule that selected the
1149 gateway.
1150
1151 Execution time of from_gw() function is M * O(log N), where M is number
1152 of LCR instances and N is average number of gateways in LCR instances.
1153
1154 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
1155 ONREPLY_ROUTE.
1156
1157 Example 1.55. from_gw usage
1158 ...
1159 $var(lcr_id) = from_any_gw("192.168.1.1", 3, 5061);
1160 ...
1161
1162 4.7. to_gw(lcr_id[, ip_addr, proto])
1163
1164 Checks if in-dialog request goes to IP address and transport protocol
1165 specified for a gateway in LCR instance lcr_id. Fails if LCR instance
1166 includes one or more gateways without IP address. IP address and
1167 transport protocol to be checked are either taken from Request-URI or
1168 (if present) from ip_addr and proto arguments. See from_gw() for more
1169 info regarding the arguments.
1170
1171 Returns 1 on success and -1 on failure and error.
1172
1173 Execution time of to_gw() function is O(log N), where N is number of
1174 gateways in the LCR instance.
1175
1176 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1177
1178 Example 1.56. to_gw usage
1179 ...
1180 if (to_gw("1")) {
1181 ...
1182 exit;
1183 };
1184 ...
1185
1186 4.8. to_any_gw([ip_addr, proto])
1187
1188 Checks if in-dialog request goes to IP address and transport protocol
1189 of any gateway. Only LCR instances, where all gateways have IP address,
1190 are included in the test. IP address and transport protocol to be
1191 checked are either taken from Request-URI or (if present) from ip_addr
1192 and proto arguments. See from_gw() for more info regarding the
1193 arguments.
1194
1195 Execution time of to_any_gw() function is M * O(log N), where M is
1196 number of LCR instances and N is average number of gateways in LCR
1197 instances.
1198
1199 If any gateway has the IP address, returns LCR identifier of the
1200 gateway. Returns -1 if request does not go to a gateway and on error.
1201
1202 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1203
1204 Example 1.57. to_gw usage
1205 ...
1206 if (to_any_gw("192.55.66.2", 1)) {
1207 ...
1208 exit;
1209 };
1210 ...
1211
1212 5. RPC Commands
1213
1214 5.1. lcr.reload
1215 5.2. lcr.dump_gws
1216 5.3. lcr.dump_rules
1217 5.4. lcr.load_gws
1218 5.5. lcr.defunct_gw
1219
1220 5.1. lcr.reload
1221
1222 Causes lcr module to re-read the contents of LCR tables into memory.
1223
1224 Name: lcr.reload
1225
1226 Parameters: none
1227
1228 Example 1.58. lcr.reload RPC example
1229 $ kamcmd lcr.reload
1230
1231 5.2. lcr.dump_gws
1232
1233 Causes lcr module to dump the contents of its in-memory gw table.
1234
1235 Parameters: none
1236
1237 Example 1.59. lcr.dump_gws RPC example
1238 $ kamcmd lcr.dump_gws
1239
1240 5.3. lcr.dump_rules
1241
1242 Causes lcr module to dump the contents of its in-memory lcr_rule and
1243 lcr_rule_target tables. Rules can be filtered by lcr_id or lcr_id and
1244 prefix. The filters are passed as optional parameters.
1245
1246 Parameters:
1247 * lcr_id filter rules based on lcr_id.
1248 * prefix filter rules based on prefix (prefixes shorter or equal to
1249 the give prefix) in addition to the previous lcr_id parameter.
1250
1251 Example 1.60. lcr.dump_rules RPC example
1252 $ kamcmd lcr.dump_rules
1253
1254 5.4. lcr.load_gws
1255
1256 Loads gateways and prints ids of matching ones in priority order.
1257
1258 Name: lcr.load_gws
1259
1260 Parameters: lcr_id uri_user [caller_uri request_uri]
1261
1262 Example 1.61. lcr.load_gws RPC example
1263 $ kamcmd lcr.load_gws 2 s:0447058050
1264
1265 5.5. lcr.defunct_gw
1266
1267 Defuncts gateway loaded into memory for a period of time (seconds)
1268 without a need to store gateway's defunct value into database and
1269 reload the tables.
1270
1271 Name: lcr.defunct_gw
1272
1273 Parameters: lcr_id gw_id period
1274
1275 Example 1.62. lcr.defunct_gw RPC example
1276 $ kamcmd lcr.defunct_gw 1 4 120
1277
1278 6. Known Limitations
1279
1280 In-memory LCR rules and gw tables are switched by two consecutive
1281 machine instructions. If lcr reload process is interrupted after the
1282 first one, in-memory gateway table does not match in-memory rule table
1283 until execution of lcr reload process is resumed.