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 <vlibsocket/api.h>
21 #include <vppinfra/error.h>
22 #include <flowprobe/flowprobe.h>
24 #define __plugin_msg_base flowprobe_test_main.msg_id_base
25 #include <vlibapi/vat_helper_macros.h>
28 * @file vpp_api_test plugin
31 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
33 /* Declare message IDs */
34 #include <flowprobe/flowprobe_msg_enum.h>
36 /* define message structures */
38 #include <flowprobe/flowprobe_all_api_h.h>
41 /* declare message handlers for each api */
43 #define vl_endianfun /* define message structures */
44 #include <flowprobe/flowprobe_all_api_h.h>
47 /* instantiate all the print functions we know about */
48 #define vl_print(handle, ...)
50 #include <flowprobe/flowprobe_all_api_h.h>
53 /* Get the API version number. */
54 #define vl_api_version(n,v) static u32 api_version=(v);
55 #include <flowprobe/flowprobe_all_api_h.h>
60 /** API message ID base */
62 /** vat_main_t pointer */
64 } flowprobe_test_main_t;
66 flowprobe_test_main_t flowprobe_test_main;
68 #define foreach_standard_reply_retval_handler \
69 _(flowprobe_tx_interface_add_del_reply) \
70 _(flowprobe_params_reply)
73 static void vl_api_##n##_t_handler \
74 (vl_api_##n##_t * mp) \
76 vat_main_t * vam = flowprobe_test_main.vat_main; \
77 i32 retval = ntohl(mp->retval); \
78 if (vam->async_mode) { \
79 vam->async_errors += (retval < 0); \
81 vam->retval = retval; \
82 vam->result_ready = 1; \
85 foreach_standard_reply_retval_handler;
89 * Table of message reply handlers, must include boilerplate handlers
92 #define foreach_vpe_api_reply_msg \
93 _(FLOWPROBE_TX_INTERFACE_ADD_DEL_REPLY, \
94 flowprobe_tx_interface_add_del_reply) \
95 _(FLOWPROBE_PARAMS_REPLY, flowprobe_params_reply)
98 api_flowprobe_tx_interface_add_del (vat_main_t * vam)
100 unformat_input_t *i = vam->input;
101 int enable_disable = 1;
102 u8 which = FLOW_VARIANT_IP4;
103 u32 sw_if_index = ~0;
104 vl_api_flowprobe_tx_interface_add_del_t *mp;
107 /* Parse args required to build the message */
108 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
110 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
112 else if (unformat (i, "sw_if_index %d", &sw_if_index))
114 else if (unformat (i, "disable"))
116 else if (unformat (i, "ip4"))
117 which = FLOW_VARIANT_IP4;
118 else if (unformat (i, "ip6"))
119 which = FLOW_VARIANT_IP6;
120 else if (unformat (i, "l2"))
121 which = FLOW_VARIANT_L2;
126 if (sw_if_index == ~0)
128 errmsg ("missing interface name / explicit sw_if_index number \n");
132 /* Construct the API message */
133 M (FLOWPROBE_TX_INTERFACE_ADD_DEL, mp);
134 mp->sw_if_index = ntohl (sw_if_index);
135 mp->is_add = enable_disable;
141 /* Wait for a reply... */
147 api_flowprobe_params (vat_main_t * vam)
149 unformat_input_t *i = vam->input;
150 u8 record_l2 = 0, record_l3 = 0, record_l4 = 0;
151 u32 active_timer = ~0;
152 u32 passive_timer = ~0;
153 vl_api_flowprobe_params_t *mp;
156 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
158 if (unformat (i, "active %d", &active_timer))
160 else if (unformat (i, "passive %d", &passive_timer))
162 else if (unformat (i, "record"))
163 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
165 if (unformat (i, "l2"))
167 else if (unformat (i, "l3"))
169 else if (unformat (i, "l4"))
178 if (passive_timer > 0 && active_timer > passive_timer)
180 errmsg ("Passive timer has to be greater than active one...\n");
184 /* Construct the API message */
185 M (FLOWPROBE_PARAMS, mp);
186 mp->record_l2 = record_l2;
187 mp->record_l3 = record_l3;
188 mp->record_l4 = record_l4;
189 mp->active_timer = ntohl (active_timer);
190 mp->passive_timer = ntohl (passive_timer);
195 /* Wait for a reply... */
202 * List of messages that the api test plugin sends,
203 * and that the data plane plugin processes
205 #define foreach_vpe_api_msg \
206 _(flowprobe_tx_interface_add_del, "<intfc> [disable]") \
207 _(flowprobe_params, "record <[l2] [l3] [l4]> [active <timer> passive <timer>]")
210 flowprobe_vat_api_hookup (vat_main_t * vam)
212 flowprobe_test_main_t *sm = &flowprobe_test_main;
213 /* Hook up handlers for replies from the data plane plug-in */
215 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
217 vl_api_##n##_t_handler, \
219 vl_api_##n##_t_endian, \
220 vl_api_##n##_t_print, \
221 sizeof(vl_api_##n##_t), 1);
222 foreach_vpe_api_reply_msg;
225 /* API messages we can send */
226 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
231 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
237 vat_plugin_register (vat_main_t * vam)
239 flowprobe_test_main_t *sm = &flowprobe_test_main;
244 /* Ask the vpp engine for the first assigned message-id */
245 name = format (0, "flowprobe_%08x%c", api_version, 0);
246 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
248 /* Don't attempt to hook up API messages if the data plane plugin is AWOL */
249 if (sm->msg_id_base != (u16) ~ 0)
250 flowprobe_vat_api_hookup (vam);
258 * fd.io coding-style-patch-verification: ON
261 * eval: (c-set-style "gnu")