Module: sip-router
Branch: master
Commit: 0d8cec6b6cd9027ef7313608db7e27667643fdf6
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0d8cec6…
Author: Anca Vamanu <anca.vamanu(a)1and1.ro>
Committer: Anca Vamanu <anca.vamanu(a)1and1.ro>
Date: Wed Mar 20 15:39:12 2013 +0200
modules/drouting Improvement for do_routing in failure route
Improvement for sort_order 2 : if the failure groups have repeating
gateways the module will take care internally not to try again a gateway
that was already tried.
---
modules/drouting/README | 37 ++++++++++++++++++------------
modules/drouting/doc/drouting_admin.xml | 15 ++++++++++++
modules/drouting/drouting.c | 38 +++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 15 deletions(-)
diff --git a/modules/drouting/README b/modules/drouting/README
index 5fee2f2..2977033 100644
--- a/modules/drouting/README
+++ b/modules/drouting/README
@@ -304,18 +304,18 @@ Chapter 1. Admin Guide
draft 09):
Table 1.4. Time recurrence attributes
- Attribute Description
- dastard Start of interval (RFC 2445 DATE-TIME)
- duration Length of interval (RFC 2445 DURATION)
- freq Frequency of recurrence (secondly,minutely,hourly, daily,weekly,
- monthly, or yearly).
- until bound of recurrence (RFC 2445 DATE-TIME)
- interval How often the recurrence repeats
- byday List of days of the week
- bymonthday List of days of the month
- byyearday List of days of the year
- byweekno List of weeks of the year
- bymonth List of months of the year
+ Attribute Description
+ dastard Start of interval (RFC 2445 DATE-TIME)
+ duration Length of interval (RFC 2445 DURATION)
+ freq Frequency of recurrence (secondly,minutely,hourly, daily,weekly,
+ monthly, or yearly).
+ until bound of recurrence (RFC 2445 DATE-TIME)
+ interval How often the recurrence repeats
+ byday List of days of the week
+ bymonthday List of days of the month
+ byyearday List of days of the year
+ byweekno List of weeks of the year
+ bymonth List of months of the year
The value stored in database has the format of:
<dtstart>|<duration>|<freq>|<until>|<interval>|<byday>|<bymonthday>
|<byyearday>|<byweekno>|<bymonth>
@@ -570,9 +570,16 @@ modparam("drouting", "drl_table",
"my_gw_lists")
destinations). Ex: 1,2;3,4,5;6 -> randomizer -> (A) 2,1;4,3,5;6 ->
usage 2,1,4,3,5,6 (B) 1,2;3,5,4;6 -> usage 1,2,3,5,4,6
* 2 - from each destination group, only a single destination is
- randomly selected; groups do maintain their order (as given); Ex:
- 1,2;3,4,5;6 -> randomizer -> (A) 2;4;6 -> usage 2,4,6 (B) 1;5;6 ->
- usage 1,5,6
+ randomly selected; groups do maintain their order (as given);
+ Ex: 1,2;3,4,5;6 -> randomizer ->
+ (A) 2;4;6 -> usage 2,4,6
+ (B) 1;5;6 -> usage 1,5,6
+ It is ok to have repeating gateways in different groups. The module
+ will take care internally in case of failure not to choose a
+ gateway that was tried already.
+ Ex: 1,2,3; 1,2,3; 1,2,3 -> no gateway will be choosen twice. So in
+ case there are 2 failures, all the three gateways (1,2,3) will be
+ tried in a random order.
Default value is “0”.
diff --git a/modules/drouting/doc/drouting_admin.xml
b/modules/drouting/doc/drouting_admin.xml
index 3dbcdd9..7bde362 100644
--- a/modules/drouting/doc/drouting_admin.xml
+++ b/modules/drouting/doc/drouting_admin.xml
@@ -942,9 +942,24 @@ modparam("drouting", "drl_table",
"my_gw_lists")
<emphasis>2</emphasis> - from each destination group, only a
single destination is randomly selected; groups do maintain their
order (as given);
+ <para>
Ex: 1,2;3,4,5;6 -> randomizer ->
+ </para>
+ <para>
(A) 2;4;6 -> usage 2,4,6
+ </para>
+ <para>
(B) 1;5;6 -> usage 1,5,6
+ </para>
+ <para>
+ It is ok to have repeating gateways in different groups. The module will
+ take care internally in case of failure not to choose a gateway that
+ was tried already.
+ </para>
+ <para>
+ Ex: 1,2,3; 1,2,3; 1,2,3 -> no gateway will be choosen twice. So in case there
+ are 2 failures, all the three gateways (1,2,3) will be tried in a random order.
+ </para>
</listitem>
</itemizedlist>
</para>
diff --git a/modules/drouting/drouting.c b/modules/drouting/drouting.c
index 43fd73e..7289085 100644
--- a/modules/drouting/drouting.c
+++ b/modules/drouting/drouting.c
@@ -646,6 +646,20 @@ static int use_next_gw(struct sip_msg* msg)
return 1;
}
+int dr_already_choosen(rt_info_t* rt_info, int* local_gwlist, int lgw_size, int check)
+{
+ int l;
+
+ for ( l = 0; l<lgw_size; l++ ) {
+ if ( rt_info->pgwl[local_gwlist[l]].pgw == rt_info->pgwl[check].pgw ) {
+ LM_INFO("Gateway already choosen %.*s, local_gwlist[%d]=%d, %d\n",
+ rt_info->pgwl[check].pgw->ip.len, rt_info->pgwl[check].pgw->ip.s, l,
local_gwlist[l], check);
+ return 1;
+ }
+ }
+
+ return 0;
+}
static int do_routing(struct sip_msg* msg, dr_group_t *drg)
{
@@ -806,6 +820,30 @@ again:
}
}
}
+
+ if ( sort_order == 2 ) {
+ /* check not to use the same gateway as before */
+ if ( t>1 ) {
+ /* check if all in the current set were already chosen */
+ if (i-j <= t-1) {
+ for( l = j; l< i; l++) {
+ if ( ! dr_already_choosen(rt_info, local_gwlist, t-1, l) )
+ break;
+ }
+ if ( l == i ) {
+ LM_INFO("All gateways in group from %d - %d were already used\n", j,
i);
+ t--; /* jump over this group, nothing to choose here */
+ j=i; continue;
+ }
+ }
+ while ( dr_already_choosen(rt_info, local_gwlist, t-1, local_gwlist[t-1]) ) {
+ local_gwlist[t-1] = j + rand()%(i-j);
+ }
+ }
+ LM_DBG("The %d gateway is %.*s [%d]\n", t,
rt_info->pgwl[local_gwlist[t-1]].pgw->ip.len,
+ rt_info->pgwl[local_gwlist[t-1]].pgw->ip.s, local_gwlist[t-1]);
+ }
+
/* next group starts from i */
j=i;
}