Skip to content

Commit

Permalink
Revert "rtpengine: Fix comments for hastable"
Browse files Browse the repository at this point in the history
This reverts commit 44c1911.
  • Loading branch information
linuxmaniac committed Nov 23, 2015
1 parent b2c5686 commit f52bace
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 124 deletions.
19 changes: 9 additions & 10 deletions modules/rtpengine/doc/rtpengine_admin.xml
Expand Up @@ -361,7 +361,7 @@ modparam("rtpengine", "read_sdp_pv", "$var(sdp)")
route {
...
$var(sdp) = $rb + "a=foo:bar\r\n";
rtpengine_manage();
rtpproxy_manage();
}
</programlisting>
</example>
Expand All @@ -386,7 +386,7 @@ modparam("rtpengine", "write_sdp_pv", "$avp(sdp)")
...
route {
...
rtpengine_manage();
rtpproxy_manage();
set_body("$avp(sdp)a=baz123\r\n", "application/sdp");
}
</programlisting>
Expand All @@ -406,7 +406,7 @@ route {
<title>Set <varname>rtp_inst_pvar</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("rtpengine", "rtp_inst_pvar", "$avp(RTP_INSTANCE)")
modparam("rtpproxy", "rtp_inst_pvar", "$avp(RTP_INSTANCE)")
...
</programlisting>
</example>
Expand All @@ -424,7 +424,7 @@ modparam("rtpengine", "rtp_inst_pvar", "$avp(RTP_INSTANCE)")
<title>Set <varname>hash_table_size</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("rtpengine", "hash_table_size", "123")
modparam("rtpproxy", "hash_table_size", "123")
...
</programlisting>
</example>
Expand All @@ -434,24 +434,23 @@ modparam("rtpengine", "hash_table_size", "123")
<title><varname>hash_table_tout</varname> (integer)</title>
<para>
Number of seconds after an rtpengine hash table entry is marked for deletion.
By default, this parameter is set to 3600 (seconds).
By default, this parameter is set to 120 (seconds).
</para>
<para>
To maintain information about a selected rtp machine node, for a given call, entries are added in a hashtable of (callid, node) pairs.
When command comes, lookup callid. If found, return chosen node. If not found, choose a new node, insert it in the hastable and return the chosen node.
When "offer" comes, insert new entry in the hastable.
When subsequent commands come, lookup callid and return chosen node.
When "delete" comes, remove old entry from hashtable.
</para>
<para>
NOTE: In the current implementation, the actual deletion happens <emphasis>on the fly</emphasis>,
while insert/remove/lookup the hastable, <emphasis>only</emphasis> for the entries in the insert/remove/lookup path.
</para>
<para>
NOTE: When configuring this parameter, one should consider maximum call time VS share memory for unfinished calls.
</para>
<example>
<title>Set <varname>hash_table_tout</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("rtpengine", "hash_table_tout", "300")
modparam("rtpproxy", "hash_table_tout", "300")
...
</programlisting>
</example>
Expand Down
97 changes: 40 additions & 57 deletions modules/rtpengine/rtpengine.c
Expand Up @@ -218,7 +218,6 @@ static int rtpp_test_ping(struct rtpp_node *node);

/* Pseudo-Variables */
static int pv_get_rtpstat_f(struct sip_msg *, pv_param_t *, pv_value_t *);
static int set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri);

/*mi commands*/
static struct mi_root* mi_enable_rtp_proxy(struct mi_root* cmd_tree, void* param);
Expand All @@ -236,7 +235,7 @@ static pid_t mypid;
static unsigned int myseqn = 0;
static str extra_id_pv_param = {NULL, 0};
static char *setid_avp_param = NULL;
static int hash_table_tout = 3600;
static int hash_table_tout = 120;
static int hash_table_size = 256;

static char ** rtpp_strings=0;
Expand Down Expand Up @@ -2285,7 +2284,6 @@ select_rtpp_node_new(str callid, int do_test, int op)
int was_forced = 0;

/* XXX Use quick-and-dirty hashing algo */
sum = 0;
for(i = 0; i < callid.len; i++)
sum += callid.s[i];
sum &= 0xff;
Expand Down Expand Up @@ -2349,38 +2347,26 @@ select_rtpp_node_new(str callid, int do_test, int op)
goto retry;
}

/* build the entry */
/* build hash table entry */
struct rtpengine_hash_entry *entry = shm_malloc(sizeof(struct rtpp_node));
if (!entry) {
LM_ERR("rtpengine hash table fail to create entry for calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
return node;
}

/* fill the entry */
if (shm_str_dup(&entry->callid, &callid) < 0) {
LM_ERR("rtpengine hash table fail to duplicate calllen=%d callid=%.*s\n",
LM_ERR("rtpengine hash table fail to duplicate calllen=%d callid=%.*s",
callid.len, callid.len, callid.s);
shm_free(entry);
return node;
}
entry->node = node;
entry->next = NULL;
entry->tout = get_ticks() + hash_table_tout;

/* insert the key<->entry from the hashtable */
/* Insert the key<->entry from the hashtable */
if (!rtpengine_hash_table_insert(&callid, entry)) {
LM_ERR("rtpengine hash table fail to insert node=%.*s for calllen=%d callid=%.*s\n",
LM_ERR("rtpengine hash table fail to insert node=%.*s for calllen=%d callid=%.*s",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
shm_free(entry->callid.s);
shm_free(entry);
return node;
} else {
LM_DBG("rtpengine hash table insert node=%.*s for calllen=%d callid=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
}

/* return selected node */
/* Return selected node */
return node;
}

Expand All @@ -2391,51 +2377,27 @@ static struct rtpp_node *
select_rtpp_node_old(str callid, int do_test, int op)
{
struct rtpp_node *node = NULL;
struct rtpengine_hash_entry *entry = NULL;

node = rtpengine_hash_table_lookup(&callid);
entry = rtpengine_hash_table_lookup(&callid);
if (!entry) {
LM_ERR("rtpengine hash table lookup failed to find entry for calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
} else {
LM_DBG("rtpengine hash table lookup find entry for calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
node = entry->node;
}

if (!node) {
LM_NOTICE("rtpengine hash table lookup failed to find node for calllen=%d callid=%.*s\n",
LM_ERR("rtpengine hash table lookup failed to find node for calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
return NULL;
} else {
LM_DBG("rtpengine hash table lookup find node=%.*s for calllen=%d callid=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
}

return node;
}

/*
* Main balancing routine. This DO try to keep the same proxy for
* the call if some proxies were disabled or enabled (e.g. kamctl command)
*/
static struct rtpp_node *
select_rtpp_node(str callid, int do_test, int op)
{
struct rtpp_node *node = NULL;

if(!active_rtpp_set) {
LM_ERR("script error - no valid set selected\n");
return NULL;
}

// lookup node
node = select_rtpp_node_old(callid, do_test, op);

// check node
if (!node) {
// run the selection algorithm
node = select_rtpp_node_new(callid, do_test, op);

// check node
if (!node) {
LM_ERR("rtpengine failed to select new for calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
return NULL;
}
}

// if node enabled, return it
if (!node->rn_disabled) {
return node;
Expand All @@ -2458,6 +2420,28 @@ select_rtpp_node(str callid, int do_test, int op)
return NULL;
}

/*
* Main balancing routine. This DO try to keep the same proxy for
* the call if some proxies were disabled or enabled (e.g. kamctl command)
*/
static struct rtpp_node *
select_rtpp_node(str callid, int do_test, int op)
{
if(!active_rtpp_set) {
LM_ERR("script error - no valid set selected\n");
return NULL;
}

// calculate and choose a node
if (op == OP_OFFER) {
// run the selection algorithm
return select_rtpp_node_new(callid, do_test, op);
} else {
// lookup the hastable (key=callid value=node) and get the old node
return select_rtpp_node_old(callid, do_test, op);
}
}

static int
get_extra_id(struct sip_msg* msg, str *id_str) {
if(msg==NULL || extra_id_pv==NULL || id_str==NULL) {
Expand Down Expand Up @@ -2874,8 +2858,7 @@ pv_get_rtpstat_f(struct sip_msg *msg, pv_param_t *param,
return rtpengine_rtpp_set_wrap(msg, rtpengine_rtpstat_wrap, parms, 1);
}

static int
set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri) {
int set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri) {
pv_value_t val;

if (rtp_inst_pvar == NULL)
Expand Down
1 change: 1 addition & 0 deletions modules/rtpengine/rtpengine.h
Expand Up @@ -61,6 +61,7 @@ struct rtpp_set_head{
struct rtpp_set *get_rtpp_set(int set_id);
int add_rtpengine_socks(struct rtpp_set * rtpp_list, char * rtpproxy);

int set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri);

int init_rtpproxy_db(void);

Expand Down

0 comments on commit f52bace

Please sign in to comment.