2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 *------------------------------------------------------------------
17 * udp_ping_test.c - test harness for udp ping plugin
18 *------------------------------------------------------------------
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
25 #include <vppinfra/error.h>
26 #include <vnet/ip/ip.h>
28 /* Declare message IDs */
29 #include <ioam/udp-ping/udp_ping_msg_enum.h>
31 /* define message structures */
33 #include <ioam/udp-ping/udp_ping_all_api_h.h>
36 /* declare message handlers for each api */
38 #define vl_endianfun /* define message structures */
39 #include <ioam/udp-ping/udp_ping_all_api_h.h>
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...)
45 #include <ioam/udp-ping/udp_ping_all_api_h.h>
48 /* Get the API version number. */
49 #define vl_api_version(n,v) static u32 api_version=(v);
50 #include <ioam/udp-ping/udp_ping_all_api_h.h>
56 /* API message ID base */
59 } udp_ping_test_main_t;
61 udp_ping_test_main_t udp_ping_test_main;
63 #define foreach_standard_reply_retval_handler \
64 _(udp_ping_add_del_reply) \
65 _(udp_ping_export_reply)
68 static void vl_api_##n##_t_handler \
69 (vl_api_##n##_t * mp) \
71 vat_main_t * vam = udp_ping_test_main.vat_main; \
72 i32 retval = ntohl(mp->retval); \
73 if (vam->async_mode) { \
74 vam->async_errors += (retval < 0); \
76 vam->retval = retval; \
77 vam->result_ready = 1; \
80 foreach_standard_reply_retval_handler;
84 * Table of message reply handlers, must include boilerplate handlers
87 #define foreach_vpe_api_reply_msg \
88 _(UDP_PING_ADD_DEL_REPLY, udp_ping_add_del_reply) \
89 _(UDP_PING_EXPORT_REPLY, udp_ping_export_reply) \
92 /* 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 + sm->msg_id_base); \
100 mp->client_index = vam->my_client_index; \
103 /* S: send a message */
104 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
106 /* W: wait for results, with timeout */
109 timeout = vat_time_now (vam) + 5.0; \
111 while (vat_time_now (vam) < timeout) { \
112 if (vam->result_ready == 1) { \
113 return (vam->retval); \
120 api_udp_ping_add_del_req (vat_main_t * vam)
122 udp_ping_test_main_t *sm = &udp_ping_test_main;
123 unformat_input_t *input = vam->input;
124 vl_api_udp_ping_add_del_req_t *mp;
126 ip6_address_t dst, src;
127 u32 start_src_port, end_src_port;
128 u32 start_dst_port, end_dst_port;
133 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
135 if (unformat (input, "src %U", unformat_ip6_address, &src))
137 else if (unformat (input, "start-src-port %d", &start_src_port))
139 else if (unformat (input, "end-src-port %d", &end_src_port))
141 else if (unformat (input, "start-dst-port %d", &start_dst_port))
143 else if (unformat (input, "end-dst-port %d", &end_dst_port))
145 else if (unformat (input, "dst %U", unformat_ip6_address, &dst))
147 else if (unformat (input, "interval %d", &interval))
149 else if (unformat (input, "disable"))
155 M (UDP_PING_ADD_DEL_REQ, udp_ping_add);
157 clib_memcpy (mp->src_ip_address, &src, 16);
158 clib_memcpy (mp->dst_ip_address, &dst, 16);
159 mp->start_src_port = (u16) start_src_port;
160 mp->end_src_port = (u16) end_src_port;
161 mp->start_dst_port = (u16) start_dst_port;
162 mp->end_dst_port = (u16) end_dst_port;
163 mp->interval = (u16) interval;
165 mp->dis = is_disable;
174 api_udp_ping_export_req (vat_main_t * vam)
176 udp_ping_test_main_t *sm = &udp_ping_test_main;
177 unformat_input_t *input = vam->input;
178 vl_api_udp_ping_export_req_t *mp;
183 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
185 if (unformat (input, "export"))
187 else if (unformat (input, "disable"))
193 M (UDP_PING_EXPORT_REQ, udp_ping_export);
204 * List of messages that the api test plugin sends,
205 * and that the data plane plugin processes
207 #define foreach_vpe_api_msg \
208 _(udp_ping_add_del_req, "src <local IPv6 address> start-src-port <first local port> "\
209 "end-src-port <last local port> " \
210 "dst <remote IPv6 address> start-dst-port <first destination port> "\
211 "end-dst-port <last destination port> "\
212 "interval <time interval in sec for which ping packet will be sent> "\
214 _(udp_ping_export_req, "export [disable]") \
218 udp_ping_test_api_hookup (vat_main_t * vam)
220 udp_ping_test_main_t *sm = &udp_ping_test_main;
221 /* Hook up handlers for replies from the data plane plug-in */
223 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
225 vl_api_##n##_t_handler, \
227 vl_api_##n##_t_endian, \
228 vl_api_##n##_t_print, \
229 sizeof(vl_api_##n##_t), 1);
230 foreach_vpe_api_reply_msg;
233 /* API messages we can send */
234 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
239 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
245 vat_plugin_register (vat_main_t * vam)
247 udp_ping_test_main_t *sm = &udp_ping_test_main;
252 name = format (0, "udp_ping_%08x%c", api_version, 0);
253 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
255 if (sm->msg_id_base != (u16) ~ 0)
256 udp_ping_test_api_hookup (vam);
264 * fd.io coding-style-patch-verification: ON
267 * eval: (c-set-style "gnu")