4 * Copyright (c) 2021 Cisco and/or its affiliates.
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.
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
24 #include <vppinfra/error.h>
25 #include <arping/arping.h>
27 #define __plugin_msg_base arping_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
29 #include <vlibmemory/vlib.api_types.h>
31 /* declare message IDs */
32 #include <vnet/format_fns.h>
33 #include <arping/arping.api_enum.h>
34 #include <arping/arping.api_types.h>
35 #include <vnet/ip/ip_types_api.h>
39 /* API message ID base */
45 arping_test_main_t arping_test_main;
47 /* arping request API */
49 api_arping (vat_main_t *vam)
52 arping_args_t args = { 0 };
54 unformat_input_t *input = vam->input;
55 f64 interval = ARPING_DEFAULT_INTERVAL;
56 vl_api_control_ping_t *mp_ping;
57 arping_test_main_t *atm = &arping_test_main;
59 args.repeat = ARPING_DEFAULT_REPEAT;
60 args.interval = ARPING_DEFAULT_INTERVAL;
61 args.sw_if_index = ~0;
63 if (unformat (input, "gratuitous"))
66 if (unformat (input, "%U", unformat_ip4_address, &args.address.ip.ip4))
67 args.address.version = AF_IP4;
68 else if (unformat (input, "%U", unformat_ip6_address, &args.address.ip.ip6))
69 args.address.version = AF_IP6;
72 errmsg ("expecting IP4/IP6 address `%U'. Usage: arping [gratuitous] "
73 "<addr> <intf> [repeat <count>] [interval <secs>]",
74 format_unformat_error, input);
78 if (!unformat_user (input, api_unformat_sw_if_index, vam, &args.sw_if_index))
80 errmsg ("unknown interface `%U'", format_unformat_error, input);
84 /* parse the rest of the parameters in a cycle */
85 while (!unformat_eof (input, NULL))
87 if (unformat (input, "interval"))
89 if (!unformat (input, "%f", &interval))
91 errmsg ("expecting interval (floating point number) got `%U'",
92 format_unformat_error, input);
95 args.interval = interval;
97 else if (unformat (input, "repeat"))
99 if (!unformat (input, "%u", &args.repeat))
101 errmsg ("expecting repeat count but got `%U'",
102 format_unformat_error, input);
108 errmsg ("unknown input `%U'", format_unformat_error, input);
115 mp->interval = clib_host_to_net_f64 (args.interval);
116 mp->repeat = clib_host_to_net_u32 (args.repeat);
117 mp->is_garp = args.is_garp;
118 mp->sw_if_index = clib_host_to_net_u32 (args.sw_if_index);
119 ip_address_encode2 (&args.address, &mp->address);
123 /* Use a control ping for synchronization */
125 atm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
126 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
127 mp_ping->_vl_msg_id = htons (atm->ping_id);
128 mp_ping->client_index = vam->my_client_index;
130 fformat (vam->ofp, "Sending ping id=%d\n", atm->ping_id);
132 vam->result_ready = 0;
140 /* arping-create reply handler */
142 vl_api_arping_reply_t_handler (vl_api_arping_reply_t *mp)
144 vat_main_t *vam = arping_test_main.vat_main;
145 i32 retval = ntohl (mp->retval);
149 fformat (vam->ofp, "arping request reply count = %d\n",
150 ntohl (mp->reply_count));
153 vam->retval = retval;
154 vam->result_ready = 1;
158 api_arping_acd (vat_main_t *vam)
160 // NOT YET IMPLEMENTED
165 vl_api_arping_acd_reply_t_handler (vl_api_arping_reply_t *mp)
167 // NOT YET IMPLEMENTED
170 #include <arping/arping.api_test.c>
173 * fd.io coding-style-patch-verification: ON
176 * eval: (c-set-style "gnu")