blob: 651abe175971f502a887beda1c4558a2a6fbebb6 [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
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 Coras93992a92017-05-24 18:03:56 -070018u8 *
Florin Corasde9a8492018-10-24 22:18:58 -070019format_session_fifos (u8 * s, va_list * args)
Florin Coras93992a92017-05-24 18:03:56 -070020{
21 stream_session_t *ss = va_arg (*args, stream_session_t *);
Florin Coras6534b7a2017-07-18 05:38:03 -040022 int verbose = va_arg (*args, int);
Florin Coras52207f12018-07-12 14:48:06 -070023 session_event_t _e, *e = &_e;
Florin Coras6534b7a2017-07-18 05:38:03 -040024 u8 found;
25
Florin Coras7fb0fe12018-04-09 09:24:52 -070026 if (!ss->server_rx_fifo || !ss->server_tx_fifo)
27 return s;
28
Florin Coras54693d22018-07-17 10:46:29 -070029 s = format (s, " Rx fifo: %U", format_svm_fifo, ss->server_rx_fifo,
30 verbose);
Florin Coras6534b7a2017-07-18 05:38:03 -040031 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 Coras54693d22018-07-17 10:46:29 -070037 s = format (s, " Tx fifo: %U", format_svm_fifo, ss->server_tx_fifo,
38 verbose);
Florin Coras6534b7a2017-07-18 05:38:03 -040039 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 Coras93992a92017-05-24 18:03:56 -070045 return s;
46}
47
Dave Barach68b0fb02017-02-28 15:15:56 -050048/**
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 */
56u8 *
57format_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 Corasde9a8492018-10-24 22:18:58 -070061 u32 tp = session_get_transport_proto (ss);
Dave Barach68b0fb02017-02-28 15:15:56 -050062 u8 *str = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -050063
Florin Coras68810622017-07-24 17:40:28 -070064 if (verbose == 1 && ss->session_state >= SESSION_STATE_ACCEPTING)
Florin Corasde9a8492018-10-24 22:18:58 -070065 str = format (0, "%-10u%-10u",
Florin Corasbb292f42017-05-19 09:49:19 -070066 svm_fifo_max_dequeue (ss->server_rx_fifo),
Florin Corasde9a8492018-10-24 22:18:58 -070067 svm_fifo_max_dequeue (ss->server_tx_fifo));
Dave Barach68b0fb02017-02-28 15:15:56 -050068
Florin Coras3cbc04b2017-10-02 00:18:51 -070069 if (ss->session_state >= SESSION_STATE_ACCEPTING)
Dave Barach68b0fb02017-02-28 15:15:56 -050070 {
Florin Corasde9a8492018-10-24 22:18:58 -070071 s = format (s, "%U", format_transport_connection, tp,
72 ss->connection_index, ss->thread_index, verbose);
Florin Corasbb292f42017-05-19 09:49:19 -070073 if (verbose == 1)
74 s = format (s, "%v", str);
Florin Coras93992a92017-05-24 18:03:56 -070075 if (verbose > 1)
Florin Corasde9a8492018-10-24 22:18:58 -070076 s = format (s, "%U", format_session_fifos, ss, verbose);
Dave Barach68b0fb02017-02-28 15:15:56 -050077 }
78 else if (ss->session_state == SESSION_STATE_LISTENING)
79 {
Florin Corasde9a8492018-10-24 22:18:58 -070080 s = format (s, "%-40U%v", format_transport_listen_connection,
81 tp, ss->connection_index, str);
Florin Coras7fb0fe12018-04-09 09:24:52 -070082 if (verbose > 1)
Florin Corasde9a8492018-10-24 22:18:58 -070083 s = format (s, "\n%U", format_session_fifos, ss, verbose);
Dave Barach68b0fb02017-02-28 15:15:56 -050084 }
Florin Corasbb292f42017-05-19 09:49:19 -070085 else if (ss->session_state == SESSION_STATE_CONNECTING)
Dave Barach68b0fb02017-02-28 15:15:56 -050086 {
Florin Corasde9a8492018-10-24 22:18:58 -070087 s = format (s, "%-40U%v", format_transport_half_open_connection,
88 tp, ss->connection_index, str);
Dave Barach68b0fb02017-02-28 15:15:56 -050089 }
Dave Barach68b0fb02017-02-28 15:15:56 -050090 else
91 {
Florin Corase04c2992017-03-01 08:17:34 -080092 clib_warning ("Session in state: %d!", ss->session_state);
Dave Barach68b0fb02017-02-28 15:15:56 -050093 }
Dave Barach68b0fb02017-02-28 15:15:56 -050094 vec_free (str);
95
96 return s;
97}
98
Florin Coras3eb50622017-07-13 01:24:57 -040099uword
100unformat_stream_session_id (unformat_input_t * input, va_list * args)
101{
102 u8 *proto = va_arg (*args, u8 *);
103 ip46_address_t *lcl = va_arg (*args, ip46_address_t *);
104 ip46_address_t *rmt = va_arg (*args, ip46_address_t *);
105 u16 *lcl_port = va_arg (*args, u16 *);
106 u16 *rmt_port = va_arg (*args, u16 *);
107 u8 *is_ip4 = va_arg (*args, u8 *);
108 u8 tuple_is_set = 0;
109
Dave Barachb7b92992018-10-17 10:38:51 -0400110 clib_memset (lcl, 0, sizeof (*lcl));
111 clib_memset (rmt, 0, sizeof (*rmt));
Florin Coras3eb50622017-07-13 01:24:57 -0400112
113 if (unformat (input, "tcp"))
114 {
115 *proto = TRANSPORT_PROTO_TCP;
116 }
117 if (unformat (input, "udp"))
118 {
119 *proto = TRANSPORT_PROTO_UDP;
120 }
Dave Barachb7f1faa2017-08-29 11:43:37 -0400121 if (unformat (input, "%U:%d->%U:%d", unformat_ip4_address, &lcl->ip4,
122 lcl_port, unformat_ip4_address, &rmt->ip4, rmt_port))
Florin Coras3eb50622017-07-13 01:24:57 -0400123 {
124 *is_ip4 = 1;
125 tuple_is_set = 1;
126 }
127 else if (unformat (input, "%U:%d->%U:%d", unformat_ip6_address, &lcl->ip6,
128 lcl_port, unformat_ip6_address, &rmt->ip6, rmt_port))
129 {
130 *is_ip4 = 0;
131 tuple_is_set = 1;
132 }
Florin Coras3eb50622017-07-13 01:24:57 -0400133
Chris Lukeb2bcad62017-09-18 08:51:22 -0400134 return tuple_is_set;
Florin Coras3eb50622017-07-13 01:24:57 -0400135}
136
137uword
138unformat_stream_session (unformat_input_t * input, va_list * args)
139{
140 stream_session_t **result = va_arg (*args, stream_session_t **);
141 stream_session_t *s;
142 u8 proto = ~0;
143 ip46_address_t lcl, rmt;
Florin Corascea194d2017-10-02 00:18:51 -0700144 u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
145 u8 is_ip4 = 0;
Florin Coras3eb50622017-07-13 01:24:57 -0400146
Chris Lukeb2bcad62017-09-18 08:51:22 -0400147 if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt,
148 &lcl_port, &rmt_port, &is_ip4))
Florin Coras3eb50622017-07-13 01:24:57 -0400149 return 0;
150
Florin Coras3eb50622017-07-13 01:24:57 -0400151 if (is_ip4)
Florin Coras3cbc04b2017-10-02 00:18:51 -0700152 s = session_lookup_safe4 (fib_index, &lcl.ip4, &rmt.ip4,
153 clib_host_to_net_u16 (lcl_port),
154 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400155 else
Florin Coras3cbc04b2017-10-02 00:18:51 -0700156 s = session_lookup_safe6 (fib_index, &lcl.ip6, &rmt.ip6,
157 clib_host_to_net_u16 (lcl_port),
158 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400159 if (s)
160 {
161 *result = s;
Florin Coras3cbc04b2017-10-02 00:18:51 -0700162 session_pool_remove_peeker (s->thread_index);
Florin Coras3eb50622017-07-13 01:24:57 -0400163 return 1;
164 }
165 return 0;
166}
167
168uword
169unformat_transport_connection (unformat_input_t * input, va_list * args)
170{
171 transport_connection_t **result = va_arg (*args, transport_connection_t **);
172 u32 suggested_proto = va_arg (*args, u32);
173 transport_connection_t *tc;
174 u8 proto = ~0;
175 ip46_address_t lcl, rmt;
Florin Corascea194d2017-10-02 00:18:51 -0700176 u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
177 u8 is_ip4 = 0;
Florin Coras3eb50622017-07-13 01:24:57 -0400178
Chris Lukeb2bcad62017-09-18 08:51:22 -0400179 if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt,
180 &lcl_port, &rmt_port, &is_ip4))
Florin Coras3eb50622017-07-13 01:24:57 -0400181 return 0;
182
Florin Coras3eb50622017-07-13 01:24:57 -0400183 proto = (proto == (u8) ~ 0) ? suggested_proto : proto;
184 if (proto == (u8) ~ 0)
185 return 0;
Florin Coras3eb50622017-07-13 01:24:57 -0400186 if (is_ip4)
Florin Corascea194d2017-10-02 00:18:51 -0700187 tc = session_lookup_connection4 (fib_index, &lcl.ip4, &rmt.ip4,
188 clib_host_to_net_u16 (lcl_port),
189 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400190 else
Florin Corascea194d2017-10-02 00:18:51 -0700191 tc = session_lookup_connection6 (fib_index, &lcl.ip6, &rmt.ip6,
192 clib_host_to_net_u16 (lcl_port),
193 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400194
195 if (tc)
196 {
197 *result = tc;
198 return 1;
199 }
200 return 0;
201}
202
Dave Barach68b0fb02017-02-28 15:15:56 -0500203static clib_error_t *
204show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
205 vlib_cli_command_t * cmd)
206{
207 session_manager_main_t *smm = &session_manager_main;
Florin Corasdbd44562017-11-09 19:30:17 -0800208 u8 *str = 0, one_session = 0, do_listeners = 0, sst, *app_name;
Dave Barach68b0fb02017-02-28 15:15:56 -0500209 int verbose = 0, i;
Florin Corasdbd44562017-11-09 19:30:17 -0800210 stream_session_t *pool, *s;
211 u32 transport_proto = ~0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500212
Florin Corase04c2992017-03-01 08:17:34 -0800213 if (!smm->is_enabled)
214 {
flyingeagle23e2125062017-04-20 20:01:14 +0800215 return clib_error_return (0, "session layer is not enabled");
Florin Corase04c2992017-03-01 08:17:34 -0800216 }
217
Dave Barach68b0fb02017-02-28 15:15:56 -0500218 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
219 {
Florin Corasbb292f42017-05-19 09:49:19 -0700220 if (unformat (input, "verbose %d", &verbose))
221 ;
222 else if (unformat (input, "verbose"))
Dave Barach68b0fb02017-02-28 15:15:56 -0500223 verbose = 1;
Florin Corasdbd44562017-11-09 19:30:17 -0800224 else if (unformat (input, "listeners %U", unformat_transport_proto,
225 &transport_proto))
226 do_listeners = 1;
Florin Coras3eb50622017-07-13 01:24:57 -0400227 else if (unformat (input, "%U", unformat_stream_session, &s))
Dave Barach2c25a622017-06-26 11:35:07 -0400228 {
229 one_session = 1;
Dave Barach2c25a622017-06-26 11:35:07 -0400230 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500231 else
Florin Coras3eb50622017-07-13 01:24:57 -0400232 return clib_error_return (0, "unknown input `%U'",
233 format_unformat_error, input);
Dave Barach68b0fb02017-02-28 15:15:56 -0500234 }
235
Dave Barach2c25a622017-06-26 11:35:07 -0400236 if (one_session)
237 {
Florin Coras6534b7a2017-07-18 05:38:03 -0400238 vlib_cli_output (vm, "%U", format_stream_session, s, 3);
Dave Barach2c25a622017-06-26 11:35:07 -0400239 return 0;
240 }
241
Florin Corasdbd44562017-11-09 19:30:17 -0800242 if (do_listeners)
243 {
244 sst = session_type_from_proto_and_ip (transport_proto, 1);
Florin Corasde9a8492018-10-24 22:18:58 -0700245 vlib_cli_output (vm, "%-40s%-24s", "Listener", "App");
Florin Coras5c9083d2018-04-13 06:39:07 -0700246 /* *INDENT-OFF* */
Florin Coras5a7ca7b2018-10-30 12:01:48 -0700247 pool_foreach (s, smm->wrk[0].sessions, ({
Florin Coras5c9083d2018-04-13 06:39:07 -0700248 if (s->session_state != SESSION_STATE_LISTENING
249 || s->session_type != sst)
250 continue;
Florin Coras15531972018-08-12 23:50:53 -0700251 app_name = application_name_from_index (s->app_wrk_index);
Florin Corasde9a8492018-10-24 22:18:58 -0700252 vlib_cli_output (vm, "%U%-25v%", format_stream_session, s, 1,
253 app_name);
Florin Coras5c9083d2018-04-13 06:39:07 -0700254 vec_free (app_name);
255 }));
256 /* *INDENT-ON* */
Florin Corasdbd44562017-11-09 19:30:17 -0800257 return 0;
258 }
259
Florin Coras5a7ca7b2018-10-30 12:01:48 -0700260 for (i = 0; i < vec_len (smm->wrk); i++)
Dave Barach68b0fb02017-02-28 15:15:56 -0500261 {
262 u32 once_per_pool;
Florin Coras0d883a42018-10-31 12:25:38 -0700263 pool = smm->wrk[i].sessions;
Dave Barach68b0fb02017-02-28 15:15:56 -0500264
265 once_per_pool = 1;
266
267 if (pool_elts (pool))
268 {
269
270 vlib_cli_output (vm, "Thread %d: %d active sessions",
271 i, pool_elts (pool));
272 if (verbose)
273 {
Florin Corasbb292f42017-05-19 09:49:19 -0700274 if (once_per_pool && verbose == 1)
Dave Barach68b0fb02017-02-28 15:15:56 -0500275 {
Florin Corasde9a8492018-10-24 22:18:58 -0700276 str = format (str, "%-50s%-15s%-10s%-10s",
277 "Connection", "State", "Rx-f", "Tx-f");
Dave Barach68b0fb02017-02-28 15:15:56 -0500278 vlib_cli_output (vm, "%v", str);
279 vec_reset_length (str);
280 once_per_pool = 0;
281 }
282
283 /* *INDENT-OFF* */
284 pool_foreach (s, pool,
285 ({
Florin Corasbb292f42017-05-19 09:49:19 -0700286 vec_reset_length (str);
287 str = format (str, "%U", format_stream_session, s, verbose);
Florin Corasbb292f42017-05-19 09:49:19 -0700288 vlib_cli_output (vm, "%v", str);
Dave Barach68b0fb02017-02-28 15:15:56 -0500289 }));
290 /* *INDENT-ON* */
291 }
292 }
293 else
294 vlib_cli_output (vm, "Thread %d: no active sessions", i);
Dave Barach2c25a622017-06-26 11:35:07 -0400295 vec_reset_length (str);
Dave Barach68b0fb02017-02-28 15:15:56 -0500296 }
297 vec_free (str);
298
299 return 0;
300}
301
Florin Corase04c2992017-03-01 08:17:34 -0800302/* *INDENT-OFF* */
Florin Coras66b11312017-07-31 17:18:03 -0700303VLIB_CLI_COMMAND (vlib_cli_show_session_command) =
Dave Barach68b0fb02017-02-28 15:15:56 -0500304{
Florin Corase04c2992017-03-01 08:17:34 -0800305 .path = "show session",
rootc9d1c5b2017-08-15 12:58:31 -0400306 .short_help = "show session [verbose [nnn]]",
Florin Corase04c2992017-03-01 08:17:34 -0800307 .function = show_session_command_fn,
308};
309/* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500310
Dave Barach2c25a622017-06-26 11:35:07 -0400311static int
312clear_session (stream_session_t * s)
313{
Florin Coras15531972018-08-12 23:50:53 -0700314 app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
315 application_t *server = application_get (server_wrk->app_index);
Dave Barach2c25a622017-06-26 11:35:07 -0400316 server->cb_fns.session_disconnect_callback (s);
317 return 0;
318}
319
Dave Barach68b0fb02017-02-28 15:15:56 -0500320static clib_error_t *
321clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
322 vlib_cli_command_t * cmd)
323{
324 session_manager_main_t *smm = &session_manager_main;
Dave Barach2c25a622017-06-26 11:35:07 -0400325 u32 thread_index = 0, clear_all = 0;
Florin Coras5a7ca7b2018-10-30 12:01:48 -0700326 session_manager_worker_t *wrk;
Dave Barach68b0fb02017-02-28 15:15:56 -0500327 u32 session_index = ~0;
Florin Coras5a7ca7b2018-10-30 12:01:48 -0700328 stream_session_t *session;
Dave Barach68b0fb02017-02-28 15:15:56 -0500329
Florin Corase04c2992017-03-01 08:17:34 -0800330 if (!smm->is_enabled)
331 {
flyingeagle23e2125062017-04-20 20:01:14 +0800332 return clib_error_return (0, "session layer is not enabled");
Florin Corase04c2992017-03-01 08:17:34 -0800333 }
334
Dave Barach68b0fb02017-02-28 15:15:56 -0500335 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
336 {
337 if (unformat (input, "thread %d", &thread_index))
338 ;
339 else if (unformat (input, "session %d", &session_index))
340 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400341 else if (unformat (input, "all"))
342 clear_all = 1;
Dave Barach68b0fb02017-02-28 15:15:56 -0500343 else
344 return clib_error_return (0, "unknown input `%U'",
345 format_unformat_error, input);
346 }
347
Dave Barach2c25a622017-06-26 11:35:07 -0400348 if (!clear_all && session_index == ~0)
Dave Barach68b0fb02017-02-28 15:15:56 -0500349 return clib_error_return (0, "session <nn> required, but not set.");
350
Dave Barach2c25a622017-06-26 11:35:07 -0400351 if (session_index != ~0)
352 {
Florin Coras3cbc04b2017-10-02 00:18:51 -0700353 session = session_get_if_valid (session_index, thread_index);
Dave Barach2c25a622017-06-26 11:35:07 -0400354 if (!session)
355 return clib_error_return (0, "no session %d on thread %d",
356 session_index, thread_index);
357 clear_session (session);
358 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500359
Dave Barach2c25a622017-06-26 11:35:07 -0400360 if (clear_all)
361 {
362 /* *INDENT-OFF* */
Florin Coras5a7ca7b2018-10-30 12:01:48 -0700363 vec_foreach (wrk, smm->wrk)
Dave Barach2c25a622017-06-26 11:35:07 -0400364 {
Florin Coras5a7ca7b2018-10-30 12:01:48 -0700365 pool_foreach(session, wrk->sessions, ({
Dave Barach2c25a622017-06-26 11:35:07 -0400366 clear_session (session);
367 }));
368 };
369 /* *INDENT-ON* */
370 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500371
372 return 0;
373}
374
Florin Corase04c2992017-03-01 08:17:34 -0800375/* *INDENT-OFF* */
376VLIB_CLI_COMMAND (clear_session_command, static) =
Dave Barach68b0fb02017-02-28 15:15:56 -0500377{
Florin Corase04c2992017-03-01 08:17:34 -0800378 .path = "clear session",
379 .short_help = "clear session thread <thread> session <index>",
380 .function = clear_session_command_fn,
381};
382/* *INDENT-ON* */
383
384static clib_error_t *
Florin Coras3eb50622017-07-13 01:24:57 -0400385show_session_fifo_trace_command_fn (vlib_main_t * vm,
386 unformat_input_t * input,
387 vlib_cli_command_t * cmd)
388{
389 stream_session_t *s = 0;
390 u8 is_rx = 0, *str = 0;
391
392 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
393 {
394 if (unformat (input, "%U", unformat_stream_session, &s))
395 ;
396 else if (unformat (input, "rx"))
397 is_rx = 1;
398 else if (unformat (input, "tx"))
399 is_rx = 0;
400 else
401 return clib_error_return (0, "unknown input `%U'",
402 format_unformat_error, input);
403 }
404
405 if (!SVM_FIFO_TRACE)
406 {
407 vlib_cli_output (vm, "fifo tracing not enabled");
408 return 0;
409 }
410
411 if (!s)
412 {
413 vlib_cli_output (vm, "could not find session");
414 return 0;
415 }
416
417 str = is_rx ?
418 svm_fifo_dump_trace (str, s->server_rx_fifo) :
419 svm_fifo_dump_trace (str, s->server_tx_fifo);
420
421 vlib_cli_output (vm, "%v", str);
422 return 0;
423}
424
425/* *INDENT-OFF* */
426VLIB_CLI_COMMAND (show_session_fifo_trace_command, static) =
427{
428 .path = "show session fifo trace",
429 .short_help = "show session fifo trace <session>",
430 .function = show_session_fifo_trace_command_fn,
431};
432/* *INDENT-ON* */
433
434static clib_error_t *
435session_replay_fifo_command_fn (vlib_main_t * vm, unformat_input_t * input,
436 vlib_cli_command_t * cmd)
437{
438 stream_session_t *s = 0;
439 u8 is_rx = 0, *str = 0;
440
441 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
442 {
443 if (unformat (input, "%U", unformat_stream_session, &s))
444 ;
445 else if (unformat (input, "rx"))
446 is_rx = 1;
447 else
448 return clib_error_return (0, "unknown input `%U'",
449 format_unformat_error, input);
450 }
451
452 if (!SVM_FIFO_TRACE)
453 {
454 vlib_cli_output (vm, "fifo tracing not enabled");
455 return 0;
456 }
457
458 if (!s)
459 {
460 vlib_cli_output (vm, "could not find session");
461 return 0;
462 }
463
464 str = is_rx ?
465 svm_fifo_replay (str, s->server_rx_fifo, 0, 1) :
466 svm_fifo_replay (str, s->server_tx_fifo, 0, 1);
467
468 vlib_cli_output (vm, "%v", str);
469 return 0;
470}
471
472/* *INDENT-OFF* */
473VLIB_CLI_COMMAND (session_replay_fifo_trace_command, static) =
474{
475 .path = "session replay fifo",
476 .short_help = "session replay fifo <session>",
477 .function = session_replay_fifo_command_fn,
478};
479/* *INDENT-ON* */
480
481static clib_error_t *
Florin Corase04c2992017-03-01 08:17:34 -0800482session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input,
483 vlib_cli_command_t * cmd)
484{
Dave Wallace8af20542017-10-26 03:29:30 -0400485 unformat_input_t _line_input, *line_input = &_line_input;
Florin Corase04c2992017-03-01 08:17:34 -0800486 u8 is_en = 1;
Dave Wallace8af20542017-10-26 03:29:30 -0400487 clib_error_t *error;
Florin Corase04c2992017-03-01 08:17:34 -0800488
Dave Wallace8af20542017-10-26 03:29:30 -0400489 if (!unformat_user (input, unformat_line_input, line_input))
Swarup Nayak82d8ec22017-12-04 11:54:43 +0530490 return clib_error_return (0, "expected enable | disable");
Dave Wallace8af20542017-10-26 03:29:30 -0400491
492 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Florin Corase04c2992017-03-01 08:17:34 -0800493 {
Dave Wallace8af20542017-10-26 03:29:30 -0400494 if (unformat (line_input, "enable"))
Florin Corase04c2992017-03-01 08:17:34 -0800495 is_en = 1;
Dave Wallace8af20542017-10-26 03:29:30 -0400496 else if (unformat (line_input, "disable"))
Florin Corase04c2992017-03-01 08:17:34 -0800497 is_en = 0;
498 else
Dave Wallace8af20542017-10-26 03:29:30 -0400499 {
500 error = clib_error_return (0, "unknown input `%U'",
501 format_unformat_error, line_input);
502 unformat_free (line_input);
503 return error;
504 }
Florin Corase04c2992017-03-01 08:17:34 -0800505 }
506
Dave Wallace8af20542017-10-26 03:29:30 -0400507 unformat_free (line_input);
Florin Corase04c2992017-03-01 08:17:34 -0800508 return vnet_session_enable_disable (vm, is_en);
509}
510
511/* *INDENT-OFF* */
512VLIB_CLI_COMMAND (session_enable_disable_command, static) =
513{
514 .path = "session",
515 .short_help = "session [enable|disable]",
516 .function = session_enable_disable_fn,
517};
518/* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500519
520/*
521 * fd.io coding-style-patch-verification: ON
522 *
523 * Local Variables:
524 * eval: (c-set-style "gnu")
525 * End:
526 */