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.api_enum.h>
30 #include <ioam/udp-ping/udp_ping.api_types.h>
32 #define vl_endianfun /* define message structures */
34 #define vl_print(handle, ...)
35 #define vl_api_version(n,v) static u32 api_version=(v);
36 #include <ioam/udp-ping/udp_ping.api.h>
43 /* API message ID base */
46 } udp_ping_test_main_t;
48 udp_ping_test_main_t udp_ping_test_main;
50 #define foreach_standard_reply_retval_handler \
51 _(udp_ping_add_del_reply) \
52 _(udp_ping_export_reply)
55 static void vl_api_##n##_t_handler \
56 (vl_api_##n##_t * mp) \
58 vat_main_t * vam = udp_ping_test_main.vat_main; \
59 i32 retval = ntohl(mp->retval); \
60 if (vam->async_mode) { \
61 vam->async_errors += (retval < 0); \
63 vam->retval = retval; \
64 vam->result_ready = 1; \
67 foreach_standard_reply_retval_handler;
71 * Table of message reply handlers, must include boilerplate handlers
74 #define foreach_vpe_api_reply_msg \
75 _(UDP_PING_ADD_DEL_REPLY, udp_ping_add_del_reply) \
76 _(UDP_PING_EXPORT_REPLY, udp_ping_export_reply) \
79 /* M: construct, but don't yet send a message */
83 vam->result_ready = 0; \
84 mp = vl_msg_api_alloc(sizeof(*mp)); \
85 clib_memset (mp, 0, sizeof (*mp)); \
86 mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
87 mp->client_index = vam->my_client_index; \
90 /* S: send a message */
91 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
93 /* W: wait for results, with timeout */
96 timeout = vat_time_now (vam) + 5.0; \
98 while (vat_time_now (vam) < timeout) { \
99 if (vam->result_ready == 1) { \
100 return (vam->retval); \
107 api_udp_ping_add_del (vat_main_t * vam)
109 udp_ping_test_main_t *sm = &udp_ping_test_main;
110 unformat_input_t *input = vam->input;
111 vl_api_udp_ping_add_del_t *mp;
113 ip6_address_t dst, src;
114 u32 start_src_port, end_src_port;
115 u32 start_dst_port, end_dst_port;
120 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
122 if (unformat (input, "src %U", unformat_ip6_address, &src))
124 else if (unformat (input, "start-src-port %d", &start_src_port))
126 else if (unformat (input, "end-src-port %d", &end_src_port))
128 else if (unformat (input, "start-dst-port %d", &start_dst_port))
130 else if (unformat (input, "end-dst-port %d", &end_dst_port))
132 else if (unformat (input, "dst %U", unformat_ip6_address, &dst))
134 else if (unformat (input, "interval %d", &interval))
136 else if (unformat (input, "disable"))
142 M (UDP_PING_ADD_DEL, udp_ping_add);
144 clib_memcpy (mp->src_ip_address, &src, 16);
145 clib_memcpy (mp->dst_ip_address, &dst, 16);
146 mp->start_src_port = (u16) start_src_port;
147 mp->end_src_port = (u16) end_src_port;
148 mp->start_dst_port = (u16) start_dst_port;
149 mp->end_dst_port = (u16) end_dst_port;
150 mp->interval = (u16) interval;
152 mp->dis = is_disable;
161 api_udp_ping_export (vat_main_t * vam)
163 udp_ping_test_main_t *sm = &udp_ping_test_main;
164 unformat_input_t *input = vam->input;
165 vl_api_udp_ping_export_t *mp;
170 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
172 if (unformat (input, "export"))
174 else if (unformat (input, "disable"))
180 M (UDP_PING_EXPORT, udp_ping_export);
191 * List of messages that the api test plugin sends,
192 * and that the data plane plugin processes
194 #define foreach_vpe_api_msg \
195 _(udp_ping_add_del, "src <local IPv6 address> start-src-port <first local port> "\
196 "end-src-port <last local port> " \
197 "dst <remote IPv6 address> start-dst-port <first destination port> "\
198 "end-dst-port <last destination port> "\
199 "interval <time interval in sec for which ping packet will be sent> "\
201 _(udp_ping_export, "export [disable]") \
205 udp_ping_test_api_hookup (vat_main_t * vam)
207 udp_ping_test_main_t *sm = &udp_ping_test_main;
208 /* Hook up handlers for replies from the data plane plug-in */
210 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
212 vl_api_##n##_t_handler, \
214 vl_api_##n##_t_endian, \
215 vl_api_##n##_t_print, \
216 sizeof(vl_api_##n##_t), 1);
217 foreach_vpe_api_reply_msg;
220 /* API messages we can send */
221 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
226 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
232 udp_ping_vat_plugin_register (vat_main_t * vam)
234 udp_ping_test_main_t *sm = &udp_ping_test_main;
239 name = format (0, "udp_ping_%08x%c", api_version, 0);
240 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
242 if (sm->msg_id_base != (u16) ~ 0)
243 udp_ping_test_api_hookup (vam);
251 * fd.io coding-style-patch-verification: ON
254 * eval: (c-set-style "gnu")