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