blob: e0db7f4f0fa606ad4626ba68af8230680c9c0c92 [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 Corasb384b542018-01-15 01:08:33 -080022#define TCP_DEBUG_SM (1)
Florin Corasf1762d62017-09-24 19:43:08 -040023#define TCP_DEBUG_CC (0)
Florin Coras68810622017-07-24 17:40:28 -070024#define TCP_DEBUG_CC_STAT (1)
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 Coras6792ec02017-03-13 03:49:51 -070059 _(SEG_INVALID, "invalid segment") \
Florin Corasc28764f2017-04-26 00:08:42 -070060 _(PAWS_FAIL, "failed paws check") \
Florin Coras6792ec02017-03-13 03:49:51 -070061 _(ACK_RCV_ERR, "invalid ack") \
Florin Coras3e350af2017-03-30 02:54:28 -070062 _(RCV_WND_SHRUNK, "shrunk rcv_wnd") \
Florin Corase69f4952017-03-07 10:06:24 -080063
64typedef enum _tcp_dbg
65{
66#define _(sym, str) TCP_DBG_##sym,
67 foreach_tcp_dbg_evt
68#undef _
69} tcp_dbg_e;
70
71typedef enum _tcp_dbg_evt
72{
73#define _(sym, str) TCP_EVT_##sym,
74 foreach_tcp_dbg_evt
75#undef _
76} tcp_dbg_evt_e;
77
78#if TCP_DEBUG
79
80#define TRANSPORT_DEBUG (1)
81
Florin Corasf03a59a2017-06-09 21:07:32 -070082/*
83 * Infra and evt track setup
84 */
85
Florin Coras9d063042017-09-14 03:08:00 -040086#define TCP_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
Florin Corase69f4952017-03-07 10:06:24 -080087
88#define DECLARE_ETD(_tc, _e, _size) \
89 struct \
90 { \
91 u32 data[_size]; \
92 } * ed; \
93 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
94 _e, _tc->c_elog_track)
95
Florin Coras6534b7a2017-07-18 05:38:03 -040096#define TCP_DBG_IP_TAG_LCL(_tc) \
Florin Corase69f4952017-03-07 10:06:24 -080097{ \
Florin Coras6534b7a2017-07-18 05:38:03 -040098 if (_tc->c_is_ip4) \
99 { \
100 ELOG_TYPE_DECLARE (_e) = \
101 { \
102 .format = "lcl: %d.%d.%d.%d:%d", \
103 .format_args = "i4i4i4i4i4", \
104 }; \
105 DECLARE_ETD(_tc, _e, 5); \
106 ed->data[0] = _tc->c_lcl_ip.ip4.as_u8[0]; \
107 ed->data[1] = _tc->c_lcl_ip.ip4.as_u8[1]; \
108 ed->data[2] = _tc->c_lcl_ip.ip4.as_u8[2]; \
109 ed->data[3] = _tc->c_lcl_ip.ip4.as_u8[3]; \
110 ed->data[4] = clib_net_to_host_u16(_tc->c_lcl_port); \
111 } \
112}
113
114#define TCP_DBG_IP_TAG_RMT(_tc) \
115{ \
116 if (_tc->c_is_ip4) \
117 { \
118 ELOG_TYPE_DECLARE (_e) = \
119 { \
120 .format = "rmt: %d.%d.%d.%d:%d", \
121 .format_args = "i4i4i4i4i4", \
122 }; \
123 DECLARE_ETD(_tc, _e, 5); \
124 ed->data[0] = _tc->c_rmt_ip.ip4.as_u8[0]; \
125 ed->data[1] = _tc->c_rmt_ip.ip4.as_u8[1]; \
126 ed->data[2] = _tc->c_rmt_ip.ip4.as_u8[2]; \
127 ed->data[3] = _tc->c_rmt_ip.ip4.as_u8[3]; \
128 ed->data[4] = clib_net_to_host_u16(_tc->c_rmt_port); \
129 } \
130}
131
132#define TCP_EVT_INIT_HANDLER(_tc, _is_l, ...) \
133{ \
134 char *_fmt = _is_l ? "l[%d].%d:%d%c" : "[%d].%d:%d->.%d:%d%c"; \
135 if (_tc->c_is_ip4) \
136 { \
137 _tc->c_elog_track.name = \
138 (char *) format (0, _fmt, _tc->c_thread_index, \
139 _tc->c_lcl_ip.ip4.as_u8[3], \
140 clib_net_to_host_u16(_tc->c_lcl_port), \
141 _tc->c_rmt_ip.ip4.as_u8[3], \
142 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
143 } \
144 else \
145 _tc->c_elog_track.name = \
146 (char *) format (0, _fmt, _tc->c_thread_index, \
147 _tc->c_lcl_ip.ip6.as_u8[15], \
148 clib_net_to_host_u16(_tc->c_lcl_port), \
149 _tc->c_rmt_ip.ip6.as_u8[15], \
150 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800151 elog_track_register (&vlib_global_main.elog_main, &_tc->c_elog_track);\
Florin Coras6534b7a2017-07-18 05:38:03 -0400152 TCP_DBG_IP_TAG_LCL(_tc); \
153 TCP_DBG_IP_TAG_RMT(_tc); \
Florin Corase69f4952017-03-07 10:06:24 -0800154}
155
156#define TCP_EVT_DEALLOC_HANDLER(_tc, ...) \
157{ \
158 vec_free (_tc->c_elog_track.name); \
159}
160
161#define TCP_EVT_OPEN_HANDLER(_tc, ...) \
162{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400163 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800164 ELOG_TYPE_DECLARE (_e) = \
165 { \
166 .format = "open: index %d", \
167 .format_args = "i4", \
168 }; \
169 DECLARE_ETD(_tc, _e, 1); \
170 ed->data[0] = _tc->c_c_index; \
171}
172
173#define TCP_EVT_CLOSE_HANDLER(_tc, ...) \
174{ \
175 ELOG_TYPE_DECLARE (_e) = \
176 { \
177 .format = "close: %d", \
178 .format_args = "i4", \
179 }; \
180 DECLARE_ETD(_tc, _e, 1); \
181 ed->data[0] = _tc->c_c_index; \
182}
183
184#define TCP_EVT_BIND_HANDLER(_tc, ...) \
185{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400186 TCP_EVT_INIT_HANDLER(_tc, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800187 ELOG_TYPE_DECLARE (_e) = \
188 { \
189 .format = "bind: listener %d", \
190 }; \
191 DECLARE_ETD(_tc, _e, 1); \
192 ed->data[0] = _tc->c_c_index; \
193}
194
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400195#define TCP_EVT_SYN_RCVD_HANDLER(_tc,_init, ...) \
Florin Coras68810622017-07-24 17:40:28 -0700196{ \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400197 if (_init) \
198 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Coras68810622017-07-24 17:40:28 -0700199 ELOG_TYPE_DECLARE (_e) = \
200 { \
201 .format = "syn-rx: irs %u", \
202 .format_args = "i4", \
203 }; \
204 DECLARE_ETD(_tc, _e, 1); \
205 ed->data[0] = _tc->irs; \
206 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
207}
208
Florin Corase69f4952017-03-07 10:06:24 -0800209#define TCP_EVT_UNBIND_HANDLER(_tc, ...) \
210{ \
211 TCP_EVT_DEALLOC_HANDLER(_tc); \
212 ELOG_TYPE_DECLARE (_e) = \
213 { \
214 .format = "unbind: listener %d", \
215 }; \
216 DECLARE_ETD(_tc, _e, 1); \
217 ed->data[0] = _tc->c_c_index; \
218 TCP_EVT_DEALLOC_HANDLER(_tc); \
219}
220
221#define TCP_EVT_DELETE_HANDLER(_tc, ...) \
222{ \
223 ELOG_TYPE_DECLARE (_e) = \
224 { \
225 .format = "delete: %d", \
226 .format_args = "i4", \
227 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700228 DECLARE_ETD(_tc, _e, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800229 ed->data[0] = _tc->c_c_index; \
230 TCP_EVT_DEALLOC_HANDLER(_tc); \
231}
232
Florin Corasf03a59a2017-06-09 21:07:32 -0700233#define CONCAT_HELPER(_a, _b) _a##_b
234#define CC(_a, _b) CONCAT_HELPER(_a, _b)
235#define TCP_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
236#else
237#define TCP_EVT_DBG(_evt, _args...)
Florin Coras9d063042017-09-14 03:08:00 -0400238#define TCP_DBG(_fmt, _args...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700239#endif
240
241/*
242 * State machine
243 */
244#if TCP_DEBUG_SM
245
Florin Coras6534b7a2017-07-18 05:38:03 -0400246#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...) \
247{ \
248 ELOG_TYPE_DECLARE (_e) = \
249 { \
250 .format = "state: %s", \
251 .format_args = "t4", \
252 .n_enum_strings = 11, \
253 .enum_strings = { \
254 "closed", \
255 "listen", \
256 "syn-sent", \
257 "syn-rcvd", \
258 "established", \
259 "close_wait", \
260 "fin-wait-1", \
261 "last-ack", \
262 "closing", \
263 "fin-wait-2", \
264 "time-wait", \
265 }, \
266 }; \
267 DECLARE_ETD(_tc, _e, 1); \
268 ed->data[0] = _tc->state; \
269}
270
Florin Coras6534b7a2017-07-18 05:38:03 -0400271#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...) \
272{ \
273 ELOG_TYPE_DECLARE (_e) = \
274 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400275 .format = "syn-tx: iss %u snd_una %u snd_una_max %u snd_nxt %u", \
276 .format_args = "i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400277 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400278 DECLARE_ETD(_tc, _e, 4); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400279 ed->data[0] = _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400280 ed->data[1] = _tc->snd_una - _tc->iss; \
281 ed->data[2] = _tc->snd_una_max - _tc->iss; \
282 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400283 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
284}
285
286#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...) \
287{ \
288 ELOG_TYPE_DECLARE (_e) = \
289 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400290 .format = "synack-tx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
291 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400292 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400293 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400294 ed->data[0] = _tc->iss; \
295 ed->data[1] = _tc->irs; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400296 ed->data[2] = _tc->snd_una - _tc->iss; \
297 ed->data[3] = _tc->snd_nxt - _tc->iss; \
298 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400299}
300
301#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...) \
302{ \
303 ELOG_TYPE_DECLARE (_e) = \
304 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400305 .format = "synack-rx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
306 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400307 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400308 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400309 ed->data[0] = _tc->iss; \
310 ed->data[1] = _tc->irs; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400311 ed->data[2] = _tc->snd_una - _tc->iss; \
312 ed->data[3] = _tc->snd_nxt - _tc->iss; \
313 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400314 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
315}
316
317#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...) \
318{ \
319 ELOG_TYPE_DECLARE (_e) = \
320 { \
321 .format = "fin-tx: snd_nxt %d rcv_nxt %d", \
322 .format_args = "i4i4", \
323 }; \
324 DECLARE_ETD(_tc, _e, 2); \
325 ed->data[0] = _tc->snd_nxt - _tc->iss; \
326 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
327}
328
329#define TCP_EVT_RST_SENT_HANDLER(_tc, ...) \
330{ \
331 ELOG_TYPE_DECLARE (_e) = \
332 { \
333 .format = "rst-tx: snd_nxt %d rcv_nxt %d", \
334 .format_args = "i4i4", \
335 }; \
336 DECLARE_ETD(_tc, _e, 2); \
337 ed->data[0] = _tc->snd_nxt - _tc->iss; \
338 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
339 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
340}
341
342#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...) \
343{ \
344 ELOG_TYPE_DECLARE (_e) = \
345 { \
346 .format = "fin-rx: snd_nxt %d rcv_nxt %d", \
347 .format_args = "i4i4", \
348 }; \
349 DECLARE_ETD(_tc, _e, 2); \
350 ed->data[0] = _tc->snd_nxt - _tc->iss; \
351 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
352}
353
354#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...) \
355{ \
356 ELOG_TYPE_DECLARE (_e) = \
357 { \
358 .format = "rst-rx: snd_nxt %d rcv_nxt %d", \
359 .format_args = "i4i4", \
360 }; \
361 DECLARE_ETD(_tc, _e, 2); \
362 ed->data[0] = _tc->snd_nxt - _tc->iss; \
363 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
364}
365
366#define TCP_EVT_SYN_RXT_HANDLER(_tc, _type, ...) \
367{ \
368 ELOG_TYPE_DECLARE (_e) = \
369 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400370 .format = "%s-rxt: iss %u irs %u snd_nxt %u rcv_nxt %u", \
371 .format_args = "t4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400372 .n_enum_strings = 2, \
373 .enum_strings = { \
374 "syn", \
375 "syn-ack", \
376 }, \
377 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400378 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400379 ed->data[0] = _type; \
380 ed->data[1] = _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400381 ed->data[2] = _tc->irs; \
382 ed->data[3] = _tc->snd_nxt - _tc->iss; \
383 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400384}
385
386#else
387#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...)
388#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...)
389#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...)
390#define TCP_EVT_SYN_RXT_HANDLER(_tc, ...)
391#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...)
392#define TCP_EVT_RST_SENT_HANDLER(_tc, ...)
393#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...)
394#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...)
395#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...)
396#endif
397
398#if TCP_DEBUG_SM > 1
399
Florin Coras6792ec02017-03-13 03:49:51 -0700400#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...) \
401{ \
402 ELOG_TYPE_DECLARE (_e) = \
403 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400404 .format = "ack-tx: acked %u rcv_nxt %u rcv_wnd %u snd_nxt %u snd_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700405 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700406 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700407 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700408 ed->data[0] = _tc->rcv_nxt - _tc->rcv_las; \
409 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
410 ed->data[2] = _tc->rcv_wnd; \
411 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700412 ed->data[4] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700413}
414
Florin Coras3e350af2017-03-30 02:54:28 -0700415#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800416{ \
417 ELOG_TYPE_DECLARE (_e) = \
418 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400419 .format = "ack-rx: %u snd_una %u snd_wnd %u cwnd %u inflight %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700420 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800421 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700422 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800423 ed->data[0] = _tc->bytes_acked; \
Florin Coras6792ec02017-03-13 03:49:51 -0700424 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700425 ed->data[2] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700426 ed->data[3] = _tc->cwnd; \
427 ed->data[4] = tcp_flight_size(_tc); \
428}
429
Florin Corase69f4952017-03-07 10:06:24 -0800430#define TCP_EVT_PKTIZE_HANDLER(_tc, ...) \
431{ \
432 ELOG_TYPE_DECLARE (_e) = \
433 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400434 .format = "tx: una %u snd_nxt %u space %u flight %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700435 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800436 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700437 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800438 ed->data[0] = _tc->snd_una - _tc->iss; \
439 ed->data[1] = _tc->snd_nxt - _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400440 ed->data[2] = tcp_available_output_snd_space (_tc); \
Florin Coras6792ec02017-03-13 03:49:51 -0700441 ed->data[3] = tcp_flight_size (_tc); \
442 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800443}
444
Florin Coras6792ec02017-03-13 03:49:51 -0700445#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800446{ \
447 ELOG_TYPE_DECLARE (_e) = \
448 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700449 .format = "in: %s len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
Florin Coras6792ec02017-03-13 03:49:51 -0700450 .format_args = "t4i4i4i4i4", \
451 .n_enum_strings = 2, \
452 .enum_strings = { \
453 "order", \
454 "ooo", \
455 }, \
Florin Corase69f4952017-03-07 10:06:24 -0800456 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700457 DECLARE_ETD(_tc, _e, 5); \
458 ed->data[0] = _type; \
459 ed->data[1] = _len; \
460 ed->data[2] = _written; \
461 ed->data[3] = (_tc->rcv_nxt - _tc->irs) + _written; \
462 ed->data[4] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las); \
Florin Corase69f4952017-03-07 10:06:24 -0800463}
464
465#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...) \
466{ \
467 tcp_connection_t *_tc; \
flyingeagle23e8146b02017-04-26 20:06:52 +0800468 if (_timer_id == TCP_TIMER_RETRANSMIT_SYN \
469 || _timer_id == TCP_TIMER_ESTABLISH) \
Florin Corase69f4952017-03-07 10:06:24 -0800470 { \
471 _tc = tcp_half_open_connection_get (_tc_index); \
472 } \
473 else \
474 { \
Damjan Marion586afd72017-04-05 19:18:20 +0200475 u32 _thread_index = vlib_get_thread_index (); \
Florin Corase69f4952017-03-07 10:06:24 -0800476 _tc = tcp_connection_get (_tc_index, _thread_index); \
477 } \
478 ELOG_TYPE_DECLARE (_e) = \
479 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400480 .format = "timer-pop: %s (%d)", \
Florin Corase69f4952017-03-07 10:06:24 -0800481 .format_args = "t4i4", \
482 .n_enum_strings = 7, \
483 .enum_strings = { \
484 "retransmit", \
485 "delack", \
Florin Coras3e350af2017-03-30 02:54:28 -0700486 "persist", \
Florin Corase69f4952017-03-07 10:06:24 -0800487 "keep", \
488 "waitclose", \
489 "retransmit syn", \
490 "establish", \
491 }, \
492 }; \
Dave Barach2c25a622017-06-26 11:35:07 -0400493 if (_tc) \
494 { \
495 DECLARE_ETD(_tc, _e, 2); \
496 ed->data[0] = _timer_id; \
497 ed->data[1] = _timer_id; \
498 } \
499 else \
500 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400501 clib_warning ("pop %d for unexisting connection %d", _timer_id, \
502 _tc_index); \
Dave Barach2c25a622017-06-26 11:35:07 -0400503 } \
Florin Corase69f4952017-03-07 10:06:24 -0800504}
505
Florin Coras6792ec02017-03-13 03:49:51 -0700506#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...) \
507{ \
508 ELOG_TYPE_DECLARE (_e) = \
509 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700510 .format = "seg-inv: seq %u end %u rcv_las %u rcv_nxt %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700511 .format_args = "i4i4i4i4i4", \
512 }; \
513 DECLARE_ETD(_tc, _e, 5); \
514 ed->data[0] = _seq - _tc->irs; \
515 ed->data[1] = _end - _tc->irs; \
516 ed->data[2] = _tc->rcv_las - _tc->irs; \
517 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
518 ed->data[4] = _tc->rcv_wnd; \
519}
520
Florin Corasc28764f2017-04-26 00:08:42 -0700521#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...) \
522{ \
523 ELOG_TYPE_DECLARE (_e) = \
524 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400525 .format = "paws-err: seq %u end %u tsval %u tsval_recent %u", \
Florin Corasc28764f2017-04-26 00:08:42 -0700526 .format_args = "i4i4i4i4", \
527 }; \
528 DECLARE_ETD(_tc, _e, 4); \
529 ed->data[0] = _seq - _tc->irs; \
530 ed->data[1] = _end - _tc->irs; \
Florin Coras93992a92017-05-24 18:03:56 -0700531 ed->data[2] = _tc->rcv_opts.tsval; \
Florin Corasc28764f2017-04-26 00:08:42 -0700532 ed->data[3] = _tc->tsval_recent; \
533}
534
Florin Coras6792ec02017-03-13 03:49:51 -0700535#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...) \
536{ \
537 ELOG_TYPE_DECLARE (_e) = \
538 { \
539 .format = "ack-err: %s ack %u snd_una %u snd_nxt %u una_max %u", \
540 .format_args = "t4i4i4i4i4", \
541 .n_enum_strings = 3, \
542 .enum_strings = { \
543 "invalid", \
544 "old", \
545 "future", \
546 }, \
547 }; \
548 DECLARE_ETD(_tc, _e, 5); \
549 ed->data[0] = _type; \
550 ed->data[1] = _ack - _tc->iss; \
551 ed->data[2] = _tc->snd_una - _tc->iss; \
552 ed->data[3] = _tc->snd_nxt - _tc->iss; \
553 ed->data[4] = _tc->snd_una_max - _tc->iss; \
554}
555
Florin Corasf03a59a2017-06-09 21:07:32 -0700556#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...) \
557{ \
558if (_av > 0) \
559{ \
560 ELOG_TYPE_DECLARE (_e) = \
561 { \
562 .format = "huh?: rcv_wnd %u obsd %u av %u rcv_nxt %u rcv_las %u", \
563 .format_args = "i4i4i4i4i4", \
564 }; \
565 DECLARE_ETD(_tc, _e, 5); \
566 ed->data[0] = _tc->rcv_wnd; \
567 ed->data[1] = _obs; \
568 ed->data[2] = _av; \
569 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
570 ed->data[4] = _tc->rcv_las - _tc->irs; \
571} \
572}
573#else
574#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700575#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700576#define TCP_EVT_PKTIZE_HANDLER(_tc, ...)
577#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...)
578#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)
579#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...)
580#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...)
581#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...)
582#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...)
583#endif
584
585/*
586 * State machine verbose
587 */
Florin Coras6534b7a2017-07-18 05:38:03 -0400588#if TCP_DEBUG_SM > 2
Florin Corasf03a59a2017-06-09 21:07:32 -0700589#define TCP_EVT_SND_WND_HANDLER(_tc, ...) \
590{ \
591 ELOG_TYPE_DECLARE (_e) = \
592 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400593 .format = "snd-wnd update: %u ", \
Florin Corasf03a59a2017-06-09 21:07:32 -0700594 .format_args = "i4", \
595 }; \
596 DECLARE_ETD(_tc, _e, 1); \
597 ed->data[0] = _tc->snd_wnd; \
598}
599
600#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...) \
601{ \
602 ELOG_TYPE_DECLARE (_e) = \
603 { \
604 .format = "out: flags %x, bytes %u", \
605 .format_args = "i4i4", \
606 }; \
607 DECLARE_ETD(_tc, _e, 2); \
608 ed->data[0] = flags; \
609 ed->data[1] = n_bytes; \
610}
611#else
612#define TCP_EVT_SND_WND_HANDLER(_tc, ...)
613#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)
614#endif
615
Florin Coras6792ec02017-03-13 03:49:51 -0700616/*
617 * Congestion Control
618 */
619
620#if TCP_DEBUG_CC
Florin Corasf1762d62017-09-24 19:43:08 -0400621
622#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
623{ \
624 ELOG_TYPE_DECLARE (_e) = \
625 { \
626 .format = "cc: %s wnd %u snd_cong %u rxt_bytes %u", \
627 .format_args = "t4i4i4i4", \
628 .n_enum_strings = 6, \
629 .enum_strings = { \
630 "fast-rxt", \
631 "rxt-timeout", \
632 "first-rxt", \
633 "recovered", \
634 "congestion", \
635 "undo", \
636 }, \
637 }; \
638 DECLARE_ETD(_tc, _e, 4); \
639 ed->data[0] = _sub_evt; \
640 ed->data[1] = tcp_available_snd_space (_tc); \
641 ed->data[2] = _tc->snd_congestion - _tc->iss; \
642 ed->data[3] = _tc->snd_rxt_bytes; \
643}
644
Florin Coras6792ec02017-03-13 03:49:51 -0700645#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...) \
646{ \
647 ELOG_TYPE_DECLARE (_e) = \
648 { \
Florin Coras93992a92017-05-24 18:03:56 -0700649 .format = "rxt: snd_nxt %u offset %u snd %u rxt %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700650 .format_args = "i4i4i4i4", \
651 }; \
652 DECLARE_ETD(_tc, _e, 4); \
653 ed->data[0] = _tc->snd_nxt - _tc->iss; \
654 ed->data[1] = offset; \
655 ed->data[2] = n_bytes; \
Florin Coras93992a92017-05-24 18:03:56 -0700656 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Coras6792ec02017-03-13 03:49:51 -0700657}
658
Florin Corasf1762d62017-09-24 19:43:08 -0400659#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...) \
Florin Coras6792ec02017-03-13 03:49:51 -0700660{ \
661 ELOG_TYPE_DECLARE (_e) = \
662 { \
Florin Corasf1762d62017-09-24 19:43:08 -0400663 .format = "dack-tx: rcv_nxt %u rcv_wnd %u snd_nxt %u av_wnd %u snd_wnd %u",\
664 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700665 }; \
Florin Corasf1762d62017-09-24 19:43:08 -0400666 DECLARE_ETD(_tc, _e, 5); \
667 ed->data[0] = _tc->rcv_nxt - _tc->irs; \
668 ed->data[1] = _tc->rcv_wnd; \
669 ed->data[2] = _tc->snd_nxt - _tc->iss; \
670 ed->data[3] = tcp_available_snd_wnd(_tc); \
671 ed->data[4] = _tc->snd_wnd; \
672}
673
674#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...) \
675{ \
676 ELOG_TYPE_DECLARE (_e) = \
677 { \
678 .format = "dack-rx: snd_una %u cwnd %u snd_wnd %u flight %u rcv_wnd %u",\
679 .format_args = "i4i4i4i4i4", \
680 }; \
681 DECLARE_ETD(_tc, _e, 5); \
682 ed->data[0] = _tc->snd_una - _tc->iss; \
683 ed->data[1] = _tc->cwnd; \
684 ed->data[2] = _tc->snd_wnd; \
685 ed->data[3] = tcp_flight_size(_tc); \
686 ed->data[4] = _tc->rcv_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700687}
688
689#define TCP_EVT_CC_PACK_HANDLER(_tc, ...) \
690{ \
691 ELOG_TYPE_DECLARE (_e) = \
692 { \
693 .format = "pack: snd_una %u snd_una_max %u", \
694 .format_args = "i4i4", \
695 }; \
696 DECLARE_ETD(_tc, _e, 2); \
697 ed->data[0] = _tc->snd_una - _tc->iss; \
698 ed->data[1] = _tc->snd_una_max - _tc->iss; \
699}
Florin Corasf1762d62017-09-24 19:43:08 -0400700#else
701#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...)
702#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...)
703#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...)
704#define TCP_EVT_CC_PACK_HANDLER(_tc, ...)
705#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...)
706#endif
Florin Coras6792ec02017-03-13 03:49:51 -0700707
Florin Corasf03a59a2017-06-09 21:07:32 -0700708/*
709 * Congestion control stats
710 */
711#if TCP_DEBUG_CC_STAT
Florin Coras6792ec02017-03-13 03:49:51 -0700712
Florin Corasf03a59a2017-06-09 21:07:32 -0700713#define STATS_INTERVAL 1
714
715#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \
Florin Coras3e350af2017-03-30 02:54:28 -0700716{ \
Florin Corasf03a59a2017-06-09 21:07:32 -0700717if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras3e350af2017-03-30 02:54:28 -0700718{ \
719 ELOG_TYPE_DECLARE (_e) = \
720 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700721 .format = "rto_stat: rto %u srtt %u rttvar %u ", \
722 .format_args = "i4i4i4", \
Florin Coras3e350af2017-03-30 02:54:28 -0700723 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700724 DECLARE_ETD(_tc, _e, 3); \
725 ed->data[0] = _tc->rto; \
726 ed->data[1] = _tc->srtt; \
727 ed->data[2] = _tc->rttvar; \
Florin Coras3e350af2017-03-30 02:54:28 -0700728} \
729}
730
Florin Corasf03a59a2017-06-09 21:07:32 -0700731#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \
732{ \
733if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras6792ec02017-03-13 03:49:51 -0700734{ \
735 ELOG_TYPE_DECLARE (_e) = \
736 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700737 .format = "cc_stat: cwnd %u flight %u space %u ssthresh %u snd_wnd %u",\
738 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700739 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700740 DECLARE_ETD(_tc, _e, 5); \
741 ed->data[0] = _tc->cwnd; \
742 ed->data[1] = tcp_flight_size (_tc); \
743 ed->data[2] = tcp_snd_space (_tc); \
744 ed->data[3] = _tc->ssthresh; \
745 ed->data[4] = _tc->snd_wnd; \
746 TCP_EVT_CC_RTO_STAT_HANDLER (_tc); \
747 _tc->c_cc_stat_tstamp = tcp_time_now(); \
748} \
Florin Coras6792ec02017-03-13 03:49:51 -0700749}
750
Florin Corasf988e692017-11-27 04:34:14 -0500751/*
752 * Buffer allocation
753 */
754#if TCP_DEBUG_BUFFER_ALLOCATION
755
756#define TCP_DBG_BUFFER_ALLOC_MAYBE_FAIL(thread_index) \
757{ \
758 static u32 *buffer_fail_counters; \
759 if (PREDICT_FALSE (buffer_fail_counters == 0)) \
760 { \
761 u32 num_threads; \
762 vlib_thread_main_t *vtm = vlib_get_thread_main (); \
763 num_threads = 1 /* main thread */ + vtm->n_threads; \
764 vec_validate (buffer_fail_counters, num_threads - 1); \
765 } \
766 if (PREDICT_FALSE (tcp_main.buffer_fail_fraction != 0.0)) \
767 { \
768 if (PREDICT_TRUE (buffer_fail_counters[thread_index] > 0)) \
769 { \
770 if ((1.0 / (f32) (buffer_fail_counters[thread_index])) \
771 < tcp_main.buffer_fail_fraction) \
772 { \
773 buffer_fail_counters[thread_index] = 0.0000001; \
774 return -1; \
775 } \
776 } \
777 buffer_fail_counters[thread_index] ++; \
778 } \
779}
780#else
781#define TCP_DBG_BUFFER_ALLOC_MAYBE_FAIL(thread_index)
782#endif
783
Florin Coras6792ec02017-03-13 03:49:51 -0700784#else
Florin Corasf03a59a2017-06-09 21:07:32 -0700785#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Coras6792ec02017-03-13 03:49:51 -0700786#endif
787
Florin Corase69f4952017-03-07 10:06:24 -0800788#endif /* SRC_VNET_TCP_TCP_DEBUG_H_ */
789/*
790 * fd.io coding-style-patch-verification: ON
791 *
792 * Local Variables:
793 * eval: (c-set-style "gnu")
794 * End:
795 */