3 * dpdk_test.c - skeleton vpp-api-test plug-in
5 * Copyright (c) <current-year> <your-organization>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <vlibapi/api.h>
20 #include <vlibmemory/api.h>
21 #include <vppinfra/error.h>
22 #include <vnet/ip/ip.h>
24 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
26 /* Declare message IDs */
27 #include <dpdk/api/dpdk_msg_enum.h>
29 /* define message structures */
31 #include <dpdk/api/dpdk.api.h>
34 /* declare message handlers for each api */
36 #define vl_endianfun /* define message structures */
37 #include <dpdk/api/dpdk.api.h>
40 /* instantiate all the print functions we know about */
41 #define vl_print(handle, ...)
43 #include <dpdk/api/dpdk.api.h>
46 /* Get the API version number. */
47 #define vl_api_version(n,v) static u32 api_version=(v);
48 #include <dpdk/api/dpdk.api.h>
52 /* API message ID base */
57 dpdk_test_main_t dpdk_test_main;
59 #define foreach_standard_reply_retval_handler \
60 _(sw_interface_set_dpdk_hqos_pipe_reply) \
61 _(sw_interface_set_dpdk_hqos_subport_reply) \
62 _(sw_interface_set_dpdk_hqos_tctbl_reply)
65 static void vl_api_##n##_t_handler \
66 (vl_api_##n##_t * mp) \
68 vat_main_t * vam = dpdk_test_main.vat_main; \
69 i32 retval = ntohl(mp->retval); \
70 if (vam->async_mode) { \
71 vam->async_errors += (retval < 0); \
73 vam->retval = retval; \
74 vam->result_ready = 1; \
77 foreach_standard_reply_retval_handler;
81 * Table of message reply handlers, must include boilerplate handlers
84 #define foreach_vpe_api_reply_msg \
85 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
86 sw_interface_set_dpdk_hqos_pipe_reply) \
87 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
88 sw_interface_set_dpdk_hqos_subport_reply) \
89 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
90 sw_interface_set_dpdk_hqos_tctbl_reply)
92 /* M: construct, but don't yet send a message */
95 vam->result_ready = 0; \
96 mp = vl_msg_api_alloc(sizeof(*mp)); \
97 clib_memset (mp, 0, sizeof (*mp)); \
98 mp->_vl_msg_id = ntohs (VL_API_##T + dm->msg_id_base); \
99 mp->client_index = vam->my_client_index; \
104 vam->result_ready = 0; \
105 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
106 clib_memset (mp, 0, sizeof (*mp)); \
107 mp->_vl_msg_id = ntohs (VL_API_##T + dm->msg_id_base); \
108 mp->client_index = vam->my_client_index; \
111 /* S: send a message */
112 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
114 /* W: wait for results, with timeout */
117 timeout = vat_time_now (vam) + 1.0; \
119 while (vat_time_now (vam) < timeout) { \
120 if (vam->result_ready == 1) { \
121 return (vam->retval); \
128 api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
130 dpdk_test_main_t * dm = &dpdk_test_main;
131 unformat_input_t *i = vam->input;
132 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
135 u8 sw_if_index_set = 0;
143 /* Parse args required to build the message */
144 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
146 if (unformat (i, "rx sw_if_index %u", &sw_if_index))
148 else if (unformat (i, "subport %u", &subport))
150 else if (unformat (i, "pipe %u", &pipe))
152 else if (unformat (i, "profile %u", &profile))
158 if (sw_if_index_set == 0)
160 errmsg ("missing interface name or sw_if_index");
164 if (subport_set == 0)
166 errmsg ("missing subport ");
172 errmsg ("missing pipe");
176 if (profile_set == 0)
178 errmsg ("missing profile");
182 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
184 mp->sw_if_index = ntohl (sw_if_index);
185 mp->subport = ntohl (subport);
186 mp->pipe = ntohl (pipe);
187 mp->profile = ntohl (profile);
197 api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
199 dpdk_test_main_t * dm = &dpdk_test_main;
200 unformat_input_t *i = vam->input;
201 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
204 u8 sw_if_index_set = 0;
207 u32 tb_rate = 1250000000; /* 10GbE */
208 u32 tb_size = 1000000;
209 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
212 /* Parse args required to build the message */
213 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
215 if (unformat (i, "rx sw_if_index %u", &sw_if_index))
217 else if (unformat (i, "subport %u", &subport))
219 else if (unformat (i, "rate %u", &tb_rate))
223 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
225 tc_rate[tc_id] = tb_rate;
227 else if (unformat (i, "bktsize %u", &tb_size))
229 else if (unformat (i, "tc0 %u", &tc_rate[0]))
231 else if (unformat (i, "tc1 %u", &tc_rate[1]))
233 else if (unformat (i, "tc2 %u", &tc_rate[2]))
235 else if (unformat (i, "tc3 %u", &tc_rate[3]))
237 else if (unformat (i, "period %u", &tc_period))
243 if (sw_if_index_set == 0)
245 errmsg ("missing interface name or sw_if_index");
249 if (subport_set == 0)
251 errmsg ("missing subport ");
255 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
257 mp->sw_if_index = ntohl (sw_if_index);
258 mp->subport = ntohl (subport);
259 mp->tb_rate = ntohl (tb_rate);
260 mp->tb_size = ntohl (tb_size);
261 mp->tc_rate[0] = ntohl (tc_rate[0]);
262 mp->tc_rate[1] = ntohl (tc_rate[1]);
263 mp->tc_rate[2] = ntohl (tc_rate[2]);
264 mp->tc_rate[3] = ntohl (tc_rate[3]);
265 mp->tc_period = ntohl (tc_period);
274 api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
276 dpdk_test_main_t * dm = &dpdk_test_main;
277 unformat_input_t *i = vam->input;
278 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
281 u8 sw_if_index_set = 0;
285 u32 entry, tc, queue;
287 /* Parse args required to build the message */
288 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
290 if (unformat (i, "rx sw_if_index %u", &sw_if_index))
292 else if (unformat (i, "entry %d", &entry))
294 else if (unformat (i, "tc %d", &tc))
296 else if (unformat (i, "queue %d", &queue))
302 if (sw_if_index_set == 0)
304 errmsg ("missing interface name or sw_if_index");
310 errmsg ("missing entry ");
316 errmsg ("missing traffic class ");
322 errmsg ("missing queue ");
326 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
328 mp->sw_if_index = ntohl (sw_if_index);
329 mp->entry = ntohl (entry);
331 mp->queue = ntohl (queue);
340 * List of messages that the api test plugin sends,
341 * and that the data plane plugin processes
343 #define foreach_vpe_api_msg \
344 _(sw_interface_set_dpdk_hqos_pipe, \
345 "rx sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
346 "profile <profile-id>\n") \
347 _(sw_interface_set_dpdk_hqos_subport, \
348 "rx sw_if_index <id> subport <subport-id> [rate <n>]\n" \
349 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
350 _(sw_interface_set_dpdk_hqos_tctbl, \
351 "rx sw_if_index <id> entry <n> tc <n> queue <n>\n")
353 static void dpdk_api_hookup (vat_main_t *vam)
355 dpdk_test_main_t * dm __attribute__((unused)) = &dpdk_test_main;
356 /* Hook up handlers for replies from the data plane plug-in */
358 vl_msg_api_set_handlers((VL_API_##N + dm->msg_id_base), \
360 vl_api_##n##_t_handler, \
362 vl_api_##n##_t_endian, \
363 vl_api_##n##_t_print, \
364 sizeof(vl_api_##n##_t), 1);
365 foreach_vpe_api_reply_msg;
368 /* API messages we can send */
369 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
374 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
379 clib_error_t * vat_plugin_register (vat_main_t *vam)
381 dpdk_test_main_t * dm = &dpdk_test_main;
386 /* Ask the vpp engine for the first assigned message-id */
387 name = format (0, "dpdk_%08x%c", api_version, 0);
388 dm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
390 if (dm->msg_id_base != (u16) ~0)
391 dpdk_api_hookup (vam);