session tcp udp tls quic: improve cli formatting

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Iae5dbb8aaaf82d8e95c2ee8bbbe6844c9dd49f80
diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c
index 8143500..beca5db 100644
--- a/src/vnet/session/application_local.c
+++ b/src/vnet/session/application_local.c
@@ -516,9 +516,9 @@
   u32 __clib_unused thread_index = va_arg (*args, u32);
   u32 __clib_unused verbose = va_arg (*args, u32);
   ct_connection_t *ct = ct_connection_get (tc_index);
-  s = format (s, "%-50U", format_ct_connection_id, ct);
+  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
   if (verbose)
-    s = format (s, "%-15s", "LISTEN");
+    s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "LISTEN");
   return s;
 }
 
@@ -530,10 +530,10 @@
 
   if (!ct)
     return s;
-  s = format (s, "%-50U", format_ct_connection_id, ct);
+  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
   if (verbose)
     {
-      s = format (s, "%-15s", "ESTABLISHED");
+      s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "ESTABLISHED");
       if (verbose > 1)
 	{
 	  s = format (s, "\n");
diff --git a/src/vnet/session/session_cli.c b/src/vnet/session/session_cli.c
index 9f6d74c..ade76ef 100644
--- a/src/vnet/session/session_cli.c
+++ b/src/vnet/session/session_cli.c
@@ -329,7 +329,8 @@
 	}
 
       if (verbose == 1)
-	vlib_cli_output (vm, "%s%-50s%-15s%-10s%-10s",
+	vlib_cli_output (vm, "%s%-" SESSION_CLI_ID_LEN "s%-"
+			 SESSION_CLI_STATE_LEN "s%-10s%-10s",
 			 thread_index ? "\n" : "",
 			 "Connection", "State", "Rx-f", "Tx-f");
 
@@ -617,7 +618,9 @@
   if (do_listeners)
     {
       sst = session_type_from_proto_and_ip (transport_proto, 1);
-      vlib_cli_output (vm, "%-50s%-24s", "Listener", "App");
+      vlib_cli_output (vm, "%-" SESSION_CLI_ID_LEN "s%-24s", "Listener",
+		       "App");
+
       /* *INDENT-OFF* */
       pool_foreach (s, smm->wrk[0].sessions, ({
 	if (s->session_state != SESSION_STATE_LISTENING
diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h
index 8cea29a..950066a 100644
--- a/src/vnet/session/session_types.h
+++ b/src/vnet/session/session_types.h
@@ -495,6 +495,9 @@
 #undef _
 } session_error_t;
 
+#define SESSION_CLI_ID_LEN "60"
+#define SESSION_CLI_STATE_LEN "15"
+
 /* Maintained for compatibility. Will be deprecated */
 #define SESSION_ERROR_SEG_CREATE SESSION_E_SEG_CREATE
 #define SESSION_ERROR_NO_SPACE SESSION_E_SEG_NO_SPACE
diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c
index a4599c2..0b3aeba 100644
--- a/src/vnet/tcp/tcp.c
+++ b/src/vnet/tcp/tcp.c
@@ -841,9 +841,10 @@
   u32 __clib_unused thread_index = va_arg (*args, u32);
   u32 verbose = va_arg (*args, u32);
   tcp_connection_t *tc = tcp_listener_get (tci);
-  s = format (s, "%-50U", format_tcp_connection_id, tc);
+  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_tcp_connection_id, tc);
   if (verbose)
-    s = format (s, "%-15U", format_tcp_state, tc->state);
+    s = format (s, "%-" SESSION_CLI_STATE_LEN "U", format_tcp_state,
+		tc->state);
   return s;
 }
 
diff --git a/src/vnet/tcp/tcp_cli.c b/src/vnet/tcp/tcp_cli.c
index 94ee21f..e2c1396 100644
--- a/src/vnet/tcp/tcp_cli.c
+++ b/src/vnet/tcp/tcp_cli.c
@@ -258,10 +258,11 @@
 
   if (!tc)
     return s;
-  s = format (s, "%-50U", format_tcp_connection_id, tc);
+  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_tcp_connection_id, tc);
   if (verbose)
     {
-      s = format (s, "%-15U", format_tcp_state, tc->state);
+      s = format (s, "%-" SESSION_CLI_STATE_LEN "U", format_tcp_state,
+		  tc->state);
       if (verbose > 1)
 	s = format (s, "\n%U", format_tcp_vars, tc);
     }
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index 9caa5d7..516cfd7 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -816,10 +816,11 @@
   if (!ctx)
     return s;
 
-  s = format (s, "%-50U", format_tls_ctx, ctx);
+  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_tls_ctx, ctx);
   if (verbose)
     {
-      s = format (s, "%-15U", format_tls_ctx_state, ctx);
+      s = format (s, "%-" SESSION_CLI_STATE_LEN "U", format_tls_ctx_state,
+		  ctx);
       if (verbose > 1)
 	s = format (s, "\n");
     }
@@ -834,9 +835,9 @@
   u32 verbose = va_arg (*args, u32);
   tls_ctx_t *ctx = tls_listener_ctx_get (tc_index);
 
-  s = format (s, "%-50U", format_tls_listener_ctx, ctx);
+  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_tls_listener_ctx, ctx);
   if (verbose)
-    s = format (s, "%-15U", format_tls_ctx_state, ctx);
+    s = format (s, "%-" SESSION_CLI_STATE_LEN "U", format_tls_ctx_state, ctx);
   return s;
 }
 
diff --git a/src/vnet/udp/udp_cli.c b/src/vnet/udp/udp_cli.c
index 89cea68..09e3a8a 100644
--- a/src/vnet/udp/udp_cli.c
+++ b/src/vnet/udp/udp_cli.c
@@ -14,6 +14,7 @@
  */
 
 #include <vnet/udp/udp.h>
+#include <vnet/session/session_types.h>
 
 u8 *
 format_udp_connection_id (u8 * s, va_list * args)
@@ -78,10 +79,10 @@
   u32 verbose = va_arg (*args, u32);
   if (!uc)
     return s;
-  s = format (s, "%-50U", format_udp_connection_id, uc);
+  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_udp_connection_id, uc);
   if (verbose)
     {
-      s = format (s, "%-15s",
+      s = format (s, "%-" SESSION_CLI_STATE_LEN "s",
 		  (uc->flags & UDP_CONN_F_LISTEN) ? "LISTEN" : "OPENED", uc);
       if (verbose > 1)
 	s = format (s, "\n%U", format_udp_vars, uc);