Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 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 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 21 | session_t *ss = va_arg (*args, 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 | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 26 | if (!ss->rx_fifo || !ss->tx_fifo) |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 27 | return s; |
| 28 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 29 | s = format (s, " Rx fifo: %U", format_svm_fifo, ss->rx_fifo, verbose); |
Florin Coras | c547e91 | 2020-12-08 17:50:45 -0800 | [diff] [blame] | 30 | if (verbose > 2 && ss->rx_fifo->shr->has_event) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 31 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 32 | found = session_node_lookup_fifo_event (ss->rx_fifo, e); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 33 | s = format (s, " session node event: %s\n", |
| 34 | found ? "found" : "not found"); |
| 35 | } |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 36 | s = format (s, " Tx fifo: %U", format_svm_fifo, ss->tx_fifo, verbose); |
Florin Coras | c547e91 | 2020-12-08 17:50:45 -0800 | [diff] [blame] | 37 | if (verbose > 2 && ss->tx_fifo->shr->has_event) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 38 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 39 | found = session_node_lookup_fifo_event (ss->tx_fifo, e); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 40 | s = format (s, " session node event: %s\n", |
| 41 | found ? "found" : "not found"); |
| 42 | } |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 43 | return s; |
| 44 | } |
| 45 | |
Florin Coras | 91f90d0 | 2019-10-23 19:28:08 -0700 | [diff] [blame] | 46 | const char *session_state_str[] = { |
| 47 | #define _(sym, str) str, |
| 48 | foreach_session_state |
| 49 | #undef _ |
| 50 | }; |
| 51 | |
| 52 | u8 * |
| 53 | format_session_state (u8 * s, va_list * args) |
| 54 | { |
| 55 | session_t *ss = va_arg (*args, session_t *); |
| 56 | |
| 57 | if (ss->session_state < SESSION_N_STATES) |
| 58 | s = format (s, "%s", session_state_str[ss->session_state]); |
| 59 | else |
| 60 | s = format (s, "UNKNOWN STATE (%d)", ss->session_state); |
| 61 | |
| 62 | return s; |
| 63 | } |
| 64 | |
| 65 | const char *session_flags_str[] = { |
| 66 | #define _(sym, str) str, |
| 67 | foreach_session_flag |
| 68 | #undef _ |
| 69 | }; |
| 70 | |
| 71 | u8 * |
| 72 | format_session_flags (u8 * s, va_list * args) |
| 73 | { |
| 74 | session_t *ss = va_arg (*args, session_t *); |
| 75 | int i, last = -1; |
| 76 | |
| 77 | for (i = 0; i < SESSION_N_FLAGS; i++) |
| 78 | if (ss->flags & (1 << i)) |
| 79 | last = i; |
| 80 | |
| 81 | for (i = 0; i < last; i++) |
| 82 | { |
| 83 | if (ss->flags & (1 << i)) |
| 84 | s = format (s, "%s, ", session_flags_str[i]); |
| 85 | } |
| 86 | if (last >= 0) |
| 87 | s = format (s, "%s", session_flags_str[last]); |
| 88 | |
| 89 | return s; |
| 90 | } |
| 91 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 92 | /** |
| 93 | * Format stream session as per the following format |
| 94 | * |
| 95 | * verbose: |
| 96 | * "Connection", "Rx fifo", "Tx fifo", "Session Index" |
| 97 | * non-verbose: |
| 98 | * "Connection" |
| 99 | */ |
| 100 | u8 * |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 101 | format_session (u8 * s, va_list * args) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 102 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 103 | session_t *ss = va_arg (*args, session_t *); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 104 | int verbose = va_arg (*args, int); |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 105 | u32 tp = session_get_transport_proto (ss); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 106 | u8 *str = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 107 | |
Florin Coras | 5f06632 | 2019-07-22 19:03:03 -0700 | [diff] [blame] | 108 | if (ss->session_state >= SESSION_STATE_TRANSPORT_DELETED) |
Florin Coras | 3389dd2 | 2019-02-01 18:00:05 -0800 | [diff] [blame] | 109 | { |
| 110 | s = format (s, "[%u:%u] CLOSED", ss->thread_index, ss->session_index); |
| 111 | return s; |
| 112 | } |
| 113 | |
| 114 | if (verbose == 1) |
| 115 | { |
Florin Coras | 3389dd2 | 2019-02-01 18:00:05 -0800 | [diff] [blame] | 116 | u32 rxf, txf; |
| 117 | |
Aloys Augustin | 6eef40b | 2020-04-01 19:50:17 +0200 | [diff] [blame] | 118 | rxf = ss->rx_fifo ? svm_fifo_max_dequeue (ss->rx_fifo) : 0; |
| 119 | txf = ss->tx_fifo ? svm_fifo_max_dequeue (ss->tx_fifo) : 0; |
Florin Coras | 3389dd2 | 2019-02-01 18:00:05 -0800 | [diff] [blame] | 120 | str = format (0, "%-10u%-10u", rxf, txf); |
| 121 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 122 | |
Florin Coras | 509028a | 2019-04-02 17:47:03 -0700 | [diff] [blame] | 123 | if (ss->session_state >= SESSION_STATE_ACCEPTING |
| 124 | || ss->session_state == SESSION_STATE_CREATED) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 125 | { |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 126 | s = format (s, "%U", format_transport_connection, tp, |
| 127 | ss->connection_index, ss->thread_index, verbose); |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 128 | if (verbose == 1) |
| 129 | s = format (s, "%v", str); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 130 | if (verbose > 1) |
Florin Coras | 91f90d0 | 2019-10-23 19:28:08 -0700 | [diff] [blame] | 131 | { |
| 132 | s = format (s, "%U", format_session_fifos, ss, verbose); |
Florin Coras | d9035a4 | 2019-11-19 18:22:41 -0800 | [diff] [blame] | 133 | s = format (s, " session: state: %U opaque: 0x%x flags: %U\n", |
| 134 | format_session_state, ss, ss->opaque, |
| 135 | format_session_flags, ss); |
Florin Coras | 91f90d0 | 2019-10-23 19:28:08 -0700 | [diff] [blame] | 136 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 137 | } |
| 138 | else if (ss->session_state == SESSION_STATE_LISTENING) |
| 139 | { |
Florin Coras | 3389dd2 | 2019-02-01 18:00:05 -0800 | [diff] [blame] | 140 | s = format (s, "%U%v", format_transport_listen_connection, |
Aloys Augustin | a0abbff | 2019-07-12 12:16:16 +0200 | [diff] [blame] | 141 | tp, ss->connection_index, ss->thread_index, verbose, str); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 142 | if (verbose > 1) |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 143 | s = format (s, "\n%U", format_session_fifos, ss, verbose); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 144 | } |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 145 | else if (ss->session_state == SESSION_STATE_CONNECTING) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 146 | { |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 147 | s = format (s, "%-40U%v", format_transport_half_open_connection, |
Aloys Augustin | a0abbff | 2019-07-12 12:16:16 +0200 | [diff] [blame] | 148 | tp, ss->connection_index, ss->thread_index, str); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 149 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 150 | else |
| 151 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 152 | clib_warning ("Session in state: %d!", ss->session_state); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 153 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 154 | vec_free (str); |
| 155 | |
| 156 | return s; |
| 157 | } |
| 158 | |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 159 | uword |
| 160 | unformat_stream_session_id (unformat_input_t * input, va_list * args) |
| 161 | { |
| 162 | u8 *proto = va_arg (*args, u8 *); |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 163 | u32 *fib_index = va_arg (*args, u32 *); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 164 | ip46_address_t *lcl = va_arg (*args, ip46_address_t *); |
| 165 | ip46_address_t *rmt = va_arg (*args, ip46_address_t *); |
| 166 | u16 *lcl_port = va_arg (*args, u16 *); |
| 167 | u16 *rmt_port = va_arg (*args, u16 *); |
| 168 | u8 *is_ip4 = va_arg (*args, u8 *); |
| 169 | u8 tuple_is_set = 0; |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 170 | u32 vrf = ~0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 171 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 172 | clib_memset (lcl, 0, sizeof (*lcl)); |
| 173 | clib_memset (rmt, 0, sizeof (*rmt)); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 174 | |
| 175 | if (unformat (input, "tcp")) |
| 176 | { |
| 177 | *proto = TRANSPORT_PROTO_TCP; |
| 178 | } |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 179 | else if (unformat (input, "udp")) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 180 | { |
| 181 | *proto = TRANSPORT_PROTO_UDP; |
| 182 | } |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 183 | else |
| 184 | return 0; |
| 185 | |
| 186 | if (unformat (input, "vrf %u", &vrf)) |
| 187 | ; |
| 188 | |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 189 | if (unformat (input, "%U:%d->%U:%d", unformat_ip4_address, &lcl->ip4, |
| 190 | lcl_port, unformat_ip4_address, &rmt->ip4, rmt_port)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 191 | { |
| 192 | *is_ip4 = 1; |
| 193 | tuple_is_set = 1; |
| 194 | } |
| 195 | else if (unformat (input, "%U:%d->%U:%d", unformat_ip6_address, &lcl->ip6, |
| 196 | lcl_port, unformat_ip6_address, &rmt->ip6, rmt_port)) |
| 197 | { |
| 198 | *is_ip4 = 0; |
| 199 | tuple_is_set = 1; |
| 200 | } |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 201 | |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 202 | if (vrf != ~0) |
| 203 | { |
| 204 | fib_protocol_t fib_proto; |
| 205 | fib_proto = *is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 206 | *fib_index = fib_table_find (fib_proto, vrf); |
| 207 | } |
| 208 | |
Chris Luke | b2bcad6 | 2017-09-18 08:51:22 -0400 | [diff] [blame] | 209 | return tuple_is_set; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | uword |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 213 | unformat_session_state (unformat_input_t * input, va_list * args) |
| 214 | { |
| 215 | session_state_t *state = va_arg (*args, session_state_t *); |
| 216 | u8 *state_vec = 0; |
| 217 | int rv = 0; |
| 218 | |
| 219 | #define _(sym, str) \ |
| 220 | if (unformat (input, str)) \ |
| 221 | { \ |
| 222 | *state = SESSION_STATE_ ## sym; \ |
| 223 | rv = 1; \ |
| 224 | goto done; \ |
| 225 | } |
| 226 | foreach_session_state |
| 227 | #undef _ |
| 228 | done: |
| 229 | vec_free (state_vec); |
| 230 | return rv; |
| 231 | } |
| 232 | |
| 233 | uword |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 234 | unformat_session (unformat_input_t * input, va_list * args) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 235 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 236 | session_t **result = va_arg (*args, session_t **); |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 237 | u32 lcl_port = 0, rmt_port = 0, fib_index = 0; |
| 238 | ip46_address_t lcl, rmt; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 239 | session_t *s; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 240 | u8 proto = ~0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 241 | u8 is_ip4 = 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 242 | |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 243 | if (!unformat (input, "%U", unformat_stream_session_id, &proto, &fib_index, |
| 244 | &lcl, &rmt, &lcl_port, &rmt_port, &is_ip4)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 245 | return 0; |
| 246 | |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 247 | if (is_ip4) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 248 | s = session_lookup_safe4 (fib_index, &lcl.ip4, &rmt.ip4, |
| 249 | clib_host_to_net_u16 (lcl_port), |
| 250 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 251 | else |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 252 | s = session_lookup_safe6 (fib_index, &lcl.ip6, &rmt.ip6, |
| 253 | clib_host_to_net_u16 (lcl_port), |
| 254 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 255 | if (s) |
| 256 | { |
| 257 | *result = s; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 258 | session_pool_remove_peeker (s->thread_index); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 259 | return 1; |
| 260 | } |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | uword |
| 265 | unformat_transport_connection (unformat_input_t * input, va_list * args) |
| 266 | { |
| 267 | transport_connection_t **result = va_arg (*args, transport_connection_t **); |
| 268 | u32 suggested_proto = va_arg (*args, u32); |
| 269 | transport_connection_t *tc; |
| 270 | u8 proto = ~0; |
| 271 | ip46_address_t lcl, rmt; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 272 | u32 lcl_port = 0, rmt_port = 0, fib_index = 0; |
| 273 | u8 is_ip4 = 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 274 | |
Florin Coras | baee8d4 | 2019-01-19 11:29:18 -0800 | [diff] [blame] | 275 | if (!unformat (input, "%U", unformat_stream_session_id, &fib_index, &proto, |
| 276 | &lcl, &rmt, &lcl_port, &rmt_port, &is_ip4)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 277 | return 0; |
| 278 | |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 279 | proto = (proto == (u8) ~ 0) ? suggested_proto : proto; |
| 280 | if (proto == (u8) ~ 0) |
| 281 | return 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 282 | if (is_ip4) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 283 | tc = session_lookup_connection4 (fib_index, &lcl.ip4, &rmt.ip4, |
| 284 | clib_host_to_net_u16 (lcl_port), |
| 285 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 286 | else |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 287 | tc = session_lookup_connection6 (fib_index, &lcl.ip6, &rmt.ip6, |
| 288 | clib_host_to_net_u16 (lcl_port), |
| 289 | clib_host_to_net_u16 (rmt_port), proto); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 290 | |
| 291 | if (tc) |
| 292 | { |
| 293 | *result = tc; |
| 294 | return 1; |
| 295 | } |
| 296 | return 0; |
| 297 | } |
| 298 | |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 299 | static void |
| 300 | session_cli_show_all_sessions (vlib_main_t * vm, int verbose) |
| 301 | { |
| 302 | session_main_t *smm = &session_main; |
Florin Coras | 2d0b2bb | 2019-11-01 14:03:28 -0700 | [diff] [blame] | 303 | u32 n_closed, thread_index; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 304 | session_t *pool, *s; |
| 305 | |
| 306 | for (thread_index = 0; thread_index < vec_len (smm->wrk); thread_index++) |
| 307 | { |
| 308 | pool = smm->wrk[thread_index].sessions; |
| 309 | |
| 310 | if (!pool_elts (pool)) |
| 311 | { |
| 312 | vlib_cli_output (vm, "Thread %d: no sessions", thread_index); |
| 313 | continue; |
| 314 | } |
| 315 | |
| 316 | if (!verbose) |
| 317 | { |
| 318 | vlib_cli_output (vm, "Thread %d: %d sessions", thread_index, |
| 319 | pool_elts (pool)); |
| 320 | continue; |
| 321 | } |
| 322 | |
| 323 | if (pool_elts (pool) > 50) |
| 324 | { |
| 325 | vlib_cli_output (vm, "Thread %u: %d sessions. Verbose output " |
| 326 | "suppressed. For more details use filters.", |
| 327 | thread_index, pool_elts (pool)); |
| 328 | continue; |
| 329 | } |
| 330 | |
| 331 | if (verbose == 1) |
Florin Coras | 7bf6ed6 | 2020-09-23 12:02:08 -0700 | [diff] [blame] | 332 | vlib_cli_output (vm, "%s%-" SESSION_CLI_ID_LEN "s%-" |
| 333 | SESSION_CLI_STATE_LEN "s%-10s%-10s", |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 334 | thread_index ? "\n" : "", |
| 335 | "Connection", "State", "Rx-f", "Tx-f"); |
| 336 | |
Florin Coras | 2d0b2bb | 2019-11-01 14:03:28 -0700 | [diff] [blame] | 337 | n_closed = 0; |
| 338 | |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 339 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 340 | pool_foreach (s, pool) { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 341 | if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED) |
| 342 | { |
| 343 | n_closed += 1; |
| 344 | continue; |
| 345 | } |
| 346 | vlib_cli_output (vm, "%U", format_session, s, verbose); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 347 | } |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 348 | /* *INDENT-ON* */ |
| 349 | |
| 350 | if (!n_closed) |
| 351 | vlib_cli_output (vm, "Thread %d: active sessions %u", thread_index, |
| 352 | pool_elts (pool) - n_closed); |
| 353 | else |
| 354 | vlib_cli_output (vm, "Thread %d: active sessions %u closed %u", |
| 355 | thread_index, pool_elts (pool) - n_closed, n_closed); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | static int |
| 360 | session_cli_filter_check (session_t * s, session_state_t * states, |
| 361 | transport_proto_t tp) |
| 362 | { |
| 363 | if (states) |
| 364 | { |
| 365 | session_state_t *state; |
| 366 | vec_foreach (state, states) if (s->session_state == *state) |
| 367 | goto check_transport; |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | check_transport: |
| 372 | |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 373 | if (tp != TRANSPORT_PROTO_INVALID && session_get_transport_proto (s) != tp) |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 374 | return 0; |
| 375 | |
| 376 | return 1; |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | session_cli_show_session_filter (vlib_main_t * vm, u32 thread_index, |
| 381 | u32 start, u32 end, session_state_t * states, |
| 382 | transport_proto_t tp, int verbose) |
| 383 | { |
| 384 | u8 output_suppressed = 0; |
| 385 | session_worker_t *wrk; |
| 386 | session_t *pool, *s; |
| 387 | u32 count = 0, max_index; |
| 388 | int i; |
| 389 | |
| 390 | wrk = session_main_get_worker_if_valid (thread_index); |
| 391 | if (!wrk) |
| 392 | { |
| 393 | vlib_cli_output (vm, "invalid thread index %u", thread_index); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | pool = wrk->sessions; |
| 398 | |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 399 | if (tp == TRANSPORT_PROTO_INVALID && states == 0 && !verbose |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 400 | && (start == 0 && end == ~0)) |
| 401 | { |
| 402 | vlib_cli_output (vm, "Thread %d: %u sessions", thread_index, |
| 403 | pool_elts (pool)); |
| 404 | return; |
| 405 | } |
| 406 | |
Florin Coras | 61a89f2 | 2019-09-09 19:22:36 -0700 | [diff] [blame] | 407 | max_index = pool_len (pool) ? pool_len (pool) - 1 : 0; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 408 | for (i = start; i <= clib_min (end, max_index); i++) |
| 409 | { |
| 410 | if (pool_is_free_index (pool, i)) |
| 411 | continue; |
| 412 | |
| 413 | s = pool_elt_at_index (pool, i); |
| 414 | |
| 415 | if (session_cli_filter_check (s, states, tp)) |
| 416 | { |
| 417 | count += 1; |
| 418 | if (verbose) |
| 419 | { |
| 420 | if (count > 50 || (verbose > 1 && count > 10)) |
| 421 | { |
| 422 | output_suppressed = 1; |
| 423 | continue; |
| 424 | } |
| 425 | if (s->session_state < SESSION_STATE_TRANSPORT_DELETED) |
| 426 | vlib_cli_output (vm, "%U", format_session, s, verbose); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | if (!output_suppressed) |
| 432 | vlib_cli_output (vm, "Thread %d: %u sessions matched filter", |
| 433 | thread_index, count); |
| 434 | else |
| 435 | vlib_cli_output (vm, "Thread %d: %u sessions matched filter. Not all" |
| 436 | " shown. Use finer grained filter.", thread_index, |
| 437 | count); |
| 438 | } |
| 439 | |
Florin Coras | 16d974e | 2020-02-09 20:03:12 +0000 | [diff] [blame] | 440 | void |
| 441 | session_cli_show_events_thread (vlib_main_t * vm, u32 thread_index) |
| 442 | { |
| 443 | session_worker_t *wrk; |
| 444 | |
| 445 | wrk = session_main_get_worker_if_valid (thread_index); |
| 446 | if (!wrk) |
| 447 | { |
| 448 | vlib_cli_output (vm, "invalid thread index %u", thread_index); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | vlib_cli_output (vm, "Thread %d:\n", thread_index); |
| 453 | vlib_cli_output (vm, " evt elements alloc: %u", |
| 454 | pool_elts (wrk->event_elts)); |
| 455 | vlib_cli_output (vm, " ctrl evt elt data alloc: %d", |
| 456 | pool_elts (wrk->ctrl_evts_data)); |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | session_cli_show_events (vlib_main_t * vm, u32 thread_index) |
| 461 | { |
| 462 | session_main_t *smm = &session_main; |
| 463 | if (!thread_index) |
| 464 | { |
| 465 | session_cli_show_events_thread (vm, thread_index); |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | for (thread_index = 0; thread_index < vec_len (smm->wrk); thread_index++) |
| 470 | session_cli_show_events_thread (vm, thread_index); |
| 471 | } |
| 472 | |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 473 | static void |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 474 | session_cli_print_session_states (vlib_main_t * vm) |
| 475 | { |
| 476 | #define _(sym, str) vlib_cli_output (vm, str); |
| 477 | foreach_session_state |
| 478 | #undef _ |
| 479 | } |
| 480 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 481 | static clib_error_t * |
| 482 | show_session_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 483 | vlib_cli_command_t * cmd) |
| 484 | { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 485 | u8 one_session = 0, do_listeners = 0, sst, do_elog = 0, do_filter = 0; |
| 486 | u32 track_index, thread_index = 0, start = 0, end = ~0, session_index; |
| 487 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 488 | transport_proto_t transport_proto = TRANSPORT_PROTO_INVALID; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 489 | session_state_t state = SESSION_N_STATES, *states = 0; |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 490 | session_main_t *smm = &session_main; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 491 | clib_error_t *error = 0; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 492 | app_worker_t *app_wrk; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 493 | u32 transport_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 494 | const u8 *app_name; |
Florin Coras | 16d974e | 2020-02-09 20:03:12 +0000 | [diff] [blame] | 495 | u8 do_events = 0; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 496 | int verbose = 0; |
| 497 | session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 498 | |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 499 | session_cli_return_if_not_enabled (); |
| 500 | |
| 501 | if (!unformat_user (input, unformat_line_input, line_input)) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 502 | { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 503 | session_cli_show_all_sessions (vm, 0); |
| 504 | return 0; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 505 | } |
| 506 | |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 507 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 508 | { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 509 | if (unformat (line_input, "verbose %d", &verbose)) |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 510 | ; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 511 | else if (unformat (line_input, "verbose")) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 512 | verbose = 1; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 513 | else if (unformat (line_input, "listeners %U", unformat_transport_proto, |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 514 | &transport_proto)) |
| 515 | do_listeners = 1; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 516 | else if (unformat (line_input, "%U", unformat_session, &s)) |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 517 | { |
| 518 | one_session = 1; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 519 | } |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 520 | else if (unformat (line_input, "thread %u index %u", &thread_index, |
| 521 | &session_index)) |
| 522 | { |
| 523 | s = session_get_if_valid (session_index, thread_index); |
| 524 | if (!s) |
| 525 | { |
| 526 | vlib_cli_output (vm, "session is not allocated"); |
| 527 | goto done; |
| 528 | } |
| 529 | one_session = 1; |
| 530 | } |
| 531 | else if (unformat (line_input, "thread %u", &thread_index)) |
| 532 | { |
| 533 | do_filter = 1; |
| 534 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 535 | else |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 536 | if (unformat (line_input, "state %U", unformat_session_state, &state)) |
| 537 | { |
| 538 | vec_add1 (states, state); |
| 539 | do_filter = 1; |
| 540 | } |
| 541 | else if (unformat (line_input, "proto %U index %u", |
| 542 | unformat_transport_proto, &transport_proto, |
| 543 | &transport_index)) |
| 544 | { |
| 545 | transport_connection_t *tc; |
| 546 | tc = transport_get_connection (transport_proto, transport_index, |
| 547 | thread_index); |
| 548 | if (!tc) |
| 549 | { |
| 550 | vlib_cli_output (vm, "transport connection %u thread %u is not" |
| 551 | " allocated", transport_index, thread_index); |
| 552 | goto done; |
| 553 | } |
| 554 | s = session_get_if_valid (tc->s_index, thread_index); |
| 555 | if (!s) |
| 556 | { |
| 557 | vlib_cli_output (vm, "session for transport connection %u " |
| 558 | "thread %u does not exist", transport_index, |
| 559 | thread_index); |
| 560 | goto done; |
| 561 | } |
| 562 | one_session = 1; |
| 563 | } |
| 564 | else if (unformat (line_input, "proto %U", unformat_transport_proto, |
| 565 | &transport_proto)) |
| 566 | do_filter = 1; |
| 567 | else if (unformat (line_input, "range %u %u", &start, &end)) |
| 568 | do_filter = 1; |
| 569 | else if (unformat (line_input, "range %u", &start)) |
| 570 | { |
| 571 | end = start + 50; |
| 572 | do_filter = 1; |
| 573 | } |
| 574 | else if (unformat (line_input, "elog")) |
| 575 | do_elog = 1; |
| 576 | else if (unformat (line_input, "protos")) |
| 577 | { |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 578 | vlib_cli_output (vm, "%U", format_transport_protos); |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 579 | goto done; |
| 580 | } |
| 581 | else if (unformat (line_input, "states")) |
| 582 | { |
| 583 | session_cli_print_session_states (vm); |
| 584 | goto done; |
| 585 | } |
Florin Coras | 16d974e | 2020-02-09 20:03:12 +0000 | [diff] [blame] | 586 | else if (unformat (line_input, "events")) |
| 587 | do_events = 1; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 588 | else |
| 589 | { |
| 590 | error = clib_error_return (0, "unknown input `%U'", |
| 591 | format_unformat_error, line_input); |
| 592 | goto done; |
| 593 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 594 | } |
| 595 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 596 | if (one_session) |
| 597 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 598 | u8 *str = format (0, "%U", format_session, s, 3); |
Florin Coras | 844a36d | 2018-12-20 09:50:50 -0800 | [diff] [blame] | 599 | if (do_elog && s->session_state != SESSION_STATE_LISTENING) |
Florin Coras | aefbede | 2018-12-19 13:07:49 -0800 | [diff] [blame] | 600 | { |
| 601 | elog_main_t *em = &vm->elog_main; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 602 | transport_connection_t *tc; |
Florin Coras | aefbede | 2018-12-19 13:07:49 -0800 | [diff] [blame] | 603 | f64 dt; |
| 604 | |
| 605 | tc = session_get_transport (s); |
| 606 | track_index = transport_elog_track_index (tc); |
| 607 | dt = (em->init_time.cpu - vm->clib_time.init_cpu_time) |
| 608 | * vm->clib_time.seconds_per_clock; |
| 609 | if (track_index != ~0) |
| 610 | str = format (str, " session elog:\n%U", format_elog_track, em, |
| 611 | dt, track_index); |
| 612 | } |
| 613 | vlib_cli_output (vm, "%v", str); |
Florin Coras | 3389dd2 | 2019-02-01 18:00:05 -0800 | [diff] [blame] | 614 | vec_free (str); |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 615 | goto done; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 616 | } |
| 617 | |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 618 | if (do_listeners) |
| 619 | { |
| 620 | sst = session_type_from_proto_and_ip (transport_proto, 1); |
Florin Coras | 7bf6ed6 | 2020-09-23 12:02:08 -0700 | [diff] [blame] | 621 | vlib_cli_output (vm, "%-" SESSION_CLI_ID_LEN "s%-24s", "Listener", |
| 622 | "App"); |
| 623 | |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 624 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 625 | pool_foreach (s, smm->wrk[0].sessions) { |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 626 | if (s->session_state != SESSION_STATE_LISTENING |
| 627 | || s->session_type != sst) |
| 628 | continue; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 629 | app_wrk = app_worker_get (s->app_wrk_index); |
| 630 | app_name = application_name_from_index (app_wrk->app_index); |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 631 | vlib_cli_output (vm, "%U%-25v%", format_session, s, 0, |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 632 | app_name); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 633 | } |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 634 | /* *INDENT-ON* */ |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 635 | goto done; |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 636 | } |
| 637 | |
Florin Coras | 16d974e | 2020-02-09 20:03:12 +0000 | [diff] [blame] | 638 | if (do_events) |
| 639 | { |
| 640 | session_cli_show_events (vm, thread_index); |
| 641 | goto done; |
| 642 | } |
| 643 | |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 644 | if (do_filter) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 645 | { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 646 | if (end < start) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 647 | { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 648 | error = clib_error_return (0, "invalid range start: %u end: %u", |
| 649 | start, end); |
| 650 | goto done; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 651 | } |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 652 | session_cli_show_session_filter (vm, thread_index, start, end, states, |
| 653 | transport_proto, verbose); |
| 654 | goto done; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 655 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 656 | |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 657 | session_cli_show_all_sessions (vm, verbose); |
| 658 | |
| 659 | done: |
| 660 | unformat_free (line_input); |
| 661 | vec_free (states); |
| 662 | return error; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 663 | } |
| 664 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 665 | /* *INDENT-OFF* */ |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 666 | VLIB_CLI_COMMAND (vlib_cli_show_session_command) = |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 667 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 668 | .path = "show session", |
Florin Coras | 3389dd2 | 2019-02-01 18:00:05 -0800 | [diff] [blame] | 669 | .short_help = "show session [verbose [n]] [listeners <proto>] " |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 670 | "[<session-id> [elog]] [thread <n> [index <n>] " |
| 671 | "[proto <proto>] [state <state>] [range <min> [<max>]] " |
| 672 | "[protos] [states] ", |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 673 | .function = show_session_command_fn, |
| 674 | }; |
| 675 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 676 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 677 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 678 | clear_session (session_t * s) |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 679 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 680 | app_worker_t *server_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | 69b68ef | 2019-04-02 11:38:51 -0700 | [diff] [blame] | 681 | app_worker_close_notify (server_wrk, s); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 685 | static clib_error_t * |
| 686 | clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 687 | vlib_cli_command_t * cmd) |
| 688 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 689 | session_main_t *smm = &session_main; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 690 | u32 thread_index = 0, clear_all = 0; |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 691 | session_worker_t *wrk; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 692 | u32 session_index = ~0; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 693 | session_t *session; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 694 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 695 | if (!smm->is_enabled) |
| 696 | { |
flyingeagle23 | e212506 | 2017-04-20 20:01:14 +0800 | [diff] [blame] | 697 | return clib_error_return (0, "session layer is not enabled"); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 698 | } |
| 699 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 700 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 701 | { |
| 702 | if (unformat (input, "thread %d", &thread_index)) |
| 703 | ; |
| 704 | else if (unformat (input, "session %d", &session_index)) |
| 705 | ; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 706 | else if (unformat (input, "all")) |
| 707 | clear_all = 1; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 708 | else |
| 709 | return clib_error_return (0, "unknown input `%U'", |
| 710 | format_unformat_error, input); |
| 711 | } |
| 712 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 713 | if (!clear_all && session_index == ~0) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 714 | return clib_error_return (0, "session <nn> required, but not set."); |
| 715 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 716 | if (session_index != ~0) |
| 717 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 718 | session = session_get_if_valid (session_index, thread_index); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 719 | if (!session) |
| 720 | return clib_error_return (0, "no session %d on thread %d", |
| 721 | session_index, thread_index); |
| 722 | clear_session (session); |
| 723 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 724 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 725 | if (clear_all) |
| 726 | { |
| 727 | /* *INDENT-OFF* */ |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 728 | vec_foreach (wrk, smm->wrk) |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 729 | { |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 730 | pool_foreach (session, wrk->sessions) { |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 731 | clear_session (session); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 732 | } |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 733 | }; |
| 734 | /* *INDENT-ON* */ |
| 735 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 736 | |
| 737 | return 0; |
| 738 | } |
| 739 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 740 | /* *INDENT-OFF* */ |
| 741 | VLIB_CLI_COMMAND (clear_session_command, static) = |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 742 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 743 | .path = "clear session", |
| 744 | .short_help = "clear session thread <thread> session <index>", |
| 745 | .function = clear_session_command_fn, |
| 746 | }; |
| 747 | /* *INDENT-ON* */ |
| 748 | |
| 749 | static clib_error_t * |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 750 | show_session_fifo_trace_command_fn (vlib_main_t * vm, |
| 751 | unformat_input_t * input, |
| 752 | vlib_cli_command_t * cmd) |
| 753 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 754 | session_t *s = 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 755 | u8 is_rx = 0, *str = 0; |
| 756 | |
| 757 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 758 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 759 | if (unformat (input, "%U", unformat_session, &s)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 760 | ; |
| 761 | else if (unformat (input, "rx")) |
| 762 | is_rx = 1; |
| 763 | else if (unformat (input, "tx")) |
| 764 | is_rx = 0; |
| 765 | else |
| 766 | return clib_error_return (0, "unknown input `%U'", |
| 767 | format_unformat_error, input); |
| 768 | } |
| 769 | |
| 770 | if (!SVM_FIFO_TRACE) |
| 771 | { |
| 772 | vlib_cli_output (vm, "fifo tracing not enabled"); |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | if (!s) |
| 777 | { |
| 778 | vlib_cli_output (vm, "could not find session"); |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | str = is_rx ? |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 783 | svm_fifo_dump_trace (str, s->rx_fifo) : |
| 784 | svm_fifo_dump_trace (str, s->tx_fifo); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 785 | |
| 786 | vlib_cli_output (vm, "%v", str); |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | /* *INDENT-OFF* */ |
| 791 | VLIB_CLI_COMMAND (show_session_fifo_trace_command, static) = |
| 792 | { |
| 793 | .path = "show session fifo trace", |
| 794 | .short_help = "show session fifo trace <session>", |
| 795 | .function = show_session_fifo_trace_command_fn, |
| 796 | }; |
| 797 | /* *INDENT-ON* */ |
| 798 | |
| 799 | static clib_error_t * |
| 800 | session_replay_fifo_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 801 | vlib_cli_command_t * cmd) |
| 802 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 803 | session_t *s = 0; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 804 | u8 is_rx = 0, *str = 0; |
| 805 | |
| 806 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 807 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 808 | if (unformat (input, "%U", unformat_session, &s)) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 809 | ; |
| 810 | else if (unformat (input, "rx")) |
| 811 | is_rx = 1; |
| 812 | else |
| 813 | return clib_error_return (0, "unknown input `%U'", |
| 814 | format_unformat_error, input); |
| 815 | } |
| 816 | |
| 817 | if (!SVM_FIFO_TRACE) |
| 818 | { |
| 819 | vlib_cli_output (vm, "fifo tracing not enabled"); |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | if (!s) |
| 824 | { |
| 825 | vlib_cli_output (vm, "could not find session"); |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | str = is_rx ? |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 830 | svm_fifo_replay (str, s->rx_fifo, 0, 1) : |
| 831 | svm_fifo_replay (str, s->tx_fifo, 0, 1); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 832 | |
| 833 | vlib_cli_output (vm, "%v", str); |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | /* *INDENT-OFF* */ |
| 838 | VLIB_CLI_COMMAND (session_replay_fifo_trace_command, static) = |
| 839 | { |
| 840 | .path = "session replay fifo", |
| 841 | .short_help = "session replay fifo <session>", |
| 842 | .function = session_replay_fifo_command_fn, |
| 843 | }; |
| 844 | /* *INDENT-ON* */ |
| 845 | |
| 846 | static clib_error_t * |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 847 | session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input, |
| 848 | vlib_cli_command_t * cmd) |
| 849 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 850 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 851 | u8 is_en = 1; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 852 | clib_error_t *error; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 853 | |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 854 | if (!unformat_user (input, unformat_line_input, line_input)) |
Swarup Nayak | 82d8ec2 | 2017-12-04 11:54:43 +0530 | [diff] [blame] | 855 | return clib_error_return (0, "expected enable | disable"); |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 856 | |
| 857 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 858 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 859 | if (unformat (line_input, "enable")) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 860 | is_en = 1; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 861 | else if (unformat (line_input, "disable")) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 862 | is_en = 0; |
| 863 | else |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 864 | { |
| 865 | error = clib_error_return (0, "unknown input `%U'", |
| 866 | format_unformat_error, line_input); |
| 867 | unformat_free (line_input); |
| 868 | return error; |
| 869 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 870 | } |
| 871 | |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 872 | unformat_free (line_input); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 873 | return vnet_session_enable_disable (vm, is_en); |
| 874 | } |
| 875 | |
| 876 | /* *INDENT-OFF* */ |
| 877 | VLIB_CLI_COMMAND (session_enable_disable_command, static) = |
| 878 | { |
| 879 | .path = "session", |
| 880 | .short_help = "session [enable|disable]", |
| 881 | .function = session_enable_disable_fn, |
| 882 | }; |
| 883 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 884 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 885 | /* |
| 886 | * fd.io coding-style-patch-verification: ON |
| 887 | * |
| 888 | * Local Variables: |
| 889 | * eval: (c-set-style "gnu") |
| 890 | * End: |
| 891 | */ |