Skip to content

Commit

Permalink
dialog: add bin profiles replication
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jun 12, 2015
1 parent 8450630 commit 307c593
Show file tree
Hide file tree
Showing 6 changed files with 876 additions and 39 deletions.
170 changes: 140 additions & 30 deletions modules/dialog/README
Expand Up @@ -75,6 +75,12 @@ Vladut-Stefan Paiu
1.6.43. profile_timeout (int)
1.6.44. accept_replicated_dialogs (int)
1.6.45. replicate_dialogs_to (string)
1.6.46. accept_replicated_profiles (int)
1.6.47. replicate_profiles_to (string)
1.6.48. replicate_profiles_buffer (string)
1.6.49. replicate_profiles_check (string)
1.6.50. replicate_profiles_timer (string)
1.6.51. replicate_profiles_expire (string)

1.7. Exported Functions

Expand Down Expand Up @@ -119,6 +125,7 @@ Vladut-Stefan Paiu
1.9.7. dlg_db_sync
1.9.8. dlg_restore_db
1.9.9. list_all_profiles
1.9.10. profile_bin_status

1.10. Exported pseudo-variables

Expand Down Expand Up @@ -192,21 +199,27 @@ Vladut-Stefan Paiu
1.43. Set profile_timeout parameter
1.44. Set accept_replicated_dialogs parameter
1.45. Set replicate_dialogs_to parameter
1.46. create_dialog() usage
1.47. match_dialog() usage
1.48. validate_dialog() usage
1.49. fix_route_dialog() usage
1.50. get_dialog_info usage
1.51. set_dlg_profile usage
1.52. unset_dlg_profile usage
1.53. is_in_profile usage
1.54. get_profile_size usage
1.55. set_dlg_flag usage
1.56. test_and_set_dlg_flag usage
1.57. reset_dlg_flag usage
1.58. is_dlg_flag_set usage
1.59. store_dlg_value usage
1.60. fetch_dlg_value usage
1.46. Set accept_replicated_profiles parameter
1.47. Set replicate_profiles_to parameter
1.48. Set replicate_profiles_buffer parameter
1.49. Set replicate_profiles_check parameter
1.50. Set replicate_profiles_timer parameter
1.51. Set replicate_profiles_expire parameter
1.52. create_dialog() usage
1.53. match_dialog() usage
1.54. validate_dialog() usage
1.55. fix_route_dialog() usage
1.56. get_dialog_info usage
1.57. set_dlg_profile usage
1.58. unset_dlg_profile usage
1.59. is_in_profile usage
1.60. get_profile_size usage
1.61. set_dlg_flag usage
1.62. test_and_set_dlg_flag usage
1.63. reset_dlg_flag usage
1.64. is_dlg_flag_set usage
1.65. store_dlg_value usage
1.66. fetch_dlg_value usage

Chapter 1. Admin Guide

Expand Down Expand Up @@ -293,6 +306,10 @@ Chapter 1. Admin Guide
several statistics regarding the number of replication packets
sent/received.

Profiles replication can also be achieved using the
accept_replicated_profiles and replicate_profiles_to
parameters.

1.5. Dependencies

1.5.1. OpenSIPS Modules
Expand Down Expand Up @@ -887,6 +904,86 @@ modparam("dialog", "accept_replicated_dialogs", 1)
modparam("dialog", "replicate_dialogs_to", "10.0.0.150:5062")
...

1.6.46. accept_replicated_profiles (int)

Registers the dialog module to the OpenSIPS Binary Internal
Interface for profiles replication.

Default value is 0 (not registered).

Example 1.46. Set accept_replicated_profiles parameter
...
modparam("dialog", "accept_replicated_profiles", 1)
...

1.6.47. replicate_profiles_to (string)

Adds a new profiles replication destination. The destination
will receive all dialog-related events (creation, updating and
deletion) over UDP, using the Binary Internal Interface.

Default value is “null” (no replication destinations).

Example 1.47. Set replicate_profiles_to parameter
...
modparam("dialog", "replicate_profiles_to", "10.0.0.150:5062")
...

1.6.48. replicate_profiles_buffer (string)

Used to specify the length of the buffer used by the binary
replication, in bytes. Usually this should be big enough to
hold as much data as possible, but small enough to avoid UDP
fragmentation. The recommended value is the smallest MTU
between all the replication instances.

Default value is 1400 bytes.

Example 1.48. Set replicate_profiles_buffer parameter
...
modparam("dialog", "replicate_profiles_buffer", 500)
...

1.6.49. replicate_profiles_check (string)

Timer in seconds, used to specify how often the module should
check whether old, replicated profiles values are obsolete and
should be removed. should replicate its profiles to the other
instances.

Default value is 10 s.

Example 1.49. Set replicate_profiles_check parameter
...
modparam("dialog", "replicate_profiles_check", 100)
...

1.6.50. replicate_profiles_timer (string)

Timer in milliseconds, used to specify how often the module
should replicate its profiles to the other instances.

Default value is 10 ms.

Example 1.50. Set replicate_profiles_timer parameter
...
modparam("dialog", "replicate_profiles_timer", 100)
...

1.6.51. replicate_profiles_expire (string)

Timer in seconds, used to specify when the profiles counters
received from a different instance should no longer be taken
into account. This is used to prevent obsolete values, in case
an instance stops replicating its counters.

Default value is 10 s.

Example 1.51. Set replicate_profiles_expire parameter
...
modparam("dialog", "replicate_profiles_expire", 10)
...

1.7. Exported Functions

1.7.1. create_dialog()
Expand All @@ -907,7 +1004,7 @@ modparam("dialog", "replicate_dialogs_to", "10.0.0.150:5062")

This function can be used from REQUEST_ROUTE.

Example 1.46. create_dialog() usage
Example 1.52. create_dialog() usage
...
create_dialog();
...
Expand Down Expand Up @@ -942,7 +1039,7 @@ create_dialog("B");

This function can be used from REQUEST_ROUTE.

Example 1.47. match_dialog() usage
Example 1.53. match_dialog() usage
...
if (has_totag()) {
loose_route();
Expand Down Expand Up @@ -972,7 +1069,7 @@ create_dialog("B");

This function can be used from REQUEST_ROUTE.

Example 1.48. validate_dialog() usage
Example 1.54. validate_dialog() usage
...
if (has_totag()) {
loose_route();
Expand All @@ -994,7 +1091,7 @@ create_dialog("B");

This function can be used from REQUEST_ROUTE.

Example 1.49. fix_route_dialog() usage
Example 1.55. fix_route_dialog() usage
...
if (has_totag()) {
loose_route();
Expand Down Expand Up @@ -1032,7 +1129,7 @@ create_dialog("B");
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE, FAILURE_ROUTE and LOCAL_ROUTE.

Example 1.50. get_dialog_info usage
Example 1.56. get_dialog_info usage
...
if ( get_dialog_info("callee","$var(x)","caller","$fu") ) {
xlog("caller $fU has another ongoing, talking to callee $var(x)\
Expand Down Expand Up @@ -1065,7 +1162,7 @@ $dlg_val(callee) = $ru;
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.51. set_dlg_profile usage
Example 1.57. set_dlg_profile usage
...
set_dlg_profile("inbound_call");
set_dlg_profile("caller","$fu");
Expand All @@ -1087,7 +1184,7 @@ set_dlg_profile("caller","$fu");
This function can be used from BRANCH_ROUTE, REPLY_ROUTE and
FAILURE_ROUTE.

Example 1.52. unset_dlg_profile usage
Example 1.58. unset_dlg_profile usage
...
unset_dlg_profile("inbound_call");
unset_dlg_profile("caller","$fu");
Expand All @@ -1114,7 +1211,7 @@ unset_dlg_profile("caller","$fu");
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.53. is_in_profile usage
Example 1.59. is_in_profile usage
...
if (is_in_profile("inbound_call")) {
log("this request belongs to a inbound call\n");
Expand Down Expand Up @@ -1145,7 +1242,7 @@ if (is_in_profile("caller","XX")) {
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.54. get_profile_size usage
Example 1.60. get_profile_size usage
...
get_profile_size("inbound_call","$avp(size)");
xlog("currently there are $avp(size) inbound calls\n");
Expand All @@ -1168,7 +1265,7 @@ xlog("currently, the user %fu has $avp(size) active outgoing calls\n");
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.55. set_dlg_flag usage
Example 1.61. set_dlg_flag usage
...
set_dlg_flag("3");
...
Expand All @@ -1189,7 +1286,7 @@ set_dlg_flag("3");
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.56. test_and_set_dlg_flag usage
Example 1.62. test_and_set_dlg_flag usage
...
test_and_set_dlg_flag("3", "0");
...
Expand All @@ -1208,7 +1305,7 @@ test_and_set_dlg_flag("3", "0");
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.57. reset_dlg_flag usage
Example 1.63. reset_dlg_flag usage
...
reset_dlg_flag("16");
...
Expand All @@ -1227,7 +1324,7 @@ reset_dlg_flag("16");
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.58. is_dlg_flag_set usage
Example 1.64. is_dlg_flag_set usage
...
if (is_dlg_flag_set("16")) {
xlog("dialog flag 16 is set\n");
Expand All @@ -1252,7 +1349,7 @@ if (is_dlg_flag_set("16")) {
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.59. store_dlg_value usage
Example 1.65. store_dlg_value usage
...
store_dlg_value("inv_src_ip","$si");
store_dlg_value("account type","prepaid");
Expand All @@ -1278,7 +1375,7 @@ $dlg_val(account_type) = "prepaid";
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
REPLY_ROUTE and FAILURE_ROUTE.

Example 1.60. fetch_dlg_value usage
Example 1.66. fetch_dlg_value usage
...
fetch_dlg_value("inv_src_ip","$avp(2)");
fetch_dlg_value("account type","$var(account)");
Expand Down Expand Up @@ -1523,6 +1620,19 @@ $var(account) = $dlg_val(account_type);
:list_all_profiles:_reply_fifo_file_
_empty_line_

1.9.10. profile_bin_status

Dumps each destination used for profiles replication, as well
as the timestamp of the last message received from them.

Name: profile_bin_status

Parameters: none

MI FIFO Command Format:
:profile_bin_status:_reply_fifo_file_
_empty_line_

1.10. Exported pseudo-variables

1.10.1. $DLG_count
Expand Down
18 changes: 17 additions & 1 deletion modules/dialog/dialog.c
Expand Up @@ -67,6 +67,7 @@
#include "dlg_profile.h"
#include "dlg_vals.h"
#include "dlg_replication.h"
#include "dlg_repl_profile.h"

static int mod_init(void);
static int child_init(int rank);
Expand Down Expand Up @@ -115,6 +116,7 @@ str cdb_url = {0,0};

/* dialog replication using the bpi interface */
int accept_replicated_dlg=0;
int accept_repl_profiles=0;
struct replication_dest *replication_dests=NULL;

static int pv_get_dlg_count( struct sip_msg *msg, pv_param_t *param,
Expand Down Expand Up @@ -266,6 +268,13 @@ static param_export_t mod_params[]={
{ "accept_replicated_dialogs",INT_PARAM, &accept_replicated_dlg },
{ "replicate_dialogs_to", STR_PARAM|USE_FUNC_PARAM,
(void *)add_replication_dest },
{ "accept_replicated_profiles",INT_PARAM, &accept_repl_profiles },
{ "replicate_profiles_timer", INT_PARAM, &repl_prof_utimer },
{ "replicate_profiles_check", INT_PARAM, &repl_prof_timer_check },
{ "replicate_profiles_buffer",INT_PARAM, &repl_prof_buffer_th },
{ "replicate_profiles_expire",INT_PARAM, &repl_prof_timer_expire},
{ "replicate_profiles_to", STR_PARAM|USE_FUNC_PARAM,
(void *)repl_prof_dest },
{ 0,0,0 }
};

Expand Down Expand Up @@ -296,6 +305,8 @@ static mi_export_t mi_cmds[] = {
{ "profile_list_dlgs", 0, mi_profile_list, 0, 0, 0},
{ "profile_get_values", 0, mi_get_profile_values, 0, 0, 0},
{ "list_all_profiles", 0, mi_list_all_profiles, 0, 0, 0},
{ "profile_bin_status", 0, mi_profiles_bin_status,
MI_NO_INPUT_FLAG, 0, 0},
{ 0, 0, 0, 0, 0, 0}
};

Expand Down Expand Up @@ -808,7 +819,7 @@ static int mod_init(void)
return -1;
}

if (accept_replicated_dlg &&
if ((accept_replicated_dlg || accept_repl_profiles) &&
bin_register_cb("dialog", receive_binary_packet) < 0) {
LM_ERR("Cannot register binary packet callback!\n");
return -1;
Expand Down Expand Up @@ -858,6 +869,11 @@ static int mod_init(void)
return -1;
}

if (repl_prof_init() < 0) {
LM_ERR("cannot initialize profile replication\n");
return -1;
}

/* if a database should be used to store the dialogs' information */
if (dlg_db_mode==DB_MODE_NONE) {
db_url.s = 0; db_url.len = 0;
Expand Down

1 comment on commit 307c593

@brettnem
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit appears to reference the file: dlg_repl_profile.h which does not exist?

Please sign in to comment.