Repair Doxygen build infrastructure
[vpp.git] / src / plugins / ioam / export-vxlan-gpe / vxlan_gpe_ioam_export_test.c
1 /*
2  * Copyright (c) 2016 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  *------------------------------------------------------------------
17  * vxlan_gpe_ioam_export_test.c - test harness plugin
18  *------------------------------------------------------------------
19  */
20
21 #include <vat/vat.h>
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vlibsocket/api.h>
25 #include <vppinfra/error.h>
26
27
28 /* Declare message IDs */
29 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_msg_enum.h>
30
31 /* define message structures */
32 #define vl_typedefs
33 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
34 #undef vl_typedefs
35
36 /* declare message handlers for each api */
37
38 #define vl_endianfun            /* define message structures */
39 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
40 #undef vl_endianfun
41
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...)
44 #define vl_printfun
45 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
46 #undef vl_printfun
47
48 /* Get the API version number. */
49 #define vl_api_version(n,v) static u32 api_version=(v);
50 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
51 #undef vl_api_version
52
53
54 typedef struct
55 {
56   /* API message ID base */
57   u16 msg_id_base;
58   vat_main_t *vat_main;
59 } export_test_main_t;
60
61 export_test_main_t export_test_main;
62
63 #define foreach_standard_reply_retval_handler   \
64 _(vxlan_gpe_ioam_export_enable_disable_reply)
65
66 #define _(n)                                            \
67     static void vl_api_##n##_t_handler                  \
68     (vl_api_##n##_t * mp)                               \
69     {                                                   \
70         vat_main_t * vam = export_test_main.vat_main;   \
71         i32 retval = ntohl(mp->retval);                 \
72         if (vam->async_mode) {                          \
73             vam->async_errors += (retval < 0);          \
74         } else {                                        \
75             vam->retval = retval;                       \
76             vam->result_ready = 1;                      \
77         }                                               \
78     }
79 foreach_standard_reply_retval_handler;
80 #undef _
81
82 /*
83  * Table of message reply handlers, must include boilerplate handlers
84  * we just generated
85  */
86 #define foreach_vpe_api_reply_msg                                       \
87 _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY, vxlan_gpe_ioam_export_enable_disable_reply)
88
89
90 /* M: construct, but don't yet send a message */
91
92 #define M(T,t)                                                  \
93 do {                                                            \
94     vam->result_ready = 0;                                      \
95     mp = vl_msg_api_alloc(sizeof(*mp));                         \
96     memset (mp, 0, sizeof (*mp));                               \
97     mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base);      \
98     mp->client_index = vam->my_client_index;                    \
99 } while(0);
100
101 #define M2(T,t,n)                                               \
102 do {                                                            \
103     vam->result_ready = 0;                                      \
104     mp = vl_msg_api_alloc(sizeof(*mp)+(n));                     \
105     memset (mp, 0, sizeof (*mp));                               \
106     mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base);      \
107     mp->client_index = vam->my_client_index;                    \
108 } while(0);
109
110 /* S: send a message */
111 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
112
113 /* W: wait for results, with timeout */
114 #define W                                       \
115 do {                                            \
116     timeout = vat_time_now (vam) + 1.0;         \
117                                                 \
118     while (vat_time_now (vam) < timeout) {      \
119         if (vam->result_ready == 1) {           \
120             return (vam->retval);               \
121         }                                       \
122     }                                           \
123     return -99;                                 \
124 } while(0);
125
126 static int
127 api_vxlan_gpe_ioam_export_enable_disable (vat_main_t * vam)
128 {
129   export_test_main_t *sm = &export_test_main;
130   unformat_input_t *i = vam->input;
131   f64 timeout;
132   int is_disable = 0;
133   vl_api_vxlan_gpe_ioam_export_enable_disable_t *mp;
134
135   /* Parse args required to build the message */
136   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
137     {
138       if (unformat (i, "disable"))
139         is_disable = 1;
140       else
141         break;
142     }
143
144   /* Construct the API message */
145   M (VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE,
146      vxlan_gpe_ioam_export_enable_disable);
147   mp->is_disable = is_disable;
148
149   /* send it... */
150   S;
151
152   /* Wait for a reply... */
153   W;
154 }
155
156 /*
157  * List of messages that the api test plugin sends,
158  * and that the data plane plugin processes
159  */
160 #define foreach_vpe_api_msg \
161 _(vxlan_gpe_ioam_export_enable_disable, "<intfc> [disable]")
162
163 void
164 vat_api_hookup (vat_main_t * vam)
165 {
166   export_test_main_t *sm = &export_test_main;
167   /* Hook up handlers for replies from the data plane plug-in */
168 #define _(N,n)                                                  \
169     vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base),     \
170                            #n,                                  \
171                            vl_api_##n##_t_handler,              \
172                            vl_noop_handler,                     \
173                            vl_api_##n##_t_endian,               \
174                            vl_api_##n##_t_print,                \
175                            sizeof(vl_api_##n##_t), 1);
176   foreach_vpe_api_reply_msg;
177 #undef _
178
179   /* API messages we can send */
180 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
181   foreach_vpe_api_msg;
182 #undef _
183
184   /* Help strings */
185 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
186   foreach_vpe_api_msg;
187 #undef _
188 }
189
190 clib_error_t *
191 vat_plugin_register (vat_main_t * vam)
192 {
193   export_test_main_t *sm = &export_test_main;
194   u8 *name;
195
196   sm->vat_main = vam;
197
198   name = format (0, "vxlan_gpe_ioam_export_%08x%c", api_version, 0);
199   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
200
201   if (sm->msg_id_base != (u16) ~ 0)
202     vat_api_hookup (vam);
203
204   vec_free (name);
205
206   return 0;
207 }
208
209 /*
210  * fd.io coding-style-patch-verification: ON
211  *
212  * Local Variables:
213  * eval: (c-set-style "gnu")
214  * End:
215  */