2 * Copyright (c) 2015 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 * sample_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>
27 #define __plugin_msg_base sample_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
30 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
32 /* Declare message IDs */
33 #include <sample/sample_msg_enum.h>
35 /* define message structures */
37 #include <sample/sample_all_api_h.h>
40 /* declare message handlers for each api */
42 #define vl_endianfun /* define message structures */
43 #include <sample/sample_all_api_h.h>
46 /* instantiate all the print functions we know about */
47 #define vl_print(handle, ...)
49 #include <sample/sample_all_api_h.h>
52 /* Get the API version number. */
53 #define vl_api_version(n,v) static u32 api_version=(v);
54 #include <sample/sample_all_api_h.h>
59 /* API message ID base */
64 sample_test_main_t sample_test_main;
66 #define foreach_standard_reply_retval_handler \
67 _(sample_macswap_enable_disable_reply)
70 static void vl_api_##n##_t_handler \
71 (vl_api_##n##_t * mp) \
73 vat_main_t * vam = sample_test_main.vat_main; \
74 i32 retval = ntohl(mp->retval); \
75 if (vam->async_mode) { \
76 vam->async_errors += (retval < 0); \
78 vam->retval = retval; \
79 vam->result_ready = 1; \
82 foreach_standard_reply_retval_handler;
86 * Table of message reply handlers, must include boilerplate handlers
89 #define foreach_vpe_api_reply_msg \
90 _(SAMPLE_MACSWAP_ENABLE_DISABLE_REPLY, sample_macswap_enable_disable_reply)
93 static int api_sample_macswap_enable_disable (vat_main_t * vam)
95 sample_test_main_t * sm = &sample_test_main;
96 unformat_input_t * i = vam->input;
98 int enable_disable = 1;
100 vl_api_sample_macswap_enable_disable_t * mp;
102 /* Parse args required to build the message */
103 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
104 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
106 else if (unformat (i, "sw_if_index %d", &sw_if_index))
108 else if (unformat (i, "disable"))
114 if (sw_if_index == ~0) {
115 errmsg ("missing interface name / explicit sw_if_index number \n");
119 /* Construct the API message */
120 M(SAMPLE_MACSWAP_ENABLE_DISABLE, mp);
121 mp->sw_if_index = ntohl (sw_if_index);
122 mp->enable_disable = enable_disable;
127 /* Wait for a reply... */
132 * List of messages that the api test plugin sends,
133 * and that the data plane plugin processes
135 #define foreach_vpe_api_msg \
136 _(sample_macswap_enable_disable, "<intfc> [disable]")
138 void vat_api_hookup (vat_main_t *vam)
140 sample_test_main_t * sm = &sample_test_main;
141 /* Hook up handlers for replies from the data plane plug-in */
143 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
145 vl_api_##n##_t_handler, \
147 vl_api_##n##_t_endian, \
148 vl_api_##n##_t_print, \
149 sizeof(vl_api_##n##_t), 1);
150 foreach_vpe_api_reply_msg;
153 /* API messages we can send */
154 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
159 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
164 clib_error_t * vat_plugin_register (vat_main_t *vam)
166 sample_test_main_t * sm = &sample_test_main;
171 name = format (0, "sample_%08x%c", api_version, 0);
172 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
174 if (sm->msg_id_base != (u16) ~0)
175 vat_api_hookup (vam);