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


Change subject: add a VTY command which shows a specific mgcp endpoint
......................................................................

add a VTY command which shows a specific mgcp endpoint

Add a new VTY command "show mgcp trunk <0-64> endpoint NAME"
which shows detailed information about a specific endpoint.

Change-Id: I5330e697ec34bf215de91d44209048a8dc226d51
Related: OS#2660
---
M src/libosmo-mgcp/mgcp_vty.c
1 file changed, 76 insertions(+), 19 deletions(-)



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

diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index ad462b7..22dd8ae 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -31,6 +31,7 @@

 #include <string.h>
 #include <inttypes.h>
+#include <limits.h>

 #define RTCP_OMIT_STR "Drop RTCP packets in both directions\n"
 #define RTP_PATCH_STR "Modify RTP packet header in both directions\n"
@@ -184,11 +185,32 @@
                end->force_output_ptime, VTY_NEWLINE);
 }

-static void dump_trunk(struct vty *vty, struct mgcp_trunk_config *cfg,
-                      int verbose)
+static void dump_endpoint(struct vty *vty, struct mgcp_endpoint *endp, int 
epidx,
+                         enum mgcp_trunk_type trunk_type, int show_stats)
+{
+       struct mgcp_conn *conn;
+
+       vty_out(vty, "Endpoint %s0x%.2x:%s",
+               trunk_type == MGCP_TRUNK_VIRTUAL ? 
MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK : "",
+               epidx, VTY_NEWLINE);
+
+       llist_for_each_entry(conn, &endp->conns, entry) {
+               vty_out(vty, "   CONN: %s%s", mgcp_conn_dump(conn), 
VTY_NEWLINE);
+
+               if (show_stats) {
+                       /* FIXME: Also add verbosity for other
+                        * connection types (E1) as soon as
+                        * the implementation is available */
+                       if (conn->type == MGCP_CONN_TYPE_RTP) {
+                               dump_rtp_end(vty, &conn->u.rtp);
+                       }
+               }
+       }
+}
+
+static void dump_trunk(struct vty *vty, struct mgcp_trunk_config *cfg, int 
show_stats)
 {
        int i;
-       struct mgcp_conn *conn;

        vty_out(vty, "%s trunk nr %d with %d endpoints:%s",
                cfg->trunk_type == MGCP_TRUNK_VIRTUAL ? "Virtual" : "E1",
@@ -201,22 +223,9 @@

        for (i = 1; i < cfg->number_endpoints; ++i) {
                struct mgcp_endpoint *endp = &cfg->endpoints[i];
-
-               vty_out(vty, "Endpoint 0x%.2x:%s", i, VTY_NEWLINE);
-
-               llist_for_each_entry(conn, &endp->conns, entry) {
-                       vty_out(vty, "   CONN: %s%s",
-                               mgcp_conn_dump(conn), VTY_NEWLINE);
-
-                       if (verbose) {
-                               /* FIXME: Also add verbosity for other
-                                * connection types (E1) as soon as
-                                * the implementation is available */
-                               if (conn->type == MGCP_CONN_TYPE_RTP) {
-                                       dump_rtp_end(vty, &conn->u.rtp);
-                               }
-                       }
-               }
+               dump_endpoint(vty, endp, i, cfg->trunk_type, show_stats);
+               if (i < cfg->number_endpoints - 1)
+                       vty_out(vty, "%s", VTY_NEWLINE);
        }
 }

@@ -241,6 +250,53 @@
        return CMD_SUCCESS;
 }

+DEFUN(show_mcgp_endpoint, show_mgcp_endpoint_cmd,
+      "show mgcp trunk <0-64> endpoint NAME",
+      SHOW_STR
+      "Display information about an MGCP Media Gateway endpoint\n"
+      "Display information about a specific trunk only\n" "Trunk number\n"
+      "Display information about an endpoint\n" "The name of the endpoint in 
hex\n")
+{
+       struct mgcp_trunk_config *trunk;
+       int trunkidx = atoi(argv[1]);
+       const char *epidxstr;
+       unsigned long epidx;
+       char *ep;
+       int i;
+       const size_t virt_prefix_len = 
sizeof(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK) - 1;
+
+       trunk = find_trunk(g_cfg, trunkidx);
+       if (!trunk) {
+               vty_out(vty, "trunk %d not found%s", trunkidx, VTY_NEWLINE);
+               return CMD_WARNING;
+       }
+
+       epidxstr = argv[1];
+       if (strncmp(epidxstr, MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, 
virt_prefix_len) == 0)
+               epidxstr += virt_prefix_len;
+       errno = 0;
+       epidx = strtoul(epidxstr, &ep, 16);
+       if (argv[1][0] == '\0' || *ep != '\0') {
+               vty_out(vty, "endpoint name '%s' is not a hex number%s", 
argv[1], VTY_NEWLINE);
+               return CMD_WARNING;
+       }
+       if ((errno == ERANGE && epidx == ULONG_MAX) /* parsed value out of 
range */
+           || epidx >= trunk->number_endpoints) {
+               vty_out(vty, "endpoint 0x%.2lx not configured%s", epidx, 
VTY_NEWLINE);
+               return CMD_WARNING;
+       }
+
+       for (i = 0; i < trunk->number_endpoints; ++i) {
+               struct mgcp_endpoint *endp = &trunk->endpoints[i];
+               if (i == epidx) {
+                       dump_endpoint(vty, endp, i, trunk->trunk_type, true);
+                       break;
+               }
+       }
+
+       return CMD_SUCCESS;
+}
+
 DEFUN(cfg_mgcp, cfg_mgcp_cmd, "mgcp", "Configure the MGCP")
 {
        vty->node = MGCP_NODE;
@@ -1217,6 +1273,7 @@
 int mgcp_vty_init(void)
 {
        install_element_ve(&show_mgcp_cmd);
+       install_element_ve(&show_mgcp_endpoint_cmd);
        install_element(ENABLE_NODE, &loop_conn_cmd);
        install_element(ENABLE_NODE, &tap_rtp_cmd);
        install_element(ENABLE_NODE, &free_endp_cmd);

--
To view, visit https://gerrit.osmocom.org/10022
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: I5330e697ec34bf215de91d44209048a8dc226d51
Gerrit-Change-Number: 10022
Gerrit-PatchSet: 1
Gerrit-Owner: Stefan Sperling <[email protected]>

Reply via email to