2 * mactime.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>
21 #include <vppinfra/time_range.h>
22 #include <vnet/ethernet/ethernet.h>
24 uword vat_unformat_sw_if_index (unformat_input_t * input, va_list * args);
26 /* Declare message IDs */
27 #include <mactime/mactime.api_enum.h>
28 #include <mactime/mactime.api_types.h>
32 /* API message ID base */
35 } mactime_test_main_t;
37 mactime_test_main_t mactime_test_main;
39 #define __plugin_msg_base mactime_test_main.msg_id_base
40 #include <vlibapi/vat_helper_macros.h>
43 api_mactime_enable_disable (vat_main_t * vam)
45 unformat_input_t *i = vam->input;
46 int enable_disable = 1;
48 vl_api_mactime_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, &sw_if_index))
56 else if (unformat (i, "sw_if_index %d", &sw_if_index))
58 else if (unformat (i, "disable"))
64 if (sw_if_index == ~0)
66 errmsg ("missing interface name / explicit sw_if_index number \n");
70 /* Construct the API message */
71 M (MACTIME_ENABLE_DISABLE, mp);
72 mp->sw_if_index = ntohl (sw_if_index);
73 mp->enable_disable = enable_disable;
78 /* Wait for a reply... */
83 /* These two ought to be in a library somewhere but they aren't */
85 my_unformat_mac_address (unformat_input_t * input, va_list * args)
87 u8 *a = va_arg (*args, u8 *);
88 return unformat (input, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3],
93 my_format_mac_address (u8 * s, va_list * args)
95 u8 *a = va_arg (*args, u8 *);
96 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
97 a[0], a[1], a[2], a[3], a[4], a[5]);
101 api_mactime_add_del_range (vat_main_t * vam)
103 unformat_input_t *i = vam->input;
104 vl_api_mactime_add_del_range_t *mp;
107 clib_timebase_range_t *rp = 0;
119 /* Parse args required to build the message */
120 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
122 if (unformat (i, "name %s", &device_name))
124 vec_add1 (device_name, 0);
127 else if (unformat (i, "allow-range %U",
128 unformat_clib_timebase_range_vector, &rp))
130 else if (unformat (i, "allow-quota-range %U",
131 unformat_clib_timebase_range_vector, &rp))
133 else if (unformat (i, "drop-range %U",
134 unformat_clib_timebase_range_vector, &rp))
136 else if (unformat (i, "allow-static"))
138 else if (unformat (i, "drop-static"))
140 else if (unformat (i, "no-udp-10001"))
142 else if (unformat (i, "mac %U", my_unformat_mac_address, mac_address))
144 else if (unformat (i, "del"))
146 else if (unformat (i, "data-quota %lldM", &data_quota))
148 else if (unformat (i, "data-quota %lldG", &data_quota))
158 vec_free (device_name);
159 errmsg ("mac address required, not set\n");
163 /* allow-range / drop-range parse errors cause this condition */
164 if (is_add && allow == 0 && drop == 0 && allow_quota == 0)
167 vec_free (device_name);
168 errmsg ("parse error...\n");
172 /* Unlikely, but check anyhow */
173 if (vec_len (device_name) > ARRAY_LEN (mp->device_name))
176 vec_free (device_name);
177 errmsg ("device name too long, max %d\n", ARRAY_LEN (mp->device_name));
181 /* Cough up a device name if none set */
184 device_name = format (0, "mac %U%c", my_format_mac_address,
188 /* Construct the API message */
189 M2 (MACTIME_ADD_DEL_RANGE, mp, sizeof (rp[0]) * vec_len (rp));
193 mp->allow_quota = allow_quota;
194 mp->no_udp_10001 = no_udp_10001;
195 mp->data_quota = clib_host_to_net_u64 (data_quota);
196 memcpy (mp->mac_address, mac_address, sizeof (mp->mac_address));
197 memcpy (mp->device_name, device_name, vec_len (device_name));
198 mp->count = clib_host_to_net_u32 (vec_len (rp));
200 for (ii = 0; ii < vec_len (rp); ii++)
202 mp->ranges[ii].start = rp[ii].start;
203 mp->ranges[ii].end = rp[ii].end;
207 vec_free (device_name);
212 /* Wait for a reply... */
217 #include <mactime/mactime.api_test.c>
220 * fd.io coding-style-patch-verification: ON
223 * eval: (c-set-style "gnu")