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