hs-test: fixed timed out tests passing in the CI
[vpp.git] / src / plugins / nat / lib / log.h
1 /*
2  * Copyright (c) 2020 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  * @file
17  * @brief NAT port/address allocation lib
18  */
19 #ifndef included_nat_log_h__
20 #define included_nat_log_h__
21
22 #include <vppinfra/elog.h>
23
24 #include <nat/lib/nat_types.api_types.h>
25
26 #define nat_elog(_pm, _level, _str)                                           \
27   do                                                                          \
28     {                                                                         \
29       if (PREDICT_FALSE (_pm->log_level >= _level))                           \
30         {                                                                     \
31           ELOG_TYPE_DECLARE (e) = {                                           \
32             .format = "nat-msg " _str,                                        \
33             .format_args = "",                                                \
34           };                                                                  \
35           ELOG_DATA (&vlib_global_main.elog_main, e);                         \
36         }                                                                     \
37     }                                                                         \
38   while (0);
39
40 #define nat_elog_addr(_pm, _level, _str, _addr)                               \
41   do                                                                          \
42     {                                                                         \
43       if (PREDICT_FALSE (_pm->log_level >= _level))                           \
44         {                                                                     \
45           ELOG_TYPE_DECLARE (e) = {                                           \
46             .format = "nat-msg " _str " %d.%d.%d.%d",                         \
47             .format_args = "i1i1i1i1",                                        \
48           };                                                                  \
49           CLIB_PACKED (struct {                                               \
50             u8 oct1;                                                          \
51             u8 oct2;                                                          \
52             u8 oct3;                                                          \
53             u8 oct4;                                                          \
54           }) *                                                                \
55             ed;                                                               \
56           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
57           ed->oct4 = _addr >> 24;                                             \
58           ed->oct3 = _addr >> 16;                                             \
59           ed->oct2 = _addr >> 8;                                              \
60           ed->oct1 = _addr;                                                   \
61         }                                                                     \
62     }                                                                         \
63   while (0);
64
65 #define nat_elog_debug_handoff(_pm, _str, _tid, _fib, _src, _dst)             \
66   do                                                                          \
67     {                                                                         \
68       if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG))                    \
69         {                                                                     \
70           ELOG_TYPE_DECLARE (e) = {                                           \
71             .format = "nat-msg " _str " ip src: %d.%d.%d.%d dst: %d.%d.%d.%d" \
72                       " tid from: %d to: %d fib: %d",                         \
73             .format_args = "i1i1i1i1i1i1i1i1i4i4i4",                          \
74           };                                                                  \
75           CLIB_PACKED (struct {                                               \
76             u8 src_oct1;                                                      \
77             u8 src_oct2;                                                      \
78             u8 src_oct3;                                                      \
79             u8 src_oct4;                                                      \
80             u8 dst_oct1;                                                      \
81             u8 dst_oct2;                                                      \
82             u8 dst_oct3;                                                      \
83             u8 dst_oct4;                                                      \
84             u32 ftid;                                                         \
85             u32 ttid;                                                         \
86             u32 fib;                                                          \
87           }) *                                                                \
88             ed;                                                               \
89           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
90           ed->src_oct1 = _src >> 24;                                          \
91           ed->src_oct2 = _src >> 16;                                          \
92           ed->src_oct3 = _src >> 8;                                           \
93           ed->src_oct4 = _src;                                                \
94           ed->dst_oct1 = _dst >> 24;                                          \
95           ed->dst_oct2 = _dst >> 16;                                          \
96           ed->dst_oct3 = _dst >> 8;                                           \
97           ed->dst_oct4 = _dst;                                                \
98           ed->ftid = vlib_get_thread_index ();                                \
99           ed->ttid = _tid;                                                    \
100           ed->fib = _fib;                                                     \
101         }                                                                     \
102     }                                                                         \
103   while (0);
104
105 #define nat_elog_debug_handoff_v2(_pm, _str, _prt, _fib, _src, _dst)          \
106   do                                                                          \
107     {                                                                         \
108       if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG))                    \
109         {                                                                     \
110           ELOG_TYPE_DECLARE (e) = {                                           \
111             .format =                                                         \
112               "nat-msg " _str " ip_src:%d.%d.%d.%d ip_dst:%d.%d.%d.%d"        \
113               " tid:%d prt:%d fib:%d",                                        \
114             .format_args = "i1i1i1i1i1i1i1i1i4i4i4",                          \
115           };                                                                  \
116           CLIB_PACKED (struct {                                               \
117             u8 src_oct1;                                                      \
118             u8 src_oct2;                                                      \
119             u8 src_oct3;                                                      \
120             u8 src_oct4;                                                      \
121             u8 dst_oct1;                                                      \
122             u8 dst_oct2;                                                      \
123             u8 dst_oct3;                                                      \
124             u8 dst_oct4;                                                      \
125             u32 tid;                                                          \
126             u32 prt;                                                          \
127             u32 fib;                                                          \
128           }) *                                                                \
129             ed;                                                               \
130           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
131           ed->src_oct1 = _src >> 24;                                          \
132           ed->src_oct2 = _src >> 16;                                          \
133           ed->src_oct3 = _src >> 8;                                           \
134           ed->src_oct4 = _src;                                                \
135           ed->dst_oct1 = _dst >> 24;                                          \
136           ed->dst_oct2 = _dst >> 16;                                          \
137           ed->dst_oct3 = _dst >> 8;                                           \
138           ed->dst_oct4 = _dst;                                                \
139           ed->tid = vlib_get_thread_index ();                                 \
140           ed->prt = _prt;                                                     \
141           ed->fib = _fib;                                                     \
142         }                                                                     \
143     }                                                                         \
144   while (0);
145
146 #define nat_elog_X1(_pm, _level, _fmt, _arg, _val1)                           \
147   do                                                                          \
148     {                                                                         \
149       if (PREDICT_FALSE (_pm->log_level >= _level))                           \
150         {                                                                     \
151           ELOG_TYPE_DECLARE (e) = {                                           \
152             .format = "nat-msg " _fmt,                                        \
153             .format_args = _arg,                                              \
154           };                                                                  \
155           CLIB_PACKED (struct { typeof (_val1) val1; }) * ed;                 \
156           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
157           ed->val1 = _val1;                                                   \
158         }                                                                     \
159     }                                                                         \
160   while (0);
161
162 #define nat_elog_notice(_pm, nat_elog_str)                                    \
163   nat_elog (_pm, NAT_LOG_INFO, "[notice] " nat_elog_str)
164 #define nat_elog_warn(_pm, nat_elog_str)                                      \
165   nat_elog (_pm, NAT_LOG_WARNING, "[warning] " nat_elog_str)
166 #define nat_elog_err(_pm, nat_elog_str)                                       \
167   nat_elog (_pm, NAT_LOG_ERROR, "[error] " nat_elog_str)
168 #define nat_elog_debug(_pm, nat_elog_str)                                     \
169   nat_elog (_pm, NAT_LOG_DEBUG, "[debug] " nat_elog_str)
170 #define nat_elog_info(_pm, nat_elog_str)                                      \
171   nat_elog (_pm, NAT_LOG_INFO, "[info] " nat_elog_str)
172
173 #define nat_elog_notice_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,           \
174                            nat_elog_val1)                                     \
175   nat_elog_X1 (_pm, NAT_LOG_NOTICE, "[notice] " nat_elog_fmt_str,             \
176                nat_elog_fmt_arg, nat_elog_val1)
177 #define nat_elog_warn_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,             \
178                          nat_elog_val1)                                       \
179   nat_elog_X1 (_pm, NAT_LOG_WARNING, "[warning] " nat_elog_fmt_str,           \
180                nat_elog_fmt_arg, nat_elog_val1)
181 #define nat_elog_err_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,              \
182                         nat_elog_val1)                                        \
183   nat_elog_X1 (_pm, NAT_LOG_ERROR, "[error] " nat_elog_fmt_str,               \
184                nat_elog_fmt_arg, nat_elog_val1)
185 #define nat_elog_debug_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,            \
186                           nat_elog_val1)                                      \
187   nat_elog_X1 (_pm, NAT_LOG_DEBUG, "[debug] " nat_elog_fmt_str,               \
188                nat_elog_fmt_arg, nat_elog_val1)
189 #define nat_elog_info_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,             \
190                          nat_elog_val1)                                       \
191   nat_elog_X1 (_pm, NAT_LOG_INFO, "[info] " nat_elog_fmt_str,                 \
192                nat_elog_fmt_arg, nat_elog_val1)
193
194 #endif /* included_nat_lib_h__ */
195 /*
196  * fd.io coding-style-patch-verification: ON
197  *
198  * Local Variables:
199  * eval: (c-set-style "gnu")
200  * End:
201  */