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