From c39c3df2514b41d98c3ee1c2b32d422ea74513c2 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 4 Apr 2016 17:06:29 +0200 Subject: [PATCH] vty: Add simple VTY output for current calls Start with a show call summary that lists simple data about the current set of calls: Call(5002) initial(type=SIP,state=CONFIRMED) remote(type=MNCC,state=INITIAL) Call(5001) initial(type=MNCC,state=PROCEEDING) remote(type=SIP,state=CONFIRMED) Related: OS#1680 --- src/call.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/call.h | 10 ++++++++++ src/vty.c | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/src/call.c b/src/call.c index 1316205..9be6b4d 100644 --- a/src/call.c +++ b/src/call.c @@ -28,6 +28,40 @@ extern void *tall_mncc_ctx; LLIST_HEAD(g_call_list); static uint32_t last_call_id = 5000; + +const struct value_string call_type_vals[] = { + { CALL_TYPE_NONE, "NONE" }, + { CALL_TYPE_SIP, "SIP" }, + { CALL_TYPE_MNCC, "MNCC" }, + { 0, NULL }, +}; + +const struct value_string mncc_state_vals[] = { + { MNCC_CC_INITIAL, "INITIAL" }, + { MNCC_CC_PROCEEDING, "PROCEEDING" }, + { MNCC_CC_CONNECTED, "CONNECTED" }, + { 0, NULL }, +}; + +const struct value_string mncc_dir_vals[] = { + { MNCC_DIR_MO, "MO" }, + { MNCC_DIR_MT, "MT" }, + { 0, NULL }, +}; + +const struct value_string sip_state_vals[] = { + { SIP_CC_INITIAL, "INITIAL" }, + { SIP_CC_DLG_CNFD, "CONFIRMED" }, + { SIP_CC_CONNECTED, "CONNECTED" }, + { 0, NULL }, +}; + +const struct value_string sip_dir_vals[] = { + { SIP_DIR_MO, "MO" }, + { SIP_DIR_MT, "MT" }, + { 0, NULL }, +}; + void calls_init(void) {} @@ -114,3 +148,25 @@ struct call_leg *call_leg_other(struct call_leg *leg) leg, leg->call->id); return NULL; } + +const char *call_leg_type(struct call_leg *leg) +{ + return get_value_string(call_type_vals, leg->type); +} + +const char *call_leg_state(struct call_leg *leg) +{ + struct mncc_call_leg *mncc; + struct sip_call_leg *sip; + + switch (leg->type) { + case CALL_TYPE_SIP: + sip = (struct sip_call_leg *) leg; + return get_value_string(sip_state_vals, sip->state); + case CALL_TYPE_MNCC: + mncc = (struct mncc_call_leg *) leg; + return get_value_string(mncc_state_vals, mncc->state); + default: + return "unknown call type"; + } +} diff --git a/src/call.h b/src/call.h index b6cb8bf..e844485 100644 --- a/src/call.h +++ b/src/call.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -133,3 +134,12 @@ void call_leg_release(struct call_leg *leg); struct call *call_mncc_create(void); struct call *call_sip_create(void); + +const char *call_leg_type(struct call_leg *leg); +const char *call_leg_state(struct call_leg *leg); + +extern const struct value_string call_type_vals[]; +extern const struct value_string mncc_state_vals[]; +extern const struct value_string mncc_dir_vals[]; +extern const struct value_string sip_state_vals[]; +extern const struct value_string sip_dir_vals[]; diff --git a/src/vty.c b/src/vty.c index 191cec8..36c273e 100644 --- a/src/vty.c +++ b/src/vty.c @@ -20,6 +20,7 @@ #include "vty.h" #include "app.h" +#include "call.h" #include @@ -171,6 +172,46 @@ DEFUN(cfg_no_use_imsi, cfg_no_use_imsi_cmd, return CMD_SUCCESS; } +DEFUN(show_calls_sum, show_calls_sum_cmd, + "show calls summary", + SHOW_STR "Current calls\n") +{ + struct call *call; + + llist_for_each_entry(call, &g_call_list, entry) { + char *initial_type, *initial_state; + char *remote_type, *remote_state; + + initial_type = initial_state = NULL; + remote_type = remote_state = NULL; + + if (call->initial) { + initial_type = talloc_strdup(tall_mncc_ctx, + call_leg_type(call->initial)); + initial_state = talloc_strdup(tall_mncc_ctx, + call_leg_state(call->initial)); + } + + if (call->remote) { + remote_type = talloc_strdup(tall_mncc_ctx, + call_leg_type(call->remote)); + remote_state = talloc_strdup(tall_mncc_ctx, + call_leg_state(call->remote)); + } + + vty_out(vty, "Call(%u) initial(type=%s,state=%s) remote(type=%s,state=%s)%s", + call->id, initial_type, initial_state, remote_type, remote_state, + VTY_NEWLINE); + + talloc_free(initial_type); + talloc_free(initial_state); + talloc_free(remote_type); + talloc_free(remote_state); + } + + return CMD_SUCCESS; +} + void mncc_sip_vty_init(void) { /* default values */ @@ -196,4 +237,6 @@ void mncc_sip_vty_init(void) install_node(&app_node, config_write_app); install_element(APP_NODE, &cfg_use_imsi_cmd); install_element(APP_NODE, &cfg_no_use_imsi_cmd); + + install_element_ve(&show_calls_sum_cmd); }