[sr-dev] git:master: modules/ims_registrar_scscf: new mod_param subscription_expires_range
Richard Good
richard.good at smilecoms.com
Thu Oct 30 14:48:35 CET 2014
Module: sip-router
Branch: master
Commit: 6eb29ad5164400e1e66ac7eb106220b012b46115
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6eb29ad5164400e1e66ac7eb106220b012b46115
Author: Richard Good <richard.good at smilecoms.com>
Committer: Richard Good <richard.good at smilecoms.com>
Date: Thu Oct 30 15:47:25 2014 +0200
modules/ims_registrar_scscf: new mod_param subscription_expires_range
If set this parameter randomises the subscription expiry
Works exactly the same as usrloc expires_range param
---
.../doc/ims_registrar_scscf_admin.xml | 91 ++++++++++++++++++-
modules/ims_registrar_scscf/reg_mod.c | 2 +
modules/ims_registrar_scscf/registrar_notify.c | 18 ++++
modules/ims_registrar_scscf/save.c | 19 ++++
4 files changed, 125 insertions(+), 5 deletions(-)
diff --git a/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml b/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml
index 0964b5e..e80d6d0 100644
--- a/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml
+++ b/modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml
@@ -67,7 +67,7 @@
contact parameters, this value will be used for newly created S-CSCF
usrloc records. The parameter contains number of second to expire (for
example use 3600 for one hour). If it is set to a lower value than the
- “min_expires” parameter then it will be ignored. This
+ min_expires parameter then it will be ignored. This
parameter can be modified via ser config framework. A random value in a
specific interval can be selected by using the default_expires_range
parameter</para>
@@ -87,10 +87,10 @@
<title>default_expires_range (int)</title>
<para>This parameter specifies that the expiry used for newly created
- S-CSCF usrloc records are not fixed(when “default_expires”
- applies), but a random value in the interval
- “[default_expires-default_expires_range%,
- default_expires+default_expires_range%]”. The value is between 0
+ S-CSCF usrloc records are not fixed(when default_expires
+ applies), but a random value in the intervalrdq
+ [default_expires-default_expires_range%,
+ default_expires+default_expires_range%]. The value is between 0
and 100 and represent the maximim percentage from default_expires that
will be substracted or added when computing the value. Default in 0,
meaning default_expires is left unmodified. This parameter can be
@@ -144,6 +144,87 @@
...</programlisting>
</example>
</section>
+
+ <section>
+ <title>subscription_default_expires (int)</title>
+
+ <para>If the processed message contains neither Expires HFs nor expires
+ contact parameters, this value will be used for newly created subscriptions.
+ The parameter contains number of second to expire (for example use 3600 for one hour).
+ If it is set to a lower value than the subscription_min_expires parameter
+ then it will be ignored. A random value in a specific interval can be selected
+ by using the subscription_expires_range parameter</para>
+
+ <para><emphasis> Default value is 3600. </emphasis></para>
+
+ <example>
+ <title>Set <varname>subscription_default_expires</varname> parameter</title>
+
+ <programlisting format="linespecific">...
+ modparam("ims_registrar_scscf", "subscription_default_expires", 3600)
+...</programlisting>
+ </example>
+ </section>
+
+ <section>
+ <title>subscription_expires_range (int)</title>
+
+ <para>This parameter specifies that the expiry used for newly created
+ subscriptions are not fixed(when subscription_default_expires
+ applies), but a random value in the interval
+ [subscription_default_expires-subscription_expires_range%,
+ subscription_default_expires+subscription_expires_range%].
+ The value is between 0 and 100 and represent the maximim percentage
+ from subscription_default_expires that will be substracted or added when
+ computing the value. Default in 0, meaning subscription_default_expires is
+ left unmodified.</para>
+
+ <para><emphasis> Default value is 0. </emphasis></para>
+
+ <example>
+ <title>Set <varname>subscription_expires_range </varname>parameter</title>
+
+ <programlisting format="linespecific">...
+ modparam("ims_registrar_scscf", "subscription_expires_range", 30) # +- 30% from subscription_expires_range
+...</programlisting>
+ </example>
+ </section>
+
+ <section>
+ <title>subscription_min_expires (int)</title>
+
+ <para>The minimum expires value of a subscription, values lower than this
+ minimum will be automatically set to the minimum. Value 0 disables the
+ checking.</para>
+
+ <para><emphasis> Default value is 10. </emphasis></para>
+
+ <example>
+ <title>Set <varname>subscription_min_expires</varname>parameter</title>
+
+ <programlisting format="linespecific">...
+ modparam("subscription_min_expires", "min_expires", 1800)
+...</programlisting>
+ </example>
+ </section>
+
+ <section>
+ <title>subscription_max_expires (int)</title>
+
+ <para>The maximum expires value of a subscription, values higher than this
+ maximum will be automatically set to the maximum. Value 0 disables the
+ checking.</para>
+
+ <para><emphasis> Default value is 1000000. </emphasis></para>
+
+ <example>
+ <title>Set <varname>subscription_max_expires</varname>parameter</title>
+
+ <programlisting format="linespecific">...
+ modparam("ims_registrar_scscf", "subscription_max_expires", 3600)
+...</programlisting>
+ </example>
+ </section>
<section>
<title>user_data_dtd (string)</title>
diff --git a/modules/ims_registrar_scscf/reg_mod.c b/modules/ims_registrar_scscf/reg_mod.c
index 3a39ec1..d412e37 100644
--- a/modules/ims_registrar_scscf/reg_mod.c
+++ b/modules/ims_registrar_scscf/reg_mod.c
@@ -153,6 +153,7 @@ str sock_hdr_name = {0, 0};
int subscription_default_expires = 3600; /**< the default value for expires if none found*/
int subscription_min_expires = 10; /**< minimum subscription expiration time */
int subscription_max_expires = 1000000; /**< maximum subscription expiration time */
+int subscription_expires_range = 0;
extern reg_notification_list *notification_list; /**< list of notifications for reg to be sent */
@@ -246,6 +247,7 @@ static param_export_t params[] = {
{"subscription_min_expires", INT_PARAM, &subscription_min_expires},
{"subscription_max_expires", INT_PARAM, &subscription_max_expires},
{"ue_unsubscribe_on_dereg", INT_PARAM, &ue_unsubscribe_on_dereg},
+ {"subscription_expires_range", INT_PARAM, &subscription_expires_range},
{"user_data_always", INT_PARAM, &user_data_always},
{0, 0, 0}
diff --git a/modules/ims_registrar_scscf/registrar_notify.c b/modules/ims_registrar_scscf/registrar_notify.c
index 93c0e2d..17a1266 100644
--- a/modules/ims_registrar_scscf/registrar_notify.c
+++ b/modules/ims_registrar_scscf/registrar_notify.c
@@ -91,6 +91,22 @@ static str ctype_hdr1 = {"Content-Type: ", 14};
static str ctype_hdr2 = {"\r\n", 2};
extern int ue_unsubscribe_on_dereg;
+extern int subscription_expires_range;
+
+/* \brief
+ * Return randomized expires between expires-range% and expires.
+ * RFC allows only value less or equal to the one provided by UAC.
+ */
+
+static inline int randomize_expires( int expires, int range )
+{
+ /* if no range is given just return expires */
+ if(range == 0) return expires;
+
+ int range_min = expires - (float)range/100 * expires;
+
+ return range_min + (float)(rand()%100)/100 * ( expires - range_min );
+}
int notify_init() {
notification_list = shm_malloc(sizeof (reg_notification_list));
@@ -1055,6 +1071,8 @@ int subscribe_to_reg(struct sip_msg *msg, char *_t, char *str2) {
if (expires < subscription_min_expires) expires = subscription_min_expires;
if (expires > subscription_max_expires) expires = subscription_max_expires;
+
+ expires = randomize_expires(expires, subscription_expires_range);
get_act_time();
expires_time = expires + act_time;
diff --git a/modules/ims_registrar_scscf/save.c b/modules/ims_registrar_scscf/save.c
index 3066019..5189f7f 100644
--- a/modules/ims_registrar_scscf/save.c
+++ b/modules/ims_registrar_scscf/save.c
@@ -86,6 +86,22 @@ extern int store_data_on_dereg; /**< should we store SAR user data on de-registr
extern int ue_unsubscribe_on_dereg;
extern int user_data_always;
+
+/* \brief
+ * Return randomized expires between expires-range% and expires.
+ * RFC allows only value less or equal to the one provided by UAC.
+ */
+static inline int randomize_expires( int expires, int range )
+{
+ /* if no range is given just return expires */
+ if(range == 0) return expires;
+
+ int range_min = expires - (float)range/100 * expires;
+
+ return range_min + (float)(rand()%100)/100 * ( expires - range_min );
+}
+
+
/*! \brief
* Calculate absolute expires value per contact as follows:
* 1) If the contact has expires value, use the value. If it
@@ -124,6 +140,9 @@ static inline int calc_contact_expires(contact_t *c, unsigned int expires_hdr, i
r = default_registrar_cfg.em_min_expires;
end:
+
+ r = randomize_expires(r, default_registrar_cfg.default_expires_range);
+
LM_DBG("Calculated expires for contact is %d\n", r);
return time(NULL) + r;
}
More information about the sr-dev
mailing list