blob: 4bc6b42e297197a3caa82ec2f2f4f97e27ef6aec [file] [log] [blame]
Florin Corase69f4952017-03-07 10:06:24 -08001/*
2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef SRC_VNET_TCP_TCP_DEBUG_H_
17#define SRC_VNET_TCP_TCP_DEBUG_H_
18
19#include <vlib/vlib.h>
20
21#define TCP_DEBUG (1)
Florin Coras68810622017-07-24 17:40:28 -070022#define TCP_DEBUG_SM (0)
23#define TCP_DEBUG_CC (1)
24#define TCP_DEBUG_CC_STAT (1)
Florin Corase69f4952017-03-07 10:06:24 -080025
26#define foreach_tcp_dbg_evt \
27 _(INIT, "") \
28 _(DEALLOC, "") \
29 _(OPEN, "open") \
30 _(CLOSE, "close") \
31 _(BIND, "bind") \
32 _(UNBIND, "unbind") \
33 _(DELETE, "delete") \
34 _(SYN_SENT, "SYN sent") \
Florin Coras6534b7a2017-07-18 05:38:03 -040035 _(SYNACK_SENT, "SYNACK sent") \
36 _(SYNACK_RCVD, "SYNACK rcvd") \
37 _(SYN_RXT, "SYN retransmit") \
Florin Corase69f4952017-03-07 10:06:24 -080038 _(FIN_SENT, "FIN sent") \
Florin Coras6792ec02017-03-13 03:49:51 -070039 _(ACK_SENT, "ACK sent") \
40 _(DUPACK_SENT, "DUPACK sent") \
Florin Corase69f4952017-03-07 10:06:24 -080041 _(RST_SENT, "RST sent") \
42 _(SYN_RCVD, "SYN rcvd") \
43 _(ACK_RCVD, "ACK rcvd") \
Florin Coras6792ec02017-03-13 03:49:51 -070044 _(DUPACK_RCVD, "DUPACK rcvd") \
Florin Corase69f4952017-03-07 10:06:24 -080045 _(FIN_RCVD, "FIN rcvd") \
46 _(RST_RCVD, "RST rcvd") \
Florin Coras6534b7a2017-07-18 05:38:03 -040047 _(STATE_CHANGE, "state change") \
Florin Corase69f4952017-03-07 10:06:24 -080048 _(PKTIZE, "packetize") \
49 _(INPUT, "in") \
Florin Coras6792ec02017-03-13 03:49:51 -070050 _(SND_WND, "snd_wnd update") \
51 _(OUTPUT, "output") \
52 _(TIMER_POP, "timer pop") \
53 _(CC_RTX, "retransmit") \
54 _(CC_EVT, "cc event") \
55 _(CC_PACK, "cc partial ack") \
Florin Corasf03a59a2017-06-09 21:07:32 -070056 _(CC_STAT, "cc stats") \
57 _(CC_RTO_STAT, "cc rto stats") \
Florin Coras6792ec02017-03-13 03:49:51 -070058 _(SEG_INVALID, "invalid segment") \
Florin Corasc28764f2017-04-26 00:08:42 -070059 _(PAWS_FAIL, "failed paws check") \
Florin Coras6792ec02017-03-13 03:49:51 -070060 _(ACK_RCV_ERR, "invalid ack") \
Florin Coras3e350af2017-03-30 02:54:28 -070061 _(RCV_WND_SHRUNK, "shrunk rcv_wnd") \
Florin Corase69f4952017-03-07 10:06:24 -080062
63typedef enum _tcp_dbg
64{
65#define _(sym, str) TCP_DBG_##sym,
66 foreach_tcp_dbg_evt
67#undef _
68} tcp_dbg_e;
69
70typedef enum _tcp_dbg_evt
71{
72#define _(sym, str) TCP_EVT_##sym,
73 foreach_tcp_dbg_evt
74#undef _
75} tcp_dbg_evt_e;
76
77#if TCP_DEBUG
78
79#define TRANSPORT_DEBUG (1)
80
Florin Corasf03a59a2017-06-09 21:07:32 -070081/*
82 * Infra and evt track setup
83 */
84
Florin 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
414#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...) \
415{ \
416 ELOG_TYPE_DECLARE (_e) = \
417 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400418 .format = "dack-tx: rcv_nxt %u rcv_wnd %u snd_nxt %u av_wnd %u snd_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700419 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700420 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700421 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700422 ed->data[0] = _tc->rcv_nxt - _tc->irs; \
423 ed->data[1] = _tc->rcv_wnd; \
424 ed->data[2] = _tc->snd_nxt - _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400425 ed->data[3] = tcp_available_snd_wnd(_tc); \
Florin Coras3e350af2017-03-30 02:54:28 -0700426 ed->data[4] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700427}
428
Florin Coras3e350af2017-03-30 02:54:28 -0700429#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800430{ \
431 ELOG_TYPE_DECLARE (_e) = \
432 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400433 .format = "ack-rx: %u snd_una %u snd_wnd %u cwnd %u inflight %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->bytes_acked; \
Florin Coras6792ec02017-03-13 03:49:51 -0700438 ed->data[1] = _tc->snd_una - _tc->iss; \
Florin Coras3e350af2017-03-30 02:54:28 -0700439 ed->data[2] = _tc->snd_wnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700440 ed->data[3] = _tc->cwnd; \
441 ed->data[4] = tcp_flight_size(_tc); \
442}
443
444#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...) \
445{ \
446 ELOG_TYPE_DECLARE (_e) = \
447 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400448 .format = "dack-rx: snd_una %u cwnd %u snd_wnd %u flight %u rcv_wnd %u",\
Florin Coras3e350af2017-03-30 02:54:28 -0700449 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700450 }; \
Florin Coras3e350af2017-03-30 02:54:28 -0700451 DECLARE_ETD(_tc, _e, 5); \
Florin Coras6792ec02017-03-13 03:49:51 -0700452 ed->data[0] = _tc->snd_una - _tc->iss; \
Florin Corase69f4952017-03-07 10:06:24 -0800453 ed->data[1] = _tc->cwnd; \
Florin Coras6792ec02017-03-13 03:49:51 -0700454 ed->data[2] = _tc->snd_wnd; \
455 ed->data[3] = tcp_flight_size(_tc); \
Florin Coras3e350af2017-03-30 02:54:28 -0700456 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800457}
458
459#define TCP_EVT_PKTIZE_HANDLER(_tc, ...) \
460{ \
461 ELOG_TYPE_DECLARE (_e) = \
462 { \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400463 .format = "tx: una %u snd_nxt %u space %u flight %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700464 .format_args = "i4i4i4i4i4", \
Florin Corase69f4952017-03-07 10:06:24 -0800465 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700466 DECLARE_ETD(_tc, _e, 5); \
Florin Corase69f4952017-03-07 10:06:24 -0800467 ed->data[0] = _tc->snd_una - _tc->iss; \
468 ed->data[1] = _tc->snd_nxt - _tc->iss; \
Florin Coras4eeeaaf2017-09-05 14:03:37 -0400469 ed->data[2] = tcp_available_output_snd_space (_tc); \
Florin Coras6792ec02017-03-13 03:49:51 -0700470 ed->data[3] = tcp_flight_size (_tc); \
471 ed->data[4] = _tc->rcv_wnd; \
Florin Corase69f4952017-03-07 10:06:24 -0800472}
473
Florin Coras6792ec02017-03-13 03:49:51 -0700474#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...) \
Florin Corase69f4952017-03-07 10:06:24 -0800475{ \
476 ELOG_TYPE_DECLARE (_e) = \
477 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700478 .format = "in: %s len %u written %d rcv_nxt %u rcv_wnd(o) %d", \
Florin Coras6792ec02017-03-13 03:49:51 -0700479 .format_args = "t4i4i4i4i4", \
480 .n_enum_strings = 2, \
481 .enum_strings = { \
482 "order", \
483 "ooo", \
484 }, \
Florin Corase69f4952017-03-07 10:06:24 -0800485 }; \
Florin Coras6792ec02017-03-13 03:49:51 -0700486 DECLARE_ETD(_tc, _e, 5); \
487 ed->data[0] = _type; \
488 ed->data[1] = _len; \
489 ed->data[2] = _written; \
490 ed->data[3] = (_tc->rcv_nxt - _tc->irs) + _written; \
491 ed->data[4] = _tc->rcv_wnd - (_tc->rcv_nxt - _tc->rcv_las); \
Florin Corase69f4952017-03-07 10:06:24 -0800492}
493
494#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...) \
495{ \
496 tcp_connection_t *_tc; \
flyingeagle23e8146b02017-04-26 20:06:52 +0800497 if (_timer_id == TCP_TIMER_RETRANSMIT_SYN \
498 || _timer_id == TCP_TIMER_ESTABLISH) \
Florin Corase69f4952017-03-07 10:06:24 -0800499 { \
500 _tc = tcp_half_open_connection_get (_tc_index); \
501 } \
502 else \
503 { \
Damjan Marion586afd72017-04-05 19:18:20 +0200504 u32 _thread_index = vlib_get_thread_index (); \
Florin Corase69f4952017-03-07 10:06:24 -0800505 _tc = tcp_connection_get (_tc_index, _thread_index); \
506 } \
507 ELOG_TYPE_DECLARE (_e) = \
508 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400509 .format = "timer-pop: %s (%d)", \
Florin Corase69f4952017-03-07 10:06:24 -0800510 .format_args = "t4i4", \
511 .n_enum_strings = 7, \
512 .enum_strings = { \
513 "retransmit", \
514 "delack", \
Florin Coras3e350af2017-03-30 02:54:28 -0700515 "persist", \
Florin Corase69f4952017-03-07 10:06:24 -0800516 "keep", \
517 "waitclose", \
518 "retransmit syn", \
519 "establish", \
520 }, \
521 }; \
Dave Barach2c25a622017-06-26 11:35:07 -0400522 if (_tc) \
523 { \
524 DECLARE_ETD(_tc, _e, 2); \
525 ed->data[0] = _timer_id; \
526 ed->data[1] = _timer_id; \
527 } \
528 else \
529 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400530 clib_warning ("pop %d for unexisting connection %d", _timer_id, \
531 _tc_index); \
Dave Barach2c25a622017-06-26 11:35:07 -0400532 } \
Florin Corase69f4952017-03-07 10:06:24 -0800533}
534
Florin Coras6792ec02017-03-13 03:49:51 -0700535#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...) \
536{ \
537 ELOG_TYPE_DECLARE (_e) = \
538 { \
Florin Coras3e350af2017-03-30 02:54:28 -0700539 .format = "seg-inv: seq %u end %u rcv_las %u rcv_nxt %u rcv_wnd %u",\
Florin Coras6792ec02017-03-13 03:49:51 -0700540 .format_args = "i4i4i4i4i4", \
541 }; \
542 DECLARE_ETD(_tc, _e, 5); \
543 ed->data[0] = _seq - _tc->irs; \
544 ed->data[1] = _end - _tc->irs; \
545 ed->data[2] = _tc->rcv_las - _tc->irs; \
546 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
547 ed->data[4] = _tc->rcv_wnd; \
548}
549
Florin Corasc28764f2017-04-26 00:08:42 -0700550#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...) \
551{ \
552 ELOG_TYPE_DECLARE (_e) = \
553 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400554 .format = "paws-err: seq %u end %u tsval %u tsval_recent %u", \
Florin Corasc28764f2017-04-26 00:08:42 -0700555 .format_args = "i4i4i4i4", \
556 }; \
557 DECLARE_ETD(_tc, _e, 4); \
558 ed->data[0] = _seq - _tc->irs; \
559 ed->data[1] = _end - _tc->irs; \
Florin Coras93992a92017-05-24 18:03:56 -0700560 ed->data[2] = _tc->rcv_opts.tsval; \
Florin Corasc28764f2017-04-26 00:08:42 -0700561 ed->data[3] = _tc->tsval_recent; \
562}
563
Florin Coras6792ec02017-03-13 03:49:51 -0700564#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...) \
565{ \
566 ELOG_TYPE_DECLARE (_e) = \
567 { \
568 .format = "ack-err: %s ack %u snd_una %u snd_nxt %u una_max %u", \
569 .format_args = "t4i4i4i4i4", \
570 .n_enum_strings = 3, \
571 .enum_strings = { \
572 "invalid", \
573 "old", \
574 "future", \
575 }, \
576 }; \
577 DECLARE_ETD(_tc, _e, 5); \
578 ed->data[0] = _type; \
579 ed->data[1] = _ack - _tc->iss; \
580 ed->data[2] = _tc->snd_una - _tc->iss; \
581 ed->data[3] = _tc->snd_nxt - _tc->iss; \
582 ed->data[4] = _tc->snd_una_max - _tc->iss; \
583}
584
Florin Corasf03a59a2017-06-09 21:07:32 -0700585#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...) \
586{ \
587if (_av > 0) \
588{ \
589 ELOG_TYPE_DECLARE (_e) = \
590 { \
591 .format = "huh?: rcv_wnd %u obsd %u av %u rcv_nxt %u rcv_las %u", \
592 .format_args = "i4i4i4i4i4", \
593 }; \
594 DECLARE_ETD(_tc, _e, 5); \
595 ed->data[0] = _tc->rcv_wnd; \
596 ed->data[1] = _obs; \
597 ed->data[2] = _av; \
598 ed->data[3] = _tc->rcv_nxt - _tc->irs; \
599 ed->data[4] = _tc->rcv_las - _tc->irs; \
600} \
601}
602#else
603#define TCP_EVT_ACK_SENT_HANDLER(_tc, ...)
604#define TCP_EVT_DUPACK_SENT_HANDLER(_tc, ...)
Florin Corasf03a59a2017-06-09 21:07:32 -0700605#define TCP_EVT_ACK_RCVD_HANDLER(_tc, ...)
606#define TCP_EVT_DUPACK_RCVD_HANDLER(_tc, ...)
607#define TCP_EVT_PKTIZE_HANDLER(_tc, ...)
608#define TCP_EVT_INPUT_HANDLER(_tc, _type, _len, _written, ...)
609#define TCP_EVT_TIMER_POP_HANDLER(_tc_index, _timer_id, ...)
610#define TCP_EVT_SEG_INVALID_HANDLER(_tc, _seq, _end, ...)
611#define TCP_EVT_PAWS_FAIL_HANDLER(_tc, _seq, _end, ...)
612#define TCP_EVT_ACK_RCV_ERR_HANDLER(_tc, _type, _ack, ...)
613#define TCP_EVT_RCV_WND_SHRUNK_HANDLER(_tc, _obs, _av, ...)
614#endif
615
616/*
617 * State machine verbose
618 */
Florin Coras6534b7a2017-07-18 05:38:03 -0400619#if TCP_DEBUG_SM > 2
Florin Corasf03a59a2017-06-09 21:07:32 -0700620#define TCP_EVT_SND_WND_HANDLER(_tc, ...) \
621{ \
622 ELOG_TYPE_DECLARE (_e) = \
623 { \
Florin Coras6534b7a2017-07-18 05:38:03 -0400624 .format = "snd-wnd update: %u ", \
Florin Corasf03a59a2017-06-09 21:07:32 -0700625 .format_args = "i4", \
626 }; \
627 DECLARE_ETD(_tc, _e, 1); \
628 ed->data[0] = _tc->snd_wnd; \
629}
630
631#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...) \
632{ \
633 ELOG_TYPE_DECLARE (_e) = \
634 { \
635 .format = "out: flags %x, bytes %u", \
636 .format_args = "i4i4", \
637 }; \
638 DECLARE_ETD(_tc, _e, 2); \
639 ed->data[0] = flags; \
640 ed->data[1] = n_bytes; \
641}
642#else
643#define TCP_EVT_SND_WND_HANDLER(_tc, ...)
644#define TCP_EVT_OUTPUT_HANDLER(_tc, flags, n_bytes,...)
645#endif
646
Florin Coras6792ec02017-03-13 03:49:51 -0700647/*
648 * Congestion Control
649 */
650
651#if TCP_DEBUG_CC
652#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...) \
653{ \
654 ELOG_TYPE_DECLARE (_e) = \
655 { \
Florin Coras93992a92017-05-24 18:03:56 -0700656 .format = "rxt: snd_nxt %u offset %u snd %u rxt %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700657 .format_args = "i4i4i4i4", \
658 }; \
659 DECLARE_ETD(_tc, _e, 4); \
660 ed->data[0] = _tc->snd_nxt - _tc->iss; \
661 ed->data[1] = offset; \
662 ed->data[2] = n_bytes; \
Florin Coras93992a92017-05-24 18:03:56 -0700663 ed->data[3] = _tc->snd_rxt_bytes; \
Florin Coras6792ec02017-03-13 03:49:51 -0700664}
665
666#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...) \
667{ \
668 ELOG_TYPE_DECLARE (_e) = \
669 { \
Florin Coras93992a92017-05-24 18:03:56 -0700670 .format = "cc: %s wnd %u snd_cong %u rxt_bytes %u", \
Florin Coras6792ec02017-03-13 03:49:51 -0700671 .format_args = "t4i4i4i4", \
672 .n_enum_strings = 5, \
673 .enum_strings = { \
Florin Coras93992a92017-05-24 18:03:56 -0700674 "fast-rxt", \
675 "rxt-timeout", \
676 "first-rxt", \
Florin Coras6792ec02017-03-13 03:49:51 -0700677 "recovered", \
678 "congestion", \
679 }, \
680 }; \
681 DECLARE_ETD(_tc, _e, 4); \
682 ed->data[0] = _sub_evt; \
683 ed->data[1] = tcp_available_snd_space (_tc); \
684 ed->data[2] = _tc->snd_congestion - _tc->iss; \
Florin Coras93992a92017-05-24 18:03:56 -0700685 ed->data[3] = _tc->snd_rxt_bytes; \
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}
699
Florin Corasf03a59a2017-06-09 21:07:32 -0700700/*
701 * Congestion control stats
702 */
703#if TCP_DEBUG_CC_STAT
Florin Coras6792ec02017-03-13 03:49:51 -0700704
Florin Corasf03a59a2017-06-09 21:07:32 -0700705#define STATS_INTERVAL 1
706
707#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \
Florin Coras3e350af2017-03-30 02:54:28 -0700708{ \
Florin Corasf03a59a2017-06-09 21:07:32 -0700709if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras3e350af2017-03-30 02:54:28 -0700710{ \
711 ELOG_TYPE_DECLARE (_e) = \
712 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700713 .format = "rto_stat: rto %u srtt %u rttvar %u ", \
714 .format_args = "i4i4i4", \
Florin Coras3e350af2017-03-30 02:54:28 -0700715 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700716 DECLARE_ETD(_tc, _e, 3); \
717 ed->data[0] = _tc->rto; \
718 ed->data[1] = _tc->srtt; \
719 ed->data[2] = _tc->rttvar; \
Florin Coras3e350af2017-03-30 02:54:28 -0700720} \
721}
722
Florin Corasf03a59a2017-06-09 21:07:32 -0700723#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \
724{ \
725if (_tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now()) \
Florin Coras6792ec02017-03-13 03:49:51 -0700726{ \
727 ELOG_TYPE_DECLARE (_e) = \
728 { \
Florin Corasf03a59a2017-06-09 21:07:32 -0700729 .format = "cc_stat: cwnd %u flight %u space %u ssthresh %u snd_wnd %u",\
730 .format_args = "i4i4i4i4i4", \
Florin Coras6792ec02017-03-13 03:49:51 -0700731 }; \
Florin Corasf03a59a2017-06-09 21:07:32 -0700732 DECLARE_ETD(_tc, _e, 5); \
733 ed->data[0] = _tc->cwnd; \
734 ed->data[1] = tcp_flight_size (_tc); \
735 ed->data[2] = tcp_snd_space (_tc); \
736 ed->data[3] = _tc->ssthresh; \
737 ed->data[4] = _tc->snd_wnd; \
738 TCP_EVT_CC_RTO_STAT_HANDLER (_tc); \
739 _tc->c_cc_stat_tstamp = tcp_time_now(); \
740} \
Florin Coras6792ec02017-03-13 03:49:51 -0700741}
742
Florin Coras6792ec02017-03-13 03:49:51 -0700743#else
Florin Corasf03a59a2017-06-09 21:07:32 -0700744#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Coras6792ec02017-03-13 03:49:51 -0700745#endif
746
Florin Corase69f4952017-03-07 10:06:24 -0800747#else
Florin Corasf03a59a2017-06-09 21:07:32 -0700748#define TCP_EVT_CC_RTX_HANDLER(_tc, offset, n_bytes, ...)
749#define TCP_EVT_CC_EVT_HANDLER(_tc, _sub_evt, ...)
750#define TCP_EVT_CC_PACK_HANDLER(_tc, ...)
Florin Coras6534b7a2017-07-18 05:38:03 -0400751#define TCP_EVT_CC_STAT_HANDLER(_tc, ...)
Florin Corase69f4952017-03-07 10:06:24 -0800752#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 */