2 * flowprobe.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>
21 #include <flowprobe/flowprobe.h>
23 #define __plugin_msg_base flowprobe_test_main.msg_id_base
24 #include <vlibapi/vat_helper_macros.h>
27 * @file vpp_api_test plugin
30 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
32 /* Declare message IDs */
33 #include <flowprobe/flowprobe_msg_enum.h>
35 /* define message structures */
37 #include <flowprobe/flowprobe_all_api_h.h>
40 /* declare message handlers for each api */
42 #define vl_endianfun /* define message structures */
43 #include <flowprobe/flowprobe_all_api_h.h>
46 /* instantiate all the print functions we know about */
47 #define vl_print(handle, ...)
49 #include <flowprobe/flowprobe_all_api_h.h>
52 /* Get the API version number. */
53 #define vl_api_version(n,v) static u32 api_version=(v);
54 #include <flowprobe/flowprobe_all_api_h.h>
59 /** API message ID base */
61 /** vat_main_t pointer */
63 } flowprobe_test_main_t;
65 flowprobe_test_main_t flowprobe_test_main;
67 #define foreach_standard_reply_retval_handler \
68 _(flowprobe_tx_interface_add_del_reply) \
69 _(flowprobe_params_reply)
72 static void vl_api_##n##_t_handler \
73 (vl_api_##n##_t * mp) \
75 vat_main_t * vam = flowprobe_test_main.vat_main; \
76 i32 retval = ntohl(mp->retval); \
77 if (vam->async_mode) { \
78 vam->async_errors += (retval < 0); \
80 vam->retval = retval; \
81 vam->result_ready = 1; \
84 foreach_standard_reply_retval_handler;
88 * Table of message reply handlers, must include boilerplate handlers
91 #define foreach_vpe_api_reply_msg \
92 _(FLOWPROBE_TX_INTERFACE_ADD_DEL_REPLY, \
93 flowprobe_tx_interface_add_del_reply) \
94 _(FLOWPROBE_PARAMS_REPLY, flowprobe_params_reply)
97 api_flowprobe_tx_interface_add_del (vat_main_t * vam)
99 unformat_input_t *i = vam->input;
100 int enable_disable = 1;
101 u8 which = FLOW_VARIANT_IP4;
102 u32 sw_if_index = ~0;
103 vl_api_flowprobe_tx_interface_add_del_t *mp;
106 /* Parse args required to build the message */
107 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
109 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
111 else if (unformat (i, "sw_if_index %d", &sw_if_index))
113 else if (unformat (i, "disable"))
115 else if (unformat (i, "ip4"))
116 which = FLOW_VARIANT_IP4;
117 else if (unformat (i, "ip6"))
118 which = FLOW_VARIANT_IP6;
119 else if (unformat (i, "l2"))
120 which = FLOW_VARIANT_L2;
125 if (sw_if_index == ~0)
127 errmsg ("missing interface name / explicit sw_if_index number \n");
131 /* Construct the API message */
132 M (FLOWPROBE_TX_INTERFACE_ADD_DEL, mp);
133 mp->sw_if_index = ntohl (sw_if_index);
134 mp->is_add = enable_disable;
140 /* Wait for a reply... */
146 api_flowprobe_params (vat_main_t * vam)
148 unformat_input_t *i = vam->input;
149 u8 record_l2 = 0, record_l3 = 0, record_l4 = 0;
150 u32 active_timer = ~0;
151 u32 passive_timer = ~0;
152 vl_api_flowprobe_params_t *mp;
155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
157 if (unformat (i, "active %d", &active_timer))
159 else if (unformat (i, "passive %d", &passive_timer))
161 else if (unformat (i, "record"))
162 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
164 if (unformat (i, "l2"))
166 else if (unformat (i, "l3"))
168 else if (unformat (i, "l4"))
177 if (passive_timer > 0 && active_timer > passive_timer)
179 errmsg ("Passive timer has to be greater than active one...\n");
183 /* Construct the API message */
184 M (FLOWPROBE_PARAMS, mp);
185 mp->record_l2 = record_l2;
186 mp->record_l3 = record_l3;
187 mp->record_l4 = record_l4;
188 mp->active_timer = ntohl (active_timer);
189 mp->passive_timer = ntohl (passive_timer);
194 /* Wait for a reply... */
201 * List of messages that the api test plugin sends,
202 * and that the data plane plugin processes
204 #define foreach_vpe_api_msg \
205 _(flowprobe_tx_interface_add_del, "<intfc> [disable]") \
206 _(flowprobe_params, "record <[l2] [l3] [l4]> [active <timer> passive <timer>]")
209 flowprobe_vat_api_hookup (vat_main_t * vam)
211 flowprobe_test_main_t *sm = &flowprobe_test_main;
212 /* Hook up handlers for replies from the data plane plug-in */
214 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
216 vl_api_##n##_t_handler, \
218 vl_api_##n##_t_endian, \
219 vl_api_##n##_t_print, \
220 sizeof(vl_api_##n##_t), 1);
221 foreach_vpe_api_reply_msg;
224 /* API messages we can send */
225 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
230 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
236 vat_plugin_register (vat_main_t * vam)
238 flowprobe_test_main_t *sm = &flowprobe_test_main;
243 /* Ask the vpp engine for the first assigned message-id */
244 name = format (0, "flowprobe_%08x%c", api_version, 0);
245 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
247 /* Don't attempt to hook up API messages if the data plane plugin is AWOL */
248 if (sm->msg_id_base != (u16) ~ 0)
249 flowprobe_vat_api_hookup (vam);
257 * fd.io coding-style-patch-verification: ON
260 * eval: (c-set-style "gnu")