blob: 04e921cd601aa7d95add2e1606799e1530f211bc [file] [log] [blame]
Florin Corase69f4952017-03-07 10:06:24 -08001/*
Florin Coras6416e622019-04-03 17:52:43 -07002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Florin Corase69f4952017-03-07 10:06:24 -08003 * 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>
Steven Luong23b33ec2022-10-07 13:53:20 -070020#include <vpp/vnet/config.h>
Florin Corase69f4952017-03-07 10:06:24 -080021
Florin Corasa436a422019-08-20 07:09:31 -070022/**
23 * Build debugging infra unconditionally. Debug components controlled via
24 * debug configuration. Comes with some overhead so it's not recommended for
25 * production/performance scenarios. Takes priority over TCP_DEBUG_ENABLE.
26 */
Steven Luong8d97a5c2022-10-06 16:48:24 -070027#ifdef VPP_TCP_DEBUG_ALWAYS
28#define TCP_DEBUG_ALWAYS (1)
29#else
Florin Corasa436a422019-08-20 07:09:31 -070030#define TCP_DEBUG_ALWAYS (0)
Steven Luong8d97a5c2022-10-06 16:48:24 -070031#endif
Florin Corasa436a422019-08-20 07:09:31 -070032/**
33 * Build debugging infra only if enabled. Debug components controlled via
34 * macros that follow.
35 */
36#define TCP_DEBUG_ENABLE (0)
37
Florin Coras2f8d8fa2018-01-26 06:36:04 -080038#define TCP_DEBUG_SM (0)
Florin Corase5c57d72019-03-19 19:36:07 -070039#define TCP_DEBUG_CC (0)
Florin Corasa436a422019-08-20 07:09:31 -070040#define TCP_DEBUG_CS (0)
41#define TCP_DEBUG_LC (0 || TCP_DEBUG_SM || TCP_DEBUG_CC || TCP_DEBUG_CS)
Florin Corase69f4952017-03-07 10:06:24 -080042
Florin Corasa436a422019-08-20 07:09:31 -070043#define TCP_DEBUG (TCP_DEBUG_ALWAYS || TCP_DEBUG_ENABLE)
44#define TCP_DEBUG_BUF_ALLOC (0)
Florin Corase69f4952017-03-07 10:06:24 -080045
Florin Corasa436a422019-08-20 07:09:31 -070046#if TCP_DEBUG > 0
Florin Corase69f4952017-03-07 10:06:24 -080047#define TRANSPORT_DEBUG (1)
Florin Corasa436a422019-08-20 07:09:31 -070048#endif
49
50#define TCP_CONCAT_HELPER(_a, _b) _a##_b
51#define TCP_CC(_a, _b) TCP_CONCAT_HELPER(_a, _b)
52
53#define tcp_evt_lvl(_evt) TCP_CC(_evt, _LVL)
54#define tcp_evt_grp(_evt) TCP_CC(_evt, _GRP)
55#define tcp_evt_handler(_evt, _args...) TCP_CC(_evt, _HANDLER) (_args)
56#define tcp_evt_grp_dbg_lvl(_evt) tcp_dbg_main.grp_dbg_lvl[tcp_evt_grp (_evt)]
57
58#define foreach_tcp_evt_grp \
59 _(LC, "life cycle") \
60 _(SM, "state machine") \
61 _(CC, "congestion control") \
62 _(CS, "cc stats") \
63
64typedef enum tcp_evt_grp_
65{
66#define _(sym, str) TCP_EVT_GRP_ ## sym,
67 foreach_tcp_evt_grp
68#undef _
69 TCP_EVT_N_GRP
70} tcp_evt_grp_e;
71
72typedef struct tcp_dbg_main_
73{
74 u8 grp_dbg_lvl[TCP_EVT_N_GRP];
75 u32 *free_track_indices;
76} tcp_dbg_main_t;
77
78extern tcp_dbg_main_t tcp_dbg_main;
79
80#define foreach_tcp_dbg_evt \
81 _(INIT, LC, 1, "init") \
82 _(DEALLOC, LC, 1, "dealloc") \
83 _(OPEN, LC, 1, "open") \
84 _(CLOSE, LC, 1, "close") \
85 _(BIND, LC, 1, "bind") \
86 _(UNBIND, LC, 1, "unbind") \
87 _(DELETE, LC, 1, "delete") \
88 _(SYN_RCVD, LC, 1, "SYN rcvd") \
89 _(STATE_CHANGE, LC, 1, "state change") \
90 _(SYN_SENT, SM, 1, "SYN sent") \
91 _(SYN_RXT, SM, 1, "SYN retransmit") \
92 _(SYNACK_SENT, SM, 1, "SYNACK sent") \
93 _(SYNACK_RCVD, SM, 1, "SYNACK rcvd") \
94 _(FIN_SENT, SM, 1, "FIN sent") \
95 _(FIN_RCVD, SM, 1, "FIN rcvd") \
96 _(RST_SENT, SM, 1, "RST sent") \
97 _(RST_RCVD, SM, 1, "RST rcvd") \
98 _(TIMER_POP, SM, 1, "timer pop") \
99 _(SEG_INVALID, SM, 2, "invalid segment") \
100 _(PAWS_FAIL, SM, 2, "failed paws check") \
101 _(ACK_RCV_ERR, SM, 2, "invalid ack") \
102 _(RCV_WND_SHRUNK, SM, 2, "shrunk rcv_wnd") \
103 _(ACK_SENT, SM, 3, "ACK sent") \
104 _(ACK_RCVD, SM, 3, "ACK rcvd") \
105 _(PKTIZE, SM, 3, "packetize") \
106 _(INPUT, SM, 3, "in") \
107 _(OUTPUT, SM, 4, "output") \
108 _(SND_WND, SM, 4, "snd_wnd update") \
109 _(CC_EVT, CC, 1, "cc event") \
110 _(CC_RTX, CC, 2, "retransmit") \
111 _(CC_PACK, CC, 2, "cc partial ack") \
112 _(DUPACK_SENT, CC, 2, "DUPACK sent") \
113 _(DUPACK_RCVD, CC, 2, "DUPACK rcvd") \
114 _(CC_SCOREBOARD, CC, 2, "scoreboard stats") \
115 _(CC_SACKS, CC, 2, "snd sacks stats") \
116 _(CC_INPUT, CC, 2, "ooo data delivered") \
117 _(CC_STAT, CS, 1, "cc stats") \
118 _(CC_RTO_STAT, CS, 1, "cc rto stats") \
119
120typedef enum tcp_evt_types_
121{
122#define _(sym, grp, lvl, str) TCP_EVT_##sym,
123 foreach_tcp_dbg_evt
124#undef _
125} tcp_evt_types_e;
126
127typedef enum tcp_evt_lvl_
128{
129#define _(sym, grp, lvl, str) TCP_EVT_## sym ## _LVL = lvl,
130 foreach_tcp_dbg_evt
131#undef _
132} tcp_evt_lvl_e;
133
134typedef enum tcp_evt_to_grp_
135{
136#define _(sym, grp, lvl, str) TCP_EVT_ ## sym ## _GRP = TCP_EVT_GRP_ ## grp,
137 foreach_tcp_dbg_evt
138#undef _
139} tcp_evt_to_grp_e;
140
141#if TCP_DEBUG_ALWAYS > 0
142#define TCP_EVT(_evt, _args...) \
143 if (PREDICT_FALSE (tcp_evt_grp_dbg_lvl (_evt) >= tcp_evt_lvl (_evt))) \
144 tcp_evt_handler (_evt, _args)
145#define TCP_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
146#elif TCP_DEBUG_ENABLE > 0
147#define TCP_EVT(_evt, _args...) tcp_evt_handler(_evt, _args)
148#define TCP_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
149#else
150#define TCP_EVT(_evt, _args...)
151#define TCP_DBG(_fmt, _args...)
152#endif
153
154void tcp_evt_track_register (elog_track_t * et);
155void tcp_debug_init (void);
156
157#define TCP_DECLARE_ETD(_tc, _e, _size) \
158struct \
159{ \
160 u32 data[_size]; \
161} * ed; \
162ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, _e, \
163 _tc->c_elog_track) \
164
165/*
166 * Event handlers definitions
167 */
168
169#if TCP_DEBUG_LC || TCP_DEBUG_ALWAYS
Florin Corase69f4952017-03-07 10:06:24 -0800170
Florin Corasf03a59a2017-06-09 21:07:32 -0700171/*
172 * Infra and evt track setup
173 */
174
Florin Coras6534b7a2017-07-18 05:38:03 -0400175#define TCP_DBG_IP_TAG_LCL(_tc) \
Florin Corase69f4952017-03-07 10:06:24 -0800176{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400177 if (_tc->c_is_ip4) \
178 { \
179 ELOG_TYPE_DECLARE (_e) = \
180 { \
181 .format = "lcl: %d.%d.%d.%d:%d", \
182 .format_args = "i4i4i4i4i4", \
183 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700184 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400185 ed->data[0] = _tc->c_lcl_ip.ip4.as_u8[0]; \
186 ed->data[1] = _tc->c_lcl_ip.ip4.as_u8[1]; \
187 ed->data[2] = _tc->c_lcl_ip.ip4.as_u8[2]; \
188 ed->data[3] = _tc->c_lcl_ip.ip4.as_u8[3]; \
189 ed->data[4] = clib_net_to_host_u16(_tc->c_lcl_port); \
190 } \
191}
192
193#define TCP_DBG_IP_TAG_RMT(_tc) \
194{ \
195 if (_tc->c_is_ip4) \
196 { \
197 ELOG_TYPE_DECLARE (_e) = \
198 { \
199 .format = "rmt: %d.%d.%d.%d:%d", \
200 .format_args = "i4i4i4i4i4", \
201 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700202 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400203 ed->data[0] = _tc->c_rmt_ip.ip4.as_u8[0]; \
204 ed->data[1] = _tc->c_rmt_ip.ip4.as_u8[1]; \
205 ed->data[2] = _tc->c_rmt_ip.ip4.as_u8[2]; \
206 ed->data[3] = _tc->c_rmt_ip.ip4.as_u8[3]; \
207 ed->data[4] = clib_net_to_host_u16(_tc->c_rmt_port); \
208 } \
209}
210
211#define TCP_EVT_INIT_HANDLER(_tc, _is_l, ...) \
212{ \
213 char *_fmt = _is_l ? "l[%d].%d:%d%c" : "[%d].%d:%d->.%d:%d%c"; \
214 if (_tc->c_is_ip4) \
215 { \
216 _tc->c_elog_track.name = \
217 (char *) format (0, _fmt, _tc->c_thread_index, \
218 _tc->c_lcl_ip.ip4.as_u8[3], \
219 clib_net_to_host_u16(_tc->c_lcl_port), \
220 _tc->c_rmt_ip.ip4.as_u8[3], \
221 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
222 } \
223 else \
224 _tc->c_elog_track.name = \
225 (char *) format (0, _fmt, _tc->c_thread_index, \
226 _tc->c_lcl_ip.ip6.as_u8[15], \
227 clib_net_to_host_u16(_tc->c_lcl_port), \
228 _tc->c_rmt_ip.ip6.as_u8[15], \
229 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
Florin Corasa436a422019-08-20 07:09:31 -0700230 tcp_evt_track_register (&_tc->c_elog_track); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400231 TCP_DBG_IP_TAG_LCL(_tc); \
232 TCP_DBG_IP_TAG_RMT(_tc); \
Florin Corase69f4952017-03-07 10:06:24 -0800233}
234
235#define TCP_EVT_DEALLOC_HANDLER(_tc, ...) \
236{ \
237 vec_free (_tc->c_elog_track.name); \
Florin Corasa436a422019-08-20 07:09:31 -0700238 vec_add1 (tcp_dbg_main.free_track_indices, \
239 _tc->c_elog_track.track_index_plus_one - 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800240}
241
242#define TCP_EVT_OPEN_HANDLER(_tc, ...) \
243{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400244 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800245 ELOG_TYPE_DECLARE (_e) = \
246 { \
247 .format = "open: index %d", \
248 .format_args = "i4", \
249 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700250 TCP_DECLARE_ETD(_tc, _e, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800251 ed->data[0] = _tc->c_c_index; \
252}
253
254#define TCP_EVT_CLOSE_HANDLER(_tc, ...) \
255{ \
256 ELOG_TYPE_DECLARE (_e) = \
257 { \
Florin Coras6416e622019-04-03 17:52:43 -0700258 .format = "close: cidx %d", \
Florin Corase69f4952017-03-07 10:06:24 -0800259 .format_args = "i4", \
260 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700261 TCP_DECLARE_ETD(_tc, _e, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800262 ed->data[0] = _tc->c_c_index; \
263}
264
265#define TCP_EVT_BIND_HANDLER(_tc, ...) \
266{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400267 TCP_EVT_INIT_HANDLER(_tc, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800268 ELOG_TYPE_DECLARE (_e) = \
269 { \
270 .format = "bind: listener %d", \
271 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700272 TCP_DECLARE_ETD(_tc, _e, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800273 ed->data[0] = _tc->c_c_index; \
274}
275
Florin Corasca1c8f32018-05-23 21:01:30 -0700276#define TCP_EVT_SYN_RCVD_HANDLER(_tc,_init, ...) \
Florin Coras68810622017-07-24 17:40:28 -0700277{ \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400278 if (_init) \
279 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Coras68810622017-07-24 17:40:28 -0700280 ELOG_TYPE_DECLARE (_e) = \
281 { \
Florin Coras6416e622019-04-03 17:52:43 -0700282 .format = "syn-rx: cidx %u sidx %u irs %u", \
283 .format_args = "i4i4i4", \
Florin Coras68810622017-07-24 17:40:28 -0700284 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700285 TCP_DECLARE_ETD(_tc, _e, 3); \
Florin Coras070fd4b2019-04-02 19:03:23 -0700286 ed->data[0] = _tc->c_c_index; \
Florin Coras6416e622019-04-03 17:52:43 -0700287 ed->data[1] = _tc->c_s_index; \
288 ed->data[2] = _tc->irs; \
Florin Coras68810622017-07-24 17:40:28 -0700289 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
290}
291
Florin Corase69f4952017-03-07 10:06:24 -0800292#define TCP_EVT_UNBIND_HANDLER(_tc, ...) \
293{ \
294 TCP_EVT_DEALLOC_HANDLER(_tc); \
295 ELOG_TYPE_DECLARE (_e) = \
296 { \
297 .format = "unbind: listener %d", \
298 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700299 TCP_DECLARE_ETD(_tc, _e, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800300 ed->data[0] = _tc->c_c_index; \
301 TCP_EVT_DEALLOC_HANDLER(_tc); \
302}
303
304#define TCP_EVT_DELETE_HANDLER(_tc, ...) \
305{ \
306 ELOG_TYPE_DECLARE (_e) = \
307 { \
Florin Coras6416e622019-04-03 17:52:43 -0700308 .format = "delete: cidx %d sidx %d", \
309 .format_args = "i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800310 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700311 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Corase69f4952017-03-07 10:06:24 -0800312 ed->data[0] = _tc->c_c_index; \
Florin Coras6416e622019-04-03 17:52:43 -0700313 ed->data[1] = _tc->c_s_index; \
Florin Corase69f4952017-03-07 10:06:24 -0800314 TCP_EVT_DEALLOC_HANDLER(_tc); \
315}
316
Florin Corasf03a59a2017-06-09 21:07:32 -0700317#endif
318
319/*
320 * State machine
321 */
Florin Corasa436a422019-08-20 07:09:31 -0700322#if TCP_DEBUG_SM > 0 || TCP_DEBUG_ALWAYS
Florin Corasf03a59a2017-06-09 21:07:32 -0700323
Florin Coras6534b7a2017-07-18 05:38:03 -0400324#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...) \
325{ \
326 ELOG_TYPE_DECLARE (_e) = \
327 { \
328 .format = "state: %s", \
329 .format_args = "t4", \
330 .n_enum_strings = 11, \
331 .enum_strings = { \
332 "closed", \
333 "listen", \
334 "syn-sent", \
335 "syn-rcvd", \
336 "established", \
337 "close_wait", \
338 "fin-wait-1", \
339 "last-ack", \
340 "closing", \
341 "fin-wait-2", \
342 "time-wait", \
343 }, \
344 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700345 TCP_DECLARE_ETD(_tc, _e, 1); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400346 ed->data[0] = _tc->state; \
347}
348
Florin Coras6534b7a2017-07-18 05:38:03 -0400349#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...) \
350{ \
351 ELOG_TYPE_DECLARE (_e) = \
352 { \
Florin Coras9404a072020-11-24 17:29:17 -0800353 .format = "syn-tx: iss %u snd_una %u snd_nxt %u", \
354 .format_args = "i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400355 }; \
Florin Coras9404a072020-11-24 17:29:17 -0800356 TCP_DECLARE_ETD(_tc, _e, 3); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400357 ed->data[0] = _tc->iss; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700358 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras9404a072020-11-24 17:29:17 -0800359 ed->data[2] = _tc->snd_nxt - _tc->iss; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400360 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
361}
362
363#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...) \
364{ \
365 ELOG_TYPE_DECLARE (_e) = \
366 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400367 .format = "synack-tx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
Florin Corasca1c8f32018-05-23 21:01:30 -0700368 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400369 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700370 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400371 ed->data[0] = _tc->iss; \
372 ed->data[1] = _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700373 ed->data[2] = _tc->snd_una - _tc->iss; \
374 ed->data[3] = _tc->snd_nxt - _tc->iss; \
375 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400376}
377
378#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...) \
379{ \
380 ELOG_TYPE_DECLARE (_e) = \
381 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400382 .format = "synack-rx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
Florin Corasca1c8f32018-05-23 21:01:30 -0700383 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400384 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700385 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400386 ed->data[0] = _tc->iss; \
387 ed->data[1] = _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700388 ed->data[2] = _tc->snd_una - _tc->iss; \
389 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 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
392}
393
394#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...) \
395{ \
396 ELOG_TYPE_DECLARE (_e) = \
397 { \
398 .format = "fin-tx: snd_nxt %d rcv_nxt %d", \
399 .format_args = "i4i4", \
400 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700401 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400402 ed->data[0] = _tc->snd_nxt - _tc->iss; \
403 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
404}
405
406#define TCP_EVT_RST_SENT_HANDLER(_tc, ...) \
407{ \
Florin Corasfc804d92018-01-26 01:27:01 -0800408if (_tc) \
Florin Coras6534b7a2017-07-18 05:38:03 -0400409 { \
Florin Corasfc804d92018-01-26 01:27:01 -0800410 ELOG_TYPE_DECLARE (_e) = \
411 { \
412 .format = "rst-tx: snd_nxt %d rcv_nxt %d", \
413 .format_args = "i4i4", \
414 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700415 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Corasfc804d92018-01-26 01:27:01 -0800416 ed->data[0] = _tc->snd_nxt - _tc->iss; \
417 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
418 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
419 } \
Florin Coras6534b7a2017-07-18 05:38:03 -0400420}
421
422#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...) \
423{ \
424 ELOG_TYPE_DECLARE (_e) = \
425 { \
426 .format = "fin-rx: snd_nxt %d rcv_nxt %d", \
427 .format_args = "i4i4", \
428 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700429 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400430 ed->data[0] = _tc->snd_nxt - _tc->iss; \
431 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
432}
433
434#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...) \
435{ \
436 ELOG_TYPE_DECLARE (_e) = \
437 { \
438 .format = "rst-rx: snd_nxt %d rcv_nxt %d", \
439 .format_args = "i4i4", \
440 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700441 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400442 ed->data[0] = _tc->snd_nxt - _tc->iss; \
443 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
444}
445
446#define TCP_EVT_SYN_RXT_HANDLER(_tc, _type, ...) \
447{ \
448 ELOG_TYPE_DECLARE (_e) = \
449 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400450 .format = "%s-rxt: iss %u irs %u snd_nxt %u rcv_nxt %u", \
Florin Corasca1c8f32018-05-23 21:01:30 -0700451 .format_args = "t4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400452 .n_enum_strings = 2, \
453 .enum_strings = { \
454 "syn", \
Florin Coras6416e622019-04-03 17:52:43 -0700455 "synack", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400456 }, \
457 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700458 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400459 ed->data[0] = _type; \
460 ed->data[1] = _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400461 ed->data[2] = _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700462 ed->data[3] = _tc->snd_nxt - _tc->iss; \
463 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400464}
Florin Coras85a3ddd2018-12-24 16:54:34 -0800465
466#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...) \
467{ \
468 tcp_connection_t *_tc; \
Florin Corasa436a422019-08-20 07:09:31 -0700469 if (_timer_id == TCP_TIMER_RETRANSMIT_SYN) \
Florin Coras85a3ddd2018-12-24 16:54:34 -0800470 { \
471 _tc = tcp_half_open_connection_get (_tc_index); \
472 } \
473 else \
474 { \
475 u32 _thread_index = vlib_get_thread_index (); \
476 _tc = tcp_connection_get (_tc_index, _thread_index); \
477 } \
478 ELOG_TYPE_DECLARE (_e) = \
479 { \
Florin Coras6416e622019-04-03 17:52:43 -0700480 .format = "timer-pop: %s cidx %u sidx %u", \
481 .format_args = "t4i4i4", \
Florin Coras85a3ddd2018-12-24 16:54:34 -0800482 .n_enum_strings = 8, \
483 .enum_strings = { \
484 "retransmit", \
485 "delack", \
486 "persist", \
487 "keep", \
488 "waitclose", \
489 "retransmit syn", \
490 "establish", \
491 "establish-ao", \
492 }, \
493 }; \
494 if (_tc) \
495 { \
Florin Corasa436a422019-08-20 07:09:31 -0700496 TCP_DECLARE_ETD(_tc, _e, 3); \
Florin Coras85a3ddd2018-12-24 16:54:34 -0800497 ed->data[0] = _timer_id; \
Florin Coras6416e622019-04-03 17:52:43 -0700498 ed->data[1] = _tc->c_c_index; \
499 ed->data[2] = _tc->c_s_index; \
Florin Coras85a3ddd2018-12-24 16:54:34 -0800500 } \
501 else \
502 { \
503 clib_warning ("pop %d for unexisting connection %d", _timer_id, \
504 _tc_index); \
505 } \
506}
507
Florin Coras6534b7a2017-07-18 05:38:03 -0400508#else
509#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...)
510#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...)
511#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...)
512#define TCP_EVT_SYN_RXT_HANDLER(_tc, ...)
513#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...)
514#define TCP_EVT_RST_SENT_HANDLER(_tc, ...)
515#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...)
516#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...)
517#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...)
Florin Coras85a3ddd2018-12-24 16:54:34 -0800518#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)
Florin Coras6534b7a2017-07-18 05:38:03 -0400519#endif
520
Florin Corasa436a422019-08-20 07:09:31 -0700521#if TCP_DEBUG_SM > 1 || TCP_DEBUG_ALWAYS
Florin Corasca1c8f32018-05-23 21:01:30 -0700522#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _btcp, ...) \
523{ \
524 ELOG_TYPE_DECLARE (_e) = \
525 { \
526 .format = "seg-inv: seq %u end %u rcv_las %u rcv_nxt %u rcv_wnd %u",\
527 .format_args = "i4i4i4i4i4", \
528 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700529 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700530 ed->data[0] = _btcp.seq_number - _tc->irs; \
531 ed->data[1] = _btcp.seq_end - _tc->irs; \
532 ed->data[2] = _tc->rcv_las - _tc->irs; \
533 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
534 ed->data[4] = _tc->rcv_wnd; \
535}
536
537#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...) \
538{ \
539 ELOG_TYPE_DECLARE (_e) = \
540 { \
541 .format = "paws-err: seq %u end %u tsval %u tsval_recent %u", \
542 .format_args = "i4i4i4i4", \
543 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700544 TCP_DECLARE_ETD(_tc, _e, 4); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700545 ed->data[0] = _seq - _tc->irs; \
546 ed->data[1] = _end - _tc->irs; \
547 ed->data[2] = _tc->rcv_opts.tsval; \
548 ed->data[3] = _tc->tsval_recent; \
549}
550
551#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...) \
552{ \
553 ELOG_TYPE_DECLARE (_e) = \
554 { \
Florin Coras9404a072020-11-24 17:29:17 -0800555 .format = "ack-err: %s ack %u snd_una %u snd_nxt %u", \
556 .format_args = "t4i4i4i4", \
Florin Corasca1c8f32018-05-23 21:01:30 -0700557 .n_enum_strings = 3, \
558 .enum_strings = { \
559 "invalid", \
560 "old", \
561 "future", \
562 }, \
563 }; \
Florin Coras9404a072020-11-24 17:29:17 -0800564 TCP_DECLARE_ETD(_tc, _e, 4); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700565 ed->data[0] = _type; \
566 ed->data[1] = _ack - _tc->iss; \
567 ed->data[2] = _tc->snd_una - _tc->iss; \
568 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700569}
570
571#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...) \
572{ \
573if (_av > 0) \
574{ \
575 ELOG_TYPE_DECLARE (_e) = \
576 { \
577 .format = "huh?: rcv_wnd %u obsd %u av %u rcv_nxt %u rcv_las %u", \
578 .format_args = "i4i4i4i4i4", \
579 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700580 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700581 ed->data[0] = _tc->rcv_wnd; \
582 ed->data[1] = _obs; \
583 ed->data[2] = _av; \
584 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
585 ed->data[4] = _tc->rcv_las - _tc->irs; \
586} \
587}
588#else
589#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _btcp, ...)
590#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...)
591#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...)
592#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...)
593#endif
594
Florin Corasa436a422019-08-20 07:09:31 -0700595#if TCP_DEBUG_SM > 2 || TCP_DEBUG_ALWAYS
Florin Coras6534b7a2017-07-18 05:38:03 -0400596
Florin Coras6792ec02017-03-13 03:49:51 -0700597#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...) \
598{ \
599 ELOG_TYPE_DECLARE (_e) = \
600 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400601 .format = "ack-tx: acked %u rcv_nxt %u rcv_wnd %u snd_nxt %u snd_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700602 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700603 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700604 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700605 ed->data[0] = _tc->rcv_nxt - _tc->rcv_las; \
606 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
607 ed->data[2] = _tc->rcv_wnd; \
608 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700609 ed->data[4] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700610}
611
Florin Coras3e350af2017-03-30 02:54:28 -0700612#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800613{ \
614 ELOG_TYPE_DECLARE (_e) = \
615 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400616 .format = "ack-rx: %u snd_una %u snd_wnd %u cwnd %u inflight %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700617 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800618 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700619 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800620 ed->data[0] = _tc->bytes_acked; \
Florin Coras6792ec02017-03-13 03:49:51 -0700621 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700622 ed->data[2] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700623 ed->data[3] = _tc->cwnd; \
624 ed->data[4] = tcp_flight_size(_tc); \
625}
626
Florin Corase69f4952017-03-07 10:06:24 -0800627#define TCP_EVT_PKTIZE_HANDLER(_tc, ...) \
628{ \
629 ELOG_TYPE_DECLARE (_e) = \
630 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400631 .format = "tx: una %u snd_nxt %u space %u flight %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700632 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800633 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700634 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800635 ed->data[0] = _tc->snd_una - _tc->iss; \
636 ed->data[1] = _tc->snd_nxt - _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400637 ed->data[2] = tcp_available_output_snd_space (_tc); \
Florin Coras6792ec02017-03-13 03:49:51 -0700638 ed->data[3] = tcp_flight_size (_tc); \
639 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800640}
641
Florin Coras6792ec02017-03-13 03:49:51 -0700642#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800643{ \
644 ELOG_TYPE_DECLARE (_e) = \
645 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700646 .format = "in: %s len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
Florin Coras6792ec02017-03-13 03:49:51 -0700647 .format_args = "t4i4i4i4i4", \
648 .n_enum_strings = 2, \
649 .enum_strings = { \
650 "order", \
651 "ooo", \
652 }, \
Florin Corase69f4952017-03-07 10:06:24 -0800653 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700654 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700655 ed->data[0] = _type; \
656 ed->data[1] = _len; \
657 ed->data[2] = _written; \
658 ed->data[3] = (_tc->rcv_nxt - _tc->irs) + _written; \
659 ed->data[4] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las); \
Florin Corase69f4952017-03-07 10:06:24 -0800660}
661
Florin Corasf03a59a2017-06-09 21:07:32 -0700662#else
663#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700664#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700665#define TCP_EVT_PKTIZE_HANDLER(_tc, ...)
666#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700667#endif
668
669/*
670 * State machine verbose
671 */
Florin Corasa436a422019-08-20 07:09:31 -0700672#if TCP_DEBUG_SM > 3 || TCP_DEBUG_ALWAYS
Florin Corasf03a59a2017-06-09 21:07:32 -0700673#define TCP_EVT_SND_WND_HANDLER(_tc, ...) \
674{ \
675 ELOG_TYPE_DECLARE (_e) = \
676 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400677 .format = "snd-wnd update: %u ", \
Florin Corasf03a59a2017-06-09 21:07:32 -0700678 .format_args = "i4", \
679 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700680 TCP_DECLARE_ETD(_tc, _e, 1); \
Florin Corasf03a59a2017-06-09 21:07:32 -0700681 ed->data[0] = _tc->snd_wnd; \
682}
683
684#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...) \
685{ \
686 ELOG_TYPE_DECLARE (_e) = \
687 { \
688 .format = "out: flags %x, bytes %u", \
689 .format_args = "i4i4", \
690 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700691 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Corasf03a59a2017-06-09 21:07:32 -0700692 ed->data[0] = flags; \
693 ed->data[1] = n_bytes; \
694}
695#else
696#define TCP_EVT_SND_WND_HANDLER(_tc, ...)
697#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)
698#endif
699
Florin Coras6792ec02017-03-13 03:49:51 -0700700/*
701 * Congestion Control
702 */
703
Florin Corasa436a422019-08-20 07:09:31 -0700704#if TCP_DEBUG_CC || TCP_DEBUG_ALWAYS
Florin Corasf1762d62017-09-24 19:43:08 -0400705
Florin Corase55a6d72018-10-31 23:09:22 -0700706#define TCP_EVT_CC_EVT_PRINT(_tc, _sub_evt) \
Florin Corasf1762d62017-09-24 19:43:08 -0400707{ \
708 ELOG_TYPE_DECLARE (_e) = \
709 { \
Florin Corasca1c8f32018-05-23 21:01:30 -0700710 .format = "cc: %s snd_space %u snd_una %u out %u flight %u", \
711 .format_args = "t4i4i4i4i4", \
712 .n_enum_strings = 7, \
Florin Corasf1762d62017-09-24 19:43:08 -0400713 .enum_strings = { \
714 "fast-rxt", \
Florin Corasf1762d62017-09-24 19:43:08 -0400715 "first-rxt", \
Florin Corase55a6d72018-10-31 23:09:22 -0700716 "rxt-timeout", \
Florin Corasf1762d62017-09-24 19:43:08 -0400717 "recovered", \
718 "congestion", \
719 "undo", \
Florin Corasca1c8f32018-05-23 21:01:30 -0700720 "recovery", \
Florin Corasf1762d62017-09-24 19:43:08 -0400721 }, \
722 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700723 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasf1762d62017-09-24 19:43:08 -0400724 ed->data[0] = _sub_evt; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700725 ed->data[1] = tcp_available_cc_snd_space (_tc); \
726 ed->data[2] = _tc->snd_una - _tc->iss; \
727 ed->data[3] = tcp_bytes_out(_tc); \
728 ed->data[4] = tcp_flight_size (_tc); \
Florin Corasf1762d62017-09-24 19:43:08 -0400729}
Florin Corase55a6d72018-10-31 23:09:22 -0700730
731#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
732{ \
733 if (_tc->snd_una != _tc->iss) \
734 TCP_EVT_CC_STAT_PRINT (_tc); \
735 if ((_sub_evt <= 1 && TCP_DEBUG_CC > 1) \
736 || (_sub_evt > 1 && TCP_DEBUG_CC > 0)) \
737 TCP_EVT_CC_EVT_PRINT (_tc, _sub_evt); \
738}
Florin Coras537b17e2018-09-28 10:35:45 -0700739#else
Florin Corase55a6d72018-10-31 23:09:22 -0700740#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
741
Florin Coras537b17e2018-09-28 10:35:45 -0700742#endif
Florin Corasf1762d62017-09-24 19:43:08 -0400743
Florin Corasa436a422019-08-20 07:09:31 -0700744#if TCP_DEBUG_CC > 1 || TCP_DEBUG_ALWAYS
Florin Coras6792ec02017-03-13 03:49:51 -0700745#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...) \
746{ \
747 ELOG_TYPE_DECLARE (_e) = \
748 { \
Florin Coras93992a92017-05-24 18:03:56 -0700749 .format = "rxt: snd_nxt %u offset %u snd %u rxt %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700750 .format_args = "i4i4i4i4", \
751 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700752 TCP_DECLARE_ETD(_tc, _e, 4); \
Florin Coras6792ec02017-03-13 03:49:51 -0700753 ed->data[0] = _tc->snd_nxt - _tc->iss; \
754 ed->data[1] = offset; \
755 ed->data[2] = n_bytes; \
Florin Coras93992a92017-05-24 18:03:56 -0700756 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Coras6792ec02017-03-13 03:49:51 -0700757}
758
Florin Corasca1c8f32018-05-23 21:01:30 -0700759#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, _btcp, ...) \
Florin Coras6792ec02017-03-13 03:49:51 -0700760{ \
761 ELOG_TYPE_DECLARE (_e) = \
762 { \
Florin Corasca1c8f32018-05-23 21:01:30 -0700763 .format = "dack-tx: rcv_nxt %u seq %u rcv_wnd %u snd_nxt %u av_wnd %u",\
Florin Corasf1762d62017-09-24 19:43:08 -0400764 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700765 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700766 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasf1762d62017-09-24 19:43:08 -0400767 ed->data[0] = _tc->rcv_nxt - _tc->irs; \
Florin Corasca1c8f32018-05-23 21:01:30 -0700768 ed->data[1] = _btcp.seq_number - _tc->irs; \
769 ed->data[2] = _tc->rcv_wnd; \
770 ed->data[3] = _tc->snd_nxt - _tc->iss; \
771 ed->data[4] = tcp_available_snd_wnd(_tc); \
Florin Corasf1762d62017-09-24 19:43:08 -0400772}
773
774#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...) \
775{ \
776 ELOG_TYPE_DECLARE (_e) = \
777 { \
778 .format = "dack-rx: snd_una %u cwnd %u snd_wnd %u flight %u rcv_wnd %u",\
779 .format_args = "i4i4i4i4i4", \
780 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700781 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasf1762d62017-09-24 19:43:08 -0400782 ed->data[0] = _tc->snd_una - _tc->iss; \
783 ed->data[1] = _tc->cwnd; \
784 ed->data[2] = _tc->snd_wnd; \
785 ed->data[3] = tcp_flight_size(_tc); \
786 ed->data[4] = _tc->rcv_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700787}
788
789#define TCP_EVT_CC_PACK_HANDLER(_tc, ...) \
790{ \
791 ELOG_TYPE_DECLARE (_e) = \
792 { \
Florin Coras9404a072020-11-24 17:29:17 -0800793 .format = "pack: snd_una %u snd_nxt %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700794 .format_args = "i4i4", \
795 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700796 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Coras6792ec02017-03-13 03:49:51 -0700797 ed->data[0] = _tc->snd_una - _tc->iss; \
Florin Coras9404a072020-11-24 17:29:17 -0800798 ed->data[1] = _tc->snd_nxt - _tc->iss; \
Florin Coras6792ec02017-03-13 03:49:51 -0700799}
Florin Corasca1c8f32018-05-23 21:01:30 -0700800#define TCP_EVT_CC_SCOREBOARD_HANDLER(_tc, ...) \
801{ \
802if (TCP_DEBUG_CC > 1 && _tc->sack_sb.last_sacked_bytes) \
803 { \
804 ELOG_TYPE_DECLARE (_e) = \
805 { \
806 .format = "sb1: holes %u lost %u sacked %u high %u highrxt %u", \
807 .format_args = "i4i4i4i4i4", \
808 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700809 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700810 ed->data[0] = pool_elts(_tc->sack_sb.holes); \
811 ed->data[1] = _tc->sack_sb.lost_bytes; \
812 ed->data[2] = _tc->sack_sb.sacked_bytes; \
813 ed->data[3] = _tc->sack_sb.high_sacked - _tc->iss; \
814 ed->data[4] = _tc->sack_sb.high_rxt - _tc->iss; \
815 } \
816if (TCP_DEBUG_CC > 1 && _tc->sack_sb.last_sacked_bytes) \
817 { \
818 sack_scoreboard_hole_t *hole; \
819 hole = scoreboard_first_hole (&_tc->sack_sb); \
820 ELOG_TYPE_DECLARE (_e) = \
821 { \
822 .format = "sb2: first start: %u end %u last start %u end %u", \
823 .format_args = "i4i4i4i4", \
824 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700825 TCP_DECLARE_ETD(_tc, _e, 4); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700826 ed->data[0] = hole ? hole->start - _tc->iss : 0; \
827 ed->data[1] = hole ? hole->end - _tc->iss : 0; \
828 hole = scoreboard_last_hole (&_tc->sack_sb); \
829 ed->data[2] = hole ? hole->start - _tc->iss : 0; \
830 ed->data[3] = hole ? hole->end - _tc->iss : 0; \
831 } \
832}
833#define TCP_EVT_CC_SACKS_HANDLER(_tc, ...) \
834{ \
835if (TCP_DEBUG_CC > 1) \
836 { \
837 ELOG_TYPE_DECLARE (_e) = \
838 { \
839 .format = "sacks: blocks %u bytes %u", \
840 .format_args = "i4i4", \
841 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700842 TCP_DECLARE_ETD(_tc, _e, 2); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700843 ed->data[0] = vec_len (_tc->snd_sacks); \
844 ed->data[1] = tcp_sack_list_bytes (_tc); \
845 } \
846}
847#define TCP_EVT_CC_INPUT_HANDLER(_tc, _len, _written, ...) \
848{ \
849 ELOG_TYPE_DECLARE (_e) = \
850 { \
851 .format = "cc input: len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
852 .format_args = "i4i4i4i4", \
853 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700854 TCP_DECLARE_ETD(_tc, _e, 4); \
Florin Corasca1c8f32018-05-23 21:01:30 -0700855 ed->data[0] = _len; \
856 ed->data[1] = _written; \
857 ed->data[2] = _tc->rcv_nxt - _tc->irs; \
858 ed->data[3] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las); \
859}
Florin Corasf1762d62017-09-24 19:43:08 -0400860#else
861#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...)
Florin Corasca1c8f32018-05-23 21:01:30 -0700862#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, _btcp, ...)
Florin Corasf1762d62017-09-24 19:43:08 -0400863#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...)
864#define TCP_EVT_CC_PACK_HANDLER(_tc, ...)
Florin Corasca1c8f32018-05-23 21:01:30 -0700865#define TCP_EVT_CC_SCOREBOARD_HANDLER(_tc, ...)
866#define TCP_EVT_CC_SACKS_HANDLER(_tc, ...)
867#define TCP_EVT_CC_INPUT_HANDLER(_tc, _len, _written, ...)
Florin Corasf1762d62017-09-24 19:43:08 -0400868#endif
Florin Coras6792ec02017-03-13 03:49:51 -0700869
Florin Corasf03a59a2017-06-09 21:07:32 -0700870/*
871 * Congestion control stats
872 */
Florin Corasa436a422019-08-20 07:09:31 -0700873#if TCP_DEBUG_CS || TCP_DEBUG_ALWAYS
Florin Coras6792ec02017-03-13 03:49:51 -0700874
Steven Luong6161bba2022-09-29 16:45:23 -0700875#define STATS_INTERVAL 0.001
Florin Corasf03a59a2017-06-09 21:07:32 -0700876
Steven Luong6161bba2022-09-29 16:45:23 -0700877#define tcp_cc_time_to_print_stats(_tc) \
878 _tc->c_cc_stat_tstamp + STATS_INTERVAL < \
879 tcp_time_now_us (_tc->c_thread_index) || \
880 tcp_in_fastrecovery (_tc)
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700881
882#define TCP_EVT_CC_RTO_STAT_PRINT(_tc) \
Florin Coras3e350af2017-03-30 02:54:28 -0700883{ \
884 ELOG_TYPE_DECLARE (_e) = \
885 { \
Florin Corasefefc6b2018-11-07 12:49:19 -0800886 .format = "rcv_stat: rto %u srtt %u mrtt-us %u rttvar %u", \
887 .format_args = "i4i4i4i4", \
Florin Coras3e350af2017-03-30 02:54:28 -0700888 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700889 TCP_DECLARE_ETD(_tc, _e, 4); \
Florin Corasf03a59a2017-06-09 21:07:32 -0700890 ed->data[0] = _tc->rto; \
891 ed->data[1] = _tc->srtt; \
Florin Corasefefc6b2018-11-07 12:49:19 -0800892 ed->data[2] = (u32) (_tc->mrtt_us * 1e6); \
893 ed->data[3] = _tc->rttvar; \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700894}
895
Steven Luong6161bba2022-09-29 16:45:23 -0700896#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \
897 { \
898 if (tcp_cc_time_to_print_stats (_tc)) \
899 { \
900 TCP_EVT_CC_RTO_STAT_PRINT (_tc); \
901 _tc->c_cc_stat_tstamp = tcp_time_now_us (_tc->c_thread_index); \
902 } \
903 }
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700904
905#define TCP_EVT_CC_SND_STAT_PRINT(_tc) \
Florin Coras62166002018-04-18 16:40:55 -0700906{ \
907 ELOG_TYPE_DECLARE (_e) = \
908 { \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700909 .format = "snd_stat: cc_space %u sacked %u lost %u out %u rxt %u", \
Florin Coras62166002018-04-18 16:40:55 -0700910 .format_args = "i4i4i4i4i4", \
911 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700912 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700913 ed->data[0] = tcp_available_cc_snd_space (_tc); \
Florin Coras62166002018-04-18 16:40:55 -0700914 ed->data[1] = _tc->sack_sb.sacked_bytes; \
915 ed->data[2] = _tc->sack_sb.lost_bytes; \
916 ed->data[3] = tcp_bytes_out (_tc); \
917 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700918}
919
Steven Luong6161bba2022-09-29 16:45:23 -0700920#define TCP_EVT_CC_SND_STAT_HANDLER(_tc, ...) \
921 { \
922 if (tcp_cc_time_to_print_stats (_tc)) \
923 { \
924 TCP_EVT_CC_SND_STAT_PRINT (_tc); \
925 _tc->c_cc_stat_tstamp = tcp_time_now_us (_tc->c_thread_index); \
926 } \
927 }
Florin Coras3e350af2017-03-30 02:54:28 -0700928
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700929#define TCP_EVT_CC_STAT_PRINT(_tc) \
Florin Coras6792ec02017-03-13 03:49:51 -0700930{ \
931 ELOG_TYPE_DECLARE (_e) = \
932 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700933 .format = "cc_stat: cwnd %u flight %u space %u ssthresh %u snd_wnd %u",\
934 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700935 }; \
Florin Corasa436a422019-08-20 07:09:31 -0700936 TCP_DECLARE_ETD(_tc, _e, 5); \
Florin Corasf03a59a2017-06-09 21:07:32 -0700937 ed->data[0] = _tc->cwnd; \
938 ed->data[1] = tcp_flight_size (_tc); \
939 ed->data[2] = tcp_snd_space (_tc); \
940 ed->data[3] = _tc->ssthresh; \
941 ed->data[4] = _tc->snd_wnd; \
Florin Corasbf4d5ce2018-10-19 16:26:24 -0700942 TCP_EVT_CC_RTO_STAT_PRINT (_tc); \
943 TCP_EVT_CC_SND_STAT_PRINT (_tc); \
944}
945
Steven Luong6161bba2022-09-29 16:45:23 -0700946#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \
947 { \
948 if (tcp_cc_time_to_print_stats (_tc)) \
949 { \
950 TCP_EVT_CC_STAT_PRINT (_tc); \
951 _tc->c_cc_stat_tstamp = tcp_time_now_us (_tc->c_thread_index); \
952 } \
953 }
Florin Corasc1a448b2018-04-20 10:51:49 -0700954#else
955#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Coras07025542019-01-19 16:45:13 -0800956#define TCP_EVT_CC_STAT_PRINT(_tc)
Florin Corasc1a448b2018-04-20 10:51:49 -0700957#endif
Florin Coras6792ec02017-03-13 03:49:51 -0700958
Florin Corasf988e692017-11-27 04:34:14 -0500959/*
960 * Buffer allocation
961 */
Florin Corasa436a422019-08-20 07:09:31 -0700962#if TCP_DEBUG_BUF_ALLOC
Florin Corasf988e692017-11-27 04:34:14 -0500963
964#define TCP_DBG_BUFFER_ALLOC_MAYBE_FAIL(thread_index) \
965{ \
966 static u32 *buffer_fail_counters; \
Florin Corasc1a448b2018-04-20 10:51:49 -0700967 if (PREDICT_FALSE (buffer_fail_counters == 0)) \
Florin Corasf988e692017-11-27 04:34:14 -0500968 { \
969 u32 num_threads; \
Florin Corasc1a448b2018-04-20 10:51:49 -0700970 vlib_thread_main_t *vtm = vlib_get_thread_main (); \
Florin Corasf988e692017-11-27 04:34:14 -0500971 num_threads = 1 /* main thread */ + vtm->n_threads; \
972 vec_validate (buffer_fail_counters, num_threads - 1); \
973 } \
Florin Coras9094b5c2019-08-12 14:17:47 -0700974 if (PREDICT_FALSE (tcp_cfg.buffer_fail_fraction != 0.0)) \
Florin Corasf988e692017-11-27 04:34:14 -0500975 { \
Florin Corasc1a448b2018-04-20 10:51:49 -0700976 if (PREDICT_TRUE (buffer_fail_counters[thread_index] > 0)) \
Florin Corasf988e692017-11-27 04:34:14 -0500977 { \
Florin Corasc1a448b2018-04-20 10:51:49 -0700978 if ((1.0 / (f32) (buffer_fail_counters[thread_index])) \
Florin Coras9094b5c2019-08-12 14:17:47 -0700979 < tcp_cfg.buffer_fail_fraction) \
Florin Corasf988e692017-11-27 04:34:14 -0500980 { \
981 buffer_fail_counters[thread_index] = 0.0000001; \
Florin Corasc1a448b2018-04-20 10:51:49 -0700982 return -1; \
Florin Corasf988e692017-11-27 04:34:14 -0500983 } \
984 } \
985 buffer_fail_counters[thread_index] ++; \
986 } \
987}
988#else
989#define TCP_DBG_BUFFER_ALLOC_MAYBE_FAIL(thread_index)
990#endif
991
Florin Corase69f4952017-03-07 10:06:24 -0800992#endif /* SRC_VNET_TCP_TCP_DEBUG_H_ */
993/*
994 * fd.io coding-style-patch-verification: ON
995 *
996 * Local Variables:
997 * eval: (c-set-style "gnu")
998 * End:
999 */