2 * oddbuf.c - skeleton vpp-api-test plug-in
4 * Copyright (c) <current-year> <your-organization>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
23 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
25 /* Declare message IDs */
26 #include <oddbuf/oddbuf_msg_enum.h>
28 /* define message structures */
30 #include <oddbuf/oddbuf_all_api_h.h>
33 /* declare message handlers for each api */
35 #define vl_endianfun /* define message structures */
36 #include <oddbuf/oddbuf_all_api_h.h>
39 /* instantiate all the print functions we know about */
40 #define vl_print(handle, ...)
42 #include <oddbuf/oddbuf_all_api_h.h>
45 /* Get the API version number. */
46 #define vl_api_version(n,v) static u32 api_version=(v);
47 #include <oddbuf/oddbuf_all_api_h.h>
53 /* API message ID base */
58 oddbuf_test_main_t oddbuf_test_main;
60 #define __plugin_msg_base oddbuf_test_main.msg_id_base
61 #include <vlibapi/vat_helper_macros.h>
63 #define foreach_standard_reply_retval_handler \
64 _(oddbuf_enable_disable_reply)
67 static void vl_api_##n##_t_handler \
68 (vl_api_##n##_t * mp) \
70 vat_main_t * vam = oddbuf_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 _(ODDBUF_ENABLE_DISABLE_REPLY, oddbuf_enable_disable_reply)
91 api_oddbuf_enable_disable (vat_main_t * vam)
93 unformat_input_t *i = vam->input;
94 int enable_disable = 1;
96 vl_api_oddbuf_enable_disable_t *mp;
99 /* Parse args required to build the message */
100 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
102 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
104 else if (unformat (i, "sw_if_index %d", &sw_if_index))
106 else if (unformat (i, "disable"))
112 if (sw_if_index == ~0)
114 errmsg ("missing interface name / explicit sw_if_index number \n");
118 /* Construct the API message */
119 M (ODDBUF_ENABLE_DISABLE, mp);
120 mp->sw_if_index = ntohl (sw_if_index);
121 mp->enable_disable = enable_disable;
126 /* 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 _(oddbuf_enable_disable, "<intfc> [disable]")
139 oddbuf_api_hookup (vat_main_t * vam)
141 oddbuf_test_main_t *otmp = &oddbuf_test_main;
142 /* Hook up handlers for replies from the data plane plug-in */
144 vl_msg_api_set_handlers((VL_API_##N + otmp->msg_id_base), \
146 vl_api_##n##_t_handler, \
148 vl_api_##n##_t_endian, \
149 vl_api_##n##_t_print, \
150 sizeof(vl_api_##n##_t), 1);
151 foreach_vpe_api_reply_msg;
154 /* API messages we can send */
155 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
160 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
165 VAT_PLUGIN_REGISTER (oddbuf);
168 * fd.io coding-style-patch-verification: ON
171 * eval: (c-set-style "gnu")