2 * nsim.c - skeleton vpp-api-test plug-in
4 * Copyright (c) <current-year> <your-organization>
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.
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
22 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
24 /* Declare message IDs */
25 #include <nsim/nsim.api_enum.h>
26 #include <nsim/nsim.api_types.h>
30 /* API message ID base */
35 nsim_test_main_t nsim_test_main;
37 #define __plugin_msg_base nsim_test_main.msg_id_base
38 #include <vlibapi/vat_helper_macros.h>
41 api_nsim_cross_connect_enable_disable (vat_main_t * vam)
43 unformat_input_t *i = vam->input;
44 int enable_disable = 1;
45 u32 sw_if_index0 = ~0;
46 u32 sw_if_index1 = ~0;
48 vl_api_nsim_cross_connect_enable_disable_t *mp;
51 /* Parse args required to build the message */
52 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
54 if (unformat (i, "%U", unformat_sw_if_index, vam, &tmp))
56 if (sw_if_index0 == ~0)
61 else if (unformat (i, "sw_if_index %d", &tmp))
63 if (sw_if_index0 == ~0)
68 else if (unformat (i, "disable"))
74 if (sw_if_index0 == ~0 || sw_if_index1 == ~0)
76 errmsg ("missing interface name / explicit sw_if_index number \n");
80 /* Construct the API message */
81 M (NSIM_CROSS_CONNECT_ENABLE_DISABLE, mp);
82 mp->sw_if_index0 = ntohl (sw_if_index0);
83 mp->sw_if_index1 = ntohl (sw_if_index1);
84 mp->enable_disable = enable_disable;
89 /* Wait for a reply... */
95 api_nsim_output_feature_enable_disable (vat_main_t * vam)
97 unformat_input_t *i = vam->input;
98 int enable_disable = 1;
100 vl_api_nsim_output_feature_enable_disable_t *mp;
103 /* Parse args required to build the message */
104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
106 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
108 else if (unformat (i, "sw_if_index %d", &sw_if_index))
110 else if (unformat (i, "disable"))
116 if (sw_if_index == ~0)
118 errmsg ("missing interface name / explicit sw_if_index number \n");
122 /* Construct the API message */
123 M (NSIM_OUTPUT_FEATURE_ENABLE_DISABLE, mp);
124 mp->sw_if_index = ntohl (sw_if_index);
125 mp->enable_disable = enable_disable;
130 /* Wait for a reply... */
136 unformat_delay (unformat_input_t * input, va_list * args)
138 f64 *result = va_arg (*args, f64 *);
141 if (unformat (input, "%f us", &tmp))
142 *result = tmp * 1e-6;
143 else if (unformat (input, "%f ms", &tmp))
144 *result = tmp * 1e-3;
145 else if (unformat (input, "%f sec", &tmp))
154 unformat_bandwidth (unformat_input_t * input, va_list * args)
156 f64 *result = va_arg (*args, f64 *);
159 if (unformat (input, "%f gbit", &tmp))
161 else if (unformat (input, "%f gbyte", &tmp))
169 api_nsim_configure (vat_main_t * vam)
171 vl_api_nsim_configure_t *mp;
172 unformat_input_t *i = vam->input;
173 f64 delay = 0.0, bandwidth = 0.0;
174 f64 packet_size = 1500.0;
175 u32 packets_per_drop = 0;
178 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
180 if (unformat (i, "delay %U", unformat_delay, &delay))
182 else if (unformat (i, "bandwidth %U", unformat_bandwidth, &bandwidth))
184 else if (unformat (i, "packet-size %f", &packet_size))
186 else if (unformat (i, "packets-per-drop %u", &packets_per_drop))
192 if (delay == 0.0 || bandwidth == 0.0)
194 errmsg ("must specify delay and bandwidth");
198 /* Construct the API message */
199 M (NSIM_CONFIGURE, mp);
200 mp->delay_in_usec = (u32) (delay * 1e6);
201 mp->delay_in_usec = ntohl (mp->delay_in_usec);
202 mp->average_packet_size = (u32) (packet_size);
203 mp->average_packet_size = ntohl (mp->average_packet_size);
204 mp->bandwidth_in_bits_per_second = (u64) (bandwidth);
205 mp->bandwidth_in_bits_per_second =
206 clib_host_to_net_u64 (mp->bandwidth_in_bits_per_second);
207 mp->packets_per_drop = ntohl (packets_per_drop);
212 /* Wait for a reply... */
217 #include <nsim/nsim.api_test.c>
220 * fd.io coding-style-patch-verification: ON
223 * eval: (c-set-style "gnu")