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 /* Declare message IDs */
25 #include <mactime/mactime.api_enum.h>
26 #include <mactime/mactime.api_types.h>
30 /* API message ID base */
33 } mactime_test_main_t;
35 mactime_test_main_t mactime_test_main;
37 #define __plugin_msg_base mactime_test_main.msg_id_base
38 #include <vlibapi/vat_helper_macros.h>
41 api_mactime_enable_disable (vat_main_t * vam)
43 unformat_input_t *i = vam->input;
44 int enable_disable = 1;
46 vl_api_mactime_enable_disable_t *mp;
49 /* Parse args required to build the message */
50 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
52 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
54 else if (unformat (i, "sw_if_index %d", &sw_if_index))
56 else if (unformat (i, "disable"))
62 if (sw_if_index == ~0)
64 errmsg ("missing interface name / explicit sw_if_index number \n");
68 /* Construct the API message */
69 M (MACTIME_ENABLE_DISABLE, mp);
70 mp->sw_if_index = ntohl (sw_if_index);
71 mp->enable_disable = enable_disable;
76 /* Wait for a reply... */
81 /* These two ought to be in a library somewhere but they aren't */
83 my_unformat_mac_address (unformat_input_t * input, va_list * args)
85 u8 *a = va_arg (*args, u8 *);
86 return unformat (input, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3],
91 my_format_mac_address (u8 * s, va_list * args)
93 u8 *a = va_arg (*args, u8 *);
94 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
95 a[0], a[1], a[2], a[3], a[4], a[5]);
99 api_mactime_add_del_range (vat_main_t * vam)
101 unformat_input_t *i = vam->input;
102 vl_api_mactime_add_del_range_t *mp;
105 clib_timebase_range_t *rp = 0;
117 /* Parse args required to build the message */
118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
120 if (unformat (i, "name %s", &device_name))
122 vec_add1 (device_name, 0);
125 else if (unformat (i, "allow-range %U",
126 unformat_clib_timebase_range_vector, &rp))
128 else if (unformat (i, "allow-quota-range %U",
129 unformat_clib_timebase_range_vector, &rp))
131 else if (unformat (i, "drop-range %U",
132 unformat_clib_timebase_range_vector, &rp))
134 else if (unformat (i, "allow-static"))
136 else if (unformat (i, "drop-static"))
138 else if (unformat (i, "no-udp-10001"))
140 else if (unformat (i, "mac %U", my_unformat_mac_address, mac_address))
142 else if (unformat (i, "del"))
144 else if (unformat (i, "data-quota %lldM", &data_quota))
146 else if (unformat (i, "data-quota %lldG", &data_quota))
156 vec_free (device_name);
157 errmsg ("mac address required, not set\n");
161 /* allow-range / drop-range parse errors cause this condition */
162 if (is_add && allow == 0 && drop == 0 && allow_quota == 0)
165 vec_free (device_name);
166 errmsg ("parse error...\n");
170 /* Unlikely, but check anyhow */
171 if (vec_len (device_name) > ARRAY_LEN (mp->device_name))
174 vec_free (device_name);
175 errmsg ("device name too long, max %d\n", ARRAY_LEN (mp->device_name));
179 /* Cough up a device name if none set */
182 device_name = format (0, "mac %U%c", my_format_mac_address,
186 /* Construct the API message */
187 M2 (MACTIME_ADD_DEL_RANGE, mp, sizeof (rp[0]) * vec_len (rp));
191 mp->allow_quota = allow_quota;
192 mp->no_udp_10001 = no_udp_10001;
193 mp->data_quota = clib_host_to_net_u64 (data_quota);
194 memcpy (mp->mac_address, mac_address, sizeof (mp->mac_address));
195 memcpy (mp->device_name, device_name, vec_len (device_name));
196 mp->count = clib_host_to_net_u32 (vec_len (rp));
198 for (ii = 0; ii < vec_len (rp); ii++)
200 mp->ranges[ii].start = rp[ii].start;
201 mp->ranges[ii].end = rp[ii].end;
205 vec_free (device_name);
210 /* Wait for a reply... */
215 #include <mactime/mactime.api_test.c>
218 * fd.io coding-style-patch-verification: ON
221 * eval: (c-set-style "gnu")