Skip to content

Commit

Permalink
rtpengine: kamctl fifo nh_show_hash_total
Browse files Browse the repository at this point in the history
Print the total number of hash entries in the hash table, at the given moment.
Updated doku.
  • Loading branch information
Stefan Mititelu committed Nov 9, 2015
1 parent 7375d0b commit 74fdbe2
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 12 deletions.
17 changes: 17 additions & 0 deletions modules/rtpengine/doc/rtpengine_admin.xml
Expand Up @@ -1041,6 +1041,23 @@ $ &ctltool; fifo nh_ping_rtpp all
</programlisting>
</example>
</section>

<section id="rtpengine.m.nh_show_hash_total">
<title><function moreinfo="none">nh_show_hash_total</function></title>
<para>
Print the total number of hash entries in the hash table at a given moment.
</para>
<example>
<title>
<function moreinfo="none">nh_show_hash_total</function> usage</title>
<programlisting format="linespecific">
...
$ &ctltool; fifo nh_show_hash_total
...
</programlisting>
</example>
</section>

</section>

</chapter>
Expand Down
64 changes: 54 additions & 10 deletions modules/rtpengine/rtpengine.c
Expand Up @@ -109,6 +109,7 @@ MODULE_VERSION
#define MI_ENABLE_RTP_PROXY "nh_enable_rtpp"
#define MI_SHOW_RTP_PROXIES "nh_show_rtpp"
#define MI_PING_RTP_PROXY "nh_ping_rtpp"
#define MI_SHOW_HASH_TOTAL "nh_show_hash_total"

#define MI_RTP_PROXY_NOT_FOUND "RTP proxy not found"
#define MI_RTP_PROXY_NOT_FOUND_LEN (sizeof(MI_RTP_PROXY_NOT_FOUND)-1)
Expand Down Expand Up @@ -143,6 +144,10 @@ MODULE_VERSION
#define MI_SUCCESS_LEN (sizeof(MI_SUCCESS)-1)
#define MI_FAIL "fail"
#define MI_FAIL_LEN (sizeof(MI_FAIL)-1)
#define MI_HASH_ENTRIES "entries"
#define MI_HASH_ENTRIES_LEN (sizeof(MI_HASH_ENTRIES)-1)
#define MI_HASH_ENTRIES_FAIL "Fail to get entry details"
#define MI_HASH_ENTRIES_FAIL_LEN (sizeof(MI_HASH_ENTRIES_FAIL)-1)

#define MI_FOUND_ALL 2
#define MI_FOUND_ONE 1
Expand Down Expand Up @@ -215,12 +220,10 @@ static int rtpp_test_ping(struct rtpp_node *node);
static int pv_get_rtpstat_f(struct sip_msg *, pv_param_t *, pv_value_t *);

/*mi commands*/
static struct mi_root* mi_enable_rtp_proxy(struct mi_root* cmd_tree,
void* param );
static struct mi_root* mi_show_rtp_proxy(struct mi_root* cmd_tree,
void* param);
static struct mi_root* mi_ping_rtp_proxy(struct mi_root* cmd_tree,
void* param);
static struct mi_root* mi_enable_rtp_proxy(struct mi_root* cmd_tree, void* param);
static struct mi_root* mi_show_rtp_proxy(struct mi_root* cmd_tree, void* param);
static struct mi_root* mi_ping_rtp_proxy(struct mi_root* cmd_tree, void* param);
static struct mi_root* mi_show_hash_total(struct mi_root* cmd_tree, void* param);


static int rtpengine_disable_tout = 60;
Expand Down Expand Up @@ -350,6 +353,7 @@ static mi_export_t mi_cmds[] = {
{MI_ENABLE_RTP_PROXY, mi_enable_rtp_proxy, 0, 0, 0},
{MI_SHOW_RTP_PROXIES, mi_show_rtp_proxy, 0, 0, 0},
{MI_PING_RTP_PROXY, mi_ping_rtp_proxy, 0, 0, 0},
{MI_SHOW_HASH_TOTAL, mi_show_hash_total, 0, 0, 0},
{ 0, 0, 0, 0, 0}
};

Expand Down Expand Up @@ -1106,8 +1110,7 @@ static int add_rtpp_node_info (struct mi_node *node,
return -1;
}

static struct mi_root* mi_show_rtp_proxy(struct mi_root* cmd_tree,
void* param)
static struct mi_root* mi_show_rtp_proxy(struct mi_root* cmd_tree, void* param)
{
struct mi_node *node;
struct mi_root *root = NULL;
Expand Down Expand Up @@ -1196,8 +1199,7 @@ static struct mi_root* mi_show_rtp_proxy(struct mi_root* cmd_tree,
return init_mi_tree(404, MI_ERROR, MI_ERROR_LEN);
}

static struct mi_root* mi_ping_rtp_proxy(struct mi_root* cmd_tree,
void* param)
static struct mi_root* mi_ping_rtp_proxy(struct mi_root* cmd_tree, void* param)
{
struct mi_node *node, *crt_node;
struct mi_attr *attr;
Expand Down Expand Up @@ -1322,6 +1324,48 @@ static struct mi_root* mi_ping_rtp_proxy(struct mi_root* cmd_tree,
}


static struct mi_root* mi_show_hash_total(struct mi_root* cmd_tree, void* param)
{
struct mi_node *node, *crt_node;
struct mi_attr *attr;
struct mi_root *root = NULL;
unsigned int total;
str total_str;

// Init print tree
root = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
if (!root) {
LM_ERR("the MI tree cannot be initialized!\n");
return 0;
}
node = &root->node;

// Create new node and add it to the roots's kids
if(!(crt_node = add_mi_node_child(node, MI_DUP_NAME, "total", strlen("total"), 0, 0))) {
LM_ERR("cannot add the child node to the tree\n");
goto error;
}

// Get total number of entries
total = rtpengine_hash_table_total();
total_str.s = int2str(total, &total_str.len);

// Add node attributes
if ((attr = add_mi_attr(crt_node, MI_DUP_VALUE, MI_HASH_ENTRIES, MI_HASH_ENTRIES_LEN, total_str.s, total_str.len)) == 0) {
LM_ERR("cannot add attributes to the node\n");
goto error;
}

return root;

error:
if (root) {
free_mi_tree(root);
}

return init_mi_tree(404, MI_HASH_ENTRIES_FAIL, MI_HASH_ENTRIES_FAIL_LEN);
}


static int
mod_init(void)
Expand Down
30 changes: 30 additions & 0 deletions modules/rtpengine/rtpengine_hash.c
Expand Up @@ -74,6 +74,7 @@ int rtpengine_hash_table_init(int size) {
// never expire the head of the hashtable index lists
rtpengine_hash_table->entry_list[i]->tout = -1;
rtpengine_hash_table->entry_list[i]->next = NULL;
rtpengine_hash_table->total = 0;
}

// init lock
Expand Down Expand Up @@ -165,6 +166,9 @@ int rtpengine_hash_table_insert(void *key, void *value) {

// set pointers
entry = last_entry;

// update total
rtpengine_hash_table->total--;
}

// next entry in the list
Expand All @@ -174,6 +178,9 @@ int rtpengine_hash_table_insert(void *key, void *value) {

last_entry->next = new_entry;

// update total
rtpengine_hash_table->total++;

// unlock
lock_release(rtpengine_hash_lock);

Expand Down Expand Up @@ -205,6 +212,9 @@ int rtpengine_hash_table_remove(void *key) {
shm_free(entry->callid.s);
shm_free(entry);

// update total
rtpengine_hash_table->total--;

// unlock
lock_release(rtpengine_hash_lock);

Expand All @@ -222,6 +232,9 @@ int rtpengine_hash_table_remove(void *key) {

// set pointers
entry = last_entry;

// update total
rtpengine_hash_table->total--;
}

last_entry = entry;
Expand Down Expand Up @@ -271,6 +284,9 @@ void* rtpengine_hash_table_lookup(void *key) {

// set pointers
entry = last_entry;

// update total
rtpengine_hash_table->total--;
}

last_entry = entry;
Expand Down Expand Up @@ -314,6 +330,9 @@ void rtpengine_hash_table_print() {

// set pointers
entry = last_entry;

// update total
rtpengine_hash_table->total--;
} else {
LM_DBG("hash_index=%d callid=%.*s tout=%u\n",
i, entry->callid.len, entry->callid.s, entry->tout - get_ticks());
Expand All @@ -327,3 +346,14 @@ void rtpengine_hash_table_print() {
// unlock
lock_release(rtpengine_hash_lock);
}

unsigned int rtpengine_hash_table_total() {

// check rtpengine hashtable
if (!rtpengine_hash_table) {
LM_ERR("NULL rtpengine_hash_table");
return 0;
}

return rtpengine_hash_table->total;
}
6 changes: 4 additions & 2 deletions modules/rtpengine/rtpengine_hash.h
Expand Up @@ -15,7 +15,8 @@ struct rtpengine_hash_entry {

/* table */
struct rtpengine_hash_table {
struct rtpengine_hash_entry **entry_list;
struct rtpengine_hash_entry **entry_list; // hastable
unsigned int total; // total number of entries in the hashtable
};


Expand All @@ -24,6 +25,7 @@ int rtpengine_hash_table_destroy();
int rtpengine_hash_table_insert(void *key, void *value);
int rtpengine_hash_table_remove(void *key);
void* rtpengine_hash_table_lookup(void *key);
void rtpengine_hash_table_print() ;
void rtpengine_hash_table_print();
unsigned int rtpengine_hash_table_total();

#endif

0 comments on commit 74fdbe2

Please sign in to comment.