Change in libosmocore[master]: ns2: Properly indent VTY output

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Wed Jan 20 14:59:04 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22323 )

Change subject: ns2: Properly indent VTY output
......................................................................

ns2: Properly indent VTY output

If multiple objects are printed in the VTY, only the first line of each
object should be on the first character of the line, all others should
be indented.  With  this patch the "snow ns entities" output becomes
much more readable:

OsmoGbProxy> show ns entities
NSEI 00102: UDP, DEAD
 FSM Instance Name: 'GPRS-NS2-SNS-BSS(NSE00102-SNS)[0x6120000018a0]', ID: 'NSE00102-SNS'
  Log-Level: 'DEBUG', State: 'SIZE'
  Timer: 1
 Maximum number of remote  NS-VCs: 8, IPv4 Endpoints: 4, IPv6 Endpoints: 0
 NSVCI none: UNCONFIGURED DYNAMIC data_weight=1 sig_weight=1 udp)[127.0.0.1]:23000<>[127.0.0.11]:8888
NSEI 00101: UDP, DEAD
 FSM Instance Name: 'GPRS-NS2-SNS-BSS(NSE00101-SNS)[0x6120000015a0]', ID: 'NSE00101-SNS'
  Log-Level: 'DEBUG', State: 'SIZE'
  Timer: 1
 Maximum number of remote  NS-VCs: 8, IPv4 Endpoints: 4, IPv6 Endpoints: 0
 NSVCI none: UNCONFIGURED DYNAMIC data_weight=1 sig_weight=1 udp)[127.0.0.1]:23000<>[127.0.0.10]:7777

Change-Id: Id1b4c80a6caef410076a68b4301adaa01ba7e57a
---
M src/gb/gprs_ns2_internal.h
M src/gb/gprs_ns2_sns.c
M src/gb/gprs_ns2_vty.c
M src/gb/gprs_ns2_vty2.c
4 files changed, 20 insertions(+), 19 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index cb5c2bd..ebb2e3b 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -245,7 +245,7 @@
 struct msgb *gprs_ns2_msgb_alloc(void);
 
 void gprs_ns2_sns_write_vty(struct vty *vty, const struct gprs_ns2_nse *nse);
-void gprs_ns2_sns_dump_vty(struct vty *vty, const struct gprs_ns2_nse *nse, bool stats);
+void gprs_ns2_sns_dump_vty(struct vty *vty, const char *prefix, const struct gprs_ns2_nse *nse, bool stats);
 void ns2_prim_status_ind(struct gprs_ns2_nse *nse,
 			 struct gprs_ns2_vc *nsvc,
 			 uint16_t bvci,
diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index e574b44..72e4ea7 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -1499,28 +1499,29 @@
 #include <osmocom/vty/vty.h>
 #include <osmocom/vty/misc.h>
 
-static void vty_dump_sns_ip4(struct vty *vty, const struct gprs_ns_ie_ip4_elem *ip4)
+static void vty_dump_sns_ip4(struct vty *vty, const char *prefix, const struct gprs_ns_ie_ip4_elem *ip4)
 {
 	struct in_addr in = { .s_addr = ip4->ip_addr };
-	vty_out(vty, " %s:%u, Signalling Weight: %u, Data Weight: %u%s",
+	vty_out(vty, "%s %s:%u, Signalling Weight: %u, Data Weight: %u%s", prefix,
 		inet_ntoa(in), ntohs(ip4->udp_port), ip4->sig_weight, ip4->data_weight, VTY_NEWLINE);
 }
 
-static void vty_dump_sns_ip6(struct vty *vty, const struct gprs_ns_ie_ip6_elem *ip6)
+static void vty_dump_sns_ip6(struct vty *vty, const char *prefix, const struct gprs_ns_ie_ip6_elem *ip6)
 {
 	char ip_addr[INET6_ADDRSTRLEN] = {};
 	if (!inet_ntop(AF_INET6, &ip6->ip_addr, ip_addr, (INET6_ADDRSTRLEN)))
 		strcpy(ip_addr, "Invalid IPv6");
 
-	vty_out(vty, " %s:%u, Signalling Weight: %u, Data Weight: %u%s",
+	vty_out(vty, "%s %s:%u, Signalling Weight: %u, Data Weight: %u%s", prefix,
 		ip_addr, ntohs(ip6->udp_port), ip6->sig_weight, ip6->data_weight, VTY_NEWLINE);
 }
 
 /*! Dump the IP-SNS state to a vty.
  *  \param[in] vty VTY to which the state shall be printed
+ *  \param[in] prefix prefix to print at start of each line (typically indenting)
  *  \param[in] nse NS Entity whose IP-SNS state shall be printed
  *  \param[in] stats Whether or not statistics shall also be printed */
-void gprs_ns2_sns_dump_vty(struct vty *vty, const struct gprs_ns2_nse *nse, bool stats)
+void gprs_ns2_sns_dump_vty(struct vty *vty, const char *prefix, const struct gprs_ns2_nse *nse, bool stats)
 {
 	struct ns2_sns_state *gss;
 	unsigned int i;
@@ -1528,30 +1529,30 @@
 	if (!nse->bss_sns_fi)
 		return;
 
-	vty_out_fsm_inst(vty, nse->bss_sns_fi);
+	vty_out_fsm_inst2(vty, prefix, nse->bss_sns_fi);
 	gss = (struct ns2_sns_state *) nse->bss_sns_fi->priv;
 
-	vty_out(vty, "Maximum number of remote  NS-VCs: %zu, IPv4 Endpoints: %zu, IPv6 Endpoints: %zu%s",
-		gss->num_max_nsvcs, gss->num_max_ip4_remote, gss->num_max_ip6_remote, VTY_NEWLINE);
+	vty_out(vty, "%sMaximum number of remote  NS-VCs: %zu, IPv4 Endpoints: %zu, IPv6 Endpoints: %zu%s",
+		prefix, gss->num_max_nsvcs, gss->num_max_ip4_remote, gss->num_max_ip6_remote, VTY_NEWLINE);
 
 	if (gss->num_ip4_local && gss->num_ip4_remote) {
-		vty_out(vty, "Local IPv4 Endpoints:%s", VTY_NEWLINE);
+		vty_out(vty, "%sLocal IPv4 Endpoints:%s", prefix, VTY_NEWLINE);
 		for (i = 0; i < gss->num_ip4_local; i++)
-			vty_dump_sns_ip4(vty, &gss->ip4_local[i]);
+			vty_dump_sns_ip4(vty, prefix, &gss->ip4_local[i]);
 
-		vty_out(vty, "Remote IPv4 Endpoints:%s", VTY_NEWLINE);
+		vty_out(vty, "%sRemote IPv4 Endpoints:%s", prefix, VTY_NEWLINE);
 		for (i = 0; i < gss->num_ip4_remote; i++)
-			vty_dump_sns_ip4(vty, &gss->ip4_remote[i]);
+			vty_dump_sns_ip4(vty, prefix, &gss->ip4_remote[i]);
 	}
 
 	if (gss->num_ip6_local && gss->num_ip6_remote) {
-		vty_out(vty, "Local IPv6 Endpoints:%s", VTY_NEWLINE);
+		vty_out(vty, "%sLocal IPv6 Endpoints:%s", prefix, VTY_NEWLINE);
 		for (i = 0; i < gss->num_ip6_local; i++)
-			vty_dump_sns_ip6(vty, &gss->ip6_local[i]);
+			vty_dump_sns_ip6(vty, prefix, &gss->ip6_local[i]);
 
-		vty_out(vty, "Remote IPv6 Endpoints:%s", VTY_NEWLINE);
+		vty_out(vty, "%sRemote IPv6 Endpoints:%s", prefix, VTY_NEWLINE);
 		for (i = 0; i < gss->num_ip6_remote; i++)
-			vty_dump_sns_ip6(vty, &gss->ip6_remote[i]);
+			vty_dump_sns_ip6(vty, prefix, &gss->ip6_remote[i]);
 	}
 }
 
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index 065f3ad..36a7f78 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -298,7 +298,7 @@
 	vty_out(vty, "NSEI %05u: %s, %s%s", nse->nsei, gprs_ns2_lltype_str(nse->ll),
 		nse->alive ? "ALIVE" : "DEAD", VTY_NEWLINE);
 
-	gprs_ns2_sns_dump_vty(vty, nse, stats);
+	gprs_ns2_sns_dump_vty(vty, " ", nse, stats);
 	llist_for_each_entry(nsvc, &nse->nsvc, list) {
 		if (persistent_only) {
 			if (nsvc->persistent)
diff --git a/src/gb/gprs_ns2_vty2.c b/src/gb/gprs_ns2_vty2.c
index 94302ef..db59717 100644
--- a/src/gb/gprs_ns2_vty2.c
+++ b/src/gb/gprs_ns2_vty2.c
@@ -1349,7 +1349,7 @@
 	vty_out(vty, "NSEI %05u: %s, %s%s", nse->nsei, gprs_ns2_lltype_str(nse->ll),
 		nse->alive ? "ALIVE" : "DEAD", VTY_NEWLINE);
 
-	gprs_ns2_sns_dump_vty(vty, nse, stats);
+	gprs_ns2_sns_dump_vty(vty, " ", nse, stats);
 	llist_for_each_entry(nsvc, &nse->nsvc, list) {
 		if (persistent_only) {
 			if (nsvc->persistent)

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id1b4c80a6caef410076a68b4301adaa01ba7e57a
Gerrit-Change-Number: 22323
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210120/54f2bc6e/attachment.htm>


More information about the gerrit-log mailing list