FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
session_cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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  */
16 #include <vnet/session/session.h>
17 
18 u8 *
19 format_session_fifos (u8 * s, va_list * args)
20 {
21  session_t *ss = va_arg (*args, session_t *);
22  int verbose = va_arg (*args, int);
23  session_event_t _e, *e = &_e;
24  u8 found;
25 
26  if (!ss->rx_fifo || !ss->tx_fifo)
27  return s;
28 
29  s = format (s, " Rx fifo: %U", format_svm_fifo, ss->rx_fifo, verbose);
30  if (verbose > 2 && ss->rx_fifo->has_event)
31  {
32  found = session_node_lookup_fifo_event (ss->rx_fifo, e);
33  s = format (s, " session node event: %s\n",
34  found ? "found" : "not found");
35  }
36  s = format (s, " Tx fifo: %U", format_svm_fifo, ss->tx_fifo, verbose);
37  if (verbose > 2 && ss->tx_fifo->has_event)
38  {
39  found = session_node_lookup_fifo_event (ss->tx_fifo, e);
40  s = format (s, " session node event: %s\n",
41  found ? "found" : "not found");
42  }
43  return s;
44 }
45 
46 const char *session_state_str[] = {
47 #define _(sym, str) str,
49 #undef _
50 };
51 
52 u8 *
53 format_session_state (u8 * s, va_list * args)
54 {
55  session_t *ss = va_arg (*args, session_t *);
56 
58  s = format (s, "%s", session_state_str[ss->session_state]);
59  else
60  s = format (s, "UNKNOWN STATE (%d)", ss->session_state);
61 
62  return s;
63 }
64 
65 const char *session_flags_str[] = {
66 #define _(sym, str) str,
68 #undef _
69 };
70 
71 u8 *
72 format_session_flags (u8 * s, va_list * args)
73 {
74  session_t *ss = va_arg (*args, session_t *);
75  int i, last = -1;
76 
77  for (i = 0; i < SESSION_N_FLAGS; i++)
78  if (ss->flags & (1 << i))
79  last = i;
80 
81  for (i = 0; i < last; i++)
82  {
83  if (ss->flags & (1 << i))
84  s = format (s, "%s, ", session_flags_str[i]);
85  }
86  if (last >= 0)
87  s = format (s, "%s", session_flags_str[last]);
88 
89  return s;
90 }
91 
92 /**
93  * Format stream session as per the following format
94  *
95  * verbose:
96  * "Connection", "Rx fifo", "Tx fifo", "Session Index"
97  * non-verbose:
98  * "Connection"
99  */
100 u8 *
101 format_session (u8 * s, va_list * args)
102 {
103  session_t *ss = va_arg (*args, session_t *);
104  int verbose = va_arg (*args, int);
106  u8 *str = 0;
107 
108  if (ss->session_state >= SESSION_STATE_TRANSPORT_DELETED)
109  {
110  s = format (s, "[%u:%u] CLOSED", ss->thread_index, ss->session_index);
111  return s;
112  }
113 
114  if (verbose == 1)
115  {
116  u32 rxf, txf;
117 
118  rxf = ss->rx_fifo ? svm_fifo_max_dequeue (ss->rx_fifo) : 0;
119  txf = ss->tx_fifo ? svm_fifo_max_dequeue (ss->tx_fifo) : 0;
120  str = format (0, "%-10u%-10u", rxf, txf);
121  }
122 
123  if (ss->session_state >= SESSION_STATE_ACCEPTING
124  || ss->session_state == SESSION_STATE_CREATED)
125  {
126  s = format (s, "%U", format_transport_connection, tp,
127  ss->connection_index, ss->thread_index, verbose);
128  if (verbose == 1)
129  s = format (s, "%v", str);
130  if (verbose > 1)
131  {
132  s = format (s, "%U", format_session_fifos, ss, verbose);
133  s = format (s, " session: state: %U opaque: 0x%x flags: %U\n",
134  format_session_state, ss, ss->opaque,
136  }
137  }
138  else if (ss->session_state == SESSION_STATE_LISTENING)
139  {
141  tp, ss->connection_index, ss->thread_index, verbose, str);
142  if (verbose > 1)
143  s = format (s, "\n%U", format_session_fifos, ss, verbose);
144  }
145  else if (ss->session_state == SESSION_STATE_CONNECTING)
146  {
148  tp, ss->connection_index, ss->thread_index, str);
149  }
150  else
151  {
152  clib_warning ("Session in state: %d!", ss->session_state);
153  }
154  vec_free (str);
155 
156  return s;
157 }
158 
159 uword
161 {
162  u8 *proto = va_arg (*args, u8 *);
163  u32 *fib_index = va_arg (*args, u32 *);
164  ip46_address_t *lcl = va_arg (*args, ip46_address_t *);
165  ip46_address_t *rmt = va_arg (*args, ip46_address_t *);
166  u16 *lcl_port = va_arg (*args, u16 *);
167  u16 *rmt_port = va_arg (*args, u16 *);
168  u8 *is_ip4 = va_arg (*args, u8 *);
169  u8 tuple_is_set = 0;
170  u32 vrf = ~0;
171 
172  clib_memset (lcl, 0, sizeof (*lcl));
173  clib_memset (rmt, 0, sizeof (*rmt));
174 
175  if (unformat (input, "tcp"))
176  {
177  *proto = TRANSPORT_PROTO_TCP;
178  }
179  else if (unformat (input, "udp"))
180  {
181  *proto = TRANSPORT_PROTO_UDP;
182  }
183  else
184  return 0;
185 
186  if (unformat (input, "vrf %u", &vrf))
187  ;
188 
189  if (unformat (input, "%U:%d->%U:%d", unformat_ip4_address, &lcl->ip4,
190  lcl_port, unformat_ip4_address, &rmt->ip4, rmt_port))
191  {
192  *is_ip4 = 1;
193  tuple_is_set = 1;
194  }
195  else if (unformat (input, "%U:%d->%U:%d", unformat_ip6_address, &lcl->ip6,
196  lcl_port, unformat_ip6_address, &rmt->ip6, rmt_port))
197  {
198  *is_ip4 = 0;
199  tuple_is_set = 1;
200  }
201 
202  if (vrf != ~0)
203  {
204  fib_protocol_t fib_proto;
205  fib_proto = *is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
206  *fib_index = fib_table_find (fib_proto, vrf);
207  }
208 
209  return tuple_is_set;
210 }
211 
212 uword
213 unformat_session_state (unformat_input_t * input, va_list * args)
214 {
215  session_state_t *state = va_arg (*args, session_state_t *);
216  u8 *state_vec = 0;
217  int rv = 0;
218 
219 #define _(sym, str) \
220  if (unformat (input, str)) \
221  { \
222  *state = SESSION_STATE_ ## sym; \
223  rv = 1; \
224  goto done; \
225  }
227 #undef _
228 done:
229  vec_free (state_vec);
230  return rv;
231 }
232 
233 uword
234 unformat_session (unformat_input_t * input, va_list * args)
235 {
236  session_t **result = va_arg (*args, session_t **);
237  u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
238  ip46_address_t lcl, rmt;
239  session_t *s;
240  u8 proto = ~0;
241  u8 is_ip4 = 0;
242 
243  if (!unformat (input, "%U", unformat_stream_session_id, &proto, &fib_index,
244  &lcl, &rmt, &lcl_port, &rmt_port, &is_ip4))
245  return 0;
246 
247  if (is_ip4)
248  s = session_lookup_safe4 (fib_index, &lcl.ip4, &rmt.ip4,
249  clib_host_to_net_u16 (lcl_port),
250  clib_host_to_net_u16 (rmt_port), proto);
251  else
252  s = session_lookup_safe6 (fib_index, &lcl.ip6, &rmt.ip6,
253  clib_host_to_net_u16 (lcl_port),
254  clib_host_to_net_u16 (rmt_port), proto);
255  if (s)
256  {
257  *result = s;
259  return 1;
260  }
261  return 0;
262 }
263 
264 uword
266 {
267  transport_connection_t **result = va_arg (*args, transport_connection_t **);
268  u32 suggested_proto = va_arg (*args, u32);
270  u8 proto = ~0;
271  ip46_address_t lcl, rmt;
272  u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
273  u8 is_ip4 = 0;
274 
275  if (!unformat (input, "%U", unformat_stream_session_id, &fib_index, &proto,
276  &lcl, &rmt, &lcl_port, &rmt_port, &is_ip4))
277  return 0;
278 
279  proto = (proto == (u8) ~ 0) ? suggested_proto : proto;
280  if (proto == (u8) ~ 0)
281  return 0;
282  if (is_ip4)
283  tc = session_lookup_connection4 (fib_index, &lcl.ip4, &rmt.ip4,
284  clib_host_to_net_u16 (lcl_port),
285  clib_host_to_net_u16 (rmt_port), proto);
286  else
287  tc = session_lookup_connection6 (fib_index, &lcl.ip6, &rmt.ip6,
288  clib_host_to_net_u16 (lcl_port),
289  clib_host_to_net_u16 (rmt_port), proto);
290 
291  if (tc)
292  {
293  *result = tc;
294  return 1;
295  }
296  return 0;
297 }
298 
299 static void
301 {
303  u32 n_closed, thread_index;
304  session_t *pool, *s;
305 
306  for (thread_index = 0; thread_index < vec_len (smm->wrk); thread_index++)
307  {
308  pool = smm->wrk[thread_index].sessions;
309 
310  if (!pool_elts (pool))
311  {
312  vlib_cli_output (vm, "Thread %d: no sessions", thread_index);
313  continue;
314  }
315 
316  if (!verbose)
317  {
318  vlib_cli_output (vm, "Thread %d: %d sessions", thread_index,
319  pool_elts (pool));
320  continue;
321  }
322 
323  if (pool_elts (pool) > 50)
324  {
325  vlib_cli_output (vm, "Thread %u: %d sessions. Verbose output "
326  "suppressed. For more details use filters.",
327  thread_index, pool_elts (pool));
328  continue;
329  }
330 
331  if (verbose == 1)
332  vlib_cli_output (vm, "%s%-50s%-15s%-10s%-10s",
333  thread_index ? "\n" : "",
334  "Connection", "State", "Rx-f", "Tx-f");
335 
336  n_closed = 0;
337 
338  /* *INDENT-OFF* */
339  pool_foreach(s, pool, ({
340  if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
341  {
342  n_closed += 1;
343  continue;
344  }
345  vlib_cli_output (vm, "%U", format_session, s, verbose);
346  }));
347  /* *INDENT-ON* */
348 
349  if (!n_closed)
350  vlib_cli_output (vm, "Thread %d: active sessions %u", thread_index,
351  pool_elts (pool) - n_closed);
352  else
353  vlib_cli_output (vm, "Thread %d: active sessions %u closed %u",
354  thread_index, pool_elts (pool) - n_closed, n_closed);
355  }
356 }
357 
358 static int
361 {
362  if (states)
363  {
365  vec_foreach (state, states) if (s->session_state == *state)
366  goto check_transport;
367  return 0;
368  }
369 
370 check_transport:
371 
373  return 0;
374 
375  return 1;
376 }
377 
378 static void
380  u32 start, u32 end, session_state_t * states,
381  transport_proto_t tp, int verbose)
382 {
383  u8 output_suppressed = 0;
384  session_worker_t *wrk;
385  session_t *pool, *s;
386  u32 count = 0, max_index;
387  int i;
388 
389  wrk = session_main_get_worker_if_valid (thread_index);
390  if (!wrk)
391  {
392  vlib_cli_output (vm, "invalid thread index %u", thread_index);
393  return;
394  }
395 
396  pool = wrk->sessions;
397 
398  if (tp == TRANSPORT_PROTO_INVALID && states == 0 && !verbose
399  && (start == 0 && end == ~0))
400  {
401  vlib_cli_output (vm, "Thread %d: %u sessions", thread_index,
402  pool_elts (pool));
403  return;
404  }
405 
406  max_index = pool_len (pool) ? pool_len (pool) - 1 : 0;
407  for (i = start; i <= clib_min (end, max_index); i++)
408  {
409  if (pool_is_free_index (pool, i))
410  continue;
411 
412  s = pool_elt_at_index (pool, i);
413 
414  if (session_cli_filter_check (s, states, tp))
415  {
416  count += 1;
417  if (verbose)
418  {
419  if (count > 50 || (verbose > 1 && count > 10))
420  {
421  output_suppressed = 1;
422  continue;
423  }
424  if (s->session_state < SESSION_STATE_TRANSPORT_DELETED)
425  vlib_cli_output (vm, "%U", format_session, s, verbose);
426  }
427  }
428  }
429 
430  if (!output_suppressed)
431  vlib_cli_output (vm, "Thread %d: %u sessions matched filter",
432  thread_index, count);
433  else
434  vlib_cli_output (vm, "Thread %d: %u sessions matched filter. Not all"
435  " shown. Use finer grained filter.", thread_index,
436  count);
437 }
438 
439 void
441 {
442  session_worker_t *wrk;
443 
444  wrk = session_main_get_worker_if_valid (thread_index);
445  if (!wrk)
446  {
447  vlib_cli_output (vm, "invalid thread index %u", thread_index);
448  return;
449  }
450 
451  vlib_cli_output (vm, "Thread %d:\n", thread_index);
452  vlib_cli_output (vm, " evt elements alloc: %u",
453  pool_elts (wrk->event_elts));
454  vlib_cli_output (vm, " ctrl evt elt data alloc: %d",
455  pool_elts (wrk->ctrl_evts_data));
456 }
457 
458 static void
460 {
462  if (!thread_index)
463  {
464  session_cli_show_events_thread (vm, thread_index);
465  return;
466  }
467 
468  for (thread_index = 0; thread_index < vec_len (smm->wrk); thread_index++)
469  session_cli_show_events_thread (vm, thread_index);
470 }
471 
472 static void
474 {
475 #define _(sym, str) vlib_cli_output (vm, str);
477 #undef _
478 }
479 
480 static clib_error_t *
482  vlib_cli_command_t * cmd)
483 {
484  u8 one_session = 0, do_listeners = 0, sst, do_elog = 0, do_filter = 0;
485  u32 track_index, thread_index = 0, start = 0, end = ~0, session_index;
486  unformat_input_t _line_input, *line_input = &_line_input;
488  session_state_t state = SESSION_N_STATES, *states = 0;
490  clib_error_t *error = 0;
491  app_worker_t *app_wrk;
492  u32 transport_index;
493  const u8 *app_name;
494  u8 do_events = 0;
495  int verbose = 0;
496  session_t *s;
497 
499 
500  if (!unformat_user (input, unformat_line_input, line_input))
501  {
503  return 0;
504  }
505 
506  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
507  {
508  if (unformat (line_input, "verbose %d", &verbose))
509  ;
510  else if (unformat (line_input, "verbose"))
511  verbose = 1;
512  else if (unformat (line_input, "listeners %U", unformat_transport_proto,
513  &transport_proto))
514  do_listeners = 1;
515  else if (unformat (line_input, "%U", unformat_session, &s))
516  {
517  one_session = 1;
518  }
519  else if (unformat (line_input, "thread %u index %u", &thread_index,
520  &session_index))
521  {
522  s = session_get_if_valid (session_index, thread_index);
523  if (!s)
524  {
525  vlib_cli_output (vm, "session is not allocated");
526  goto done;
527  }
528  one_session = 1;
529  }
530  else if (unformat (line_input, "thread %u", &thread_index))
531  {
532  do_filter = 1;
533  }
534  else
535  if (unformat (line_input, "state %U", unformat_session_state, &state))
536  {
537  vec_add1 (states, state);
538  do_filter = 1;
539  }
540  else if (unformat (line_input, "proto %U index %u",
541  unformat_transport_proto, &transport_proto,
542  &transport_index))
543  {
545  tc = transport_get_connection (transport_proto, transport_index,
546  thread_index);
547  if (!tc)
548  {
549  vlib_cli_output (vm, "transport connection %u thread %u is not"
550  " allocated", transport_index, thread_index);
551  goto done;
552  }
553  s = session_get_if_valid (tc->s_index, thread_index);
554  if (!s)
555  {
556  vlib_cli_output (vm, "session for transport connection %u "
557  "thread %u does not exist", transport_index,
558  thread_index);
559  goto done;
560  }
561  one_session = 1;
562  }
563  else if (unformat (line_input, "proto %U", unformat_transport_proto,
564  &transport_proto))
565  do_filter = 1;
566  else if (unformat (line_input, "range %u %u", &start, &end))
567  do_filter = 1;
568  else if (unformat (line_input, "range %u", &start))
569  {
570  end = start + 50;
571  do_filter = 1;
572  }
573  else if (unformat (line_input, "elog"))
574  do_elog = 1;
575  else if (unformat (line_input, "protos"))
576  {
578  goto done;
579  }
580  else if (unformat (line_input, "states"))
581  {
583  goto done;
584  }
585  else if (unformat (line_input, "events"))
586  do_events = 1;
587  else
588  {
589  error = clib_error_return (0, "unknown input `%U'",
590  format_unformat_error, line_input);
591  goto done;
592  }
593  }
594 
595  if (one_session)
596  {
597  u8 *str = format (0, "%U", format_session, s, 3);
598  if (do_elog && s->session_state != SESSION_STATE_LISTENING)
599  {
600  elog_main_t *em = &vm->elog_main;
602  f64 dt;
603 
604  tc = session_get_transport (s);
605  track_index = transport_elog_track_index (tc);
606  dt = (em->init_time.cpu - vm->clib_time.init_cpu_time)
608  if (track_index != ~0)
609  str = format (str, " session elog:\n%U", format_elog_track, em,
610  dt, track_index);
611  }
612  vlib_cli_output (vm, "%v", str);
613  vec_free (str);
614  goto done;
615  }
616 
617  if (do_listeners)
618  {
619  sst = session_type_from_proto_and_ip (transport_proto, 1);
620  vlib_cli_output (vm, "%-50s%-24s", "Listener", "App");
621  /* *INDENT-OFF* */
622  pool_foreach (s, smm->wrk[0].sessions, ({
623  if (s->session_state != SESSION_STATE_LISTENING
624  || s->session_type != sst)
625  continue;
626  app_wrk = app_worker_get (s->app_wrk_index);
627  app_name = application_name_from_index (app_wrk->app_index);
628  vlib_cli_output (vm, "%U%-25v%", format_session, s, 0,
629  app_name);
630  }));
631  /* *INDENT-ON* */
632  goto done;
633  }
634 
635  if (do_events)
636  {
637  session_cli_show_events (vm, thread_index);
638  goto done;
639  }
640 
641  if (do_filter)
642  {
643  if (end < start)
644  {
645  error = clib_error_return (0, "invalid range start: %u end: %u",
646  start, end);
647  goto done;
648  }
649  session_cli_show_session_filter (vm, thread_index, start, end, states,
650  transport_proto, verbose);
651  goto done;
652  }
653 
654  session_cli_show_all_sessions (vm, verbose);
655 
656 done:
657  unformat_free (line_input);
658  vec_free (states);
659  return error;
660 }
661 
662 /* *INDENT-OFF* */
663 VLIB_CLI_COMMAND (vlib_cli_show_session_command) =
664 {
665  .path = "show session",
666  .short_help = "show session [verbose [n]] [listeners <proto>] "
667  "[<session-id> [elog]] [thread <n> [index <n>] "
668  "[proto <proto>] [state <state>] [range <min> [<max>]] "
669  "[protos] [states] ",
670  .function = show_session_command_fn,
671 };
672 /* *INDENT-ON* */
673 
674 static int
676 {
677  app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
678  app_worker_close_notify (server_wrk, s);
679  return 0;
680 }
681 
682 static clib_error_t *
684  vlib_cli_command_t * cmd)
685 {
687  u32 thread_index = 0, clear_all = 0;
688  session_worker_t *wrk;
689  u32 session_index = ~0;
690  session_t *session;
691 
692  if (!smm->is_enabled)
693  {
694  return clib_error_return (0, "session layer is not enabled");
695  }
696 
698  {
699  if (unformat (input, "thread %d", &thread_index))
700  ;
701  else if (unformat (input, "session %d", &session_index))
702  ;
703  else if (unformat (input, "all"))
704  clear_all = 1;
705  else
706  return clib_error_return (0, "unknown input `%U'",
707  format_unformat_error, input);
708  }
709 
710  if (!clear_all && session_index == ~0)
711  return clib_error_return (0, "session <nn> required, but not set.");
712 
713  if (session_index != ~0)
714  {
715  session = session_get_if_valid (session_index, thread_index);
716  if (!session)
717  return clib_error_return (0, "no session %d on thread %d",
718  session_index, thread_index);
719  clear_session (session);
720  }
721 
722  if (clear_all)
723  {
724  /* *INDENT-OFF* */
725  vec_foreach (wrk, smm->wrk)
726  {
727  pool_foreach(session, wrk->sessions, ({
728  clear_session (session);
729  }));
730  };
731  /* *INDENT-ON* */
732  }
733 
734  return 0;
735 }
736 
737 /* *INDENT-OFF* */
738 VLIB_CLI_COMMAND (clear_session_command, static) =
739 {
740  .path = "clear session",
741  .short_help = "clear session thread <thread> session <index>",
742  .function = clear_session_command_fn,
743 };
744 /* *INDENT-ON* */
745 
746 static clib_error_t *
748  unformat_input_t * input,
749  vlib_cli_command_t * cmd)
750 {
751  session_t *s = 0;
752  u8 is_rx = 0, *str = 0;
753 
755  {
756  if (unformat (input, "%U", unformat_session, &s))
757  ;
758  else if (unformat (input, "rx"))
759  is_rx = 1;
760  else if (unformat (input, "tx"))
761  is_rx = 0;
762  else
763  return clib_error_return (0, "unknown input `%U'",
764  format_unformat_error, input);
765  }
766 
767  if (!SVM_FIFO_TRACE)
768  {
769  vlib_cli_output (vm, "fifo tracing not enabled");
770  return 0;
771  }
772 
773  if (!s)
774  {
775  vlib_cli_output (vm, "could not find session");
776  return 0;
777  }
778 
779  str = is_rx ?
780  svm_fifo_dump_trace (str, s->rx_fifo) :
781  svm_fifo_dump_trace (str, s->tx_fifo);
782 
783  vlib_cli_output (vm, "%v", str);
784  return 0;
785 }
786 
787 /* *INDENT-OFF* */
788 VLIB_CLI_COMMAND (show_session_fifo_trace_command, static) =
789 {
790  .path = "show session fifo trace",
791  .short_help = "show session fifo trace <session>",
793 };
794 /* *INDENT-ON* */
795 
796 static clib_error_t *
798  vlib_cli_command_t * cmd)
799 {
800  session_t *s = 0;
801  u8 is_rx = 0, *str = 0;
802 
804  {
805  if (unformat (input, "%U", unformat_session, &s))
806  ;
807  else if (unformat (input, "rx"))
808  is_rx = 1;
809  else
810  return clib_error_return (0, "unknown input `%U'",
811  format_unformat_error, input);
812  }
813 
814  if (!SVM_FIFO_TRACE)
815  {
816  vlib_cli_output (vm, "fifo tracing not enabled");
817  return 0;
818  }
819 
820  if (!s)
821  {
822  vlib_cli_output (vm, "could not find session");
823  return 0;
824  }
825 
826  str = is_rx ?
827  svm_fifo_replay (str, s->rx_fifo, 0, 1) :
828  svm_fifo_replay (str, s->tx_fifo, 0, 1);
829 
830  vlib_cli_output (vm, "%v", str);
831  return 0;
832 }
833 
834 /* *INDENT-OFF* */
835 VLIB_CLI_COMMAND (session_replay_fifo_trace_command, static) =
836 {
837  .path = "session replay fifo",
838  .short_help = "session replay fifo <session>",
839  .function = session_replay_fifo_command_fn,
840 };
841 /* *INDENT-ON* */
842 
843 static clib_error_t *
845  vlib_cli_command_t * cmd)
846 {
847  unformat_input_t _line_input, *line_input = &_line_input;
848  u8 is_en = 1;
849  clib_error_t *error;
850 
851  if (!unformat_user (input, unformat_line_input, line_input))
852  return clib_error_return (0, "expected enable | disable");
853 
854  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
855  {
856  if (unformat (line_input, "enable"))
857  is_en = 1;
858  else if (unformat (line_input, "disable"))
859  is_en = 0;
860  else
861  {
862  error = clib_error_return (0, "unknown input `%U'",
863  format_unformat_error, line_input);
864  unformat_free (line_input);
865  return error;
866  }
867  }
868 
869  unformat_free (line_input);
870  return vnet_session_enable_disable (vm, is_en);
871 }
872 
873 /* *INDENT-OFF* */
874 VLIB_CLI_COMMAND (session_enable_disable_command, static) =
875 {
876  .path = "session",
877  .short_help = "session [enable|disable]",
878  .function = session_enable_disable_fn,
879 };
880 /* *INDENT-ON* */
881 
882 /*
883  * fd.io coding-style-patch-verification: ON
884  *
885  * Local Variables:
886  * eval: (c-set-style "gnu")
887  * End:
888  */
u8 count
Definition: dhcp.api:208
u32 connection_index
Index of the transport connection associated to the session.
u8 * format_transport_connection(u8 *s, va_list *args)
Definition: transport.c:80
u8 * format_session_fifos(u8 *s, va_list *args)
Definition: session_cli.c:19
#define clib_min(x, y)
Definition: clib.h:327
transport_proto
Definition: session.api:22
svm_fifo_t * tx_fifo
session_main_t session_main
Definition: session.c:25
format_function_t format_svm_fifo
Definition: svm_fifo.h:395
u32 session_index
Index in thread pool where session was allocated.
#define session_cli_return_if_not_enabled()
Definition: session.h:644
elog_time_stamp_t init_time
Timestamps.
Definition: elog.h:172
session_t * session_lookup_safe4(u32 fib_index, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup session with ip4 and transport layer information.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1620
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_worker_t * wrk
Worker contexts.
Definition: session.h:143
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:308
session_evt_ctrl_data_t * ctrl_evts_data
Pool of ctrl events data buffers.
Definition: session.h:104
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
static transport_proto_t session_get_transport_proto(session_t *s)
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
static int clear_session(session_t *s)
Definition: session_cli.c:675
u8 * format_transport_protos(u8 *s, va_list *args)
Definition: transport.c:190
#define TRANSPORT_PROTO_INVALID
Definition: session.h:209
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
#define SVM_FIFO_TRACE
Definition: fifo_types.h:24
static clib_error_t * clear_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: session_cli.c:683
vlib_main_t * vm
Definition: in2out_ed.c:1582
static void session_pool_remove_peeker(u32 thread_index)
Definition: session.h:359
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
session_evt_elt_t * event_elts
Pool of session event list elements.
Definition: session.h:101
clib_time_t clib_time
Definition: main.h:124
session_t * session_lookup_safe6(u32 fib_index, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup session with ip6 and transport layer information.
u32 flags
Session flags.
u8 * format_session_state(u8 *s, va_list *args)
Definition: session_cli.c:53
unsigned char u8
Definition: types.h:56
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
session_t * sessions
Worker session pool.
Definition: session.h:77
double f64
Definition: types.h:142
transport_connection_t * session_lookup_connection6(u32 fib_index, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup connection with ip6 and transport layer information.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
unformat_function_t unformat_ip4_address
Definition: format.h:68
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
Definition: svm_fifo.h:433
#define clib_error_return(e, args...)
Definition: error.h:99
static clib_error_t * show_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: session_cli.c:481
unsigned int u32
Definition: types.h:88
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1097
void session_cli_show_events_thread(vlib_main_t *vm, u32 thread_index)
Definition: session_cli.c:440
session_state_t
transport_connection_t * session_lookup_connection4(u32 fib_index, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup connection with ip4 and transport layer information.
uword unformat_session_state(unformat_input_t *input, va_list *args)
Definition: session_cli.c:213
unformat_function_t unformat_line_input
Definition: format.h:283
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
vl_api_ip_proto_t proto
Definition: acl_types.api:50
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u8 is_enabled
Session manager is enabled.
Definition: session.h:166
uword unformat_transport_connection(unformat_input_t *input, va_list *args)
Definition: session_cli.c:265
f64 seconds_per_clock
Definition: time.h:58
uword unformat_session(unformat_input_t *input, va_list *args)
Definition: session_cli.c:234
u8 * svm_fifo_replay(u8 *s, svm_fifo_t *f, u8 no_read, u8 verbose)
Definition: svm_fifo.c:1407
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1768
uword unformat_stream_session_id(unformat_input_t *input, va_list *args)
Definition: session_cli.c:160
unformat_function_t unformat_ip6_address
Definition: format.h:89
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
static transport_connection_t * transport_get_connection(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.h:149
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
static void session_cli_show_events(vlib_main_t *vm, u32 thread_index)
Definition: session_cli.c:459
static void session_cli_print_session_states(vlib_main_t *vm)
Definition: session_cli.c:473
const char * session_flags_str[]
Definition: session_cli.c:65
#define clib_warning(format, args...)
Definition: error.h:59
elog_main_t elog_main
Definition: main.h:224
struct _transport_connection transport_connection_t
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:299
static u32 transport_elog_track_index(transport_connection_t *tc)
Definition: transport.h:250
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
const char * session_state_str[]
Definition: session_cli.c:46
static void session_cli_show_session_filter(vlib_main_t *vm, u32 thread_index, u32 start, u32 end, session_state_t *states, transport_proto_t tp, int verbose)
Definition: session_cli.c:379
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:696
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
Definition: transport.c:155
u64 cpu
CPU cycle counter.
Definition: elog.h:126
static int session_cli_filter_check(session_t *s, session_state_t *states, transport_proto_t tp)
Definition: session_cli.c:359
#define foreach_session_state
u8 * format_transport_half_open_connection(u8 *s, va_list *args)
Definition: transport.c:124
enum _transport_proto transport_proto_t
u8 thread_index
Index of the thread that allocated the session.
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
Definition: session_cli.c:101
u8 * svm_fifo_dump_trace(u8 *s, svm_fifo_t *f)
Definition: svm_fifo.c:1383
app_worker_t * app_worker_get(u32 wrk_index)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 * format_elog_track(u8 *s, va_list *args)
Definition: elog.c:408
volatile u8 session_state
State in session layer state machine.
u32 opaque
Opaque, for general use.
u64 uword
Definition: types.h:112
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
u8 * format_transport_listen_connection(u8 *s, va_list *args)
Definition: transport.c:110
static clib_error_t * session_replay_fifo_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: session_cli.c:797
static clib_error_t * show_session_fifo_trace_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: session_cli.c:747
u8 * format_session_flags(u8 *s, va_list *args)
Definition: session_cli.c:72
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
u64 init_cpu_time
Definition: time.h:61
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
#define vec_foreach(var, vec)
Vector iterator.
u32 app_wrk_index
Index of the app worker that owns the session.
f64 end
end of the time range
Definition: mactime.api:44
u8 session_node_lookup_fifo_event(svm_fifo_t *f, session_event_t *e)
static void session_cli_show_all_sessions(vlib_main_t *vm, int verbose)
Definition: session_cli.c:300
static clib_error_t * session_enable_disable_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: session_cli.c:844
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
static session_worker_t * session_main_get_worker_if_valid(u32 thread_index)
Definition: session.h:625
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128