Review at  https://gerrit.osmocom.org/4397

GPRS: add vty command to show only persistent NS

The regular 'sh ns' lists all available NS. Sometimes it's handy to know
which of those are persistent.

* add "show ns persistent" command
* adjust parameters of dump-ns*() functions to use bool where
  appropriate

Change-Id: Ib812864bae3ea414cc107a7b4f49bea4e6161795
---
M src/gb/gprs_ns_vty.c
1 file changed, 23 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/97/4397/1

diff --git a/src/gb/gprs_ns_vty.c b/src/gb/gprs_ns_vty.c
index c6fb141..a3f7b2b 100644
--- a/src/gb/gprs_ns_vty.c
+++ b/src/gb/gprs_ns_vty.c
@@ -156,8 +156,12 @@
        return CMD_SUCCESS;
 }
 
-static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
+static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, bool stats, bool 
persistent_only)
 {
+       if (persistent_only)
+               if (!nsvc->persistent)
+                       return;
+
        vty_out(vty, "NSEI %5u, NS-VC %5u, %5s %9s, ",
                nsvc->nsei, nsvc->nsvci,
                NS_DESC_A(nsvc->state),
@@ -182,7 +186,7 @@
        }
 }
 
-static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
+static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, bool stats, 
bool persistent_only)
 {
        struct gprs_nsvc *nsvc;
        struct in_addr ia;
@@ -198,7 +202,7 @@
        llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
                if (nsvc == nsi->unknown_nsvc)
                        continue;
-               dump_nse(vty, nsvc, stats);
+               dump_nse(vty, nsvc, stats, persistent_only);
        }
 }
 
@@ -206,7 +210,7 @@
        SHOW_STR "Display information about the NS protocol")
 {
        struct gprs_ns_inst *nsi = vty_nsi;
-       dump_ns(vty, nsi, 0);
+       dump_ns(vty, nsi, false, false);
        return CMD_SUCCESS;
 }
 
@@ -216,7 +220,17 @@
        "Include statistics\n")
 {
        struct gprs_ns_inst *nsi = vty_nsi;
-       dump_ns(vty, nsi, 1);
+       dump_ns(vty, nsi, true, false);
+       return CMD_SUCCESS;
+}
+
+DEFUN(show_ns_pers, show_ns_pers_cmd, "show ns persistent",
+       SHOW_STR
+       "Display information about the NS protocol\n"
+       "Show only persistent NS\n")
+{
+       struct gprs_ns_inst *nsi = vty_nsi;
+       dump_ns(vty, nsi, true, true);
        return CMD_SUCCESS;
 }
 
@@ -230,7 +244,7 @@
        struct gprs_ns_inst *nsi = vty_nsi;
        struct gprs_nsvc *nsvc;
        uint16_t id = atoi(argv[1]);
-       int show_stats = 0;
+       bool show_stats = false;
 
        if (!strcmp(argv[0], "nsei"))
                nsvc = gprs_nsvc_by_nsei(nsi, id);
@@ -243,9 +257,9 @@
        }
 
        if (argc >= 3)
-               show_stats = 1;
+               show_stats = true;
 
-       dump_nse(vty, nsvc, show_stats);
+       dump_nse(vty, nsvc, show_stats, false);
        return CMD_SUCCESS;
 }
 
@@ -594,6 +608,7 @@
 
        install_element_ve(&show_ns_cmd);
        install_element_ve(&show_ns_stats_cmd);
+       install_element_ve(&show_ns_pers_cmd);
        install_element_ve(&show_nse_cmd);
        install_element_ve(&logging_fltr_nsvc_cmd);
 

-- 
To view, visit https://gerrit.osmocom.org/4397
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib812864bae3ea414cc107a7b4f49bea4e6161795
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <[email protected]>

Reply via email to