blob: d9325c4ffa282a12a68943493ad0d21e80ec520c [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003 * api_format.c
4 *
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07005 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016 * limitations under the License.
Ed Warnickecb9cada2015-12-08 15:45:58 -070017 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
21#include <vlibapi/api.h>
22#include <vlibmemory/api.h>
23#include <vlibsocket/api.h>
24#include <vnet/ip/ip.h>
25#include <vnet/sr/sr_packet.h>
26#include <vnet/l2/l2_input.h>
27#include <vnet/l2tp/l2tp.h>
28#include <vnet/vxlan/vxlan.h>
Chris Luke27fe48f2016-04-28 13:44:38 -040029#include <vnet/gre/gre.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070030#include <vnet/vxlan-gpe/vxlan_gpe.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070031#include <vnet/lisp-gpe/lisp_gpe.h>
32
Dave Barachaa6920e2016-06-27 09:25:13 -040033#include <vpp-api/vpe_msg_enum.h>
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080034#include <vnet/l2/l2_classify.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070035#include <vnet/l2/l2_vtr.h>
36#include <vnet/classify/input_acl.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070037#include <vnet/classify/policer_classify.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010038#include <vnet/mpls/mpls.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050039#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -070040#include <vnet/ipsec/ipsec.h>
Matus Fabiane5f42fe2016-04-08 11:18:08 +020041#include <vnet/ipsec/ikev2.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050042#else
43#include <inttypes.h>
44#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070045#include <vnet/map/map.h>
Dave Barachc07bf5d2016-02-17 17:52:26 -050046#include <vnet/cop/cop.h>
Shwetha20a64f52016-03-25 10:55:01 +000047#include <vnet/ip/ip6_hop_by_hop.h>
Dave Barach6f9bca22016-04-30 10:25:32 -040048#include <vnet/ip/ip_source_and_port_range_check.h>
Matus Fabian65fcd4d2016-05-13 05:44:48 -070049#include <vnet/policer/xlate.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070050#include <vnet/policer/policer.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070051#include <vnet/policer/police.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070052
53#include "vat/json_format.h"
54
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020055#include <sys/stat.h>
56
Dave Barach72d72232016-08-04 10:15:08 -040057#define vl_typedefs /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080058#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070059#undef vl_typedefs
60
61/* declare message handlers for each api */
62
Dave Barach72d72232016-08-04 10:15:08 -040063#define vl_endianfun /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080064#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070065#undef vl_endianfun
66
67/* instantiate all the print functions we know about */
68#define vl_print(handle, ...)
69#define vl_printfun
Dave Barachaa6920e2016-06-27 09:25:13 -040070#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070071#undef vl_printfun
72
Dave Barach72d72232016-08-04 10:15:08 -040073uword
74unformat_sw_if_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070075{
Dave Barach72d72232016-08-04 10:15:08 -040076 vat_main_t *vam = va_arg (*args, vat_main_t *);
77 u32 *result = va_arg (*args, u32 *);
78 u8 *if_name;
79 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 if (!unformat (input, "%s", &if_name))
Dave Barach72d72232016-08-04 10:15:08 -040082 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
84 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
85 if (p == 0)
Dave Barach72d72232016-08-04 10:15:08 -040086 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087 *result = p[0];
88 return 1;
89}
90
91/* Parse an IP4 address %d.%d.%d.%d. */
Dave Barach72d72232016-08-04 10:15:08 -040092uword
93unformat_ip4_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070094{
Dave Barach72d72232016-08-04 10:15:08 -040095 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 unsigned a[4];
97
Dave Barach72d72232016-08-04 10:15:08 -040098 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 return 0;
100
101 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
102 return 0;
103
104 result[0] = a[0];
105 result[1] = a[1];
106 result[2] = a[2];
107 result[3] = a[3];
108
109 return 1;
110}
111
112
113uword
114unformat_ethernet_address (unformat_input_t * input, va_list * args)
115{
Dave Barach72d72232016-08-04 10:15:08 -0400116 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 u32 i, a[6];
118
Dave Barach72d72232016-08-04 10:15:08 -0400119 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
120 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 return 0;
122
123 /* Check range. */
124 for (i = 0; i < 6; i++)
125 if (a[i] >= (1 << 8))
126 return 0;
127
128 for (i = 0; i < 6; i++)
129 result[i] = a[i];
130
131 return 1;
132}
133
134/* Returns ethernet type as an int in host byte order. */
135uword
136unformat_ethernet_type_host_byte_order (unformat_input_t * input,
137 va_list * args)
138{
Dave Barach72d72232016-08-04 10:15:08 -0400139 u16 *result = va_arg (*args, u16 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140 int type;
141
142 /* Numeric type. */
Dave Barach72d72232016-08-04 10:15:08 -0400143 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144 {
145 if (type >= (1 << 16))
146 return 0;
147 *result = type;
148 return 1;
149 }
150 return 0;
151}
152
153/* Parse an IP6 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400154uword
155unformat_ip6_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156{
Dave Barach72d72232016-08-04 10:15:08 -0400157 ip6_address_t *result = va_arg (*args, ip6_address_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 u16 hex_quads[8];
159 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
160 uword c, n_colon, double_colon_index;
161
162 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
163 double_colon_index = ARRAY_LEN (hex_quads);
164 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
165 {
166 hex_digit = 16;
167 if (c >= '0' && c <= '9')
168 hex_digit = c - '0';
169 else if (c >= 'a' && c <= 'f')
170 hex_digit = c + 10 - 'a';
171 else if (c >= 'A' && c <= 'F')
172 hex_digit = c + 10 - 'A';
173 else if (c == ':' && n_colon < 2)
174 n_colon++;
175 else
176 {
177 unformat_put_input (input);
178 break;
179 }
180
181 /* Too many hex quads. */
182 if (n_hex_quads >= ARRAY_LEN (hex_quads))
183 return 0;
184
185 if (hex_digit < 16)
186 {
187 hex_quad = (hex_quad << 4) | hex_digit;
188
189 /* Hex quad must fit in 16 bits. */
190 if (n_hex_digits >= 4)
191 return 0;
192
193 n_colon = 0;
194 n_hex_digits++;
195 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800196
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197 /* Save position of :: */
198 if (n_colon == 2)
199 {
200 /* More than one :: ? */
201 if (double_colon_index < ARRAY_LEN (hex_quads))
202 return 0;
203 double_colon_index = n_hex_quads;
204 }
205
206 if (n_colon > 0 && n_hex_digits > 0)
207 {
208 hex_quads[n_hex_quads++] = hex_quad;
209 hex_quad = 0;
210 n_hex_digits = 0;
211 }
212 }
213
214 if (n_hex_digits > 0)
215 hex_quads[n_hex_quads++] = hex_quad;
216
217 {
218 word i;
219
220 /* Expand :: to appropriate number of zero hex quads. */
221 if (double_colon_index < ARRAY_LEN (hex_quads))
222 {
223 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
224
225 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
226 hex_quads[n_zero + i] = hex_quads[i];
227
228 for (i = 0; i < n_zero; i++)
229 hex_quads[double_colon_index + i] = 0;
230
231 n_hex_quads = ARRAY_LEN (hex_quads);
232 }
233
234 /* Too few hex quads given. */
235 if (n_hex_quads < ARRAY_LEN (hex_quads))
236 return 0;
237
238 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
239 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
240
241 return 1;
242 }
243}
244
245uword
246unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
247{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500248#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400249 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250
Dave Barach72d72232016-08-04 10:15:08 -0400251 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700252#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
253 foreach_ipsec_policy_action
254#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400255 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256 return 0;
257 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500258#else
259 return 0;
260#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700261}
262
263uword
264unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
265{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500266#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400267 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700268
Dave Barach72d72232016-08-04 10:15:08 -0400269 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
271 foreach_ipsec_crypto_alg
272#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400273 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700274 return 0;
275 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500276#else
277 return 0;
278#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279}
280
281u8 *
282format_ipsec_crypto_alg (u8 * s, va_list * args)
283{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500284#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -0700285 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400286 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287
288 switch (i)
289 {
290#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400291 foreach_ipsec_crypto_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400293 default:
294 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700295 }
296 return format (s, "%s", t);
Dave Barachbfdedbd2016-01-20 09:11:55 -0500297#else
298 return format (s, "Unimplemented");
299#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300}
301
302uword
303unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
304{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500305#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400306 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700307
Dave Barach72d72232016-08-04 10:15:08 -0400308 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
310 foreach_ipsec_integ_alg
311#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400312 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313 return 0;
314 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500315#else
316 return 0;
317#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700318}
319
320u8 *
321format_ipsec_integ_alg (u8 * s, va_list * args)
322{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500323#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400325 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700326
327 switch (i)
328 {
329#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400330 foreach_ipsec_integ_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400332 default:
333 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334 }
335 return format (s, "%s", t);
Dave Barachbfdedbd2016-01-20 09:11:55 -0500336#else
337 return format (s, "Unsupported");
338#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339}
340
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200341uword
342unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
343{
344#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400345 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200346
Dave Barach72d72232016-08-04 10:15:08 -0400347 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200348#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
349 foreach_ikev2_auth_method
350#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400351 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200352 return 0;
353 return 1;
354#else
355 return 0;
356#endif
357}
358
359uword
360unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
361{
362#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400363 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200364
Dave Barach72d72232016-08-04 10:15:08 -0400365 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200366#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
367 foreach_ikev2_id_type
368#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400369 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200370 return 0;
371 return 1;
372#else
373 return 0;
374#endif
375}
376
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700377uword
378unformat_policer_rate_type (unformat_input_t * input, va_list * args)
379{
Dave Barach72d72232016-08-04 10:15:08 -0400380 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700381
382 if (unformat (input, "kbps"))
383 *r = SSE2_QOS_RATE_KBPS;
Dave Barach72d72232016-08-04 10:15:08 -0400384 else if (unformat (input, "pps"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700385 *r = SSE2_QOS_RATE_PPS;
386 else
387 return 0;
388 return 1;
389}
390
391uword
392unformat_policer_round_type (unformat_input_t * input, va_list * args)
393{
Dave Barach72d72232016-08-04 10:15:08 -0400394 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700395
Dave Barach72d72232016-08-04 10:15:08 -0400396 if (unformat (input, "closest"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700397 *r = SSE2_QOS_ROUND_TO_CLOSEST;
398 else if (unformat (input, "up"))
399 *r = SSE2_QOS_ROUND_TO_UP;
400 else if (unformat (input, "down"))
401 *r = SSE2_QOS_ROUND_TO_DOWN;
402 else
403 return 0;
404 return 1;
405}
406
407uword
408unformat_policer_type (unformat_input_t * input, va_list * args)
409{
Dave Barach72d72232016-08-04 10:15:08 -0400410 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700411
412 if (unformat (input, "1r2c"))
413 *r = SSE2_QOS_POLICER_TYPE_1R2C;
414 else if (unformat (input, "1r3c"))
415 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
416 else if (unformat (input, "2r3c-2698"))
417 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
418 else if (unformat (input, "2r3c-4115"))
419 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
420 else if (unformat (input, "2r3c-mef5cf1"))
421 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
422 else
423 return 0;
424 return 1;
425}
426
Matus Fabian4ac74c92016-05-31 07:33:29 -0700427uword
428unformat_dscp (unformat_input_t * input, va_list * va)
429{
Dave Barach72d72232016-08-04 10:15:08 -0400430 u8 *r = va_arg (*va, u8 *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700431
Dave Barach72d72232016-08-04 10:15:08 -0400432 if (0);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700433#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
Dave Barach72d72232016-08-04 10:15:08 -0400434 foreach_vnet_dscp
Matus Fabian4ac74c92016-05-31 07:33:29 -0700435#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400436 else
Matus Fabian4ac74c92016-05-31 07:33:29 -0700437 return 0;
438 return 1;
439}
440
441uword
442unformat_policer_action_type (unformat_input_t * input, va_list * va)
443{
Dave Barach72d72232016-08-04 10:15:08 -0400444 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700445 = va_arg (*va, sse2_qos_pol_action_params_st *);
446
447 if (unformat (input, "drop"))
448 a->action_type = SSE2_QOS_ACTION_DROP;
449 else if (unformat (input, "transmit"))
450 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
451 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
452 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
453 else
454 return 0;
455 return 1;
456}
457
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700458uword
459unformat_classify_table_type (unformat_input_t * input, va_list * va)
460{
Dave Barach72d72232016-08-04 10:15:08 -0400461 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700462 u32 tid;
463
464 if (unformat (input, "ip4"))
465 tid = POLICER_CLASSIFY_TABLE_IP4;
466 else if (unformat (input, "ip6"))
467 tid = POLICER_CLASSIFY_TABLE_IP6;
468 else if (unformat (input, "l2"))
469 tid = POLICER_CLASSIFY_TABLE_L2;
470 else
471 return 0;
472
473 *r = tid;
474 return 1;
475}
476
Dave Barach72d72232016-08-04 10:15:08 -0400477u8 *
478format_ip4_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700479{
Dave Barach72d72232016-08-04 10:15:08 -0400480 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700481 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
482}
483
Dave Barach72d72232016-08-04 10:15:08 -0400484u8 *
485format_ip6_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486{
Dave Barach72d72232016-08-04 10:15:08 -0400487 ip6_address_t *a = va_arg (*args, ip6_address_t *);
488 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700489
Dave Barach72d72232016-08-04 10:15:08 -0400490 i_max_n_zero = ARRAY_LEN (a->as_u16);
491 max_n_zeros = 0;
492 i_first_zero = i_max_n_zero;
493 n_zeros = 0;
494 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
495 {
496 u32 is_zero = a->as_u16[i] == 0;
497 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
498 {
499 i_first_zero = i;
500 n_zeros = 0;
501 }
502 n_zeros += is_zero;
503 if ((!is_zero && n_zeros > max_n_zeros)
504 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
505 {
506 i_max_n_zero = i_first_zero;
507 max_n_zeros = n_zeros;
508 i_first_zero = ARRAY_LEN (a->as_u16);
509 n_zeros = 0;
510 }
511 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700512
Dave Barach72d72232016-08-04 10:15:08 -0400513 last_double_colon = 0;
514 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
515 {
516 if (i == i_max_n_zero && max_n_zeros > 1)
517 {
518 s = format (s, "::");
519 i += max_n_zeros - 1;
520 last_double_colon = 1;
521 }
522 else
523 {
524 s = format (s, "%s%x",
525 (last_double_colon || i == 0) ? "" : ":",
526 clib_net_to_host_u16 (a->as_u16[i]));
527 last_double_colon = 0;
528 }
529 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700530
Dave Barach72d72232016-08-04 10:15:08 -0400531 return s;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700532}
533
Chris Luke99cb3352016-04-26 10:49:53 -0400534/* Format an IP46 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400535u8 *
536format_ip46_address (u8 * s, va_list * args)
Chris Luke99cb3352016-04-26 10:49:53 -0400537{
538 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
Damjan Marion86be4872016-05-24 23:19:11 +0200539 ip46_type_t type = va_arg (*args, ip46_type_t);
540 int is_ip4 = 1;
541
542 switch (type)
543 {
Dave Barach72d72232016-08-04 10:15:08 -0400544 case IP46_TYPE_ANY:
545 is_ip4 = ip46_address_is_ip4 (ip46);
546 break;
547 case IP46_TYPE_IP4:
548 is_ip4 = 1;
549 break;
550 case IP46_TYPE_IP6:
551 is_ip4 = 0;
552 break;
Damjan Marion86be4872016-05-24 23:19:11 +0200553 }
554
555 return is_ip4 ?
Dave Barach72d72232016-08-04 10:15:08 -0400556 format (s, "%U", format_ip4_address, &ip46->ip4) :
557 format (s, "%U", format_ip6_address, &ip46->ip6);
Chris Luke99cb3352016-04-26 10:49:53 -0400558}
559
Dave Barach72d72232016-08-04 10:15:08 -0400560u8 *
561format_ethernet_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562{
Dave Barach72d72232016-08-04 10:15:08 -0400563 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700564
565 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -0400566 a[0], a[1], a[2], a[3], a[4], a[5]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700567}
568
Dave Barach72d72232016-08-04 10:15:08 -0400569void
570increment_v4_address (ip4_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571{
Dave Barach72d72232016-08-04 10:15:08 -0400572 u32 v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700573
Dave Barach72d72232016-08-04 10:15:08 -0400574 v = ntohl (a->as_u32) + 1;
575 a->as_u32 = ntohl (v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700576}
577
Dave Barach72d72232016-08-04 10:15:08 -0400578void
579increment_v6_address (ip6_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580{
Dave Barach72d72232016-08-04 10:15:08 -0400581 u64 v0, v1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700582
Dave Barach72d72232016-08-04 10:15:08 -0400583 v0 = clib_net_to_host_u64 (a->as_u64[0]);
584 v1 = clib_net_to_host_u64 (a->as_u64[1]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700585
Dave Barach72d72232016-08-04 10:15:08 -0400586 v1 += 1;
587 if (v1 == 0)
588 v0 += 1;
589 a->as_u64[0] = clib_net_to_host_u64 (v0);
590 a->as_u64[1] = clib_net_to_host_u64 (v1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700591}
592
Dave Barach72d72232016-08-04 10:15:08 -0400593void
594increment_mac_address (u64 * mac)
Dave Barach41da02d2016-07-11 16:48:42 -0700595{
Dave Barach72d72232016-08-04 10:15:08 -0400596 u64 tmp = *mac;
Dave Barach41da02d2016-07-11 16:48:42 -0700597
Dave Barach72d72232016-08-04 10:15:08 -0400598 tmp = clib_net_to_host_u64 (tmp);
599 tmp += 1 << 16; /* skip unused (least significant) octets */
600 tmp = clib_host_to_net_u64 (tmp);
601 *mac = tmp;
Dave Barach41da02d2016-07-11 16:48:42 -0700602}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700603
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800604static void vl_api_create_loopback_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400605 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700606{
Dave Barach72d72232016-08-04 10:15:08 -0400607 vat_main_t *vam = &vat_main;
608 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700609
Dave Barach72d72232016-08-04 10:15:08 -0400610 vam->retval = retval;
611 vam->regenerate_interface_table = 1;
612 vam->sw_if_index = ntohl (mp->sw_if_index);
613 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614}
615
616static void vl_api_create_loopback_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400617 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700618{
Dave Barach72d72232016-08-04 10:15:08 -0400619 vat_main_t *vam = &vat_main;
620 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700621
Dave Barach72d72232016-08-04 10:15:08 -0400622 vat_json_init_object (&node);
623 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
624 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700625
Dave Barach72d72232016-08-04 10:15:08 -0400626 vat_json_print (vam->ofp, &node);
627 vat_json_free (&node);
628 vam->retval = ntohl (mp->retval);
629 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700630}
631
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800632static void vl_api_af_packet_create_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400633 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700634{
Dave Barach72d72232016-08-04 10:15:08 -0400635 vat_main_t *vam = &vat_main;
636 i32 retval = ntohl (mp->retval);
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700637
Dave Barach72d72232016-08-04 10:15:08 -0400638 vam->retval = retval;
639 vam->regenerate_interface_table = 1;
640 vam->sw_if_index = ntohl (mp->sw_if_index);
641 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700642}
643
644static void vl_api_af_packet_create_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400645 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700646{
Dave Barach72d72232016-08-04 10:15:08 -0400647 vat_main_t *vam = &vat_main;
648 vat_json_node_t node;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700649
Dave Barach72d72232016-08-04 10:15:08 -0400650 vat_json_init_object (&node);
651 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
652 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700653
Dave Barach72d72232016-08-04 10:15:08 -0400654 vat_json_print (vam->ofp, &node);
655 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700656
Dave Barach72d72232016-08-04 10:15:08 -0400657 vam->retval = ntohl (mp->retval);
658 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700659}
660
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800661static void vl_api_create_vlan_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400662 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700663{
Dave Barach72d72232016-08-04 10:15:08 -0400664 vat_main_t *vam = &vat_main;
665 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700666
Dave Barach72d72232016-08-04 10:15:08 -0400667 vam->retval = retval;
668 vam->regenerate_interface_table = 1;
669 vam->sw_if_index = ntohl (mp->sw_if_index);
670 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671}
672
673static void vl_api_create_vlan_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400674 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700675{
Dave Barach72d72232016-08-04 10:15:08 -0400676 vat_main_t *vam = &vat_main;
677 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700678
Dave Barach72d72232016-08-04 10:15:08 -0400679 vat_json_init_object (&node);
680 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
681 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700682
Dave Barach72d72232016-08-04 10:15:08 -0400683 vat_json_print (vam->ofp, &node);
684 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700685
Dave Barach72d72232016-08-04 10:15:08 -0400686 vam->retval = ntohl (mp->retval);
687 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700688}
689
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800690static void vl_api_create_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400691 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700692{
Dave Barach72d72232016-08-04 10:15:08 -0400693 vat_main_t *vam = &vat_main;
694 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700695
Dave Barach72d72232016-08-04 10:15:08 -0400696 vam->retval = retval;
697 vam->regenerate_interface_table = 1;
698 vam->sw_if_index = ntohl (mp->sw_if_index);
699 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700}
701
702static void vl_api_create_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400703 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700704{
Dave Barach72d72232016-08-04 10:15:08 -0400705 vat_main_t *vam = &vat_main;
706 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700707
Dave Barach72d72232016-08-04 10:15:08 -0400708 vat_json_init_object (&node);
709 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
710 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700711
Dave Barach72d72232016-08-04 10:15:08 -0400712 vat_json_print (vam->ofp, &node);
713 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700714
Dave Barach72d72232016-08-04 10:15:08 -0400715 vam->retval = ntohl (mp->retval);
716 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700717}
718
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800719static void vl_api_interface_name_renumber_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400720 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700721{
Dave Barach72d72232016-08-04 10:15:08 -0400722 vat_main_t *vam = &vat_main;
723 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724
Dave Barach72d72232016-08-04 10:15:08 -0400725 vam->retval = retval;
726 vam->regenerate_interface_table = 1;
727 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700728}
729
730static void vl_api_interface_name_renumber_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400731 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700732{
Dave Barach72d72232016-08-04 10:15:08 -0400733 vat_main_t *vam = &vat_main;
734 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700735
Dave Barach72d72232016-08-04 10:15:08 -0400736 vat_json_init_object (&node);
737 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700738
Dave Barach72d72232016-08-04 10:15:08 -0400739 vat_json_print (vam->ofp, &node);
740 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741
Dave Barach72d72232016-08-04 10:15:08 -0400742 vam->retval = ntohl (mp->retval);
743 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744}
745
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800746/*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700747 * Special-case: build the interface table, maintain
748 * the next loopback sw_if_index vbl.
749 */
750static void vl_api_sw_interface_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400751 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700752{
Dave Barach72d72232016-08-04 10:15:08 -0400753 vat_main_t *vam = &vat_main;
754 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700755
Dave Barach72d72232016-08-04 10:15:08 -0400756 hash_set_mem (vam->sw_if_index_by_interface_name, s,
757 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700758
Dave Barach72d72232016-08-04 10:15:08 -0400759 /* In sub interface case, fill the sub interface table entry */
760 if (mp->sw_if_index != mp->sup_sw_if_index)
761 {
762 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700763
Dave Barach72d72232016-08-04 10:15:08 -0400764 vec_add2 (vam->sw_if_subif_table, sub, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700765
Dave Barach72d72232016-08-04 10:15:08 -0400766 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
767 strncpy ((char *) sub->interface_name, (char *) s,
768 vec_len (sub->interface_name));
769 sub->sw_if_index = ntohl (mp->sw_if_index);
770 sub->sub_id = ntohl (mp->sub_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700771
Dave Barach72d72232016-08-04 10:15:08 -0400772 sub->sub_dot1ad = mp->sub_dot1ad;
773 sub->sub_number_of_tags = mp->sub_number_of_tags;
774 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
775 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
776 sub->sub_exact_match = mp->sub_exact_match;
777 sub->sub_default = mp->sub_default;
778 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
779 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700780
Dave Barach72d72232016-08-04 10:15:08 -0400781 /* vlan tag rewrite */
782 sub->vtr_op = ntohl (mp->vtr_op);
783 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
784 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
785 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700786 }
787}
788
789static void vl_api_sw_interface_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400790 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700791{
Dave Barach72d72232016-08-04 10:15:08 -0400792 vat_main_t *vam = &vat_main;
793 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794
Dave Barach72d72232016-08-04 10:15:08 -0400795 if (VAT_JSON_ARRAY != vam->json_tree.type)
796 {
797 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
798 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700799 }
Dave Barach72d72232016-08-04 10:15:08 -0400800 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801
Dave Barach72d72232016-08-04 10:15:08 -0400802 vat_json_init_object (node);
803 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
804 vat_json_object_add_uint (node, "sup_sw_if_index",
805 ntohl (mp->sup_sw_if_index));
806 vat_json_object_add_uint (node, "l2_address_length",
807 ntohl (mp->l2_address_length));
808 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
809 sizeof (mp->l2_address));
810 vat_json_object_add_string_copy (node, "interface_name",
811 mp->interface_name);
812 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
813 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
814 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
815 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
816 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
817 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
818 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
819 vat_json_object_add_uint (node, "sub_number_of_tags",
820 mp->sub_number_of_tags);
821 vat_json_object_add_uint (node, "sub_outer_vlan_id",
822 ntohs (mp->sub_outer_vlan_id));
823 vat_json_object_add_uint (node, "sub_inner_vlan_id",
824 ntohs (mp->sub_inner_vlan_id));
825 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
826 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
827 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
828 mp->sub_outer_vlan_id_any);
829 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
830 mp->sub_inner_vlan_id_any);
831 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
832 vat_json_object_add_uint (node, "vtr_push_dot1q",
833 ntohl (mp->vtr_push_dot1q));
834 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
835 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836}
837
838static void vl_api_sw_interface_set_flags_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400839 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700840{
Dave Barach72d72232016-08-04 10:15:08 -0400841 vat_main_t *vam = &vat_main;
842 if (vam->interface_event_display)
843 errmsg ("interface flags: sw_if_index %d %s %s\n",
844 ntohl (mp->sw_if_index),
845 mp->admin_up_down ? "admin-up" : "admin-down",
846 mp->link_up_down ? "link-up" : "link-down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700847}
848
849static void vl_api_sw_interface_set_flags_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400850 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700851{
Dave Barach72d72232016-08-04 10:15:08 -0400852 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700853}
854
Dave Barach72d72232016-08-04 10:15:08 -0400855static void
856vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700857{
Dave Barach72d72232016-08-04 10:15:08 -0400858 vat_main_t *vam = &vat_main;
859 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700860
Dave Barach72d72232016-08-04 10:15:08 -0400861 vam->retval = retval;
862 vam->shmem_result = (u8 *) mp->reply_in_shmem;
863 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700864}
865
Dave Barach72d72232016-08-04 10:15:08 -0400866static void
867vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700868{
Dave Barach72d72232016-08-04 10:15:08 -0400869 vat_main_t *vam = &vat_main;
870 vat_json_node_t node;
871 api_main_t *am = &api_main;
872 void *oldheap;
873 u8 *reply;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700874
Dave Barach72d72232016-08-04 10:15:08 -0400875 vat_json_init_object (&node);
876 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
877 vat_json_object_add_uint (&node, "reply_in_shmem",
878 ntohl (mp->reply_in_shmem));
879 /* Toss the shared-memory original... */
880 pthread_mutex_lock (&am->vlib_rp->mutex);
881 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -0500882
Dave Barach72d72232016-08-04 10:15:08 -0400883 reply = (u8 *) (mp->reply_in_shmem);
884 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800885
Dave Barach72d72232016-08-04 10:15:08 -0400886 svm_pop_heap (oldheap);
887 pthread_mutex_unlock (&am->vlib_rp->mutex);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700888
Dave Barach72d72232016-08-04 10:15:08 -0400889 vat_json_print (vam->ofp, &node);
890 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700891
Dave Barach72d72232016-08-04 10:15:08 -0400892 vam->retval = ntohl (mp->retval);
893 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700894}
895
Ole Troanc27213a2016-08-31 14:50:49 +0200896static void
897vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
898{
899 vat_main_t *vam = &vat_main;
900 i32 retval = ntohl (mp->retval);
901
902 vam->retval = retval;
903 vam->cmd_reply = mp->reply;
904 vam->result_ready = 1;
905}
906
907static void
908vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
909{
910 vat_main_t *vam = &vat_main;
911 vat_json_node_t node;
912
913 vat_json_init_object (&node);
914 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
915 vat_json_object_add_string_copy (&node, "reply", mp->reply);
916
917 vat_json_print (vam->ofp, &node);
918 vat_json_free (&node);
919
920 vam->retval = ntohl (mp->retval);
921 vam->result_ready = 1;
922}
923
Ed Warnickecb9cada2015-12-08 15:45:58 -0700924static void vl_api_classify_add_del_table_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400925 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700926{
Dave Barach72d72232016-08-04 10:15:08 -0400927 vat_main_t *vam = &vat_main;
928 i32 retval = ntohl (mp->retval);
929 if (vam->async_mode)
930 {
931 vam->async_errors += (retval < 0);
932 }
933 else
934 {
935 vam->retval = retval;
936 if (retval == 0 &&
937 ((mp->new_table_index != 0xFFFFFFFF) ||
938 (mp->skip_n_vectors != 0xFFFFFFFF) ||
939 (mp->match_n_vectors != 0xFFFFFFFF)))
940 /*
941 * Note: this is just barely thread-safe, depends on
942 * the main thread spinning waiting for an answer...
943 */
944 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
945 ntohl (mp->new_table_index),
946 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
947 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700948 }
949}
950
951static void vl_api_classify_add_del_table_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400952 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700953{
Dave Barach72d72232016-08-04 10:15:08 -0400954 vat_main_t *vam = &vat_main;
955 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700956
Dave Barach72d72232016-08-04 10:15:08 -0400957 vat_json_init_object (&node);
958 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
959 vat_json_object_add_uint (&node, "new_table_index",
960 ntohl (mp->new_table_index));
961 vat_json_object_add_uint (&node, "skip_n_vectors",
962 ntohl (mp->skip_n_vectors));
963 vat_json_object_add_uint (&node, "match_n_vectors",
964 ntohl (mp->match_n_vectors));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965
Dave Barach72d72232016-08-04 10:15:08 -0400966 vat_json_print (vam->ofp, &node);
967 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968
Dave Barach72d72232016-08-04 10:15:08 -0400969 vam->retval = ntohl (mp->retval);
970 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700971}
972
973static void vl_api_get_node_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400974 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700975{
Dave Barach72d72232016-08-04 10:15:08 -0400976 vat_main_t *vam = &vat_main;
977 i32 retval = ntohl (mp->retval);
978 if (vam->async_mode)
979 {
980 vam->async_errors += (retval < 0);
981 }
982 else
983 {
984 vam->retval = retval;
985 if (retval == 0)
986 errmsg ("node index %d\n", ntohl (mp->node_index));
987 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700988 }
989}
990
991static void vl_api_get_node_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400992 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700993{
Dave Barach72d72232016-08-04 10:15:08 -0400994 vat_main_t *vam = &vat_main;
995 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700996
Dave Barach72d72232016-08-04 10:15:08 -0400997 vat_json_init_object (&node);
998 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
999 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001000
Dave Barach72d72232016-08-04 10:15:08 -04001001 vat_json_print (vam->ofp, &node);
1002 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001003
Dave Barach72d72232016-08-04 10:15:08 -04001004 vam->retval = ntohl (mp->retval);
1005 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001006}
1007
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001008static void vl_api_get_next_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001009 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001010{
Dave Barach72d72232016-08-04 10:15:08 -04001011 vat_main_t *vam = &vat_main;
1012 i32 retval = ntohl (mp->retval);
1013 if (vam->async_mode)
1014 {
1015 vam->async_errors += (retval < 0);
1016 }
1017 else
1018 {
1019 vam->retval = retval;
1020 if (retval == 0)
1021 errmsg ("next node index %d\n", ntohl (mp->next_index));
1022 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001023 }
1024}
1025
1026static void vl_api_get_next_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001027 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001028{
Dave Barach72d72232016-08-04 10:15:08 -04001029 vat_main_t *vam = &vat_main;
1030 vat_json_node_t node;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001031
Dave Barach72d72232016-08-04 10:15:08 -04001032 vat_json_init_object (&node);
1033 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1034 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001035
Dave Barach72d72232016-08-04 10:15:08 -04001036 vat_json_print (vam->ofp, &node);
1037 vat_json_free (&node);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001038
Dave Barach72d72232016-08-04 10:15:08 -04001039 vam->retval = ntohl (mp->retval);
1040 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001041}
1042
Ed Warnickecb9cada2015-12-08 15:45:58 -07001043static void vl_api_add_node_next_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001044 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001045{
Dave Barach72d72232016-08-04 10:15:08 -04001046 vat_main_t *vam = &vat_main;
1047 i32 retval = ntohl (mp->retval);
1048 if (vam->async_mode)
1049 {
1050 vam->async_errors += (retval < 0);
1051 }
1052 else
1053 {
1054 vam->retval = retval;
1055 if (retval == 0)
1056 errmsg ("next index %d\n", ntohl (mp->next_index));
1057 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001058 }
1059}
1060
1061static void vl_api_add_node_next_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001062 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001063{
Dave Barach72d72232016-08-04 10:15:08 -04001064 vat_main_t *vam = &vat_main;
1065 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001066
Dave Barach72d72232016-08-04 10:15:08 -04001067 vat_json_init_object (&node);
1068 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1069 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001070
Dave Barach72d72232016-08-04 10:15:08 -04001071 vat_json_print (vam->ofp, &node);
1072 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001073
Dave Barach72d72232016-08-04 10:15:08 -04001074 vam->retval = ntohl (mp->retval);
1075 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001076}
1077
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001078static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001079 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001080{
Dave Barach72d72232016-08-04 10:15:08 -04001081 vat_main_t *vam = &vat_main;
1082 i32 retval = ntohl (mp->retval);
1083 u32 sw_if_index = ntohl (mp->tunnel_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001084
Dave Barach72d72232016-08-04 10:15:08 -04001085 if (retval >= 0 && sw_if_index != (u32) ~ 0)
1086 {
1087 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001088 }
Dave Barach72d72232016-08-04 10:15:08 -04001089 vam->retval = retval;
1090 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001091}
1092
1093static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001094 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001095{
Dave Barach72d72232016-08-04 10:15:08 -04001096 vat_main_t *vam = &vat_main;
1097 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001098
Dave Barach72d72232016-08-04 10:15:08 -04001099 vat_json_init_object (&node);
1100 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1101 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
1102 ntohl (mp->tunnel_sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001103
Dave Barach72d72232016-08-04 10:15:08 -04001104 vat_json_print (vam->ofp, &node);
1105 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001106
Dave Barach72d72232016-08-04 10:15:08 -04001107 vam->retval = ntohl (mp->retval);
1108 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001109}
1110
Ed Warnickecb9cada2015-12-08 15:45:58 -07001111
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001112static void vl_api_show_version_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001113 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001114{
Dave Barach72d72232016-08-04 10:15:08 -04001115 vat_main_t *vam = &vat_main;
1116 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117
Dave Barach72d72232016-08-04 10:15:08 -04001118 if (retval >= 0)
1119 {
1120 errmsg (" program: %s\n", mp->program);
1121 errmsg (" version: %s\n", mp->version);
1122 errmsg (" build date: %s\n", mp->build_date);
1123 errmsg ("build directory: %s\n", mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001124 }
Dave Barach72d72232016-08-04 10:15:08 -04001125 vam->retval = retval;
1126 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001127}
1128
1129static void vl_api_show_version_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001130 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001131{
Dave Barach72d72232016-08-04 10:15:08 -04001132 vat_main_t *vam = &vat_main;
1133 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001134
Dave Barach72d72232016-08-04 10:15:08 -04001135 vat_json_init_object (&node);
1136 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1137 vat_json_object_add_string_copy (&node, "program", mp->program);
1138 vat_json_object_add_string_copy (&node, "version", mp->version);
1139 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1140 vat_json_object_add_string_copy (&node, "build_directory",
1141 mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001142
Dave Barach72d72232016-08-04 10:15:08 -04001143 vat_json_print (vam->ofp, &node);
1144 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001145
Dave Barach72d72232016-08-04 10:15:08 -04001146 vam->retval = ntohl (mp->retval);
1147 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001148}
1149
Dave Barach72d72232016-08-04 10:15:08 -04001150static void
1151vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001152{
Dave Barach72d72232016-08-04 10:15:08 -04001153 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001154 errmsg ("arp %s event: address %U new mac %U sw_if_index %d\n",
1155 mp->mac_ip ? "mac/ip binding" : "address resolution",
Dave Barach72d72232016-08-04 10:15:08 -04001156 format_ip4_address, &mp->address,
1157 format_ethernet_address, mp->new_mac, mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001158}
1159
Dave Barach72d72232016-08-04 10:15:08 -04001160static void
1161vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001162{
Dave Barach72d72232016-08-04 10:15:08 -04001163 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001164}
1165
John Lo1edfba92016-08-27 01:11:57 -04001166static void
1167vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1168{
1169 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001170 errmsg ("ip6 nd %s event: address %U new mac %U sw_if_index %d\n",
1171 mp->mac_ip ? "mac/ip binding" : "address resolution",
John Lo1edfba92016-08-27 01:11:57 -04001172 format_ip6_address, mp->address,
1173 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1174}
1175
1176static void
1177vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1178{
1179 /* JSON output not supported */
1180}
1181
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001182/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001183 * Special-case: build the bridge domain table, maintain
1184 * the next bd id vbl.
1185 */
1186static void vl_api_bridge_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001187 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001188{
Dave Barach72d72232016-08-04 10:15:08 -04001189 vat_main_t *vam = &vat_main;
1190 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001191
Dave Barach72d72232016-08-04 10:15:08 -04001192 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1193 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001194
Dave Barach72d72232016-08-04 10:15:08 -04001195 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1196 ntohl (mp->bd_id), mp->learn, mp->forward,
1197 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001198
Dave Barach72d72232016-08-04 10:15:08 -04001199 if (n_sw_ifs)
1200 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1201 "Interface Name");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001202}
1203
1204static void vl_api_bridge_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001205 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001206{
Dave Barach72d72232016-08-04 10:15:08 -04001207 vat_main_t *vam = &vat_main;
1208 vat_json_node_t *node, *array = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001209
Dave Barach72d72232016-08-04 10:15:08 -04001210 if (VAT_JSON_ARRAY != vam->json_tree.type)
1211 {
1212 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1213 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214 }
Dave Barach72d72232016-08-04 10:15:08 -04001215 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001216
Dave Barach72d72232016-08-04 10:15:08 -04001217 vat_json_init_object (node);
1218 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1219 vat_json_object_add_uint (node, "flood", mp->flood);
1220 vat_json_object_add_uint (node, "forward", mp->forward);
1221 vat_json_object_add_uint (node, "learn", mp->learn);
1222 vat_json_object_add_uint (node, "bvi_sw_if_index",
1223 ntohl (mp->bvi_sw_if_index));
1224 vat_json_object_add_uint (node, "n_sw_ifs", ntohl (mp->n_sw_ifs));
1225 array = vat_json_object_add (node, "sw_if");
1226 vat_json_init_array (array);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001227}
1228
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001229/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001230 * Special-case: build the bridge domain sw if table.
1231 */
1232static void vl_api_bridge_domain_sw_if_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001233 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001234{
Dave Barach72d72232016-08-04 10:15:08 -04001235 vat_main_t *vam = &vat_main;
1236 hash_pair_t *p;
1237 u8 *sw_if_name = 0;
1238 u32 sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001239
Dave Barach72d72232016-08-04 10:15:08 -04001240 sw_if_index = ntohl (mp->sw_if_index);
1241 /* *INDENT-OFF* */
1242 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1243 ({
1244 if ((u32) p->value[0] == sw_if_index)
1245 {
1246 sw_if_name = (u8 *)(p->key);
1247 break;
1248 }
1249 }));
1250 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001251
Dave Barach72d72232016-08-04 10:15:08 -04001252 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1253 mp->shg, sw_if_name ? (char *) sw_if_name :
1254 "sw_if_index not found!");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001255}
1256
1257static void vl_api_bridge_domain_sw_if_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001258 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001259{
Dave Barach72d72232016-08-04 10:15:08 -04001260 vat_main_t *vam = &vat_main;
1261 vat_json_node_t *node = NULL;
1262 uword last_index = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001263
Dave Barach72d72232016-08-04 10:15:08 -04001264 ASSERT (VAT_JSON_ARRAY == vam->json_tree.type);
1265 ASSERT (vec_len (vam->json_tree.array) >= 1);
1266 last_index = vec_len (vam->json_tree.array) - 1;
1267 node = &vam->json_tree.array[last_index];
1268 node = vat_json_object_get_element (node, "sw_if");
1269 ASSERT (NULL != node);
1270 node = vat_json_array_add (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001271
Dave Barach72d72232016-08-04 10:15:08 -04001272 vat_json_init_object (node);
1273 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1274 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1275 vat_json_object_add_uint (node, "shg", mp->shg);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001276}
1277
1278static void vl_api_control_ping_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001279 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001280{
Dave Barach72d72232016-08-04 10:15:08 -04001281 vat_main_t *vam = &vat_main;
1282 i32 retval = ntohl (mp->retval);
1283 if (vam->async_mode)
1284 {
1285 vam->async_errors += (retval < 0);
1286 }
1287 else
1288 {
1289 vam->retval = retval;
1290 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001291 }
1292}
1293
1294static void vl_api_control_ping_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001295 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001296{
Dave Barach72d72232016-08-04 10:15:08 -04001297 vat_main_t *vam = &vat_main;
1298 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001299
Dave Barach72d72232016-08-04 10:15:08 -04001300 if (VAT_JSON_NONE != vam->json_tree.type)
1301 {
1302 vat_json_print (vam->ofp, &vam->json_tree);
1303 vat_json_free (&vam->json_tree);
1304 vam->json_tree.type = VAT_JSON_NONE;
1305 }
1306 else
1307 {
1308 /* just print [] */
1309 vat_json_init_array (&vam->json_tree);
1310 vat_json_print (vam->ofp, &vam->json_tree);
1311 vam->json_tree.type = VAT_JSON_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001312 }
1313
Dave Barach72d72232016-08-04 10:15:08 -04001314 vam->retval = retval;
1315 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001316}
1317
Dave Barach72d72232016-08-04 10:15:08 -04001318static void
1319vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001320{
Dave Barach72d72232016-08-04 10:15:08 -04001321 vat_main_t *vam = &vat_main;
1322 i32 retval = ntohl (mp->retval);
1323 if (vam->async_mode)
1324 {
1325 vam->async_errors += (retval < 0);
1326 }
1327 else
1328 {
1329 vam->retval = retval;
1330 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001331 }
1332}
1333
1334static void vl_api_l2_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001335 (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001336{
Dave Barach72d72232016-08-04 10:15:08 -04001337 vat_main_t *vam = &vat_main;
1338 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001339
Dave Barach72d72232016-08-04 10:15:08 -04001340 vat_json_init_object (&node);
1341 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1342 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1343 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001344
Dave Barach72d72232016-08-04 10:15:08 -04001345 vat_json_print (vam->ofp, &node);
1346 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001347
Dave Barach72d72232016-08-04 10:15:08 -04001348 vam->retval = ntohl (mp->retval);
1349 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001350}
1351
1352static void vl_api_bridge_flags_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001353 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001354{
Dave Barach72d72232016-08-04 10:15:08 -04001355 vat_main_t *vam = &vat_main;
1356 i32 retval = ntohl (mp->retval);
1357 if (vam->async_mode)
1358 {
1359 vam->async_errors += (retval < 0);
1360 }
1361 else
1362 {
1363 vam->retval = retval;
1364 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001365 }
1366}
1367
1368static void vl_api_bridge_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001369 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001370{
Dave Barach72d72232016-08-04 10:15:08 -04001371 vat_main_t *vam = &vat_main;
1372 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001373
Dave Barach72d72232016-08-04 10:15:08 -04001374 vat_json_init_object (&node);
1375 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1376 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1377 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001378
Dave Barach72d72232016-08-04 10:15:08 -04001379 vat_json_print (vam->ofp, &node);
1380 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001381
Dave Barach72d72232016-08-04 10:15:08 -04001382 vam->retval = ntohl (mp->retval);
1383 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001384}
1385
1386static void vl_api_tap_connect_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001387 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001388{
Dave Barach72d72232016-08-04 10:15:08 -04001389 vat_main_t *vam = &vat_main;
1390 i32 retval = ntohl (mp->retval);
1391 if (vam->async_mode)
1392 {
1393 vam->async_errors += (retval < 0);
1394 }
1395 else
1396 {
1397 vam->retval = retval;
1398 vam->sw_if_index = ntohl (mp->sw_if_index);
1399 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001400 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001401
Ed Warnickecb9cada2015-12-08 15:45:58 -07001402}
1403
1404static void vl_api_tap_connect_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001405 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001406{
Dave Barach72d72232016-08-04 10:15:08 -04001407 vat_main_t *vam = &vat_main;
1408 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001409
Dave Barach72d72232016-08-04 10:15:08 -04001410 vat_json_init_object (&node);
1411 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1412 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001413
Dave Barach72d72232016-08-04 10:15:08 -04001414 vat_json_print (vam->ofp, &node);
1415 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001416
Dave Barach72d72232016-08-04 10:15:08 -04001417 vam->retval = ntohl (mp->retval);
1418 vam->result_ready = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001419
Ed Warnickecb9cada2015-12-08 15:45:58 -07001420}
1421
Dave Barach72d72232016-08-04 10:15:08 -04001422static void
1423vl_api_tap_modify_reply_t_handler (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424{
Dave Barach72d72232016-08-04 10:15:08 -04001425 vat_main_t *vam = &vat_main;
1426 i32 retval = ntohl (mp->retval);
1427 if (vam->async_mode)
1428 {
1429 vam->async_errors += (retval < 0);
1430 }
1431 else
1432 {
1433 vam->retval = retval;
1434 vam->sw_if_index = ntohl (mp->sw_if_index);
1435 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001436 }
1437}
1438
1439static void vl_api_tap_modify_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001440 (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001441{
Dave Barach72d72232016-08-04 10:15:08 -04001442 vat_main_t *vam = &vat_main;
1443 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001444
Dave Barach72d72232016-08-04 10:15:08 -04001445 vat_json_init_object (&node);
1446 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1447 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001448
Dave Barach72d72232016-08-04 10:15:08 -04001449 vat_json_print (vam->ofp, &node);
1450 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001451
Dave Barach72d72232016-08-04 10:15:08 -04001452 vam->retval = ntohl (mp->retval);
1453 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001454}
1455
Dave Barach72d72232016-08-04 10:15:08 -04001456static void
1457vl_api_tap_delete_reply_t_handler (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001458{
Dave Barach72d72232016-08-04 10:15:08 -04001459 vat_main_t *vam = &vat_main;
1460 i32 retval = ntohl (mp->retval);
1461 if (vam->async_mode)
1462 {
1463 vam->async_errors += (retval < 0);
1464 }
1465 else
1466 {
1467 vam->retval = retval;
1468 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001469 }
1470}
1471
1472static void vl_api_tap_delete_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001473 (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001474{
Dave Barach72d72232016-08-04 10:15:08 -04001475 vat_main_t *vam = &vat_main;
1476 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001477
Dave Barach72d72232016-08-04 10:15:08 -04001478 vat_json_init_object (&node);
1479 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001480
Dave Barach72d72232016-08-04 10:15:08 -04001481 vat_json_print (vam->ofp, &node);
1482 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001483
Dave Barach72d72232016-08-04 10:15:08 -04001484 vam->retval = ntohl (mp->retval);
1485 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001486}
1487
1488static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001489 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001490{
Dave Barach72d72232016-08-04 10:15:08 -04001491 vat_main_t *vam = &vat_main;
1492 i32 retval = ntohl (mp->retval);
1493 if (vam->async_mode)
1494 {
1495 vam->async_errors += (retval < 0);
1496 }
1497 else
1498 {
1499 vam->retval = retval;
1500 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001501 }
1502}
1503
1504static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001505 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001506{
Dave Barach72d72232016-08-04 10:15:08 -04001507 vat_main_t *vam = &vat_main;
1508 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001509
Dave Barach72d72232016-08-04 10:15:08 -04001510 vat_json_init_object (&node);
1511 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1512 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
1513 ntohl (mp->tunnel_sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001514
Dave Barach72d72232016-08-04 10:15:08 -04001515 vat_json_print (vam->ofp, &node);
1516 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001517
Dave Barach72d72232016-08-04 10:15:08 -04001518 vam->retval = ntohl (mp->retval);
1519 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001520}
1521
1522static void vl_api_l2tpv3_create_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001523 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001524{
Dave Barach72d72232016-08-04 10:15:08 -04001525 vat_main_t *vam = &vat_main;
1526 i32 retval = ntohl (mp->retval);
1527 if (vam->async_mode)
1528 {
1529 vam->async_errors += (retval < 0);
1530 }
1531 else
1532 {
1533 vam->retval = retval;
1534 vam->sw_if_index = ntohl (mp->sw_if_index);
1535 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001536 }
1537}
1538
1539static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001540 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001541{
Dave Barach72d72232016-08-04 10:15:08 -04001542 vat_main_t *vam = &vat_main;
1543 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001544
Dave Barach72d72232016-08-04 10:15:08 -04001545 vat_json_init_object (&node);
1546 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1547 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001548
Dave Barach72d72232016-08-04 10:15:08 -04001549 vat_json_print (vam->ofp, &node);
1550 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001551
Dave Barach72d72232016-08-04 10:15:08 -04001552 vam->retval = ntohl (mp->retval);
1553 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001554}
1555
Filip Tehlar3a834602016-08-11 12:21:37 +02001556
1557static void vl_api_lisp_add_del_locator_set_reply_t_handler
1558 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1559{
1560 vat_main_t *vam = &vat_main;
1561 i32 retval = ntohl (mp->retval);
1562 if (vam->async_mode)
1563 {
1564 vam->async_errors += (retval < 0);
1565 }
1566 else
1567 {
1568 vam->retval = retval;
1569 vam->result_ready = 1;
1570 }
1571}
1572
1573static void vl_api_lisp_add_del_locator_set_reply_t_handler_json
1574 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1575{
1576 vat_main_t *vam = &vat_main;
1577 vat_json_node_t node;
1578
1579 vat_json_init_object (&node);
1580 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1581 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
1582
1583 vat_json_print (vam->ofp, &node);
1584 vat_json_free (&node);
1585
1586 vam->retval = ntohl (mp->retval);
1587 vam->result_ready = 1;
1588}
1589
Ed Warnickecb9cada2015-12-08 15:45:58 -07001590static void vl_api_vxlan_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001591 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001592{
Dave Barach72d72232016-08-04 10:15:08 -04001593 vat_main_t *vam = &vat_main;
1594 i32 retval = ntohl (mp->retval);
1595 if (vam->async_mode)
1596 {
1597 vam->async_errors += (retval < 0);
1598 }
1599 else
1600 {
1601 vam->retval = retval;
1602 vam->sw_if_index = ntohl (mp->sw_if_index);
1603 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001604 }
1605}
1606
1607static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001608 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001609{
Dave Barach72d72232016-08-04 10:15:08 -04001610 vat_main_t *vam = &vat_main;
1611 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001612
Dave Barach72d72232016-08-04 10:15:08 -04001613 vat_json_init_object (&node);
1614 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1615 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001616
Dave Barach72d72232016-08-04 10:15:08 -04001617 vat_json_print (vam->ofp, &node);
1618 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001619
Dave Barach72d72232016-08-04 10:15:08 -04001620 vam->retval = ntohl (mp->retval);
1621 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001622}
1623
Chris Luke27fe48f2016-04-28 13:44:38 -04001624static void vl_api_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001625 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001626{
Dave Barach72d72232016-08-04 10:15:08 -04001627 vat_main_t *vam = &vat_main;
1628 i32 retval = ntohl (mp->retval);
1629 if (vam->async_mode)
1630 {
1631 vam->async_errors += (retval < 0);
1632 }
1633 else
1634 {
1635 vam->retval = retval;
1636 vam->sw_if_index = ntohl (mp->sw_if_index);
1637 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001638 }
1639}
1640
1641static void vl_api_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001642 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001643{
Dave Barach72d72232016-08-04 10:15:08 -04001644 vat_main_t *vam = &vat_main;
1645 vat_json_node_t node;
Chris Luke27fe48f2016-04-28 13:44:38 -04001646
Dave Barach72d72232016-08-04 10:15:08 -04001647 vat_json_init_object (&node);
1648 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1649 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Chris Luke27fe48f2016-04-28 13:44:38 -04001650
Dave Barach72d72232016-08-04 10:15:08 -04001651 vat_json_print (vam->ofp, &node);
1652 vat_json_free (&node);
Chris Luke27fe48f2016-04-28 13:44:38 -04001653
Dave Barach72d72232016-08-04 10:15:08 -04001654 vam->retval = ntohl (mp->retval);
1655 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001656}
1657
Ed Warnickecb9cada2015-12-08 15:45:58 -07001658static void vl_api_create_vhost_user_if_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001659 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001660{
Dave Barach72d72232016-08-04 10:15:08 -04001661 vat_main_t *vam = &vat_main;
1662 i32 retval = ntohl (mp->retval);
1663 if (vam->async_mode)
1664 {
1665 vam->async_errors += (retval < 0);
1666 }
1667 else
1668 {
1669 vam->retval = retval;
1670 vam->sw_if_index = ntohl (mp->sw_if_index);
1671 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001672 }
1673}
1674
1675static void vl_api_create_vhost_user_if_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001676 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001677{
Dave Barach72d72232016-08-04 10:15:08 -04001678 vat_main_t *vam = &vat_main;
1679 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001680
Dave Barach72d72232016-08-04 10:15:08 -04001681 vat_json_init_object (&node);
1682 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1683 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001684
Dave Barach72d72232016-08-04 10:15:08 -04001685 vat_json_print (vam->ofp, &node);
1686 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001687
Dave Barach72d72232016-08-04 10:15:08 -04001688 vam->retval = ntohl (mp->retval);
1689 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001690}
1691
1692static void vl_api_ip_address_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001693 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001694{
Dave Barach72d72232016-08-04 10:15:08 -04001695 vat_main_t *vam = &vat_main;
1696 static ip_address_details_t empty_ip_address_details = { {0} };
1697 ip_address_details_t *address = NULL;
1698 ip_details_t *current_ip_details = NULL;
1699 ip_details_t *details = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001700
Dave Barach72d72232016-08-04 10:15:08 -04001701 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001702
Dave Barach72d72232016-08-04 10:15:08 -04001703 if (!details || vam->current_sw_if_index >= vec_len (details)
1704 || !details[vam->current_sw_if_index].present)
1705 {
1706 errmsg ("ip address details arrived but not stored\n");
1707 errmsg ("ip_dump should be called first\n");
1708 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001709 }
1710
Dave Barach72d72232016-08-04 10:15:08 -04001711 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001712
1713#define addresses (current_ip_details->addr)
1714
Dave Barach72d72232016-08-04 10:15:08 -04001715 vec_validate_init_empty (addresses, vec_len (addresses),
1716 empty_ip_address_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001717
Dave Barach72d72232016-08-04 10:15:08 -04001718 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001719
Dave Barach72d72232016-08-04 10:15:08 -04001720 clib_memcpy (&address->ip, &mp->ip, sizeof (address->ip));
1721 address->prefix_length = mp->prefix_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001722#undef addresses
1723}
1724
1725static void vl_api_ip_address_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001726 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001727{
Dave Barach72d72232016-08-04 10:15:08 -04001728 vat_main_t *vam = &vat_main;
1729 vat_json_node_t *node = NULL;
1730 struct in6_addr ip6;
1731 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001732
Dave Barach72d72232016-08-04 10:15:08 -04001733 if (VAT_JSON_ARRAY != vam->json_tree.type)
1734 {
1735 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1736 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001737 }
Dave Barach72d72232016-08-04 10:15:08 -04001738 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001739
Dave Barach72d72232016-08-04 10:15:08 -04001740 vat_json_init_object (node);
1741 if (vam->is_ipv6)
1742 {
1743 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
1744 vat_json_object_add_ip6 (node, "ip", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001745 }
Dave Barach72d72232016-08-04 10:15:08 -04001746 else
1747 {
1748 clib_memcpy (&ip4, mp->ip, sizeof (ip4));
1749 vat_json_object_add_ip4 (node, "ip", ip4);
1750 }
1751 vat_json_object_add_uint (node, "prefix_length", mp->prefix_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001752}
1753
Dave Barach72d72232016-08-04 10:15:08 -04001754static void
1755vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001756{
Dave Barach72d72232016-08-04 10:15:08 -04001757 vat_main_t *vam = &vat_main;
1758 static ip_details_t empty_ip_details = { 0 };
1759 ip_details_t *ip = NULL;
1760 u32 sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001761
Dave Barach72d72232016-08-04 10:15:08 -04001762 sw_if_index = ntohl (mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001763
Dave Barach72d72232016-08-04 10:15:08 -04001764 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1765 sw_if_index, empty_ip_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001766
Dave Barach72d72232016-08-04 10:15:08 -04001767 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1768 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001769
Dave Barach72d72232016-08-04 10:15:08 -04001770 ip->present = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001771}
1772
Dave Barach72d72232016-08-04 10:15:08 -04001773static void
1774vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001775{
Dave Barach72d72232016-08-04 10:15:08 -04001776 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001777
Dave Barach72d72232016-08-04 10:15:08 -04001778 if (VAT_JSON_ARRAY != vam->json_tree.type)
1779 {
1780 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1781 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001782 }
Dave Barach72d72232016-08-04 10:15:08 -04001783 vat_json_array_add_uint (&vam->json_tree,
1784 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001785}
1786
1787static void vl_api_map_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001788 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001789{
Dave Barach72d72232016-08-04 10:15:08 -04001790 vat_json_node_t *node = NULL;
1791 vat_main_t *vam = &vat_main;
1792 struct in6_addr ip6;
1793 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001794
Dave Barach72d72232016-08-04 10:15:08 -04001795 if (VAT_JSON_ARRAY != vam->json_tree.type)
1796 {
1797 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1798 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001799 }
1800
Dave Barach72d72232016-08-04 10:15:08 -04001801 node = vat_json_array_add (&vam->json_tree);
1802 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001803
Dave Barach72d72232016-08-04 10:15:08 -04001804 vat_json_object_add_uint (node, "domain_index",
1805 clib_net_to_host_u32 (mp->domain_index));
1806 clib_memcpy (&ip6, mp->ip6_prefix, sizeof (ip6));
1807 vat_json_object_add_ip6 (node, "ip6_prefix", ip6);
1808 clib_memcpy (&ip4, mp->ip4_prefix, sizeof (ip4));
1809 vat_json_object_add_ip4 (node, "ip4_prefix", ip4);
1810 clib_memcpy (&ip6, mp->ip6_src, sizeof (ip6));
1811 vat_json_object_add_ip6 (node, "ip6_src", ip6);
1812 vat_json_object_add_int (node, "ip6_prefix_len", mp->ip6_prefix_len);
1813 vat_json_object_add_int (node, "ip4_prefix_len", mp->ip4_prefix_len);
1814 vat_json_object_add_int (node, "ip6_src_len", mp->ip6_src_len);
1815 vat_json_object_add_int (node, "ea_bits_len", mp->ea_bits_len);
1816 vat_json_object_add_int (node, "psid_offset", mp->psid_offset);
1817 vat_json_object_add_int (node, "psid_length", mp->psid_length);
1818 vat_json_object_add_uint (node, "flags", mp->flags);
1819 vat_json_object_add_uint (node, "mtu", clib_net_to_host_u16 (mp->mtu));
1820 vat_json_object_add_int (node, "is_translation", mp->is_translation);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001821}
1822
1823static void vl_api_map_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001824 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001825{
Dave Barach72d72232016-08-04 10:15:08 -04001826 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001827
Dave Barach72d72232016-08-04 10:15:08 -04001828 if (mp->is_translation)
1829 {
1830 fformat (vam->ofp,
1831 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1832 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1833 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1834 format_ip6_address, mp->ip6_src, mp->ip6_src_len,
1835 clib_net_to_host_u32 (mp->domain_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001836 }
Dave Barach72d72232016-08-04 10:15:08 -04001837 else
1838 {
1839 fformat (vam->ofp,
1840 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1841 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1842 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1843 format_ip6_address, mp->ip6_src,
1844 clib_net_to_host_u32 (mp->domain_index));
1845 }
1846 fformat (vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1847 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu,
1848 mp->is_translation ? "map-t" : "");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849}
1850
1851static void vl_api_map_rule_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001852 (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001853{
Dave Barach72d72232016-08-04 10:15:08 -04001854 struct in6_addr ip6;
1855 vat_json_node_t *node = NULL;
1856 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001857
Dave Barach72d72232016-08-04 10:15:08 -04001858 if (VAT_JSON_ARRAY != vam->json_tree.type)
1859 {
1860 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1861 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001862 }
1863
Dave Barach72d72232016-08-04 10:15:08 -04001864 node = vat_json_array_add (&vam->json_tree);
1865 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001866
Dave Barach72d72232016-08-04 10:15:08 -04001867 vat_json_object_add_uint (node, "psid", clib_net_to_host_u16 (mp->psid));
1868 clib_memcpy (&ip6, mp->ip6_dst, sizeof (ip6));
1869 vat_json_object_add_ip6 (node, "ip6_dst", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001870}
1871
Dave Barach72d72232016-08-04 10:15:08 -04001872static void
1873vl_api_map_rule_details_t_handler (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001874{
Dave Barach72d72232016-08-04 10:15:08 -04001875 vat_main_t *vam = &vat_main;
1876 fformat (vam->ofp, " %d (psid) %U (ip6-dst)\n",
1877 clib_net_to_host_u16 (mp->psid), format_ip6_address, mp->ip6_dst);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001878}
1879
Dave Barach72d72232016-08-04 10:15:08 -04001880static void
1881vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001882{
Dave Barach72d72232016-08-04 10:15:08 -04001883 vat_main_t *vam = &vat_main;
1884 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1885 "router_addr %U host_mac %U\n",
1886 mp->pid, mp->is_ipv6 ? "ipv6" : "ipv4", mp->hostname,
1887 format_ip4_address, &mp->host_address,
1888 format_ip4_address, &mp->router_address,
1889 format_ethernet_address, mp->host_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001890}
1891
1892static void vl_api_dhcp_compl_event_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001893 (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001894{
Dave Barach72d72232016-08-04 10:15:08 -04001895 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001896}
1897
Dave Barach72d72232016-08-04 10:15:08 -04001898static void
1899set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1900 u32 counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001901{
Dave Barach72d72232016-08-04 10:15:08 -04001902 vat_main_t *vam = &vat_main;
1903 static u64 default_counter = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001904
Dave Barach72d72232016-08-04 10:15:08 -04001905 vec_validate_init_empty (vam->simple_interface_counters, vnet_counter_type,
1906 NULL);
1907 vec_validate_init_empty (vam->simple_interface_counters[vnet_counter_type],
1908 sw_if_index, default_counter);
1909 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001910}
1911
Dave Barach72d72232016-08-04 10:15:08 -04001912static void
1913set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1914 interface_counter_t counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001915{
Dave Barach72d72232016-08-04 10:15:08 -04001916 vat_main_t *vam = &vat_main;
1917 static interface_counter_t default_counter = { 0, };
Ed Warnickecb9cada2015-12-08 15:45:58 -07001918
Dave Barach72d72232016-08-04 10:15:08 -04001919 vec_validate_init_empty (vam->combined_interface_counters,
1920 vnet_counter_type, NULL);
1921 vec_validate_init_empty (vam->combined_interface_counters
1922 [vnet_counter_type], sw_if_index, default_counter);
1923 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001924}
1925
1926static void vl_api_vnet_interface_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001927 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001928{
Dave Barach72d72232016-08-04 10:15:08 -04001929 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001930}
1931
1932static void vl_api_vnet_interface_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001933 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001934{
Dave Barach72d72232016-08-04 10:15:08 -04001935 interface_counter_t counter;
1936 vlib_counter_t *v;
1937 u64 *v_packets;
1938 u64 packets;
1939 u32 count;
1940 u32 first_sw_if_index;
1941 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001942
Dave Barach72d72232016-08-04 10:15:08 -04001943 count = ntohl (mp->count);
1944 first_sw_if_index = ntohl (mp->first_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001945
Dave Barach72d72232016-08-04 10:15:08 -04001946 if (!mp->is_combined)
1947 {
1948 v_packets = (u64 *) & mp->data;
1949 for (i = 0; i < count; i++)
1950 {
1951 packets =
1952 clib_net_to_host_u64 (clib_mem_unaligned (v_packets, u64));
1953 set_simple_interface_counter (mp->vnet_counter_type,
1954 first_sw_if_index + i, packets);
1955 v_packets++;
1956 }
1957 }
1958 else
1959 {
1960 v = (vlib_counter_t *) & mp->data;
1961 for (i = 0; i < count; i++)
1962 {
1963 counter.packets =
1964 clib_net_to_host_u64 (clib_mem_unaligned (&v->packets, u64));
1965 counter.bytes =
1966 clib_net_to_host_u64 (clib_mem_unaligned (&v->bytes, u64));
1967 set_combined_interface_counter (mp->vnet_counter_type,
1968 first_sw_if_index + i, counter);
1969 v++;
1970 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001971 }
1972}
1973
Dave Barach72d72232016-08-04 10:15:08 -04001974static u32
1975ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001976{
Dave Barach72d72232016-08-04 10:15:08 -04001977 vat_main_t *vam = &vat_main;
1978 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001979
Dave Barach72d72232016-08-04 10:15:08 -04001980 for (i = 0; i < vec_len (vam->ip4_fib_counters_vrf_id_by_index); i++)
1981 {
1982 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id)
1983 {
1984 return i;
1985 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001986 }
Dave Barach72d72232016-08-04 10:15:08 -04001987 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001988}
1989
Dave Barach72d72232016-08-04 10:15:08 -04001990static u32
1991ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001992{
Dave Barach72d72232016-08-04 10:15:08 -04001993 vat_main_t *vam = &vat_main;
1994 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001995
Dave Barach72d72232016-08-04 10:15:08 -04001996 for (i = 0; i < vec_len (vam->ip6_fib_counters_vrf_id_by_index); i++)
1997 {
1998 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id)
1999 {
2000 return i;
2001 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002002 }
Dave Barach72d72232016-08-04 10:15:08 -04002003 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002004}
2005
2006static void vl_api_vnet_ip4_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002007 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002008{
Dave Barach72d72232016-08-04 10:15:08 -04002009 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002010}
2011
2012static void vl_api_vnet_ip4_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002013 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002014{
Dave Barach72d72232016-08-04 10:15:08 -04002015 vat_main_t *vam = &vat_main;
2016 vl_api_ip4_fib_counter_t *v;
2017 ip4_fib_counter_t *counter;
2018 struct in_addr ip4;
2019 u32 vrf_id;
2020 u32 vrf_index;
2021 u32 count;
2022 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002023
Dave Barach72d72232016-08-04 10:15:08 -04002024 vrf_id = ntohl (mp->vrf_id);
2025 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2026 if (~0 == vrf_index)
2027 {
2028 vrf_index = vec_len (vam->ip4_fib_counters_vrf_id_by_index);
2029 vec_validate (vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
2030 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2031 vec_validate (vam->ip4_fib_counters, vrf_index);
2032 vam->ip4_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002033 }
2034
Dave Barach72d72232016-08-04 10:15:08 -04002035 vec_free (vam->ip4_fib_counters[vrf_index]);
2036 v = (vl_api_ip4_fib_counter_t *) & mp->c;
2037 count = ntohl (mp->count);
2038 for (i = 0; i < count; i++)
2039 {
2040 vec_validate (vam->ip4_fib_counters[vrf_index], i);
2041 counter = &vam->ip4_fib_counters[vrf_index][i];
2042 clib_memcpy (&ip4, &v->address, sizeof (ip4));
2043 counter->address = ip4;
2044 counter->address_length = v->address_length;
2045 counter->packets = clib_net_to_host_u64 (v->packets);
2046 counter->bytes = clib_net_to_host_u64 (v->bytes);
2047 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002048 }
2049}
2050
2051static void vl_api_vnet_ip6_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002052 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002053{
Dave Barach72d72232016-08-04 10:15:08 -04002054 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002055}
2056
2057static void vl_api_vnet_ip6_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002058 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002059{
Dave Barach72d72232016-08-04 10:15:08 -04002060 vat_main_t *vam = &vat_main;
2061 vl_api_ip6_fib_counter_t *v;
2062 ip6_fib_counter_t *counter;
2063 struct in6_addr ip6;
2064 u32 vrf_id;
2065 u32 vrf_index;
2066 u32 count;
2067 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002068
Dave Barach72d72232016-08-04 10:15:08 -04002069 vrf_id = ntohl (mp->vrf_id);
2070 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2071 if (~0 == vrf_index)
2072 {
2073 vrf_index = vec_len (vam->ip6_fib_counters_vrf_id_by_index);
2074 vec_validate (vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
2075 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2076 vec_validate (vam->ip6_fib_counters, vrf_index);
2077 vam->ip6_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002078 }
2079
Dave Barach72d72232016-08-04 10:15:08 -04002080 vec_free (vam->ip6_fib_counters[vrf_index]);
2081 v = (vl_api_ip6_fib_counter_t *) & mp->c;
2082 count = ntohl (mp->count);
2083 for (i = 0; i < count; i++)
2084 {
2085 vec_validate (vam->ip6_fib_counters[vrf_index], i);
2086 counter = &vam->ip6_fib_counters[vrf_index][i];
2087 clib_memcpy (&ip6, &v->address, sizeof (ip6));
2088 counter->address = ip6;
2089 counter->address_length = v->address_length;
2090 counter->packets = clib_net_to_host_u64 (v->packets);
2091 counter->bytes = clib_net_to_host_u64 (v->bytes);
2092 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002093 }
2094}
2095
2096static void vl_api_get_first_msg_id_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002097 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002098{
Dave Barach72d72232016-08-04 10:15:08 -04002099 vat_main_t *vam = &vat_main;
2100 i32 retval = ntohl (mp->retval);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002101
Dave Barach72d72232016-08-04 10:15:08 -04002102 if (vam->async_mode)
2103 {
2104 vam->async_errors += (retval < 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002105 }
Dave Barach72d72232016-08-04 10:15:08 -04002106 else
2107 {
2108 vam->retval = retval;
2109 vam->result_ready = 1;
2110 }
2111 if (retval >= 0)
2112 {
2113 errmsg ("first message id %d\n", ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002114 }
2115}
2116
2117static void vl_api_get_first_msg_id_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002118 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002119{
Dave Barach72d72232016-08-04 10:15:08 -04002120 vat_main_t *vam = &vat_main;
2121 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002122
Dave Barach72d72232016-08-04 10:15:08 -04002123 vat_json_init_object (&node);
2124 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2125 vat_json_object_add_uint (&node, "first_msg_id",
2126 (uint) ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002127
Dave Barach72d72232016-08-04 10:15:08 -04002128 vat_json_print (vam->ofp, &node);
2129 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002130
Dave Barach72d72232016-08-04 10:15:08 -04002131 vam->retval = ntohl (mp->retval);
2132 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002133}
2134
Dave Barachb44e9bc2016-02-19 09:06:23 -05002135static void vl_api_get_node_graph_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002136 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002137{
Dave Barach72d72232016-08-04 10:15:08 -04002138 vat_main_t *vam = &vat_main;
2139 api_main_t *am = &api_main;
2140 i32 retval = ntohl (mp->retval);
2141 u8 *pvt_copy, *reply;
2142 void *oldheap;
2143 vlib_node_t *node;
2144 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002145
Dave Barach72d72232016-08-04 10:15:08 -04002146 if (vam->async_mode)
2147 {
2148 vam->async_errors += (retval < 0);
2149 }
2150 else
2151 {
2152 vam->retval = retval;
2153 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002154 }
2155
Dave Barach72d72232016-08-04 10:15:08 -04002156 /* "Should never happen..." */
2157 if (retval != 0)
2158 return;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002159
Dave Barach72d72232016-08-04 10:15:08 -04002160 reply = (u8 *) (mp->reply_in_shmem);
2161 pvt_copy = vec_dup (reply);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002162
Dave Barach72d72232016-08-04 10:15:08 -04002163 /* Toss the shared-memory original... */
2164 pthread_mutex_lock (&am->vlib_rp->mutex);
2165 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002166
Dave Barach72d72232016-08-04 10:15:08 -04002167 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002168
Dave Barach72d72232016-08-04 10:15:08 -04002169 svm_pop_heap (oldheap);
2170 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002171
Dave Barach72d72232016-08-04 10:15:08 -04002172 if (vam->graph_nodes)
2173 {
2174 hash_free (vam->graph_node_index_by_name);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002175
Dave Barach72d72232016-08-04 10:15:08 -04002176 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2177 {
2178 node = vam->graph_nodes[i];
2179 vec_free (node->name);
2180 vec_free (node->next_nodes);
2181 vec_free (node);
2182 }
2183 vec_free (vam->graph_nodes);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002184 }
2185
Dave Barach72d72232016-08-04 10:15:08 -04002186 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2187 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2188 vec_free (pvt_copy);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002189
Dave Barach72d72232016-08-04 10:15:08 -04002190 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2191 {
2192 node = vam->graph_nodes[i];
2193 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002194 }
2195}
2196
2197static void vl_api_get_node_graph_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002198 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002199{
Dave Barach72d72232016-08-04 10:15:08 -04002200 vat_main_t *vam = &vat_main;
2201 api_main_t *am = &api_main;
2202 void *oldheap;
2203 vat_json_node_t node;
2204 u8 *reply;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002205
Dave Barach72d72232016-08-04 10:15:08 -04002206 /* $$$$ make this real? */
2207 vat_json_init_object (&node);
2208 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2209 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002210
Dave Barach72d72232016-08-04 10:15:08 -04002211 reply = (u8 *) (mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002212
Dave Barach72d72232016-08-04 10:15:08 -04002213 /* Toss the shared-memory original... */
2214 pthread_mutex_lock (&am->vlib_rp->mutex);
2215 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002216
Dave Barach72d72232016-08-04 10:15:08 -04002217 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002218
Dave Barach72d72232016-08-04 10:15:08 -04002219 svm_pop_heap (oldheap);
2220 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002221
Dave Barach72d72232016-08-04 10:15:08 -04002222 vat_json_print (vam->ofp, &node);
2223 vat_json_free (&node);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002224
Dave Barach72d72232016-08-04 10:15:08 -04002225 vam->retval = ntohl (mp->retval);
2226 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002227}
2228
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002229static void
Dave Barach72d72232016-08-04 10:15:08 -04002230vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002231{
Dave Barach72d72232016-08-04 10:15:08 -04002232 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002233 u8 *s = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002234
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002235 if (mp->local)
Dave Barach72d72232016-08-04 10:15:08 -04002236 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002237 s = format (s, "%=16d%=16d%=16d\n",
2238 ntohl (mp->sw_if_index), mp->priority, mp->weight);
Dave Barach72d72232016-08-04 10:15:08 -04002239 }
2240 else
2241 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002242 s = format (s, "%=16U%=16d%=16d\n",
2243 mp->is_ipv6 ? format_ip6_address :
2244 format_ip4_address,
2245 mp->ip_address, mp->priority, mp->weight);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002246 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002247
2248 fformat (vam->ofp, "%v", s);
2249 vec_free (s);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002250}
2251
2252static void
Dave Barach72d72232016-08-04 10:15:08 -04002253vl_api_lisp_locator_details_t_handler_json (vl_api_lisp_locator_details_t *
2254 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002255{
Dave Barach72d72232016-08-04 10:15:08 -04002256 vat_main_t *vam = &vat_main;
2257 vat_json_node_t *node = NULL;
Dave Barach72d72232016-08-04 10:15:08 -04002258 struct in6_addr ip6;
2259 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002260
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002261 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Barach72d72232016-08-04 10:15:08 -04002262 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002263 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2264 vat_json_init_array (&vam->json_tree);
2265 }
2266 node = vat_json_array_add (&vam->json_tree);
2267 vat_json_init_object (node);
2268
2269 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2270 vat_json_object_add_uint (node, "priority", mp->priority);
2271 vat_json_object_add_uint (node, "weight", mp->weight);
2272
2273 if (mp->local)
2274 vat_json_object_add_uint (node, "sw_if_index",
2275 clib_net_to_host_u32 (mp->sw_if_index));
2276 else
2277 {
2278 if (mp->is_ipv6)
Dave Barach72d72232016-08-04 10:15:08 -04002279 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002280 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2281 vat_json_object_add_ip6 (node, "address", ip6);
Dave Barach72d72232016-08-04 10:15:08 -04002282 }
2283 else
2284 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002285 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2286 vat_json_object_add_ip4 (node, "address", ip4);
Dave Barach72d72232016-08-04 10:15:08 -04002287 }
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002288 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002289}
2290
2291static void
2292vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
2293 mp)
2294{
2295 vat_main_t *vam = &vat_main;
2296 u8 *ls_name = 0;
2297
2298 ls_name = format (0, "%s", mp->ls_name);
2299
2300 fformat (vam->ofp, "%=10d%=15v\n", clib_net_to_host_u32 (mp->ls_index),
2301 ls_name);
2302 vec_free (ls_name);
2303}
2304
2305static void
2306 vl_api_lisp_locator_set_details_t_handler_json
2307 (vl_api_lisp_locator_set_details_t * mp)
2308{
2309 vat_main_t *vam = &vat_main;
2310 vat_json_node_t *node = 0;
2311 u8 *ls_name = 0;
2312
2313 ls_name = format (0, "%s", mp->ls_name);
2314 vec_add1 (ls_name, 0);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002315
Dave Barach72d72232016-08-04 10:15:08 -04002316 if (VAT_JSON_ARRAY != vam->json_tree.type)
2317 {
2318 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2319 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002320 }
Dave Barach72d72232016-08-04 10:15:08 -04002321 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002322
Dave Barach72d72232016-08-04 10:15:08 -04002323 vat_json_init_object (node);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002324 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2325 vat_json_object_add_uint (node, "ls_index",
2326 clib_net_to_host_u32 (mp->ls_index));
2327 vec_free (ls_name);
2328}
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002329
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002330static u8 *
2331format_lisp_flat_eid (u8 * s, va_list * args)
2332{
2333 u32 type = va_arg (*args, u32);
2334 u8 *eid = va_arg (*args, u8 *);
2335 u32 eid_len = va_arg (*args, u32);
2336
2337 switch (type)
Dave Barach72d72232016-08-04 10:15:08 -04002338 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002339 case 0:
2340 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2341 case 1:
2342 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2343 case 2:
2344 return format (s, "%U", format_ethernet_address, eid);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002345 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002346 return 0;
Dave Barach72d72232016-08-04 10:15:08 -04002347}
2348
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002349static u8 *
2350format_lisp_eid_vat (u8 * s, va_list * args)
Dave Barach72d72232016-08-04 10:15:08 -04002351{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002352 u32 type = va_arg (*args, u32);
2353 u8 *eid = va_arg (*args, u8 *);
2354 u32 eid_len = va_arg (*args, u32);
2355 u8 *seid = va_arg (*args, u8 *);
2356 u32 seid_len = va_arg (*args, u32);
2357 u32 is_src_dst = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -04002358
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002359 if (is_src_dst)
2360 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002361
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002362 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002363
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002364 return s;
Dave Barach72d72232016-08-04 10:15:08 -04002365}
2366
2367static void
Filip Tehlarc00617b2016-08-27 08:40:26 +02002368vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
2369{
2370 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002371 u8 *s = 0, *eid = 0;
2372
2373 if (~0 == mp->locator_set_index)
2374 s = format (0, "action: %d", mp->action);
2375 else
2376 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2377
2378 eid = format (0, "%U", format_lisp_eid_vat,
2379 mp->eid_type,
2380 mp->eid,
2381 mp->eid_prefix_len,
2382 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2383 vec_add1 (eid, 0);
2384
2385 fformat (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-d\n",
2386 clib_net_to_host_u32 (mp->vni),
2387 eid,
2388 mp->is_local ? "local" : "remote",
2389 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative);
2390 vec_free (s);
2391 vec_free (eid);
Filip Tehlarc00617b2016-08-27 08:40:26 +02002392}
2393
2394static void
Dave Barach72d72232016-08-04 10:15:08 -04002395vl_api_lisp_eid_table_details_t_handler_json (vl_api_lisp_eid_table_details_t
2396 * mp)
2397{
2398 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002399 vat_json_node_t *node = 0;
2400 u8 *eid = 0;
2401
2402 if (VAT_JSON_ARRAY != vam->json_tree.type)
2403 {
2404 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2405 vat_json_init_array (&vam->json_tree);
2406 }
2407 node = vat_json_array_add (&vam->json_tree);
2408
2409 vat_json_init_object (node);
2410 if (~0 == mp->locator_set_index)
2411 vat_json_object_add_uint (node, "action", mp->action);
2412 else
2413 vat_json_object_add_uint (node, "locator_set_index",
2414 clib_net_to_host_u32 (mp->locator_set_index));
2415
2416 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
2417 eid = format (0, "%U", format_lisp_eid_vat,
2418 mp->eid_type,
2419 mp->eid,
2420 mp->eid_prefix_len,
2421 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2422 vec_add1 (eid, 0);
2423 vat_json_object_add_string_copy (node, "eid", eid);
2424 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2425 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
2426 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
2427 vec_free (eid);
Dave Barach72d72232016-08-04 10:15:08 -04002428}
2429
2430static void
2431 vl_api_lisp_eid_table_map_details_t_handler
2432 (vl_api_lisp_eid_table_map_details_t * mp)
2433{
2434 vat_main_t *vam = &vat_main;
2435
2436 u8 *line = format (0, "%=10d%=10d",
2437 clib_net_to_host_u32 (mp->vni),
Filip Tehlarc0681792016-08-24 14:11:07 +02002438 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002439 fformat (vam->ofp, "%v\n", line);
2440 vec_free (line);
2441}
2442
2443static void
2444 vl_api_lisp_eid_table_map_details_t_handler_json
2445 (vl_api_lisp_eid_table_map_details_t * mp)
2446{
2447 vat_main_t *vam = &vat_main;
2448 vat_json_node_t *node = NULL;
2449
2450 if (VAT_JSON_ARRAY != vam->json_tree.type)
2451 {
2452 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2453 vat_json_init_array (&vam->json_tree);
2454 }
2455 node = vat_json_array_add (&vam->json_tree);
2456 vat_json_init_object (node);
Filip Tehlarc0681792016-08-24 14:11:07 +02002457 vat_json_object_add_uint (node, "dp_table",
2458 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002459 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
Filip Tehlar2f653d02016-07-13 13:17:15 +02002460}
2461
Filip Tehlar50a4e142016-08-24 11:28:02 +02002462static void
2463 vl_api_lisp_eid_table_vni_details_t_handler
2464 (vl_api_lisp_eid_table_vni_details_t * mp)
2465{
2466 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002467
Filip Tehlar50a4e142016-08-24 11:28:02 +02002468 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
2469 fformat (vam->ofp, "%v\n", line);
2470 vec_free (line);
2471}
2472
2473static void
2474 vl_api_lisp_eid_table_vni_details_t_handler_json
2475 (vl_api_lisp_eid_table_vni_details_t * mp)
2476{
2477 vat_main_t *vam = &vat_main;
2478 vat_json_node_t *node = NULL;
2479
2480 if (VAT_JSON_ARRAY != vam->json_tree.type)
2481 {
2482 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2483 vat_json_init_array (&vam->json_tree);
2484 }
2485 node = vat_json_array_add (&vam->json_tree);
2486 vat_json_init_object (node);
2487 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2488}
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002489
2490static u8 *
2491format_decap_next (u8 * s, va_list * args)
2492{
2493 u32 next_index = va_arg (*args, u32);
2494
2495 switch (next_index)
2496 {
2497 case LISP_GPE_INPUT_NEXT_DROP:
2498 return format (s, "drop");
2499 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2500 return format (s, "ip4");
2501 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2502 return format (s, "ip6");
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002503 default:
2504 return format (s, "unknown %d", next_index);
2505 }
2506 return s;
2507}
2508
2509static void
Dave Barach72d72232016-08-04 10:15:08 -04002510vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *
2511 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002512{
Dave Barach72d72232016-08-04 10:15:08 -04002513 vat_main_t *vam = &vat_main;
2514 u8 *iid_str;
2515 u8 *flag_str = NULL;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002516
Dave Barach72d72232016-08-04 10:15:08 -04002517 iid_str = format (0, "%d (0x%x)", ntohl (mp->iid), ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002518
2519#define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2520 foreach_lisp_gpe_flag_bit;
2521#undef _
2522
Dave Barach72d72232016-08-04 10:15:08 -04002523 fformat (vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2524 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2525 mp->tunnels,
2526 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2527 mp->source_ip,
2528 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2529 mp->destination_ip,
2530 ntohl (mp->encap_fib_id),
2531 ntohl (mp->decap_fib_id),
2532 format_decap_next, ntohl (mp->dcap_next),
2533 mp->ver_res >> 6,
2534 flag_str, mp->next_protocol, mp->ver_res, mp->res, iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002535
Dave Barach72d72232016-08-04 10:15:08 -04002536 vec_free (iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002537}
2538
2539static void
Dave Barach72d72232016-08-04 10:15:08 -04002540 vl_api_lisp_gpe_tunnel_details_t_handler_json
2541 (vl_api_lisp_gpe_tunnel_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002542{
Dave Barach72d72232016-08-04 10:15:08 -04002543 vat_main_t *vam = &vat_main;
2544 vat_json_node_t *node = NULL;
2545 struct in6_addr ip6;
2546 struct in_addr ip4;
2547 u8 *next_decap_str;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002548
Dave Barach72d72232016-08-04 10:15:08 -04002549 next_decap_str = format (0, "%U", format_decap_next, htonl (mp->dcap_next));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002550
Dave Barach72d72232016-08-04 10:15:08 -04002551 if (VAT_JSON_ARRAY != vam->json_tree.type)
2552 {
2553 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2554 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002555 }
Dave Barach72d72232016-08-04 10:15:08 -04002556 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002557
Dave Barach72d72232016-08-04 10:15:08 -04002558 vat_json_init_object (node);
2559 vat_json_object_add_uint (node, "tunel", mp->tunnels);
2560 if (mp->is_ipv6)
2561 {
2562 clib_memcpy (&ip6, mp->source_ip, sizeof (ip6));
2563 vat_json_object_add_ip6 (node, "source address", ip6);
2564 clib_memcpy (&ip6, mp->destination_ip, sizeof (ip6));
2565 vat_json_object_add_ip6 (node, "destination address", ip6);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002566 }
Dave Barach72d72232016-08-04 10:15:08 -04002567 else
2568 {
2569 clib_memcpy (&ip4, mp->source_ip, sizeof (ip4));
2570 vat_json_object_add_ip4 (node, "source address", ip4);
2571 clib_memcpy (&ip4, mp->destination_ip, sizeof (ip4));
2572 vat_json_object_add_ip4 (node, "destination address", ip4);
2573 }
2574 vat_json_object_add_uint (node, "fib encap", ntohl (mp->encap_fib_id));
2575 vat_json_object_add_uint (node, "fib decap", ntohl (mp->decap_fib_id));
2576 vat_json_object_add_string_copy (node, "decap next", next_decap_str);
2577 vat_json_object_add_uint (node, "lisp version", mp->ver_res >> 6);
2578 vat_json_object_add_uint (node, "flags", mp->flags);
2579 vat_json_object_add_uint (node, "next protocol", mp->next_protocol);
2580 vat_json_object_add_uint (node, "ver_res", mp->ver_res);
2581 vat_json_object_add_uint (node, "res", mp->res);
2582 vat_json_object_add_uint (node, "iid", ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002583
Dave Barach72d72232016-08-04 10:15:08 -04002584 vec_free (next_decap_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002585}
2586
2587static void
Dave Barach72d72232016-08-04 10:15:08 -04002588vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
2589 * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002590{
Dave Barach72d72232016-08-04 10:15:08 -04002591 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002592
Dave Barach72d72232016-08-04 10:15:08 -04002593 fformat (vam->ofp, "%=20U\n",
2594 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2595 mp->ip_address);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002596}
2597
2598static void
Dave Barach72d72232016-08-04 10:15:08 -04002599 vl_api_lisp_map_resolver_details_t_handler_json
2600 (vl_api_lisp_map_resolver_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002601{
Dave Barach72d72232016-08-04 10:15:08 -04002602 vat_main_t *vam = &vat_main;
2603 vat_json_node_t *node = NULL;
2604 struct in6_addr ip6;
2605 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002606
Dave Barach72d72232016-08-04 10:15:08 -04002607 if (VAT_JSON_ARRAY != vam->json_tree.type)
2608 {
2609 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2610 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002611 }
Dave Barach72d72232016-08-04 10:15:08 -04002612 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002613
Dave Barach72d72232016-08-04 10:15:08 -04002614 vat_json_init_object (node);
2615 if (mp->is_ipv6)
2616 {
2617 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2618 vat_json_object_add_ip6 (node, "map resolver", ip6);
2619 }
2620 else
2621 {
2622 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2623 vat_json_object_add_ip4 (node, "map resolver", ip4);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002624 }
2625}
2626
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002627static void
Dave Barach72d72232016-08-04 10:15:08 -04002628 vl_api_show_lisp_status_reply_t_handler
2629 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002630{
Dave Barach72d72232016-08-04 10:15:08 -04002631 vat_main_t *vam = &vat_main;
2632 i32 retval = ntohl (mp->retval);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002633
Dave Barach72d72232016-08-04 10:15:08 -04002634 if (0 <= retval)
2635 {
2636 fformat (vam->ofp, "feature: %s\ngpe: %s\n",
2637 mp->feature_status ? "enabled" : "disabled",
2638 mp->gpe_status ? "enabled" : "disabled");
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002639 }
2640
Dave Barach72d72232016-08-04 10:15:08 -04002641 vam->retval = retval;
2642 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002643}
2644
2645static void
Dave Barach72d72232016-08-04 10:15:08 -04002646 vl_api_show_lisp_status_reply_t_handler_json
2647 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002648{
Dave Barach72d72232016-08-04 10:15:08 -04002649 vat_main_t *vam = &vat_main;
2650 vat_json_node_t node;
2651 u8 *gpe_status = NULL;
2652 u8 *feature_status = NULL;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002653
Dave Barach72d72232016-08-04 10:15:08 -04002654 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2655 feature_status = format (0, "%s",
2656 mp->feature_status ? "enabled" : "disabled");
2657 vec_add1 (gpe_status, 0);
2658 vec_add1 (feature_status, 0);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002659
Dave Barach72d72232016-08-04 10:15:08 -04002660 vat_json_init_object (&node);
2661 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
2662 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
Filip Tehlar46d4e362016-05-09 09:39:26 +02002663
Dave Barach72d72232016-08-04 10:15:08 -04002664 vec_free (gpe_status);
2665 vec_free (feature_status);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002666
Dave Barach72d72232016-08-04 10:15:08 -04002667 vat_json_print (vam->ofp, &node);
2668 vat_json_free (&node);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002669
Dave Barach72d72232016-08-04 10:15:08 -04002670 vam->retval = ntohl (mp->retval);
2671 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002672}
2673
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002674static void
Dave Barach72d72232016-08-04 10:15:08 -04002675 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
2676 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002677{
Dave Barach72d72232016-08-04 10:15:08 -04002678 vat_main_t *vam = &vat_main;
2679 i32 retval = ntohl (mp->retval);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002680
Dave Barach72d72232016-08-04 10:15:08 -04002681 if (retval >= 0)
2682 {
2683 fformat (vam->ofp, "%=20s\n", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002684 }
2685
Dave Barach72d72232016-08-04 10:15:08 -04002686 vam->retval = retval;
2687 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002688}
2689
2690static void
Dave Barach72d72232016-08-04 10:15:08 -04002691 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json
2692 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002693{
Dave Barach72d72232016-08-04 10:15:08 -04002694 vat_main_t *vam = &vat_main;
2695 vat_json_node_t *node = NULL;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002696
Dave Barach72d72232016-08-04 10:15:08 -04002697 if (VAT_JSON_ARRAY != vam->json_tree.type)
2698 {
2699 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2700 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002701 }
Dave Barach72d72232016-08-04 10:15:08 -04002702 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002703
Dave Barach72d72232016-08-04 10:15:08 -04002704 vat_json_init_object (node);
2705 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002706
Dave Barach72d72232016-08-04 10:15:08 -04002707 vat_json_print (vam->ofp, node);
2708 vat_json_free (node);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002709
Dave Barach72d72232016-08-04 10:15:08 -04002710 vam->retval = ntohl (mp->retval);
2711 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002712}
2713
Florin Corasdca88042016-09-14 16:01:38 +02002714static u8 *
2715format_lisp_map_request_mode (u8 * s, va_list * args)
2716{
2717 u32 mode = va_arg (*args, u32);
2718
2719 switch (mode)
2720 {
2721 case 0:
2722 return format (0, "dst-only");
2723 case 1:
2724 return format (0, "src-dst");
2725 }
2726 return 0;
2727}
2728
2729static void
2730 vl_api_show_lisp_map_request_mode_reply_t_handler
2731 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2732{
2733 vat_main_t *vam = &vat_main;
2734 i32 retval = ntohl (mp->retval);
2735
2736 if (0 <= retval)
2737 {
2738 u32 mode = mp->mode;
2739 fformat (vam->ofp, "map_request_mode: %U\n",
2740 format_lisp_map_request_mode, mode);
2741 }
2742
2743 vam->retval = retval;
2744 vam->result_ready = 1;
2745}
2746
2747static void
2748 vl_api_show_lisp_map_request_mode_reply_t_handler_json
2749 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2750{
2751 vat_main_t *vam = &vat_main;
2752 vat_json_node_t node;
2753 u8 *s = 0;
2754 u32 mode;
2755
2756 mode = mp->mode;
2757 s = format (0, "%U", format_lisp_map_request_mode, mode);
2758 vec_add1 (s, 0);
2759
2760 vat_json_init_object (&node);
2761 vat_json_object_add_string_copy (&node, "map_request_mode", s);
2762 vat_json_print (vam->ofp, &node);
2763 vat_json_free (&node);
2764
2765 vec_free (s);
2766 vam->retval = ntohl (mp->retval);
2767 vam->result_ready = 1;
2768}
2769
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002770static void
2771vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2772{
Dave Barach72d72232016-08-04 10:15:08 -04002773 vat_main_t *vam = &vat_main;
2774 i32 retval = ntohl (mp->retval);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002775
Dave Barach72d72232016-08-04 10:15:08 -04002776 if (0 <= retval)
2777 {
2778 fformat (vam->ofp, "%-20s%-16s\n",
2779 mp->status ? "enabled" : "disabled",
2780 mp->status ? (char *) mp->locator_set_name : "");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002781 }
2782
Dave Barach72d72232016-08-04 10:15:08 -04002783 vam->retval = retval;
2784 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002785}
2786
2787static void
Dave Barach72d72232016-08-04 10:15:08 -04002788vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t *
2789 mp)
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002790{
Dave Barach72d72232016-08-04 10:15:08 -04002791 vat_main_t *vam = &vat_main;
2792 vat_json_node_t node;
2793 u8 *status = 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002794
Dave Barach72d72232016-08-04 10:15:08 -04002795 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2796 vec_add1 (status, 0);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002797
Dave Barach72d72232016-08-04 10:15:08 -04002798 vat_json_init_object (&node);
2799 vat_json_object_add_string_copy (&node, "status", status);
2800 if (mp->status)
2801 {
2802 vat_json_object_add_string_copy (&node, "locator_set",
2803 mp->locator_set_name);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002804 }
2805
Dave Barach72d72232016-08-04 10:15:08 -04002806 vec_free (status);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002807
Dave Barach72d72232016-08-04 10:15:08 -04002808 vat_json_print (vam->ofp, &node);
2809 vat_json_free (&node);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002810
Dave Barach72d72232016-08-04 10:15:08 -04002811 vam->retval = ntohl (mp->retval);
2812 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002813}
2814
Dave Barach72d72232016-08-04 10:15:08 -04002815static u8 *
2816format_policer_type (u8 * s, va_list * va)
Matus Fabiane8554802016-05-18 23:40:37 -07002817{
Dave Barach72d72232016-08-04 10:15:08 -04002818 u32 i = va_arg (*va, u32);
Matus Fabiane8554802016-05-18 23:40:37 -07002819
Dave Barach72d72232016-08-04 10:15:08 -04002820 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2821 s = format (s, "1r2c");
2822 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2823 s = format (s, "1r3c");
2824 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2825 s = format (s, "2r3c-2698");
2826 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2827 s = format (s, "2r3c-4115");
2828 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2829 s = format (s, "2r3c-mef5cf1");
2830 else
2831 s = format (s, "ILLEGAL");
Matus Fabiane8554802016-05-18 23:40:37 -07002832 return s;
2833}
2834
Dave Barach72d72232016-08-04 10:15:08 -04002835static u8 *
2836format_policer_rate_type (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -07002837{
2838 u32 i = va_arg (*va, u32);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002839
Dave Barach72d72232016-08-04 10:15:08 -04002840 if (i == SSE2_QOS_RATE_KBPS)
2841 s = format (s, "kbps");
2842 else if (i == SSE2_QOS_RATE_PPS)
2843 s = format (s, "pps");
2844 else
2845 s = format (s, "ILLEGAL");
2846 return s;
2847}
2848
2849static u8 *
2850format_policer_round_type (u8 * s, va_list * va)
2851{
2852 u32 i = va_arg (*va, u32);
2853
2854 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2855 s = format (s, "closest");
2856 else if (i == SSE2_QOS_ROUND_TO_UP)
2857 s = format (s, "up");
2858 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2859 s = format (s, "down");
2860 else
2861 s = format (s, "ILLEGAL");
2862 return s;
2863}
2864
2865static u8 *
2866format_policer_action_type (u8 * s, va_list * va)
2867{
2868 u32 i = va_arg (*va, u32);
2869
2870 if (i == SSE2_QOS_ACTION_DROP)
2871 s = format (s, "drop");
2872 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2873 s = format (s, "transmit");
2874 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2875 s = format (s, "mark-and-transmit");
2876 else
2877 s = format (s, "ILLEGAL");
2878 return s;
2879}
2880
2881static u8 *
2882format_dscp (u8 * s, va_list * va)
2883{
2884 u32 i = va_arg (*va, u32);
2885 char *t = 0;
2886
2887 switch (i)
2888 {
2889#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2890 foreach_vnet_dscp
2891#undef _
Matus Fabian4ac74c92016-05-31 07:33:29 -07002892 default:
2893 return format (s, "ILLEGAL");
Dave Barach72d72232016-08-04 10:15:08 -04002894 }
Matus Fabian4ac74c92016-05-31 07:33:29 -07002895 s = format (s, "%s", t);
2896 return s;
2897}
2898
Dave Barach72d72232016-08-04 10:15:08 -04002899static void
2900vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07002901{
Dave Barach72d72232016-08-04 10:15:08 -04002902 vat_main_t *vam = &vat_main;
2903 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
Matus Fabian4ac74c92016-05-31 07:33:29 -07002904
Dave Barach72d72232016-08-04 10:15:08 -04002905 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2906 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
2907 else
2908 conform_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002909
Dave Barach72d72232016-08-04 10:15:08 -04002910 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2911 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
2912 else
2913 exceed_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002914
Dave Barach72d72232016-08-04 10:15:08 -04002915 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2916 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
2917 else
2918 violate_dscp_str = format (0, "");
Matus Fabiane8554802016-05-18 23:40:37 -07002919
Dave Barach72d72232016-08-04 10:15:08 -04002920 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2921 "rate type %U, round type %U, %s rate, %s color-aware, "
2922 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2923 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2924 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2925 mp->name,
2926 format_policer_type, mp->type,
2927 ntohl (mp->cir),
2928 ntohl (mp->eir),
2929 clib_net_to_host_u64 (mp->cb),
2930 clib_net_to_host_u64 (mp->eb),
2931 format_policer_rate_type, mp->rate_type,
2932 format_policer_round_type, mp->round_type,
2933 mp->single_rate ? "single" : "dual",
2934 mp->color_aware ? "is" : "not",
2935 ntohl (mp->cir_tokens_per_period),
2936 ntohl (mp->pir_tokens_per_period),
2937 ntohl (mp->scale),
2938 ntohl (mp->current_limit),
2939 ntohl (mp->current_bucket),
2940 ntohl (mp->extended_limit),
2941 ntohl (mp->extended_bucket),
2942 clib_net_to_host_u64 (mp->last_update_time),
2943 format_policer_action_type, mp->conform_action_type,
2944 conform_dscp_str,
2945 format_policer_action_type, mp->exceed_action_type,
2946 exceed_dscp_str,
2947 format_policer_action_type, mp->violate_action_type,
2948 violate_dscp_str);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002949
Dave Barach72d72232016-08-04 10:15:08 -04002950 vec_free (conform_dscp_str);
2951 vec_free (exceed_dscp_str);
2952 vec_free (violate_dscp_str);
Matus Fabiane8554802016-05-18 23:40:37 -07002953}
2954
2955static void vl_api_policer_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002956 (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07002957{
Dave Barach72d72232016-08-04 10:15:08 -04002958 vat_main_t *vam = &vat_main;
2959 vat_json_node_t *node;
2960 u8 *rate_type_str, *round_type_str, *type_str;
2961 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
Matus Fabiane8554802016-05-18 23:40:37 -07002962
Dave Barach72d72232016-08-04 10:15:08 -04002963 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2964 round_type_str =
2965 format (0, "%U", format_policer_round_type, mp->round_type);
2966 type_str = format (0, "%U", format_policer_type, mp->type);
2967 conform_action_str = format (0, "%U", format_policer_action_type,
2968 mp->conform_action_type);
2969 exceed_action_str = format (0, "%U", format_policer_action_type,
2970 mp->exceed_action_type);
2971 violate_action_str = format (0, "%U", format_policer_action_type,
2972 mp->violate_action_type);
Matus Fabiane8554802016-05-18 23:40:37 -07002973
Dave Barach72d72232016-08-04 10:15:08 -04002974 if (VAT_JSON_ARRAY != vam->json_tree.type)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02002975 {
Dave Barach72d72232016-08-04 10:15:08 -04002976 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2977 vat_json_init_array (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02002978 }
Dave Barach72d72232016-08-04 10:15:08 -04002979 node = vat_json_array_add (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02002980
Dave Barach72d72232016-08-04 10:15:08 -04002981 vat_json_init_object (node);
2982 vat_json_object_add_string_copy (node, "name", mp->name);
2983 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2984 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2985 vat_json_object_add_uint (node, "cb", ntohl (mp->cb));
2986 vat_json_object_add_uint (node, "eb", ntohl (mp->eb));
2987 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2988 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2989 vat_json_object_add_string_copy (node, "type", type_str);
2990 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2991 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2992 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2993 vat_json_object_add_uint (node, "cir_tokens_per_period",
2994 ntohl (mp->cir_tokens_per_period));
2995 vat_json_object_add_uint (node, "eir_tokens_per_period",
2996 ntohl (mp->pir_tokens_per_period));
2997 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2998 vat_json_object_add_uint (node, "current_bucket",
2999 ntohl (mp->current_bucket));
3000 vat_json_object_add_uint (node, "extended_limit",
3001 ntohl (mp->extended_limit));
3002 vat_json_object_add_uint (node, "extended_bucket",
3003 ntohl (mp->extended_bucket));
3004 vat_json_object_add_uint (node, "last_update_time",
3005 ntohl (mp->last_update_time));
3006 vat_json_object_add_string_copy (node, "conform_action",
3007 conform_action_str);
3008 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3009 {
3010 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3011 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
3012 vec_free (dscp_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003013 }
Dave Barach72d72232016-08-04 10:15:08 -04003014 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
3015 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3016 {
3017 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3018 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
3019 vec_free (dscp_str);
3020 }
3021 vat_json_object_add_string_copy (node, "violate_action",
3022 violate_action_str);
3023 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3024 {
3025 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3026 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
3027 vec_free (dscp_str);
3028 }
3029
3030 vec_free (rate_type_str);
3031 vec_free (round_type_str);
3032 vec_free (type_str);
3033 vec_free (conform_action_str);
3034 vec_free (exceed_action_str);
3035 vec_free (violate_action_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003036}
3037
Dave Barach72d72232016-08-04 10:15:08 -04003038static void
3039vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
3040 mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003041{
Dave Barach72d72232016-08-04 10:15:08 -04003042 vat_main_t *vam = &vat_main;
3043 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003044
Dave Barach72d72232016-08-04 10:15:08 -04003045 if (count > 0)
3046 fformat (vam->ofp, "classify table ids (%d) : ", count);
3047 for (i = 0; i < count; i++)
3048 {
3049 fformat (vam->ofp, "%d", ntohl (mp->ids[i]));
3050 fformat (vam->ofp, (i < count - 1) ? "," : "\n");
3051 }
3052 vam->retval = ntohl (mp->retval);
3053 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003054}
3055
Dave Barach72d72232016-08-04 10:15:08 -04003056static void
3057 vl_api_classify_table_ids_reply_t_handler_json
3058 (vl_api_classify_table_ids_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003059{
Dave Barach72d72232016-08-04 10:15:08 -04003060 vat_main_t *vam = &vat_main;
3061 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003062
Dave Barach72d72232016-08-04 10:15:08 -04003063 if (count > 0)
3064 {
3065 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003066
Dave Barach72d72232016-08-04 10:15:08 -04003067 vat_json_init_object (&node);
3068 for (i = 0; i < count; i++)
3069 {
3070 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
3071 }
3072 vat_json_print (vam->ofp, &node);
3073 vat_json_free (&node);
3074 }
3075 vam->retval = ntohl (mp->retval);
3076 vam->result_ready = 1;
3077}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003078
Dave Barach72d72232016-08-04 10:15:08 -04003079static void
3080 vl_api_classify_table_by_interface_reply_t_handler
3081 (vl_api_classify_table_by_interface_reply_t * mp)
3082{
3083 vat_main_t *vam = &vat_main;
3084 u32 table_id;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003085
Dave Barach72d72232016-08-04 10:15:08 -04003086 table_id = ntohl (mp->l2_table_id);
3087 if (table_id != ~0)
3088 fformat (vam->ofp, "l2 table id : %d\n", table_id);
3089 else
3090 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
3091 table_id = ntohl (mp->ip4_table_id);
3092 if (table_id != ~0)
3093 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
3094 else
3095 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
3096 table_id = ntohl (mp->ip6_table_id);
3097 if (table_id != ~0)
3098 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
3099 else
3100 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
3101 vam->retval = ntohl (mp->retval);
3102 vam->result_ready = 1;
3103}
3104
3105static void
3106 vl_api_classify_table_by_interface_reply_t_handler_json
3107 (vl_api_classify_table_by_interface_reply_t * mp)
3108{
3109 vat_main_t *vam = &vat_main;
3110 vat_json_node_t node;
3111
3112 vat_json_init_object (&node);
3113
3114 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
3115 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
3116 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
3117
3118 vat_json_print (vam->ofp, &node);
3119 vat_json_free (&node);
3120
3121 vam->retval = ntohl (mp->retval);
3122 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003123}
3124
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003125static void vl_api_policer_add_del_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003126 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003127{
Dave Barach72d72232016-08-04 10:15:08 -04003128 vat_main_t *vam = &vat_main;
3129 i32 retval = ntohl (mp->retval);
3130 if (vam->async_mode)
3131 {
3132 vam->async_errors += (retval < 0);
3133 }
3134 else
3135 {
3136 vam->retval = retval;
3137 vam->result_ready = 1;
3138 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3139 /*
3140 * Note: this is just barely thread-safe, depends on
3141 * the main thread spinning waiting for an answer...
3142 */
3143 errmsg ("policer index %d\n", ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003144 }
3145}
3146
3147static void vl_api_policer_add_del_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003148 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003149{
Dave Barach72d72232016-08-04 10:15:08 -04003150 vat_main_t *vam = &vat_main;
3151 vat_json_node_t node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003152
Dave Barach72d72232016-08-04 10:15:08 -04003153 vat_json_init_object (&node);
3154 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3155 vat_json_object_add_uint (&node, "policer_index",
3156 ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003157
Dave Barach72d72232016-08-04 10:15:08 -04003158 vat_json_print (vam->ofp, &node);
3159 vat_json_free (&node);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003160
Dave Barach72d72232016-08-04 10:15:08 -04003161 vam->retval = ntohl (mp->retval);
3162 vam->result_ready = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003163}
3164
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003165/* Format hex dump. */
Dave Barach72d72232016-08-04 10:15:08 -04003166u8 *
3167format_hex_bytes (u8 * s, va_list * va)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003168{
Dave Barach72d72232016-08-04 10:15:08 -04003169 u8 *bytes = va_arg (*va, u8 *);
3170 int n_bytes = va_arg (*va, int);
3171 uword i;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003172
Dave Barach72d72232016-08-04 10:15:08 -04003173 /* Print short or long form depending on byte count. */
3174 uword short_form = n_bytes <= 32;
3175 uword indent = format_get_indent (s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003176
Dave Barach72d72232016-08-04 10:15:08 -04003177 if (n_bytes == 0)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003178 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003179
Dave Barach72d72232016-08-04 10:15:08 -04003180 for (i = 0; i < n_bytes; i++)
3181 {
3182 if (!short_form && (i % 32) == 0)
3183 s = format (s, "%08x: ", i);
3184 s = format (s, "%02x", bytes[i]);
3185 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3186 s = format (s, "\n%U", format_white_space, indent);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003187 }
Dave Barach72d72232016-08-04 10:15:08 -04003188
3189 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003190}
3191
Dave Barach72d72232016-08-04 10:15:08 -04003192static void
3193vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3194 * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003195{
Dave Barach72d72232016-08-04 10:15:08 -04003196 vat_main_t *vam = &vat_main;
3197 i32 retval = ntohl (mp->retval);
3198 if (retval == 0)
3199 {
3200 fformat (vam->ofp, "classify table info :\n");
3201 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n",
3202 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3203 ntohl (mp->miss_next_index));
3204 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n",
3205 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3206 ntohl (mp->match_n_vectors));
3207 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask,
3208 ntohl (mp->mask_length));
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003209 }
Dave Barach72d72232016-08-04 10:15:08 -04003210 vam->retval = retval;
3211 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003212}
3213
Dave Barach72d72232016-08-04 10:15:08 -04003214static void
3215 vl_api_classify_table_info_reply_t_handler_json
3216 (vl_api_classify_table_info_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003217{
Dave Barach72d72232016-08-04 10:15:08 -04003218 vat_main_t *vam = &vat_main;
3219 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003220
Dave Barach72d72232016-08-04 10:15:08 -04003221 i32 retval = ntohl (mp->retval);
3222 if (retval == 0)
3223 {
3224 vat_json_init_object (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003225
Dave Barach72d72232016-08-04 10:15:08 -04003226 vat_json_object_add_int (&node, "sessions",
3227 ntohl (mp->active_sessions));
3228 vat_json_object_add_int (&node, "nexttbl",
3229 ntohl (mp->next_table_index));
3230 vat_json_object_add_int (&node, "nextnode",
3231 ntohl (mp->miss_next_index));
3232 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3233 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3234 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3235 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3236 ntohl (mp->mask_length), 0);
3237 vat_json_object_add_string_copy (&node, "mask", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003238
Dave Barach72d72232016-08-04 10:15:08 -04003239 vat_json_print (vam->ofp, &node);
3240 vat_json_free (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003241 }
Dave Barach72d72232016-08-04 10:15:08 -04003242 vam->retval = ntohl (mp->retval);
3243 vam->result_ready = 1;
3244}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003245
Dave Barach72d72232016-08-04 10:15:08 -04003246static void
3247vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3248 mp)
3249{
3250 vat_main_t *vam = &vat_main;
3251
3252 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3253 ntohl (mp->hit_next_index), ntohl (mp->advance),
3254 ntohl (mp->opaque_index));
3255 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match,
3256 ntohl (mp->match_length));
3257}
3258
3259static void
3260 vl_api_classify_session_details_t_handler_json
3261 (vl_api_classify_session_details_t * mp)
3262{
3263 vat_main_t *vam = &vat_main;
3264 vat_json_node_t *node = NULL;
3265
3266 if (VAT_JSON_ARRAY != vam->json_tree.type)
3267 {
3268 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3269 vat_json_init_array (&vam->json_tree);
3270 }
3271 node = vat_json_array_add (&vam->json_tree);
3272
3273 vat_json_init_object (node);
3274 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3275 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3276 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3277 u8 *s =
3278 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3279 0);
3280 vat_json_object_add_string_copy (node, "match", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003281}
Matus Fabiane8554802016-05-18 23:40:37 -07003282
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003283static void vl_api_pg_create_interface_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003284 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003285{
Dave Barach72d72232016-08-04 10:15:08 -04003286 vat_main_t *vam = &vat_main;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003287
Dave Barach72d72232016-08-04 10:15:08 -04003288 vam->retval = ntohl (mp->retval);
3289 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003290}
3291
3292static void vl_api_pg_create_interface_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003293 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003294{
Dave Barach72d72232016-08-04 10:15:08 -04003295 vat_main_t *vam = &vat_main;
3296 vat_json_node_t node;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003297
Dave Barach72d72232016-08-04 10:15:08 -04003298 i32 retval = ntohl (mp->retval);
3299 if (retval == 0)
3300 {
3301 vat_json_init_object (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003302
Dave Barach72d72232016-08-04 10:15:08 -04003303 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003304
Dave Barach72d72232016-08-04 10:15:08 -04003305 vat_json_print (vam->ofp, &node);
3306 vat_json_free (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003307 }
Dave Barach72d72232016-08-04 10:15:08 -04003308 vam->retval = ntohl (mp->retval);
3309 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003310}
3311
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003312static void vl_api_policer_classify_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003313 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003314{
Dave Barach72d72232016-08-04 10:15:08 -04003315 vat_main_t *vam = &vat_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003316
Dave Barach72d72232016-08-04 10:15:08 -04003317 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3318 ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003319}
3320
3321static void vl_api_policer_classify_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003322 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003323{
Dave Barach72d72232016-08-04 10:15:08 -04003324 vat_main_t *vam = &vat_main;
3325 vat_json_node_t *node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003326
Dave Barach72d72232016-08-04 10:15:08 -04003327 if (VAT_JSON_ARRAY != vam->json_tree.type)
3328 {
3329 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3330 vat_json_init_array (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003331 }
Dave Barach72d72232016-08-04 10:15:08 -04003332 node = vat_json_array_add (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003333
Dave Barach72d72232016-08-04 10:15:08 -04003334 vat_json_init_object (node);
3335 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3336 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003337}
3338
Matus Fabian694265d2016-08-10 01:55:36 -07003339static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
3340 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3341{
3342 vat_main_t *vam = &vat_main;
3343 i32 retval = ntohl (mp->retval);
3344 if (vam->async_mode)
3345 {
3346 vam->async_errors += (retval < 0);
3347 }
3348 else
3349 {
3350 vam->retval = retval;
3351 vam->sw_if_index = ntohl (mp->sw_if_index);
3352 vam->result_ready = 1;
3353 }
3354}
3355
3356static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
3357 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3358{
3359 vat_main_t *vam = &vat_main;
3360 vat_json_node_t node;
3361
3362 vat_json_init_object (&node);
3363 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3364 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
3365
3366 vat_json_print (vam->ofp, &node);
3367 vat_json_free (&node);
3368
3369 vam->retval = ntohl (mp->retval);
3370 vam->result_ready = 1;
3371}
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003372
Ed Warnickecb9cada2015-12-08 15:45:58 -07003373#define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
3374#define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
3375#define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
3376#define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
3377
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003378/*
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003379 * Generate boilerplate reply handlers, which
Ed Warnickecb9cada2015-12-08 15:45:58 -07003380 * dig the return value out of the xxx_reply_t API message,
3381 * stick it into vam->retval, and set vam->result_ready
3382 *
3383 * Could also do this by pointing N message decode slots at
3384 * a single function, but that could break in subtle ways.
3385 */
3386
3387#define foreach_standard_reply_retval_handler \
3388_(sw_interface_set_flags_reply) \
3389_(sw_interface_add_del_address_reply) \
3390_(sw_interface_set_table_reply) \
3391_(sw_interface_set_vpath_reply) \
3392_(sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003393_(sw_interface_set_dpdk_hqos_pipe_reply) \
3394_(sw_interface_set_dpdk_hqos_subport_reply) \
3395_(sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003396_(bridge_domain_add_del_reply) \
3397_(sw_interface_set_l2_xconnect_reply) \
3398_(l2fib_add_del_reply) \
3399_(ip_add_del_route_reply) \
3400_(proxy_arp_add_del_reply) \
3401_(proxy_arp_intfc_enable_disable_reply) \
3402_(mpls_add_del_encap_reply) \
3403_(mpls_add_del_decap_reply) \
3404_(mpls_ethernet_add_del_tunnel_2_reply) \
3405_(sw_interface_set_unnumbered_reply) \
3406_(ip_neighbor_add_del_reply) \
3407_(reset_vrf_reply) \
3408_(oam_add_del_reply) \
3409_(reset_fib_reply) \
3410_(dhcp_proxy_config_reply) \
3411_(dhcp_proxy_config_2_reply) \
3412_(dhcp_proxy_set_vss_reply) \
3413_(dhcp_client_config_reply) \
3414_(set_ip_flow_hash_reply) \
3415_(sw_interface_ip6_enable_disable_reply) \
3416_(sw_interface_ip6_set_link_local_address_reply) \
3417_(sw_interface_ip6nd_ra_prefix_reply) \
3418_(sw_interface_ip6nd_ra_config_reply) \
3419_(set_arp_neighbor_limit_reply) \
3420_(l2_patch_add_del_reply) \
3421_(sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003422_(sr_policy_add_del_reply) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07003423_(sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003424_(classify_add_del_session_reply) \
3425_(classify_set_interface_ip_table_reply) \
3426_(classify_set_interface_l2_tables_reply) \
3427_(l2tpv3_set_tunnel_cookies_reply) \
3428_(l2tpv3_interface_enable_disable_reply) \
3429_(l2tpv3_set_lookup_key_reply) \
3430_(l2_fib_clear_table_reply) \
3431_(l2_interface_efp_filter_reply) \
3432_(l2_interface_vlan_tag_rewrite_reply) \
3433_(modify_vhost_user_if_reply) \
3434_(delete_vhost_user_if_reply) \
3435_(want_ip4_arp_events_reply) \
John Lo1edfba92016-08-27 01:11:57 -04003436_(want_ip6_nd_events_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003437_(input_acl_set_interface_reply) \
3438_(ipsec_spd_add_del_reply) \
3439_(ipsec_interface_add_del_spd_reply) \
3440_(ipsec_spd_add_del_entry_reply) \
3441_(ipsec_sad_add_del_entry_reply) \
3442_(ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003443_(ikev2_profile_add_del_reply) \
3444_(ikev2_profile_set_auth_reply) \
3445_(ikev2_profile_set_id_reply) \
3446_(ikev2_profile_set_ts_reply) \
3447_(ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003448_(delete_loopback_reply) \
3449_(bd_ip_mac_add_del_reply) \
3450_(map_del_domain_reply) \
3451_(map_add_del_rule_reply) \
3452_(want_interface_events_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003453_(want_stats_reply) \
3454_(cop_interface_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003455_(cop_whitelist_enable_disable_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003456_(sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003457_(ioam_enable_reply) \
3458_(ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003459_(lisp_add_del_locator_reply) \
3460_(lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003461_(lisp_add_del_remote_mapping_reply) \
3462_(lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003463_(lisp_gpe_add_del_fwd_entry_reply) \
3464_(lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003465_(lisp_gpe_enable_disable_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003466_(lisp_gpe_add_del_iface_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003467_(lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003468_(lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003469_(lisp_map_request_mode_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003470_(lisp_add_del_map_request_itr_rlocs_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003471_(lisp_eid_table_add_del_map_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003472_(vxlan_gpe_add_del_tunnel_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003473_(af_packet_delete_reply) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003474_(policer_classify_set_interface_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003475_(netmap_create_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003476_(netmap_delete_reply) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003477_(set_ipfix_exporter_reply) \
3478_(set_ipfix_classify_stream_reply) \
3479_(ipfix_classify_table_add_del_reply) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003480_(pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003481_(pg_enable_disable_reply) \
3482_(ip_source_and_port_range_check_add_del_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003483_(ip_source_and_port_range_check_interface_add_del_reply)\
Pavel Kotucek95300d12016-08-26 16:11:36 +02003484_(delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003485_(l2_interface_pbb_tag_rewrite_reply) \
3486_(punt_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003487
3488#define _(n) \
3489 static void vl_api_##n##_t_handler \
3490 (vl_api_##n##_t * mp) \
3491 { \
3492 vat_main_t * vam = &vat_main; \
3493 i32 retval = ntohl(mp->retval); \
3494 if (vam->async_mode) { \
3495 vam->async_errors += (retval < 0); \
3496 } else { \
3497 vam->retval = retval; \
3498 vam->result_ready = 1; \
3499 } \
3500 }
3501foreach_standard_reply_retval_handler;
3502#undef _
3503
3504#define _(n) \
3505 static void vl_api_##n##_t_handler_json \
3506 (vl_api_##n##_t * mp) \
3507 { \
3508 vat_main_t * vam = &vat_main; \
3509 vat_json_node_t node; \
3510 vat_json_init_object(&node); \
3511 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3512 vat_json_print(vam->ofp, &node); \
3513 vam->retval = ntohl(mp->retval); \
3514 vam->result_ready = 1; \
3515 }
3516foreach_standard_reply_retval_handler;
3517#undef _
3518
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003519/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07003520 * Table of message reply handlers, must include boilerplate handlers
3521 * we just generated
3522 */
3523
3524#define foreach_vpe_api_reply_msg \
3525_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3526_(SW_INTERFACE_DETAILS, sw_interface_details) \
3527_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3528_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3529_(CONTROL_PING_REPLY, control_ping_reply) \
3530_(CLI_REPLY, cli_reply) \
Ole Troanc27213a2016-08-31 14:50:49 +02003531_(CLI_INBAND_REPLY, cli_inband_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003532_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3533 sw_interface_add_del_address_reply) \
3534_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3535_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3536_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3537 sw_interface_set_l2_xconnect_reply) \
3538_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3539 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003540_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3541 sw_interface_set_dpdk_hqos_pipe_reply) \
3542_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3543 sw_interface_set_dpdk_hqos_subport_reply) \
3544_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3545 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003546_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3547_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3548_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3549_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3550_(L2_FLAGS_REPLY, l2_flags_reply) \
3551_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3552_(TAP_CONNECT_REPLY, tap_connect_reply) \
3553_(TAP_MODIFY_REPLY, tap_modify_reply) \
3554_(TAP_DELETE_REPLY, tap_delete_reply) \
3555_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3556_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
3557_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3558_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3559 proxy_arp_intfc_enable_disable_reply) \
3560_(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
3561_(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
3562_(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
3563_(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3564 mpls_ethernet_add_del_tunnel_reply) \
3565_(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3566 mpls_ethernet_add_del_tunnel_2_reply) \
3567_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3568 sw_interface_set_unnumbered_reply) \
3569_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3570_(RESET_VRF_REPLY, reset_vrf_reply) \
3571_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3572_(CREATE_SUBIF_REPLY, create_subif_reply) \
3573_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3574_(RESET_FIB_REPLY, reset_fib_reply) \
3575_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3576_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3577_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3578_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3579_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3580_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3581 sw_interface_ip6_enable_disable_reply) \
3582_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3583 sw_interface_ip6_set_link_local_address_reply) \
3584_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3585 sw_interface_ip6nd_ra_prefix_reply) \
3586_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3587 sw_interface_ip6nd_ra_config_reply) \
3588_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3589_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3590_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003591_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3592_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003593_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3594_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3595_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3596classify_set_interface_ip_table_reply) \
3597_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3598 classify_set_interface_l2_tables_reply) \
3599_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3600_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3601_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3602_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3603_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3604 l2tpv3_interface_enable_disable_reply) \
3605_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3606_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3607_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003608_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003609_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3610_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003611_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3612_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3613_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3614_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3615_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3616_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3617_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3618_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003619_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003620_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3621_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003622_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3623_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3624_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003625_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3626_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003627_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3628_(IP_ADDRESS_DETAILS, ip_address_details) \
3629_(IP_DETAILS, ip_details) \
3630_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3631_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3632_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3633_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3634_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003635_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3636_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3637_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3638_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3639_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003640_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3641_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3642_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3643_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3644_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3645_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3646_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3647_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003648_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003649_(MAP_DOMAIN_DETAILS, map_domain_details) \
3650_(MAP_RULE_DETAILS, map_rule_details) \
3651_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3652_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003653_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3654_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003655_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003656_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003657_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003658_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3659_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003660_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3661_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3662_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003663_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3664_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003665_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3666_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003667_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003668_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003669_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003670_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003671_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003672_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3673_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003674_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003675_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003676_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003677_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003678_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003679_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003680_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003681_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3682 lisp_add_del_map_request_itr_rlocs_reply) \
3683_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3684 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003685_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003686_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003687_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003688_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003689_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003690_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003691_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3692_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003693_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003694_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
3695_(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
3696_(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3697_(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003698_(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
3699_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3700_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3701_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003702_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003703_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3704_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3705_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3706_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3707_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3708_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003709_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3710_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3711_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003712_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3713_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3714 ip_source_and_port_range_check_add_del_reply) \
3715_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003716 ip_source_and_port_range_check_interface_add_del_reply) \
3717_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003718_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
Pavel Kotucek95300d12016-08-26 16:11:36 +02003719_(DELETE_SUBIF_REPLY, delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003720_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3721_(PUNT_REPLY, punt_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003722
3723/* M: construct, but don't yet send a message */
3724
3725#define M(T,t) \
3726do { \
3727 vam->result_ready = 0; \
3728 mp = vl_msg_api_alloc(sizeof(*mp)); \
3729 memset (mp, 0, sizeof (*mp)); \
3730 mp->_vl_msg_id = ntohs (VL_API_##T); \
3731 mp->client_index = vam->my_client_index; \
3732} while(0);
3733
3734#define M2(T,t,n) \
3735do { \
3736 vam->result_ready = 0; \
3737 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3738 memset (mp, 0, sizeof (*mp)); \
3739 mp->_vl_msg_id = ntohs (VL_API_##T); \
3740 mp->client_index = vam->my_client_index; \
3741} while(0);
3742
3743
3744/* S: send a message */
3745#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3746
3747/* W: wait for results, with timeout */
3748#define W \
3749do { \
3750 timeout = vat_time_now (vam) + 1.0; \
3751 \
3752 while (vat_time_now (vam) < timeout) { \
3753 if (vam->result_ready == 1) { \
3754 return (vam->retval); \
3755 } \
3756 } \
3757 return -99; \
3758} while(0);
3759
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003760/* W2: wait for results, with timeout */
3761#define W2(body) \
3762do { \
3763 timeout = vat_time_now (vam) + 1.0; \
3764 \
3765 while (vat_time_now (vam) < timeout) { \
3766 if (vam->result_ready == 1) { \
3767 (body); \
3768 return (vam->retval); \
3769 } \
3770 } \
3771 return -99; \
3772} while(0);
3773
Dave Barach72d72232016-08-04 10:15:08 -04003774typedef struct
3775{
3776 u8 *name;
3777 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003778} name_sort_t;
3779
3780
3781#define STR_VTR_OP_CASE(op) \
3782 case L2_VTR_ ## op: \
3783 return "" # op;
3784
Dave Barach72d72232016-08-04 10:15:08 -04003785static const char *
3786str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003787{
Dave Barach72d72232016-08-04 10:15:08 -04003788 switch (vtr_op)
3789 {
3790 STR_VTR_OP_CASE (DISABLED);
3791 STR_VTR_OP_CASE (PUSH_1);
3792 STR_VTR_OP_CASE (PUSH_2);
3793 STR_VTR_OP_CASE (POP_1);
3794 STR_VTR_OP_CASE (POP_2);
3795 STR_VTR_OP_CASE (TRANSLATE_1_1);
3796 STR_VTR_OP_CASE (TRANSLATE_1_2);
3797 STR_VTR_OP_CASE (TRANSLATE_2_1);
3798 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003799 }
3800
Dave Barach72d72232016-08-04 10:15:08 -04003801 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07003802}
3803
Dave Barach72d72232016-08-04 10:15:08 -04003804static int
3805dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003806{
Dave Barach72d72232016-08-04 10:15:08 -04003807 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003808
Dave Barach72d72232016-08-04 10:15:08 -04003809 if (vam->json_output)
3810 {
3811 clib_warning
3812 ("JSON output supported only for VPE API calls and dump_stats_table");
3813 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003814 }
3815
Dave Barach72d72232016-08-04 10:15:08 -04003816 fformat (vam->ofp,
3817 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3818 "Interface", "sw_if_index",
3819 "sub id", "dot1ad", "tags", "outer id",
3820 "inner id", "exact", "default", "outer any", "inner any");
3821
3822 vec_foreach (sub, vam->sw_if_subif_table)
3823 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07003824 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003825 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3826 sub->interface_name,
3827 sub->sw_if_index,
3828 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3829 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3830 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3831 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3832 if (sub->vtr_op != L2_VTR_DISABLED)
3833 {
3834 fformat (vam->ofp,
3835 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3836 "tag1: %d tag2: %d ]\n",
3837 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3838 sub->vtr_tag1, sub->vtr_tag2);
3839 }
3840 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003841
Dave Barach72d72232016-08-04 10:15:08 -04003842 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003843}
3844
Dave Barach72d72232016-08-04 10:15:08 -04003845static int
3846name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003847{
Dave Barach72d72232016-08-04 10:15:08 -04003848 name_sort_t *n1 = a1;
3849 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003850
Dave Barach72d72232016-08-04 10:15:08 -04003851 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003852}
3853
Dave Barach72d72232016-08-04 10:15:08 -04003854static int
3855dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003856{
Dave Barach72d72232016-08-04 10:15:08 -04003857 hash_pair_t *p;
3858 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003859
Dave Barach72d72232016-08-04 10:15:08 -04003860 if (vam->json_output)
3861 {
3862 clib_warning
3863 ("JSON output supported only for VPE API calls and dump_stats_table");
3864 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003865 }
3866
Dave Barach72d72232016-08-04 10:15:08 -04003867 /* *INDENT-OFF* */
3868 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3869 ({
3870 vec_add2 (nses, ns, 1);
3871 ns->name = (u8 *)(p->key);
3872 ns->value = (u32) p->value[0];
3873 }));
3874 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003875
Dave Barach72d72232016-08-04 10:15:08 -04003876 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003877
Dave Barach72d72232016-08-04 10:15:08 -04003878 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3879 vec_foreach (ns, nses)
3880 {
3881 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3882 }
3883 vec_free (nses);
3884 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003885}
3886
Dave Barach72d72232016-08-04 10:15:08 -04003887static int
3888dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003889{
Dave Barach72d72232016-08-04 10:15:08 -04003890 const ip_details_t *det = NULL;
3891 const ip_address_details_t *address = NULL;
3892 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003893
Dave Barach72d72232016-08-04 10:15:08 -04003894 fformat (vam->ofp, "%-12s\n", "sw_if_index");
3895
Dave Barach72d72232016-08-04 10:15:08 -04003896 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3897 {
3898 i++;
3899 if (!det->present)
3900 {
3901 continue;
3902 }
3903 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003904 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003905 " %-30s%-13s\n", "Address", "Prefix length");
3906 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003907 {
Dave Barach72d72232016-08-04 10:15:08 -04003908 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003909 }
Dave Barach72d72232016-08-04 10:15:08 -04003910 vec_foreach (address, det->addr)
3911 {
3912 fformat (vam->ofp,
3913 " %-30U%-13d\n",
3914 is_ipv6 ? format_ip6_address : format_ip4_address,
3915 address->ip, address->prefix_length);
3916 }
3917 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003918
Dave Barach72d72232016-08-04 10:15:08 -04003919 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003920}
3921
Dave Barach72d72232016-08-04 10:15:08 -04003922static int
3923dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003924{
Dave Barach72d72232016-08-04 10:15:08 -04003925 if (vam->json_output)
3926 {
3927 clib_warning
3928 ("JSON output supported only for VPE API calls and dump_stats_table");
3929 return -99;
3930 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003931
Dave Barach72d72232016-08-04 10:15:08 -04003932 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003933}
3934
Dave Barach72d72232016-08-04 10:15:08 -04003935static int
3936dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003937{
Dave Barach72d72232016-08-04 10:15:08 -04003938 if (vam->json_output)
3939 {
3940 clib_warning
3941 ("JSON output supported only for VPE API calls and dump_stats_table");
3942 return -99;
3943 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003944
Dave Barach72d72232016-08-04 10:15:08 -04003945 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003946}
3947
Dave Barach72d72232016-08-04 10:15:08 -04003948static char *
3949counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003950{
Dave Barach72d72232016-08-04 10:15:08 -04003951 if (!is_combined)
3952 {
3953 switch (counter_type)
3954 {
3955 case VNET_INTERFACE_COUNTER_DROP:
3956 return "drop";
3957 case VNET_INTERFACE_COUNTER_PUNT:
3958 return "punt";
3959 case VNET_INTERFACE_COUNTER_IP4:
3960 return "ip4";
3961 case VNET_INTERFACE_COUNTER_IP6:
3962 return "ip6";
3963 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3964 return "rx-no-buf";
3965 case VNET_INTERFACE_COUNTER_RX_MISS:
3966 return "rx-miss";
3967 case VNET_INTERFACE_COUNTER_RX_ERROR:
3968 return "rx-error";
3969 case VNET_INTERFACE_COUNTER_TX_ERROR:
3970 return "tx-error";
3971 default:
3972 return "INVALID-COUNTER-TYPE";
3973 }
3974 }
3975 else
3976 {
3977 switch (counter_type)
3978 {
3979 case VNET_INTERFACE_COUNTER_RX:
3980 return "rx";
3981 case VNET_INTERFACE_COUNTER_TX:
3982 return "tx";
3983 default:
3984 return "INVALID-COUNTER-TYPE";
3985 }
3986 }
3987}
Ed Warnickecb9cada2015-12-08 15:45:58 -07003988
Dave Barach72d72232016-08-04 10:15:08 -04003989static int
3990dump_stats_table (vat_main_t * vam)
3991{
3992 vat_json_node_t node;
3993 vat_json_node_t *msg_array;
3994 vat_json_node_t *msg;
3995 vat_json_node_t *counter_array;
3996 vat_json_node_t *counter;
3997 interface_counter_t c;
3998 u64 packets;
3999 ip4_fib_counter_t *c4;
4000 ip6_fib_counter_t *c6;
4001 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004002
Dave Barach72d72232016-08-04 10:15:08 -04004003 if (!vam->json_output)
4004 {
4005 clib_warning ("dump_stats_table supported only in JSON format");
4006 return -99;
4007 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004008
Dave Barach72d72232016-08-04 10:15:08 -04004009 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004010
Dave Barach72d72232016-08-04 10:15:08 -04004011 /* interface counters */
4012 msg_array = vat_json_object_add (&node, "interface_counters");
4013 vat_json_init_array (msg_array);
4014 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4015 {
4016 msg = vat_json_array_add (msg_array);
4017 vat_json_init_object (msg);
4018 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4019 (u8 *) counter_type_to_str (i, 0));
4020 vat_json_object_add_int (msg, "is_combined", 0);
4021 counter_array = vat_json_object_add (msg, "data");
4022 vat_json_init_array (counter_array);
4023 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4024 {
4025 packets = vam->simple_interface_counters[i][j];
4026 vat_json_array_add_uint (counter_array, packets);
4027 }
4028 }
4029 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4030 {
4031 msg = vat_json_array_add (msg_array);
4032 vat_json_init_object (msg);
4033 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4034 (u8 *) counter_type_to_str (i, 1));
4035 vat_json_object_add_int (msg, "is_combined", 1);
4036 counter_array = vat_json_object_add (msg, "data");
4037 vat_json_init_array (counter_array);
4038 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4039 {
4040 c = vam->combined_interface_counters[i][j];
4041 counter = vat_json_array_add (counter_array);
4042 vat_json_init_object (counter);
4043 vat_json_object_add_uint (counter, "packets", c.packets);
4044 vat_json_object_add_uint (counter, "bytes", c.bytes);
4045 }
4046 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004047
Dave Barach72d72232016-08-04 10:15:08 -04004048 /* ip4 fib counters */
4049 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4050 vat_json_init_array (msg_array);
4051 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4052 {
4053 msg = vat_json_array_add (msg_array);
4054 vat_json_init_object (msg);
4055 vat_json_object_add_uint (msg, "vrf_id",
4056 vam->ip4_fib_counters_vrf_id_by_index[i]);
4057 counter_array = vat_json_object_add (msg, "c");
4058 vat_json_init_array (counter_array);
4059 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4060 {
4061 counter = vat_json_array_add (counter_array);
4062 vat_json_init_object (counter);
4063 c4 = &vam->ip4_fib_counters[i][j];
4064 vat_json_object_add_ip4 (counter, "address", c4->address);
4065 vat_json_object_add_uint (counter, "address_length",
4066 c4->address_length);
4067 vat_json_object_add_uint (counter, "packets", c4->packets);
4068 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4069 }
4070 }
4071
4072 /* ip6 fib counters */
4073 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4074 vat_json_init_array (msg_array);
4075 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4076 {
4077 msg = vat_json_array_add (msg_array);
4078 vat_json_init_object (msg);
4079 vat_json_object_add_uint (msg, "vrf_id",
4080 vam->ip6_fib_counters_vrf_id_by_index[i]);
4081 counter_array = vat_json_object_add (msg, "c");
4082 vat_json_init_array (counter_array);
4083 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4084 {
4085 counter = vat_json_array_add (counter_array);
4086 vat_json_init_object (counter);
4087 c6 = &vam->ip6_fib_counters[i][j];
4088 vat_json_object_add_ip6 (counter, "address", c6->address);
4089 vat_json_object_add_uint (counter, "address_length",
4090 c6->address_length);
4091 vat_json_object_add_uint (counter, "packets", c6->packets);
4092 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4093 }
4094 }
4095
4096 vat_json_print (vam->ofp, &node);
4097 vat_json_free (&node);
4098
4099 return 0;
4100}
4101
4102int
4103exec (vat_main_t * vam)
4104{
4105 api_main_t *am = &api_main;
4106 vl_api_cli_request_t *mp;
4107 f64 timeout;
4108 void *oldheap;
4109 u8 *cmd = 0;
4110 unformat_input_t *i = vam->input;
4111
4112 if (vec_len (i->buffer) == 0)
4113 return -1;
4114
4115 if (vam->exec_mode == 0 && unformat (i, "mode"))
4116 {
4117 vam->exec_mode = 1;
4118 return 0;
4119 }
4120 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4121 {
4122 vam->exec_mode = 0;
4123 return 0;
4124 }
4125
4126
4127 M (CLI_REQUEST, cli_request);
4128
4129 /*
4130 * Copy cmd into shared memory.
4131 * In order for the CLI command to work, it
4132 * must be a vector ending in \n, not a C-string ending
4133 * in \n\0.
4134 */
4135 pthread_mutex_lock (&am->vlib_rp->mutex);
4136 oldheap = svm_push_data_heap (am->vlib_rp);
4137
4138 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4139 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4140
4141 svm_pop_heap (oldheap);
4142 pthread_mutex_unlock (&am->vlib_rp->mutex);
4143
4144 mp->cmd_in_shmem = (u64) cmd;
4145 S;
4146 timeout = vat_time_now (vam) + 10.0;
4147
4148 while (vat_time_now (vam) < timeout)
4149 {
4150 if (vam->result_ready == 1)
4151 {
4152 u8 *free_me;
4153 if (vam->shmem_result != NULL)
4154 fformat (vam->ofp, "%s", vam->shmem_result);
4155 pthread_mutex_lock (&am->vlib_rp->mutex);
4156 oldheap = svm_push_data_heap (am->vlib_rp);
4157
4158 free_me = (u8 *) vam->shmem_result;
4159 vec_free (free_me);
4160
4161 svm_pop_heap (oldheap);
4162 pthread_mutex_unlock (&am->vlib_rp->mutex);
4163 return 0;
4164 }
4165 }
4166 return -99;
4167}
4168
Ole Troanc27213a2016-08-31 14:50:49 +02004169/*
4170 * Future replacement of exec() that passes CLI buffers directly in
4171 * the API messages instead of an additional shared memory area.
4172 */
4173static int
4174exec_inband (vat_main_t * vam)
4175{
4176 vl_api_cli_inband_t *mp;
4177 f64 timeout;
4178 unformat_input_t *i = vam->input;
4179
4180 if (vec_len (i->buffer) == 0)
4181 return -1;
4182
4183 if (vam->exec_mode == 0 && unformat (i, "mode"))
4184 {
4185 vam->exec_mode = 1;
4186 return 0;
4187 }
4188 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4189 {
4190 vam->exec_mode = 0;
4191 return 0;
4192 }
4193
4194 /*
4195 * In order for the CLI command to work, it
4196 * must be a vector ending in \n, not a C-string ending
4197 * in \n\0.
4198 */
4199 u32 len = vec_len (vam->input->buffer);
4200 M2 (CLI_INBAND, cli_inband, len);
4201 clib_memcpy (mp->cmd, vam->input->buffer, len);
4202 mp->length = htonl (len);
4203
4204 S;
4205 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4206}
4207
Dave Barach72d72232016-08-04 10:15:08 -04004208static int
4209api_create_loopback (vat_main_t * vam)
4210{
4211 unformat_input_t *i = vam->input;
4212 vl_api_create_loopback_t *mp;
4213 f64 timeout;
4214 u8 mac_address[6];
4215 u8 mac_set = 0;
4216
4217 memset (mac_address, 0, sizeof (mac_address));
4218
4219 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4220 {
4221 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4222 mac_set = 1;
4223 else
4224 break;
4225 }
4226
4227 /* Construct the API message */
4228 M (CREATE_LOOPBACK, create_loopback);
4229 if (mac_set)
4230 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4231
4232 S;
4233 W;
4234}
4235
4236static int
4237api_delete_loopback (vat_main_t * vam)
4238{
4239 unformat_input_t *i = vam->input;
4240 vl_api_delete_loopback_t *mp;
4241 f64 timeout;
4242 u32 sw_if_index = ~0;
4243
4244 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4245 {
4246 if (unformat (i, "sw_if_index %d", &sw_if_index))
4247 ;
4248 else
4249 break;
4250 }
4251
4252 if (sw_if_index == ~0)
4253 {
4254 errmsg ("missing sw_if_index\n");
4255 return -99;
4256 }
4257
4258 /* Construct the API message */
4259 M (DELETE_LOOPBACK, delete_loopback);
4260 mp->sw_if_index = ntohl (sw_if_index);
4261
4262 S;
4263 W;
4264}
4265
4266static int
4267api_want_stats (vat_main_t * vam)
4268{
4269 unformat_input_t *i = vam->input;
4270 vl_api_want_stats_t *mp;
4271 f64 timeout;
4272 int enable = -1;
4273
4274 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4275 {
4276 if (unformat (i, "enable"))
4277 enable = 1;
4278 else if (unformat (i, "disable"))
4279 enable = 0;
4280 else
4281 break;
4282 }
4283
4284 if (enable == -1)
4285 {
4286 errmsg ("missing enable|disable\n");
4287 return -99;
4288 }
4289
4290 M (WANT_STATS, want_stats);
4291 mp->enable_disable = enable;
4292
4293 S;
4294 W;
4295}
4296
4297static int
4298api_want_interface_events (vat_main_t * vam)
4299{
4300 unformat_input_t *i = vam->input;
4301 vl_api_want_interface_events_t *mp;
4302 f64 timeout;
4303 int enable = -1;
4304
4305 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4306 {
4307 if (unformat (i, "enable"))
4308 enable = 1;
4309 else if (unformat (i, "disable"))
4310 enable = 0;
4311 else
4312 break;
4313 }
4314
4315 if (enable == -1)
4316 {
4317 errmsg ("missing enable|disable\n");
4318 return -99;
4319 }
4320
4321 M (WANT_INTERFACE_EVENTS, want_interface_events);
4322 mp->enable_disable = enable;
4323
4324 vam->interface_event_display = enable;
4325
4326 S;
4327 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004328}
4329
4330
4331/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004332int
4333api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004334{
Dave Barach72d72232016-08-04 10:15:08 -04004335 vl_api_sw_interface_dump_t *mp;
4336 f64 timeout;
4337 hash_pair_t *p;
4338 name_sort_t *nses = 0, *ns;
4339 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004340
Dave Barach72d72232016-08-04 10:15:08 -04004341 /* Toss the old name table */
4342 /* *INDENT-OFF* */
4343 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4344 ({
4345 vec_add2 (nses, ns, 1);
4346 ns->name = (u8 *)(p->key);
4347 ns->value = (u32) p->value[0];
4348 }));
4349 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004350
Dave Barach72d72232016-08-04 10:15:08 -04004351 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004352
Dave Barach72d72232016-08-04 10:15:08 -04004353 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004354
Dave Barach72d72232016-08-04 10:15:08 -04004355 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004356
Dave Barach72d72232016-08-04 10:15:08 -04004357 vec_foreach (sub, vam->sw_if_subif_table)
4358 {
4359 vec_free (sub->interface_name);
4360 }
4361 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004362
Dave Barach72d72232016-08-04 10:15:08 -04004363 /* recreate the interface name hash table */
4364 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004365
Dave Barach72d72232016-08-04 10:15:08 -04004366 /* Get list of ethernets */
4367 M (SW_INTERFACE_DUMP, sw_interface_dump);
4368 mp->name_filter_valid = 1;
4369 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4370 S;
4371
4372 /* and local / loopback interfaces */
4373 M (SW_INTERFACE_DUMP, sw_interface_dump);
4374 mp->name_filter_valid = 1;
4375 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4376 S;
4377
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004378 /* and packet-generator interfaces */
4379 M (SW_INTERFACE_DUMP, sw_interface_dump);
4380 mp->name_filter_valid = 1;
4381 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4382 S;
Dave Barach72d72232016-08-04 10:15:08 -04004383
4384 /* and vxlan-gpe tunnel interfaces */
4385 M (SW_INTERFACE_DUMP, sw_interface_dump);
4386 mp->name_filter_valid = 1;
4387 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4388 sizeof (mp->name_filter) - 1);
4389 S;
4390
4391 /* and vxlan tunnel interfaces */
4392 M (SW_INTERFACE_DUMP, sw_interface_dump);
4393 mp->name_filter_valid = 1;
4394 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4395 S;
4396
4397 /* and host (af_packet) interfaces */
4398 M (SW_INTERFACE_DUMP, sw_interface_dump);
4399 mp->name_filter_valid = 1;
4400 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4401 S;
4402
4403 /* and l2tpv3 tunnel interfaces */
4404 M (SW_INTERFACE_DUMP, sw_interface_dump);
4405 mp->name_filter_valid = 1;
4406 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4407 sizeof (mp->name_filter) - 1);
4408 S;
4409
4410 /* and GRE tunnel interfaces */
4411 M (SW_INTERFACE_DUMP, sw_interface_dump);
4412 mp->name_filter_valid = 1;
4413 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4414 S;
4415
Florin Corasce982752016-09-06 13:36:11 +02004416 /* and LISP-GPE interfaces */
4417 M (SW_INTERFACE_DUMP, sw_interface_dump);
4418 mp->name_filter_valid = 1;
4419 strncpy ((char *) mp->name_filter, "lisp_gpe",
4420 sizeof (mp->name_filter) - 1);
4421 S;
4422
Matus Fabian8fce3e32016-09-06 23:19:43 -07004423 /* and IPSEC tunnel interfaces */
4424 M (SW_INTERFACE_DUMP, sw_interface_dump);
4425 mp->name_filter_valid = 1;
4426 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4427 S;
4428
Dave Barach72d72232016-08-04 10:15:08 -04004429 /* Use a control ping for synchronization */
4430 {
4431 vl_api_control_ping_t *mp;
4432 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004433 S;
Dave Barach72d72232016-08-04 10:15:08 -04004434 }
4435 W;
4436}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004437
Dave Barach72d72232016-08-04 10:15:08 -04004438static int
4439api_sw_interface_set_flags (vat_main_t * vam)
4440{
4441 unformat_input_t *i = vam->input;
4442 vl_api_sw_interface_set_flags_t *mp;
4443 f64 timeout;
4444 u32 sw_if_index;
4445 u8 sw_if_index_set = 0;
4446 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004447
Dave Barach72d72232016-08-04 10:15:08 -04004448 /* Parse args required to build the message */
4449 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004450 {
Dave Barach72d72232016-08-04 10:15:08 -04004451 if (unformat (i, "admin-up"))
4452 admin_up = 1;
4453 else if (unformat (i, "admin-down"))
4454 admin_up = 0;
4455 else if (unformat (i, "link-up"))
4456 link_up = 1;
4457 else if (unformat (i, "link-down"))
4458 link_up = 0;
4459 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4460 sw_if_index_set = 1;
4461 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4462 sw_if_index_set = 1;
4463 else
4464 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004465 }
4466
Dave Barach72d72232016-08-04 10:15:08 -04004467 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004468 {
Dave Barach72d72232016-08-04 10:15:08 -04004469 errmsg ("missing interface name or sw_if_index\n");
4470 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004471 }
4472
Dave Barach72d72232016-08-04 10:15:08 -04004473 /* Construct the API message */
4474 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4475 mp->sw_if_index = ntohl (sw_if_index);
4476 mp->admin_up_down = admin_up;
4477 mp->link_up_down = link_up;
4478
4479 /* send it... */
4480 S;
4481
4482 /* Wait for a reply, return the good/bad news... */
4483 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004484}
4485
Dave Barach72d72232016-08-04 10:15:08 -04004486static int
4487api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004488{
Dave Barach72d72232016-08-04 10:15:08 -04004489 unformat_input_t *i = vam->input;
4490 vl_api_sw_interface_clear_stats_t *mp;
4491 f64 timeout;
4492 u32 sw_if_index;
4493 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004494
Dave Barach72d72232016-08-04 10:15:08 -04004495 /* Parse args required to build the message */
4496 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4497 {
4498 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4499 sw_if_index_set = 1;
4500 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4501 sw_if_index_set = 1;
4502 else
4503 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004504 }
4505
Dave Barach72d72232016-08-04 10:15:08 -04004506 /* Construct the API message */
4507 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004508
Dave Barach72d72232016-08-04 10:15:08 -04004509 if (sw_if_index_set == 1)
4510 mp->sw_if_index = ntohl (sw_if_index);
4511 else
4512 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004513
Dave Barach72d72232016-08-04 10:15:08 -04004514 /* send it... */
4515 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004516
Dave Barach72d72232016-08-04 10:15:08 -04004517 /* Wait for a reply, return the good/bad news... */
4518 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004519}
4520
Dave Barach72d72232016-08-04 10:15:08 -04004521static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004522api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4523{
4524 unformat_input_t *i = vam->input;
4525 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4526 f64 timeout;
4527 u32 sw_if_index;
4528 u8 sw_if_index_set = 0;
4529 u32 subport;
4530 u8 subport_set = 0;
4531 u32 pipe;
4532 u8 pipe_set = 0;
4533 u32 profile;
4534 u8 profile_set = 0;
4535
4536 /* Parse args required to build the message */
4537 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4538 {
4539 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4540 sw_if_index_set = 1;
4541 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4542 sw_if_index_set = 1;
4543 else if (unformat (i, "subport %u", &subport))
4544 subport_set = 1;
4545 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4546 sw_if_index_set = 1;
4547 else if (unformat (i, "pipe %u", &pipe))
4548 pipe_set = 1;
4549 else if (unformat (i, "profile %u", &profile))
4550 profile_set = 1;
4551 else
4552 break;
4553 }
4554
4555 if (sw_if_index_set == 0)
4556 {
4557 errmsg ("missing interface name or sw_if_index\n");
4558 return -99;
4559 }
4560
4561 if (subport_set == 0)
4562 {
4563 errmsg ("missing subport \n");
4564 return -99;
4565 }
4566
4567 if (pipe_set == 0)
4568 {
4569 errmsg ("missing pipe\n");
4570 return -99;
4571 }
4572
4573 if (profile_set == 0)
4574 {
4575 errmsg ("missing profile\n");
4576 return -99;
4577 }
4578
4579 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4580
4581 mp->sw_if_index = ntohl (sw_if_index);
4582 mp->subport = ntohl (subport);
4583 mp->pipe = ntohl (pipe);
4584 mp->profile = ntohl (profile);
4585
4586
4587 S;
4588 W;
4589 /* NOTREACHED */
4590 return 0;
4591}
4592
4593static int
4594api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4595{
4596 unformat_input_t *i = vam->input;
4597 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4598 f64 timeout;
4599 u32 sw_if_index;
4600 u8 sw_if_index_set = 0;
4601 u32 subport;
4602 u8 subport_set = 0;
4603 u32 tb_rate = 1250000000; /* 10GbE */
4604 u32 tb_size = 1000000;
4605 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4606 u32 tc_period = 10;
4607
4608 /* Parse args required to build the message */
4609 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4610 {
4611 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4612 sw_if_index_set = 1;
4613 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4614 sw_if_index_set = 1;
4615 else if (unformat (i, "subport %u", &subport))
4616 subport_set = 1;
4617 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4618 sw_if_index_set = 1;
4619 else if (unformat (i, "rate %u", &tb_rate))
4620 {
4621 u32 tc_id;
4622
4623 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4624 tc_id++)
4625 tc_rate[tc_id] = tb_rate;
4626 }
4627 else if (unformat (i, "bktsize %u", &tb_size))
4628 ;
4629 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4630 ;
4631 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4632 ;
4633 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4634 ;
4635 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4636 ;
4637 else if (unformat (i, "period %u", &tc_period))
4638 ;
4639 else
4640 break;
4641 }
4642
4643 if (sw_if_index_set == 0)
4644 {
4645 errmsg ("missing interface name or sw_if_index\n");
4646 return -99;
4647 }
4648
4649 if (subport_set == 0)
4650 {
4651 errmsg ("missing subport \n");
4652 return -99;
4653 }
4654
4655 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4656
4657 mp->sw_if_index = ntohl (sw_if_index);
4658 mp->subport = ntohl (subport);
4659 mp->tb_rate = ntohl (tb_rate);
4660 mp->tb_size = ntohl (tb_size);
4661 mp->tc_rate[0] = ntohl (tc_rate[0]);
4662 mp->tc_rate[1] = ntohl (tc_rate[1]);
4663 mp->tc_rate[2] = ntohl (tc_rate[2]);
4664 mp->tc_rate[3] = ntohl (tc_rate[3]);
4665 mp->tc_period = ntohl (tc_period);
4666
4667 S;
4668 W;
4669 /* NOTREACHED */
4670 return 0;
4671}
4672
4673static int
4674api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4675{
4676 unformat_input_t *i = vam->input;
4677 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4678 f64 timeout;
4679 u32 sw_if_index;
4680 u8 sw_if_index_set = 0;
4681 u8 entry_set = 0;
4682 u8 tc_set = 0;
4683 u8 queue_set = 0;
4684 u32 entry, tc, queue;
4685
4686 /* Parse args required to build the message */
4687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4688 {
4689 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4690 sw_if_index_set = 1;
4691 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4692 sw_if_index_set = 1;
4693 else if (unformat (i, "entry %d", &entry))
4694 entry_set = 1;
4695 else if (unformat (i, "tc %d", &tc))
4696 tc_set = 1;
4697 else if (unformat (i, "queue %d", &queue))
4698 queue_set = 1;
4699 else
4700 break;
4701 }
4702
4703 if (sw_if_index_set == 0)
4704 {
4705 errmsg ("missing interface name or sw_if_index\n");
4706 return -99;
4707 }
4708
4709 if (entry_set == 0)
4710 {
4711 errmsg ("missing entry \n");
4712 return -99;
4713 }
4714
4715 if (tc_set == 0)
4716 {
4717 errmsg ("missing traffic class \n");
4718 return -99;
4719 }
4720
4721 if (queue_set == 0)
4722 {
4723 errmsg ("missing queue \n");
4724 return -99;
4725 }
4726
4727 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4728
4729 mp->sw_if_index = ntohl (sw_if_index);
4730 mp->entry = ntohl (entry);
4731 mp->tc = ntohl (tc);
4732 mp->queue = ntohl (queue);
4733
4734 S;
4735 W;
4736 /* NOTREACHED */
4737 return 0;
4738}
4739
4740static int
Dave Barach72d72232016-08-04 10:15:08 -04004741api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004742{
Dave Barach72d72232016-08-04 10:15:08 -04004743 unformat_input_t *i = vam->input;
4744 vl_api_sw_interface_add_del_address_t *mp;
4745 f64 timeout;
4746 u32 sw_if_index;
4747 u8 sw_if_index_set = 0;
4748 u8 is_add = 1, del_all = 0;
4749 u32 address_length = 0;
4750 u8 v4_address_set = 0;
4751 u8 v6_address_set = 0;
4752 ip4_address_t v4address;
4753 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004754
Dave Barach72d72232016-08-04 10:15:08 -04004755 /* Parse args required to build the message */
4756 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4757 {
4758 if (unformat (i, "del-all"))
4759 del_all = 1;
4760 else if (unformat (i, "del"))
4761 is_add = 0;
4762 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4763 sw_if_index_set = 1;
4764 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4765 sw_if_index_set = 1;
4766 else if (unformat (i, "%U/%d",
4767 unformat_ip4_address, &v4address, &address_length))
4768 v4_address_set = 1;
4769 else if (unformat (i, "%U/%d",
4770 unformat_ip6_address, &v6address, &address_length))
4771 v6_address_set = 1;
4772 else
4773 break;
4774 }
4775
4776 if (sw_if_index_set == 0)
4777 {
4778 errmsg ("missing interface name or sw_if_index\n");
4779 return -99;
4780 }
4781 if (v4_address_set && v6_address_set)
4782 {
4783 errmsg ("both v4 and v6 addresses set\n");
4784 return -99;
4785 }
4786 if (!v4_address_set && !v6_address_set && !del_all)
4787 {
4788 errmsg ("no addresses set\n");
4789 return -99;
4790 }
4791
4792 /* Construct the API message */
4793 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4794
4795 mp->sw_if_index = ntohl (sw_if_index);
4796 mp->is_add = is_add;
4797 mp->del_all = del_all;
4798 if (v6_address_set)
4799 {
4800 mp->is_ipv6 = 1;
4801 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4802 }
4803 else
4804 {
4805 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4806 }
4807 mp->address_length = address_length;
4808
4809 /* send it... */
4810 S;
4811
4812 /* Wait for a reply, return good/bad news */
4813 W;
4814}
4815
4816static int
4817api_sw_interface_set_table (vat_main_t * vam)
4818{
4819 unformat_input_t *i = vam->input;
4820 vl_api_sw_interface_set_table_t *mp;
4821 f64 timeout;
4822 u32 sw_if_index, vrf_id = 0;
4823 u8 sw_if_index_set = 0;
4824 u8 is_ipv6 = 0;
4825
4826 /* Parse args required to build the message */
4827 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4828 {
4829 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4830 sw_if_index_set = 1;
4831 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4832 sw_if_index_set = 1;
4833 else if (unformat (i, "vrf %d", &vrf_id))
4834 ;
4835 else if (unformat (i, "ipv6"))
4836 is_ipv6 = 1;
4837 else
4838 break;
4839 }
4840
4841 if (sw_if_index_set == 0)
4842 {
4843 errmsg ("missing interface name or sw_if_index\n");
4844 return -99;
4845 }
4846
4847 /* Construct the API message */
4848 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4849
4850 mp->sw_if_index = ntohl (sw_if_index);
4851 mp->is_ipv6 = is_ipv6;
4852 mp->vrf_id = ntohl (vrf_id);
4853
4854 /* send it... */
4855 S;
4856
4857 /* Wait for a reply... */
4858 W;
4859}
4860
4861static int
4862api_sw_interface_set_vpath (vat_main_t * vam)
4863{
4864 unformat_input_t *i = vam->input;
4865 vl_api_sw_interface_set_vpath_t *mp;
4866 f64 timeout;
4867 u32 sw_if_index = 0;
4868 u8 sw_if_index_set = 0;
4869 u8 is_enable = 0;
4870
4871 /* Parse args required to build the message */
4872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4873 {
4874 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4875 sw_if_index_set = 1;
4876 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4877 sw_if_index_set = 1;
4878 else if (unformat (i, "enable"))
4879 is_enable = 1;
4880 else if (unformat (i, "disable"))
4881 is_enable = 0;
4882 else
4883 break;
4884 }
4885
4886 if (sw_if_index_set == 0)
4887 {
4888 errmsg ("missing interface name or sw_if_index\n");
4889 return -99;
4890 }
4891
4892 /* Construct the API message */
4893 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
4894
4895 mp->sw_if_index = ntohl (sw_if_index);
4896 mp->enable = is_enable;
4897
4898 /* send it... */
4899 S;
4900
4901 /* Wait for a reply... */
4902 W;
4903}
4904
4905static int
4906api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4907{
4908 unformat_input_t *i = vam->input;
4909 vl_api_sw_interface_set_l2_xconnect_t *mp;
4910 f64 timeout;
4911 u32 rx_sw_if_index;
4912 u8 rx_sw_if_index_set = 0;
4913 u32 tx_sw_if_index;
4914 u8 tx_sw_if_index_set = 0;
4915 u8 enable = 1;
4916
4917 /* Parse args required to build the message */
4918 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4919 {
4920 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4921 rx_sw_if_index_set = 1;
4922 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4923 tx_sw_if_index_set = 1;
4924 else if (unformat (i, "rx"))
4925 {
4926 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4927 {
4928 if (unformat (i, "%U", unformat_sw_if_index, vam,
4929 &rx_sw_if_index))
4930 rx_sw_if_index_set = 1;
4931 }
4932 else
Dave Barach41da02d2016-07-11 16:48:42 -07004933 break;
Dave Barach41da02d2016-07-11 16:48:42 -07004934 }
Dave Barach72d72232016-08-04 10:15:08 -04004935 else if (unformat (i, "tx"))
4936 {
4937 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4938 {
4939 if (unformat (i, "%U", unformat_sw_if_index, vam,
4940 &tx_sw_if_index))
4941 tx_sw_if_index_set = 1;
4942 }
4943 else
4944 break;
4945 }
4946 else if (unformat (i, "enable"))
4947 enable = 1;
4948 else if (unformat (i, "disable"))
4949 enable = 0;
4950 else
4951 break;
Dave Barach41da02d2016-07-11 16:48:42 -07004952 }
4953
Dave Barach72d72232016-08-04 10:15:08 -04004954 if (rx_sw_if_index_set == 0)
4955 {
4956 errmsg ("missing rx interface name or rx_sw_if_index\n");
4957 return -99;
4958 }
Dave Barach41da02d2016-07-11 16:48:42 -07004959
Dave Barach72d72232016-08-04 10:15:08 -04004960 if (enable && (tx_sw_if_index_set == 0))
4961 {
4962 errmsg ("missing tx interface name or tx_sw_if_index\n");
4963 return -99;
4964 }
Dave Barach41da02d2016-07-11 16:48:42 -07004965
Dave Barach72d72232016-08-04 10:15:08 -04004966 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07004967
Dave Barach72d72232016-08-04 10:15:08 -04004968 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4969 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4970 mp->enable = enable;
4971
4972 S;
4973 W;
4974 /* NOTREACHED */
4975 return 0;
4976}
4977
4978static int
4979api_sw_interface_set_l2_bridge (vat_main_t * vam)
4980{
4981 unformat_input_t *i = vam->input;
4982 vl_api_sw_interface_set_l2_bridge_t *mp;
4983 f64 timeout;
4984 u32 rx_sw_if_index;
4985 u8 rx_sw_if_index_set = 0;
4986 u32 bd_id;
4987 u8 bd_id_set = 0;
4988 u8 bvi = 0;
4989 u32 shg = 0;
4990 u8 enable = 1;
4991
4992 /* Parse args required to build the message */
4993 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4994 {
4995 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4996 rx_sw_if_index_set = 1;
4997 else if (unformat (i, "bd_id %d", &bd_id))
4998 bd_id_set = 1;
4999 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
5000 rx_sw_if_index_set = 1;
5001 else if (unformat (i, "shg %d", &shg))
5002 ;
5003 else if (unformat (i, "bvi"))
5004 bvi = 1;
5005 else if (unformat (i, "enable"))
5006 enable = 1;
5007 else if (unformat (i, "disable"))
5008 enable = 0;
5009 else
5010 break;
5011 }
5012
5013 if (rx_sw_if_index_set == 0)
5014 {
5015 errmsg ("missing rx interface name or sw_if_index\n");
5016 return -99;
5017 }
5018
5019 if (enable && (bd_id_set == 0))
5020 {
5021 errmsg ("missing bridge domain\n");
5022 return -99;
5023 }
5024
5025 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5026
5027 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5028 mp->bd_id = ntohl (bd_id);
5029 mp->shg = (u8) shg;
5030 mp->bvi = bvi;
5031 mp->enable = enable;
5032
5033 S;
5034 W;
5035 /* NOTREACHED */
5036 return 0;
5037}
5038
5039static int
5040api_bridge_domain_dump (vat_main_t * vam)
5041{
5042 unformat_input_t *i = vam->input;
5043 vl_api_bridge_domain_dump_t *mp;
5044 f64 timeout;
5045 u32 bd_id = ~0;
5046
5047 /* Parse args required to build the message */
5048 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5049 {
5050 if (unformat (i, "bd_id %d", &bd_id))
5051 ;
5052 else
5053 break;
5054 }
5055
5056 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5057 mp->bd_id = ntohl (bd_id);
5058 S;
5059
5060 /* Use a control ping for synchronization */
5061 {
5062 vl_api_control_ping_t *mp;
5063 M (CONTROL_PING, control_ping);
5064 S;
5065 }
5066
5067 W;
5068 /* NOTREACHED */
5069 return 0;
5070}
5071
5072static int
5073api_bridge_domain_add_del (vat_main_t * vam)
5074{
5075 unformat_input_t *i = vam->input;
5076 vl_api_bridge_domain_add_del_t *mp;
5077 f64 timeout;
5078 u32 bd_id = ~0;
5079 u8 is_add = 1;
5080 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5081
5082 /* Parse args required to build the message */
5083 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5084 {
5085 if (unformat (i, "bd_id %d", &bd_id))
5086 ;
5087 else if (unformat (i, "flood %d", &flood))
5088 ;
5089 else if (unformat (i, "uu-flood %d", &uu_flood))
5090 ;
5091 else if (unformat (i, "forward %d", &forward))
5092 ;
5093 else if (unformat (i, "learn %d", &learn))
5094 ;
5095 else if (unformat (i, "arp-term %d", &arp_term))
5096 ;
5097 else if (unformat (i, "del"))
5098 {
5099 is_add = 0;
5100 flood = uu_flood = forward = learn = 0;
5101 }
5102 else
5103 break;
5104 }
5105
5106 if (bd_id == ~0)
5107 {
5108 errmsg ("missing bridge domain\n");
5109 return -99;
5110 }
5111
5112 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5113
5114 mp->bd_id = ntohl (bd_id);
5115 mp->flood = flood;
5116 mp->uu_flood = uu_flood;
5117 mp->forward = forward;
5118 mp->learn = learn;
5119 mp->arp_term = arp_term;
5120 mp->is_add = is_add;
5121
5122 S;
5123 W;
5124 /* NOTREACHED */
5125 return 0;
5126}
5127
5128static int
5129api_l2fib_add_del (vat_main_t * vam)
5130{
5131 unformat_input_t *i = vam->input;
5132 vl_api_l2fib_add_del_t *mp;
5133 f64 timeout;
5134 u64 mac = 0;
5135 u8 mac_set = 0;
5136 u32 bd_id;
5137 u8 bd_id_set = 0;
5138 u32 sw_if_index;
5139 u8 sw_if_index_set = 0;
5140 u8 is_add = 1;
5141 u8 static_mac = 0;
5142 u8 filter_mac = 0;
5143 u8 bvi_mac = 0;
5144 int count = 1;
5145 f64 before = 0;
5146 int j;
5147
5148 /* Parse args required to build the message */
5149 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5150 {
5151 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5152 mac_set = 1;
5153 else if (unformat (i, "bd_id %d", &bd_id))
5154 bd_id_set = 1;
5155 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5156 sw_if_index_set = 1;
5157 else if (unformat (i, "sw_if"))
5158 {
5159 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5160 {
5161 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5162 sw_if_index_set = 1;
5163 }
5164 else
5165 break;
5166 }
5167 else if (unformat (i, "static"))
5168 static_mac = 1;
5169 else if (unformat (i, "filter"))
5170 {
5171 filter_mac = 1;
5172 static_mac = 1;
5173 }
5174 else if (unformat (i, "bvi"))
5175 {
5176 bvi_mac = 1;
5177 static_mac = 1;
5178 }
5179 else if (unformat (i, "del"))
5180 is_add = 0;
5181 else if (unformat (i, "count %d", &count))
5182 ;
5183 else
5184 break;
5185 }
5186
5187 if (mac_set == 0)
5188 {
5189 errmsg ("missing mac address\n");
5190 return -99;
5191 }
5192
5193 if (bd_id_set == 0)
5194 {
5195 errmsg ("missing bridge domain\n");
5196 return -99;
5197 }
5198
5199 if (is_add && (sw_if_index_set == 0))
5200 {
5201 errmsg ("missing interface name or sw_if_index\n");
5202 return -99;
5203 }
5204
5205 if (count > 1)
5206 {
5207 /* Turn on async mode */
5208 vam->async_mode = 1;
5209 vam->async_errors = 0;
5210 before = vat_time_now (vam);
5211 }
5212
5213 for (j = 0; j < count; j++)
5214 {
5215 M (L2FIB_ADD_DEL, l2fib_add_del);
5216
5217 mp->mac = mac;
5218 mp->bd_id = ntohl (bd_id);
5219 mp->is_add = is_add;
5220
5221 if (is_add)
5222 {
5223 mp->sw_if_index = ntohl (sw_if_index);
5224 mp->static_mac = static_mac;
5225 mp->filter_mac = filter_mac;
5226 mp->bvi_mac = bvi_mac;
5227 }
5228 increment_mac_address (&mac);
5229 /* send it... */
5230 S;
5231 }
5232
5233 if (count > 1)
5234 {
5235 vl_api_control_ping_t *mp;
5236 f64 after;
5237
5238 /* Shut off async mode */
5239 vam->async_mode = 0;
5240
5241 M (CONTROL_PING, control_ping);
5242 S;
5243
5244 timeout = vat_time_now (vam) + 1.0;
5245 while (vat_time_now (vam) < timeout)
5246 if (vam->result_ready == 1)
5247 goto out;
5248 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005249
5250 out:
Dave Barach72d72232016-08-04 10:15:08 -04005251 if (vam->retval == -99)
5252 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005253
Dave Barach72d72232016-08-04 10:15:08 -04005254 if (vam->async_errors > 0)
5255 {
5256 errmsg ("%d asynchronous errors\n", vam->async_errors);
5257 vam->retval = -98;
5258 }
5259 vam->async_errors = 0;
5260 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005261
Dave Barach72d72232016-08-04 10:15:08 -04005262 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5263 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005264 }
Dave Barach72d72232016-08-04 10:15:08 -04005265 else
5266 {
5267 /* Wait for a reply... */
5268 W;
5269 }
5270 /* Return the good/bad news */
5271 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005272}
5273
Dave Barach72d72232016-08-04 10:15:08 -04005274static int
5275api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005276{
Dave Barach72d72232016-08-04 10:15:08 -04005277 unformat_input_t *i = vam->input;
5278 vl_api_l2_flags_t *mp;
5279 f64 timeout;
5280 u32 sw_if_index;
5281 u32 feature_bitmap = 0;
5282 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005283
Dave Barach72d72232016-08-04 10:15:08 -04005284 /* Parse args required to build the message */
5285 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5286 {
5287 if (unformat (i, "sw_if_index %d", &sw_if_index))
5288 sw_if_index_set = 1;
5289 else if (unformat (i, "sw_if"))
5290 {
5291 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5292 {
5293 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5294 sw_if_index_set = 1;
5295 }
5296 else
5297 break;
5298 }
5299 else if (unformat (i, "learn"))
5300 feature_bitmap |= L2INPUT_FEAT_LEARN;
5301 else if (unformat (i, "forward"))
5302 feature_bitmap |= L2INPUT_FEAT_FWD;
5303 else if (unformat (i, "flood"))
5304 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5305 else if (unformat (i, "uu-flood"))
5306 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5307 else
5308 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005309 }
5310
Dave Barach72d72232016-08-04 10:15:08 -04005311 if (sw_if_index_set == 0)
5312 {
5313 errmsg ("missing interface name or sw_if_index\n");
5314 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005315 }
5316
Dave Barach72d72232016-08-04 10:15:08 -04005317 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005318
Dave Barach72d72232016-08-04 10:15:08 -04005319 mp->sw_if_index = ntohl (sw_if_index);
5320 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005321
Dave Barach72d72232016-08-04 10:15:08 -04005322 S;
5323 W;
5324 /* NOTREACHED */
5325 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005326}
5327
Dave Barach72d72232016-08-04 10:15:08 -04005328static int
5329api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005330{
Dave Barach72d72232016-08-04 10:15:08 -04005331 unformat_input_t *i = vam->input;
5332 vl_api_bridge_flags_t *mp;
5333 f64 timeout;
5334 u32 bd_id;
5335 u8 bd_id_set = 0;
5336 u8 is_set = 1;
5337 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005338
Dave Barach72d72232016-08-04 10:15:08 -04005339 /* Parse args required to build the message */
5340 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5341 {
5342 if (unformat (i, "bd_id %d", &bd_id))
5343 bd_id_set = 1;
5344 else if (unformat (i, "learn"))
5345 flags |= L2_LEARN;
5346 else if (unformat (i, "forward"))
5347 flags |= L2_FWD;
5348 else if (unformat (i, "flood"))
5349 flags |= L2_FLOOD;
5350 else if (unformat (i, "uu-flood"))
5351 flags |= L2_UU_FLOOD;
5352 else if (unformat (i, "arp-term"))
5353 flags |= L2_ARP_TERM;
5354 else if (unformat (i, "off"))
5355 is_set = 0;
5356 else if (unformat (i, "disable"))
5357 is_set = 0;
5358 else
5359 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005360 }
5361
Dave Barach72d72232016-08-04 10:15:08 -04005362 if (bd_id_set == 0)
5363 {
5364 errmsg ("missing bridge domain\n");
5365 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005366 }
5367
Dave Barach72d72232016-08-04 10:15:08 -04005368 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005369
Dave Barach72d72232016-08-04 10:15:08 -04005370 mp->bd_id = ntohl (bd_id);
5371 mp->feature_bitmap = ntohl (flags);
5372 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005373
Dave Barach72d72232016-08-04 10:15:08 -04005374 S;
5375 W;
5376 /* NOTREACHED */
5377 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005378}
5379
Dave Barach72d72232016-08-04 10:15:08 -04005380static int
5381api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005382{
Dave Barach72d72232016-08-04 10:15:08 -04005383 unformat_input_t *i = vam->input;
5384 vl_api_bd_ip_mac_add_del_t *mp;
5385 f64 timeout;
5386 u32 bd_id;
5387 u8 is_ipv6 = 0;
5388 u8 is_add = 1;
5389 u8 bd_id_set = 0;
5390 u8 ip_set = 0;
5391 u8 mac_set = 0;
5392 ip4_address_t v4addr;
5393 ip6_address_t v6addr;
5394 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005395
Ed Warnickecb9cada2015-12-08 15:45:58 -07005396
Dave Barach72d72232016-08-04 10:15:08 -04005397 /* Parse args required to build the message */
5398 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5399 {
5400 if (unformat (i, "bd_id %d", &bd_id))
5401 {
5402 bd_id_set++;
5403 }
5404 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5405 {
5406 ip_set++;
5407 }
5408 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5409 {
5410 ip_set++;
5411 is_ipv6++;
5412 }
5413 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5414 {
5415 mac_set++;
5416 }
5417 else if (unformat (i, "del"))
5418 is_add = 0;
5419 else
5420 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005421 }
5422
Dave Barach72d72232016-08-04 10:15:08 -04005423 if (bd_id_set == 0)
5424 {
5425 errmsg ("missing bridge domain\n");
5426 return -99;
5427 }
5428 else if (ip_set == 0)
5429 {
5430 errmsg ("missing IP address\n");
5431 return -99;
5432 }
5433 else if (mac_set == 0)
5434 {
5435 errmsg ("missing MAC address\n");
5436 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005437 }
5438
Dave Barach72d72232016-08-04 10:15:08 -04005439 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005440
Dave Barach72d72232016-08-04 10:15:08 -04005441 mp->bd_id = ntohl (bd_id);
5442 mp->is_ipv6 = is_ipv6;
5443 mp->is_add = is_add;
5444 if (is_ipv6)
5445 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5446 else
5447 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5448 clib_memcpy (mp->mac_address, macaddr, 6);
5449 S;
5450 W;
5451 /* NOTREACHED */
5452 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005453}
5454
Dave Barach72d72232016-08-04 10:15:08 -04005455static int
5456api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005457{
Dave Barach72d72232016-08-04 10:15:08 -04005458 unformat_input_t *i = vam->input;
5459 vl_api_tap_connect_t *mp;
5460 f64 timeout;
5461 u8 mac_address[6];
5462 u8 random_mac = 1;
5463 u8 name_set = 0;
5464 u8 *tap_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005465
Dave Barach72d72232016-08-04 10:15:08 -04005466 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005467
Dave Barach72d72232016-08-04 10:15:08 -04005468 /* Parse args required to build the message */
5469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5470 {
5471 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5472 {
5473 random_mac = 0;
5474 }
5475 else if (unformat (i, "random-mac"))
5476 random_mac = 1;
5477 else if (unformat (i, "tapname %s", &tap_name))
5478 name_set = 1;
5479 else
5480 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005481 }
5482
Dave Barach72d72232016-08-04 10:15:08 -04005483 if (name_set == 0)
5484 {
5485 errmsg ("missing tap name\n");
5486 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005487 }
Dave Barach72d72232016-08-04 10:15:08 -04005488 if (vec_len (tap_name) > 63)
5489 {
5490 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005491 }
Dave Barach72d72232016-08-04 10:15:08 -04005492 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005493
Dave Barach72d72232016-08-04 10:15:08 -04005494 /* Construct the API message */
5495 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005496
Dave Barach72d72232016-08-04 10:15:08 -04005497 mp->use_random_mac = random_mac;
5498 clib_memcpy (mp->mac_address, mac_address, 6);
5499 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5500 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005501
Dave Barach72d72232016-08-04 10:15:08 -04005502 /* send it... */
5503 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005504
Dave Barach72d72232016-08-04 10:15:08 -04005505 /* Wait for a reply... */
5506 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005507}
5508
Dave Barach72d72232016-08-04 10:15:08 -04005509static int
5510api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005511{
Dave Barach72d72232016-08-04 10:15:08 -04005512 unformat_input_t *i = vam->input;
5513 vl_api_tap_modify_t *mp;
5514 f64 timeout;
5515 u8 mac_address[6];
5516 u8 random_mac = 1;
5517 u8 name_set = 0;
5518 u8 *tap_name;
5519 u32 sw_if_index = ~0;
5520 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005521
Dave Barach72d72232016-08-04 10:15:08 -04005522 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005523
Dave Barach72d72232016-08-04 10:15:08 -04005524 /* Parse args required to build the message */
5525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5526 {
5527 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5528 sw_if_index_set = 1;
5529 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5530 sw_if_index_set = 1;
5531 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5532 {
5533 random_mac = 0;
5534 }
5535 else if (unformat (i, "random-mac"))
5536 random_mac = 1;
5537 else if (unformat (i, "tapname %s", &tap_name))
5538 name_set = 1;
5539 else
5540 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005541 }
5542
Dave Barach72d72232016-08-04 10:15:08 -04005543 if (sw_if_index_set == 0)
5544 {
5545 errmsg ("missing vpp interface name");
5546 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005547 }
Dave Barach72d72232016-08-04 10:15:08 -04005548 if (name_set == 0)
5549 {
5550 errmsg ("missing tap name\n");
5551 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005552 }
Dave Barach72d72232016-08-04 10:15:08 -04005553 if (vec_len (tap_name) > 63)
5554 {
5555 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005556 }
Dave Barach72d72232016-08-04 10:15:08 -04005557 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005558
Dave Barach72d72232016-08-04 10:15:08 -04005559 /* Construct the API message */
5560 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005561
Dave Barach72d72232016-08-04 10:15:08 -04005562 mp->use_random_mac = random_mac;
5563 mp->sw_if_index = ntohl (sw_if_index);
5564 clib_memcpy (mp->mac_address, mac_address, 6);
5565 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5566 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005567
Dave Barach72d72232016-08-04 10:15:08 -04005568 /* send it... */
5569 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005570
Dave Barach72d72232016-08-04 10:15:08 -04005571 /* Wait for a reply... */
5572 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005573}
5574
Dave Barach72d72232016-08-04 10:15:08 -04005575static int
5576api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005577{
Dave Barach72d72232016-08-04 10:15:08 -04005578 unformat_input_t *i = vam->input;
5579 vl_api_tap_delete_t *mp;
5580 f64 timeout;
5581 u32 sw_if_index = ~0;
5582 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005583
Dave Barach72d72232016-08-04 10:15:08 -04005584 /* Parse args required to build the message */
5585 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5586 {
5587 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5588 sw_if_index_set = 1;
5589 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5590 sw_if_index_set = 1;
5591 else
5592 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005593 }
5594
Dave Barach72d72232016-08-04 10:15:08 -04005595 if (sw_if_index_set == 0)
5596 {
5597 errmsg ("missing vpp interface name");
5598 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005599 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005600
Dave Barach72d72232016-08-04 10:15:08 -04005601 /* Construct the API message */
5602 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005603
Dave Barach72d72232016-08-04 10:15:08 -04005604 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005605
Dave Barach72d72232016-08-04 10:15:08 -04005606 /* send it... */
5607 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005608
Dave Barach72d72232016-08-04 10:15:08 -04005609 /* Wait for a reply... */
5610 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005611}
5612
Dave Barach72d72232016-08-04 10:15:08 -04005613static int
5614api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005615{
Dave Barach72d72232016-08-04 10:15:08 -04005616 unformat_input_t *i = vam->input;
5617 vl_api_ip_add_del_route_t *mp;
5618 f64 timeout;
5619 u32 sw_if_index = ~0, vrf_id = 0;
5620 u8 sw_if_index_set = 0;
5621 u8 is_ipv6 = 0;
5622 u8 is_local = 0, is_drop = 0;
5623 u8 create_vrf_if_needed = 0;
5624 u8 is_add = 1;
5625 u8 next_hop_weight = 1;
5626 u8 not_last = 0;
5627 u8 is_multipath = 0;
5628 u8 address_set = 0;
5629 u8 address_length_set = 0;
5630 u32 lookup_in_vrf = 0;
5631 u32 resolve_attempts = 0;
5632 u32 dst_address_length = 0;
5633 u8 next_hop_set = 0;
5634 ip4_address_t v4_dst_address, v4_next_hop_address;
5635 ip6_address_t v6_dst_address, v6_next_hop_address;
5636 int count = 1;
5637 int j;
5638 f64 before = 0;
5639 u32 random_add_del = 0;
5640 u32 *random_vector = 0;
5641 uword *random_hash;
5642 u32 random_seed = 0xdeaddabe;
5643 u32 classify_table_index = ~0;
5644 u8 is_classify = 0;
Neale Ranns33a7dd52016-10-07 15:14:33 +01005645 u8 resolve_host = 0, resolve_attached = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005646
Dave Barach72d72232016-08-04 10:15:08 -04005647 /* Parse args required to build the message */
5648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5649 {
5650 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5651 sw_if_index_set = 1;
5652 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5653 sw_if_index_set = 1;
5654 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
5655 {
5656 address_set = 1;
5657 is_ipv6 = 0;
5658 }
5659 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
5660 {
5661 address_set = 1;
5662 is_ipv6 = 1;
5663 }
5664 else if (unformat (i, "/%d", &dst_address_length))
5665 {
5666 address_length_set = 1;
5667 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005668
Dave Barach72d72232016-08-04 10:15:08 -04005669 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
5670 &v4_next_hop_address))
5671 {
5672 next_hop_set = 1;
5673 }
5674 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
5675 &v6_next_hop_address))
5676 {
5677 next_hop_set = 1;
5678 }
5679 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5680 ;
5681 else if (unformat (i, "weight %d", &next_hop_weight))
5682 ;
5683 else if (unformat (i, "drop"))
5684 {
5685 is_drop = 1;
5686 }
5687 else if (unformat (i, "local"))
5688 {
5689 is_local = 1;
5690 }
5691 else if (unformat (i, "classify %d", &classify_table_index))
5692 {
5693 is_classify = 1;
5694 }
5695 else if (unformat (i, "del"))
5696 is_add = 0;
5697 else if (unformat (i, "add"))
5698 is_add = 1;
5699 else if (unformat (i, "not-last"))
5700 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005701 else if (unformat (i, "resolve-via-host"))
5702 resolve_host = 1;
5703 else if (unformat (i, "resolve-via-attached"))
5704 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005705 else if (unformat (i, "multipath"))
5706 is_multipath = 1;
5707 else if (unformat (i, "vrf %d", &vrf_id))
5708 ;
5709 else if (unformat (i, "create-vrf"))
5710 create_vrf_if_needed = 1;
5711 else if (unformat (i, "count %d", &count))
5712 ;
5713 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
5714 ;
5715 else if (unformat (i, "random"))
5716 random_add_del = 1;
5717 else if (unformat (i, "seed %d", &random_seed))
5718 ;
5719 else
5720 {
5721 clib_warning ("parse error '%U'", format_unformat_error, i);
5722 return -99;
5723 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005724 }
5725
Dave Barach72d72232016-08-04 10:15:08 -04005726 if (resolve_attempts > 0 && sw_if_index_set == 0)
5727 {
5728 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
5729 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005730 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005731
Dave Barach72d72232016-08-04 10:15:08 -04005732 if (!next_hop_set && !is_drop && !is_local && !is_classify)
5733 {
5734 errmsg ("next hop / local / drop / classify not set\n");
5735 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005736 }
5737
Dave Barach72d72232016-08-04 10:15:08 -04005738 if (address_set == 0)
5739 {
5740 errmsg ("missing addresses\n");
5741 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005742 }
5743
Dave Barach72d72232016-08-04 10:15:08 -04005744 if (address_length_set == 0)
5745 {
5746 errmsg ("missing address length\n");
5747 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005748 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005749
Dave Barach72d72232016-08-04 10:15:08 -04005750 /* Generate a pile of unique, random routes */
5751 if (random_add_del)
5752 {
5753 u32 this_random_address;
5754 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005755
Dave Barach72d72232016-08-04 10:15:08 -04005756 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
5757 for (j = 0; j <= count; j++)
5758 {
5759 do
5760 {
5761 this_random_address = random_u32 (&random_seed);
5762 this_random_address =
5763 clib_host_to_net_u32 (this_random_address);
5764 }
5765 while (hash_get (random_hash, this_random_address));
5766 vec_add1 (random_vector, this_random_address);
5767 hash_set (random_hash, this_random_address, 1);
5768 }
5769 hash_free (random_hash);
5770 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07005771 }
5772
Dave Barach72d72232016-08-04 10:15:08 -04005773 if (count > 1)
5774 {
5775 /* Turn on async mode */
5776 vam->async_mode = 1;
5777 vam->async_errors = 0;
5778 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005779 }
5780
Dave Barach72d72232016-08-04 10:15:08 -04005781 for (j = 0; j < count; j++)
5782 {
5783 /* Construct the API message */
5784 M (IP_ADD_DEL_ROUTE, ip_add_del_route);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005785
Dave Barach72d72232016-08-04 10:15:08 -04005786 mp->next_hop_sw_if_index = ntohl (sw_if_index);
5787 mp->vrf_id = ntohl (vrf_id);
5788 if (resolve_attempts > 0)
5789 {
5790 mp->resolve_attempts = ntohl (resolve_attempts);
5791 mp->resolve_if_needed = 1;
5792 }
5793 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005794
Dave Barach72d72232016-08-04 10:15:08 -04005795 mp->is_add = is_add;
5796 mp->is_drop = is_drop;
5797 mp->is_ipv6 = is_ipv6;
5798 mp->is_local = is_local;
5799 mp->is_classify = is_classify;
5800 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005801 mp->is_resolve_host = resolve_host;
5802 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04005803 mp->not_last = not_last;
5804 mp->next_hop_weight = next_hop_weight;
5805 mp->dst_address_length = dst_address_length;
5806 mp->lookup_in_vrf = ntohl (lookup_in_vrf);
5807 mp->classify_table_index = ntohl (classify_table_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005808
Dave Barach72d72232016-08-04 10:15:08 -04005809 if (is_ipv6)
5810 {
5811 clib_memcpy (mp->dst_address, &v6_dst_address,
5812 sizeof (v6_dst_address));
5813 if (next_hop_set)
5814 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
5815 sizeof (v6_next_hop_address));
5816 increment_v6_address (&v6_dst_address);
5817 }
5818 else
5819 {
5820 clib_memcpy (mp->dst_address, &v4_dst_address,
5821 sizeof (v4_dst_address));
5822 if (next_hop_set)
5823 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
5824 sizeof (v4_next_hop_address));
5825 if (random_add_del)
5826 v4_dst_address.as_u32 = random_vector[j + 1];
5827 else
5828 increment_v4_address (&v4_dst_address);
5829 }
5830 /* send it... */
5831 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005832 }
5833
Dave Barach72d72232016-08-04 10:15:08 -04005834 /* When testing multiple add/del ops, use a control-ping to sync */
5835 if (count > 1)
5836 {
5837 vl_api_control_ping_t *mp;
5838 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005839
Dave Barach72d72232016-08-04 10:15:08 -04005840 /* Shut off async mode */
5841 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005842
Dave Barach72d72232016-08-04 10:15:08 -04005843 M (CONTROL_PING, control_ping);
5844 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005845
Dave Barach72d72232016-08-04 10:15:08 -04005846 timeout = vat_time_now (vam) + 1.0;
5847 while (vat_time_now (vam) < timeout)
5848 if (vam->result_ready == 1)
5849 goto out;
5850 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005851
5852 out:
Dave Barach72d72232016-08-04 10:15:08 -04005853 if (vam->retval == -99)
5854 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005855
Dave Barach72d72232016-08-04 10:15:08 -04005856 if (vam->async_errors > 0)
5857 {
5858 errmsg ("%d asynchronous errors\n", vam->async_errors);
5859 vam->retval = -98;
5860 }
5861 vam->async_errors = 0;
5862 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005863
Dave Barach72d72232016-08-04 10:15:08 -04005864 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5865 count, after - before, count / (after - before));
5866 }
5867 else
5868 {
5869 /* Wait for a reply... */
5870 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005871 }
5872
Dave Barach72d72232016-08-04 10:15:08 -04005873 /* Return the good/bad news */
5874 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005875}
5876
Dave Barach72d72232016-08-04 10:15:08 -04005877static int
5878api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005879{
Dave Barach72d72232016-08-04 10:15:08 -04005880 unformat_input_t *i = vam->input;
5881 vl_api_proxy_arp_add_del_t *mp;
5882 f64 timeout;
5883 u32 vrf_id = 0;
5884 u8 is_add = 1;
5885 ip4_address_t lo, hi;
5886 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005887
Dave Barach72d72232016-08-04 10:15:08 -04005888 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5889 {
5890 if (unformat (i, "vrf %d", &vrf_id))
5891 ;
5892 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
5893 unformat_ip4_address, &hi))
5894 range_set = 1;
5895 else if (unformat (i, "del"))
5896 is_add = 0;
5897 else
5898 {
5899 clib_warning ("parse error '%U'", format_unformat_error, i);
5900 return -99;
5901 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005902 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005903
Dave Barach72d72232016-08-04 10:15:08 -04005904 if (range_set == 0)
5905 {
5906 errmsg ("address range not set\n");
5907 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005908 }
5909
Dave Barach72d72232016-08-04 10:15:08 -04005910 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005911
Dave Barach72d72232016-08-04 10:15:08 -04005912 mp->vrf_id = ntohl (vrf_id);
5913 mp->is_add = is_add;
5914 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
5915 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005916
Dave Barach72d72232016-08-04 10:15:08 -04005917 S;
5918 W;
5919 /* NOTREACHED */
5920 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005921}
5922
Dave Barach72d72232016-08-04 10:15:08 -04005923static int
5924api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005925{
Dave Barach72d72232016-08-04 10:15:08 -04005926 unformat_input_t *i = vam->input;
5927 vl_api_proxy_arp_intfc_enable_disable_t *mp;
5928 f64 timeout;
5929 u32 sw_if_index;
5930 u8 enable = 1;
5931 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005932
Dave Barach72d72232016-08-04 10:15:08 -04005933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5934 {
5935 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5936 sw_if_index_set = 1;
5937 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5938 sw_if_index_set = 1;
5939 else if (unformat (i, "enable"))
5940 enable = 1;
5941 else if (unformat (i, "disable"))
5942 enable = 0;
5943 else
5944 {
5945 clib_warning ("parse error '%U'", format_unformat_error, i);
5946 return -99;
5947 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005948 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005949
Dave Barach72d72232016-08-04 10:15:08 -04005950 if (sw_if_index_set == 0)
5951 {
5952 errmsg ("missing interface name or sw_if_index\n");
5953 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005954 }
5955
Dave Barach72d72232016-08-04 10:15:08 -04005956 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005957
Dave Barach72d72232016-08-04 10:15:08 -04005958 mp->sw_if_index = ntohl (sw_if_index);
5959 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005960
Dave Barach72d72232016-08-04 10:15:08 -04005961 S;
5962 W;
5963 /* NOTREACHED */
5964 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005965}
5966
Dave Barach72d72232016-08-04 10:15:08 -04005967static int
5968api_mpls_add_del_decap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005969{
Dave Barach72d72232016-08-04 10:15:08 -04005970 unformat_input_t *i = vam->input;
5971 vl_api_mpls_add_del_decap_t *mp;
5972 f64 timeout;
5973 u32 rx_vrf_id = 0;
5974 u32 tx_vrf_id = 0;
5975 u32 label = 0;
5976 u8 is_add = 1;
5977 u8 s_bit = 1;
5978 u32 next_index = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005979
Dave Barach72d72232016-08-04 10:15:08 -04005980 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5981 {
5982 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5983 ;
5984 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
5985 ;
5986 else if (unformat (i, "label %d", &label))
5987 ;
5988 else if (unformat (i, "next-index %d", &next_index))
5989 ;
5990 else if (unformat (i, "del"))
5991 is_add = 0;
5992 else if (unformat (i, "s-bit-clear"))
5993 s_bit = 0;
5994 else
5995 {
5996 clib_warning ("parse error '%U'", format_unformat_error, i);
5997 return -99;
5998 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005999 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006000
Dave Barach72d72232016-08-04 10:15:08 -04006001 M (MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006002
Dave Barach72d72232016-08-04 10:15:08 -04006003 mp->rx_vrf_id = ntohl (rx_vrf_id);
6004 mp->tx_vrf_id = ntohl (tx_vrf_id);
6005 mp->label = ntohl (label);
6006 mp->next_index = ntohl (next_index);
6007 mp->s_bit = s_bit;
6008 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006009
Dave Barach72d72232016-08-04 10:15:08 -04006010 S;
6011 W;
6012 /* NOTREACHED */
6013 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006014}
6015
Dave Barach72d72232016-08-04 10:15:08 -04006016static int
6017api_mpls_add_del_encap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006018{
Dave Barach72d72232016-08-04 10:15:08 -04006019 unformat_input_t *i = vam->input;
6020 vl_api_mpls_add_del_encap_t *mp;
6021 f64 timeout;
6022 u32 vrf_id = 0;
6023 u32 *labels = 0;
6024 u32 label;
6025 ip4_address_t dst_address;
6026 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006027
Dave Barach72d72232016-08-04 10:15:08 -04006028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6029 {
6030 if (unformat (i, "vrf %d", &vrf_id))
6031 ;
6032 else if (unformat (i, "label %d", &label))
6033 vec_add1 (labels, ntohl (label));
6034 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6035 ;
6036 else if (unformat (i, "del"))
6037 is_add = 0;
6038 else
6039 {
6040 clib_warning ("parse error '%U'", format_unformat_error, i);
6041 return -99;
6042 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006043 }
6044
Dave Barach72d72232016-08-04 10:15:08 -04006045 if (vec_len (labels) == 0)
6046 {
6047 errmsg ("missing encap label stack\n");
6048 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006049 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006050
Dave Barach72d72232016-08-04 10:15:08 -04006051 M2 (MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
6052 sizeof (u32) * vec_len (labels));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006053
Dave Barach72d72232016-08-04 10:15:08 -04006054 mp->vrf_id = ntohl (vrf_id);
6055 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6056 mp->is_add = is_add;
6057 mp->nlabels = vec_len (labels);
6058 clib_memcpy (mp->labels, labels, sizeof (u32) * mp->nlabels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006059
Dave Barach72d72232016-08-04 10:15:08 -04006060 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006061
Dave Barach72d72232016-08-04 10:15:08 -04006062 S;
6063 W;
6064 /* NOTREACHED */
6065 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006066}
6067
Dave Barach72d72232016-08-04 10:15:08 -04006068static int
6069api_mpls_gre_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006070{
Dave Barach72d72232016-08-04 10:15:08 -04006071 unformat_input_t *i = vam->input;
6072 vl_api_mpls_gre_add_del_tunnel_t *mp;
6073 f64 timeout;
6074 u32 inner_vrf_id = 0;
6075 u32 outer_vrf_id = 0;
6076 ip4_address_t src_address;
6077 ip4_address_t dst_address;
6078 ip4_address_t intfc_address;
6079 u32 tmp;
6080 u8 intfc_address_length = 0;
6081 u8 is_add = 1;
6082 u8 l2_only = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006083
Dave Barach72d72232016-08-04 10:15:08 -04006084 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6085 {
6086 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6087 ;
6088 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6089 ;
6090 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
6091 ;
6092 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6093 ;
6094 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6095 &intfc_address, &tmp))
6096 intfc_address_length = tmp;
6097 else if (unformat (i, "l2-only"))
6098 l2_only = 1;
6099 else if (unformat (i, "del"))
6100 is_add = 0;
6101 else
6102 {
6103 clib_warning ("parse error '%U'", format_unformat_error, i);
6104 return -99;
6105 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006106 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006107
Dave Barach72d72232016-08-04 10:15:08 -04006108 M (MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006109
Dave Barach72d72232016-08-04 10:15:08 -04006110 mp->inner_vrf_id = ntohl (inner_vrf_id);
6111 mp->outer_vrf_id = ntohl (outer_vrf_id);
6112 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
6113 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6114 clib_memcpy (mp->intfc_address, &intfc_address, sizeof (intfc_address));
6115 mp->intfc_address_length = intfc_address_length;
6116 mp->l2_only = l2_only;
6117 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006118
Dave Barach72d72232016-08-04 10:15:08 -04006119 S;
6120 W;
6121 /* NOTREACHED */
6122 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006123}
6124
Dave Barach72d72232016-08-04 10:15:08 -04006125static int
6126api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006127{
Dave Barach72d72232016-08-04 10:15:08 -04006128 unformat_input_t *i = vam->input;
6129 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
6130 f64 timeout;
6131 u32 inner_vrf_id = 0;
6132 ip4_address_t intfc_address;
6133 u8 dst_mac_address[6];
6134 int dst_set = 1;
6135 u32 tmp;
6136 u8 intfc_address_length = 0;
6137 u8 is_add = 1;
6138 u8 l2_only = 0;
6139 u32 tx_sw_if_index;
6140 int tx_sw_if_index_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006141
Dave Barach72d72232016-08-04 10:15:08 -04006142 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6143 {
6144 if (unformat (i, "vrf %d", &inner_vrf_id))
6145 ;
6146 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6147 &intfc_address, &tmp))
6148 intfc_address_length = tmp;
6149 else if (unformat (i, "%U", unformat_sw_if_index, vam, &tx_sw_if_index))
6150 tx_sw_if_index_set = 1;
6151 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6152 tx_sw_if_index_set = 1;
6153 else if (unformat (i, "dst %U", unformat_ethernet_address,
6154 dst_mac_address))
6155 dst_set = 1;
6156 else if (unformat (i, "l2-only"))
6157 l2_only = 1;
6158 else if (unformat (i, "del"))
6159 is_add = 0;
6160 else
6161 {
6162 clib_warning ("parse error '%U'", format_unformat_error, i);
6163 return -99;
6164 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006165 }
6166
Dave Barach72d72232016-08-04 10:15:08 -04006167 if (!dst_set)
6168 {
6169 errmsg ("dst (mac address) not set\n");
6170 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006171 }
Dave Barach72d72232016-08-04 10:15:08 -04006172 if (!tx_sw_if_index_set)
6173 {
6174 errmsg ("tx-intfc not set\n");
6175 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006176 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006177
Dave Barach72d72232016-08-04 10:15:08 -04006178 M (MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006179
Dave Barach72d72232016-08-04 10:15:08 -04006180 mp->vrf_id = ntohl (inner_vrf_id);
6181 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
6182 mp->adj_address_length = intfc_address_length;
6183 clib_memcpy (mp->dst_mac_address, dst_mac_address,
6184 sizeof (dst_mac_address));
6185 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6186 mp->l2_only = l2_only;
6187 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006188
Dave Barach72d72232016-08-04 10:15:08 -04006189 S;
6190 W;
6191 /* NOTREACHED */
6192 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006193}
6194
Dave Barach72d72232016-08-04 10:15:08 -04006195static int
6196api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006197{
Dave Barach72d72232016-08-04 10:15:08 -04006198 unformat_input_t *i = vam->input;
6199 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
6200 f64 timeout;
6201 u32 inner_vrf_id = 0;
6202 u32 outer_vrf_id = 0;
6203 ip4_address_t adj_address;
6204 int adj_address_set = 0;
6205 ip4_address_t next_hop_address;
6206 int next_hop_address_set = 0;
6207 u32 tmp;
6208 u8 adj_address_length = 0;
6209 u8 l2_only = 0;
6210 u8 is_add = 1;
6211 u32 resolve_attempts = 5;
6212 u8 resolve_if_needed = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006213
Dave Barach72d72232016-08-04 10:15:08 -04006214 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6215 {
6216 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6217 ;
6218 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6219 ;
6220 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6221 &adj_address, &tmp))
6222 {
6223 adj_address_length = tmp;
6224 adj_address_set = 1;
6225 }
6226 else if (unformat (i, "next-hop %U", unformat_ip4_address,
6227 &next_hop_address))
6228 next_hop_address_set = 1;
6229 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
6230 ;
6231 else if (unformat (i, "resolve-if-needed %d", &tmp))
6232 resolve_if_needed = tmp;
6233 else if (unformat (i, "l2-only"))
6234 l2_only = 1;
6235 else if (unformat (i, "del"))
6236 is_add = 0;
6237 else
6238 {
6239 clib_warning ("parse error '%U'", format_unformat_error, i);
6240 return -99;
6241 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006242 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006243
Dave Barach72d72232016-08-04 10:15:08 -04006244 if (!adj_address_set)
6245 {
6246 errmsg ("adjacency address/mask not set\n");
6247 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006248 }
Dave Barach72d72232016-08-04 10:15:08 -04006249 if (!next_hop_address_set)
6250 {
6251 errmsg ("ip4 next hop address (in outer fib) not set\n");
6252 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006253 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006254
Dave Barach72d72232016-08-04 10:15:08 -04006255 M (MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006256
Dave Barach72d72232016-08-04 10:15:08 -04006257 mp->inner_vrf_id = ntohl (inner_vrf_id);
6258 mp->outer_vrf_id = ntohl (outer_vrf_id);
6259 mp->resolve_attempts = ntohl (resolve_attempts);
6260 mp->resolve_if_needed = resolve_if_needed;
6261 mp->is_add = is_add;
6262 mp->l2_only = l2_only;
6263 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
6264 mp->adj_address_length = adj_address_length;
6265 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
6266 sizeof (next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006267
Dave Barach72d72232016-08-04 10:15:08 -04006268 S;
6269 W;
6270 /* NOTREACHED */
6271 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006272}
6273
Dave Barach72d72232016-08-04 10:15:08 -04006274static int
6275api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006276{
Dave Barach72d72232016-08-04 10:15:08 -04006277 unformat_input_t *i = vam->input;
6278 vl_api_sw_interface_set_unnumbered_t *mp;
6279 f64 timeout;
6280 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006281 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006282 u8 is_add = 1;
6283 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006284
Dave Barach72d72232016-08-04 10:15:08 -04006285 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6286 {
6287 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6288 sw_if_index_set = 1;
6289 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6290 sw_if_index_set = 1;
6291 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6292 ;
6293 else if (unformat (i, "del"))
6294 is_add = 0;
6295 else
6296 {
6297 clib_warning ("parse error '%U'", format_unformat_error, i);
6298 return -99;
6299 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006300 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006301
Dave Barach72d72232016-08-04 10:15:08 -04006302 if (sw_if_index_set == 0)
6303 {
6304 errmsg ("missing interface name or sw_if_index\n");
6305 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006306 }
6307
Dave Barach72d72232016-08-04 10:15:08 -04006308 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006309
Dave Barach72d72232016-08-04 10:15:08 -04006310 mp->sw_if_index = ntohl (sw_if_index);
6311 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6312 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006313
Dave Barach72d72232016-08-04 10:15:08 -04006314 S;
6315 W;
6316 /* NOTREACHED */
6317 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006318}
6319
Dave Barach72d72232016-08-04 10:15:08 -04006320static int
6321api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006322{
Dave Barach72d72232016-08-04 10:15:08 -04006323 unformat_input_t *i = vam->input;
6324 vl_api_ip_neighbor_add_del_t *mp;
6325 f64 timeout;
6326 u32 sw_if_index;
6327 u8 sw_if_index_set = 0;
6328 u32 vrf_id = 0;
6329 u8 is_add = 1;
6330 u8 is_static = 0;
6331 u8 mac_address[6];
6332 u8 mac_set = 0;
6333 u8 v4_address_set = 0;
6334 u8 v6_address_set = 0;
6335 ip4_address_t v4address;
6336 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006337
Dave Barach72d72232016-08-04 10:15:08 -04006338 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006339
Dave Barach72d72232016-08-04 10:15:08 -04006340 /* Parse args required to build the message */
6341 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6342 {
6343 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6344 {
6345 mac_set = 1;
6346 }
6347 else if (unformat (i, "del"))
6348 is_add = 0;
6349 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6350 sw_if_index_set = 1;
6351 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6352 sw_if_index_set = 1;
6353 else if (unformat (i, "is_static"))
6354 is_static = 1;
6355 else if (unformat (i, "vrf %d", &vrf_id))
6356 ;
6357 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6358 v4_address_set = 1;
6359 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6360 v6_address_set = 1;
6361 else
6362 {
6363 clib_warning ("parse error '%U'", format_unformat_error, i);
6364 return -99;
6365 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006366 }
6367
Dave Barach72d72232016-08-04 10:15:08 -04006368 if (sw_if_index_set == 0)
6369 {
6370 errmsg ("missing interface name or sw_if_index\n");
6371 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006372 }
Dave Barach72d72232016-08-04 10:15:08 -04006373 if (v4_address_set && v6_address_set)
6374 {
6375 errmsg ("both v4 and v6 addresses set\n");
6376 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006377 }
Dave Barach72d72232016-08-04 10:15:08 -04006378 if (!v4_address_set && !v6_address_set)
6379 {
6380 errmsg ("no address set\n");
6381 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006382 }
6383
Dave Barach72d72232016-08-04 10:15:08 -04006384 /* Construct the API message */
6385 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006386
Dave Barach72d72232016-08-04 10:15:08 -04006387 mp->sw_if_index = ntohl (sw_if_index);
6388 mp->is_add = is_add;
6389 mp->vrf_id = ntohl (vrf_id);
6390 mp->is_static = is_static;
6391 if (mac_set)
6392 clib_memcpy (mp->mac_address, mac_address, 6);
6393 if (v6_address_set)
6394 {
6395 mp->is_ipv6 = 1;
6396 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6397 }
6398 else
6399 {
6400 /* mp->is_ipv6 = 0; via memset in M macro above */
6401 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006402 }
6403
Dave Barach72d72232016-08-04 10:15:08 -04006404 /* send it... */
6405 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006406
Dave Barach72d72232016-08-04 10:15:08 -04006407 /* Wait for a reply, return good/bad news */
6408 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006409
Dave Barach72d72232016-08-04 10:15:08 -04006410 /* NOTREACHED */
6411 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006412}
6413
Dave Barach72d72232016-08-04 10:15:08 -04006414static int
6415api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006416{
Dave Barach72d72232016-08-04 10:15:08 -04006417 unformat_input_t *i = vam->input;
6418 vl_api_reset_vrf_t *mp;
6419 f64 timeout;
6420 u32 vrf_id = 0;
6421 u8 is_ipv6 = 0;
6422 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006423
Dave Barach72d72232016-08-04 10:15:08 -04006424 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6425 {
6426 if (unformat (i, "vrf %d", &vrf_id))
6427 vrf_id_set = 1;
6428 else if (unformat (i, "ipv6"))
6429 is_ipv6 = 1;
6430 else
6431 {
6432 clib_warning ("parse error '%U'", format_unformat_error, i);
6433 return -99;
6434 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006435 }
6436
Dave Barach72d72232016-08-04 10:15:08 -04006437 if (vrf_id_set == 0)
6438 {
6439 errmsg ("missing vrf id\n");
6440 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006441 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006442
Dave Barach72d72232016-08-04 10:15:08 -04006443 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006444
Dave Barach72d72232016-08-04 10:15:08 -04006445 mp->vrf_id = ntohl (vrf_id);
6446 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006447
Dave Barach72d72232016-08-04 10:15:08 -04006448 S;
6449 W;
6450 /* NOTREACHED */
6451 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006452}
6453
Dave Barach72d72232016-08-04 10:15:08 -04006454static int
6455api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006456{
Dave Barach72d72232016-08-04 10:15:08 -04006457 unformat_input_t *i = vam->input;
6458 vl_api_create_vlan_subif_t *mp;
6459 f64 timeout;
6460 u32 sw_if_index;
6461 u8 sw_if_index_set = 0;
6462 u32 vlan_id;
6463 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006464
Dave Barach72d72232016-08-04 10:15:08 -04006465 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6466 {
6467 if (unformat (i, "sw_if_index %d", &sw_if_index))
6468 sw_if_index_set = 1;
6469 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6470 sw_if_index_set = 1;
6471 else if (unformat (i, "vlan %d", &vlan_id))
6472 vlan_id_set = 1;
6473 else
6474 {
6475 clib_warning ("parse error '%U'", format_unformat_error, i);
6476 return -99;
6477 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006478 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006479
Dave Barach72d72232016-08-04 10:15:08 -04006480 if (sw_if_index_set == 0)
6481 {
6482 errmsg ("missing interface name or sw_if_index\n");
6483 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006484 }
6485
Dave Barach72d72232016-08-04 10:15:08 -04006486 if (vlan_id_set == 0)
6487 {
6488 errmsg ("missing vlan_id\n");
6489 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006490 }
Dave Barach72d72232016-08-04 10:15:08 -04006491 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006492
Dave Barach72d72232016-08-04 10:15:08 -04006493 mp->sw_if_index = ntohl (sw_if_index);
6494 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006495
Dave Barach72d72232016-08-04 10:15:08 -04006496 S;
6497 W;
6498 /* NOTREACHED */
6499 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006500}
6501
6502#define foreach_create_subif_bit \
6503_(no_tags) \
6504_(one_tag) \
6505_(two_tags) \
6506_(dot1ad) \
6507_(exact_match) \
6508_(default_sub) \
6509_(outer_vlan_id_any) \
6510_(inner_vlan_id_any)
6511
Dave Barach72d72232016-08-04 10:15:08 -04006512static int
6513api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006514{
Dave Barach72d72232016-08-04 10:15:08 -04006515 unformat_input_t *i = vam->input;
6516 vl_api_create_subif_t *mp;
6517 f64 timeout;
6518 u32 sw_if_index;
6519 u8 sw_if_index_set = 0;
6520 u32 sub_id;
6521 u8 sub_id_set = 0;
6522 u32 no_tags = 0;
6523 u32 one_tag = 0;
6524 u32 two_tags = 0;
6525 u32 dot1ad = 0;
6526 u32 exact_match = 0;
6527 u32 default_sub = 0;
6528 u32 outer_vlan_id_any = 0;
6529 u32 inner_vlan_id_any = 0;
6530 u32 tmp;
6531 u16 outer_vlan_id = 0;
6532 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006533
Dave Barach72d72232016-08-04 10:15:08 -04006534 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6535 {
6536 if (unformat (i, "sw_if_index %d", &sw_if_index))
6537 sw_if_index_set = 1;
6538 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6539 sw_if_index_set = 1;
6540 else if (unformat (i, "sub_id %d", &sub_id))
6541 sub_id_set = 1;
6542 else if (unformat (i, "outer_vlan_id %d", &tmp))
6543 outer_vlan_id = tmp;
6544 else if (unformat (i, "inner_vlan_id %d", &tmp))
6545 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006546
6547#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04006548 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07006549#undef _
Dave Barach72d72232016-08-04 10:15:08 -04006550 else
6551 {
6552 clib_warning ("parse error '%U'", format_unformat_error, i);
6553 return -99;
6554 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006555 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006556
Dave Barach72d72232016-08-04 10:15:08 -04006557 if (sw_if_index_set == 0)
6558 {
6559 errmsg ("missing interface name or sw_if_index\n");
6560 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006561 }
6562
Dave Barach72d72232016-08-04 10:15:08 -04006563 if (sub_id_set == 0)
6564 {
6565 errmsg ("missing sub_id\n");
6566 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006567 }
Dave Barach72d72232016-08-04 10:15:08 -04006568 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006569
Dave Barach72d72232016-08-04 10:15:08 -04006570 mp->sw_if_index = ntohl (sw_if_index);
6571 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006572
Ed Warnickecb9cada2015-12-08 15:45:58 -07006573#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04006574 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006575#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006576
Dave Barach72d72232016-08-04 10:15:08 -04006577 mp->outer_vlan_id = ntohs (outer_vlan_id);
6578 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006579
Dave Barach72d72232016-08-04 10:15:08 -04006580 S;
6581 W;
6582 /* NOTREACHED */
6583 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006584}
6585
Dave Barach72d72232016-08-04 10:15:08 -04006586static int
6587api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006588{
Dave Barach72d72232016-08-04 10:15:08 -04006589 unformat_input_t *i = vam->input;
6590 vl_api_oam_add_del_t *mp;
6591 f64 timeout;
6592 u32 vrf_id = 0;
6593 u8 is_add = 1;
6594 ip4_address_t src, dst;
6595 u8 src_set = 0;
6596 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006597
Dave Barach72d72232016-08-04 10:15:08 -04006598 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6599 {
6600 if (unformat (i, "vrf %d", &vrf_id))
6601 ;
6602 else if (unformat (i, "src %U", unformat_ip4_address, &src))
6603 src_set = 1;
6604 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
6605 dst_set = 1;
6606 else if (unformat (i, "del"))
6607 is_add = 0;
6608 else
6609 {
6610 clib_warning ("parse error '%U'", format_unformat_error, i);
6611 return -99;
6612 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006613 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006614
Dave Barach72d72232016-08-04 10:15:08 -04006615 if (src_set == 0)
6616 {
6617 errmsg ("missing src addr\n");
6618 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006619 }
6620
Dave Barach72d72232016-08-04 10:15:08 -04006621 if (dst_set == 0)
6622 {
6623 errmsg ("missing dst addr\n");
6624 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006625 }
6626
Dave Barach72d72232016-08-04 10:15:08 -04006627 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006628
Dave Barach72d72232016-08-04 10:15:08 -04006629 mp->vrf_id = ntohl (vrf_id);
6630 mp->is_add = is_add;
6631 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
6632 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006633
Dave Barach72d72232016-08-04 10:15:08 -04006634 S;
6635 W;
6636 /* NOTREACHED */
6637 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006638}
6639
Dave Barach72d72232016-08-04 10:15:08 -04006640static int
6641api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006642{
Dave Barach72d72232016-08-04 10:15:08 -04006643 unformat_input_t *i = vam->input;
6644 vl_api_reset_fib_t *mp;
6645 f64 timeout;
6646 u32 vrf_id = 0;
6647 u8 is_ipv6 = 0;
6648 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006649
Dave Barach72d72232016-08-04 10:15:08 -04006650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6651 {
6652 if (unformat (i, "vrf %d", &vrf_id))
6653 vrf_id_set = 1;
6654 else if (unformat (i, "ipv6"))
6655 is_ipv6 = 1;
6656 else
6657 {
6658 clib_warning ("parse error '%U'", format_unformat_error, i);
6659 return -99;
6660 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006661 }
6662
Dave Barach72d72232016-08-04 10:15:08 -04006663 if (vrf_id_set == 0)
6664 {
6665 errmsg ("missing vrf id\n");
6666 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006667 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006668
Dave Barach72d72232016-08-04 10:15:08 -04006669 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006670
Dave Barach72d72232016-08-04 10:15:08 -04006671 mp->vrf_id = ntohl (vrf_id);
6672 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006673
Dave Barach72d72232016-08-04 10:15:08 -04006674 S;
6675 W;
6676 /* NOTREACHED */
6677 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006678}
6679
Dave Barach72d72232016-08-04 10:15:08 -04006680static int
6681api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006682{
Dave Barach72d72232016-08-04 10:15:08 -04006683 unformat_input_t *i = vam->input;
6684 vl_api_dhcp_proxy_config_t *mp;
6685 f64 timeout;
6686 u32 vrf_id = 0;
6687 u8 is_add = 1;
6688 u8 insert_cid = 1;
6689 u8 v4_address_set = 0;
6690 u8 v6_address_set = 0;
6691 ip4_address_t v4address;
6692 ip6_address_t v6address;
6693 u8 v4_src_address_set = 0;
6694 u8 v6_src_address_set = 0;
6695 ip4_address_t v4srcaddress;
6696 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006697
Dave Barach72d72232016-08-04 10:15:08 -04006698 /* Parse args required to build the message */
6699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6700 {
6701 if (unformat (i, "del"))
6702 is_add = 0;
6703 else if (unformat (i, "vrf %d", &vrf_id))
6704 ;
6705 else if (unformat (i, "insert-cid %d", &insert_cid))
6706 ;
6707 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
6708 v4_address_set = 1;
6709 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
6710 v6_address_set = 1;
6711 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
6712 v4_src_address_set = 1;
6713 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
6714 v6_src_address_set = 1;
6715 else
6716 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006717 }
6718
Dave Barach72d72232016-08-04 10:15:08 -04006719 if (v4_address_set && v6_address_set)
6720 {
6721 errmsg ("both v4 and v6 server addresses set\n");
6722 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006723 }
Dave Barach72d72232016-08-04 10:15:08 -04006724 if (!v4_address_set && !v6_address_set)
6725 {
6726 errmsg ("no server addresses set\n");
6727 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006728 }
6729
Dave Barach72d72232016-08-04 10:15:08 -04006730 if (v4_src_address_set && v6_src_address_set)
6731 {
6732 errmsg ("both v4 and v6 src addresses set\n");
6733 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006734 }
Dave Barach72d72232016-08-04 10:15:08 -04006735 if (!v4_src_address_set && !v6_src_address_set)
6736 {
6737 errmsg ("no src addresses set\n");
6738 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006739 }
6740
Dave Barach72d72232016-08-04 10:15:08 -04006741 if (!(v4_src_address_set && v4_address_set) &&
6742 !(v6_src_address_set && v6_address_set))
6743 {
6744 errmsg ("no matching server and src addresses set\n");
6745 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006746 }
6747
Dave Barach72d72232016-08-04 10:15:08 -04006748 /* Construct the API message */
6749 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006750
Dave Barach72d72232016-08-04 10:15:08 -04006751 mp->insert_circuit_id = insert_cid;
6752 mp->is_add = is_add;
6753 mp->vrf_id = ntohl (vrf_id);
6754 if (v6_address_set)
6755 {
6756 mp->is_ipv6 = 1;
6757 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
6758 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
6759 }
6760 else
6761 {
6762 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
6763 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006764 }
6765
Dave Barach72d72232016-08-04 10:15:08 -04006766 /* send it... */
6767 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006768
Dave Barach72d72232016-08-04 10:15:08 -04006769 /* Wait for a reply, return good/bad news */
6770 W;
6771 /* NOTREACHED */
6772 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006773}
6774
Dave Barach72d72232016-08-04 10:15:08 -04006775static int
6776api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006777{
Dave Barach72d72232016-08-04 10:15:08 -04006778 unformat_input_t *i = vam->input;
6779 vl_api_dhcp_proxy_config_2_t *mp;
6780 f64 timeout;
6781 u32 rx_vrf_id = 0;
6782 u32 server_vrf_id = 0;
6783 u8 is_add = 1;
6784 u8 insert_cid = 1;
6785 u8 v4_address_set = 0;
6786 u8 v6_address_set = 0;
6787 ip4_address_t v4address;
6788 ip6_address_t v6address;
6789 u8 v4_src_address_set = 0;
6790 u8 v6_src_address_set = 0;
6791 ip4_address_t v4srcaddress;
6792 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006793
Dave Barach72d72232016-08-04 10:15:08 -04006794 /* Parse args required to build the message */
6795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6796 {
6797 if (unformat (i, "del"))
6798 is_add = 0;
6799 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
6800 ;
6801 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
6802 ;
6803 else if (unformat (i, "insert-cid %d", &insert_cid))
6804 ;
6805 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
6806 v4_address_set = 1;
6807 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
6808 v6_address_set = 1;
6809 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
6810 v4_src_address_set = 1;
6811 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
6812 v6_src_address_set = 1;
6813 else
6814 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006815 }
6816
Dave Barach72d72232016-08-04 10:15:08 -04006817 if (v4_address_set && v6_address_set)
6818 {
6819 errmsg ("both v4 and v6 server addresses set\n");
6820 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006821 }
Dave Barach72d72232016-08-04 10:15:08 -04006822 if (!v4_address_set && !v6_address_set)
6823 {
6824 errmsg ("no server addresses set\n");
6825 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006826 }
6827
Dave Barach72d72232016-08-04 10:15:08 -04006828 if (v4_src_address_set && v6_src_address_set)
6829 {
6830 errmsg ("both v4 and v6 src addresses set\n");
6831 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006832 }
Dave Barach72d72232016-08-04 10:15:08 -04006833 if (!v4_src_address_set && !v6_src_address_set)
6834 {
6835 errmsg ("no src addresses set\n");
6836 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006837 }
6838
Dave Barach72d72232016-08-04 10:15:08 -04006839 if (!(v4_src_address_set && v4_address_set) &&
6840 !(v6_src_address_set && v6_address_set))
6841 {
6842 errmsg ("no matching server and src addresses set\n");
6843 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006844 }
6845
Dave Barach72d72232016-08-04 10:15:08 -04006846 /* Construct the API message */
6847 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006848
Dave Barach72d72232016-08-04 10:15:08 -04006849 mp->insert_circuit_id = insert_cid;
6850 mp->is_add = is_add;
6851 mp->rx_vrf_id = ntohl (rx_vrf_id);
6852 mp->server_vrf_id = ntohl (server_vrf_id);
6853 if (v6_address_set)
6854 {
6855 mp->is_ipv6 = 1;
6856 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
6857 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
6858 }
6859 else
6860 {
6861 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
6862 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006863 }
6864
Dave Barach72d72232016-08-04 10:15:08 -04006865 /* send it... */
6866 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006867
Dave Barach72d72232016-08-04 10:15:08 -04006868 /* Wait for a reply, return good/bad news */
6869 W;
6870 /* NOTREACHED */
6871 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006872}
6873
Dave Barach72d72232016-08-04 10:15:08 -04006874static int
6875api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006876{
Dave Barach72d72232016-08-04 10:15:08 -04006877 unformat_input_t *i = vam->input;
6878 vl_api_dhcp_proxy_set_vss_t *mp;
6879 f64 timeout;
6880 u8 is_ipv6 = 0;
6881 u8 is_add = 1;
6882 u32 tbl_id;
6883 u8 tbl_id_set = 0;
6884 u32 oui;
6885 u8 oui_set = 0;
6886 u32 fib_id;
6887 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006888
Dave Barach72d72232016-08-04 10:15:08 -04006889 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6890 {
6891 if (unformat (i, "tbl_id %d", &tbl_id))
6892 tbl_id_set = 1;
6893 if (unformat (i, "fib_id %d", &fib_id))
6894 fib_id_set = 1;
6895 if (unformat (i, "oui %d", &oui))
6896 oui_set = 1;
6897 else if (unformat (i, "ipv6"))
6898 is_ipv6 = 1;
6899 else if (unformat (i, "del"))
6900 is_add = 0;
6901 else
6902 {
6903 clib_warning ("parse error '%U'", format_unformat_error, i);
6904 return -99;
6905 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006906 }
6907
Dave Barach72d72232016-08-04 10:15:08 -04006908 if (tbl_id_set == 0)
6909 {
6910 errmsg ("missing tbl id\n");
6911 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006912 }
6913
Dave Barach72d72232016-08-04 10:15:08 -04006914 if (fib_id_set == 0)
6915 {
6916 errmsg ("missing fib id\n");
6917 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006918 }
Dave Barach72d72232016-08-04 10:15:08 -04006919 if (oui_set == 0)
6920 {
6921 errmsg ("missing oui\n");
6922 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006923 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006924
Dave Barach72d72232016-08-04 10:15:08 -04006925 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
6926 mp->tbl_id = ntohl (tbl_id);
6927 mp->fib_id = ntohl (fib_id);
6928 mp->oui = ntohl (oui);
6929 mp->is_ipv6 = is_ipv6;
6930 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006931
Dave Barach72d72232016-08-04 10:15:08 -04006932 S;
6933 W;
6934 /* NOTREACHED */
6935 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006936}
6937
Dave Barach72d72232016-08-04 10:15:08 -04006938static int
6939api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006940{
Dave Barach72d72232016-08-04 10:15:08 -04006941 unformat_input_t *i = vam->input;
6942 vl_api_dhcp_client_config_t *mp;
6943 f64 timeout;
6944 u32 sw_if_index;
6945 u8 sw_if_index_set = 0;
6946 u8 is_add = 1;
6947 u8 *hostname = 0;
6948 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006949
Dave Barach72d72232016-08-04 10:15:08 -04006950 /* Parse args required to build the message */
6951 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6952 {
6953 if (unformat (i, "del"))
6954 is_add = 0;
6955 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6956 sw_if_index_set = 1;
6957 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6958 sw_if_index_set = 1;
6959 else if (unformat (i, "hostname %s", &hostname))
6960 ;
6961 else if (unformat (i, "disable_event"))
6962 disable_event = 1;
6963 else
6964 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006965 }
6966
Dave Barach72d72232016-08-04 10:15:08 -04006967 if (sw_if_index_set == 0)
6968 {
6969 errmsg ("missing interface name or sw_if_index\n");
6970 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006971 }
6972
Dave Barach72d72232016-08-04 10:15:08 -04006973 if (vec_len (hostname) > 63)
6974 {
6975 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006976 }
Dave Barach72d72232016-08-04 10:15:08 -04006977 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006978
Dave Barach72d72232016-08-04 10:15:08 -04006979 /* Construct the API message */
6980 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006981
Dave Barach72d72232016-08-04 10:15:08 -04006982 mp->sw_if_index = ntohl (sw_if_index);
6983 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
6984 vec_free (hostname);
6985 mp->is_add = is_add;
6986 mp->want_dhcp_event = disable_event ? 0 : 1;
6987 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006988
Dave Barach72d72232016-08-04 10:15:08 -04006989 /* send it... */
6990 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006991
Dave Barach72d72232016-08-04 10:15:08 -04006992 /* Wait for a reply, return good/bad news */
6993 W;
6994 /* NOTREACHED */
6995 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006996}
6997
Dave Barach72d72232016-08-04 10:15:08 -04006998static int
6999api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007000{
Dave Barach72d72232016-08-04 10:15:08 -04007001 unformat_input_t *i = vam->input;
7002 vl_api_set_ip_flow_hash_t *mp;
7003 f64 timeout;
7004 u32 vrf_id = 0;
7005 u8 is_ipv6 = 0;
7006 u8 vrf_id_set = 0;
7007 u8 src = 0;
7008 u8 dst = 0;
7009 u8 sport = 0;
7010 u8 dport = 0;
7011 u8 proto = 0;
7012 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007013
Dave Barach72d72232016-08-04 10:15:08 -04007014 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7015 {
7016 if (unformat (i, "vrf %d", &vrf_id))
7017 vrf_id_set = 1;
7018 else if (unformat (i, "ipv6"))
7019 is_ipv6 = 1;
7020 else if (unformat (i, "src"))
7021 src = 1;
7022 else if (unformat (i, "dst"))
7023 dst = 1;
7024 else if (unformat (i, "sport"))
7025 sport = 1;
7026 else if (unformat (i, "dport"))
7027 dport = 1;
7028 else if (unformat (i, "proto"))
7029 proto = 1;
7030 else if (unformat (i, "reverse"))
7031 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007032
Dave Barach72d72232016-08-04 10:15:08 -04007033 else
7034 {
7035 clib_warning ("parse error '%U'", format_unformat_error, i);
7036 return -99;
7037 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007038 }
7039
Dave Barach72d72232016-08-04 10:15:08 -04007040 if (vrf_id_set == 0)
7041 {
7042 errmsg ("missing vrf id\n");
7043 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007044 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007045
Dave Barach72d72232016-08-04 10:15:08 -04007046 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7047 mp->src = src;
7048 mp->dst = dst;
7049 mp->sport = sport;
7050 mp->dport = dport;
7051 mp->proto = proto;
7052 mp->reverse = reverse;
7053 mp->vrf_id = ntohl (vrf_id);
7054 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007055
Dave Barach72d72232016-08-04 10:15:08 -04007056 S;
7057 W;
7058 /* NOTREACHED */
7059 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007060}
7061
Dave Barach72d72232016-08-04 10:15:08 -04007062static int
7063api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007064{
Dave Barach72d72232016-08-04 10:15:08 -04007065 unformat_input_t *i = vam->input;
7066 vl_api_sw_interface_ip6_enable_disable_t *mp;
7067 f64 timeout;
7068 u32 sw_if_index;
7069 u8 sw_if_index_set = 0;
7070 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007071
Dave Barach72d72232016-08-04 10:15:08 -04007072 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7073 {
7074 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7075 sw_if_index_set = 1;
7076 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7077 sw_if_index_set = 1;
7078 else if (unformat (i, "enable"))
7079 enable = 1;
7080 else if (unformat (i, "disable"))
7081 enable = 0;
7082 else
7083 {
7084 clib_warning ("parse error '%U'", format_unformat_error, i);
7085 return -99;
7086 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007087 }
7088
Dave Barach72d72232016-08-04 10:15:08 -04007089 if (sw_if_index_set == 0)
7090 {
7091 errmsg ("missing interface name or sw_if_index\n");
7092 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007093 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007094
Dave Barach72d72232016-08-04 10:15:08 -04007095 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007096
Dave Barach72d72232016-08-04 10:15:08 -04007097 mp->sw_if_index = ntohl (sw_if_index);
7098 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007099
Dave Barach72d72232016-08-04 10:15:08 -04007100 S;
7101 W;
7102 /* NOTREACHED */
7103 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007104}
7105
Dave Barach72d72232016-08-04 10:15:08 -04007106static int
7107api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007108{
Dave Barach72d72232016-08-04 10:15:08 -04007109 unformat_input_t *i = vam->input;
7110 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7111 f64 timeout;
7112 u32 sw_if_index;
7113 u8 sw_if_index_set = 0;
7114 u32 address_length = 0;
7115 u8 v6_address_set = 0;
7116 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007117
Dave Barach72d72232016-08-04 10:15:08 -04007118 /* Parse args required to build the message */
7119 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7120 {
7121 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7122 sw_if_index_set = 1;
7123 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7124 sw_if_index_set = 1;
7125 else if (unformat (i, "%U/%d",
7126 unformat_ip6_address, &v6address, &address_length))
7127 v6_address_set = 1;
7128 else
7129 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007130 }
7131
Dave Barach72d72232016-08-04 10:15:08 -04007132 if (sw_if_index_set == 0)
7133 {
7134 errmsg ("missing interface name or sw_if_index\n");
7135 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007136 }
Dave Barach72d72232016-08-04 10:15:08 -04007137 if (!v6_address_set)
7138 {
7139 errmsg ("no address set\n");
7140 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007141 }
7142
Dave Barach72d72232016-08-04 10:15:08 -04007143 /* Construct the API message */
7144 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7145 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007146
Dave Barach72d72232016-08-04 10:15:08 -04007147 mp->sw_if_index = ntohl (sw_if_index);
7148 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7149 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007150
Dave Barach72d72232016-08-04 10:15:08 -04007151 /* send it... */
7152 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007153
Dave Barach72d72232016-08-04 10:15:08 -04007154 /* Wait for a reply, return good/bad news */
7155 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007156
Dave Barach72d72232016-08-04 10:15:08 -04007157 /* NOTREACHED */
7158 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007159}
7160
7161
Dave Barach72d72232016-08-04 10:15:08 -04007162static int
7163api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007164{
Dave Barach72d72232016-08-04 10:15:08 -04007165 unformat_input_t *i = vam->input;
7166 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7167 f64 timeout;
7168 u32 sw_if_index;
7169 u8 sw_if_index_set = 0;
7170 u32 address_length = 0;
7171 u8 v6_address_set = 0;
7172 ip6_address_t v6address;
7173 u8 use_default = 0;
7174 u8 no_advertise = 0;
7175 u8 off_link = 0;
7176 u8 no_autoconfig = 0;
7177 u8 no_onlink = 0;
7178 u8 is_no = 0;
7179 u32 val_lifetime = 0;
7180 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007181
Dave Barach72d72232016-08-04 10:15:08 -04007182 /* Parse args required to build the message */
7183 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7184 {
7185 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7186 sw_if_index_set = 1;
7187 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7188 sw_if_index_set = 1;
7189 else if (unformat (i, "%U/%d",
7190 unformat_ip6_address, &v6address, &address_length))
7191 v6_address_set = 1;
7192 else if (unformat (i, "val_life %d", &val_lifetime))
7193 ;
7194 else if (unformat (i, "pref_life %d", &pref_lifetime))
7195 ;
7196 else if (unformat (i, "def"))
7197 use_default = 1;
7198 else if (unformat (i, "noadv"))
7199 no_advertise = 1;
7200 else if (unformat (i, "offl"))
7201 off_link = 1;
7202 else if (unformat (i, "noauto"))
7203 no_autoconfig = 1;
7204 else if (unformat (i, "nolink"))
7205 no_onlink = 1;
7206 else if (unformat (i, "isno"))
7207 is_no = 1;
7208 else
7209 {
7210 clib_warning ("parse error '%U'", format_unformat_error, i);
7211 return -99;
7212 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007213 }
7214
Dave Barach72d72232016-08-04 10:15:08 -04007215 if (sw_if_index_set == 0)
7216 {
7217 errmsg ("missing interface name or sw_if_index\n");
7218 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007219 }
Dave Barach72d72232016-08-04 10:15:08 -04007220 if (!v6_address_set)
7221 {
7222 errmsg ("no address set\n");
7223 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007224 }
7225
Dave Barach72d72232016-08-04 10:15:08 -04007226 /* Construct the API message */
7227 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007228
Dave Barach72d72232016-08-04 10:15:08 -04007229 mp->sw_if_index = ntohl (sw_if_index);
7230 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7231 mp->address_length = address_length;
7232 mp->use_default = use_default;
7233 mp->no_advertise = no_advertise;
7234 mp->off_link = off_link;
7235 mp->no_autoconfig = no_autoconfig;
7236 mp->no_onlink = no_onlink;
7237 mp->is_no = is_no;
7238 mp->val_lifetime = ntohl (val_lifetime);
7239 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007240
Dave Barach72d72232016-08-04 10:15:08 -04007241 /* send it... */
7242 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007243
Dave Barach72d72232016-08-04 10:15:08 -04007244 /* Wait for a reply, return good/bad news */
7245 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007246
Dave Barach72d72232016-08-04 10:15:08 -04007247 /* NOTREACHED */
7248 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007249}
7250
Dave Barach72d72232016-08-04 10:15:08 -04007251static int
7252api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007253{
Dave Barach72d72232016-08-04 10:15:08 -04007254 unformat_input_t *i = vam->input;
7255 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7256 f64 timeout;
7257 u32 sw_if_index;
7258 u8 sw_if_index_set = 0;
7259 u8 suppress = 0;
7260 u8 managed = 0;
7261 u8 other = 0;
7262 u8 ll_option = 0;
7263 u8 send_unicast = 0;
7264 u8 cease = 0;
7265 u8 is_no = 0;
7266 u8 default_router = 0;
7267 u32 max_interval = 0;
7268 u32 min_interval = 0;
7269 u32 lifetime = 0;
7270 u32 initial_count = 0;
7271 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007272
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007273
Dave Barach72d72232016-08-04 10:15:08 -04007274 /* Parse args required to build the message */
7275 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7276 {
7277 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7278 sw_if_index_set = 1;
7279 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7280 sw_if_index_set = 1;
7281 else if (unformat (i, "maxint %d", &max_interval))
7282 ;
7283 else if (unformat (i, "minint %d", &min_interval))
7284 ;
7285 else if (unformat (i, "life %d", &lifetime))
7286 ;
7287 else if (unformat (i, "count %d", &initial_count))
7288 ;
7289 else if (unformat (i, "interval %d", &initial_interval))
7290 ;
7291 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7292 suppress = 1;
7293 else if (unformat (i, "managed"))
7294 managed = 1;
7295 else if (unformat (i, "other"))
7296 other = 1;
7297 else if (unformat (i, "ll"))
7298 ll_option = 1;
7299 else if (unformat (i, "send"))
7300 send_unicast = 1;
7301 else if (unformat (i, "cease"))
7302 cease = 1;
7303 else if (unformat (i, "isno"))
7304 is_no = 1;
7305 else if (unformat (i, "def"))
7306 default_router = 1;
7307 else
7308 {
7309 clib_warning ("parse error '%U'", format_unformat_error, i);
7310 return -99;
7311 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007312 }
7313
Dave Barach72d72232016-08-04 10:15:08 -04007314 if (sw_if_index_set == 0)
7315 {
7316 errmsg ("missing interface name or sw_if_index\n");
7317 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007318 }
7319
Dave Barach72d72232016-08-04 10:15:08 -04007320 /* Construct the API message */
7321 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007322
Dave Barach72d72232016-08-04 10:15:08 -04007323 mp->sw_if_index = ntohl (sw_if_index);
7324 mp->max_interval = ntohl (max_interval);
7325 mp->min_interval = ntohl (min_interval);
7326 mp->lifetime = ntohl (lifetime);
7327 mp->initial_count = ntohl (initial_count);
7328 mp->initial_interval = ntohl (initial_interval);
7329 mp->suppress = suppress;
7330 mp->managed = managed;
7331 mp->other = other;
7332 mp->ll_option = ll_option;
7333 mp->send_unicast = send_unicast;
7334 mp->cease = cease;
7335 mp->is_no = is_no;
7336 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007337
Dave Barach72d72232016-08-04 10:15:08 -04007338 /* send it... */
7339 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007340
Dave Barach72d72232016-08-04 10:15:08 -04007341 /* Wait for a reply, return good/bad news */
7342 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007343
Dave Barach72d72232016-08-04 10:15:08 -04007344 /* NOTREACHED */
7345 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007346}
7347
Dave Barach72d72232016-08-04 10:15:08 -04007348static int
7349api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007350{
Dave Barach72d72232016-08-04 10:15:08 -04007351 unformat_input_t *i = vam->input;
7352 vl_api_set_arp_neighbor_limit_t *mp;
7353 f64 timeout;
7354 u32 arp_nbr_limit;
7355 u8 limit_set = 0;
7356 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007357
Dave Barach72d72232016-08-04 10:15:08 -04007358 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7359 {
7360 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7361 limit_set = 1;
7362 else if (unformat (i, "ipv6"))
7363 is_ipv6 = 1;
7364 else
7365 {
7366 clib_warning ("parse error '%U'", format_unformat_error, i);
7367 return -99;
7368 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007369 }
7370
Dave Barach72d72232016-08-04 10:15:08 -04007371 if (limit_set == 0)
7372 {
7373 errmsg ("missing limit value\n");
7374 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007375 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007376
Dave Barach72d72232016-08-04 10:15:08 -04007377 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007378
Dave Barach72d72232016-08-04 10:15:08 -04007379 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7380 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007381
Dave Barach72d72232016-08-04 10:15:08 -04007382 S;
7383 W;
7384 /* NOTREACHED */
7385 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007386}
7387
Dave Barach72d72232016-08-04 10:15:08 -04007388static int
7389api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007390{
Dave Barach72d72232016-08-04 10:15:08 -04007391 unformat_input_t *i = vam->input;
7392 vl_api_l2_patch_add_del_t *mp;
7393 f64 timeout;
7394 u32 rx_sw_if_index;
7395 u8 rx_sw_if_index_set = 0;
7396 u32 tx_sw_if_index;
7397 u8 tx_sw_if_index_set = 0;
7398 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007399
Dave Barach72d72232016-08-04 10:15:08 -04007400 /* Parse args required to build the message */
7401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7402 {
7403 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7404 rx_sw_if_index_set = 1;
7405 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7406 tx_sw_if_index_set = 1;
7407 else if (unformat (i, "rx"))
7408 {
7409 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7410 {
7411 if (unformat (i, "%U", unformat_sw_if_index, vam,
7412 &rx_sw_if_index))
7413 rx_sw_if_index_set = 1;
7414 }
7415 else
7416 break;
7417 }
7418 else if (unformat (i, "tx"))
7419 {
7420 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7421 {
7422 if (unformat (i, "%U", unformat_sw_if_index, vam,
7423 &tx_sw_if_index))
7424 tx_sw_if_index_set = 1;
7425 }
7426 else
7427 break;
7428 }
7429 else if (unformat (i, "del"))
7430 is_add = 0;
7431 else
7432 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007433 }
7434
Dave Barach72d72232016-08-04 10:15:08 -04007435 if (rx_sw_if_index_set == 0)
7436 {
7437 errmsg ("missing rx interface name or rx_sw_if_index\n");
7438 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007439 }
7440
Dave Barach72d72232016-08-04 10:15:08 -04007441 if (tx_sw_if_index_set == 0)
7442 {
7443 errmsg ("missing tx interface name or tx_sw_if_index\n");
7444 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007445 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007446
Dave Barach72d72232016-08-04 10:15:08 -04007447 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007448
Dave Barach72d72232016-08-04 10:15:08 -04007449 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7450 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7451 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007452
Dave Barach72d72232016-08-04 10:15:08 -04007453 S;
7454 W;
7455 /* NOTREACHED */
7456 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007457}
Dave Barach72d72232016-08-04 10:15:08 -04007458
7459static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007460api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007461{
Dave Barach72d72232016-08-04 10:15:08 -04007462 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007463 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007464 f64 timeout;
7465 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007466 int has_trace_option = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007467 int has_pow_option = 0;
7468 int has_ppc_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007469
Shwetha20a64f52016-03-25 10:55:01 +00007470 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7471 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007472 if (unformat (input, "trace"))
7473 has_trace_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007474 else if (unformat (input, "pow"))
Dave Barach72d72232016-08-04 10:15:08 -04007475 has_pow_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007476 else if (unformat (input, "ppc encap"))
Dave Barach72d72232016-08-04 10:15:08 -04007477 has_ppc_option = PPC_ENCAP;
Shwetha20a64f52016-03-25 10:55:01 +00007478 else if (unformat (input, "ppc decap"))
Dave Barach72d72232016-08-04 10:15:08 -04007479 has_ppc_option = PPC_DECAP;
Shwetha20a64f52016-03-25 10:55:01 +00007480 else if (unformat (input, "ppc none"))
Dave Barach72d72232016-08-04 10:15:08 -04007481 has_ppc_option = PPC_NONE;
Shwetha20a64f52016-03-25 10:55:01 +00007482 else
Dave Barach72d72232016-08-04 10:15:08 -04007483 break;
Shwetha20a64f52016-03-25 10:55:01 +00007484 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007485 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007486 mp->id = htons (id);
Shwetha20a64f52016-03-25 10:55:01 +00007487 mp->trace_ppc = has_ppc_option;
Shwetha20a64f52016-03-25 10:55:01 +00007488 mp->pow_enable = has_pow_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007489 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007490
Dave Barach72d72232016-08-04 10:15:08 -04007491 S;
7492 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007493
Dave Barach72d72232016-08-04 10:15:08 -04007494 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007495
Shwetha20a64f52016-03-25 10:55:01 +00007496}
Dave Barach72d72232016-08-04 10:15:08 -04007497
Shwetha20a64f52016-03-25 10:55:01 +00007498
Dave Barach72d72232016-08-04 10:15:08 -04007499static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007500api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007501{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007502 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007503 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007504
Vengada Govindan07d2f842016-08-25 10:34:34 -07007505 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04007506 S;
7507 W;
7508 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00007509}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007510
Dave Barach72d72232016-08-04 10:15:08 -04007511static int
7512api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007513{
Dave Barach72d72232016-08-04 10:15:08 -04007514 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007515 vl_api_sr_tunnel_add_del_t *mp;
7516 f64 timeout;
7517 int is_del = 0;
7518 int pl_index;
7519 ip6_address_t src_address;
7520 int src_address_set = 0;
7521 ip6_address_t dst_address;
7522 u32 dst_mask_width;
7523 int dst_address_set = 0;
7524 u16 flags = 0;
7525 u32 rx_table_id = 0;
7526 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007527 ip6_address_t *segments = 0;
7528 ip6_address_t *this_seg;
7529 ip6_address_t *tags = 0;
7530 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007531 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04007532 u8 *name = 0;
7533 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007534
7535 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7536 {
7537 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007538 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007539 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04007540 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007541 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007542 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007543 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007544 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007545 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007546 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007547 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04007548 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007549 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04007550 unformat_ip6_address, &dst_address, &dst_mask_width))
7551 dst_address_set = 1;
7552 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
7553 {
7554 vec_add2 (segments, this_seg, 1);
7555 clib_memcpy (this_seg->as_u8, next_address.as_u8,
7556 sizeof (*this_seg));
7557 }
7558 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
7559 {
7560 vec_add2 (tags, this_tag, 1);
7561 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
7562 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007563 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04007564 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007565 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04007566 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007567 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007568 {
7569 if (pl_index <= 0 || pl_index > 4)
7570 {
7571 pl_index_range_error:
7572 errmsg ("pl index %d out of range\n", pl_index);
7573 return -99;
7574 }
7575 flags |=
7576 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
7577 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007578 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007579 {
7580 if (pl_index <= 0 || pl_index > 4)
7581 goto pl_index_range_error;
7582 flags |=
7583 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
7584 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007585 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007586 {
7587 if (pl_index <= 0 || pl_index > 4)
7588 goto pl_index_range_error;
7589 flags |=
7590 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
7591 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007592 else
Dave Barach72d72232016-08-04 10:15:08 -04007593 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007594 }
7595
7596 if (!src_address_set)
7597 {
7598 errmsg ("src address required\n");
7599 return -99;
7600 }
7601
7602 if (!dst_address_set)
7603 {
7604 errmsg ("dst address required\n");
7605 return -99;
7606 }
7607
7608 if (!segments)
7609 {
7610 errmsg ("at least one sr segment required\n");
7611 return -99;
7612 }
7613
Dave Barach72d72232016-08-04 10:15:08 -04007614 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
7615 vec_len (segments) * sizeof (ip6_address_t)
7616 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007617
Damjan Marionf1213b82016-03-13 02:22:06 +01007618 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
7619 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007620 mp->dst_mask_width = dst_mask_width;
7621 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
7622 mp->n_segments = vec_len (segments);
7623 mp->n_tags = vec_len (tags);
7624 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007625 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04007626 vec_len (segments) * sizeof (ip6_address_t));
7627 clib_memcpy (mp->segs_and_tags +
7628 vec_len (segments) * sizeof (ip6_address_t), tags,
7629 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007630
7631 mp->outer_vrf_id = ntohl (rx_table_id);
7632 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04007633 memcpy (mp->name, name, vec_len (name));
7634 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007635
7636 vec_free (segments);
7637 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007638
Dave Barach72d72232016-08-04 10:15:08 -04007639 S;
7640 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007641 /* NOTREACHED */
7642}
7643
Dave Barach72d72232016-08-04 10:15:08 -04007644static int
7645api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007646{
Dave Barach72d72232016-08-04 10:15:08 -04007647 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007648 vl_api_sr_policy_add_del_t *mp;
7649 f64 timeout;
7650 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007651 u8 *name = 0;
7652 u8 *tunnel_name = 0;
7653 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007654
Dave Barach72d72232016-08-04 10:15:08 -04007655 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007656 int tunnel_set = 0;
7657 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007658 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
7659 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007660
7661 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7662 {
7663 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007664 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007665 else if (unformat (input, "name %s", &name))
7666 name_set = 1;
7667 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04007668 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007669 if (tunnel_name)
7670 {
7671 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007672 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04007673 - length = #bytes to store in serial vector
7674 - +1 = byte to store that length
7675 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007676 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007677 tunnel_set = 1;
7678 tunnel_name = 0;
7679 }
Dave Barach72d72232016-08-04 10:15:08 -04007680 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007681 else
Dave Barach72d72232016-08-04 10:15:08 -04007682 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007683 }
7684
7685 if (!name_set)
7686 {
7687 errmsg ("policy name required\n");
7688 return -99;
7689 }
7690
7691 if ((!tunnel_set) && (!is_del))
7692 {
7693 errmsg ("tunnel name required\n");
7694 return -99;
7695 }
7696
Dave Barach72d72232016-08-04 10:15:08 -04007697 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007698
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007699
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007700
7701 mp->is_add = !is_del;
7702
Dave Barach72d72232016-08-04 10:15:08 -04007703 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007704 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
Dave Barach72d72232016-08-04 10:15:08 -04007705 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007706 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04007707 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
7708 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007709
Dave Barach72d72232016-08-04 10:15:08 -04007710 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007711 {
7712 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04007713 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
7714 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007715 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04007716 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007717 }
Dave Barach72d72232016-08-04 10:15:08 -04007718 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007719
7720 vec_free (tunnel_names);
7721 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007722
Dave Barach72d72232016-08-04 10:15:08 -04007723 S;
7724 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007725 /* NOTREACHED */
7726}
7727
Dave Barach72d72232016-08-04 10:15:08 -04007728static int
7729api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007730{
Dave Barach72d72232016-08-04 10:15:08 -04007731 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007732 vl_api_sr_multicast_map_add_del_t *mp;
7733 f64 timeout;
7734 int is_del = 0;
7735 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04007736 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007737 int multicast_address_set = 0;
7738
7739 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7740 {
7741 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007742 is_del = 1;
7743 else
7744 if (unformat
7745 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007746 multicast_address_set = 1;
7747 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007748 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007749 else
Dave Barach72d72232016-08-04 10:15:08 -04007750 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007751 }
7752
7753 if (!is_del && !policy_name)
7754 {
7755 errmsg ("sr-policy name required\n");
7756 return -99;
7757 }
7758
7759
7760 if (!multicast_address_set)
7761 {
7762 errmsg ("address required\n");
7763 return -99;
7764 }
7765
Dave Barach72d72232016-08-04 10:15:08 -04007766 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007767
7768 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04007769 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
7770 clib_memcpy (mp->multicast_address, &multicast_address,
7771 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007772
7773
7774 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007775
Dave Barach72d72232016-08-04 10:15:08 -04007776 S;
7777 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007778 /* NOTREACHED */
7779}
7780
Ed Warnickecb9cada2015-12-08 15:45:58 -07007781
7782#define foreach_ip4_proto_field \
7783_(src_address) \
7784_(dst_address) \
7785_(tos) \
7786_(length) \
7787_(fragment_id) \
7788_(ttl) \
7789_(protocol) \
7790_(checksum)
7791
Dave Barach72d72232016-08-04 10:15:08 -04007792uword
7793unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007794{
Dave Barach72d72232016-08-04 10:15:08 -04007795 u8 **maskp = va_arg (*args, u8 **);
7796 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007797 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007798 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007799
Ed Warnickecb9cada2015-12-08 15:45:58 -07007800#define _(a) u8 a=0;
7801 foreach_ip4_proto_field;
7802#undef _
7803 u8 version = 0;
7804 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007805
7806
7807 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007808 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007809 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04007810 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007811 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04007812 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007813 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04007814 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007815 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04007816 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007817 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04007818 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007819
Ed Warnickecb9cada2015-12-08 15:45:58 -07007820#define _(a) else if (unformat (input, #a)) a=1;
7821 foreach_ip4_proto_field
7822#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007823 else
7824 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007825 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007826
Ed Warnickecb9cada2015-12-08 15:45:58 -07007827#define _(a) found_something += a;
7828 foreach_ip4_proto_field;
7829#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007830
Ed Warnickecb9cada2015-12-08 15:45:58 -07007831 if (found_something == 0)
7832 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007833
Ed Warnickecb9cada2015-12-08 15:45:58 -07007834 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007835
Ed Warnickecb9cada2015-12-08 15:45:58 -07007836 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007837
Ed Warnickecb9cada2015-12-08 15:45:58 -07007838#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
7839 foreach_ip4_proto_field;
7840#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007841
Ed Warnickecb9cada2015-12-08 15:45:58 -07007842 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007843
Ed Warnickecb9cada2015-12-08 15:45:58 -07007844 if (version)
7845 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007846
Ed Warnickecb9cada2015-12-08 15:45:58 -07007847 if (hdr_length)
7848 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007849
Ed Warnickecb9cada2015-12-08 15:45:58 -07007850 *maskp = mask;
7851 return 1;
7852}
7853
7854#define foreach_ip6_proto_field \
7855_(src_address) \
7856_(dst_address) \
7857_(payload_length) \
7858_(hop_limit) \
7859_(protocol)
7860
Dave Barach72d72232016-08-04 10:15:08 -04007861uword
7862unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007863{
Dave Barach72d72232016-08-04 10:15:08 -04007864 u8 **maskp = va_arg (*args, u8 **);
7865 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007866 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007867 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007868 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007869
Ed Warnickecb9cada2015-12-08 15:45:58 -07007870#define _(a) u8 a=0;
7871 foreach_ip6_proto_field;
7872#undef _
7873 u8 version = 0;
7874 u8 traffic_class = 0;
7875 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007876
7877 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007878 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007879 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04007880 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007881 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04007882 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007883 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04007884 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007885 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04007886 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007887 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04007888 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007889 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04007890 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007891
Ed Warnickecb9cada2015-12-08 15:45:58 -07007892#define _(a) else if (unformat (input, #a)) a=1;
7893 foreach_ip6_proto_field
7894#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007895 else
7896 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007897 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007898
Ed Warnickecb9cada2015-12-08 15:45:58 -07007899#define _(a) found_something += a;
7900 foreach_ip6_proto_field;
7901#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007902
Ed Warnickecb9cada2015-12-08 15:45:58 -07007903 if (found_something == 0)
7904 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007905
Ed Warnickecb9cada2015-12-08 15:45:58 -07007906 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007907
Ed Warnickecb9cada2015-12-08 15:45:58 -07007908 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007909
Ed Warnickecb9cada2015-12-08 15:45:58 -07007910#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
7911 foreach_ip6_proto_field;
7912#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007913
Ed Warnickecb9cada2015-12-08 15:45:58 -07007914 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007915
Ed Warnickecb9cada2015-12-08 15:45:58 -07007916 if (version)
7917 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7918
7919 if (traffic_class)
7920 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7921
7922 if (flow_label)
7923 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7924
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007925 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07007926 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007927
Ed Warnickecb9cada2015-12-08 15:45:58 -07007928 *maskp = mask;
7929 return 1;
7930}
7931
Dave Barach72d72232016-08-04 10:15:08 -04007932uword
7933unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007934{
Dave Barach72d72232016-08-04 10:15:08 -04007935 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007936
Dave Barach72d72232016-08-04 10:15:08 -04007937 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7938 {
7939 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7940 return 1;
7941 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7942 return 1;
7943 else
7944 break;
7945 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007946 return 0;
7947}
7948
Dave Barach72d72232016-08-04 10:15:08 -04007949uword
7950unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007951{
Dave Barach72d72232016-08-04 10:15:08 -04007952 u8 **maskp = va_arg (*args, u8 **);
7953 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007954 u8 src = 0;
7955 u8 dst = 0;
7956 u8 proto = 0;
7957 u8 tag1 = 0;
7958 u8 tag2 = 0;
7959 u8 ignore_tag1 = 0;
7960 u8 ignore_tag2 = 0;
7961 u8 cos1 = 0;
7962 u8 cos2 = 0;
7963 u8 dot1q = 0;
7964 u8 dot1ad = 0;
7965 int len = 14;
7966
Dave Barach72d72232016-08-04 10:15:08 -04007967 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7968 {
7969 if (unformat (input, "src"))
7970 src = 1;
7971 else if (unformat (input, "dst"))
7972 dst = 1;
7973 else if (unformat (input, "proto"))
7974 proto = 1;
7975 else if (unformat (input, "tag1"))
7976 tag1 = 1;
7977 else if (unformat (input, "tag2"))
7978 tag2 = 1;
7979 else if (unformat (input, "ignore-tag1"))
7980 ignore_tag1 = 1;
7981 else if (unformat (input, "ignore-tag2"))
7982 ignore_tag2 = 1;
7983 else if (unformat (input, "cos1"))
7984 cos1 = 1;
7985 else if (unformat (input, "cos2"))
7986 cos2 = 1;
7987 else if (unformat (input, "dot1q"))
7988 dot1q = 1;
7989 else if (unformat (input, "dot1ad"))
7990 dot1ad = 1;
7991 else
7992 break;
7993 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007994 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04007995 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007996 return 0;
7997
7998 if (tag1 || ignore_tag1 || cos1 || dot1q)
7999 len = 18;
8000 if (tag2 || ignore_tag2 || cos2 || dot1ad)
8001 len = 22;
8002
Dave Barach72d72232016-08-04 10:15:08 -04008003 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008004
8005 if (dst)
8006 memset (mask, 0xff, 6);
8007
8008 if (src)
8009 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008010
Ed Warnickecb9cada2015-12-08 15:45:58 -07008011 if (tag2 || dot1ad)
8012 {
8013 /* inner vlan tag */
8014 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008015 {
8016 mask[19] = 0xff;
8017 mask[18] = 0x0f;
8018 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008019 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008020 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008021 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008022 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008023 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008024 {
8025 mask[15] = 0xff;
8026 mask[14] = 0x0f;
8027 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008028 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008029 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008030 *maskp = mask;
8031 return 1;
8032 }
8033 if (tag1 | dot1q)
8034 {
8035 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008036 {
8037 mask[15] = 0xff;
8038 mask[14] = 0x0f;
8039 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008040 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008041 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008042 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008043 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008044
8045 *maskp = mask;
8046 return 1;
8047 }
8048 if (cos2)
8049 mask[18] |= 0xe0;
8050 if (cos1)
8051 mask[14] |= 0xe0;
8052 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008053 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008054
Ed Warnickecb9cada2015-12-08 15:45:58 -07008055 *maskp = mask;
8056 return 1;
8057}
8058
Dave Barach72d72232016-08-04 10:15:08 -04008059uword
8060unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008061{
Dave Barach72d72232016-08-04 10:15:08 -04008062 u8 **maskp = va_arg (*args, u8 **);
8063 u32 *skipp = va_arg (*args, u32 *);
8064 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008065 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008066 u8 *mask = 0;
8067 u8 *l2 = 0;
8068 u8 *l3 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008069 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008070
Dave Barach72d72232016-08-04 10:15:08 -04008071 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8072 {
8073 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8074 ;
8075 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8076 ;
8077 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8078 ;
8079 else
8080 break;
8081 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008082
8083 if (mask || l2 || l3)
8084 {
8085 if (l2 || l3)
Dave Barach72d72232016-08-04 10:15:08 -04008086 {
8087 /* "With a free Ethernet header in every package" */
8088 if (l2 == 0)
8089 vec_validate (l2, 13);
8090 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008091 if (vec_len (l3))
8092 {
8093 vec_append (mask, l3);
8094 vec_free (l3);
8095 }
Dave Barach72d72232016-08-04 10:15:08 -04008096 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008097
8098 /* Scan forward looking for the first significant mask octet */
8099 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008100 if (mask[i])
8101 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008102
8103 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008104 *skipp = i / sizeof (u32x4);
8105 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008106
8107 /* Pad mask to an even multiple of the vector size */
8108 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008109 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008110
8111 match = vec_len (mask) / sizeof (u32x4);
8112
Dave Barach72d72232016-08-04 10:15:08 -04008113 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8114 {
8115 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8116 if (*tmp || *(tmp + 1))
8117 break;
8118 match--;
8119 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008120 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008121 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008122
Dave Barach72d72232016-08-04 10:15:08 -04008123 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008124
8125 *matchp = match;
8126 *maskp = mask;
8127
8128 return 1;
8129 }
8130
8131 return 0;
8132}
8133
8134#define foreach_l2_next \
8135_(drop, DROP) \
8136_(ethernet, ETHERNET_INPUT) \
8137_(ip4, IP4_INPUT) \
8138_(ip6, IP6_INPUT)
8139
Dave Barach72d72232016-08-04 10:15:08 -04008140uword
8141unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008142{
Dave Barach72d72232016-08-04 10:15:08 -04008143 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008144 u32 next_index = 0;
8145 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008146
Ed Warnickecb9cada2015-12-08 15:45:58 -07008147#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008148 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008149 foreach_l2_next;
8150#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008151
Ed Warnickecb9cada2015-12-08 15:45:58 -07008152 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008153 {
8154 next_index = tmp;
8155 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008156 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008157
Ed Warnickecb9cada2015-12-08 15:45:58 -07008158 return 0;
8159
Dave Barach72d72232016-08-04 10:15:08 -04008160out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008161 *miss_next_indexp = next_index;
8162 return 1;
8163}
8164
8165#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008166_(drop, DROP) \
8167_(local, LOCAL) \
8168_(rewrite, REWRITE)
8169
Dave Barach72d72232016-08-04 10:15:08 -04008170uword
8171unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008172{
Dave Barach72d72232016-08-04 10:15:08 -04008173 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008174 u32 next_index = 0;
8175 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008176
Ed Warnickecb9cada2015-12-08 15:45:58 -07008177#define _(n,N) \
8178 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8179 foreach_ip_next;
8180#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008181
Ed Warnickecb9cada2015-12-08 15:45:58 -07008182 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008183 {
8184 next_index = tmp;
8185 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008186 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008187
Ed Warnickecb9cada2015-12-08 15:45:58 -07008188 return 0;
8189
Dave Barach72d72232016-08-04 10:15:08 -04008190out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008191 *miss_next_indexp = next_index;
8192 return 1;
8193}
8194
8195#define foreach_acl_next \
8196_(deny, DENY)
8197
Dave Barach72d72232016-08-04 10:15:08 -04008198uword
8199unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008200{
Dave Barach72d72232016-08-04 10:15:08 -04008201 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008202 u32 next_index = 0;
8203 u32 tmp;
8204
8205#define _(n,N) \
8206 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8207 foreach_acl_next;
8208#undef _
8209
8210 if (unformat (input, "permit"))
8211 {
8212 next_index = ~0;
8213 goto out;
8214 }
8215 else if (unformat (input, "%d", &tmp))
8216 {
8217 next_index = tmp;
8218 goto out;
8219 }
8220
8221 return 0;
8222
Dave Barach72d72232016-08-04 10:15:08 -04008223out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008224 *miss_next_indexp = next_index;
8225 return 1;
8226}
8227
Dave Barach72d72232016-08-04 10:15:08 -04008228uword
8229unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008230{
Dave Barach72d72232016-08-04 10:15:08 -04008231 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008232
8233 if (unformat (input, "conform-color"))
8234 *r = POLICE_CONFORM;
8235 else if (unformat (input, "exceed-color"))
8236 *r = POLICE_EXCEED;
8237 else
8238 return 0;
8239
8240 return 1;
8241}
8242
Dave Barach72d72232016-08-04 10:15:08 -04008243static int
8244api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008245{
Dave Barach72d72232016-08-04 10:15:08 -04008246 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008247 vl_api_classify_add_del_table_t *mp;
8248
8249 u32 nbuckets = 2;
8250 u32 skip = ~0;
8251 u32 match = ~0;
8252 int is_add = 1;
8253 u32 table_index = ~0;
8254 u32 next_table_index = ~0;
8255 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008256 u32 memory_size = 32 << 20;
8257 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008258 f64 timeout;
8259
Dave Barach72d72232016-08-04 10:15:08 -04008260 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8261 {
8262 if (unformat (i, "del"))
8263 is_add = 0;
8264 else if (unformat (i, "buckets %d", &nbuckets))
8265 ;
8266 else if (unformat (i, "memory_size %d", &memory_size))
8267 ;
8268 else if (unformat (i, "skip %d", &skip))
8269 ;
8270 else if (unformat (i, "match %d", &match))
8271 ;
8272 else if (unformat (i, "table %d", &table_index))
8273 ;
8274 else if (unformat (i, "mask %U", unformat_classify_mask,
8275 &mask, &skip, &match))
8276 ;
8277 else if (unformat (i, "next-table %d", &next_table_index))
8278 ;
8279 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8280 &miss_next_index))
8281 ;
8282 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8283 &miss_next_index))
8284 ;
8285 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8286 &miss_next_index))
8287 ;
8288 else
8289 break;
8290 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008291
Dave Barach72d72232016-08-04 10:15:08 -04008292 if (is_add && mask == 0)
8293 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008294 errmsg ("Mask required\n");
8295 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008296 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008297
Dave Barach72d72232016-08-04 10:15:08 -04008298 if (is_add && skip == ~0)
8299 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008300 errmsg ("skip count required\n");
8301 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008302 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008303
Dave Barach72d72232016-08-04 10:15:08 -04008304 if (is_add && match == ~0)
8305 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008306 errmsg ("match count required\n");
8307 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008308 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008309
Dave Barach72d72232016-08-04 10:15:08 -04008310 if (!is_add && table_index == ~0)
8311 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008312 errmsg ("table index required for delete\n");
8313 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008314 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008315
Dave Barach72d72232016-08-04 10:15:08 -04008316 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008317
8318 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008319 mp->table_index = ntohl (table_index);
8320 mp->nbuckets = ntohl (nbuckets);
8321 mp->memory_size = ntohl (memory_size);
8322 mp->skip_n_vectors = ntohl (skip);
8323 mp->match_n_vectors = ntohl (match);
8324 mp->next_table_index = ntohl (next_table_index);
8325 mp->miss_next_index = ntohl (miss_next_index);
8326 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008327
Dave Barach72d72232016-08-04 10:15:08 -04008328 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008329
Dave Barach72d72232016-08-04 10:15:08 -04008330 S;
8331 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008332 /* NOTREACHED */
8333}
8334
Dave Barach72d72232016-08-04 10:15:08 -04008335uword
8336unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008337{
Dave Barach72d72232016-08-04 10:15:08 -04008338 u8 **matchp = va_arg (*args, u8 **);
8339 u8 *match = 0;
8340 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008341 int version = 0;
8342 u32 version_val;
8343 int hdr_length = 0;
8344 u32 hdr_length_val;
8345 int src = 0, dst = 0;
8346 ip4_address_t src_val, dst_val;
8347 int proto = 0;
8348 u32 proto_val;
8349 int tos = 0;
8350 u32 tos_val;
8351 int length = 0;
8352 u32 length_val;
8353 int fragment_id = 0;
8354 u32 fragment_id_val;
8355 int ttl = 0;
8356 int ttl_val;
8357 int checksum = 0;
8358 u32 checksum_val;
8359
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008360 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008361 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008362 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008363 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008364 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008365 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008366 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008367 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008368 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008369 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008370 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008371 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008372 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04008373 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008374 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008375 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008376 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04008377 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008378 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04008379 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008380 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04008381 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008382 else
Dave Barach72d72232016-08-04 10:15:08 -04008383 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008384 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008385
Ed Warnickecb9cada2015-12-08 15:45:58 -07008386 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8387 + ttl + checksum == 0)
8388 return 0;
8389
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008390 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008391 * Aligned because we use the real comparison functions
8392 */
Dave Barach72d72232016-08-04 10:15:08 -04008393 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008394
Ed Warnickecb9cada2015-12-08 15:45:58 -07008395 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008396
Ed Warnickecb9cada2015-12-08 15:45:58 -07008397 /* These are realistically matched in practice */
8398 if (src)
8399 ip->src_address.as_u32 = src_val.as_u32;
8400
8401 if (dst)
8402 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008403
Ed Warnickecb9cada2015-12-08 15:45:58 -07008404 if (proto)
8405 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008406
Ed Warnickecb9cada2015-12-08 15:45:58 -07008407
8408 /* These are not, but they're included for completeness */
8409 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04008410 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008411
8412 if (hdr_length)
8413 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008414
Ed Warnickecb9cada2015-12-08 15:45:58 -07008415 if (tos)
8416 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008417
Ed Warnickecb9cada2015-12-08 15:45:58 -07008418 if (length)
8419 ip->length = length_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008420
Ed Warnickecb9cada2015-12-08 15:45:58 -07008421 if (ttl)
8422 ip->ttl = ttl_val;
8423
8424 if (checksum)
8425 ip->checksum = checksum_val;
8426
8427 *matchp = match;
8428 return 1;
8429}
8430
Dave Barach72d72232016-08-04 10:15:08 -04008431uword
8432unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008433{
Dave Barach72d72232016-08-04 10:15:08 -04008434 u8 **matchp = va_arg (*args, u8 **);
8435 u8 *match = 0;
8436 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008437 int version = 0;
8438 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04008439 u8 traffic_class = 0;
8440 u32 traffic_class_val = 0;
8441 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008442 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008443 int src = 0, dst = 0;
8444 ip6_address_t src_val, dst_val;
8445 int proto = 0;
8446 u32 proto_val;
8447 int payload_length = 0;
8448 u32 payload_length_val;
8449 int hop_limit = 0;
8450 int hop_limit_val;
8451 u32 ip_version_traffic_class_and_flow_label;
8452
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008453 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008454 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008455 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008456 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008457 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04008458 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008459 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04008460 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008461 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008462 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008463 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008464 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008465 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008466 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008467 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008468 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008469 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04008470 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008471 else
Dave Barach72d72232016-08-04 10:15:08 -04008472 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008473 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008474
Ed Warnickecb9cada2015-12-08 15:45:58 -07008475 if (version + traffic_class + flow_label + src + dst + proto +
8476 payload_length + hop_limit == 0)
8477 return 0;
8478
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008479 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008480 * Aligned because we use the real comparison functions
8481 */
Dave Barach72d72232016-08-04 10:15:08 -04008482 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008483
Ed Warnickecb9cada2015-12-08 15:45:58 -07008484 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008485
Ed Warnickecb9cada2015-12-08 15:45:58 -07008486 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01008487 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008488
8489 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01008490 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008491
Ed Warnickecb9cada2015-12-08 15:45:58 -07008492 if (proto)
8493 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008494
Ed Warnickecb9cada2015-12-08 15:45:58 -07008495 ip_version_traffic_class_and_flow_label = 0;
8496
8497 if (version)
8498 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8499
8500 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04008501 ip_version_traffic_class_and_flow_label |=
8502 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008503
8504 if (flow_label)
8505 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008506
8507 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008508 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8509
8510 if (payload_length)
8511 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008512
Ed Warnickecb9cada2015-12-08 15:45:58 -07008513 if (hop_limit)
8514 ip->hop_limit = hop_limit_val;
8515
8516 *matchp = match;
8517 return 1;
8518}
8519
Dave Barach72d72232016-08-04 10:15:08 -04008520uword
8521unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008522{
Dave Barach72d72232016-08-04 10:15:08 -04008523 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008524
Dave Barach72d72232016-08-04 10:15:08 -04008525 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8526 {
8527 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8528 return 1;
8529 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8530 return 1;
8531 else
8532 break;
8533 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008534 return 0;
8535}
8536
Dave Barach72d72232016-08-04 10:15:08 -04008537uword
8538unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008539{
Dave Barach72d72232016-08-04 10:15:08 -04008540 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008541 u32 tag;
8542
Dave Barach72d72232016-08-04 10:15:08 -04008543 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07008544 {
Dave Barach72d72232016-08-04 10:15:08 -04008545 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008546 tagp[1] = tag & 0xFF;
8547 return 1;
8548 }
8549
8550 return 0;
8551}
8552
Dave Barach72d72232016-08-04 10:15:08 -04008553uword
8554unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008555{
Dave Barach72d72232016-08-04 10:15:08 -04008556 u8 **matchp = va_arg (*args, u8 **);
8557 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008558 u8 src = 0;
8559 u8 src_val[6];
8560 u8 dst = 0;
8561 u8 dst_val[6];
8562 u8 proto = 0;
8563 u16 proto_val;
8564 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008565 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008566 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008567 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008568 int len = 14;
8569 u8 ignore_tag1 = 0;
8570 u8 ignore_tag2 = 0;
8571 u8 cos1 = 0;
8572 u8 cos2 = 0;
8573 u32 cos1_val = 0;
8574 u32 cos2_val = 0;
8575
Dave Barach72d72232016-08-04 10:15:08 -04008576 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8577 {
8578 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8579 src = 1;
8580 else
8581 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8582 dst = 1;
8583 else if (unformat (input, "proto %U",
8584 unformat_ethernet_type_host_byte_order, &proto_val))
8585 proto = 1;
8586 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8587 tag1 = 1;
8588 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8589 tag2 = 1;
8590 else if (unformat (input, "ignore-tag1"))
8591 ignore_tag1 = 1;
8592 else if (unformat (input, "ignore-tag2"))
8593 ignore_tag2 = 1;
8594 else if (unformat (input, "cos1 %d", &cos1_val))
8595 cos1 = 1;
8596 else if (unformat (input, "cos2 %d", &cos2_val))
8597 cos2 = 1;
8598 else
8599 break;
8600 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008601 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04008602 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008603 return 0;
8604
8605 if (tag1 || ignore_tag1 || cos1)
8606 len = 18;
8607 if (tag2 || ignore_tag2 || cos2)
8608 len = 22;
8609
Dave Barach72d72232016-08-04 10:15:08 -04008610 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008611
8612 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01008613 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008614
8615 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01008616 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008617
Ed Warnickecb9cada2015-12-08 15:45:58 -07008618 if (tag2)
8619 {
8620 /* inner vlan tag */
8621 match[19] = tag2_val[1];
8622 match[18] = tag2_val[0];
8623 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008624 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008625 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008626 {
8627 match[21] = proto_val & 0xff;
8628 match[20] = proto_val >> 8;
8629 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008630 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008631 {
8632 match[15] = tag1_val[1];
8633 match[14] = tag1_val[0];
8634 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008635 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008636 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008637 *matchp = match;
8638 return 1;
8639 }
8640 if (tag1)
8641 {
Dave Barach72d72232016-08-04 10:15:08 -04008642 match[15] = tag1_val[1];
8643 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008644 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008645 {
8646 match[17] = proto_val & 0xff;
8647 match[16] = proto_val >> 8;
8648 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008649 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008650 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008651
8652 *matchp = match;
8653 return 1;
8654 }
8655 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008656 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008657 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008658 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008659 if (proto)
8660 {
8661 match[13] = proto_val & 0xff;
8662 match[12] = proto_val >> 8;
8663 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008664
Ed Warnickecb9cada2015-12-08 15:45:58 -07008665 *matchp = match;
8666 return 1;
8667}
8668
8669
Dave Barach72d72232016-08-04 10:15:08 -04008670uword
8671unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008672{
Dave Barach72d72232016-08-04 10:15:08 -04008673 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008674 u32 skip_n_vectors = va_arg (*args, u32);
8675 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008676
Dave Barach72d72232016-08-04 10:15:08 -04008677 u8 *match = 0;
8678 u8 *l2 = 0;
8679 u8 *l3 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008680
Dave Barach72d72232016-08-04 10:15:08 -04008681 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8682 {
8683 if (unformat (input, "hex %U", unformat_hex_string, &match))
8684 ;
8685 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8686 ;
8687 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8688 ;
8689 else
8690 break;
8691 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008692
8693 if (match || l2 || l3)
8694 {
8695 if (l2 || l3)
Dave Barach72d72232016-08-04 10:15:08 -04008696 {
8697 /* "Win a free Ethernet header in every packet" */
8698 if (l2 == 0)
8699 vec_validate_aligned (l2, 13, sizeof (u32x4));
8700 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008701 if (vec_len (l3))
8702 {
8703 vec_append_aligned (match, l3, sizeof (u32x4));
8704 vec_free (l3);
8705 }
Dave Barach72d72232016-08-04 10:15:08 -04008706 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008707
8708 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008709 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04008710 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8711 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008712
Dave Barach72d72232016-08-04 10:15:08 -04008713 /* Set size, include skipped vectors */
8714 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008715
8716 *matchp = match;
8717
8718 return 1;
8719 }
8720
8721 return 0;
8722}
8723
Dave Barach72d72232016-08-04 10:15:08 -04008724static int
8725api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008726{
Dave Barach72d72232016-08-04 10:15:08 -04008727 unformat_input_t *i = vam->input;
8728 vl_api_classify_add_del_session_t *mp;
8729 int is_add = 1;
8730 u32 table_index = ~0;
8731 u32 hit_next_index = ~0;
8732 u32 opaque_index = ~0;
8733 u8 *match = 0;
8734 i32 advance = 0;
8735 f64 timeout;
8736 u32 skip_n_vectors = 0;
8737 u32 match_n_vectors = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008738
Dave Barach72d72232016-08-04 10:15:08 -04008739 /*
8740 * Warning: you have to supply skip_n and match_n
8741 * because the API client cant simply look at the classify
8742 * table object.
8743 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07008744
Dave Barach72d72232016-08-04 10:15:08 -04008745 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8746 {
8747 if (unformat (i, "del"))
8748 is_add = 0;
8749 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
8750 &hit_next_index))
8751 ;
8752 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8753 &hit_next_index))
8754 ;
8755 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
8756 &hit_next_index))
8757 ;
8758 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8759 ;
8760 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8761 ;
8762 else if (unformat (i, "opaque-index %d", &opaque_index))
8763 ;
8764 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8765 ;
8766 else if (unformat (i, "match_n %d", &match_n_vectors))
8767 ;
8768 else if (unformat (i, "match %U", unformat_classify_match,
8769 &match, skip_n_vectors, match_n_vectors))
8770 ;
8771 else if (unformat (i, "advance %d", &advance))
8772 ;
8773 else if (unformat (i, "table-index %d", &table_index))
8774 ;
8775 else
8776 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008777 }
8778
Dave Barach72d72232016-08-04 10:15:08 -04008779 if (table_index == ~0)
8780 {
8781 errmsg ("Table index required\n");
8782 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008783 }
8784
Dave Barach72d72232016-08-04 10:15:08 -04008785 if (is_add && match == 0)
8786 {
8787 errmsg ("Match value required\n");
8788 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008789 }
8790
Dave Barach72d72232016-08-04 10:15:08 -04008791 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008792
Dave Barach72d72232016-08-04 10:15:08 -04008793 mp->is_add = is_add;
8794 mp->table_index = ntohl (table_index);
8795 mp->hit_next_index = ntohl (hit_next_index);
8796 mp->opaque_index = ntohl (opaque_index);
8797 mp->advance = ntohl (advance);
8798 clib_memcpy (mp->match, match, vec_len (match));
8799 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008800
Dave Barach72d72232016-08-04 10:15:08 -04008801 S;
8802 W;
8803 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07008804}
8805
Dave Barach72d72232016-08-04 10:15:08 -04008806static int
8807api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008808{
Dave Barach72d72232016-08-04 10:15:08 -04008809 unformat_input_t *i = vam->input;
8810 vl_api_classify_set_interface_ip_table_t *mp;
8811 f64 timeout;
8812 u32 sw_if_index;
8813 int sw_if_index_set;
8814 u32 table_index = ~0;
8815 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008816
Dave Barach72d72232016-08-04 10:15:08 -04008817 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8818 {
8819 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8820 sw_if_index_set = 1;
8821 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8822 sw_if_index_set = 1;
8823 else if (unformat (i, "table %d", &table_index))
8824 ;
8825 else
8826 {
8827 clib_warning ("parse error '%U'", format_unformat_error, i);
8828 return -99;
8829 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008830 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008831
Dave Barach72d72232016-08-04 10:15:08 -04008832 if (sw_if_index_set == 0)
8833 {
8834 errmsg ("missing interface name or sw_if_index\n");
8835 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008836 }
8837
8838
Dave Barach72d72232016-08-04 10:15:08 -04008839 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008840
Dave Barach72d72232016-08-04 10:15:08 -04008841 mp->sw_if_index = ntohl (sw_if_index);
8842 mp->table_index = ntohl (table_index);
8843 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008844
Dave Barach72d72232016-08-04 10:15:08 -04008845 S;
8846 W;
8847 /* NOTREACHED */
8848 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008849}
8850
Dave Barach72d72232016-08-04 10:15:08 -04008851static int
8852api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008853{
Dave Barach72d72232016-08-04 10:15:08 -04008854 unformat_input_t *i = vam->input;
8855 vl_api_classify_set_interface_l2_tables_t *mp;
8856 f64 timeout;
8857 u32 sw_if_index;
8858 int sw_if_index_set;
8859 u32 ip4_table_index = ~0;
8860 u32 ip6_table_index = ~0;
8861 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04008862 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008863
Dave Barach72d72232016-08-04 10:15:08 -04008864 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8865 {
8866 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8867 sw_if_index_set = 1;
8868 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8869 sw_if_index_set = 1;
8870 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8871 ;
8872 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8873 ;
8874 else if (unformat (i, "other-table %d", &other_table_index))
8875 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04008876 else if (unformat (i, "is-input %d", &is_input))
8877 ;
Dave Barach72d72232016-08-04 10:15:08 -04008878 else
8879 {
8880 clib_warning ("parse error '%U'", format_unformat_error, i);
8881 return -99;
8882 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008883 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008884
Dave Barach72d72232016-08-04 10:15:08 -04008885 if (sw_if_index_set == 0)
8886 {
8887 errmsg ("missing interface name or sw_if_index\n");
8888 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008889 }
8890
8891
Dave Barach72d72232016-08-04 10:15:08 -04008892 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008893
Dave Barach72d72232016-08-04 10:15:08 -04008894 mp->sw_if_index = ntohl (sw_if_index);
8895 mp->ip4_table_index = ntohl (ip4_table_index);
8896 mp->ip6_table_index = ntohl (ip6_table_index);
8897 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04008898 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008899
Dave Barach72d72232016-08-04 10:15:08 -04008900 S;
8901 W;
8902 /* NOTREACHED */
8903 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008904}
8905
Dave Barach72d72232016-08-04 10:15:08 -04008906static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008907api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008908{
Dave Barach72d72232016-08-04 10:15:08 -04008909 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008910 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04008911 ip4_address_t collector_address;
8912 u8 collector_address_set = 0;
8913 u32 collector_port = ~0;
8914 ip4_address_t src_address;
8915 u8 src_address_set = 0;
8916 u32 vrf_id = ~0;
8917 u32 path_mtu = ~0;
8918 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008919 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008920 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008921
Dave Barach72d72232016-08-04 10:15:08 -04008922 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8923 {
8924 if (unformat (i, "collector_address %U", unformat_ip4_address,
8925 &collector_address))
8926 collector_address_set = 1;
8927 else if (unformat (i, "collector_port %d", &collector_port))
8928 ;
8929 else if (unformat (i, "src_address %U", unformat_ip4_address,
8930 &src_address))
8931 src_address_set = 1;
8932 else if (unformat (i, "vrf_id %d", &vrf_id))
8933 ;
8934 else if (unformat (i, "path_mtu %d", &path_mtu))
8935 ;
8936 else if (unformat (i, "template_interval %d", &template_interval))
8937 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008938 else if (unformat (i, "udp_checksum"))
8939 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04008940 else
8941 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008942 }
8943
Dave Barach72d72232016-08-04 10:15:08 -04008944 if (collector_address_set == 0)
8945 {
8946 errmsg ("collector_address required\n");
8947 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008948 }
8949
Dave Barach72d72232016-08-04 10:15:08 -04008950 if (src_address_set == 0)
8951 {
8952 errmsg ("src_address required\n");
8953 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008954 }
8955
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008956 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008957
Dave Barach72d72232016-08-04 10:15:08 -04008958 memcpy (mp->collector_address, collector_address.data,
8959 sizeof (collector_address.data));
8960 mp->collector_port = htons ((u16) collector_port);
8961 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
8962 mp->vrf_id = htonl (vrf_id);
8963 mp->path_mtu = htonl (path_mtu);
8964 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008965 mp->udp_checksum = udp_checksum;
8966
8967 S;
8968 W;
8969 /* NOTREACHED */
8970}
8971
8972static int
8973api_set_ipfix_classify_stream (vat_main_t * vam)
8974{
8975 unformat_input_t *i = vam->input;
8976 vl_api_set_ipfix_classify_stream_t *mp;
8977 u32 domain_id = 0;
8978 u32 src_port = UDP_DST_PORT_ipfix;
8979 f64 timeout;
8980
8981 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8982 {
8983 if (unformat (i, "domain %d", &domain_id))
8984 ;
8985 else if (unformat (i, "src_port %d", &src_port))
8986 ;
8987 else
8988 {
8989 errmsg ("unknown input `%U'", format_unformat_error, i);
8990 return -99;
8991 }
8992 }
8993
8994 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
8995
8996 mp->domain_id = htonl (domain_id);
8997 mp->src_port = htons ((u16) src_port);
8998
8999 S;
9000 W;
9001 /* NOTREACHED */
9002}
9003
9004static int
9005api_ipfix_classify_table_add_del (vat_main_t * vam)
9006{
9007 unformat_input_t *i = vam->input;
9008 vl_api_ipfix_classify_table_add_del_t *mp;
9009 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009010 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009011 u8 ip_version = 0;
9012 u8 transport_protocol = 255;
9013 f64 timeout;
9014
9015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9016 {
9017 if (unformat (i, "add"))
9018 is_add = 1;
9019 else if (unformat (i, "del"))
9020 is_add = 0;
9021 else if (unformat (i, "table %d", &classify_table_index))
9022 ;
9023 else if (unformat (i, "ip4"))
9024 ip_version = 4;
9025 else if (unformat (i, "ip6"))
9026 ip_version = 6;
9027 else if (unformat (i, "tcp"))
9028 transport_protocol = 6;
9029 else if (unformat (i, "udp"))
9030 transport_protocol = 17;
9031 else
9032 {
9033 errmsg ("unknown input `%U'", format_unformat_error, i);
9034 return -99;
9035 }
9036 }
9037
9038 if (is_add == -1)
9039 {
9040 errmsg ("expecting: add|del");
9041 return -99;
9042 }
9043 if (classify_table_index == ~0)
9044 {
9045 errmsg ("classifier table not specified");
9046 return -99;
9047 }
9048 if (ip_version == 0)
9049 {
9050 errmsg ("IP version not specified");
9051 return -99;
9052 }
9053
9054 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9055
9056 mp->is_add = is_add;
9057 mp->table_id = htonl (classify_table_index);
9058 mp->ip_version = ip_version;
9059 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009060
Dave Barach72d72232016-08-04 10:15:08 -04009061 S;
9062 W;
9063 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009064}
9065
Dave Barach72d72232016-08-04 10:15:08 -04009066static int
9067api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009068{
Dave Barach72d72232016-08-04 10:15:08 -04009069 unformat_input_t *i = vam->input;
9070 vl_api_get_node_index_t *mp;
9071 f64 timeout;
9072 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009073
Dave Barach72d72232016-08-04 10:15:08 -04009074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9075 {
9076 if (unformat (i, "node %s", &name))
9077 ;
9078 else
9079 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009080 }
Dave Barach72d72232016-08-04 10:15:08 -04009081 if (name == 0)
9082 {
9083 errmsg ("node name required\n");
9084 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009085 }
Dave Barach72d72232016-08-04 10:15:08 -04009086 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9087 {
9088 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9089 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009090 }
9091
Dave Barach72d72232016-08-04 10:15:08 -04009092 M (GET_NODE_INDEX, get_node_index);
9093 clib_memcpy (mp->node_name, name, vec_len (name));
9094 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009095
Dave Barach72d72232016-08-04 10:15:08 -04009096 S;
9097 W;
9098 /* NOTREACHED */
9099 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009100}
9101
Dave Barach72d72232016-08-04 10:15:08 -04009102static int
9103api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009104{
Dave Barach72d72232016-08-04 10:15:08 -04009105 unformat_input_t *i = vam->input;
9106 vl_api_get_next_index_t *mp;
9107 f64 timeout;
9108 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009109
Dave Barach72d72232016-08-04 10:15:08 -04009110 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9111 {
9112 if (unformat (i, "node-name %s", &node_name))
9113 ;
9114 else if (unformat (i, "next-node-name %s", &next_node_name))
9115 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009116 }
9117
Dave Barach72d72232016-08-04 10:15:08 -04009118 if (node_name == 0)
9119 {
9120 errmsg ("node name required\n");
9121 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009122 }
Dave Barach72d72232016-08-04 10:15:08 -04009123 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9124 {
9125 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9126 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009127 }
9128
Dave Barach72d72232016-08-04 10:15:08 -04009129 if (next_node_name == 0)
9130 {
9131 errmsg ("next node name required\n");
9132 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009133 }
Dave Barach72d72232016-08-04 10:15:08 -04009134 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9135 {
9136 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9137 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009138 }
9139
Dave Barach72d72232016-08-04 10:15:08 -04009140 M (GET_NEXT_INDEX, get_next_index);
9141 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9142 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9143 vec_free (node_name);
9144 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009145
Dave Barach72d72232016-08-04 10:15:08 -04009146 S;
9147 W;
9148 /* NOTREACHED */
9149 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009150}
9151
Dave Barach72d72232016-08-04 10:15:08 -04009152static int
9153api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009154{
Dave Barach72d72232016-08-04 10:15:08 -04009155 unformat_input_t *i = vam->input;
9156 vl_api_add_node_next_t *mp;
9157 f64 timeout;
9158 u8 *name = 0;
9159 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009160
Dave Barach72d72232016-08-04 10:15:08 -04009161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9162 {
9163 if (unformat (i, "node %s", &name))
9164 ;
9165 else if (unformat (i, "next %s", &next))
9166 ;
9167 else
9168 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009169 }
Dave Barach72d72232016-08-04 10:15:08 -04009170 if (name == 0)
9171 {
9172 errmsg ("node name required\n");
9173 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009174 }
Dave Barach72d72232016-08-04 10:15:08 -04009175 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9176 {
9177 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9178 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009179 }
Dave Barach72d72232016-08-04 10:15:08 -04009180 if (next == 0)
9181 {
9182 errmsg ("next node required\n");
9183 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009184 }
Dave Barach72d72232016-08-04 10:15:08 -04009185 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9186 {
9187 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9188 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009189 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009190
Dave Barach72d72232016-08-04 10:15:08 -04009191 M (ADD_NODE_NEXT, add_node_next);
9192 clib_memcpy (mp->node_name, name, vec_len (name));
9193 clib_memcpy (mp->next_name, next, vec_len (next));
9194 vec_free (name);
9195 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009196
Dave Barach72d72232016-08-04 10:15:08 -04009197 S;
9198 W;
9199 /* NOTREACHED */
9200 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009201}
9202
Dave Barach72d72232016-08-04 10:15:08 -04009203static int
9204api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009205{
Dave Barach72d72232016-08-04 10:15:08 -04009206 unformat_input_t *i = vam->input;
9207 ip6_address_t client_address, our_address;
9208 int client_address_set = 0;
9209 int our_address_set = 0;
9210 u32 local_session_id = 0;
9211 u32 remote_session_id = 0;
9212 u64 local_cookie = 0;
9213 u64 remote_cookie = 0;
9214 u8 l2_sublayer_present = 0;
9215 vl_api_l2tpv3_create_tunnel_t *mp;
9216 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009217
Dave Barach72d72232016-08-04 10:15:08 -04009218 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9219 {
9220 if (unformat (i, "client_address %U", unformat_ip6_address,
9221 &client_address))
9222 client_address_set = 1;
9223 else if (unformat (i, "our_address %U", unformat_ip6_address,
9224 &our_address))
9225 our_address_set = 1;
9226 else if (unformat (i, "local_session_id %d", &local_session_id))
9227 ;
9228 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9229 ;
9230 else if (unformat (i, "local_cookie %lld", &local_cookie))
9231 ;
9232 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9233 ;
9234 else if (unformat (i, "l2-sublayer-present"))
9235 l2_sublayer_present = 1;
9236 else
9237 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009238 }
9239
Dave Barach72d72232016-08-04 10:15:08 -04009240 if (client_address_set == 0)
9241 {
9242 errmsg ("client_address required\n");
9243 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009244 }
9245
Dave Barach72d72232016-08-04 10:15:08 -04009246 if (our_address_set == 0)
9247 {
9248 errmsg ("our_address required\n");
9249 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009250 }
9251
Dave Barach72d72232016-08-04 10:15:08 -04009252 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009253
Dave Barach72d72232016-08-04 10:15:08 -04009254 clib_memcpy (mp->client_address, client_address.as_u8,
9255 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009256
Dave Barach72d72232016-08-04 10:15:08 -04009257 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009258
Dave Barach72d72232016-08-04 10:15:08 -04009259 mp->local_session_id = ntohl (local_session_id);
9260 mp->remote_session_id = ntohl (remote_session_id);
9261 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9262 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9263 mp->l2_sublayer_present = l2_sublayer_present;
9264 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009265
Dave Barach72d72232016-08-04 10:15:08 -04009266 S;
9267 W;
9268 /* NOTREACHED */
9269 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009270}
9271
Dave Barach72d72232016-08-04 10:15:08 -04009272static int
9273api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009274{
Dave Barach72d72232016-08-04 10:15:08 -04009275 unformat_input_t *i = vam->input;
9276 u32 sw_if_index;
9277 u8 sw_if_index_set = 0;
9278 u64 new_local_cookie = 0;
9279 u64 new_remote_cookie = 0;
9280 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9281 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009282
Dave Barach72d72232016-08-04 10:15:08 -04009283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9284 {
9285 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9286 sw_if_index_set = 1;
9287 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9288 sw_if_index_set = 1;
9289 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9290 ;
9291 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
9292 ;
9293 else
9294 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009295 }
9296
Dave Barach72d72232016-08-04 10:15:08 -04009297 if (sw_if_index_set == 0)
9298 {
9299 errmsg ("missing interface name or sw_if_index\n");
9300 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009301 }
9302
Dave Barach72d72232016-08-04 10:15:08 -04009303 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009304
Dave Barach72d72232016-08-04 10:15:08 -04009305 mp->sw_if_index = ntohl (sw_if_index);
9306 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
9307 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009308
Dave Barach72d72232016-08-04 10:15:08 -04009309 S;
9310 W;
9311 /* NOTREACHED */
9312 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009313}
9314
Dave Barach72d72232016-08-04 10:15:08 -04009315static int
9316api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009317{
Dave Barach72d72232016-08-04 10:15:08 -04009318 unformat_input_t *i = vam->input;
9319 vl_api_l2tpv3_interface_enable_disable_t *mp;
9320 f64 timeout;
9321 u32 sw_if_index;
9322 u8 sw_if_index_set = 0;
9323 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009324
Dave Barach72d72232016-08-04 10:15:08 -04009325 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9326 {
9327 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9328 sw_if_index_set = 1;
9329 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9330 sw_if_index_set = 1;
9331 else if (unformat (i, "enable"))
9332 enable_disable = 1;
9333 else if (unformat (i, "disable"))
9334 enable_disable = 0;
9335 else
9336 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009337 }
9338
Dave Barach72d72232016-08-04 10:15:08 -04009339 if (sw_if_index_set == 0)
9340 {
9341 errmsg ("missing interface name or sw_if_index\n");
9342 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009343 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009344
Dave Barach72d72232016-08-04 10:15:08 -04009345 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009346
Dave Barach72d72232016-08-04 10:15:08 -04009347 mp->sw_if_index = ntohl (sw_if_index);
9348 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009349
Dave Barach72d72232016-08-04 10:15:08 -04009350 S;
9351 W;
9352 /* NOTREACHED */
9353 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009354}
9355
Dave Barach72d72232016-08-04 10:15:08 -04009356static int
9357api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009358{
Dave Barach72d72232016-08-04 10:15:08 -04009359 unformat_input_t *i = vam->input;
9360 vl_api_l2tpv3_set_lookup_key_t *mp;
9361 f64 timeout;
9362 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009363
Dave Barach72d72232016-08-04 10:15:08 -04009364 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9365 {
9366 if (unformat (i, "lookup_v6_src"))
9367 key = L2T_LOOKUP_SRC_ADDRESS;
9368 else if (unformat (i, "lookup_v6_dst"))
9369 key = L2T_LOOKUP_DST_ADDRESS;
9370 else if (unformat (i, "lookup_session_id"))
9371 key = L2T_LOOKUP_SESSION_ID;
9372 else
9373 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009374 }
9375
Dave Barach72d72232016-08-04 10:15:08 -04009376 if (key == (u8) ~ 0)
9377 {
9378 errmsg ("l2tp session lookup key unset\n");
9379 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009380 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009381
Dave Barach72d72232016-08-04 10:15:08 -04009382 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009383
Dave Barach72d72232016-08-04 10:15:08 -04009384 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009385
Dave Barach72d72232016-08-04 10:15:08 -04009386 S;
9387 W;
9388 /* NOTREACHED */
9389 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009390}
9391
9392static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009393 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009394{
Dave Barach72d72232016-08-04 10:15:08 -04009395 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009396
Dave Barach72d72232016-08-04 10:15:08 -04009397 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
9398 format_ip6_address, mp->our_address,
9399 format_ip6_address, mp->client_address,
9400 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009401
Dave Barach72d72232016-08-04 10:15:08 -04009402 fformat (vam->ofp,
9403 " local cookies %016llx %016llx remote cookie %016llx\n",
9404 clib_net_to_host_u64 (mp->local_cookie[0]),
9405 clib_net_to_host_u64 (mp->local_cookie[1]),
9406 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009407
Dave Barach72d72232016-08-04 10:15:08 -04009408 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
9409 clib_net_to_host_u32 (mp->local_session_id),
9410 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009411
Dave Barach72d72232016-08-04 10:15:08 -04009412 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
9413 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009414
9415}
9416
9417static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009418 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009419{
Dave Barach72d72232016-08-04 10:15:08 -04009420 vat_main_t *vam = &vat_main;
9421 vat_json_node_t *node = NULL;
9422 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009423
Dave Barach72d72232016-08-04 10:15:08 -04009424 if (VAT_JSON_ARRAY != vam->json_tree.type)
9425 {
9426 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9427 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009428 }
Dave Barach72d72232016-08-04 10:15:08 -04009429 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009430
Dave Barach72d72232016-08-04 10:15:08 -04009431 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009432
Dave Barach72d72232016-08-04 10:15:08 -04009433 clib_memcpy (&addr, mp->our_address, sizeof (addr));
9434 vat_json_object_add_ip6 (node, "our_address", addr);
9435 clib_memcpy (&addr, mp->client_address, sizeof (addr));
9436 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009437
Dave Barach72d72232016-08-04 10:15:08 -04009438 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
9439 vat_json_init_array (lc);
9440 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
9441 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
9442 vat_json_object_add_uint (node, "remote_cookie",
9443 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009444
Dave Barach72d72232016-08-04 10:15:08 -04009445 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
9446 vat_json_object_add_uint (node, "local_session_id",
9447 clib_net_to_host_u32 (mp->local_session_id));
9448 vat_json_object_add_uint (node, "remote_session_id",
9449 clib_net_to_host_u32 (mp->remote_session_id));
9450 vat_json_object_add_string_copy (node, "l2_sublayer",
9451 mp->l2_sublayer_present ? (u8 *) "present"
9452 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009453}
9454
Dave Barach72d72232016-08-04 10:15:08 -04009455static int
9456api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009457{
Dave Barach72d72232016-08-04 10:15:08 -04009458 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
9459 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009460
Dave Barach72d72232016-08-04 10:15:08 -04009461 /* Get list of l2tpv3-tunnel interfaces */
9462 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
9463 S;
9464
9465 /* Use a control ping for synchronization */
9466 {
9467 vl_api_control_ping_t *mp;
9468 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009469 S;
Dave Barach72d72232016-08-04 10:15:08 -04009470 }
9471 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009472}
9473
9474
9475static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009476 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009477{
Dave Barach72d72232016-08-04 10:15:08 -04009478 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009479
Dave Barach72d72232016-08-04 10:15:08 -04009480 fformat (vam->ofp, "%-16s %d\n",
9481 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009482}
9483
9484static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009485 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009486{
Dave Barach72d72232016-08-04 10:15:08 -04009487 vat_main_t *vam = &vat_main;
9488 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009489
Dave Barach72d72232016-08-04 10:15:08 -04009490 if (VAT_JSON_ARRAY != vam->json_tree.type)
9491 {
9492 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9493 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009494 }
Dave Barach72d72232016-08-04 10:15:08 -04009495 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009496
Dave Barach72d72232016-08-04 10:15:08 -04009497 vat_json_init_object (node);
9498 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9499 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009500}
9501
Dave Barach72d72232016-08-04 10:15:08 -04009502static int
9503api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009504{
Dave Barach72d72232016-08-04 10:15:08 -04009505 vl_api_sw_interface_tap_dump_t *mp;
9506 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009507
Dave Barach72d72232016-08-04 10:15:08 -04009508 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
9509 /* Get list of tap interfaces */
9510 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
9511 S;
9512
9513 /* Use a control ping for synchronization */
9514 {
9515 vl_api_control_ping_t *mp;
9516 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009517 S;
Dave Barach72d72232016-08-04 10:15:08 -04009518 }
9519 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009520}
9521
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009522static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -04009523 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009524{
Dave Barach72d72232016-08-04 10:15:08 -04009525 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009526 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009527
Ed Warnickecb9cada2015-12-08 15:45:58 -07009528 if (unformat (input, "drop"))
9529 *result = VXLAN_INPUT_NEXT_DROP;
9530 else if (unformat (input, "ip4"))
9531 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
9532 else if (unformat (input, "ip6"))
9533 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
9534 else if (unformat (input, "l2"))
9535 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9536 else if (unformat (input, "%d", &tmp))
9537 *result = tmp;
9538 else
9539 return 0;
9540 return 1;
9541}
9542
Dave Barach72d72232016-08-04 10:15:08 -04009543static int
9544api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009545{
Dave Barach72d72232016-08-04 10:15:08 -04009546 unformat_input_t *line_input = vam->input;
9547 vl_api_vxlan_add_del_tunnel_t *mp;
9548 f64 timeout;
9549 ip4_address_t src4, dst4;
9550 ip6_address_t src6, dst6;
9551 u8 is_add = 1;
9552 u8 ipv4_set = 0, ipv6_set = 0;
9553 u8 src_set = 0;
9554 u8 dst_set = 0;
9555 u32 encap_vrf_id = 0;
9556 u32 decap_next_index = ~0;
9557 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009558
Dave Barach72d72232016-08-04 10:15:08 -04009559 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9560 {
9561 if (unformat (line_input, "del"))
9562 is_add = 0;
9563 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
9564 {
9565 ipv4_set = 1;
9566 src_set = 1;
9567 }
9568 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
9569 {
9570 ipv4_set = 1;
9571 dst_set = 1;
9572 }
9573 else if (unformat (line_input, "src %U", unformat_ip6_address, &src6))
9574 {
9575 ipv6_set = 1;
9576 src_set = 1;
9577 }
9578 else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst6))
9579 {
9580 ipv6_set = 1;
9581 dst_set = 1;
9582 }
9583 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9584 ;
9585 else if (unformat (line_input, "decap-next %U",
9586 unformat_vxlan_decap_next, &decap_next_index))
9587 ;
9588 else if (unformat (line_input, "vni %d", &vni))
9589 ;
9590 else
9591 {
9592 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9593 return -99;
9594 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009595 }
9596
Dave Barach72d72232016-08-04 10:15:08 -04009597 if (src_set == 0)
9598 {
9599 errmsg ("tunnel src address not specified\n");
9600 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009601 }
Dave Barach72d72232016-08-04 10:15:08 -04009602 if (dst_set == 0)
9603 {
9604 errmsg ("tunnel dst address not specified\n");
9605 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009606 }
9607
Dave Barach72d72232016-08-04 10:15:08 -04009608 if (ipv4_set && ipv6_set)
9609 {
9610 errmsg ("both IPv4 and IPv6 addresses specified");
9611 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -04009612 }
9613
Dave Barach72d72232016-08-04 10:15:08 -04009614 if ((vni == 0) || (vni >> 24))
9615 {
9616 errmsg ("vni not specified or out of range\n");
9617 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009618 }
9619
Dave Barach72d72232016-08-04 10:15:08 -04009620 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -04009621
Dave Barach72d72232016-08-04 10:15:08 -04009622 if (ipv6_set)
9623 {
9624 clib_memcpy (&mp->src_address, &src6, sizeof (src6));
9625 clib_memcpy (&mp->dst_address, &dst6, sizeof (dst6));
Chris Luke99cb3352016-04-26 10:49:53 -04009626 }
Dave Barach72d72232016-08-04 10:15:08 -04009627 else
9628 {
9629 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
9630 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
9631 }
9632 mp->encap_vrf_id = ntohl (encap_vrf_id);
9633 mp->decap_next_index = ntohl (decap_next_index);
9634 mp->vni = ntohl (vni);
9635 mp->is_add = is_add;
9636 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009637
Dave Barach72d72232016-08-04 10:15:08 -04009638 S;
9639 W;
9640 /* NOTREACHED */
9641 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009642}
9643
Dave Wallace60231f32015-12-17 21:04:30 -05009644static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009645 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -05009646{
Dave Barach72d72232016-08-04 10:15:08 -04009647 vat_main_t *vam = &vat_main;
Dave Wallace60231f32015-12-17 21:04:30 -05009648
Dave Barach72d72232016-08-04 10:15:08 -04009649 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
9650 ntohl (mp->sw_if_index),
9651 format_ip46_address, &(mp->src_address[0]),
9652 IP46_TYPE_ANY,
9653 format_ip46_address, &(mp->dst_address[0]),
9654 IP46_TYPE_ANY,
9655 ntohl (mp->encap_vrf_id),
9656 ntohl (mp->decap_next_index), ntohl (mp->vni));
Dave Wallace60231f32015-12-17 21:04:30 -05009657}
9658
9659static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009660 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -05009661{
Dave Barach72d72232016-08-04 10:15:08 -04009662 vat_main_t *vam = &vat_main;
9663 vat_json_node_t *node = NULL;
9664 struct in_addr ip4;
9665 struct in6_addr ip6;
Dave Wallace60231f32015-12-17 21:04:30 -05009666
Dave Barach72d72232016-08-04 10:15:08 -04009667 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -05009668 {
Dave Barach72d72232016-08-04 10:15:08 -04009669 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9670 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -05009671 }
Dave Barach72d72232016-08-04 10:15:08 -04009672 node = vat_json_array_add (&vam->json_tree);
9673
9674 vat_json_init_object (node);
9675 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9676 if (mp->is_ipv6)
9677 {
9678 clib_memcpy (&ip6, &(mp->src_address[0]), sizeof (ip6));
9679 vat_json_object_add_ip6 (node, "src_address", ip6);
9680 clib_memcpy (&ip6, &(mp->dst_address[0]), sizeof (ip6));
9681 vat_json_object_add_ip6 (node, "dst_address", ip6);
9682 }
9683 else
9684 {
9685 clib_memcpy (&ip4, &(mp->src_address[0]), sizeof (ip4));
9686 vat_json_object_add_ip4 (node, "src_address", ip4);
9687 clib_memcpy (&ip4, &(mp->dst_address[0]), sizeof (ip4));
9688 vat_json_object_add_ip4 (node, "dst_address", ip4);
9689 }
9690 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9691 vat_json_object_add_uint (node, "decap_next_index",
9692 ntohl (mp->decap_next_index));
9693 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9694 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Dave Wallace60231f32015-12-17 21:04:30 -05009695}
9696
Dave Barach72d72232016-08-04 10:15:08 -04009697static int
9698api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -04009699{
Dave Barach72d72232016-08-04 10:15:08 -04009700 unformat_input_t *i = vam->input;
9701 vl_api_vxlan_tunnel_dump_t *mp;
9702 f64 timeout;
9703 u32 sw_if_index;
9704 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009705
Dave Barach72d72232016-08-04 10:15:08 -04009706 /* Parse args required to build the message */
9707 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9708 {
9709 if (unformat (i, "sw_if_index %d", &sw_if_index))
9710 sw_if_index_set = 1;
9711 else
9712 break;
Chris Luke27fe48f2016-04-28 13:44:38 -04009713 }
9714
Dave Barach72d72232016-08-04 10:15:08 -04009715 if (sw_if_index_set == 0)
9716 {
9717 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009718 }
Dave Barach72d72232016-08-04 10:15:08 -04009719
9720 if (!vam->json_output)
9721 {
9722 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
9723 "sw_if_index", "src_address", "dst_address",
9724 "encap_vrf_id", "decap_next_index", "vni");
9725 }
9726
9727 /* Get list of vxlan-tunnel interfaces */
9728 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
9729
9730 mp->sw_if_index = htonl (sw_if_index);
9731
9732 S;
9733
9734 /* Use a control ping for synchronization */
9735 {
9736 vl_api_control_ping_t *mp;
9737 M (CONTROL_PING, control_ping);
9738 S;
9739 }
9740 W;
9741}
9742
9743static int
9744api_gre_add_del_tunnel (vat_main_t * vam)
9745{
9746 unformat_input_t *line_input = vam->input;
9747 vl_api_gre_add_del_tunnel_t *mp;
9748 f64 timeout;
9749 ip4_address_t src4, dst4;
9750 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -07009751 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009752 u8 src_set = 0;
9753 u8 dst_set = 0;
9754 u32 outer_fib_id = 0;
9755
9756 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9757 {
9758 if (unformat (line_input, "del"))
9759 is_add = 0;
9760 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
9761 src_set = 1;
9762 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
9763 dst_set = 1;
9764 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
9765 ;
David Hothama8cd3092016-09-19 09:55:07 -07009766 else if (unformat (line_input, "teb"))
9767 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009768 else
9769 {
9770 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9771 return -99;
9772 }
9773 }
9774
9775 if (src_set == 0)
9776 {
9777 errmsg ("tunnel src address not specified\n");
9778 return -99;
9779 }
9780 if (dst_set == 0)
9781 {
9782 errmsg ("tunnel dst address not specified\n");
9783 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -04009784 }
9785
9786
Dave Barach72d72232016-08-04 10:15:08 -04009787 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -04009788
Dave Barach72d72232016-08-04 10:15:08 -04009789 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
9790 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
9791 mp->outer_fib_id = ntohl (outer_fib_id);
9792 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -07009793 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -04009794
Dave Barach72d72232016-08-04 10:15:08 -04009795 S;
9796 W;
9797 /* NOTREACHED */
9798 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009799}
9800
9801static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009802 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04009803{
Dave Barach72d72232016-08-04 10:15:08 -04009804 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -04009805
David Hothama8cd3092016-09-19 09:55:07 -07009806 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -04009807 ntohl (mp->sw_if_index),
9808 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -07009809 format_ip4_address, &mp->dst_address,
9810 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -04009811}
9812
9813static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009814 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04009815{
Dave Barach72d72232016-08-04 10:15:08 -04009816 vat_main_t *vam = &vat_main;
9817 vat_json_node_t *node = NULL;
9818 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -04009819
Dave Barach72d72232016-08-04 10:15:08 -04009820 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -04009821 {
Dave Barach72d72232016-08-04 10:15:08 -04009822 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9823 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -04009824 }
Dave Barach72d72232016-08-04 10:15:08 -04009825 node = vat_json_array_add (&vam->json_tree);
9826
9827 vat_json_init_object (node);
9828 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9829 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
9830 vat_json_object_add_ip4 (node, "src_address", ip4);
9831 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
9832 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -07009833 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -04009834 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -04009835}
9836
Dave Barach72d72232016-08-04 10:15:08 -04009837static int
9838api_gre_tunnel_dump (vat_main_t * vam)
9839{
9840 unformat_input_t *i = vam->input;
9841 vl_api_gre_tunnel_dump_t *mp;
9842 f64 timeout;
9843 u32 sw_if_index;
9844 u8 sw_if_index_set = 0;
9845
9846 /* Parse args required to build the message */
9847 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9848 {
9849 if (unformat (i, "sw_if_index %d", &sw_if_index))
9850 sw_if_index_set = 1;
9851 else
9852 break;
9853 }
9854
9855 if (sw_if_index_set == 0)
9856 {
9857 sw_if_index = ~0;
9858 }
9859
9860 if (!vam->json_output)
9861 {
David Hothama8cd3092016-09-19 09:55:07 -07009862 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
9863 "sw_if_index", "src_address", "dst_address", "teb",
9864 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -04009865 }
9866
9867 /* Get list of gre-tunnel interfaces */
9868 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
9869
9870 mp->sw_if_index = htonl (sw_if_index);
9871
9872 S;
9873
9874 /* Use a control ping for synchronization */
9875 {
9876 vl_api_control_ping_t *mp;
9877 M (CONTROL_PING, control_ping);
9878 S;
9879 }
9880 W;
9881}
9882
9883static int
9884api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009885{
9886// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -04009887 vl_api_l2_fib_clear_table_t *mp;
9888 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009889
Dave Barach72d72232016-08-04 10:15:08 -04009890 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009891
Dave Barach72d72232016-08-04 10:15:08 -04009892 S;
9893 W;
9894 /* NOTREACHED */
9895 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009896}
9897
Dave Barach72d72232016-08-04 10:15:08 -04009898static int
9899api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009900{
Dave Barach72d72232016-08-04 10:15:08 -04009901 unformat_input_t *i = vam->input;
9902 vl_api_l2_interface_efp_filter_t *mp;
9903 f64 timeout;
9904 u32 sw_if_index;
9905 u8 enable = 1;
9906 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009907
Dave Barach72d72232016-08-04 10:15:08 -04009908 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9909 {
9910 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9911 sw_if_index_set = 1;
9912 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9913 sw_if_index_set = 1;
9914 else if (unformat (i, "enable"))
9915 enable = 1;
9916 else if (unformat (i, "disable"))
9917 enable = 0;
9918 else
9919 {
9920 clib_warning ("parse error '%U'", format_unformat_error, i);
9921 return -99;
9922 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009923 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009924
Dave Barach72d72232016-08-04 10:15:08 -04009925 if (sw_if_index_set == 0)
9926 {
9927 errmsg ("missing sw_if_index\n");
9928 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009929 }
9930
Dave Barach72d72232016-08-04 10:15:08 -04009931 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009932
Dave Barach72d72232016-08-04 10:15:08 -04009933 mp->sw_if_index = ntohl (sw_if_index);
9934 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009935
Dave Barach72d72232016-08-04 10:15:08 -04009936 S;
9937 W;
9938 /* NOTREACHED */
9939 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009940}
9941
9942#define foreach_vtr_op \
9943_("disable", L2_VTR_DISABLED) \
9944_("push-1", L2_VTR_PUSH_1) \
9945_("push-2", L2_VTR_PUSH_2) \
9946_("pop-1", L2_VTR_POP_1) \
9947_("pop-2", L2_VTR_POP_2) \
9948_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9949_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9950_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9951_("translate-2-2", L2_VTR_TRANSLATE_2_2)
9952
Dave Barach72d72232016-08-04 10:15:08 -04009953static int
9954api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009955{
Dave Barach72d72232016-08-04 10:15:08 -04009956 unformat_input_t *i = vam->input;
9957 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9958 f64 timeout;
9959 u32 sw_if_index;
9960 u8 sw_if_index_set = 0;
9961 u8 vtr_op_set = 0;
9962 u32 vtr_op = 0;
9963 u32 push_dot1q = 1;
9964 u32 tag1 = ~0;
9965 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009966
Dave Barach72d72232016-08-04 10:15:08 -04009967 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9968 {
9969 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9970 sw_if_index_set = 1;
9971 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9972 sw_if_index_set = 1;
9973 else if (unformat (i, "vtr_op %d", &vtr_op))
9974 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009975#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -04009976 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -07009977#undef _
Dave Barach72d72232016-08-04 10:15:08 -04009978 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9979 ;
9980 else if (unformat (i, "tag1 %d", &tag1))
9981 ;
9982 else if (unformat (i, "tag2 %d", &tag2))
9983 ;
9984 else
9985 {
9986 clib_warning ("parse error '%U'", format_unformat_error, i);
9987 return -99;
9988 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009989 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009990
Dave Barach72d72232016-08-04 10:15:08 -04009991 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9992 {
9993 errmsg ("missing vtr operation or sw_if_index\n");
9994 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009995 }
9996
Dave Barach72d72232016-08-04 10:15:08 -04009997 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
9998 mp->sw_if_index = ntohl (sw_if_index);
9999 mp->vtr_op = ntohl (vtr_op);
10000 mp->push_dot1q = ntohl (push_dot1q);
10001 mp->tag1 = ntohl (tag1);
10002 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010003
Dave Barach72d72232016-08-04 10:15:08 -040010004 S;
10005 W;
10006 /* NOTREACHED */
10007 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010008}
10009
Dave Barach72d72232016-08-04 10:15:08 -040010010static int
10011api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010012{
Dave Barach72d72232016-08-04 10:15:08 -040010013 unformat_input_t *i = vam->input;
10014 vl_api_create_vhost_user_if_t *mp;
10015 f64 timeout;
10016 u8 *file_name;
10017 u8 is_server = 0;
10018 u8 file_name_set = 0;
10019 u32 custom_dev_instance = ~0;
10020 u8 hwaddr[6];
10021 u8 use_custom_mac = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010022
Dave Barach72d72232016-08-04 10:15:08 -040010023 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10024 {
10025 if (unformat (i, "socket %s", &file_name))
10026 {
10027 file_name_set = 1;
10028 }
10029 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10030 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010031 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010032 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010033 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010034 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010035 else
Dave Barach72d72232016-08-04 10:15:08 -040010036 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010037 }
10038
Dave Barach72d72232016-08-04 10:15:08 -040010039 if (file_name_set == 0)
10040 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010041 errmsg ("missing socket file name\n");
10042 return -99;
10043 }
10044
Dave Barach72d72232016-08-04 10:15:08 -040010045 if (vec_len (file_name) > 255)
10046 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010047 errmsg ("socket file name too long\n");
10048 return -99;
10049 }
Dave Barach72d72232016-08-04 10:15:08 -040010050 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010051
Dave Barach72d72232016-08-04 10:15:08 -040010052 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010053
Dave Barach72d72232016-08-04 10:15:08 -040010054 mp->is_server = is_server;
10055 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10056 vec_free (file_name);
10057 if (custom_dev_instance != ~0)
10058 {
10059 mp->renumber = 1;
10060 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010061 }
Dave Barach72d72232016-08-04 10:15:08 -040010062 mp->use_custom_mac = use_custom_mac;
10063 clib_memcpy (mp->mac_address, hwaddr, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010064
Dave Barach72d72232016-08-04 10:15:08 -040010065 S;
10066 W;
10067 /* NOTREACHED */
10068 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010069}
10070
Dave Barach72d72232016-08-04 10:15:08 -040010071static int
10072api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010073{
Dave Barach72d72232016-08-04 10:15:08 -040010074 unformat_input_t *i = vam->input;
10075 vl_api_modify_vhost_user_if_t *mp;
10076 f64 timeout;
10077 u8 *file_name;
10078 u8 is_server = 0;
10079 u8 file_name_set = 0;
10080 u32 custom_dev_instance = ~0;
10081 u8 sw_if_index_set = 0;
10082 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010083
Dave Barach72d72232016-08-04 10:15:08 -040010084 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10085 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010086 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010087 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010088 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010089 sw_if_index_set = 1;
10090 else if (unformat (i, "socket %s", &file_name))
10091 {
10092 file_name_set = 1;
10093 }
10094 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10095 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010096 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010097 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010098 else
Dave Barach72d72232016-08-04 10:15:08 -040010099 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010100 }
10101
Dave Barach72d72232016-08-04 10:15:08 -040010102 if (sw_if_index_set == 0)
10103 {
10104 errmsg ("missing sw_if_index or interface name\n");
10105 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010106 }
10107
Dave Barach72d72232016-08-04 10:15:08 -040010108 if (file_name_set == 0)
10109 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010110 errmsg ("missing socket file name\n");
10111 return -99;
10112 }
10113
Dave Barach72d72232016-08-04 10:15:08 -040010114 if (vec_len (file_name) > 255)
10115 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010116 errmsg ("socket file name too long\n");
10117 return -99;
10118 }
Dave Barach72d72232016-08-04 10:15:08 -040010119 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010120
Dave Barach72d72232016-08-04 10:15:08 -040010121 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010122
Dave Barach72d72232016-08-04 10:15:08 -040010123 mp->sw_if_index = ntohl (sw_if_index);
10124 mp->is_server = is_server;
10125 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10126 vec_free (file_name);
10127 if (custom_dev_instance != ~0)
10128 {
10129 mp->renumber = 1;
10130 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010131 }
10132
Dave Barach72d72232016-08-04 10:15:08 -040010133 S;
10134 W;
10135 /* NOTREACHED */
10136 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010137}
10138
Dave Barach72d72232016-08-04 10:15:08 -040010139static int
10140api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010141{
Dave Barach72d72232016-08-04 10:15:08 -040010142 unformat_input_t *i = vam->input;
10143 vl_api_delete_vhost_user_if_t *mp;
10144 f64 timeout;
10145 u32 sw_if_index = ~0;
10146 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010147
Dave Barach72d72232016-08-04 10:15:08 -040010148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10149 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010150 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010151 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010152 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010153 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010154 else
Dave Barach72d72232016-08-04 10:15:08 -040010155 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010156 }
10157
Dave Barach72d72232016-08-04 10:15:08 -040010158 if (sw_if_index_set == 0)
10159 {
10160 errmsg ("missing sw_if_index or interface name\n");
10161 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010162 }
10163
10164
Dave Barach72d72232016-08-04 10:15:08 -040010165 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010166
Dave Barach72d72232016-08-04 10:15:08 -040010167 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010168
Dave Barach72d72232016-08-04 10:15:08 -040010169 S;
10170 W;
10171 /* NOTREACHED */
10172 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010173}
10174
10175static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010176 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010177{
Dave Barach72d72232016-08-04 10:15:08 -040010178 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010179
Dave Barach72d72232016-08-04 10:15:08 -040010180 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10181 (char *) mp->interface_name,
10182 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10183 clib_net_to_host_u64 (mp->features), mp->is_server,
10184 ntohl (mp->num_regions), (char *) mp->sock_filename);
10185 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010186}
10187
10188static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010189 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010190{
Dave Barach72d72232016-08-04 10:15:08 -040010191 vat_main_t *vam = &vat_main;
10192 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010193
Dave Barach72d72232016-08-04 10:15:08 -040010194 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010195 {
Dave Barach72d72232016-08-04 10:15:08 -040010196 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10197 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010198 }
Dave Barach72d72232016-08-04 10:15:08 -040010199 node = vat_json_array_add (&vam->json_tree);
10200
10201 vat_json_init_object (node);
10202 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10203 vat_json_object_add_string_copy (node, "interface_name",
10204 mp->interface_name);
10205 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10206 ntohl (mp->virtio_net_hdr_sz));
10207 vat_json_object_add_uint (node, "features",
10208 clib_net_to_host_u64 (mp->features));
10209 vat_json_object_add_uint (node, "is_server", mp->is_server);
10210 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10211 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10212 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010213}
10214
Dave Barach72d72232016-08-04 10:15:08 -040010215static int
10216api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010217{
Dave Barach72d72232016-08-04 10:15:08 -040010218 vl_api_sw_interface_vhost_user_dump_t *mp;
10219 f64 timeout;
10220 fformat (vam->ofp,
10221 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010222
Dave Barach72d72232016-08-04 10:15:08 -040010223 /* Get list of vhost-user interfaces */
10224 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10225 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010226
Dave Barach72d72232016-08-04 10:15:08 -040010227 /* Use a control ping for synchronization */
10228 {
10229 vl_api_control_ping_t *mp;
10230 M (CONTROL_PING, control_ping);
10231 S;
10232 }
10233 W;
10234}
10235
10236static int
10237api_show_version (vat_main_t * vam)
10238{
10239 vl_api_show_version_t *mp;
10240 f64 timeout;
10241
10242 M (SHOW_VERSION, show_version);
10243
10244 S;
10245 W;
10246 /* NOTREACHED */
10247 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010248}
10249
Ed Warnickecb9cada2015-12-08 15:45:58 -070010250
Dave Barach72d72232016-08-04 10:15:08 -040010251static int
10252api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010253{
Dave Barach72d72232016-08-04 10:15:08 -040010254 unformat_input_t *line_input = vam->input;
10255 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10256 f64 timeout;
10257 ip4_address_t local4, remote4;
10258 ip6_address_t local6, remote6;
10259 u8 is_add = 1;
10260 u8 ipv4_set = 0, ipv6_set = 0;
10261 u8 local_set = 0;
10262 u8 remote_set = 0;
10263 u32 encap_vrf_id = 0;
10264 u32 decap_vrf_id = 0;
10265 u8 protocol = ~0;
10266 u32 vni;
10267 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010268
Dave Barach72d72232016-08-04 10:15:08 -040010269 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10270 {
10271 if (unformat (line_input, "del"))
10272 is_add = 0;
10273 else if (unformat (line_input, "local %U",
10274 unformat_ip4_address, &local4))
10275 {
10276 local_set = 1;
10277 ipv4_set = 1;
10278 }
10279 else if (unformat (line_input, "remote %U",
10280 unformat_ip4_address, &remote4))
10281 {
10282 remote_set = 1;
10283 ipv4_set = 1;
10284 }
10285 else if (unformat (line_input, "local %U",
10286 unformat_ip6_address, &local6))
10287 {
10288 local_set = 1;
10289 ipv6_set = 1;
10290 }
10291 else if (unformat (line_input, "remote %U",
10292 unformat_ip6_address, &remote6))
10293 {
10294 remote_set = 1;
10295 ipv6_set = 1;
10296 }
10297 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10298 ;
10299 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10300 ;
10301 else if (unformat (line_input, "vni %d", &vni))
10302 vni_set = 1;
10303 else if (unformat (line_input, "next-ip4"))
10304 protocol = 1;
10305 else if (unformat (line_input, "next-ip6"))
10306 protocol = 2;
10307 else if (unformat (line_input, "next-ethernet"))
10308 protocol = 3;
10309 else if (unformat (line_input, "next-nsh"))
10310 protocol = 4;
10311 else
10312 {
10313 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10314 return -99;
10315 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010316 }
10317
Dave Barach72d72232016-08-04 10:15:08 -040010318 if (local_set == 0)
10319 {
10320 errmsg ("tunnel local address not specified\n");
10321 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010322 }
Dave Barach72d72232016-08-04 10:15:08 -040010323 if (remote_set == 0)
10324 {
10325 errmsg ("tunnel remote address not specified\n");
10326 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010327 }
Dave Barach72d72232016-08-04 10:15:08 -040010328 if (ipv4_set && ipv6_set)
10329 {
10330 errmsg ("both IPv4 and IPv6 addresses specified");
10331 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080010332 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010333
Dave Barach72d72232016-08-04 10:15:08 -040010334 if (vni_set == 0)
10335 {
10336 errmsg ("vni not specified\n");
10337 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010338 }
10339
Dave Barach72d72232016-08-04 10:15:08 -040010340 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010341
Hongjun Nidf921cc2016-05-25 01:16:19 +080010342
Dave Barach72d72232016-08-04 10:15:08 -040010343 if (ipv6_set)
10344 {
10345 clib_memcpy (&mp->local, &local6, sizeof (local6));
10346 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
10347 }
10348 else
10349 {
10350 clib_memcpy (&mp->local, &local4, sizeof (local4));
10351 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080010352 }
10353
Dave Barach72d72232016-08-04 10:15:08 -040010354 mp->encap_vrf_id = ntohl (encap_vrf_id);
10355 mp->decap_vrf_id = ntohl (decap_vrf_id);
10356 mp->protocol = ntohl (protocol);
10357 mp->vni = ntohl (vni);
10358 mp->is_add = is_add;
10359 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010360
Dave Barach72d72232016-08-04 10:15:08 -040010361 S;
10362 W;
10363 /* NOTREACHED */
10364 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010365}
10366
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010367static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010368 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010369{
Dave Barach72d72232016-08-04 10:15:08 -040010370 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010371
Dave Barach72d72232016-08-04 10:15:08 -040010372 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
10373 ntohl (mp->sw_if_index),
10374 format_ip46_address, &(mp->local[0]),
10375 format_ip46_address, &(mp->remote[0]),
10376 ntohl (mp->vni),
10377 ntohl (mp->protocol),
10378 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010379}
10380
10381static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010382 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010383{
Dave Barach72d72232016-08-04 10:15:08 -040010384 vat_main_t *vam = &vat_main;
10385 vat_json_node_t *node = NULL;
10386 struct in_addr ip4;
10387 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010388
Dave Barach72d72232016-08-04 10:15:08 -040010389 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010390 {
Dave Barach72d72232016-08-04 10:15:08 -040010391 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10392 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010393 }
Dave Barach72d72232016-08-04 10:15:08 -040010394 node = vat_json_array_add (&vam->json_tree);
10395
10396 vat_json_init_object (node);
10397 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10398 if (mp->is_ipv6)
10399 {
10400 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
10401 vat_json_object_add_ip6 (node, "local", ip6);
10402 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
10403 vat_json_object_add_ip6 (node, "remote", ip6);
10404 }
10405 else
10406 {
10407 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
10408 vat_json_object_add_ip4 (node, "local", ip4);
10409 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
10410 vat_json_object_add_ip4 (node, "remote", ip4);
10411 }
10412 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10413 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10414 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10415 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10416 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010417}
10418
Dave Barach72d72232016-08-04 10:15:08 -040010419static int
10420api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010421{
Dave Barach72d72232016-08-04 10:15:08 -040010422 unformat_input_t *i = vam->input;
10423 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10424 f64 timeout;
10425 u32 sw_if_index;
10426 u8 sw_if_index_set = 0;
10427
10428 /* Parse args required to build the message */
10429 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10430 {
10431 if (unformat (i, "sw_if_index %d", &sw_if_index))
10432 sw_if_index_set = 1;
10433 else
10434 break;
10435 }
10436
10437 if (sw_if_index_set == 0)
10438 {
10439 sw_if_index = ~0;
10440 }
10441
10442 if (!vam->json_output)
10443 {
10444 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
10445 "sw_if_index", "local", "remote", "vni",
10446 "protocol", "encap_vrf_id", "decap_vrf_id");
10447 }
10448
10449 /* Get list of vxlan-tunnel interfaces */
10450 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
10451
10452 mp->sw_if_index = htonl (sw_if_index);
10453
10454 S;
10455
10456 /* Use a control ping for synchronization */
10457 {
10458 vl_api_control_ping_t *mp;
10459 M (CONTROL_PING, control_ping);
10460 S;
10461 }
10462 W;
10463}
10464
10465u8 *
10466format_l2_fib_mac_address (u8 * s, va_list * args)
10467{
10468 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010469
10470 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040010471 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010472}
10473
10474static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010475 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010476{
Dave Barach72d72232016-08-04 10:15:08 -040010477 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010478
Dave Barach72d72232016-08-04 10:15:08 -040010479 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10480 " %d %d %d\n",
10481 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
10482 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10483 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010484}
10485
10486static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010487 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010488{
Dave Barach72d72232016-08-04 10:15:08 -040010489 vat_main_t *vam = &vat_main;
10490 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010491
Dave Barach72d72232016-08-04 10:15:08 -040010492 if (VAT_JSON_ARRAY != vam->json_tree.type)
10493 {
10494 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10495 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010496 }
Dave Barach72d72232016-08-04 10:15:08 -040010497 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010498
Dave Barach72d72232016-08-04 10:15:08 -040010499 vat_json_init_object (node);
10500 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10501 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
10502 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10503 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10504 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10505 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010506}
10507
Dave Barach72d72232016-08-04 10:15:08 -040010508static int
10509api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010510{
Dave Barach72d72232016-08-04 10:15:08 -040010511 unformat_input_t *i = vam->input;
10512 vl_api_l2_fib_table_dump_t *mp;
10513 f64 timeout;
10514 u32 bd_id;
10515 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010516
Dave Barach72d72232016-08-04 10:15:08 -040010517 /* Parse args required to build the message */
10518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010519 {
Dave Barach72d72232016-08-04 10:15:08 -040010520 if (unformat (i, "bd_id %d", &bd_id))
10521 bd_id_set = 1;
10522 else
10523 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010524 }
Dave Barach72d72232016-08-04 10:15:08 -040010525
10526 if (bd_id_set == 0)
10527 {
10528 errmsg ("missing bridge domain\n");
10529 return -99;
10530 }
10531
10532 fformat (vam->ofp,
10533 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
10534
10535 /* Get list of l2 fib entries */
10536 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
10537
10538 mp->bd_id = ntohl (bd_id);
10539 S;
10540
10541 /* Use a control ping for synchronization */
10542 {
10543 vl_api_control_ping_t *mp;
10544 M (CONTROL_PING, control_ping);
10545 S;
10546 }
10547 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010548}
10549
10550
10551static int
10552api_interface_name_renumber (vat_main_t * vam)
10553{
Dave Barach72d72232016-08-04 10:15:08 -040010554 unformat_input_t *line_input = vam->input;
10555 vl_api_interface_name_renumber_t *mp;
10556 u32 sw_if_index = ~0;
10557 f64 timeout;
10558 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010559
Dave Barach72d72232016-08-04 10:15:08 -040010560 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10561 {
10562 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
10563 &sw_if_index))
10564 ;
10565 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10566 ;
10567 else if (unformat (line_input, "new_show_dev_instance %d",
10568 &new_show_dev_instance))
10569 ;
10570 else
10571 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010572 }
10573
Dave Barach72d72232016-08-04 10:15:08 -040010574 if (sw_if_index == ~0)
10575 {
10576 errmsg ("missing interface name or sw_if_index\n");
10577 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010578 }
10579
Dave Barach72d72232016-08-04 10:15:08 -040010580 if (new_show_dev_instance == ~0)
10581 {
10582 errmsg ("missing new_show_dev_instance\n");
10583 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010584 }
10585
Dave Barach72d72232016-08-04 10:15:08 -040010586 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010587
Dave Barach72d72232016-08-04 10:15:08 -040010588 mp->sw_if_index = ntohl (sw_if_index);
10589 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010590
Dave Barach72d72232016-08-04 10:15:08 -040010591 S;
10592 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010593}
10594
10595static int
10596api_want_ip4_arp_events (vat_main_t * vam)
10597{
Dave Barach72d72232016-08-04 10:15:08 -040010598 unformat_input_t *line_input = vam->input;
10599 vl_api_want_ip4_arp_events_t *mp;
10600 f64 timeout;
10601 ip4_address_t address;
10602 int address_set = 0;
10603 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010604
Dave Barach72d72232016-08-04 10:15:08 -040010605 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10606 {
10607 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
10608 address_set = 1;
10609 else if (unformat (line_input, "del"))
10610 enable_disable = 0;
10611 else
10612 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010613 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010614
Dave Barach72d72232016-08-04 10:15:08 -040010615 if (address_set == 0)
10616 {
10617 errmsg ("missing addresses\n");
10618 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010619 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010620
Dave Barach72d72232016-08-04 10:15:08 -040010621 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
10622 mp->enable_disable = enable_disable;
10623 mp->pid = getpid ();
10624 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010625
Dave Barach72d72232016-08-04 10:15:08 -040010626 S;
10627 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010628}
10629
Dave Barach72d72232016-08-04 10:15:08 -040010630static int
John Lo1edfba92016-08-27 01:11:57 -040010631api_want_ip6_nd_events (vat_main_t * vam)
10632{
10633 unformat_input_t *line_input = vam->input;
10634 vl_api_want_ip6_nd_events_t *mp;
10635 f64 timeout;
10636 ip6_address_t address;
10637 int address_set = 0;
10638 u32 enable_disable = 1;
10639
10640 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10641 {
10642 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
10643 address_set = 1;
10644 else if (unformat (line_input, "del"))
10645 enable_disable = 0;
10646 else
10647 break;
10648 }
10649
10650 if (address_set == 0)
10651 {
10652 errmsg ("missing addresses\n");
10653 return -99;
10654 }
10655
10656 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
10657 mp->enable_disable = enable_disable;
10658 mp->pid = getpid ();
10659 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
10660
10661 S;
10662 W;
10663}
10664
10665static int
Dave Barach72d72232016-08-04 10:15:08 -040010666api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010667{
Dave Barach72d72232016-08-04 10:15:08 -040010668 unformat_input_t *i = vam->input;
10669 vl_api_input_acl_set_interface_t *mp;
10670 f64 timeout;
10671 u32 sw_if_index;
10672 int sw_if_index_set;
10673 u32 ip4_table_index = ~0;
10674 u32 ip6_table_index = ~0;
10675 u32 l2_table_index = ~0;
10676 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010677
Dave Barach72d72232016-08-04 10:15:08 -040010678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10679 {
10680 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10681 sw_if_index_set = 1;
10682 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10683 sw_if_index_set = 1;
10684 else if (unformat (i, "del"))
10685 is_add = 0;
10686 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10687 ;
10688 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10689 ;
10690 else if (unformat (i, "l2-table %d", &l2_table_index))
10691 ;
10692 else
10693 {
10694 clib_warning ("parse error '%U'", format_unformat_error, i);
10695 return -99;
10696 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010697 }
10698
Dave Barach72d72232016-08-04 10:15:08 -040010699 if (sw_if_index_set == 0)
10700 {
10701 errmsg ("missing interface name or sw_if_index\n");
10702 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010703 }
10704
Dave Barach72d72232016-08-04 10:15:08 -040010705 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010706
Dave Barach72d72232016-08-04 10:15:08 -040010707 mp->sw_if_index = ntohl (sw_if_index);
10708 mp->ip4_table_index = ntohl (ip4_table_index);
10709 mp->ip6_table_index = ntohl (ip6_table_index);
10710 mp->l2_table_index = ntohl (l2_table_index);
10711 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010712
Dave Barach72d72232016-08-04 10:15:08 -040010713 S;
10714 W;
10715 /* NOTREACHED */
10716 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010717}
10718
10719static int
10720api_ip_address_dump (vat_main_t * vam)
10721{
Dave Barach72d72232016-08-04 10:15:08 -040010722 unformat_input_t *i = vam->input;
10723 vl_api_ip_address_dump_t *mp;
10724 u32 sw_if_index = ~0;
10725 u8 sw_if_index_set = 0;
10726 u8 ipv4_set = 0;
10727 u8 ipv6_set = 0;
10728 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010729
Dave Barach72d72232016-08-04 10:15:08 -040010730 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010731 {
Dave Barach72d72232016-08-04 10:15:08 -040010732 if (unformat (i, "sw_if_index %d", &sw_if_index))
10733 sw_if_index_set = 1;
10734 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10735 sw_if_index_set = 1;
10736 else if (unformat (i, "ipv4"))
10737 ipv4_set = 1;
10738 else if (unformat (i, "ipv6"))
10739 ipv6_set = 1;
10740 else
10741 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010742 }
Dave Barach72d72232016-08-04 10:15:08 -040010743
10744 if (ipv4_set && ipv6_set)
10745 {
10746 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
10747 return -99;
10748 }
10749
10750 if ((!ipv4_set) && (!ipv6_set))
10751 {
10752 errmsg ("no ipv4 nor ipv6 flag set\n");
10753 return -99;
10754 }
10755
10756 if (sw_if_index_set == 0)
10757 {
10758 errmsg ("missing interface name or sw_if_index\n");
10759 return -99;
10760 }
10761
10762 vam->current_sw_if_index = sw_if_index;
10763 vam->is_ipv6 = ipv6_set;
10764
10765 M (IP_ADDRESS_DUMP, ip_address_dump);
10766 mp->sw_if_index = ntohl (sw_if_index);
10767 mp->is_ipv6 = ipv6_set;
10768 S;
10769
10770 /* Use a control ping for synchronization */
10771 {
10772 vl_api_control_ping_t *mp;
10773 M (CONTROL_PING, control_ping);
10774 S;
10775 }
10776 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010777}
10778
10779static int
10780api_ip_dump (vat_main_t * vam)
10781{
Dave Barach72d72232016-08-04 10:15:08 -040010782 vl_api_ip_dump_t *mp;
10783 unformat_input_t *in = vam->input;
10784 int ipv4_set = 0;
10785 int ipv6_set = 0;
10786 int is_ipv6;
10787 f64 timeout;
10788 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010789
Dave Barach72d72232016-08-04 10:15:08 -040010790 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010791 {
Dave Barach72d72232016-08-04 10:15:08 -040010792 if (unformat (in, "ipv4"))
10793 ipv4_set = 1;
10794 else if (unformat (in, "ipv6"))
10795 ipv6_set = 1;
10796 else
10797 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010798 }
Dave Barach72d72232016-08-04 10:15:08 -040010799
10800 if (ipv4_set && ipv6_set)
10801 {
10802 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
10803 return -99;
10804 }
10805
10806 if ((!ipv4_set) && (!ipv6_set))
10807 {
10808 errmsg ("no ipv4 nor ipv6 flag set\n");
10809 return -99;
10810 }
10811
10812 is_ipv6 = ipv6_set;
10813 vam->is_ipv6 = is_ipv6;
10814
10815 /* free old data */
10816 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10817 {
10818 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10819 }
10820 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10821
10822 M (IP_DUMP, ip_dump);
10823 mp->is_ipv6 = ipv6_set;
10824 S;
10825
10826 /* Use a control ping for synchronization */
10827 {
10828 vl_api_control_ping_t *mp;
10829 M (CONTROL_PING, control_ping);
10830 S;
10831 }
10832 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010833}
10834
10835static int
10836api_ipsec_spd_add_del (vat_main_t * vam)
10837{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010838#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010839 unformat_input_t *i = vam->input;
10840 vl_api_ipsec_spd_add_del_t *mp;
10841 f64 timeout;
10842 u32 spd_id = ~0;
10843 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010844
Dave Barach72d72232016-08-04 10:15:08 -040010845 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10846 {
10847 if (unformat (i, "spd_id %d", &spd_id))
10848 ;
10849 else if (unformat (i, "del"))
10850 is_add = 0;
10851 else
10852 {
10853 clib_warning ("parse error '%U'", format_unformat_error, i);
10854 return -99;
10855 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010856 }
Dave Barach72d72232016-08-04 10:15:08 -040010857 if (spd_id == ~0)
10858 {
10859 errmsg ("spd_id must be set\n");
10860 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010861 }
10862
Dave Barach72d72232016-08-04 10:15:08 -040010863 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010864
Dave Barach72d72232016-08-04 10:15:08 -040010865 mp->spd_id = ntohl (spd_id);
10866 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010867
Dave Barach72d72232016-08-04 10:15:08 -040010868 S;
10869 W;
10870 /* NOTREACHED */
10871 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010872#else
Dave Barach72d72232016-08-04 10:15:08 -040010873 clib_warning ("unsupported (no dpdk)");
10874 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010875#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070010876}
10877
10878static int
10879api_ipsec_interface_add_del_spd (vat_main_t * vam)
10880{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010881#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010882 unformat_input_t *i = vam->input;
10883 vl_api_ipsec_interface_add_del_spd_t *mp;
10884 f64 timeout;
10885 u32 sw_if_index;
10886 u8 sw_if_index_set = 0;
10887 u32 spd_id = (u32) ~ 0;
10888 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010889
Dave Barach72d72232016-08-04 10:15:08 -040010890 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10891 {
10892 if (unformat (i, "del"))
10893 is_add = 0;
10894 else if (unformat (i, "spd_id %d", &spd_id))
10895 ;
10896 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10897 sw_if_index_set = 1;
10898 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10899 sw_if_index_set = 1;
10900 else
10901 {
10902 clib_warning ("parse error '%U'", format_unformat_error, i);
10903 return -99;
10904 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010905
10906 }
10907
Dave Barach72d72232016-08-04 10:15:08 -040010908 if (spd_id == (u32) ~ 0)
10909 {
10910 errmsg ("spd_id must be set\n");
10911 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010912 }
10913
Dave Barach72d72232016-08-04 10:15:08 -040010914 if (sw_if_index_set == 0)
10915 {
10916 errmsg ("missing interface name or sw_if_index\n");
10917 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010918 }
10919
Dave Barach72d72232016-08-04 10:15:08 -040010920 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010921
Dave Barach72d72232016-08-04 10:15:08 -040010922 mp->spd_id = ntohl (spd_id);
10923 mp->sw_if_index = ntohl (sw_if_index);
10924 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010925
Dave Barach72d72232016-08-04 10:15:08 -040010926 S;
10927 W;
10928 /* NOTREACHED */
10929 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010930#else
Dave Barach72d72232016-08-04 10:15:08 -040010931 clib_warning ("unsupported (no dpdk)");
10932 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010933#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070010934}
10935
10936static int
10937api_ipsec_spd_add_del_entry (vat_main_t * vam)
10938{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010939#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010940 unformat_input_t *i = vam->input;
10941 vl_api_ipsec_spd_add_del_entry_t *mp;
10942 f64 timeout;
10943 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040010944 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040010945 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010946 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10947 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10948 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
10949 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010950
Dave Barach72d72232016-08-04 10:15:08 -040010951 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
10952 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
10953 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
10954 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
10955 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
10956 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010957
Dave Barach72d72232016-08-04 10:15:08 -040010958 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10959 {
10960 if (unformat (i, "del"))
10961 is_add = 0;
10962 if (unformat (i, "outbound"))
10963 is_outbound = 1;
10964 if (unformat (i, "inbound"))
10965 is_outbound = 0;
10966 else if (unformat (i, "spd_id %d", &spd_id))
10967 ;
10968 else if (unformat (i, "sa_id %d", &sa_id))
10969 ;
10970 else if (unformat (i, "priority %d", &priority))
10971 ;
10972 else if (unformat (i, "protocol %d", &protocol))
10973 ;
10974 else if (unformat (i, "lport_start %d", &lport_start))
10975 ;
10976 else if (unformat (i, "lport_stop %d", &lport_stop))
10977 ;
10978 else if (unformat (i, "rport_start %d", &rport_start))
10979 ;
10980 else if (unformat (i, "rport_stop %d", &rport_stop))
10981 ;
10982 else
10983 if (unformat
10984 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
10985 {
10986 is_ipv6 = 0;
10987 is_ip_any = 0;
10988 }
10989 else
10990 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
10991 {
10992 is_ipv6 = 0;
10993 is_ip_any = 0;
10994 }
10995 else
10996 if (unformat
10997 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
10998 {
10999 is_ipv6 = 0;
11000 is_ip_any = 0;
11001 }
11002 else
11003 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11004 {
11005 is_ipv6 = 0;
11006 is_ip_any = 0;
11007 }
11008 else
11009 if (unformat
11010 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11011 {
11012 is_ipv6 = 1;
11013 is_ip_any = 0;
11014 }
11015 else
11016 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11017 {
11018 is_ipv6 = 1;
11019 is_ip_any = 0;
11020 }
11021 else
11022 if (unformat
11023 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11024 {
11025 is_ipv6 = 1;
11026 is_ip_any = 0;
11027 }
11028 else
11029 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11030 {
11031 is_ipv6 = 1;
11032 is_ip_any = 0;
11033 }
11034 else
11035 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11036 {
11037 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11038 {
11039 clib_warning ("unsupported action: 'resolve'");
11040 return -99;
11041 }
11042 }
11043 else
11044 {
11045 clib_warning ("parse error '%U'", format_unformat_error, i);
11046 return -99;
11047 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011048
11049 }
11050
Dave Barach72d72232016-08-04 10:15:08 -040011051 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011052
Dave Barach72d72232016-08-04 10:15:08 -040011053 mp->spd_id = ntohl (spd_id);
11054 mp->priority = ntohl (priority);
11055 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011056
Dave Barach72d72232016-08-04 10:15:08 -040011057 mp->is_ipv6 = is_ipv6;
11058 if (is_ipv6 || is_ip_any)
11059 {
11060 clib_memcpy (mp->remote_address_start, &raddr6_start,
11061 sizeof (ip6_address_t));
11062 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11063 sizeof (ip6_address_t));
11064 clib_memcpy (mp->local_address_start, &laddr6_start,
11065 sizeof (ip6_address_t));
11066 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11067 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011068 }
Dave Barach72d72232016-08-04 10:15:08 -040011069 else
11070 {
11071 clib_memcpy (mp->remote_address_start, &raddr4_start,
11072 sizeof (ip4_address_t));
11073 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11074 sizeof (ip4_address_t));
11075 clib_memcpy (mp->local_address_start, &laddr4_start,
11076 sizeof (ip4_address_t));
11077 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11078 sizeof (ip4_address_t));
11079 }
11080 mp->protocol = (u8) protocol;
11081 mp->local_port_start = ntohs ((u16) lport_start);
11082 mp->local_port_stop = ntohs ((u16) lport_stop);
11083 mp->remote_port_start = ntohs ((u16) rport_start);
11084 mp->remote_port_stop = ntohs ((u16) rport_stop);
11085 mp->policy = (u8) policy;
11086 mp->sa_id = ntohl (sa_id);
11087 mp->is_add = is_add;
11088 mp->is_ip_any = is_ip_any;
11089 S;
11090 W;
11091 /* NOTREACHED */
11092 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011093#else
Dave Barach72d72232016-08-04 10:15:08 -040011094 clib_warning ("unsupported (no dpdk)");
11095 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011096#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011097}
11098
11099static int
11100api_ipsec_sad_add_del_entry (vat_main_t * vam)
11101{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011102#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011103 unformat_input_t *i = vam->input;
11104 vl_api_ipsec_sad_add_del_entry_t *mp;
11105 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011106 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011107 u8 *ck = 0, *ik = 0;
11108 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011109
Dave Barach72d72232016-08-04 10:15:08 -040011110 u8 protocol = IPSEC_PROTOCOL_AH;
11111 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11112 u32 crypto_alg = 0, integ_alg = 0;
11113 ip4_address_t tun_src4;
11114 ip4_address_t tun_dst4;
11115 ip6_address_t tun_src6;
11116 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011117
Dave Barach72d72232016-08-04 10:15:08 -040011118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11119 {
11120 if (unformat (i, "del"))
11121 is_add = 0;
11122 else if (unformat (i, "sad_id %d", &sad_id))
11123 ;
11124 else if (unformat (i, "spi %d", &spi))
11125 ;
11126 else if (unformat (i, "esp"))
11127 protocol = IPSEC_PROTOCOL_ESP;
11128 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11129 {
11130 is_tunnel = 1;
11131 is_tunnel_ipv6 = 0;
11132 }
11133 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11134 {
11135 is_tunnel = 1;
11136 is_tunnel_ipv6 = 0;
11137 }
11138 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11139 {
11140 is_tunnel = 1;
11141 is_tunnel_ipv6 = 1;
11142 }
11143 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11144 {
11145 is_tunnel = 1;
11146 is_tunnel_ipv6 = 1;
11147 }
11148 else
11149 if (unformat
11150 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11151 {
11152 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
11153 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256)
11154 {
11155 clib_warning ("unsupported crypto-alg: '%U'",
11156 format_ipsec_crypto_alg, crypto_alg);
11157 return -99;
11158 }
11159 }
11160 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11161 ;
11162 else
11163 if (unformat
11164 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11165 {
11166 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
11167 integ_alg > IPSEC_INTEG_ALG_SHA_512_256)
11168 {
11169 clib_warning ("unsupported integ-alg: '%U'",
11170 format_ipsec_integ_alg, integ_alg);
11171 return -99;
11172 }
11173 }
11174 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11175 ;
11176 else
11177 {
11178 clib_warning ("parse error '%U'", format_unformat_error, i);
11179 return -99;
11180 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011181
11182 }
11183
Dave Barach72d72232016-08-04 10:15:08 -040011184 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011185
Dave Barach72d72232016-08-04 10:15:08 -040011186 mp->sad_id = ntohl (sad_id);
11187 mp->is_add = is_add;
11188 mp->protocol = protocol;
11189 mp->spi = ntohl (spi);
11190 mp->is_tunnel = is_tunnel;
11191 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11192 mp->crypto_algorithm = crypto_alg;
11193 mp->integrity_algorithm = integ_alg;
11194 mp->crypto_key_length = vec_len (ck);
11195 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011196
Dave Barach72d72232016-08-04 10:15:08 -040011197 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11198 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011199
Dave Barach72d72232016-08-04 10:15:08 -040011200 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11201 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011202
Dave Barach839fe3e2016-08-10 11:35:54 -040011203 if (ck)
11204 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11205 if (ik)
11206 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011207
Dave Barach72d72232016-08-04 10:15:08 -040011208 if (is_tunnel)
11209 {
11210 if (is_tunnel_ipv6)
11211 {
11212 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11213 sizeof (ip6_address_t));
11214 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
11215 sizeof (ip6_address_t));
11216 }
11217 else
11218 {
11219 clib_memcpy (mp->tunnel_src_address, &tun_src4,
11220 sizeof (ip4_address_t));
11221 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
11222 sizeof (ip4_address_t));
11223 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011224 }
11225
Dave Barach72d72232016-08-04 10:15:08 -040011226 S;
11227 W;
11228 /* NOTREACHED */
11229 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011230#else
Dave Barach72d72232016-08-04 10:15:08 -040011231 clib_warning ("unsupported (no dpdk)");
11232 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011233#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011234}
11235
11236static int
11237api_ipsec_sa_set_key (vat_main_t * vam)
11238{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011239#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011240 unformat_input_t *i = vam->input;
11241 vl_api_ipsec_sa_set_key_t *mp;
11242 f64 timeout;
11243 u32 sa_id;
11244 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011245
Dave Barach72d72232016-08-04 10:15:08 -040011246 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11247 {
11248 if (unformat (i, "sa_id %d", &sa_id))
11249 ;
11250 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11251 ;
11252 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11253 ;
11254 else
11255 {
11256 clib_warning ("parse error '%U'", format_unformat_error, i);
11257 return -99;
11258 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011259 }
11260
Dave Barach72d72232016-08-04 10:15:08 -040011261 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011262
Dave Barach72d72232016-08-04 10:15:08 -040011263 mp->sa_id = ntohl (sa_id);
11264 mp->crypto_key_length = vec_len (ck);
11265 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011266
Dave Barach72d72232016-08-04 10:15:08 -040011267 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11268 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011269
Dave Barach72d72232016-08-04 10:15:08 -040011270 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11271 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011272
Dave Barach839fe3e2016-08-10 11:35:54 -040011273 if (ck)
11274 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11275 if (ik)
11276 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011277
Dave Barach72d72232016-08-04 10:15:08 -040011278 S;
11279 W;
11280 /* NOTREACHED */
11281 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011282#else
Dave Barach72d72232016-08-04 10:15:08 -040011283 clib_warning ("unsupported (no dpdk)");
11284 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011285#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011286}
11287
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011288static int
11289api_ikev2_profile_add_del (vat_main_t * vam)
11290{
11291#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011292 unformat_input_t *i = vam->input;
11293 vl_api_ikev2_profile_add_del_t *mp;
11294 f64 timeout;
11295 u8 is_add = 1;
11296 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011297
Dave Barach72d72232016-08-04 10:15:08 -040011298 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011299
Dave Barach72d72232016-08-04 10:15:08 -040011300 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11301 {
11302 if (unformat (i, "del"))
11303 is_add = 0;
11304 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11305 vec_add1 (name, 0);
11306 else
11307 {
11308 errmsg ("parse error '%U'", format_unformat_error, i);
11309 return -99;
11310 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011311 }
11312
Dave Barach72d72232016-08-04 10:15:08 -040011313 if (!vec_len (name))
11314 {
11315 errmsg ("profile name must be specified");
11316 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011317 }
11318
Dave Barach72d72232016-08-04 10:15:08 -040011319 if (vec_len (name) > 64)
11320 {
11321 errmsg ("profile name too long");
11322 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011323 }
11324
Dave Barach72d72232016-08-04 10:15:08 -040011325 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011326
Dave Barach72d72232016-08-04 10:15:08 -040011327 clib_memcpy (mp->name, name, vec_len (name));
11328 mp->is_add = is_add;
11329 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011330
Dave Barach72d72232016-08-04 10:15:08 -040011331 S;
11332 W;
11333 /* NOTREACHED */
11334 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011335#else
Dave Barach72d72232016-08-04 10:15:08 -040011336 clib_warning ("unsupported (no dpdk)");
11337 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011338#endif
11339}
11340
11341static int
11342api_ikev2_profile_set_auth (vat_main_t * vam)
11343{
11344#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011345 unformat_input_t *i = vam->input;
11346 vl_api_ikev2_profile_set_auth_t *mp;
11347 f64 timeout;
11348 u8 *name = 0;
11349 u8 *data = 0;
11350 u32 auth_method = 0;
11351 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011352
Dave Barach72d72232016-08-04 10:15:08 -040011353 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011354
Dave Barach72d72232016-08-04 10:15:08 -040011355 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11356 {
11357 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11358 vec_add1 (name, 0);
11359 else if (unformat (i, "auth_method %U",
11360 unformat_ikev2_auth_method, &auth_method))
11361 ;
11362 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
11363 is_hex = 1;
11364 else if (unformat (i, "auth_data %v", &data))
11365 ;
11366 else
11367 {
11368 errmsg ("parse error '%U'", format_unformat_error, i);
11369 return -99;
11370 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011371 }
11372
Dave Barach72d72232016-08-04 10:15:08 -040011373 if (!vec_len (name))
11374 {
11375 errmsg ("profile name must be specified");
11376 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011377 }
11378
Dave Barach72d72232016-08-04 10:15:08 -040011379 if (vec_len (name) > 64)
11380 {
11381 errmsg ("profile name too long");
11382 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011383 }
11384
Dave Barach72d72232016-08-04 10:15:08 -040011385 if (!vec_len (data))
11386 {
11387 errmsg ("auth_data must be specified");
11388 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011389 }
11390
Dave Barach72d72232016-08-04 10:15:08 -040011391 if (!auth_method)
11392 {
11393 errmsg ("auth_method must be specified");
11394 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011395 }
11396
Dave Barach72d72232016-08-04 10:15:08 -040011397 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011398
Dave Barach72d72232016-08-04 10:15:08 -040011399 mp->is_hex = is_hex;
11400 mp->auth_method = (u8) auth_method;
11401 mp->data_len = vec_len (data);
11402 clib_memcpy (mp->name, name, vec_len (name));
11403 clib_memcpy (mp->data, data, vec_len (data));
11404 vec_free (name);
11405 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011406
Dave Barach72d72232016-08-04 10:15:08 -040011407 S;
11408 W;
11409 /* NOTREACHED */
11410 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011411#else
Dave Barach72d72232016-08-04 10:15:08 -040011412 clib_warning ("unsupported (no dpdk)");
11413 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011414#endif
11415}
11416
11417static int
11418api_ikev2_profile_set_id (vat_main_t * vam)
11419{
11420#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011421 unformat_input_t *i = vam->input;
11422 vl_api_ikev2_profile_set_id_t *mp;
11423 f64 timeout;
11424 u8 *name = 0;
11425 u8 *data = 0;
11426 u8 is_local = 0;
11427 u32 id_type = 0;
11428 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011429
Dave Barach72d72232016-08-04 10:15:08 -040011430 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011431
Dave Barach72d72232016-08-04 10:15:08 -040011432 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11433 {
11434 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11435 vec_add1 (name, 0);
11436 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
11437 ;
11438 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
11439 {
11440 data = vec_new (u8, 4);
11441 clib_memcpy (data, ip4.as_u8, 4);
11442 }
11443 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
11444 ;
11445 else if (unformat (i, "id_data %v", &data))
11446 ;
11447 else if (unformat (i, "local"))
11448 is_local = 1;
11449 else if (unformat (i, "remote"))
11450 is_local = 0;
11451 else
11452 {
11453 errmsg ("parse error '%U'", format_unformat_error, i);
11454 return -99;
11455 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011456 }
11457
Dave Barach72d72232016-08-04 10:15:08 -040011458 if (!vec_len (name))
11459 {
11460 errmsg ("profile name must be specified");
11461 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011462 }
11463
Dave Barach72d72232016-08-04 10:15:08 -040011464 if (vec_len (name) > 64)
11465 {
11466 errmsg ("profile name too long");
11467 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011468 }
11469
Dave Barach72d72232016-08-04 10:15:08 -040011470 if (!vec_len (data))
11471 {
11472 errmsg ("id_data must be specified");
11473 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011474 }
11475
Dave Barach72d72232016-08-04 10:15:08 -040011476 if (!id_type)
11477 {
11478 errmsg ("id_type must be specified");
11479 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011480 }
11481
Dave Barach72d72232016-08-04 10:15:08 -040011482 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011483
Dave Barach72d72232016-08-04 10:15:08 -040011484 mp->is_local = is_local;
11485 mp->id_type = (u8) id_type;
11486 mp->data_len = vec_len (data);
11487 clib_memcpy (mp->name, name, vec_len (name));
11488 clib_memcpy (mp->data, data, vec_len (data));
11489 vec_free (name);
11490 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011491
Dave Barach72d72232016-08-04 10:15:08 -040011492 S;
11493 W;
11494 /* NOTREACHED */
11495 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011496#else
Dave Barach72d72232016-08-04 10:15:08 -040011497 clib_warning ("unsupported (no dpdk)");
11498 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011499#endif
11500}
11501
11502static int
11503api_ikev2_profile_set_ts (vat_main_t * vam)
11504{
11505#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011506 unformat_input_t *i = vam->input;
11507 vl_api_ikev2_profile_set_ts_t *mp;
11508 f64 timeout;
11509 u8 *name = 0;
11510 u8 is_local = 0;
11511 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
11512 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011513
Dave Barach72d72232016-08-04 10:15:08 -040011514 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011515
Dave Barach72d72232016-08-04 10:15:08 -040011516 start_addr.as_u32 = 0;
11517 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011518
Dave Barach72d72232016-08-04 10:15:08 -040011519 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11520 {
11521 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11522 vec_add1 (name, 0);
11523 else if (unformat (i, "protocol %d", &proto))
11524 ;
11525 else if (unformat (i, "start_port %d", &start_port))
11526 ;
11527 else if (unformat (i, "end_port %d", &end_port))
11528 ;
11529 else
11530 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
11531 ;
11532 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
11533 ;
11534 else if (unformat (i, "local"))
11535 is_local = 1;
11536 else if (unformat (i, "remote"))
11537 is_local = 0;
11538 else
11539 {
11540 errmsg ("parse error '%U'", format_unformat_error, i);
11541 return -99;
11542 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011543 }
11544
Dave Barach72d72232016-08-04 10:15:08 -040011545 if (!vec_len (name))
11546 {
11547 errmsg ("profile name must be specified");
11548 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011549 }
11550
Dave Barach72d72232016-08-04 10:15:08 -040011551 if (vec_len (name) > 64)
11552 {
11553 errmsg ("profile name too long");
11554 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011555 }
11556
Dave Barach72d72232016-08-04 10:15:08 -040011557 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011558
Dave Barach72d72232016-08-04 10:15:08 -040011559 mp->is_local = is_local;
11560 mp->proto = (u8) proto;
11561 mp->start_port = (u16) start_port;
11562 mp->end_port = (u16) end_port;
11563 mp->start_addr = start_addr.as_u32;
11564 mp->end_addr = end_addr.as_u32;
11565 clib_memcpy (mp->name, name, vec_len (name));
11566 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011567
Dave Barach72d72232016-08-04 10:15:08 -040011568 S;
11569 W;
11570 /* NOTREACHED */
11571 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011572#else
Dave Barach72d72232016-08-04 10:15:08 -040011573 clib_warning ("unsupported (no dpdk)");
11574 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011575#endif
11576}
11577
11578static int
11579api_ikev2_set_local_key (vat_main_t * vam)
11580{
11581#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011582 unformat_input_t *i = vam->input;
11583 vl_api_ikev2_set_local_key_t *mp;
11584 f64 timeout;
11585 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011586
Dave Barach72d72232016-08-04 10:15:08 -040011587 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11588 {
11589 if (unformat (i, "file %v", &file))
11590 vec_add1 (file, 0);
11591 else
11592 {
11593 errmsg ("parse error '%U'", format_unformat_error, i);
11594 return -99;
11595 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011596 }
11597
Dave Barach72d72232016-08-04 10:15:08 -040011598 if (!vec_len (file))
11599 {
11600 errmsg ("RSA key file must be specified");
11601 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011602 }
11603
Dave Barach72d72232016-08-04 10:15:08 -040011604 if (vec_len (file) > 256)
11605 {
11606 errmsg ("file name too long");
11607 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011608 }
11609
Dave Barach72d72232016-08-04 10:15:08 -040011610 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011611
Dave Barach72d72232016-08-04 10:15:08 -040011612 clib_memcpy (mp->key_file, file, vec_len (file));
11613 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011614
Dave Barach72d72232016-08-04 10:15:08 -040011615 S;
11616 W;
11617 /* NOTREACHED */
11618 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011619#else
Dave Barach72d72232016-08-04 10:15:08 -040011620 clib_warning ("unsupported (no dpdk)");
11621 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011622#endif
11623}
11624
Ed Warnickecb9cada2015-12-08 15:45:58 -070011625/*
11626 * MAP
11627 */
Dave Barach72d72232016-08-04 10:15:08 -040011628static int
11629api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011630{
11631 unformat_input_t *i = vam->input;
11632 vl_api_map_add_domain_t *mp;
11633 f64 timeout;
11634
11635 ip4_address_t ip4_prefix;
11636 ip6_address_t ip6_prefix;
11637 ip6_address_t ip6_src;
11638 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040011639 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
11640 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011641 u8 is_translation = 0;
11642 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020011643 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011644
Dave Barach72d72232016-08-04 10:15:08 -040011645 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11646 {
11647 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
11648 &ip4_prefix, &ip4_prefix_len))
11649 num_m_args++;
11650 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
11651 &ip6_prefix, &ip6_prefix_len))
11652 num_m_args++;
11653 else
11654 if (unformat
11655 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
11656 &ip6_src_len))
11657 num_m_args++;
11658 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
11659 num_m_args++;
11660 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
11661 num_m_args++;
11662 else if (unformat (i, "psid-offset %d", &psid_offset))
11663 num_m_args++;
11664 else if (unformat (i, "psid-len %d", &psid_length))
11665 num_m_args++;
11666 else if (unformat (i, "mtu %d", &mtu))
11667 num_m_args++;
11668 else if (unformat (i, "map-t"))
11669 is_translation = 1;
11670 else
11671 {
11672 clib_warning ("parse error '%U'", format_unformat_error, i);
11673 return -99;
11674 }
11675 }
11676
Ole Troan07e7eab2016-08-25 00:24:08 +020011677 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040011678 {
11679 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070011680 return -99;
11681 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011682
11683 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011684 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011685
Dave Barach72d72232016-08-04 10:15:08 -040011686 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011687 mp->ip4_prefix_len = ip4_prefix_len;
11688
Dave Barach72d72232016-08-04 10:15:08 -040011689 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011690 mp->ip6_prefix_len = ip6_prefix_len;
11691
Dave Barach72d72232016-08-04 10:15:08 -040011692 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011693 mp->ip6_src_prefix_len = ip6_src_len;
11694
11695 mp->ea_bits_len = ea_bits_len;
11696 mp->psid_offset = psid_offset;
11697 mp->psid_length = psid_length;
11698 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040011699 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011700
11701 /* send it... */
11702 S;
11703
11704 /* Wait for a reply, return good/bad news */
11705 W;
11706}
11707
Dave Barach72d72232016-08-04 10:15:08 -040011708static int
11709api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011710{
11711 unformat_input_t *i = vam->input;
11712 vl_api_map_del_domain_t *mp;
11713 f64 timeout;
11714
11715 u32 num_m_args = 0;
11716 u32 index;
11717
Dave Barach72d72232016-08-04 10:15:08 -040011718 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11719 {
11720 if (unformat (i, "index %d", &index))
11721 num_m_args++;
11722 else
11723 {
11724 clib_warning ("parse error '%U'", format_unformat_error, i);
11725 return -99;
11726 }
11727 }
11728
11729 if (num_m_args != 1)
11730 {
11731 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070011732 return -99;
11733 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011734
11735 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011736 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011737
Dave Barach72d72232016-08-04 10:15:08 -040011738 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011739
11740 /* send it... */
11741 S;
11742
11743 /* Wait for a reply, return good/bad news */
11744 W;
11745}
11746
Dave Barach72d72232016-08-04 10:15:08 -040011747static int
11748api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011749{
11750 unformat_input_t *i = vam->input;
11751 vl_api_map_add_del_rule_t *mp;
11752 f64 timeout;
11753 u8 is_add = 1;
11754 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040011755 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011756
Dave Barach72d72232016-08-04 10:15:08 -040011757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11758 {
11759 if (unformat (i, "index %d", &index))
11760 num_m_args++;
11761 else if (unformat (i, "psid %d", &psid))
11762 num_m_args++;
11763 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
11764 num_m_args++;
11765 else if (unformat (i, "del"))
11766 {
11767 is_add = 0;
11768 }
11769 else
11770 {
11771 clib_warning ("parse error '%U'", format_unformat_error, i);
11772 return -99;
11773 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011774 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011775
11776 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011777 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011778
Dave Barach72d72232016-08-04 10:15:08 -040011779 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011780 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040011781 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
11782 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011783
11784 /* send it... */
11785 S;
11786
11787 /* Wait for a reply, return good/bad news */
11788 W;
11789}
11790
Dave Barach72d72232016-08-04 10:15:08 -040011791static int
11792api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011793{
Dave Barach72d72232016-08-04 10:15:08 -040011794 vl_api_map_domain_dump_t *mp;
11795 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011796
Dave Barach72d72232016-08-04 10:15:08 -040011797 /* Construct the API message */
11798 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011799
Dave Barach72d72232016-08-04 10:15:08 -040011800 /* send it... */
11801 S;
11802
11803 /* Use a control ping for synchronization */
11804 {
11805 vl_api_control_ping_t *mp;
11806 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011807 S;
Dave Barach72d72232016-08-04 10:15:08 -040011808 }
11809 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011810}
11811
Dave Barach72d72232016-08-04 10:15:08 -040011812static int
11813api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011814{
Dave Barach72d72232016-08-04 10:15:08 -040011815 unformat_input_t *i = vam->input;
11816 vl_api_map_rule_dump_t *mp;
11817 f64 timeout;
11818 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011819
Dave Barach72d72232016-08-04 10:15:08 -040011820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011821 {
Dave Barach72d72232016-08-04 10:15:08 -040011822 if (unformat (i, "index %u", &domain_index))
11823 ;
11824 else
11825 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011826 }
Dave Barach72d72232016-08-04 10:15:08 -040011827
11828 if (domain_index == ~0)
11829 {
11830 clib_warning ("parse error: domain index expected");
11831 return -99;
11832 }
11833
11834 /* Construct the API message */
11835 M (MAP_RULE_DUMP, map_rule_dump);
11836
11837 mp->domain_index = htonl (domain_index);
11838
11839 /* send it... */
11840 S;
11841
11842 /* Use a control ping for synchronization */
11843 {
11844 vl_api_control_ping_t *mp;
11845 M (CONTROL_PING, control_ping);
11846 S;
11847 }
11848 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011849}
11850
11851static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011852 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011853{
Dave Barach72d72232016-08-04 10:15:08 -040011854 vat_main_t *vam = &vat_main;
11855 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011856
Dave Barach72d72232016-08-04 10:15:08 -040011857 if (vam->async_mode)
11858 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070011859 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040011860 }
11861 else
11862 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070011863 vam->retval = retval;
11864 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040011865 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011866}
11867
11868static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011869 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011870{
Dave Barach72d72232016-08-04 10:15:08 -040011871 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011872 vat_json_node_t node;
11873
Dave Barach72d72232016-08-04 10:15:08 -040011874 vat_json_init_object (&node);
11875 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
11876 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011877
Dave Barach72d72232016-08-04 10:15:08 -040011878 vat_json_print (vam->ofp, &node);
11879 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011880
Dave Barach72d72232016-08-04 10:15:08 -040011881 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011882 vam->result_ready = 1;
11883}
11884
11885static int
11886api_get_first_msg_id (vat_main_t * vam)
11887{
Dave Barach72d72232016-08-04 10:15:08 -040011888 vl_api_get_first_msg_id_t *mp;
11889 f64 timeout;
11890 unformat_input_t *i = vam->input;
11891 u8 *name;
11892 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011893
Dave Barach72d72232016-08-04 10:15:08 -040011894 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11895 {
11896 if (unformat (i, "client %s", &name))
11897 name_set = 1;
11898 else
11899 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011900 }
11901
Dave Barach72d72232016-08-04 10:15:08 -040011902 if (name_set == 0)
11903 {
11904 errmsg ("missing client name\n");
11905 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011906 }
Dave Barach72d72232016-08-04 10:15:08 -040011907 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011908
Dave Barach72d72232016-08-04 10:15:08 -040011909 if (vec_len (name) > 63)
11910 {
11911 errmsg ("client name too long\n");
11912 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011913 }
11914
Dave Barach72d72232016-08-04 10:15:08 -040011915 M (GET_FIRST_MSG_ID, get_first_msg_id);
11916 clib_memcpy (mp->name, name, vec_len (name));
11917 S;
11918 W;
11919 /* NOTREACHED */
11920 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011921}
11922
Dave Barach72d72232016-08-04 10:15:08 -040011923static int
11924api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050011925{
Dave Barach72d72232016-08-04 10:15:08 -040011926 unformat_input_t *line_input = vam->input;
11927 vl_api_cop_interface_enable_disable_t *mp;
11928 f64 timeout;
11929 u32 sw_if_index = ~0;
11930 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011931
Dave Barach72d72232016-08-04 10:15:08 -040011932 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11933 {
11934 if (unformat (line_input, "disable"))
11935 enable_disable = 0;
11936 if (unformat (line_input, "enable"))
11937 enable_disable = 1;
11938 else if (unformat (line_input, "%U", unformat_sw_if_index,
11939 vam, &sw_if_index))
11940 ;
11941 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11942 ;
11943 else
11944 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011945 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011946
Dave Barach72d72232016-08-04 10:15:08 -040011947 if (sw_if_index == ~0)
11948 {
11949 errmsg ("missing interface name or sw_if_index\n");
11950 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011951 }
11952
Dave Barach72d72232016-08-04 10:15:08 -040011953 /* Construct the API message */
11954 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
11955 mp->sw_if_index = ntohl (sw_if_index);
11956 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011957
Dave Barach72d72232016-08-04 10:15:08 -040011958 /* send it... */
11959 S;
11960 /* Wait for the reply */
11961 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011962}
11963
Dave Barach72d72232016-08-04 10:15:08 -040011964static int
11965api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050011966{
Dave Barach72d72232016-08-04 10:15:08 -040011967 unformat_input_t *line_input = vam->input;
11968 vl_api_cop_whitelist_enable_disable_t *mp;
11969 f64 timeout;
11970 u32 sw_if_index = ~0;
11971 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040011972 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011973
Dave Barach72d72232016-08-04 10:15:08 -040011974 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11975 {
11976 if (unformat (line_input, "ip4"))
11977 ip4 = 1;
11978 else if (unformat (line_input, "ip6"))
11979 ip6 = 1;
11980 else if (unformat (line_input, "default"))
11981 default_cop = 1;
11982 else if (unformat (line_input, "%U", unformat_sw_if_index,
11983 vam, &sw_if_index))
11984 ;
11985 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11986 ;
11987 else if (unformat (line_input, "fib-id %d", &fib_id))
11988 ;
11989 else
11990 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011991 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011992
Dave Barach72d72232016-08-04 10:15:08 -040011993 if (sw_if_index == ~0)
11994 {
11995 errmsg ("missing interface name or sw_if_index\n");
11996 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011997 }
11998
Dave Barach72d72232016-08-04 10:15:08 -040011999 /* Construct the API message */
12000 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
12001 mp->sw_if_index = ntohl (sw_if_index);
12002 mp->fib_id = ntohl (fib_id);
12003 mp->ip4 = ip4;
12004 mp->ip6 = ip6;
12005 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012006
Dave Barach72d72232016-08-04 10:15:08 -040012007 /* send it... */
12008 S;
12009 /* Wait for the reply */
12010 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012011}
12012
Dave Barach72d72232016-08-04 10:15:08 -040012013static int
12014api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012015{
Dave Barach72d72232016-08-04 10:15:08 -040012016 vl_api_get_node_graph_t *mp;
12017 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012018
Dave Barach72d72232016-08-04 10:15:08 -040012019 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012020
Dave Barach72d72232016-08-04 10:15:08 -040012021 /* send it... */
12022 S;
12023 /* Wait for the reply */
12024 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012025}
12026
Dave Barach72d72232016-08-04 10:15:08 -040012027/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012028/** Used for parsing LISP eids */
12029typedef CLIB_PACKED(struct{
12030 u8 addr[16]; /**< eid address */
12031 u32 len; /**< prefix length if IP */
12032 u8 type; /**< type of eid */
12033}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012034/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012035
12036static uword
12037unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12038{
Dave Barach72d72232016-08-04 10:15:08 -040012039 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012040
Dave Barach72d72232016-08-04 10:15:08 -040012041 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012042
Dave Barach72d72232016-08-04 10:15:08 -040012043 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12044 {
12045 a->type = 0; /* ipv4 type */
12046 }
12047 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12048 {
12049 a->type = 1; /* ipv6 type */
12050 }
12051 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12052 {
12053 a->type = 2; /* mac type */
12054 }
12055 else
12056 {
Florin Coras429e7952016-08-02 02:31:03 +020012057 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012058 }
Florin Coras429e7952016-08-02 02:31:03 +020012059
Dave Barach72d72232016-08-04 10:15:08 -040012060 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12061 {
Florin Coras429e7952016-08-02 02:31:03 +020012062 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012063 }
Florin Coras429e7952016-08-02 02:31:03 +020012064
12065 return 1;
12066}
12067
12068static int
12069lisp_eid_size_vat (u8 type)
12070{
Dave Barach72d72232016-08-04 10:15:08 -040012071 switch (type)
12072 {
Florin Coras429e7952016-08-02 02:31:03 +020012073 case 0:
12074 return 4;
12075 case 1:
12076 return 16;
12077 case 2:
12078 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012079 }
Florin Coras429e7952016-08-02 02:31:03 +020012080 return 0;
12081}
12082
12083static void
12084lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12085{
Dave Barach72d72232016-08-04 10:15:08 -040012086 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012087}
12088
Dave Barach72d72232016-08-04 10:15:08 -040012089/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012090/** Used for transferring locators via VPP API */
12091typedef CLIB_PACKED(struct
12092{
Dave Barach72d72232016-08-04 10:15:08 -040012093 u32 sw_if_index; /**< locator sw_if_index */
12094 u8 priority; /**< locator priority */
12095 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012096}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012097/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012098
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012099static int
Dave Barach72d72232016-08-04 10:15:08 -040012100api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012101{
Dave Barach72d72232016-08-04 10:15:08 -040012102 unformat_input_t *input = vam->input;
12103 vl_api_lisp_add_del_locator_set_t *mp;
12104 f64 timeout = ~0;
12105 u8 is_add = 1;
12106 u8 *locator_set_name = NULL;
12107 u8 locator_set_name_set = 0;
12108 ls_locator_t locator, *locators = 0;
12109 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012110 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012111
Dave Barach72d72232016-08-04 10:15:08 -040012112 /* Parse args required to build the message */
12113 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12114 {
12115 if (unformat (input, "del"))
12116 {
12117 is_add = 0;
12118 }
12119 else if (unformat (input, "locator-set %s", &locator_set_name))
12120 {
12121 locator_set_name_set = 1;
12122 }
12123 else if (unformat (input, "sw_if_index %u p %u w %u",
12124 &sw_if_index, &priority, &weight))
12125 {
12126 locator.sw_if_index = htonl (sw_if_index);
12127 locator.priority = priority;
12128 locator.weight = weight;
12129 vec_add1 (locators, locator);
12130 }
12131 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12132 vam, &sw_if_index, &priority, &weight))
12133 {
12134 locator.sw_if_index = htonl (sw_if_index);
12135 locator.priority = priority;
12136 locator.weight = weight;
12137 vec_add1 (locators, locator);
12138 }
12139 else
12140 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012141 }
12142
Dave Barach72d72232016-08-04 10:15:08 -040012143 if (locator_set_name_set == 0)
12144 {
12145 errmsg ("missing locator-set name");
12146 vec_free (locators);
12147 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012148 }
12149
Dave Barach72d72232016-08-04 10:15:08 -040012150 if (vec_len (locator_set_name) > 64)
12151 {
12152 errmsg ("locator-set name too long\n");
12153 vec_free (locator_set_name);
12154 vec_free (locators);
12155 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012156 }
Dave Barach72d72232016-08-04 10:15:08 -040012157 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012158
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012159 data_len = sizeof (ls_locator_t) * vec_len (locators);
12160
Dave Barach72d72232016-08-04 10:15:08 -040012161 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012162 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012163
Dave Barach72d72232016-08-04 10:15:08 -040012164 mp->is_add = is_add;
12165 clib_memcpy (mp->locator_set_name, locator_set_name,
12166 vec_len (locator_set_name));
12167 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012168
Filip Tehlare3552c42016-08-26 12:44:38 +020012169 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012170 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012171 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012172 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012173
Dave Barach72d72232016-08-04 10:15:08 -040012174 /* send it... */
12175 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012176
Dave Barach72d72232016-08-04 10:15:08 -040012177 /* Wait for a reply... */
12178 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012179
Dave Barach72d72232016-08-04 10:15:08 -040012180 /* NOTREACHED */
12181 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012182}
12183
12184static int
Dave Barach72d72232016-08-04 10:15:08 -040012185api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012186{
Dave Barach72d72232016-08-04 10:15:08 -040012187 unformat_input_t *input = vam->input;
12188 vl_api_lisp_add_del_locator_t *mp;
12189 f64 timeout = ~0;
12190 u32 tmp_if_index = ~0;
12191 u32 sw_if_index = ~0;
12192 u8 sw_if_index_set = 0;
12193 u8 sw_if_index_if_name_set = 0;
12194 u32 priority = ~0;
12195 u8 priority_set = 0;
12196 u32 weight = ~0;
12197 u8 weight_set = 0;
12198 u8 is_add = 1;
12199 u8 *locator_set_name = NULL;
12200 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012201
Dave Barach72d72232016-08-04 10:15:08 -040012202 /* Parse args required to build the message */
12203 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12204 {
12205 if (unformat (input, "del"))
12206 {
12207 is_add = 0;
12208 }
12209 else if (unformat (input, "locator-set %s", &locator_set_name))
12210 {
12211 locator_set_name_set = 1;
12212 }
12213 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12214 &tmp_if_index))
12215 {
12216 sw_if_index_if_name_set = 1;
12217 sw_if_index = tmp_if_index;
12218 }
12219 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12220 {
12221 sw_if_index_set = 1;
12222 sw_if_index = tmp_if_index;
12223 }
12224 else if (unformat (input, "p %d", &priority))
12225 {
12226 priority_set = 1;
12227 }
12228 else if (unformat (input, "w %d", &weight))
12229 {
12230 weight_set = 1;
12231 }
12232 else
12233 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012234 }
12235
Dave Barach72d72232016-08-04 10:15:08 -040012236 if (locator_set_name_set == 0)
12237 {
12238 errmsg ("missing locator-set name");
12239 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012240 }
12241
Dave Barach72d72232016-08-04 10:15:08 -040012242 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12243 {
12244 errmsg ("missing sw_if_index");
12245 vec_free (locator_set_name);
12246 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012247 }
12248
Dave Barach72d72232016-08-04 10:15:08 -040012249 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
12250 {
12251 errmsg ("cannot use both params interface name and sw_if_index");
12252 vec_free (locator_set_name);
12253 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012254 }
12255
Dave Barach72d72232016-08-04 10:15:08 -040012256 if (priority_set == 0)
12257 {
12258 errmsg ("missing locator-set priority\n");
12259 vec_free (locator_set_name);
12260 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012261 }
12262
Dave Barach72d72232016-08-04 10:15:08 -040012263 if (weight_set == 0)
12264 {
12265 errmsg ("missing locator-set weight\n");
12266 vec_free (locator_set_name);
12267 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012268 }
12269
Dave Barach72d72232016-08-04 10:15:08 -040012270 if (vec_len (locator_set_name) > 64)
12271 {
12272 errmsg ("locator-set name too long\n");
12273 vec_free (locator_set_name);
12274 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012275 }
Dave Barach72d72232016-08-04 10:15:08 -040012276 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012277
Dave Barach72d72232016-08-04 10:15:08 -040012278 /* Construct the API message */
12279 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012280
Dave Barach72d72232016-08-04 10:15:08 -040012281 mp->is_add = is_add;
12282 mp->sw_if_index = ntohl (sw_if_index);
12283 mp->priority = priority;
12284 mp->weight = weight;
12285 clib_memcpy (mp->locator_set_name, locator_set_name,
12286 vec_len (locator_set_name));
12287 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012288
Dave Barach72d72232016-08-04 10:15:08 -040012289 /* send it... */
12290 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012291
Dave Barach72d72232016-08-04 10:15:08 -040012292 /* Wait for a reply... */
12293 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012294
Dave Barach72d72232016-08-04 10:15:08 -040012295 /* NOTREACHED */
12296 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012297}
12298
12299static int
Dave Barach72d72232016-08-04 10:15:08 -040012300api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012301{
Dave Barach72d72232016-08-04 10:15:08 -040012302 unformat_input_t *input = vam->input;
12303 vl_api_lisp_add_del_local_eid_t *mp;
12304 f64 timeout = ~0;
12305 u8 is_add = 1;
12306 u8 eid_set = 0;
12307 lisp_eid_vat_t _eid, *eid = &_eid;
12308 u8 *locator_set_name = 0;
12309 u8 locator_set_name_set = 0;
12310 u32 vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012311
Dave Barach72d72232016-08-04 10:15:08 -040012312 /* Parse args required to build the message */
12313 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12314 {
12315 if (unformat (input, "del"))
12316 {
12317 is_add = 0;
12318 }
12319 else if (unformat (input, "vni %d", &vni))
12320 {
12321 ;
12322 }
12323 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
12324 {
12325 eid_set = 1;
12326 }
12327 else if (unformat (input, "locator-set %s", &locator_set_name))
12328 {
12329 locator_set_name_set = 1;
12330 }
12331 else
12332 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012333 }
12334
Dave Barach72d72232016-08-04 10:15:08 -040012335 if (locator_set_name_set == 0)
12336 {
12337 errmsg ("missing locator-set name\n");
12338 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012339 }
12340
Dave Barach72d72232016-08-04 10:15:08 -040012341 if (0 == eid_set)
12342 {
12343 errmsg ("EID address not set!");
12344 vec_free (locator_set_name);
12345 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020012346 }
12347
Dave Barach72d72232016-08-04 10:15:08 -040012348 if (vec_len (locator_set_name) > 64)
12349 {
12350 errmsg ("locator-set name too long\n");
12351 vec_free (locator_set_name);
12352 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012353 }
Dave Barach72d72232016-08-04 10:15:08 -040012354 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012355
Dave Barach72d72232016-08-04 10:15:08 -040012356 /* Construct the API message */
12357 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012358
Dave Barach72d72232016-08-04 10:15:08 -040012359 mp->is_add = is_add;
12360 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
12361 mp->eid_type = eid->type;
12362 mp->prefix_len = eid->len;
12363 mp->vni = clib_host_to_net_u32 (vni);
12364 clib_memcpy (mp->locator_set_name, locator_set_name,
12365 vec_len (locator_set_name));
Florin Coras429e7952016-08-02 02:31:03 +020012366
Dave Barach72d72232016-08-04 10:15:08 -040012367 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012368
Dave Barach72d72232016-08-04 10:15:08 -040012369 /* send it... */
12370 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012371
Dave Barach72d72232016-08-04 10:15:08 -040012372 /* Wait for a reply... */
12373 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012374
Dave Barach72d72232016-08-04 10:15:08 -040012375 /* NOTREACHED */
12376 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012377}
12378
Dave Barach72d72232016-08-04 10:15:08 -040012379/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012380/** Used for transferring locators via VPP API */
12381typedef CLIB_PACKED(struct
12382{
Dave Barach72d72232016-08-04 10:15:08 -040012383 u8 is_ip4; /**< is locator an IPv4 address? */
12384 u8 priority; /**< locator priority */
12385 u8 weight; /**< locator weight */
12386 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020012387}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040012388/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012389
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012390static int
Dave Barach72d72232016-08-04 10:15:08 -040012391api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012392{
Dave Barach72d72232016-08-04 10:15:08 -040012393 unformat_input_t *input = vam->input;
12394 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
12395 f64 timeout = ~0;
12396 u8 is_add = 1;
12397 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
12398 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
12399 u8 rmt_eid_set = 0, lcl_eid_set = 0;
12400 u32 action = ~0, p, w;
12401 ip4_address_t rmt_rloc4, lcl_rloc4;
12402 ip6_address_t rmt_rloc6, lcl_rloc6;
12403 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012404
Dave Barach839fe3e2016-08-10 11:35:54 -040012405 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020012406
Dave Barach72d72232016-08-04 10:15:08 -040012407 /* Parse args required to build the message */
12408 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12409 {
12410 if (unformat (input, "del"))
12411 {
12412 is_add = 0;
12413 }
12414 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
12415 {
12416 rmt_eid_set = 1;
12417 }
12418 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
12419 {
12420 lcl_eid_set = 1;
12421 }
12422 else if (unformat (input, "p %d w %d", &p, &w))
12423 {
12424 if (!curr_rloc)
12425 {
12426 errmsg ("No RLOC configured for setting priority/weight!");
12427 return -99;
12428 }
12429 curr_rloc->priority = p;
12430 curr_rloc->weight = w;
12431 }
12432 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
12433 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
12434 {
12435 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020012436
Dave Barach72d72232016-08-04 10:15:08 -040012437 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020012438 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012439 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012440
Dave Barach72d72232016-08-04 10:15:08 -040012441 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
12442 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012443 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012444 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12445 }
Florin Coras7fbfad32016-08-05 16:57:33 +020012446 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040012447 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
12448 {
12449 rloc.is_ip4 = 0;
12450 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020012451 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012452 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012453
Dave Barach72d72232016-08-04 10:15:08 -040012454 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
12455 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012456 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012457 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12458 }
12459 else if (unformat (input, "action %d", &action))
12460 {
12461 ;
12462 }
12463 else
12464 {
12465 clib_warning ("parse error '%U'", format_unformat_error, input);
12466 return -99;
12467 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012468 }
12469
Dave Barach72d72232016-08-04 10:15:08 -040012470 if (!rmt_eid_set)
12471 {
12472 errmsg ("remote eid addresses not set\n");
12473 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012474 }
12475
Dave Barach72d72232016-08-04 10:15:08 -040012476 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
12477 {
12478 errmsg ("eid types don't match\n");
12479 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012480 }
12481
Dave Barach839fe3e2016-08-10 11:35:54 -040012482 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020012483 {
12484 errmsg ("action not set for negative mapping\n");
12485 return -99;
12486 }
12487
Dave Barach72d72232016-08-04 10:15:08 -040012488 /* Construct the API message */
12489 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012490
Dave Barach72d72232016-08-04 10:15:08 -040012491 mp->is_add = is_add;
12492 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
12493 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
12494 mp->eid_type = rmt_eid->type;
12495 mp->rmt_len = rmt_eid->len;
12496 mp->lcl_len = lcl_eid->len;
12497 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020012498
Florin Coras7fbfad32016-08-05 16:57:33 +020012499 if (0 != rmt_locs && 0 != lcl_locs)
12500 {
Dave Barach839fe3e2016-08-10 11:35:54 -040012501 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020012502 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012503 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012504 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012505 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012506 }
Dave Barach72d72232016-08-04 10:15:08 -040012507 vec_free (lcl_locs);
12508 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012509
Dave Barach72d72232016-08-04 10:15:08 -040012510 /* send it... */
12511 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012512
Dave Barach72d72232016-08-04 10:15:08 -040012513 /* Wait for a reply... */
12514 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012515
Dave Barach72d72232016-08-04 10:15:08 -040012516 /* NOTREACHED */
12517 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012518}
12519
12520static int
Dave Barach72d72232016-08-04 10:15:08 -040012521api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012522{
Dave Barach72d72232016-08-04 10:15:08 -040012523 unformat_input_t *input = vam->input;
12524 vl_api_lisp_add_del_map_resolver_t *mp;
12525 f64 timeout = ~0;
12526 u8 is_add = 1;
12527 u8 ipv4_set = 0;
12528 u8 ipv6_set = 0;
12529 ip4_address_t ipv4;
12530 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012531
Dave Barach72d72232016-08-04 10:15:08 -040012532 /* Parse args required to build the message */
12533 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12534 {
12535 if (unformat (input, "del"))
12536 {
12537 is_add = 0;
12538 }
12539 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
12540 {
12541 ipv4_set = 1;
12542 }
12543 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
12544 {
12545 ipv6_set = 1;
12546 }
12547 else
12548 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012549 }
12550
Dave Barach72d72232016-08-04 10:15:08 -040012551 if (ipv4_set && ipv6_set)
12552 {
12553 errmsg ("both eid v4 and v6 addresses set\n");
12554 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012555 }
12556
Dave Barach72d72232016-08-04 10:15:08 -040012557 if (!ipv4_set && !ipv6_set)
12558 {
12559 errmsg ("eid addresses not set\n");
12560 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012561 }
12562
Dave Barach72d72232016-08-04 10:15:08 -040012563 /* Construct the API message */
12564 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012565
Dave Barach72d72232016-08-04 10:15:08 -040012566 mp->is_add = is_add;
12567 if (ipv6_set)
12568 {
12569 mp->is_ipv6 = 1;
12570 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
12571 }
12572 else
12573 {
12574 mp->is_ipv6 = 0;
12575 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012576 }
12577
Dave Barach72d72232016-08-04 10:15:08 -040012578 /* send it... */
12579 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012580
Dave Barach72d72232016-08-04 10:15:08 -040012581 /* Wait for a reply... */
12582 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012583
Dave Barach72d72232016-08-04 10:15:08 -040012584 /* NOTREACHED */
12585 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012586}
12587
12588static int
Florin Coras577c3552016-04-21 00:45:40 +020012589api_lisp_gpe_enable_disable (vat_main_t * vam)
12590{
Dave Barach72d72232016-08-04 10:15:08 -040012591 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020012592 vl_api_lisp_gpe_enable_disable_t *mp;
12593 f64 timeout = ~0;
12594 u8 is_set = 0;
12595 u8 is_en = 1;
12596
12597 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040012598 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12599 {
12600 if (unformat (input, "enable"))
12601 {
12602 is_set = 1;
12603 is_en = 1;
12604 }
12605 else if (unformat (input, "disable"))
12606 {
12607 is_set = 1;
12608 is_en = 0;
12609 }
12610 else
12611 break;
12612 }
Florin Coras577c3552016-04-21 00:45:40 +020012613
Dave Barach72d72232016-08-04 10:15:08 -040012614 if (is_set == 0)
12615 {
12616 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020012617 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040012618 }
Florin Coras577c3552016-04-21 00:45:40 +020012619
12620 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012621 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020012622
12623 mp->is_en = is_en;
12624
12625 /* send it... */
12626 S;
12627
12628 /* Wait for a reply... */
12629 W;
12630
12631 /* NOTREACHED */
12632 return 0;
12633}
12634
12635static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020012636api_lisp_enable_disable (vat_main_t * vam)
12637{
Dave Barach72d72232016-08-04 10:15:08 -040012638 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020012639 vl_api_lisp_enable_disable_t *mp;
12640 f64 timeout = ~0;
12641 u8 is_set = 0;
12642 u8 is_en = 0;
12643
12644 /* Parse args required to build the message */
12645 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12646 {
12647 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040012648 {
12649 is_set = 1;
12650 is_en = 1;
12651 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020012652 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040012653 {
12654 is_set = 1;
12655 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020012656 else
Dave Barach72d72232016-08-04 10:15:08 -040012657 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020012658 }
12659
12660 if (!is_set)
12661 {
12662 errmsg ("Value not set\n");
12663 return -99;
12664 }
12665
12666 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012667 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020012668
12669 mp->is_en = is_en;
12670
12671 /* send it... */
12672 S;
12673
12674 /* Wait for a reply... */
12675 W;
12676
12677 /* NOTREACHED */
12678 return 0;
12679}
12680
Florin Corasdca88042016-09-14 16:01:38 +020012681static int
12682api_show_lisp_map_request_mode (vat_main_t * vam)
12683{
12684 f64 timeout = ~0;
12685 vl_api_show_lisp_map_request_mode_t *mp;
12686
12687 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
12688
12689 /* send */
12690 S;
12691
12692 /* wait for reply */
12693 W;
12694
12695 return 0;
12696}
12697
12698static int
12699api_lisp_map_request_mode (vat_main_t * vam)
12700{
12701 f64 timeout = ~0;
12702 unformat_input_t *input = vam->input;
12703 vl_api_lisp_map_request_mode_t *mp;
12704 u8 mode = 0;
12705
12706 /* Parse args required to build the message */
12707 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12708 {
12709 if (unformat (input, "dst-only"))
12710 mode = 0;
12711 else if (unformat (input, "src-dst"))
12712 mode = 1;
12713 else
12714 {
12715 errmsg ("parse error '%U'", format_unformat_error, input);
12716 return -99;
12717 }
12718 }
12719
12720 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
12721
12722 mp->mode = mode;
12723
12724 /* send */
12725 S;
12726
12727 /* wait for reply */
12728 W;
12729
12730 /* notreached */
12731 return 0;
12732}
12733
Filip Tehlar195bcee2016-05-13 17:37:35 +020012734/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020012735 * Enable/disable LISP proxy ITR.
12736 *
12737 * @param vam vpp API test context
12738 * @return return code
12739 */
12740static int
12741api_lisp_pitr_set_locator_set (vat_main_t * vam)
12742{
12743 f64 timeout = ~0;
12744 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012745 unformat_input_t *input = vam->input;
12746 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012747 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012748 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012749
12750 /* Parse args required to build the message */
12751 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12752 {
12753 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040012754 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012755 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040012756 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012757 else
Dave Barach72d72232016-08-04 10:15:08 -040012758 {
12759 errmsg ("parse error '%U'", format_unformat_error, input);
12760 return -99;
12761 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020012762 }
12763
12764 if (!ls_name_set)
12765 {
12766 errmsg ("locator-set name not set!");
12767 return -99;
12768 }
12769
Dave Barach72d72232016-08-04 10:15:08 -040012770 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020012771
12772 mp->is_add = is_add;
12773 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
12774 vec_free (ls_name);
12775
12776 /* send */
12777 S;
12778
12779 /* wait for reply */
12780 W;
12781
Dave Barach72d72232016-08-04 10:15:08 -040012782 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020012783 return 0;
12784}
12785
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012786static int
12787api_show_lisp_pitr (vat_main_t * vam)
12788{
Dave Barach72d72232016-08-04 10:15:08 -040012789 vl_api_show_lisp_pitr_t *mp;
12790 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012791
Dave Barach72d72232016-08-04 10:15:08 -040012792 if (!vam->json_output)
12793 {
12794 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012795 }
12796
Dave Barach72d72232016-08-04 10:15:08 -040012797 M (SHOW_LISP_PITR, show_lisp_pitr);
12798 /* send it... */
12799 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012800
Dave Barach72d72232016-08-04 10:15:08 -040012801 /* Wait for a reply... */
12802 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012803
Dave Barach72d72232016-08-04 10:15:08 -040012804 /* NOTREACHED */
12805 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012806}
12807
Filip Tehlar53f09e32016-05-19 14:25:44 +020012808/**
Filip Tehlar324112f2016-06-02 16:07:38 +020012809 * Add/delete mapping between vni and vrf
12810 */
12811static int
12812api_lisp_eid_table_add_del_map (vat_main_t * vam)
12813{
12814 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040012815 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020012816 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020012817 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
12818 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020012819
12820 /* Parse args required to build the message */
12821 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12822 {
12823 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040012824 is_add = 0;
12825 else if (unformat (input, "vrf %d", &vrf))
12826 vrf_set = 1;
12827 else if (unformat (input, "bd_index %d", &bd_index))
12828 bd_index_set = 1;
12829 else if (unformat (input, "vni %d", &vni))
12830 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020012831 else
Dave Barach72d72232016-08-04 10:15:08 -040012832 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020012833 }
12834
Florin Coras1a1adc72016-07-22 01:45:30 +020012835 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020012836 {
12837 errmsg ("missing arguments!");
12838 return -99;
12839 }
12840
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020012841 if (vrf_set && bd_index_set)
12842 {
12843 errmsg ("error: both vrf and bd entered!");
12844 return -99;
12845 }
12846
Dave Barach72d72232016-08-04 10:15:08 -040012847 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020012848
12849 mp->is_add = is_add;
12850 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020012851 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020012852 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020012853
12854 /* send */
12855 S;
12856
12857 /* wait for reply */
12858 W;
12859
Dave Barach72d72232016-08-04 10:15:08 -040012860 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020012861 return 0;
12862}
12863
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012864uword
12865unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
12866{
12867 u32 *action = va_arg (*args, u32 *);
12868 u8 *s = 0;
12869
12870 if (unformat (input, "%s", &s))
12871 {
12872 if (!strcmp ((char *) s, "no-action"))
12873 action[0] = 0;
12874 else if (!strcmp ((char *) s, "natively-forward"))
12875 action[0] = 1;
12876 else if (!strcmp ((char *) s, "send-map-request"))
12877 action[0] = 2;
12878 else if (!strcmp ((char *) s, "drop"))
12879 action[0] = 3;
12880 else
12881 {
12882 clib_warning ("invalid action: '%s'", s);
12883 action[0] = 3;
12884 }
12885 }
12886 else
12887 return 0;
12888
12889 vec_free (s);
12890 return 1;
12891}
12892
Filip Tehlar324112f2016-06-02 16:07:38 +020012893/**
Florin Corasf727db92016-06-23 15:01:58 +020012894 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020012895 *
12896 * @param vam vpp API test context
12897 * @return return code
12898 */
12899static int
12900api_lisp_add_del_remote_mapping (vat_main_t * vam)
12901{
Dave Barach72d72232016-08-04 10:15:08 -040012902 unformat_input_t *input = vam->input;
12903 vl_api_lisp_add_del_remote_mapping_t *mp;
12904 f64 timeout = ~0;
12905 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012906 lisp_eid_vat_t _eid, *eid = &_eid;
12907 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012908 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012909 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040012910 ip4_address_t rloc4;
12911 ip6_address_t rloc6;
12912 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012913
Dave Barach839fe3e2016-08-10 11:35:54 -040012914 memset (&rloc, 0, sizeof (rloc));
12915
Dave Barach72d72232016-08-04 10:15:08 -040012916 /* Parse args required to build the message */
12917 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12918 {
12919 if (unformat (input, "del-all"))
12920 {
12921 del_all = 1;
12922 }
12923 else if (unformat (input, "del"))
12924 {
12925 is_add = 0;
12926 }
12927 else if (unformat (input, "add"))
12928 {
12929 is_add = 1;
12930 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020012931 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040012932 {
12933 eid_set = 1;
12934 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012935 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040012936 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012937 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012938 }
12939 else if (unformat (input, "vni %d", &vni))
12940 {
12941 ;
12942 }
12943 else if (unformat (input, "p %d w %d", &p, &w))
12944 {
12945 if (!curr_rloc)
12946 {
12947 errmsg ("No RLOC configured for setting priority/weight!");
12948 return -99;
12949 }
12950 curr_rloc->priority = p;
12951 curr_rloc->weight = w;
12952 }
12953 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
12954 {
12955 rloc.is_ip4 = 1;
12956 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
12957 vec_add1 (rlocs, rloc);
12958 curr_rloc = &rlocs[vec_len (rlocs) - 1];
12959 }
12960 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
12961 {
12962 rloc.is_ip4 = 0;
12963 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
12964 vec_add1 (rlocs, rloc);
12965 curr_rloc = &rlocs[vec_len (rlocs) - 1];
12966 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012967 else if (unformat (input, "action %U",
12968 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040012969 {
12970 ;
12971 }
12972 else
12973 {
12974 clib_warning ("parse error '%U'", format_unformat_error, input);
12975 return -99;
12976 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020012977 }
12978
Dave Barach72d72232016-08-04 10:15:08 -040012979 if (0 == eid_set)
12980 {
12981 errmsg ("missing params!");
12982 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012983 }
12984
Dave Barach72d72232016-08-04 10:15:08 -040012985 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
12986 {
12987 errmsg ("no action set for negative map-reply!");
12988 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012989 }
12990
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012991 data_len = vec_len (rlocs) * sizeof (rloc_t);
12992
12993 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012994 mp->is_add = is_add;
12995 mp->vni = htonl (vni);
12996 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012997 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040012998 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012999 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040013000 mp->del_all = del_all;
13001 mp->eid_type = eid->type;
13002 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013003 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013004
Filip Tehlare3552c42016-08-26 12:44:38 +020013005 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013006 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013007 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013008
Dave Barach72d72232016-08-04 10:15:08 -040013009 /* send it... */
13010 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013011
Dave Barach72d72232016-08-04 10:15:08 -040013012 /* Wait for a reply... */
13013 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013014
Dave Barach72d72232016-08-04 10:15:08 -040013015 /* NOTREACHED */
13016 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013017}
13018
Florin Corasf727db92016-06-23 15:01:58 +020013019/**
13020 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
13021 * forwarding entries in data-plane accordingly.
13022 *
13023 * @param vam vpp API test context
13024 * @return return code
13025 */
13026static int
13027api_lisp_add_del_adjacency (vat_main_t * vam)
13028{
Dave Barach72d72232016-08-04 10:15:08 -040013029 unformat_input_t *input = vam->input;
13030 vl_api_lisp_add_del_adjacency_t *mp;
13031 f64 timeout = ~0;
13032 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013033 ip4_address_t leid4, reid4;
13034 ip6_address_t leid6, reid6;
13035 u8 reid_mac[6] = { 0 };
13036 u8 leid_mac[6] = { 0 };
13037 u8 reid_type, leid_type;
13038 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040013039 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020013040
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013041 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020013042
Dave Barach72d72232016-08-04 10:15:08 -040013043 /* Parse args required to build the message */
13044 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13045 {
13046 if (unformat (input, "del"))
13047 {
13048 is_add = 0;
13049 }
13050 else if (unformat (input, "add"))
13051 {
13052 is_add = 1;
13053 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013054 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
13055 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013056 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013057 reid_type = 0; /* ipv4 */
13058 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013059 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013060 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
13061 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013062 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013063 reid_type = 1; /* ipv6 */
13064 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013065 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013066 else if (unformat (input, "reid %U", unformat_ethernet_address,
13067 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013068 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013069 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013070 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013071 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
13072 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013073 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013074 leid_type = 0; /* ipv4 */
13075 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013076 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013077 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
13078 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013079 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013080 leid_type = 1; /* ipv6 */
13081 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013082 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013083 else if (unformat (input, "leid %U", unformat_ethernet_address,
13084 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013085 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013086 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013087 }
13088 else if (unformat (input, "vni %d", &vni))
13089 {
13090 ;
13091 }
13092 else
13093 {
13094 errmsg ("parse error '%U'", format_unformat_error, input);
13095 return -99;
13096 }
Florin Corasf727db92016-06-23 15:01:58 +020013097 }
13098
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013099 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013100 {
13101 errmsg ("missing params!");
13102 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013103 }
13104
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013105 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013106 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013107 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040013108 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013109 }
13110
Dave Barach72d72232016-08-04 10:15:08 -040013111 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
13112 mp->is_add = is_add;
13113 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013114 mp->leid_len = leid_len;
13115 mp->reid_len = reid_len;
13116 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020013117
Dave Barach72d72232016-08-04 10:15:08 -040013118 switch (mp->eid_type)
13119 {
Florin Corasf727db92016-06-23 15:01:58 +020013120 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013121 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
13122 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040013123 break;
Florin Corasf727db92016-06-23 15:01:58 +020013124 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013125 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
13126 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040013127 break;
Florin Corasf727db92016-06-23 15:01:58 +020013128 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013129 clib_memcpy (mp->leid, leid_mac, 6);
13130 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040013131 break;
Florin Corasf727db92016-06-23 15:01:58 +020013132 default:
Dave Barach72d72232016-08-04 10:15:08 -040013133 errmsg ("unknown EID type %d!", mp->eid_type);
13134 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013135 }
13136
Dave Barach72d72232016-08-04 10:15:08 -040013137 /* send it... */
13138 S;
Florin Corasf727db92016-06-23 15:01:58 +020013139
Dave Barach72d72232016-08-04 10:15:08 -040013140 /* Wait for a reply... */
13141 W;
Florin Corasf727db92016-06-23 15:01:58 +020013142
Dave Barach72d72232016-08-04 10:15:08 -040013143 /* NOTREACHED */
13144 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013145}
13146
Filip Tehlar46d4e362016-05-09 09:39:26 +020013147static int
Dave Barach72d72232016-08-04 10:15:08 -040013148api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013149{
Dave Barach72d72232016-08-04 10:15:08 -040013150 unformat_input_t *input = vam->input;
13151 vl_api_lisp_gpe_add_del_iface_t *mp;
13152 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020013153 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040013154 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013155
Dave Barach72d72232016-08-04 10:15:08 -040013156 /* Parse args required to build the message */
13157 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13158 {
13159 if (unformat (input, "up"))
13160 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013161 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013162 is_add = 1;
13163 }
13164 else if (unformat (input, "down"))
13165 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013166 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013167 is_add = 0;
13168 }
13169 else if (unformat (input, "table_id %d", &dp_table))
13170 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013171 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013172 }
13173 else if (unformat (input, "bd_id %d", &dp_table))
13174 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013175 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013176 is_l2 = 1;
13177 }
13178 else if (unformat (input, "vni %d", &vni))
13179 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013180 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013181 }
13182 else
13183 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013184 }
13185
Florin Coras7fbfad32016-08-05 16:57:33 +020013186 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040013187 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013188 errmsg ("Action not set\n");
13189 return -99;
13190 }
13191 if (dp_table_set == 0 || vni_set == 0)
13192 {
13193 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040013194 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013195 }
13196
Dave Barach72d72232016-08-04 10:15:08 -040013197 /* Construct the API message */
13198 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013199
Dave Barach72d72232016-08-04 10:15:08 -040013200 mp->is_add = is_add;
13201 mp->dp_table = dp_table;
13202 mp->is_l2 = is_l2;
13203 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013204
Dave Barach72d72232016-08-04 10:15:08 -040013205 /* send it... */
13206 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013207
Dave Barach72d72232016-08-04 10:15:08 -040013208 /* Wait for a reply... */
13209 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013210
Dave Barach72d72232016-08-04 10:15:08 -040013211 /* NOTREACHED */
13212 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013213}
13214
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013215/**
13216 * Add/del map request itr rlocs from LISP control plane and updates
13217 *
13218 * @param vam vpp API test context
13219 * @return return code
13220 */
13221static int
Dave Barach72d72232016-08-04 10:15:08 -040013222api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013223{
Dave Barach72d72232016-08-04 10:15:08 -040013224 unformat_input_t *input = vam->input;
13225 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
13226 f64 timeout = ~0;
13227 u8 *locator_set_name = 0;
13228 u8 locator_set_name_set = 0;
13229 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013230
Dave Barach72d72232016-08-04 10:15:08 -040013231 /* Parse args required to build the message */
13232 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013233 {
Dave Barach72d72232016-08-04 10:15:08 -040013234 if (unformat (input, "del"))
13235 {
13236 is_add = 0;
13237 }
13238 else if (unformat (input, "%_%v%_", &locator_set_name))
13239 {
13240 locator_set_name_set = 1;
13241 }
13242 else
13243 {
13244 clib_warning ("parse error '%U'", format_unformat_error, input);
13245 return -99;
13246 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013247 }
13248
Dave Barach72d72232016-08-04 10:15:08 -040013249 if (is_add && !locator_set_name_set)
13250 {
13251 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020013252 return -99;
13253 }
13254
Dave Barach72d72232016-08-04 10:15:08 -040013255 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020013256 {
Dave Barach72d72232016-08-04 10:15:08 -040013257 errmsg ("itr-rloc locator-set name too long\n");
13258 vec_free (locator_set_name);
13259 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013260 }
13261
Dave Barach72d72232016-08-04 10:15:08 -040013262 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
13263 mp->is_add = is_add;
13264 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013265 {
Dave Barach72d72232016-08-04 10:15:08 -040013266 clib_memcpy (mp->locator_set_name, locator_set_name,
13267 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013268 }
Dave Barach72d72232016-08-04 10:15:08 -040013269 else
13270 {
13271 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013272 }
Dave Barach72d72232016-08-04 10:15:08 -040013273 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013274
Dave Barach72d72232016-08-04 10:15:08 -040013275 /* send it... */
13276 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013277
Dave Barach72d72232016-08-04 10:15:08 -040013278 /* Wait for a reply... */
13279 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013280
Dave Barach72d72232016-08-04 10:15:08 -040013281 /* NOTREACHED */
13282 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013283}
13284
13285static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013286api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013287{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013288 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013289 vl_api_lisp_locator_dump_t *mp;
13290 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013291 u8 is_index_set = 0, is_name_set = 0;
13292 u8 *ls_name = 0;
13293 u32 ls_index = ~0;
13294
13295 /* Parse args required to build the message */
13296 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13297 {
13298 if (unformat (input, "ls_name %_%v%_", &ls_name))
13299 {
13300 is_name_set = 1;
13301 }
13302 else if (unformat (input, "ls_index %d", &ls_index))
13303 {
13304 is_index_set = 1;
13305 }
13306 else
13307 {
13308 errmsg ("parse error '%U'", format_unformat_error, input);
13309 return -99;
13310 }
13311 }
13312
13313 if (!is_index_set && !is_name_set)
13314 {
13315 errmsg ("error: expected one of index or name!\n");
13316 return -99;
13317 }
13318
13319 if (is_index_set && is_name_set)
13320 {
13321 errmsg ("error: only one param expected!\n");
13322 return -99;
13323 }
13324
Florin Coras042d2122016-09-21 16:38:19 +020013325 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020013326 {
13327 errmsg ("error: locator set name too long!");
13328 return -99;
13329 }
13330
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013331 if (!vam->json_output)
13332 {
13333 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
13334 "weight");
13335 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013336
Dave Barach72d72232016-08-04 10:15:08 -040013337 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013338 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013339
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013340 if (is_index_set)
13341 mp->ls_index = clib_host_to_net_u32 (ls_index);
13342 else
13343 {
13344 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020013345 strncpy ((char *) mp->ls_name, (char *) ls_name,
13346 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013347 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013348
Dave Barach72d72232016-08-04 10:15:08 -040013349 /* send it... */
13350 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013351
Dave Barach72d72232016-08-04 10:15:08 -040013352 /* Use a control ping for synchronization */
13353 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013354 vl_api_control_ping_t *mp;
13355 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013356 S;
13357 }
13358 /* Wait for a reply... */
13359 W;
Dave Barach72d72232016-08-04 10:15:08 -040013360
13361 /* NOTREACHED */
13362 return 0;
13363}
13364
13365static int
13366api_lisp_locator_set_dump (vat_main_t * vam)
13367{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013368 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040013369 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013370 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013371 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013372
13373 /* Parse args required to build the message */
13374 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13375 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013376 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040013377 {
13378 filter = 1;
13379 }
13380 else if (unformat (input, "remote"))
13381 {
13382 filter = 2;
13383 }
13384 else
13385 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013386 errmsg ("parse error '%U'", format_unformat_error, input);
13387 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013388 }
13389 }
13390
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013391 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040013392 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013393 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040013394 }
13395
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013396 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040013397
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013398 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040013399
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013400 /* send it... */
13401 S;
13402
13403 /* Use a control ping for synchronization */
13404 {
13405 vl_api_control_ping_t *mp;
13406 M (CONTROL_PING, control_ping);
13407 S;
13408 }
13409 /* Wait for a reply... */
13410 W;
13411
13412 /* NOTREACHED */
13413 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040013414}
13415
13416static int
13417api_lisp_eid_table_map_dump (vat_main_t * vam)
13418{
Filip Tehlarc0681792016-08-24 14:11:07 +020013419 u8 is_l2 = 0;
13420 u8 mode_set = 0;
13421 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013422 vl_api_lisp_eid_table_map_dump_t *mp;
13423 f64 timeout = ~0;
13424
Filip Tehlarc0681792016-08-24 14:11:07 +020013425 /* Parse args required to build the message */
13426 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13427 {
13428 if (unformat (input, "l2"))
13429 {
13430 is_l2 = 1;
13431 mode_set = 1;
13432 }
13433 else if (unformat (input, "l3"))
13434 {
13435 is_l2 = 0;
13436 mode_set = 1;
13437 }
13438 else
13439 {
13440 errmsg ("parse error '%U'", format_unformat_error, input);
13441 return -99;
13442 }
13443 }
13444
13445 if (!mode_set)
13446 {
13447 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
13448 return -99;
13449 }
13450
Dave Barach72d72232016-08-04 10:15:08 -040013451 if (!vam->json_output)
13452 {
Filip Tehlarc0681792016-08-24 14:11:07 +020013453 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040013454 }
13455
13456 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020013457 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040013458
13459 /* send it... */
13460 S;
13461
13462 /* Use a control ping for synchronization */
13463 {
13464 vl_api_control_ping_t *mp;
13465 M (CONTROL_PING, control_ping);
13466 S;
13467 }
13468 /* Wait for a reply... */
13469 W;
13470
13471 /* NOTREACHED */
13472 return 0;
13473}
13474
13475static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020013476api_lisp_eid_table_vni_dump (vat_main_t * vam)
13477{
13478 vl_api_lisp_eid_table_vni_dump_t *mp;
13479 f64 timeout = ~0;
13480
13481 if (!vam->json_output)
13482 {
13483 fformat (vam->ofp, "VNI\n");
13484 }
13485
13486 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
13487
13488 /* send it... */
13489 S;
13490
13491 /* Use a control ping for synchronization */
13492 {
13493 vl_api_control_ping_t *mp;
13494 M (CONTROL_PING, control_ping);
13495 S;
13496 }
13497 /* Wait for a reply... */
13498 W;
13499
13500 /* NOTREACHED */
13501 return 0;
13502}
13503
13504static int
Dave Barach72d72232016-08-04 10:15:08 -040013505api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013506{
Dave Barach72d72232016-08-04 10:15:08 -040013507 unformat_input_t *i = vam->input;
13508 vl_api_lisp_eid_table_dump_t *mp;
13509 f64 timeout = ~0;
13510 struct in_addr ip4;
13511 struct in6_addr ip6;
13512 u8 mac[6];
13513 u8 eid_type = ~0, eid_set = 0;
13514 u32 prefix_length = ~0, t, vni = 0;
13515 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013516
Dave Barach72d72232016-08-04 10:15:08 -040013517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013518 {
Dave Barach72d72232016-08-04 10:15:08 -040013519 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
13520 {
13521 eid_set = 1;
13522 eid_type = 0;
13523 prefix_length = t;
13524 }
13525 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
13526 {
13527 eid_set = 1;
13528 eid_type = 1;
13529 prefix_length = t;
13530 }
13531 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
13532 {
13533 eid_set = 1;
13534 eid_type = 2;
13535 }
13536 else if (unformat (i, "vni %d", &t))
13537 {
13538 vni = t;
13539 }
13540 else if (unformat (i, "local"))
13541 {
13542 filter = 1;
13543 }
13544 else if (unformat (i, "remote"))
13545 {
13546 filter = 2;
13547 }
13548 else
13549 {
13550 errmsg ("parse error '%U'", format_unformat_error, i);
13551 return -99;
13552 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013553 }
13554
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013555 if (!vam->json_output)
13556 {
13557 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type",
13558 "ls_index", "ttl", "authoritative");
13559 }
13560
Dave Barach72d72232016-08-04 10:15:08 -040013561 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013562
Dave Barach72d72232016-08-04 10:15:08 -040013563 mp->filter = filter;
13564 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013565 {
Dave Barach72d72232016-08-04 10:15:08 -040013566 mp->eid_set = 1;
13567 mp->vni = htonl (vni);
13568 mp->eid_type = eid_type;
13569 switch (eid_type)
13570 {
13571 case 0:
13572 mp->prefix_length = prefix_length;
13573 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
13574 break;
13575 case 1:
13576 mp->prefix_length = prefix_length;
13577 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
13578 break;
13579 case 2:
13580 clib_memcpy (mp->eid, mac, sizeof (mac));
13581 break;
13582 default:
13583 errmsg ("unknown EID type %d!", eid_type);
13584 return -99;
13585 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013586 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013587
Dave Barach72d72232016-08-04 10:15:08 -040013588 /* send it... */
13589 S;
13590
13591 /* Use a control ping for synchronization */
13592 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013593 vl_api_control_ping_t *mp;
13594 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013595 S;
13596 }
13597
13598 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013599 W;
Dave Barach72d72232016-08-04 10:15:08 -040013600
13601 /* NOTREACHED */
13602 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013603}
13604
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013605static int
Dave Barach72d72232016-08-04 10:15:08 -040013606api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013607{
Dave Barach72d72232016-08-04 10:15:08 -040013608 vl_api_lisp_gpe_tunnel_dump_t *mp;
13609 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013610
Dave Barach72d72232016-08-04 10:15:08 -040013611 if (!vam->json_output)
13612 {
13613 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
13614 "%=16s%=16s%=16s%=16s%=16s\n",
13615 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
13616 "Decap next", "Lisp version", "Flags", "Next protocol",
13617 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013618 }
13619
Dave Barach72d72232016-08-04 10:15:08 -040013620 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
13621 /* send it... */
13622 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013623
Dave Barach72d72232016-08-04 10:15:08 -040013624 /* Use a control ping for synchronization */
13625 {
13626 vl_api_control_ping_t *mp;
13627 M (CONTROL_PING, control_ping);
13628 S;
13629 }
13630 /* Wait for a reply... */
13631 W;
13632
13633 /* NOTREACHED */
13634 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013635}
13636
Matus Fabian8a95a482016-05-06 15:14:13 +020013637static int
Dave Barach72d72232016-08-04 10:15:08 -040013638api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013639{
Dave Barach72d72232016-08-04 10:15:08 -040013640 vl_api_lisp_map_resolver_dump_t *mp;
13641 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013642
Dave Barach72d72232016-08-04 10:15:08 -040013643 if (!vam->json_output)
13644 {
13645 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013646 }
13647
Dave Barach72d72232016-08-04 10:15:08 -040013648 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
13649 /* send it... */
13650 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013651
Dave Barach72d72232016-08-04 10:15:08 -040013652 /* Use a control ping for synchronization */
13653 {
13654 vl_api_control_ping_t *mp;
13655 M (CONTROL_PING, control_ping);
13656 S;
13657 }
13658 /* Wait for a reply... */
13659 W;
13660
13661 /* NOTREACHED */
13662 return 0;
13663}
13664
13665static int
13666api_show_lisp_status (vat_main_t * vam)
13667{
13668 vl_api_show_lisp_status_t *mp;
13669 f64 timeout = ~0;
13670
13671 if (!vam->json_output)
13672 {
13673 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
13674 }
13675
13676 M (SHOW_LISP_STATUS, show_lisp_status);
13677 /* send it... */
13678 S;
13679 /* Wait for a reply... */
13680 W;
13681
13682 /* NOTREACHED */
13683 return 0;
13684}
13685
13686static int
13687api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
13688{
13689 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
13690 f64 timeout = ~0;
13691
13692 if (!vam->json_output)
13693 {
13694 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
13695 }
13696
13697 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
13698 /* send it... */
13699 S;
13700 /* Wait for a reply... */
13701 W;
13702
13703 /* NOTREACHED */
13704 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013705}
13706
13707static int
Matus Fabian8a95a482016-05-06 15:14:13 +020013708api_af_packet_create (vat_main_t * vam)
13709{
Dave Barach72d72232016-08-04 10:15:08 -040013710 unformat_input_t *i = vam->input;
13711 vl_api_af_packet_create_t *mp;
13712 f64 timeout;
13713 u8 *host_if_name = 0;
13714 u8 hw_addr[6];
13715 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020013716
Dave Barach72d72232016-08-04 10:15:08 -040013717 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020013718
Dave Barach72d72232016-08-04 10:15:08 -040013719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13720 {
13721 if (unformat (i, "name %s", &host_if_name))
13722 vec_add1 (host_if_name, 0);
13723 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
13724 random_hw_addr = 0;
13725 else
13726 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020013727 }
13728
Dave Barach72d72232016-08-04 10:15:08 -040013729 if (!vec_len (host_if_name))
13730 {
13731 errmsg ("host-interface name must be specified");
13732 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013733 }
13734
Dave Barach72d72232016-08-04 10:15:08 -040013735 if (vec_len (host_if_name) > 64)
13736 {
13737 errmsg ("host-interface name too long");
13738 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013739 }
13740
Dave Barach72d72232016-08-04 10:15:08 -040013741 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020013742
Dave Barach72d72232016-08-04 10:15:08 -040013743 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
13744 clib_memcpy (mp->hw_addr, hw_addr, 6);
13745 mp->use_random_hw_addr = random_hw_addr;
13746 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020013747
Dave Barach72d72232016-08-04 10:15:08 -040013748 S;
13749 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
13750 /* NOTREACHED */
13751 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013752}
13753
13754static int
13755api_af_packet_delete (vat_main_t * vam)
13756{
Dave Barach72d72232016-08-04 10:15:08 -040013757 unformat_input_t *i = vam->input;
13758 vl_api_af_packet_delete_t *mp;
13759 f64 timeout;
13760 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013761
Dave Barach72d72232016-08-04 10:15:08 -040013762 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13763 {
13764 if (unformat (i, "name %s", &host_if_name))
13765 vec_add1 (host_if_name, 0);
13766 else
13767 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020013768 }
13769
Dave Barach72d72232016-08-04 10:15:08 -040013770 if (!vec_len (host_if_name))
13771 {
13772 errmsg ("host-interface name must be specified");
13773 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013774 }
13775
Dave Barach72d72232016-08-04 10:15:08 -040013776 if (vec_len (host_if_name) > 64)
13777 {
13778 errmsg ("host-interface name too long");
13779 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013780 }
13781
Dave Barach72d72232016-08-04 10:15:08 -040013782 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020013783
Dave Barach72d72232016-08-04 10:15:08 -040013784 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
13785 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020013786
Dave Barach72d72232016-08-04 10:15:08 -040013787 S;
13788 W;
13789 /* NOTREACHED */
13790 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013791}
13792
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013793static int
13794api_policer_add_del (vat_main_t * vam)
13795{
Dave Barach72d72232016-08-04 10:15:08 -040013796 unformat_input_t *i = vam->input;
13797 vl_api_policer_add_del_t *mp;
13798 f64 timeout;
13799 u8 is_add = 1;
13800 u8 *name = 0;
13801 u32 cir = 0;
13802 u32 eir = 0;
13803 u64 cb = 0;
13804 u64 eb = 0;
13805 u8 rate_type = 0;
13806 u8 round_type = 0;
13807 u8 type = 0;
13808 u8 color_aware = 0;
13809 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013810
Dave Barach839fe3e2016-08-10 11:35:54 -040013811 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
13812 conform_action.dscp = 0;
13813 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
13814 exceed_action.dscp = 0;
13815 violate_action.action_type = SSE2_QOS_ACTION_DROP;
13816 violate_action.dscp = 0;
13817
Dave Barach72d72232016-08-04 10:15:08 -040013818 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13819 {
13820 if (unformat (i, "del"))
13821 is_add = 0;
13822 else if (unformat (i, "name %s", &name))
13823 vec_add1 (name, 0);
13824 else if (unformat (i, "cir %u", &cir))
13825 ;
13826 else if (unformat (i, "eir %u", &eir))
13827 ;
13828 else if (unformat (i, "cb %u", &cb))
13829 ;
13830 else if (unformat (i, "eb %u", &eb))
13831 ;
13832 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
13833 &rate_type))
13834 ;
13835 else if (unformat (i, "round_type %U", unformat_policer_round_type,
13836 &round_type))
13837 ;
13838 else if (unformat (i, "type %U", unformat_policer_type, &type))
13839 ;
13840 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
13841 &conform_action))
13842 ;
13843 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
13844 &exceed_action))
13845 ;
13846 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
13847 &violate_action))
13848 ;
13849 else if (unformat (i, "color-aware"))
13850 color_aware = 1;
13851 else
13852 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013853 }
13854
Dave Barach72d72232016-08-04 10:15:08 -040013855 if (!vec_len (name))
13856 {
13857 errmsg ("policer name must be specified");
13858 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013859 }
13860
Dave Barach72d72232016-08-04 10:15:08 -040013861 if (vec_len (name) > 64)
13862 {
13863 errmsg ("policer name too long");
13864 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013865 }
13866
Dave Barach72d72232016-08-04 10:15:08 -040013867 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013868
Dave Barach72d72232016-08-04 10:15:08 -040013869 clib_memcpy (mp->name, name, vec_len (name));
13870 vec_free (name);
13871 mp->is_add = is_add;
13872 mp->cir = cir;
13873 mp->eir = eir;
13874 mp->cb = cb;
13875 mp->eb = eb;
13876 mp->rate_type = rate_type;
13877 mp->round_type = round_type;
13878 mp->type = type;
13879 mp->conform_action_type = conform_action.action_type;
13880 mp->conform_dscp = conform_action.dscp;
13881 mp->exceed_action_type = exceed_action.action_type;
13882 mp->exceed_dscp = exceed_action.dscp;
13883 mp->violate_action_type = violate_action.action_type;
13884 mp->violate_dscp = violate_action.dscp;
13885 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013886
Dave Barach72d72232016-08-04 10:15:08 -040013887 S;
13888 W;
13889 /* NOTREACHED */
13890 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013891}
13892
Matus Fabian82e29c42016-05-11 04:49:46 -070013893static int
Dave Barach72d72232016-08-04 10:15:08 -040013894api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070013895{
Dave Barach72d72232016-08-04 10:15:08 -040013896 unformat_input_t *i = vam->input;
13897 vl_api_policer_dump_t *mp;
13898 f64 timeout = ~0;
13899 u8 *match_name = 0;
13900 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070013901
Dave Barach72d72232016-08-04 10:15:08 -040013902 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070013903 {
Dave Barach72d72232016-08-04 10:15:08 -040013904 if (unformat (i, "name %s", &match_name))
13905 {
13906 vec_add1 (match_name, 0);
13907 match_name_valid = 1;
13908 }
13909 else
13910 break;
Matus Fabiane8554802016-05-18 23:40:37 -070013911 }
Matus Fabiane8554802016-05-18 23:40:37 -070013912
Dave Barach72d72232016-08-04 10:15:08 -040013913 M (POLICER_DUMP, policer_dump);
13914 mp->match_name_valid = match_name_valid;
13915 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
13916 vec_free (match_name);
13917 /* send it... */
13918 S;
13919
13920 /* Use a control ping for synchronization */
13921 {
13922 vl_api_control_ping_t *mp;
13923 M (CONTROL_PING, control_ping);
13924 S;
13925 }
13926 /* Wait for a reply... */
13927 W;
13928
13929 /* NOTREACHED */
13930 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070013931}
13932
13933static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013934api_policer_classify_set_interface (vat_main_t * vam)
13935{
Dave Barach72d72232016-08-04 10:15:08 -040013936 unformat_input_t *i = vam->input;
13937 vl_api_policer_classify_set_interface_t *mp;
13938 f64 timeout;
13939 u32 sw_if_index;
13940 int sw_if_index_set;
13941 u32 ip4_table_index = ~0;
13942 u32 ip6_table_index = ~0;
13943 u32 l2_table_index = ~0;
13944 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013945
Dave Barach72d72232016-08-04 10:15:08 -040013946 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13947 {
13948 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
13949 sw_if_index_set = 1;
13950 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13951 sw_if_index_set = 1;
13952 else if (unformat (i, "del"))
13953 is_add = 0;
13954 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13955 ;
13956 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13957 ;
13958 else if (unformat (i, "l2-table %d", &l2_table_index))
13959 ;
13960 else
13961 {
13962 clib_warning ("parse error '%U'", format_unformat_error, i);
13963 return -99;
13964 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013965 }
13966
Dave Barach72d72232016-08-04 10:15:08 -040013967 if (sw_if_index_set == 0)
13968 {
13969 errmsg ("missing interface name or sw_if_index\n");
13970 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013971 }
13972
Dave Barach72d72232016-08-04 10:15:08 -040013973 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013974
Dave Barach72d72232016-08-04 10:15:08 -040013975 mp->sw_if_index = ntohl (sw_if_index);
13976 mp->ip4_table_index = ntohl (ip4_table_index);
13977 mp->ip6_table_index = ntohl (ip6_table_index);
13978 mp->l2_table_index = ntohl (l2_table_index);
13979 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013980
Dave Barach72d72232016-08-04 10:15:08 -040013981 S;
13982 W;
13983 /* NOTREACHED */
13984 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013985}
13986
13987static int
Dave Barach72d72232016-08-04 10:15:08 -040013988api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013989{
Dave Barach72d72232016-08-04 10:15:08 -040013990 unformat_input_t *i = vam->input;
13991 vl_api_policer_classify_dump_t *mp;
13992 f64 timeout = ~0;
13993 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013994
Dave Barach72d72232016-08-04 10:15:08 -040013995 if (unformat (i, "type %U", unformat_classify_table_type, &type))
13996 ;
13997 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013998 {
Dave Barach72d72232016-08-04 10:15:08 -040013999 errmsg ("classify table type must be specified\n");
14000 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014001 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014002
Dave Barach72d72232016-08-04 10:15:08 -040014003 if (!vam->json_output)
14004 {
14005 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
14006 }
14007
14008 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
14009 mp->type = type;
14010 /* send it... */
14011 S;
14012
14013 /* Use a control ping for synchronization */
14014 {
14015 vl_api_control_ping_t *mp;
14016 M (CONTROL_PING, control_ping);
14017 S;
14018 }
14019 /* Wait for a reply... */
14020 W;
14021
14022 /* NOTREACHED */
14023 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014024}
14025
14026static int
Matus Fabian82e29c42016-05-11 04:49:46 -070014027api_netmap_create (vat_main_t * vam)
14028{
Dave Barach72d72232016-08-04 10:15:08 -040014029 unformat_input_t *i = vam->input;
14030 vl_api_netmap_create_t *mp;
14031 f64 timeout;
14032 u8 *if_name = 0;
14033 u8 hw_addr[6];
14034 u8 random_hw_addr = 1;
14035 u8 is_pipe = 0;
14036 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014037
Dave Barach72d72232016-08-04 10:15:08 -040014038 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070014039
Dave Barach72d72232016-08-04 10:15:08 -040014040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14041 {
14042 if (unformat (i, "name %s", &if_name))
14043 vec_add1 (if_name, 0);
14044 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14045 random_hw_addr = 0;
14046 else if (unformat (i, "pipe"))
14047 is_pipe = 1;
14048 else if (unformat (i, "master"))
14049 is_master = 1;
14050 else if (unformat (i, "slave"))
14051 is_master = 0;
14052 else
14053 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014054 }
14055
Dave Barach72d72232016-08-04 10:15:08 -040014056 if (!vec_len (if_name))
14057 {
14058 errmsg ("interface name must be specified");
14059 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014060 }
14061
Dave Barach72d72232016-08-04 10:15:08 -040014062 if (vec_len (if_name) > 64)
14063 {
14064 errmsg ("interface name too long");
14065 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014066 }
14067
Dave Barach72d72232016-08-04 10:15:08 -040014068 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070014069
Dave Barach72d72232016-08-04 10:15:08 -040014070 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14071 clib_memcpy (mp->hw_addr, hw_addr, 6);
14072 mp->use_random_hw_addr = random_hw_addr;
14073 mp->is_pipe = is_pipe;
14074 mp->is_master = is_master;
14075 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014076
Dave Barach72d72232016-08-04 10:15:08 -040014077 S;
14078 W;
14079 /* NOTREACHED */
14080 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014081}
14082
14083static int
14084api_netmap_delete (vat_main_t * vam)
14085{
Dave Barach72d72232016-08-04 10:15:08 -040014086 unformat_input_t *i = vam->input;
14087 vl_api_netmap_delete_t *mp;
14088 f64 timeout;
14089 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014090
Dave Barach72d72232016-08-04 10:15:08 -040014091 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14092 {
14093 if (unformat (i, "name %s", &if_name))
14094 vec_add1 (if_name, 0);
14095 else
14096 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014097 }
14098
Dave Barach72d72232016-08-04 10:15:08 -040014099 if (!vec_len (if_name))
14100 {
14101 errmsg ("interface name must be specified");
14102 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014103 }
14104
Dave Barach72d72232016-08-04 10:15:08 -040014105 if (vec_len (if_name) > 64)
14106 {
14107 errmsg ("interface name too long");
14108 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014109 }
14110
Dave Barach72d72232016-08-04 10:15:08 -040014111 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070014112
Dave Barach72d72232016-08-04 10:15:08 -040014113 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14114 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014115
Dave Barach72d72232016-08-04 10:15:08 -040014116 S;
14117 W;
14118 /* NOTREACHED */
14119 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014120}
14121
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014122static void vl_api_mpls_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014123 (vl_api_mpls_gre_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014124{
Dave Barach72d72232016-08-04 10:15:08 -040014125 vat_main_t *vam = &vat_main;
14126 i32 i;
14127 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014128
Dave Barach72d72232016-08-04 10:15:08 -040014129 if (mp->l2_only == 0)
14130 {
14131 fformat (vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
14132 ntohl (mp->tunnel_index),
14133 format_ip4_address, &mp->tunnel_src,
14134 format_ip4_address, &mp->tunnel_dst,
14135 format_ip4_address, &mp->intfc_address,
14136 ntohl (mp->mask_width));
14137 for (i = 0; i < len; i++)
14138 {
14139 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
14140 }
14141 fformat (vam->ofp, "\n");
14142 fformat (vam->ofp, " inner fib index %d, outer fib index %d\n",
14143 ntohl (mp->inner_fib_index), ntohl (mp->outer_fib_index));
14144 }
14145 else
14146 {
14147 fformat (vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
14148 ntohl (mp->tunnel_index),
14149 format_ip4_address, &mp->tunnel_src,
14150 format_ip4_address, &mp->tunnel_dst,
14151 format_ip4_address, &mp->intfc_address);
14152 for (i = 0; i < len; i++)
14153 {
14154 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
14155 }
14156 fformat (vam->ofp, "\n");
14157 fformat (vam->ofp, " l2 interface %d, outer fib index %d\n",
14158 ntohl (mp->hw_if_index), ntohl (mp->outer_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014159 }
14160}
14161
14162static void vl_api_mpls_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014163 (vl_api_mpls_gre_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014164{
Dave Barach72d72232016-08-04 10:15:08 -040014165 vat_main_t *vam = &vat_main;
14166 vat_json_node_t *node = NULL;
14167 struct in_addr ip4;
14168 i32 i;
14169 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014170
Dave Barach72d72232016-08-04 10:15:08 -040014171 if (VAT_JSON_ARRAY != vam->json_tree.type)
14172 {
14173 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14174 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014175 }
Dave Barach72d72232016-08-04 10:15:08 -040014176 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014177
Dave Barach72d72232016-08-04 10:15:08 -040014178 vat_json_init_object (node);
14179 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14180 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14181 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14182 vat_json_object_add_uint (node, "inner_fib_index",
14183 ntohl (mp->inner_fib_index));
14184 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14185 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14186 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14187 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14188 clib_memcpy (&ip4, &(mp->tunnel_src), sizeof (ip4));
14189 vat_json_object_add_ip4 (node, "tunnel_src", ip4);
14190 clib_memcpy (&ip4, &(mp->tunnel_dst), sizeof (ip4));
14191 vat_json_object_add_ip4 (node, "tunnel_dst", ip4);
14192 vat_json_object_add_uint (node, "outer_fib_index",
14193 ntohl (mp->outer_fib_index));
14194 vat_json_object_add_uint (node, "label_count", len);
14195 for (i = 0; i < len; i++)
14196 {
14197 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014198 }
14199}
14200
Dave Barach72d72232016-08-04 10:15:08 -040014201static int
14202api_mpls_gre_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014203{
Dave Barach72d72232016-08-04 10:15:08 -040014204 vl_api_mpls_gre_tunnel_dump_t *mp;
14205 f64 timeout;
14206 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014207
Dave Barach72d72232016-08-04 10:15:08 -040014208 /* Parse args required to build the message */
14209 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014210 {
Dave Barach72d72232016-08-04 10:15:08 -040014211 if (!unformat (vam->input, "tunnel_index %d", &index))
14212 {
14213 index = -1;
14214 break;
14215 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014216 }
Dave Barach72d72232016-08-04 10:15:08 -040014217
14218 fformat (vam->ofp, " tunnel_index %d\n", index);
14219
14220 M (MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
14221 mp->tunnel_index = htonl (index);
14222 S;
14223
14224 /* Use a control ping for synchronization */
14225 {
14226 vl_api_control_ping_t *mp;
14227 M (CONTROL_PING, control_ping);
14228 S;
14229 }
14230 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014231}
14232
14233static void vl_api_mpls_eth_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014234 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014235{
Dave Barach72d72232016-08-04 10:15:08 -040014236 vat_main_t *vam = &vat_main;
14237 i32 i;
14238 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014239
Dave Barach72d72232016-08-04 10:15:08 -040014240 fformat (vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
14241 ntohl (mp->tunnel_index),
14242 format_ethernet_address, &mp->tunnel_dst_mac,
14243 format_ip4_address, &mp->intfc_address, ntohl (mp->mask_width));
14244 for (i = 0; i < len; i++)
14245 {
14246 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014247 }
Dave Barach72d72232016-08-04 10:15:08 -040014248 fformat (vam->ofp, "\n");
14249 fformat (vam->ofp, " tx on %d, rx fib index %d\n",
14250 ntohl (mp->tx_sw_if_index), ntohl (mp->inner_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014251}
14252
14253static void vl_api_mpls_eth_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014254 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014255{
Dave Barach72d72232016-08-04 10:15:08 -040014256 vat_main_t *vam = &vat_main;
14257 vat_json_node_t *node = NULL;
14258 struct in_addr ip4;
14259 i32 i;
14260 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014261
Dave Barach72d72232016-08-04 10:15:08 -040014262 if (VAT_JSON_ARRAY != vam->json_tree.type)
14263 {
14264 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14265 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014266 }
Dave Barach72d72232016-08-04 10:15:08 -040014267 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014268
Dave Barach72d72232016-08-04 10:15:08 -040014269 vat_json_init_object (node);
14270 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14271 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14272 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14273 vat_json_object_add_uint (node, "inner_fib_index",
14274 ntohl (mp->inner_fib_index));
14275 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14276 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14277 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14278 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14279 vat_json_object_add_string_copy (node, "tunnel_dst_mac",
14280 format (0, "%U", format_ethernet_address,
14281 &mp->tunnel_dst_mac));
14282 vat_json_object_add_uint (node, "tx_sw_if_index",
14283 ntohl (mp->tx_sw_if_index));
14284 vat_json_object_add_uint (node, "label_count", len);
14285 for (i = 0; i < len; i++)
14286 {
14287 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014288 }
14289}
14290
Dave Barach72d72232016-08-04 10:15:08 -040014291static int
14292api_mpls_eth_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014293{
Dave Barach72d72232016-08-04 10:15:08 -040014294 vl_api_mpls_eth_tunnel_dump_t *mp;
14295 f64 timeout;
14296 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014297
Dave Barach72d72232016-08-04 10:15:08 -040014298 /* Parse args required to build the message */
14299 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014300 {
Dave Barach72d72232016-08-04 10:15:08 -040014301 if (!unformat (vam->input, "tunnel_index %d", &index))
14302 {
14303 index = -1;
14304 break;
14305 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014306 }
Dave Barach72d72232016-08-04 10:15:08 -040014307
14308 fformat (vam->ofp, " tunnel_index %d\n", index);
14309
14310 M (MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
14311 mp->tunnel_index = htonl (index);
14312 S;
14313
14314 /* Use a control ping for synchronization */
14315 {
14316 vl_api_control_ping_t *mp;
14317 M (CONTROL_PING, control_ping);
14318 S;
14319 }
14320 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014321}
14322
14323static void vl_api_mpls_fib_encap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014324 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014325{
Dave Barach72d72232016-08-04 10:15:08 -040014326 vat_main_t *vam = &vat_main;
14327 i32 i;
14328 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014329
Dave Barach72d72232016-08-04 10:15:08 -040014330 fformat (vam->ofp, "table %d, dest %U, label ",
14331 ntohl (mp->fib_index), format_ip4_address, &mp->dest, len);
14332 for (i = 0; i < len; i++)
14333 {
14334 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014335 }
Dave Barach72d72232016-08-04 10:15:08 -040014336 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014337}
14338
14339static void vl_api_mpls_fib_encap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014340 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014341{
Dave Barach72d72232016-08-04 10:15:08 -040014342 vat_main_t *vam = &vat_main;
14343 vat_json_node_t *node = NULL;
14344 i32 i;
14345 i32 len = ntohl (mp->nlabels);
14346 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014347
Dave Barach72d72232016-08-04 10:15:08 -040014348 if (VAT_JSON_ARRAY != vam->json_tree.type)
14349 {
14350 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14351 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014352 }
Dave Barach72d72232016-08-04 10:15:08 -040014353 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014354
Dave Barach72d72232016-08-04 10:15:08 -040014355 vat_json_init_object (node);
14356 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14357 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14358 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14359 vat_json_object_add_ip4 (node, "dest", ip4);
14360 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14361 vat_json_object_add_uint (node, "label_count", len);
14362 for (i = 0; i < len; i++)
14363 {
14364 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014365 }
14366}
14367
Dave Barach72d72232016-08-04 10:15:08 -040014368static int
14369api_mpls_fib_encap_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014370{
Dave Barach72d72232016-08-04 10:15:08 -040014371 vl_api_mpls_fib_encap_dump_t *mp;
14372 f64 timeout;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014373
Dave Barach72d72232016-08-04 10:15:08 -040014374 M (MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
14375 S;
14376
14377 /* Use a control ping for synchronization */
14378 {
14379 vl_api_control_ping_t *mp;
14380 M (CONTROL_PING, control_ping);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014381 S;
Dave Barach72d72232016-08-04 10:15:08 -040014382 }
14383 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014384}
14385
14386static void vl_api_mpls_fib_decap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014387 (vl_api_mpls_fib_decap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014388{
Dave Barach72d72232016-08-04 10:15:08 -040014389 vat_main_t *vam = &vat_main;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014390
Dave Barach72d72232016-08-04 10:15:08 -040014391 fformat (vam->ofp,
14392 "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
14393 ntohl (mp->rx_table_id), ntohl (mp->tx_table_id), mp->swif_tag,
14394 ntohl (mp->label), ntohl (mp->s_bit));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014395}
14396
14397static void vl_api_mpls_fib_decap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014398 (vl_api_mpls_fib_decap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014399{
Dave Barach72d72232016-08-04 10:15:08 -040014400 vat_main_t *vam = &vat_main;
14401 vat_json_node_t *node = NULL;
14402 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014403
Dave Barach72d72232016-08-04 10:15:08 -040014404 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014405 {
Dave Barach72d72232016-08-04 10:15:08 -040014406 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14407 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014408 }
Dave Barach72d72232016-08-04 10:15:08 -040014409 node = vat_json_array_add (&vam->json_tree);
14410
14411 vat_json_init_object (node);
14412 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14413 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14414 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14415 vat_json_object_add_ip4 (node, "dest", ip4);
14416 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14417 vat_json_object_add_uint (node, "label", ntohl (mp->label));
14418 vat_json_object_add_uint (node, "rx_table_id", ntohl (mp->rx_table_id));
14419 vat_json_object_add_uint (node, "tx_table_id", ntohl (mp->tx_table_id));
14420 vat_json_object_add_string_copy (node, "swif_tag", mp->swif_tag);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014421}
14422
Dave Barach72d72232016-08-04 10:15:08 -040014423static int
14424api_mpls_fib_decap_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014425{
Dave Barach72d72232016-08-04 10:15:08 -040014426 vl_api_mpls_fib_decap_dump_t *mp;
14427 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014428
Dave Barach72d72232016-08-04 10:15:08 -040014429 M (MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
14430 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014431
Dave Barach72d72232016-08-04 10:15:08 -040014432 /* Use a control ping for synchronization */
14433 {
14434 vl_api_control_ping_t *mp;
14435 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014436 S;
Dave Barach72d72232016-08-04 10:15:08 -040014437 }
14438 W;
14439}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014440
Dave Barach72d72232016-08-04 10:15:08 -040014441int
14442api_classify_table_ids (vat_main_t * vam)
14443{
14444 vl_api_classify_table_ids_t *mp;
14445 f64 timeout;
14446
14447 /* Construct the API message */
14448 M (CLASSIFY_TABLE_IDS, classify_table_ids);
14449 mp->context = 0;
14450
14451 S;
14452 W;
14453 /* NOTREACHED */
14454 return 0;
14455}
14456
14457int
14458api_classify_table_by_interface (vat_main_t * vam)
14459{
14460 unformat_input_t *input = vam->input;
14461 vl_api_classify_table_by_interface_t *mp;
14462 f64 timeout;
14463
14464 u32 sw_if_index = ~0;
14465 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014466 {
Dave Barach72d72232016-08-04 10:15:08 -040014467 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
14468 ;
14469 else if (unformat (input, "sw_if_index %d", &sw_if_index))
14470 ;
14471 else
14472 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014473 }
Dave Barach72d72232016-08-04 10:15:08 -040014474 if (sw_if_index == ~0)
14475 {
14476 errmsg ("missing interface name or sw_if_index\n");
14477 return -99;
14478 }
14479
14480 /* Construct the API message */
14481 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
14482 mp->context = 0;
14483 mp->sw_if_index = ntohl (sw_if_index);
14484
14485 S;
14486 W;
14487 /* NOTREACHED */
14488 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014489}
14490
Dave Barach72d72232016-08-04 10:15:08 -040014491int
14492api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014493{
Dave Barach72d72232016-08-04 10:15:08 -040014494 unformat_input_t *input = vam->input;
14495 vl_api_classify_table_info_t *mp;
14496 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014497
Dave Barach72d72232016-08-04 10:15:08 -040014498 u32 table_id = ~0;
14499 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14500 {
14501 if (unformat (input, "table_id %d", &table_id))
14502 ;
14503 else
14504 break;
14505 }
14506 if (table_id == ~0)
14507 {
14508 errmsg ("missing table id\n");
14509 return -99;
14510 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014511
Dave Barach72d72232016-08-04 10:15:08 -040014512 /* Construct the API message */
14513 M (CLASSIFY_TABLE_INFO, classify_table_info);
14514 mp->context = 0;
14515 mp->table_id = ntohl (table_id);
14516
14517 S;
14518 W;
14519 /* NOTREACHED */
14520 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014521}
14522
Dave Barach72d72232016-08-04 10:15:08 -040014523int
14524api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014525{
Dave Barach72d72232016-08-04 10:15:08 -040014526 unformat_input_t *input = vam->input;
14527 vl_api_classify_session_dump_t *mp;
14528 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014529
Dave Barach72d72232016-08-04 10:15:08 -040014530 u32 table_id = ~0;
14531 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14532 {
14533 if (unformat (input, "table_id %d", &table_id))
14534 ;
14535 else
14536 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014537 }
Dave Barach72d72232016-08-04 10:15:08 -040014538 if (table_id == ~0)
14539 {
14540 errmsg ("missing table id\n");
14541 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014542 }
14543
Dave Barach72d72232016-08-04 10:15:08 -040014544 /* Construct the API message */
14545 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
14546 mp->context = 0;
14547 mp->table_id = ntohl (table_id);
14548 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014549
Dave Barach72d72232016-08-04 10:15:08 -040014550 /* Use a control ping for synchronization */
14551 {
14552 vl_api_control_ping_t *mp;
14553 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040014554 S;
Dave Barach72d72232016-08-04 10:15:08 -040014555 }
14556 W;
14557 /* NOTREACHED */
14558 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040014559}
14560
Dave Barach72d72232016-08-04 10:15:08 -040014561static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014562vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070014563{
Dave Barach72d72232016-08-04 10:15:08 -040014564 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014565
Dave Barach72d72232016-08-04 10:15:08 -040014566 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014567 "src_address %U, vrf_id %d, path_mtu %u, "
14568 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040014569 format_ip4_address, mp->collector_address,
14570 ntohs (mp->collector_port),
14571 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014572 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
14573 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040014574
14575 vam->retval = 0;
14576 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014577}
14578
Dave Barach72d72232016-08-04 10:15:08 -040014579static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014580 vl_api_ipfix_exporter_details_t_handler_json
14581 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014582{
Dave Barach72d72232016-08-04 10:15:08 -040014583 vat_main_t *vam = &vat_main;
14584 vat_json_node_t node;
14585 struct in_addr collector_address;
14586 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014587
Dave Barach72d72232016-08-04 10:15:08 -040014588 vat_json_init_object (&node);
14589 clib_memcpy (&collector_address, &mp->collector_address,
14590 sizeof (collector_address));
14591 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
14592 vat_json_object_add_uint (&node, "collector_port",
14593 ntohs (mp->collector_port));
14594 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
14595 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014596 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040014597 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
14598 vat_json_object_add_uint (&node, "template_interval",
14599 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014600 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040014601
14602 vat_json_print (vam->ofp, &node);
14603 vat_json_free (&node);
14604 vam->retval = 0;
14605 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014606}
14607
Dave Barach72d72232016-08-04 10:15:08 -040014608int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014609api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070014610{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014611 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014612 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014613
Dave Barach72d72232016-08-04 10:15:08 -040014614 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014615 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014616 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014617
Dave Barach72d72232016-08-04 10:15:08 -040014618 S;
14619 W;
14620 /* NOTREACHED */
14621 return 0;
14622}
Ed Warnickecb9cada2015-12-08 15:45:58 -070014623
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014624static int
14625api_ipfix_classify_stream_dump (vat_main_t * vam)
14626{
14627 vl_api_ipfix_classify_stream_dump_t *mp;
14628 f64 timeout;
14629
14630 /* Construct the API message */
14631 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
14632 mp->context = 0;
14633
14634 S;
14635 W;
14636 /* NOTREACHED */
14637 return 0;
14638}
14639
14640static void
14641 vl_api_ipfix_classify_stream_details_t_handler
14642 (vl_api_ipfix_classify_stream_details_t * mp)
14643{
14644 vat_main_t *vam = &vat_main;
14645 fformat (vam->ofp, "domain_id %d, src_port %d\n",
14646 ntohl (mp->domain_id), ntohs (mp->src_port));
14647 vam->retval = 0;
14648 vam->result_ready = 1;
14649}
14650
14651static void
14652 vl_api_ipfix_classify_stream_details_t_handler_json
14653 (vl_api_ipfix_classify_stream_details_t * mp)
14654{
14655 vat_main_t *vam = &vat_main;
14656 vat_json_node_t node;
14657
14658 vat_json_init_object (&node);
14659 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
14660 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
14661
14662 vat_json_print (vam->ofp, &node);
14663 vat_json_free (&node);
14664 vam->retval = 0;
14665 vam->result_ready = 1;
14666}
14667
14668static int
14669api_ipfix_classify_table_dump (vat_main_t * vam)
14670{
14671 vl_api_ipfix_classify_table_dump_t *mp;
14672 f64 timeout;
14673
14674 if (!vam->json_output)
14675 {
14676 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
14677 "transport_protocol");
14678 }
14679
14680 /* Construct the API message */
14681 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
14682
14683 /* send it... */
14684 S;
14685
14686 /* Use a control ping for synchronization */
14687 {
14688 vl_api_control_ping_t *mp;
14689 M (CONTROL_PING, control_ping);
14690 S;
14691 }
14692 W;
14693}
14694
14695static void
14696 vl_api_ipfix_classify_table_details_t_handler
14697 (vl_api_ipfix_classify_table_details_t * mp)
14698{
14699 vat_main_t *vam = &vat_main;
14700 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
14701 mp->transport_protocol);
14702}
14703
14704static void
14705 vl_api_ipfix_classify_table_details_t_handler_json
14706 (vl_api_ipfix_classify_table_details_t * mp)
14707{
14708 vat_json_node_t *node = NULL;
14709 vat_main_t *vam = &vat_main;
14710
14711 if (VAT_JSON_ARRAY != vam->json_tree.type)
14712 {
14713 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14714 vat_json_init_array (&vam->json_tree);
14715 }
14716
14717 node = vat_json_array_add (&vam->json_tree);
14718 vat_json_init_object (node);
14719
14720 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
14721 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
14722 vat_json_object_add_uint (node, "transport_protocol",
14723 mp->transport_protocol);
14724}
14725
Dave Barach72d72232016-08-04 10:15:08 -040014726int
14727api_pg_create_interface (vat_main_t * vam)
14728{
14729 unformat_input_t *input = vam->input;
14730 vl_api_pg_create_interface_t *mp;
14731 f64 timeout;
14732
14733 u32 if_id = ~0;
14734 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14735 {
14736 if (unformat (input, "if_id %d", &if_id))
14737 ;
14738 else
14739 break;
14740 }
14741 if (if_id == ~0)
14742 {
14743 errmsg ("missing pg interface index\n");
14744 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014745 }
14746
Dave Barach72d72232016-08-04 10:15:08 -040014747 /* Construct the API message */
14748 M (PG_CREATE_INTERFACE, pg_create_interface);
14749 mp->context = 0;
14750 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070014751
Dave Barach72d72232016-08-04 10:15:08 -040014752 S;
14753 W;
14754 /* NOTREACHED */
14755 return 0;
14756}
14757
14758int
14759api_pg_capture (vat_main_t * vam)
14760{
14761 unformat_input_t *input = vam->input;
14762 vl_api_pg_capture_t *mp;
14763 f64 timeout;
14764
14765 u32 if_id = ~0;
14766 u8 enable = 1;
14767 u32 count = 1;
14768 u8 pcap_file_set = 0;
14769 u8 *pcap_file = 0;
14770 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14771 {
14772 if (unformat (input, "if_id %d", &if_id))
14773 ;
14774 else if (unformat (input, "pcap %s", &pcap_file))
14775 pcap_file_set = 1;
14776 else if (unformat (input, "count %d", &count))
14777 ;
14778 else if (unformat (input, "disable"))
14779 enable = 0;
14780 else
14781 break;
14782 }
14783 if (if_id == ~0)
14784 {
14785 errmsg ("missing pg interface index\n");
14786 return -99;
14787 }
14788 if (pcap_file_set > 0)
14789 {
14790 if (vec_len (pcap_file) > 255)
14791 {
14792 errmsg ("pcap file name is too long\n");
14793 return -99;
14794 }
14795 }
14796
14797 u32 name_len = vec_len (pcap_file);
14798 /* Construct the API message */
14799 M (PG_CAPTURE, pg_capture);
14800 mp->context = 0;
14801 mp->interface_id = ntohl (if_id);
14802 mp->is_enabled = enable;
14803 mp->count = ntohl (count);
14804 mp->pcap_name_length = ntohl (name_len);
14805 if (pcap_file_set != 0)
14806 {
14807 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
14808 }
14809 vec_free (pcap_file);
14810
14811 S;
14812 W;
14813 /* NOTREACHED */
14814 return 0;
14815}
14816
14817int
14818api_pg_enable_disable (vat_main_t * vam)
14819{
14820 unformat_input_t *input = vam->input;
14821 vl_api_pg_enable_disable_t *mp;
14822 f64 timeout;
14823
14824 u8 enable = 1;
14825 u8 stream_name_set = 0;
14826 u8 *stream_name = 0;
14827 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14828 {
14829 if (unformat (input, "stream %s", &stream_name))
14830 stream_name_set = 1;
14831 else if (unformat (input, "disable"))
14832 enable = 0;
14833 else
14834 break;
14835 }
14836
14837 if (stream_name_set > 0)
14838 {
14839 if (vec_len (stream_name) > 255)
14840 {
14841 errmsg ("stream name too long\n");
14842 return -99;
14843 }
14844 }
14845
14846 u32 name_len = vec_len (stream_name);
14847 /* Construct the API message */
14848 M (PG_ENABLE_DISABLE, pg_enable_disable);
14849 mp->context = 0;
14850 mp->is_enabled = enable;
14851 if (stream_name_set != 0)
14852 {
14853 mp->stream_name_length = ntohl (name_len);
14854 clib_memcpy (mp->stream_name, stream_name, name_len);
14855 }
14856 vec_free (stream_name);
14857
14858 S;
14859 W;
14860 /* NOTREACHED */
14861 return 0;
14862}
14863
14864int
14865api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
14866{
14867 unformat_input_t *input = vam->input;
14868 vl_api_ip_source_and_port_range_check_add_del_t *mp;
14869 f64 timeout;
14870
14871 u16 *low_ports = 0;
14872 u16 *high_ports = 0;
14873 u16 this_low;
14874 u16 this_hi;
14875 ip4_address_t ip4_addr;
14876 ip6_address_t ip6_addr;
14877 u32 length;
14878 u32 tmp, tmp2;
14879 u8 prefix_set = 0;
14880 u32 vrf_id = ~0;
14881 u8 is_add = 1;
14882 u8 is_ipv6 = 0;
14883
14884 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14885 {
14886 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
14887 {
14888 prefix_set = 1;
14889 }
14890 else
14891 if (unformat
14892 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
14893 {
14894 prefix_set = 1;
14895 is_ipv6 = 1;
14896 }
14897 else if (unformat (input, "vrf %d", &vrf_id))
14898 ;
14899 else if (unformat (input, "del"))
14900 is_add = 0;
14901 else if (unformat (input, "port %d", &tmp))
14902 {
14903 if (tmp == 0 || tmp > 65535)
14904 {
14905 errmsg ("port %d out of range", tmp);
14906 return -99;
14907 }
14908 this_low = tmp;
14909 this_hi = this_low + 1;
14910 vec_add1 (low_ports, this_low);
14911 vec_add1 (high_ports, this_hi);
14912 }
14913 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
14914 {
14915 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
14916 {
14917 errmsg ("incorrect range parameters\n");
14918 return -99;
14919 }
14920 this_low = tmp;
14921 /* Note: in debug CLI +1 is added to high before
14922 passing to real fn that does "the work"
14923 (ip_source_and_port_range_check_add_del).
14924 This fn is a wrapper around the binary API fn a
14925 control plane will call, which expects this increment
14926 to have occurred. Hence letting the binary API control
14927 plane fn do the increment for consistency between VAT
14928 and other control planes.
14929 */
14930 this_hi = tmp2;
14931 vec_add1 (low_ports, this_low);
14932 vec_add1 (high_ports, this_hi);
14933 }
14934 else
14935 break;
14936 }
14937
14938 if (prefix_set == 0)
14939 {
14940 errmsg ("<address>/<mask> not specified\n");
14941 return -99;
14942 }
14943
14944 if (vrf_id == ~0)
14945 {
14946 errmsg ("VRF ID required, not specified\n");
14947 return -99;
14948 }
14949
14950 if (vrf_id == 0)
14951 {
14952 errmsg
14953 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
14954 return -99;
14955 }
14956
14957 if (vec_len (low_ports) == 0)
14958 {
14959 errmsg ("At least one port or port range required\n");
14960 return -99;
14961 }
14962
14963 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
14964 ip_source_and_port_range_check_add_del);
14965
14966 mp->is_add = is_add;
14967
14968 if (is_ipv6)
14969 {
14970 mp->is_ipv6 = 1;
14971 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
14972 }
14973 else
14974 {
14975 mp->is_ipv6 = 0;
14976 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
14977 }
14978
14979 mp->mask_length = length;
14980 mp->number_of_ranges = vec_len (low_ports);
14981
14982 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
14983 vec_free (low_ports);
14984
14985 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
14986 vec_free (high_ports);
14987
14988 mp->vrf_id = ntohl (vrf_id);
14989
14990 S;
14991 W;
14992 /* NOTREACHED */
14993 return 0;
14994}
14995
14996int
14997api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
14998{
14999 unformat_input_t *input = vam->input;
15000 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
15001 f64 timeout;
15002 u32 sw_if_index = ~0;
15003 int vrf_set = 0;
15004 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
15005 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
15006 u8 is_add = 1;
15007
15008 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15009 {
15010 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15011 ;
15012 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15013 ;
15014 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
15015 vrf_set = 1;
15016 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
15017 vrf_set = 1;
15018 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
15019 vrf_set = 1;
15020 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
15021 vrf_set = 1;
15022 else if (unformat (input, "del"))
15023 is_add = 0;
15024 else
15025 break;
15026 }
15027
15028 if (sw_if_index == ~0)
15029 {
15030 errmsg ("Interface required but not specified\n");
15031 return -99;
15032 }
15033
15034 if (vrf_set == 0)
15035 {
15036 errmsg ("VRF ID required but not specified\n");
15037 return -99;
15038 }
15039
15040 if (tcp_out_vrf_id == 0
15041 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
15042 {
15043 errmsg
15044 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15045 return -99;
15046 }
15047
15048 /* Construct the API message */
15049 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
15050 ip_source_and_port_range_check_interface_add_del);
15051
15052 mp->sw_if_index = ntohl (sw_if_index);
15053 mp->is_add = is_add;
15054 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
15055 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
15056 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
15057 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
15058
15059 /* send it... */
15060 S;
15061
15062 /* Wait for a reply... */
15063 W;
15064}
15065
15066static int
Matus Fabian694265d2016-08-10 01:55:36 -070015067api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
15068{
15069 unformat_input_t *i = vam->input;
15070 vl_api_ipsec_gre_add_del_tunnel_t *mp;
15071 f64 timeout;
15072 u32 local_sa_id = 0;
15073 u32 remote_sa_id = 0;
15074 ip4_address_t src_address;
15075 ip4_address_t dst_address;
15076 u8 is_add = 1;
15077
15078 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15079 {
15080 if (unformat (i, "local_sa %d", &local_sa_id))
15081 ;
15082 else if (unformat (i, "remote_sa %d", &remote_sa_id))
15083 ;
15084 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
15085 ;
15086 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
15087 ;
15088 else if (unformat (i, "del"))
15089 is_add = 0;
15090 else
15091 {
15092 clib_warning ("parse error '%U'", format_unformat_error, i);
15093 return -99;
15094 }
15095 }
15096
15097 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
15098
15099 mp->local_sa_id = ntohl (local_sa_id);
15100 mp->remote_sa_id = ntohl (remote_sa_id);
15101 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
15102 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
15103 mp->is_add = is_add;
15104
15105 S;
15106 W;
15107 /* NOTREACHED */
15108 return 0;
15109}
15110
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070015111static int
15112api_punt (vat_main_t * vam)
15113{
15114 unformat_input_t *i = vam->input;
15115 vl_api_punt_t *mp;
15116 f64 timeout;
15117 u32 ipv = ~0;
15118 u32 protocol = ~0;
15119 u32 port = ~0;
15120 int is_add = 1;
15121
15122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15123 {
15124 if (unformat (i, "ip %d", &ipv))
15125 ;
15126 else if (unformat (i, "protocol %d", &protocol))
15127 ;
15128 else if (unformat (i, "port %d", &port))
15129 ;
15130 else if (unformat (i, "del"))
15131 is_add = 0;
15132 else
15133 {
15134 clib_warning ("parse error '%U'", format_unformat_error, i);
15135 return -99;
15136 }
15137 }
15138
15139 M (PUNT, punt);
15140
15141 mp->is_add = (u8) is_add;
15142 mp->ipv = (u8) ipv;
15143 mp->l4_protocol = (u8) protocol;
15144 mp->l4_port = htons ((u16) port);
15145
15146 S;
15147 W;
15148 /* NOTREACHED */
15149 return 0;
15150}
15151
Matus Fabian694265d2016-08-10 01:55:36 -070015152static void vl_api_ipsec_gre_tunnel_details_t_handler
15153 (vl_api_ipsec_gre_tunnel_details_t * mp)
15154{
15155 vat_main_t *vam = &vat_main;
15156
15157 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
15158 ntohl (mp->sw_if_index),
15159 format_ip4_address, &mp->src_address,
15160 format_ip4_address, &mp->dst_address,
15161 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
15162}
15163
15164static void vl_api_ipsec_gre_tunnel_details_t_handler_json
15165 (vl_api_ipsec_gre_tunnel_details_t * mp)
15166{
15167 vat_main_t *vam = &vat_main;
15168 vat_json_node_t *node = NULL;
15169 struct in_addr ip4;
15170
15171 if (VAT_JSON_ARRAY != vam->json_tree.type)
15172 {
15173 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15174 vat_json_init_array (&vam->json_tree);
15175 }
15176 node = vat_json_array_add (&vam->json_tree);
15177
15178 vat_json_init_object (node);
15179 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
15180 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
15181 vat_json_object_add_ip4 (node, "src_address", ip4);
15182 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
15183 vat_json_object_add_ip4 (node, "dst_address", ip4);
15184 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
15185 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
15186}
15187
15188static int
15189api_ipsec_gre_tunnel_dump (vat_main_t * vam)
15190{
15191 unformat_input_t *i = vam->input;
15192 vl_api_ipsec_gre_tunnel_dump_t *mp;
15193 f64 timeout;
15194 u32 sw_if_index;
15195 u8 sw_if_index_set = 0;
15196
15197 /* Parse args required to build the message */
15198 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15199 {
15200 if (unformat (i, "sw_if_index %d", &sw_if_index))
15201 sw_if_index_set = 1;
15202 else
15203 break;
15204 }
15205
15206 if (sw_if_index_set == 0)
15207 {
15208 sw_if_index = ~0;
15209 }
15210
15211 if (!vam->json_output)
15212 {
15213 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
15214 "sw_if_index", "src_address", "dst_address",
15215 "local_sa_id", "remote_sa_id");
15216 }
15217
15218 /* Get list of gre-tunnel interfaces */
15219 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
15220
15221 mp->sw_if_index = htonl (sw_if_index);
15222
15223 S;
15224
15225 /* Use a control ping for synchronization */
15226 {
15227 vl_api_control_ping_t *mp;
15228 M (CONTROL_PING, control_ping);
15229 S;
15230 }
15231 W;
15232}
15233
15234static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015235api_delete_subif (vat_main_t * vam)
15236{
15237 unformat_input_t *i = vam->input;
15238 vl_api_delete_subif_t *mp;
15239 f64 timeout;
15240 u32 sw_if_index = ~0;
15241
15242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15243 {
15244 if (unformat (i, "sw_if_index %d", &sw_if_index))
15245 ;
15246 else
15247 break;
15248 }
15249
15250 if (sw_if_index == ~0)
15251 {
15252 errmsg ("missing sw_if_index\n");
15253 return -99;
15254 }
15255
15256 /* Construct the API message */
15257 M (DELETE_SUBIF, delete_subif);
15258 mp->sw_if_index = ntohl (sw_if_index);
15259
15260 S;
15261 W;
15262}
15263
Pavel Kotucek95300d12016-08-26 16:11:36 +020015264#define foreach_pbb_vtr_op \
15265_("disable", L2_VTR_DISABLED) \
15266_("pop", L2_VTR_POP_2) \
15267_("push", L2_VTR_PUSH_2)
15268
15269static int
15270api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
15271{
15272 unformat_input_t *i = vam->input;
15273 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
15274 f64 timeout;
15275 u32 sw_if_index = ~0, vtr_op = ~0;
15276 u16 outer_tag = ~0;
15277 u8 dmac[6], smac[6];
15278 u8 dmac_set = 0, smac_set = 0;
15279 u16 vlanid = 0;
15280 u32 sid = ~0;
15281 u32 tmp;
15282
15283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15284 {
15285 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15286 ;
15287 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15288 ;
15289 else if (unformat (i, "vtr_op %d", &vtr_op))
15290 ;
15291#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
15292 foreach_pbb_vtr_op
15293#undef _
15294 else if (unformat (i, "translate_pbb_stag"))
15295 {
15296 if (unformat (i, "%d", &tmp))
15297 {
15298 vtr_op = L2_VTR_TRANSLATE_2_1;
15299 outer_tag = tmp;
15300 }
15301 else
15302 {
15303 errmsg
15304 ("translate_pbb_stag operation requires outer tag definition\n");
15305 return -99;
15306 }
15307 }
15308 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
15309 dmac_set++;
15310 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
15311 smac_set++;
15312 else if (unformat (i, "sid %d", &sid))
15313 ;
15314 else if (unformat (i, "vlanid %d", &tmp))
15315 vlanid = tmp;
15316 else
15317 {
15318 clib_warning ("parse error '%U'", format_unformat_error, i);
15319 return -99;
15320 }
15321 }
15322
15323 if ((sw_if_index == ~0) || (vtr_op == ~0))
15324 {
15325 errmsg ("missing sw_if_index or vtr operation\n");
15326 return -99;
15327 }
15328 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
15329 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
15330 {
15331 errmsg
15332 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
15333 return -99;
15334 }
15335
15336 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
15337 mp->sw_if_index = ntohl (sw_if_index);
15338 mp->vtr_op = ntohl (vtr_op);
15339 mp->outer_tag = ntohs (outer_tag);
15340 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
15341 clib_memcpy (mp->b_smac, smac, sizeof (smac));
15342 mp->b_vlanid = ntohs (vlanid);
15343 mp->i_sid = ntohl (sid);
15344
15345 S;
15346 W;
15347 /* NOTREACHED */
15348 return 0;
15349}
15350
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015351static int
Dave Barach72d72232016-08-04 10:15:08 -040015352q_or_quit (vat_main_t * vam)
15353{
15354 longjmp (vam->jump_buf, 1);
15355 return 0; /* not so much */
15356}
15357
15358static int
15359q (vat_main_t * vam)
15360{
15361 return q_or_quit (vam);
15362}
15363
15364static int
15365quit (vat_main_t * vam)
15366{
15367 return q_or_quit (vam);
15368}
15369
15370static int
15371comment (vat_main_t * vam)
15372{
15373 return 0;
15374}
15375
15376static int
15377cmd_cmp (void *a1, void *a2)
15378{
15379 u8 **c1 = a1;
15380 u8 **c2 = a2;
15381
15382 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
15383}
15384
15385static int
15386help (vat_main_t * vam)
15387{
15388 u8 **cmds = 0;
15389 u8 *name = 0;
15390 hash_pair_t *p;
15391 unformat_input_t *i = vam->input;
15392 int j;
15393
15394 if (unformat (i, "%s", &name))
15395 {
15396 uword *hs;
15397
15398 vec_add1 (name, 0);
15399
15400 hs = hash_get_mem (vam->help_by_name, name);
15401 if (hs)
15402 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
15403 else
15404 fformat (vam->ofp, "No such msg / command '%s'\n", name);
15405 vec_free (name);
15406 return 0;
15407 }
15408
15409 fformat (vam->ofp, "Help is available for the following:\n");
15410
15411 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015412 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070015413 ({
Dave Barach72d72232016-08-04 10:15:08 -040015414 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015415 }));
Dave Barach72d72232016-08-04 10:15:08 -040015416 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015417
Dave Barach72d72232016-08-04 10:15:08 -040015418 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015419
Dave Barach72d72232016-08-04 10:15:08 -040015420 for (j = 0; j < vec_len (cmds); j++)
15421 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015422
Dave Barach72d72232016-08-04 10:15:08 -040015423 vec_free (cmds);
15424 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015425}
15426
Dave Barach72d72232016-08-04 10:15:08 -040015427static int
15428set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015429{
Dave Barach72d72232016-08-04 10:15:08 -040015430 u8 *name = 0, *value = 0;
15431 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015432
Dave Barach72d72232016-08-04 10:15:08 -040015433 if (unformat (i, "%s", &name))
15434 {
15435 /* The input buffer is a vector, not a string. */
15436 value = vec_dup (i->buffer);
15437 vec_delete (value, i->index, 0);
15438 /* Almost certainly has a trailing newline */
15439 if (value[vec_len (value) - 1] == '\n')
15440 value[vec_len (value) - 1] = 0;
15441 /* Make sure it's a proper string, one way or the other */
15442 vec_add1 (value, 0);
15443 (void) clib_macro_set_value (&vam->macro_main,
15444 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015445 }
Dave Barach72d72232016-08-04 10:15:08 -040015446 else
15447 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070015448
Dave Barach72d72232016-08-04 10:15:08 -040015449 vec_free (name);
15450 vec_free (value);
15451 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015452}
15453
Dave Barach72d72232016-08-04 10:15:08 -040015454static int
15455unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015456{
Dave Barach72d72232016-08-04 10:15:08 -040015457 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015458
Dave Barach72d72232016-08-04 10:15:08 -040015459 if (unformat (vam->input, "%s", &name))
15460 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
15461 errmsg ("unset: %s wasn't set\n", name);
15462 vec_free (name);
15463 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015464}
15465
Dave Barach72d72232016-08-04 10:15:08 -040015466typedef struct
15467{
15468 u8 *name;
15469 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015470} macro_sort_t;
15471
15472
Dave Barach72d72232016-08-04 10:15:08 -040015473static int
15474macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015475{
Dave Barach72d72232016-08-04 10:15:08 -040015476 macro_sort_t *s1 = a1;
15477 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015478
Dave Barach72d72232016-08-04 10:15:08 -040015479 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015480}
15481
Dave Barach72d72232016-08-04 10:15:08 -040015482static int
15483dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015484{
Dave Barach72d72232016-08-04 10:15:08 -040015485 macro_sort_t *sort_me = 0, *sm;
15486 int i;
15487 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015488
Dave Barach72d72232016-08-04 10:15:08 -040015489 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015490 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070015491 ({
Dave Barach72d72232016-08-04 10:15:08 -040015492 vec_add2 (sort_me, sm, 1);
15493 sm->name = (u8 *)(p->key);
15494 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015495 }));
Dave Barach72d72232016-08-04 10:15:08 -040015496 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015497
Dave Barach72d72232016-08-04 10:15:08 -040015498 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015499
Dave Barach72d72232016-08-04 10:15:08 -040015500 if (vec_len (sort_me))
15501 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
15502 else
15503 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070015504
Dave Barach72d72232016-08-04 10:15:08 -040015505 for (i = 0; i < vec_len (sort_me); i++)
15506 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
15507 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015508}
15509
Dave Barach72d72232016-08-04 10:15:08 -040015510static int
15511dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050015512{
Dave Barach72d72232016-08-04 10:15:08 -040015513 int i, j;
15514 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015515
Dave Barach72d72232016-08-04 10:15:08 -040015516 if (vec_len (vam->graph_nodes) == 0)
15517 {
15518 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
15519 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015520 }
15521
Dave Barach72d72232016-08-04 10:15:08 -040015522 for (i = 0; i < vec_len (vam->graph_nodes); i++)
15523 {
15524 node = vam->graph_nodes[i];
15525 fformat (vam->ofp, "[%d] %s\n", i, node->name);
15526 for (j = 0; j < vec_len (node->next_nodes); j++)
15527 {
15528 if (node->next_nodes[j] != ~0)
15529 {
15530 next_node = vam->graph_nodes[node->next_nodes[j]];
15531 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
15532 }
15533 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050015534 }
Dave Barach72d72232016-08-04 10:15:08 -040015535 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015536}
15537
Dave Barach72d72232016-08-04 10:15:08 -040015538static int
15539search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050015540{
Dave Barach72d72232016-08-04 10:15:08 -040015541 unformat_input_t *line_input = vam->input;
15542 u8 *node_to_find;
15543 int j;
15544 vlib_node_t *node, *next_node;
15545 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015546
Dave Barach72d72232016-08-04 10:15:08 -040015547 if (vam->graph_node_index_by_name == 0)
15548 {
15549 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
15550 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015551 }
15552
Dave Barach72d72232016-08-04 10:15:08 -040015553 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
15554 {
15555 if (unformat (line_input, "%s", &node_to_find))
15556 {
15557 vec_add1 (node_to_find, 0);
15558 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
15559 if (p == 0)
15560 {
15561 fformat (vam->ofp, "%s not found...\n", node_to_find);
15562 goto out;
15563 }
15564 node = vam->graph_nodes[p[0]];
15565 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
15566 for (j = 0; j < vec_len (node->next_nodes); j++)
15567 {
15568 if (node->next_nodes[j] != ~0)
15569 {
15570 next_node = vam->graph_nodes[node->next_nodes[j]];
15571 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
15572 }
15573 }
15574 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015575
Dave Barach72d72232016-08-04 10:15:08 -040015576 else
15577 {
15578 clib_warning ("parse error '%U'", format_unformat_error,
15579 line_input);
15580 return -99;
15581 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050015582
15583 out:
Dave Barach72d72232016-08-04 10:15:08 -040015584 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015585
Dave Barachb44e9bc2016-02-19 09:06:23 -050015586 }
15587
Dave Barach72d72232016-08-04 10:15:08 -040015588 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015589}
15590
15591
Dave Barach72d72232016-08-04 10:15:08 -040015592static int
15593script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015594{
Dave Barach72d72232016-08-04 10:15:08 -040015595 u8 *s = 0;
15596 char *save_current_file;
15597 unformat_input_t save_input;
15598 jmp_buf save_jump_buf;
15599 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015600
Dave Barach72d72232016-08-04 10:15:08 -040015601 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015602
Dave Barach72d72232016-08-04 10:15:08 -040015603 if (unformat (vam->input, "%s", &s))
15604 {
15605 new_fp = fopen ((char *) s, "r");
15606 if (new_fp == 0)
15607 {
15608 errmsg ("Couldn't open script file %s\n", s);
15609 vec_free (s);
15610 return -99;
15611 }
15612 }
15613 else
15614 {
15615 errmsg ("Missing script name\n");
15616 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015617 }
15618
Dave Barach72d72232016-08-04 10:15:08 -040015619 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
15620 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
15621 save_ifp = vam->ifp;
15622 save_line_number = vam->input_line_number;
15623 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015624
Dave Barach72d72232016-08-04 10:15:08 -040015625 vam->input_line_number = 0;
15626 vam->ifp = new_fp;
15627 vam->current_file = s;
15628 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015629
Dave Barach72d72232016-08-04 10:15:08 -040015630 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
15631 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
15632 vam->ifp = save_ifp;
15633 vam->input_line_number = save_line_number;
15634 vam->current_file = (u8 *) save_current_file;
15635 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015636
Dave Barach72d72232016-08-04 10:15:08 -040015637 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015638}
15639
Dave Barach72d72232016-08-04 10:15:08 -040015640static int
15641echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015642{
Dave Barach72d72232016-08-04 10:15:08 -040015643 fformat (vam->ofp, "%v", vam->input->buffer);
15644 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015645}
15646
15647/* List of API message constructors, CLI names map to api_xxx */
15648#define foreach_vpe_api_msg \
15649_(create_loopback,"[mac <mac-addr>]") \
15650_(sw_interface_dump,"") \
15651_(sw_interface_set_flags, \
15652 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
15653_(sw_interface_add_del_address, \
15654 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
15655_(sw_interface_set_table, \
15656 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
15657_(sw_interface_set_vpath, \
15658 "<intfc> | sw_if_index <id> enable | disable") \
15659_(sw_interface_set_l2_xconnect, \
15660 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15661 "enable | disable") \
15662_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040015663 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015664 "[shg <split-horizon-group>] [bvi]\n" \
15665 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010015666_(sw_interface_set_dpdk_hqos_pipe, \
15667 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
15668 "profile <profile-id>\n") \
15669_(sw_interface_set_dpdk_hqos_subport, \
15670 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
15671 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
15672_(sw_interface_set_dpdk_hqos_tctbl, \
15673 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015674_(bridge_domain_add_del, \
15675 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
15676_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
15677_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070015678 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015679_(l2_flags, \
15680 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
15681_(bridge_flags, \
15682 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
15683_(tap_connect, \
15684 "tapname <name> mac <mac-addr> | random-mac") \
15685_(tap_modify, \
15686 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
15687_(tap_delete, \
15688 "<vpp-if-name> | sw_if_index <id>") \
15689_(sw_interface_tap_dump, "") \
15690_(ip_add_del_route, \
15691 "<addr>/<mask> via <addr> [vrf <n>]\n" \
15692 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
15693 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
15694 "[multipath] [count <n>]") \
15695_(proxy_arp_add_del, \
15696 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
15697_(proxy_arp_intfc_enable_disable, \
15698 "<intfc> | sw_if_index <id> enable | disable") \
15699_(mpls_add_del_encap, \
15700 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
15701_(mpls_add_del_decap, \
15702 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
15703_(mpls_gre_add_del_tunnel, \
15704 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
15705 "adj <ip4-address>/<mask-width> [del]") \
15706_(sw_interface_set_unnumbered, \
15707 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
15708_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040015709 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
15710 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015711_(reset_vrf, "vrf <id> [ipv6]") \
15712_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
15713_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
15714 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
15715 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
15716 "[outer_vlan_id_any][inner_vlan_id_any]") \
15717_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
15718_(reset_fib, "vrf <n> [ipv6]") \
15719_(dhcp_proxy_config, \
15720 "svr <v46-address> src <v46-address>\n" \
15721 "insert-cid <n> [del]") \
15722_(dhcp_proxy_config_2, \
15723 "svr <v46-address> src <v46-address>\n" \
15724 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
15725_(dhcp_proxy_set_vss, \
15726 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
15727_(dhcp_client_config, \
15728 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
15729_(set_ip_flow_hash, \
15730 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
15731_(sw_interface_ip6_enable_disable, \
15732 "<intfc> | sw_if_index <id> enable | disable") \
15733_(sw_interface_ip6_set_link_local_address, \
15734 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
15735_(sw_interface_ip6nd_ra_prefix, \
15736 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
15737 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
15738 "[nolink] [isno]") \
15739_(sw_interface_ip6nd_ra_config, \
15740 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040015741 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015742 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
15743_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
15744_(l2_patch_add_del, \
15745 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15746 "enable | disable") \
15747_(mpls_ethernet_add_del_tunnel, \
15748 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
15749 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
15750_(mpls_ethernet_add_del_tunnel_2, \
15751 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
15752 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
15753_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070015754 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
15755 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
15756 "[policy <policy_name>]") \
15757_(sr_policy_add_del, \
15758 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
15759_(sr_multicast_map_add_del, \
15760 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015761_(classify_add_del_table, \
15762 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
15763 "[del] mask <mask-value>\n" \
15764 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
15765_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015766 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
15767 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
15768 " [l3 [ip4|ip6]]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015769_(classify_set_interface_ip_table, \
15770 "<intfc> | sw_if_index <nn> table <nn>") \
15771_(classify_set_interface_l2_tables, \
15772 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15773 " [other-table <nn>]") \
15774_(get_node_index, "node <node-name") \
15775_(add_node_next, "node <node-name> next <next-node-name>") \
15776_(l2tpv3_create_tunnel, \
15777 "client_address <ip6-addr> our_address <ip6-addr>\n" \
15778 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
15779 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
15780_(l2tpv3_set_tunnel_cookies, \
15781 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
15782 "[new_remote_cookie <nn>]\n") \
15783_(l2tpv3_interface_enable_disable, \
15784 "<intfc> | sw_if_index <nn> enable | disable") \
15785_(l2tpv3_set_lookup_key, \
15786 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
15787_(sw_if_l2tpv3_tunnel_dump, "") \
15788_(vxlan_add_del_tunnel, \
Chris Luke404be662016-05-27 12:11:24 -040015789 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015790 " [decap-next l2|ip4|ip6] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050015791_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040015792_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070015793 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040015794_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015795_(l2_fib_clear_table, "") \
15796_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
15797_(l2_interface_vlan_tag_rewrite, \
15798 "<intfc> | sw_if_index <nn> \n" \
15799 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
15800 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
15801_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000015802 "socket <filename> [server] [renumber <dev_instance>] " \
15803 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015804_(modify_vhost_user_if, \
15805 "<intfc> | sw_if_index <nn> socket <filename>\n" \
15806 "[server] [renumber <dev_instance>]") \
15807_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
15808_(sw_interface_vhost_user_dump, "") \
15809_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080015810_(vxlan_gpe_add_del_tunnel, \
15811 "local <addr> remote <addr> vni <nn>\n" \
15812 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
15813 "[next-ethernet] [next-nsh]\n") \
15814_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015815_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015816_(interface_name_renumber, \
15817 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
15818_(input_acl_set_interface, \
15819 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15820 " [l2-table <nn>] [del]") \
15821_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040015822_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015823_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15824_(ip_dump, "ipv4 | ipv6") \
15825_(ipsec_spd_add_del, "spd_id <n> [del]") \
15826_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15827 " spid_id <n> ") \
15828_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15829 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15830 " integ_alg <alg> integ_key <hex>") \
15831_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
15832 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15833 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15834 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
15835_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020015836_(ikev2_profile_add_del, "name <profile_name> [del]") \
15837_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
15838 "(auth_data 0x<data> | auth_data <data>)") \
15839_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
15840 "(id_data 0x<data> | id_data <data>) (local|remote)") \
15841_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
15842 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
15843 "(local|remote)") \
15844_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015845_(delete_loopback,"sw_if_index <nn>") \
15846_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15847_(map_add_domain, \
15848 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
15849 "ip6-src <ip6addr> " \
15850 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
15851_(map_del_domain, "index <n>") \
15852_(map_add_del_rule, \
15853 "index <n> psid <n> dst <ip6addr> [del]") \
15854_(map_domain_dump, "") \
15855_(map_rule_dump, "index <map-domain>") \
15856_(want_interface_events, "enable|disable") \
15857_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050015858_(get_first_msg_id, "client <name>") \
15859_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15860_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015861 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010015862_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000015863_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070015864_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15865_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020015866_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
15867 " sw_if_index <sw_if_index> p <priority> " \
15868 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015869_(lisp_add_del_locator, "locator-set <locator_name> " \
15870 "iface <intf> | sw_if_index <sw_if_index> " \
15871 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020015872_(lisp_add_del_local_eid,"vni <vni> eid " \
15873 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015874 "locator-set <locator_name> [del]") \
Florin Coras429e7952016-08-02 02:31:03 +020015875_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
15876 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015877_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020015878_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020015879_(lisp_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015880_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020015881_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
15882 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020015883 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020015884 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020015885 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020015886_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
15887 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020015888_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020015889_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020015890_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020015891_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020015892_(lisp_locator_set_dump, "[local | remote]") \
15893_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020015894_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
15895 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020015896_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020015897_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015898_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020015899_(lisp_map_resolver_dump, "") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020015900_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020015901_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020015902_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020015903_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020015904_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070015905_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070015906_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070015907_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015908_(policer_classify_set_interface, \
15909 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15910 " [l2-table <nn>] [del]") \
15911_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070015912_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
15913 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015914_(netmap_delete, "name <interface name>") \
15915_(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
15916_(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
15917_(mpls_fib_encap_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015918_(mpls_fib_decap_dump, "") \
15919_(classify_table_ids, "") \
15920_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15921_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015922_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015923_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15924 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15925 "[template_interval <nn>] [udp_checksum]") \
15926_(ipfix_exporter_dump, "") \
15927_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15928_(ipfix_classify_stream_dump, "") \
15929_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
15930_(ipfix_classify_table_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015931_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15932_(pg_create_interface, "if_id <nn>") \
15933_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040015934_(pg_enable_disable, "[stream <id>] disable") \
15935_(ip_source_and_port_range_check_add_del, \
15936 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15937_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070015938 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070015939 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15940_(ipsec_gre_add_del_tunnel, \
15941 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015942_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020015943_(delete_subif,"sub_sw_if_index <nn> sub_if_id <nn>") \
15944_(l2_interface_pbb_tag_rewrite, \
15945 "<intfc> | sw_if_index <nn> \n" \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070015946 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
15947 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
15948_(punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]")
Ed Warnickecb9cada2015-12-08 15:45:58 -070015949
15950/* List of command functions, CLI names map directly to functions */
15951#define foreach_cli_function \
15952_(comment, "usage: comment <ignore-rest-of-line>") \
15953_(dump_interface_table, "usage: dump_interface_table") \
15954_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15955_(dump_ipv4_table, "usage: dump_ipv4_table") \
15956_(dump_ipv6_table, "usage: dump_ipv6_table") \
15957_(dump_stats_table, "usage: dump_stats_table") \
15958_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015959_(dump_node_table, "usage: dump_node_table") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015960_(echo, "usage: echo <message>") \
15961_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020015962_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015963_(help, "usage: help") \
15964_(q, "usage: quit") \
15965_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015966_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015967_(set, "usage: set <variable-name> <value>") \
15968_(script, "usage: script <file-name>") \
15969_(unset, "usage: unset <variable-name>")
15970
15971#define _(N,n) \
15972 static void vl_api_##n##_t_handler_uni \
15973 (vl_api_##n##_t * mp) \
15974 { \
15975 vat_main_t * vam = &vat_main; \
15976 if (vam->json_output) { \
15977 vl_api_##n##_t_handler_json(mp); \
15978 } else { \
15979 vl_api_##n##_t_handler(mp); \
15980 } \
15981 }
15982foreach_vpe_api_reply_msg;
15983#undef _
15984
Dave Barach72d72232016-08-04 10:15:08 -040015985void
15986vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015987{
15988#define _(N,n) \
15989 vl_msg_api_set_handlers(VL_API_##N, #n, \
15990 vl_api_##n##_t_handler_uni, \
15991 vl_noop_handler, \
15992 vl_api_##n##_t_endian, \
15993 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015994 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040015995 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015996#undef _
15997
Dave Barach72d72232016-08-04 10:15:08 -040015998 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015999
Dave Barach72d72232016-08-04 10:15:08 -040016000 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016001
Dave Barach72d72232016-08-04 10:15:08 -040016002 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016003
Dave Barach72d72232016-08-04 10:15:08 -040016004 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016005
Dave Barach72d72232016-08-04 10:15:08 -040016006 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016007#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040016008 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016009#undef _
16010
Dave Barach72d72232016-08-04 10:15:08 -040016011 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016012#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040016013 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016014#undef _
16015
Dave Barach72d72232016-08-04 10:15:08 -040016016 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016017#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040016018 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016019#undef _
16020
Dave Barach72d72232016-08-04 10:15:08 -040016021 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016022#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040016023 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016024#undef _
16025}
16026
16027#undef vl_api_version
16028#define vl_api_version(n,v) static u32 vpe_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040016029#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070016030#undef vl_api_version
16031
Dave Barach72d72232016-08-04 10:15:08 -040016032void
16033vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016034{
Dave Barach72d72232016-08-04 10:15:08 -040016035 /*
16036 * Send the main API signature in slot 0. This bit of code must
16037 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
16038 */
16039 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016040}
Dave Barach72d72232016-08-04 10:15:08 -040016041
16042/*
16043 * fd.io coding-style-patch-verification: ON
16044 *
16045 * Local Variables:
16046 * eval: (c-set-style "gnu")
16047 * End:
16048 */