Implement sack based tcp loss recovery (RFC 6675)
[vpp.git] / src / vnet / session / session_cli.c
old mode 100644 (file)
new mode 100755 (executable)
index b2943a1..6b8341a
 #include <vnet/session/application.h>
 #include <vnet/session/session.h>
 
+u8 *
+format_stream_session_fifos (u8 * s, va_list * args)
+{
+  stream_session_t *ss = va_arg (*args, stream_session_t *);
+  s = format (s, " Rx fifo: %U", format_svm_fifo, ss->server_rx_fifo, 1);
+  s = format (s, " Tx fifo: %U", format_svm_fifo, ss->server_tx_fifo, 1);
+  return s;
+}
+
 /**
  * Format stream session as per the following format
  *
@@ -30,37 +39,45 @@ format_stream_session (u8 * s, va_list * args)
   int verbose = va_arg (*args, int);
   transport_proto_vft_t *tp_vft;
   u8 *str = 0;
-
   tp_vft = session_get_transport_vft (ss->session_type);
 
-  if (verbose)
-    str = format (0, "%-20llp%-20llp%-15lld", ss->server_rx_fifo,
-                 ss->server_tx_fifo, stream_session_get_index (ss));
+  if (verbose == 1)
+    str = format (0, "%-10u%-10u%-10lld",
+                 svm_fifo_max_dequeue (ss->server_rx_fifo),
+                 svm_fifo_max_enqueue (ss->server_tx_fifo),
+                 stream_session_get_index (ss));
 
   if (ss->session_state == SESSION_STATE_READY)
     {
-      s = format (s, "%-40U%v", tp_vft->format_connection,
-                 ss->connection_index, ss->thread_index, str);
+      s = format (s, "%U", tp_vft->format_connection, ss->connection_index,
+                 ss->thread_index, verbose);
+      if (verbose == 1)
+       s = format (s, "%v", str);
+      if (verbose > 1)
+       s = format (s, "%U", format_stream_session_fifos, ss);
     }
   else if (ss->session_state == SESSION_STATE_LISTENING)
     {
       s = format (s, "%-40U%v", tp_vft->format_listener, ss->connection_index,
                  str);
     }
-  else if (ss->session_state == SESSION_STATE_READY)
+  else if (ss->session_state == SESSION_STATE_CONNECTING)
     {
-      s =
-       format (s, "%-40U%v", tp_vft->format_half_open, ss->connection_index,
-               str);
+      s = format (s, "%-40U%v", tp_vft->format_half_open,
+                 ss->connection_index, str);
     }
   else if (ss->session_state == SESSION_STATE_CLOSED)
     {
-      s = format (s, "[CL] %-40U%v", tp_vft->format_connection,
-                 ss->connection_index, ss->thread_index, str);
+      s = format (s, "[CL] %-40U", tp_vft->format_connection,
+                 ss->connection_index, ss->thread_index, verbose);
+      if (verbose == 1)
+       s = format (s, "%v", str);
+      if (verbose > 1)
+       s = format (s, "%U", format_stream_session_fifos, ss);
     }
   else
     {
-      clib_warning ("Session in unknown state!");
+      clib_warning ("Session in state: %d!", ss->session_state);
     }
 
   vec_free (str);
@@ -78,9 +95,16 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
   stream_session_t *s;
   u8 *str = 0;
 
+  if (!smm->is_enabled)
+    {
+      return clib_error_return (0, "session layer is not enabled");
+    }
+
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (input, "verbose"))
+      if (unformat (input, "verbose %d", &verbose))
+       ;
+      else if (unformat (input, "verbose"))
        verbose = 1;
       else
        break;
@@ -100,11 +124,11 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
                           i, pool_elts (pool));
          if (verbose)
            {
-             if (once_per_pool)
+             if (once_per_pool && verbose == 1)
                {
-                 str = format (str, "%-40s%-20s%-20s%-15s",
-                               "Connection", "Rx fifo", "Tx fifo",
-                               "Session Index");
+                 str =
+                   format (str, "%-50s%-15s%-10s%-10s%-10s", "Connection",
+                           "State", "Rx-f", "Tx-f", "S-idx");
                  vlib_cli_output (vm, "%v", str);
                  vec_reset_length (str);
                  once_per_pool = 0;
@@ -113,7 +137,9 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
               /* *INDENT-OFF* */
               pool_foreach (s, pool,
               ({
-                vlib_cli_output (vm, "%U", format_stream_session, s, verbose);
+               vec_reset_length (str);
+                str = format (str, "%U", format_stream_session, s, verbose);
+                vlib_cli_output (vm, "%v", str);
               }));
               /* *INDENT-ON* */
            }
@@ -126,11 +152,14 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
   return 0;
 }
 
-VLIB_CLI_COMMAND (show_uri_command, static) =
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (show_session_command, static) =
 {
-.path = "show session",.short_help = "show session [verbose]",.function =
-    show_session_command_fn,};
-
+  .path = "show session",
+  .short_help = "show session [verbose]",
+  .function = show_session_command_fn,
+};
+/* *INDENT-ON* */
 
 static clib_error_t *
 clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
@@ -142,6 +171,11 @@ clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
   stream_session_t *pool, *session;
   application_t *server;
 
+  if (!smm->is_enabled)
+    {
+      return clib_error_return (0, "session layer is not enabled");
+    }
+
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
       if (unformat (input, "thread %d", &thread_index))
@@ -174,11 +208,43 @@ clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
   return 0;
 }
 
-VLIB_CLI_COMMAND (clear_uri_session_command, static) =
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (clear_session_command, static) =
+{
+  .path = "clear session",
+  .short_help = "clear session thread <thread> session <index>",
+  .function = clear_session_command_fn,
+};
+/* *INDENT-ON* */
+
+static clib_error_t *
+session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input,
+                          vlib_cli_command_t * cmd)
+{
+  u8 is_en = 1;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "enable"))
+       is_en = 1;
+      else if (unformat (input, "disable"))
+       is_en = 0;
+      else
+       return clib_error_return (0, "unknown input `%U'",
+                                 format_unformat_error, input);
+    }
+
+  return vnet_session_enable_disable (vm, is_en);
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (session_enable_disable_command, static) =
 {
-.path = "clear session",.short_help =
-    "clear session thread <thread> session <index>",.function =
-    clear_session_command_fn,};
+  .path = "session",
+  .short_help = "session [enable|disable]",
+  .function = session_enable_disable_fn,
+};
+/* *INDENT-ON* */
 
 /*
  * fd.io coding-style-patch-verification: ON