5b641cc7ce7b0ff1915f5325587a3c49d20a5a83
[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 #include <vlibapi/vat_helper_macros.h>
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 static int
90 api_vxlan_gpe_ioam_export_enable_disable (vat_main_t * vam)
91 {
92   unformat_input_t *i = vam->input;
93   f64 timeout;
94   int is_disable = 0;
95   vl_api_vxlan_gpe_ioam_export_enable_disable_t *mp;
96
97   /* Parse args required to build the message */
98   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
99     {
100       if (unformat (i, "disable"))
101         is_disable = 1;
102       else
103         break;
104     }
105
106   /* Construct the API message */
107   M (VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE,
108      vxlan_gpe_ioam_export_enable_disable);
109   mp->is_disable = is_disable;
110
111   /* send it... */
112   S;
113
114   /* Wait for a reply... */
115   W;
116 }
117
118 /*
119  * List of messages that the api test plugin sends,
120  * and that the data plane plugin processes
121  */
122 #define foreach_vpe_api_msg \
123 _(vxlan_gpe_ioam_export_enable_disable, "<intfc> [disable]")
124
125 static void
126 vxlan_gpe_ioam_vat_api_hookup (vat_main_t * vam)
127 {
128   export_test_main_t *sm = &export_test_main;
129   /* Hook up handlers for replies from the data plane plug-in */
130 #define _(N,n)                                                  \
131     vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base),     \
132                            #n,                                  \
133                            vl_api_##n##_t_handler,              \
134                            vl_noop_handler,                     \
135                            vl_api_##n##_t_endian,               \
136                            vl_api_##n##_t_print,                \
137                            sizeof(vl_api_##n##_t), 1);
138   foreach_vpe_api_reply_msg;
139 #undef _
140
141   /* API messages we can send */
142 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
143   foreach_vpe_api_msg;
144 #undef _
145
146   /* Help strings */
147 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
148   foreach_vpe_api_msg;
149 #undef _
150 }
151
152 clib_error_t *
153 vat_plugin_register (vat_main_t * vam)
154 {
155   export_test_main_t *sm = &export_test_main;
156   u8 *name;
157
158   sm->vat_main = vam;
159
160   name = format (0, "vxlan_gpe_ioam_export_%08x%c", api_version, 0);
161   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
162
163   if (sm->msg_id_base != (u16) ~ 0)
164     vxlan_gpe_ioam_vat_api_hookup (vam);
165
166   vec_free (name);
167
168   return 0;
169 }
170
171 /*
172  * fd.io coding-style-patch-verification: ON
173  *
174  * Local Variables:
175  * eval: (c-set-style "gnu")
176  * End:
177  */