blob: 8ee716a3c8238560c82cee6eca1805f4768886f4 [file] [log] [blame]
Florin Coras0d427d82018-06-27 03:24:07 -07001/*
Florin Coras5e062572019-03-14 19:07:51 -07002 * Copyright (c) 2018-2019 Cisco and/or its affiliates.
Florin Coras0d427d82018-06-27 03:24:07 -07003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this
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_VCL_VCL_DEBUG_H_
17#define SRC_VCL_VCL_DEBUG_H_
18
19#include <vppinfra/elog.h>
20
21#define VCL_ELOG 0
Florin Coras0e88e852018-09-17 22:09:02 -070022#define VCL_DBG_ON 1
Florin Coras0d427d82018-06-27 03:24:07 -070023
24#define VDBG(_lvl, _fmt, _args...) \
Florin Coras0e88e852018-09-17 22:09:02 -070025 if (VCL_DBG_ON && vcm->debug > _lvl) \
Florin Coras47c40e22018-11-26 17:01:36 -080026 clib_warning ("vcl<%d:%d>: " _fmt, \
27 vcm->workers[__vcl_worker_index].current_pid, \
Florin Coras053a0e42018-11-13 15:52:38 -080028 __vcl_worker_index, ##_args)
29
30#define VWRN(_fmt, _args...) \
Florin Coras47c40e22018-11-26 17:01:36 -080031 clib_warning ("vcl<%d:%d>: " _fmt, \
32 vcm->workers[__vcl_worker_index].current_pid, \
33 __vcl_worker_index, ##_args)
Florin Coras053a0e42018-11-13 15:52:38 -080034
35#define VERR(_fmt, _args...) \
Florin Coras47c40e22018-11-26 17:01:36 -080036 clib_warning ("vcl<%d:%d>: ERROR " _fmt, \
37 vcm->workers[__vcl_worker_index].current_pid, \
Florin Coras053a0e42018-11-13 15:52:38 -080038 __vcl_worker_index, ##_args)
Florin Coras0d427d82018-06-27 03:24:07 -070039
40#define foreach_vcl_dbg_evt \
41 _(INIT, "vcl init track") \
42 _(TIMEOUT, "vcl timeout") \
43 _(DETACH, "vcl detach") \
44 _(SESSION_INIT, "init session track") \
45 _(SESSION_TIMEOUT, "session timeout") \
46 _(CREATE, "session create") \
47 _(CLOSE, "session close") \
48 _(BIND, "session bind") \
49 _(UNBIND, "session unbind") \
50 _(ACCEPT, "session accept") \
51 _(EPOLL_CREATE, "epoll session create") \
52 _(EPOLL_CTLADD, "epoll ctl add") \
53 _(EPOLL_CTLDEL, "epoll ctl del") \
54
55typedef enum vcl_dbg_evt_
56{
57#define _(sym, str) VCL_EVT_##sym,
58 foreach_vcl_dbg_evt
59#undef _
60} vcl_dbg_evt_e;
61
62#if VCL_ELOG
63
64#define VCL_DECLARE_ETD(_s, _e, _size) \
65 struct { u32 data[_size]; } * ed; \
66 ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track) \
67
68#define VCL_EVT_INIT_HANDLER(_vcm, ...) \
69{ \
70 _vcm->elog_track.name = (char *) format (0, "P:%d:C:%d%c", getpid (), \
71 _vcm->my_client_index, 0); \
72 elog_track_register (&_vcm->elog_main, &_vcm->elog_track); \
73 ELOG_TYPE_DECLARE (e) = \
74 { \
75 .format = "connect_vpp:rv:%d", \
76 .format_args = "i4", \
77 }; \
78 struct { u32 data; } *ed; \
79 ed = ELOG_TRACK_DATA (&_vcm->elog_main, e, _vcm->elog_track); \
80 ed->data = (u32) rv; \
81}
82
83#define VCL_EVT_SESSION_INIT_HANDLER(_s, _s_index, ...) \
84{ \
85 _s->elog_track.name = (char *) format (0, "CI:%d:S:%d%c", \
86 vcm->my_client_index, \
87 _s_index, 0); \
88 elog_track_register (&vcm->elog_main, &_s->elog_track); \
89}
90
91#define VCL_EVT_BIND_HANDLER(_s, ...) \
92{ \
93 if (_s->lcl_addr.is_ip4) \
94 { \
95 ELOG_TYPE_DECLARE (_e) = \
96 { \
97 .format = "bind local:%s:%d.%d.%d.%d:%d ", \
98 .format_args = "t1i1i1i1i1i2", \
99 .n_enum_strings = 2, \
100 .enum_strings = {"TCP", "UDP",}, \
101 }; \
102 CLIB_PACKED (struct { \
103 u8 proto; \
104 u8 addr[4]; \
105 u16 port; \
106 }) *ed; \
107 ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track); \
108 ed->proto = _s->proto; \
109 ed->addr[0] = _s->lcl_addr.ip46.ip4.as_u8[0]; \
110 ed->addr[1] = _s->lcl_addr.ip46.ip4.as_u8[1]; \
111 ed->addr[2] = _s->lcl_addr.ip46.ip4.as_u8[2]; \
112 ed->addr[3] = _s->lcl_addr.ip46.ip4.as_u8[3]; \
113 ed->port = clib_net_to_host_u16 (_s->lcl_port); \
114 } \
115 else \
116 { \
117 /* TBD */ \
118 } \
119}
120
121#define VCL_EVT_ACCEPT_HANDLER(_s, _ls, _s_idx, ...) \
122{ \
123 VCL_EVT_SESSION_INIT_HANDLER (_s, _s_idx); \
124 ELOG_TYPE_DECLARE (_e) = \
125 { \
126 .format = "accept: listen_handle:%x from_handle:%x", \
127 .format_args = "i8i8", \
128 }; \
129 struct { u64 handle[2]; } *ed; \
130 ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track); \
131 ed->handle[0] = _ls->vpp_handle; \
132 ed->handle[1] = _s->vpp_handle; \
133 if (_s->peer_addr.is_ip4) \
134 { \
135 ELOG_TYPE_DECLARE (_e) = \
136 { \
137 .format = "accept:S:%x addr:%d.%d.%d.%d:%d", \
138 .format_args = "i8i1i1i1i1i2", \
139 }; \
140 CLIB_PACKED (struct { \
141 u32 s_idx; \
142 u8 addr[4]; \
143 u16 port; \
144 }) * ed; \
145 ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track); \
146 ed->s_idx = _s_idx; \
147 ed->addr[0] = _s->peer_addr.ip46.ip4.as_u8[0]; \
148 ed->addr[1] = _s->peer_addr.ip46.ip4.as_u8[1]; \
149 ed->addr[2] = _s->peer_addr.ip46.ip4.as_u8[2]; \
150 ed->addr[3] = _s->peer_addr.ip46.ip4.as_u8[3]; \
151 ed->port = clib_net_to_host_u16 (_s->peer_port); \
152 } \
153 else \
154 { \
155 /* TBD */ \
156 } \
157}
158
159#define VCL_EVT_CREATE_HANDLER(_s, _proto, _state, _is_nb, _s_idx, ...) \
160{ \
161 VCL_EVT_SESSION_INIT_HANDLER (_s, _s_idx); \
162 ELOG_TYPE_DECLARE (_e) = \
163 { \
164 .format = "create:proto:%d state:%d is_nonblk:%d idx: %d", \
165 .format_args = "i4i4i4i4", \
166 }; \
167 VCL_DECLARE_ETD (_s, _e, 4); \
168 ed->data[0] = _proto; \
169 ed->data[1] = _state; \
170 ed->data[2] = _is_nb; \
171 ed->data[3] = _s_idx; \
172}
173
174#define VCL_EVT_CLOSE_HANDLER(_s, _rv, ...) \
175{ \
176 ELOG_TYPE_DECLARE (_e) = \
177 { \
178 .format = "session_close:rv:%d", \
179 .format_args = "i4", \
180 }; \
181 VCL_DECLARE_ETD (_s, _e, 1); \
182 ed->data[0] = _rv; \
183}
184
185#define VCL_EVT_SESSION_TIMEOUT_HANDLER(_s, _state, ...) \
186{ \
187 ELOG_TYPE_DECLARE (_e) = \
188 { \
189 .format = "ERR: timeout state:%d", \
190 .format_args = "i4", \
191 }; \
192 VCL_DECLARE_ETD (_s, _e, 1); \
193 ed->data[0] = _state; \
194}
195
196#define VCL_EVT_TIMEOUT_HANDLER(_vcm, _state, ...) \
197{ \
198 ELOG_TYPE_DECLARE (_e) = \
199 { \
200 .format = "ERR: timeout state:%d", \
201 .format_args = "i4", \
202 }; \
203 struct { u32 data; } * ed; \
204 ed = ELOG_TRACK_DATA (&_vcm->elog_main, _e, _vcm->elog_track); \
205 ed->data[0] = _state; \
206}
207
208#define VCL_EVT_DETACH_HANDLER(_vcm, ...) \
209{ \
210 ELOG_TYPE_DECLARE (_e) = \
211 { \
212 .format = "app_detach:C:%d", \
213 .format_args = "i4", \
214 }; \
215 struct { u32 data; } * ed; \
216 ed = ELOG_TRACK_DATA (&_vcm->elog_main, _e, _vcm->elog_track); \
217 ed->data = _vcm->my_client_index; \
218}
219
220#define VCL_EVT_UNBIND_HANDLER(_s, ...) \
221{ \
222 ELOG_TYPE_DECLARE (_e) = \
223 { \
224 .format = "unbind: handle:%x", \
225 .format_args = "i8", \
226 }; \
227 struct { u64 data; } * ed; \
228 ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track); \
229 ed->data = _s->vpp_handle; \
230}
231
232#define VCL_EVT_EPOLL_CREATE_HANDLER(_s, _s_idx, ...) \
233{ \
234 VCL_EVT_SESSION_INIT_HANDLER (_s, _s_idx); \
235 ELOG_TYPE_DECLARE (_e) = \
236 { \
237 .format = "create epoll vep_idx: %d", \
238 .format_args = "i4", \
239 }; \
240 VCL_DECLARE_ETD (_s, _e, 1); \
241 ed->data[0] = _s_idx; \
242}
243
244#define VCL_EVT_EPOLL_CTLADD_HANDLER(_s, _evts, _evt_data, ...) \
245{ \
246 ELOG_TYPE_DECLARE (_e) = \
247 { \
248 .format = "epoll_ctladd: events:%x data:%x", \
249 .format_args = "i4", \
250 }; \
251 struct { \
252 u32 events; \
253 u64 event_data; \
254 } * ed; \
255 ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track); \
256 ed->events = _evts; \
257 ed->event_data = _evt_data; \
258}
259
260#define VCL_EVT_EPOLL_CTLDEL_HANDLER(_s, _vep_idx, ...) \
261{ \
262 ELOG_TYPE_DECLARE (_e) = \
263 { \
264 .format = "epoll_ctldel: vep:%d", \
265 .format_args = "i4", \
266 }; \
267 VCL_DECLARE_ETD (_s, _e, 1); \
268 ed->data[0] = _vep_idx; \
269}
270
271#define vcl_elog_init(_vcm) \
272{ \
273 _vcm->elog_main.lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, \
274 CLIB_CACHE_LINE_BYTES);\
275 _vcm->elog_main.lock[0] = 0; \
276 _vcm->elog_main.event_ring_size = _vcm->cfg.event_ring_size; \
277 elog_init (&_vcm->elog_main, _vcm->elog_main.event_ring_size); \
278 elog_enable_disable (&_vcm->elog_main, 1); \
279}
280
281#define vcl_elog_stop(_vcm) \
282{ \
283 clib_error_t *error = 0; \
284 char *chroot_file = (char *) format (0, "%s/%d-%d-vcl-elog%c", \
285 _vcm->cfg.event_log_path, \
286 _vcm->my_client_index, \
287 getpid (), 0); \
288 error = elog_write_file (&_vcm->elog_main, chroot_file, \
289 1 /* flush ring */ ); \
290 if (error) \
291 clib_error_report (error); \
292 clib_warning ("[%d] Event Log:'%s' ", getpid (), chroot_file); \
293 vec_free (chroot_file); \
294}
295
296#define CONCAT_HELPER(_a, _b) _a##_b
297#define CC(_a, _b) CONCAT_HELPER(_a, _b)
298#define vcl_evt(_evt, _args...) CC(_evt, _HANDLER)(_args)
299#else
300#define vcl_evt(_evt, _args...)
301#define vcl_elog_init(_vcm)
302#define vcl_elog_stop(_vcm)
303#endif
304
305#endif /* SRC_VCL_VCL_DEBUG_H_ */
306
307/*
308 * fd.io coding-style-patch-verification: ON
309 *
310 * Local Variables:
311 * eval: (c-set-style "gnu")
312 * End:
313 */