2 * flowperpkt.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 <vlibsocket/api.h>
21 #include <vppinfra/error.h>
24 * @file vpp_api_test plugin
27 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
29 /* Declare message IDs */
30 #include <flowperpkt/flowperpkt_msg_enum.h>
32 /* define message structures */
34 #include <flowperpkt/flowperpkt_all_api_h.h>
37 /* declare message handlers for each api */
39 #define vl_endianfun /* define message structures */
40 #include <flowperpkt/flowperpkt_all_api_h.h>
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...)
46 #include <flowperpkt/flowperpkt_all_api_h.h>
49 /* Get the API version number. */
50 #define vl_api_version(n,v) static u32 api_version=(v);
51 #include <flowperpkt/flowperpkt_all_api_h.h>
56 /** API message ID base */
58 /** vat_main_t pointer */
60 } flowperpkt_test_main_t;
62 flowperpkt_test_main_t flowperpkt_test_main;
64 #define foreach_standard_reply_retval_handler \
65 _(flowperpkt_tx_interface_add_del_reply)
68 static void vl_api_##n##_t_handler \
69 (vl_api_##n##_t * mp) \
71 vat_main_t * vam = flowperpkt_test_main.vat_main; \
72 i32 retval = ntohl(mp->retval); \
73 if (vam->async_mode) { \
74 vam->async_errors += (retval < 0); \
76 vam->retval = retval; \
77 vam->result_ready = 1; \
80 foreach_standard_reply_retval_handler;
84 * Table of message reply handlers, must include boilerplate handlers
87 #define foreach_vpe_api_reply_msg \
88 _(FLOWPERPKT_TX_INTERFACE_ADD_DEL_REPLY, \
89 flowperpkt_tx_interface_add_del_reply)
92 /* M: construct, but don't yet send a message */
96 vam->result_ready = 0; \
97 mp = vl_msg_api_alloc(sizeof(*mp)); \
98 memset (mp, 0, sizeof (*mp)); \
99 mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
100 mp->client_index = vam->my_client_index; \
105 vam->result_ready = 0; \
106 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
107 memset (mp, 0, sizeof (*mp)); \
108 mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
109 mp->client_index = vam->my_client_index; \
112 /* S: send a message */
113 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
115 /* W: wait for results, with timeout */
118 timeout = vat_time_now (vam) + 1.0; \
120 while (vat_time_now (vam) < timeout) { \
121 if (vam->result_ready == 1) { \
122 return (vam->retval); \
129 api_flowperpkt_tx_interface_add_del (vat_main_t * vam)
131 flowperpkt_test_main_t *sm = &flowperpkt_test_main;
132 unformat_input_t *i = vam->input;
134 int enable_disable = 1;
135 u8 which = 0; /* ipv4 by default */
136 u32 sw_if_index = ~0;
137 vl_api_flowperpkt_tx_interface_add_del_t *mp;
139 /* Parse args required to build the message */
140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
142 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
144 else if (unformat (i, "sw_if_index %d", &sw_if_index))
146 else if (unformat (i, "disable"))
148 else if (unformat (i, "l2"))
154 if (sw_if_index == ~0)
156 errmsg ("missing interface name / explicit sw_if_index number \n");
160 /* Construct the API message */
161 M (FLOWPERPKT_TX_INTERFACE_ADD_DEL, flowperpkt_tx_interface_add_del);
162 mp->sw_if_index = ntohl (sw_if_index);
163 mp->is_add = enable_disable;
169 /* Wait for a reply... */
174 * List of messages that the api test plugin sends,
175 * and that the data plane plugin processes
177 #define foreach_vpe_api_msg \
178 _(flowperpkt_tx_interface_add_del, "<intfc> [disable]")
181 vat_api_hookup (vat_main_t * vam)
183 flowperpkt_test_main_t *sm = &flowperpkt_test_main;
184 /* Hook up handlers for replies from the data plane plug-in */
186 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
188 vl_api_##n##_t_handler, \
190 vl_api_##n##_t_endian, \
191 vl_api_##n##_t_print, \
192 sizeof(vl_api_##n##_t), 1);
193 foreach_vpe_api_reply_msg;
196 /* API messages we can send */
197 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
202 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
208 vat_plugin_register (vat_main_t * vam)
210 flowperpkt_test_main_t *sm = &flowperpkt_test_main;
215 /* Ask the vpp engine for the first assigned message-id */
216 name = format (0, "flowperpkt_%08x%c", api_version, 0);
217 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
219 /* Don't attempt to hook up API messages if the data plane plugin is AWOL */
220 if (sm->msg_id_base != (u16) ~ 0)
221 vat_api_hookup (vam);
229 * fd.io coding-style-patch-verification: ON
232 * eval: (c-set-style "gnu")