17d31c95bcb574b3195235da4ae04283d4488839
[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 #define __plugin_msg_base export_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
29
30 /* Declare message IDs */
31 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_msg_enum.h>
32
33 /* define message structures */
34 #define vl_typedefs
35 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
36 #undef vl_typedefs
37
38 /* declare message handlers for each api */
39
40 #define vl_endianfun            /* define message structures */
41 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
42 #undef vl_endianfun
43
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
46 #define vl_printfun
47 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
48 #undef vl_printfun
49
50 /* Get the API version number. */
51 #define vl_api_version(n,v) static u32 api_version=(v);
52 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
53 #undef vl_api_version
54
55
56 typedef struct
57 {
58   /* API message ID base */
59   u16 msg_id_base;
60   vat_main_t *vat_main;
61 } export_test_main_t;
62
63 export_test_main_t export_test_main;
64
65 #define foreach_standard_reply_retval_handler   \
66 _(vxlan_gpe_ioam_export_enable_disable_reply)
67
68 #define _(n)                                            \
69     static void vl_api_##n##_t_handler                  \
70     (vl_api_##n##_t * mp)                               \
71     {                                                   \
72         vat_main_t * vam = export_test_main.vat_main;   \
73         i32 retval = ntohl(mp->retval);                 \
74         if (vam->async_mode) {                          \
75             vam->async_errors += (retval < 0);          \
76         } else {                                        \
77             vam->retval = retval;                       \
78             vam->result_ready = 1;                      \
79         }                                               \
80     }
81 foreach_standard_reply_retval_handler;
82 #undef _
83
84 /*
85  * Table of message reply handlers, must include boilerplate handlers
86  * we just generated
87  */
88 #define foreach_vpe_api_reply_msg                                       \
89 _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY, vxlan_gpe_ioam_export_enable_disable_reply)
90
91 static int
92 api_vxlan_gpe_ioam_export_enable_disable (vat_main_t * vam)
93 {
94   unformat_input_t *i = vam->input;
95   int is_disable = 0;
96   vl_api_vxlan_gpe_ioam_export_enable_disable_t *mp;
97   int ret;
98
99   /* Parse args required to build the message */
100   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
101     {
102       if (unformat (i, "disable"))
103         is_disable = 1;
104       else
105         break;
106     }
107
108   /* Construct the API message */
109   M (VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE, mp);
110   mp->is_disable = is_disable;
111
112   /* send it... */
113   S (mp);
114
115   /* Wait for a reply... */
116   W (ret);
117   return ret;
118 }
119
120 /*
121  * List of messages that the api test plugin sends,
122  * and that the data plane plugin processes
123  */
124 #define foreach_vpe_api_msg \
125 _(vxlan_gpe_ioam_export_enable_disable, "<intfc> [disable]")
126
127 static void
128 vxlan_gpe_ioam_vat_api_hookup (vat_main_t * vam)
129 {
130   export_test_main_t *sm = &export_test_main;
131   /* Hook up handlers for replies from the data plane plug-in */
132 #define _(N,n)                                                  \
133     vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base),     \
134                            #n,                                  \
135                            vl_api_##n##_t_handler,              \
136                            vl_noop_handler,                     \
137                            vl_api_##n##_t_endian,               \
138                            vl_api_##n##_t_print,                \
139                            sizeof(vl_api_##n##_t), 1);
140   foreach_vpe_api_reply_msg;
141 #undef _
142
143   /* API messages we can send */
144 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
145   foreach_vpe_api_msg;
146 #undef _
147
148   /* Help strings */
149 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
150   foreach_vpe_api_msg;
151 #undef _
152 }
153
154 clib_error_t *
155 vat_plugin_register (vat_main_t * vam)
156 {
157   export_test_main_t *sm = &export_test_main;
158   u8 *name;
159
160   sm->vat_main = vam;
161
162   name = format (0, "vxlan_gpe_ioam_export_%08x%c", api_version, 0);
163   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
164
165   if (sm->msg_id_base != (u16) ~ 0)
166     vxlan_gpe_ioam_vat_api_hookup (vam);
167
168   vec_free (name);
169
170   return 0;
171 }
172
173 /*
174  * fd.io coding-style-patch-verification: ON
175  *
176  * Local Variables:
177  * eval: (c-set-style "gnu")
178  * End:
179  */