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.api_enum.h>
34 #include <flowprobe/flowprobe.api_types.h>
38 /** API message ID base */
40 /** vat_main_t pointer */
42 } flowprobe_test_main_t;
44 flowprobe_test_main_t flowprobe_test_main;
47 api_flowprobe_tx_interface_add_del (vat_main_t * vam)
49 unformat_input_t *i = vam->input;
50 int enable_disable = 1;
51 u8 which = FLOW_VARIANT_IP4;
53 vl_api_flowprobe_tx_interface_add_del_t *mp;
56 /* Parse args required to build the message */
57 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
59 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
61 else if (unformat (i, "sw_if_index %d", &sw_if_index))
63 else if (unformat (i, "disable"))
65 else if (unformat (i, "ip4"))
66 which = FLOW_VARIANT_IP4;
67 else if (unformat (i, "ip6"))
68 which = FLOW_VARIANT_IP6;
69 else if (unformat (i, "l2"))
70 which = FLOW_VARIANT_L2;
75 if (sw_if_index == ~0)
77 errmsg ("missing interface name / explicit sw_if_index number \n");
81 /* Construct the API message */
82 M (FLOWPROBE_TX_INTERFACE_ADD_DEL, mp);
83 mp->sw_if_index = ntohl (sw_if_index);
84 mp->is_add = enable_disable;
90 /* Wait for a reply... */
96 api_flowprobe_interface_add_del (vat_main_t *vam)
98 unformat_input_t *i = vam->input;
99 int enable_disable = 1;
100 u8 which = FLOWPROBE_WHICH_IP4;
101 u8 direction = FLOWPROBE_DIRECTION_TX;
102 u32 sw_if_index = ~0;
103 vl_api_flowprobe_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 = FLOWPROBE_WHICH_IP4;
117 else if (unformat (i, "ip6"))
118 which = FLOWPROBE_WHICH_IP6;
119 else if (unformat (i, "l2"))
120 which = FLOWPROBE_WHICH_L2;
121 else if (unformat (i, "rx"))
122 direction = FLOWPROBE_DIRECTION_RX;
123 else if (unformat (i, "tx"))
124 direction = FLOWPROBE_DIRECTION_TX;
125 else if (unformat (i, "both"))
126 direction = FLOWPROBE_DIRECTION_BOTH;
131 if (sw_if_index == ~0)
133 errmsg ("Missing interface name / explicit sw_if_index number\n");
137 /* Construct the API message */
138 M (FLOWPROBE_INTERFACE_ADD_DEL, mp);
139 mp->sw_if_index = ntohl (sw_if_index);
140 mp->is_add = enable_disable;
142 mp->direction = direction;
147 /* Wait for a reply... */
153 api_flowprobe_interface_dump (vat_main_t *vam)
155 unformat_input_t *i = vam->input;
156 vl_api_flowprobe_interface_dump_t *mp;
157 vl_api_control_ping_t *mp_ping;
158 u32 sw_if_index = ~0;
161 /* Parse args required to build the message */
162 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
164 if (unformat (i, "%d", &sw_if_index))
170 /* Construct the API message */
171 M (FLOWPROBE_INTERFACE_DUMP, mp);
172 mp->sw_if_index = htonl (sw_if_index);
177 /* Use control ping for synchronization */
178 PING (&flowprobe_test_main, mp_ping);
181 /* Wait for a reply... */
187 vl_api_flowprobe_interface_details_t_handler (
188 vl_api_flowprobe_interface_details_t *mp)
190 vat_main_t *vam = flowprobe_test_main.vat_main;
195 const char *variants[] = {
196 [FLOWPROBE_WHICH_IP4] = "ip4",
197 [FLOWPROBE_WHICH_IP6] = "ip6",
198 [FLOWPROBE_WHICH_L2] = "l2",
201 const char *directions[] = {
202 [FLOWPROBE_DIRECTION_RX] = "rx",
203 [FLOWPROBE_DIRECTION_TX] = "tx",
204 [FLOWPROBE_DIRECTION_BOTH] = "rx tx",
205 "Erroneous direction",
208 sw_if_index = ntohl (mp->sw_if_index);
211 if (which > ARRAY_LEN (variants) - 2)
212 which = ARRAY_LEN (variants) - 1;
214 direction = mp->direction;
215 if (direction > ARRAY_LEN (directions) - 2)
216 direction = ARRAY_LEN (directions) - 1;
218 out = format (0, "sw_if_index: %u, variant: %s, direction: %s\n%c",
219 sw_if_index, variants[which], directions[direction], 0);
221 fformat (vam->ofp, (char *) out);
226 api_flowprobe_params (vat_main_t * vam)
228 unformat_input_t *i = vam->input;
229 u32 active_timer = ~0;
230 u32 passive_timer = ~0;
231 vl_api_flowprobe_params_t *mp;
235 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
237 if (unformat (i, "active %d", &active_timer))
239 else if (unformat (i, "passive %d", &passive_timer))
241 else if (unformat (i, "record"))
242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
244 if (unformat (i, "l2"))
245 record_flags |= FLOWPROBE_RECORD_FLAG_L2;
246 else if (unformat (i, "l3"))
247 record_flags |= FLOWPROBE_RECORD_FLAG_L3;
248 else if (unformat (i, "l4"))
249 record_flags |= FLOWPROBE_RECORD_FLAG_L4;
257 if (passive_timer > 0 && active_timer > passive_timer)
259 errmsg ("Passive timer has to be greater than active one...\n");
263 /* Construct the API message */
264 M (FLOWPROBE_PARAMS, mp);
265 mp->record_flags = record_flags;
266 mp->active_timer = ntohl (active_timer);
267 mp->passive_timer = ntohl (passive_timer);
272 /* Wait for a reply... */
279 api_flowprobe_set_params (vat_main_t *vam)
281 unformat_input_t *i = vam->input;
282 vl_api_flowprobe_set_params_t *mp;
283 u32 active_timer = ~0;
284 u32 passive_timer = ~0;
288 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
290 if (unformat (i, "active %d", &active_timer))
292 else if (unformat (i, "passive %d", &passive_timer))
294 else if (unformat (i, "record"))
295 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
297 if (unformat (i, "l2"))
298 record_flags |= FLOWPROBE_RECORD_FLAG_L2;
299 else if (unformat (i, "l3"))
300 record_flags |= FLOWPROBE_RECORD_FLAG_L3;
301 else if (unformat (i, "l4"))
302 record_flags |= FLOWPROBE_RECORD_FLAG_L4;
310 /* Construct the API message */
311 M (FLOWPROBE_SET_PARAMS, mp);
312 mp->record_flags = record_flags;
313 mp->active_timer = ntohl (active_timer);
314 mp->passive_timer = ntohl (passive_timer);
319 /* Wait for a reply... */
326 api_flowprobe_get_params (vat_main_t *vam)
328 vl_api_flowprobe_get_params_t *mp;
331 /* Construct the API message */
332 M (FLOWPROBE_GET_PARAMS, mp);
337 /* Wait for a reply... */
343 vl_api_flowprobe_get_params_reply_t_handler (
344 vl_api_flowprobe_get_params_reply_t *mp)
346 vat_main_t *vam = flowprobe_test_main.vat_main;
350 format (0, "active: %u, passive: %u, record:", ntohl (mp->active_timer),
351 ntohl (mp->passive_timer));
353 if (mp->record_flags & FLOWPROBE_RECORD_FLAG_L2)
354 out = format (out, " l2");
355 if (mp->record_flags & FLOWPROBE_RECORD_FLAG_L3)
356 out = format (out, " l3");
357 if (mp->record_flags & FLOWPROBE_RECORD_FLAG_L4)
358 out = format (out, " l4");
360 out = format (out, "\n%c", 0);
361 fformat (vam->ofp, (char *) out);
363 vam->result_ready = 1;
367 * List of messages that the api test plugin sends,
368 * and that the data plane plugin processes
370 #include <flowprobe/flowprobe.api_test.c>
373 * fd.io coding-style-patch-verification: ON
376 * eval: (c-set-style "gnu")