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