FD.io VPP  v20.01-48-g3e0dafb74
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  u8 post_accept = ss->session_state >= SESSION_STATE_ACCEPTING;
117  u8 hasf = post_accept
119  u32 rxf, txf;
120 
121  rxf = hasf ? svm_fifo_max_dequeue (ss->rx_fifo) : 0;
122  txf = hasf ? svm_fifo_max_dequeue (ss->tx_fifo) : 0;
123  str = format (0, "%-10u%-10u", rxf, txf);
124  }
125 
126  if (ss->session_state >= SESSION_STATE_ACCEPTING
127  || ss->session_state == SESSION_STATE_CREATED)
128  {
129  s = format (s, "%U", format_transport_connection, tp,
130  ss->connection_index, ss->thread_index, verbose);
131  if (verbose == 1)
132  s = format (s, "%v", str);
133  if (verbose > 1)
134  {
135  s = format (s, "%U", format_session_fifos, ss, verbose);
136  s = format (s, " session: state: %U opaque: 0x%x flags: %U\n",
137  format_session_state, ss, ss->opaque,
139  }
140  }
141  else if (ss->session_state == SESSION_STATE_LISTENING)
142  {
144  tp, ss->connection_index, ss->thread_index, verbose, str);
145  if (verbose > 1)
146  s = format (s, "\n%U", format_session_fifos, ss, verbose);
147  }
148  else if (ss->session_state == SESSION_STATE_CONNECTING)
149  {
151  tp, ss->connection_index, ss->thread_index, str);
152  }
153  else
154  {
155  clib_warning ("Session in state: %d!", ss->session_state);
156  }
157  vec_free (str);
158 
159  return s;
160 }
161 
162 uword
164 {
165  u8 *proto = va_arg (*args, u8 *);
166  u32 *fib_index = va_arg (*args, u32 *);
167  ip46_address_t *lcl = va_arg (*args, ip46_address_t *);
168  ip46_address_t *rmt = va_arg (*args, ip46_address_t *);
169  u16 *lcl_port = va_arg (*args, u16 *);
170  u16 *rmt_port = va_arg (*args, u16 *);
171  u8 *is_ip4 = va_arg (*args, u8 *);
172  u8 tuple_is_set = 0;
173  u32 vrf = ~0;
174 
175  clib_memset (lcl, 0, sizeof (*lcl));
176  clib_memset (rmt, 0, sizeof (*rmt));
177 
178  if (unformat (input, "tcp"))
179  {
180  *proto = TRANSPORT_PROTO_TCP;
181  }
182  else if (unformat (input, "udp"))
183  {
184  *proto = TRANSPORT_PROTO_UDP;
185  }
186  else
187  return 0;
188 
189  if (unformat (input, "vrf %u", &vrf))
190  ;
191 
192  if (unformat (input, "%U:%d->%U:%d", unformat_ip4_address, &lcl->ip4,
193  lcl_port, unformat_ip4_address, &rmt->ip4, rmt_port))
194  {
195  *is_ip4 = 1;
196  tuple_is_set = 1;
197  }
198  else if (unformat (input, "%U:%d->%U:%d", unformat_ip6_address, &lcl->ip6,
199  lcl_port, unformat_ip6_address, &rmt->ip6, rmt_port))
200  {
201  *is_ip4 = 0;
202  tuple_is_set = 1;
203  }
204 
205  if (vrf != ~0)
206  {
207  fib_protocol_t fib_proto;
208  fib_proto = *is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
209  *fib_index = fib_table_find (fib_proto, vrf);
210  }
211 
212  return tuple_is_set;
213 }
214 
215 uword
216 unformat_session_state (unformat_input_t * input, va_list * args)
217 {
218  session_state_t *state = va_arg (*args, session_state_t *);
219  u8 *state_vec = 0;
220  int rv = 0;
221 
222 #define _(sym, str) \
223  if (unformat (input, str)) \
224  { \
225  *state = SESSION_STATE_ ## sym; \
226  rv = 1; \
227  goto done; \
228  }
230 #undef _
231 done:
232  vec_free (state_vec);
233  return rv;
234 }
235 
236 uword
237 unformat_session (unformat_input_t * input, va_list * args)
238 {
239  session_t **result = va_arg (*args, session_t **);
240  u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
241  ip46_address_t lcl, rmt;
242  session_t *s;
243  u8 proto = ~0;
244  u8 is_ip4 = 0;
245 
246  if (!unformat (input, "%U", unformat_stream_session_id, &proto, &fib_index,
247  &lcl, &rmt, &lcl_port, &rmt_port, &is_ip4))
248  return 0;
249 
250  if (is_ip4)
251  s = session_lookup_safe4 (fib_index, &lcl.ip4, &rmt.ip4,
252  clib_host_to_net_u16 (lcl_port),
253  clib_host_to_net_u16 (rmt_port), proto);
254  else
255  s = session_lookup_safe6 (fib_index, &lcl.ip6, &rmt.ip6,
256  clib_host_to_net_u16 (lcl_port),
257  clib_host_to_net_u16 (rmt_port), proto);
258  if (s)
259  {
260  *result = s;
262  return 1;
263  }
264  return 0;
265 }
266 
267 uword
269 {
270  transport_connection_t **result = va_arg (*args, transport_connection_t **);
271  u32 suggested_proto = va_arg (*args, u32);
273  u8 proto = ~0;
274  ip46_address_t lcl, rmt;
275  u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
276  u8 is_ip4 = 0;
277 
278  if (!unformat (input, "%U", unformat_stream_session_id, &fib_index, &proto,
279  &lcl, &rmt, &lcl_port, &rmt_port, &is_ip4))
280  return 0;
281 
282  proto = (proto == (u8) ~ 0) ? suggested_proto : proto;
283  if (proto == (u8) ~ 0)
284  return 0;
285  if (is_ip4)
286  tc = session_lookup_connection4 (fib_index, &lcl.ip4, &rmt.ip4,
287  clib_host_to_net_u16 (lcl_port),
288  clib_host_to_net_u16 (rmt_port), proto);
289  else
290  tc = session_lookup_connection6 (fib_index, &lcl.ip6, &rmt.ip6,
291  clib_host_to_net_u16 (lcl_port),
292  clib_host_to_net_u16 (rmt_port), proto);
293 
294  if (tc)
295  {
296  *result = tc;
297  return 1;
298  }
299  return 0;
300 }
301 
302 static void
304 {
306  u32 n_closed, thread_index;
307  session_t *pool, *s;
308 
309  for (thread_index = 0; thread_index < vec_len (smm->wrk); thread_index++)
310  {
311  pool = smm->wrk[thread_index].sessions;
312 
313  if (!pool_elts (pool))
314  {
315  vlib_cli_output (vm, "Thread %d: no sessions", thread_index);
316  continue;
317  }
318 
319  if (!verbose)
320  {
321  vlib_cli_output (vm, "Thread %d: %d sessions", thread_index,
322  pool_elts (pool));
323  continue;
324  }
325 
326  if (pool_elts (pool) > 50)
327  {
328  vlib_cli_output (vm, "Thread %u: %d sessions. Verbose output "
329  "suppressed. For more details use filters.",
330  thread_index, pool_elts (pool));
331  continue;
332  }
333 
334  if (verbose == 1)
335  vlib_cli_output (vm, "%s%-50s%-15s%-10s%-10s",
336  thread_index ? "\n" : "",
337  "Connection", "State", "Rx-f", "Tx-f");
338 
339  n_closed = 0;
340 
341  /* *INDENT-OFF* */
342  pool_foreach(s, pool, ({
343  if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
344  {
345  n_closed += 1;
346  continue;
347  }
348  vlib_cli_output (vm, "%U", format_session, s, verbose);
349  }));
350  /* *INDENT-ON* */
351 
352  if (!n_closed)
353  vlib_cli_output (vm, "Thread %d: active sessions %u", thread_index,
354  pool_elts (pool) - n_closed);
355  else
356  vlib_cli_output (vm, "Thread %d: active sessions %u closed %u",
357  thread_index, pool_elts (pool) - n_closed, n_closed);
358  }
359 }
360 
361 static int
364 {
365  if (states)
366  {
368  vec_foreach (state, states) if (s->session_state == *state)
369  goto check_transport;
370  return 0;
371  }
372 
373 check_transport:
374 
375  if (tp != TRANSPORT_N_PROTO && session_get_transport_proto (s) != tp)
376  return 0;
377 
378  return 1;
379 }
380 
381 static void
383  u32 start, u32 end, session_state_t * states,
384  transport_proto_t tp, int verbose)
385 {
386  u8 output_suppressed = 0;
387  session_worker_t *wrk;
388  session_t *pool, *s;
389  u32 count = 0, max_index;
390  int i;
391 
392  wrk = session_main_get_worker_if_valid (thread_index);
393  if (!wrk)
394  {
395  vlib_cli_output (vm, "invalid thread index %u", thread_index);
396  return;
397  }
398 
399  pool = wrk->sessions;
400 
401  if (tp == TRANSPORT_N_PROTO && states == 0 && !verbose
402  && (start == 0 && end == ~0))
403  {
404  vlib_cli_output (vm, "Thread %d: %u sessions", thread_index,
405  pool_elts (pool));
406  return;
407  }
408 
409  max_index = pool_len (pool) ? pool_len (pool) - 1 : 0;
410  for (i = start; i <= clib_min (end, max_index); i++)
411  {
412  if (pool_is_free_index (pool, i))
413  continue;
414 
415  s = pool_elt_at_index (pool, i);
416 
417  if (session_cli_filter_check (s, states, tp))
418  {
419  count += 1;
420  if (verbose)
421  {
422  if (count > 50 || (verbose > 1 && count > 10))
423  {
424  output_suppressed = 1;
425  continue;
426  }
427  if (s->session_state < SESSION_STATE_TRANSPORT_DELETED)
428  vlib_cli_output (vm, "%U", format_session, s, verbose);
429  }
430  }
431  }
432 
433  if (!output_suppressed)
434  vlib_cli_output (vm, "Thread %d: %u sessions matched filter",
435  thread_index, count);
436  else
437  vlib_cli_output (vm, "Thread %d: %u sessions matched filter. Not all"
438  " shown. Use finer grained filter.", thread_index,
439  count);
440 }
441 
442 static void
444 {
445 #define _(sym, str, sstr) vlib_cli_output (vm, str);
447 #undef _
448 }
449 
450 static void
452 {
453 #define _(sym, str) vlib_cli_output (vm, str);
455 #undef _
456 }
457 
458 static clib_error_t *
460  vlib_cli_command_t * cmd)
461 {
462  u8 one_session = 0, do_listeners = 0, sst, do_elog = 0, do_filter = 0;
463  u32 track_index, thread_index = 0, start = 0, end = ~0, session_index;
464  unformat_input_t _line_input, *line_input = &_line_input;
465  transport_proto_t transport_proto = TRANSPORT_N_PROTO;
466  session_state_t state = SESSION_N_STATES, *states = 0;
468  clib_error_t *error = 0;
469  app_worker_t *app_wrk;
470  u32 transport_index;
471  const u8 *app_name;
472  int verbose = 0;
473  session_t *s;
474 
476 
477  if (!unformat_user (input, unformat_line_input, line_input))
478  {
480  return 0;
481  }
482 
483  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
484  {
485  if (unformat (line_input, "verbose %d", &verbose))
486  ;
487  else if (unformat (line_input, "verbose"))
488  verbose = 1;
489  else if (unformat (line_input, "listeners %U", unformat_transport_proto,
490  &transport_proto))
491  do_listeners = 1;
492  else if (unformat (line_input, "%U", unformat_session, &s))
493  {
494  one_session = 1;
495  }
496  else if (unformat (line_input, "thread %u index %u", &thread_index,
497  &session_index))
498  {
499  s = session_get_if_valid (session_index, thread_index);
500  if (!s)
501  {
502  vlib_cli_output (vm, "session is not allocated");
503  goto done;
504  }
505  one_session = 1;
506  }
507  else if (unformat (line_input, "thread %u", &thread_index))
508  {
509  do_filter = 1;
510  }
511  else
512  if (unformat (line_input, "state %U", unformat_session_state, &state))
513  {
514  vec_add1 (states, state);
515  do_filter = 1;
516  }
517  else if (unformat (line_input, "proto %U index %u",
518  unformat_transport_proto, &transport_proto,
519  &transport_index))
520  {
522  tc = transport_get_connection (transport_proto, transport_index,
523  thread_index);
524  if (!tc)
525  {
526  vlib_cli_output (vm, "transport connection %u thread %u is not"
527  " allocated", transport_index, thread_index);
528  goto done;
529  }
530  s = session_get_if_valid (tc->s_index, thread_index);
531  if (!s)
532  {
533  vlib_cli_output (vm, "session for transport connection %u "
534  "thread %u does not exist", transport_index,
535  thread_index);
536  goto done;
537  }
538  one_session = 1;
539  }
540  else if (unformat (line_input, "proto %U", unformat_transport_proto,
541  &transport_proto))
542  do_filter = 1;
543  else if (unformat (line_input, "range %u %u", &start, &end))
544  do_filter = 1;
545  else if (unformat (line_input, "range %u", &start))
546  {
547  end = start + 50;
548  do_filter = 1;
549  }
550  else if (unformat (line_input, "elog"))
551  do_elog = 1;
552  else if (unformat (line_input, "protos"))
553  {
555  goto done;
556  }
557  else if (unformat (line_input, "states"))
558  {
560  goto done;
561  }
562  else
563  {
564  error = clib_error_return (0, "unknown input `%U'",
565  format_unformat_error, line_input);
566  goto done;
567  }
568  }
569 
570  if (one_session)
571  {
572  u8 *str = format (0, "%U", format_session, s, 3);
573  if (do_elog && s->session_state != SESSION_STATE_LISTENING)
574  {
575  elog_main_t *em = &vm->elog_main;
577  f64 dt;
578 
579  tc = session_get_transport (s);
580  track_index = transport_elog_track_index (tc);
581  dt = (em->init_time.cpu - vm->clib_time.init_cpu_time)
583  if (track_index != ~0)
584  str = format (str, " session elog:\n%U", format_elog_track, em,
585  dt, track_index);
586  }
587  vlib_cli_output (vm, "%v", str);
588  vec_free (str);
589  goto done;
590  }
591 
592  if (do_listeners)
593  {
594  sst = session_type_from_proto_and_ip (transport_proto, 1);
595  vlib_cli_output (vm, "%-50s%-24s", "Listener", "App");
596  /* *INDENT-OFF* */
597  pool_foreach (s, smm->wrk[0].sessions, ({
598  if (s->session_state != SESSION_STATE_LISTENING
599  || s->session_type != sst)
600  continue;
601  app_wrk = app_worker_get (s->app_wrk_index);
602  app_name = application_name_from_index (app_wrk->app_index);
603  vlib_cli_output (vm, "%U%-25v%", format_session, s, 0,
604  app_name);
605  }));
606  /* *INDENT-ON* */
607  goto done;
608  }
609 
610  if (do_filter)
611  {
612  if (end < start)
613  {
614  error = clib_error_return (0, "invalid range start: %u end: %u",
615  start, end);
616  goto done;
617  }
618  session_cli_show_session_filter (vm, thread_index, start, end, states,
619  transport_proto, verbose);
620  goto done;
621  }
622 
623  session_cli_show_all_sessions (vm, verbose);
624 
625 done:
626  unformat_free (line_input);
627  vec_free (states);
628  return error;
629 }
630 
631 /* *INDENT-OFF* */
632 VLIB_CLI_COMMAND (vlib_cli_show_session_command) =
633 {
634  .path = "show session",
635  .short_help = "show session [verbose [n]] [listeners <proto>] "
636  "[<session-id> [elog]] [thread <n> [index <n>] "
637  "[proto <proto>] [state <state>] [range <min> [<max>]] "
638  "[protos] [states] ",
639  .function = show_session_command_fn,
640 };
641 /* *INDENT-ON* */
642 
643 static int
645 {
646  app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
647  app_worker_close_notify (server_wrk, s);
648  return 0;
649 }
650 
651 static clib_error_t *
653  vlib_cli_command_t * cmd)
654 {
656  u32 thread_index = 0, clear_all = 0;
657  session_worker_t *wrk;
658  u32 session_index = ~0;
659  session_t *session;
660 
661  if (!smm->is_enabled)
662  {
663  return clib_error_return (0, "session layer is not enabled");
664  }
665 
667  {
668  if (unformat (input, "thread %d", &thread_index))
669  ;
670  else if (unformat (input, "session %d", &session_index))
671  ;
672  else if (unformat (input, "all"))
673  clear_all = 1;
674  else
675  return clib_error_return (0, "unknown input `%U'",
676  format_unformat_error, input);
677  }
678 
679  if (!clear_all && session_index == ~0)
680  return clib_error_return (0, "session <nn> required, but not set.");
681 
682  if (session_index != ~0)
683  {
684  session = session_get_if_valid (session_index, thread_index);
685  if (!session)
686  return clib_error_return (0, "no session %d on thread %d",
687  session_index, thread_index);
688  clear_session (session);
689  }
690 
691  if (clear_all)
692  {
693  /* *INDENT-OFF* */
694  vec_foreach (wrk, smm->wrk)
695  {
696  pool_foreach(session, wrk->sessions, ({
697  clear_session (session);
698  }));
699  };
700  /* *INDENT-ON* */
701  }
702 
703  return 0;
704 }
705 
706 /* *INDENT-OFF* */
707 VLIB_CLI_COMMAND (clear_session_command, static) =
708 {
709  .path = "clear session",
710  .short_help = "clear session thread <thread> session <index>",
711  .function = clear_session_command_fn,
712 };
713 /* *INDENT-ON* */
714 
715 static clib_error_t *
717  unformat_input_t * input,
718  vlib_cli_command_t * cmd)
719 {
720  session_t *s = 0;
721  u8 is_rx = 0, *str = 0;
722 
724  {
725  if (unformat (input, "%U", unformat_session, &s))
726  ;
727  else if (unformat (input, "rx"))
728  is_rx = 1;
729  else if (unformat (input, "tx"))
730  is_rx = 0;
731  else
732  return clib_error_return (0, "unknown input `%U'",
733  format_unformat_error, input);
734  }
735 
736  if (!SVM_FIFO_TRACE)
737  {
738  vlib_cli_output (vm, "fifo tracing not enabled");
739  return 0;
740  }
741 
742  if (!s)
743  {
744  vlib_cli_output (vm, "could not find session");
745  return 0;
746  }
747 
748  str = is_rx ?
749  svm_fifo_dump_trace (str, s->rx_fifo) :
750  svm_fifo_dump_trace (str, s->tx_fifo);
751 
752  vlib_cli_output (vm, "%v", str);
753  return 0;
754 }
755 
756 /* *INDENT-OFF* */
757 VLIB_CLI_COMMAND (show_session_fifo_trace_command, static) =
758 {
759  .path = "show session fifo trace",
760  .short_help = "show session fifo trace <session>",
762 };
763 /* *INDENT-ON* */
764 
765 static clib_error_t *
767  vlib_cli_command_t * cmd)
768 {
769  session_t *s = 0;
770  u8 is_rx = 0, *str = 0;
771 
773  {
774  if (unformat (input, "%U", unformat_session, &s))
775  ;
776  else if (unformat (input, "rx"))
777  is_rx = 1;
778  else
779  return clib_error_return (0, "unknown input `%U'",
780  format_unformat_error, input);
781  }
782 
783  if (!SVM_FIFO_TRACE)
784  {
785  vlib_cli_output (vm, "fifo tracing not enabled");
786  return 0;
787  }
788 
789  if (!s)
790  {
791  vlib_cli_output (vm, "could not find session");
792  return 0;
793  }
794 
795  str = is_rx ?
796  svm_fifo_replay (str, s->rx_fifo, 0, 1) :
797  svm_fifo_replay (str, s->tx_fifo, 0, 1);
798 
799  vlib_cli_output (vm, "%v", str);
800  return 0;
801 }
802 
803 /* *INDENT-OFF* */
804 VLIB_CLI_COMMAND (session_replay_fifo_trace_command, static) =
805 {
806  .path = "session replay fifo",
807  .short_help = "session replay fifo <session>",
808  .function = session_replay_fifo_command_fn,
809 };
810 /* *INDENT-ON* */
811 
812 static clib_error_t *
814  vlib_cli_command_t * cmd)
815 {
816  unformat_input_t _line_input, *line_input = &_line_input;
817  u8 is_en = 1;
818  clib_error_t *error;
819 
820  if (!unformat_user (input, unformat_line_input, line_input))
821  return clib_error_return (0, "expected enable | disable");
822 
823  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
824  {
825  if (unformat (line_input, "enable"))
826  is_en = 1;
827  else if (unformat (line_input, "disable"))
828  is_en = 0;
829  else
830  {
831  error = clib_error_return (0, "unknown input `%U'",
832  format_unformat_error, line_input);
833  unformat_free (line_input);
834  return error;
835  }
836  }
837 
838  unformat_free (line_input);
839  return vnet_session_enable_disable (vm, is_en);
840 }
841 
842 /* *INDENT-OFF* */
843 VLIB_CLI_COMMAND (session_enable_disable_command, static) =
844 {
845  .path = "session",
846  .short_help = "session [enable|disable]",
847  .function = session_enable_disable_fn,
848 };
849 /* *INDENT-ON* */
850 
851 /*
852  * fd.io coding-style-patch-verification: ON
853  *
854  * Local Variables:
855  * eval: (c-set-style "gnu")
856  * End:
857  */
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:84
u8 * format_session_fifos(u8 *s, va_list *args)
Definition: session_cli.c:19
u8 proto
Definition: acl_types.api:47
#define clib_min(x, y)
Definition: clib.h:295
svm_fifo_t * tx_fifo
session_main_t session_main
Definition: session.c:26
format_function_t format_svm_fifo
Definition: svm_fifo.h:490
u32 session_index
Index in thread pool where session was allocated.
#define session_cli_return_if_not_enabled()
Definition: session.h:618
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:1461
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_worker_t * wrk
Worker contexts.
Definition: session.h:147
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:302
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
static transport_proto_t session_get_transport_proto(session_t *s)
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
int i
static int clear_session(session_t *s)
Definition: session_cli.c:644
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
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:652
static void session_pool_remove_peeker(u32 thread_index)
Definition: session.h:353
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
clib_time_t clib_time
Definition: main.h:87
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:81
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:498
unformat_function_t unformat_ip4_address
Definition: format.h:68
#define foreach_transport_proto
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
Definition: svm_fifo.h:528
#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:459
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
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:216
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:519
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u8 is_enabled
Session manager is enabled.
Definition: session.h:168
uword unformat_transport_connection(unformat_input_t *input, va_list *args)
Definition: session_cli.c:268
f64 seconds_per_clock
Definition: time.h:57
uword unformat_session(unformat_input_t *input, va_list *args)
Definition: session_cli.c:237
u8 * svm_fifo_replay(u8 *s, svm_fifo_t *f, u8 no_read, u8 verbose)
Definition: svm_fifo.c:1292
vlib_main_t * vm
Definition: in2out_ed.c:1810
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1606
uword unformat_stream_session_id(unformat_input_t *input, va_list *args)
Definition: session_cli.c:163
unformat_function_t unformat_ip6_address
Definition: format.h:89
u8 is_ip4
Definition: lisp_gpe.api:232
#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:119
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:342
static void session_cli_print_session_states(vlib_main_t *vm)
Definition: session_cli.c:451
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:193
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:284
static u32 transport_elog_track_index(transport_connection_t *tc)
Definition: transport.h:179
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
const char * session_state_str[]
Definition: session_cli.c:46
#define SVM_FIFO_TRACE
Definition: svm_fifo.h:37
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:382
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
Definition: transport.c:156
static void session_cli_print_transport_protos(vlib_main_t *vm)
Definition: session_cli.c:443
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:362
#define foreach_session_state
u8 * format_transport_half_open_connection(u8 *s, va_list *args)
Definition: transport.c:125
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:1268
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
connectionless service
u8 * format_transport_listen_connection(u8 *s, va_list *args)
Definition: transport.c:111
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:766
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:716
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:62
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:303
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:813
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
static transport_service_type_t session_transport_service_type(session_t *s)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
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:599
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128