X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession%2Fsession_cli.c;h=344937c684a0a6c0e5b43dc6e19580db03569fed;hb=af21b2e6994893e97ad0fef52ca154c69a4a09cb;hp=b03353e564ad8173e1da475e08ca6b1f7efbca17;hpb=2d0b2bbb97d57cb4bac30e4f3138b70c277aee47;p=vpp.git diff --git a/src/vnet/session/session_cli.c b/src/vnet/session/session_cli.c old mode 100755 new mode 100644 index b03353e564a..344937c684a --- a/src/vnet/session/session_cli.c +++ b/src/vnet/session/session_cli.c @@ -27,14 +27,14 @@ format_session_fifos (u8 * s, va_list * args) return s; s = format (s, " Rx fifo: %U", format_svm_fifo, ss->rx_fifo, verbose); - if (verbose > 2 && ss->rx_fifo->has_event) + if (verbose > 2 && ss->rx_fifo->shr->has_event) { 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->tx_fifo, verbose); - if (verbose > 2 && ss->tx_fifo->has_event) + if (verbose > 2 && ss->tx_fifo->shr->has_event) { found = session_node_lookup_fifo_event (ss->tx_fifo, e); s = format (s, " session node event: %s\n", @@ -43,6 +43,52 @@ format_session_fifos (u8 * s, va_list * args) return s; } +const char *session_state_str[] = { +#define _(sym, str) str, + foreach_session_state +#undef _ +}; + +u8 * +format_session_state (u8 * s, va_list * args) +{ + session_t *ss = va_arg (*args, session_t *); + + if (ss->session_state < SESSION_N_STATES) + s = format (s, "%s", session_state_str[ss->session_state]); + else + s = format (s, "UNKNOWN STATE (%d)", ss->session_state); + + return s; +} + +const char *session_flags_str[] = { +#define _(sym, str) str, + foreach_session_flag +#undef _ +}; + +u8 * +format_session_flags (u8 * s, va_list * args) +{ + session_t *ss = va_arg (*args, session_t *); + int i, last = -1; + + for (i = 0; i < SESSION_N_FLAGS; i++) + if (ss->flags & (1 << i)) + last = i; + + for (i = 0; i < last; i++) + { + if (ss->flags & (1 << i)) + s = format (s, "%s, ", session_flags_str[i]); + } + if (last >= 0) + s = format (s, "%s", session_flags_str[last]); + + return s; +} + /** * Format stream session as per the following format * @@ -67,13 +113,10 @@ format_session (u8 * s, va_list * args) if (verbose == 1) { - u8 post_accept = ss->session_state >= SESSION_STATE_ACCEPTING; - u8 hasf = post_accept - || session_transport_service_type (ss) == TRANSPORT_SERVICE_CL; u32 rxf, txf; - rxf = hasf ? svm_fifo_max_dequeue (ss->rx_fifo) : 0; - txf = hasf ? svm_fifo_max_dequeue (ss->tx_fifo) : 0; + rxf = ss->rx_fifo ? svm_fifo_max_dequeue (ss->rx_fifo) : 0; + txf = ss->tx_fifo ? svm_fifo_max_dequeue (ss->tx_fifo) : 0; str = format (0, "%-10u%-10u", rxf, txf); } @@ -85,7 +128,12 @@ format_session (u8 * s, va_list * args) if (verbose == 1) s = format (s, "%v", str); if (verbose > 1) - s = format (s, "%U", format_session_fifos, ss, verbose); + { + s = format (s, "%U", format_session_fifos, ss, verbose); + s = format (s, " session: state: %U opaque: 0x%x flags: %U\n", + format_session_state, ss, ss->opaque, + format_session_flags, ss); + } } else if (ss->session_state == SESSION_STATE_LISTENING) { @@ -96,8 +144,12 @@ format_session (u8 * s, va_list * args) } else if (ss->session_state == SESSION_STATE_CONNECTING) { - s = format (s, "%-40U%v", format_transport_half_open_connection, - tp, ss->connection_index, ss->thread_index, str); + if (ss->flags & SESSION_F_HALF_OPEN) + s = format (s, "%U%v", format_transport_half_open_connection, tp, + ss->connection_index, ss->thread_index, verbose, str); + else + s = format (s, "%U", format_transport_connection, tp, + ss->connection_index, ss->thread_index, verbose); } else { @@ -207,7 +259,6 @@ unformat_session (unformat_input_t * input, va_list * args) if (s) { *result = s; - session_pool_remove_peeker (s->thread_index); return 1; } return 0; @@ -281,21 +332,22 @@ session_cli_show_all_sessions (vlib_main_t * vm, int verbose) } 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"); n_closed = 0; /* *INDENT-OFF* */ - pool_foreach(s, pool, ({ + 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) @@ -321,7 +373,7 @@ session_cli_filter_check (session_t * s, session_state_t * states, check_transport: - if (tp != TRANSPORT_N_PROTO && session_get_transport_proto (s) != tp) + if (tp != TRANSPORT_PROTO_INVALID && session_get_transport_proto (s) != tp) return 0; return 1; @@ -347,7 +399,7 @@ session_cli_show_session_filter (vlib_main_t * vm, u32 thread_index, pool = wrk->sessions; - if (tp == TRANSPORT_N_PROTO && states == 0 && !verbose + if (tp == TRANSPORT_PROTO_INVALID && states == 0 && !verbose && (start == 0 && end == ~0)) { vlib_cli_output (vm, "Thread %d: %u sessions", thread_index, @@ -388,12 +440,37 @@ session_cli_show_session_filter (vlib_main_t * vm, u32 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", + clib_llist_elts (wrk->event_elts)); + vlib_cli_output (vm, " ctrl evt elt data alloc: %d", + clib_llist_elts (wrk->ctrl_evts_data)); +} + static void -session_cli_print_transport_protos (vlib_main_t * vm) +session_cli_show_events (vlib_main_t * vm, u32 thread_index) { -#define _(sym, str, sstr) vlib_cli_output (vm, str); - foreach_transport_proto -#undef _ + 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 @@ -410,39 +487,33 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, { u8 one_session = 0, do_listeners = 0, sst, do_elog = 0, do_filter = 0; u32 track_index, thread_index = 0, start = 0, end = ~0, session_index; - unformat_input_t _line_input, *line_input = &_line_input; - transport_proto_t transport_proto = TRANSPORT_N_PROTO; + transport_proto_t transport_proto = TRANSPORT_PROTO_INVALID; session_state_t state = SESSION_N_STATES, *states = 0; session_main_t *smm = &session_main; clib_error_t *error = 0; app_worker_t *app_wrk; u32 transport_index; const u8 *app_name; + u8 do_events = 0; int verbose = 0; session_t *s; session_cli_return_if_not_enabled (); - if (!unformat_user (input, unformat_line_input, line_input)) - { - session_cli_show_all_sessions (vm, 0); - return 0; - } - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "verbose %d", &verbose)) + if (unformat (input, "verbose %d", &verbose)) ; - else if (unformat (line_input, "verbose")) + else if (unformat (input, "verbose")) verbose = 1; - else if (unformat (line_input, "listeners %U", unformat_transport_proto, + else if (unformat (input, "listeners %U", unformat_transport_proto, &transport_proto)) do_listeners = 1; - else if (unformat (line_input, "%U", unformat_session, &s)) + else if (unformat (input, "%U", unformat_session, &s)) { one_session = 1; } - else if (unformat (line_input, "thread %u index %u", &thread_index, + else if (unformat (input, "thread %u index %u", &thread_index, &session_index)) { s = session_get_if_valid (session_index, thread_index); @@ -453,19 +524,17 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, } one_session = 1; } - else if (unformat (line_input, "thread %u", &thread_index)) + else if (unformat (input, "thread %u", &thread_index)) { do_filter = 1; } - else - if (unformat (line_input, "state %U", unformat_session_state, &state)) + else if (unformat (input, "state %U", unformat_session_state, &state)) { vec_add1 (states, state); do_filter = 1; } - else if (unformat (line_input, "proto %U index %u", - unformat_transport_proto, &transport_proto, - &transport_index)) + else if (unformat (input, "proto %U index %u", unformat_transport_proto, + &transport_proto, &transport_index)) { transport_connection_t *tc; tc = transport_get_connection (transport_proto, transport_index, @@ -486,32 +555,34 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, } one_session = 1; } - else if (unformat (line_input, "proto %U", unformat_transport_proto, + else if (unformat (input, "proto %U", unformat_transport_proto, &transport_proto)) do_filter = 1; - else if (unformat (line_input, "range %u %u", &start, &end)) + else if (unformat (input, "range %u %u", &start, &end)) do_filter = 1; - else if (unformat (line_input, "range %u", &start)) + else if (unformat (input, "range %u", &start)) { end = start + 50; do_filter = 1; } - else if (unformat (line_input, "elog")) + else if (unformat (input, "elog")) do_elog = 1; - else if (unformat (line_input, "protos")) + else if (unformat (input, "protos")) { - session_cli_print_transport_protos (vm); + vlib_cli_output (vm, "%U", format_transport_protos); goto done; } - else if (unformat (line_input, "states")) + else if (unformat (input, "states")) { session_cli_print_session_states (vm); goto done; } + else if (unformat (input, "events")) + do_events = 1; else { error = clib_error_return (0, "unknown input `%U'", - format_unformat_error, line_input); + format_unformat_error, input); goto done; } } @@ -521,7 +592,7 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, 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; + elog_main_t *em = &vlib_global_main.elog_main; transport_connection_t *tc; f64 dt; @@ -541,9 +612,11 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, 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, ({ + pool_foreach (s, smm->wrk[0].sessions) { if (s->session_state != SESSION_STATE_LISTENING || s->session_type != sst) continue; @@ -551,11 +624,17 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, app_name = application_name_from_index (app_wrk->app_index); vlib_cli_output (vm, "%U%-25v%", format_session, s, 0, app_name); - })); + } /* *INDENT-ON* */ goto done; } + if (do_events) + { + session_cli_show_events (vm, thread_index); + goto done; + } + if (do_filter) { if (end < start) @@ -572,7 +651,6 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, session_cli_show_all_sessions (vm, verbose); done: - unformat_free (line_input); vec_free (states); return error; } @@ -642,9 +720,9 @@ clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input, /* *INDENT-OFF* */ vec_foreach (wrk, smm->wrk) { - pool_foreach(session, wrk->sessions, ({ + pool_foreach (session, wrk->sessions) { clear_session (session); - })); + } }; /* *INDENT-ON* */ } @@ -762,29 +840,22 @@ static clib_error_t * session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_en = 1; - clib_error_t *error; - - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); + u8 is_en = 2; - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "enable")) + if (unformat (input, "enable")) is_en = 1; - else if (unformat (line_input, "disable")) + else if (unformat (input, "disable")) is_en = 0; else - { - error = clib_error_return (0, "unknown input `%U'", - format_unformat_error, line_input); - unformat_free (line_input); - return error; - } + return clib_error_return (0, "unknown input `%U'", + format_unformat_error, input); } - unformat_free (line_input); + if (is_en > 1) + return clib_error_return (0, "expected enable | disable"); + return vnet_session_enable_disable (vm, is_en); }