Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #include <vnet/session/application.h> |
| 16 | #include <vnet/session/session.h> |
| 17 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 18 | u8 * |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 19 | format_session_fifos (u8 * s, va_list * args) |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 20 | { |
| 21 | stream_session_t *ss = va_arg (*args, stream_session_t *); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 22 | int verbose = va_arg (*args, int); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 23 | session_event_t _e, *e = &_e; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 24 | u8 found; |
| 25 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 26 | if (!ss->server_rx_fifo || !ss->server_tx_fifo) |
| 27 | return s; |
| 28 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 29 | s = format (s, " Rx fifo: %U", format_svm_fifo, ss->server_rx_fifo, |
| 30 | verbose); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 31 | if (verbose > 2 && ss->server_rx_fifo->has_event) |
| 32 | { |
| 33 | found = session_node_lookup_fifo_event (ss->server_rx_fifo, e); |
| 34 | s = format (s, " session node event: %s\n", |
| 35 | found ? "found" : "not found"); |
| 36 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 37 | s = format (s, " Tx fifo: %U", format_svm_fifo, ss->server_tx_fifo, |
| 38 | verbose); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 39 | if (verbose > 2 && ss->server_tx_fifo->has_event) |
| 40 | { |
| 41 | found = session_node_lookup_fifo_event (ss->server_tx_fifo, e); |
| 42 | s = format (s, " session node event: %s\n", |
| 43 | found ? "found" : "not found"); |
| 44 | } |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 45 | return s; |
| 46 | } |
| 47 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 48 | /** |
| 49 | * Format stream session as per the following format |
| 50 | * |
| 51 | * verbose: |
| 52 | * "Connection", "Rx fifo", "Tx fifo", "Session Index" |
| 53 | * non-verbose: |
| 54 | * "Connection" |
| 55 | */ |
| 56 | u8 * |
| 57 | format_stream_session (u8 * s, va_list * args) |
| 58 | { |
| 59 | stream_session_t *ss = va_arg (*args, stream_session_t *); |
| 60 | int verbose = va_arg (*args, int); |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 61 | u32 tp = session_get_transport_proto (ss); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 62 | u8 *str = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 63 | |
Florin Coras | 6881062 | 2017-07-24 17:40:28 -0700 | [diff] [blame] | 64 | if (verbose == 1 && ss->session_state >= SESSION_STATE_ACCEPTING) |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 65 | str = format (0, "%-10u%-10u", |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 66 | svm_fifo_max_dequeue (ss->server_rx_fifo), |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 67 | svm_fifo_max_dequeue (ss->server_tx_fifo)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 68 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 69 | if (ss->session_state >= SESSION_STATE_ACCEPTING) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 70 | { |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 71 | s = format (s, "%U", format_transport_connection, tp, |
| 72 | ss->connection_index, ss->thread_index, verbose); |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 73 | if (verbose == 1) |
| 74 | s = format (s, "%v", str); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 75 | if (verbose > 1) |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 76 | s = format (s, "%U", format_session_fifos, ss, verbose); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 77 | } |
| 78 | else if (ss->session_state == SESSION_STATE_LISTENING) |
| 79 | { |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 80 | s = format (s, "%-40U%v", format_transport_listen_connection, |
| 81 | tp, ss->connection_index, str); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 82 | if (verbose > 1) |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 83 | s = format (s, "\n%U", format_session_fifos, ss, verbose); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 84 | } |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 85 | else if (ss->session_state == SESSION_STATE_CONNECTING) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 86 | { |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 87 | s = format (s, "%-40U%v", format_transport_half_open_connection, |
| 88 | tp, ss->connection_index, str); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 89 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 90 | else |
| 91 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 92 | clib_warning ("Session in state: %d!", ss->session_state); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 93 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 94 | vec_free (str); |
| 95 | |
| 96 | return s; |
| 97 | } |
| 98 | |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 99 | uword |
| 100 | unformat_stream_session_id (unformat_input_t * input, va_list * args) |
| 101 | { |
| 102 | u8 *proto = va_arg (*args, u8 *); |
| 103 | ip46_address_t *lcl = va_arg (*args, ip46_address_t *); |
| 104 | ip46_address_t *rmt = va_arg (*args, ip46_address_t *); |
| 105 | u16 *lcl_port = va_arg (*args, u16 *); |
| 106 | u16 *rmt_port = va_arg (*args, u16 *); |
| 107 | u8 *is_ip4 = va_arg (*args, u8 *); |
| 108 | u8 tuple_is_set = 0; |
| 109 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 110 | clib_memset (lcl, 0, sizeof (*lcl)); |
| 111 | clib_memset (rmt, 0, sizeof (*rmt)); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 112 | |
| 113 | if (unformat (input, "tcp")) |
| 114 | { |
| 115 | *proto = TRANSPORT_PROTO_TCP; |
| 116 | } |
| 117 | if (unformat (input, "udp")) |
| 118 | { |
| 119 | *proto = TRANSPORT_PROTO_UDP; |
| 120 | } |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 121 | if (unformat (input, "%U:%d->%U:%d", unformat_ip4_address, &lcl->ip4, |
| 122 | lcl_port, unformat_ip4_address, &rmt->ip4, rmt_port)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 123 | { |
| 124 | *is_ip4 = 1; |
| 125 | tuple_is_set = 1; |
| 126 | } |
| 127 | else if (unformat (input, "%U:%d->%U:%d", unformat_ip6_address, &lcl->ip6, |
| 128 | lcl_port, unformat_ip6_address, &rmt->ip6, rmt_port)) |
| 129 | { |
| 130 | *is_ip4 = 0; |
| 131 | tuple_is_set = 1; |
| 132 | } |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 133 | |
Chris Luke | b2bcad6 | 2017-09-18 08:51:22 -0400 | [diff] [blame] | 134 | return tuple_is_set; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | uword |
| 138 | unformat_stream_session (unformat_input_t * input, va_list * args) |
| 139 | { |
| 140 | stream_session_t **result = va_arg (*args, stream_session_t **); |
| 141 | stream_session_t *s; |
| 142 | u8 proto = ~0; |
| 143 | ip46_address_t lcl, rmt; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 144 | u32 lcl_port = 0, rmt_port = 0, fib_index = 0; |
| 145 | u8 is_ip4 = 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 146 | |
Chris Luke | b2bcad6 | 2017-09-18 08:51:22 -0400 | [diff] [blame] | 147 | if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt, |
| 148 | &lcl_port, &rmt_port, &is_ip4)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 149 | return 0; |
| 150 | |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 151 | if (is_ip4) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 152 | s = session_lookup_safe4 (fib_index, &lcl.ip4, &rmt.ip4, |
| 153 | clib_host_to_net_u16 (lcl_port), |
| 154 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 155 | else |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 156 | s = session_lookup_safe6 (fib_index, &lcl.ip6, &rmt.ip6, |
| 157 | clib_host_to_net_u16 (lcl_port), |
| 158 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 159 | if (s) |
| 160 | { |
| 161 | *result = s; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 162 | session_pool_remove_peeker (s->thread_index); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 163 | return 1; |
| 164 | } |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | uword |
| 169 | unformat_transport_connection (unformat_input_t * input, va_list * args) |
| 170 | { |
| 171 | transport_connection_t **result = va_arg (*args, transport_connection_t **); |
| 172 | u32 suggested_proto = va_arg (*args, u32); |
| 173 | transport_connection_t *tc; |
| 174 | u8 proto = ~0; |
| 175 | ip46_address_t lcl, rmt; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 176 | u32 lcl_port = 0, rmt_port = 0, fib_index = 0; |
| 177 | u8 is_ip4 = 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 178 | |
Chris Luke | b2bcad6 | 2017-09-18 08:51:22 -0400 | [diff] [blame] | 179 | if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt, |
| 180 | &lcl_port, &rmt_port, &is_ip4)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 181 | return 0; |
| 182 | |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 183 | proto = (proto == (u8) ~ 0) ? suggested_proto : proto; |
| 184 | if (proto == (u8) ~ 0) |
| 185 | return 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 186 | if (is_ip4) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 187 | tc = session_lookup_connection4 (fib_index, &lcl.ip4, &rmt.ip4, |
| 188 | clib_host_to_net_u16 (lcl_port), |
| 189 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 190 | else |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 191 | tc = session_lookup_connection6 (fib_index, &lcl.ip6, &rmt.ip6, |
| 192 | clib_host_to_net_u16 (lcl_port), |
| 193 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 194 | |
| 195 | if (tc) |
| 196 | { |
| 197 | *result = tc; |
| 198 | return 1; |
| 199 | } |
| 200 | return 0; |
| 201 | } |
| 202 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 203 | static clib_error_t * |
| 204 | show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 205 | vlib_cli_command_t * cmd) |
| 206 | { |
| 207 | session_manager_main_t *smm = &session_manager_main; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 208 | u8 *str = 0, one_session = 0, do_listeners = 0, sst; |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 209 | stream_session_t *pool, *s; |
| 210 | u32 transport_proto = ~0; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 211 | app_worker_t *app_wrk; |
| 212 | int verbose = 0, i; |
| 213 | const u8 *app_name; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 214 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 215 | if (!smm->is_enabled) |
| 216 | { |
flyingeagle23 | e212506 | 2017-04-20 20:01:14 +0800 | [diff] [blame] | 217 | return clib_error_return (0, "session layer is not enabled"); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 220 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 221 | { |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 222 | if (unformat (input, "verbose %d", &verbose)) |
| 223 | ; |
| 224 | else if (unformat (input, "verbose")) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 225 | verbose = 1; |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 226 | else if (unformat (input, "listeners %U", unformat_transport_proto, |
| 227 | &transport_proto)) |
| 228 | do_listeners = 1; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 229 | else if (unformat (input, "%U", unformat_stream_session, &s)) |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 230 | { |
| 231 | one_session = 1; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 232 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 233 | else |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 234 | return clib_error_return (0, "unknown input `%U'", |
| 235 | format_unformat_error, input); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 238 | if (one_session) |
| 239 | { |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 240 | vlib_cli_output (vm, "%U", format_stream_session, s, 3); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 241 | return 0; |
| 242 | } |
| 243 | |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 244 | if (do_listeners) |
| 245 | { |
| 246 | sst = session_type_from_proto_and_ip (transport_proto, 1); |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 247 | vlib_cli_output (vm, "%-40s%-24s", "Listener", "App"); |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 248 | /* *INDENT-OFF* */ |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 249 | pool_foreach (s, smm->wrk[0].sessions, ({ |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 250 | if (s->session_state != SESSION_STATE_LISTENING |
| 251 | || s->session_type != sst) |
| 252 | continue; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 253 | app_wrk = app_worker_get (s->app_wrk_index); |
| 254 | app_name = application_name_from_index (app_wrk->app_index); |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 255 | vlib_cli_output (vm, "%U%-25v%", format_stream_session, s, 1, |
| 256 | app_name); |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 257 | })); |
| 258 | /* *INDENT-ON* */ |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 262 | for (i = 0; i < vec_len (smm->wrk); i++) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 263 | { |
| 264 | u32 once_per_pool; |
Florin Coras | 0d883a4 | 2018-10-31 12:25:38 -0700 | [diff] [blame] | 265 | pool = smm->wrk[i].sessions; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 266 | |
| 267 | once_per_pool = 1; |
| 268 | |
| 269 | if (pool_elts (pool)) |
| 270 | { |
| 271 | |
| 272 | vlib_cli_output (vm, "Thread %d: %d active sessions", |
| 273 | i, pool_elts (pool)); |
| 274 | if (verbose) |
| 275 | { |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 276 | if (once_per_pool && verbose == 1) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 277 | { |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 278 | str = format (str, "%-50s%-15s%-10s%-10s", |
| 279 | "Connection", "State", "Rx-f", "Tx-f"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 280 | vlib_cli_output (vm, "%v", str); |
| 281 | vec_reset_length (str); |
| 282 | once_per_pool = 0; |
| 283 | } |
| 284 | |
| 285 | /* *INDENT-OFF* */ |
| 286 | pool_foreach (s, pool, |
| 287 | ({ |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 288 | vec_reset_length (str); |
| 289 | str = format (str, "%U", format_stream_session, s, verbose); |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 290 | vlib_cli_output (vm, "%v", str); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 291 | })); |
| 292 | /* *INDENT-ON* */ |
| 293 | } |
| 294 | } |
| 295 | else |
| 296 | vlib_cli_output (vm, "Thread %d: no active sessions", i); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 297 | vec_reset_length (str); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 298 | } |
| 299 | vec_free (str); |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 304 | /* *INDENT-OFF* */ |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 305 | VLIB_CLI_COMMAND (vlib_cli_show_session_command) = |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 306 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 307 | .path = "show session", |
root | c9d1c5b | 2017-08-15 12:58:31 -0400 | [diff] [blame] | 308 | .short_help = "show session [verbose [nnn]]", |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 309 | .function = show_session_command_fn, |
| 310 | }; |
| 311 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 312 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 313 | static int |
| 314 | clear_session (stream_session_t * s) |
| 315 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 316 | app_worker_t *server_wrk = app_worker_get (s->app_wrk_index); |
| 317 | application_t *server = application_get (server_wrk->app_index); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 318 | server->cb_fns.session_disconnect_callback (s); |
| 319 | return 0; |
| 320 | } |
| 321 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 322 | static clib_error_t * |
| 323 | clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 324 | vlib_cli_command_t * cmd) |
| 325 | { |
| 326 | session_manager_main_t *smm = &session_manager_main; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 327 | u32 thread_index = 0, clear_all = 0; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 328 | session_manager_worker_t *wrk; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 329 | u32 session_index = ~0; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 330 | stream_session_t *session; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 331 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 332 | if (!smm->is_enabled) |
| 333 | { |
flyingeagle23 | e212506 | 2017-04-20 20:01:14 +0800 | [diff] [blame] | 334 | return clib_error_return (0, "session layer is not enabled"); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 337 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 338 | { |
| 339 | if (unformat (input, "thread %d", &thread_index)) |
| 340 | ; |
| 341 | else if (unformat (input, "session %d", &session_index)) |
| 342 | ; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 343 | else if (unformat (input, "all")) |
| 344 | clear_all = 1; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 345 | else |
| 346 | return clib_error_return (0, "unknown input `%U'", |
| 347 | format_unformat_error, input); |
| 348 | } |
| 349 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 350 | if (!clear_all && session_index == ~0) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 351 | return clib_error_return (0, "session <nn> required, but not set."); |
| 352 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 353 | if (session_index != ~0) |
| 354 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 355 | session = session_get_if_valid (session_index, thread_index); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 356 | if (!session) |
| 357 | return clib_error_return (0, "no session %d on thread %d", |
| 358 | session_index, thread_index); |
| 359 | clear_session (session); |
| 360 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 361 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 362 | if (clear_all) |
| 363 | { |
| 364 | /* *INDENT-OFF* */ |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 365 | vec_foreach (wrk, smm->wrk) |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 366 | { |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 367 | pool_foreach(session, wrk->sessions, ({ |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 368 | clear_session (session); |
| 369 | })); |
| 370 | }; |
| 371 | /* *INDENT-ON* */ |
| 372 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 377 | /* *INDENT-OFF* */ |
| 378 | VLIB_CLI_COMMAND (clear_session_command, static) = |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 379 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 380 | .path = "clear session", |
| 381 | .short_help = "clear session thread <thread> session <index>", |
| 382 | .function = clear_session_command_fn, |
| 383 | }; |
| 384 | /* *INDENT-ON* */ |
| 385 | |
| 386 | static clib_error_t * |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 387 | show_session_fifo_trace_command_fn (vlib_main_t * vm, |
| 388 | unformat_input_t * input, |
| 389 | vlib_cli_command_t * cmd) |
| 390 | { |
| 391 | stream_session_t *s = 0; |
| 392 | u8 is_rx = 0, *str = 0; |
| 393 | |
| 394 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 395 | { |
| 396 | if (unformat (input, "%U", unformat_stream_session, &s)) |
| 397 | ; |
| 398 | else if (unformat (input, "rx")) |
| 399 | is_rx = 1; |
| 400 | else if (unformat (input, "tx")) |
| 401 | is_rx = 0; |
| 402 | else |
| 403 | return clib_error_return (0, "unknown input `%U'", |
| 404 | format_unformat_error, input); |
| 405 | } |
| 406 | |
| 407 | if (!SVM_FIFO_TRACE) |
| 408 | { |
| 409 | vlib_cli_output (vm, "fifo tracing not enabled"); |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | if (!s) |
| 414 | { |
| 415 | vlib_cli_output (vm, "could not find session"); |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | str = is_rx ? |
| 420 | svm_fifo_dump_trace (str, s->server_rx_fifo) : |
| 421 | svm_fifo_dump_trace (str, s->server_tx_fifo); |
| 422 | |
| 423 | vlib_cli_output (vm, "%v", str); |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | /* *INDENT-OFF* */ |
| 428 | VLIB_CLI_COMMAND (show_session_fifo_trace_command, static) = |
| 429 | { |
| 430 | .path = "show session fifo trace", |
| 431 | .short_help = "show session fifo trace <session>", |
| 432 | .function = show_session_fifo_trace_command_fn, |
| 433 | }; |
| 434 | /* *INDENT-ON* */ |
| 435 | |
| 436 | static clib_error_t * |
| 437 | session_replay_fifo_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 438 | vlib_cli_command_t * cmd) |
| 439 | { |
| 440 | stream_session_t *s = 0; |
| 441 | u8 is_rx = 0, *str = 0; |
| 442 | |
| 443 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 444 | { |
| 445 | if (unformat (input, "%U", unformat_stream_session, &s)) |
| 446 | ; |
| 447 | else if (unformat (input, "rx")) |
| 448 | is_rx = 1; |
| 449 | else |
| 450 | return clib_error_return (0, "unknown input `%U'", |
| 451 | format_unformat_error, input); |
| 452 | } |
| 453 | |
| 454 | if (!SVM_FIFO_TRACE) |
| 455 | { |
| 456 | vlib_cli_output (vm, "fifo tracing not enabled"); |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | if (!s) |
| 461 | { |
| 462 | vlib_cli_output (vm, "could not find session"); |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | str = is_rx ? |
| 467 | svm_fifo_replay (str, s->server_rx_fifo, 0, 1) : |
| 468 | svm_fifo_replay (str, s->server_tx_fifo, 0, 1); |
| 469 | |
| 470 | vlib_cli_output (vm, "%v", str); |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | /* *INDENT-OFF* */ |
| 475 | VLIB_CLI_COMMAND (session_replay_fifo_trace_command, static) = |
| 476 | { |
| 477 | .path = "session replay fifo", |
| 478 | .short_help = "session replay fifo <session>", |
| 479 | .function = session_replay_fifo_command_fn, |
| 480 | }; |
| 481 | /* *INDENT-ON* */ |
| 482 | |
| 483 | static clib_error_t * |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 484 | session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input, |
| 485 | vlib_cli_command_t * cmd) |
| 486 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 487 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 488 | u8 is_en = 1; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 489 | clib_error_t *error; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 490 | |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 491 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 492 | return clib_error_return (0, "expected enable | disable"); |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 493 | |
| 494 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 495 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 496 | if (unformat (line_input, "enable")) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 497 | is_en = 1; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 498 | else if (unformat (line_input, "disable")) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 499 | is_en = 0; |
| 500 | else |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 501 | { |
| 502 | error = clib_error_return (0, "unknown input `%U'", |
| 503 | format_unformat_error, line_input); |
| 504 | unformat_free (line_input); |
| 505 | return error; |
| 506 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 509 | unformat_free (line_input); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 510 | return vnet_session_enable_disable (vm, is_en); |
| 511 | } |
| 512 | |
| 513 | /* *INDENT-OFF* */ |
| 514 | VLIB_CLI_COMMAND (session_enable_disable_command, static) = |
| 515 | { |
| 516 | .path = "session", |
| 517 | .short_help = "session [enable|disable]", |
| 518 | .function = session_enable_disable_fn, |
| 519 | }; |
| 520 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 521 | |
| 522 | /* |
| 523 | * fd.io coding-style-patch-verification: ON |
| 524 | * |
| 525 | * Local Variables: |
| 526 | * eval: (c-set-style "gnu") |
| 527 | * End: |
| 528 | */ |