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