blob: 23ad39187c22714bbd51a81a3ade4d2762530cc8 [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 Coras2f8d8fa2018-01-26 06:36:04 -080022#define TCP_DEBUG_SM (0)
Florin Corase5c57d72019-03-19 19:36:07 -070023#define TCP_DEBUG_CC (0)
24#define TCP_DEBUG_CC_STAT (0)
Florin Corasf988e692017-11-27 04:34:14 -050025#define TCP_DEBUG_BUFFER_ALLOCATION (0)
Florin Corase69f4952017-03-07 10:06:24 -080026
27#define foreach_tcp_dbg_evt \
28 _(INIT, "") \
29 _(DEALLOC, "") \
30 _(OPEN, "open") \
31 _(CLOSE, "close") \
32 _(BIND, "bind") \
33 _(UNBIND, "unbind") \
34 _(DELETE, "delete") \
35 _(SYN_SENT, "SYN sent") \
Florin Coras6534b7a2017-07-18 05:38:03 -040036 _(SYNACK_SENT, "SYNACK sent") \
37 _(SYNACK_RCVD, "SYNACK rcvd") \
38 _(SYN_RXT, "SYN retransmit") \
Florin Corase69f4952017-03-07 10:06:24 -080039 _(FIN_SENT, "FIN sent") \
Florin Coras6792ec02017-03-13 03:49:51 -070040 _(ACK_SENT, "ACK sent") \
41 _(DUPACK_SENT, "DUPACK sent") \
Florin Corase69f4952017-03-07 10:06:24 -080042 _(RST_SENT, "RST sent") \
43 _(SYN_RCVD, "SYN rcvd") \
44 _(ACK_RCVD, "ACK rcvd") \
Florin Coras6792ec02017-03-13 03:49:51 -070045 _(DUPACK_RCVD, "DUPACK rcvd") \
Florin Corase69f4952017-03-07 10:06:24 -080046 _(FIN_RCVD, "FIN rcvd") \
47 _(RST_RCVD, "RST rcvd") \
Florin Coras6534b7a2017-07-18 05:38:03 -040048 _(STATE_CHANGE, "state change") \
Florin Corase69f4952017-03-07 10:06:24 -080049 _(PKTIZE, "packetize") \
50 _(INPUT, "in") \
Florin Coras6792ec02017-03-13 03:49:51 -070051 _(SND_WND, "snd_wnd update") \
52 _(OUTPUT, "output") \
53 _(TIMER_POP, "timer pop") \
54 _(CC_RTX, "retransmit") \
55 _(CC_EVT, "cc event") \
56 _(CC_PACK, "cc partial ack") \
Florin Corasf03a59a2017-06-09 21:07:32 -070057 _(CC_STAT, "cc stats") \
58 _(CC_RTO_STAT, "cc rto stats") \
Florin Corasca1c8f32018-05-23 21:01:30 -070059 _(CC_SCOREBOARD, "scoreboard stats") \
60 _(CC_SACKS, "snd sacks stats") \
61 _(CC_INPUT, "ooo data delivered") \
Florin Coras6792ec02017-03-13 03:49:51 -070062 _(SEG_INVALID, "invalid segment") \
Florin Corasc28764f2017-04-26 00:08:42 -070063 _(PAWS_FAIL, "failed paws check") \
Florin Coras6792ec02017-03-13 03:49:51 -070064 _(ACK_RCV_ERR, "invalid ack") \
Florin Coras3e350af2017-03-30 02:54:28 -070065 _(RCV_WND_SHRUNK, "shrunk rcv_wnd") \
Florin Corase69f4952017-03-07 10:06:24 -080066
67typedef enum _tcp_dbg
68{
69#define _(sym, str) TCP_DBG_##sym,
70 foreach_tcp_dbg_evt
71#undef _
72} tcp_dbg_e;
73
74typedef enum _tcp_dbg_evt
75{
76#define _(sym, str) TCP_EVT_##sym,
77 foreach_tcp_dbg_evt
78#undef _
79} tcp_dbg_evt_e;
80
81#if TCP_DEBUG
82
83#define TRANSPORT_DEBUG (1)
84
Florin Corasf03a59a2017-06-09 21:07:32 -070085/*
86 * Infra and evt track setup
87 */
88
Florin Coras9d063042017-09-14 03:08:00 -040089#define TCP_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
Florin Corase69f4952017-03-07 10:06:24 -080090
91#define DECLARE_ETD(_tc, _e, _size) \
92 struct \
93 { \
94 u32 data[_size]; \
95 } * ed; \
96 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
97 _e, _tc->c_elog_track)
98
Florin Coras6534b7a2017-07-18 05:38:03 -040099#define TCP_DBG_IP_TAG_LCL(_tc) \
Florin Corase69f4952017-03-07 10:06:24 -0800100{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400101 if (_tc->c_is_ip4) \
102 { \
103 ELOG_TYPE_DECLARE (_e) = \
104 { \
105 .format = "lcl: %d.%d.%d.%d:%d", \
106 .format_args = "i4i4i4i4i4", \
107 }; \
108 DECLARE_ETD(_tc, _e, 5); \
109 ed->data[0] = _tc->c_lcl_ip.ip4.as_u8[0]; \
110 ed->data[1] = _tc->c_lcl_ip.ip4.as_u8[1]; \
111 ed->data[2] = _tc->c_lcl_ip.ip4.as_u8[2]; \
112 ed->data[3] = _tc->c_lcl_ip.ip4.as_u8[3]; \
113 ed->data[4] = clib_net_to_host_u16(_tc->c_lcl_port); \
114 } \
115}
116
117#define TCP_DBG_IP_TAG_RMT(_tc) \
118{ \
119 if (_tc->c_is_ip4) \
120 { \
121 ELOG_TYPE_DECLARE (_e) = \
122 { \
123 .format = "rmt: %d.%d.%d.%d:%d", \
124 .format_args = "i4i4i4i4i4", \
125 }; \
126 DECLARE_ETD(_tc, _e, 5); \
127 ed->data[0] = _tc->c_rmt_ip.ip4.as_u8[0]; \
128 ed->data[1] = _tc->c_rmt_ip.ip4.as_u8[1]; \
129 ed->data[2] = _tc->c_rmt_ip.ip4.as_u8[2]; \
130 ed->data[3] = _tc->c_rmt_ip.ip4.as_u8[3]; \
131 ed->data[4] = clib_net_to_host_u16(_tc->c_rmt_port); \
132 } \
133}
134
135#define TCP_EVT_INIT_HANDLER(_tc, _is_l, ...) \
136{ \
137 char *_fmt = _is_l ? "l[%d].%d:%d%c" : "[%d].%d:%d->.%d:%d%c"; \
138 if (_tc->c_is_ip4) \
139 { \
140 _tc->c_elog_track.name = \
141 (char *) format (0, _fmt, _tc->c_thread_index, \
142 _tc->c_lcl_ip.ip4.as_u8[3], \
143 clib_net_to_host_u16(_tc->c_lcl_port), \
144 _tc->c_rmt_ip.ip4.as_u8[3], \
145 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
146 } \
147 else \
148 _tc->c_elog_track.name = \
149 (char *) format (0, _fmt, _tc->c_thread_index, \
150 _tc->c_lcl_ip.ip6.as_u8[15], \
151 clib_net_to_host_u16(_tc->c_lcl_port), \
152 _tc->c_rmt_ip.ip6.as_u8[15], \
153 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800154 elog_track_register (&vlib_global_main.elog_main, &_tc->c_elog_track);\
Florin Coras6534b7a2017-07-18 05:38:03 -0400155 TCP_DBG_IP_TAG_LCL(_tc); \
156 TCP_DBG_IP_TAG_RMT(_tc); \
Florin Corase69f4952017-03-07 10:06:24 -0800157}
158
159#define TCP_EVT_DEALLOC_HANDLER(_tc, ...) \
160{ \
161 vec_free (_tc->c_elog_track.name); \
162}
163
164#define TCP_EVT_OPEN_HANDLER(_tc, ...) \
165{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400166 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800167 ELOG_TYPE_DECLARE (_e) = \
168 { \
169 .format = "open: index %d", \
170 .format_args = "i4", \
171 }; \
172 DECLARE_ETD(_tc, _e, 1); \
173 ed->data[0] = _tc->c_c_index; \
174}
175
176#define TCP_EVT_CLOSE_HANDLER(_tc, ...) \
177{ \
178 ELOG_TYPE_DECLARE (_e) = \
179 { \
180 .format = "close: %d", \
181 .format_args = "i4", \
182 }; \
183 DECLARE_ETD(_tc, _e, 1); \
184 ed->data[0] = _tc->c_c_index; \
185}
186
187#define TCP_EVT_BIND_HANDLER(_tc, ...) \
188{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400189 TCP_EVT_INIT_HANDLER(_tc, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800190 ELOG_TYPE_DECLARE (_e) = \
191 { \
192 .format = "bind: listener %d", \
193 }; \
194 DECLARE_ETD(_tc, _e, 1); \
195 ed->data[0] = _tc->c_c_index; \
196}
197
Florin Corasca1c8f32018-05-23 21:01:30 -0700198#define TCP_EVT_SYN_RCVD_HANDLER(_tc,_init, ...) \
Florin Coras68810622017-07-24 17:40:28 -0700199{ \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400200 if (_init) \
201 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Coras68810622017-07-24 17:40:28 -0700202 ELOG_TYPE_DECLARE (_e) = \
203 { \
Florin Coras070fd4b2019-04-02 19:03:23 -0700204 .format = "syn-rx: idx %u irs %u", \
205 .format_args = "i4i4", \
Florin Coras68810622017-07-24 17:40:28 -0700206 }; \
Florin Coras070fd4b2019-04-02 19:03:23 -0700207 DECLARE_ETD(_tc, _e, 2); \
208 ed->data[0] = _tc->c_c_index; \
209 ed->data[1] = _tc->irs; \
Florin Coras68810622017-07-24 17:40:28 -0700210 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...)
Florin Coras9d063042017-09-14 03:08:00 -0400242#define TCP_DBG(_fmt, _args...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700243#endif
244
245/*
246 * State machine
247 */
248#if TCP_DEBUG_SM
249
Florin Coras6534b7a2017-07-18 05:38:03 -0400250#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...) \
251{ \
252 ELOG_TYPE_DECLARE (_e) = \
253 { \
254 .format = "state: %s", \
255 .format_args = "t4", \
256 .n_enum_strings = 11, \
257 .enum_strings = { \
258 "closed", \
259 "listen", \
260 "syn-sent", \
261 "syn-rcvd", \
262 "established", \
263 "close_wait", \
264 "fin-wait-1", \
265 "last-ack", \
266 "closing", \
267 "fin-wait-2", \
268 "time-wait", \
269 }, \
270 }; \
271 DECLARE_ETD(_tc, _e, 1); \
272 ed->data[0] = _tc->state; \
273}
274
Florin Coras6534b7a2017-07-18 05:38:03 -0400275#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...) \
276{ \
277 ELOG_TYPE_DECLARE (_e) = \
278 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400279 .format = "syn-tx: iss %u snd_una %u snd_una_max %u snd_nxt %u", \
280 .format_args = "i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400281 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400282 DECLARE_ETD(_tc, _e, 4); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400283 ed->data[0] = _tc->iss; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700284 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400285 ed->data[2] = _tc->snd_una_max - _tc->iss; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700286 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400287 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
288}
289
290#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...) \
291{ \
292 ELOG_TYPE_DECLARE (_e) = \
293 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400294 .format = "synack-tx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
Florin Corasca1c8f32018-05-23 21:01:30 -0700295 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400296 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400297 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400298 ed->data[0] = _tc->iss; \
299 ed->data[1] = _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700300 ed->data[2] = _tc->snd_una - _tc->iss; \
301 ed->data[3] = _tc->snd_nxt - _tc->iss; \
302 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400303}
304
305#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...) \
306{ \
307 ELOG_TYPE_DECLARE (_e) = \
308 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400309 .format = "synack-rx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
Florin Corasca1c8f32018-05-23 21:01:30 -0700310 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400311 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400312 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400313 ed->data[0] = _tc->iss; \
314 ed->data[1] = _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700315 ed->data[2] = _tc->snd_una - _tc->iss; \
316 ed->data[3] = _tc->snd_nxt - _tc->iss; \
317 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400318 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
319}
320
321#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...) \
322{ \
323 ELOG_TYPE_DECLARE (_e) = \
324 { \
325 .format = "fin-tx: snd_nxt %d rcv_nxt %d", \
326 .format_args = "i4i4", \
327 }; \
328 DECLARE_ETD(_tc, _e, 2); \
329 ed->data[0] = _tc->snd_nxt - _tc->iss; \
330 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
331}
332
333#define TCP_EVT_RST_SENT_HANDLER(_tc, ...) \
334{ \
Florin Corasfc804d92018-01-26 01:27:01 -0800335if (_tc) \
Florin Coras6534b7a2017-07-18 05:38:03 -0400336 { \
Florin Corasfc804d92018-01-26 01:27:01 -0800337 ELOG_TYPE_DECLARE (_e) = \
338 { \
339 .format = "rst-tx: snd_nxt %d rcv_nxt %d", \
340 .format_args = "i4i4", \
341 }; \
342 DECLARE_ETD(_tc, _e, 2); \
343 ed->data[0] = _tc->snd_nxt - _tc->iss; \
344 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
345 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
346 } \
Florin Coras6534b7a2017-07-18 05:38:03 -0400347}
348
349#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...) \
350{ \
351 ELOG_TYPE_DECLARE (_e) = \
352 { \
353 .format = "fin-rx: snd_nxt %d rcv_nxt %d", \
354 .format_args = "i4i4", \
355 }; \
356 DECLARE_ETD(_tc, _e, 2); \
357 ed->data[0] = _tc->snd_nxt - _tc->iss; \
358 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
359}
360
361#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...) \
362{ \
363 ELOG_TYPE_DECLARE (_e) = \
364 { \
365 .format = "rst-rx: snd_nxt %d rcv_nxt %d", \
366 .format_args = "i4i4", \
367 }; \
368 DECLARE_ETD(_tc, _e, 2); \
369 ed->data[0] = _tc->snd_nxt - _tc->iss; \
370 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
371}
372
373#define TCP_EVT_SYN_RXT_HANDLER(_tc, _type, ...) \
374{ \
375 ELOG_TYPE_DECLARE (_e) = \
376 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400377 .format = "%s-rxt: iss %u irs %u snd_nxt %u rcv_nxt %u", \
Florin Corasca1c8f32018-05-23 21:01:30 -0700378 .format_args = "t4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400379 .n_enum_strings = 2, \
380 .enum_strings = { \
381 "syn", \
382 "syn-ack", \
383 }, \
384 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400385 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400386 ed->data[0] = _type; \
387 ed->data[1] = _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400388 ed->data[2] = _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700389 ed->data[3] = _tc->snd_nxt - _tc->iss; \
390 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400391}
Florin Coras85a3ddd2018-12-24 16:54:34 -0800392
393#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...) \
394{ \
395 tcp_connection_t *_tc; \
396 if (_timer_id == TCP_TIMER_RETRANSMIT_SYN \
397 || _timer_id == TCP_TIMER_ESTABLISH_AO) \
398 { \
399 _tc = tcp_half_open_connection_get (_tc_index); \
400 } \
401 else \
402 { \
403 u32 _thread_index = vlib_get_thread_index (); \
404 _tc = tcp_connection_get (_tc_index, _thread_index); \
405 } \
406 ELOG_TYPE_DECLARE (_e) = \
407 { \
408 .format = "timer-pop: %s (%d)", \
409 .format_args = "t4i4", \
410 .n_enum_strings = 8, \
411 .enum_strings = { \
412 "retransmit", \
413 "delack", \
414 "persist", \
415 "keep", \
416 "waitclose", \
417 "retransmit syn", \
418 "establish", \
419 "establish-ao", \
420 }, \
421 }; \
422 if (_tc) \
423 { \
424 DECLARE_ETD(_tc, _e, 2); \
425 ed->data[0] = _timer_id; \
426 ed->data[1] = _timer_id; \
427 } \
428 else \
429 { \
430 clib_warning ("pop %d for unexisting connection %d", _timer_id, \
431 _tc_index); \
432 } \
433}
434
Florin Coras6534b7a2017-07-18 05:38:03 -0400435#else
436#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...)
437#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...)
438#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...)
439#define TCP_EVT_SYN_RXT_HANDLER(_tc, ...)
440#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...)
441#define TCP_EVT_RST_SENT_HANDLER(_tc, ...)
442#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...)
443#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...)
444#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...)
Florin Coras85a3ddd2018-12-24 16:54:34 -0800445#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)
Florin Coras6534b7a2017-07-18 05:38:03 -0400446#endif
447
448#if TCP_DEBUG_SM > 1
Florin Corasca1c8f32018-05-23 21:01:30 -0700449#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _btcp, ...) \
450{ \
451 ELOG_TYPE_DECLARE (_e) = \
452 { \
453 .format = "seg-inv: seq %u end %u rcv_las %u rcv_nxt %u rcv_wnd %u",\
454 .format_args = "i4i4i4i4i4", \
455 }; \
456 DECLARE_ETD(_tc, _e, 5); \
457 ed->data[0] = _btcp.seq_number - _tc->irs; \
458 ed->data[1] = _btcp.seq_end - _tc->irs; \
459 ed->data[2] = _tc->rcv_las - _tc->irs; \
460 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
461 ed->data[4] = _tc->rcv_wnd; \
462}
463
464#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...) \
465{ \
466 ELOG_TYPE_DECLARE (_e) = \
467 { \
468 .format = "paws-err: seq %u end %u tsval %u tsval_recent %u", \
469 .format_args = "i4i4i4i4", \
470 }; \
471 DECLARE_ETD(_tc, _e, 4); \
472 ed->data[0] = _seq - _tc->irs; \
473 ed->data[1] = _end - _tc->irs; \
474 ed->data[2] = _tc->rcv_opts.tsval; \
475 ed->data[3] = _tc->tsval_recent; \
476}
477
478#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...) \
479{ \
480 ELOG_TYPE_DECLARE (_e) = \
481 { \
482 .format = "ack-err: %s ack %u snd_una %u snd_nxt %u una_max %u", \
483 .format_args = "t4i4i4i4i4", \
484 .n_enum_strings = 3, \
485 .enum_strings = { \
486 "invalid", \
487 "old", \
488 "future", \
489 }, \
490 }; \
491 DECLARE_ETD(_tc, _e, 5); \
492 ed->data[0] = _type; \
493 ed->data[1] = _ack - _tc->iss; \
494 ed->data[2] = _tc->snd_una - _tc->iss; \
495 ed->data[3] = _tc->snd_nxt - _tc->iss; \
496 ed->data[4] = _tc->snd_una_max - _tc->iss; \
497}
498
499#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...) \
500{ \
501if (_av > 0) \
502{ \
503 ELOG_TYPE_DECLARE (_e) = \
504 { \
505 .format = "huh?: rcv_wnd %u obsd %u av %u rcv_nxt %u rcv_las %u", \
506 .format_args = "i4i4i4i4i4", \
507 }; \
508 DECLARE_ETD(_tc, _e, 5); \
509 ed->data[0] = _tc->rcv_wnd; \
510 ed->data[1] = _obs; \
511 ed->data[2] = _av; \
512 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
513 ed->data[4] = _tc->rcv_las - _tc->irs; \
514} \
515}
516#else
517#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _btcp, ...)
518#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...)
519#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...)
520#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...)
521#endif
522
523#if TCP_DEBUG_SM > 2
Florin Coras6534b7a2017-07-18 05:38:03 -0400524
Florin Coras6792ec02017-03-13 03:49:51 -0700525#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...) \
526{ \
527 ELOG_TYPE_DECLARE (_e) = \
528 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400529 .format = "ack-tx: acked %u rcv_nxt %u rcv_wnd %u snd_nxt %u snd_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700530 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700531 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700532 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700533 ed->data[0] = _tc->rcv_nxt - _tc->rcv_las; \
534 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
535 ed->data[2] = _tc->rcv_wnd; \
536 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700537 ed->data[4] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700538}
539
Florin Coras3e350af2017-03-30 02:54:28 -0700540#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800541{ \
542 ELOG_TYPE_DECLARE (_e) = \
543 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400544 .format = "ack-rx: %u snd_una %u snd_wnd %u cwnd %u inflight %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700545 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800546 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700547 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800548 ed->data[0] = _tc->bytes_acked; \
Florin Coras6792ec02017-03-13 03:49:51 -0700549 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700550 ed->data[2] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700551 ed->data[3] = _tc->cwnd; \
552 ed->data[4] = tcp_flight_size(_tc); \
553}
554
Florin Corase69f4952017-03-07 10:06:24 -0800555#define TCP_EVT_PKTIZE_HANDLER(_tc, ...) \
556{ \
557 ELOG_TYPE_DECLARE (_e) = \
558 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400559 .format = "tx: una %u snd_nxt %u space %u flight %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700560 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800561 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700562 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800563 ed->data[0] = _tc->snd_una - _tc->iss; \
564 ed->data[1] = _tc->snd_nxt - _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400565 ed->data[2] = tcp_available_output_snd_space (_tc); \
Florin Coras6792ec02017-03-13 03:49:51 -0700566 ed->data[3] = tcp_flight_size (_tc); \
567 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800568}
569
Florin Coras6792ec02017-03-13 03:49:51 -0700570#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800571{ \
572 ELOG_TYPE_DECLARE (_e) = \
573 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700574 .format = "in: %s len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
Florin Coras6792ec02017-03-13 03:49:51 -0700575 .format_args = "t4i4i4i4i4", \
576 .n_enum_strings = 2, \
577 .enum_strings = { \
578 "order", \
579 "ooo", \
580 }, \
Florin Corase69f4952017-03-07 10:06:24 -0800581 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700582 DECLARE_ETD(_tc, _e, 5); \
583 ed->data[0] = _type; \
584 ed->data[1] = _len; \
585 ed->data[2] = _written; \
586 ed->data[3] = (_tc->rcv_nxt - _tc->irs) + _written; \
587 ed->data[4] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las); \
Florin Corase69f4952017-03-07 10:06:24 -0800588}
589
Florin Corasf03a59a2017-06-09 21:07:32 -0700590#else
591#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700592#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700593#define TCP_EVT_PKTIZE_HANDLER(_tc, ...)
594#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700595#endif
596
597/*
598 * State machine verbose
599 */
Florin Corasca1c8f32018-05-23 21:01:30 -0700600#if TCP_DEBUG_SM > 3
Florin Corasf03a59a2017-06-09 21:07:32 -0700601#define TCP_EVT_SND_WND_HANDLER(_tc, ...) \
602{ \
603 ELOG_TYPE_DECLARE (_e) = \
604 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400605 .format = "snd-wnd update: %u ", \
Florin Corasf03a59a2017-06-09 21:07:32 -0700606 .format_args = "i4", \
607 }; \
608 DECLARE_ETD(_tc, _e, 1); \
609 ed->data[0] = _tc->snd_wnd; \
610}
611
612#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...) \
613{ \
614 ELOG_TYPE_DECLARE (_e) = \
615 { \
616 .format = "out: flags %x, bytes %u", \
617 .format_args = "i4i4", \
618 }; \
619 DECLARE_ETD(_tc, _e, 2); \
620 ed->data[0] = flags; \
621 ed->data[1] = n_bytes; \
622}
623#else
624#define TCP_EVT_SND_WND_HANDLER(_tc, ...)
625#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)
626#endif
627
Florin Coras6792ec02017-03-13 03:49:51 -0700628/*
629 * Congestion Control
630 */
631
632#if TCP_DEBUG_CC
Florin Corasf1762d62017-09-24 19:43:08 -0400633
Florin Corase55a6d72018-10-31 23:09:22 -0700634#define TCP_EVT_CC_EVT_PRINT(_tc, _sub_evt) \
Florin Corasf1762d62017-09-24 19:43:08 -0400635{ \
636 ELOG_TYPE_DECLARE (_e) = \
637 { \
Florin Corasca1c8f32018-05-23 21:01:30 -0700638 .format = "cc: %s snd_space %u snd_una %u out %u flight %u", \
639 .format_args = "t4i4i4i4i4", \
640 .n_enum_strings = 7, \
Florin Corasf1762d62017-09-24 19:43:08 -0400641 .enum_strings = { \
642 "fast-rxt", \
Florin Corasf1762d62017-09-24 19:43:08 -0400643 "first-rxt", \
Florin Corase55a6d72018-10-31 23:09:22 -0700644 "rxt-timeout", \
Florin Corasf1762d62017-09-24 19:43:08 -0400645 "recovered", \
646 "congestion", \
647 "undo", \
Florin Corasca1c8f32018-05-23 21:01:30 -0700648 "recovery", \
Florin Corasf1762d62017-09-24 19:43:08 -0400649 }, \
650 }; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700651 DECLARE_ETD(_tc, _e, 5); \
Florin Corasf1762d62017-09-24 19:43:08 -0400652 ed->data[0] = _sub_evt; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700653 ed->data[1] = tcp_available_cc_snd_space (_tc); \
654 ed->data[2] = _tc->snd_una - _tc->iss; \
655 ed->data[3] = tcp_bytes_out(_tc); \
656 ed->data[4] = tcp_flight_size (_tc); \
Florin Corasf1762d62017-09-24 19:43:08 -0400657}
Florin Corase55a6d72018-10-31 23:09:22 -0700658
659#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
660{ \
661 if (_tc->snd_una != _tc->iss) \
662 TCP_EVT_CC_STAT_PRINT (_tc); \
663 if ((_sub_evt <= 1 && TCP_DEBUG_CC > 1) \
664 || (_sub_evt > 1 && TCP_DEBUG_CC > 0)) \
665 TCP_EVT_CC_EVT_PRINT (_tc, _sub_evt); \
666}
Florin Coras537b17e2018-09-28 10:35:45 -0700667#else
Florin Corase55a6d72018-10-31 23:09:22 -0700668#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
669
Florin Coras537b17e2018-09-28 10:35:45 -0700670#endif
Florin Corasf1762d62017-09-24 19:43:08 -0400671
Florin Coras537b17e2018-09-28 10:35:45 -0700672#if TCP_DEBUG_CC > 1
Florin Coras6792ec02017-03-13 03:49:51 -0700673#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...) \
674{ \
675 ELOG_TYPE_DECLARE (_e) = \
676 { \
Florin Coras93992a92017-05-24 18:03:56 -0700677 .format = "rxt: snd_nxt %u offset %u snd %u rxt %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700678 .format_args = "i4i4i4i4", \
679 }; \
680 DECLARE_ETD(_tc, _e, 4); \
681 ed->data[0] = _tc->snd_nxt - _tc->iss; \
682 ed->data[1] = offset; \
683 ed->data[2] = n_bytes; \
Florin Coras93992a92017-05-24 18:03:56 -0700684 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Coras6792ec02017-03-13 03:49:51 -0700685}
686
Florin Corasca1c8f32018-05-23 21:01:30 -0700687#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, _btcp, ...) \
Florin Coras6792ec02017-03-13 03:49:51 -0700688{ \
689 ELOG_TYPE_DECLARE (_e) = \
690 { \
Florin Corasca1c8f32018-05-23 21:01:30 -0700691 .format = "dack-tx: rcv_nxt %u seq %u rcv_wnd %u snd_nxt %u av_wnd %u",\
Florin Corasf1762d62017-09-24 19:43:08 -0400692 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700693 }; \
Florin Corasf1762d62017-09-24 19:43:08 -0400694 DECLARE_ETD(_tc, _e, 5); \
695 ed->data[0] = _tc->rcv_nxt - _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700696 ed->data[1] = _btcp.seq_number - _tc->irs; \
697 ed->data[2] = _tc->rcv_wnd; \
698 ed->data[3] = _tc->snd_nxt - _tc->iss; \
699 ed->data[4] = tcp_available_snd_wnd(_tc); \
Florin Corasf1762d62017-09-24 19:43:08 -0400700}
701
702#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...) \
703{ \
704 ELOG_TYPE_DECLARE (_e) = \
705 { \
706 .format = "dack-rx: snd_una %u cwnd %u snd_wnd %u flight %u rcv_wnd %u",\
707 .format_args = "i4i4i4i4i4", \
708 }; \
709 DECLARE_ETD(_tc, _e, 5); \
710 ed->data[0] = _tc->snd_una - _tc->iss; \
711 ed->data[1] = _tc->cwnd; \
712 ed->data[2] = _tc->snd_wnd; \
713 ed->data[3] = tcp_flight_size(_tc); \
714 ed->data[4] = _tc->rcv_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700715}
716
717#define TCP_EVT_CC_PACK_HANDLER(_tc, ...) \
718{ \
719 ELOG_TYPE_DECLARE (_e) = \
720 { \
721 .format = "pack: snd_una %u snd_una_max %u", \
722 .format_args = "i4i4", \
723 }; \
724 DECLARE_ETD(_tc, _e, 2); \
725 ed->data[0] = _tc->snd_una - _tc->iss; \
726 ed->data[1] = _tc->snd_una_max - _tc->iss; \
727}
Florin Corasca1c8f32018-05-23 21:01:30 -0700728#define TCP_EVT_CC_SCOREBOARD_HANDLER(_tc, ...) \
729{ \
730if (TCP_DEBUG_CC > 1 && _tc->sack_sb.last_sacked_bytes) \
731 { \
732 ELOG_TYPE_DECLARE (_e) = \
733 { \
734 .format = "sb1: holes %u lost %u sacked %u high %u highrxt %u", \
735 .format_args = "i4i4i4i4i4", \
736 }; \
737 DECLARE_ETD(_tc, _e, 5); \
738 ed->data[0] = pool_elts(_tc->sack_sb.holes); \
739 ed->data[1] = _tc->sack_sb.lost_bytes; \
740 ed->data[2] = _tc->sack_sb.sacked_bytes; \
741 ed->data[3] = _tc->sack_sb.high_sacked - _tc->iss; \
742 ed->data[4] = _tc->sack_sb.high_rxt - _tc->iss; \
743 } \
744if (TCP_DEBUG_CC > 1 && _tc->sack_sb.last_sacked_bytes) \
745 { \
746 sack_scoreboard_hole_t *hole; \
747 hole = scoreboard_first_hole (&_tc->sack_sb); \
748 ELOG_TYPE_DECLARE (_e) = \
749 { \
750 .format = "sb2: first start: %u end %u last start %u end %u", \
751 .format_args = "i4i4i4i4", \
752 }; \
753 DECLARE_ETD(_tc, _e, 4); \
754 ed->data[0] = hole ? hole->start - _tc->iss : 0; \
755 ed->data[1] = hole ? hole->end - _tc->iss : 0; \
756 hole = scoreboard_last_hole (&_tc->sack_sb); \
757 ed->data[2] = hole ? hole->start - _tc->iss : 0; \
758 ed->data[3] = hole ? hole->end - _tc->iss : 0; \
759 } \
760}
761#define TCP_EVT_CC_SACKS_HANDLER(_tc, ...) \
762{ \
763if (TCP_DEBUG_CC > 1) \
764 { \
765 ELOG_TYPE_DECLARE (_e) = \
766 { \
767 .format = "sacks: blocks %u bytes %u", \
768 .format_args = "i4i4", \
769 }; \
770 DECLARE_ETD(_tc, _e, 2); \
771 ed->data[0] = vec_len (_tc->snd_sacks); \
772 ed->data[1] = tcp_sack_list_bytes (_tc); \
773 } \
774}
775#define TCP_EVT_CC_INPUT_HANDLER(_tc, _len, _written, ...) \
776{ \
777 ELOG_TYPE_DECLARE (_e) = \
778 { \
779 .format = "cc input: len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
780 .format_args = "i4i4i4i4", \
781 }; \
782 DECLARE_ETD(_tc, _e, 4); \
783 ed->data[0] = _len; \
784 ed->data[1] = _written; \
785 ed->data[2] = _tc->rcv_nxt - _tc->irs; \
786 ed->data[3] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las); \
787}
Florin Corasf1762d62017-09-24 19:43:08 -0400788#else
789#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...)
Florin Corasca1c8f32018-05-23 21:01:30 -0700790#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, _btcp, ...)
Florin Corasf1762d62017-09-24 19:43:08 -0400791#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...)
792#define TCP_EVT_CC_PACK_HANDLER(_tc, ...)
Florin Corasca1c8f32018-05-23 21:01:30 -0700793#define TCP_EVT_CC_SCOREBOARD_HANDLER(_tc, ...)
794#define TCP_EVT_CC_SACKS_HANDLER(_tc, ...)
795#define TCP_EVT_CC_INPUT_HANDLER(_tc, _len, _written, ...)
Florin Corasf1762d62017-09-24 19:43:08 -0400796#endif
Florin Coras6792ec02017-03-13 03:49:51 -0700797
Florin Corasf03a59a2017-06-09 21:07:32 -0700798/*
799 * Congestion control stats
800 */
801#if TCP_DEBUG_CC_STAT
Florin Coras6792ec02017-03-13 03:49:51 -0700802
Florin Corasf03a59a2017-06-09 21:07:32 -0700803#define STATS_INTERVAL 1
804
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700805#define tcp_cc_time_to_print_stats(_tc) \
806 _tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now() \
807 || tcp_in_fastrecovery (_tc) \
808
809#define TCP_EVT_CC_RTO_STAT_PRINT(_tc) \
Florin Coras3e350af2017-03-30 02:54:28 -0700810{ \
811 ELOG_TYPE_DECLARE (_e) = \
812 { \
Florin Corasefefc6b2018-11-07 12:49:19 -0800813 .format = "rcv_stat: rto %u srtt %u mrtt-us %u rttvar %u", \
814 .format_args = "i4i4i4i4", \
Florin Coras3e350af2017-03-30 02:54:28 -0700815 }; \
Florin Corasefefc6b2018-11-07 12:49:19 -0800816 DECLARE_ETD(_tc, _e, 4); \
Florin Corasf03a59a2017-06-09 21:07:32 -0700817 ed->data[0] = _tc->rto; \
818 ed->data[1] = _tc->srtt; \
Florin Corasefefc6b2018-11-07 12:49:19 -0800819 ed->data[2] = (u32) (_tc->mrtt_us * 1e6); \
820 ed->data[3] = _tc->rttvar; \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700821}
822
823#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \
824{ \
825if (tcp_cc_time_to_print_stats (_tc)) \
826{ \
827 TCP_EVT_CC_RTO_STAT_PRINT (_tc); \
Florin Coras3c514d52018-12-22 11:39:33 -0800828 _tc->c_cc_stat_tstamp = tcp_time_now (); \
Florin Coras3e350af2017-03-30 02:54:28 -0700829} \
830}
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700831
832#define TCP_EVT_CC_SND_STAT_PRINT(_tc) \
Florin Coras62166002018-04-18 16:40:55 -0700833{ \
834 ELOG_TYPE_DECLARE (_e) = \
835 { \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700836 .format = "snd_stat: cc_space %u sacked %u lost %u out %u rxt %u", \
Florin Coras62166002018-04-18 16:40:55 -0700837 .format_args = "i4i4i4i4i4", \
838 }; \
839 DECLARE_ETD(_tc, _e, 5); \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700840 ed->data[0] = tcp_available_cc_snd_space (_tc); \
Florin Coras62166002018-04-18 16:40:55 -0700841 ed->data[1] = _tc->sack_sb.sacked_bytes; \
842 ed->data[2] = _tc->sack_sb.lost_bytes; \
843 ed->data[3] = tcp_bytes_out (_tc); \
844 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700845}
846
847#define TCP_EVT_CC_SND_STAT_HANDLER(_tc, ...) \
848{ \
849if (tcp_cc_time_to_print_stats (_tc)) \
850{ \
851 TCP_EVT_CC_SND_STAT_PRINT(_tc); \
Florin Coras3c514d52018-12-22 11:39:33 -0800852 _tc->c_cc_stat_tstamp = tcp_time_now (); \
Florin Coras62166002018-04-18 16:40:55 -0700853} \
854}
Florin Coras3e350af2017-03-30 02:54:28 -0700855
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700856#define TCP_EVT_CC_STAT_PRINT(_tc) \
Florin Coras6792ec02017-03-13 03:49:51 -0700857{ \
858 ELOG_TYPE_DECLARE (_e) = \
859 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700860 .format = "cc_stat: cwnd %u flight %u space %u ssthresh %u snd_wnd %u",\
861 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700862 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700863 DECLARE_ETD(_tc, _e, 5); \
864 ed->data[0] = _tc->cwnd; \
865 ed->data[1] = tcp_flight_size (_tc); \
866 ed->data[2] = tcp_snd_space (_tc); \
867 ed->data[3] = _tc->ssthresh; \
868 ed->data[4] = _tc->snd_wnd; \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700869 TCP_EVT_CC_RTO_STAT_PRINT (_tc); \
870 TCP_EVT_CC_SND_STAT_PRINT (_tc); \
871}
872
873#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \
874{ \
875if (tcp_cc_time_to_print_stats (_tc)) \
876{ \
877 TCP_EVT_CC_STAT_PRINT (_tc); \
Florin Corasf03a59a2017-06-09 21:07:32 -0700878 _tc->c_cc_stat_tstamp = tcp_time_now(); \
879} \
Florin Coras6792ec02017-03-13 03:49:51 -0700880}
Florin Corasc1a448b2018-04-20 10:51:49 -0700881#else
882#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Coras07025542019-01-19 16:45:13 -0800883#define TCP_EVT_CC_STAT_PRINT(_tc)
Florin Corasc1a448b2018-04-20 10:51:49 -0700884#endif
Florin Coras6792ec02017-03-13 03:49:51 -0700885
Florin Corasf988e692017-11-27 04:34:14 -0500886/*
887 * Buffer allocation
888 */
889#if TCP_DEBUG_BUFFER_ALLOCATION
890
891#define TCP_DBG_BUFFER_ALLOC_MAYBE_FAIL(thread_index) \
892{ \
893 static u32 *buffer_fail_counters; \
Florin Corasc1a448b2018-04-20 10:51:49 -0700894 if (PREDICT_FALSE (buffer_fail_counters == 0)) \
Florin Corasf988e692017-11-27 04:34:14 -0500895 { \
896 u32 num_threads; \
Florin Corasc1a448b2018-04-20 10:51:49 -0700897 vlib_thread_main_t *vtm = vlib_get_thread_main (); \
Florin Corasf988e692017-11-27 04:34:14 -0500898 num_threads = 1 /* main thread */ + vtm->n_threads; \
899 vec_validate (buffer_fail_counters, num_threads - 1); \
900 } \
901 if (PREDICT_FALSE (tcp_main.buffer_fail_fraction != 0.0)) \
902 { \
Florin Corasc1a448b2018-04-20 10:51:49 -0700903 if (PREDICT_TRUE (buffer_fail_counters[thread_index] > 0)) \
Florin Corasf988e692017-11-27 04:34:14 -0500904 { \
Florin Corasc1a448b2018-04-20 10:51:49 -0700905 if ((1.0 / (f32) (buffer_fail_counters[thread_index])) \
Florin Corasf988e692017-11-27 04:34:14 -0500906 < tcp_main.buffer_fail_fraction) \
907 { \
908 buffer_fail_counters[thread_index] = 0.0000001; \
Florin Corasc1a448b2018-04-20 10:51:49 -0700909 return -1; \
Florin Corasf988e692017-11-27 04:34:14 -0500910 } \
911 } \
912 buffer_fail_counters[thread_index] ++; \
913 } \
914}
915#else
916#define TCP_DBG_BUFFER_ALLOC_MAYBE_FAIL(thread_index)
917#endif
918
Florin Corase69f4952017-03-07 10:06:24 -0800919#endif /* SRC_VNET_TCP_TCP_DEBUG_H_ */
920/*
921 * fd.io coding-style-patch-verification: ON
922 *
923 * Local Variables:
924 * eval: (c-set-style "gnu")
925 * End:
926 */