session: separate ctrl, new and old events
[vpp.git] / src / vnet / session / session_cli.c
index 99baf44..fd598f4 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
 u8 *
 format_session_fifos (u8 * s, va_list * args)
 {
-  stream_session_t *ss = va_arg (*args, stream_session_t *);
+  session_t *ss = va_arg (*args, session_t *);
   int verbose = va_arg (*args, int);
   session_event_t _e, *e = &_e;
   u8 found;
 
-  if (!ss->server_rx_fifo || !ss->server_tx_fifo)
+  if (!ss->rx_fifo || !ss->tx_fifo)
     return s;
 
-  s = format (s, " Rx fifo: %U", format_svm_fifo, ss->server_rx_fifo,
-             verbose);
-  if (verbose > 2 && ss->server_rx_fifo->has_event)
+  s = format (s, " Rx fifo: %U", format_svm_fifo, ss->rx_fifo, verbose);
+  if (verbose > 2 && ss->rx_fifo->has_event)
     {
-      found = session_node_lookup_fifo_event (ss->server_rx_fifo, e);
+      found = session_node_lookup_fifo_event (ss->rx_fifo, e);
       s = format (s, " session node event: %s\n",
                  found ? "found" : "not found");
     }
-  s = format (s, " Tx fifo: %U", format_svm_fifo, ss->server_tx_fifo,
-             verbose);
-  if (verbose > 2 && ss->server_tx_fifo->has_event)
+  s = format (s, " Tx fifo: %U", format_svm_fifo, ss->tx_fifo, verbose);
+  if (verbose > 2 && ss->tx_fifo->has_event)
     {
-      found = session_node_lookup_fifo_event (ss->server_tx_fifo, e);
+      found = session_node_lookup_fifo_event (ss->tx_fifo, e);
       s = format (s, " session node event: %s\n",
                  found ? "found" : "not found");
     }
@@ -54,14 +52,14 @@ format_session_fifos (u8 * s, va_list * args)
  *   "Connection"
  */
 u8 *
-format_stream_session (u8 * s, va_list * args)
+format_session (u8 * s, va_list * args)
 {
-  stream_session_t *ss = va_arg (*args, stream_session_t *);
+  session_t *ss = va_arg (*args, session_t *);
   int verbose = va_arg (*args, int);
   u32 tp = session_get_transport_proto (ss);
   u8 *str = 0;
 
-  if (ss->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+  if (ss->session_state >= SESSION_STATE_TRANSPORT_DELETED)
     {
       s = format (s, "[%u:%u] CLOSED", ss->thread_index, ss->session_index);
       return s;
@@ -70,15 +68,17 @@ format_stream_session (u8 * s, va_list * args)
   if (verbose == 1)
     {
       u8 post_accept = ss->session_state >= SESSION_STATE_ACCEPTING;
-      u8 hasf = post_accept | session_tx_is_dgram (ss);
+      u8 hasf = post_accept
+       || session_transport_service_type (ss) == TRANSPORT_SERVICE_CL;
       u32 rxf, txf;
 
-      rxf = hasf ? svm_fifo_max_dequeue (ss->server_rx_fifo) : 0;
-      txf = hasf ? svm_fifo_max_dequeue (ss->server_tx_fifo) : 0;
+      rxf = hasf ? svm_fifo_max_dequeue (ss->rx_fifo) : 0;
+      txf = hasf ? svm_fifo_max_dequeue (ss->tx_fifo) : 0;
       str = format (0, "%-10u%-10u", rxf, txf);
     }
 
-  if (ss->session_state >= SESSION_STATE_ACCEPTING)
+  if (ss->session_state >= SESSION_STATE_ACCEPTING
+      || ss->session_state == SESSION_STATE_CREATED)
     {
       s = format (s, "%U", format_transport_connection, tp,
                  ss->connection_index, ss->thread_index, verbose);
@@ -90,14 +90,14 @@ format_stream_session (u8 * s, va_list * args)
   else if (ss->session_state == SESSION_STATE_LISTENING)
     {
       s = format (s, "%U%v", format_transport_listen_connection,
-                 tp, ss->connection_index, verbose, str);
+                 tp, ss->connection_index, ss->thread_index, verbose, str);
       if (verbose > 1)
        s = format (s, "\n%U", format_session_fifos, ss, verbose);
     }
   else if (ss->session_state == SESSION_STATE_CONNECTING)
     {
       s = format (s, "%-40U%v", format_transport_half_open_connection,
-                 tp, ss->connection_index, str);
+                 tp, ss->connection_index, ss->thread_index, str);
     }
   else
     {
@@ -162,12 +162,12 @@ unformat_stream_session_id (unformat_input_t * input, va_list * args)
 }
 
 uword
-unformat_stream_session (unformat_input_t * input, va_list * args)
+unformat_session (unformat_input_t * input, va_list * args)
 {
-  stream_session_t **result = va_arg (*args, stream_session_t **);
+  session_t **result = va_arg (*args, session_t **);
   u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
   ip46_address_t lcl, rmt;
-  stream_session_t *s;
+  session_t *s;
   u8 proto = ~0;
   u8 is_ip4 = 0;
 
@@ -232,9 +232,9 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
                         vlib_cli_command_t * cmd)
 {
   u8 one_session = 0, do_listeners = 0, sst, do_elog = 0;
-  session_manager_main_t *smm = &session_manager_main;
+  session_main_t *smm = &session_main;
   u32 transport_proto = ~0, track_index;
-  stream_session_t *pool, *s;
+  session_t *pool, *s;
   transport_connection_t *tc;
   app_worker_t *app_wrk;
   int verbose = 0, i;
@@ -254,7 +254,7 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
       else if (unformat (input, "listeners %U", unformat_transport_proto,
                         &transport_proto))
        do_listeners = 1;
-      else if (unformat (input, "%U", unformat_stream_session, &s))
+      else if (unformat (input, "%U", unformat_session, &s))
        {
          one_session = 1;
        }
@@ -267,7 +267,7 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
 
   if (one_session)
     {
-      u8 *str = format (0, "%U", format_stream_session, s, 3);
+      u8 *str = format (0, "%U", format_session, s, 3);
       if (do_elog && s->session_state != SESSION_STATE_LISTENING)
        {
          elog_main_t *em = &vm->elog_main;
@@ -297,7 +297,7 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
          continue;
        app_wrk = app_worker_get (s->app_wrk_index);
        app_name = application_name_from_index (app_wrk->app_index);
-       vlib_cli_output (vm, "%U%-25v%", format_stream_session, s, 0,
+       vlib_cli_output (vm, "%U%-25v%", format_session, s, 0,
                         app_name);
       }));
       /* *INDENT-ON* */
@@ -330,12 +330,12 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
 
       /* *INDENT-OFF* */
       pool_foreach (s, pool, ({
-        if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+        if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
           {
             n_closed += 1;
             continue;
           }
-        vlib_cli_output (vm, "%U", format_stream_session, s, verbose);
+        vlib_cli_output (vm, "%U", format_session, s, verbose);
       }));
       /* *INDENT-ON* */
 
@@ -361,11 +361,10 @@ VLIB_CLI_COMMAND (vlib_cli_show_session_command) =
 /* *INDENT-ON* */
 
 static int
-clear_session (stream_session_t * s)
+clear_session (session_t * s)
 {
   app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
-  application_t *server = application_get (server_wrk->app_index);
-  server->cb_fns.session_disconnect_callback (s);
+  app_worker_close_notify (server_wrk, s);
   return 0;
 }
 
@@ -373,11 +372,11 @@ static clib_error_t *
 clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
                          vlib_cli_command_t * cmd)
 {
-  session_manager_main_t *smm = &session_manager_main;
+  session_main_t *smm = &session_main;
   u32 thread_index = 0, clear_all = 0;
-  session_manager_worker_t *wrk;
+  session_worker_t *wrk;
   u32 session_index = ~0;
-  stream_session_t *session;
+  session_t *session;
 
   if (!smm->is_enabled)
     {
@@ -438,12 +437,12 @@ show_session_fifo_trace_command_fn (vlib_main_t * vm,
                                    unformat_input_t * input,
                                    vlib_cli_command_t * cmd)
 {
-  stream_session_t *s = 0;
+  session_t *s = 0;
   u8 is_rx = 0, *str = 0;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (input, "%U", unformat_stream_session, &s))
+      if (unformat (input, "%U", unformat_session, &s))
        ;
       else if (unformat (input, "rx"))
        is_rx = 1;
@@ -467,8 +466,8 @@ show_session_fifo_trace_command_fn (vlib_main_t * vm,
     }
 
   str = is_rx ?
-    svm_fifo_dump_trace (str, s->server_rx_fifo) :
-    svm_fifo_dump_trace (str, s->server_tx_fifo);
+    svm_fifo_dump_trace (str, s->rx_fifo) :
+    svm_fifo_dump_trace (str, s->tx_fifo);
 
   vlib_cli_output (vm, "%v", str);
   return 0;
@@ -487,12 +486,12 @@ static clib_error_t *
 session_replay_fifo_command_fn (vlib_main_t * vm, unformat_input_t * input,
                                vlib_cli_command_t * cmd)
 {
-  stream_session_t *s = 0;
+  session_t *s = 0;
   u8 is_rx = 0, *str = 0;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (input, "%U", unformat_stream_session, &s))
+      if (unformat (input, "%U", unformat_session, &s))
        ;
       else if (unformat (input, "rx"))
        is_rx = 1;
@@ -514,8 +513,8 @@ session_replay_fifo_command_fn (vlib_main_t * vm, unformat_input_t * input,
     }
 
   str = is_rx ?
-    svm_fifo_replay (str, s->server_rx_fifo, 0, 1) :
-    svm_fifo_replay (str, s->server_tx_fifo, 0, 1);
+    svm_fifo_replay (str, s->rx_fifo, 0, 1) :
+    svm_fifo_replay (str, s->tx_fifo, 0, 1);
 
   vlib_cli_output (vm, "%v", str);
   return 0;