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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 *------------------------------------------------------------------
17 * vxlan_gpe_ioam_export_test.c - test harness plugin
18 *------------------------------------------------------------------
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vlibsocket/api.h>
25 #include <vppinfra/error.h>
28 /* Declare message IDs */
29 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_msg_enum.h>
31 /* define message structures */
33 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
36 /* declare message handlers for each api */
38 #define vl_endianfun /* define message structures */
39 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...)
45 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
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>
56 /* API message ID base */
61 export_test_main_t export_test_main;
63 #define foreach_standard_reply_retval_handler \
64 _(vxlan_gpe_ioam_export_enable_disable_reply)
67 static void vl_api_##n##_t_handler \
68 (vl_api_##n##_t * mp) \
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); \
75 vam->retval = retval; \
76 vam->result_ready = 1; \
79 foreach_standard_reply_retval_handler;
83 * Table of message reply handlers, must include boilerplate handlers
86 #define foreach_vpe_api_reply_msg \
87 _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY, vxlan_gpe_ioam_export_enable_disable_reply)
90 /* M: construct, but don't yet send a message */
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; \
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; \
110 /* S: send a message */
111 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
113 /* W: wait for results, with timeout */
116 timeout = vat_time_now (vam) + 1.0; \
118 while (vat_time_now (vam) < timeout) { \
119 if (vam->result_ready == 1) { \
120 return (vam->retval); \
127 api_vxlan_gpe_ioam_export_enable_disable (vat_main_t * vam)
129 export_test_main_t *sm = &export_test_main;
130 unformat_input_t *i = vam->input;
133 vl_api_vxlan_gpe_ioam_export_enable_disable_t *mp;
135 /* Parse args required to build the message */
136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
138 if (unformat (i, "disable"))
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;
152 /* Wait for a reply... */
157 * List of messages that the api test plugin sends,
158 * and that the data plane plugin processes
160 #define foreach_vpe_api_msg \
161 _(vxlan_gpe_ioam_export_enable_disable, "<intfc> [disable]")
164 vat_api_hookup (vat_main_t * vam)
166 export_test_main_t *sm = &export_test_main;
167 /* Hook up handlers for replies from the data plane plug-in */
169 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
171 vl_api_##n##_t_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;
179 /* API messages we can send */
180 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
185 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
191 vat_plugin_register (vat_main_t * vam)
193 export_test_main_t *sm = &export_test_main;
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);
201 if (sm->msg_id_base != (u16) ~ 0)
202 vat_api_hookup (vam);
210 * fd.io coding-style-patch-verification: ON
213 * eval: (c-set-style "gnu")