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>
22 #include <vlibapi/vat_helper_macros.h>
25 * @file vpp_api_test plugin
28 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
30 /* Declare message IDs */
31 #include <flowperpkt/flowperpkt_msg_enum.h>
33 /* define message structures */
35 #include <flowperpkt/flowperpkt_all_api_h.h>
38 /* declare message handlers for each api */
40 #define vl_endianfun /* define message structures */
41 #include <flowperpkt/flowperpkt_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
47 #include <flowperpkt/flowperpkt_all_api_h.h>
50 /* Get the API version number. */
51 #define vl_api_version(n,v) static u32 api_version=(v);
52 #include <flowperpkt/flowperpkt_all_api_h.h>
57 /** API message ID base */
59 /** vat_main_t pointer */
61 } flowperpkt_test_main_t;
63 flowperpkt_test_main_t flowperpkt_test_main;
65 #define foreach_standard_reply_retval_handler \
66 _(flowperpkt_tx_interface_add_del_reply)
69 static void vl_api_##n##_t_handler \
70 (vl_api_##n##_t * mp) \
72 vat_main_t * vam = flowperpkt_test_main.vat_main; \
73 i32 retval = ntohl(mp->retval); \
74 if (vam->async_mode) { \
75 vam->async_errors += (retval < 0); \
77 vam->retval = retval; \
78 vam->result_ready = 1; \
81 foreach_standard_reply_retval_handler;
85 * Table of message reply handlers, must include boilerplate handlers
88 #define foreach_vpe_api_reply_msg \
89 _(FLOWPERPKT_TX_INTERFACE_ADD_DEL_REPLY, \
90 flowperpkt_tx_interface_add_del_reply)
93 api_flowperpkt_tx_interface_add_del (vat_main_t * vam)
95 unformat_input_t *i = vam->input;
97 int enable_disable = 1;
98 u8 which = 0; /* ipv4 by default */
100 vl_api_flowperpkt_tx_interface_add_del_t *mp;
102 /* Parse args required to build the message */
103 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
105 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
107 else if (unformat (i, "sw_if_index %d", &sw_if_index))
109 else if (unformat (i, "disable"))
111 else if (unformat (i, "l2"))
117 if (sw_if_index == ~0)
119 errmsg ("missing interface name / explicit sw_if_index number \n");
123 /* Construct the API message */
124 M (FLOWPERPKT_TX_INTERFACE_ADD_DEL, flowperpkt_tx_interface_add_del);
125 mp->sw_if_index = ntohl (sw_if_index);
126 mp->is_add = enable_disable;
132 /* Wait for a reply... */
137 * List of messages that the api test plugin sends,
138 * and that the data plane plugin processes
140 #define foreach_vpe_api_msg \
141 _(flowperpkt_tx_interface_add_del, "<intfc> [disable]")
144 flowperpkt_vat_api_hookup (vat_main_t * vam)
146 flowperpkt_test_main_t *sm = &flowperpkt_test_main;
147 /* Hook up handlers for replies from the data plane plug-in */
149 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
151 vl_api_##n##_t_handler, \
153 vl_api_##n##_t_endian, \
154 vl_api_##n##_t_print, \
155 sizeof(vl_api_##n##_t), 1);
156 foreach_vpe_api_reply_msg;
159 /* API messages we can send */
160 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
165 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
171 vat_plugin_register (vat_main_t * vam)
173 flowperpkt_test_main_t *sm = &flowperpkt_test_main;
178 /* Ask the vpp engine for the first assigned message-id */
179 name = format (0, "flowperpkt_%08x%c", api_version, 0);
180 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
182 /* Don't attempt to hook up API messages if the data plane plugin is AWOL */
183 if (sm->msg_id_base != (u16) ~ 0)
184 flowperpkt_vat_api_hookup (vam);
192 * fd.io coding-style-patch-verification: ON
195 * eval: (c-set-style "gnu")