aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/tcp/tcp_debug.c
blob: cf61d226c7fd40e593b59b988c452c1f39946fbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (c) 2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <vnet/tcp/tcp_debug.h>

tcp_dbg_main_t tcp_dbg_main;

void
tcp_evt_track_register (elog_track_t * et)
{
  tcp_dbg_main_t *tdm = &tcp_dbg_main;
  u32 fl_len, track_index;

  fl_len = vec_len (tdm->free_track_indices);
  if (fl_len)
    {
      track_index = tdm->free_track_indices[fl_len - 1];
      _vec_len (tdm->free_track_indices) -= 1;
      et->track_index_plus_one = track_index + 1;
    }
  else
    elog_track_register (&vlib_global_main.elog_main, et);
}

static const char *tcp_evt_grp_str[] = {
#define _(sym, str) str,
  foreach_tcp_evt_grp
#undef _
};

static void
tcp_debug_show_groups (void)
{
  tcp_dbg_main_t *tdm = &tcp_dbg_main;
  vlib_main_t *vm = vlib_get_main ();
  int i = 0;

  vlib_cli_output (vm, "%-10s%-30s%-10s", "Index", "Group", "Level");

  for (i = 0; i < TCP_EVT_N_GRP; i++)
    vlib_cli_output (vm, "%-10d%-30s%-10d", i, tcp_evt_grp_str[i],
		     tdm->grp_dbg_lvl[i]);
}

static clib_error_t *
tcp_debug_fn (vlib_main_t * vm, unformat_input_t * input,
	      vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  tcp_dbg_main_t *tdm = &tcp_dbg_main;
  u32 group = ~0, level = ~0;
  clib_error_t *error = 0;
  u8 is_show = 0;

  if (!TCP_DEBUG_ALWAYS)
    return clib_error_return (0, "must compile with TCP_DEBUG_ALWAYS set");

  if (!unformat_user (input, unformat_line_input, line_input))
    return clib_error_return (0, "expected enable | disable");

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "show"))
	is_show = 1;
      else if (unformat (line_input, "group %d", &group))
	;
      else if (unformat (line_input, "level %d", &level))
	;
      else
	{
	  error = clib_error_return (0, "unknown input `%U'",
				     format_unformat_error, line_input);
	  goto done;
	}
    }

  if (is_show)
    {
      tcp_debug_show_groups ();
      goto done;
    }
  if (group >= TCP_EVT_N_GRP)
    {
      error = clib_error_return (0, "group out of bounds");
      goto done;
    }
  if (group == ~0 || level == ~0)
    {
      error = clib_error_return (0, "group and level must be set");
      goto done;
    }

  tdm->grp_dbg_lvl[group] = level;

done:

  unformat_free (line_input);
  return error;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (tcp_debug_command, static) =
{
  .path = "tcp debug",
  .short_help = "tcp [show] [debug group <N> level <N>]",
  .function = tcp_debug_fn,
};
/* *INDENT-ON* */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
pan class="o">~0) ? (1) : (0)))) + lo); } #define fill_with_random_data(ptr, bytes, seed) \ do { \ u8 * _v(p) = (u8 *) (ptr); \ uword _v(b) = (bytes); \ uword _v(i); \ \ for (_v(i) = 0; _v(i) < _v(b); _v(i)++) \ _v(p)[_v(i)] = (u8) bounded_random_u32 (&(seed), 0, 255); \ \ } while (0) #define compute_mem_hash(hash, ptr, bytes) \ ({ \ u8 * _v(p) = (u8 *) (ptr); \ uword _v(b) = (uword) (bytes); \ uword _v(i); \ uword _v(h) = (u8) (hash); \ \ if (_v(p) && _v(b) > 0) \ { \ for (_v(i) = 0; _v(i) < _v(b); _v(i)++) \ _v(h) ^= _v(p)[_v(i)]; \ } \ \ _v(h); \ }) #define log2_align_down(value, align) \ ({ \ uword _v = (uword) (value); \ uword _a = (uword) (align); \ uword _m = (1 << _a) - 1; \ \ _v = _v & ~_m; \ }) #define log2_align_up(value, align) \ ({ \ uword _v = (uword) (value); \ uword _a = (uword) (align); \ uword _m = (1 << _a) - 1; \ \ _v = (_v + _m) & ~_m; \ }) #define log2_align_ptr_down(ptr, align) \ uword_to_pointer (log2_align_down (pointer_to_uword (ptr), align), void *) #define log2_align_ptr_up(ptr, align) \ uword_to_pointer (log2_align_up (pointer_to_uword (ptr), align), void *) #define MAX_LOG2_ALIGN 6 #define MAX_UNALIGN_OFFSET ((1 << MAX_LOG2_ALIGN) - 1) /* Allocates pointer to memory whose address is: addr = <log2_align>-aligned address */ always_inline void * alloc_aligned (uword size, uword log2_align, void **ptr_to_free) { void *p; if (size <= 0) return NULL; p = (void *) clib_mem_alloc (size + (1 << log2_align) - 1); if (ptr_to_free) *ptr_to_free = p; return (p) ? log2_align_ptr_up (p, log2_align) : (NULL); } /* Allocates pointer to memory whose address is: addr = MAX_LOG2_ALIGN-aligned address + <offset> */ always_inline void * alloc_unaligned (uword size, uword offset, void **ptr_to_free) { void *p; if (size <= 0) return NULL; ASSERT (offset <= MAX_UNALIGN_OFFSET); p = alloc_aligned (size + (1 << MAX_LOG2_ALIGN), MAX_LOG2_ALIGN, ptr_to_free); if (!p) return NULL; return (void *) ((u8 *) p + (offset % MAX_UNALIGN_OFFSET)); } #define memory_snap() \ do { \ clib_mem_usage_t _usage = { 0 }; \ clib_mem_usage (&_usage); \ fformat (stdout, "%U\n", format_clib_mem_usage, _usage, 0); \ } while (0) #endif /* included_test_vec_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */