| 1 |
Dynamic Routing Module |
| 2 |
|
| 3 |
Voice Sistem SRL |
| 4 |
|
| 5 |
Edited by |
| 6 |
|
| 7 |
Ovidiu Sas |
| 8 |
|
| 9 |
Anca-Maria Vamanu |
| 10 |
|
| 11 |
Copyright © 2005-2008 Voice Sistem SRL |
| 12 |
__________________________________________________________________ |
| 13 |
|
| 14 |
Table of Contents |
| 15 |
|
| 16 |
1. Admin Guide |
| 17 |
|
| 18 |
1. Overview |
| 19 |
|
| 20 |
1.1. Introduction |
| 21 |
1.2. Features |
| 22 |
1.3. Performance |
| 23 |
1.4. Routing Rule Definition |
| 24 |
|
| 25 |
1.4.1. Gateway Addresses |
| 26 |
1.4.2. Destination/GW lists |
| 27 |
1.4.3. Routing Rules |
| 28 |
|
| 29 |
1.5. Routing Rule Processing |
| 30 |
|
| 31 |
2. Dependencies |
| 32 |
|
| 33 |
2.1. Kamailio Modules |
| 34 |
2.2. External Libraries or Applications |
| 35 |
|
| 36 |
3. Parameters |
| 37 |
|
| 38 |
3.1. db_url(str) |
| 39 |
3.2. drd_table(str) |
| 40 |
3.3. drr_table(str) |
| 41 |
3.4. drg_table(str) |
| 42 |
3.5. drl_table(str) |
| 43 |
3.6. sort_order (int) |
| 44 |
3.7. ruri_avp (str) |
| 45 |
3.8. attrs_avp (str) |
| 46 |
3.9. use_domain (int) |
| 47 |
3.10. drg_user_col (str) |
| 48 |
3.11. drg_domain_col (str) |
| 49 |
3.12. drg_grpid_col (str) |
| 50 |
3.13. fetch_rows (int) |
| 51 |
3.14. force_dns (int) |
| 52 |
3.15. enable_keepalive (int) |
| 53 |
|
| 54 |
4. Functions |
| 55 |
|
| 56 |
4.1. do_routing([groupID]) |
| 57 |
4.2. next_routing() |
| 58 |
4.3. use_next_gw() |
| 59 |
4.4. goes_to_gw([type]) |
| 60 |
4.5. is_from_gw([ type, [flag] ]) |
| 61 |
|
| 62 |
5. RPC Commands |
| 63 |
|
| 64 |
5.1. drouting.reload |
| 65 |
|
| 66 |
6. Installation |
| 67 |
|
| 68 |
2. Developer Guide |
| 69 |
|
| 70 |
List of Tables |
| 71 |
|
| 72 |
1.1. Definition of table dr_gateways |
| 73 |
1.2. Sample dr_gateways records |
| 74 |
1.3. Definition of dr_rules table |
| 75 |
1.4. Time recurrence attributes |
| 76 |
1.5. Sample dr_rules records |
| 77 |
|
| 78 |
List of Examples |
| 79 |
|
| 80 |
1.1. Set db_url parameter |
| 81 |
1.2. Set drd_table parameter |
| 82 |
1.3. Set drr_table parameter |
| 83 |
1.4. Set drg_table parameter |
| 84 |
1.5. Set drl_table parameter |
| 85 |
1.6. Set sort_order parameter |
| 86 |
1.7. Set ruri_avp parameter |
| 87 |
1.8. Set attrs_avp parameter |
| 88 |
1.9. Set use_domain parameter |
| 89 |
1.10. Set drg_user_col parameter |
| 90 |
1.11. Set drg_domain_col parameter |
| 91 |
1.12. Set drg_grpid_col parameter |
| 92 |
1.13. Set fetch_rows parameter |
| 93 |
1.14. Set force_dns parameter |
| 94 |
1.15. Set enable_keepalive parameter |
| 95 |
1.16. do_routing usage |
| 96 |
1.17. next_routing usage |
| 97 |
1.18. goes_to_gw usage |
| 98 |
1.19. is_from_gw usage |
| 99 |
|
| 100 |
Chapter 1. Admin Guide |
| 101 |
|
| 102 |
Table of Contents |
| 103 |
|
| 104 |
1. Overview |
| 105 |
|
| 106 |
1.1. Introduction |
| 107 |
1.2. Features |
| 108 |
1.3. Performance |
| 109 |
1.4. Routing Rule Definition |
| 110 |
|
| 111 |
1.4.1. Gateway Addresses |
| 112 |
1.4.2. Destination/GW lists |
| 113 |
1.4.3. Routing Rules |
| 114 |
|
| 115 |
1.5. Routing Rule Processing |
| 116 |
|
| 117 |
2. Dependencies |
| 118 |
|
| 119 |
2.1. Kamailio Modules |
| 120 |
2.2. External Libraries or Applications |
| 121 |
|
| 122 |
3. Parameters |
| 123 |
|
| 124 |
3.1. db_url(str) |
| 125 |
3.2. drd_table(str) |
| 126 |
3.3. drr_table(str) |
| 127 |
3.4. drg_table(str) |
| 128 |
3.5. drl_table(str) |
| 129 |
3.6. sort_order (int) |
| 130 |
3.7. ruri_avp (str) |
| 131 |
3.8. attrs_avp (str) |
| 132 |
3.9. use_domain (int) |
| 133 |
3.10. drg_user_col (str) |
| 134 |
3.11. drg_domain_col (str) |
| 135 |
3.12. drg_grpid_col (str) |
| 136 |
3.13. fetch_rows (int) |
| 137 |
3.14. force_dns (int) |
| 138 |
3.15. enable_keepalive (int) |
| 139 |
|
| 140 |
4. Functions |
| 141 |
|
| 142 |
4.1. do_routing([groupID]) |
| 143 |
4.2. next_routing() |
| 144 |
4.3. use_next_gw() |
| 145 |
4.4. goes_to_gw([type]) |
| 146 |
4.5. is_from_gw([ type, [flag] ]) |
| 147 |
|
| 148 |
5. RPC Commands |
| 149 |
|
| 150 |
5.1. drouting.reload |
| 151 |
|
| 152 |
6. Installation |
| 153 |
|
| 154 |
1. Overview |
| 155 |
|
| 156 |
1.1. Introduction |
| 157 |
1.2. Features |
| 158 |
1.3. Performance |
| 159 |
1.4. Routing Rule Definition |
| 160 |
|
| 161 |
1.4.1. Gateway Addresses |
| 162 |
1.4.2. Destination/GW lists |
| 163 |
1.4.3. Routing Rules |
| 164 |
|
| 165 |
1.5. Routing Rule Processing |
| 166 |
|
| 167 |
1.1. Introduction |
| 168 |
|
| 169 |
Dynamic Routing is a module for selecting (based on multiple criteria) |
| 170 |
the best gateway/destination to be used for delivering a certain call. |
| 171 |
Least Cost Routing (LCR) is a special case of dynamic routing - when |
| 172 |
the rules are ordered based on costs. Dynamic Routing comes with many |
| 173 |
features regarding routing rule selection: |
| 174 |
* prefix based |
| 175 |
* caller/group based |
| 176 |
* time based |
| 177 |
* priority based |
| 178 |
|
| 179 |
, processing : |
| 180 |
* stripping and prefixing |
| 181 |
* default rules |
| 182 |
* inbound and outbound processing |
| 183 |
* script route triggering |
| 184 |
|
| 185 |
and failure handling: |
| 186 |
* serial forking |
| 187 |
* weight based GW selection |
| 188 |
* random GW selection |
| 189 |
|
| 190 |
1.2. Features |
| 191 |
|
| 192 |
The dynamic routing implementation for Kamailio is designed with the |
| 193 |
following properties: |
| 194 |
* routing info (destinations, rules, groups) are stored in a database |
| 195 |
and loaded into memory at start up time; reload at runtime via RPC |
| 196 |
command |
| 197 |
* load balancing or random selection of the destinations (from a |
| 198 |
given set) |
| 199 |
* able to handle large volume of routing info (300K of rules) with |
| 200 |
minimal speed/time and memory consumption penalties |
| 201 |
* script integration - Pseudo variables support in functions; |
| 202 |
scripting route triggering when rules are matched |
| 203 |
* bidirectional behavior - inbound and outbound processing (strip and |
| 204 |
prefixing when sending and receiving from a destination/GW) |
| 205 |
|
| 206 |
1.3. Performance |
| 207 |
|
| 208 |
There were several tests performed regarding the performance of the |
| 209 |
module when dealing with a large number of routing rules. |
| 210 |
|
| 211 |
The tests were performed with a set of 383000 rules and to values were |
| 212 |
measured: |
| 213 |
* time to load from DB |
| 214 |
* used shared memory |
| 215 |
|
| 216 |
The time to load was varying between 4 seconds and 8 seconds, depending |
| 217 |
of the caching of the DB client - the first load was the slowest (as |
| 218 |
the DB query hits the disk drive); the following are faster as data is |
| 219 |
already cached in the DB client. So technically speaking, the time to |
| 220 |
load (without the time to query which is DB type dependent) is ~4 |
| 221 |
seconds |
| 222 |
|
| 223 |
After loading the data into shared memory ~ 96M of memory were used |
| 224 |
exclusively for the DR data. |
| 225 |
|
| 226 |
1.4. Routing Rule Definition |
| 227 |
|
| 228 |
Dynamic routing rules are stored in a database, in four tables: |
| 229 |
* one for storing the gateway definitions |
| 230 |
* one for storing the routing rule definitions |
| 231 |
* one for storing the users mappings over groups |
| 232 |
* one for storing a list of gateways, so you don't have to enter all |
| 233 |
the elements every time you need it |
| 234 |
|
| 235 |
1.4.1. Gateway Addresses |
| 236 |
|
| 237 |
Default name for the table storing gateway addresses is “dr_gateways”. |
| 238 |
Gateway addresses are stored in a separate table because of need to |
| 239 |
access them independent of Dynamic Routing processing (e.g., adding/ |
| 240 |
removing gateway PRI prefix before/after performing other operation -- |
| 241 |
receiving/relaying to gateway). |
| 242 |
|
| 243 |
Table 1.1. Definition of table dr_gateways |
| 244 |
Column name Type Default value Description |
| 245 |
gwid integer auto increment unique identifier for GW |
| 246 |
type unsigned int 0 type/class of GW |
| 247 |
address varchar(128) address of the gateway |
| 248 |
strip unsigned int 0 no of digits to strip |
| 249 |
pri_prefix varchar(255) PRI prefix of the gateway |
| 250 |
description varchar(128) description of the gateway |
| 251 |
|
| 252 |
Once a rule is matched, the STRIP number of digits are removed from the |
| 253 |
username part of the RURI and then the PRI prefix has to be added to |
| 254 |
the request URI before forwarding the call to the gateway. |
| 255 |
|
| 256 |
Table 1.2. Sample dr_gateways records |
| 257 |
gwid type address strip pri_prefix description |
| 258 |
1 10 10.10.10.10:5080 0 2222 Gateway 1 |
| 259 |
2 10 10.10.10.10 2 3333 Gateway 2 |
| 260 |
3 20 10.10.10.11 0 Gateway 3 |
| 261 |
|
| 262 |
1.4.2. Destination/GW lists |
| 263 |
|
| 264 |
For each rule, you can set a list of destinations to be used. The list |
| 265 |
is comma or pipe separated enumeration of the destinations. The module |
| 266 |
will use (one by one) each destination from the list (in the given |
| 267 |
order). |
| 268 |
|
| 269 |
Also the module allows the usage of groups in the destination lists. A |
| 270 |
group of destinations is delimited by semi-colon char. inside the whole |
| 271 |
destination list ( like: 2,4;5,78,23;4;7;2 ). The destinations from |
| 272 |
within a group may be act differently (like load-balancing, random |
| 273 |
selection, etc), depending of the “sort_order” module parameter - more |
| 274 |
about this is available under the module parameters section. |
| 275 |
|
| 276 |
1.4.3. Routing Rules |
| 277 |
|
| 278 |
Default name for the table storing rule definitions is “dr_rules”. |
| 279 |
|
| 280 |
Table 1.3. Definition of dr_rules table |
| 281 |
Column name Type Default Description |
| 282 |
ruleid integer auto UID of the rule |
| 283 |
groupid varchar(255) list of routing group IDs |
| 284 |
prefix varchar(64) destination prefix for this route |
| 285 |
timerec varchar(255) time recurrence for this rule |
| 286 |
priority integer 0 priority of the rule |
| 287 |
routeid integer 0 route block to be execute |
| 288 |
gwlist varchar(255) the list with GWs to be used |
| 289 |
description varchar(128) description of this rule |
| 290 |
|
| 291 |
a. groupid column |
| 292 |
Each user must be member of only one routing group. It must be |
| 293 |
specified in user's profile. |
| 294 |
b. prefix column |
| 295 |
Destination URI must start with prefix value to match the rule. The |
| 296 |
prefix value can contain only digits (0..9), '+', '*' or '#'. |
| 297 |
c. time rec column |
| 298 |
A date-time expression that defines the time recurrence to match |
| 299 |
for current rule. Time recurrences are based closely on the |
| 300 |
specification of recurring intervals of time in the Internet |
| 301 |
Calendaring and Scheduling Core Object Specification (calendar |
| 302 |
COS), RFC 2445. The set of attributes used in routing rule |
| 303 |
specification is subset of time recurrence attributes used by Call |
| 304 |
Processing Language (CPL). These attributes are (extracted from CPL |
| 305 |
draft 09): |
| 306 |
Table 1.4. Time recurrence attributes |
| 307 |
|
| 308 |
Attribute Description |
| 309 |
dastard Start of interval (RFC 2445 DATE-TIME) |
| 310 |
duration Length of interval (RFC 2445 DURATION) |
| 311 |
freq Frequency of recurrence (secondly,minutely,hourly, daily,weekly, |
| 312 |
monthly, or yearly). |
| 313 |
until bound of recurrence (RFC 2445 DATE-TIME) |
| 314 |
interval How often the recurrence repeats |
| 315 |
byday List of days of the week |
| 316 |
bymonthday List of days of the month |
| 317 |
byyearday List of days of the year |
| 318 |
byweekno List of weeks of the year |
| 319 |
bymonth List of months of the year |
| 320 |
The value stored in database has the format of: |
| 321 |
<dtstart>|<duration>|<freq>|<until>|<interval>|<byday>|<bymonthday> |
| 322 |
|<byyearday>|<byweekno>|<bymonth> |
| 323 |
When an attribute is not specified, the corresponding place must be |
| 324 |
left empty, whenever another attribute that follows in the list has |
| 325 |
to be specified. |
| 326 |
Detailed description of time recurrence attributes: |
| 327 |
+ dtstart - specifies the beginning of the first period. |
| 328 |
+ duration - specifies the duration of the period. For a |
| 329 |
recurring interval, the “duration” parameter MUST be small |
| 330 |
enough such that subsequent intervals do not overlap. For |
| 331 |
non-recurring intervals, durations of any positive length are |
| 332 |
permitted, zero-length duration means “forever”. |
| 333 |
Negative-length durations are not allowed. In the common case |
| 334 |
of a duration less than one day, the value starts with 'PT' |
| 335 |
followed by number of hours, minutes and seconds, e.g., a |
| 336 |
duration of 8 hours and 30 minutes is written 'PT8H30M'. See |
| 337 |
RFC 2445 DURATION specifications for full format. |
| 338 |
+ freq - takes one of the following values: “daily”, to specify |
| 339 |
repeating periods based on an interval of a day or more; |
| 340 |
“weekly”, to specify repeating periods based on an interval of |
| 341 |
a week or more; “monthly”, to specify repeating periods based |
| 342 |
on an interval of a month or more; and “yearly”, to specify |
| 343 |
repeating periods based on an interval of a year or more. |
| 344 |
These values are not case-sensitive. |
| 345 |
+ until - defines an iCalendar COS DATE or DATE-TIME value which |
| 346 |
bounds the recurrence rule in an inclusive manner. If the |
| 347 |
value specified by “until” is synchronized with the specified |
| 348 |
recurrence, this date or date-time becomes the last instance |
| 349 |
of the recurrence. If not present, the recurrence is |
| 350 |
considered to repeat forever. |
| 351 |
+ interval - contains a positive integer representing how often |
| 352 |
the recurrence rule repeats. The default value is “1”, meaning |
| 353 |
every day for a “daily” rule, every week for a “weekly” rule, |
| 354 |
every month for a “monthly” rule and every year for a “yearly” |
| 355 |
rule. |
| 356 |
+ interval - contains a positive integer representing how often |
| 357 |
the recurrence rule repeats. The default value is “1”, meaning |
| 358 |
every day for a “daily” rule, every week for a “weekly” rule, |
| 359 |
every month for a “monthly” rule and every year for a “yearly” |
| 360 |
rule. |
| 361 |
+ byday - specifies a comma-separated list of days of the week. |
| 362 |
“MO” indicates Monday; “TU” indicates Tuesday; “WE” indicates |
| 363 |
Wednesday; “TH” indicates Thursday; “FR” indicates Friday; |
| 364 |
“SA” indicates Saturday; “SU” indicates Sunday. These values |
| 365 |
are not case-sensitive. |
| 366 |
Each “byday” value can also be preceded by a positive (+n) or |
| 367 |
negative (-n) integer. If present, this indicates the nth |
| 368 |
occurrence of the specific day within the “monthly” or |
| 369 |
“yearly” recurrence. For example, within a “monthly” rule, |
| 370 |
+1MO (or simply 1MO) represents the first Monday within the |
| 371 |
month, whereas -1MO represents the last Monday of the month. |
| 372 |
If an integer modifier is not present, it means all days of |
| 373 |
this type within the specified frequency. For example, within |
| 374 |
a “monthly” rule, MO represents all Mondays within the month. |
| 375 |
+ bymonthday - parameter specifies a comma-separated list of |
| 376 |
days of the month. Valid values are 1 to 31 or -31 to -1. For |
| 377 |
example, -10 represents the tenth to the last day of the |
| 378 |
month. |
| 379 |
+ byyearday - specifies a comma-separated list of days of the |
| 380 |
year. Valid values are 1 to 366 or -366 to -1. For example, -1 |
| 381 |
represents the last day of the year (December 31st) and -306 |
| 382 |
represents the 306th to the last day of the year (March 1st). |
| 383 |
+ byweekno - specifies a comma-separated list of ordinals |
| 384 |
specifying weeks of the year. Valid values are 1 to 53 or -53 |
| 385 |
to -1. |
| 386 |
+ bymonth - parameter specifies a comma-separated list of months |
| 387 |
of the year. Valid values are 1 to 12. |
| 388 |
A recurrence is specified by including the “freq” parameter, which |
| 389 |
indicates the type of recurrence rule. Parameters other than |
| 390 |
“dtstart” and “duration” SHOULD NOT be specified unless “freq” is |
| 391 |
present. |
| 392 |
If byxxx parameter values are found which are beyond the available |
| 393 |
scope (ie, bymonthday=“30” in February), they are simply ignored. |
| 394 |
Byxxx parameters modify the recurrence in some manner. Byxxx rule |
| 395 |
parts for a period of time which is the same or greater than the |
| 396 |
frequency generally reduce or limit the number of occurrences of |
| 397 |
the recurrence generated. For example, freq=“daily” bymonth=“1” |
| 398 |
reduces the number of recurrence instances from all days (if the |
| 399 |
“bymonth” parameter is not present) to all days in January. Byxxx |
| 400 |
parameters for a period of time less than the frequency generally |
| 401 |
increase or expand the number of occurrences of the recurrence. For |
| 402 |
example, freq=“yearly” bymonth=“1,2” increases the number of days |
| 403 |
within the yearly recurrence set from 1 (if “bymonth” parameter is |
| 404 |
not present) to 2. |
| 405 |
If multiple Byxxx parameters are specified, then after evaluating |
| 406 |
the specified “freq” and “interval” parameters, the Byxxx |
| 407 |
parameters are applied to the current set of evaluated occurrences |
| 408 |
in the following order: “bymonth”, “byweekno”, “byyearday”, |
| 409 |
“bymonthday”, “byday”; then “until” is evaluated. |
| 410 |
Here is an example of evaluating multiple Byxxx parameters. |
| 411 |
dtstart=“19970105T083000” duration=“PT10M” freq=“yearly” |
| 412 |
interval=“2” bymonth=“1” byday=“SU” |
| 413 |
First, the interval=“2” would be applied to freq=“yearly” to arrive |
| 414 |
at “every other year” . Then, bymonth=“1” would be applied to |
| 415 |
arrive at “every January, every other year”. Then, byday=“SU” would |
| 416 |
be applied to arrive at “every Sunday in January, every other year, |
| 417 |
from 8:30 to 8:40 ”. The appropriate minutes and hours have been |
| 418 |
retrieved from the “dtstart” and “duration” parameters. |
| 419 |
d. priority column |
| 420 |
If many rules are eligible, choose the one with highest priority. |
| 421 |
e. routeid column |
| 422 |
If different than 0, then execute the route with the specified ID. |
| 423 |
That is, a route which can be used to perform custom operations on |
| 424 |
message. At this route, no modification is performed at signaling |
| 425 |
level. |
| 426 |
f. gwlist column |
| 427 |
A comma separated list of gateway identifiers corresponding to a |
| 428 |
row in table “dr_gateways”. You can use a predefined list from the |
| 429 |
table “dr_gw_lists” preceded by the character “#”. The first |
| 430 |
gateway is tried first and if routing to it fails, then the second |
| 431 |
one, and so one. If no gateway is left a negative response is sent |
| 432 |
back to caller. |
| 433 |
g. Routing Rules Examples |
| 434 |
Table 1.5. Sample dr_rules records |
| 435 |
|
| 436 |
ruleid group prefix timerec priority routeid gwlist description |
| 437 |
1 6 0049 20040101T083000|10H|weekly|||MO,TU,WE,TH,FR 5 23 1,2 Rule 1 |
| 438 |
2 8 0049 20040101T083000 0 0 1,2 Rule 2 |
| 439 |
3 7,8,9 0049 20040101T083000 0 0 3 Rule 3 |
| 440 |
(The time recurrence for first rule is: |
| 441 |
“20040101T083000|10H|weekly|||MO,TU,WE,TH,FR”) |
| 442 |
|
| 443 |
1.5. Routing Rule Processing |
| 444 |
|
| 445 |
The module can be used to find out which is the best gateway to use for |
| 446 |
new calls terminated to PSTN. The algorithm to select the rule is as |
| 447 |
follows: |
| 448 |
* the module discovers the routing group of the originating user. |
| 449 |
This step is skipped if a routing group is passed from the script |
| 450 |
as parameter. |
| 451 |
* once the group is known, in the subset of the rules for this group |
| 452 |
the module looks for the one that matches the destination based on |
| 453 |
"prefix" column. The set of rules with the longest prefix is |
| 454 |
chosen. If no digit from the prefix matches, the default rules are |
| 455 |
used (rules with no prefix) |
| 456 |
* within the set of rules is applied the time criteria, and the rule |
| 457 |
which has the highest priority and matches the time criteria is |
| 458 |
selected to drive the routing. |
| 459 |
* Once found the rule, it may contain a route ID to execute. If a |
| 460 |
certain flag is set, then the processing is stopped after executing |
| 461 |
the route block. |
| 462 |
* The rule must contain a gateway chain. The module will execute |
| 463 |
serial forking for each address in chain. The next address in chain |
| 464 |
is used only if the previously has failed. |
| 465 |
* With the right gateway address found, the prefix (PRI) of the |
| 466 |
gateway is added to the request URI and then the request is |
| 467 |
forwarded. |
| 468 |
|
| 469 |
If no rule is found to match the selection criteria a default action |
| 470 |
must be taken (e.g., error response sent back). If the gateway in the |
| 471 |
chain has no prefix the request is forwarded without adding any prefix |
| 472 |
to the request URI. |
| 473 |
|
| 474 |
2. Dependencies |
| 475 |
|
| 476 |
2.1. Kamailio Modules |
| 477 |
2.2. External Libraries or Applications |
| 478 |
|
| 479 |
2.1. Kamailio Modules |
| 480 |
|
| 481 |
The following modules must be loaded before this module: |
| 482 |
* a database module. |
| 483 |
|
| 484 |
2.2. External Libraries or Applications |
| 485 |
|
| 486 |
* none. |
| 487 |
|
| 488 |
3. Parameters |
| 489 |
|
| 490 |
3.1. db_url(str) |
| 491 |
3.2. drd_table(str) |
| 492 |
3.3. drr_table(str) |
| 493 |
3.4. drg_table(str) |
| 494 |
3.5. drl_table(str) |
| 495 |
3.6. sort_order (int) |
| 496 |
3.7. ruri_avp (str) |
| 497 |
3.8. attrs_avp (str) |
| 498 |
3.9. use_domain (int) |
| 499 |
3.10. drg_user_col (str) |
| 500 |
3.11. drg_domain_col (str) |
| 501 |
3.12. drg_grpid_col (str) |
| 502 |
3.13. fetch_rows (int) |
| 503 |
3.14. force_dns (int) |
| 504 |
3.15. enable_keepalive (int) |
| 505 |
|
| 506 |
3.1. db_url(str) |
| 507 |
|
| 508 |
The database url. |
| 509 |
|
| 510 |
Default value is “mysql://kamailioro:kamailioro@localhost/kamailio”. |
| 511 |
|
| 512 |
Example 1.1. Set db_url parameter |
| 513 |
... |
| 514 |
modparam("drouting", "db_url", |
| 515 |
"mysql://kamailio:kamailiorw@localhost/kamailio") |
| 516 |
... |
| 517 |
|
| 518 |
3.2. drd_table(str) |
| 519 |
|
| 520 |
The name of the db table storing gateway addresses. |
| 521 |
|
| 522 |
Default value is “dr_gateways”. |
| 523 |
|
| 524 |
Example 1.2. Set drd_table parameter |
| 525 |
... |
| 526 |
modparam("drouting", "drd_table", "dr_gateways") |
| 527 |
... |
| 528 |
|
| 529 |
3.3. drr_table(str) |
| 530 |
|
| 531 |
The name of the db table storing routing rules. |
| 532 |
|
| 533 |
Default value is “dr_rules”. |
| 534 |
|
| 535 |
Example 1.3. Set drr_table parameter |
| 536 |
... |
| 537 |
modparam("drouting", "drr_table", "rules") |
| 538 |
... |
| 539 |
|
| 540 |
3.4. drg_table(str) |
| 541 |
|
| 542 |
The name of the db table storing groups. |
| 543 |
|
| 544 |
Default value is “dr_groups”. |
| 545 |
|
| 546 |
Example 1.4. Set drg_table parameter |
| 547 |
... |
| 548 |
modparam("drouting", "drg_table", "groups") |
| 549 |
... |
| 550 |
|
| 551 |
3.5. drl_table(str) |
| 552 |
|
| 553 |
The name of the db table storing definitions of destination lists (to |
| 554 |
be used directly by the routing rules). You will have an identifier to |
| 555 |
a group of gateways instead of having all the members of the group as |
| 556 |
individual elements. Very useful to reuse a list of gateways in |
| 557 |
different places. |
| 558 |
|
| 559 |
Default value is “dr_gw_lists”. |
| 560 |
|
| 561 |
Example 1.5. Set drl_table parameter |
| 562 |
... |
| 563 |
modparam("drouting", "drl_table", "my_gw_lists") |
| 564 |
... |
| 565 |
|
| 566 |
3.6. sort_order (int) |
| 567 |
|
| 568 |
Defines how the destination list should be processed (ordering of the |
| 569 |
elements). Possible modes are |
| 570 |
* 0 - destination groups are ignored and all the destinations are |
| 571 |
tried in the given order; Ex: list 1,2;3,4,5;6 will lead to usage |
| 572 |
as 1,2,3,4,5,6 |
| 573 |
* 1 - the destinations from each group are randomly arranged (only |
| 574 |
the two first elements are randomly selected); groups do maintain |
| 575 |
their order (as given); the resulting list is used (with all the |
| 576 |
defined destinations). Ex: 1,2;3,4,5;6 -> randomizer -> (A) |
| 577 |
2,1;4,3,5;6 -> usage 2,1,4,3,5,6 (B) 1,2;3,5,4;6 -> usage |
| 578 |
1,2,3,5,4,6 |
| 579 |
* 2 - from each destination group, only a single destination is |
| 580 |
randomly selected; groups do maintain their order (as given); |
| 581 |
Ex: 1,2;3,4,5;6 -> randomizer -> |
| 582 |
(A) 2;4;6 -> usage 2,4,6 |
| 583 |
(B) 1;5;6 -> usage 1,5,6 |
| 584 |
It is ok to have repeating gateways in different groups. The module |
| 585 |
will take care internally in case of failure not to choose a |
| 586 |
gateway that was tried already. |
| 587 |
Ex: 1,2,3; 1,2,3; 1,2,3 -> no gateway will be chosen twice. So in |
| 588 |
case there are 2 failures, all the three gateways (1,2,3) will be |
| 589 |
tried in a random order. |
| 590 |
|
| 591 |
Default value is “0”. |
| 592 |
|
| 593 |
Example 1.6. Set sort_order parameter |
| 594 |
... |
| 595 |
modparam("drouting", "sort_order", 2) |
| 596 |
... |
| 597 |
|
| 598 |
3.7. ruri_avp (str) |
| 599 |
|
| 600 |
The name of the avp for storing Request URIs to be later used |
| 601 |
(alternative destinations for the current one). |
| 602 |
|
| 603 |
Default value is “NULL”. |
| 604 |
|
| 605 |
Example 1.7. Set ruri_avp parameter |
| 606 |
... |
| 607 |
modparam("drouting", "ruri_avp", '$avp(dr_ruri)') |
| 608 |
modparam("drouting", "ruri_avp", '$avp(i:33)') |
| 609 |
... |
| 610 |
|
| 611 |
3.8. attrs_avp (str) |
| 612 |
|
| 613 |
The name of the avp for storing the attribute of the current selected |
| 614 |
destination - once a new destination is selected (via the use_next_gw() |
| 615 |
function), the AVP will be updated with the attrs of the new used |
| 616 |
destination. |
| 617 |
|
| 618 |
Default value is “NULL”. |
| 619 |
|
| 620 |
Example 1.8. Set attrs_avp parameter |
| 621 |
... |
| 622 |
modparam("drouting", "attrs_avp", '$avp(dr_attrs)') |
| 623 |
modparam("drouting", "atrrs_avp", '$avp(i:67)') |
| 624 |
... |
| 625 |
|
| 626 |
3.9. use_domain (int) |
| 627 |
|
| 628 |
Flag to configure whether to use domain match when querying database |
| 629 |
for user's routing group. |
| 630 |
|
| 631 |
Default value is “1”. |
| 632 |
|
| 633 |
Example 1.9. Set use_domain parameter |
| 634 |
... |
| 635 |
modparam("drouting", "use_domain", 0) |
| 636 |
... |
| 637 |
|
| 638 |
3.10. drg_user_col (str) |
| 639 |
|
| 640 |
The name of the column in group db table where the username is stored. |
| 641 |
|
| 642 |
Default value is “username”. |
| 643 |
|
| 644 |
Example 1.10. Set drg_user_col parameter |
| 645 |
... |
| 646 |
modparam("drouting", "drg_user_col", "user") |
| 647 |
... |
| 648 |
|
| 649 |
3.11. drg_domain_col (str) |
| 650 |
|
| 651 |
The name of the column in group db table where the domain is stored. |
| 652 |
|
| 653 |
Default value is “domain”. |
| 654 |
|
| 655 |
Example 1.11. Set drg_domain_col parameter |
| 656 |
... |
| 657 |
modparam("drouting", "drg_domain_col", "host") |
| 658 |
... |
| 659 |
|
| 660 |
3.12. drg_grpid_col (str) |
| 661 |
|
| 662 |
The name of the column in group db table where the group id is stored. |
| 663 |
|
| 664 |
Default value is “groupid”. |
| 665 |
|
| 666 |
Example 1.12. Set drg_grpid_col parameter |
| 667 |
... |
| 668 |
modparam("drouting", "drg_grpid_col", "grpid") |
| 669 |
... |
| 670 |
|
| 671 |
3.13. fetch_rows (int) |
| 672 |
|
| 673 |
The number of rows that should be fetched from the result of a query in |
| 674 |
rules db table. |
| 675 |
|
| 676 |
Default value is “2000”. |
| 677 |
|
| 678 |
Example 1.13. Set fetch_rows parameter |
| 679 |
... |
| 680 |
modparam("drouting", "fetch_rows", 1500) |
| 681 |
... |
| 682 |
|
| 683 |
3.14. force_dns (int) |
| 684 |
|
| 685 |
Force DNS resolving of GW/destination names (if not IPs) during |
| 686 |
startup. If not enabled, the GW name will be blindly used during |
| 687 |
routing. |
| 688 |
|
| 689 |
Default value is “1 (enabled)”. |
| 690 |
|
| 691 |
Example 1.14. Set force_dns parameter |
| 692 |
... |
| 693 |
modparam("drouting", "force_dns", 0) |
| 694 |
... |
| 695 |
|
| 696 |
3.15. enable_keepalive (int) |
| 697 |
|
| 698 |
Enable monitoring of GW/destinations using keepalive module. |
| 699 |
Destinations found unavailable will not be used on do_routing() call. |
| 700 |
|
| 701 |
Default value is “0 (disabled)”. |
| 702 |
|
| 703 |
Example 1.15. Set enable_keepalive parameter |
| 704 |
... |
| 705 |
modparam("drouting", "enable_keepalive", 1) |
| 706 |
... |
| 707 |
|
| 708 |
4. Functions |
| 709 |
|
| 710 |
4.1. do_routing([groupID]) |
| 711 |
4.2. next_routing() |
| 712 |
4.3. use_next_gw() |
| 713 |
4.4. goes_to_gw([type]) |
| 714 |
4.5. is_from_gw([ type, [flag] ]) |
| 715 |
|
| 716 |
4.1. do_routing([groupID]) |
| 717 |
|
| 718 |
Function to trigger routing of the message according to the rules in |
| 719 |
the database table and the configured parameters. |
| 720 |
|
| 721 |
This function can be used from REQUEST_ROUTE and FAILURE_ROUTE. |
| 722 |
|
| 723 |
The module can take one optional parameter: the routing group the |
| 724 |
caller belongs to - this may be a static int value or a variable |
| 725 |
holding an int. If none specified, the function will automatically try |
| 726 |
to query the dr_group table to get the group id associated with the |
| 727 |
user in From URI. |
| 728 |
|
| 729 |
Example 1.16. do_routing usage |
| 730 |
... |
| 731 |
do_routing(); |
| 732 |
... |
| 733 |
do_routing("0"); |
| 734 |
... |
| 735 |
do_routing("$avp(i:10)"); |
| 736 |
|
| 737 |
4.2. next_routing() |
| 738 |
|
| 739 |
The function takes the next available destination (set by do_routing, |
| 740 |
as alternative destinations) and push it into RURI. Note that the |
| 741 |
function just sets the RURI (nothing more). |
| 742 |
|
| 743 |
If a new RURI is set, the used destination is removed from the pending |
| 744 |
set of alternative destinations. |
| 745 |
|
| 746 |
This function can be used from REQUEST_ROUTE and FAILURE_ROUTE. |
| 747 |
|
| 748 |
The function returns true only if a new RURI was set. False is returned |
| 749 |
is no other alternative destinations are found or in case of internal |
| 750 |
processing error. |
| 751 |
|
| 752 |
Example 1.17. next_routing usage |
| 753 |
... |
| 754 |
if (next_routing()) { |
| 755 |
t_relay(); |
| 756 |
exit; |
| 757 |
} |
| 758 |
... |
| 759 |
|
| 760 |
4.3. use_next_gw() |
| 761 |
|
| 762 |
Same as next_routing(). |
| 763 |
|
| 764 |
4.4. goes_to_gw([type]) |
| 765 |
|
| 766 |
Function returns true if the destination of the current request |
| 767 |
(destination URI or Request URI) points (as IP) to one of the gateways. |
| 768 |
There is no DNS lookups done if the domain part of the URI is not an |
| 769 |
IP. |
| 770 |
|
| 771 |
This function does not change anything in the message. |
| 772 |
|
| 773 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE and |
| 774 |
ONREPLY_ROUTE. |
| 775 |
|
| 776 |
The function can take two optional parameters: |
| 777 |
* type - GW/destination type to be checked |
| 778 |
|
| 779 |
Example 1.18. goes_to_gw usage |
| 780 |
... |
| 781 |
if (goes_to_gw("1")) { |
| 782 |
sl_send_reply("403","Forbidden"); |
| 783 |
exit; |
| 784 |
} |
| 785 |
... |
| 786 |
|
| 787 |
4.5. is_from_gw([ type, [flag] ]) |
| 788 |
|
| 789 |
The function checks if the sender of the message is a gateway from a |
| 790 |
group in drouting rules. |
| 791 |
|
| 792 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE and |
| 793 |
ONREPLY_ROUTE. |
| 794 |
|
| 795 |
The function can take two parameters: |
| 796 |
* type (mandatory) - GW/destination type to be checked |
| 797 |
* flags (optional) - if message is a request and the GW has a STRIP |
| 798 |
defined, then apply it if GW is source. |
| 799 |
|
| 800 |
Example 1.19. is_from_gw usage |
| 801 |
... |
| 802 |
if (is_from_gw("1") { |
| 803 |
} |
| 804 |
... |
| 805 |
if (is_from_gw("3","1") { |
| 806 |
} |
| 807 |
... |
| 808 |
|
| 809 |
5. RPC Commands |
| 810 |
|
| 811 |
5.1. drouting.reload |
| 812 |
|
| 813 |
5.1. drouting.reload |
| 814 |
|
| 815 |
Command to reload routing rules from database. |
| 816 |
|
| 817 |
It takes no parameter. |
| 818 |
|
| 819 |
RPC Command Format: |
| 820 |
kamctl rpc drouting.reload |
| 821 |
|
| 822 |
6. Installation |
| 823 |
|
| 824 |
The module requires 3 table in Kamailio database: dr_groups, |
| 825 |
dr_gateways, dr_rules. The SQL syntax to create them can be found in |
| 826 |
drouting-create.sql script in kamctl db directories. You can also find |
| 827 |
the complete database documentation on the project webpage, |
| 828 |
https://www.kamailio.org/docs/db-tables/kamailio-db-devel.html. |
| 829 |
|
| 830 |
Chapter 2. Developer Guide |
| 831 |
|
| 832 |
The module provides no function to be used by other Kamailio modules. |