+static void
+session_cli_show_all_sessions (vlib_main_t * vm, int verbose)
+{
+ session_main_t *smm = &session_main;
+ u32 n_closed, thread_index;
+ session_t *pool, *s;
+
+ for (thread_index = 0; thread_index < vec_len (smm->wrk); thread_index++)
+ {
+ pool = smm->wrk[thread_index].sessions;
+
+ if (!pool_elts (pool))
+ {
+ vlib_cli_output (vm, "Thread %d: no sessions", thread_index);
+ continue;
+ }
+
+ if (!verbose)
+ {
+ vlib_cli_output (vm, "Thread %d: %d sessions", thread_index,
+ pool_elts (pool));
+ continue;
+ }
+
+ if (pool_elts (pool) > 50)
+ {
+ vlib_cli_output (vm, "Thread %u: %d sessions. Verbose output "
+ "suppressed. For more details use filters.",
+ thread_index, pool_elts (pool));
+ continue;
+ }
+
+ if (verbose == 1)
+ vlib_cli_output (vm, "%s%-50s%-15s%-10s%-10s",
+ thread_index ? "\n" : "",
+ "Connection", "State", "Rx-f", "Tx-f");
+
+ n_closed = 0;
+
+ /* *INDENT-OFF* */
+ pool_foreach(s, pool, ({
+ if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
+ {
+ n_closed += 1;
+ continue;
+ }
+ vlib_cli_output (vm, "%U", format_session, s, verbose);
+ }));
+ /* *INDENT-ON* */
+
+ if (!n_closed)
+ vlib_cli_output (vm, "Thread %d: active sessions %u", thread_index,
+ pool_elts (pool) - n_closed);
+ else
+ vlib_cli_output (vm, "Thread %d: active sessions %u closed %u",
+ thread_index, pool_elts (pool) - n_closed, n_closed);
+ }
+}
+
+static int
+session_cli_filter_check (session_t * s, session_state_t * states,
+ transport_proto_t tp)
+{
+ if (states)
+ {
+ session_state_t *state;
+ vec_foreach (state, states) if (s->session_state == *state)
+ goto check_transport;
+ return 0;
+ }
+
+check_transport:
+
+ if (tp != TRANSPORT_PROTO_INVALID && session_get_transport_proto (s) != tp)
+ return 0;
+
+ return 1;
+}
+
+static void
+session_cli_show_session_filter (vlib_main_t * vm, u32 thread_index,
+ u32 start, u32 end, session_state_t * states,
+ transport_proto_t tp, int verbose)
+{
+ u8 output_suppressed = 0;
+ session_worker_t *wrk;
+ session_t *pool, *s;
+ u32 count = 0, max_index;
+ int i;
+
+ wrk = session_main_get_worker_if_valid (thread_index);
+ if (!wrk)
+ {
+ vlib_cli_output (vm, "invalid thread index %u", thread_index);
+ return;
+ }
+
+ pool = wrk->sessions;
+
+ if (tp == TRANSPORT_PROTO_INVALID && states == 0 && !verbose
+ && (start == 0 && end == ~0))
+ {
+ vlib_cli_output (vm, "Thread %d: %u sessions", thread_index,
+ pool_elts (pool));
+ return;
+ }
+
+ max_index = pool_len (pool) ? pool_len (pool) - 1 : 0;
+ for (i = start; i <= clib_min (end, max_index); i++)
+ {
+ if (pool_is_free_index (pool, i))
+ continue;
+
+ s = pool_elt_at_index (pool, i);
+
+ if (session_cli_filter_check (s, states, tp))
+ {
+ count += 1;
+ if (verbose)
+ {
+ if (count > 50 || (verbose > 1 && count > 10))
+ {
+ output_suppressed = 1;
+ continue;
+ }
+ if (s->session_state < SESSION_STATE_TRANSPORT_DELETED)
+ vlib_cli_output (vm, "%U", format_session, s, verbose);
+ }
+ }
+ }
+
+ if (!output_suppressed)
+ vlib_cli_output (vm, "Thread %d: %u sessions matched filter",
+ thread_index, count);
+ else
+ vlib_cli_output (vm, "Thread %d: %u sessions matched filter. Not all"
+ " shown. Use finer grained filter.", thread_index,
+ count);
+}
+
+void
+session_cli_show_events_thread (vlib_main_t * vm, u32 thread_index)
+{
+ session_worker_t *wrk;
+
+ wrk = session_main_get_worker_if_valid (thread_index);
+ if (!wrk)
+ {
+ vlib_cli_output (vm, "invalid thread index %u", thread_index);
+ return;
+ }
+
+ vlib_cli_output (vm, "Thread %d:\n", thread_index);
+ vlib_cli_output (vm, " evt elements alloc: %u",
+ pool_elts (wrk->event_elts));
+ vlib_cli_output (vm, " ctrl evt elt data alloc: %d",
+ pool_elts (wrk->ctrl_evts_data));
+}
+
+static void
+session_cli_show_events (vlib_main_t * vm, u32 thread_index)
+{
+ session_main_t *smm = &session_main;
+ if (!thread_index)
+ {
+ session_cli_show_events_thread (vm, thread_index);
+ return;
+ }
+
+ for (thread_index = 0; thread_index < vec_len (smm->wrk); thread_index++)
+ session_cli_show_events_thread (vm, thread_index);
+}
+
+static void
+session_cli_print_session_states (vlib_main_t * vm)
+{
+#define _(sym, str) vlib_cli_output (vm, str);
+ foreach_session_state
+#undef _
+}
+