blob: fc36eb29afd71ce3f250ab7a11b115206342f074 [file] [log] [blame]
Florin Corase69f4952017-03-07 10:06:24 -08001/*
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)
Florin Coras68810622017-07-24 17:40:28 -070022#define TCP_DEBUG_SM (0)
23#define TCP_DEBUG_CC (1)
24#define TCP_DEBUG_CC_STAT (1)
Florin Corase69f4952017-03-07 10:06:24 -080025
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") \
Florin Coras6534b7a2017-07-18 05:38:03 -040035 _(SYNACK_SENT, "SYNACK sent") \
36 _(SYNACK_RCVD, "SYNACK rcvd") \
37 _(SYN_RXT, "SYN retransmit") \
Florin Corase69f4952017-03-07 10:06:24 -080038 _(FIN_SENT, "FIN sent") \
Florin Coras6792ec02017-03-13 03:49:51 -070039 _(ACK_SENT, "ACK sent") \
40 _(DUPACK_SENT, "DUPACK sent") \
Florin Corase69f4952017-03-07 10:06:24 -080041 _(RST_SENT, "RST sent") \
42 _(SYN_RCVD, "SYN rcvd") \
43 _(ACK_RCVD, "ACK rcvd") \
Florin Coras6792ec02017-03-13 03:49:51 -070044 _(DUPACK_RCVD, "DUPACK rcvd") \
Florin Corase69f4952017-03-07 10:06:24 -080045 _(FIN_RCVD, "FIN rcvd") \
46 _(RST_RCVD, "RST rcvd") \
Florin Coras6534b7a2017-07-18 05:38:03 -040047 _(STATE_CHANGE, "state change") \
Florin Corase69f4952017-03-07 10:06:24 -080048 _(PKTIZE, "packetize") \
49 _(INPUT, "in") \
Florin Coras6792ec02017-03-13 03:49:51 -070050 _(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") \
Florin Corasf03a59a2017-06-09 21:07:32 -070056 _(CC_STAT, "cc stats") \
57 _(CC_RTO_STAT, "cc rto stats") \
Florin Coras6792ec02017-03-13 03:49:51 -070058 _(SEG_INVALID, "invalid segment") \
Florin Corasc28764f2017-04-26 00:08:42 -070059 _(PAWS_FAIL, "failed paws check") \
Florin Coras6792ec02017-03-13 03:49:51 -070060 _(ACK_RCV_ERR, "invalid ack") \
Florin Coras3e350af2017-03-30 02:54:28 -070061 _(RCV_WND_SHRUNK, "shrunk rcv_wnd") \
Florin Corase69f4952017-03-07 10:06:24 -080062
63typedef enum _tcp_dbg
64{
65#define _(sym, str) TCP_DBG_##sym,
66 foreach_tcp_dbg_evt
67#undef _
68} tcp_dbg_e;
69
70typedef 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
Florin Corasf03a59a2017-06-09 21:07:32 -070081/*
82 * Infra and evt track setup
83 */
84
Florin Corase69f4952017-03-07 10:06:24 -080085#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
Florin Coras6534b7a2017-07-18 05:38:03 -0400101#define TCP_DBG_IP_TAG_LCL(_tc) \
Florin Corase69f4952017-03-07 10:06:24 -0800102{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400103 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); \
Florin Corase69f4952017-03-07 10:06:24 -0800156 elog_track_register (&vlib_global_main.elog_main, &_tc->c_elog_track);\
Florin Coras6534b7a2017-07-18 05:38:03 -0400157 TCP_DBG_IP_TAG_LCL(_tc); \
158 TCP_DBG_IP_TAG_RMT(_tc); \
Florin Corase69f4952017-03-07 10:06:24 -0800159}
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{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400168 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800169 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{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400191 TCP_EVT_INIT_HANDLER(_tc, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800192 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
Florin Coras68810622017-07-24 17:40:28 -0700200#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
Florin Corase69f4952017-03-07 10:06:24 -0800213#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 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700232 DECLARE_ETD(_tc, _e, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800233 ed->data[0] = _tc->c_c_index; \
234 TCP_EVT_DEALLOC_HANDLER(_tc); \
235}
236
Florin Corasf03a59a2017-06-09 21:07:32 -0700237#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
Florin Coras6534b7a2017-07-18 05:38:03 -0400249#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
Florin Coras6534b7a2017-07-18 05:38:03 -0400274#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
Florin Coras6792ec02017-03-13 03:49:51 -0700391#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...) \
392{ \
393 ELOG_TYPE_DECLARE (_e) = \
394 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400395 .format = "ack-tx: acked %u rcv_nxt %u rcv_wnd %u snd_nxt %u snd_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700396 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700397 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700398 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700399 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; \
Florin Coras3e350af2017-03-30 02:54:28 -0700403 ed->data[4] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700404}
405
406#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...) \
407{ \
408 ELOG_TYPE_DECLARE (_e) = \
409 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400410 .format = "dack-tx: rcv_nxt %u rcv_wnd %u snd_nxt %u av_wnd %u snd_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700411 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700412 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700413 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700414 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); \
Florin Coras3e350af2017-03-30 02:54:28 -0700418 ed->data[4] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700419}
420
Florin Coras3e350af2017-03-30 02:54:28 -0700421#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800422{ \
423 ELOG_TYPE_DECLARE (_e) = \
424 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700425 .format = "acked: %u snd_una %u snd_wnd %u cwnd %u inflight %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700426 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800427 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700428 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800429 ed->data[0] = _tc->bytes_acked; \
Florin Coras6792ec02017-03-13 03:49:51 -0700430 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700431 ed->data[2] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700432 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 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400440 .format = "dack-rx: snd_una %u cwnd %u snd_wnd %u flight %u rcv_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700441 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700442 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700443 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700444 ed->data[0] = _tc->snd_una - _tc->iss; \
Florin Corase69f4952017-03-07 10:06:24 -0800445 ed->data[1] = _tc->cwnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700446 ed->data[2] = _tc->snd_wnd; \
447 ed->data[3] = tcp_flight_size(_tc); \
Florin Coras3e350af2017-03-30 02:54:28 -0700448 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800449}
450
451#define TCP_EVT_PKTIZE_HANDLER(_tc, ...) \
452{ \
453 ELOG_TYPE_DECLARE (_e) = \
454 { \
Florin Coras6792ec02017-03-13 03:49:51 -0700455 .format = "pktize: una %u snd_nxt %u space %u flight %u rcv_wnd %u",\
456 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800457 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700458 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800459 ed->data[0] = _tc->snd_una - _tc->iss; \
460 ed->data[1] = _tc->snd_nxt - _tc->iss; \
Florin Coras6792ec02017-03-13 03:49:51 -0700461 ed->data[2] = tcp_available_snd_space (_tc); \
462 ed->data[3] = tcp_flight_size (_tc); \
463 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800464}
465
Florin Coras6792ec02017-03-13 03:49:51 -0700466#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800467{ \
468 ELOG_TYPE_DECLARE (_e) = \
469 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700470 .format = "in: %s len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
Florin Coras6792ec02017-03-13 03:49:51 -0700471 .format_args = "t4i4i4i4i4", \
472 .n_enum_strings = 2, \
473 .enum_strings = { \
474 "order", \
475 "ooo", \
476 }, \
Florin Corase69f4952017-03-07 10:06:24 -0800477 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700478 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); \
Florin Corase69f4952017-03-07 10:06:24 -0800484}
485
486#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...) \
487{ \
488 tcp_connection_t *_tc; \
flyingeagle23e8146b02017-04-26 20:06:52 +0800489 if (_timer_id == TCP_TIMER_RETRANSMIT_SYN \
490 || _timer_id == TCP_TIMER_ESTABLISH) \
Florin Corase69f4952017-03-07 10:06:24 -0800491 { \
492 _tc = tcp_half_open_connection_get (_tc_index); \
493 } \
494 else \
495 { \
Damjan Marion586afd72017-04-05 19:18:20 +0200496 u32 _thread_index = vlib_get_thread_index (); \
Florin Corase69f4952017-03-07 10:06:24 -0800497 _tc = tcp_connection_get (_tc_index, _thread_index); \
498 } \
499 ELOG_TYPE_DECLARE (_e) = \
500 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400501 .format = "timer-pop: %s (%d)", \
Florin Corase69f4952017-03-07 10:06:24 -0800502 .format_args = "t4i4", \
503 .n_enum_strings = 7, \
504 .enum_strings = { \
505 "retransmit", \
506 "delack", \
Florin Coras3e350af2017-03-30 02:54:28 -0700507 "persist", \
Florin Corase69f4952017-03-07 10:06:24 -0800508 "keep", \
509 "waitclose", \
510 "retransmit syn", \
511 "establish", \
512 }, \
513 }; \
Dave Barach2c25a622017-06-26 11:35:07 -0400514 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 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400522 clib_warning ("pop %d for unexisting connection %d", _timer_id, \
523 _tc_index); \
Dave Barach2c25a622017-06-26 11:35:07 -0400524 } \
Florin Corase69f4952017-03-07 10:06:24 -0800525}
526
Florin Coras6792ec02017-03-13 03:49:51 -0700527#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...) \
528{ \
529 ELOG_TYPE_DECLARE (_e) = \
530 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700531 .format = "seg-inv: seq %u end %u rcv_las %u rcv_nxt %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700532 .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
Florin Corasc28764f2017-04-26 00:08:42 -0700542#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...) \
543{ \
544 ELOG_TYPE_DECLARE (_e) = \
545 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400546 .format = "paws-err: seq %u end %u tsval %u tsval_recent %u", \
Florin Corasc28764f2017-04-26 00:08:42 -0700547 .format_args = "i4i4i4i4", \
548 }; \
549 DECLARE_ETD(_tc, _e, 4); \
550 ed->data[0] = _seq - _tc->irs; \
551 ed->data[1] = _end - _tc->irs; \
Florin Coras93992a92017-05-24 18:03:56 -0700552 ed->data[2] = _tc->rcv_opts.tsval; \
Florin Corasc28764f2017-04-26 00:08:42 -0700553 ed->data[3] = _tc->tsval_recent; \
554}
555
Florin Coras6792ec02017-03-13 03:49:51 -0700556#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
Florin Corasf03a59a2017-06-09 21:07:32 -0700577#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...) \
578{ \
579if (_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, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700597#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 */
Florin Coras6534b7a2017-07-18 05:38:03 -0400611#if TCP_DEBUG_SM > 2
Florin Corasf03a59a2017-06-09 21:07:32 -0700612#define TCP_EVT_SND_WND_HANDLER(_tc, ...) \
613{ \
614 ELOG_TYPE_DECLARE (_e) = \
615 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400616 .format = "snd-wnd update: %u ", \
Florin Corasf03a59a2017-06-09 21:07:32 -0700617 .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
Florin Coras6792ec02017-03-13 03:49:51 -0700639/*
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 { \
Florin Coras93992a92017-05-24 18:03:56 -0700648 .format = "rxt: snd_nxt %u offset %u snd %u rxt %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700649 .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; \
Florin Coras93992a92017-05-24 18:03:56 -0700655 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Coras6792ec02017-03-13 03:49:51 -0700656}
657
658#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
659{ \
660 ELOG_TYPE_DECLARE (_e) = \
661 { \
Florin Coras93992a92017-05-24 18:03:56 -0700662 .format = "cc: %s wnd %u snd_cong %u rxt_bytes %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700663 .format_args = "t4i4i4i4", \
664 .n_enum_strings = 5, \
665 .enum_strings = { \
Florin Coras93992a92017-05-24 18:03:56 -0700666 "fast-rxt", \
667 "rxt-timeout", \
668 "first-rxt", \
Florin Coras6792ec02017-03-13 03:49:51 -0700669 "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; \
Florin Coras93992a92017-05-24 18:03:56 -0700677 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Coras6792ec02017-03-13 03:49:51 -0700678}
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
Florin Corasf03a59a2017-06-09 21:07:32 -0700692/*
693 * Congestion control stats
694 */
695#if TCP_DEBUG_CC_STAT
Florin Coras6792ec02017-03-13 03:49:51 -0700696
Florin Corasf03a59a2017-06-09 21:07:32 -0700697#define STATS_INTERVAL 1
698
699#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \
Florin Coras3e350af2017-03-30 02:54:28 -0700700{ \
Florin Corasf03a59a2017-06-09 21:07:32 -0700701if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras3e350af2017-03-30 02:54:28 -0700702{ \
703 ELOG_TYPE_DECLARE (_e) = \
704 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700705 .format = "rto_stat: rto %u srtt %u rttvar %u ", \
706 .format_args = "i4i4i4", \
Florin Coras3e350af2017-03-30 02:54:28 -0700707 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700708 DECLARE_ETD(_tc, _e, 3); \
709 ed->data[0] = _tc->rto; \
710 ed->data[1] = _tc->srtt; \
711 ed->data[2] = _tc->rttvar; \
Florin Coras3e350af2017-03-30 02:54:28 -0700712} \
713}
714
Florin Corasf03a59a2017-06-09 21:07:32 -0700715#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \
716{ \
717if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras6792ec02017-03-13 03:49:51 -0700718{ \
719 ELOG_TYPE_DECLARE (_e) = \
720 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700721 .format = "cc_stat: cwnd %u flight %u space %u ssthresh %u snd_wnd %u",\
722 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700723 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700724 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} \
Florin Coras6792ec02017-03-13 03:49:51 -0700733}
734
Florin Coras6792ec02017-03-13 03:49:51 -0700735#else
Florin Corasf03a59a2017-06-09 21:07:32 -0700736#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Coras6792ec02017-03-13 03:49:51 -0700737#endif
738
Florin Corase69f4952017-03-07 10:06:24 -0800739#else
Florin Corasf03a59a2017-06-09 21:07:32 -0700740#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, ...)
Florin Coras6534b7a2017-07-18 05:38:03 -0400743#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Corase69f4952017-03-07 10:06:24 -0800744#endif
745
Florin Corase69f4952017-03-07 10:06:24 -0800746#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 */