Stefan Sperling has uploaded this change for review. ( 
https://gerrit.osmocom.org/11521


Change subject: add DLCX command statistics to osmo-mgw
......................................................................

add DLCX command statistics to osmo-mgw

Add a counter group for DLCX commands. The group contains counters for
successful connection processing as well as various error conditions.
This provides a quick overview of DLCX failures on each trunk throughout
the lifetime of the osmo-mgw process.

The counters are displayed by 'show mgcp stats' and 'show rate-counters'

Change-Id: Ie0dde2faf02fd68a69f986973d39b1bea367039b
Depends: I80d36181600901ae2e0f321dc02b5d54ddc94139I
Related: OS#2660
---
M include/osmocom/mgcp/mgcp.h
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_vty.c
3 files changed, 67 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/21/11521/1

diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h
index 4a307cd..d08c3ef 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -155,6 +155,18 @@
        MGCP_MDCX_FAIL_DEFERRED_BY_POLICY
 };

+/* Global MCGP DLCX related rate counters */
+enum {
+       MGCP_DLCX_SUCCESS,
+       MGCP_DLCX_FAIL_WILDCARD,
+       MGCP_DLCX_FAIL_NO_CONN,
+       MGCP_DLCX_FAIL_INVALID_CALLID,
+       MGCP_DLCX_FAIL_INVALID_CONNID,
+       MGCP_DLCX_FAIL_UNHANDLED_PARAM,
+       MGCP_DLCX_FAIL_REJECTED_BY_POLICY,
+       MGCP_DLCX_FAIL_DEFERRED_BY_POLICY,
+       MGCP_DLCX_FAIL_NO_RTP
+};

 struct mgcp_trunk_config {
        struct llist_head entry;
@@ -198,6 +210,8 @@
        struct rate_ctr_group *mgcp_crcx_ctr_group;
        /* Rate counter group which contains stats for processed MDCX commands. 
*/
        struct rate_ctr_group *mgcp_mdcx_ctr_group;
+       /* Rate counter group which contains stats for processed DLCX commands. 
*/
+       struct rate_ctr_group *mgcp_dlcx_ctr_group;
        /* Rate counter group which aggregates stats of individual RTP 
connections. */
        struct rate_ctr_group *all_rtp_conn_stats;
 };
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 767faa9..b9469ec 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -73,7 +73,7 @@

 const static struct rate_ctr_group_desc mgcp_crcx_ctr_group_desc = {
        .group_name_prefix = "crcx",
-       .group_description = "crxc statistics",
+       .group_description = "crcx statistics",
        .class_id = OSMO_STATS_CLASS_GLOBAL,
        .num_ctr = ARRAY_SIZE(mgcp_crcx_ctr_desc),
        .ctr_desc = mgcp_crcx_ctr_desc
@@ -104,6 +104,26 @@
        .ctr_desc = mgcp_mdcx_ctr_desc
 };

+static const struct rate_ctr_desc mgcp_dlcx_ctr_desc[] = {
+       [MGCP_DLCX_SUCCESS] = {"dlcx:success", "DLCX command processed 
successfully."},
+       [MGCP_DLCX_FAIL_WILDCARD] = {"dlcx:wildcard", "wildcard names in DLCX 
commands are unsupported."},
+       [MGCP_DLCX_FAIL_NO_CONN] = {"dlcx:no_conn", "endpoint specified in DLCX 
command has no active connections."},
+       [MGCP_DLCX_FAIL_INVALID_CALLID] = {"dlcx:callid", "invalid CallId 
specified in DLCX command."},
+       [MGCP_DLCX_FAIL_INVALID_CONNID] = {"dlcx:connid", "invalid connection 
ID specified in DLCX command."},
+       [MGCP_DLCX_FAIL_UNHANDLED_PARAM] = {"dlcx:unhandled_param", "unhandled 
parameter in DLCX command."},
+       [MGCP_DLCX_FAIL_REJECTED_BY_POLICY] = {"dlcx:rejected", "connection 
deletion rejected by policy."},
+       [MGCP_DLCX_FAIL_DEFERRED_BY_POLICY] = {"dlcx:deferred", "connection 
deletion deferred by policy."},
+       [MGCP_DLCX_FAIL_NO_RTP] = {"dlcx:no_rtp", "no rtp stream associated 
with connection."},
+};
+
+const static struct rate_ctr_group_desc mgcp_dlcx_ctr_group_desc = {
+       .group_name_prefix = "dlcx",
+       .group_description = "dlcx statistics",
+       .class_id = OSMO_STATS_CLASS_GLOBAL,
+       .num_ctr = ARRAY_SIZE(mgcp_dlcx_ctr_desc),
+       .ctr_desc = mgcp_dlcx_ctr_desc
+};
+
 /* Must be kept in sync with rate_ctr_desc in mgcp_conn.c */
 static const struct rate_ctr_desc all_rtp_conn_rate_ctr_desc[] = {
        [IN_STREAM_ERR_TSTMP_CTR] = {"all_rtp:err_tstmp_in", "Total inbound 
rtp-stream timestamp errors."},
@@ -1251,7 +1271,9 @@
 /* DLCX command handler, processes the received command */
 static struct msgb *handle_delete_con(struct mgcp_parse_data *p)
 {
+       struct mgcp_trunk_config *tcfg = p->endp->tcfg;
        struct mgcp_endpoint *endp = p->endp;
+       struct rate_ctr_group *rate_ctrs = tcfg->mgcp_dlcx_ctr_group;
        int error_code = 400;
        int silent = 0;
        char *line;
@@ -1268,6 +1290,7 @@
                LOGP(DLMGCP, LOGL_ERROR,
                     "DLCX: endpoint:0x%x wildcarded endpoint names not 
supported.\n",
                     ENDPOINT_NUMBER(endp));
+               rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_WILDCARD]);
                return create_err_response(endp, 507, "DLCX", p->trans);
        }

@@ -1275,6 +1298,7 @@
                LOGP(DLMGCP, LOGL_ERROR,
                     "DLCX: endpoint:0x%x endpoint is not holding a 
connection.\n",
                     ENDPOINT_NUMBER(endp));
+               rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_NO_CONN]);
                return create_err_response(endp, 515, "DLCX", p->trans);
        }

@@ -1286,13 +1310,16 @@
                case 'C':
                        if (mgcp_verify_call_id(endp, line + 3) != 0) {
                                error_code = 516;
+                               
rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CALLID]);
                                goto error3;
                        }
                        break;
                case 'I':
                        conn_id = (const char *)line + 3;
-                       if ((error_code = mgcp_verify_ci(endp, conn_id)))
+                       if ((error_code = mgcp_verify_ci(endp, conn_id))) {
+                               
rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CONNID]);
                                goto error3;
+                       }
                        break;
                case 'Z':
                        silent = strcmp("noanswer", line + 3) == 0;
@@ -1301,6 +1328,7 @@
                        LOGP(DLMGCP, LOGL_NOTICE,
                             "DLCX: endpoint:0x%x Unhandled MGCP option: 
'%c'/%d\n",
                             ENDPOINT_NUMBER(endp), line[0], line[0]);
+                       
rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_UNHANDLED_PARAM]);
                        return create_err_response(NULL, 539, "DLCX", p->trans);
                        break;
                }
@@ -1316,12 +1344,14 @@
                        LOGP(DLMGCP, LOGL_NOTICE,
                             "DLCX: endpoint:0x%x rejected by policy\n",
                             ENDPOINT_NUMBER(endp));
+                       
rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_REJECTED_BY_POLICY]);
                        if (silent)
                                goto out_silent;
                        return create_err_response(endp, 400, "DLCX", p->trans);
                        break;
                case MGCP_POLICY_DEFER:
                        /* stop processing */
+                       
rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_DEFERRED_BY_POLICY]);
                        return NULL;
                        break;
                case MGCP_POLICY_CONT:
@@ -1334,9 +1364,13 @@
         * wildcarded DLCX and drop all connections at once. (See also
         * RFC3435 Section F.7) */
        if (!conn_id) {
+               int num_conns = llist_count(&endp->conns);
                LOGP(DLMGCP, LOGL_NOTICE,
-                    "DLCX: endpoint:0x%x missing ci (connectionIdentifier), 
will remove all connections at once\n",
-                    ENDPOINT_NUMBER(endp));
+                    "DLCX: endpoint:0x%x missing ci (connectionIdentifier), 
will remove all connections (%d total) at once\n",
+                    num_conns, ENDPOINT_NUMBER(endp));
+
+               if (num_conns > 0)
+                       rate_ctr_add(&rate_ctrs->ctr[MGCP_DLCX_SUCCESS], 
num_conns);

                mgcp_endp_release(endp);

@@ -1348,9 +1382,10 @@

        /* Find the connection */
        conn = mgcp_conn_get_rtp(endp, conn_id);
-       if (!conn)
+       if (!conn) {
+               rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_NO_RTP]);
                goto error3;
-
+       }
        /* save the statistics of the current connection */
        mgcp_format_stats(stats, sizeof(stats), conn->conn);

@@ -1375,6 +1410,7 @@
                p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp),
                                  MGCP_ENDP_DLCX);

+       rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_SUCCESS]);
        if (silent)
                goto out_silent;
        return create_ok_resp_with_param(endp, 250, "DLCX", p->trans, stats);
@@ -1517,6 +1553,7 @@
         * a better way of assigning indices? */
        static unsigned int crcx_rate_ctr_index = 0;
        static unsigned int mdcx_rate_ctr_index = 0;
+       static unsigned int dlcx_rate_ctr_index = 0;
        static unsigned int all_rtp_conn_rate_ctr_index = 0;

        if (trunk->mgcp_crcx_ctr_group == NULL) {
@@ -1531,6 +1568,12 @@
                talloc_set_destructor(trunk->mgcp_mdcx_ctr_group, 
free_rate_counter_group);
                mdcx_rate_ctr_index++;
        }
+       if (trunk->mgcp_dlcx_ctr_group == NULL) {
+               trunk->mgcp_dlcx_ctr_group = rate_ctr_group_alloc(ctx, 
&mgcp_dlcx_ctr_group_desc, dlcx_rate_ctr_index);
+               OSMO_ASSERT(trunk->mgcp_dlcx_ctr_group);
+               talloc_set_destructor(trunk->mgcp_dlcx_ctr_group, 
free_rate_counter_group);
+               dlcx_rate_ctr_index++;
+       }
        if (trunk->all_rtp_conn_stats == NULL) {
                trunk->all_rtp_conn_stats = rate_ctr_group_alloc(ctx, 
&all_rtp_conn_rate_ctr_group_desc,
                                                                 
all_rtp_conn_rate_ctr_index);
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index e40d412..83f845a 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -249,6 +249,10 @@
                vty_out(vty, "   %s:%s", 
cfg->mgcp_crcx_ctr_group->desc->group_description, VTY_NEWLINE);
                vty_out_rate_ctr_group_fmt(vty, "   %25n: %10c (%S/s %M/m %H/h 
%D/d) %d", cfg->mgcp_crcx_ctr_group);
        }
+       if (show_stats && cfg->mgcp_dlcx_ctr_group) {
+               vty_out(vty, "   %s:%s", 
cfg->mgcp_dlcx_ctr_group->desc->group_description, VTY_NEWLINE);
+               vty_out_rate_ctr_group_fmt(vty, "   %25n: %10c (%S/s %M/m %H/h 
%D/d) %d", cfg->mgcp_dlcx_ctr_group);
+       }
        if (show_stats && cfg->mgcp_mdcx_ctr_group) {
                vty_out(vty, "   %s:%s", 
cfg->mgcp_mdcx_ctr_group->desc->group_description, VTY_NEWLINE);
                vty_out_rate_ctr_group_fmt(vty, "   %25n: %10c (%S/s %M/m %H/h 
%D/d) %d", cfg->mgcp_mdcx_ctr_group);

--
To view, visit https://gerrit.osmocom.org/11521
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie0dde2faf02fd68a69f986973d39b1bea367039b
Gerrit-Change-Number: 11521
Gerrit-PatchSet: 1
Gerrit-Owner: Stefan Sperling <[email protected]>

Reply via email to