blob: eb318cde4b9688d6ec97e58ca1404103c89955e8 [file] [log] [blame]
Florin Corase69f4952017-03-07 10:06:24 -08001/*
2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef SRC_VNET_TCP_TCP_DEBUG_H_
17#define SRC_VNET_TCP_TCP_DEBUG_H_
18
19#include <vlib/vlib.h>
20
21#define TCP_DEBUG (1)
Florin Coras68810622017-07-24 17:40:28 -070022#define TCP_DEBUG_SM (0)
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 Corase69f4952017-03-07 10:06:24 -080025
26#define foreach_tcp_dbg_evt \
27 _(INIT, "") \
28 _(DEALLOC, "") \
29 _(OPEN, "open") \
30 _(CLOSE, "close") \
31 _(BIND, "bind") \
32 _(UNBIND, "unbind") \
33 _(DELETE, "delete") \
34 _(SYN_SENT, "SYN sent") \
Florin Coras6534b7a2017-07-18 05:38:03 -040035 _(SYNACK_SENT, "SYNACK sent") \
36 _(SYNACK_RCVD, "SYNACK rcvd") \
37 _(SYN_RXT, "SYN retransmit") \
Florin Corase69f4952017-03-07 10:06:24 -080038 _(FIN_SENT, "FIN sent") \
Florin Coras6792ec02017-03-13 03:49:51 -070039 _(ACK_SENT, "ACK sent") \
40 _(DUPACK_SENT, "DUPACK sent") \
Florin Corase69f4952017-03-07 10:06:24 -080041 _(RST_SENT, "RST sent") \
42 _(SYN_RCVD, "SYN rcvd") \
43 _(ACK_RCVD, "ACK rcvd") \
Florin Coras6792ec02017-03-13 03:49:51 -070044 _(DUPACK_RCVD, "DUPACK rcvd") \
Florin Corase69f4952017-03-07 10:06:24 -080045 _(FIN_RCVD, "FIN rcvd") \
46 _(RST_RCVD, "RST rcvd") \
Florin Coras6534b7a2017-07-18 05:38:03 -040047 _(STATE_CHANGE, "state change") \
Florin Corase69f4952017-03-07 10:06:24 -080048 _(PKTIZE, "packetize") \
49 _(INPUT, "in") \
Florin Coras6792ec02017-03-13 03:49:51 -070050 _(SND_WND, "snd_wnd update") \
51 _(OUTPUT, "output") \
52 _(TIMER_POP, "timer pop") \
53 _(CC_RTX, "retransmit") \
54 _(CC_EVT, "cc event") \
55 _(CC_PACK, "cc partial ack") \
Florin Corasf03a59a2017-06-09 21:07:32 -070056 _(CC_STAT, "cc stats") \
57 _(CC_RTO_STAT, "cc rto stats") \
Florin Coras6792ec02017-03-13 03:49:51 -070058 _(SEG_INVALID, "invalid segment") \
Florin Corasc28764f2017-04-26 00:08:42 -070059 _(PAWS_FAIL, "failed paws check") \
Florin Coras6792ec02017-03-13 03:49:51 -070060 _(ACK_RCV_ERR, "invalid ack") \
Florin Coras3e350af2017-03-30 02:54:28 -070061 _(RCV_WND_SHRUNK, "shrunk rcv_wnd") \
Florin Corase69f4952017-03-07 10:06:24 -080062
63typedef enum _tcp_dbg
64{
65#define _(sym, str) TCP_DBG_##sym,
66 foreach_tcp_dbg_evt
67#undef _
68} tcp_dbg_e;
69
70typedef enum _tcp_dbg_evt
71{
72#define _(sym, str) TCP_EVT_##sym,
73 foreach_tcp_dbg_evt
74#undef _
75} tcp_dbg_evt_e;
76
77#if TCP_DEBUG
78
79#define TRANSPORT_DEBUG (1)
80
Florin Corasf03a59a2017-06-09 21:07:32 -070081/*
82 * Infra and evt track setup
83 */
84
Florin Coras9d063042017-09-14 03:08:00 -040085#define TCP_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
Florin Corase69f4952017-03-07 10:06:24 -080086
87#define DECLARE_ETD(_tc, _e, _size) \
88 struct \
89 { \
90 u32 data[_size]; \
91 } * ed; \
92 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
93 _e, _tc->c_elog_track)
94
Florin Coras6534b7a2017-07-18 05:38:03 -040095#define TCP_DBG_IP_TAG_LCL(_tc) \
Florin Corase69f4952017-03-07 10:06:24 -080096{ \
Florin Coras6534b7a2017-07-18 05:38:03 -040097 if (_tc->c_is_ip4) \
98 { \
99 ELOG_TYPE_DECLARE (_e) = \
100 { \
101 .format = "lcl: %d.%d.%d.%d:%d", \
102 .format_args = "i4i4i4i4i4", \
103 }; \
104 DECLARE_ETD(_tc, _e, 5); \
105 ed->data[0] = _tc->c_lcl_ip.ip4.as_u8[0]; \
106 ed->data[1] = _tc->c_lcl_ip.ip4.as_u8[1]; \
107 ed->data[2] = _tc->c_lcl_ip.ip4.as_u8[2]; \
108 ed->data[3] = _tc->c_lcl_ip.ip4.as_u8[3]; \
109 ed->data[4] = clib_net_to_host_u16(_tc->c_lcl_port); \
110 } \
111}
112
113#define TCP_DBG_IP_TAG_RMT(_tc) \
114{ \
115 if (_tc->c_is_ip4) \
116 { \
117 ELOG_TYPE_DECLARE (_e) = \
118 { \
119 .format = "rmt: %d.%d.%d.%d:%d", \
120 .format_args = "i4i4i4i4i4", \
121 }; \
122 DECLARE_ETD(_tc, _e, 5); \
123 ed->data[0] = _tc->c_rmt_ip.ip4.as_u8[0]; \
124 ed->data[1] = _tc->c_rmt_ip.ip4.as_u8[1]; \
125 ed->data[2] = _tc->c_rmt_ip.ip4.as_u8[2]; \
126 ed->data[3] = _tc->c_rmt_ip.ip4.as_u8[3]; \
127 ed->data[4] = clib_net_to_host_u16(_tc->c_rmt_port); \
128 } \
129}
130
131#define TCP_EVT_INIT_HANDLER(_tc, _is_l, ...) \
132{ \
133 char *_fmt = _is_l ? "l[%d].%d:%d%c" : "[%d].%d:%d->.%d:%d%c"; \
134 if (_tc->c_is_ip4) \
135 { \
136 _tc->c_elog_track.name = \
137 (char *) format (0, _fmt, _tc->c_thread_index, \
138 _tc->c_lcl_ip.ip4.as_u8[3], \
139 clib_net_to_host_u16(_tc->c_lcl_port), \
140 _tc->c_rmt_ip.ip4.as_u8[3], \
141 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
142 } \
143 else \
144 _tc->c_elog_track.name = \
145 (char *) format (0, _fmt, _tc->c_thread_index, \
146 _tc->c_lcl_ip.ip6.as_u8[15], \
147 clib_net_to_host_u16(_tc->c_lcl_port), \
148 _tc->c_rmt_ip.ip6.as_u8[15], \
149 clib_net_to_host_u16(_tc->c_rmt_port), 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800150 elog_track_register (&vlib_global_main.elog_main, &_tc->c_elog_track);\
Florin Coras6534b7a2017-07-18 05:38:03 -0400151 TCP_DBG_IP_TAG_LCL(_tc); \
152 TCP_DBG_IP_TAG_RMT(_tc); \
Florin Corase69f4952017-03-07 10:06:24 -0800153}
154
155#define TCP_EVT_DEALLOC_HANDLER(_tc, ...) \
156{ \
157 vec_free (_tc->c_elog_track.name); \
158}
159
160#define TCP_EVT_OPEN_HANDLER(_tc, ...) \
161{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400162 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Corase69f4952017-03-07 10:06:24 -0800163 ELOG_TYPE_DECLARE (_e) = \
164 { \
165 .format = "open: index %d", \
166 .format_args = "i4", \
167 }; \
168 DECLARE_ETD(_tc, _e, 1); \
169 ed->data[0] = _tc->c_c_index; \
170}
171
172#define TCP_EVT_CLOSE_HANDLER(_tc, ...) \
173{ \
174 ELOG_TYPE_DECLARE (_e) = \
175 { \
176 .format = "close: %d", \
177 .format_args = "i4", \
178 }; \
179 DECLARE_ETD(_tc, _e, 1); \
180 ed->data[0] = _tc->c_c_index; \
181}
182
183#define TCP_EVT_BIND_HANDLER(_tc, ...) \
184{ \
Florin Coras6534b7a2017-07-18 05:38:03 -0400185 TCP_EVT_INIT_HANDLER(_tc, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800186 ELOG_TYPE_DECLARE (_e) = \
187 { \
188 .format = "bind: listener %d", \
189 }; \
190 DECLARE_ETD(_tc, _e, 1); \
191 ed->data[0] = _tc->c_c_index; \
192}
193
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400194#define TCP_EVT_SYN_RCVD_HANDLER(_tc,_init, ...) \
Florin Coras68810622017-07-24 17:40:28 -0700195{ \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400196 if (_init) \
197 TCP_EVT_INIT_HANDLER(_tc, 0); \
Florin Coras68810622017-07-24 17:40:28 -0700198 ELOG_TYPE_DECLARE (_e) = \
199 { \
200 .format = "syn-rx: irs %u", \
201 .format_args = "i4", \
202 }; \
203 DECLARE_ETD(_tc, _e, 1); \
204 ed->data[0] = _tc->irs; \
205 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
206}
207
Florin Corase69f4952017-03-07 10:06:24 -0800208#define TCP_EVT_UNBIND_HANDLER(_tc, ...) \
209{ \
210 TCP_EVT_DEALLOC_HANDLER(_tc); \
211 ELOG_TYPE_DECLARE (_e) = \
212 { \
213 .format = "unbind: listener %d", \
214 }; \
215 DECLARE_ETD(_tc, _e, 1); \
216 ed->data[0] = _tc->c_c_index; \
217 TCP_EVT_DEALLOC_HANDLER(_tc); \
218}
219
220#define TCP_EVT_DELETE_HANDLER(_tc, ...) \
221{ \
222 ELOG_TYPE_DECLARE (_e) = \
223 { \
224 .format = "delete: %d", \
225 .format_args = "i4", \
226 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700227 DECLARE_ETD(_tc, _e, 1); \
Florin Corase69f4952017-03-07 10:06:24 -0800228 ed->data[0] = _tc->c_c_index; \
229 TCP_EVT_DEALLOC_HANDLER(_tc); \
230}
231
Florin Corasf03a59a2017-06-09 21:07:32 -0700232#define CONCAT_HELPER(_a, _b) _a##_b
233#define CC(_a, _b) CONCAT_HELPER(_a, _b)
234#define TCP_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
235#else
236#define TCP_EVT_DBG(_evt, _args...)
Florin Coras9d063042017-09-14 03:08:00 -0400237#define TCP_DBG(_fmt, _args...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700238#endif
239
240/*
241 * State machine
242 */
243#if TCP_DEBUG_SM
244
Florin Coras6534b7a2017-07-18 05:38:03 -0400245#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...) \
246{ \
247 ELOG_TYPE_DECLARE (_e) = \
248 { \
249 .format = "state: %s", \
250 .format_args = "t4", \
251 .n_enum_strings = 11, \
252 .enum_strings = { \
253 "closed", \
254 "listen", \
255 "syn-sent", \
256 "syn-rcvd", \
257 "established", \
258 "close_wait", \
259 "fin-wait-1", \
260 "last-ack", \
261 "closing", \
262 "fin-wait-2", \
263 "time-wait", \
264 }, \
265 }; \
266 DECLARE_ETD(_tc, _e, 1); \
267 ed->data[0] = _tc->state; \
268}
269
Florin Coras6534b7a2017-07-18 05:38:03 -0400270#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...) \
271{ \
272 ELOG_TYPE_DECLARE (_e) = \
273 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400274 .format = "syn-tx: iss %u snd_una %u snd_una_max %u snd_nxt %u", \
275 .format_args = "i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400276 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400277 DECLARE_ETD(_tc, _e, 4); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400278 ed->data[0] = _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400279 ed->data[1] = _tc->snd_una - _tc->iss; \
280 ed->data[2] = _tc->snd_una_max - _tc->iss; \
281 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400282 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
283}
284
285#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...) \
286{ \
287 ELOG_TYPE_DECLARE (_e) = \
288 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400289 .format = "synack-tx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
290 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400291 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400292 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400293 ed->data[0] = _tc->iss; \
294 ed->data[1] = _tc->irs; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400295 ed->data[2] = _tc->snd_una - _tc->iss; \
296 ed->data[3] = _tc->snd_nxt - _tc->iss; \
297 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400298}
299
300#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...) \
301{ \
302 ELOG_TYPE_DECLARE (_e) = \
303 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400304 .format = "synack-rx: iss %u irs %u snd_una %u snd_nxt %u rcv_nxt %u",\
305 .format_args = "i4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400306 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400307 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400308 ed->data[0] = _tc->iss; \
309 ed->data[1] = _tc->irs; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400310 ed->data[2] = _tc->snd_una - _tc->iss; \
311 ed->data[3] = _tc->snd_nxt - _tc->iss; \
312 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400313 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
314}
315
316#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...) \
317{ \
318 ELOG_TYPE_DECLARE (_e) = \
319 { \
320 .format = "fin-tx: snd_nxt %d rcv_nxt %d", \
321 .format_args = "i4i4", \
322 }; \
323 DECLARE_ETD(_tc, _e, 2); \
324 ed->data[0] = _tc->snd_nxt - _tc->iss; \
325 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
326}
327
328#define TCP_EVT_RST_SENT_HANDLER(_tc, ...) \
329{ \
330 ELOG_TYPE_DECLARE (_e) = \
331 { \
332 .format = "rst-tx: snd_nxt %d rcv_nxt %d", \
333 .format_args = "i4i4", \
334 }; \
335 DECLARE_ETD(_tc, _e, 2); \
336 ed->data[0] = _tc->snd_nxt - _tc->iss; \
337 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
338 TCP_EVT_STATE_CHANGE_HANDLER(_tc); \
339}
340
341#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...) \
342{ \
343 ELOG_TYPE_DECLARE (_e) = \
344 { \
345 .format = "fin-rx: snd_nxt %d rcv_nxt %d", \
346 .format_args = "i4i4", \
347 }; \
348 DECLARE_ETD(_tc, _e, 2); \
349 ed->data[0] = _tc->snd_nxt - _tc->iss; \
350 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
351}
352
353#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...) \
354{ \
355 ELOG_TYPE_DECLARE (_e) = \
356 { \
357 .format = "rst-rx: snd_nxt %d rcv_nxt %d", \
358 .format_args = "i4i4", \
359 }; \
360 DECLARE_ETD(_tc, _e, 2); \
361 ed->data[0] = _tc->snd_nxt - _tc->iss; \
362 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
363}
364
365#define TCP_EVT_SYN_RXT_HANDLER(_tc, _type, ...) \
366{ \
367 ELOG_TYPE_DECLARE (_e) = \
368 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400369 .format = "%s-rxt: iss %u irs %u snd_nxt %u rcv_nxt %u", \
370 .format_args = "t4i4i4i4i4", \
Florin Coras6534b7a2017-07-18 05:38:03 -0400371 .n_enum_strings = 2, \
372 .enum_strings = { \
373 "syn", \
374 "syn-ack", \
375 }, \
376 }; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400377 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6534b7a2017-07-18 05:38:03 -0400378 ed->data[0] = _type; \
379 ed->data[1] = _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400380 ed->data[2] = _tc->irs; \
381 ed->data[3] = _tc->snd_nxt - _tc->iss; \
382 ed->data[4] = _tc->rcv_nxt - _tc->irs; \
Florin Coras6534b7a2017-07-18 05:38:03 -0400383}
384
385#else
386#define TCP_EVT_SYN_SENT_HANDLER(_tc, ...)
387#define TCP_EVT_SYNACK_SENT_HANDLER(_tc, ...)
388#define TCP_EVT_SYNACK_RCVD_HANDLER(_tc, ...)
389#define TCP_EVT_SYN_RXT_HANDLER(_tc, ...)
390#define TCP_EVT_FIN_SENT_HANDLER(_tc, ...)
391#define TCP_EVT_RST_SENT_HANDLER(_tc, ...)
392#define TCP_EVT_FIN_RCVD_HANDLER(_tc, ...)
393#define TCP_EVT_RST_RCVD_HANDLER(_tc, ...)
394#define TCP_EVT_STATE_CHANGE_HANDLER(_tc, ...)
395#endif
396
397#if TCP_DEBUG_SM > 1
398
Florin Coras6792ec02017-03-13 03:49:51 -0700399#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...) \
400{ \
401 ELOG_TYPE_DECLARE (_e) = \
402 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400403 .format = "ack-tx: acked %u rcv_nxt %u rcv_wnd %u snd_nxt %u snd_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700404 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700405 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700406 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700407 ed->data[0] = _tc->rcv_nxt - _tc->rcv_las; \
408 ed->data[1] = _tc->rcv_nxt - _tc->irs; \
409 ed->data[2] = _tc->rcv_wnd; \
410 ed->data[3] = _tc->snd_nxt - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700411 ed->data[4] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700412}
413
Florin Coras3e350af2017-03-30 02:54:28 -0700414#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800415{ \
416 ELOG_TYPE_DECLARE (_e) = \
417 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400418 .format = "ack-rx: %u snd_una %u snd_wnd %u cwnd %u inflight %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700419 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800420 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700421 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800422 ed->data[0] = _tc->bytes_acked; \
Florin Coras6792ec02017-03-13 03:49:51 -0700423 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700424 ed->data[2] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700425 ed->data[3] = _tc->cwnd; \
426 ed->data[4] = tcp_flight_size(_tc); \
427}
428
Florin Corase69f4952017-03-07 10:06:24 -0800429#define TCP_EVT_PKTIZE_HANDLER(_tc, ...) \
430{ \
431 ELOG_TYPE_DECLARE (_e) = \
432 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400433 .format = "tx: una %u snd_nxt %u space %u flight %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700434 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800435 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700436 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800437 ed->data[0] = _tc->snd_una - _tc->iss; \
438 ed->data[1] = _tc->snd_nxt - _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400439 ed->data[2] = tcp_available_output_snd_space (_tc); \
Florin Coras6792ec02017-03-13 03:49:51 -0700440 ed->data[3] = tcp_flight_size (_tc); \
441 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800442}
443
Florin Coras6792ec02017-03-13 03:49:51 -0700444#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800445{ \
446 ELOG_TYPE_DECLARE (_e) = \
447 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700448 .format = "in: %s len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
Florin Coras6792ec02017-03-13 03:49:51 -0700449 .format_args = "t4i4i4i4i4", \
450 .n_enum_strings = 2, \
451 .enum_strings = { \
452 "order", \
453 "ooo", \
454 }, \
Florin Corase69f4952017-03-07 10:06:24 -0800455 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700456 DECLARE_ETD(_tc, _e, 5); \
457 ed->data[0] = _type; \
458 ed->data[1] = _len; \
459 ed->data[2] = _written; \
460 ed->data[3] = (_tc->rcv_nxt - _tc->irs) + _written; \
461 ed->data[4] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las); \
Florin Corase69f4952017-03-07 10:06:24 -0800462}
463
464#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...) \
465{ \
466 tcp_connection_t *_tc; \
flyingeagle23e8146b02017-04-26 20:06:52 +0800467 if (_timer_id == TCP_TIMER_RETRANSMIT_SYN \
468 || _timer_id == TCP_TIMER_ESTABLISH) \
Florin Corase69f4952017-03-07 10:06:24 -0800469 { \
470 _tc = tcp_half_open_connection_get (_tc_index); \
471 } \
472 else \
473 { \
Damjan Marion586afd72017-04-05 19:18:20 +0200474 u32 _thread_index = vlib_get_thread_index (); \
Florin Corase69f4952017-03-07 10:06:24 -0800475 _tc = tcp_connection_get (_tc_index, _thread_index); \
476 } \
477 ELOG_TYPE_DECLARE (_e) = \
478 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400479 .format = "timer-pop: %s (%d)", \
Florin Corase69f4952017-03-07 10:06:24 -0800480 .format_args = "t4i4", \
481 .n_enum_strings = 7, \
482 .enum_strings = { \
483 "retransmit", \
484 "delack", \
Florin Coras3e350af2017-03-30 02:54:28 -0700485 "persist", \
Florin Corase69f4952017-03-07 10:06:24 -0800486 "keep", \
487 "waitclose", \
488 "retransmit syn", \
489 "establish", \
490 }, \
491 }; \
Dave Barach2c25a622017-06-26 11:35:07 -0400492 if (_tc) \
493 { \
494 DECLARE_ETD(_tc, _e, 2); \
495 ed->data[0] = _timer_id; \
496 ed->data[1] = _timer_id; \
497 } \
498 else \
499 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400500 clib_warning ("pop %d for unexisting connection %d", _timer_id, \
501 _tc_index); \
Dave Barach2c25a622017-06-26 11:35:07 -0400502 } \
Florin Corase69f4952017-03-07 10:06:24 -0800503}
504
Florin Coras6792ec02017-03-13 03:49:51 -0700505#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...) \
506{ \
507 ELOG_TYPE_DECLARE (_e) = \
508 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700509 .format = "seg-inv: seq %u end %u rcv_las %u rcv_nxt %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700510 .format_args = "i4i4i4i4i4", \
511 }; \
512 DECLARE_ETD(_tc, _e, 5); \
513 ed->data[0] = _seq - _tc->irs; \
514 ed->data[1] = _end - _tc->irs; \
515 ed->data[2] = _tc->rcv_las - _tc->irs; \
516 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
517 ed->data[4] = _tc->rcv_wnd; \
518}
519
Florin Corasc28764f2017-04-26 00:08:42 -0700520#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...) \
521{ \
522 ELOG_TYPE_DECLARE (_e) = \
523 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400524 .format = "paws-err: seq %u end %u tsval %u tsval_recent %u", \
Florin Corasc28764f2017-04-26 00:08:42 -0700525 .format_args = "i4i4i4i4", \
526 }; \
527 DECLARE_ETD(_tc, _e, 4); \
528 ed->data[0] = _seq - _tc->irs; \
529 ed->data[1] = _end - _tc->irs; \
Florin Coras93992a92017-05-24 18:03:56 -0700530 ed->data[2] = _tc->rcv_opts.tsval; \
Florin Corasc28764f2017-04-26 00:08:42 -0700531 ed->data[3] = _tc->tsval_recent; \
532}
533
Florin Coras6792ec02017-03-13 03:49:51 -0700534#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...) \
535{ \
536 ELOG_TYPE_DECLARE (_e) = \
537 { \
538 .format = "ack-err: %s ack %u snd_una %u snd_nxt %u una_max %u", \
539 .format_args = "t4i4i4i4i4", \
540 .n_enum_strings = 3, \
541 .enum_strings = { \
542 "invalid", \
543 "old", \
544 "future", \
545 }, \
546 }; \
547 DECLARE_ETD(_tc, _e, 5); \
548 ed->data[0] = _type; \
549 ed->data[1] = _ack - _tc->iss; \
550 ed->data[2] = _tc->snd_una - _tc->iss; \
551 ed->data[3] = _tc->snd_nxt - _tc->iss; \
552 ed->data[4] = _tc->snd_una_max - _tc->iss; \
553}
554
Florin Corasf03a59a2017-06-09 21:07:32 -0700555#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...) \
556{ \
557if (_av > 0) \
558{ \
559 ELOG_TYPE_DECLARE (_e) = \
560 { \
561 .format = "huh?: rcv_wnd %u obsd %u av %u rcv_nxt %u rcv_las %u", \
562 .format_args = "i4i4i4i4i4", \
563 }; \
564 DECLARE_ETD(_tc, _e, 5); \
565 ed->data[0] = _tc->rcv_wnd; \
566 ed->data[1] = _obs; \
567 ed->data[2] = _av; \
568 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
569 ed->data[4] = _tc->rcv_las - _tc->irs; \
570} \
571}
572#else
573#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700574#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700575#define TCP_EVT_PKTIZE_HANDLER(_tc, ...)
576#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...)
577#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)
578#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...)
579#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...)
580#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...)
581#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...)
582#endif
583
584/*
585 * State machine verbose
586 */
Florin Coras6534b7a2017-07-18 05:38:03 -0400587#if TCP_DEBUG_SM > 2
Florin Corasf03a59a2017-06-09 21:07:32 -0700588#define TCP_EVT_SND_WND_HANDLER(_tc, ...) \
589{ \
590 ELOG_TYPE_DECLARE (_e) = \
591 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400592 .format = "snd-wnd update: %u ", \
Florin Corasf03a59a2017-06-09 21:07:32 -0700593 .format_args = "i4", \
594 }; \
595 DECLARE_ETD(_tc, _e, 1); \
596 ed->data[0] = _tc->snd_wnd; \
597}
598
599#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...) \
600{ \
601 ELOG_TYPE_DECLARE (_e) = \
602 { \
603 .format = "out: flags %x, bytes %u", \
604 .format_args = "i4i4", \
605 }; \
606 DECLARE_ETD(_tc, _e, 2); \
607 ed->data[0] = flags; \
608 ed->data[1] = n_bytes; \
609}
610#else
611#define TCP_EVT_SND_WND_HANDLER(_tc, ...)
612#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)
613#endif
614
Florin Coras6792ec02017-03-13 03:49:51 -0700615/*
616 * Congestion Control
617 */
618
619#if TCP_DEBUG_CC
Florin Corasf1762d62017-09-24 19:43:08 -0400620
621#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
622{ \
623 ELOG_TYPE_DECLARE (_e) = \
624 { \
625 .format = "cc: %s wnd %u snd_cong %u rxt_bytes %u", \
626 .format_args = "t4i4i4i4", \
627 .n_enum_strings = 6, \
628 .enum_strings = { \
629 "fast-rxt", \
630 "rxt-timeout", \
631 "first-rxt", \
632 "recovered", \
633 "congestion", \
634 "undo", \
635 }, \
636 }; \
637 DECLARE_ETD(_tc, _e, 4); \
638 ed->data[0] = _sub_evt; \
639 ed->data[1] = tcp_available_snd_space (_tc); \
640 ed->data[2] = _tc->snd_congestion - _tc->iss; \
641 ed->data[3] = _tc->snd_rxt_bytes; \
642}
643
Florin Coras6792ec02017-03-13 03:49:51 -0700644#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...) \
645{ \
646 ELOG_TYPE_DECLARE (_e) = \
647 { \
Florin Coras93992a92017-05-24 18:03:56 -0700648 .format = "rxt: snd_nxt %u offset %u snd %u rxt %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700649 .format_args = "i4i4i4i4", \
650 }; \
651 DECLARE_ETD(_tc, _e, 4); \
652 ed->data[0] = _tc->snd_nxt - _tc->iss; \
653 ed->data[1] = offset; \
654 ed->data[2] = n_bytes; \
Florin Coras93992a92017-05-24 18:03:56 -0700655 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Coras6792ec02017-03-13 03:49:51 -0700656}
657
Florin Corasf1762d62017-09-24 19:43:08 -0400658#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...) \
Florin Coras6792ec02017-03-13 03:49:51 -0700659{ \
660 ELOG_TYPE_DECLARE (_e) = \
661 { \
Florin Corasf1762d62017-09-24 19:43:08 -0400662 .format = "dack-tx: rcv_nxt %u rcv_wnd %u snd_nxt %u av_wnd %u snd_wnd %u",\
663 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700664 }; \
Florin Corasf1762d62017-09-24 19:43:08 -0400665 DECLARE_ETD(_tc, _e, 5); \
666 ed->data[0] = _tc->rcv_nxt - _tc->irs; \
667 ed->data[1] = _tc->rcv_wnd; \
668 ed->data[2] = _tc->snd_nxt - _tc->iss; \
669 ed->data[3] = tcp_available_snd_wnd(_tc); \
670 ed->data[4] = _tc->snd_wnd; \
671}
672
673#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...) \
674{ \
675 ELOG_TYPE_DECLARE (_e) = \
676 { \
677 .format = "dack-rx: snd_una %u cwnd %u snd_wnd %u flight %u rcv_wnd %u",\
678 .format_args = "i4i4i4i4i4", \
679 }; \
680 DECLARE_ETD(_tc, _e, 5); \
681 ed->data[0] = _tc->snd_una - _tc->iss; \
682 ed->data[1] = _tc->cwnd; \
683 ed->data[2] = _tc->snd_wnd; \
684 ed->data[3] = tcp_flight_size(_tc); \
685 ed->data[4] = _tc->rcv_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700686}
687
688#define TCP_EVT_CC_PACK_HANDLER(_tc, ...) \
689{ \
690 ELOG_TYPE_DECLARE (_e) = \
691 { \
692 .format = "pack: snd_una %u snd_una_max %u", \
693 .format_args = "i4i4", \
694 }; \
695 DECLARE_ETD(_tc, _e, 2); \
696 ed->data[0] = _tc->snd_una - _tc->iss; \
697 ed->data[1] = _tc->snd_una_max - _tc->iss; \
698}
Florin Corasf1762d62017-09-24 19:43:08 -0400699#else
700#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...)
701#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...)
702#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...)
703#define TCP_EVT_CC_PACK_HANDLER(_tc, ...)
704#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...)
705#endif
Florin Coras6792ec02017-03-13 03:49:51 -0700706
Florin Corasf03a59a2017-06-09 21:07:32 -0700707/*
708 * Congestion control stats
709 */
710#if TCP_DEBUG_CC_STAT
Florin Coras6792ec02017-03-13 03:49:51 -0700711
Florin Corasf03a59a2017-06-09 21:07:32 -0700712#define STATS_INTERVAL 1
713
714#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \
Florin Coras3e350af2017-03-30 02:54:28 -0700715{ \
Florin Corasf03a59a2017-06-09 21:07:32 -0700716if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras3e350af2017-03-30 02:54:28 -0700717{ \
718 ELOG_TYPE_DECLARE (_e) = \
719 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700720 .format = "rto_stat: rto %u srtt %u rttvar %u ", \
721 .format_args = "i4i4i4", \
Florin Coras3e350af2017-03-30 02:54:28 -0700722 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700723 DECLARE_ETD(_tc, _e, 3); \
724 ed->data[0] = _tc->rto; \
725 ed->data[1] = _tc->srtt; \
726 ed->data[2] = _tc->rttvar; \
Florin Coras3e350af2017-03-30 02:54:28 -0700727} \
728}
729
Florin Corasf03a59a2017-06-09 21:07:32 -0700730#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \
731{ \
732if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras6792ec02017-03-13 03:49:51 -0700733{ \
734 ELOG_TYPE_DECLARE (_e) = \
735 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700736 .format = "cc_stat: cwnd %u flight %u space %u ssthresh %u snd_wnd %u",\
737 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700738 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700739 DECLARE_ETD(_tc, _e, 5); \
740 ed->data[0] = _tc->cwnd; \
741 ed->data[1] = tcp_flight_size (_tc); \
742 ed->data[2] = tcp_snd_space (_tc); \
743 ed->data[3] = _tc->ssthresh; \
744 ed->data[4] = _tc->snd_wnd; \
745 TCP_EVT_CC_RTO_STAT_HANDLER (_tc); \
746 _tc->c_cc_stat_tstamp = tcp_time_now(); \
747} \
Florin Coras6792ec02017-03-13 03:49:51 -0700748}
749
Florin Coras6792ec02017-03-13 03:49:51 -0700750#else
Florin Corasf03a59a2017-06-09 21:07:32 -0700751#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Coras6792ec02017-03-13 03:49:51 -0700752#endif
753
Florin Corase69f4952017-03-07 10:06:24 -0800754#endif /* SRC_VNET_TCP_TCP_DEBUG_H_ */
755/*
756 * fd.io coding-style-patch-verification: ON
757 *
758 * Local Variables:
759 * eval: (c-set-style "gnu")
760 * End:
761 */