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 <vlibsocket/api.h>
22 #include <vppinfra/error.h>
23 #include <vnet/ip/ip.h>
25 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
27 /* Declare message IDs */
28 #include <dpdk/api/dpdk_msg_enum.h>
30 /* define message structures */
32 #include <dpdk/api/dpdk.api.h>
35 /* declare message handlers for each api */
37 #define vl_endianfun /* define message structures */
38 #include <dpdk/api/dpdk.api.h>
41 /* instantiate all the print functions we know about */
42 #define vl_print(handle, ...)
44 #include <dpdk/api/dpdk.api.h>
47 /* Get the API version number. */
48 #define vl_api_version(n,v) static u32 api_version=(v);
49 #include <dpdk/api/dpdk.api.h>
53 /* API message ID base */
58 dpdk_test_main_t dpdk_test_main;
60 #define foreach_standard_reply_retval_handler \
61 _(sw_interface_set_dpdk_hqos_pipe_reply) \
62 _(sw_interface_set_dpdk_hqos_subport_reply) \
63 _(sw_interface_set_dpdk_hqos_tctbl_reply)
66 static void vl_api_##n##_t_handler \
67 (vl_api_##n##_t * mp) \
69 vat_main_t * vam = dpdk_test_main.vat_main; \
70 i32 retval = ntohl(mp->retval); \
71 if (vam->async_mode) { \
72 vam->async_errors += (retval < 0); \
74 vam->retval = retval; \
75 vam->result_ready = 1; \
78 foreach_standard_reply_retval_handler;
82 * Table of message reply handlers, must include boilerplate handlers
85 #define foreach_vpe_api_reply_msg \
86 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
87 sw_interface_set_dpdk_hqos_pipe_reply) \
88 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
89 sw_interface_set_dpdk_hqos_subport_reply) \
90 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
91 sw_interface_set_dpdk_hqos_tctbl_reply)
93 /* M: construct, but don't yet send a message */
96 vam->result_ready = 0; \
97 mp = vl_msg_api_alloc(sizeof(*mp)); \
98 memset (mp, 0, sizeof (*mp)); \
99 mp->_vl_msg_id = ntohs (VL_API_##T + dm->msg_id_base); \
100 mp->client_index = vam->my_client_index; \
105 vam->result_ready = 0; \
106 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
107 memset (mp, 0, sizeof (*mp)); \
108 mp->_vl_msg_id = ntohs (VL_API_##T + dm->msg_id_base); \
109 mp->client_index = vam->my_client_index; \
112 /* S: send a message */
113 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
115 /* W: wait for results, with timeout */
118 timeout = vat_time_now (vam) + 1.0; \
120 while (vat_time_now (vam) < timeout) { \
121 if (vam->result_ready == 1) { \
122 return (vam->retval); \
129 api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
131 dpdk_test_main_t * dm = &dpdk_test_main;
132 unformat_input_t *i = vam->input;
133 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
136 u8 sw_if_index_set = 0;
144 /* Parse args required to build the message */
145 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
147 if (unformat (i, "rx sw_if_index %u", &sw_if_index))
149 else if (unformat (i, "subport %u", &subport))
151 else if (unformat (i, "pipe %u", &pipe))
153 else if (unformat (i, "profile %u", &profile))
159 if (sw_if_index_set == 0)
161 errmsg ("missing interface name or sw_if_index");
165 if (subport_set == 0)
167 errmsg ("missing subport ");
173 errmsg ("missing pipe");
177 if (profile_set == 0)
179 errmsg ("missing profile");
183 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
185 mp->sw_if_index = ntohl (sw_if_index);
186 mp->subport = ntohl (subport);
187 mp->pipe = ntohl (pipe);
188 mp->profile = ntohl (profile);
198 api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
200 dpdk_test_main_t * dm = &dpdk_test_main;
201 unformat_input_t *i = vam->input;
202 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
205 u8 sw_if_index_set = 0;
208 u32 tb_rate = 1250000000; /* 10GbE */
209 u32 tb_size = 1000000;
210 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
213 /* Parse args required to build the message */
214 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
216 if (unformat (i, "rx sw_if_index %u", &sw_if_index))
218 else if (unformat (i, "subport %u", &subport))
220 else if (unformat (i, "rate %u", &tb_rate))
224 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
226 tc_rate[tc_id] = tb_rate;
228 else if (unformat (i, "bktsize %u", &tb_size))
230 else if (unformat (i, "tc0 %u", &tc_rate[0]))
232 else if (unformat (i, "tc1 %u", &tc_rate[1]))
234 else if (unformat (i, "tc2 %u", &tc_rate[2]))
236 else if (unformat (i, "tc3 %u", &tc_rate[3]))
238 else if (unformat (i, "period %u", &tc_period))
244 if (sw_if_index_set == 0)
246 errmsg ("missing interface name or sw_if_index");
250 if (subport_set == 0)
252 errmsg ("missing subport ");
256 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
258 mp->sw_if_index = ntohl (sw_if_index);
259 mp->subport = ntohl (subport);
260 mp->tb_rate = ntohl (tb_rate);
261 mp->tb_size = ntohl (tb_size);
262 mp->tc_rate[0] = ntohl (tc_rate[0]);
263 mp->tc_rate[1] = ntohl (tc_rate[1]);
264 mp->tc_rate[2] = ntohl (tc_rate[2]);
265 mp->tc_rate[3] = ntohl (tc_rate[3]);
266 mp->tc_period = ntohl (tc_period);
275 api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
277 dpdk_test_main_t * dm = &dpdk_test_main;
278 unformat_input_t *i = vam->input;
279 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
282 u8 sw_if_index_set = 0;
286 u32 entry, tc, queue;
288 /* Parse args required to build the message */
289 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
291 if (unformat (i, "rx sw_if_index %u", &sw_if_index))
293 else if (unformat (i, "entry %d", &entry))
295 else if (unformat (i, "tc %d", &tc))
297 else if (unformat (i, "queue %d", &queue))
303 if (sw_if_index_set == 0)
305 errmsg ("missing interface name or sw_if_index");
311 errmsg ("missing entry ");
317 errmsg ("missing traffic class ");
323 errmsg ("missing queue ");
327 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
329 mp->sw_if_index = ntohl (sw_if_index);
330 mp->entry = ntohl (entry);
332 mp->queue = ntohl (queue);
341 * List of messages that the api test plugin sends,
342 * and that the data plane plugin processes
344 #define foreach_vpe_api_msg \
345 _(sw_interface_set_dpdk_hqos_pipe, \
346 "rx sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
347 "profile <profile-id>\n") \
348 _(sw_interface_set_dpdk_hqos_subport, \
349 "rx sw_if_index <id> subport <subport-id> [rate <n>]\n" \
350 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
351 _(sw_interface_set_dpdk_hqos_tctbl, \
352 "rx sw_if_index <id> entry <n> tc <n> queue <n>\n")
354 void vat_api_hookup (vat_main_t *vam)
356 dpdk_test_main_t * dm __attribute__((unused)) = &dpdk_test_main;
357 /* Hook up handlers for replies from the data plane plug-in */
359 vl_msg_api_set_handlers((VL_API_##N + dm->msg_id_base), \
361 vl_api_##n##_t_handler, \
363 vl_api_##n##_t_endian, \
364 vl_api_##n##_t_print, \
365 sizeof(vl_api_##n##_t), 1);
366 foreach_vpe_api_reply_msg;
369 /* API messages we can send */
370 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
375 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
380 clib_error_t * vat_plugin_register (vat_main_t *vam)
382 dpdk_test_main_t * dm = &dpdk_test_main;
387 /* Ask the vpp engine for the first assigned message-id */
388 name = format (0, "dpdk_%08x%c", api_version, 0);
389 dm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
391 if (dm->msg_id_base != (u16) ~0)
392 vat_api_hookup (vam);