069c512da26771cd0dcc3c239e8bd647f0d0304a
[vpp.git] / src / vnet / tcp / tcp_debug.h
1 /*
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
16 #ifndef SRC_VNET_TCP_TCP_DEBUG_H_
17 #define SRC_VNET_TCP_TCP_DEBUG_H_
18
19 #include <vlib/vlib.h>
20
21 #define TCP_DEBUG (1)
22
23 #define foreach_tcp_dbg_evt             \
24   _(INIT, "")                           \
25   _(DEALLOC, "")                        \
26   _(OPEN, "open")                       \
27   _(CLOSE, "close")                     \
28   _(BIND, "bind")                       \
29   _(UNBIND, "unbind")                   \
30   _(DELETE, "delete")                   \
31   _(SYN_SENT, "SYN sent")               \
32   _(FIN_SENT, "FIN sent")               \
33   _(RST_SENT, "RST sent")               \
34   _(SYN_RCVD, "SYN rcvd")               \
35   _(ACK_RCVD, "ACK rcvd")               \
36   _(FIN_RCVD, "FIN rcvd")               \
37   _(RST_RCVD, "RST rcvd")               \
38   _(PKTIZE, "packetize")                \
39   _(INPUT, "in")                        \
40   _(TIMER_POP, "timer pop")
41
42 typedef enum _tcp_dbg
43 {
44 #define _(sym, str) TCP_DBG_##sym,
45   foreach_tcp_dbg_evt
46 #undef _
47 } tcp_dbg_e;
48
49 typedef enum _tcp_dbg_evt
50 {
51 #define _(sym, str) TCP_EVT_##sym,
52   foreach_tcp_dbg_evt
53 #undef _
54 } tcp_dbg_evt_e;
55
56 #if TCP_DEBUG
57
58 #define TRANSPORT_DEBUG (1)
59
60 #define TCP_DBG(_tc, _evt, _args...)                                    \
61 {                                                                       \
62     u8 *_tmp = 0;                                                       \
63     _tmp = format(_tmp, "%U", format_tcp_connection_verbose, _tc);      \
64     clib_warning("%s", _tmp);                                           \
65     vec_free(_tmp);                                                     \
66 }
67
68 #define DECLARE_ETD(_tc, _e, _size)                                     \
69   struct                                                                \
70   {                                                                     \
71     u32 data[_size];                                                    \
72   } * ed;                                                               \
73   ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main,                    \
74                         _e, _tc->c_elog_track)
75
76 #define TCP_EVT_INIT_HANDLER(_tc, ...)                                  \
77 {                                                                       \
78   _tc->c_elog_track.name =                                              \
79         (char *) format (0, "%d%c", _tc->c_c_index, 0);                 \
80   elog_track_register (&vlib_global_main.elog_main, &_tc->c_elog_track);\
81 }
82
83 #define TCP_EVT_DEALLOC_HANDLER(_tc, ...)                               \
84 {                                                                       \
85   vec_free (_tc->c_elog_track.name);                                    \
86 }
87
88 #define TCP_EVT_OPEN_HANDLER(_tc, ...)                                  \
89 {                                                                       \
90   TCP_EVT_INIT_HANDLER(_tc);                                            \
91   ELOG_TYPE_DECLARE (_e) =                                              \
92   {                                                                     \
93     .format = "open: index %d",                                         \
94     .format_args = "i4",                                                \
95   };                                                                    \
96   DECLARE_ETD(_tc, _e, 1);                                              \
97   ed->data[0] = _tc->c_c_index;                                         \
98 }
99
100 #define TCP_EVT_CLOSE_HANDLER(_tc, ...)                                 \
101 {                                                                       \
102   ELOG_TYPE_DECLARE (_e) =                                              \
103   {                                                                     \
104     .format = "close: %d",                                              \
105     .format_args = "i4",                                                \
106   };                                                                    \
107   DECLARE_ETD(_tc, _e, 1);                                              \
108   ed->data[0] = _tc->c_c_index;                                         \
109 }
110
111 #define TCP_EVT_BIND_HANDLER(_tc, ...)                                  \
112 {                                                                       \
113   TCP_EVT_INIT_HANDLER(_tc);                                            \
114   ELOG_TYPE_DECLARE (_e) =                                              \
115   {                                                                     \
116     .format = "bind: listener %d",                                      \
117   };                                                                    \
118   DECLARE_ETD(_tc, _e, 1);                                              \
119   ed->data[0] = _tc->c_c_index;                                         \
120 }
121
122 #define TCP_EVT_UNBIND_HANDLER(_tc, ...)                                \
123 {                                                                       \
124   TCP_EVT_DEALLOC_HANDLER(_tc);                                         \
125   ELOG_TYPE_DECLARE (_e) =                                              \
126   {                                                                     \
127     .format = "unbind: listener %d",                                    \
128   };                                                                    \
129   DECLARE_ETD(_tc, _e, 1);                                              \
130   ed->data[0] = _tc->c_c_index;                                         \
131   TCP_EVT_DEALLOC_HANDLER(_tc);                                         \
132 }
133
134 #define TCP_EVT_DELETE_HANDLER(_tc, ...)                                \
135 {                                                                       \
136   ELOG_TYPE_DECLARE (_e) =                                              \
137   {                                                                     \
138     .format = "delete: %d",                                             \
139     .format_args = "i4",                                                \
140   };                                                                    \
141   DECLARE_ETD(_tc, _e, 0);                                              \
142   ed->data[0] = _tc->c_c_index;                                         \
143   TCP_EVT_DEALLOC_HANDLER(_tc);                                         \
144 }
145
146 #define TCP_EVT_SYN_SENT_HANDLER(_tc, ...)                              \
147 {                                                                       \
148   ELOG_TYPE_DECLARE (_e) =                                              \
149   {                                                                     \
150     .format = "SYN: iss %d",                                            \
151     .format_args = "i4",                                                \
152   };                                                                    \
153   DECLARE_ETD(_tc, _e, 1);                                              \
154   ed->data[0] = _tc->iss;                                               \
155 }
156
157 #define TCP_EVT_FIN_SENT_HANDLER(_tc, ...)                              \
158 {                                                                       \
159   ELOG_TYPE_DECLARE (_e) =                                              \
160   {                                                                     \
161     .format = "FIN: snd_nxt %d rcv_nxt %d",                             \
162     .format_args = "i4i4",                                              \
163   };                                                                    \
164   DECLARE_ETD(_tc, _e, 2);                                              \
165   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
166   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
167 }
168
169 #define TCP_EVT_RST_SENT_HANDLER(_tc, ...)                              \
170 {                                                                       \
171   ELOG_TYPE_DECLARE (_e) =                                              \
172   {                                                                     \
173     .format = "RST: snd_nxt %d rcv_nxt %d",                             \
174     .format_args = "i4i4",                                              \
175   };                                                                    \
176   DECLARE_ETD(_tc, _e, 2);                                              \
177   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
178   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
179 }
180
181 #define TCP_EVT_SYN_RCVD_HANDLER(_tc, ...)                              \
182 {                                                                       \
183   TCP_EVT_INIT_HANDLER(_tc);                                            \
184   ELOG_TYPE_DECLARE (_e) =                                              \
185   {                                                                     \
186     .format = "SYN rcvd: irs %d",                                       \
187     .format_args = "i4",                                                \
188   };                                                                    \
189   DECLARE_ETD(_tc, _e, 1);                                              \
190   ed->data[0] = _tc->irs;                                               \
191 }
192
193 #define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...)                              \
194 {                                                                       \
195   ELOG_TYPE_DECLARE (_e) =                                              \
196   {                                                                     \
197     .format = "FIN rcvd: snd_nxt %d rcv_nxt %d",                        \
198     .format_args = "i4i4",                                              \
199   };                                                                    \
200   DECLARE_ETD(_tc, _e, 2);                                              \
201   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
202   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
203 }
204
205 #define TCP_EVT_RST_RCVD_HANDLER(_tc, ...)                              \
206 {                                                                       \
207   ELOG_TYPE_DECLARE (_e) =                                              \
208   {                                                                     \
209     .format = "RST rcvd: snd_nxt %d rcv_nxt %d",                        \
210     .format_args = "i4i4",                                              \
211   };                                                                    \
212   DECLARE_ETD(_tc, _e, 2);                                              \
213   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
214   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
215 }
216
217 #define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)                              \
218 {                                                                       \
219   ELOG_TYPE_DECLARE (_e) =                                              \
220   {                                                                     \
221     .format = "ACK: acked %u cwnd %u inflight %u",                      \
222     .format_args = "i4i4i4",                                            \
223   };                                                                    \
224   DECLARE_ETD(_tc, _e, 3);                                              \
225   ed->data[0] = _tc->bytes_acked;                                       \
226   ed->data[1] = _tc->cwnd;                                              \
227   ed->data[2] = tcp_flight_size(_tc);                                   \
228 }
229
230 #define TCP_EVT_PKTIZE_HANDLER(_tc, ...)                                \
231 {                                                                       \
232   ELOG_TYPE_DECLARE (_e) =                                              \
233   {                                                                     \
234     .format = "pktize: snd_una %u snd_nxt %u una_max %u",               \
235     .format_args = "i4i4i4",                                            \
236   };                                                                    \
237   DECLARE_ETD(_tc, _e, 3);                                              \
238   ed->data[0] = _tc->snd_una - _tc->iss;                                \
239   ed->data[1] = _tc->snd_nxt - _tc->iss;                                \
240   ed->data[2] = _tc->snd_una_max - _tc->iss;                            \
241 }
242
243 #define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)                 \
244 {                                                                       \
245   ELOG_TYPE_DECLARE (_e) =                                              \
246   {                                                                     \
247     .format = "out: flags %x, bytes %u",                                \
248     .format_args = "i4i4",                                              \
249   };                                                                    \
250   DECLARE_ETD(_tc, _e, 2);                                              \
251   ed->data[0] = flags;                                                  \
252   ed->data[1] = n_bytes;                                                \
253 }
254
255 #define TCP_EVT_INPUT_HANDLER(_tc, n_bytes, ...)                        \
256 {                                                                       \
257   ELOG_TYPE_DECLARE (_e) =                                              \
258   {                                                                     \
259     .format = "in: bytes %u rcv_nxt %u",                                \
260     .format_args = "i4i4",                                              \
261   };                                                                    \
262   DECLARE_ETD(_tc, _e, 2);                                              \
263   ed->data[0] = n_bytes;                                                \
264   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
265 }
266
267 #define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)            \
268 {                                                                       \
269   tcp_connection_t *_tc;                                                \
270   if (_timer_id == TCP_TIMER_RETRANSMIT_SYN)                            \
271     {                                                                   \
272       _tc = tcp_half_open_connection_get (_tc_index);                   \
273     }                                                                   \
274   else                                                                  \
275     {                                                                   \
276       u32 _thread_index = os_get_cpu_number ();                         \
277       _tc = tcp_connection_get (_tc_index, _thread_index);              \
278     }                                                                   \
279   ELOG_TYPE_DECLARE (_e) =                                              \
280   {                                                                     \
281     .format = "TimerPop: %s (%d)",                                      \
282     .format_args = "t4i4",                                              \
283     .n_enum_strings = 7,                                                \
284     .enum_strings = {                                                   \
285       "retransmit",                                                     \
286       "delack",                                                         \
287       "BUG",                                                            \
288       "keep",                                                           \
289       "waitclose",                                                      \
290       "retransmit syn",                                                 \
291       "establish",                                                      \
292     },                                                                  \
293   };                                                                    \
294   DECLARE_ETD(_tc, _e, 2);                                              \
295   ed->data[0] = _timer_id;                                              \
296   ed->data[1] = _timer_id;                                              \
297 }
298
299 #define CONCAT_HELPER(_a, _b) _a##_b
300 #define CC(_a, _b) CONCAT_HELPER(_a, _b)
301
302 #define TCP_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
303
304 #else
305 #define TCP_EVT_DBG(_evt, _args...)
306 #endif
307
308
309 #endif /* SRC_VNET_TCP_TCP_DEBUG_H_ */
310 /*
311  * fd.io coding-style-patch-verification: ON
312  *
313  * Local Variables:
314  * eval: (c-set-style "gnu")
315  * End:
316  */