api: refactor format_vl_api_prefix_t return keys
[vpp.git] / src / plugins / gbp / gbp_api_print.h
1 /*
2  * Copyright (c) 2019 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 __GBP_API_PRINT_H__
17 #define __GBP_API_PRINT_H__
18
19 #include <vpp/api/types.h>
20
21 /* Macro to finish up custom dump fns */
22 #define PRINT_S \
23     vec_add1 (s, 0);                            \
24     vl_print (handle, (char *)s);               \
25     vec_free (s);
26
27 static inline void *
28 vl_api_gbp_bridge_domain_add_t_print (vl_api_gbp_bridge_domain_add_t * a,
29                                       void *handle)
30 {
31   u8 *s = 0;
32
33   s = format (s, "SCRIPT: gbp_bridge_domain_add ");
34   s = format (s, "bd_id %d ", ntohl (a->bd.bd_id));
35   s = format (s, "flags %d ", ntohl (a->bd.flags));
36   s = format (s, "uu-fwd %d ", ntohl (a->bd.uu_fwd_sw_if_index));
37   s = format (s, "bvi %d ", ntohl (a->bd.bvi_sw_if_index));
38   s = format (s, "bm-flood %d", ntohl (a->bd.bm_flood_sw_if_index));
39
40   s = format (s, "\n");
41
42   PRINT_S;
43
44   return handle;
45 }
46
47 static inline void *
48 vl_api_gbp_bridge_domain_del_t_print (vl_api_gbp_bridge_domain_del_t * a,
49                                       void *handle)
50 {
51   u8 *s = 0;
52
53   s = format (s, "SCRIPT: gbp_bridge_domain_del ");
54   s = format (s, "bd_id %d ", ntohl (a->bd_id));
55
56   s = format (s, "\n");
57
58   PRINT_S;
59
60   return handle;
61 }
62
63 static inline void *
64 vl_api_gbp_route_domain_add_t_print (vl_api_gbp_route_domain_add_t * a,
65                                      void *handle)
66 {
67   u8 *s = 0;
68
69   s = format (s, "SCRIPT: gbp_route_domain_add ");
70   s = format (s, "rd_id %d ", ntohl (a->rd.rd_id));
71   s = format (s, "ip4_table_id %d ", ntohl (a->rd.ip4_table_id));
72   s = format (s, "ip6_table_id %d ", ntohl (a->rd.ip6_table_id));
73   s = format (s, "ip4_uu_sw_if_index %d ", ntohl (a->rd.ip4_uu_sw_if_index));
74   s = format (s, "ip6_uu_sw_if_index %d", ntohl (a->rd.ip6_uu_sw_if_index));
75
76   s = format (s, "\n");
77
78   PRINT_S;
79
80   return handle;
81 }
82
83 static inline void *
84 vl_api_gbp_route_domain_del_t_print (vl_api_gbp_route_domain_del_t * a,
85                                      void *handle)
86 {
87   u8 *s = 0;
88
89   s = format (s, "SCRIPT: gbp_route_domain_del ");
90   s = format (s, "rd_id %d", ntohl (a->rd_id));
91
92   s = format (s, "\n");
93
94   PRINT_S;
95
96   return handle;
97 }
98
99 static inline void *
100 vl_api_gbp_endpoint_add_t_print (vl_api_gbp_endpoint_add_t * a, void *handle)
101 {
102   u8 *s = 0;
103
104   s = format (s, "SCRIPT: gbp_endpoint_add ");
105   s = format (s, "sw_if_index %d ", ntohl (a->endpoint.sw_if_index));
106   s = format (s, "sclass %d ", ntohs (a->endpoint.sclass));
107   s = format (s, "flags %x ", ntohl (a->endpoint.flags));
108   s = format (s, "mac %U ", format_vl_api_mac_address, a->endpoint.mac);
109   s =
110     format (s, "\n\ttun\n\t\t src %U", format_vl_api_address,
111             &a->endpoint.tun.src);
112   s =
113     format (s, "\n\t\t dst %U ", format_vl_api_address, &a->endpoint.tun.dst);
114
115   if (a->endpoint.n_ips)
116     s = format (s, "\n\t ips");
117   for (int i = 0; i < a->endpoint.n_ips; i++)
118     s = format (s, "\n\t\t %U", format_vl_api_address, &a->endpoint.ips[i]);
119
120   s = format (s, "\n");
121
122   PRINT_S;
123
124   return handle;
125 }
126
127 static inline void *
128 vl_api_gbp_endpoint_del_t_print (vl_api_gbp_endpoint_del_t * a, void *handle)
129 {
130   u8 *s = 0;
131
132   s = format (s, "SCRIPT: gbp_endpoint_del ");
133   s = format (s, "handle %d", ntohl (a->handle));
134
135   s = format (s, "\n");
136
137   PRINT_S;
138
139   return handle;
140 }
141
142 static inline void *
143 vl_api_gbp_endpoint_group_add_t_print (vl_api_gbp_endpoint_group_add_t * a,
144                                        void *handle)
145 {
146   u8 *s = 0;
147
148   s = format (s, "SCRIPT: gbp_endpoint_group_add ");
149   s = format (s, "vnid %d ", ntohl (a->epg.vnid));
150   s = format (s, "sclass %d ", ntohs (a->epg.sclass));
151   s = format (s, "bd_id %d ", ntohl (a->epg.bd_id));
152   s = format (s, "rd_id %d ", ntohl (a->epg.rd_id));
153   s = format (s, "uplink_sw_if_index %d ", ntohl (a->epg.uplink_sw_if_index));
154   s =
155     format (s, "remote_ep_timeout %d",
156             ntohl (a->epg.retention.remote_ep_timeout));
157
158   s = format (s, "\n");
159
160   PRINT_S;
161
162   return handle;
163 }
164
165 static inline void *
166 vl_api_gbp_endpoint_group_del_t_print (vl_api_gbp_endpoint_group_del_t * a,
167                                        void *handle)
168 {
169   u8 *s = 0;
170
171   s = format (s, "SCRIPT: gbp_endpoint_group_del ");
172   s = format (s, "sclass %d ", ntohs (a->sclass));
173
174   s = format (s, "\n");
175
176   PRINT_S;
177
178   return handle;
179 }
180
181 static inline void *
182 vl_api_gbp_recirc_add_del_t_print (vl_api_gbp_recirc_add_del_t * a,
183                                    void *handle)
184 {
185   u8 *s = 0;
186
187   s = format (s, "SCRIPT: gbp_recirc_add_del ");
188
189   if (a->is_add)
190     s = format (s, "add ");
191   else
192     s = format (s, "del ");
193   s = format (s, "sw_if_index %d ", ntohl (a->recirc.sw_if_index));
194   s = format (s, "sclass %d ", ntohs (a->recirc.sclass));
195   s = format (s, "is_ext %d ", a->recirc.is_ext);
196
197   s = format (s, "\n");
198
199   PRINT_S;
200
201   return handle;
202 }
203
204 static inline void *
205 vl_api_gbp_subnet_add_del_t_print (vl_api_gbp_subnet_add_del_t * a,
206                                    void *handle)
207 {
208   u8 *s = 0;
209
210   s = format (s, "SCRIPT: gbp_subnet_add_del ");
211   if (a->is_add)
212     s = format (s, "add ");
213   else
214     s = format (s, "del ");
215   s = format (s, "rd_id %d ", ntohl (a->subnet.rd_id));
216   s = format (s, "sw_if_index %d ", ntohl (a->subnet.sw_if_index));
217   s = format (s, "sclass %d ", ntohs (a->subnet.sclass));
218   s = format (s, "type %d ", ntohl (a->subnet.type));
219   s =
220     format (s, "prefix %U/%d", format_vl_api_address,
221             &a->subnet.prefix.address, a->subnet.prefix.len);
222
223   s = format (s, "\n");
224
225   PRINT_S;
226
227   return handle;
228 }
229
230 static inline void *
231 vl_api_gbp_contract_add_del_t_print (vl_api_gbp_contract_add_del_t * a,
232                                      void *handle)
233 {
234   u8 *s = 0;
235
236   s = format (s, "SCRIPT: gbp_contract_add_del ");
237   if (a->is_add)
238     s = format (s, "add ");
239   else
240     s = format (s, "del ");
241   s = format (s, "sclass %d ", ntohs (a->contract.sclass));
242   s = format (s, "dclass %d ", ntohs (a->contract.dclass));
243   s = format (s, "acl_index %d \n", ntohl (a->contract.acl_index));
244   for (int i = 0; i < a->contract.n_rules; i++)
245     {
246       s = format (s, "\t action %d\n", ntohl (a->contract.rules[i].action));
247       s =
248         format (s, "\t hash_mode %d",
249                 ntohl (a->contract.rules[i].nh_set.hash_mode));
250       for (int j = 0; j < a->contract.rules[i].nh_set.n_nhs; j++)
251         {
252           s =
253             format (s, "\n\t \t nhs ip %U ", format_vl_api_address,
254                     &a->contract.rules[i].nh_set.nhs[j].ip);
255           s =
256             format (s, "nhs mac %U ", format_vl_api_mac_address,
257                     a->contract.rules[i].nh_set.nhs[j].mac);
258           s =
259             format (s, "nhs bd_id %d ",
260                     ntohl (a->contract.rules[i].nh_set.nhs[j].bd_id));
261           s =
262             format (s, "nhs rd_id %d",
263                     ntohl (a->contract.rules[i].nh_set.nhs[j].rd_id));
264         }
265       s = format (s, "\n");
266     }
267
268   if (a->contract.n_ether_types)
269     s = format (s, "\tethertypes");
270   for (int i = 0; i < a->contract.n_ether_types; i++)
271     {
272       s = format (s, " %d ", ntohs (a->contract.allowed_ethertypes[i]));
273     }
274
275   s = format (s, "\n");
276
277   PRINT_S;
278
279   return handle;
280 }
281
282 static inline void *
283 vl_api_gbp_vxlan_tunnel_add_t_print (vl_api_gbp_vxlan_tunnel_add_t * a,
284                                      void *handle)
285 {
286   u8 *s = 0;
287
288   s = format (s, "SCRIPT: gbp_vxlan_tunnel_add ");
289
290   s = format (s, "vni %d ", ntohl (a->tunnel.vni));
291   s = format (s, "mode %d ", ntohl (a->tunnel.mode));
292   s = format (s, "bd_rd_id %d ", ntohl (a->tunnel.bd_rd_id));
293   s = format (s, "src %U ", format_vl_api_ip4_address, a->tunnel.src);
294
295   s = format (s, "\n");
296
297   PRINT_S;
298
299   return handle;
300 }
301
302 static inline void *
303 vl_api_gbp_vxlan_tunnel_del_t_print (vl_api_gbp_vxlan_tunnel_del_t * a,
304                                      void *handle)
305 {
306   u8 *s = 0;
307
308   s = format (s, "SCRIPT: gbp_vxlan_tunnel_del ");
309   s = format (s, "vni %d ", ntohl (a->vni));
310
311   s = format (s, "\n");
312
313   PRINT_S;
314
315   return handle;
316 }
317
318 static inline void *
319 vl_api_gbp_ext_itf_add_del_t_print (vl_api_gbp_ext_itf_add_del_t * a,
320                                     void *handle)
321 {
322   u8 *s = 0;
323
324   s = format (s, "SCRIPT: gbp_ext_itf_add_del ");
325   if (a->is_add)
326     s = format (s, "add ");
327   else
328     s = format (s, "del ");
329
330   s = format (s, "sw_if_index %d ", ntohl (a->ext_itf.sw_if_index));
331   s = format (s, "bd_id %d ", ntohl (a->ext_itf.bd_id));
332   s = format (s, "rd_id %d ", ntohl (a->ext_itf.rd_id));
333
334   s = format (s, "\n");
335
336   PRINT_S;
337
338   return handle;
339 }
340
341 /*
342  * fd.io coding-style-patch-verification: ON
343  *
344  * Local Variables:
345  * eval: (c-set-style "gnu")
346  * End:
347  */
348
349 #endif /* __GBP_API_PRINT_H__ */