Make tcp active open data structures thread safe
[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 #define TCP_DEBUG_SM (0)
23 #define TCP_DEBUG_CC (1)
24 #define TCP_DEBUG_CC_STAT (1)
25
26 #define foreach_tcp_dbg_evt             \
27   _(INIT, "")                           \
28   _(DEALLOC, "")                        \
29   _(OPEN, "open")                       \
30   _(CLOSE, "close")                     \
31   _(BIND, "bind")                       \
32   _(UNBIND, "unbind")                   \
33   _(DELETE, "delete")                   \
34   _(SYN_SENT, "SYN sent")               \
35   _(SYNACK_SENT, "SYNACK sent")         \
36   _(SYNACK_RCVD, "SYNACK rcvd")         \
37   _(SYN_RXT, "SYN retransmit")          \
38   _(FIN_SENT, "FIN sent")               \
39   _(ACK_SENT, "ACK sent")               \
40   _(DUPACK_SENT, "DUPACK sent")         \
41   _(RST_SENT, "RST sent")               \
42   _(SYN_RCVD, "SYN rcvd")               \
43   _(ACK_RCVD, "ACK rcvd")               \
44   _(DUPACK_RCVD, "DUPACK rcvd")         \
45   _(FIN_RCVD, "FIN rcvd")               \
46   _(RST_RCVD, "RST rcvd")               \
47   _(STATE_CHANGE, "state change")       \
48   _(PKTIZE, "packetize")                \
49   _(INPUT, "in")                        \
50   _(SND_WND, "snd_wnd update")          \
51   _(OUTPUT, "output")                   \
52   _(TIMER_POP, "timer pop")             \
53   _(CC_RTX, "retransmit")               \
54   _(CC_EVT, "cc event")                 \
55   _(CC_PACK, "cc partial ack")          \
56   _(CC_STAT, "cc stats")                \
57   _(CC_RTO_STAT, "cc rto stats")        \
58   _(SEG_INVALID, "invalid segment")     \
59   _(PAWS_FAIL, "failed paws check")     \
60   _(ACK_RCV_ERR, "invalid ack")         \
61   _(RCV_WND_SHRUNK, "shrunk rcv_wnd")   \
62
63 typedef enum _tcp_dbg
64 {
65 #define _(sym, str) TCP_DBG_##sym,
66   foreach_tcp_dbg_evt
67 #undef _
68 } tcp_dbg_e;
69
70 typedef enum _tcp_dbg_evt
71 {
72 #define _(sym, str) TCP_EVT_##sym,
73   foreach_tcp_dbg_evt
74 #undef _
75 } tcp_dbg_evt_e;
76
77 #if TCP_DEBUG
78
79 #define TRANSPORT_DEBUG (1)
80
81 /*
82  * Infra and evt track setup
83  */
84
85 #define TCP_DBG(_tc, _evt, _args...)                                    \
86 {                                                                       \
87     u8 *_tmp = 0;                                                       \
88     _tmp = format(_tmp, "%U", format_tcp_connection_verbose, _tc);      \
89     clib_warning("%s", _tmp);                                           \
90     vec_free(_tmp);                                                     \
91 }
92
93 #define DECLARE_ETD(_tc, _e, _size)                                     \
94   struct                                                                \
95   {                                                                     \
96     u32 data[_size];                                                    \
97   } * ed;                                                               \
98   ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main,                    \
99                         _e, _tc->c_elog_track)
100
101 #define TCP_DBG_IP_TAG_LCL(_tc)                                         \
102 {                                                                       \
103   if (_tc->c_is_ip4)                                                    \
104     {                                                                   \
105       ELOG_TYPE_DECLARE (_e) =                                          \
106       {                                                                 \
107         .format = "lcl: %d.%d.%d.%d:%d",                                \
108         .format_args = "i4i4i4i4i4",                                    \
109       };                                                                \
110       DECLARE_ETD(_tc, _e, 5);                                          \
111       ed->data[0] = _tc->c_lcl_ip.ip4.as_u8[0];                         \
112       ed->data[1] = _tc->c_lcl_ip.ip4.as_u8[1];                         \
113       ed->data[2] = _tc->c_lcl_ip.ip4.as_u8[2];                         \
114       ed->data[3] = _tc->c_lcl_ip.ip4.as_u8[3];                         \
115       ed->data[4] = clib_net_to_host_u16(_tc->c_lcl_port);              \
116     }                                                                   \
117 }
118
119 #define TCP_DBG_IP_TAG_RMT(_tc)                                         \
120 {                                                                       \
121   if (_tc->c_is_ip4)                                                    \
122     {                                                                   \
123       ELOG_TYPE_DECLARE (_e) =                                          \
124       {                                                                 \
125         .format = "rmt: %d.%d.%d.%d:%d",                                \
126         .format_args = "i4i4i4i4i4",                                    \
127       };                                                                \
128       DECLARE_ETD(_tc, _e, 5);                                          \
129       ed->data[0] = _tc->c_rmt_ip.ip4.as_u8[0];                         \
130       ed->data[1] = _tc->c_rmt_ip.ip4.as_u8[1];                         \
131       ed->data[2] = _tc->c_rmt_ip.ip4.as_u8[2];                         \
132       ed->data[3] = _tc->c_rmt_ip.ip4.as_u8[3];                         \
133       ed->data[4] = clib_net_to_host_u16(_tc->c_rmt_port);              \
134     }                                                                   \
135 }
136
137 #define TCP_EVT_INIT_HANDLER(_tc, _is_l, ...)                           \
138 {                                                                       \
139   char *_fmt = _is_l ? "l[%d].%d:%d%c" : "[%d].%d:%d->.%d:%d%c";        \
140   if (_tc->c_is_ip4)                                                    \
141     {                                                                   \
142       _tc->c_elog_track.name =                                          \
143         (char *) format (0, _fmt, _tc->c_thread_index,                  \
144                          _tc->c_lcl_ip.ip4.as_u8[3],                    \
145                          clib_net_to_host_u16(_tc->c_lcl_port),         \
146                          _tc->c_rmt_ip.ip4.as_u8[3],                    \
147                          clib_net_to_host_u16(_tc->c_rmt_port), 0);     \
148     }                                                                   \
149   else                                                                  \
150       _tc->c_elog_track.name =                                          \
151         (char *) format (0, _fmt, _tc->c_thread_index,                  \
152                          _tc->c_lcl_ip.ip6.as_u8[15],                   \
153                          clib_net_to_host_u16(_tc->c_lcl_port),         \
154                          _tc->c_rmt_ip.ip6.as_u8[15],                   \
155                          clib_net_to_host_u16(_tc->c_rmt_port), 0);     \
156   elog_track_register (&vlib_global_main.elog_main, &_tc->c_elog_track);\
157   TCP_DBG_IP_TAG_LCL(_tc);                                              \
158   TCP_DBG_IP_TAG_RMT(_tc);                                              \
159 }
160
161 #define TCP_EVT_DEALLOC_HANDLER(_tc, ...)                               \
162 {                                                                       \
163   vec_free (_tc->c_elog_track.name);                                    \
164 }
165
166 #define TCP_EVT_OPEN_HANDLER(_tc, ...)                                  \
167 {                                                                       \
168   TCP_EVT_INIT_HANDLER(_tc, 0);                                         \
169   ELOG_TYPE_DECLARE (_e) =                                              \
170   {                                                                     \
171     .format = "open: index %d",                                         \
172     .format_args = "i4",                                                \
173   };                                                                    \
174   DECLARE_ETD(_tc, _e, 1);                                              \
175   ed->data[0] = _tc->c_c_index;                                         \
176 }
177
178 #define TCP_EVT_CLOSE_HANDLER(_tc, ...)                                 \
179 {                                                                       \
180   ELOG_TYPE_DECLARE (_e) =                                              \
181   {                                                                     \
182     .format = "close: %d",                                              \
183     .format_args = "i4",                                                \
184   };                                                                    \
185   DECLARE_ETD(_tc, _e, 1);                                              \
186   ed->data[0] = _tc->c_c_index;                                         \
187 }
188
189 #define TCP_EVT_BIND_HANDLER(_tc, ...)                                  \
190 {                                                                       \
191   TCP_EVT_INIT_HANDLER(_tc, 1);                                         \
192   ELOG_TYPE_DECLARE (_e) =                                              \
193   {                                                                     \
194     .format = "bind: listener %d",                                      \
195   };                                                                    \
196   DECLARE_ETD(_tc, _e, 1);                                              \
197   ed->data[0] = _tc->c_c_index;                                         \
198 }
199
200 #define TCP_EVT_SYN_RCVD_HANDLER(_tc, ...)                              \
201 {                                                                       \
202   TCP_EVT_INIT_HANDLER(_tc, 0);                                         \
203   ELOG_TYPE_DECLARE (_e) =                                              \
204   {                                                                     \
205     .format = "syn-rx: irs %u",                                         \
206     .format_args = "i4",                                                \
207   };                                                                    \
208   DECLARE_ETD(_tc, _e, 1);                                              \
209   ed->data[0] = _tc->irs;                                               \
210   TCP_EVT_STATE_CHANGE_HANDLER(_tc);                                    \
211 }
212
213 #define TCP_EVT_UNBIND_HANDLER(_tc, ...)                                \
214 {                                                                       \
215   TCP_EVT_DEALLOC_HANDLER(_tc);                                         \
216   ELOG_TYPE_DECLARE (_e) =                                              \
217   {                                                                     \
218     .format = "unbind: listener %d",                                    \
219   };                                                                    \
220   DECLARE_ETD(_tc, _e, 1);                                              \
221   ed->data[0] = _tc->c_c_index;                                         \
222   TCP_EVT_DEALLOC_HANDLER(_tc);                                         \
223 }
224
225 #define TCP_EVT_DELETE_HANDLER(_tc, ...)                                \
226 {                                                                       \
227   ELOG_TYPE_DECLARE (_e) =                                              \
228   {                                                                     \
229     .format = "delete: %d",                                             \
230     .format_args = "i4",                                                \
231   };                                                                    \
232   DECLARE_ETD(_tc, _e, 1);                                              \
233   ed->data[0] = _tc->c_c_index;                                         \
234   TCP_EVT_DEALLOC_HANDLER(_tc);                                         \
235 }
236
237 #define CONCAT_HELPER(_a, _b) _a##_b
238 #define CC(_a, _b) CONCAT_HELPER(_a, _b)
239 #define TCP_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
240 #else
241 #define TCP_EVT_DBG(_evt, _args...)
242 #endif
243
244 /*
245  * State machine
246  */
247 #if TCP_DEBUG_SM
248
249 #define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...)                          \
250 {                                                                       \
251   ELOG_TYPE_DECLARE (_e) =                                              \
252   {                                                                     \
253     .format = "state: %s",                                              \
254     .format_args = "t4",                                                \
255     .n_enum_strings = 11,                                               \
256     .enum_strings = {                                                   \
257       "closed",                                                         \
258       "listen",                                                         \
259       "syn-sent",                                                       \
260       "syn-rcvd",                                                       \
261       "established",                                                    \
262       "close_wait",                                                     \
263       "fin-wait-1",                                                     \
264       "last-ack",                                                       \
265       "closing",                                                        \
266       "fin-wait-2",                                                     \
267       "time-wait",                                                      \
268     },                                                                  \
269   };                                                                    \
270   DECLARE_ETD(_tc, _e, 1);                                              \
271   ed->data[0] = _tc->state;                                             \
272 }
273
274 #define TCP_EVT_SYN_SENT_HANDLER(_tc, ...)                              \
275 {                                                                       \
276   ELOG_TYPE_DECLARE (_e) =                                              \
277   {                                                                     \
278     .format = "syn-tx: iss %u",                                         \
279     .format_args = "i4",                                                \
280   };                                                                    \
281   DECLARE_ETD(_tc, _e, 1);                                              \
282   ed->data[0] = _tc->iss;                                               \
283   TCP_EVT_STATE_CHANGE_HANDLER(_tc);                                    \
284 }
285
286 #define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...)                           \
287 {                                                                       \
288   ELOG_TYPE_DECLARE (_e) =                                              \
289   {                                                                     \
290     .format = "synack-tx: iss %u irs %u",                               \
291     .format_args = "i4i4",                                              \
292   };                                                                    \
293   DECLARE_ETD(_tc, _e, 2);                                              \
294   ed->data[0] = _tc->iss;                                               \
295   ed->data[1] = _tc->irs;                                               \
296 }
297
298 #define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...)                           \
299 {                                                                       \
300   ELOG_TYPE_DECLARE (_e) =                                              \
301   {                                                                     \
302     .format = "synack-rx: iss %u irs %u",                               \
303     .format_args = "i4i4",                                              \
304   };                                                                    \
305   DECLARE_ETD(_tc, _e, 2);                                              \
306   ed->data[0] = _tc->iss;                                               \
307   ed->data[1] = _tc->irs;                                               \
308   TCP_EVT_STATE_CHANGE_HANDLER(_tc);                                    \
309 }
310
311 #define TCP_EVT_FIN_SENT_HANDLER(_tc, ...)                              \
312 {                                                                       \
313   ELOG_TYPE_DECLARE (_e) =                                              \
314   {                                                                     \
315     .format = "fin-tx: snd_nxt %d rcv_nxt %d",                          \
316     .format_args = "i4i4",                                              \
317   };                                                                    \
318   DECLARE_ETD(_tc, _e, 2);                                              \
319   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
320   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
321 }
322
323 #define TCP_EVT_RST_SENT_HANDLER(_tc, ...)                              \
324 {                                                                       \
325   ELOG_TYPE_DECLARE (_e) =                                              \
326   {                                                                     \
327     .format = "rst-tx: snd_nxt %d rcv_nxt %d",                          \
328     .format_args = "i4i4",                                              \
329   };                                                                    \
330   DECLARE_ETD(_tc, _e, 2);                                              \
331   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
332   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
333   TCP_EVT_STATE_CHANGE_HANDLER(_tc);                                    \
334 }
335
336 #define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...)                              \
337 {                                                                       \
338   ELOG_TYPE_DECLARE (_e) =                                              \
339   {                                                                     \
340     .format = "fin-rx: snd_nxt %d rcv_nxt %d",                          \
341     .format_args = "i4i4",                                              \
342   };                                                                    \
343   DECLARE_ETD(_tc, _e, 2);                                              \
344   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
345   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
346 }
347
348 #define TCP_EVT_RST_RCVD_HANDLER(_tc, ...)                              \
349 {                                                                       \
350   ELOG_TYPE_DECLARE (_e) =                                              \
351   {                                                                     \
352     .format = "rst-rx: snd_nxt %d rcv_nxt %d",                          \
353     .format_args = "i4i4",                                              \
354   };                                                                    \
355   DECLARE_ETD(_tc, _e, 2);                                              \
356   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
357   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
358 }
359
360 #define TCP_EVT_SYN_RXT_HANDLER(_tc, _type, ...)                        \
361 {                                                                       \
362   ELOG_TYPE_DECLARE (_e) =                                              \
363   {                                                                     \
364     .format = "%s-rxt: iss %u",                                         \
365     .format_args = "t4i4",                                              \
366     .n_enum_strings = 2,                                                \
367     .enum_strings = {                                                   \
368         "syn",                                                          \
369         "syn-ack",                                                      \
370     },                                                                  \
371   };                                                                    \
372   DECLARE_ETD(_tc, _e, 2);                                              \
373   ed->data[0] = _type;                                                  \
374   ed->data[1] = _tc->iss;                                               \
375 }
376
377 #else
378 #define TCP_EVT_SYN_SENT_HANDLER(_tc, ...)
379 #define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...)
380 #define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...)
381 #define TCP_EVT_SYN_RXT_HANDLER(_tc, ...)
382 #define TCP_EVT_FIN_SENT_HANDLER(_tc, ...)
383 #define TCP_EVT_RST_SENT_HANDLER(_tc, ...)
384 #define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...)
385 #define TCP_EVT_RST_RCVD_HANDLER(_tc, ...)
386 #define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...)
387 #endif
388
389 #if TCP_DEBUG_SM > 1
390
391 #define TCP_EVT_ACK_SENT_HANDLER(_tc, ...)                              \
392 {                                                                       \
393   ELOG_TYPE_DECLARE (_e) =                                              \
394   {                                                                     \
395     .format = "ack-tx: acked %u rcv_nxt %u rcv_wnd %u snd_nxt %u snd_wnd %u",\
396     .format_args = "i4i4i4i4i4",                                        \
397   };                                                                    \
398   DECLARE_ETD(_tc, _e, 5);                                              \
399   ed->data[0] = _tc->rcv_nxt - _tc->rcv_las;                            \
400   ed->data[1] = _tc->rcv_nxt - _tc->irs;                                \
401   ed->data[2] = _tc->rcv_wnd;                                           \
402   ed->data[3] = _tc->snd_nxt - _tc->iss;                                \
403   ed->data[4] = _tc->snd_wnd;                                           \
404 }
405
406 #define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...)                           \
407 {                                                                       \
408   ELOG_TYPE_DECLARE (_e) =                                              \
409   {                                                                     \
410     .format = "dack-tx: rcv_nxt %u rcv_wnd %u snd_nxt %u av_wnd %u snd_wnd %u",\
411     .format_args = "i4i4i4i4i4",                                        \
412   };                                                                    \
413   DECLARE_ETD(_tc, _e, 5);                                              \
414   ed->data[0] = _tc->rcv_nxt - _tc->irs;                                \
415   ed->data[1] = _tc->rcv_wnd;                                           \
416   ed->data[2] = _tc->snd_nxt - _tc->iss;                                \
417   ed->data[3] = tcp_available_wnd(_tc);                                 \
418   ed->data[4] = _tc->snd_wnd;                                           \
419 }
420
421 #define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)                              \
422 {                                                                       \
423   ELOG_TYPE_DECLARE (_e) =                                              \
424   {                                                                     \
425     .format = "acked: %u snd_una %u snd_wnd %u cwnd %u inflight %u",    \
426     .format_args = "i4i4i4i4i4",                                        \
427   };                                                                    \
428   DECLARE_ETD(_tc, _e, 5);                                              \
429   ed->data[0] = _tc->bytes_acked;                                       \
430   ed->data[1] = _tc->snd_una - _tc->iss;                                \
431   ed->data[2] = _tc->snd_wnd;                                           \
432   ed->data[3] = _tc->cwnd;                                              \
433   ed->data[4] = tcp_flight_size(_tc);                                   \
434 }
435
436 #define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...)                           \
437 {                                                                       \
438   ELOG_TYPE_DECLARE (_e) =                                              \
439   {                                                                     \
440     .format = "dack-rx: snd_una %u cwnd %u snd_wnd %u flight %u rcv_wnd %u",\
441     .format_args = "i4i4i4i4i4",                                        \
442   };                                                                    \
443   DECLARE_ETD(_tc, _e, 5);                                              \
444   ed->data[0] = _tc->snd_una - _tc->iss;                                \
445   ed->data[1] = _tc->cwnd;                                              \
446   ed->data[2] = _tc->snd_wnd;                                           \
447   ed->data[3] = tcp_flight_size(_tc);                                   \
448   ed->data[4] = _tc->rcv_wnd;                                           \
449 }
450
451 #define TCP_EVT_PKTIZE_HANDLER(_tc, ...)                                \
452 {                                                                       \
453   ELOG_TYPE_DECLARE (_e) =                                              \
454   {                                                                     \
455     .format = "pktize: una %u snd_nxt %u space %u flight %u rcv_wnd %u",\
456     .format_args = "i4i4i4i4i4",                                        \
457   };                                                                    \
458   DECLARE_ETD(_tc, _e, 5);                                              \
459   ed->data[0] = _tc->snd_una - _tc->iss;                                \
460   ed->data[1] = _tc->snd_nxt - _tc->iss;                                \
461   ed->data[2] = tcp_available_snd_space (_tc);                          \
462   ed->data[3] = tcp_flight_size (_tc);                                  \
463   ed->data[4] = _tc->rcv_wnd;                                           \
464 }
465
466 #define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...)          \
467 {                                                                       \
468   ELOG_TYPE_DECLARE (_e) =                                              \
469   {                                                                     \
470     .format = "in: %s len %u written %d rcv_nxt %u rcv_wnd(o) %d",      \
471     .format_args = "t4i4i4i4i4",                                        \
472     .n_enum_strings = 2,                                                \
473     .enum_strings = {                                                   \
474       "order",                                                          \
475       "ooo",                                                            \
476     },                                                                  \
477   };                                                                    \
478   DECLARE_ETD(_tc, _e, 5);                                              \
479   ed->data[0] = _type;                                                  \
480   ed->data[1] = _len;                                                   \
481   ed->data[2] = _written;                                               \
482   ed->data[3] = (_tc->rcv_nxt - _tc->irs) + _written;                   \
483   ed->data[4] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las);           \
484 }
485
486 #define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)            \
487 {                                                                       \
488   tcp_connection_t *_tc;                                                \
489   if (_timer_id == TCP_TIMER_RETRANSMIT_SYN                             \
490     || _timer_id == TCP_TIMER_ESTABLISH)                                \
491     {                                                                   \
492       _tc = tcp_half_open_connection_get (_tc_index);                   \
493     }                                                                   \
494   else                                                                  \
495     {                                                                   \
496       u32 _thread_index = vlib_get_thread_index ();                     \
497       _tc = tcp_connection_get (_tc_index, _thread_index);              \
498     }                                                                   \
499   ELOG_TYPE_DECLARE (_e) =                                              \
500   {                                                                     \
501     .format = "timer-pop: %s (%d)",                                     \
502     .format_args = "t4i4",                                              \
503     .n_enum_strings = 7,                                                \
504     .enum_strings = {                                                   \
505       "retransmit",                                                     \
506       "delack",                                                         \
507       "persist",                                                        \
508       "keep",                                                           \
509       "waitclose",                                                      \
510       "retransmit syn",                                                 \
511       "establish",                                                      \
512     },                                                                  \
513   };                                                                    \
514   if (_tc)                                                              \
515     {                                                                   \
516       DECLARE_ETD(_tc, _e, 2);                                          \
517       ed->data[0] = _timer_id;                                          \
518       ed->data[1] = _timer_id;                                          \
519     }                                                                   \
520   else                                                                  \
521     {                                                                   \
522       clib_warning ("pop %d for unexisting connection %d", _timer_id,   \
523                     _tc_index);                                         \
524     }                                                                   \
525 }
526
527 #define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...)               \
528 {                                                                       \
529   ELOG_TYPE_DECLARE (_e) =                                              \
530   {                                                                     \
531     .format = "seg-inv: seq %u end %u rcv_las %u rcv_nxt %u rcv_wnd %u",\
532     .format_args = "i4i4i4i4i4",                                        \
533   };                                                                    \
534   DECLARE_ETD(_tc, _e, 5);                                              \
535   ed->data[0] = _seq - _tc->irs;                                        \
536   ed->data[1] = _end - _tc->irs;                                        \
537   ed->data[2] = _tc->rcv_las - _tc->irs;                                \
538   ed->data[3] = _tc->rcv_nxt - _tc->irs;                                \
539   ed->data[4] = _tc->rcv_wnd;                                           \
540 }
541
542 #define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...)                 \
543 {                                                                       \
544   ELOG_TYPE_DECLARE (_e) =                                              \
545   {                                                                     \
546     .format = "paws-err: seq %u end %u tsval %u tsval_recent %u",       \
547     .format_args = "i4i4i4i4",                                          \
548   };                                                                    \
549   DECLARE_ETD(_tc, _e, 4);                                              \
550   ed->data[0] = _seq - _tc->irs;                                        \
551   ed->data[1] = _end - _tc->irs;                                        \
552   ed->data[2] = _tc->rcv_opts.tsval;                                    \
553   ed->data[3] = _tc->tsval_recent;                                      \
554 }
555
556 #define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...)              \
557 {                                                                       \
558   ELOG_TYPE_DECLARE (_e) =                                              \
559   {                                                                     \
560     .format = "ack-err: %s ack %u snd_una %u snd_nxt %u una_max %u",    \
561     .format_args = "t4i4i4i4i4",                                        \
562     .n_enum_strings = 3,                                                \
563     .enum_strings = {                                                   \
564       "invalid",                                                        \
565       "old",                                                            \
566       "future",                                                         \
567     },                                                                  \
568   };                                                                    \
569   DECLARE_ETD(_tc, _e, 5);                                              \
570   ed->data[0] = _type;                                                  \
571   ed->data[1] = _ack - _tc->iss;                                        \
572   ed->data[2] = _tc->snd_una - _tc->iss;                                \
573   ed->data[3] = _tc->snd_nxt - _tc->iss;                                \
574   ed->data[4] = _tc->snd_una_max - _tc->iss;                            \
575 }
576
577 #define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...)             \
578 {                                                                       \
579 if (_av > 0)                                                            \
580 {                                                                       \
581   ELOG_TYPE_DECLARE (_e) =                                              \
582   {                                                                     \
583     .format = "huh?: rcv_wnd %u obsd %u av %u rcv_nxt %u rcv_las %u",   \
584     .format_args = "i4i4i4i4i4",                                        \
585   };                                                                    \
586   DECLARE_ETD(_tc, _e, 5);                                              \
587   ed->data[0] = _tc->rcv_wnd;                                           \
588   ed->data[1] = _obs;                                                   \
589   ed->data[2] = _av;                                                    \
590   ed->data[3] = _tc->rcv_nxt - _tc->irs;                                \
591   ed->data[4] = _tc->rcv_las - _tc->irs;                                \
592 }                                                                       \
593 }
594 #else
595 #define TCP_EVT_ACK_SENT_HANDLER(_tc, ...)
596 #define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...)
597 #define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)
598 #define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...)
599 #define TCP_EVT_PKTIZE_HANDLER(_tc, ...)
600 #define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...)
601 #define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)
602 #define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...)
603 #define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...)
604 #define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...)
605 #define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...)
606 #endif
607
608 /*
609  * State machine verbose
610  */
611 #if TCP_DEBUG_SM > 2
612 #define TCP_EVT_SND_WND_HANDLER(_tc, ...)                               \
613 {                                                                       \
614   ELOG_TYPE_DECLARE (_e) =                                              \
615   {                                                                     \
616     .format = "snd-wnd update: %u ",                                    \
617     .format_args = "i4",                                                \
618   };                                                                    \
619   DECLARE_ETD(_tc, _e, 1);                                              \
620   ed->data[0] = _tc->snd_wnd;                                           \
621 }
622
623 #define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)                 \
624 {                                                                       \
625   ELOG_TYPE_DECLARE (_e) =                                              \
626   {                                                                     \
627     .format = "out: flags %x, bytes %u",                                \
628     .format_args = "i4i4",                                              \
629   };                                                                    \
630   DECLARE_ETD(_tc, _e, 2);                                              \
631   ed->data[0] = flags;                                                  \
632   ed->data[1] = n_bytes;                                                \
633 }
634 #else
635 #define TCP_EVT_SND_WND_HANDLER(_tc, ...)
636 #define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)
637 #endif
638
639 /*
640  * Congestion Control
641  */
642
643 #if TCP_DEBUG_CC
644 #define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...)               \
645 {                                                                       \
646   ELOG_TYPE_DECLARE (_e) =                                              \
647   {                                                                     \
648     .format = "rxt: snd_nxt %u offset %u snd %u rxt %u",                \
649     .format_args = "i4i4i4i4",                                          \
650   };                                                                    \
651   DECLARE_ETD(_tc, _e, 4);                                              \
652   ed->data[0] = _tc->snd_nxt - _tc->iss;                                \
653   ed->data[1] = offset;                                                 \
654   ed->data[2] = n_bytes;                                                \
655   ed->data[3] = _tc->snd_rxt_bytes;                                     \
656 }
657
658 #define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...)                      \
659 {                                                                       \
660   ELOG_TYPE_DECLARE (_e) =                                              \
661   {                                                                     \
662     .format = "cc: %s wnd %u snd_cong %u rxt_bytes %u",                 \
663     .format_args = "t4i4i4i4",                                          \
664     .n_enum_strings = 5,                                                \
665     .enum_strings = {                                                   \
666       "fast-rxt",                                                       \
667       "rxt-timeout",                                                    \
668       "first-rxt",                                                      \
669       "recovered",                                                      \
670       "congestion",                                                     \
671     },                                                                  \
672   };                                                                    \
673   DECLARE_ETD(_tc, _e, 4);                                              \
674   ed->data[0] = _sub_evt;                                               \
675   ed->data[1] = tcp_available_snd_space (_tc);                          \
676   ed->data[2] = _tc->snd_congestion - _tc->iss;                         \
677   ed->data[3] = _tc->snd_rxt_bytes;                                     \
678 }
679
680 #define TCP_EVT_CC_PACK_HANDLER(_tc, ...)                               \
681 {                                                                       \
682   ELOG_TYPE_DECLARE (_e) =                                              \
683   {                                                                     \
684     .format = "pack: snd_una %u snd_una_max %u",                        \
685     .format_args = "i4i4",                                              \
686   };                                                                    \
687   DECLARE_ETD(_tc, _e, 2);                                              \
688   ed->data[0] = _tc->snd_una - _tc->iss;                                \
689   ed->data[1] = _tc->snd_una_max - _tc->iss;                            \
690 }
691
692 /*
693  * Congestion control stats
694  */
695 #if TCP_DEBUG_CC_STAT
696
697 #define STATS_INTERVAL 1
698
699 #define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...)                           \
700 {                                                                       \
701 if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now())            \
702 {                                                                       \
703   ELOG_TYPE_DECLARE (_e) =                                              \
704   {                                                                     \
705     .format = "rto_stat: rto %u srtt %u rttvar %u ",                    \
706     .format_args = "i4i4i4",                                            \
707   };                                                                    \
708   DECLARE_ETD(_tc, _e, 3);                                              \
709   ed->data[0] = _tc->rto;                                               \
710   ed->data[1] = _tc->srtt;                                              \
711   ed->data[2] = _tc->rttvar;                                            \
712 }                                                                       \
713 }
714
715 #define TCP_EVT_CC_STAT_HANDLER(_tc, ...)                               \
716 {                                                                       \
717 if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now())            \
718 {                                                                       \
719   ELOG_TYPE_DECLARE (_e) =                                              \
720   {                                                                     \
721     .format = "cc_stat: cwnd %u flight %u space %u ssthresh %u snd_wnd %u",\
722     .format_args = "i4i4i4i4i4",                                        \
723   };                                                                    \
724   DECLARE_ETD(_tc, _e, 5);                                              \
725   ed->data[0] = _tc->cwnd;                                              \
726   ed->data[1] = tcp_flight_size (_tc);                                  \
727   ed->data[2] = tcp_snd_space (_tc);                                    \
728   ed->data[3] = _tc->ssthresh;                                          \
729   ed->data[4] = _tc->snd_wnd;                                           \
730   TCP_EVT_CC_RTO_STAT_HANDLER (_tc);                                    \
731   _tc->c_cc_stat_tstamp = tcp_time_now();                               \
732 }                                                                       \
733 }
734
735 #else
736 #define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
737 #endif
738
739 #else
740 #define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...)
741 #define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...)
742 #define TCP_EVT_CC_PACK_HANDLER(_tc, ...)
743 #define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
744 #endif
745
746 #endif /* SRC_VNET_TCP_TCP_DEBUG_H_ */
747 /*
748  * fd.io coding-style-patch-verification: ON
749  *
750  * Local Variables:
751  * eval: (c-set-style "gnu")
752  * End:
753  */