Debian Codegraph @

src/modules/dispatcher/README

raw
1 DISPATCHER Module
2
3 Daniel-Constantin Mierla
4
5 <[email protected]>
6
7 Edited by
8
9 Daniel-Constantin Mierla
10
11 <[email protected]>
12
13 Carsten Bock
14
15 ng-voice GmbH
16
17 Olle E. Johansson
18
19 Edvina AB
20
21 Alessandro Arrichiello
22
23 Hewlett Packard
24
25 Luis Martin
26
27 Julien Chavanton
28
29 <[email protected]>
30
31 Federico Cabiddu
32
33 <[email protected]>
34
35 Tyler Moore
36
37 <[email protected]>
38
39 Copyright © 2004 FhG FOKUS
40
41 Copyright © 2005 Voice Sistem
42
43 Copyright © 2010 Daniel-Constantin Mierla (asipto.com)
44
45 Copyright © 2014 Olle E. Johansson, Edvina AB
46
47 Copyright © 2015 Alessandro Arrichiello, Hewlett Packard
48
49 Copyright © 2017, 2018 Julien chavanton, Flowroute
50
51 Copyright © 2020 Federico Cabiddu, Libon
52
53 Copyright © 2025 Tyler Moore, dOpenSource
54 __________________________________________________________________
55
56 Table of Contents
57
58 1. Admin Guide
59
60 1. Overview
61 2. Dependencies
62
63 2.1. Kamailio modules
64 2.2. External libraries or applications
65
66 3. Parameters
67
68 3.1. list_file (string)
69 3.2. db_url (string)
70 3.3. table_name (string)
71 3.4. setid_col (string)
72 3.5. destination_col (string)
73 3.6. flags_col (string)
74 3.7. priority_col (string)
75 3.8. attrs_col (string)
76 3.9. force_dst (int)
77 3.10. flags (int)
78 3.11. use_default (int)
79 3.12. xavp_dst (str)
80 3.13. xavp_dst_mode (int)
81 3.14. xavp_ctx (str)
82 3.15. xavp_ctx_mode (int)
83 3.16. hash_pvar (str)
84 3.17. setid_pvname (str)
85 3.18. attrs_pvname (str)
86 3.19. ds_ping_method (string)
87 3.20. ds_ping_from (string)
88 3.21. ds_ping_interval (int)
89 3.22. ds_ping_fr_timer (int)
90 3.23. ds_probing_threshold (int)
91 3.24. ds_inactive_threshold (int)
92 3.25. ds_ping_reply_codes (string)
93 3.26. ds_probing_mode (int)
94 3.27. ds_ping_latency_stats (int)
95 3.28. ds_retain_latency_stats (int)
96 3.29. ds_latency_estimator_alpha (int)
97 3.30. ds_hash_size (int)
98 3.31. ds_hash_expire (int)
99 3.32. ds_hash_initexpire (int)
100 3.33. ds_hash_check_interval (int)
101 3.34. outbound_proxy (str)
102 3.35. ds_default_socket (str)
103 3.36. ds_default_sockname (str)
104 3.37. ds_ping_socket (str)
105 3.38. ds_timer_mode (int)
106 3.39. event_callback (str)
107 3.40. event_callback_mode (int)
108 3.41. ds_attrs_none (int)
109 3.42. ds_db_extra_attrs (str)
110 3.43. ds_load_mode (int)
111 3.44. reload_delta (int)
112 3.45. ds_dns_mode (int)
113 3.46. ds_dns_interval (int)
114 3.47. ds_dns_ttl (int)
115
116 4. Functions
117
118 4.1. ds_select_dst(set, alg[, limit])
119 4.2. ds_select_domain(set, alg[, limit])
120 4.3. ds_select(set, alg [, limit])
121 4.4. ds_select_routes(rules, mode [, limit])
122 4.5. ds_next_dst()
123 4.6. ds_next_domain()
124 4.7. ds_set_dst()
125 4.8. ds_set_domain()
126 4.9. ds_mark_dst([state])
127 4.10. ds_mark_addr(state, setid, uri)
128 4.11. ds_list_exists(groupid)
129 4.12. ds_is_from_list([groupid [, mode [, uri] ] ])
130 4.13. ds_is_active(groupid [, uri])
131 4.14. ds_load_update()
132 4.15. ds_load_unset()
133 4.16. ds_reload()
134 4.17. ds_dsg_fetch(setid)
135 4.18. ds_dsg_fetch_uri(setid, uri)
136 4.19. ds_oc_set_attrs(setid, uri, rval, tval, sval)
137
138 5. RPC Commands
139
140 5.1. dispatcher.set_state
141 5.2. dispatcher.set_duid_state
142 5.3. dispatcher.list
143 5.4. dispatcher.reload
144 5.5. dispatcher.ping_active
145 5.6. dispatcher.add
146 5.7. dispatcher.remove
147 5.8. dispatcher.hash
148 5.9. dispatcher.oclist
149
150 6. Installation and Running
151
152 6.1. Destination List File
153
154 6.1.1. Special Attributes
155 6.1.2. File Format
156
157 6.2. Kamailio config file
158
159 7. Event routes
160
161 7.1. dispatcher:dst-down
162 7.2. dispatcher:dst-up
163
164 2. Frequently Asked Questions
165
166 List of Examples
167
168 1.1. Set the “list_file” parameter
169 1.2. Set “db_url” parameter
170 1.3. Set “table_name” parameter
171 1.4. Set “setid_col” parameter
172 1.5. Set “destination_col” parameter
173 1.6. Set “flags_col” parameter
174 1.7. Set “priority_col” parameter
175 1.8. Set “attrs_col” parameter
176 1.9. Set the “force_dst” parameter
177 1.10. Set the “flags” parameter
178 1.11. Set the “use_default” parameter
179 1.12. Set the “xavp_dst” parameter
180 1.13. Set the “xavp_dst_mode” parameter
181 1.14. Set the “xavp_ctx” parameter
182 1.15. Set the “xavp_ctx_mode” parameter
183 1.16. Use $avp(hash) for hashing:
184 1.17. Use combination of PVs for hashing:
185 1.18. Set the “setid_pvname” parameter
186 1.19. Set the “attrs_pvname” parameter
187 1.20. Set the “ds_ping_method” parameter
188 1.21. Set the “ds_ping_from” parameter
189 1.22. Set the “ds_ping_interval” parameter
190 1.23. Set the “ds_ping_fr_timer” parameter
191 1.24. Set the “ds_probing_threshold” parameter
192 1.25. Set the “ds_inactive_threshold” parameter
193 1.26. Set the “ds_ping_reply_codes” parameter
194 1.27. Set the “ds_probing_mode” parameter
195 1.28. accessing the metrics
196 1.29. Set the “ds_ping_latency_stats” parameter
197 1.30. Set the “ds_retain_latency_stats” parameter
198 1.31. Set the “ds_latency_estimator_alpha” parameter
199 1.32. Set the “ds_hash_size” parameter
200 1.33. Set the “ds_hash_expire” parameter
201 1.34. Set the “ds_hash_initexpire” parameter
202 1.35. Set the “ds_hash_check_interval” parameter
203 1.36. Set the “outbound_proxy” parameter
204 1.37. Set the “ds_default_socket” parameter
205 1.38. Set the “ds_default_sockname” parameter
206 1.39. Set the “ds_ping_socket” parameter
207 1.40. Set the “ds_timer_mode” parameter
208 1.41. Set event_callback parameter
209 1.42. Set event_callback_mode parameter
210 1.43. Set the “ds_attrs_none” parameter
211 1.44. Set the “ds_db_extra_attrs” parameter
212 1.45. Set the “ds_load_mode” parameter
213 1.46. Set reload_delta parameter
214 1.47. Set the “ds_dns_mode” parameter
215 1.48. Set the “ds_dns_interval” parameter
216 1.49. Set the “ds_dns_ttl” parameter
217 1.50. latency_optimized_dispatching usage
218 1.51. ds_select_dst usage
219 1.52. configuring load balancing with congestion detection
220 1.53. ds_select_domain usage
221 1.54. ds_select usage
222 1.55. ds_select_routes usage
223 1.56. ds_mark_dst usage
224 1.57. ds_mark_addr usage
225 1.58. ds_list_exists usage
226 1.59. ds_is_from_list usage
227 1.60. ds_is_active usage
228 1.61. ds_load_unset usage
229 1.62. ds_reload usage
230 1.63. ds_dsg_fetch() usage
231 1.64. ds_dsg_fetch_uri() usage
232 1.65. ds_oc_set_attrs() usage
233 1.66. dispatcher list file
234 1.67. Kamailio config script - sample dispatcher usage
235
236 Chapter 1. Admin Guide
237
238 Table of Contents
239
240 1. Overview
241 2. Dependencies
242
243 2.1. Kamailio modules
244 2.2. External libraries or applications
245
246 3. Parameters
247
248 3.1. list_file (string)
249 3.2. db_url (string)
250 3.3. table_name (string)
251 3.4. setid_col (string)
252 3.5. destination_col (string)
253 3.6. flags_col (string)
254 3.7. priority_col (string)
255 3.8. attrs_col (string)
256 3.9. force_dst (int)
257 3.10. flags (int)
258 3.11. use_default (int)
259 3.12. xavp_dst (str)
260 3.13. xavp_dst_mode (int)
261 3.14. xavp_ctx (str)
262 3.15. xavp_ctx_mode (int)
263 3.16. hash_pvar (str)
264 3.17. setid_pvname (str)
265 3.18. attrs_pvname (str)
266 3.19. ds_ping_method (string)
267 3.20. ds_ping_from (string)
268 3.21. ds_ping_interval (int)
269 3.22. ds_ping_fr_timer (int)
270 3.23. ds_probing_threshold (int)
271 3.24. ds_inactive_threshold (int)
272 3.25. ds_ping_reply_codes (string)
273 3.26. ds_probing_mode (int)
274 3.27. ds_ping_latency_stats (int)
275 3.28. ds_retain_latency_stats (int)
276 3.29. ds_latency_estimator_alpha (int)
277 3.30. ds_hash_size (int)
278 3.31. ds_hash_expire (int)
279 3.32. ds_hash_initexpire (int)
280 3.33. ds_hash_check_interval (int)
281 3.34. outbound_proxy (str)
282 3.35. ds_default_socket (str)
283 3.36. ds_default_sockname (str)
284 3.37. ds_ping_socket (str)
285 3.38. ds_timer_mode (int)
286 3.39. event_callback (str)
287 3.40. event_callback_mode (int)
288 3.41. ds_attrs_none (int)
289 3.42. ds_db_extra_attrs (str)
290 3.43. ds_load_mode (int)
291 3.44. reload_delta (int)
292 3.45. ds_dns_mode (int)
293 3.46. ds_dns_interval (int)
294 3.47. ds_dns_ttl (int)
295
296 4. Functions
297
298 4.1. ds_select_dst(set, alg[, limit])
299 4.2. ds_select_domain(set, alg[, limit])
300 4.3. ds_select(set, alg [, limit])
301 4.4. ds_select_routes(rules, mode [, limit])
302 4.5. ds_next_dst()
303 4.6. ds_next_domain()
304 4.7. ds_set_dst()
305 4.8. ds_set_domain()
306 4.9. ds_mark_dst([state])
307 4.10. ds_mark_addr(state, setid, uri)
308 4.11. ds_list_exists(groupid)
309 4.12. ds_is_from_list([groupid [, mode [, uri] ] ])
310 4.13. ds_is_active(groupid [, uri])
311 4.14. ds_load_update()
312 4.15. ds_load_unset()
313 4.16. ds_reload()
314 4.17. ds_dsg_fetch(setid)
315 4.18. ds_dsg_fetch_uri(setid, uri)
316 4.19. ds_oc_set_attrs(setid, uri, rval, tval, sval)
317
318 5. RPC Commands
319
320 5.1. dispatcher.set_state
321 5.2. dispatcher.set_duid_state
322 5.3. dispatcher.list
323 5.4. dispatcher.reload
324 5.5. dispatcher.ping_active
325 5.6. dispatcher.add
326 5.7. dispatcher.remove
327 5.8. dispatcher.hash
328 5.9. dispatcher.oclist
329
330 6. Installation and Running
331
332 6.1. Destination List File
333
334 6.1.1. Special Attributes
335 6.1.2. File Format
336
337 6.2. Kamailio config file
338
339 7. Event routes
340
341 7.1. dispatcher:dst-down
342 7.2. dispatcher:dst-up
343
344 1. Overview
345
346 This module offers SIP load balancer functionality and it can be used
347 as SIP traffic dispatcher. There are many load balancing and traffic
348 dispatching algorithms that you can choose from, for example:
349 round-robin, weight based load balancing, call load distribution, and
350 hashing over SIP message attributes.
351
352 The module can be used as a stateless load balancer; it does not depend
353 on any call state tracking module. It requires the TM module if you
354 enable auto-discovery of active/inactive gateways.
355
356 It is very lightweight, therefore suitable for handling heavy SIP
357 traffic. As the module has a small footprint and the ability to load
358 balancing rules from a plain text file, it is suitable for embedded
359 systems.
360
361 2. Dependencies
362
363 2.1. Kamailio modules
364 2.2. External libraries or applications
365
366 2.1. Kamailio modules
367
368 The following modules must be loaded before this module:
369 * TM - only if active recovery of failed hosts is required.
370 * database engine - only if you want to load balancing routes from
371 database instead of plain text file. .
372
373 2.2. External libraries or applications
374
375 The following libraries or applications must be installed before
376 running Kamailio with this module:
377 * none.
378
379 3. Parameters
380
381 3.1. list_file (string)
382 3.2. db_url (string)
383 3.3. table_name (string)
384 3.4. setid_col (string)
385 3.5. destination_col (string)
386 3.6. flags_col (string)
387 3.7. priority_col (string)
388 3.8. attrs_col (string)
389 3.9. force_dst (int)
390 3.10. flags (int)
391 3.11. use_default (int)
392 3.12. xavp_dst (str)
393 3.13. xavp_dst_mode (int)
394 3.14. xavp_ctx (str)
395 3.15. xavp_ctx_mode (int)
396 3.16. hash_pvar (str)
397 3.17. setid_pvname (str)
398 3.18. attrs_pvname (str)
399 3.19. ds_ping_method (string)
400 3.20. ds_ping_from (string)
401 3.21. ds_ping_interval (int)
402 3.22. ds_ping_fr_timer (int)
403 3.23. ds_probing_threshold (int)
404 3.24. ds_inactive_threshold (int)
405 3.25. ds_ping_reply_codes (string)
406 3.26. ds_probing_mode (int)
407 3.27. ds_ping_latency_stats (int)
408 3.28. ds_retain_latency_stats (int)
409 3.29. ds_latency_estimator_alpha (int)
410 3.30. ds_hash_size (int)
411 3.31. ds_hash_expire (int)
412 3.32. ds_hash_initexpire (int)
413 3.33. ds_hash_check_interval (int)
414 3.34. outbound_proxy (str)
415 3.35. ds_default_socket (str)
416 3.36. ds_default_sockname (str)
417 3.37. ds_ping_socket (str)
418 3.38. ds_timer_mode (int)
419 3.39. event_callback (str)
420 3.40. event_callback_mode (int)
421 3.41. ds_attrs_none (int)
422 3.42. ds_db_extra_attrs (str)
423 3.43. ds_load_mode (int)
424 3.44. reload_delta (int)
425 3.45. ds_dns_mode (int)
426 3.46. ds_dns_interval (int)
427 3.47. ds_dns_ttl (int)
428
429 3.1. list_file (string)
430
431 Path to the file with destination sets (destination groups).
432
433 Default value is “/etc/kamailio/dispatcher.list” or
434 “/usr/local/etc/kamailio/dispatcher.list”.
435
436 Example 1.1. Set the “list_file” parameter
437 ...
438 modparam("dispatcher", "list_file", "/run/kamailio/dispatcher.list")
439 ...
440
441 3.2. db_url (string)
442
443 If you want to load the list of gateways from the database you must set
444 this parameter.
445
446 Default value is “NULL” (disable DB support).
447
448 Example 1.2. Set “db_url” parameter
449 ...
450 modparam("dispatcher", "db_url", "mysql://user:passwd@localhost/database")
451 ...
452
453 3.3. table_name (string)
454
455 If you want to load the list of gateways from the database you must set
456 this parameter as the database name.
457
458 Default value is “dispatcher”.
459
460 Example 1.3. Set “table_name” parameter
461 ...
462 modparam("dispatcher", "table_name", "my_dispatcher")
463 ...
464
465 3.4. setid_col (string)
466
467 The column's name in the database storing the gateway's set (group) id.
468
469 Default value is “setid”.
470
471 Example 1.4. Set “setid_col” parameter
472 ...
473 modparam("dispatcher", "setid_col", "groupid")
474 ...
475
476 3.5. destination_col (string)
477
478 The column's name in the database storing the destination sip URI.
479
480 Default value is “destination”.
481
482 Example 1.5. Set “destination_col” parameter
483 ...
484 modparam("dispatcher", "destination_col", "uri")
485 ...
486
487 3.6. flags_col (string)
488
489 The column's name in the database storing the flags for the destination
490 URI.
491
492 Default value is “flags”.
493
494 Example 1.6. Set “flags_col” parameter
495 ...
496 modparam("dispatcher", "flags_col", "dstflags")
497 ...
498
499 3.7. priority_col (string)
500
501 The column's name in the database storing the priority for destination
502 URI.
503
504 Default value is “priority”.
505
506 Example 1.7. Set “priority_col” parameter
507 ...
508 modparam("dispatcher", "priority_col", "dstpriority")
509 ...
510
511 3.8. attrs_col (string)
512
513 The column's name in the database storing the attributes for
514 destination URI.
515
516 Default value is “attrs”.
517
518 Example 1.8. Set “attrs_col” parameter
519 ...
520 modparam("dispatcher", "attrs_col", "dstattrs")
521 ...
522
523 3.9. force_dst (int)
524
525 If set to 1, force overwriting of destination address (outbound proxy)
526 when that is already set. If set to 0, will return error when the
527 destination address is already set.
528
529 Default value is “1”.
530
531 Example 1.9. Set the “force_dst” parameter
532 ...
533 modparam("dispatcher", "force_dst", 1)
534 ...
535
536 3.10. flags (int)
537
538 Various flags that affect dispatcher's behaviour. The flags are defined
539 as a bitmask on an integer value. If flag 1 is set only the username
540 part of the URI will be used when computing an URI based hash. If no
541 flags are set the username, hostname and port will be used. The port is
542 used only if different from 5060 (normal sip URI) or 5061 (in the sips:
543 case).
544
545 If flag 2 is set, then failover support is enabled. The functions
546 exported by the module will store the rest of addresses from the
547 destination set in XAPVs, and use these XAVPs to try next address if
548 the current-tried destination fails.
549
550 Default value is “0”.
551
552 Example 1.10. Set the “flags” parameter
553 ...
554 modparam("dispatcher", "flags", 3)
555 ...
556
557 3.11. use_default (int)
558
559 If the parameter is set to 1, the last address in destination set is
560 used as a final option to send the request to. For example, it is
561 useful when wanting to send the call to an announcement server saying:
562 "the gateways are full, try later".
563
564 Default value is “0”.
565
566 Example 1.11. Set the “use_default” parameter
567 ...
568 modparam("dispatcher", "use_default", 1)
569 ...
570
571 3.12. xavp_dst (str)
572
573 The name of the XAVP which will hold the list with addresses and
574 associated properties, in the order they have been selected by the
575 chosen algorithm. If use_default is 1, the values of last XAVP
576 correspond to the last address in destination set. In case of using
577 dispatcher.list file, you have to set the priority field for each
578 destination to ensure a particular order there. The first XAVP is the
579 current selected destination. All the other addresses from the
580 destination set will be added in the XAVP list to be able to implement
581 serial forking.
582
583 Note
584
585 You must set this parameter if you want to do load balancing fail over.
586
587 Default value is “_dsdst_”.
588
589 Example 1.12. Set the “xavp_dst” parameter
590 ...
591 modparam("dispatcher", "xavp_dst", "_dsdst_")
592 ...
593
594 3.13. xavp_dst_mode (int)
595
596 Control what fields are added to the XAVP specified by xavp_dst
597 parameter.
598
599 The addeded fields are:
600 * grp - the set id (group id).
601 * uri - the URI address.
602 * sock - the socket pointer.
603 * socket - the socket string - it is added only if xavp_dst_mode has
604 bit 2 set (value 2).
605 * sockname - the sockname string - it is added only if xavp_dst_mode
606 has bit 3 set (value 3).
607 * dstid - the destination unique id (in case of call load
608 distribution algorithm).
609 * attrs - the attributes - they are added if xavp_dst_mode does not
610 have the bit 1 set (value 1).
611
612 Default value is “0” (add grp, uri, sock, attr and optionally dstid
613 fields).
614
615 Example 1.13. Set the “xavp_dst_mode” parameter
616 ...
617 modparam("dispatcher", "xavp_dst_mode", 1)
618 ...
619 modparam("dispatcher", "xavp_dst_mode", 2)
620 ...
621
622 3.14. xavp_ctx (str)
623
624 The name of the XAVP which will hold some attributes specific to
625 dispatcher routing context. The XAVP can hold the next fields: cnt -
626 the number of addresses selected for routing.
627
628 Default value is “_dsctx_”.
629
630 Example 1.14. Set the “xavp_ctx” parameter
631 ...
632 modparam("dispatcher", "xavp_ctx", "_dsctx_")
633 ...
634
635 3.15. xavp_ctx_mode (int)
636
637 Control what fields are added to the XAVP specified by xavp_ctx
638 parameter. The cnt field is added if xavp_cnt_mode does not have the
639 bit 1 set.
640
641 Default value is “0” (add all fields).
642
643 Example 1.15. Set the “xavp_ctx_mode” parameter
644 ...
645 modparam("dispatcher", "xavp_ctx_mode", 1)
646 ...
647
648 3.16. hash_pvar (str)
649
650 String with PVs used for the hashing algorithm 7.
651
652 Note
653
654 You must set this parameter if you want do hashing over custom message
655 parts.
656
657 Default value is “null” - disabled.
658
659 Example 1.16. Use $avp(hash) for hashing:
660 ...
661 modparam("dispatcher", "hash_pvar", "$avp(hash)")
662 ...
663
664 Example 1.17. Use combination of PVs for hashing:
665 ...
666 modparam("dispatcher", "hash_pvar", "hash the $fU@$ci")
667 ...
668
669 3.17. setid_pvname (str)
670
671 The name of the PV where to store the set ID (group ID) when calling
672 ds_is_from_list() with no parameter.
673
674 Default value is “null” - don't set PV.
675
676 Example 1.18. Set the “setid_pvname” parameter
677 ...
678 modparam("dispatcher", "setid_pvname", "$var(setid)")
679 ...
680
681 3.18. attrs_pvname (str)
682
683 The name of the PV where to store the attributes of matching address
684 when calling ds_is_from_list().
685
686 Default value is “null” - don't set PV.
687
688 Example 1.19. Set the “attrs_pvname” parameter
689 ...
690 modparam("dispatcher", "attrs_pvname", "$var(attrs)")
691 ...
692
693 3.19. ds_ping_method (string)
694
695 With this method you can define, with which method you want to probe
696 the gateways. Pinging gateways feature depends on ds_ping_interval
697 parameter.
698
699 Default value is “OPTIONS”.
700
701 Example 1.20. Set the “ds_ping_method” parameter
702 ...
703 modparam("dispatcher", "ds_ping_method", "INFO")
704 ...
705
706 3.20. ds_ping_from (string)
707
708 With this Method you can define the "From:"-Line for the request, sent
709 to the failed gateways. This method is only available, if compiled with
710 the probing of failed gateways enabled.
711
712 Default value is “sip:dispatcher@localhost”.
713
714 Example 1.21. Set the “ds_ping_from” parameter
715 ...
716 modparam("dispatcher", "ds_ping_from", "sip:[email protected]")
717 ...
718
719 3.21. ds_ping_interval (int)
720
721 With this parameter you can define the interval for sending a request
722 to a gateway marked as inactive upon a failed request routing to it.
723 This parameter is only used, when the TM-Module is loaded. If set to
724 “0”, the pinging of inactive gateway is disabled.
725
726 Default value is “0”.
727
728 Example 1.22. Set the “ds_ping_interval” parameter
729 ...
730 modparam("dispatcher", "ds_ping_interval", 30)
731 ...
732
733 3.22. ds_ping_fr_timer (int)
734
735 If greater than 0, its value is used to set the "fr_timer" value for
736 the local transactions created to send out the OPTIONS pings.
737
738 Default value is “0” (not set).
739
740 Example 1.23. Set the “ds_ping_fr_timer” parameter
741 ...
742 modparam("dispatcher", "ds_ping_fr_timer", 10)
743 ...
744
745 3.23. ds_probing_threshold (int)
746
747 If you want to set a gateway into inactive mode, there can be a
748 specific number of failed requests until it will change from "active"
749 to "inactive". It is using the state "trying", that allows selection of
750 gateway but indicates there was a failure previously with the gateway.
751 The number of attempts can be set with this parameter. This parameter
752 can be modified via ser config framework.
753
754 Default value is “1” (set inactive with first failure).
755
756 Example 1.24. Set the “ds_probing_threshold” parameter
757 ...
758 modparam("dispatcher", "ds_probing_threshold", 10)
759 ...
760
761 3.24. ds_inactive_threshold (int)
762
763 If you want to set a gateway into active mode (after being inactive),
764 there can be a specific number of successful requests until it will
765 change from "inactive" to "active". The number of attempts can be set
766 with this parameter. This parameter can be modified via ser config
767 framework.
768
769 Default value is “1” (set active with first success).
770
771 Example 1.25. Set the “ds_inactive_threshold” parameter
772 ...
773 modparam("dispatcher", "ds_inactive_threshold", 10)
774 ...
775
776 3.25. ds_ping_reply_codes (string)
777
778 This parameter defines the valid response codes, which are accepted as
779 a valid reply to the PING-Method. It is a list separated by colons,
780 where you may define either a single code (e.g. "code=202" would accept
781 202 as an additional, valid response) or a class of responses, you want
782 to accept (e.g. "class=2" would accept everything from 200 to 299 as
783 valid response). This parameter can be modified via config framework.
784
785 Please note that the response codes the module accepts as valid reply
786 to the PING-Method are not only the ones generated from the remote
787 servers, but also those that are generated locally. E.g.: setting
788 code=408 or class=400 will never set a backend down even if it is,
789 because internally the Kamailio transaction layer generates a 408 in
790 the case of no response from the remote server, and this internal code
791 408 is accepted as valid value.
792
793 Default value is “” (only 200 OK is accepted).
794
795 Example 1.26. Set the “ds_ping_reply_codes” parameter
796 ...
797 modparam("dispatcher", "ds_ping_reply_codes", "class=2;code=403;code=488;class=3
798 ")
799 ...
800
801 3.26. ds_probing_mode (int)
802
803 Controls what gateways are tested to see if they are reachable.
804 * Value 0: If set to 0, only the gateways with state PROBING are
805 tested. After a gateway is probed, the PROBING state is cleared in
806 this mode. This means that no probing will be executed at all only
807 if flag in config file is set to 8/PROBING (please check
808 destination list file syntaxis for more details), it will probe
809 only one time at startup or after dispatcher reload.
810 * Value 1: If set to 1, all gateways are tested. If set to 1 and
811 there is a failure of keepalive to an active gateway, then it is
812 set to TRYING state. This means that probing will be executed all
813 the time, but you can skip some servers with flag 4 in destination
814 list file, for example.
815 * Value 2: if set to 2, only gateways in INACTIVE state with PROBING
816 mode set are tested.
817 * Value 3: If set to 3, any gateway with state PROBING is continually
818 probed without modifying/removing the PROBING state. This allows
819 selected gateways to be probed continually, regardless of state
820 changes.
821
822 Default value is “0”.
823
824 Example 1.27. Set the “ds_probing_mode” parameter
825 ...
826 modparam("dispatcher", "ds_probing_mode", 1)
827 ...
828
829 3.27. ds_ping_latency_stats (int)
830
831 Enable latency measurement when pinging nodes The estimator can be
832 initialized at startup and reload using the attribute latency.
833 * If set to 0, disable latency measurement.
834 * If set to 1, enable latency measurement.
835
836 Default value is “0”.
837
838 Example 1.28. accessing the metrics
839 # using the command :
840 kamctl rpc dispatcher.list
841 ...
842 DEST: {
843 URI: sip:1.2.3.4
844 FLAGS: AX
845 PRIORITY: 9
846 ATTRS: {
847 BODY: latency=24
848 }
849 LATENCY: {
850 AVG: 24.250000 # weighted moving average for the last few weeks
851 STD: 1.035000 # standard deviation of AVG
852 EST: 25.000000 # short term estimate, see parameter: ds_latency_
853 estimator_alpha
854 MAX: 26 # maximum value seen
855 TIMEOUT: 0 # count of ping timeouts
856 }
857 }
858 ...
859
860 Example 1.29. Set the “ds_ping_latency_stats” parameter
861 ...
862 modparam("dispatcher", "ds_ping_latency_stats", 1)
863 ...
864
865 3.28. ds_retain_latency_stats (int)
866
867 Retain latency stats for existing destinations when reloading from file
868 or database.
869 * If set to 0, stats for all destinations will be reset on reload.
870 * If set to 1, stats for existing destinations will persist across
871 reloads.
872
873 Default value is “0”.
874
875 Example 1.30. Set the “ds_retain_latency_stats” parameter
876 ...
877 modparam("dispatcher", "ds_retain_latency_stats", 1)
878 ...
879
880 3.29. ds_latency_estimator_alpha (int)
881
882 The parameter decides how important each latency ping observation is in
883 the calculation of the EWMA. The higher the value of alpha, the more
884 closely the EWMA tracks the original time series. Because Kamailio
885 doesn't support float parameter types, the value in the parameter is
886 divided by 1000 and stored as float. For example, if you want to set
887 the alpha to be 0.25, use value 250 here.
888
889 Default value is “100 => 0.1”.
890
891 Example 1.31. Set the “ds_latency_estimator_alpha” parameter
892 ...
893 modparam("dispatcher", "ds_latency_estimator_alpha", 900)
894 ...
895
896 3.30. ds_hash_size (int)
897
898 The value to be used as power of two to set the number of slots to hash
899 table storing data for call load dispatching (e.g., value 8 will create
900 a hash table with 256 slots). It must be greater than 0 to enable call
901 load dispatching feature (alg 10).
902
903 Default value is “0”.
904
905 Example 1.32. Set the “ds_hash_size” parameter
906 ...
907 modparam("dispatcher", "ds_hash_size", 9)
908 ...
909
910 3.31. ds_hash_expire (int)
911
912 Expiration time in seconds to remove the load on a destination if no
913 BYE was received meanwhile.
914
915 Default value is “7200”.
916
917 Example 1.33. Set the “ds_hash_expire” parameter
918 ...
919 modparam("dispatcher", "ds_hash_expire", 3600)
920 ...
921
922 3.32. ds_hash_initexpire (int)
923
924 Expiration time in seconds to remove the load on a destination if no
925 200 for INVITE was received meanwhile and state updated with
926 ds_load_update().
927
928 Default value is “7200”.
929
930 Example 1.34. Set the “ds_hash_initexpire” parameter
931 ...
932 modparam("dispatcher", "ds_hash_initexpire", 60)
933 ...
934
935 3.33. ds_hash_check_interval (int)
936
937 Time interval in seconds to scan internal hash table with call load
938 dispatching data for expired items.
939
940 Default value is “30”.
941
942 Example 1.35. Set the “ds_hash_check_interval” parameter
943 ...
944 modparam("dispatcher", "ds_hash_check_interval", 60)
945 ...
946
947 3.34. outbound_proxy (str)
948
949 SIP URI of outbound proxy to be used when sending pings.
950
951 By default no outbound proxy is defined.
952
953 Example 1.36. Set the “outbound_proxy” parameter
954 ...
955 modparam("dispatcher", "outbound_proxy", "sip:outbound.example.com")
956 ...
957
958 3.35. ds_default_socket (str)
959
960 Default socket to be used for sending pings and dispatching requests
961 when a gateway has no send socket configured.
962
963 By default no default socket is defined, the first configuration script
964 listen directive is used.
965
966 If parameter "ds_default_sockname" is set, then this parameter is
967 ignored.
968
969 Example 1.37. Set the “ds_default_socket” parameter
970 ...
971 modparam("dispatcher", "ds_default_socket", "udp:192.168.0.125:5060")
972 ...
973
974 3.36. ds_default_sockname (str)
975
976 Default socket name to be used for sending pings and dispatching
977 requests when a gateway has no send socket configured.
978
979 By default no default socket is defined, the first configuration script
980 listen directive is used.
981
982 This parameter is used even if "ds_default_socket" parameter is set
983 (this parameter has higher priority).
984
985 Example 1.38. Set the “ds_default_sockname” parameter
986 ...
987 listen=udp:1.2.3.4:5060 name "sock1"
988 ...
989 modparam("dispatcher", "ds_default_sockname", "sock1")
990 ...
991
992 3.37. ds_ping_socket (str)
993
994 Default socket to be used for sending ping requests when a gateway has
995 no "ping_socket" configured.
996
997 Example 1.39. Set the “ds_ping_socket” parameter
998 ...
999 modparam("dispatcher", "ds_ping_socket", "udp:192.168.0.125:5060")
1000 ...
1001
1002 3.38. ds_timer_mode (int)
1003
1004 Specify the timer process to be used by the module for keepalives and
1005 active dialogs tracking.
1006
1007 It can be set to:
1008 * 0 - use main timer process.
1009 * 1 - use secondary timer process.
1010
1011 On a server with a lot of traffic, using secondary timer can help with
1012 performances, because the main timer can be overloaded by taking care
1013 of transactions retransmissions and expirations of items in memory.
1014
1015 Default value is “0”.
1016
1017 Example 1.40. Set the “ds_timer_mode” parameter
1018 ...
1019 modparam("dispatcher", "ds_timer_mode", 1)
1020 ...
1021
1022 3.39. event_callback (str)
1023
1024 The name of the function in the kemi configuration file (embedded
1025 scripting language such as Lua, Python, ...) to be executed instead of
1026 event_route[...] blocks.
1027
1028 The function receives a string parameter with the name of the event,
1029 the values are: 'dispatcher:dst-down', 'dispatcher:dst-up'.
1030
1031 Default value is 'empty' (no function is executed for events).
1032
1033 Example 1.41. Set event_callback parameter
1034 ...
1035 modparam("dispatcher", "event_callback", "ksr_dispatcher_event")
1036 ...
1037 -- event callback function implemented in Lua
1038 function ksr_dispatcher_event(evname)
1039 KSR.info("===== dispatcher module triggered event: " .. evname .. "\n");
1040 return 1;
1041 end
1042 ...
1043
1044 3.40. event_callback_mode (int)
1045
1046 Controls when the event_route or the KEMI event callback function are
1047 executed. If set to 0, they are executed when the destination state
1048 changes based on OPTIONS keepalives or the use of config functions to
1049 set the state (e.g., ds_mark_dst(...)). If set to 1, they are executed
1050 only on state change due to OPTIONS keepalives. If set to 2, the event
1051 routes will always be executed when a state change occurs, even if no
1052 previous state exists (for example, on startup or reload).
1053
1054 Note that event routes are not executed on RPC commands setting the
1055 destination state.
1056
1057 Default value is '0'.
1058
1059 Example 1.42. Set event_callback_mode parameter
1060 ...
1061 modparam("dispatcher", "event_callback_mode", 1)
1062 ...
1063 -- event callback function implemented in Lua
1064 function ksr_dispatcher_event(evname)
1065 KSR.info("===== dispatcher module triggered event: " .. evname .. "\n");
1066 return 1;
1067 end
1068 ...
1069
1070 3.41. ds_attrs_none (int)
1071
1072 If set to 1, "none=yes" is set in the attrs for those records that have
1073 no attrs value, to ensure that corresponding XAVP fields for records do
1074 not get mixed up.
1075
1076 Default value is “0”.
1077
1078 Example 1.43. Set the “ds_attrs_none” parameter
1079 ...
1080 modparam("dispatcher", "ds_attrs_none", 1)
1081 ...
1082
1083 3.42. ds_db_extra_attrs (str)
1084
1085 Set a list of column names to be loaded from database dispatcher table
1086 and be concatenated to 'attrs' field. The format is:
1087 'aname1=cname1;aname2=cname2;...;anameN=cnameN'.
1088
1089 The 'anameX' is the attribute name and 'cnameX' is column name. The
1090 additional columns must be added to database dispatcher table and their
1091 type must be a string type (VARCHAR, etc..) or integer type (UNSIGNED
1092 INT, BIGINT, etc..). These fields can be a convenient way of loading
1093 IDs, or additional related info into the 'attrs' XAVP when matching a
1094 dispatcher set.
1095
1096 Default value is “empty”.
1097
1098 Example 1.44. Set the “ds_db_extra_attrs” parameter
1099 ...
1100 modparam("dispatcher", "ds_db_extra_attrs", "socket=socket;pref=prefix")
1101 ...
1102
1103 3.43. ds_load_mode (int)
1104
1105 If set to 1, the module throws error when failing to add a destination
1106 address (e.g., invalid URI). If set to 0, it skips the failing address
1107 and continues with the next ones.
1108
1109 Default value is “0”.
1110
1111 Example 1.45. Set the “ds_load_mode” parameter
1112 ...
1113 modparam("dispatcher", "ds_load_mode", 1)
1114 ...
1115
1116 3.44. reload_delta (int)
1117
1118 The number of seconds that have to be waited before executing a new
1119 reload of dispatcher records. By default there is a rate limiting of
1120 maximum one reload in five seconds.
1121
1122 If set to 0, no rate limit is configured. Note carefully: use this
1123 configuration only in tests environments because executing many RPC
1124 reload commands at the same time can cause unexpected behavior.
1125
1126 Default value is “5”.
1127
1128 Example 1.46. Set reload_delta parameter
1129 ...
1130 modparam("dispatcher", "reload_delta", 1)
1131 ...
1132
1133 3.45. ds_dns_mode (int)
1134
1135 Specify the how DNS resolving is done for destination addresses.
1136
1137 It is a bitwise flag and can be set to one or the sum of:
1138 * 1 - do it at startup and reload (previous behaviour).
1139 * 2 - do it always when the address is matched with
1140 ds_is_from_list().
1141 * 4 - do it startup/reload and refresh on the timer interval
1142 specified by ds_dns_interval.
1143 * 8 - do SRV (and NAPTR if enabled in core) query instead of A/AAAA
1144 lookup. NAPTR is done if protocol and port are not set. SRV is done
1145 if port is not set.
1146
1147 Default value is “1”.
1148
1149 Example 1.47. Set the “ds_dns_mode” parameter
1150 ...
1151 modparam("dispatcher", "ds_dns_mode", 2)
1152 ...
1153
1154 3.46. ds_dns_interval (int)
1155
1156 The interval in seconds to periodically refresh the DNS queries for
1157 destination addresses if ds_dns_mode has value 4 set.
1158
1159 Default value is “600”.
1160
1161 Example 1.48. Set the “ds_dns_interval” parameter
1162 ...
1163 modparam("dispatcher", "ds_interval_mode", 1800)
1164 ...
1165
1166 3.47. ds_dns_ttl (int)
1167
1168 The interval in seconds to set TTL for DNS results received for queries
1169 dones inside this module. If 0, this TTL is not set, result and core
1170 values are used.
1171
1172 Default value is “0”.
1173
1174 Example 1.49. Set the “ds_dns_ttl” parameter
1175 ...
1176 modparam("dispatcher", "ds_interval_mode", 7200)
1177 ...
1178
1179 4. Functions
1180
1181 4.1. ds_select_dst(set, alg[, limit])
1182 4.2. ds_select_domain(set, alg[, limit])
1183 4.3. ds_select(set, alg [, limit])
1184 4.4. ds_select_routes(rules, mode [, limit])
1185 4.5. ds_next_dst()
1186 4.6. ds_next_domain()
1187 4.7. ds_set_dst()
1188 4.8. ds_set_domain()
1189 4.9. ds_mark_dst([state])
1190 4.10. ds_mark_addr(state, setid, uri)
1191 4.11. ds_list_exists(groupid)
1192 4.12. ds_is_from_list([groupid [, mode [, uri] ] ])
1193 4.13. ds_is_active(groupid [, uri])
1194 4.14. ds_load_update()
1195 4.15. ds_load_unset()
1196 4.16. ds_reload()
1197 4.17. ds_dsg_fetch(setid)
1198 4.18. ds_dsg_fetch_uri(setid, uri)
1199 4.19. ds_oc_set_attrs(setid, uri, rval, tval, sval)
1200
1201 4.1. ds_select_dst(set, alg[, limit])
1202
1203 The method selects a destination from addresses set. It returns true if
1204 a new destination is set. The selected address is set to dst_uri field
1205 (aka the outbound proxy address or the $du variable), not being visible
1206 in the SIP request.
1207
1208 If the bit 2 in 'flags' parameter is set, the rest of the addresses
1209 from the destination set are stored in XAVP list (limited with an
1210 optional 'limit' parameter). You can use 'ds_next_dst()' to use next
1211 address in order to achieve serial forking to all possible
1212 destinations.
1213
1214 Meaning of the parameters is as follows:
1215 * set - the id of the set from where to pick up destination address.
1216 It is the first column in destination list file. The parameter can
1217 be an integer or a variable holding an integer.
1218 * alg - the algorithm used to select the destination address. The
1219 parameter can be an integer or a variable holding an integer.
1220 + “0” - hash over callid
1221 + “1” - hash over from URI.
1222 + “2” - hash over to URI.
1223 + “3” - hash over request-URI user.
1224 + “4” - round-robin (next destination).
1225 + “5” - hash over authorization-username (Proxy-Authorization or
1226 "normal" authorization). If no username is found, round robin
1227 is used.
1228 + “6” - random destination (using rand()).
1229 + “7” - hash over the content of PVs string. Note: This works
1230 only when the parameter hash_pvar is set.
1231 + “8” - select destination sorted by priority attribute value
1232 (serial forking ordered by priority).
1233 + “9” - use weight based load distribution. You have to set the
1234 attribute 'weight' for each address (gateway) in destination
1235 set. See also the description of the 'weight' attribute in the
1236 'Special Attributes' section.
1237 + “10” - use call load distribution. You have to set the
1238 attribute 'duid' (as an unique string id) per each address in
1239 destination set. Also, you must set the parameter
1240 'ds_hash_size'.
1241 The algorithm can be used even with stateless proxy mode,
1242 there is no SIP dialog tracking depending on other modules,
1243 just an internal lightweight call tracking by Call-Id, thus is
1244 fast and suitable even for embedded systems.
1245 The first destination selected by this algorithm is the one
1246 that has the least number of calls associated. The rest of the
1247 destination list is taken in order of the entries in set -
1248 anyhow, until a re-route to next destination happens, the load
1249 on each address can change.
1250 This algorithm can be used only for dispatching INVITE
1251 requests as it is the only SIP method creating a SIP call.
1252 + “11” - use relative weight based load distribution. You have
1253 to set the attribute 'rweight' per each address in destination
1254 set. Active host usage probability is rweight/(SUM of all
1255 active host rweights in destination group).
1256 The major difference from the weight distribution is the
1257 probability recalculation according to rweight value in case
1258 of destinations being active or inactive.
1259 For example, 100 calls in 3-destinations group with rweight
1260 params 1/2/1 will be distributed as 25/50/25. If the third
1261 destination becomes inactive, the distribution is changed to
1262 33/67/0. If the computation of percentage per destination is
1263 not an exact integer number, the value is trucated and the
1264 last destination is used to fill the remaining percentage till
1265 100.
1266 Using this algorithm, you can also enable congestion control
1267 by setting the attribute 'cc=1', when 'cc' is enabled the
1268 'weight' attribute will also be used to control congestion
1269 tolerance. When facing congestion the weight of a gateway is
1270 lowered by 1 for every ms of estimated congestion, a 'rweight'
1271 value of 50 is recommended. See the example "configuring load
1272 balancing with congestion detection" below.
1273 The congestion estimation is done using an Exponentially
1274 Weighted Moving Average (EWMA). More information about the
1275 algorithm can be found at
1276 http://www.itl.nist.gov/div898/handbook/pmc/section3/pmc324.ht
1277 m. If all the gateways in a set are above their congestion
1278 threshold(weight), the load distribution is instead done using
1279 the ratio of estimated congestion ms.
1280 See also the description of the 'rweight' attribute in the
1281 'Special Attributes' section.
1282 + “12” - dispatch to all destinations in setid at once (parallel
1283 forking). Note that the XAVPs are no longer set with the
1284 values of the destination records, no re-routing making sense
1285 in this case. A side effect is that marking the one
1286 destination as inactive is not possible if the transaction
1287 fails (which means that all branches failed, or in other
1288 words, all the destinations were not answering the call).
1289 + “13” - latency optimized dispatching
1290 - The algorithm will load balance using round-robin
1291 prioritizing the gateways with the highest priority.
1292 - If ds_ping_latency_stats is active the algorithm will adjust
1293 the priority of the gateway automatically, the priority will
1294 be lowered by 1 point every time the latency ms is as high as
1295 the priority.
1296 - If the attribute 'cc=1' is set, the latency used is
1297 congestion ms : estimate (current latency ms) - average
1298 (normal condition latency ms).
1299 Example 1.50. latency_optimized_dispatching usage
1300 Using this simple formula :
1301 ADJUSTED_PRIORITY = PRIORITY - (ESTIMATED_LATENCY_MS/PRIORITY)
1302
1303 GATEWAY | PRIORITY | ESTIMATED | ADJUSTED | LOAD
1304 # | | LATENCY | PRIORITY | DISTRIBUTION
1305 1 | 30 | 21 | 30 | 33%
1306 2 | 30 | 91 | 27 | 0%
1307 3 | 30 | 61 | 28 | 0%
1308 4 | 30 | 19 | 30 | 33%
1309 5 | 30 | 32 | 29 | 0%
1310 6 | 30 | 0 | 30 | 33%
1311 7 | 30 | 201 | 24 | 0%
1312
1313
1314 With congestion control the formula becomes :
1315 CONGESTION_MS = CURRENT_LATENCY_MS - NORMAL_CONDITION_LATENCY_MS
1316 ADJUSTED_PRIORITY = PRIORITY - (CONGESTION_MS/PRIORITY)
1317 + “64” - round-robin (next destination) with over load control
1318 (destination record is skipped based on over load control
1319 rate).
1320 + “14” - round-robin (4) if all the destinations in the group
1321 have the same priority and the priority is greater than 0,
1322 otherise serial dispatching (8).
1323 + “X” - if the algorithm is not implemented, the first entry in
1324 set is chosen.
1325 * limit - the maximum number of items to be stored in XAVP list for
1326 further fail-overs (the first selected destination and default
1327 destination are the first to be put in the list). This can improve
1328 the performance especially if you are using a large list of
1329 gateways.
1330
1331 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1332
1333 Example 1.51. ds_select_dst usage
1334 ...
1335 ds_select_dst("1", "0");
1336 ...
1337 $var(a) = 4;
1338 ds_select_dst("1", "$var(a)");
1339 ...
1340 ds_select_dst("1", "4", "3");
1341 ...
1342
1343 Example 1.52. configuring load balancing with congestion detection
1344 ...
1345 # sample of SQL provisioning statements
1346 INSERT INTO "dispatcher"
1347 VALUES(1,1,'sip:192.168.0.1:5060',0,12,'rweight=50;weight=50;cc=1;','');
1348 INSERT INTO "dispatcher"
1349 VALUES(2,1,'sip:192.168.0.2:5060',0,12,'rweight=50;weight=50;cc=1;','');
1350 ...
1351 modparam("dispatcher", "ds_ping_interval", 1) # ping gateways once/second
1352 modparam("dispatcher", "ds_ping_latency_stats", 1) # update congestion metrics
1353 # configure the latency estimator
1354 modparam("dispatcher", "ds_latency_estimator_alpha", 900)
1355 ...
1356 if (!ds_select_dst("1", "11")) { # use relative weight based load distribution
1357 ...
1358 # sample of output from 'kamctl rpc dispatcher.list'
1359 DEST: {
1360 URI: sip:192.168.0.1:5060
1361 FLAGS: AP
1362 PRIORITY: 12
1363 ATTRS: {
1364 BODY: rweight=50;weight=50;cc=1 # configuration values
1365 DUID:
1366 MAXLOAD: 0
1367 WEIGHT: 50
1368 RWEIGHT: 50
1369 SOCKET:
1370 SOCKNAME:
1371 OBPROXY:
1372 }
1373 LATENCY: {
1374 AVG: 20.104000
1375 STD: 1.273000
1376 # estimated congestion is currently 25ms = 45ms(EST) -20ms(AVG)
1377 EST: 45.005000
1378 MAX: 132
1379 TIMEOUT: 3
1380 }
1381 }
1382 ...
1383
1384 4.2. ds_select_domain(set, alg[, limit])
1385
1386 The method selects a destination from addresses set and rewrites the
1387 host and port from R-URI. The parameters have same meaning as for
1388 ds_select_dst().
1389
1390 If the bit 2 in 'flags' is set, the rest of the addresses from the
1391 destination set are stored in XAVP list (limited with an optional
1392 'limit' parameter). You can use 'ds_next_domain()' to use next address
1393 to achieve serial forking to all possible destinations.
1394
1395 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1396
1397 Example 1.53. ds_select_domain usage
1398 ...
1399 $var(a) = 4;
1400 if(ds_select_domain("1", "$var(a)")) {
1401 t_relay();
1402 exit;
1403 }
1404 ...
1405
1406 4.3. ds_select(set, alg [, limit])
1407
1408 The method selects a destination from addresses set and adds it in the
1409 XAVP specified for this module. It is not updating R-URI nor the
1410 destination URI. The parameters have same meaning as for
1411 ds_select_dst().
1412
1413 If the bit 2 in 'flags' is set, the rest of the addresses from the
1414 destination set are stored in XAVP list (limited with an optional
1415 'limit' parameter). You can execute 'ds_next_domain()' or
1416 'ds_next_dst()' to use next address to achieve serial forking to all
1417 possible destinations.
1418
1419 This function can be used from ANY_ROUTE.
1420
1421 Example 1.54. ds_select usage
1422 ...
1423 $var(a) = 4;
1424 if(ds_select("1", "$var(a)")) {
1425 ds_next_domain();
1426 t_relay();
1427 exit;
1428 }
1429 ...
1430
1431 4.4. ds_select_routes(rules, mode [, limit])
1432
1433 The method selects destinations following the rules combining groups
1434 add algorithms, controlling where the first destination address is
1435 pushed, and optionally setting a limit of selected addresses.
1436
1437 Parameters:
1438 * rules - a string in the format "grp1=alg1;grp2=alg2;...grpN=algN",
1439 where grpX is an integer number identifying a dispatcher set id and
1440 algN is a dispatcher algorithm identifier. No white spaces should
1441 be given in the parameter value. The parameter can contain
1442 pseudo-variables.
1443 * mode - control where to push the first selected target address.
1444 Valid values are: '0', 'd' or 'D' to push the address in
1445 destination URI; '1', 'r' or 'R' to push the address in R-URI; '2',
1446 'x' or 'X' to push the address only in the XAVP when failure
1447 rerouting is enabled. Note that only first character of the
1448 parameter matters, therefore one can use a more meaningful value
1449 such as 'ruri' instead of 'r'. The parameter can contain pseudo
1450 variables.
1451 * limit - a positive integer value to restrict the number of selected
1452 target addresses. If it is 0, then no limit is considered. The
1453 parameter can be a static integer or a variable holding an integer
1454 value.
1455
1456 If the bit 2 in 'flags' is set, the rest of the addresses from the
1457 destination groups are stored in XAVP list (limited with an optional
1458 'limit' parameter). You can execute 'ds_next_domain()' or
1459 'ds_next_dst()' to use next address to achieve serial forking to all
1460 possible destinations.
1461
1462 This function can be used from ANY_ROUTE.
1463
1464 Example 1.55. ds_select_routes usage
1465 ...
1466 $var(alg) = 4;
1467 $var(limit) = 8;
1468 if(ds_select_routes("1=4;2=$var(alg)", "ruri", "$var(limit)")) {
1469 t_on_failure("REROUTE");
1470 t_relay();
1471 exit;
1472 }
1473 failure_route[REROUTE] {
1474 if(t_check_status("408|5[0-9][0-9]")) {
1475 if(ds_next_domain()) {
1476 t_on_failure("REROUTE");
1477 t_relay();
1478 exit;
1479 }
1480 }
1481 }
1482 ...
1483
1484 4.5. ds_next_dst()
1485
1486 Takes the next destination address from the corresponding XAVPs and
1487 sets the dst_uri (outbound proxy address).
1488
1489 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1490
1491 4.6. ds_next_domain()
1492
1493 Takes the next destination address from the corresponding XAVPs and
1494 sets the domain part of the request URI.
1495
1496 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1497
1498 4.7. ds_set_dst()
1499
1500 Takes the current destination address from the corresponding XAVPs and
1501 sets the dst_uri (outbound proxy address).
1502
1503 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1504
1505 4.8. ds_set_domain()
1506
1507 Takes the current destination address from the corresponding XAVPs and
1508 sets the domain part of the request URI.
1509
1510 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1511
1512 4.9. ds_mark_dst([state])
1513
1514 Mark the last used address from destination set as inactive ("i"/"I"),
1515 active ("a"/"A"), disabled ("d"/"D") or trying ("t"/"T"). Apart of
1516 disabled state, a destination can be set in probing mode by adding
1517 ("p"/"P") flag. With this function, an automatic detection of failed
1518 gateways can be implemented. When an address is marked as inactive or
1519 disabled, it will be ignored by 'ds_select_dst' and 'ds_select_domain'.
1520
1521 The parameter state is optional, when it is missing, then the
1522 destination will be marked inactive (i.e., same as 'i').
1523
1524 Possible values for state parameter:
1525 * "a" or "A" - the last destination should be set to active and the
1526 error-counter should set to "0".
1527 * "i" or "I" - the last destination should be set to inactive and
1528 will be ignored in future requests.
1529 * "t" or "T" - the last destination should be set to temporary trying
1530 state and failure counter is incremented. When the failure counter
1531 reaches the threshold, the destination will be set inactive.
1532 * "p" and "P" - this has to be used in addition to one of the
1533 previous flags - the last destination will be set to probing. This
1534 mean the destination will be pinged with SIP OPTIONS requests from
1535 time to time to detect if it is up or down.
1536
1537 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
1538
1539 Example 1.56. ds_mark_dst usage
1540 ...
1541 failure_route[tryagain] {
1542 ...
1543 if(t_check_status("500"))
1544 ds_mark_dst("ip"); # set to inactive and probing
1545 ...
1546 }
1547 ...
1548
1549 4.10. ds_mark_addr(state, setid, uri)
1550
1551 Set the state to the target specified by setid and uri. The parameter
1552 state can have same value as for ds_mark_dst(). All parameters can
1553 contain variables.
1554
1555 This function can be used from ANY_ROUTE.
1556
1557 Example 1.57. ds_mark_addr usage
1558 ...
1559 ds_mark_addr("ip", "1", "sip:127.0.0.1:5080"); # set to inactive and probing
1560 ...
1561
1562 4.11. ds_list_exists(groupid)
1563
1564 Function alias: ds_list_exist(groupid)
1565
1566 Check if a specific group is defined in dispatcher list or database.
1567 * groupid - A group ID to check.
1568
1569 It returns true (value 1) if the group exists, or otherwise false (-1
1570 when the group is not found; -2 when evaluating the parameter fails).
1571
1572 This function can be used from ANY_ROUTE.
1573
1574 Example 1.58. ds_list_exists usage
1575 ...
1576 if(ds_list_exists("10")) {
1577 ...
1578 }
1579 ...
1580
1581 4.12. ds_is_from_list([groupid [, mode [, uri] ] ])
1582
1583 This function returns true, if there is a match of source address or
1584 uri with an address in the given group of the dispatcher-list;
1585 otherwise false.
1586
1587 Description of parameters:
1588 * groupid (optional) - if not given or its value is -1, the matching
1589 will be done over all addresses in all dispatcher groups. Otherwise
1590 the matching will be done only against the addresses in the
1591 specific group id. The parameter can be an integer or a variable
1592 holding an integer value.
1593 * mode - (optional) - a bitmask to specify how the matching should be
1594 done. If the parameter is missing, the matching is done with
1595 ignoring the protocol (value 2). If parameter is 0, all ip, port
1596 and proto are matched and active status is ignored. If bit one is
1597 set, then port is ignored. If bit two is set, then protocol is
1598 ignored. If bit three is set, then state must be active. If bit
1599 four is set, then socket/sockname be matched. If bit five is set,
1600 then try to find the most closest target from all dispatcher
1601 targets with the mandatory ip and combination of local socket,
1602 protocol, port, the weighted search result is combined from bit
1603 flags of matched components: ip - 1, port - 2, protocol - 4, local
1604 socket - 8, the target with the maximum value of flags combination
1605 will be selected. The parameter can be an integer or a variable
1606 holding an integer value. It must be provided if the uri parameter
1607 is provided.
1608 * uri (optional) - if parameter is empty or missing, the matching is
1609 done against source IP, port and protocol. Otherwise the value has
1610 to be a valid SIP URI, used to match against addresses in the
1611 dispatcher list. Only IP, port and protocol are matches, any
1612 additional parameters are ignored. The parameter can be a static or
1613 dynamic (with variables) string. The domain part of the URI can be
1614 an IP address or a hostname.
1615
1616 Upon a match, the variable specified by 'setid_pvname' parameter will
1617 be set to groupid of matching address and the attributes will be set in
1618 variable specified by 'attrs_pvname'.
1619
1620 Note
1621
1622 Note on default transport (RFC 3263 See 4.1 Selecting a Transport
1623 Protocol): The dispatcher module normalizes the transport protocol of
1624 destination URIs according to RFC 3263 default transport rules. When a
1625 destination in the dispatcher list does not contain an explicit
1626 ;transport= URI parameter, the module derives and sets the transport
1627 based on the SIP URI scheme and RFC 3263 resolution procedures (in
1628 short, UDP for 'sip:' and TCP for 'sips:').
1629
1630 Note that for backward compatibility mode, when no parameter is given
1631 or only groupid is given, the matching is done only for IP address and
1632 port (protocol is ignored).
1633
1634 This function can be used from ANY_ROUTE.
1635
1636 Example 1.59. ds_is_from_list usage
1637 ...
1638 if(ds_is_from_list()) {
1639 ...
1640 }
1641 if(ds_is_from_list("10")) {
1642 ...
1643 }
1644 if(ds_is_from_list("10", "3")) {
1645 ...
1646 }
1647 if(ds_is_from_list("10", "3", "sip:127.0.0.1:5080")) {
1648 ...
1649 }
1650 ...
1651
1652 4.13. ds_is_active(groupid [, uri])
1653
1654 This function returns true, if there is an active URI in the
1655 destination group; otherwise false. If the uri parameter is provided,
1656 then the corresponding destination has to be active.
1657
1658 Description of parameters:
1659 * groupid - the group id. The parameter can be an integer or a
1660 variable holding an integer value.
1661 * uri (optional) - the URI of the destination. if parameter is empty
1662 or missing, the any destination is matched.
1663
1664 This function can be used from ANY_ROUTE.
1665
1666 Example 1.60. ds_is_active usage
1667 ...
1668 if(ds_is_active("10")) {
1669 ...
1670 }
1671 if(ds_is_active("10", "sip:127.0.0.1:5080")) {
1672 ...
1673 }
1674 ...
1675
1676 4.14. ds_load_update()
1677
1678 Updates the load state:
1679 * if it is a BYE or CANCEL - remove the load from destination address
1680 used to forward the INVITE
1681 * if it is a reply to INVITE - set internal state to confirmed for
1682 call load structure when reply code is 2xx.
1683
1684 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
1685 BRANCH_ROUTE and ONREPLY_ROUTE.
1686
1687 4.15. ds_load_unset()
1688
1689 Remove the call load for the destination that routed the call.
1690
1691 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
1692 BRANCH_ROUTE and ONREPLY_ROUTE.
1693
1694 Example 1.61. ds_load_unset usage
1695 ...
1696 route {
1697 ...
1698 if(is_method("BYE|CANCEL"))
1699 ds_load_update();
1700 ...
1701 ds_select_dst("1", "10");
1702 ...
1703 }
1704
1705 onreply_route {
1706 ...
1707 if(is_method("INVITE")
1708 {
1709 if(status=~"2[0-9][0-9]")
1710 ds_load_update();
1711 else if(status=~"[3-7][0-9][0-9]")
1712 ds_load_unset();
1713 }
1714 ...
1715 }
1716 ...
1717
1718 4.16. ds_reload()
1719
1720 Reloads the groups and included destinations.
1721
1722 Name: ds_reload
1723
1724 Parameters: none
1725
1726 This function can be used from ANY_ROUTE.
1727
1728 Example 1.62. ds_reload usage
1729 ...
1730 ds_reload();
1731 ...
1732
1733 4.17. ds_dsg_fetch(setid)
1734
1735 Sets the destination group id to setid for fetching $dsg(key)
1736 attributes.
1737
1738 Parameters: setid - integer or variable holding the set id value
1739
1740 This function can be used from ANY_ROUTE.
1741
1742 Example 1.63. ds_dsg_fetch() usage
1743 ...
1744 ds_dsg_fetch("1");
1745 xinfo("set id: 1 - all: $dsg(count); active: $dsg(active)\n");
1746 ...
1747
1748 4.18. ds_dsg_fetch_uri(setid, uri)
1749
1750 Sets the destination group id to setid for fetching $dsg(key)
1751 attributes and the overload-control attributes to the corresponding uri
1752 record from that group.
1753
1754 Parameters: setid - integer or variable holding the set id value; uri -
1755 string or variables holding the SIP URI value.
1756
1757 This function can be used from ANY_ROUTE.
1758
1759 Example 1.64. ds_dsg_fetch_uri() usage
1760 ...
1761 ds_dsg_fetch_uri("1", "sip:127.0.0.1:5080");
1762 xinfo("set id: 1 - all: $dsg(count); active: $dsg(active); $dsg(ocrate)\n");
1763 ...
1764
1765 4.19. ds_oc_set_attrs(setid, uri, rval, tval, sval)
1766
1767 Sets the overload control rate, time interval limit and sequence number
1768 for the destination record (setid, uri) following RFC7339
1769 specifications.
1770
1771 Description of parameters:
1772 * setid - the set (group) id. The parameter can be an integer or a
1773 variable holding an integer value.
1774 * uri - the URI of the destination.
1775 * rval - the value of the overload control rate (from 1 to 100) - how
1776 many times to skip using this destination in 100 selections.
1777 * tval - time interval limit to apply the overload control rate (in
1778 milliseconds). If the value is 0 or negative, then the default
1779 value 500 is used.
1780 * sval - the sequence number for overload control.
1781
1782 The parameters can include variables.
1783
1784 The returns 1 (cfg-true) when the oc attrbutes are udpated for a
1785 destination record; -1 (cfg-false) when there is an internal error; -2
1786 (cfg-false) when no destination is updated (e.g., not found or the
1787 ocseq condition fails).
1788
1789 This function can be used from ANY_ROUTE.
1790
1791 Example 1.65. ds_oc_set_attrs() usage
1792 ...
1793 ds_oc_set_attrs("1", "sip:127.0.0.1:5080", "30", "180000", "1");
1794 ...
1795
1796 5. RPC Commands
1797
1798 5.1. dispatcher.set_state
1799 5.2. dispatcher.set_duid_state
1800 5.3. dispatcher.list
1801 5.4. dispatcher.reload
1802 5.5. dispatcher.ping_active
1803 5.6. dispatcher.add
1804 5.7. dispatcher.remove
1805 5.8. dispatcher.hash
1806 5.9. dispatcher.oclist
1807
1808 5.1. dispatcher.set_state
1809
1810 Sets the state for a destination address (can be use to mark the
1811 destination as active or inactive).
1812
1813 Name: dispatcher.set_state
1814
1815 Parameters:
1816 * _state_ : state of the destination address
1817 + “a”: active
1818 + “i”: inactive
1819 + “t”: trying
1820 + “d”: disabled
1821 The states “a”, “i” or “t” can be followed by “p” to set probing
1822 mode (e.g. 'ap', 'ip' or 'tp').
1823 * _group_: destination group id
1824 * _address_: address of the destination in the _group_ or 'all' to
1825 update all destinations in the group
1826
1827 Example:
1828 ...
1829 # prototype: kamcmd dispatcher.set_state _state_ _group_ _address_
1830 kamcmd dispatcher.set_state ip 2 sip:127.0.0.1:5080
1831 kamcmd dispatcher.set_state ip 3 all
1832 ...
1833
1834 5.2. dispatcher.set_duid_state
1835
1836 Sets the state for a destination by matching on 'duid' attribute. The
1837 first two parameters 'state' and 'group' are the same like for RPC
1838 command 'dispatcher.set_state'. The third parameter 'duid' is the value
1839 to be matched against the 'duid' attribute of dispatcher destinations.
1840
1841 Example:
1842 ...
1843 # prototype: kamcmd dispatcher.set_duid_state _state_ _group_ _duid_
1844 kamcmd dispatcher.set_duid_state ip 2 xyz
1845 ...
1846
1847 5.3. dispatcher.list
1848
1849 Lists the routing groups with destination addresses and corresponding
1850 attributes.
1851
1852 Name: dispatcher.list
1853
1854 Parameters:
1855 * _rmode_ - (optional) response mode - can be: 'short' to get a
1856 shorter version of groups and destinations; 'full' to get more
1857 attributes per destination
1858
1859 Example:
1860 kamcmd dispatcher.list
1861 ...
1862 DEST: {
1863 URI: sip:192.168.0.1:5060
1864 FLAGS: AP
1865 PRIORITY: 12
1866 }
1867 ...
1868
1869 FLAGS consist out of 2 letters. First letter describe status of
1870 destination: A-active, I – inactive, T – trying, D – disabled.
1871 Second letter might be P or X. P is for probing, so AP means
1872 destination is active and it is tested by SIP options continuously. X
1873 means that there are no probing or sip pinging. So AX means that
1874 destination is assumed as active and it is not tested by SIP options.
1875 DX respectively is disabled destination that is not tested, etc.
1876
1877 5.4. dispatcher.reload
1878
1879 Reloads the groups and included destinations. The command is disabled
1880 for call load based dispatching (algorithm 10) since removal of
1881 destinations may leave the list of active calls with broken references.
1882
1883 Name: dispatcher.reload
1884
1885 Parameters: none
1886
1887 Example
1888 kamcmd dispatcher.reload
1889
1890 5.5. dispatcher.ping_active
1891
1892 Sets the global state for sending keepalive requests to destinations.
1893
1894 Name: dispatcher.ping_active
1895
1896 Parameters:
1897 * _state_ : state of sending keepalives
1898 + “0”: inactive (don't send)
1899 + “1”: active (send)
1900
1901 If the state parameter is missing, the current state is returned. When
1902 state is changed, new and old values of the state are returned. Default
1903 value for state is 1.
1904
1905 Example:
1906 ...
1907 # prototype: kamctl rpc dispatcher.ping_active _state_
1908 kamctl rpc dispatcher.ping_active 0
1909 ...
1910
1911 5.6. dispatcher.add
1912
1913 Add a destination address to the in-memory dispatcher list. Reloading
1914 the dispatcher will remove any destinations that are only added to the
1915 in-memory dispatcher list.
1916
1917 Name: dispatcher.add
1918
1919 Parameters:
1920 * _group_: destination group id
1921 * _address_: address of the destination in the _group_
1922 * _flags_ (optional): as described in the list file format, default 0
1923 * _priority_ (optional): as described in the list file format,
1924 default 0
1925 * _attrs_ (optional): as described in the list file format, default
1926 ""
1927
1928 Example:
1929 ...
1930 # prototype: kamcmd dispatcher.add _group_ _address_ _flags_ _priority_ _attrs_
1931 kamcmd dispatcher.add 2 sip:127.0.0.1:5080
1932 kamcmd dispatcher.add 3 sip:127.0.0.1:5075 8
1933 kamcmd dispatcher.add 3 sip:127.0.0.1:5075 0 0 duid=abc;socket=udp:127.0.0.1:506
1934 0
1935 ...
1936
1937 5.7. dispatcher.remove
1938
1939 Remove a destination address from the in-memory dispatcher list.
1940 Reloading the dispatcher from file or database will re-add destinations
1941 that are removed using this command.
1942
1943 This command will remove all entries that match the group and address.
1944
1945 Name: dispatcher.remove
1946
1947 Parameters:
1948 * _group_: destination group id
1949 * _address_: address of the destination in the _group_
1950
1951 Example:
1952 ...
1953 # prototype: kamcmd dispatcher.remove _group_ _address_
1954 kamcmd dispatcher.remove 2 sip:127.0.0.1:5080
1955 kamcmd dispatcher.remove 3 sip:127.0.0.1:5075;transport=udp
1956 ...
1957
1958 5.8. dispatcher.hash
1959
1960 Compute the hash id corresponding to the string parameter values.
1961
1962 Return the hash id and the corresponding slot, if 'nslots' parameter is
1963 not 0.
1964
1965 Name: dispatcher.hash
1966
1967 Parameters:
1968 * _nslots_: number of slots
1969 * _val1_: string value
1970 * _val2_: (optional) string value
1971
1972 It can be useful to find what address in a destination group (setid) is
1973 going to be used when hashing a value or a URI. For a URI, the
1974 corresponding username and domain have to be provided as _val1_ and
1975 _val2_. If the URI has a port different than 5060 (or 5061 for TLS),
1976 then the _val2_ has to be 'domain:port'. The _nslots_ has to be the
1977 number of addresses in the group (setid). The returned 'slot' value
1978 represents the index of the address to be used for routing.
1979
1980 Example:
1981 ...
1982 # prototype: kamctl rpc dispatcher.hash _nslots_ _val1_ [_val2_]
1983 kamctl rpc dispatcher.hash 0 alice server.com
1984 kamctl rpc dispatcher.hash 4 bob server.com
1985 ...
1986
1987 5.9. dispatcher.oclist
1988
1989 List the overload control attributes for the records in a specific
1990 group.
1991
1992 Name: dispatcher.oclist
1993
1994 Parameters:
1995 * _group_: destination group id
1996
1997 Example:
1998 ...
1999 # prototype: kamcli dispatcher.oclist _group_
2000 kamcli dispatcher.oclist 1
2001 ...
2002
2003 6. Installation and Running
2004
2005 6.1. Destination List File
2006
2007 6.1.1. Special Attributes
2008 6.1.2. File Format
2009
2010 6.2. Kamailio config file
2011
2012 6.1. Destination List File
2013
2014 Each destination point must be on one line. First token is the set id
2015 (an integer value, also referenced by group id), followed by
2016 destination address (string value in full SIP URI format).
2017
2018 Optionally, these fields can be followed by:
2019 * flags - control the mode of using the destination address and
2020 sending keepalives. The value is a decimal number (inside the text
2021 file it can be also provided as hexadecimal number). It is a
2022 bitwise value that can be built using the following flags:
2023 + 1 (bit at index 0 - 1 <<0) - inactive destination
2024 + 2 (bit at index 1 - 1 <<1) - temporary trying destination (in
2025 the way to become inactive if it does not reply to keepalives
2026 - there is a module parameter to set the threshold of
2027 failures)
2028 + 4 (bit at index 2 - 1 <<2) - admin disabled destination
2029 + 8 (bit at index 3 - 1 <<3) - probing destination (sending keep
2030 alives);
2031 + 16 (bit at index 4 - 1 <<4) - skip DNS A/AAAA resolve at
2032 startup, useful when the hostname of the destination address
2033 is a NAPTR or SRV record only. Such addresses cannot be
2034 matched anymore with ds_is_from_list(...).
2035 + 32 (bit at index 5 - 1 <<5) - no ping to destination
2036 * priority: sets the priority in destination list (based on it is
2037 done the initial ordering inside the set)
2038 * attributes: extra fields in form of name1=value1;...;nameN=valueN.
2039
2040 6.1.1. Special Attributes
2041
2042 There are some predefined names:
2043 * 'duid' - used for call load dispatching. It must be an unique value
2044 to identify a destination (gateway address). Practically the load
2045 within the group is associated with this value.>
2046 * 'maxload' - used for call load dispatching. It must be a positive
2047 integer, defining the upper limit of active calls per destination.
2048 When the limit is reached, then the gateway is no longer selected
2049 for new calls until an exiting call via that gateway is terminated.
2050 If set to 0, then no active call limit is used.>
2051 * 'weight' - used for weight based load distribution. It must be set
2052 to a positive integer value between 1 and 100 (inclusive the
2053 limits), otherwise the destination address is ignored (its weight
2054 set to 0). The value represents the percent of calls to be sent to
2055 that gateways. The sum must not exceed 100, otherwise the
2056 destinations whose weight added to the sum go over 100 are ignored.
2057 If the sum is less than 100, then the last destination is used to
2058 fill the missing percentage. See also the description of the
2059 corresponding algorithm parameter for ds_select_dst().
2060 * 'rweight' - used for relative weight based load distribution. It
2061 must be set to a positive integer value between 1 and 100
2062 (inclusive the limits) otherwise host will be excluded from
2063 relative weight distribution type - its rweight is set to 0. See
2064 also the description of the corresponding algorithm parameter for
2065 ds_select_dst().
2066 * 'socket' - used to set the sending socket for the gateway. It is
2067 used for sending the SIP traffic as well as OPTIONS keepalives.
2068 * 'ping_socket' - used to set the sending socket for ping requests.
2069 It overwrites the general ds_ping_socket parameter.
2070 * 'sockname' - used to set by name the sending socket for the
2071 gateway. It is used for sending the SIP traffic as well as OPTIONS
2072 keepalives and has priority over 'socket' attribute.
2073 * 'ping_from' - used to set the From URI in OPTIONS keepalives. It
2074 overwrites the general ds_ping_from parameter.
2075 * 'obproxy' - SIP URI of outbound proxy to be used when sending
2076 pings. It overwrites the general ds_outbound_proxy parameter.
2077 * 'latency' - latency_stats initialization in ms.
2078 * 'ocmin' - minimum limit for over load control rate (value between 0
2079 and 100, default 10).
2080 * 'ocrate' - over load control rate (value between 0 and 100, default
2081 100).
2082
2083 6.1.2. File Format
2084
2085 Line format is:
2086 ...
2087 setid(int) destination(sip uri) flags(int,opt) priority(int,opt) attrs(str,opt)
2088 ...
2089
2090 Full line examples:
2091 ...
2092 1 sip:127.0.0.1:5080 0 0 duid=abc;socket=udp:127.0.0.1:5060;my=xyz;ping_from=sip
2093 :myproxy.com
2094 1 sip:127.0.0.1:5090 0x8 0 socket=udp:127.0.0.1:5060;prefix=49
2095 ...
2096
2097 For database, each element of a line resides in a different column.
2098 Next is a dispatcher.list file example:
2099
2100 Example 1.66. dispatcher list file
2101 ...
2102 #
2103 # dispatcher destination sets (groups)
2104 #
2105
2106 # line format
2107 # setid(int) destination(sip uri) flags(int,opt) priority(int,opt) attributes(st
2108 r,opt)
2109
2110 # proxies
2111 2 sip:127.0.0.1:5080;transport=tcp 0 10 class=4;prefix=448;strip=2
2112 2 sip:127.0.0.1:5082;px=vx 0 5 duid=abc;socket=udp:192.168.0.125:5060;pipe=p10
2113
2114 # gateways
2115 1 sip:127.0.0.1:7070 0 0 duid=xyz;maxload=20
2116 1 sip:127.0.0.1:7072 0 5
2117 1 sip:127.0.0.1:7074
2118
2119 ...
2120
2121 6.2. Kamailio config file
2122
2123 Next listing shows a sample config for using the dispatcher module.
2124
2125 Example 1.67. Kamailio config script - sample dispatcher usage
2126 ...
2127 #!KAMAILIO
2128 #
2129 # sample config file for dispatcher module
2130 # - load balancing of VoIP calls with round robin
2131 # - no TPC listening
2132 # - don't dispatch REGISTER and presence requests
2133 #
2134 # Kamailio SIP Server
2135 # - web: https://www.kamailio.org
2136 # - git: http://github.com/kamailio/
2137 #
2138 # Direct your questions about this file to: [email protected]
2139 #
2140 # Refer to the Core CookBook at https://www.kamailio.org/w/documentation/
2141 # for an explanation of possible statements, functions and parameters.
2142 #
2143 # Several features can be enabled using '#!define WITH_FEATURE' directives:
2144 #
2145 # *** To run in debug mode:
2146 # - define WITH_DEBUG
2147 #
2148
2149 #!ifndef DBURL
2150 #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
2151 #!endif
2152
2153 # - flags
2154 # FLT_ - per transaction (message) flags
2155 # FLB_ - per branch flags
2156 #!define FLT_ACC 1
2157 #!define FLT_ACCMISSED 2
2158 #!define FLT_ACCFAILED 3
2159
2160 ####### Global Parameters #########
2161
2162 #!ifdef WITH_DEBUG
2163 debug=4
2164 log_stderror=yes
2165 #!else
2166 debug=2
2167 log_stderror=no
2168 #!endif
2169
2170 memdbg=5
2171 memlog=5
2172
2173 log_facility=LOG_LOCAL0
2174
2175 fork=yes
2176 children=4
2177
2178 /* comment the next line to enable TCP */
2179 disable_tcp=yes
2180
2181 /* uncomment the next line to disable the auto discovery of local aliases
2182 based on revers DNS on IPs (default on) */
2183 auto_aliases=no
2184
2185 /* add local domain aliases */
2186 # alias="mysipserver.com"
2187
2188 port=5060
2189
2190 /* uncomment and configure the following line if you want Kamailio to
2191 bind on a specific interface/port/proto (default bind on all available) */
2192 # listen=udp:127.0.0.1:5060
2193
2194 sip_warning=no
2195
2196 ####### Modules Section ########
2197
2198 # set module path
2199 #mpath="/usr/local/lib/kamailio/modules/"
2200
2201 loadmodule "db_mysql.so"
2202 loadmodule "jsonrpcs.so"
2203 loadmodule "kex.so"
2204 loadmodule "corex.so"
2205 loadmodule "tm.so"
2206 loadmodule "tmx.so"
2207 loadmodule "sl.so"
2208 loadmodule "rr.so"
2209 loadmodule "pv.so"
2210 loadmodule "maxfwd.so"
2211 loadmodule "textops.so"
2212 loadmodule "siputils.so"
2213 loadmodule "xlog.so"
2214 loadmodule "sanity.so"
2215 loadmodule "ctl.so"
2216 loadmodule "acc.so"
2217 loadmodule "dispatcher.so"
2218
2219
2220 # ----------------- setting module-specific parameters ---------------
2221
2222
2223 # ----- jsonrpcs params -----
2224 modparam("jsonrpcs", "pretty_format", 1)
2225
2226
2227 # ----- rr params -----
2228 # add value to ;lr param to cope with most of the UAs
2229 modparam("rr", "enable_full_lr", 1)
2230 # do not append from tag to the RR (no need for this script)
2231 modparam("rr", "append_fromtag", 0)
2232
2233
2234 # ----- acc params -----
2235 modparam("acc", "log_flag", FLT_ACC)
2236 modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
2237 modparam("acc", "log_extra",
2238 "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd;s
2239 rc_ip=$si")
2240
2241 # ----- tm params -----
2242 modparam("tm", "fr_timer", 2000)
2243 modparam("tm", "fr_inv_timer", 40000)
2244
2245 # ----- dispatcher params -----
2246 modparam("dispatcher", "db_url", DBURL)
2247 modparam("dispatcher", "table_name", "dispatcher")
2248 modparam("dispatcher", "flags", 2)
2249 modparam("dispatcher", "xavp_dst", "_dsdst_")
2250 modparam("dispatcher", "xavp_ctx", "_dsctx_")
2251 modparam("dispatcher", "ds_ping_from", "sip:[email protected]")
2252 modparam("dispatcher", "ds_ping_interval", 60)
2253 modparam("dispatcher", "ds_probing_mode", 1)
2254 modparam("dispatcher", "ds_timer_mode", 1)
2255
2256 ####### Routing Logic ########
2257
2258
2259 # main request routing logic
2260
2261 request_route {
2262
2263 # per request initial checks
2264 route(REQINIT);
2265
2266 # CANCEL processing
2267 if (is_method("CANCEL")) {
2268 if (t_check_trans()) {
2269 route(RELAY);
2270 }
2271 exit;
2272 }
2273
2274 # handle retransmissions
2275 if (!is_method("ACK")) {
2276 if(t_precheck_trans()) {
2277 t_check_trans();
2278 exit;
2279 }
2280 t_check_trans();
2281 }
2282
2283 # handle requests within SIP dialogs
2284 route(WITHINDLG);
2285
2286 ### only initial requests (no To tag)
2287
2288 # record routing for dialog forming requests (in case they are routed)
2289 # - remove preloaded route headers
2290 remove_hf("Route");
2291 if (is_method("INVITE|SUBSCRIBE")) {
2292 record_route();
2293 }
2294
2295 # account only INVITEs
2296 if (is_method("INVITE")) {
2297 setflag(FLT_ACC); # do accounting
2298 }
2299
2300 # handle presence related requests
2301 route(PRESENCE);
2302
2303 # handle registrations
2304 route(REGISTRAR);
2305
2306 if ($rU==$null) {
2307 # request with no Username in RURI
2308 sl_send_reply("484","Address Incomplete");
2309 exit;
2310 }
2311
2312 # dispatch destinations
2313 route(DISPATCH);
2314 }
2315
2316
2317 route[RELAY] {
2318 if (!t_relay()) {
2319 sl_reply_error();
2320 }
2321 exit;
2322 }
2323
2324 # Per SIP request initial checks
2325 route[REQINIT] {
2326 if (!mf_process_maxfwd_header("10")) {
2327 sl_send_reply("483","Too Many Hops");
2328 exit;
2329 }
2330
2331 if(!sanity_check("1511", "7")) {
2332 xlog("Malformed SIP message from $si:$sp\n");
2333 exit;
2334 }
2335 }
2336
2337 # Handle requests within SIP dialogs
2338 route[WITHINDLG] {
2339 if (!has_totag()) {
2340 return;
2341 }
2342
2343 # sequential request within a dialog should
2344 # take the path determined by record-routing
2345 if (loose_route()) {
2346 if (is_method("BYE")) {
2347 setflag(FLT_ACC); # do accounting ...
2348 setflag(FLT_ACCFAILED); # ... even if the transaction fa
2349 ils
2350 }
2351 route(RELAY);
2352 }
2353
2354 if (is_method("SUBSCRIBE") && uri == myself) {
2355 # in-dialog subscribe requests
2356 route(PRESENCE);
2357 }
2358
2359 if ( is_method("ACK") ) {
2360 if ( t_check_trans() ) {
2361 # non loose-route, but stateful ACK;
2362 # must be ACK after a 487 or e.g. 404 from upstream serv
2363 er
2364 t_relay();
2365 exit;
2366 } else {
2367 # ACK without matching transaction ... ignore and discar
2368 d.
2369 exit;
2370 }
2371 }
2372
2373 sl_send_reply("404","Not here");
2374 exit;
2375 }
2376
2377 # Handle SIP registrations
2378 route[REGISTRAR] {
2379 if(!is_method("REGISTER"))
2380 return;
2381
2382 sl_send_reply("404", "No registrar");
2383 exit;
2384 }
2385
2386 # Presence server route
2387 route[PRESENCE] {
2388 if(!is_method("PUBLISH|SUBSCRIBE"))
2389 return;
2390
2391 sl_send_reply("404", "Not here");
2392 exit;
2393 }
2394
2395 # Dispatch requests
2396 route[DISPATCH] {
2397 # round robin dispatching on gateways group '1'
2398 if(!ds_select_dst("1", "4")) {
2399 send_reply("404", "No destination");
2400 exit;
2401 }
2402 xdbg("--- SCRIPT: going to <$ru> via <$du> (attrs: $xavp(_dsdst_=>attrs)
2403 )\n");
2404 t_on_failure("RTF_DISPATCH");
2405 route(RELAY);
2406 exit;
2407 }
2408
2409 # Try next destinations in failure route
2410 failure_route[RTF_DISPATCH] {
2411 if (t_is_canceled()) {
2412 exit;
2413 }
2414 # next DST - only for 500 or local timeout
2415 if (t_check_status("500")
2416 or (t_branch_timeout() and !t_branch_replied())) {
2417 if(ds_next_dst()) {
2418 xdbg("--- SCRIPT: retrying to <$ru> via <$du> (attrs: $x
2419 avp(_dsdst_=>attrs))\n");
2420 t_on_failure("RTF_DISPATCH");
2421 route(RELAY);
2422 exit;
2423 }
2424 }
2425 }
2426
2427 ...
2428
2429 7. Event routes
2430
2431 7.1. dispatcher:dst-down
2432 7.2. dispatcher:dst-up
2433
2434 7.1. dispatcher:dst-down
2435
2436 When defined, the module calls event_route[dispatcher:ds-down] when a
2437 destination goes down (becomes probing). A typical use case is to
2438 update NMC equipment as to the status of a destination.
2439
2440 Its execution is controlled by event_callback_mode parameter.
2441 ...
2442 event_route[dispatcher:dst-down] {
2443 xlog("L_ERR", "Destination down: $rm $ru ($du)\n");
2444 }
2445 ...
2446
2447 7.2. dispatcher:dst-up
2448
2449 When defined, the module calls event_route[dispatcher:ds-up] when a
2450 destination that was previously down (probing) comes up. A typical use
2451 case is to update NMC equipment as to the status of a destination.
2452
2453 Its execution is controlled by event_callback_mode parameter.
2454 ...
2455 event_route[dispatcher:dst-up] {
2456 xlog("L_ERR", "Destination up: $rm $ru\n");
2457 }
2458 ...
2459
2460 Chapter 2. Frequently Asked Questions
2461
2462 2.1. Does dispatcher provide a fair distribution?
2463 2.2. Is dispatcher dialog stateful?
2464 2.3. Where can I find more about Kamailio?
2465 2.4. Where can I post a question about this module?
2466 2.5. How can I report a bug?
2467
2468 2.1.
2469
2470 Does dispatcher provide a fair distribution?
2471
2472 The algorithms doing hashing over parts of SIP message don't guarantee
2473 a fair distribution. You should do some measurements to decide what
2474 hashing algorithm fits better in your environment.
2475
2476 Other distribution algorithms such as round robin or call load
2477 dispatching do a fair distribution in terms of delivered calls to
2478 gateways.
2479
2480 2.2.
2481
2482 Is dispatcher dialog stateful?
2483
2484 No. Dispatcher is stateless, although some distribution algorithms are
2485 designed to select same destination for subsequent requests of the same
2486 dialog (e.g., hashing the call-id).
2487
2488 2.3.
2489
2490 Where can I find more about Kamailio?
2491
2492 Take a look at https://www.kamailio.org/.
2493
2494 2.4.
2495
2496 Where can I post a question about this module?
2497
2498 First at all check if your question was already answered on one of our
2499 mailing lists:
2500 * User Mailing List -
2501 https://lists.kamailio.org/mailman3/postorius/lists/sr-users.lists.
2502 kamailio.org/
2503 * Developer Mailing List -
2504 https://lists.kamailio.org/mailman3/postorius/lists/sr-dev.lists.ka
2505 mailio.org/
2506
2507 E-mails regarding any stable version should be sent to
2508 <[email protected]> and e-mail regarding development versions
2509 or GIT snapshots should be sent to <[email protected]>.
2510
2511 2.5.
2512
2513 How can I report a bug?
2514
2515 Please follow the guidelines provided at:
2516 https://github.com/kamailio/kamailio/issues