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