blob: 7dc7ceab79260845797da69ca75b1e7d4d7ee240 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003 * api_format.c
4 *
Ed Warnickecb9cada2015-12-08 15:45:58 -07005 * Copyright (c) 2014 Cisco and/or its affiliates.
6 * 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) \
3485_(l2_interface_pbb_tag_rewrite_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003486
3487#define _(n) \
3488 static void vl_api_##n##_t_handler \
3489 (vl_api_##n##_t * mp) \
3490 { \
3491 vat_main_t * vam = &vat_main; \
3492 i32 retval = ntohl(mp->retval); \
3493 if (vam->async_mode) { \
3494 vam->async_errors += (retval < 0); \
3495 } else { \
3496 vam->retval = retval; \
3497 vam->result_ready = 1; \
3498 } \
3499 }
3500foreach_standard_reply_retval_handler;
3501#undef _
3502
3503#define _(n) \
3504 static void vl_api_##n##_t_handler_json \
3505 (vl_api_##n##_t * mp) \
3506 { \
3507 vat_main_t * vam = &vat_main; \
3508 vat_json_node_t node; \
3509 vat_json_init_object(&node); \
3510 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3511 vat_json_print(vam->ofp, &node); \
3512 vam->retval = ntohl(mp->retval); \
3513 vam->result_ready = 1; \
3514 }
3515foreach_standard_reply_retval_handler;
3516#undef _
3517
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003518/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07003519 * Table of message reply handlers, must include boilerplate handlers
3520 * we just generated
3521 */
3522
3523#define foreach_vpe_api_reply_msg \
3524_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3525_(SW_INTERFACE_DETAILS, sw_interface_details) \
3526_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3527_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3528_(CONTROL_PING_REPLY, control_ping_reply) \
3529_(CLI_REPLY, cli_reply) \
Ole Troanc27213a2016-08-31 14:50:49 +02003530_(CLI_INBAND_REPLY, cli_inband_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003531_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3532 sw_interface_add_del_address_reply) \
3533_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3534_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3535_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3536 sw_interface_set_l2_xconnect_reply) \
3537_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3538 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003539_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3540 sw_interface_set_dpdk_hqos_pipe_reply) \
3541_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3542 sw_interface_set_dpdk_hqos_subport_reply) \
3543_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3544 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003545_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3546_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3547_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3548_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3549_(L2_FLAGS_REPLY, l2_flags_reply) \
3550_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3551_(TAP_CONNECT_REPLY, tap_connect_reply) \
3552_(TAP_MODIFY_REPLY, tap_modify_reply) \
3553_(TAP_DELETE_REPLY, tap_delete_reply) \
3554_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3555_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
3556_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3557_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3558 proxy_arp_intfc_enable_disable_reply) \
3559_(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
3560_(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
3561_(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
3562_(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3563 mpls_ethernet_add_del_tunnel_reply) \
3564_(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3565 mpls_ethernet_add_del_tunnel_2_reply) \
3566_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3567 sw_interface_set_unnumbered_reply) \
3568_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3569_(RESET_VRF_REPLY, reset_vrf_reply) \
3570_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3571_(CREATE_SUBIF_REPLY, create_subif_reply) \
3572_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3573_(RESET_FIB_REPLY, reset_fib_reply) \
3574_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3575_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3576_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3577_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3578_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3579_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3580 sw_interface_ip6_enable_disable_reply) \
3581_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3582 sw_interface_ip6_set_link_local_address_reply) \
3583_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3584 sw_interface_ip6nd_ra_prefix_reply) \
3585_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3586 sw_interface_ip6nd_ra_config_reply) \
3587_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3588_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3589_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003590_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3591_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003592_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3593_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3594_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3595classify_set_interface_ip_table_reply) \
3596_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3597 classify_set_interface_l2_tables_reply) \
3598_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3599_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3600_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3601_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3602_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3603 l2tpv3_interface_enable_disable_reply) \
3604_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3605_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3606_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003607_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003608_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3609_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003610_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3611_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3612_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3613_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3614_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3615_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3616_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3617_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003618_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003619_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3620_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003621_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3622_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3623_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003624_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3625_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003626_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3627_(IP_ADDRESS_DETAILS, ip_address_details) \
3628_(IP_DETAILS, ip_details) \
3629_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3630_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3631_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3632_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3633_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003634_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3635_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3636_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3637_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3638_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003639_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3640_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3641_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3642_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3643_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3644_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3645_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3646_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003647_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003648_(MAP_DOMAIN_DETAILS, map_domain_details) \
3649_(MAP_RULE_DETAILS, map_rule_details) \
3650_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3651_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003652_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3653_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003654_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003655_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003656_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003657_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3658_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003659_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3660_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3661_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003662_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3663_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003664_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3665_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003666_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003667_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003668_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003669_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003670_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003671_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3672_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003673_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003674_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003675_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003676_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003677_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003678_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003679_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003680_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3681 lisp_add_del_map_request_itr_rlocs_reply) \
3682_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3683 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003684_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003685_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003686_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003687_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003688_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003689_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003690_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3691_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003692_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003693_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
3694_(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
3695_(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3696_(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003697_(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
3698_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3699_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3700_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003701_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003702_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3703_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3704_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3705_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3706_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3707_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003708_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3709_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3710_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003711_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3712_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3713 ip_source_and_port_range_check_add_del_reply) \
3714_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003715 ip_source_and_port_range_check_interface_add_del_reply) \
3716_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003717_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
Pavel Kotucek95300d12016-08-26 16:11:36 +02003718_(DELETE_SUBIF_REPLY, delete_subif_reply) \
3719_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003720
3721/* M: construct, but don't yet send a message */
3722
3723#define M(T,t) \
3724do { \
3725 vam->result_ready = 0; \
3726 mp = vl_msg_api_alloc(sizeof(*mp)); \
3727 memset (mp, 0, sizeof (*mp)); \
3728 mp->_vl_msg_id = ntohs (VL_API_##T); \
3729 mp->client_index = vam->my_client_index; \
3730} while(0);
3731
3732#define M2(T,t,n) \
3733do { \
3734 vam->result_ready = 0; \
3735 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3736 memset (mp, 0, sizeof (*mp)); \
3737 mp->_vl_msg_id = ntohs (VL_API_##T); \
3738 mp->client_index = vam->my_client_index; \
3739} while(0);
3740
3741
3742/* S: send a message */
3743#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3744
3745/* W: wait for results, with timeout */
3746#define W \
3747do { \
3748 timeout = vat_time_now (vam) + 1.0; \
3749 \
3750 while (vat_time_now (vam) < timeout) { \
3751 if (vam->result_ready == 1) { \
3752 return (vam->retval); \
3753 } \
3754 } \
3755 return -99; \
3756} while(0);
3757
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003758/* W2: wait for results, with timeout */
3759#define W2(body) \
3760do { \
3761 timeout = vat_time_now (vam) + 1.0; \
3762 \
3763 while (vat_time_now (vam) < timeout) { \
3764 if (vam->result_ready == 1) { \
3765 (body); \
3766 return (vam->retval); \
3767 } \
3768 } \
3769 return -99; \
3770} while(0);
3771
Dave Barach72d72232016-08-04 10:15:08 -04003772typedef struct
3773{
3774 u8 *name;
3775 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003776} name_sort_t;
3777
3778
3779#define STR_VTR_OP_CASE(op) \
3780 case L2_VTR_ ## op: \
3781 return "" # op;
3782
Dave Barach72d72232016-08-04 10:15:08 -04003783static const char *
3784str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003785{
Dave Barach72d72232016-08-04 10:15:08 -04003786 switch (vtr_op)
3787 {
3788 STR_VTR_OP_CASE (DISABLED);
3789 STR_VTR_OP_CASE (PUSH_1);
3790 STR_VTR_OP_CASE (PUSH_2);
3791 STR_VTR_OP_CASE (POP_1);
3792 STR_VTR_OP_CASE (POP_2);
3793 STR_VTR_OP_CASE (TRANSLATE_1_1);
3794 STR_VTR_OP_CASE (TRANSLATE_1_2);
3795 STR_VTR_OP_CASE (TRANSLATE_2_1);
3796 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003797 }
3798
Dave Barach72d72232016-08-04 10:15:08 -04003799 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07003800}
3801
Dave Barach72d72232016-08-04 10:15:08 -04003802static int
3803dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003804{
Dave Barach72d72232016-08-04 10:15:08 -04003805 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003806
Dave Barach72d72232016-08-04 10:15:08 -04003807 if (vam->json_output)
3808 {
3809 clib_warning
3810 ("JSON output supported only for VPE API calls and dump_stats_table");
3811 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003812 }
3813
Dave Barach72d72232016-08-04 10:15:08 -04003814 fformat (vam->ofp,
3815 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3816 "Interface", "sw_if_index",
3817 "sub id", "dot1ad", "tags", "outer id",
3818 "inner id", "exact", "default", "outer any", "inner any");
3819
3820 vec_foreach (sub, vam->sw_if_subif_table)
3821 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07003822 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003823 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3824 sub->interface_name,
3825 sub->sw_if_index,
3826 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3827 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3828 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3829 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3830 if (sub->vtr_op != L2_VTR_DISABLED)
3831 {
3832 fformat (vam->ofp,
3833 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3834 "tag1: %d tag2: %d ]\n",
3835 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3836 sub->vtr_tag1, sub->vtr_tag2);
3837 }
3838 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003839
Dave Barach72d72232016-08-04 10:15:08 -04003840 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003841}
3842
Dave Barach72d72232016-08-04 10:15:08 -04003843static int
3844name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003845{
Dave Barach72d72232016-08-04 10:15:08 -04003846 name_sort_t *n1 = a1;
3847 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003848
Dave Barach72d72232016-08-04 10:15:08 -04003849 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003850}
3851
Dave Barach72d72232016-08-04 10:15:08 -04003852static int
3853dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003854{
Dave Barach72d72232016-08-04 10:15:08 -04003855 hash_pair_t *p;
3856 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003857
Dave Barach72d72232016-08-04 10:15:08 -04003858 if (vam->json_output)
3859 {
3860 clib_warning
3861 ("JSON output supported only for VPE API calls and dump_stats_table");
3862 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003863 }
3864
Dave Barach72d72232016-08-04 10:15:08 -04003865 /* *INDENT-OFF* */
3866 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3867 ({
3868 vec_add2 (nses, ns, 1);
3869 ns->name = (u8 *)(p->key);
3870 ns->value = (u32) p->value[0];
3871 }));
3872 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003873
Dave Barach72d72232016-08-04 10:15:08 -04003874 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003875
Dave Barach72d72232016-08-04 10:15:08 -04003876 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3877 vec_foreach (ns, nses)
3878 {
3879 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3880 }
3881 vec_free (nses);
3882 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003883}
3884
Dave Barach72d72232016-08-04 10:15:08 -04003885static int
3886dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003887{
Dave Barach72d72232016-08-04 10:15:08 -04003888 const ip_details_t *det = NULL;
3889 const ip_address_details_t *address = NULL;
3890 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003891
Dave Barach72d72232016-08-04 10:15:08 -04003892 fformat (vam->ofp, "%-12s\n", "sw_if_index");
3893
Dave Barach72d72232016-08-04 10:15:08 -04003894 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3895 {
3896 i++;
3897 if (!det->present)
3898 {
3899 continue;
3900 }
3901 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003902 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003903 " %-30s%-13s\n", "Address", "Prefix length");
3904 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003905 {
Dave Barach72d72232016-08-04 10:15:08 -04003906 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003907 }
Dave Barach72d72232016-08-04 10:15:08 -04003908 vec_foreach (address, det->addr)
3909 {
3910 fformat (vam->ofp,
3911 " %-30U%-13d\n",
3912 is_ipv6 ? format_ip6_address : format_ip4_address,
3913 address->ip, address->prefix_length);
3914 }
3915 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003916
Dave Barach72d72232016-08-04 10:15:08 -04003917 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003918}
3919
Dave Barach72d72232016-08-04 10:15:08 -04003920static int
3921dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003922{
Dave Barach72d72232016-08-04 10:15:08 -04003923 if (vam->json_output)
3924 {
3925 clib_warning
3926 ("JSON output supported only for VPE API calls and dump_stats_table");
3927 return -99;
3928 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003929
Dave Barach72d72232016-08-04 10:15:08 -04003930 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003931}
3932
Dave Barach72d72232016-08-04 10:15:08 -04003933static int
3934dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003935{
Dave Barach72d72232016-08-04 10:15:08 -04003936 if (vam->json_output)
3937 {
3938 clib_warning
3939 ("JSON output supported only for VPE API calls and dump_stats_table");
3940 return -99;
3941 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003942
Dave Barach72d72232016-08-04 10:15:08 -04003943 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003944}
3945
Dave Barach72d72232016-08-04 10:15:08 -04003946static char *
3947counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003948{
Dave Barach72d72232016-08-04 10:15:08 -04003949 if (!is_combined)
3950 {
3951 switch (counter_type)
3952 {
3953 case VNET_INTERFACE_COUNTER_DROP:
3954 return "drop";
3955 case VNET_INTERFACE_COUNTER_PUNT:
3956 return "punt";
3957 case VNET_INTERFACE_COUNTER_IP4:
3958 return "ip4";
3959 case VNET_INTERFACE_COUNTER_IP6:
3960 return "ip6";
3961 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3962 return "rx-no-buf";
3963 case VNET_INTERFACE_COUNTER_RX_MISS:
3964 return "rx-miss";
3965 case VNET_INTERFACE_COUNTER_RX_ERROR:
3966 return "rx-error";
3967 case VNET_INTERFACE_COUNTER_TX_ERROR:
3968 return "tx-error";
3969 default:
3970 return "INVALID-COUNTER-TYPE";
3971 }
3972 }
3973 else
3974 {
3975 switch (counter_type)
3976 {
3977 case VNET_INTERFACE_COUNTER_RX:
3978 return "rx";
3979 case VNET_INTERFACE_COUNTER_TX:
3980 return "tx";
3981 default:
3982 return "INVALID-COUNTER-TYPE";
3983 }
3984 }
3985}
Ed Warnickecb9cada2015-12-08 15:45:58 -07003986
Dave Barach72d72232016-08-04 10:15:08 -04003987static int
3988dump_stats_table (vat_main_t * vam)
3989{
3990 vat_json_node_t node;
3991 vat_json_node_t *msg_array;
3992 vat_json_node_t *msg;
3993 vat_json_node_t *counter_array;
3994 vat_json_node_t *counter;
3995 interface_counter_t c;
3996 u64 packets;
3997 ip4_fib_counter_t *c4;
3998 ip6_fib_counter_t *c6;
3999 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004000
Dave Barach72d72232016-08-04 10:15:08 -04004001 if (!vam->json_output)
4002 {
4003 clib_warning ("dump_stats_table supported only in JSON format");
4004 return -99;
4005 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004006
Dave Barach72d72232016-08-04 10:15:08 -04004007 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004008
Dave Barach72d72232016-08-04 10:15:08 -04004009 /* interface counters */
4010 msg_array = vat_json_object_add (&node, "interface_counters");
4011 vat_json_init_array (msg_array);
4012 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4013 {
4014 msg = vat_json_array_add (msg_array);
4015 vat_json_init_object (msg);
4016 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4017 (u8 *) counter_type_to_str (i, 0));
4018 vat_json_object_add_int (msg, "is_combined", 0);
4019 counter_array = vat_json_object_add (msg, "data");
4020 vat_json_init_array (counter_array);
4021 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4022 {
4023 packets = vam->simple_interface_counters[i][j];
4024 vat_json_array_add_uint (counter_array, packets);
4025 }
4026 }
4027 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4028 {
4029 msg = vat_json_array_add (msg_array);
4030 vat_json_init_object (msg);
4031 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4032 (u8 *) counter_type_to_str (i, 1));
4033 vat_json_object_add_int (msg, "is_combined", 1);
4034 counter_array = vat_json_object_add (msg, "data");
4035 vat_json_init_array (counter_array);
4036 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4037 {
4038 c = vam->combined_interface_counters[i][j];
4039 counter = vat_json_array_add (counter_array);
4040 vat_json_init_object (counter);
4041 vat_json_object_add_uint (counter, "packets", c.packets);
4042 vat_json_object_add_uint (counter, "bytes", c.bytes);
4043 }
4044 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004045
Dave Barach72d72232016-08-04 10:15:08 -04004046 /* ip4 fib counters */
4047 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4048 vat_json_init_array (msg_array);
4049 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4050 {
4051 msg = vat_json_array_add (msg_array);
4052 vat_json_init_object (msg);
4053 vat_json_object_add_uint (msg, "vrf_id",
4054 vam->ip4_fib_counters_vrf_id_by_index[i]);
4055 counter_array = vat_json_object_add (msg, "c");
4056 vat_json_init_array (counter_array);
4057 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4058 {
4059 counter = vat_json_array_add (counter_array);
4060 vat_json_init_object (counter);
4061 c4 = &vam->ip4_fib_counters[i][j];
4062 vat_json_object_add_ip4 (counter, "address", c4->address);
4063 vat_json_object_add_uint (counter, "address_length",
4064 c4->address_length);
4065 vat_json_object_add_uint (counter, "packets", c4->packets);
4066 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4067 }
4068 }
4069
4070 /* ip6 fib counters */
4071 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4072 vat_json_init_array (msg_array);
4073 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4074 {
4075 msg = vat_json_array_add (msg_array);
4076 vat_json_init_object (msg);
4077 vat_json_object_add_uint (msg, "vrf_id",
4078 vam->ip6_fib_counters_vrf_id_by_index[i]);
4079 counter_array = vat_json_object_add (msg, "c");
4080 vat_json_init_array (counter_array);
4081 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4082 {
4083 counter = vat_json_array_add (counter_array);
4084 vat_json_init_object (counter);
4085 c6 = &vam->ip6_fib_counters[i][j];
4086 vat_json_object_add_ip6 (counter, "address", c6->address);
4087 vat_json_object_add_uint (counter, "address_length",
4088 c6->address_length);
4089 vat_json_object_add_uint (counter, "packets", c6->packets);
4090 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4091 }
4092 }
4093
4094 vat_json_print (vam->ofp, &node);
4095 vat_json_free (&node);
4096
4097 return 0;
4098}
4099
4100int
4101exec (vat_main_t * vam)
4102{
4103 api_main_t *am = &api_main;
4104 vl_api_cli_request_t *mp;
4105 f64 timeout;
4106 void *oldheap;
4107 u8 *cmd = 0;
4108 unformat_input_t *i = vam->input;
4109
4110 if (vec_len (i->buffer) == 0)
4111 return -1;
4112
4113 if (vam->exec_mode == 0 && unformat (i, "mode"))
4114 {
4115 vam->exec_mode = 1;
4116 return 0;
4117 }
4118 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4119 {
4120 vam->exec_mode = 0;
4121 return 0;
4122 }
4123
4124
4125 M (CLI_REQUEST, cli_request);
4126
4127 /*
4128 * Copy cmd into shared memory.
4129 * In order for the CLI command to work, it
4130 * must be a vector ending in \n, not a C-string ending
4131 * in \n\0.
4132 */
4133 pthread_mutex_lock (&am->vlib_rp->mutex);
4134 oldheap = svm_push_data_heap (am->vlib_rp);
4135
4136 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4137 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4138
4139 svm_pop_heap (oldheap);
4140 pthread_mutex_unlock (&am->vlib_rp->mutex);
4141
4142 mp->cmd_in_shmem = (u64) cmd;
4143 S;
4144 timeout = vat_time_now (vam) + 10.0;
4145
4146 while (vat_time_now (vam) < timeout)
4147 {
4148 if (vam->result_ready == 1)
4149 {
4150 u8 *free_me;
4151 if (vam->shmem_result != NULL)
4152 fformat (vam->ofp, "%s", vam->shmem_result);
4153 pthread_mutex_lock (&am->vlib_rp->mutex);
4154 oldheap = svm_push_data_heap (am->vlib_rp);
4155
4156 free_me = (u8 *) vam->shmem_result;
4157 vec_free (free_me);
4158
4159 svm_pop_heap (oldheap);
4160 pthread_mutex_unlock (&am->vlib_rp->mutex);
4161 return 0;
4162 }
4163 }
4164 return -99;
4165}
4166
Ole Troanc27213a2016-08-31 14:50:49 +02004167/*
4168 * Future replacement of exec() that passes CLI buffers directly in
4169 * the API messages instead of an additional shared memory area.
4170 */
4171static int
4172exec_inband (vat_main_t * vam)
4173{
4174 vl_api_cli_inband_t *mp;
4175 f64 timeout;
4176 unformat_input_t *i = vam->input;
4177
4178 if (vec_len (i->buffer) == 0)
4179 return -1;
4180
4181 if (vam->exec_mode == 0 && unformat (i, "mode"))
4182 {
4183 vam->exec_mode = 1;
4184 return 0;
4185 }
4186 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4187 {
4188 vam->exec_mode = 0;
4189 return 0;
4190 }
4191
4192 /*
4193 * In order for the CLI command to work, it
4194 * must be a vector ending in \n, not a C-string ending
4195 * in \n\0.
4196 */
4197 u32 len = vec_len (vam->input->buffer);
4198 M2 (CLI_INBAND, cli_inband, len);
4199 clib_memcpy (mp->cmd, vam->input->buffer, len);
4200 mp->length = htonl (len);
4201
4202 S;
4203 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4204}
4205
Dave Barach72d72232016-08-04 10:15:08 -04004206static int
4207api_create_loopback (vat_main_t * vam)
4208{
4209 unformat_input_t *i = vam->input;
4210 vl_api_create_loopback_t *mp;
4211 f64 timeout;
4212 u8 mac_address[6];
4213 u8 mac_set = 0;
4214
4215 memset (mac_address, 0, sizeof (mac_address));
4216
4217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4218 {
4219 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4220 mac_set = 1;
4221 else
4222 break;
4223 }
4224
4225 /* Construct the API message */
4226 M (CREATE_LOOPBACK, create_loopback);
4227 if (mac_set)
4228 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4229
4230 S;
4231 W;
4232}
4233
4234static int
4235api_delete_loopback (vat_main_t * vam)
4236{
4237 unformat_input_t *i = vam->input;
4238 vl_api_delete_loopback_t *mp;
4239 f64 timeout;
4240 u32 sw_if_index = ~0;
4241
4242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4243 {
4244 if (unformat (i, "sw_if_index %d", &sw_if_index))
4245 ;
4246 else
4247 break;
4248 }
4249
4250 if (sw_if_index == ~0)
4251 {
4252 errmsg ("missing sw_if_index\n");
4253 return -99;
4254 }
4255
4256 /* Construct the API message */
4257 M (DELETE_LOOPBACK, delete_loopback);
4258 mp->sw_if_index = ntohl (sw_if_index);
4259
4260 S;
4261 W;
4262}
4263
4264static int
4265api_want_stats (vat_main_t * vam)
4266{
4267 unformat_input_t *i = vam->input;
4268 vl_api_want_stats_t *mp;
4269 f64 timeout;
4270 int enable = -1;
4271
4272 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4273 {
4274 if (unformat (i, "enable"))
4275 enable = 1;
4276 else if (unformat (i, "disable"))
4277 enable = 0;
4278 else
4279 break;
4280 }
4281
4282 if (enable == -1)
4283 {
4284 errmsg ("missing enable|disable\n");
4285 return -99;
4286 }
4287
4288 M (WANT_STATS, want_stats);
4289 mp->enable_disable = enable;
4290
4291 S;
4292 W;
4293}
4294
4295static int
4296api_want_interface_events (vat_main_t * vam)
4297{
4298 unformat_input_t *i = vam->input;
4299 vl_api_want_interface_events_t *mp;
4300 f64 timeout;
4301 int enable = -1;
4302
4303 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4304 {
4305 if (unformat (i, "enable"))
4306 enable = 1;
4307 else if (unformat (i, "disable"))
4308 enable = 0;
4309 else
4310 break;
4311 }
4312
4313 if (enable == -1)
4314 {
4315 errmsg ("missing enable|disable\n");
4316 return -99;
4317 }
4318
4319 M (WANT_INTERFACE_EVENTS, want_interface_events);
4320 mp->enable_disable = enable;
4321
4322 vam->interface_event_display = enable;
4323
4324 S;
4325 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004326}
4327
4328
4329/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004330int
4331api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004332{
Dave Barach72d72232016-08-04 10:15:08 -04004333 vl_api_sw_interface_dump_t *mp;
4334 f64 timeout;
4335 hash_pair_t *p;
4336 name_sort_t *nses = 0, *ns;
4337 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004338
Dave Barach72d72232016-08-04 10:15:08 -04004339 /* Toss the old name table */
4340 /* *INDENT-OFF* */
4341 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4342 ({
4343 vec_add2 (nses, ns, 1);
4344 ns->name = (u8 *)(p->key);
4345 ns->value = (u32) p->value[0];
4346 }));
4347 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004348
Dave Barach72d72232016-08-04 10:15:08 -04004349 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004350
Dave Barach72d72232016-08-04 10:15:08 -04004351 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004352
Dave Barach72d72232016-08-04 10:15:08 -04004353 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004354
Dave Barach72d72232016-08-04 10:15:08 -04004355 vec_foreach (sub, vam->sw_if_subif_table)
4356 {
4357 vec_free (sub->interface_name);
4358 }
4359 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004360
Dave Barach72d72232016-08-04 10:15:08 -04004361 /* recreate the interface name hash table */
4362 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004363
Dave Barach72d72232016-08-04 10:15:08 -04004364 /* Get list of ethernets */
4365 M (SW_INTERFACE_DUMP, sw_interface_dump);
4366 mp->name_filter_valid = 1;
4367 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4368 S;
4369
4370 /* and local / loopback interfaces */
4371 M (SW_INTERFACE_DUMP, sw_interface_dump);
4372 mp->name_filter_valid = 1;
4373 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4374 S;
4375
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004376 /* and packet-generator interfaces */
4377 M (SW_INTERFACE_DUMP, sw_interface_dump);
4378 mp->name_filter_valid = 1;
4379 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4380 S;
Dave Barach72d72232016-08-04 10:15:08 -04004381
4382 /* and vxlan-gpe tunnel interfaces */
4383 M (SW_INTERFACE_DUMP, sw_interface_dump);
4384 mp->name_filter_valid = 1;
4385 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4386 sizeof (mp->name_filter) - 1);
4387 S;
4388
4389 /* and vxlan tunnel interfaces */
4390 M (SW_INTERFACE_DUMP, sw_interface_dump);
4391 mp->name_filter_valid = 1;
4392 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4393 S;
4394
4395 /* and host (af_packet) interfaces */
4396 M (SW_INTERFACE_DUMP, sw_interface_dump);
4397 mp->name_filter_valid = 1;
4398 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4399 S;
4400
4401 /* and l2tpv3 tunnel interfaces */
4402 M (SW_INTERFACE_DUMP, sw_interface_dump);
4403 mp->name_filter_valid = 1;
4404 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4405 sizeof (mp->name_filter) - 1);
4406 S;
4407
4408 /* and GRE tunnel interfaces */
4409 M (SW_INTERFACE_DUMP, sw_interface_dump);
4410 mp->name_filter_valid = 1;
4411 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4412 S;
4413
Florin Corasce982752016-09-06 13:36:11 +02004414 /* and LISP-GPE interfaces */
4415 M (SW_INTERFACE_DUMP, sw_interface_dump);
4416 mp->name_filter_valid = 1;
4417 strncpy ((char *) mp->name_filter, "lisp_gpe",
4418 sizeof (mp->name_filter) - 1);
4419 S;
4420
Matus Fabian8fce3e32016-09-06 23:19:43 -07004421 /* and IPSEC tunnel interfaces */
4422 M (SW_INTERFACE_DUMP, sw_interface_dump);
4423 mp->name_filter_valid = 1;
4424 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4425 S;
4426
Dave Barach72d72232016-08-04 10:15:08 -04004427 /* Use a control ping for synchronization */
4428 {
4429 vl_api_control_ping_t *mp;
4430 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004431 S;
Dave Barach72d72232016-08-04 10:15:08 -04004432 }
4433 W;
4434}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004435
Dave Barach72d72232016-08-04 10:15:08 -04004436static int
4437api_sw_interface_set_flags (vat_main_t * vam)
4438{
4439 unformat_input_t *i = vam->input;
4440 vl_api_sw_interface_set_flags_t *mp;
4441 f64 timeout;
4442 u32 sw_if_index;
4443 u8 sw_if_index_set = 0;
4444 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004445
Dave Barach72d72232016-08-04 10:15:08 -04004446 /* Parse args required to build the message */
4447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004448 {
Dave Barach72d72232016-08-04 10:15:08 -04004449 if (unformat (i, "admin-up"))
4450 admin_up = 1;
4451 else if (unformat (i, "admin-down"))
4452 admin_up = 0;
4453 else if (unformat (i, "link-up"))
4454 link_up = 1;
4455 else if (unformat (i, "link-down"))
4456 link_up = 0;
4457 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4458 sw_if_index_set = 1;
4459 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4460 sw_if_index_set = 1;
4461 else
4462 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004463 }
4464
Dave Barach72d72232016-08-04 10:15:08 -04004465 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004466 {
Dave Barach72d72232016-08-04 10:15:08 -04004467 errmsg ("missing interface name or sw_if_index\n");
4468 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004469 }
4470
Dave Barach72d72232016-08-04 10:15:08 -04004471 /* Construct the API message */
4472 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4473 mp->sw_if_index = ntohl (sw_if_index);
4474 mp->admin_up_down = admin_up;
4475 mp->link_up_down = link_up;
4476
4477 /* send it... */
4478 S;
4479
4480 /* Wait for a reply, return the good/bad news... */
4481 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004482}
4483
Dave Barach72d72232016-08-04 10:15:08 -04004484static int
4485api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004486{
Dave Barach72d72232016-08-04 10:15:08 -04004487 unformat_input_t *i = vam->input;
4488 vl_api_sw_interface_clear_stats_t *mp;
4489 f64 timeout;
4490 u32 sw_if_index;
4491 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004492
Dave Barach72d72232016-08-04 10:15:08 -04004493 /* Parse args required to build the message */
4494 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4495 {
4496 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4497 sw_if_index_set = 1;
4498 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4499 sw_if_index_set = 1;
4500 else
4501 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004502 }
4503
Dave Barach72d72232016-08-04 10:15:08 -04004504 /* Construct the API message */
4505 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004506
Dave Barach72d72232016-08-04 10:15:08 -04004507 if (sw_if_index_set == 1)
4508 mp->sw_if_index = ntohl (sw_if_index);
4509 else
4510 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004511
Dave Barach72d72232016-08-04 10:15:08 -04004512 /* send it... */
4513 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004514
Dave Barach72d72232016-08-04 10:15:08 -04004515 /* Wait for a reply, return the good/bad news... */
4516 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004517}
4518
Dave Barach72d72232016-08-04 10:15:08 -04004519static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004520api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4521{
4522 unformat_input_t *i = vam->input;
4523 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4524 f64 timeout;
4525 u32 sw_if_index;
4526 u8 sw_if_index_set = 0;
4527 u32 subport;
4528 u8 subport_set = 0;
4529 u32 pipe;
4530 u8 pipe_set = 0;
4531 u32 profile;
4532 u8 profile_set = 0;
4533
4534 /* Parse args required to build the message */
4535 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4536 {
4537 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4538 sw_if_index_set = 1;
4539 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4540 sw_if_index_set = 1;
4541 else if (unformat (i, "subport %u", &subport))
4542 subport_set = 1;
4543 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4544 sw_if_index_set = 1;
4545 else if (unformat (i, "pipe %u", &pipe))
4546 pipe_set = 1;
4547 else if (unformat (i, "profile %u", &profile))
4548 profile_set = 1;
4549 else
4550 break;
4551 }
4552
4553 if (sw_if_index_set == 0)
4554 {
4555 errmsg ("missing interface name or sw_if_index\n");
4556 return -99;
4557 }
4558
4559 if (subport_set == 0)
4560 {
4561 errmsg ("missing subport \n");
4562 return -99;
4563 }
4564
4565 if (pipe_set == 0)
4566 {
4567 errmsg ("missing pipe\n");
4568 return -99;
4569 }
4570
4571 if (profile_set == 0)
4572 {
4573 errmsg ("missing profile\n");
4574 return -99;
4575 }
4576
4577 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4578
4579 mp->sw_if_index = ntohl (sw_if_index);
4580 mp->subport = ntohl (subport);
4581 mp->pipe = ntohl (pipe);
4582 mp->profile = ntohl (profile);
4583
4584
4585 S;
4586 W;
4587 /* NOTREACHED */
4588 return 0;
4589}
4590
4591static int
4592api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4593{
4594 unformat_input_t *i = vam->input;
4595 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4596 f64 timeout;
4597 u32 sw_if_index;
4598 u8 sw_if_index_set = 0;
4599 u32 subport;
4600 u8 subport_set = 0;
4601 u32 tb_rate = 1250000000; /* 10GbE */
4602 u32 tb_size = 1000000;
4603 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4604 u32 tc_period = 10;
4605
4606 /* Parse args required to build the message */
4607 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4608 {
4609 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4610 sw_if_index_set = 1;
4611 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4612 sw_if_index_set = 1;
4613 else if (unformat (i, "subport %u", &subport))
4614 subport_set = 1;
4615 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4616 sw_if_index_set = 1;
4617 else if (unformat (i, "rate %u", &tb_rate))
4618 {
4619 u32 tc_id;
4620
4621 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4622 tc_id++)
4623 tc_rate[tc_id] = tb_rate;
4624 }
4625 else if (unformat (i, "bktsize %u", &tb_size))
4626 ;
4627 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4628 ;
4629 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4630 ;
4631 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4632 ;
4633 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4634 ;
4635 else if (unformat (i, "period %u", &tc_period))
4636 ;
4637 else
4638 break;
4639 }
4640
4641 if (sw_if_index_set == 0)
4642 {
4643 errmsg ("missing interface name or sw_if_index\n");
4644 return -99;
4645 }
4646
4647 if (subport_set == 0)
4648 {
4649 errmsg ("missing subport \n");
4650 return -99;
4651 }
4652
4653 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4654
4655 mp->sw_if_index = ntohl (sw_if_index);
4656 mp->subport = ntohl (subport);
4657 mp->tb_rate = ntohl (tb_rate);
4658 mp->tb_size = ntohl (tb_size);
4659 mp->tc_rate[0] = ntohl (tc_rate[0]);
4660 mp->tc_rate[1] = ntohl (tc_rate[1]);
4661 mp->tc_rate[2] = ntohl (tc_rate[2]);
4662 mp->tc_rate[3] = ntohl (tc_rate[3]);
4663 mp->tc_period = ntohl (tc_period);
4664
4665 S;
4666 W;
4667 /* NOTREACHED */
4668 return 0;
4669}
4670
4671static int
4672api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4673{
4674 unformat_input_t *i = vam->input;
4675 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4676 f64 timeout;
4677 u32 sw_if_index;
4678 u8 sw_if_index_set = 0;
4679 u8 entry_set = 0;
4680 u8 tc_set = 0;
4681 u8 queue_set = 0;
4682 u32 entry, tc, queue;
4683
4684 /* Parse args required to build the message */
4685 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4686 {
4687 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4688 sw_if_index_set = 1;
4689 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4690 sw_if_index_set = 1;
4691 else if (unformat (i, "entry %d", &entry))
4692 entry_set = 1;
4693 else if (unformat (i, "tc %d", &tc))
4694 tc_set = 1;
4695 else if (unformat (i, "queue %d", &queue))
4696 queue_set = 1;
4697 else
4698 break;
4699 }
4700
4701 if (sw_if_index_set == 0)
4702 {
4703 errmsg ("missing interface name or sw_if_index\n");
4704 return -99;
4705 }
4706
4707 if (entry_set == 0)
4708 {
4709 errmsg ("missing entry \n");
4710 return -99;
4711 }
4712
4713 if (tc_set == 0)
4714 {
4715 errmsg ("missing traffic class \n");
4716 return -99;
4717 }
4718
4719 if (queue_set == 0)
4720 {
4721 errmsg ("missing queue \n");
4722 return -99;
4723 }
4724
4725 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4726
4727 mp->sw_if_index = ntohl (sw_if_index);
4728 mp->entry = ntohl (entry);
4729 mp->tc = ntohl (tc);
4730 mp->queue = ntohl (queue);
4731
4732 S;
4733 W;
4734 /* NOTREACHED */
4735 return 0;
4736}
4737
4738static int
Dave Barach72d72232016-08-04 10:15:08 -04004739api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004740{
Dave Barach72d72232016-08-04 10:15:08 -04004741 unformat_input_t *i = vam->input;
4742 vl_api_sw_interface_add_del_address_t *mp;
4743 f64 timeout;
4744 u32 sw_if_index;
4745 u8 sw_if_index_set = 0;
4746 u8 is_add = 1, del_all = 0;
4747 u32 address_length = 0;
4748 u8 v4_address_set = 0;
4749 u8 v6_address_set = 0;
4750 ip4_address_t v4address;
4751 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004752
Dave Barach72d72232016-08-04 10:15:08 -04004753 /* Parse args required to build the message */
4754 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4755 {
4756 if (unformat (i, "del-all"))
4757 del_all = 1;
4758 else if (unformat (i, "del"))
4759 is_add = 0;
4760 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4761 sw_if_index_set = 1;
4762 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4763 sw_if_index_set = 1;
4764 else if (unformat (i, "%U/%d",
4765 unformat_ip4_address, &v4address, &address_length))
4766 v4_address_set = 1;
4767 else if (unformat (i, "%U/%d",
4768 unformat_ip6_address, &v6address, &address_length))
4769 v6_address_set = 1;
4770 else
4771 break;
4772 }
4773
4774 if (sw_if_index_set == 0)
4775 {
4776 errmsg ("missing interface name or sw_if_index\n");
4777 return -99;
4778 }
4779 if (v4_address_set && v6_address_set)
4780 {
4781 errmsg ("both v4 and v6 addresses set\n");
4782 return -99;
4783 }
4784 if (!v4_address_set && !v6_address_set && !del_all)
4785 {
4786 errmsg ("no addresses set\n");
4787 return -99;
4788 }
4789
4790 /* Construct the API message */
4791 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4792
4793 mp->sw_if_index = ntohl (sw_if_index);
4794 mp->is_add = is_add;
4795 mp->del_all = del_all;
4796 if (v6_address_set)
4797 {
4798 mp->is_ipv6 = 1;
4799 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4800 }
4801 else
4802 {
4803 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4804 }
4805 mp->address_length = address_length;
4806
4807 /* send it... */
4808 S;
4809
4810 /* Wait for a reply, return good/bad news */
4811 W;
4812}
4813
4814static int
4815api_sw_interface_set_table (vat_main_t * vam)
4816{
4817 unformat_input_t *i = vam->input;
4818 vl_api_sw_interface_set_table_t *mp;
4819 f64 timeout;
4820 u32 sw_if_index, vrf_id = 0;
4821 u8 sw_if_index_set = 0;
4822 u8 is_ipv6 = 0;
4823
4824 /* Parse args required to build the message */
4825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4826 {
4827 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4828 sw_if_index_set = 1;
4829 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4830 sw_if_index_set = 1;
4831 else if (unformat (i, "vrf %d", &vrf_id))
4832 ;
4833 else if (unformat (i, "ipv6"))
4834 is_ipv6 = 1;
4835 else
4836 break;
4837 }
4838
4839 if (sw_if_index_set == 0)
4840 {
4841 errmsg ("missing interface name or sw_if_index\n");
4842 return -99;
4843 }
4844
4845 /* Construct the API message */
4846 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4847
4848 mp->sw_if_index = ntohl (sw_if_index);
4849 mp->is_ipv6 = is_ipv6;
4850 mp->vrf_id = ntohl (vrf_id);
4851
4852 /* send it... */
4853 S;
4854
4855 /* Wait for a reply... */
4856 W;
4857}
4858
4859static int
4860api_sw_interface_set_vpath (vat_main_t * vam)
4861{
4862 unformat_input_t *i = vam->input;
4863 vl_api_sw_interface_set_vpath_t *mp;
4864 f64 timeout;
4865 u32 sw_if_index = 0;
4866 u8 sw_if_index_set = 0;
4867 u8 is_enable = 0;
4868
4869 /* Parse args required to build the message */
4870 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4871 {
4872 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4873 sw_if_index_set = 1;
4874 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4875 sw_if_index_set = 1;
4876 else if (unformat (i, "enable"))
4877 is_enable = 1;
4878 else if (unformat (i, "disable"))
4879 is_enable = 0;
4880 else
4881 break;
4882 }
4883
4884 if (sw_if_index_set == 0)
4885 {
4886 errmsg ("missing interface name or sw_if_index\n");
4887 return -99;
4888 }
4889
4890 /* Construct the API message */
4891 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
4892
4893 mp->sw_if_index = ntohl (sw_if_index);
4894 mp->enable = is_enable;
4895
4896 /* send it... */
4897 S;
4898
4899 /* Wait for a reply... */
4900 W;
4901}
4902
4903static int
4904api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4905{
4906 unformat_input_t *i = vam->input;
4907 vl_api_sw_interface_set_l2_xconnect_t *mp;
4908 f64 timeout;
4909 u32 rx_sw_if_index;
4910 u8 rx_sw_if_index_set = 0;
4911 u32 tx_sw_if_index;
4912 u8 tx_sw_if_index_set = 0;
4913 u8 enable = 1;
4914
4915 /* Parse args required to build the message */
4916 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4917 {
4918 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4919 rx_sw_if_index_set = 1;
4920 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4921 tx_sw_if_index_set = 1;
4922 else if (unformat (i, "rx"))
4923 {
4924 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4925 {
4926 if (unformat (i, "%U", unformat_sw_if_index, vam,
4927 &rx_sw_if_index))
4928 rx_sw_if_index_set = 1;
4929 }
4930 else
Dave Barach41da02d2016-07-11 16:48:42 -07004931 break;
Dave Barach41da02d2016-07-11 16:48:42 -07004932 }
Dave Barach72d72232016-08-04 10:15:08 -04004933 else if (unformat (i, "tx"))
4934 {
4935 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4936 {
4937 if (unformat (i, "%U", unformat_sw_if_index, vam,
4938 &tx_sw_if_index))
4939 tx_sw_if_index_set = 1;
4940 }
4941 else
4942 break;
4943 }
4944 else if (unformat (i, "enable"))
4945 enable = 1;
4946 else if (unformat (i, "disable"))
4947 enable = 0;
4948 else
4949 break;
Dave Barach41da02d2016-07-11 16:48:42 -07004950 }
4951
Dave Barach72d72232016-08-04 10:15:08 -04004952 if (rx_sw_if_index_set == 0)
4953 {
4954 errmsg ("missing rx interface name or rx_sw_if_index\n");
4955 return -99;
4956 }
Dave Barach41da02d2016-07-11 16:48:42 -07004957
Dave Barach72d72232016-08-04 10:15:08 -04004958 if (enable && (tx_sw_if_index_set == 0))
4959 {
4960 errmsg ("missing tx interface name or tx_sw_if_index\n");
4961 return -99;
4962 }
Dave Barach41da02d2016-07-11 16:48:42 -07004963
Dave Barach72d72232016-08-04 10:15:08 -04004964 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07004965
Dave Barach72d72232016-08-04 10:15:08 -04004966 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4967 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4968 mp->enable = enable;
4969
4970 S;
4971 W;
4972 /* NOTREACHED */
4973 return 0;
4974}
4975
4976static int
4977api_sw_interface_set_l2_bridge (vat_main_t * vam)
4978{
4979 unformat_input_t *i = vam->input;
4980 vl_api_sw_interface_set_l2_bridge_t *mp;
4981 f64 timeout;
4982 u32 rx_sw_if_index;
4983 u8 rx_sw_if_index_set = 0;
4984 u32 bd_id;
4985 u8 bd_id_set = 0;
4986 u8 bvi = 0;
4987 u32 shg = 0;
4988 u8 enable = 1;
4989
4990 /* Parse args required to build the message */
4991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4992 {
4993 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4994 rx_sw_if_index_set = 1;
4995 else if (unformat (i, "bd_id %d", &bd_id))
4996 bd_id_set = 1;
4997 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
4998 rx_sw_if_index_set = 1;
4999 else if (unformat (i, "shg %d", &shg))
5000 ;
5001 else if (unformat (i, "bvi"))
5002 bvi = 1;
5003 else if (unformat (i, "enable"))
5004 enable = 1;
5005 else if (unformat (i, "disable"))
5006 enable = 0;
5007 else
5008 break;
5009 }
5010
5011 if (rx_sw_if_index_set == 0)
5012 {
5013 errmsg ("missing rx interface name or sw_if_index\n");
5014 return -99;
5015 }
5016
5017 if (enable && (bd_id_set == 0))
5018 {
5019 errmsg ("missing bridge domain\n");
5020 return -99;
5021 }
5022
5023 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5024
5025 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5026 mp->bd_id = ntohl (bd_id);
5027 mp->shg = (u8) shg;
5028 mp->bvi = bvi;
5029 mp->enable = enable;
5030
5031 S;
5032 W;
5033 /* NOTREACHED */
5034 return 0;
5035}
5036
5037static int
5038api_bridge_domain_dump (vat_main_t * vam)
5039{
5040 unformat_input_t *i = vam->input;
5041 vl_api_bridge_domain_dump_t *mp;
5042 f64 timeout;
5043 u32 bd_id = ~0;
5044
5045 /* Parse args required to build the message */
5046 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5047 {
5048 if (unformat (i, "bd_id %d", &bd_id))
5049 ;
5050 else
5051 break;
5052 }
5053
5054 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5055 mp->bd_id = ntohl (bd_id);
5056 S;
5057
5058 /* Use a control ping for synchronization */
5059 {
5060 vl_api_control_ping_t *mp;
5061 M (CONTROL_PING, control_ping);
5062 S;
5063 }
5064
5065 W;
5066 /* NOTREACHED */
5067 return 0;
5068}
5069
5070static int
5071api_bridge_domain_add_del (vat_main_t * vam)
5072{
5073 unformat_input_t *i = vam->input;
5074 vl_api_bridge_domain_add_del_t *mp;
5075 f64 timeout;
5076 u32 bd_id = ~0;
5077 u8 is_add = 1;
5078 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5079
5080 /* Parse args required to build the message */
5081 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5082 {
5083 if (unformat (i, "bd_id %d", &bd_id))
5084 ;
5085 else if (unformat (i, "flood %d", &flood))
5086 ;
5087 else if (unformat (i, "uu-flood %d", &uu_flood))
5088 ;
5089 else if (unformat (i, "forward %d", &forward))
5090 ;
5091 else if (unformat (i, "learn %d", &learn))
5092 ;
5093 else if (unformat (i, "arp-term %d", &arp_term))
5094 ;
5095 else if (unformat (i, "del"))
5096 {
5097 is_add = 0;
5098 flood = uu_flood = forward = learn = 0;
5099 }
5100 else
5101 break;
5102 }
5103
5104 if (bd_id == ~0)
5105 {
5106 errmsg ("missing bridge domain\n");
5107 return -99;
5108 }
5109
5110 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5111
5112 mp->bd_id = ntohl (bd_id);
5113 mp->flood = flood;
5114 mp->uu_flood = uu_flood;
5115 mp->forward = forward;
5116 mp->learn = learn;
5117 mp->arp_term = arp_term;
5118 mp->is_add = is_add;
5119
5120 S;
5121 W;
5122 /* NOTREACHED */
5123 return 0;
5124}
5125
5126static int
5127api_l2fib_add_del (vat_main_t * vam)
5128{
5129 unformat_input_t *i = vam->input;
5130 vl_api_l2fib_add_del_t *mp;
5131 f64 timeout;
5132 u64 mac = 0;
5133 u8 mac_set = 0;
5134 u32 bd_id;
5135 u8 bd_id_set = 0;
5136 u32 sw_if_index;
5137 u8 sw_if_index_set = 0;
5138 u8 is_add = 1;
5139 u8 static_mac = 0;
5140 u8 filter_mac = 0;
5141 u8 bvi_mac = 0;
5142 int count = 1;
5143 f64 before = 0;
5144 int j;
5145
5146 /* Parse args required to build the message */
5147 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5148 {
5149 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5150 mac_set = 1;
5151 else if (unformat (i, "bd_id %d", &bd_id))
5152 bd_id_set = 1;
5153 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5154 sw_if_index_set = 1;
5155 else if (unformat (i, "sw_if"))
5156 {
5157 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5158 {
5159 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5160 sw_if_index_set = 1;
5161 }
5162 else
5163 break;
5164 }
5165 else if (unformat (i, "static"))
5166 static_mac = 1;
5167 else if (unformat (i, "filter"))
5168 {
5169 filter_mac = 1;
5170 static_mac = 1;
5171 }
5172 else if (unformat (i, "bvi"))
5173 {
5174 bvi_mac = 1;
5175 static_mac = 1;
5176 }
5177 else if (unformat (i, "del"))
5178 is_add = 0;
5179 else if (unformat (i, "count %d", &count))
5180 ;
5181 else
5182 break;
5183 }
5184
5185 if (mac_set == 0)
5186 {
5187 errmsg ("missing mac address\n");
5188 return -99;
5189 }
5190
5191 if (bd_id_set == 0)
5192 {
5193 errmsg ("missing bridge domain\n");
5194 return -99;
5195 }
5196
5197 if (is_add && (sw_if_index_set == 0))
5198 {
5199 errmsg ("missing interface name or sw_if_index\n");
5200 return -99;
5201 }
5202
5203 if (count > 1)
5204 {
5205 /* Turn on async mode */
5206 vam->async_mode = 1;
5207 vam->async_errors = 0;
5208 before = vat_time_now (vam);
5209 }
5210
5211 for (j = 0; j < count; j++)
5212 {
5213 M (L2FIB_ADD_DEL, l2fib_add_del);
5214
5215 mp->mac = mac;
5216 mp->bd_id = ntohl (bd_id);
5217 mp->is_add = is_add;
5218
5219 if (is_add)
5220 {
5221 mp->sw_if_index = ntohl (sw_if_index);
5222 mp->static_mac = static_mac;
5223 mp->filter_mac = filter_mac;
5224 mp->bvi_mac = bvi_mac;
5225 }
5226 increment_mac_address (&mac);
5227 /* send it... */
5228 S;
5229 }
5230
5231 if (count > 1)
5232 {
5233 vl_api_control_ping_t *mp;
5234 f64 after;
5235
5236 /* Shut off async mode */
5237 vam->async_mode = 0;
5238
5239 M (CONTROL_PING, control_ping);
5240 S;
5241
5242 timeout = vat_time_now (vam) + 1.0;
5243 while (vat_time_now (vam) < timeout)
5244 if (vam->result_ready == 1)
5245 goto out;
5246 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005247
5248 out:
Dave Barach72d72232016-08-04 10:15:08 -04005249 if (vam->retval == -99)
5250 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005251
Dave Barach72d72232016-08-04 10:15:08 -04005252 if (vam->async_errors > 0)
5253 {
5254 errmsg ("%d asynchronous errors\n", vam->async_errors);
5255 vam->retval = -98;
5256 }
5257 vam->async_errors = 0;
5258 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005259
Dave Barach72d72232016-08-04 10:15:08 -04005260 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5261 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005262 }
Dave Barach72d72232016-08-04 10:15:08 -04005263 else
5264 {
5265 /* Wait for a reply... */
5266 W;
5267 }
5268 /* Return the good/bad news */
5269 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005270}
5271
Dave Barach72d72232016-08-04 10:15:08 -04005272static int
5273api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005274{
Dave Barach72d72232016-08-04 10:15:08 -04005275 unformat_input_t *i = vam->input;
5276 vl_api_l2_flags_t *mp;
5277 f64 timeout;
5278 u32 sw_if_index;
5279 u32 feature_bitmap = 0;
5280 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005281
Dave Barach72d72232016-08-04 10:15:08 -04005282 /* Parse args required to build the message */
5283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5284 {
5285 if (unformat (i, "sw_if_index %d", &sw_if_index))
5286 sw_if_index_set = 1;
5287 else if (unformat (i, "sw_if"))
5288 {
5289 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5290 {
5291 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5292 sw_if_index_set = 1;
5293 }
5294 else
5295 break;
5296 }
5297 else if (unformat (i, "learn"))
5298 feature_bitmap |= L2INPUT_FEAT_LEARN;
5299 else if (unformat (i, "forward"))
5300 feature_bitmap |= L2INPUT_FEAT_FWD;
5301 else if (unformat (i, "flood"))
5302 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5303 else if (unformat (i, "uu-flood"))
5304 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5305 else
5306 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005307 }
5308
Dave Barach72d72232016-08-04 10:15:08 -04005309 if (sw_if_index_set == 0)
5310 {
5311 errmsg ("missing interface name or sw_if_index\n");
5312 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005313 }
5314
Dave Barach72d72232016-08-04 10:15:08 -04005315 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005316
Dave Barach72d72232016-08-04 10:15:08 -04005317 mp->sw_if_index = ntohl (sw_if_index);
5318 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005319
Dave Barach72d72232016-08-04 10:15:08 -04005320 S;
5321 W;
5322 /* NOTREACHED */
5323 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005324}
5325
Dave Barach72d72232016-08-04 10:15:08 -04005326static int
5327api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005328{
Dave Barach72d72232016-08-04 10:15:08 -04005329 unformat_input_t *i = vam->input;
5330 vl_api_bridge_flags_t *mp;
5331 f64 timeout;
5332 u32 bd_id;
5333 u8 bd_id_set = 0;
5334 u8 is_set = 1;
5335 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005336
Dave Barach72d72232016-08-04 10:15:08 -04005337 /* Parse args required to build the message */
5338 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5339 {
5340 if (unformat (i, "bd_id %d", &bd_id))
5341 bd_id_set = 1;
5342 else if (unformat (i, "learn"))
5343 flags |= L2_LEARN;
5344 else if (unformat (i, "forward"))
5345 flags |= L2_FWD;
5346 else if (unformat (i, "flood"))
5347 flags |= L2_FLOOD;
5348 else if (unformat (i, "uu-flood"))
5349 flags |= L2_UU_FLOOD;
5350 else if (unformat (i, "arp-term"))
5351 flags |= L2_ARP_TERM;
5352 else if (unformat (i, "off"))
5353 is_set = 0;
5354 else if (unformat (i, "disable"))
5355 is_set = 0;
5356 else
5357 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005358 }
5359
Dave Barach72d72232016-08-04 10:15:08 -04005360 if (bd_id_set == 0)
5361 {
5362 errmsg ("missing bridge domain\n");
5363 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005364 }
5365
Dave Barach72d72232016-08-04 10:15:08 -04005366 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005367
Dave Barach72d72232016-08-04 10:15:08 -04005368 mp->bd_id = ntohl (bd_id);
5369 mp->feature_bitmap = ntohl (flags);
5370 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005371
Dave Barach72d72232016-08-04 10:15:08 -04005372 S;
5373 W;
5374 /* NOTREACHED */
5375 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005376}
5377
Dave Barach72d72232016-08-04 10:15:08 -04005378static int
5379api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005380{
Dave Barach72d72232016-08-04 10:15:08 -04005381 unformat_input_t *i = vam->input;
5382 vl_api_bd_ip_mac_add_del_t *mp;
5383 f64 timeout;
5384 u32 bd_id;
5385 u8 is_ipv6 = 0;
5386 u8 is_add = 1;
5387 u8 bd_id_set = 0;
5388 u8 ip_set = 0;
5389 u8 mac_set = 0;
5390 ip4_address_t v4addr;
5391 ip6_address_t v6addr;
5392 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005393
Ed Warnickecb9cada2015-12-08 15:45:58 -07005394
Dave Barach72d72232016-08-04 10:15:08 -04005395 /* Parse args required to build the message */
5396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5397 {
5398 if (unformat (i, "bd_id %d", &bd_id))
5399 {
5400 bd_id_set++;
5401 }
5402 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5403 {
5404 ip_set++;
5405 }
5406 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5407 {
5408 ip_set++;
5409 is_ipv6++;
5410 }
5411 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5412 {
5413 mac_set++;
5414 }
5415 else if (unformat (i, "del"))
5416 is_add = 0;
5417 else
5418 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005419 }
5420
Dave Barach72d72232016-08-04 10:15:08 -04005421 if (bd_id_set == 0)
5422 {
5423 errmsg ("missing bridge domain\n");
5424 return -99;
5425 }
5426 else if (ip_set == 0)
5427 {
5428 errmsg ("missing IP address\n");
5429 return -99;
5430 }
5431 else if (mac_set == 0)
5432 {
5433 errmsg ("missing MAC address\n");
5434 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005435 }
5436
Dave Barach72d72232016-08-04 10:15:08 -04005437 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005438
Dave Barach72d72232016-08-04 10:15:08 -04005439 mp->bd_id = ntohl (bd_id);
5440 mp->is_ipv6 = is_ipv6;
5441 mp->is_add = is_add;
5442 if (is_ipv6)
5443 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5444 else
5445 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5446 clib_memcpy (mp->mac_address, macaddr, 6);
5447 S;
5448 W;
5449 /* NOTREACHED */
5450 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005451}
5452
Dave Barach72d72232016-08-04 10:15:08 -04005453static int
5454api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005455{
Dave Barach72d72232016-08-04 10:15:08 -04005456 unformat_input_t *i = vam->input;
5457 vl_api_tap_connect_t *mp;
5458 f64 timeout;
5459 u8 mac_address[6];
5460 u8 random_mac = 1;
5461 u8 name_set = 0;
5462 u8 *tap_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005463
Dave Barach72d72232016-08-04 10:15:08 -04005464 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005465
Dave Barach72d72232016-08-04 10:15:08 -04005466 /* Parse args required to build the message */
5467 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5468 {
5469 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5470 {
5471 random_mac = 0;
5472 }
5473 else if (unformat (i, "random-mac"))
5474 random_mac = 1;
5475 else if (unformat (i, "tapname %s", &tap_name))
5476 name_set = 1;
5477 else
5478 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005479 }
5480
Dave Barach72d72232016-08-04 10:15:08 -04005481 if (name_set == 0)
5482 {
5483 errmsg ("missing tap name\n");
5484 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005485 }
Dave Barach72d72232016-08-04 10:15:08 -04005486 if (vec_len (tap_name) > 63)
5487 {
5488 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005489 }
Dave Barach72d72232016-08-04 10:15:08 -04005490 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005491
Dave Barach72d72232016-08-04 10:15:08 -04005492 /* Construct the API message */
5493 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005494
Dave Barach72d72232016-08-04 10:15:08 -04005495 mp->use_random_mac = random_mac;
5496 clib_memcpy (mp->mac_address, mac_address, 6);
5497 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5498 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005499
Dave Barach72d72232016-08-04 10:15:08 -04005500 /* send it... */
5501 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005502
Dave Barach72d72232016-08-04 10:15:08 -04005503 /* Wait for a reply... */
5504 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005505}
5506
Dave Barach72d72232016-08-04 10:15:08 -04005507static int
5508api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005509{
Dave Barach72d72232016-08-04 10:15:08 -04005510 unformat_input_t *i = vam->input;
5511 vl_api_tap_modify_t *mp;
5512 f64 timeout;
5513 u8 mac_address[6];
5514 u8 random_mac = 1;
5515 u8 name_set = 0;
5516 u8 *tap_name;
5517 u32 sw_if_index = ~0;
5518 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005519
Dave Barach72d72232016-08-04 10:15:08 -04005520 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005521
Dave Barach72d72232016-08-04 10:15:08 -04005522 /* Parse args required to build the message */
5523 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5524 {
5525 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5526 sw_if_index_set = 1;
5527 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5528 sw_if_index_set = 1;
5529 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5530 {
5531 random_mac = 0;
5532 }
5533 else if (unformat (i, "random-mac"))
5534 random_mac = 1;
5535 else if (unformat (i, "tapname %s", &tap_name))
5536 name_set = 1;
5537 else
5538 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005539 }
5540
Dave Barach72d72232016-08-04 10:15:08 -04005541 if (sw_if_index_set == 0)
5542 {
5543 errmsg ("missing vpp interface name");
5544 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005545 }
Dave Barach72d72232016-08-04 10:15:08 -04005546 if (name_set == 0)
5547 {
5548 errmsg ("missing tap name\n");
5549 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005550 }
Dave Barach72d72232016-08-04 10:15:08 -04005551 if (vec_len (tap_name) > 63)
5552 {
5553 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005554 }
Dave Barach72d72232016-08-04 10:15:08 -04005555 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005556
Dave Barach72d72232016-08-04 10:15:08 -04005557 /* Construct the API message */
5558 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005559
Dave Barach72d72232016-08-04 10:15:08 -04005560 mp->use_random_mac = random_mac;
5561 mp->sw_if_index = ntohl (sw_if_index);
5562 clib_memcpy (mp->mac_address, mac_address, 6);
5563 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5564 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005565
Dave Barach72d72232016-08-04 10:15:08 -04005566 /* send it... */
5567 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005568
Dave Barach72d72232016-08-04 10:15:08 -04005569 /* Wait for a reply... */
5570 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005571}
5572
Dave Barach72d72232016-08-04 10:15:08 -04005573static int
5574api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005575{
Dave Barach72d72232016-08-04 10:15:08 -04005576 unformat_input_t *i = vam->input;
5577 vl_api_tap_delete_t *mp;
5578 f64 timeout;
5579 u32 sw_if_index = ~0;
5580 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005581
Dave Barach72d72232016-08-04 10:15:08 -04005582 /* Parse args required to build the message */
5583 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5584 {
5585 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5586 sw_if_index_set = 1;
5587 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5588 sw_if_index_set = 1;
5589 else
5590 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005591 }
5592
Dave Barach72d72232016-08-04 10:15:08 -04005593 if (sw_if_index_set == 0)
5594 {
5595 errmsg ("missing vpp interface name");
5596 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005597 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005598
Dave Barach72d72232016-08-04 10:15:08 -04005599 /* Construct the API message */
5600 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005601
Dave Barach72d72232016-08-04 10:15:08 -04005602 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005603
Dave Barach72d72232016-08-04 10:15:08 -04005604 /* send it... */
5605 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005606
Dave Barach72d72232016-08-04 10:15:08 -04005607 /* Wait for a reply... */
5608 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005609}
5610
Dave Barach72d72232016-08-04 10:15:08 -04005611static int
5612api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005613{
Dave Barach72d72232016-08-04 10:15:08 -04005614 unformat_input_t *i = vam->input;
5615 vl_api_ip_add_del_route_t *mp;
5616 f64 timeout;
5617 u32 sw_if_index = ~0, vrf_id = 0;
5618 u8 sw_if_index_set = 0;
5619 u8 is_ipv6 = 0;
5620 u8 is_local = 0, is_drop = 0;
5621 u8 create_vrf_if_needed = 0;
5622 u8 is_add = 1;
5623 u8 next_hop_weight = 1;
5624 u8 not_last = 0;
5625 u8 is_multipath = 0;
5626 u8 address_set = 0;
5627 u8 address_length_set = 0;
5628 u32 lookup_in_vrf = 0;
5629 u32 resolve_attempts = 0;
5630 u32 dst_address_length = 0;
5631 u8 next_hop_set = 0;
5632 ip4_address_t v4_dst_address, v4_next_hop_address;
5633 ip6_address_t v6_dst_address, v6_next_hop_address;
5634 int count = 1;
5635 int j;
5636 f64 before = 0;
5637 u32 random_add_del = 0;
5638 u32 *random_vector = 0;
5639 uword *random_hash;
5640 u32 random_seed = 0xdeaddabe;
5641 u32 classify_table_index = ~0;
5642 u8 is_classify = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005643 u8 resolve_host, resolve_attached;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005644
Dave Barach72d72232016-08-04 10:15:08 -04005645 /* Parse args required to build the message */
5646 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5647 {
5648 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5649 sw_if_index_set = 1;
5650 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5651 sw_if_index_set = 1;
5652 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
5653 {
5654 address_set = 1;
5655 is_ipv6 = 0;
5656 }
5657 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
5658 {
5659 address_set = 1;
5660 is_ipv6 = 1;
5661 }
5662 else if (unformat (i, "/%d", &dst_address_length))
5663 {
5664 address_length_set = 1;
5665 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005666
Dave Barach72d72232016-08-04 10:15:08 -04005667 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
5668 &v4_next_hop_address))
5669 {
5670 next_hop_set = 1;
5671 }
5672 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
5673 &v6_next_hop_address))
5674 {
5675 next_hop_set = 1;
5676 }
5677 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5678 ;
5679 else if (unformat (i, "weight %d", &next_hop_weight))
5680 ;
5681 else if (unformat (i, "drop"))
5682 {
5683 is_drop = 1;
5684 }
5685 else if (unformat (i, "local"))
5686 {
5687 is_local = 1;
5688 }
5689 else if (unformat (i, "classify %d", &classify_table_index))
5690 {
5691 is_classify = 1;
5692 }
5693 else if (unformat (i, "del"))
5694 is_add = 0;
5695 else if (unformat (i, "add"))
5696 is_add = 1;
5697 else if (unformat (i, "not-last"))
5698 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005699 else if (unformat (i, "resolve-via-host"))
5700 resolve_host = 1;
5701 else if (unformat (i, "resolve-via-attached"))
5702 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005703 else if (unformat (i, "multipath"))
5704 is_multipath = 1;
5705 else if (unformat (i, "vrf %d", &vrf_id))
5706 ;
5707 else if (unformat (i, "create-vrf"))
5708 create_vrf_if_needed = 1;
5709 else if (unformat (i, "count %d", &count))
5710 ;
5711 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
5712 ;
5713 else if (unformat (i, "random"))
5714 random_add_del = 1;
5715 else if (unformat (i, "seed %d", &random_seed))
5716 ;
5717 else
5718 {
5719 clib_warning ("parse error '%U'", format_unformat_error, i);
5720 return -99;
5721 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005722 }
5723
Dave Barach72d72232016-08-04 10:15:08 -04005724 if (resolve_attempts > 0 && sw_if_index_set == 0)
5725 {
5726 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
5727 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005728 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005729
Dave Barach72d72232016-08-04 10:15:08 -04005730 if (!next_hop_set && !is_drop && !is_local && !is_classify)
5731 {
5732 errmsg ("next hop / local / drop / classify not set\n");
5733 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005734 }
5735
Dave Barach72d72232016-08-04 10:15:08 -04005736 if (address_set == 0)
5737 {
5738 errmsg ("missing addresses\n");
5739 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005740 }
5741
Dave Barach72d72232016-08-04 10:15:08 -04005742 if (address_length_set == 0)
5743 {
5744 errmsg ("missing address length\n");
5745 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005746 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005747
Dave Barach72d72232016-08-04 10:15:08 -04005748 /* Generate a pile of unique, random routes */
5749 if (random_add_del)
5750 {
5751 u32 this_random_address;
5752 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005753
Dave Barach72d72232016-08-04 10:15:08 -04005754 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
5755 for (j = 0; j <= count; j++)
5756 {
5757 do
5758 {
5759 this_random_address = random_u32 (&random_seed);
5760 this_random_address =
5761 clib_host_to_net_u32 (this_random_address);
5762 }
5763 while (hash_get (random_hash, this_random_address));
5764 vec_add1 (random_vector, this_random_address);
5765 hash_set (random_hash, this_random_address, 1);
5766 }
5767 hash_free (random_hash);
5768 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07005769 }
5770
Dave Barach72d72232016-08-04 10:15:08 -04005771 if (count > 1)
5772 {
5773 /* Turn on async mode */
5774 vam->async_mode = 1;
5775 vam->async_errors = 0;
5776 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005777 }
5778
Dave Barach72d72232016-08-04 10:15:08 -04005779 for (j = 0; j < count; j++)
5780 {
5781 /* Construct the API message */
5782 M (IP_ADD_DEL_ROUTE, ip_add_del_route);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005783
Dave Barach72d72232016-08-04 10:15:08 -04005784 mp->next_hop_sw_if_index = ntohl (sw_if_index);
5785 mp->vrf_id = ntohl (vrf_id);
5786 if (resolve_attempts > 0)
5787 {
5788 mp->resolve_attempts = ntohl (resolve_attempts);
5789 mp->resolve_if_needed = 1;
5790 }
5791 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005792
Dave Barach72d72232016-08-04 10:15:08 -04005793 mp->is_add = is_add;
5794 mp->is_drop = is_drop;
5795 mp->is_ipv6 = is_ipv6;
5796 mp->is_local = is_local;
5797 mp->is_classify = is_classify;
5798 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005799 mp->is_resolve_host = resolve_host;
5800 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04005801 mp->not_last = not_last;
5802 mp->next_hop_weight = next_hop_weight;
5803 mp->dst_address_length = dst_address_length;
5804 mp->lookup_in_vrf = ntohl (lookup_in_vrf);
5805 mp->classify_table_index = ntohl (classify_table_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005806
Dave Barach72d72232016-08-04 10:15:08 -04005807 if (is_ipv6)
5808 {
5809 clib_memcpy (mp->dst_address, &v6_dst_address,
5810 sizeof (v6_dst_address));
5811 if (next_hop_set)
5812 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
5813 sizeof (v6_next_hop_address));
5814 increment_v6_address (&v6_dst_address);
5815 }
5816 else
5817 {
5818 clib_memcpy (mp->dst_address, &v4_dst_address,
5819 sizeof (v4_dst_address));
5820 if (next_hop_set)
5821 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
5822 sizeof (v4_next_hop_address));
5823 if (random_add_del)
5824 v4_dst_address.as_u32 = random_vector[j + 1];
5825 else
5826 increment_v4_address (&v4_dst_address);
5827 }
5828 /* send it... */
5829 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005830 }
5831
Dave Barach72d72232016-08-04 10:15:08 -04005832 /* When testing multiple add/del ops, use a control-ping to sync */
5833 if (count > 1)
5834 {
5835 vl_api_control_ping_t *mp;
5836 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005837
Dave Barach72d72232016-08-04 10:15:08 -04005838 /* Shut off async mode */
5839 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005840
Dave Barach72d72232016-08-04 10:15:08 -04005841 M (CONTROL_PING, control_ping);
5842 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005843
Dave Barach72d72232016-08-04 10:15:08 -04005844 timeout = vat_time_now (vam) + 1.0;
5845 while (vat_time_now (vam) < timeout)
5846 if (vam->result_ready == 1)
5847 goto out;
5848 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005849
5850 out:
Dave Barach72d72232016-08-04 10:15:08 -04005851 if (vam->retval == -99)
5852 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005853
Dave Barach72d72232016-08-04 10:15:08 -04005854 if (vam->async_errors > 0)
5855 {
5856 errmsg ("%d asynchronous errors\n", vam->async_errors);
5857 vam->retval = -98;
5858 }
5859 vam->async_errors = 0;
5860 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005861
Dave Barach72d72232016-08-04 10:15:08 -04005862 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5863 count, after - before, count / (after - before));
5864 }
5865 else
5866 {
5867 /* Wait for a reply... */
5868 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005869 }
5870
Dave Barach72d72232016-08-04 10:15:08 -04005871 /* Return the good/bad news */
5872 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005873}
5874
Dave Barach72d72232016-08-04 10:15:08 -04005875static int
5876api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005877{
Dave Barach72d72232016-08-04 10:15:08 -04005878 unformat_input_t *i = vam->input;
5879 vl_api_proxy_arp_add_del_t *mp;
5880 f64 timeout;
5881 u32 vrf_id = 0;
5882 u8 is_add = 1;
5883 ip4_address_t lo, hi;
5884 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005885
Dave Barach72d72232016-08-04 10:15:08 -04005886 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5887 {
5888 if (unformat (i, "vrf %d", &vrf_id))
5889 ;
5890 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
5891 unformat_ip4_address, &hi))
5892 range_set = 1;
5893 else if (unformat (i, "del"))
5894 is_add = 0;
5895 else
5896 {
5897 clib_warning ("parse error '%U'", format_unformat_error, i);
5898 return -99;
5899 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005900 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005901
Dave Barach72d72232016-08-04 10:15:08 -04005902 if (range_set == 0)
5903 {
5904 errmsg ("address range not set\n");
5905 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005906 }
5907
Dave Barach72d72232016-08-04 10:15:08 -04005908 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005909
Dave Barach72d72232016-08-04 10:15:08 -04005910 mp->vrf_id = ntohl (vrf_id);
5911 mp->is_add = is_add;
5912 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
5913 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005914
Dave Barach72d72232016-08-04 10:15:08 -04005915 S;
5916 W;
5917 /* NOTREACHED */
5918 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005919}
5920
Dave Barach72d72232016-08-04 10:15:08 -04005921static int
5922api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005923{
Dave Barach72d72232016-08-04 10:15:08 -04005924 unformat_input_t *i = vam->input;
5925 vl_api_proxy_arp_intfc_enable_disable_t *mp;
5926 f64 timeout;
5927 u32 sw_if_index;
5928 u8 enable = 1;
5929 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005930
Dave Barach72d72232016-08-04 10:15:08 -04005931 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5932 {
5933 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5934 sw_if_index_set = 1;
5935 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5936 sw_if_index_set = 1;
5937 else if (unformat (i, "enable"))
5938 enable = 1;
5939 else if (unformat (i, "disable"))
5940 enable = 0;
5941 else
5942 {
5943 clib_warning ("parse error '%U'", format_unformat_error, i);
5944 return -99;
5945 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005946 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005947
Dave Barach72d72232016-08-04 10:15:08 -04005948 if (sw_if_index_set == 0)
5949 {
5950 errmsg ("missing interface name or sw_if_index\n");
5951 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005952 }
5953
Dave Barach72d72232016-08-04 10:15:08 -04005954 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005955
Dave Barach72d72232016-08-04 10:15:08 -04005956 mp->sw_if_index = ntohl (sw_if_index);
5957 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005958
Dave Barach72d72232016-08-04 10:15:08 -04005959 S;
5960 W;
5961 /* NOTREACHED */
5962 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005963}
5964
Dave Barach72d72232016-08-04 10:15:08 -04005965static int
5966api_mpls_add_del_decap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005967{
Dave Barach72d72232016-08-04 10:15:08 -04005968 unformat_input_t *i = vam->input;
5969 vl_api_mpls_add_del_decap_t *mp;
5970 f64 timeout;
5971 u32 rx_vrf_id = 0;
5972 u32 tx_vrf_id = 0;
5973 u32 label = 0;
5974 u8 is_add = 1;
5975 u8 s_bit = 1;
5976 u32 next_index = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005977
Dave Barach72d72232016-08-04 10:15:08 -04005978 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5979 {
5980 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5981 ;
5982 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
5983 ;
5984 else if (unformat (i, "label %d", &label))
5985 ;
5986 else if (unformat (i, "next-index %d", &next_index))
5987 ;
5988 else if (unformat (i, "del"))
5989 is_add = 0;
5990 else if (unformat (i, "s-bit-clear"))
5991 s_bit = 0;
5992 else
5993 {
5994 clib_warning ("parse error '%U'", format_unformat_error, i);
5995 return -99;
5996 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005997 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005998
Dave Barach72d72232016-08-04 10:15:08 -04005999 M (MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006000
Dave Barach72d72232016-08-04 10:15:08 -04006001 mp->rx_vrf_id = ntohl (rx_vrf_id);
6002 mp->tx_vrf_id = ntohl (tx_vrf_id);
6003 mp->label = ntohl (label);
6004 mp->next_index = ntohl (next_index);
6005 mp->s_bit = s_bit;
6006 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006007
Dave Barach72d72232016-08-04 10:15:08 -04006008 S;
6009 W;
6010 /* NOTREACHED */
6011 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006012}
6013
Dave Barach72d72232016-08-04 10:15:08 -04006014static int
6015api_mpls_add_del_encap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006016{
Dave Barach72d72232016-08-04 10:15:08 -04006017 unformat_input_t *i = vam->input;
6018 vl_api_mpls_add_del_encap_t *mp;
6019 f64 timeout;
6020 u32 vrf_id = 0;
6021 u32 *labels = 0;
6022 u32 label;
6023 ip4_address_t dst_address;
6024 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006025
Dave Barach72d72232016-08-04 10:15:08 -04006026 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6027 {
6028 if (unformat (i, "vrf %d", &vrf_id))
6029 ;
6030 else if (unformat (i, "label %d", &label))
6031 vec_add1 (labels, ntohl (label));
6032 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6033 ;
6034 else if (unformat (i, "del"))
6035 is_add = 0;
6036 else
6037 {
6038 clib_warning ("parse error '%U'", format_unformat_error, i);
6039 return -99;
6040 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006041 }
6042
Dave Barach72d72232016-08-04 10:15:08 -04006043 if (vec_len (labels) == 0)
6044 {
6045 errmsg ("missing encap label stack\n");
6046 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006047 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006048
Dave Barach72d72232016-08-04 10:15:08 -04006049 M2 (MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
6050 sizeof (u32) * vec_len (labels));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006051
Dave Barach72d72232016-08-04 10:15:08 -04006052 mp->vrf_id = ntohl (vrf_id);
6053 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6054 mp->is_add = is_add;
6055 mp->nlabels = vec_len (labels);
6056 clib_memcpy (mp->labels, labels, sizeof (u32) * mp->nlabels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006057
Dave Barach72d72232016-08-04 10:15:08 -04006058 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006059
Dave Barach72d72232016-08-04 10:15:08 -04006060 S;
6061 W;
6062 /* NOTREACHED */
6063 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006064}
6065
Dave Barach72d72232016-08-04 10:15:08 -04006066static int
6067api_mpls_gre_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006068{
Dave Barach72d72232016-08-04 10:15:08 -04006069 unformat_input_t *i = vam->input;
6070 vl_api_mpls_gre_add_del_tunnel_t *mp;
6071 f64 timeout;
6072 u32 inner_vrf_id = 0;
6073 u32 outer_vrf_id = 0;
6074 ip4_address_t src_address;
6075 ip4_address_t dst_address;
6076 ip4_address_t intfc_address;
6077 u32 tmp;
6078 u8 intfc_address_length = 0;
6079 u8 is_add = 1;
6080 u8 l2_only = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006081
Dave Barach72d72232016-08-04 10:15:08 -04006082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6083 {
6084 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6085 ;
6086 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6087 ;
6088 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
6089 ;
6090 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6091 ;
6092 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6093 &intfc_address, &tmp))
6094 intfc_address_length = tmp;
6095 else if (unformat (i, "l2-only"))
6096 l2_only = 1;
6097 else if (unformat (i, "del"))
6098 is_add = 0;
6099 else
6100 {
6101 clib_warning ("parse error '%U'", format_unformat_error, i);
6102 return -99;
6103 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006104 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006105
Dave Barach72d72232016-08-04 10:15:08 -04006106 M (MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006107
Dave Barach72d72232016-08-04 10:15:08 -04006108 mp->inner_vrf_id = ntohl (inner_vrf_id);
6109 mp->outer_vrf_id = ntohl (outer_vrf_id);
6110 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
6111 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6112 clib_memcpy (mp->intfc_address, &intfc_address, sizeof (intfc_address));
6113 mp->intfc_address_length = intfc_address_length;
6114 mp->l2_only = l2_only;
6115 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006116
Dave Barach72d72232016-08-04 10:15:08 -04006117 S;
6118 W;
6119 /* NOTREACHED */
6120 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006121}
6122
Dave Barach72d72232016-08-04 10:15:08 -04006123static int
6124api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006125{
Dave Barach72d72232016-08-04 10:15:08 -04006126 unformat_input_t *i = vam->input;
6127 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
6128 f64 timeout;
6129 u32 inner_vrf_id = 0;
6130 ip4_address_t intfc_address;
6131 u8 dst_mac_address[6];
6132 int dst_set = 1;
6133 u32 tmp;
6134 u8 intfc_address_length = 0;
6135 u8 is_add = 1;
6136 u8 l2_only = 0;
6137 u32 tx_sw_if_index;
6138 int tx_sw_if_index_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006139
Dave Barach72d72232016-08-04 10:15:08 -04006140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6141 {
6142 if (unformat (i, "vrf %d", &inner_vrf_id))
6143 ;
6144 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6145 &intfc_address, &tmp))
6146 intfc_address_length = tmp;
6147 else if (unformat (i, "%U", unformat_sw_if_index, vam, &tx_sw_if_index))
6148 tx_sw_if_index_set = 1;
6149 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6150 tx_sw_if_index_set = 1;
6151 else if (unformat (i, "dst %U", unformat_ethernet_address,
6152 dst_mac_address))
6153 dst_set = 1;
6154 else if (unformat (i, "l2-only"))
6155 l2_only = 1;
6156 else if (unformat (i, "del"))
6157 is_add = 0;
6158 else
6159 {
6160 clib_warning ("parse error '%U'", format_unformat_error, i);
6161 return -99;
6162 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006163 }
6164
Dave Barach72d72232016-08-04 10:15:08 -04006165 if (!dst_set)
6166 {
6167 errmsg ("dst (mac address) not set\n");
6168 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006169 }
Dave Barach72d72232016-08-04 10:15:08 -04006170 if (!tx_sw_if_index_set)
6171 {
6172 errmsg ("tx-intfc not set\n");
6173 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006174 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006175
Dave Barach72d72232016-08-04 10:15:08 -04006176 M (MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006177
Dave Barach72d72232016-08-04 10:15:08 -04006178 mp->vrf_id = ntohl (inner_vrf_id);
6179 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
6180 mp->adj_address_length = intfc_address_length;
6181 clib_memcpy (mp->dst_mac_address, dst_mac_address,
6182 sizeof (dst_mac_address));
6183 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6184 mp->l2_only = l2_only;
6185 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006186
Dave Barach72d72232016-08-04 10:15:08 -04006187 S;
6188 W;
6189 /* NOTREACHED */
6190 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006191}
6192
Dave Barach72d72232016-08-04 10:15:08 -04006193static int
6194api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006195{
Dave Barach72d72232016-08-04 10:15:08 -04006196 unformat_input_t *i = vam->input;
6197 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
6198 f64 timeout;
6199 u32 inner_vrf_id = 0;
6200 u32 outer_vrf_id = 0;
6201 ip4_address_t adj_address;
6202 int adj_address_set = 0;
6203 ip4_address_t next_hop_address;
6204 int next_hop_address_set = 0;
6205 u32 tmp;
6206 u8 adj_address_length = 0;
6207 u8 l2_only = 0;
6208 u8 is_add = 1;
6209 u32 resolve_attempts = 5;
6210 u8 resolve_if_needed = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006211
Dave Barach72d72232016-08-04 10:15:08 -04006212 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6213 {
6214 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6215 ;
6216 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6217 ;
6218 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6219 &adj_address, &tmp))
6220 {
6221 adj_address_length = tmp;
6222 adj_address_set = 1;
6223 }
6224 else if (unformat (i, "next-hop %U", unformat_ip4_address,
6225 &next_hop_address))
6226 next_hop_address_set = 1;
6227 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
6228 ;
6229 else if (unformat (i, "resolve-if-needed %d", &tmp))
6230 resolve_if_needed = tmp;
6231 else if (unformat (i, "l2-only"))
6232 l2_only = 1;
6233 else if (unformat (i, "del"))
6234 is_add = 0;
6235 else
6236 {
6237 clib_warning ("parse error '%U'", format_unformat_error, i);
6238 return -99;
6239 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006240 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006241
Dave Barach72d72232016-08-04 10:15:08 -04006242 if (!adj_address_set)
6243 {
6244 errmsg ("adjacency address/mask not set\n");
6245 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006246 }
Dave Barach72d72232016-08-04 10:15:08 -04006247 if (!next_hop_address_set)
6248 {
6249 errmsg ("ip4 next hop address (in outer fib) not set\n");
6250 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006251 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006252
Dave Barach72d72232016-08-04 10:15:08 -04006253 M (MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006254
Dave Barach72d72232016-08-04 10:15:08 -04006255 mp->inner_vrf_id = ntohl (inner_vrf_id);
6256 mp->outer_vrf_id = ntohl (outer_vrf_id);
6257 mp->resolve_attempts = ntohl (resolve_attempts);
6258 mp->resolve_if_needed = resolve_if_needed;
6259 mp->is_add = is_add;
6260 mp->l2_only = l2_only;
6261 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
6262 mp->adj_address_length = adj_address_length;
6263 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
6264 sizeof (next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006265
Dave Barach72d72232016-08-04 10:15:08 -04006266 S;
6267 W;
6268 /* NOTREACHED */
6269 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006270}
6271
Dave Barach72d72232016-08-04 10:15:08 -04006272static int
6273api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006274{
Dave Barach72d72232016-08-04 10:15:08 -04006275 unformat_input_t *i = vam->input;
6276 vl_api_sw_interface_set_unnumbered_t *mp;
6277 f64 timeout;
6278 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006279 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006280 u8 is_add = 1;
6281 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006282
Dave Barach72d72232016-08-04 10:15:08 -04006283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6284 {
6285 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6286 sw_if_index_set = 1;
6287 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6288 sw_if_index_set = 1;
6289 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6290 ;
6291 else if (unformat (i, "del"))
6292 is_add = 0;
6293 else
6294 {
6295 clib_warning ("parse error '%U'", format_unformat_error, i);
6296 return -99;
6297 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006298 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006299
Dave Barach72d72232016-08-04 10:15:08 -04006300 if (sw_if_index_set == 0)
6301 {
6302 errmsg ("missing interface name or sw_if_index\n");
6303 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006304 }
6305
Dave Barach72d72232016-08-04 10:15:08 -04006306 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006307
Dave Barach72d72232016-08-04 10:15:08 -04006308 mp->sw_if_index = ntohl (sw_if_index);
6309 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6310 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006311
Dave Barach72d72232016-08-04 10:15:08 -04006312 S;
6313 W;
6314 /* NOTREACHED */
6315 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006316}
6317
Dave Barach72d72232016-08-04 10:15:08 -04006318static int
6319api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006320{
Dave Barach72d72232016-08-04 10:15:08 -04006321 unformat_input_t *i = vam->input;
6322 vl_api_ip_neighbor_add_del_t *mp;
6323 f64 timeout;
6324 u32 sw_if_index;
6325 u8 sw_if_index_set = 0;
6326 u32 vrf_id = 0;
6327 u8 is_add = 1;
6328 u8 is_static = 0;
6329 u8 mac_address[6];
6330 u8 mac_set = 0;
6331 u8 v4_address_set = 0;
6332 u8 v6_address_set = 0;
6333 ip4_address_t v4address;
6334 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006335
Dave Barach72d72232016-08-04 10:15:08 -04006336 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006337
Dave Barach72d72232016-08-04 10:15:08 -04006338 /* Parse args required to build the message */
6339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6340 {
6341 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6342 {
6343 mac_set = 1;
6344 }
6345 else if (unformat (i, "del"))
6346 is_add = 0;
6347 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6348 sw_if_index_set = 1;
6349 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6350 sw_if_index_set = 1;
6351 else if (unformat (i, "is_static"))
6352 is_static = 1;
6353 else if (unformat (i, "vrf %d", &vrf_id))
6354 ;
6355 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6356 v4_address_set = 1;
6357 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6358 v6_address_set = 1;
6359 else
6360 {
6361 clib_warning ("parse error '%U'", format_unformat_error, i);
6362 return -99;
6363 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006364 }
6365
Dave Barach72d72232016-08-04 10:15:08 -04006366 if (sw_if_index_set == 0)
6367 {
6368 errmsg ("missing interface name or sw_if_index\n");
6369 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006370 }
Dave Barach72d72232016-08-04 10:15:08 -04006371 if (v4_address_set && v6_address_set)
6372 {
6373 errmsg ("both v4 and v6 addresses set\n");
6374 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006375 }
Dave Barach72d72232016-08-04 10:15:08 -04006376 if (!v4_address_set && !v6_address_set)
6377 {
6378 errmsg ("no address set\n");
6379 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006380 }
6381
Dave Barach72d72232016-08-04 10:15:08 -04006382 /* Construct the API message */
6383 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006384
Dave Barach72d72232016-08-04 10:15:08 -04006385 mp->sw_if_index = ntohl (sw_if_index);
6386 mp->is_add = is_add;
6387 mp->vrf_id = ntohl (vrf_id);
6388 mp->is_static = is_static;
6389 if (mac_set)
6390 clib_memcpy (mp->mac_address, mac_address, 6);
6391 if (v6_address_set)
6392 {
6393 mp->is_ipv6 = 1;
6394 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6395 }
6396 else
6397 {
6398 /* mp->is_ipv6 = 0; via memset in M macro above */
6399 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006400 }
6401
Dave Barach72d72232016-08-04 10:15:08 -04006402 /* send it... */
6403 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006404
Dave Barach72d72232016-08-04 10:15:08 -04006405 /* Wait for a reply, return good/bad news */
6406 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006407
Dave Barach72d72232016-08-04 10:15:08 -04006408 /* NOTREACHED */
6409 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006410}
6411
Dave Barach72d72232016-08-04 10:15:08 -04006412static int
6413api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006414{
Dave Barach72d72232016-08-04 10:15:08 -04006415 unformat_input_t *i = vam->input;
6416 vl_api_reset_vrf_t *mp;
6417 f64 timeout;
6418 u32 vrf_id = 0;
6419 u8 is_ipv6 = 0;
6420 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006421
Dave Barach72d72232016-08-04 10:15:08 -04006422 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6423 {
6424 if (unformat (i, "vrf %d", &vrf_id))
6425 vrf_id_set = 1;
6426 else if (unformat (i, "ipv6"))
6427 is_ipv6 = 1;
6428 else
6429 {
6430 clib_warning ("parse error '%U'", format_unformat_error, i);
6431 return -99;
6432 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006433 }
6434
Dave Barach72d72232016-08-04 10:15:08 -04006435 if (vrf_id_set == 0)
6436 {
6437 errmsg ("missing vrf id\n");
6438 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006439 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006440
Dave Barach72d72232016-08-04 10:15:08 -04006441 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006442
Dave Barach72d72232016-08-04 10:15:08 -04006443 mp->vrf_id = ntohl (vrf_id);
6444 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006445
Dave Barach72d72232016-08-04 10:15:08 -04006446 S;
6447 W;
6448 /* NOTREACHED */
6449 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006450}
6451
Dave Barach72d72232016-08-04 10:15:08 -04006452static int
6453api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006454{
Dave Barach72d72232016-08-04 10:15:08 -04006455 unformat_input_t *i = vam->input;
6456 vl_api_create_vlan_subif_t *mp;
6457 f64 timeout;
6458 u32 sw_if_index;
6459 u8 sw_if_index_set = 0;
6460 u32 vlan_id;
6461 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006462
Dave Barach72d72232016-08-04 10:15:08 -04006463 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6464 {
6465 if (unformat (i, "sw_if_index %d", &sw_if_index))
6466 sw_if_index_set = 1;
6467 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6468 sw_if_index_set = 1;
6469 else if (unformat (i, "vlan %d", &vlan_id))
6470 vlan_id_set = 1;
6471 else
6472 {
6473 clib_warning ("parse error '%U'", format_unformat_error, i);
6474 return -99;
6475 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006476 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006477
Dave Barach72d72232016-08-04 10:15:08 -04006478 if (sw_if_index_set == 0)
6479 {
6480 errmsg ("missing interface name or sw_if_index\n");
6481 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006482 }
6483
Dave Barach72d72232016-08-04 10:15:08 -04006484 if (vlan_id_set == 0)
6485 {
6486 errmsg ("missing vlan_id\n");
6487 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006488 }
Dave Barach72d72232016-08-04 10:15:08 -04006489 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006490
Dave Barach72d72232016-08-04 10:15:08 -04006491 mp->sw_if_index = ntohl (sw_if_index);
6492 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006493
Dave Barach72d72232016-08-04 10:15:08 -04006494 S;
6495 W;
6496 /* NOTREACHED */
6497 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006498}
6499
6500#define foreach_create_subif_bit \
6501_(no_tags) \
6502_(one_tag) \
6503_(two_tags) \
6504_(dot1ad) \
6505_(exact_match) \
6506_(default_sub) \
6507_(outer_vlan_id_any) \
6508_(inner_vlan_id_any)
6509
Dave Barach72d72232016-08-04 10:15:08 -04006510static int
6511api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006512{
Dave Barach72d72232016-08-04 10:15:08 -04006513 unformat_input_t *i = vam->input;
6514 vl_api_create_subif_t *mp;
6515 f64 timeout;
6516 u32 sw_if_index;
6517 u8 sw_if_index_set = 0;
6518 u32 sub_id;
6519 u8 sub_id_set = 0;
6520 u32 no_tags = 0;
6521 u32 one_tag = 0;
6522 u32 two_tags = 0;
6523 u32 dot1ad = 0;
6524 u32 exact_match = 0;
6525 u32 default_sub = 0;
6526 u32 outer_vlan_id_any = 0;
6527 u32 inner_vlan_id_any = 0;
6528 u32 tmp;
6529 u16 outer_vlan_id = 0;
6530 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006531
Dave Barach72d72232016-08-04 10:15:08 -04006532 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6533 {
6534 if (unformat (i, "sw_if_index %d", &sw_if_index))
6535 sw_if_index_set = 1;
6536 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6537 sw_if_index_set = 1;
6538 else if (unformat (i, "sub_id %d", &sub_id))
6539 sub_id_set = 1;
6540 else if (unformat (i, "outer_vlan_id %d", &tmp))
6541 outer_vlan_id = tmp;
6542 else if (unformat (i, "inner_vlan_id %d", &tmp))
6543 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006544
6545#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04006546 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07006547#undef _
Dave Barach72d72232016-08-04 10:15:08 -04006548 else
6549 {
6550 clib_warning ("parse error '%U'", format_unformat_error, i);
6551 return -99;
6552 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006553 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006554
Dave Barach72d72232016-08-04 10:15:08 -04006555 if (sw_if_index_set == 0)
6556 {
6557 errmsg ("missing interface name or sw_if_index\n");
6558 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006559 }
6560
Dave Barach72d72232016-08-04 10:15:08 -04006561 if (sub_id_set == 0)
6562 {
6563 errmsg ("missing sub_id\n");
6564 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006565 }
Dave Barach72d72232016-08-04 10:15:08 -04006566 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006567
Dave Barach72d72232016-08-04 10:15:08 -04006568 mp->sw_if_index = ntohl (sw_if_index);
6569 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006570
Ed Warnickecb9cada2015-12-08 15:45:58 -07006571#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04006572 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006573#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006574
Dave Barach72d72232016-08-04 10:15:08 -04006575 mp->outer_vlan_id = ntohs (outer_vlan_id);
6576 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006577
Dave Barach72d72232016-08-04 10:15:08 -04006578 S;
6579 W;
6580 /* NOTREACHED */
6581 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006582}
6583
Dave Barach72d72232016-08-04 10:15:08 -04006584static int
6585api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006586{
Dave Barach72d72232016-08-04 10:15:08 -04006587 unformat_input_t *i = vam->input;
6588 vl_api_oam_add_del_t *mp;
6589 f64 timeout;
6590 u32 vrf_id = 0;
6591 u8 is_add = 1;
6592 ip4_address_t src, dst;
6593 u8 src_set = 0;
6594 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006595
Dave Barach72d72232016-08-04 10:15:08 -04006596 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6597 {
6598 if (unformat (i, "vrf %d", &vrf_id))
6599 ;
6600 else if (unformat (i, "src %U", unformat_ip4_address, &src))
6601 src_set = 1;
6602 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
6603 dst_set = 1;
6604 else if (unformat (i, "del"))
6605 is_add = 0;
6606 else
6607 {
6608 clib_warning ("parse error '%U'", format_unformat_error, i);
6609 return -99;
6610 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006611 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006612
Dave Barach72d72232016-08-04 10:15:08 -04006613 if (src_set == 0)
6614 {
6615 errmsg ("missing src addr\n");
6616 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006617 }
6618
Dave Barach72d72232016-08-04 10:15:08 -04006619 if (dst_set == 0)
6620 {
6621 errmsg ("missing dst addr\n");
6622 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006623 }
6624
Dave Barach72d72232016-08-04 10:15:08 -04006625 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006626
Dave Barach72d72232016-08-04 10:15:08 -04006627 mp->vrf_id = ntohl (vrf_id);
6628 mp->is_add = is_add;
6629 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
6630 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006631
Dave Barach72d72232016-08-04 10:15:08 -04006632 S;
6633 W;
6634 /* NOTREACHED */
6635 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006636}
6637
Dave Barach72d72232016-08-04 10:15:08 -04006638static int
6639api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006640{
Dave Barach72d72232016-08-04 10:15:08 -04006641 unformat_input_t *i = vam->input;
6642 vl_api_reset_fib_t *mp;
6643 f64 timeout;
6644 u32 vrf_id = 0;
6645 u8 is_ipv6 = 0;
6646 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006647
Dave Barach72d72232016-08-04 10:15:08 -04006648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6649 {
6650 if (unformat (i, "vrf %d", &vrf_id))
6651 vrf_id_set = 1;
6652 else if (unformat (i, "ipv6"))
6653 is_ipv6 = 1;
6654 else
6655 {
6656 clib_warning ("parse error '%U'", format_unformat_error, i);
6657 return -99;
6658 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006659 }
6660
Dave Barach72d72232016-08-04 10:15:08 -04006661 if (vrf_id_set == 0)
6662 {
6663 errmsg ("missing vrf id\n");
6664 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006665 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006666
Dave Barach72d72232016-08-04 10:15:08 -04006667 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006668
Dave Barach72d72232016-08-04 10:15:08 -04006669 mp->vrf_id = ntohl (vrf_id);
6670 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006671
Dave Barach72d72232016-08-04 10:15:08 -04006672 S;
6673 W;
6674 /* NOTREACHED */
6675 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006676}
6677
Dave Barach72d72232016-08-04 10:15:08 -04006678static int
6679api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006680{
Dave Barach72d72232016-08-04 10:15:08 -04006681 unformat_input_t *i = vam->input;
6682 vl_api_dhcp_proxy_config_t *mp;
6683 f64 timeout;
6684 u32 vrf_id = 0;
6685 u8 is_add = 1;
6686 u8 insert_cid = 1;
6687 u8 v4_address_set = 0;
6688 u8 v6_address_set = 0;
6689 ip4_address_t v4address;
6690 ip6_address_t v6address;
6691 u8 v4_src_address_set = 0;
6692 u8 v6_src_address_set = 0;
6693 ip4_address_t v4srcaddress;
6694 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006695
Dave Barach72d72232016-08-04 10:15:08 -04006696 /* Parse args required to build the message */
6697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6698 {
6699 if (unformat (i, "del"))
6700 is_add = 0;
6701 else if (unformat (i, "vrf %d", &vrf_id))
6702 ;
6703 else if (unformat (i, "insert-cid %d", &insert_cid))
6704 ;
6705 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
6706 v4_address_set = 1;
6707 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
6708 v6_address_set = 1;
6709 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
6710 v4_src_address_set = 1;
6711 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
6712 v6_src_address_set = 1;
6713 else
6714 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006715 }
6716
Dave Barach72d72232016-08-04 10:15:08 -04006717 if (v4_address_set && v6_address_set)
6718 {
6719 errmsg ("both v4 and v6 server addresses set\n");
6720 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006721 }
Dave Barach72d72232016-08-04 10:15:08 -04006722 if (!v4_address_set && !v6_address_set)
6723 {
6724 errmsg ("no server addresses set\n");
6725 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006726 }
6727
Dave Barach72d72232016-08-04 10:15:08 -04006728 if (v4_src_address_set && v6_src_address_set)
6729 {
6730 errmsg ("both v4 and v6 src addresses set\n");
6731 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006732 }
Dave Barach72d72232016-08-04 10:15:08 -04006733 if (!v4_src_address_set && !v6_src_address_set)
6734 {
6735 errmsg ("no src addresses set\n");
6736 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006737 }
6738
Dave Barach72d72232016-08-04 10:15:08 -04006739 if (!(v4_src_address_set && v4_address_set) &&
6740 !(v6_src_address_set && v6_address_set))
6741 {
6742 errmsg ("no matching server and src addresses set\n");
6743 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006744 }
6745
Dave Barach72d72232016-08-04 10:15:08 -04006746 /* Construct the API message */
6747 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006748
Dave Barach72d72232016-08-04 10:15:08 -04006749 mp->insert_circuit_id = insert_cid;
6750 mp->is_add = is_add;
6751 mp->vrf_id = ntohl (vrf_id);
6752 if (v6_address_set)
6753 {
6754 mp->is_ipv6 = 1;
6755 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
6756 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
6757 }
6758 else
6759 {
6760 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
6761 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006762 }
6763
Dave Barach72d72232016-08-04 10:15:08 -04006764 /* send it... */
6765 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006766
Dave Barach72d72232016-08-04 10:15:08 -04006767 /* Wait for a reply, return good/bad news */
6768 W;
6769 /* NOTREACHED */
6770 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006771}
6772
Dave Barach72d72232016-08-04 10:15:08 -04006773static int
6774api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006775{
Dave Barach72d72232016-08-04 10:15:08 -04006776 unformat_input_t *i = vam->input;
6777 vl_api_dhcp_proxy_config_2_t *mp;
6778 f64 timeout;
6779 u32 rx_vrf_id = 0;
6780 u32 server_vrf_id = 0;
6781 u8 is_add = 1;
6782 u8 insert_cid = 1;
6783 u8 v4_address_set = 0;
6784 u8 v6_address_set = 0;
6785 ip4_address_t v4address;
6786 ip6_address_t v6address;
6787 u8 v4_src_address_set = 0;
6788 u8 v6_src_address_set = 0;
6789 ip4_address_t v4srcaddress;
6790 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006791
Dave Barach72d72232016-08-04 10:15:08 -04006792 /* Parse args required to build the message */
6793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6794 {
6795 if (unformat (i, "del"))
6796 is_add = 0;
6797 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
6798 ;
6799 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
6800 ;
6801 else if (unformat (i, "insert-cid %d", &insert_cid))
6802 ;
6803 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
6804 v4_address_set = 1;
6805 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
6806 v6_address_set = 1;
6807 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
6808 v4_src_address_set = 1;
6809 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
6810 v6_src_address_set = 1;
6811 else
6812 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006813 }
6814
Dave Barach72d72232016-08-04 10:15:08 -04006815 if (v4_address_set && v6_address_set)
6816 {
6817 errmsg ("both v4 and v6 server addresses set\n");
6818 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006819 }
Dave Barach72d72232016-08-04 10:15:08 -04006820 if (!v4_address_set && !v6_address_set)
6821 {
6822 errmsg ("no server addresses set\n");
6823 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006824 }
6825
Dave Barach72d72232016-08-04 10:15:08 -04006826 if (v4_src_address_set && v6_src_address_set)
6827 {
6828 errmsg ("both v4 and v6 src addresses set\n");
6829 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006830 }
Dave Barach72d72232016-08-04 10:15:08 -04006831 if (!v4_src_address_set && !v6_src_address_set)
6832 {
6833 errmsg ("no src addresses set\n");
6834 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006835 }
6836
Dave Barach72d72232016-08-04 10:15:08 -04006837 if (!(v4_src_address_set && v4_address_set) &&
6838 !(v6_src_address_set && v6_address_set))
6839 {
6840 errmsg ("no matching server and src addresses set\n");
6841 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006842 }
6843
Dave Barach72d72232016-08-04 10:15:08 -04006844 /* Construct the API message */
6845 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006846
Dave Barach72d72232016-08-04 10:15:08 -04006847 mp->insert_circuit_id = insert_cid;
6848 mp->is_add = is_add;
6849 mp->rx_vrf_id = ntohl (rx_vrf_id);
6850 mp->server_vrf_id = ntohl (server_vrf_id);
6851 if (v6_address_set)
6852 {
6853 mp->is_ipv6 = 1;
6854 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
6855 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
6856 }
6857 else
6858 {
6859 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
6860 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006861 }
6862
Dave Barach72d72232016-08-04 10:15:08 -04006863 /* send it... */
6864 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006865
Dave Barach72d72232016-08-04 10:15:08 -04006866 /* Wait for a reply, return good/bad news */
6867 W;
6868 /* NOTREACHED */
6869 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006870}
6871
Dave Barach72d72232016-08-04 10:15:08 -04006872static int
6873api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006874{
Dave Barach72d72232016-08-04 10:15:08 -04006875 unformat_input_t *i = vam->input;
6876 vl_api_dhcp_proxy_set_vss_t *mp;
6877 f64 timeout;
6878 u8 is_ipv6 = 0;
6879 u8 is_add = 1;
6880 u32 tbl_id;
6881 u8 tbl_id_set = 0;
6882 u32 oui;
6883 u8 oui_set = 0;
6884 u32 fib_id;
6885 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006886
Dave Barach72d72232016-08-04 10:15:08 -04006887 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6888 {
6889 if (unformat (i, "tbl_id %d", &tbl_id))
6890 tbl_id_set = 1;
6891 if (unformat (i, "fib_id %d", &fib_id))
6892 fib_id_set = 1;
6893 if (unformat (i, "oui %d", &oui))
6894 oui_set = 1;
6895 else if (unformat (i, "ipv6"))
6896 is_ipv6 = 1;
6897 else if (unformat (i, "del"))
6898 is_add = 0;
6899 else
6900 {
6901 clib_warning ("parse error '%U'", format_unformat_error, i);
6902 return -99;
6903 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006904 }
6905
Dave Barach72d72232016-08-04 10:15:08 -04006906 if (tbl_id_set == 0)
6907 {
6908 errmsg ("missing tbl id\n");
6909 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006910 }
6911
Dave Barach72d72232016-08-04 10:15:08 -04006912 if (fib_id_set == 0)
6913 {
6914 errmsg ("missing fib id\n");
6915 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006916 }
Dave Barach72d72232016-08-04 10:15:08 -04006917 if (oui_set == 0)
6918 {
6919 errmsg ("missing oui\n");
6920 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006921 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006922
Dave Barach72d72232016-08-04 10:15:08 -04006923 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
6924 mp->tbl_id = ntohl (tbl_id);
6925 mp->fib_id = ntohl (fib_id);
6926 mp->oui = ntohl (oui);
6927 mp->is_ipv6 = is_ipv6;
6928 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006929
Dave Barach72d72232016-08-04 10:15:08 -04006930 S;
6931 W;
6932 /* NOTREACHED */
6933 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006934}
6935
Dave Barach72d72232016-08-04 10:15:08 -04006936static int
6937api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006938{
Dave Barach72d72232016-08-04 10:15:08 -04006939 unformat_input_t *i = vam->input;
6940 vl_api_dhcp_client_config_t *mp;
6941 f64 timeout;
6942 u32 sw_if_index;
6943 u8 sw_if_index_set = 0;
6944 u8 is_add = 1;
6945 u8 *hostname = 0;
6946 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006947
Dave Barach72d72232016-08-04 10:15:08 -04006948 /* Parse args required to build the message */
6949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6950 {
6951 if (unformat (i, "del"))
6952 is_add = 0;
6953 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6954 sw_if_index_set = 1;
6955 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6956 sw_if_index_set = 1;
6957 else if (unformat (i, "hostname %s", &hostname))
6958 ;
6959 else if (unformat (i, "disable_event"))
6960 disable_event = 1;
6961 else
6962 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006963 }
6964
Dave Barach72d72232016-08-04 10:15:08 -04006965 if (sw_if_index_set == 0)
6966 {
6967 errmsg ("missing interface name or sw_if_index\n");
6968 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006969 }
6970
Dave Barach72d72232016-08-04 10:15:08 -04006971 if (vec_len (hostname) > 63)
6972 {
6973 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006974 }
Dave Barach72d72232016-08-04 10:15:08 -04006975 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006976
Dave Barach72d72232016-08-04 10:15:08 -04006977 /* Construct the API message */
6978 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006979
Dave Barach72d72232016-08-04 10:15:08 -04006980 mp->sw_if_index = ntohl (sw_if_index);
6981 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
6982 vec_free (hostname);
6983 mp->is_add = is_add;
6984 mp->want_dhcp_event = disable_event ? 0 : 1;
6985 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006986
Dave Barach72d72232016-08-04 10:15:08 -04006987 /* send it... */
6988 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006989
Dave Barach72d72232016-08-04 10:15:08 -04006990 /* Wait for a reply, return good/bad news */
6991 W;
6992 /* NOTREACHED */
6993 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006994}
6995
Dave Barach72d72232016-08-04 10:15:08 -04006996static int
6997api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006998{
Dave Barach72d72232016-08-04 10:15:08 -04006999 unformat_input_t *i = vam->input;
7000 vl_api_set_ip_flow_hash_t *mp;
7001 f64 timeout;
7002 u32 vrf_id = 0;
7003 u8 is_ipv6 = 0;
7004 u8 vrf_id_set = 0;
7005 u8 src = 0;
7006 u8 dst = 0;
7007 u8 sport = 0;
7008 u8 dport = 0;
7009 u8 proto = 0;
7010 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007011
Dave Barach72d72232016-08-04 10:15:08 -04007012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7013 {
7014 if (unformat (i, "vrf %d", &vrf_id))
7015 vrf_id_set = 1;
7016 else if (unformat (i, "ipv6"))
7017 is_ipv6 = 1;
7018 else if (unformat (i, "src"))
7019 src = 1;
7020 else if (unformat (i, "dst"))
7021 dst = 1;
7022 else if (unformat (i, "sport"))
7023 sport = 1;
7024 else if (unformat (i, "dport"))
7025 dport = 1;
7026 else if (unformat (i, "proto"))
7027 proto = 1;
7028 else if (unformat (i, "reverse"))
7029 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007030
Dave Barach72d72232016-08-04 10:15:08 -04007031 else
7032 {
7033 clib_warning ("parse error '%U'", format_unformat_error, i);
7034 return -99;
7035 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007036 }
7037
Dave Barach72d72232016-08-04 10:15:08 -04007038 if (vrf_id_set == 0)
7039 {
7040 errmsg ("missing vrf id\n");
7041 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007042 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007043
Dave Barach72d72232016-08-04 10:15:08 -04007044 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7045 mp->src = src;
7046 mp->dst = dst;
7047 mp->sport = sport;
7048 mp->dport = dport;
7049 mp->proto = proto;
7050 mp->reverse = reverse;
7051 mp->vrf_id = ntohl (vrf_id);
7052 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007053
Dave Barach72d72232016-08-04 10:15:08 -04007054 S;
7055 W;
7056 /* NOTREACHED */
7057 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007058}
7059
Dave Barach72d72232016-08-04 10:15:08 -04007060static int
7061api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007062{
Dave Barach72d72232016-08-04 10:15:08 -04007063 unformat_input_t *i = vam->input;
7064 vl_api_sw_interface_ip6_enable_disable_t *mp;
7065 f64 timeout;
7066 u32 sw_if_index;
7067 u8 sw_if_index_set = 0;
7068 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007069
Dave Barach72d72232016-08-04 10:15:08 -04007070 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7071 {
7072 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7073 sw_if_index_set = 1;
7074 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7075 sw_if_index_set = 1;
7076 else if (unformat (i, "enable"))
7077 enable = 1;
7078 else if (unformat (i, "disable"))
7079 enable = 0;
7080 else
7081 {
7082 clib_warning ("parse error '%U'", format_unformat_error, i);
7083 return -99;
7084 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007085 }
7086
Dave Barach72d72232016-08-04 10:15:08 -04007087 if (sw_if_index_set == 0)
7088 {
7089 errmsg ("missing interface name or sw_if_index\n");
7090 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007091 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007092
Dave Barach72d72232016-08-04 10:15:08 -04007093 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007094
Dave Barach72d72232016-08-04 10:15:08 -04007095 mp->sw_if_index = ntohl (sw_if_index);
7096 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007097
Dave Barach72d72232016-08-04 10:15:08 -04007098 S;
7099 W;
7100 /* NOTREACHED */
7101 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007102}
7103
Dave Barach72d72232016-08-04 10:15:08 -04007104static int
7105api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007106{
Dave Barach72d72232016-08-04 10:15:08 -04007107 unformat_input_t *i = vam->input;
7108 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7109 f64 timeout;
7110 u32 sw_if_index;
7111 u8 sw_if_index_set = 0;
7112 u32 address_length = 0;
7113 u8 v6_address_set = 0;
7114 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007115
Dave Barach72d72232016-08-04 10:15:08 -04007116 /* Parse args required to build the message */
7117 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7118 {
7119 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7120 sw_if_index_set = 1;
7121 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7122 sw_if_index_set = 1;
7123 else if (unformat (i, "%U/%d",
7124 unformat_ip6_address, &v6address, &address_length))
7125 v6_address_set = 1;
7126 else
7127 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007128 }
7129
Dave Barach72d72232016-08-04 10:15:08 -04007130 if (sw_if_index_set == 0)
7131 {
7132 errmsg ("missing interface name or sw_if_index\n");
7133 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007134 }
Dave Barach72d72232016-08-04 10:15:08 -04007135 if (!v6_address_set)
7136 {
7137 errmsg ("no address set\n");
7138 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007139 }
7140
Dave Barach72d72232016-08-04 10:15:08 -04007141 /* Construct the API message */
7142 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7143 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007144
Dave Barach72d72232016-08-04 10:15:08 -04007145 mp->sw_if_index = ntohl (sw_if_index);
7146 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7147 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007148
Dave Barach72d72232016-08-04 10:15:08 -04007149 /* send it... */
7150 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007151
Dave Barach72d72232016-08-04 10:15:08 -04007152 /* Wait for a reply, return good/bad news */
7153 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007154
Dave Barach72d72232016-08-04 10:15:08 -04007155 /* NOTREACHED */
7156 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007157}
7158
7159
Dave Barach72d72232016-08-04 10:15:08 -04007160static int
7161api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007162{
Dave Barach72d72232016-08-04 10:15:08 -04007163 unformat_input_t *i = vam->input;
7164 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7165 f64 timeout;
7166 u32 sw_if_index;
7167 u8 sw_if_index_set = 0;
7168 u32 address_length = 0;
7169 u8 v6_address_set = 0;
7170 ip6_address_t v6address;
7171 u8 use_default = 0;
7172 u8 no_advertise = 0;
7173 u8 off_link = 0;
7174 u8 no_autoconfig = 0;
7175 u8 no_onlink = 0;
7176 u8 is_no = 0;
7177 u32 val_lifetime = 0;
7178 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007179
Dave Barach72d72232016-08-04 10:15:08 -04007180 /* Parse args required to build the message */
7181 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7182 {
7183 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7184 sw_if_index_set = 1;
7185 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7186 sw_if_index_set = 1;
7187 else if (unformat (i, "%U/%d",
7188 unformat_ip6_address, &v6address, &address_length))
7189 v6_address_set = 1;
7190 else if (unformat (i, "val_life %d", &val_lifetime))
7191 ;
7192 else if (unformat (i, "pref_life %d", &pref_lifetime))
7193 ;
7194 else if (unformat (i, "def"))
7195 use_default = 1;
7196 else if (unformat (i, "noadv"))
7197 no_advertise = 1;
7198 else if (unformat (i, "offl"))
7199 off_link = 1;
7200 else if (unformat (i, "noauto"))
7201 no_autoconfig = 1;
7202 else if (unformat (i, "nolink"))
7203 no_onlink = 1;
7204 else if (unformat (i, "isno"))
7205 is_no = 1;
7206 else
7207 {
7208 clib_warning ("parse error '%U'", format_unformat_error, i);
7209 return -99;
7210 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007211 }
7212
Dave Barach72d72232016-08-04 10:15:08 -04007213 if (sw_if_index_set == 0)
7214 {
7215 errmsg ("missing interface name or sw_if_index\n");
7216 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007217 }
Dave Barach72d72232016-08-04 10:15:08 -04007218 if (!v6_address_set)
7219 {
7220 errmsg ("no address set\n");
7221 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007222 }
7223
Dave Barach72d72232016-08-04 10:15:08 -04007224 /* Construct the API message */
7225 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007226
Dave Barach72d72232016-08-04 10:15:08 -04007227 mp->sw_if_index = ntohl (sw_if_index);
7228 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7229 mp->address_length = address_length;
7230 mp->use_default = use_default;
7231 mp->no_advertise = no_advertise;
7232 mp->off_link = off_link;
7233 mp->no_autoconfig = no_autoconfig;
7234 mp->no_onlink = no_onlink;
7235 mp->is_no = is_no;
7236 mp->val_lifetime = ntohl (val_lifetime);
7237 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007238
Dave Barach72d72232016-08-04 10:15:08 -04007239 /* send it... */
7240 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007241
Dave Barach72d72232016-08-04 10:15:08 -04007242 /* Wait for a reply, return good/bad news */
7243 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007244
Dave Barach72d72232016-08-04 10:15:08 -04007245 /* NOTREACHED */
7246 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007247}
7248
Dave Barach72d72232016-08-04 10:15:08 -04007249static int
7250api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007251{
Dave Barach72d72232016-08-04 10:15:08 -04007252 unformat_input_t *i = vam->input;
7253 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7254 f64 timeout;
7255 u32 sw_if_index;
7256 u8 sw_if_index_set = 0;
7257 u8 suppress = 0;
7258 u8 managed = 0;
7259 u8 other = 0;
7260 u8 ll_option = 0;
7261 u8 send_unicast = 0;
7262 u8 cease = 0;
7263 u8 is_no = 0;
7264 u8 default_router = 0;
7265 u32 max_interval = 0;
7266 u32 min_interval = 0;
7267 u32 lifetime = 0;
7268 u32 initial_count = 0;
7269 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007270
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007271
Dave Barach72d72232016-08-04 10:15:08 -04007272 /* Parse args required to build the message */
7273 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7274 {
7275 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7276 sw_if_index_set = 1;
7277 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7278 sw_if_index_set = 1;
7279 else if (unformat (i, "maxint %d", &max_interval))
7280 ;
7281 else if (unformat (i, "minint %d", &min_interval))
7282 ;
7283 else if (unformat (i, "life %d", &lifetime))
7284 ;
7285 else if (unformat (i, "count %d", &initial_count))
7286 ;
7287 else if (unformat (i, "interval %d", &initial_interval))
7288 ;
7289 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7290 suppress = 1;
7291 else if (unformat (i, "managed"))
7292 managed = 1;
7293 else if (unformat (i, "other"))
7294 other = 1;
7295 else if (unformat (i, "ll"))
7296 ll_option = 1;
7297 else if (unformat (i, "send"))
7298 send_unicast = 1;
7299 else if (unformat (i, "cease"))
7300 cease = 1;
7301 else if (unformat (i, "isno"))
7302 is_no = 1;
7303 else if (unformat (i, "def"))
7304 default_router = 1;
7305 else
7306 {
7307 clib_warning ("parse error '%U'", format_unformat_error, i);
7308 return -99;
7309 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007310 }
7311
Dave Barach72d72232016-08-04 10:15:08 -04007312 if (sw_if_index_set == 0)
7313 {
7314 errmsg ("missing interface name or sw_if_index\n");
7315 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007316 }
7317
Dave Barach72d72232016-08-04 10:15:08 -04007318 /* Construct the API message */
7319 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007320
Dave Barach72d72232016-08-04 10:15:08 -04007321 mp->sw_if_index = ntohl (sw_if_index);
7322 mp->max_interval = ntohl (max_interval);
7323 mp->min_interval = ntohl (min_interval);
7324 mp->lifetime = ntohl (lifetime);
7325 mp->initial_count = ntohl (initial_count);
7326 mp->initial_interval = ntohl (initial_interval);
7327 mp->suppress = suppress;
7328 mp->managed = managed;
7329 mp->other = other;
7330 mp->ll_option = ll_option;
7331 mp->send_unicast = send_unicast;
7332 mp->cease = cease;
7333 mp->is_no = is_no;
7334 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007335
Dave Barach72d72232016-08-04 10:15:08 -04007336 /* send it... */
7337 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007338
Dave Barach72d72232016-08-04 10:15:08 -04007339 /* Wait for a reply, return good/bad news */
7340 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007341
Dave Barach72d72232016-08-04 10:15:08 -04007342 /* NOTREACHED */
7343 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007344}
7345
Dave Barach72d72232016-08-04 10:15:08 -04007346static int
7347api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007348{
Dave Barach72d72232016-08-04 10:15:08 -04007349 unformat_input_t *i = vam->input;
7350 vl_api_set_arp_neighbor_limit_t *mp;
7351 f64 timeout;
7352 u32 arp_nbr_limit;
7353 u8 limit_set = 0;
7354 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007355
Dave Barach72d72232016-08-04 10:15:08 -04007356 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7357 {
7358 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7359 limit_set = 1;
7360 else if (unformat (i, "ipv6"))
7361 is_ipv6 = 1;
7362 else
7363 {
7364 clib_warning ("parse error '%U'", format_unformat_error, i);
7365 return -99;
7366 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007367 }
7368
Dave Barach72d72232016-08-04 10:15:08 -04007369 if (limit_set == 0)
7370 {
7371 errmsg ("missing limit value\n");
7372 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007373 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007374
Dave Barach72d72232016-08-04 10:15:08 -04007375 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007376
Dave Barach72d72232016-08-04 10:15:08 -04007377 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7378 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007379
Dave Barach72d72232016-08-04 10:15:08 -04007380 S;
7381 W;
7382 /* NOTREACHED */
7383 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007384}
7385
Dave Barach72d72232016-08-04 10:15:08 -04007386static int
7387api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007388{
Dave Barach72d72232016-08-04 10:15:08 -04007389 unformat_input_t *i = vam->input;
7390 vl_api_l2_patch_add_del_t *mp;
7391 f64 timeout;
7392 u32 rx_sw_if_index;
7393 u8 rx_sw_if_index_set = 0;
7394 u32 tx_sw_if_index;
7395 u8 tx_sw_if_index_set = 0;
7396 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007397
Dave Barach72d72232016-08-04 10:15:08 -04007398 /* Parse args required to build the message */
7399 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7400 {
7401 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7402 rx_sw_if_index_set = 1;
7403 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7404 tx_sw_if_index_set = 1;
7405 else if (unformat (i, "rx"))
7406 {
7407 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7408 {
7409 if (unformat (i, "%U", unformat_sw_if_index, vam,
7410 &rx_sw_if_index))
7411 rx_sw_if_index_set = 1;
7412 }
7413 else
7414 break;
7415 }
7416 else if (unformat (i, "tx"))
7417 {
7418 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7419 {
7420 if (unformat (i, "%U", unformat_sw_if_index, vam,
7421 &tx_sw_if_index))
7422 tx_sw_if_index_set = 1;
7423 }
7424 else
7425 break;
7426 }
7427 else if (unformat (i, "del"))
7428 is_add = 0;
7429 else
7430 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007431 }
7432
Dave Barach72d72232016-08-04 10:15:08 -04007433 if (rx_sw_if_index_set == 0)
7434 {
7435 errmsg ("missing rx interface name or rx_sw_if_index\n");
7436 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007437 }
7438
Dave Barach72d72232016-08-04 10:15:08 -04007439 if (tx_sw_if_index_set == 0)
7440 {
7441 errmsg ("missing tx interface name or tx_sw_if_index\n");
7442 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007443 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007444
Dave Barach72d72232016-08-04 10:15:08 -04007445 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007446
Dave Barach72d72232016-08-04 10:15:08 -04007447 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7448 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7449 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007450
Dave Barach72d72232016-08-04 10:15:08 -04007451 S;
7452 W;
7453 /* NOTREACHED */
7454 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007455}
Dave Barach72d72232016-08-04 10:15:08 -04007456
7457static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007458api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007459{
Dave Barach72d72232016-08-04 10:15:08 -04007460 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007461 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007462 f64 timeout;
7463 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007464 int has_trace_option = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007465 int has_pow_option = 0;
7466 int has_ppc_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007467
Shwetha20a64f52016-03-25 10:55:01 +00007468 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7469 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007470 if (unformat (input, "trace"))
7471 has_trace_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007472 else if (unformat (input, "pow"))
Dave Barach72d72232016-08-04 10:15:08 -04007473 has_pow_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007474 else if (unformat (input, "ppc encap"))
Dave Barach72d72232016-08-04 10:15:08 -04007475 has_ppc_option = PPC_ENCAP;
Shwetha20a64f52016-03-25 10:55:01 +00007476 else if (unformat (input, "ppc decap"))
Dave Barach72d72232016-08-04 10:15:08 -04007477 has_ppc_option = PPC_DECAP;
Shwetha20a64f52016-03-25 10:55:01 +00007478 else if (unformat (input, "ppc none"))
Dave Barach72d72232016-08-04 10:15:08 -04007479 has_ppc_option = PPC_NONE;
Shwetha20a64f52016-03-25 10:55:01 +00007480 else
Dave Barach72d72232016-08-04 10:15:08 -04007481 break;
Shwetha20a64f52016-03-25 10:55:01 +00007482 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007483 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007484 mp->id = htons (id);
Shwetha20a64f52016-03-25 10:55:01 +00007485 mp->trace_ppc = has_ppc_option;
Shwetha20a64f52016-03-25 10:55:01 +00007486 mp->pow_enable = has_pow_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007487 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007488
Dave Barach72d72232016-08-04 10:15:08 -04007489 S;
7490 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007491
Dave Barach72d72232016-08-04 10:15:08 -04007492 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007493
Shwetha20a64f52016-03-25 10:55:01 +00007494}
Dave Barach72d72232016-08-04 10:15:08 -04007495
Shwetha20a64f52016-03-25 10:55:01 +00007496
Dave Barach72d72232016-08-04 10:15:08 -04007497static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007498api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007499{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007500 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007501 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007502
Vengada Govindan07d2f842016-08-25 10:34:34 -07007503 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04007504 S;
7505 W;
7506 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00007507}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007508
Dave Barach72d72232016-08-04 10:15:08 -04007509static int
7510api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007511{
Dave Barach72d72232016-08-04 10:15:08 -04007512 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007513 vl_api_sr_tunnel_add_del_t *mp;
7514 f64 timeout;
7515 int is_del = 0;
7516 int pl_index;
7517 ip6_address_t src_address;
7518 int src_address_set = 0;
7519 ip6_address_t dst_address;
7520 u32 dst_mask_width;
7521 int dst_address_set = 0;
7522 u16 flags = 0;
7523 u32 rx_table_id = 0;
7524 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007525 ip6_address_t *segments = 0;
7526 ip6_address_t *this_seg;
7527 ip6_address_t *tags = 0;
7528 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007529 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04007530 u8 *name = 0;
7531 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007532
7533 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7534 {
7535 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007536 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007537 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04007538 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007539 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007540 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007541 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007542 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007543 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007544 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007545 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04007546 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007547 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04007548 unformat_ip6_address, &dst_address, &dst_mask_width))
7549 dst_address_set = 1;
7550 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
7551 {
7552 vec_add2 (segments, this_seg, 1);
7553 clib_memcpy (this_seg->as_u8, next_address.as_u8,
7554 sizeof (*this_seg));
7555 }
7556 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
7557 {
7558 vec_add2 (tags, this_tag, 1);
7559 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
7560 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007561 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04007562 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007563 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04007564 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007565 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007566 {
7567 if (pl_index <= 0 || pl_index > 4)
7568 {
7569 pl_index_range_error:
7570 errmsg ("pl index %d out of range\n", pl_index);
7571 return -99;
7572 }
7573 flags |=
7574 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
7575 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007576 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007577 {
7578 if (pl_index <= 0 || pl_index > 4)
7579 goto pl_index_range_error;
7580 flags |=
7581 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
7582 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007583 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007584 {
7585 if (pl_index <= 0 || pl_index > 4)
7586 goto pl_index_range_error;
7587 flags |=
7588 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
7589 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007590 else
Dave Barach72d72232016-08-04 10:15:08 -04007591 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007592 }
7593
7594 if (!src_address_set)
7595 {
7596 errmsg ("src address required\n");
7597 return -99;
7598 }
7599
7600 if (!dst_address_set)
7601 {
7602 errmsg ("dst address required\n");
7603 return -99;
7604 }
7605
7606 if (!segments)
7607 {
7608 errmsg ("at least one sr segment required\n");
7609 return -99;
7610 }
7611
Dave Barach72d72232016-08-04 10:15:08 -04007612 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
7613 vec_len (segments) * sizeof (ip6_address_t)
7614 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007615
Damjan Marionf1213b82016-03-13 02:22:06 +01007616 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
7617 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007618 mp->dst_mask_width = dst_mask_width;
7619 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
7620 mp->n_segments = vec_len (segments);
7621 mp->n_tags = vec_len (tags);
7622 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007623 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04007624 vec_len (segments) * sizeof (ip6_address_t));
7625 clib_memcpy (mp->segs_and_tags +
7626 vec_len (segments) * sizeof (ip6_address_t), tags,
7627 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007628
7629 mp->outer_vrf_id = ntohl (rx_table_id);
7630 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04007631 memcpy (mp->name, name, vec_len (name));
7632 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007633
7634 vec_free (segments);
7635 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007636
Dave Barach72d72232016-08-04 10:15:08 -04007637 S;
7638 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007639 /* NOTREACHED */
7640}
7641
Dave Barach72d72232016-08-04 10:15:08 -04007642static int
7643api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007644{
Dave Barach72d72232016-08-04 10:15:08 -04007645 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007646 vl_api_sr_policy_add_del_t *mp;
7647 f64 timeout;
7648 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007649 u8 *name = 0;
7650 u8 *tunnel_name = 0;
7651 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007652
Dave Barach72d72232016-08-04 10:15:08 -04007653 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007654 int tunnel_set = 0;
7655 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007656 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
7657 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 -07007658
7659 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7660 {
7661 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007662 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007663 else if (unformat (input, "name %s", &name))
7664 name_set = 1;
7665 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04007666 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007667 if (tunnel_name)
7668 {
7669 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007670 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04007671 - length = #bytes to store in serial vector
7672 - +1 = byte to store that length
7673 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007674 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007675 tunnel_set = 1;
7676 tunnel_name = 0;
7677 }
Dave Barach72d72232016-08-04 10:15:08 -04007678 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007679 else
Dave Barach72d72232016-08-04 10:15:08 -04007680 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007681 }
7682
7683 if (!name_set)
7684 {
7685 errmsg ("policy name required\n");
7686 return -99;
7687 }
7688
7689 if ((!tunnel_set) && (!is_del))
7690 {
7691 errmsg ("tunnel name required\n");
7692 return -99;
7693 }
7694
Dave Barach72d72232016-08-04 10:15:08 -04007695 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007696
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007697
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007698
7699 mp->is_add = !is_del;
7700
Dave Barach72d72232016-08-04 10:15:08 -04007701 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007702 // 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 -04007703 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007704 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04007705 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
7706 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007707
Dave Barach72d72232016-08-04 10:15:08 -04007708 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007709 {
7710 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04007711 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
7712 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007713 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04007714 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007715 }
Dave Barach72d72232016-08-04 10:15:08 -04007716 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 -07007717
7718 vec_free (tunnel_names);
7719 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007720
Dave Barach72d72232016-08-04 10:15:08 -04007721 S;
7722 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007723 /* NOTREACHED */
7724}
7725
Dave Barach72d72232016-08-04 10:15:08 -04007726static int
7727api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007728{
Dave Barach72d72232016-08-04 10:15:08 -04007729 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007730 vl_api_sr_multicast_map_add_del_t *mp;
7731 f64 timeout;
7732 int is_del = 0;
7733 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04007734 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007735 int multicast_address_set = 0;
7736
7737 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7738 {
7739 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007740 is_del = 1;
7741 else
7742 if (unformat
7743 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007744 multicast_address_set = 1;
7745 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007746 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007747 else
Dave Barach72d72232016-08-04 10:15:08 -04007748 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007749 }
7750
7751 if (!is_del && !policy_name)
7752 {
7753 errmsg ("sr-policy name required\n");
7754 return -99;
7755 }
7756
7757
7758 if (!multicast_address_set)
7759 {
7760 errmsg ("address required\n");
7761 return -99;
7762 }
7763
Dave Barach72d72232016-08-04 10:15:08 -04007764 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007765
7766 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04007767 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
7768 clib_memcpy (mp->multicast_address, &multicast_address,
7769 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007770
7771
7772 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007773
Dave Barach72d72232016-08-04 10:15:08 -04007774 S;
7775 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007776 /* NOTREACHED */
7777}
7778
Ed Warnickecb9cada2015-12-08 15:45:58 -07007779
7780#define foreach_ip4_proto_field \
7781_(src_address) \
7782_(dst_address) \
7783_(tos) \
7784_(length) \
7785_(fragment_id) \
7786_(ttl) \
7787_(protocol) \
7788_(checksum)
7789
Dave Barach72d72232016-08-04 10:15:08 -04007790uword
7791unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007792{
Dave Barach72d72232016-08-04 10:15:08 -04007793 u8 **maskp = va_arg (*args, u8 **);
7794 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007795 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007796 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007797
Ed Warnickecb9cada2015-12-08 15:45:58 -07007798#define _(a) u8 a=0;
7799 foreach_ip4_proto_field;
7800#undef _
7801 u8 version = 0;
7802 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007803
7804
7805 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007806 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007807 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04007808 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007809 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04007810 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007811 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04007812 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007813 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04007814 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007815 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04007816 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007817
Ed Warnickecb9cada2015-12-08 15:45:58 -07007818#define _(a) else if (unformat (input, #a)) a=1;
7819 foreach_ip4_proto_field
7820#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007821 else
7822 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007823 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007824
Ed Warnickecb9cada2015-12-08 15:45:58 -07007825#define _(a) found_something += a;
7826 foreach_ip4_proto_field;
7827#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007828
Ed Warnickecb9cada2015-12-08 15:45:58 -07007829 if (found_something == 0)
7830 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007831
Ed Warnickecb9cada2015-12-08 15:45:58 -07007832 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007833
Ed Warnickecb9cada2015-12-08 15:45:58 -07007834 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007835
Ed Warnickecb9cada2015-12-08 15:45:58 -07007836#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
7837 foreach_ip4_proto_field;
7838#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007839
Ed Warnickecb9cada2015-12-08 15:45:58 -07007840 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007841
Ed Warnickecb9cada2015-12-08 15:45:58 -07007842 if (version)
7843 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007844
Ed Warnickecb9cada2015-12-08 15:45:58 -07007845 if (hdr_length)
7846 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007847
Ed Warnickecb9cada2015-12-08 15:45:58 -07007848 *maskp = mask;
7849 return 1;
7850}
7851
7852#define foreach_ip6_proto_field \
7853_(src_address) \
7854_(dst_address) \
7855_(payload_length) \
7856_(hop_limit) \
7857_(protocol)
7858
Dave Barach72d72232016-08-04 10:15:08 -04007859uword
7860unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007861{
Dave Barach72d72232016-08-04 10:15:08 -04007862 u8 **maskp = va_arg (*args, u8 **);
7863 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007864 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007865 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007866 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007867
Ed Warnickecb9cada2015-12-08 15:45:58 -07007868#define _(a) u8 a=0;
7869 foreach_ip6_proto_field;
7870#undef _
7871 u8 version = 0;
7872 u8 traffic_class = 0;
7873 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007874
7875 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007876 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007877 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04007878 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007879 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04007880 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007881 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04007882 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007883 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04007884 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007885 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04007886 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007887 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04007888 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007889
Ed Warnickecb9cada2015-12-08 15:45:58 -07007890#define _(a) else if (unformat (input, #a)) a=1;
7891 foreach_ip6_proto_field
7892#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007893 else
7894 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007895 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007896
Ed Warnickecb9cada2015-12-08 15:45:58 -07007897#define _(a) found_something += a;
7898 foreach_ip6_proto_field;
7899#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007900
Ed Warnickecb9cada2015-12-08 15:45:58 -07007901 if (found_something == 0)
7902 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007903
Ed Warnickecb9cada2015-12-08 15:45:58 -07007904 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007905
Ed Warnickecb9cada2015-12-08 15:45:58 -07007906 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007907
Ed Warnickecb9cada2015-12-08 15:45:58 -07007908#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
7909 foreach_ip6_proto_field;
7910#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007911
Ed Warnickecb9cada2015-12-08 15:45:58 -07007912 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007913
Ed Warnickecb9cada2015-12-08 15:45:58 -07007914 if (version)
7915 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7916
7917 if (traffic_class)
7918 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7919
7920 if (flow_label)
7921 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7922
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007923 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07007924 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007925
Ed Warnickecb9cada2015-12-08 15:45:58 -07007926 *maskp = mask;
7927 return 1;
7928}
7929
Dave Barach72d72232016-08-04 10:15:08 -04007930uword
7931unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007932{
Dave Barach72d72232016-08-04 10:15:08 -04007933 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007934
Dave Barach72d72232016-08-04 10:15:08 -04007935 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7936 {
7937 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7938 return 1;
7939 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7940 return 1;
7941 else
7942 break;
7943 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007944 return 0;
7945}
7946
Dave Barach72d72232016-08-04 10:15:08 -04007947uword
7948unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007949{
Dave Barach72d72232016-08-04 10:15:08 -04007950 u8 **maskp = va_arg (*args, u8 **);
7951 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007952 u8 src = 0;
7953 u8 dst = 0;
7954 u8 proto = 0;
7955 u8 tag1 = 0;
7956 u8 tag2 = 0;
7957 u8 ignore_tag1 = 0;
7958 u8 ignore_tag2 = 0;
7959 u8 cos1 = 0;
7960 u8 cos2 = 0;
7961 u8 dot1q = 0;
7962 u8 dot1ad = 0;
7963 int len = 14;
7964
Dave Barach72d72232016-08-04 10:15:08 -04007965 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7966 {
7967 if (unformat (input, "src"))
7968 src = 1;
7969 else if (unformat (input, "dst"))
7970 dst = 1;
7971 else if (unformat (input, "proto"))
7972 proto = 1;
7973 else if (unformat (input, "tag1"))
7974 tag1 = 1;
7975 else if (unformat (input, "tag2"))
7976 tag2 = 1;
7977 else if (unformat (input, "ignore-tag1"))
7978 ignore_tag1 = 1;
7979 else if (unformat (input, "ignore-tag2"))
7980 ignore_tag2 = 1;
7981 else if (unformat (input, "cos1"))
7982 cos1 = 1;
7983 else if (unformat (input, "cos2"))
7984 cos2 = 1;
7985 else if (unformat (input, "dot1q"))
7986 dot1q = 1;
7987 else if (unformat (input, "dot1ad"))
7988 dot1ad = 1;
7989 else
7990 break;
7991 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007992 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04007993 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007994 return 0;
7995
7996 if (tag1 || ignore_tag1 || cos1 || dot1q)
7997 len = 18;
7998 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7999 len = 22;
8000
Dave Barach72d72232016-08-04 10:15:08 -04008001 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008002
8003 if (dst)
8004 memset (mask, 0xff, 6);
8005
8006 if (src)
8007 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008008
Ed Warnickecb9cada2015-12-08 15:45:58 -07008009 if (tag2 || dot1ad)
8010 {
8011 /* inner vlan tag */
8012 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008013 {
8014 mask[19] = 0xff;
8015 mask[18] = 0x0f;
8016 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008017 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008018 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008019 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008020 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008021 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008022 {
8023 mask[15] = 0xff;
8024 mask[14] = 0x0f;
8025 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008026 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008027 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008028 *maskp = mask;
8029 return 1;
8030 }
8031 if (tag1 | dot1q)
8032 {
8033 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008034 {
8035 mask[15] = 0xff;
8036 mask[14] = 0x0f;
8037 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008038 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008039 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008040 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008041 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008042
8043 *maskp = mask;
8044 return 1;
8045 }
8046 if (cos2)
8047 mask[18] |= 0xe0;
8048 if (cos1)
8049 mask[14] |= 0xe0;
8050 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008051 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008052
Ed Warnickecb9cada2015-12-08 15:45:58 -07008053 *maskp = mask;
8054 return 1;
8055}
8056
Dave Barach72d72232016-08-04 10:15:08 -04008057uword
8058unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008059{
Dave Barach72d72232016-08-04 10:15:08 -04008060 u8 **maskp = va_arg (*args, u8 **);
8061 u32 *skipp = va_arg (*args, u32 *);
8062 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008063 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008064 u8 *mask = 0;
8065 u8 *l2 = 0;
8066 u8 *l3 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008067 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008068
Dave Barach72d72232016-08-04 10:15:08 -04008069 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8070 {
8071 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8072 ;
8073 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8074 ;
8075 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8076 ;
8077 else
8078 break;
8079 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008080
8081 if (mask || l2 || l3)
8082 {
8083 if (l2 || l3)
Dave Barach72d72232016-08-04 10:15:08 -04008084 {
8085 /* "With a free Ethernet header in every package" */
8086 if (l2 == 0)
8087 vec_validate (l2, 13);
8088 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008089 if (vec_len (l3))
8090 {
8091 vec_append (mask, l3);
8092 vec_free (l3);
8093 }
Dave Barach72d72232016-08-04 10:15:08 -04008094 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008095
8096 /* Scan forward looking for the first significant mask octet */
8097 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008098 if (mask[i])
8099 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008100
8101 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008102 *skipp = i / sizeof (u32x4);
8103 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008104
8105 /* Pad mask to an even multiple of the vector size */
8106 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008107 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008108
8109 match = vec_len (mask) / sizeof (u32x4);
8110
Dave Barach72d72232016-08-04 10:15:08 -04008111 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8112 {
8113 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8114 if (*tmp || *(tmp + 1))
8115 break;
8116 match--;
8117 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008118 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008119 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008120
Dave Barach72d72232016-08-04 10:15:08 -04008121 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008122
8123 *matchp = match;
8124 *maskp = mask;
8125
8126 return 1;
8127 }
8128
8129 return 0;
8130}
8131
8132#define foreach_l2_next \
8133_(drop, DROP) \
8134_(ethernet, ETHERNET_INPUT) \
8135_(ip4, IP4_INPUT) \
8136_(ip6, IP6_INPUT)
8137
Dave Barach72d72232016-08-04 10:15:08 -04008138uword
8139unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008140{
Dave Barach72d72232016-08-04 10:15:08 -04008141 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008142 u32 next_index = 0;
8143 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008144
Ed Warnickecb9cada2015-12-08 15:45:58 -07008145#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008146 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008147 foreach_l2_next;
8148#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008149
Ed Warnickecb9cada2015-12-08 15:45:58 -07008150 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008151 {
8152 next_index = tmp;
8153 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008154 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008155
Ed Warnickecb9cada2015-12-08 15:45:58 -07008156 return 0;
8157
Dave Barach72d72232016-08-04 10:15:08 -04008158out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008159 *miss_next_indexp = next_index;
8160 return 1;
8161}
8162
8163#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008164_(drop, DROP) \
8165_(local, LOCAL) \
8166_(rewrite, REWRITE)
8167
Dave Barach72d72232016-08-04 10:15:08 -04008168uword
8169unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008170{
Dave Barach72d72232016-08-04 10:15:08 -04008171 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008172 u32 next_index = 0;
8173 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008174
Ed Warnickecb9cada2015-12-08 15:45:58 -07008175#define _(n,N) \
8176 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8177 foreach_ip_next;
8178#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008179
Ed Warnickecb9cada2015-12-08 15:45:58 -07008180 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008181 {
8182 next_index = tmp;
8183 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008184 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008185
Ed Warnickecb9cada2015-12-08 15:45:58 -07008186 return 0;
8187
Dave Barach72d72232016-08-04 10:15:08 -04008188out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008189 *miss_next_indexp = next_index;
8190 return 1;
8191}
8192
8193#define foreach_acl_next \
8194_(deny, DENY)
8195
Dave Barach72d72232016-08-04 10:15:08 -04008196uword
8197unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008198{
Dave Barach72d72232016-08-04 10:15:08 -04008199 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008200 u32 next_index = 0;
8201 u32 tmp;
8202
8203#define _(n,N) \
8204 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8205 foreach_acl_next;
8206#undef _
8207
8208 if (unformat (input, "permit"))
8209 {
8210 next_index = ~0;
8211 goto out;
8212 }
8213 else if (unformat (input, "%d", &tmp))
8214 {
8215 next_index = tmp;
8216 goto out;
8217 }
8218
8219 return 0;
8220
Dave Barach72d72232016-08-04 10:15:08 -04008221out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008222 *miss_next_indexp = next_index;
8223 return 1;
8224}
8225
Dave Barach72d72232016-08-04 10:15:08 -04008226uword
8227unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008228{
Dave Barach72d72232016-08-04 10:15:08 -04008229 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008230
8231 if (unformat (input, "conform-color"))
8232 *r = POLICE_CONFORM;
8233 else if (unformat (input, "exceed-color"))
8234 *r = POLICE_EXCEED;
8235 else
8236 return 0;
8237
8238 return 1;
8239}
8240
Dave Barach72d72232016-08-04 10:15:08 -04008241static int
8242api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008243{
Dave Barach72d72232016-08-04 10:15:08 -04008244 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008245 vl_api_classify_add_del_table_t *mp;
8246
8247 u32 nbuckets = 2;
8248 u32 skip = ~0;
8249 u32 match = ~0;
8250 int is_add = 1;
8251 u32 table_index = ~0;
8252 u32 next_table_index = ~0;
8253 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008254 u32 memory_size = 32 << 20;
8255 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008256 f64 timeout;
8257
Dave Barach72d72232016-08-04 10:15:08 -04008258 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8259 {
8260 if (unformat (i, "del"))
8261 is_add = 0;
8262 else if (unformat (i, "buckets %d", &nbuckets))
8263 ;
8264 else if (unformat (i, "memory_size %d", &memory_size))
8265 ;
8266 else if (unformat (i, "skip %d", &skip))
8267 ;
8268 else if (unformat (i, "match %d", &match))
8269 ;
8270 else if (unformat (i, "table %d", &table_index))
8271 ;
8272 else if (unformat (i, "mask %U", unformat_classify_mask,
8273 &mask, &skip, &match))
8274 ;
8275 else if (unformat (i, "next-table %d", &next_table_index))
8276 ;
8277 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8278 &miss_next_index))
8279 ;
8280 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8281 &miss_next_index))
8282 ;
8283 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8284 &miss_next_index))
8285 ;
8286 else
8287 break;
8288 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008289
Dave Barach72d72232016-08-04 10:15:08 -04008290 if (is_add && mask == 0)
8291 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008292 errmsg ("Mask required\n");
8293 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008294 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008295
Dave Barach72d72232016-08-04 10:15:08 -04008296 if (is_add && skip == ~0)
8297 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008298 errmsg ("skip count required\n");
8299 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008300 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008301
Dave Barach72d72232016-08-04 10:15:08 -04008302 if (is_add && match == ~0)
8303 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008304 errmsg ("match count required\n");
8305 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008306 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008307
Dave Barach72d72232016-08-04 10:15:08 -04008308 if (!is_add && table_index == ~0)
8309 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008310 errmsg ("table index required for delete\n");
8311 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008312 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008313
Dave Barach72d72232016-08-04 10:15:08 -04008314 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008315
8316 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008317 mp->table_index = ntohl (table_index);
8318 mp->nbuckets = ntohl (nbuckets);
8319 mp->memory_size = ntohl (memory_size);
8320 mp->skip_n_vectors = ntohl (skip);
8321 mp->match_n_vectors = ntohl (match);
8322 mp->next_table_index = ntohl (next_table_index);
8323 mp->miss_next_index = ntohl (miss_next_index);
8324 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008325
Dave Barach72d72232016-08-04 10:15:08 -04008326 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008327
Dave Barach72d72232016-08-04 10:15:08 -04008328 S;
8329 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008330 /* NOTREACHED */
8331}
8332
Dave Barach72d72232016-08-04 10:15:08 -04008333uword
8334unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008335{
Dave Barach72d72232016-08-04 10:15:08 -04008336 u8 **matchp = va_arg (*args, u8 **);
8337 u8 *match = 0;
8338 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008339 int version = 0;
8340 u32 version_val;
8341 int hdr_length = 0;
8342 u32 hdr_length_val;
8343 int src = 0, dst = 0;
8344 ip4_address_t src_val, dst_val;
8345 int proto = 0;
8346 u32 proto_val;
8347 int tos = 0;
8348 u32 tos_val;
8349 int length = 0;
8350 u32 length_val;
8351 int fragment_id = 0;
8352 u32 fragment_id_val;
8353 int ttl = 0;
8354 int ttl_val;
8355 int checksum = 0;
8356 u32 checksum_val;
8357
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008358 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008359 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008360 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008361 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008362 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008363 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008364 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008365 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008366 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008367 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008368 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008369 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008370 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04008371 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008372 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008373 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008374 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04008375 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008376 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04008377 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008378 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04008379 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008380 else
Dave Barach72d72232016-08-04 10:15:08 -04008381 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008382 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008383
Ed Warnickecb9cada2015-12-08 15:45:58 -07008384 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8385 + ttl + checksum == 0)
8386 return 0;
8387
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008388 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008389 * Aligned because we use the real comparison functions
8390 */
Dave Barach72d72232016-08-04 10:15:08 -04008391 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008392
Ed Warnickecb9cada2015-12-08 15:45:58 -07008393 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008394
Ed Warnickecb9cada2015-12-08 15:45:58 -07008395 /* These are realistically matched in practice */
8396 if (src)
8397 ip->src_address.as_u32 = src_val.as_u32;
8398
8399 if (dst)
8400 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008401
Ed Warnickecb9cada2015-12-08 15:45:58 -07008402 if (proto)
8403 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008404
Ed Warnickecb9cada2015-12-08 15:45:58 -07008405
8406 /* These are not, but they're included for completeness */
8407 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04008408 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008409
8410 if (hdr_length)
8411 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008412
Ed Warnickecb9cada2015-12-08 15:45:58 -07008413 if (tos)
8414 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008415
Ed Warnickecb9cada2015-12-08 15:45:58 -07008416 if (length)
8417 ip->length = length_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008418
Ed Warnickecb9cada2015-12-08 15:45:58 -07008419 if (ttl)
8420 ip->ttl = ttl_val;
8421
8422 if (checksum)
8423 ip->checksum = checksum_val;
8424
8425 *matchp = match;
8426 return 1;
8427}
8428
Dave Barach72d72232016-08-04 10:15:08 -04008429uword
8430unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008431{
Dave Barach72d72232016-08-04 10:15:08 -04008432 u8 **matchp = va_arg (*args, u8 **);
8433 u8 *match = 0;
8434 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008435 int version = 0;
8436 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04008437 u8 traffic_class = 0;
8438 u32 traffic_class_val = 0;
8439 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008440 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008441 int src = 0, dst = 0;
8442 ip6_address_t src_val, dst_val;
8443 int proto = 0;
8444 u32 proto_val;
8445 int payload_length = 0;
8446 u32 payload_length_val;
8447 int hop_limit = 0;
8448 int hop_limit_val;
8449 u32 ip_version_traffic_class_and_flow_label;
8450
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008451 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008452 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008453 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008454 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008455 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04008456 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008457 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04008458 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008459 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008460 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008461 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008462 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008463 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008464 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008465 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008466 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008467 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04008468 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008469 else
Dave Barach72d72232016-08-04 10:15:08 -04008470 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008471 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008472
Ed Warnickecb9cada2015-12-08 15:45:58 -07008473 if (version + traffic_class + flow_label + src + dst + proto +
8474 payload_length + hop_limit == 0)
8475 return 0;
8476
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008477 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008478 * Aligned because we use the real comparison functions
8479 */
Dave Barach72d72232016-08-04 10:15:08 -04008480 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008481
Ed Warnickecb9cada2015-12-08 15:45:58 -07008482 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008483
Ed Warnickecb9cada2015-12-08 15:45:58 -07008484 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01008485 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008486
8487 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01008488 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008489
Ed Warnickecb9cada2015-12-08 15:45:58 -07008490 if (proto)
8491 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008492
Ed Warnickecb9cada2015-12-08 15:45:58 -07008493 ip_version_traffic_class_and_flow_label = 0;
8494
8495 if (version)
8496 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8497
8498 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04008499 ip_version_traffic_class_and_flow_label |=
8500 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008501
8502 if (flow_label)
8503 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008504
8505 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008506 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8507
8508 if (payload_length)
8509 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008510
Ed Warnickecb9cada2015-12-08 15:45:58 -07008511 if (hop_limit)
8512 ip->hop_limit = hop_limit_val;
8513
8514 *matchp = match;
8515 return 1;
8516}
8517
Dave Barach72d72232016-08-04 10:15:08 -04008518uword
8519unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008520{
Dave Barach72d72232016-08-04 10:15:08 -04008521 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008522
Dave Barach72d72232016-08-04 10:15:08 -04008523 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8524 {
8525 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8526 return 1;
8527 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8528 return 1;
8529 else
8530 break;
8531 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008532 return 0;
8533}
8534
Dave Barach72d72232016-08-04 10:15:08 -04008535uword
8536unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008537{
Dave Barach72d72232016-08-04 10:15:08 -04008538 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008539 u32 tag;
8540
Dave Barach72d72232016-08-04 10:15:08 -04008541 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07008542 {
Dave Barach72d72232016-08-04 10:15:08 -04008543 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008544 tagp[1] = tag & 0xFF;
8545 return 1;
8546 }
8547
8548 return 0;
8549}
8550
Dave Barach72d72232016-08-04 10:15:08 -04008551uword
8552unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008553{
Dave Barach72d72232016-08-04 10:15:08 -04008554 u8 **matchp = va_arg (*args, u8 **);
8555 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008556 u8 src = 0;
8557 u8 src_val[6];
8558 u8 dst = 0;
8559 u8 dst_val[6];
8560 u8 proto = 0;
8561 u16 proto_val;
8562 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008563 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008564 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008565 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008566 int len = 14;
8567 u8 ignore_tag1 = 0;
8568 u8 ignore_tag2 = 0;
8569 u8 cos1 = 0;
8570 u8 cos2 = 0;
8571 u32 cos1_val = 0;
8572 u32 cos2_val = 0;
8573
Dave Barach72d72232016-08-04 10:15:08 -04008574 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8575 {
8576 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8577 src = 1;
8578 else
8579 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8580 dst = 1;
8581 else if (unformat (input, "proto %U",
8582 unformat_ethernet_type_host_byte_order, &proto_val))
8583 proto = 1;
8584 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8585 tag1 = 1;
8586 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8587 tag2 = 1;
8588 else if (unformat (input, "ignore-tag1"))
8589 ignore_tag1 = 1;
8590 else if (unformat (input, "ignore-tag2"))
8591 ignore_tag2 = 1;
8592 else if (unformat (input, "cos1 %d", &cos1_val))
8593 cos1 = 1;
8594 else if (unformat (input, "cos2 %d", &cos2_val))
8595 cos2 = 1;
8596 else
8597 break;
8598 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008599 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04008600 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008601 return 0;
8602
8603 if (tag1 || ignore_tag1 || cos1)
8604 len = 18;
8605 if (tag2 || ignore_tag2 || cos2)
8606 len = 22;
8607
Dave Barach72d72232016-08-04 10:15:08 -04008608 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008609
8610 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01008611 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008612
8613 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01008614 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008615
Ed Warnickecb9cada2015-12-08 15:45:58 -07008616 if (tag2)
8617 {
8618 /* inner vlan tag */
8619 match[19] = tag2_val[1];
8620 match[18] = tag2_val[0];
8621 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008622 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008623 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008624 {
8625 match[21] = proto_val & 0xff;
8626 match[20] = proto_val >> 8;
8627 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008628 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008629 {
8630 match[15] = tag1_val[1];
8631 match[14] = tag1_val[0];
8632 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008633 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008634 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008635 *matchp = match;
8636 return 1;
8637 }
8638 if (tag1)
8639 {
Dave Barach72d72232016-08-04 10:15:08 -04008640 match[15] = tag1_val[1];
8641 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008642 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008643 {
8644 match[17] = proto_val & 0xff;
8645 match[16] = proto_val >> 8;
8646 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008647 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008648 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008649
8650 *matchp = match;
8651 return 1;
8652 }
8653 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008654 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008655 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008656 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008657 if (proto)
8658 {
8659 match[13] = proto_val & 0xff;
8660 match[12] = proto_val >> 8;
8661 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008662
Ed Warnickecb9cada2015-12-08 15:45:58 -07008663 *matchp = match;
8664 return 1;
8665}
8666
8667
Dave Barach72d72232016-08-04 10:15:08 -04008668uword
8669unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008670{
Dave Barach72d72232016-08-04 10:15:08 -04008671 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008672 u32 skip_n_vectors = va_arg (*args, u32);
8673 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008674
Dave Barach72d72232016-08-04 10:15:08 -04008675 u8 *match = 0;
8676 u8 *l2 = 0;
8677 u8 *l3 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008678
Dave Barach72d72232016-08-04 10:15:08 -04008679 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8680 {
8681 if (unformat (input, "hex %U", unformat_hex_string, &match))
8682 ;
8683 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8684 ;
8685 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8686 ;
8687 else
8688 break;
8689 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008690
8691 if (match || l2 || l3)
8692 {
8693 if (l2 || l3)
Dave Barach72d72232016-08-04 10:15:08 -04008694 {
8695 /* "Win a free Ethernet header in every packet" */
8696 if (l2 == 0)
8697 vec_validate_aligned (l2, 13, sizeof (u32x4));
8698 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008699 if (vec_len (l3))
8700 {
8701 vec_append_aligned (match, l3, sizeof (u32x4));
8702 vec_free (l3);
8703 }
Dave Barach72d72232016-08-04 10:15:08 -04008704 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008705
8706 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008707 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04008708 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8709 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008710
Dave Barach72d72232016-08-04 10:15:08 -04008711 /* Set size, include skipped vectors */
8712 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008713
8714 *matchp = match;
8715
8716 return 1;
8717 }
8718
8719 return 0;
8720}
8721
Dave Barach72d72232016-08-04 10:15:08 -04008722static int
8723api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008724{
Dave Barach72d72232016-08-04 10:15:08 -04008725 unformat_input_t *i = vam->input;
8726 vl_api_classify_add_del_session_t *mp;
8727 int is_add = 1;
8728 u32 table_index = ~0;
8729 u32 hit_next_index = ~0;
8730 u32 opaque_index = ~0;
8731 u8 *match = 0;
8732 i32 advance = 0;
8733 f64 timeout;
8734 u32 skip_n_vectors = 0;
8735 u32 match_n_vectors = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008736
Dave Barach72d72232016-08-04 10:15:08 -04008737 /*
8738 * Warning: you have to supply skip_n and match_n
8739 * because the API client cant simply look at the classify
8740 * table object.
8741 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07008742
Dave Barach72d72232016-08-04 10:15:08 -04008743 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8744 {
8745 if (unformat (i, "del"))
8746 is_add = 0;
8747 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
8748 &hit_next_index))
8749 ;
8750 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8751 &hit_next_index))
8752 ;
8753 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
8754 &hit_next_index))
8755 ;
8756 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8757 ;
8758 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8759 ;
8760 else if (unformat (i, "opaque-index %d", &opaque_index))
8761 ;
8762 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8763 ;
8764 else if (unformat (i, "match_n %d", &match_n_vectors))
8765 ;
8766 else if (unformat (i, "match %U", unformat_classify_match,
8767 &match, skip_n_vectors, match_n_vectors))
8768 ;
8769 else if (unformat (i, "advance %d", &advance))
8770 ;
8771 else if (unformat (i, "table-index %d", &table_index))
8772 ;
8773 else
8774 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008775 }
8776
Dave Barach72d72232016-08-04 10:15:08 -04008777 if (table_index == ~0)
8778 {
8779 errmsg ("Table index required\n");
8780 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008781 }
8782
Dave Barach72d72232016-08-04 10:15:08 -04008783 if (is_add && match == 0)
8784 {
8785 errmsg ("Match value required\n");
8786 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008787 }
8788
Dave Barach72d72232016-08-04 10:15:08 -04008789 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008790
Dave Barach72d72232016-08-04 10:15:08 -04008791 mp->is_add = is_add;
8792 mp->table_index = ntohl (table_index);
8793 mp->hit_next_index = ntohl (hit_next_index);
8794 mp->opaque_index = ntohl (opaque_index);
8795 mp->advance = ntohl (advance);
8796 clib_memcpy (mp->match, match, vec_len (match));
8797 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008798
Dave Barach72d72232016-08-04 10:15:08 -04008799 S;
8800 W;
8801 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07008802}
8803
Dave Barach72d72232016-08-04 10:15:08 -04008804static int
8805api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008806{
Dave Barach72d72232016-08-04 10:15:08 -04008807 unformat_input_t *i = vam->input;
8808 vl_api_classify_set_interface_ip_table_t *mp;
8809 f64 timeout;
8810 u32 sw_if_index;
8811 int sw_if_index_set;
8812 u32 table_index = ~0;
8813 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008814
Dave Barach72d72232016-08-04 10:15:08 -04008815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8816 {
8817 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8818 sw_if_index_set = 1;
8819 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8820 sw_if_index_set = 1;
8821 else if (unformat (i, "table %d", &table_index))
8822 ;
8823 else
8824 {
8825 clib_warning ("parse error '%U'", format_unformat_error, i);
8826 return -99;
8827 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008828 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008829
Dave Barach72d72232016-08-04 10:15:08 -04008830 if (sw_if_index_set == 0)
8831 {
8832 errmsg ("missing interface name or sw_if_index\n");
8833 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008834 }
8835
8836
Dave Barach72d72232016-08-04 10:15:08 -04008837 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008838
Dave Barach72d72232016-08-04 10:15:08 -04008839 mp->sw_if_index = ntohl (sw_if_index);
8840 mp->table_index = ntohl (table_index);
8841 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008842
Dave Barach72d72232016-08-04 10:15:08 -04008843 S;
8844 W;
8845 /* NOTREACHED */
8846 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008847}
8848
Dave Barach72d72232016-08-04 10:15:08 -04008849static int
8850api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008851{
Dave Barach72d72232016-08-04 10:15:08 -04008852 unformat_input_t *i = vam->input;
8853 vl_api_classify_set_interface_l2_tables_t *mp;
8854 f64 timeout;
8855 u32 sw_if_index;
8856 int sw_if_index_set;
8857 u32 ip4_table_index = ~0;
8858 u32 ip6_table_index = ~0;
8859 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04008860 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008861
Dave Barach72d72232016-08-04 10:15:08 -04008862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8863 {
8864 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8865 sw_if_index_set = 1;
8866 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8867 sw_if_index_set = 1;
8868 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8869 ;
8870 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8871 ;
8872 else if (unformat (i, "other-table %d", &other_table_index))
8873 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04008874 else if (unformat (i, "is-input %d", &is_input))
8875 ;
Dave Barach72d72232016-08-04 10:15:08 -04008876 else
8877 {
8878 clib_warning ("parse error '%U'", format_unformat_error, i);
8879 return -99;
8880 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008881 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008882
Dave Barach72d72232016-08-04 10:15:08 -04008883 if (sw_if_index_set == 0)
8884 {
8885 errmsg ("missing interface name or sw_if_index\n");
8886 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008887 }
8888
8889
Dave Barach72d72232016-08-04 10:15:08 -04008890 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008891
Dave Barach72d72232016-08-04 10:15:08 -04008892 mp->sw_if_index = ntohl (sw_if_index);
8893 mp->ip4_table_index = ntohl (ip4_table_index);
8894 mp->ip6_table_index = ntohl (ip6_table_index);
8895 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04008896 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008897
Dave Barach72d72232016-08-04 10:15:08 -04008898 S;
8899 W;
8900 /* NOTREACHED */
8901 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008902}
8903
Dave Barach72d72232016-08-04 10:15:08 -04008904static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008905api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008906{
Dave Barach72d72232016-08-04 10:15:08 -04008907 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008908 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04008909 ip4_address_t collector_address;
8910 u8 collector_address_set = 0;
8911 u32 collector_port = ~0;
8912 ip4_address_t src_address;
8913 u8 src_address_set = 0;
8914 u32 vrf_id = ~0;
8915 u32 path_mtu = ~0;
8916 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008917 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008918 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008919
Dave Barach72d72232016-08-04 10:15:08 -04008920 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8921 {
8922 if (unformat (i, "collector_address %U", unformat_ip4_address,
8923 &collector_address))
8924 collector_address_set = 1;
8925 else if (unformat (i, "collector_port %d", &collector_port))
8926 ;
8927 else if (unformat (i, "src_address %U", unformat_ip4_address,
8928 &src_address))
8929 src_address_set = 1;
8930 else if (unformat (i, "vrf_id %d", &vrf_id))
8931 ;
8932 else if (unformat (i, "path_mtu %d", &path_mtu))
8933 ;
8934 else if (unformat (i, "template_interval %d", &template_interval))
8935 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008936 else if (unformat (i, "udp_checksum"))
8937 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04008938 else
8939 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008940 }
8941
Dave Barach72d72232016-08-04 10:15:08 -04008942 if (collector_address_set == 0)
8943 {
8944 errmsg ("collector_address required\n");
8945 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008946 }
8947
Dave Barach72d72232016-08-04 10:15:08 -04008948 if (src_address_set == 0)
8949 {
8950 errmsg ("src_address required\n");
8951 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008952 }
8953
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008954 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008955
Dave Barach72d72232016-08-04 10:15:08 -04008956 memcpy (mp->collector_address, collector_address.data,
8957 sizeof (collector_address.data));
8958 mp->collector_port = htons ((u16) collector_port);
8959 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
8960 mp->vrf_id = htonl (vrf_id);
8961 mp->path_mtu = htonl (path_mtu);
8962 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008963 mp->udp_checksum = udp_checksum;
8964
8965 S;
8966 W;
8967 /* NOTREACHED */
8968}
8969
8970static int
8971api_set_ipfix_classify_stream (vat_main_t * vam)
8972{
8973 unformat_input_t *i = vam->input;
8974 vl_api_set_ipfix_classify_stream_t *mp;
8975 u32 domain_id = 0;
8976 u32 src_port = UDP_DST_PORT_ipfix;
8977 f64 timeout;
8978
8979 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8980 {
8981 if (unformat (i, "domain %d", &domain_id))
8982 ;
8983 else if (unformat (i, "src_port %d", &src_port))
8984 ;
8985 else
8986 {
8987 errmsg ("unknown input `%U'", format_unformat_error, i);
8988 return -99;
8989 }
8990 }
8991
8992 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
8993
8994 mp->domain_id = htonl (domain_id);
8995 mp->src_port = htons ((u16) src_port);
8996
8997 S;
8998 W;
8999 /* NOTREACHED */
9000}
9001
9002static int
9003api_ipfix_classify_table_add_del (vat_main_t * vam)
9004{
9005 unformat_input_t *i = vam->input;
9006 vl_api_ipfix_classify_table_add_del_t *mp;
9007 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009008 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009009 u8 ip_version = 0;
9010 u8 transport_protocol = 255;
9011 f64 timeout;
9012
9013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9014 {
9015 if (unformat (i, "add"))
9016 is_add = 1;
9017 else if (unformat (i, "del"))
9018 is_add = 0;
9019 else if (unformat (i, "table %d", &classify_table_index))
9020 ;
9021 else if (unformat (i, "ip4"))
9022 ip_version = 4;
9023 else if (unformat (i, "ip6"))
9024 ip_version = 6;
9025 else if (unformat (i, "tcp"))
9026 transport_protocol = 6;
9027 else if (unformat (i, "udp"))
9028 transport_protocol = 17;
9029 else
9030 {
9031 errmsg ("unknown input `%U'", format_unformat_error, i);
9032 return -99;
9033 }
9034 }
9035
9036 if (is_add == -1)
9037 {
9038 errmsg ("expecting: add|del");
9039 return -99;
9040 }
9041 if (classify_table_index == ~0)
9042 {
9043 errmsg ("classifier table not specified");
9044 return -99;
9045 }
9046 if (ip_version == 0)
9047 {
9048 errmsg ("IP version not specified");
9049 return -99;
9050 }
9051
9052 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9053
9054 mp->is_add = is_add;
9055 mp->table_id = htonl (classify_table_index);
9056 mp->ip_version = ip_version;
9057 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009058
Dave Barach72d72232016-08-04 10:15:08 -04009059 S;
9060 W;
9061 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009062}
9063
Dave Barach72d72232016-08-04 10:15:08 -04009064static int
9065api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009066{
Dave Barach72d72232016-08-04 10:15:08 -04009067 unformat_input_t *i = vam->input;
9068 vl_api_get_node_index_t *mp;
9069 f64 timeout;
9070 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009071
Dave Barach72d72232016-08-04 10:15:08 -04009072 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9073 {
9074 if (unformat (i, "node %s", &name))
9075 ;
9076 else
9077 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009078 }
Dave Barach72d72232016-08-04 10:15:08 -04009079 if (name == 0)
9080 {
9081 errmsg ("node name required\n");
9082 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009083 }
Dave Barach72d72232016-08-04 10:15:08 -04009084 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9085 {
9086 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9087 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009088 }
9089
Dave Barach72d72232016-08-04 10:15:08 -04009090 M (GET_NODE_INDEX, get_node_index);
9091 clib_memcpy (mp->node_name, name, vec_len (name));
9092 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009093
Dave Barach72d72232016-08-04 10:15:08 -04009094 S;
9095 W;
9096 /* NOTREACHED */
9097 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009098}
9099
Dave Barach72d72232016-08-04 10:15:08 -04009100static int
9101api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009102{
Dave Barach72d72232016-08-04 10:15:08 -04009103 unformat_input_t *i = vam->input;
9104 vl_api_get_next_index_t *mp;
9105 f64 timeout;
9106 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009107
Dave Barach72d72232016-08-04 10:15:08 -04009108 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9109 {
9110 if (unformat (i, "node-name %s", &node_name))
9111 ;
9112 else if (unformat (i, "next-node-name %s", &next_node_name))
9113 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009114 }
9115
Dave Barach72d72232016-08-04 10:15:08 -04009116 if (node_name == 0)
9117 {
9118 errmsg ("node name required\n");
9119 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009120 }
Dave Barach72d72232016-08-04 10:15:08 -04009121 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9122 {
9123 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9124 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009125 }
9126
Dave Barach72d72232016-08-04 10:15:08 -04009127 if (next_node_name == 0)
9128 {
9129 errmsg ("next node name required\n");
9130 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009131 }
Dave Barach72d72232016-08-04 10:15:08 -04009132 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9133 {
9134 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9135 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009136 }
9137
Dave Barach72d72232016-08-04 10:15:08 -04009138 M (GET_NEXT_INDEX, get_next_index);
9139 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9140 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9141 vec_free (node_name);
9142 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009143
Dave Barach72d72232016-08-04 10:15:08 -04009144 S;
9145 W;
9146 /* NOTREACHED */
9147 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009148}
9149
Dave Barach72d72232016-08-04 10:15:08 -04009150static int
9151api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009152{
Dave Barach72d72232016-08-04 10:15:08 -04009153 unformat_input_t *i = vam->input;
9154 vl_api_add_node_next_t *mp;
9155 f64 timeout;
9156 u8 *name = 0;
9157 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009158
Dave Barach72d72232016-08-04 10:15:08 -04009159 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9160 {
9161 if (unformat (i, "node %s", &name))
9162 ;
9163 else if (unformat (i, "next %s", &next))
9164 ;
9165 else
9166 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009167 }
Dave Barach72d72232016-08-04 10:15:08 -04009168 if (name == 0)
9169 {
9170 errmsg ("node name required\n");
9171 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009172 }
Dave Barach72d72232016-08-04 10:15:08 -04009173 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9174 {
9175 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9176 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009177 }
Dave Barach72d72232016-08-04 10:15:08 -04009178 if (next == 0)
9179 {
9180 errmsg ("next node required\n");
9181 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009182 }
Dave Barach72d72232016-08-04 10:15:08 -04009183 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9184 {
9185 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9186 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009187 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009188
Dave Barach72d72232016-08-04 10:15:08 -04009189 M (ADD_NODE_NEXT, add_node_next);
9190 clib_memcpy (mp->node_name, name, vec_len (name));
9191 clib_memcpy (mp->next_name, next, vec_len (next));
9192 vec_free (name);
9193 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009194
Dave Barach72d72232016-08-04 10:15:08 -04009195 S;
9196 W;
9197 /* NOTREACHED */
9198 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009199}
9200
Dave Barach72d72232016-08-04 10:15:08 -04009201static int
9202api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009203{
Dave Barach72d72232016-08-04 10:15:08 -04009204 unformat_input_t *i = vam->input;
9205 ip6_address_t client_address, our_address;
9206 int client_address_set = 0;
9207 int our_address_set = 0;
9208 u32 local_session_id = 0;
9209 u32 remote_session_id = 0;
9210 u64 local_cookie = 0;
9211 u64 remote_cookie = 0;
9212 u8 l2_sublayer_present = 0;
9213 vl_api_l2tpv3_create_tunnel_t *mp;
9214 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009215
Dave Barach72d72232016-08-04 10:15:08 -04009216 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9217 {
9218 if (unformat (i, "client_address %U", unformat_ip6_address,
9219 &client_address))
9220 client_address_set = 1;
9221 else if (unformat (i, "our_address %U", unformat_ip6_address,
9222 &our_address))
9223 our_address_set = 1;
9224 else if (unformat (i, "local_session_id %d", &local_session_id))
9225 ;
9226 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9227 ;
9228 else if (unformat (i, "local_cookie %lld", &local_cookie))
9229 ;
9230 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9231 ;
9232 else if (unformat (i, "l2-sublayer-present"))
9233 l2_sublayer_present = 1;
9234 else
9235 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009236 }
9237
Dave Barach72d72232016-08-04 10:15:08 -04009238 if (client_address_set == 0)
9239 {
9240 errmsg ("client_address required\n");
9241 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009242 }
9243
Dave Barach72d72232016-08-04 10:15:08 -04009244 if (our_address_set == 0)
9245 {
9246 errmsg ("our_address required\n");
9247 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009248 }
9249
Dave Barach72d72232016-08-04 10:15:08 -04009250 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009251
Dave Barach72d72232016-08-04 10:15:08 -04009252 clib_memcpy (mp->client_address, client_address.as_u8,
9253 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009254
Dave Barach72d72232016-08-04 10:15:08 -04009255 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009256
Dave Barach72d72232016-08-04 10:15:08 -04009257 mp->local_session_id = ntohl (local_session_id);
9258 mp->remote_session_id = ntohl (remote_session_id);
9259 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9260 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9261 mp->l2_sublayer_present = l2_sublayer_present;
9262 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009263
Dave Barach72d72232016-08-04 10:15:08 -04009264 S;
9265 W;
9266 /* NOTREACHED */
9267 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009268}
9269
Dave Barach72d72232016-08-04 10:15:08 -04009270static int
9271api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009272{
Dave Barach72d72232016-08-04 10:15:08 -04009273 unformat_input_t *i = vam->input;
9274 u32 sw_if_index;
9275 u8 sw_if_index_set = 0;
9276 u64 new_local_cookie = 0;
9277 u64 new_remote_cookie = 0;
9278 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9279 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009280
Dave Barach72d72232016-08-04 10:15:08 -04009281 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9282 {
9283 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9284 sw_if_index_set = 1;
9285 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9286 sw_if_index_set = 1;
9287 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9288 ;
9289 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
9290 ;
9291 else
9292 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009293 }
9294
Dave Barach72d72232016-08-04 10:15:08 -04009295 if (sw_if_index_set == 0)
9296 {
9297 errmsg ("missing interface name or sw_if_index\n");
9298 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009299 }
9300
Dave Barach72d72232016-08-04 10:15:08 -04009301 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009302
Dave Barach72d72232016-08-04 10:15:08 -04009303 mp->sw_if_index = ntohl (sw_if_index);
9304 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
9305 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009306
Dave Barach72d72232016-08-04 10:15:08 -04009307 S;
9308 W;
9309 /* NOTREACHED */
9310 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009311}
9312
Dave Barach72d72232016-08-04 10:15:08 -04009313static int
9314api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009315{
Dave Barach72d72232016-08-04 10:15:08 -04009316 unformat_input_t *i = vam->input;
9317 vl_api_l2tpv3_interface_enable_disable_t *mp;
9318 f64 timeout;
9319 u32 sw_if_index;
9320 u8 sw_if_index_set = 0;
9321 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009322
Dave Barach72d72232016-08-04 10:15:08 -04009323 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9324 {
9325 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9326 sw_if_index_set = 1;
9327 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9328 sw_if_index_set = 1;
9329 else if (unformat (i, "enable"))
9330 enable_disable = 1;
9331 else if (unformat (i, "disable"))
9332 enable_disable = 0;
9333 else
9334 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009335 }
9336
Dave Barach72d72232016-08-04 10:15:08 -04009337 if (sw_if_index_set == 0)
9338 {
9339 errmsg ("missing interface name or sw_if_index\n");
9340 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009341 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009342
Dave Barach72d72232016-08-04 10:15:08 -04009343 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009344
Dave Barach72d72232016-08-04 10:15:08 -04009345 mp->sw_if_index = ntohl (sw_if_index);
9346 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009347
Dave Barach72d72232016-08-04 10:15:08 -04009348 S;
9349 W;
9350 /* NOTREACHED */
9351 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009352}
9353
Dave Barach72d72232016-08-04 10:15:08 -04009354static int
9355api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009356{
Dave Barach72d72232016-08-04 10:15:08 -04009357 unformat_input_t *i = vam->input;
9358 vl_api_l2tpv3_set_lookup_key_t *mp;
9359 f64 timeout;
9360 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009361
Dave Barach72d72232016-08-04 10:15:08 -04009362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9363 {
9364 if (unformat (i, "lookup_v6_src"))
9365 key = L2T_LOOKUP_SRC_ADDRESS;
9366 else if (unformat (i, "lookup_v6_dst"))
9367 key = L2T_LOOKUP_DST_ADDRESS;
9368 else if (unformat (i, "lookup_session_id"))
9369 key = L2T_LOOKUP_SESSION_ID;
9370 else
9371 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009372 }
9373
Dave Barach72d72232016-08-04 10:15:08 -04009374 if (key == (u8) ~ 0)
9375 {
9376 errmsg ("l2tp session lookup key unset\n");
9377 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009378 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009379
Dave Barach72d72232016-08-04 10:15:08 -04009380 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009381
Dave Barach72d72232016-08-04 10:15:08 -04009382 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009383
Dave Barach72d72232016-08-04 10:15:08 -04009384 S;
9385 W;
9386 /* NOTREACHED */
9387 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009388}
9389
9390static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009391 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009392{
Dave Barach72d72232016-08-04 10:15:08 -04009393 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009394
Dave Barach72d72232016-08-04 10:15:08 -04009395 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
9396 format_ip6_address, mp->our_address,
9397 format_ip6_address, mp->client_address,
9398 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009399
Dave Barach72d72232016-08-04 10:15:08 -04009400 fformat (vam->ofp,
9401 " local cookies %016llx %016llx remote cookie %016llx\n",
9402 clib_net_to_host_u64 (mp->local_cookie[0]),
9403 clib_net_to_host_u64 (mp->local_cookie[1]),
9404 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009405
Dave Barach72d72232016-08-04 10:15:08 -04009406 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
9407 clib_net_to_host_u32 (mp->local_session_id),
9408 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009409
Dave Barach72d72232016-08-04 10:15:08 -04009410 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
9411 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009412
9413}
9414
9415static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009416 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009417{
Dave Barach72d72232016-08-04 10:15:08 -04009418 vat_main_t *vam = &vat_main;
9419 vat_json_node_t *node = NULL;
9420 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009421
Dave Barach72d72232016-08-04 10:15:08 -04009422 if (VAT_JSON_ARRAY != vam->json_tree.type)
9423 {
9424 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9425 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009426 }
Dave Barach72d72232016-08-04 10:15:08 -04009427 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009428
Dave Barach72d72232016-08-04 10:15:08 -04009429 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009430
Dave Barach72d72232016-08-04 10:15:08 -04009431 clib_memcpy (&addr, mp->our_address, sizeof (addr));
9432 vat_json_object_add_ip6 (node, "our_address", addr);
9433 clib_memcpy (&addr, mp->client_address, sizeof (addr));
9434 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009435
Dave Barach72d72232016-08-04 10:15:08 -04009436 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
9437 vat_json_init_array (lc);
9438 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
9439 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
9440 vat_json_object_add_uint (node, "remote_cookie",
9441 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009442
Dave Barach72d72232016-08-04 10:15:08 -04009443 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
9444 vat_json_object_add_uint (node, "local_session_id",
9445 clib_net_to_host_u32 (mp->local_session_id));
9446 vat_json_object_add_uint (node, "remote_session_id",
9447 clib_net_to_host_u32 (mp->remote_session_id));
9448 vat_json_object_add_string_copy (node, "l2_sublayer",
9449 mp->l2_sublayer_present ? (u8 *) "present"
9450 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009451}
9452
Dave Barach72d72232016-08-04 10:15:08 -04009453static int
9454api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009455{
Dave Barach72d72232016-08-04 10:15:08 -04009456 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
9457 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009458
Dave Barach72d72232016-08-04 10:15:08 -04009459 /* Get list of l2tpv3-tunnel interfaces */
9460 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
9461 S;
9462
9463 /* Use a control ping for synchronization */
9464 {
9465 vl_api_control_ping_t *mp;
9466 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009467 S;
Dave Barach72d72232016-08-04 10:15:08 -04009468 }
9469 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009470}
9471
9472
9473static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009474 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009475{
Dave Barach72d72232016-08-04 10:15:08 -04009476 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009477
Dave Barach72d72232016-08-04 10:15:08 -04009478 fformat (vam->ofp, "%-16s %d\n",
9479 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009480}
9481
9482static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009483 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009484{
Dave Barach72d72232016-08-04 10:15:08 -04009485 vat_main_t *vam = &vat_main;
9486 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009487
Dave Barach72d72232016-08-04 10:15:08 -04009488 if (VAT_JSON_ARRAY != vam->json_tree.type)
9489 {
9490 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9491 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009492 }
Dave Barach72d72232016-08-04 10:15:08 -04009493 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009494
Dave Barach72d72232016-08-04 10:15:08 -04009495 vat_json_init_object (node);
9496 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9497 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009498}
9499
Dave Barach72d72232016-08-04 10:15:08 -04009500static int
9501api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009502{
Dave Barach72d72232016-08-04 10:15:08 -04009503 vl_api_sw_interface_tap_dump_t *mp;
9504 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009505
Dave Barach72d72232016-08-04 10:15:08 -04009506 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
9507 /* Get list of tap interfaces */
9508 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
9509 S;
9510
9511 /* Use a control ping for synchronization */
9512 {
9513 vl_api_control_ping_t *mp;
9514 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009515 S;
Dave Barach72d72232016-08-04 10:15:08 -04009516 }
9517 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009518}
9519
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009520static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -04009521 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009522{
Dave Barach72d72232016-08-04 10:15:08 -04009523 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009524 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009525
Ed Warnickecb9cada2015-12-08 15:45:58 -07009526 if (unformat (input, "drop"))
9527 *result = VXLAN_INPUT_NEXT_DROP;
9528 else if (unformat (input, "ip4"))
9529 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
9530 else if (unformat (input, "ip6"))
9531 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
9532 else if (unformat (input, "l2"))
9533 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9534 else if (unformat (input, "%d", &tmp))
9535 *result = tmp;
9536 else
9537 return 0;
9538 return 1;
9539}
9540
Dave Barach72d72232016-08-04 10:15:08 -04009541static int
9542api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009543{
Dave Barach72d72232016-08-04 10:15:08 -04009544 unformat_input_t *line_input = vam->input;
9545 vl_api_vxlan_add_del_tunnel_t *mp;
9546 f64 timeout;
9547 ip4_address_t src4, dst4;
9548 ip6_address_t src6, dst6;
9549 u8 is_add = 1;
9550 u8 ipv4_set = 0, ipv6_set = 0;
9551 u8 src_set = 0;
9552 u8 dst_set = 0;
9553 u32 encap_vrf_id = 0;
9554 u32 decap_next_index = ~0;
9555 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009556
Dave Barach72d72232016-08-04 10:15:08 -04009557 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9558 {
9559 if (unformat (line_input, "del"))
9560 is_add = 0;
9561 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
9562 {
9563 ipv4_set = 1;
9564 src_set = 1;
9565 }
9566 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
9567 {
9568 ipv4_set = 1;
9569 dst_set = 1;
9570 }
9571 else if (unformat (line_input, "src %U", unformat_ip6_address, &src6))
9572 {
9573 ipv6_set = 1;
9574 src_set = 1;
9575 }
9576 else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst6))
9577 {
9578 ipv6_set = 1;
9579 dst_set = 1;
9580 }
9581 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9582 ;
9583 else if (unformat (line_input, "decap-next %U",
9584 unformat_vxlan_decap_next, &decap_next_index))
9585 ;
9586 else if (unformat (line_input, "vni %d", &vni))
9587 ;
9588 else
9589 {
9590 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9591 return -99;
9592 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009593 }
9594
Dave Barach72d72232016-08-04 10:15:08 -04009595 if (src_set == 0)
9596 {
9597 errmsg ("tunnel src address not specified\n");
9598 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009599 }
Dave Barach72d72232016-08-04 10:15:08 -04009600 if (dst_set == 0)
9601 {
9602 errmsg ("tunnel dst address not specified\n");
9603 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009604 }
9605
Dave Barach72d72232016-08-04 10:15:08 -04009606 if (ipv4_set && ipv6_set)
9607 {
9608 errmsg ("both IPv4 and IPv6 addresses specified");
9609 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -04009610 }
9611
Dave Barach72d72232016-08-04 10:15:08 -04009612 if ((vni == 0) || (vni >> 24))
9613 {
9614 errmsg ("vni not specified or out of range\n");
9615 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009616 }
9617
Dave Barach72d72232016-08-04 10:15:08 -04009618 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -04009619
Dave Barach72d72232016-08-04 10:15:08 -04009620 if (ipv6_set)
9621 {
9622 clib_memcpy (&mp->src_address, &src6, sizeof (src6));
9623 clib_memcpy (&mp->dst_address, &dst6, sizeof (dst6));
Chris Luke99cb3352016-04-26 10:49:53 -04009624 }
Dave Barach72d72232016-08-04 10:15:08 -04009625 else
9626 {
9627 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
9628 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
9629 }
9630 mp->encap_vrf_id = ntohl (encap_vrf_id);
9631 mp->decap_next_index = ntohl (decap_next_index);
9632 mp->vni = ntohl (vni);
9633 mp->is_add = is_add;
9634 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009635
Dave Barach72d72232016-08-04 10:15:08 -04009636 S;
9637 W;
9638 /* NOTREACHED */
9639 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009640}
9641
Dave Wallace60231f32015-12-17 21:04:30 -05009642static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009643 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -05009644{
Dave Barach72d72232016-08-04 10:15:08 -04009645 vat_main_t *vam = &vat_main;
Dave Wallace60231f32015-12-17 21:04:30 -05009646
Dave Barach72d72232016-08-04 10:15:08 -04009647 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
9648 ntohl (mp->sw_if_index),
9649 format_ip46_address, &(mp->src_address[0]),
9650 IP46_TYPE_ANY,
9651 format_ip46_address, &(mp->dst_address[0]),
9652 IP46_TYPE_ANY,
9653 ntohl (mp->encap_vrf_id),
9654 ntohl (mp->decap_next_index), ntohl (mp->vni));
Dave Wallace60231f32015-12-17 21:04:30 -05009655}
9656
9657static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009658 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -05009659{
Dave Barach72d72232016-08-04 10:15:08 -04009660 vat_main_t *vam = &vat_main;
9661 vat_json_node_t *node = NULL;
9662 struct in_addr ip4;
9663 struct in6_addr ip6;
Dave Wallace60231f32015-12-17 21:04:30 -05009664
Dave Barach72d72232016-08-04 10:15:08 -04009665 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -05009666 {
Dave Barach72d72232016-08-04 10:15:08 -04009667 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9668 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -05009669 }
Dave Barach72d72232016-08-04 10:15:08 -04009670 node = vat_json_array_add (&vam->json_tree);
9671
9672 vat_json_init_object (node);
9673 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9674 if (mp->is_ipv6)
9675 {
9676 clib_memcpy (&ip6, &(mp->src_address[0]), sizeof (ip6));
9677 vat_json_object_add_ip6 (node, "src_address", ip6);
9678 clib_memcpy (&ip6, &(mp->dst_address[0]), sizeof (ip6));
9679 vat_json_object_add_ip6 (node, "dst_address", ip6);
9680 }
9681 else
9682 {
9683 clib_memcpy (&ip4, &(mp->src_address[0]), sizeof (ip4));
9684 vat_json_object_add_ip4 (node, "src_address", ip4);
9685 clib_memcpy (&ip4, &(mp->dst_address[0]), sizeof (ip4));
9686 vat_json_object_add_ip4 (node, "dst_address", ip4);
9687 }
9688 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9689 vat_json_object_add_uint (node, "decap_next_index",
9690 ntohl (mp->decap_next_index));
9691 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9692 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Dave Wallace60231f32015-12-17 21:04:30 -05009693}
9694
Dave Barach72d72232016-08-04 10:15:08 -04009695static int
9696api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -04009697{
Dave Barach72d72232016-08-04 10:15:08 -04009698 unformat_input_t *i = vam->input;
9699 vl_api_vxlan_tunnel_dump_t *mp;
9700 f64 timeout;
9701 u32 sw_if_index;
9702 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009703
Dave Barach72d72232016-08-04 10:15:08 -04009704 /* Parse args required to build the message */
9705 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9706 {
9707 if (unformat (i, "sw_if_index %d", &sw_if_index))
9708 sw_if_index_set = 1;
9709 else
9710 break;
Chris Luke27fe48f2016-04-28 13:44:38 -04009711 }
9712
Dave Barach72d72232016-08-04 10:15:08 -04009713 if (sw_if_index_set == 0)
9714 {
9715 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009716 }
Dave Barach72d72232016-08-04 10:15:08 -04009717
9718 if (!vam->json_output)
9719 {
9720 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
9721 "sw_if_index", "src_address", "dst_address",
9722 "encap_vrf_id", "decap_next_index", "vni");
9723 }
9724
9725 /* Get list of vxlan-tunnel interfaces */
9726 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
9727
9728 mp->sw_if_index = htonl (sw_if_index);
9729
9730 S;
9731
9732 /* Use a control ping for synchronization */
9733 {
9734 vl_api_control_ping_t *mp;
9735 M (CONTROL_PING, control_ping);
9736 S;
9737 }
9738 W;
9739}
9740
9741static int
9742api_gre_add_del_tunnel (vat_main_t * vam)
9743{
9744 unformat_input_t *line_input = vam->input;
9745 vl_api_gre_add_del_tunnel_t *mp;
9746 f64 timeout;
9747 ip4_address_t src4, dst4;
9748 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -07009749 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009750 u8 src_set = 0;
9751 u8 dst_set = 0;
9752 u32 outer_fib_id = 0;
9753
9754 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9755 {
9756 if (unformat (line_input, "del"))
9757 is_add = 0;
9758 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
9759 src_set = 1;
9760 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
9761 dst_set = 1;
9762 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
9763 ;
David Hothama8cd3092016-09-19 09:55:07 -07009764 else if (unformat (line_input, "teb"))
9765 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009766 else
9767 {
9768 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9769 return -99;
9770 }
9771 }
9772
9773 if (src_set == 0)
9774 {
9775 errmsg ("tunnel src address not specified\n");
9776 return -99;
9777 }
9778 if (dst_set == 0)
9779 {
9780 errmsg ("tunnel dst address not specified\n");
9781 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -04009782 }
9783
9784
Dave Barach72d72232016-08-04 10:15:08 -04009785 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -04009786
Dave Barach72d72232016-08-04 10:15:08 -04009787 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
9788 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
9789 mp->outer_fib_id = ntohl (outer_fib_id);
9790 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -07009791 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -04009792
Dave Barach72d72232016-08-04 10:15:08 -04009793 S;
9794 W;
9795 /* NOTREACHED */
9796 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009797}
9798
9799static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009800 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04009801{
Dave Barach72d72232016-08-04 10:15:08 -04009802 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -04009803
David Hothama8cd3092016-09-19 09:55:07 -07009804 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -04009805 ntohl (mp->sw_if_index),
9806 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -07009807 format_ip4_address, &mp->dst_address,
9808 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -04009809}
9810
9811static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009812 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04009813{
Dave Barach72d72232016-08-04 10:15:08 -04009814 vat_main_t *vam = &vat_main;
9815 vat_json_node_t *node = NULL;
9816 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -04009817
Dave Barach72d72232016-08-04 10:15:08 -04009818 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -04009819 {
Dave Barach72d72232016-08-04 10:15:08 -04009820 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9821 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -04009822 }
Dave Barach72d72232016-08-04 10:15:08 -04009823 node = vat_json_array_add (&vam->json_tree);
9824
9825 vat_json_init_object (node);
9826 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9827 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
9828 vat_json_object_add_ip4 (node, "src_address", ip4);
9829 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
9830 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -07009831 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -04009832 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -04009833}
9834
Dave Barach72d72232016-08-04 10:15:08 -04009835static int
9836api_gre_tunnel_dump (vat_main_t * vam)
9837{
9838 unformat_input_t *i = vam->input;
9839 vl_api_gre_tunnel_dump_t *mp;
9840 f64 timeout;
9841 u32 sw_if_index;
9842 u8 sw_if_index_set = 0;
9843
9844 /* Parse args required to build the message */
9845 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9846 {
9847 if (unformat (i, "sw_if_index %d", &sw_if_index))
9848 sw_if_index_set = 1;
9849 else
9850 break;
9851 }
9852
9853 if (sw_if_index_set == 0)
9854 {
9855 sw_if_index = ~0;
9856 }
9857
9858 if (!vam->json_output)
9859 {
David Hothama8cd3092016-09-19 09:55:07 -07009860 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
9861 "sw_if_index", "src_address", "dst_address", "teb",
9862 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -04009863 }
9864
9865 /* Get list of gre-tunnel interfaces */
9866 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
9867
9868 mp->sw_if_index = htonl (sw_if_index);
9869
9870 S;
9871
9872 /* Use a control ping for synchronization */
9873 {
9874 vl_api_control_ping_t *mp;
9875 M (CONTROL_PING, control_ping);
9876 S;
9877 }
9878 W;
9879}
9880
9881static int
9882api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009883{
9884// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -04009885 vl_api_l2_fib_clear_table_t *mp;
9886 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009887
Dave Barach72d72232016-08-04 10:15:08 -04009888 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009889
Dave Barach72d72232016-08-04 10:15:08 -04009890 S;
9891 W;
9892 /* NOTREACHED */
9893 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009894}
9895
Dave Barach72d72232016-08-04 10:15:08 -04009896static int
9897api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009898{
Dave Barach72d72232016-08-04 10:15:08 -04009899 unformat_input_t *i = vam->input;
9900 vl_api_l2_interface_efp_filter_t *mp;
9901 f64 timeout;
9902 u32 sw_if_index;
9903 u8 enable = 1;
9904 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009905
Dave Barach72d72232016-08-04 10:15:08 -04009906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9907 {
9908 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9909 sw_if_index_set = 1;
9910 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9911 sw_if_index_set = 1;
9912 else if (unformat (i, "enable"))
9913 enable = 1;
9914 else if (unformat (i, "disable"))
9915 enable = 0;
9916 else
9917 {
9918 clib_warning ("parse error '%U'", format_unformat_error, i);
9919 return -99;
9920 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009921 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009922
Dave Barach72d72232016-08-04 10:15:08 -04009923 if (sw_if_index_set == 0)
9924 {
9925 errmsg ("missing sw_if_index\n");
9926 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009927 }
9928
Dave Barach72d72232016-08-04 10:15:08 -04009929 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009930
Dave Barach72d72232016-08-04 10:15:08 -04009931 mp->sw_if_index = ntohl (sw_if_index);
9932 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009933
Dave Barach72d72232016-08-04 10:15:08 -04009934 S;
9935 W;
9936 /* NOTREACHED */
9937 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009938}
9939
9940#define foreach_vtr_op \
9941_("disable", L2_VTR_DISABLED) \
9942_("push-1", L2_VTR_PUSH_1) \
9943_("push-2", L2_VTR_PUSH_2) \
9944_("pop-1", L2_VTR_POP_1) \
9945_("pop-2", L2_VTR_POP_2) \
9946_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9947_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9948_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9949_("translate-2-2", L2_VTR_TRANSLATE_2_2)
9950
Dave Barach72d72232016-08-04 10:15:08 -04009951static int
9952api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009953{
Dave Barach72d72232016-08-04 10:15:08 -04009954 unformat_input_t *i = vam->input;
9955 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9956 f64 timeout;
9957 u32 sw_if_index;
9958 u8 sw_if_index_set = 0;
9959 u8 vtr_op_set = 0;
9960 u32 vtr_op = 0;
9961 u32 push_dot1q = 1;
9962 u32 tag1 = ~0;
9963 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009964
Dave Barach72d72232016-08-04 10:15:08 -04009965 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9966 {
9967 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9968 sw_if_index_set = 1;
9969 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9970 sw_if_index_set = 1;
9971 else if (unformat (i, "vtr_op %d", &vtr_op))
9972 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009973#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -04009974 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -07009975#undef _
Dave Barach72d72232016-08-04 10:15:08 -04009976 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9977 ;
9978 else if (unformat (i, "tag1 %d", &tag1))
9979 ;
9980 else if (unformat (i, "tag2 %d", &tag2))
9981 ;
9982 else
9983 {
9984 clib_warning ("parse error '%U'", format_unformat_error, i);
9985 return -99;
9986 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009987 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009988
Dave Barach72d72232016-08-04 10:15:08 -04009989 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9990 {
9991 errmsg ("missing vtr operation or sw_if_index\n");
9992 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009993 }
9994
Dave Barach72d72232016-08-04 10:15:08 -04009995 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
9996 mp->sw_if_index = ntohl (sw_if_index);
9997 mp->vtr_op = ntohl (vtr_op);
9998 mp->push_dot1q = ntohl (push_dot1q);
9999 mp->tag1 = ntohl (tag1);
10000 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010001
Dave Barach72d72232016-08-04 10:15:08 -040010002 S;
10003 W;
10004 /* NOTREACHED */
10005 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010006}
10007
Dave Barach72d72232016-08-04 10:15:08 -040010008static int
10009api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010010{
Dave Barach72d72232016-08-04 10:15:08 -040010011 unformat_input_t *i = vam->input;
10012 vl_api_create_vhost_user_if_t *mp;
10013 f64 timeout;
10014 u8 *file_name;
10015 u8 is_server = 0;
10016 u8 file_name_set = 0;
10017 u32 custom_dev_instance = ~0;
10018 u8 hwaddr[6];
10019 u8 use_custom_mac = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010020
Dave Barach72d72232016-08-04 10:15:08 -040010021 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10022 {
10023 if (unformat (i, "socket %s", &file_name))
10024 {
10025 file_name_set = 1;
10026 }
10027 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10028 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010029 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010030 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010031 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010032 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010033 else
Dave Barach72d72232016-08-04 10:15:08 -040010034 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010035 }
10036
Dave Barach72d72232016-08-04 10:15:08 -040010037 if (file_name_set == 0)
10038 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010039 errmsg ("missing socket file name\n");
10040 return -99;
10041 }
10042
Dave Barach72d72232016-08-04 10:15:08 -040010043 if (vec_len (file_name) > 255)
10044 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010045 errmsg ("socket file name too long\n");
10046 return -99;
10047 }
Dave Barach72d72232016-08-04 10:15:08 -040010048 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010049
Dave Barach72d72232016-08-04 10:15:08 -040010050 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010051
Dave Barach72d72232016-08-04 10:15:08 -040010052 mp->is_server = is_server;
10053 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10054 vec_free (file_name);
10055 if (custom_dev_instance != ~0)
10056 {
10057 mp->renumber = 1;
10058 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010059 }
Dave Barach72d72232016-08-04 10:15:08 -040010060 mp->use_custom_mac = use_custom_mac;
10061 clib_memcpy (mp->mac_address, hwaddr, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010062
Dave Barach72d72232016-08-04 10:15:08 -040010063 S;
10064 W;
10065 /* NOTREACHED */
10066 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010067}
10068
Dave Barach72d72232016-08-04 10:15:08 -040010069static int
10070api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010071{
Dave Barach72d72232016-08-04 10:15:08 -040010072 unformat_input_t *i = vam->input;
10073 vl_api_modify_vhost_user_if_t *mp;
10074 f64 timeout;
10075 u8 *file_name;
10076 u8 is_server = 0;
10077 u8 file_name_set = 0;
10078 u32 custom_dev_instance = ~0;
10079 u8 sw_if_index_set = 0;
10080 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010081
Dave Barach72d72232016-08-04 10:15:08 -040010082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10083 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010084 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010085 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010086 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010087 sw_if_index_set = 1;
10088 else if (unformat (i, "socket %s", &file_name))
10089 {
10090 file_name_set = 1;
10091 }
10092 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10093 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010094 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010095 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010096 else
Dave Barach72d72232016-08-04 10:15:08 -040010097 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010098 }
10099
Dave Barach72d72232016-08-04 10:15:08 -040010100 if (sw_if_index_set == 0)
10101 {
10102 errmsg ("missing sw_if_index or interface name\n");
10103 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010104 }
10105
Dave Barach72d72232016-08-04 10:15:08 -040010106 if (file_name_set == 0)
10107 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010108 errmsg ("missing socket file name\n");
10109 return -99;
10110 }
10111
Dave Barach72d72232016-08-04 10:15:08 -040010112 if (vec_len (file_name) > 255)
10113 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010114 errmsg ("socket file name too long\n");
10115 return -99;
10116 }
Dave Barach72d72232016-08-04 10:15:08 -040010117 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010118
Dave Barach72d72232016-08-04 10:15:08 -040010119 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010120
Dave Barach72d72232016-08-04 10:15:08 -040010121 mp->sw_if_index = ntohl (sw_if_index);
10122 mp->is_server = is_server;
10123 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10124 vec_free (file_name);
10125 if (custom_dev_instance != ~0)
10126 {
10127 mp->renumber = 1;
10128 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010129 }
10130
Dave Barach72d72232016-08-04 10:15:08 -040010131 S;
10132 W;
10133 /* NOTREACHED */
10134 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010135}
10136
Dave Barach72d72232016-08-04 10:15:08 -040010137static int
10138api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010139{
Dave Barach72d72232016-08-04 10:15:08 -040010140 unformat_input_t *i = vam->input;
10141 vl_api_delete_vhost_user_if_t *mp;
10142 f64 timeout;
10143 u32 sw_if_index = ~0;
10144 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010145
Dave Barach72d72232016-08-04 10:15:08 -040010146 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10147 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010148 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010149 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010150 else if (unformat (i, "sw_if_index %d", &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
Dave Barach72d72232016-08-04 10:15:08 -040010153 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010154 }
10155
Dave Barach72d72232016-08-04 10:15:08 -040010156 if (sw_if_index_set == 0)
10157 {
10158 errmsg ("missing sw_if_index or interface name\n");
10159 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010160 }
10161
10162
Dave Barach72d72232016-08-04 10:15:08 -040010163 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010164
Dave Barach72d72232016-08-04 10:15:08 -040010165 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010166
Dave Barach72d72232016-08-04 10:15:08 -040010167 S;
10168 W;
10169 /* NOTREACHED */
10170 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010171}
10172
10173static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010174 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010175{
Dave Barach72d72232016-08-04 10:15:08 -040010176 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010177
Dave Barach72d72232016-08-04 10:15:08 -040010178 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10179 (char *) mp->interface_name,
10180 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10181 clib_net_to_host_u64 (mp->features), mp->is_server,
10182 ntohl (mp->num_regions), (char *) mp->sock_filename);
10183 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010184}
10185
10186static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010187 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010188{
Dave Barach72d72232016-08-04 10:15:08 -040010189 vat_main_t *vam = &vat_main;
10190 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010191
Dave Barach72d72232016-08-04 10:15:08 -040010192 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010193 {
Dave Barach72d72232016-08-04 10:15:08 -040010194 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10195 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010196 }
Dave Barach72d72232016-08-04 10:15:08 -040010197 node = vat_json_array_add (&vam->json_tree);
10198
10199 vat_json_init_object (node);
10200 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10201 vat_json_object_add_string_copy (node, "interface_name",
10202 mp->interface_name);
10203 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10204 ntohl (mp->virtio_net_hdr_sz));
10205 vat_json_object_add_uint (node, "features",
10206 clib_net_to_host_u64 (mp->features));
10207 vat_json_object_add_uint (node, "is_server", mp->is_server);
10208 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10209 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10210 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010211}
10212
Dave Barach72d72232016-08-04 10:15:08 -040010213static int
10214api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010215{
Dave Barach72d72232016-08-04 10:15:08 -040010216 vl_api_sw_interface_vhost_user_dump_t *mp;
10217 f64 timeout;
10218 fformat (vam->ofp,
10219 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010220
Dave Barach72d72232016-08-04 10:15:08 -040010221 /* Get list of vhost-user interfaces */
10222 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10223 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010224
Dave Barach72d72232016-08-04 10:15:08 -040010225 /* Use a control ping for synchronization */
10226 {
10227 vl_api_control_ping_t *mp;
10228 M (CONTROL_PING, control_ping);
10229 S;
10230 }
10231 W;
10232}
10233
10234static int
10235api_show_version (vat_main_t * vam)
10236{
10237 vl_api_show_version_t *mp;
10238 f64 timeout;
10239
10240 M (SHOW_VERSION, show_version);
10241
10242 S;
10243 W;
10244 /* NOTREACHED */
10245 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010246}
10247
Ed Warnickecb9cada2015-12-08 15:45:58 -070010248
Dave Barach72d72232016-08-04 10:15:08 -040010249static int
10250api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010251{
Dave Barach72d72232016-08-04 10:15:08 -040010252 unformat_input_t *line_input = vam->input;
10253 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10254 f64 timeout;
10255 ip4_address_t local4, remote4;
10256 ip6_address_t local6, remote6;
10257 u8 is_add = 1;
10258 u8 ipv4_set = 0, ipv6_set = 0;
10259 u8 local_set = 0;
10260 u8 remote_set = 0;
10261 u32 encap_vrf_id = 0;
10262 u32 decap_vrf_id = 0;
10263 u8 protocol = ~0;
10264 u32 vni;
10265 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010266
Dave Barach72d72232016-08-04 10:15:08 -040010267 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10268 {
10269 if (unformat (line_input, "del"))
10270 is_add = 0;
10271 else if (unformat (line_input, "local %U",
10272 unformat_ip4_address, &local4))
10273 {
10274 local_set = 1;
10275 ipv4_set = 1;
10276 }
10277 else if (unformat (line_input, "remote %U",
10278 unformat_ip4_address, &remote4))
10279 {
10280 remote_set = 1;
10281 ipv4_set = 1;
10282 }
10283 else if (unformat (line_input, "local %U",
10284 unformat_ip6_address, &local6))
10285 {
10286 local_set = 1;
10287 ipv6_set = 1;
10288 }
10289 else if (unformat (line_input, "remote %U",
10290 unformat_ip6_address, &remote6))
10291 {
10292 remote_set = 1;
10293 ipv6_set = 1;
10294 }
10295 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10296 ;
10297 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10298 ;
10299 else if (unformat (line_input, "vni %d", &vni))
10300 vni_set = 1;
10301 else if (unformat (line_input, "next-ip4"))
10302 protocol = 1;
10303 else if (unformat (line_input, "next-ip6"))
10304 protocol = 2;
10305 else if (unformat (line_input, "next-ethernet"))
10306 protocol = 3;
10307 else if (unformat (line_input, "next-nsh"))
10308 protocol = 4;
10309 else
10310 {
10311 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10312 return -99;
10313 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010314 }
10315
Dave Barach72d72232016-08-04 10:15:08 -040010316 if (local_set == 0)
10317 {
10318 errmsg ("tunnel local address not specified\n");
10319 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010320 }
Dave Barach72d72232016-08-04 10:15:08 -040010321 if (remote_set == 0)
10322 {
10323 errmsg ("tunnel remote address not specified\n");
10324 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010325 }
Dave Barach72d72232016-08-04 10:15:08 -040010326 if (ipv4_set && ipv6_set)
10327 {
10328 errmsg ("both IPv4 and IPv6 addresses specified");
10329 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080010330 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010331
Dave Barach72d72232016-08-04 10:15:08 -040010332 if (vni_set == 0)
10333 {
10334 errmsg ("vni not specified\n");
10335 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010336 }
10337
Dave Barach72d72232016-08-04 10:15:08 -040010338 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010339
Hongjun Nidf921cc2016-05-25 01:16:19 +080010340
Dave Barach72d72232016-08-04 10:15:08 -040010341 if (ipv6_set)
10342 {
10343 clib_memcpy (&mp->local, &local6, sizeof (local6));
10344 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
10345 }
10346 else
10347 {
10348 clib_memcpy (&mp->local, &local4, sizeof (local4));
10349 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080010350 }
10351
Dave Barach72d72232016-08-04 10:15:08 -040010352 mp->encap_vrf_id = ntohl (encap_vrf_id);
10353 mp->decap_vrf_id = ntohl (decap_vrf_id);
10354 mp->protocol = ntohl (protocol);
10355 mp->vni = ntohl (vni);
10356 mp->is_add = is_add;
10357 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010358
Dave Barach72d72232016-08-04 10:15:08 -040010359 S;
10360 W;
10361 /* NOTREACHED */
10362 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010363}
10364
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010365static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010366 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010367{
Dave Barach72d72232016-08-04 10:15:08 -040010368 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010369
Dave Barach72d72232016-08-04 10:15:08 -040010370 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
10371 ntohl (mp->sw_if_index),
10372 format_ip46_address, &(mp->local[0]),
10373 format_ip46_address, &(mp->remote[0]),
10374 ntohl (mp->vni),
10375 ntohl (mp->protocol),
10376 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010377}
10378
10379static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010380 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010381{
Dave Barach72d72232016-08-04 10:15:08 -040010382 vat_main_t *vam = &vat_main;
10383 vat_json_node_t *node = NULL;
10384 struct in_addr ip4;
10385 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010386
Dave Barach72d72232016-08-04 10:15:08 -040010387 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010388 {
Dave Barach72d72232016-08-04 10:15:08 -040010389 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10390 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010391 }
Dave Barach72d72232016-08-04 10:15:08 -040010392 node = vat_json_array_add (&vam->json_tree);
10393
10394 vat_json_init_object (node);
10395 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10396 if (mp->is_ipv6)
10397 {
10398 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
10399 vat_json_object_add_ip6 (node, "local", ip6);
10400 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
10401 vat_json_object_add_ip6 (node, "remote", ip6);
10402 }
10403 else
10404 {
10405 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
10406 vat_json_object_add_ip4 (node, "local", ip4);
10407 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
10408 vat_json_object_add_ip4 (node, "remote", ip4);
10409 }
10410 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10411 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10412 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10413 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10414 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010415}
10416
Dave Barach72d72232016-08-04 10:15:08 -040010417static int
10418api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010419{
Dave Barach72d72232016-08-04 10:15:08 -040010420 unformat_input_t *i = vam->input;
10421 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10422 f64 timeout;
10423 u32 sw_if_index;
10424 u8 sw_if_index_set = 0;
10425
10426 /* Parse args required to build the message */
10427 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10428 {
10429 if (unformat (i, "sw_if_index %d", &sw_if_index))
10430 sw_if_index_set = 1;
10431 else
10432 break;
10433 }
10434
10435 if (sw_if_index_set == 0)
10436 {
10437 sw_if_index = ~0;
10438 }
10439
10440 if (!vam->json_output)
10441 {
10442 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
10443 "sw_if_index", "local", "remote", "vni",
10444 "protocol", "encap_vrf_id", "decap_vrf_id");
10445 }
10446
10447 /* Get list of vxlan-tunnel interfaces */
10448 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
10449
10450 mp->sw_if_index = htonl (sw_if_index);
10451
10452 S;
10453
10454 /* Use a control ping for synchronization */
10455 {
10456 vl_api_control_ping_t *mp;
10457 M (CONTROL_PING, control_ping);
10458 S;
10459 }
10460 W;
10461}
10462
10463u8 *
10464format_l2_fib_mac_address (u8 * s, va_list * args)
10465{
10466 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010467
10468 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040010469 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010470}
10471
10472static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010473 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010474{
Dave Barach72d72232016-08-04 10:15:08 -040010475 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010476
Dave Barach72d72232016-08-04 10:15:08 -040010477 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10478 " %d %d %d\n",
10479 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
10480 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10481 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010482}
10483
10484static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010485 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010486{
Dave Barach72d72232016-08-04 10:15:08 -040010487 vat_main_t *vam = &vat_main;
10488 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010489
Dave Barach72d72232016-08-04 10:15:08 -040010490 if (VAT_JSON_ARRAY != vam->json_tree.type)
10491 {
10492 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10493 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010494 }
Dave Barach72d72232016-08-04 10:15:08 -040010495 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010496
Dave Barach72d72232016-08-04 10:15:08 -040010497 vat_json_init_object (node);
10498 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10499 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
10500 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10501 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10502 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10503 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010504}
10505
Dave Barach72d72232016-08-04 10:15:08 -040010506static int
10507api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010508{
Dave Barach72d72232016-08-04 10:15:08 -040010509 unformat_input_t *i = vam->input;
10510 vl_api_l2_fib_table_dump_t *mp;
10511 f64 timeout;
10512 u32 bd_id;
10513 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010514
Dave Barach72d72232016-08-04 10:15:08 -040010515 /* Parse args required to build the message */
10516 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010517 {
Dave Barach72d72232016-08-04 10:15:08 -040010518 if (unformat (i, "bd_id %d", &bd_id))
10519 bd_id_set = 1;
10520 else
10521 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010522 }
Dave Barach72d72232016-08-04 10:15:08 -040010523
10524 if (bd_id_set == 0)
10525 {
10526 errmsg ("missing bridge domain\n");
10527 return -99;
10528 }
10529
10530 fformat (vam->ofp,
10531 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
10532
10533 /* Get list of l2 fib entries */
10534 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
10535
10536 mp->bd_id = ntohl (bd_id);
10537 S;
10538
10539 /* Use a control ping for synchronization */
10540 {
10541 vl_api_control_ping_t *mp;
10542 M (CONTROL_PING, control_ping);
10543 S;
10544 }
10545 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010546}
10547
10548
10549static int
10550api_interface_name_renumber (vat_main_t * vam)
10551{
Dave Barach72d72232016-08-04 10:15:08 -040010552 unformat_input_t *line_input = vam->input;
10553 vl_api_interface_name_renumber_t *mp;
10554 u32 sw_if_index = ~0;
10555 f64 timeout;
10556 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010557
Dave Barach72d72232016-08-04 10:15:08 -040010558 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10559 {
10560 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
10561 &sw_if_index))
10562 ;
10563 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10564 ;
10565 else if (unformat (line_input, "new_show_dev_instance %d",
10566 &new_show_dev_instance))
10567 ;
10568 else
10569 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010570 }
10571
Dave Barach72d72232016-08-04 10:15:08 -040010572 if (sw_if_index == ~0)
10573 {
10574 errmsg ("missing interface name or sw_if_index\n");
10575 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010576 }
10577
Dave Barach72d72232016-08-04 10:15:08 -040010578 if (new_show_dev_instance == ~0)
10579 {
10580 errmsg ("missing new_show_dev_instance\n");
10581 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010582 }
10583
Dave Barach72d72232016-08-04 10:15:08 -040010584 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010585
Dave Barach72d72232016-08-04 10:15:08 -040010586 mp->sw_if_index = ntohl (sw_if_index);
10587 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010588
Dave Barach72d72232016-08-04 10:15:08 -040010589 S;
10590 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010591}
10592
10593static int
10594api_want_ip4_arp_events (vat_main_t * vam)
10595{
Dave Barach72d72232016-08-04 10:15:08 -040010596 unformat_input_t *line_input = vam->input;
10597 vl_api_want_ip4_arp_events_t *mp;
10598 f64 timeout;
10599 ip4_address_t address;
10600 int address_set = 0;
10601 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010602
Dave Barach72d72232016-08-04 10:15:08 -040010603 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10604 {
10605 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
10606 address_set = 1;
10607 else if (unformat (line_input, "del"))
10608 enable_disable = 0;
10609 else
10610 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010611 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010612
Dave Barach72d72232016-08-04 10:15:08 -040010613 if (address_set == 0)
10614 {
10615 errmsg ("missing addresses\n");
10616 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010617 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010618
Dave Barach72d72232016-08-04 10:15:08 -040010619 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
10620 mp->enable_disable = enable_disable;
10621 mp->pid = getpid ();
10622 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010623
Dave Barach72d72232016-08-04 10:15:08 -040010624 S;
10625 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010626}
10627
Dave Barach72d72232016-08-04 10:15:08 -040010628static int
John Lo1edfba92016-08-27 01:11:57 -040010629api_want_ip6_nd_events (vat_main_t * vam)
10630{
10631 unformat_input_t *line_input = vam->input;
10632 vl_api_want_ip6_nd_events_t *mp;
10633 f64 timeout;
10634 ip6_address_t address;
10635 int address_set = 0;
10636 u32 enable_disable = 1;
10637
10638 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10639 {
10640 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
10641 address_set = 1;
10642 else if (unformat (line_input, "del"))
10643 enable_disable = 0;
10644 else
10645 break;
10646 }
10647
10648 if (address_set == 0)
10649 {
10650 errmsg ("missing addresses\n");
10651 return -99;
10652 }
10653
10654 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
10655 mp->enable_disable = enable_disable;
10656 mp->pid = getpid ();
10657 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
10658
10659 S;
10660 W;
10661}
10662
10663static int
Dave Barach72d72232016-08-04 10:15:08 -040010664api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010665{
Dave Barach72d72232016-08-04 10:15:08 -040010666 unformat_input_t *i = vam->input;
10667 vl_api_input_acl_set_interface_t *mp;
10668 f64 timeout;
10669 u32 sw_if_index;
10670 int sw_if_index_set;
10671 u32 ip4_table_index = ~0;
10672 u32 ip6_table_index = ~0;
10673 u32 l2_table_index = ~0;
10674 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010675
Dave Barach72d72232016-08-04 10:15:08 -040010676 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10677 {
10678 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10679 sw_if_index_set = 1;
10680 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10681 sw_if_index_set = 1;
10682 else if (unformat (i, "del"))
10683 is_add = 0;
10684 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10685 ;
10686 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10687 ;
10688 else if (unformat (i, "l2-table %d", &l2_table_index))
10689 ;
10690 else
10691 {
10692 clib_warning ("parse error '%U'", format_unformat_error, i);
10693 return -99;
10694 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010695 }
10696
Dave Barach72d72232016-08-04 10:15:08 -040010697 if (sw_if_index_set == 0)
10698 {
10699 errmsg ("missing interface name or sw_if_index\n");
10700 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010701 }
10702
Dave Barach72d72232016-08-04 10:15:08 -040010703 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010704
Dave Barach72d72232016-08-04 10:15:08 -040010705 mp->sw_if_index = ntohl (sw_if_index);
10706 mp->ip4_table_index = ntohl (ip4_table_index);
10707 mp->ip6_table_index = ntohl (ip6_table_index);
10708 mp->l2_table_index = ntohl (l2_table_index);
10709 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010710
Dave Barach72d72232016-08-04 10:15:08 -040010711 S;
10712 W;
10713 /* NOTREACHED */
10714 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010715}
10716
10717static int
10718api_ip_address_dump (vat_main_t * vam)
10719{
Dave Barach72d72232016-08-04 10:15:08 -040010720 unformat_input_t *i = vam->input;
10721 vl_api_ip_address_dump_t *mp;
10722 u32 sw_if_index = ~0;
10723 u8 sw_if_index_set = 0;
10724 u8 ipv4_set = 0;
10725 u8 ipv6_set = 0;
10726 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010727
Dave Barach72d72232016-08-04 10:15:08 -040010728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010729 {
Dave Barach72d72232016-08-04 10:15:08 -040010730 if (unformat (i, "sw_if_index %d", &sw_if_index))
10731 sw_if_index_set = 1;
10732 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10733 sw_if_index_set = 1;
10734 else if (unformat (i, "ipv4"))
10735 ipv4_set = 1;
10736 else if (unformat (i, "ipv6"))
10737 ipv6_set = 1;
10738 else
10739 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010740 }
Dave Barach72d72232016-08-04 10:15:08 -040010741
10742 if (ipv4_set && ipv6_set)
10743 {
10744 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
10745 return -99;
10746 }
10747
10748 if ((!ipv4_set) && (!ipv6_set))
10749 {
10750 errmsg ("no ipv4 nor ipv6 flag set\n");
10751 return -99;
10752 }
10753
10754 if (sw_if_index_set == 0)
10755 {
10756 errmsg ("missing interface name or sw_if_index\n");
10757 return -99;
10758 }
10759
10760 vam->current_sw_if_index = sw_if_index;
10761 vam->is_ipv6 = ipv6_set;
10762
10763 M (IP_ADDRESS_DUMP, ip_address_dump);
10764 mp->sw_if_index = ntohl (sw_if_index);
10765 mp->is_ipv6 = ipv6_set;
10766 S;
10767
10768 /* Use a control ping for synchronization */
10769 {
10770 vl_api_control_ping_t *mp;
10771 M (CONTROL_PING, control_ping);
10772 S;
10773 }
10774 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010775}
10776
10777static int
10778api_ip_dump (vat_main_t * vam)
10779{
Dave Barach72d72232016-08-04 10:15:08 -040010780 vl_api_ip_dump_t *mp;
10781 unformat_input_t *in = vam->input;
10782 int ipv4_set = 0;
10783 int ipv6_set = 0;
10784 int is_ipv6;
10785 f64 timeout;
10786 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010787
Dave Barach72d72232016-08-04 10:15:08 -040010788 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010789 {
Dave Barach72d72232016-08-04 10:15:08 -040010790 if (unformat (in, "ipv4"))
10791 ipv4_set = 1;
10792 else if (unformat (in, "ipv6"))
10793 ipv6_set = 1;
10794 else
10795 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010796 }
Dave Barach72d72232016-08-04 10:15:08 -040010797
10798 if (ipv4_set && ipv6_set)
10799 {
10800 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
10801 return -99;
10802 }
10803
10804 if ((!ipv4_set) && (!ipv6_set))
10805 {
10806 errmsg ("no ipv4 nor ipv6 flag set\n");
10807 return -99;
10808 }
10809
10810 is_ipv6 = ipv6_set;
10811 vam->is_ipv6 = is_ipv6;
10812
10813 /* free old data */
10814 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10815 {
10816 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10817 }
10818 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10819
10820 M (IP_DUMP, ip_dump);
10821 mp->is_ipv6 = ipv6_set;
10822 S;
10823
10824 /* Use a control ping for synchronization */
10825 {
10826 vl_api_control_ping_t *mp;
10827 M (CONTROL_PING, control_ping);
10828 S;
10829 }
10830 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010831}
10832
10833static int
10834api_ipsec_spd_add_del (vat_main_t * vam)
10835{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010836#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010837 unformat_input_t *i = vam->input;
10838 vl_api_ipsec_spd_add_del_t *mp;
10839 f64 timeout;
10840 u32 spd_id = ~0;
10841 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010842
Dave Barach72d72232016-08-04 10:15:08 -040010843 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10844 {
10845 if (unformat (i, "spd_id %d", &spd_id))
10846 ;
10847 else if (unformat (i, "del"))
10848 is_add = 0;
10849 else
10850 {
10851 clib_warning ("parse error '%U'", format_unformat_error, i);
10852 return -99;
10853 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010854 }
Dave Barach72d72232016-08-04 10:15:08 -040010855 if (spd_id == ~0)
10856 {
10857 errmsg ("spd_id must be set\n");
10858 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010859 }
10860
Dave Barach72d72232016-08-04 10:15:08 -040010861 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010862
Dave Barach72d72232016-08-04 10:15:08 -040010863 mp->spd_id = ntohl (spd_id);
10864 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010865
Dave Barach72d72232016-08-04 10:15:08 -040010866 S;
10867 W;
10868 /* NOTREACHED */
10869 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010870#else
Dave Barach72d72232016-08-04 10:15:08 -040010871 clib_warning ("unsupported (no dpdk)");
10872 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010873#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070010874}
10875
10876static int
10877api_ipsec_interface_add_del_spd (vat_main_t * vam)
10878{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010879#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010880 unformat_input_t *i = vam->input;
10881 vl_api_ipsec_interface_add_del_spd_t *mp;
10882 f64 timeout;
10883 u32 sw_if_index;
10884 u8 sw_if_index_set = 0;
10885 u32 spd_id = (u32) ~ 0;
10886 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010887
Dave Barach72d72232016-08-04 10:15:08 -040010888 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10889 {
10890 if (unformat (i, "del"))
10891 is_add = 0;
10892 else if (unformat (i, "spd_id %d", &spd_id))
10893 ;
10894 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10895 sw_if_index_set = 1;
10896 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10897 sw_if_index_set = 1;
10898 else
10899 {
10900 clib_warning ("parse error '%U'", format_unformat_error, i);
10901 return -99;
10902 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010903
10904 }
10905
Dave Barach72d72232016-08-04 10:15:08 -040010906 if (spd_id == (u32) ~ 0)
10907 {
10908 errmsg ("spd_id must be set\n");
10909 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010910 }
10911
Dave Barach72d72232016-08-04 10:15:08 -040010912 if (sw_if_index_set == 0)
10913 {
10914 errmsg ("missing interface name or sw_if_index\n");
10915 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010916 }
10917
Dave Barach72d72232016-08-04 10:15:08 -040010918 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010919
Dave Barach72d72232016-08-04 10:15:08 -040010920 mp->spd_id = ntohl (spd_id);
10921 mp->sw_if_index = ntohl (sw_if_index);
10922 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010923
Dave Barach72d72232016-08-04 10:15:08 -040010924 S;
10925 W;
10926 /* NOTREACHED */
10927 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010928#else
Dave Barach72d72232016-08-04 10:15:08 -040010929 clib_warning ("unsupported (no dpdk)");
10930 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010931#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070010932}
10933
10934static int
10935api_ipsec_spd_add_del_entry (vat_main_t * vam)
10936{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010937#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010938 unformat_input_t *i = vam->input;
10939 vl_api_ipsec_spd_add_del_entry_t *mp;
10940 f64 timeout;
10941 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040010942 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040010943 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010944 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10945 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10946 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
10947 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010948
Dave Barach72d72232016-08-04 10:15:08 -040010949 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
10950 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
10951 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
10952 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
10953 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
10954 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010955
Dave Barach72d72232016-08-04 10:15:08 -040010956 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10957 {
10958 if (unformat (i, "del"))
10959 is_add = 0;
10960 if (unformat (i, "outbound"))
10961 is_outbound = 1;
10962 if (unformat (i, "inbound"))
10963 is_outbound = 0;
10964 else if (unformat (i, "spd_id %d", &spd_id))
10965 ;
10966 else if (unformat (i, "sa_id %d", &sa_id))
10967 ;
10968 else if (unformat (i, "priority %d", &priority))
10969 ;
10970 else if (unformat (i, "protocol %d", &protocol))
10971 ;
10972 else if (unformat (i, "lport_start %d", &lport_start))
10973 ;
10974 else if (unformat (i, "lport_stop %d", &lport_stop))
10975 ;
10976 else if (unformat (i, "rport_start %d", &rport_start))
10977 ;
10978 else if (unformat (i, "rport_stop %d", &rport_stop))
10979 ;
10980 else
10981 if (unformat
10982 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
10983 {
10984 is_ipv6 = 0;
10985 is_ip_any = 0;
10986 }
10987 else
10988 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
10989 {
10990 is_ipv6 = 0;
10991 is_ip_any = 0;
10992 }
10993 else
10994 if (unformat
10995 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
10996 {
10997 is_ipv6 = 0;
10998 is_ip_any = 0;
10999 }
11000 else
11001 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11002 {
11003 is_ipv6 = 0;
11004 is_ip_any = 0;
11005 }
11006 else
11007 if (unformat
11008 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11009 {
11010 is_ipv6 = 1;
11011 is_ip_any = 0;
11012 }
11013 else
11014 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11015 {
11016 is_ipv6 = 1;
11017 is_ip_any = 0;
11018 }
11019 else
11020 if (unformat
11021 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11022 {
11023 is_ipv6 = 1;
11024 is_ip_any = 0;
11025 }
11026 else
11027 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11028 {
11029 is_ipv6 = 1;
11030 is_ip_any = 0;
11031 }
11032 else
11033 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11034 {
11035 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11036 {
11037 clib_warning ("unsupported action: 'resolve'");
11038 return -99;
11039 }
11040 }
11041 else
11042 {
11043 clib_warning ("parse error '%U'", format_unformat_error, i);
11044 return -99;
11045 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011046
11047 }
11048
Dave Barach72d72232016-08-04 10:15:08 -040011049 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011050
Dave Barach72d72232016-08-04 10:15:08 -040011051 mp->spd_id = ntohl (spd_id);
11052 mp->priority = ntohl (priority);
11053 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011054
Dave Barach72d72232016-08-04 10:15:08 -040011055 mp->is_ipv6 = is_ipv6;
11056 if (is_ipv6 || is_ip_any)
11057 {
11058 clib_memcpy (mp->remote_address_start, &raddr6_start,
11059 sizeof (ip6_address_t));
11060 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11061 sizeof (ip6_address_t));
11062 clib_memcpy (mp->local_address_start, &laddr6_start,
11063 sizeof (ip6_address_t));
11064 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11065 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011066 }
Dave Barach72d72232016-08-04 10:15:08 -040011067 else
11068 {
11069 clib_memcpy (mp->remote_address_start, &raddr4_start,
11070 sizeof (ip4_address_t));
11071 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11072 sizeof (ip4_address_t));
11073 clib_memcpy (mp->local_address_start, &laddr4_start,
11074 sizeof (ip4_address_t));
11075 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11076 sizeof (ip4_address_t));
11077 }
11078 mp->protocol = (u8) protocol;
11079 mp->local_port_start = ntohs ((u16) lport_start);
11080 mp->local_port_stop = ntohs ((u16) lport_stop);
11081 mp->remote_port_start = ntohs ((u16) rport_start);
11082 mp->remote_port_stop = ntohs ((u16) rport_stop);
11083 mp->policy = (u8) policy;
11084 mp->sa_id = ntohl (sa_id);
11085 mp->is_add = is_add;
11086 mp->is_ip_any = is_ip_any;
11087 S;
11088 W;
11089 /* NOTREACHED */
11090 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011091#else
Dave Barach72d72232016-08-04 10:15:08 -040011092 clib_warning ("unsupported (no dpdk)");
11093 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011094#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011095}
11096
11097static int
11098api_ipsec_sad_add_del_entry (vat_main_t * vam)
11099{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011100#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011101 unformat_input_t *i = vam->input;
11102 vl_api_ipsec_sad_add_del_entry_t *mp;
11103 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011104 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011105 u8 *ck = 0, *ik = 0;
11106 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011107
Dave Barach72d72232016-08-04 10:15:08 -040011108 u8 protocol = IPSEC_PROTOCOL_AH;
11109 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11110 u32 crypto_alg = 0, integ_alg = 0;
11111 ip4_address_t tun_src4;
11112 ip4_address_t tun_dst4;
11113 ip6_address_t tun_src6;
11114 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011115
Dave Barach72d72232016-08-04 10:15:08 -040011116 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11117 {
11118 if (unformat (i, "del"))
11119 is_add = 0;
11120 else if (unformat (i, "sad_id %d", &sad_id))
11121 ;
11122 else if (unformat (i, "spi %d", &spi))
11123 ;
11124 else if (unformat (i, "esp"))
11125 protocol = IPSEC_PROTOCOL_ESP;
11126 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11127 {
11128 is_tunnel = 1;
11129 is_tunnel_ipv6 = 0;
11130 }
11131 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11132 {
11133 is_tunnel = 1;
11134 is_tunnel_ipv6 = 0;
11135 }
11136 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11137 {
11138 is_tunnel = 1;
11139 is_tunnel_ipv6 = 1;
11140 }
11141 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11142 {
11143 is_tunnel = 1;
11144 is_tunnel_ipv6 = 1;
11145 }
11146 else
11147 if (unformat
11148 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11149 {
11150 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
11151 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256)
11152 {
11153 clib_warning ("unsupported crypto-alg: '%U'",
11154 format_ipsec_crypto_alg, crypto_alg);
11155 return -99;
11156 }
11157 }
11158 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11159 ;
11160 else
11161 if (unformat
11162 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11163 {
11164 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
11165 integ_alg > IPSEC_INTEG_ALG_SHA_512_256)
11166 {
11167 clib_warning ("unsupported integ-alg: '%U'",
11168 format_ipsec_integ_alg, integ_alg);
11169 return -99;
11170 }
11171 }
11172 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11173 ;
11174 else
11175 {
11176 clib_warning ("parse error '%U'", format_unformat_error, i);
11177 return -99;
11178 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011179
11180 }
11181
Dave Barach72d72232016-08-04 10:15:08 -040011182 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011183
Dave Barach72d72232016-08-04 10:15:08 -040011184 mp->sad_id = ntohl (sad_id);
11185 mp->is_add = is_add;
11186 mp->protocol = protocol;
11187 mp->spi = ntohl (spi);
11188 mp->is_tunnel = is_tunnel;
11189 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11190 mp->crypto_algorithm = crypto_alg;
11191 mp->integrity_algorithm = integ_alg;
11192 mp->crypto_key_length = vec_len (ck);
11193 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011194
Dave Barach72d72232016-08-04 10:15:08 -040011195 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11196 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011197
Dave Barach72d72232016-08-04 10:15:08 -040011198 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11199 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011200
Dave Barach839fe3e2016-08-10 11:35:54 -040011201 if (ck)
11202 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11203 if (ik)
11204 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011205
Dave Barach72d72232016-08-04 10:15:08 -040011206 if (is_tunnel)
11207 {
11208 if (is_tunnel_ipv6)
11209 {
11210 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11211 sizeof (ip6_address_t));
11212 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
11213 sizeof (ip6_address_t));
11214 }
11215 else
11216 {
11217 clib_memcpy (mp->tunnel_src_address, &tun_src4,
11218 sizeof (ip4_address_t));
11219 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
11220 sizeof (ip4_address_t));
11221 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011222 }
11223
Dave Barach72d72232016-08-04 10:15:08 -040011224 S;
11225 W;
11226 /* NOTREACHED */
11227 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011228#else
Dave Barach72d72232016-08-04 10:15:08 -040011229 clib_warning ("unsupported (no dpdk)");
11230 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011231#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011232}
11233
11234static int
11235api_ipsec_sa_set_key (vat_main_t * vam)
11236{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011237#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011238 unformat_input_t *i = vam->input;
11239 vl_api_ipsec_sa_set_key_t *mp;
11240 f64 timeout;
11241 u32 sa_id;
11242 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011243
Dave Barach72d72232016-08-04 10:15:08 -040011244 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11245 {
11246 if (unformat (i, "sa_id %d", &sa_id))
11247 ;
11248 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11249 ;
11250 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11251 ;
11252 else
11253 {
11254 clib_warning ("parse error '%U'", format_unformat_error, i);
11255 return -99;
11256 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011257 }
11258
Dave Barach72d72232016-08-04 10:15:08 -040011259 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011260
Dave Barach72d72232016-08-04 10:15:08 -040011261 mp->sa_id = ntohl (sa_id);
11262 mp->crypto_key_length = vec_len (ck);
11263 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011264
Dave Barach72d72232016-08-04 10:15:08 -040011265 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11266 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011267
Dave Barach72d72232016-08-04 10:15:08 -040011268 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11269 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011270
Dave Barach839fe3e2016-08-10 11:35:54 -040011271 if (ck)
11272 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11273 if (ik)
11274 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011275
Dave Barach72d72232016-08-04 10:15:08 -040011276 S;
11277 W;
11278 /* NOTREACHED */
11279 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011280#else
Dave Barach72d72232016-08-04 10:15:08 -040011281 clib_warning ("unsupported (no dpdk)");
11282 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011283#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011284}
11285
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011286static int
11287api_ikev2_profile_add_del (vat_main_t * vam)
11288{
11289#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011290 unformat_input_t *i = vam->input;
11291 vl_api_ikev2_profile_add_del_t *mp;
11292 f64 timeout;
11293 u8 is_add = 1;
11294 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011295
Dave Barach72d72232016-08-04 10:15:08 -040011296 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011297
Dave Barach72d72232016-08-04 10:15:08 -040011298 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11299 {
11300 if (unformat (i, "del"))
11301 is_add = 0;
11302 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11303 vec_add1 (name, 0);
11304 else
11305 {
11306 errmsg ("parse error '%U'", format_unformat_error, i);
11307 return -99;
11308 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011309 }
11310
Dave Barach72d72232016-08-04 10:15:08 -040011311 if (!vec_len (name))
11312 {
11313 errmsg ("profile name must be specified");
11314 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011315 }
11316
Dave Barach72d72232016-08-04 10:15:08 -040011317 if (vec_len (name) > 64)
11318 {
11319 errmsg ("profile name too long");
11320 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011321 }
11322
Dave Barach72d72232016-08-04 10:15:08 -040011323 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011324
Dave Barach72d72232016-08-04 10:15:08 -040011325 clib_memcpy (mp->name, name, vec_len (name));
11326 mp->is_add = is_add;
11327 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011328
Dave Barach72d72232016-08-04 10:15:08 -040011329 S;
11330 W;
11331 /* NOTREACHED */
11332 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011333#else
Dave Barach72d72232016-08-04 10:15:08 -040011334 clib_warning ("unsupported (no dpdk)");
11335 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011336#endif
11337}
11338
11339static int
11340api_ikev2_profile_set_auth (vat_main_t * vam)
11341{
11342#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011343 unformat_input_t *i = vam->input;
11344 vl_api_ikev2_profile_set_auth_t *mp;
11345 f64 timeout;
11346 u8 *name = 0;
11347 u8 *data = 0;
11348 u32 auth_method = 0;
11349 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011350
Dave Barach72d72232016-08-04 10:15:08 -040011351 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011352
Dave Barach72d72232016-08-04 10:15:08 -040011353 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11354 {
11355 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11356 vec_add1 (name, 0);
11357 else if (unformat (i, "auth_method %U",
11358 unformat_ikev2_auth_method, &auth_method))
11359 ;
11360 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
11361 is_hex = 1;
11362 else if (unformat (i, "auth_data %v", &data))
11363 ;
11364 else
11365 {
11366 errmsg ("parse error '%U'", format_unformat_error, i);
11367 return -99;
11368 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011369 }
11370
Dave Barach72d72232016-08-04 10:15:08 -040011371 if (!vec_len (name))
11372 {
11373 errmsg ("profile name must be specified");
11374 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011375 }
11376
Dave Barach72d72232016-08-04 10:15:08 -040011377 if (vec_len (name) > 64)
11378 {
11379 errmsg ("profile name too long");
11380 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011381 }
11382
Dave Barach72d72232016-08-04 10:15:08 -040011383 if (!vec_len (data))
11384 {
11385 errmsg ("auth_data must be specified");
11386 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011387 }
11388
Dave Barach72d72232016-08-04 10:15:08 -040011389 if (!auth_method)
11390 {
11391 errmsg ("auth_method must be specified");
11392 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011393 }
11394
Dave Barach72d72232016-08-04 10:15:08 -040011395 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011396
Dave Barach72d72232016-08-04 10:15:08 -040011397 mp->is_hex = is_hex;
11398 mp->auth_method = (u8) auth_method;
11399 mp->data_len = vec_len (data);
11400 clib_memcpy (mp->name, name, vec_len (name));
11401 clib_memcpy (mp->data, data, vec_len (data));
11402 vec_free (name);
11403 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011404
Dave Barach72d72232016-08-04 10:15:08 -040011405 S;
11406 W;
11407 /* NOTREACHED */
11408 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011409#else
Dave Barach72d72232016-08-04 10:15:08 -040011410 clib_warning ("unsupported (no dpdk)");
11411 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011412#endif
11413}
11414
11415static int
11416api_ikev2_profile_set_id (vat_main_t * vam)
11417{
11418#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011419 unformat_input_t *i = vam->input;
11420 vl_api_ikev2_profile_set_id_t *mp;
11421 f64 timeout;
11422 u8 *name = 0;
11423 u8 *data = 0;
11424 u8 is_local = 0;
11425 u32 id_type = 0;
11426 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011427
Dave Barach72d72232016-08-04 10:15:08 -040011428 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011429
Dave Barach72d72232016-08-04 10:15:08 -040011430 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11431 {
11432 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11433 vec_add1 (name, 0);
11434 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
11435 ;
11436 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
11437 {
11438 data = vec_new (u8, 4);
11439 clib_memcpy (data, ip4.as_u8, 4);
11440 }
11441 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
11442 ;
11443 else if (unformat (i, "id_data %v", &data))
11444 ;
11445 else if (unformat (i, "local"))
11446 is_local = 1;
11447 else if (unformat (i, "remote"))
11448 is_local = 0;
11449 else
11450 {
11451 errmsg ("parse error '%U'", format_unformat_error, i);
11452 return -99;
11453 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011454 }
11455
Dave Barach72d72232016-08-04 10:15:08 -040011456 if (!vec_len (name))
11457 {
11458 errmsg ("profile name must be specified");
11459 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011460 }
11461
Dave Barach72d72232016-08-04 10:15:08 -040011462 if (vec_len (name) > 64)
11463 {
11464 errmsg ("profile name too long");
11465 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011466 }
11467
Dave Barach72d72232016-08-04 10:15:08 -040011468 if (!vec_len (data))
11469 {
11470 errmsg ("id_data must be specified");
11471 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011472 }
11473
Dave Barach72d72232016-08-04 10:15:08 -040011474 if (!id_type)
11475 {
11476 errmsg ("id_type must be specified");
11477 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011478 }
11479
Dave Barach72d72232016-08-04 10:15:08 -040011480 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011481
Dave Barach72d72232016-08-04 10:15:08 -040011482 mp->is_local = is_local;
11483 mp->id_type = (u8) id_type;
11484 mp->data_len = vec_len (data);
11485 clib_memcpy (mp->name, name, vec_len (name));
11486 clib_memcpy (mp->data, data, vec_len (data));
11487 vec_free (name);
11488 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011489
Dave Barach72d72232016-08-04 10:15:08 -040011490 S;
11491 W;
11492 /* NOTREACHED */
11493 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011494#else
Dave Barach72d72232016-08-04 10:15:08 -040011495 clib_warning ("unsupported (no dpdk)");
11496 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011497#endif
11498}
11499
11500static int
11501api_ikev2_profile_set_ts (vat_main_t * vam)
11502{
11503#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011504 unformat_input_t *i = vam->input;
11505 vl_api_ikev2_profile_set_ts_t *mp;
11506 f64 timeout;
11507 u8 *name = 0;
11508 u8 is_local = 0;
11509 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
11510 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011511
Dave Barach72d72232016-08-04 10:15:08 -040011512 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011513
Dave Barach72d72232016-08-04 10:15:08 -040011514 start_addr.as_u32 = 0;
11515 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011516
Dave Barach72d72232016-08-04 10:15:08 -040011517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11518 {
11519 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11520 vec_add1 (name, 0);
11521 else if (unformat (i, "protocol %d", &proto))
11522 ;
11523 else if (unformat (i, "start_port %d", &start_port))
11524 ;
11525 else if (unformat (i, "end_port %d", &end_port))
11526 ;
11527 else
11528 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
11529 ;
11530 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
11531 ;
11532 else if (unformat (i, "local"))
11533 is_local = 1;
11534 else if (unformat (i, "remote"))
11535 is_local = 0;
11536 else
11537 {
11538 errmsg ("parse error '%U'", format_unformat_error, i);
11539 return -99;
11540 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011541 }
11542
Dave Barach72d72232016-08-04 10:15:08 -040011543 if (!vec_len (name))
11544 {
11545 errmsg ("profile name must be specified");
11546 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011547 }
11548
Dave Barach72d72232016-08-04 10:15:08 -040011549 if (vec_len (name) > 64)
11550 {
11551 errmsg ("profile name too long");
11552 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011553 }
11554
Dave Barach72d72232016-08-04 10:15:08 -040011555 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011556
Dave Barach72d72232016-08-04 10:15:08 -040011557 mp->is_local = is_local;
11558 mp->proto = (u8) proto;
11559 mp->start_port = (u16) start_port;
11560 mp->end_port = (u16) end_port;
11561 mp->start_addr = start_addr.as_u32;
11562 mp->end_addr = end_addr.as_u32;
11563 clib_memcpy (mp->name, name, vec_len (name));
11564 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011565
Dave Barach72d72232016-08-04 10:15:08 -040011566 S;
11567 W;
11568 /* NOTREACHED */
11569 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011570#else
Dave Barach72d72232016-08-04 10:15:08 -040011571 clib_warning ("unsupported (no dpdk)");
11572 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011573#endif
11574}
11575
11576static int
11577api_ikev2_set_local_key (vat_main_t * vam)
11578{
11579#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011580 unformat_input_t *i = vam->input;
11581 vl_api_ikev2_set_local_key_t *mp;
11582 f64 timeout;
11583 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011584
Dave Barach72d72232016-08-04 10:15:08 -040011585 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11586 {
11587 if (unformat (i, "file %v", &file))
11588 vec_add1 (file, 0);
11589 else
11590 {
11591 errmsg ("parse error '%U'", format_unformat_error, i);
11592 return -99;
11593 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011594 }
11595
Dave Barach72d72232016-08-04 10:15:08 -040011596 if (!vec_len (file))
11597 {
11598 errmsg ("RSA key file must be specified");
11599 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011600 }
11601
Dave Barach72d72232016-08-04 10:15:08 -040011602 if (vec_len (file) > 256)
11603 {
11604 errmsg ("file name too long");
11605 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011606 }
11607
Dave Barach72d72232016-08-04 10:15:08 -040011608 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011609
Dave Barach72d72232016-08-04 10:15:08 -040011610 clib_memcpy (mp->key_file, file, vec_len (file));
11611 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011612
Dave Barach72d72232016-08-04 10:15:08 -040011613 S;
11614 W;
11615 /* NOTREACHED */
11616 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011617#else
Dave Barach72d72232016-08-04 10:15:08 -040011618 clib_warning ("unsupported (no dpdk)");
11619 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011620#endif
11621}
11622
Ed Warnickecb9cada2015-12-08 15:45:58 -070011623/*
11624 * MAP
11625 */
Dave Barach72d72232016-08-04 10:15:08 -040011626static int
11627api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011628{
11629 unformat_input_t *i = vam->input;
11630 vl_api_map_add_domain_t *mp;
11631 f64 timeout;
11632
11633 ip4_address_t ip4_prefix;
11634 ip6_address_t ip6_prefix;
11635 ip6_address_t ip6_src;
11636 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040011637 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
11638 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011639 u8 is_translation = 0;
11640 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020011641 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011642
Dave Barach72d72232016-08-04 10:15:08 -040011643 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11644 {
11645 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
11646 &ip4_prefix, &ip4_prefix_len))
11647 num_m_args++;
11648 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
11649 &ip6_prefix, &ip6_prefix_len))
11650 num_m_args++;
11651 else
11652 if (unformat
11653 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
11654 &ip6_src_len))
11655 num_m_args++;
11656 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
11657 num_m_args++;
11658 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
11659 num_m_args++;
11660 else if (unformat (i, "psid-offset %d", &psid_offset))
11661 num_m_args++;
11662 else if (unformat (i, "psid-len %d", &psid_length))
11663 num_m_args++;
11664 else if (unformat (i, "mtu %d", &mtu))
11665 num_m_args++;
11666 else if (unformat (i, "map-t"))
11667 is_translation = 1;
11668 else
11669 {
11670 clib_warning ("parse error '%U'", format_unformat_error, i);
11671 return -99;
11672 }
11673 }
11674
Ole Troan07e7eab2016-08-25 00:24:08 +020011675 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040011676 {
11677 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070011678 return -99;
11679 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011680
11681 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011682 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011683
Dave Barach72d72232016-08-04 10:15:08 -040011684 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011685 mp->ip4_prefix_len = ip4_prefix_len;
11686
Dave Barach72d72232016-08-04 10:15:08 -040011687 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011688 mp->ip6_prefix_len = ip6_prefix_len;
11689
Dave Barach72d72232016-08-04 10:15:08 -040011690 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011691 mp->ip6_src_prefix_len = ip6_src_len;
11692
11693 mp->ea_bits_len = ea_bits_len;
11694 mp->psid_offset = psid_offset;
11695 mp->psid_length = psid_length;
11696 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040011697 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011698
11699 /* send it... */
11700 S;
11701
11702 /* Wait for a reply, return good/bad news */
11703 W;
11704}
11705
Dave Barach72d72232016-08-04 10:15:08 -040011706static int
11707api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011708{
11709 unformat_input_t *i = vam->input;
11710 vl_api_map_del_domain_t *mp;
11711 f64 timeout;
11712
11713 u32 num_m_args = 0;
11714 u32 index;
11715
Dave Barach72d72232016-08-04 10:15:08 -040011716 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11717 {
11718 if (unformat (i, "index %d", &index))
11719 num_m_args++;
11720 else
11721 {
11722 clib_warning ("parse error '%U'", format_unformat_error, i);
11723 return -99;
11724 }
11725 }
11726
11727 if (num_m_args != 1)
11728 {
11729 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070011730 return -99;
11731 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011732
11733 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011734 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011735
Dave Barach72d72232016-08-04 10:15:08 -040011736 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011737
11738 /* send it... */
11739 S;
11740
11741 /* Wait for a reply, return good/bad news */
11742 W;
11743}
11744
Dave Barach72d72232016-08-04 10:15:08 -040011745static int
11746api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011747{
11748 unformat_input_t *i = vam->input;
11749 vl_api_map_add_del_rule_t *mp;
11750 f64 timeout;
11751 u8 is_add = 1;
11752 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040011753 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011754
Dave Barach72d72232016-08-04 10:15:08 -040011755 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11756 {
11757 if (unformat (i, "index %d", &index))
11758 num_m_args++;
11759 else if (unformat (i, "psid %d", &psid))
11760 num_m_args++;
11761 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
11762 num_m_args++;
11763 else if (unformat (i, "del"))
11764 {
11765 is_add = 0;
11766 }
11767 else
11768 {
11769 clib_warning ("parse error '%U'", format_unformat_error, i);
11770 return -99;
11771 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011772 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011773
11774 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011775 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011776
Dave Barach72d72232016-08-04 10:15:08 -040011777 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011778 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040011779 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
11780 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011781
11782 /* send it... */
11783 S;
11784
11785 /* Wait for a reply, return good/bad news */
11786 W;
11787}
11788
Dave Barach72d72232016-08-04 10:15:08 -040011789static int
11790api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011791{
Dave Barach72d72232016-08-04 10:15:08 -040011792 vl_api_map_domain_dump_t *mp;
11793 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011794
Dave Barach72d72232016-08-04 10:15:08 -040011795 /* Construct the API message */
11796 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011797
Dave Barach72d72232016-08-04 10:15:08 -040011798 /* send it... */
11799 S;
11800
11801 /* Use a control ping for synchronization */
11802 {
11803 vl_api_control_ping_t *mp;
11804 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011805 S;
Dave Barach72d72232016-08-04 10:15:08 -040011806 }
11807 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011808}
11809
Dave Barach72d72232016-08-04 10:15:08 -040011810static int
11811api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011812{
Dave Barach72d72232016-08-04 10:15:08 -040011813 unformat_input_t *i = vam->input;
11814 vl_api_map_rule_dump_t *mp;
11815 f64 timeout;
11816 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011817
Dave Barach72d72232016-08-04 10:15:08 -040011818 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011819 {
Dave Barach72d72232016-08-04 10:15:08 -040011820 if (unformat (i, "index %u", &domain_index))
11821 ;
11822 else
11823 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011824 }
Dave Barach72d72232016-08-04 10:15:08 -040011825
11826 if (domain_index == ~0)
11827 {
11828 clib_warning ("parse error: domain index expected");
11829 return -99;
11830 }
11831
11832 /* Construct the API message */
11833 M (MAP_RULE_DUMP, map_rule_dump);
11834
11835 mp->domain_index = htonl (domain_index);
11836
11837 /* send it... */
11838 S;
11839
11840 /* Use a control ping for synchronization */
11841 {
11842 vl_api_control_ping_t *mp;
11843 M (CONTROL_PING, control_ping);
11844 S;
11845 }
11846 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011847}
11848
11849static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011850 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011851{
Dave Barach72d72232016-08-04 10:15:08 -040011852 vat_main_t *vam = &vat_main;
11853 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011854
Dave Barach72d72232016-08-04 10:15:08 -040011855 if (vam->async_mode)
11856 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070011857 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040011858 }
11859 else
11860 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070011861 vam->retval = retval;
11862 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040011863 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011864}
11865
11866static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011867 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011868{
Dave Barach72d72232016-08-04 10:15:08 -040011869 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011870 vat_json_node_t node;
11871
Dave Barach72d72232016-08-04 10:15:08 -040011872 vat_json_init_object (&node);
11873 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
11874 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011875
Dave Barach72d72232016-08-04 10:15:08 -040011876 vat_json_print (vam->ofp, &node);
11877 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011878
Dave Barach72d72232016-08-04 10:15:08 -040011879 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011880 vam->result_ready = 1;
11881}
11882
11883static int
11884api_get_first_msg_id (vat_main_t * vam)
11885{
Dave Barach72d72232016-08-04 10:15:08 -040011886 vl_api_get_first_msg_id_t *mp;
11887 f64 timeout;
11888 unformat_input_t *i = vam->input;
11889 u8 *name;
11890 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011891
Dave Barach72d72232016-08-04 10:15:08 -040011892 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11893 {
11894 if (unformat (i, "client %s", &name))
11895 name_set = 1;
11896 else
11897 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011898 }
11899
Dave Barach72d72232016-08-04 10:15:08 -040011900 if (name_set == 0)
11901 {
11902 errmsg ("missing client name\n");
11903 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011904 }
Dave Barach72d72232016-08-04 10:15:08 -040011905 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011906
Dave Barach72d72232016-08-04 10:15:08 -040011907 if (vec_len (name) > 63)
11908 {
11909 errmsg ("client name too long\n");
11910 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011911 }
11912
Dave Barach72d72232016-08-04 10:15:08 -040011913 M (GET_FIRST_MSG_ID, get_first_msg_id);
11914 clib_memcpy (mp->name, name, vec_len (name));
11915 S;
11916 W;
11917 /* NOTREACHED */
11918 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011919}
11920
Dave Barach72d72232016-08-04 10:15:08 -040011921static int
11922api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050011923{
Dave Barach72d72232016-08-04 10:15:08 -040011924 unformat_input_t *line_input = vam->input;
11925 vl_api_cop_interface_enable_disable_t *mp;
11926 f64 timeout;
11927 u32 sw_if_index = ~0;
11928 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011929
Dave Barach72d72232016-08-04 10:15:08 -040011930 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11931 {
11932 if (unformat (line_input, "disable"))
11933 enable_disable = 0;
11934 if (unformat (line_input, "enable"))
11935 enable_disable = 1;
11936 else if (unformat (line_input, "%U", unformat_sw_if_index,
11937 vam, &sw_if_index))
11938 ;
11939 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11940 ;
11941 else
11942 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011943 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011944
Dave Barach72d72232016-08-04 10:15:08 -040011945 if (sw_if_index == ~0)
11946 {
11947 errmsg ("missing interface name or sw_if_index\n");
11948 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011949 }
11950
Dave Barach72d72232016-08-04 10:15:08 -040011951 /* Construct the API message */
11952 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
11953 mp->sw_if_index = ntohl (sw_if_index);
11954 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011955
Dave Barach72d72232016-08-04 10:15:08 -040011956 /* send it... */
11957 S;
11958 /* Wait for the reply */
11959 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011960}
11961
Dave Barach72d72232016-08-04 10:15:08 -040011962static int
11963api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050011964{
Dave Barach72d72232016-08-04 10:15:08 -040011965 unformat_input_t *line_input = vam->input;
11966 vl_api_cop_whitelist_enable_disable_t *mp;
11967 f64 timeout;
11968 u32 sw_if_index = ~0;
11969 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040011970 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011971
Dave Barach72d72232016-08-04 10:15:08 -040011972 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11973 {
11974 if (unformat (line_input, "ip4"))
11975 ip4 = 1;
11976 else if (unformat (line_input, "ip6"))
11977 ip6 = 1;
11978 else if (unformat (line_input, "default"))
11979 default_cop = 1;
11980 else if (unformat (line_input, "%U", unformat_sw_if_index,
11981 vam, &sw_if_index))
11982 ;
11983 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11984 ;
11985 else if (unformat (line_input, "fib-id %d", &fib_id))
11986 ;
11987 else
11988 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011989 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011990
Dave Barach72d72232016-08-04 10:15:08 -040011991 if (sw_if_index == ~0)
11992 {
11993 errmsg ("missing interface name or sw_if_index\n");
11994 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011995 }
11996
Dave Barach72d72232016-08-04 10:15:08 -040011997 /* Construct the API message */
11998 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
11999 mp->sw_if_index = ntohl (sw_if_index);
12000 mp->fib_id = ntohl (fib_id);
12001 mp->ip4 = ip4;
12002 mp->ip6 = ip6;
12003 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012004
Dave Barach72d72232016-08-04 10:15:08 -040012005 /* send it... */
12006 S;
12007 /* Wait for the reply */
12008 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012009}
12010
Dave Barach72d72232016-08-04 10:15:08 -040012011static int
12012api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012013{
Dave Barach72d72232016-08-04 10:15:08 -040012014 vl_api_get_node_graph_t *mp;
12015 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012016
Dave Barach72d72232016-08-04 10:15:08 -040012017 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012018
Dave Barach72d72232016-08-04 10:15:08 -040012019 /* send it... */
12020 S;
12021 /* Wait for the reply */
12022 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012023}
12024
Dave Barach72d72232016-08-04 10:15:08 -040012025/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012026/** Used for parsing LISP eids */
12027typedef CLIB_PACKED(struct{
12028 u8 addr[16]; /**< eid address */
12029 u32 len; /**< prefix length if IP */
12030 u8 type; /**< type of eid */
12031}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012032/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012033
12034static uword
12035unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12036{
Dave Barach72d72232016-08-04 10:15:08 -040012037 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012038
Dave Barach72d72232016-08-04 10:15:08 -040012039 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012040
Dave Barach72d72232016-08-04 10:15:08 -040012041 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12042 {
12043 a->type = 0; /* ipv4 type */
12044 }
12045 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12046 {
12047 a->type = 1; /* ipv6 type */
12048 }
12049 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12050 {
12051 a->type = 2; /* mac type */
12052 }
12053 else
12054 {
Florin Coras429e7952016-08-02 02:31:03 +020012055 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012056 }
Florin Coras429e7952016-08-02 02:31:03 +020012057
Dave Barach72d72232016-08-04 10:15:08 -040012058 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12059 {
Florin Coras429e7952016-08-02 02:31:03 +020012060 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012061 }
Florin Coras429e7952016-08-02 02:31:03 +020012062
12063 return 1;
12064}
12065
12066static int
12067lisp_eid_size_vat (u8 type)
12068{
Dave Barach72d72232016-08-04 10:15:08 -040012069 switch (type)
12070 {
Florin Coras429e7952016-08-02 02:31:03 +020012071 case 0:
12072 return 4;
12073 case 1:
12074 return 16;
12075 case 2:
12076 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012077 }
Florin Coras429e7952016-08-02 02:31:03 +020012078 return 0;
12079}
12080
12081static void
12082lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12083{
Dave Barach72d72232016-08-04 10:15:08 -040012084 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012085}
12086
Dave Barach72d72232016-08-04 10:15:08 -040012087/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012088/** Used for transferring locators via VPP API */
12089typedef CLIB_PACKED(struct
12090{
Dave Barach72d72232016-08-04 10:15:08 -040012091 u32 sw_if_index; /**< locator sw_if_index */
12092 u8 priority; /**< locator priority */
12093 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012094}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012095/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012096
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012097static int
Dave Barach72d72232016-08-04 10:15:08 -040012098api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012099{
Dave Barach72d72232016-08-04 10:15:08 -040012100 unformat_input_t *input = vam->input;
12101 vl_api_lisp_add_del_locator_set_t *mp;
12102 f64 timeout = ~0;
12103 u8 is_add = 1;
12104 u8 *locator_set_name = NULL;
12105 u8 locator_set_name_set = 0;
12106 ls_locator_t locator, *locators = 0;
12107 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012108 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012109
Dave Barach72d72232016-08-04 10:15:08 -040012110 /* Parse args required to build the message */
12111 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12112 {
12113 if (unformat (input, "del"))
12114 {
12115 is_add = 0;
12116 }
12117 else if (unformat (input, "locator-set %s", &locator_set_name))
12118 {
12119 locator_set_name_set = 1;
12120 }
12121 else if (unformat (input, "sw_if_index %u p %u w %u",
12122 &sw_if_index, &priority, &weight))
12123 {
12124 locator.sw_if_index = htonl (sw_if_index);
12125 locator.priority = priority;
12126 locator.weight = weight;
12127 vec_add1 (locators, locator);
12128 }
12129 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12130 vam, &sw_if_index, &priority, &weight))
12131 {
12132 locator.sw_if_index = htonl (sw_if_index);
12133 locator.priority = priority;
12134 locator.weight = weight;
12135 vec_add1 (locators, locator);
12136 }
12137 else
12138 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012139 }
12140
Dave Barach72d72232016-08-04 10:15:08 -040012141 if (locator_set_name_set == 0)
12142 {
12143 errmsg ("missing locator-set name");
12144 vec_free (locators);
12145 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012146 }
12147
Dave Barach72d72232016-08-04 10:15:08 -040012148 if (vec_len (locator_set_name) > 64)
12149 {
12150 errmsg ("locator-set name too long\n");
12151 vec_free (locator_set_name);
12152 vec_free (locators);
12153 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012154 }
Dave Barach72d72232016-08-04 10:15:08 -040012155 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012156
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012157 data_len = sizeof (ls_locator_t) * vec_len (locators);
12158
Dave Barach72d72232016-08-04 10:15:08 -040012159 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012160 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012161
Dave Barach72d72232016-08-04 10:15:08 -040012162 mp->is_add = is_add;
12163 clib_memcpy (mp->locator_set_name, locator_set_name,
12164 vec_len (locator_set_name));
12165 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012166
Filip Tehlare3552c42016-08-26 12:44:38 +020012167 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012168 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012169 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012170 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012171
Dave Barach72d72232016-08-04 10:15:08 -040012172 /* send it... */
12173 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012174
Dave Barach72d72232016-08-04 10:15:08 -040012175 /* Wait for a reply... */
12176 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012177
Dave Barach72d72232016-08-04 10:15:08 -040012178 /* NOTREACHED */
12179 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012180}
12181
12182static int
Dave Barach72d72232016-08-04 10:15:08 -040012183api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012184{
Dave Barach72d72232016-08-04 10:15:08 -040012185 unformat_input_t *input = vam->input;
12186 vl_api_lisp_add_del_locator_t *mp;
12187 f64 timeout = ~0;
12188 u32 tmp_if_index = ~0;
12189 u32 sw_if_index = ~0;
12190 u8 sw_if_index_set = 0;
12191 u8 sw_if_index_if_name_set = 0;
12192 u32 priority = ~0;
12193 u8 priority_set = 0;
12194 u32 weight = ~0;
12195 u8 weight_set = 0;
12196 u8 is_add = 1;
12197 u8 *locator_set_name = NULL;
12198 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012199
Dave Barach72d72232016-08-04 10:15:08 -040012200 /* Parse args required to build the message */
12201 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12202 {
12203 if (unformat (input, "del"))
12204 {
12205 is_add = 0;
12206 }
12207 else if (unformat (input, "locator-set %s", &locator_set_name))
12208 {
12209 locator_set_name_set = 1;
12210 }
12211 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12212 &tmp_if_index))
12213 {
12214 sw_if_index_if_name_set = 1;
12215 sw_if_index = tmp_if_index;
12216 }
12217 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12218 {
12219 sw_if_index_set = 1;
12220 sw_if_index = tmp_if_index;
12221 }
12222 else if (unformat (input, "p %d", &priority))
12223 {
12224 priority_set = 1;
12225 }
12226 else if (unformat (input, "w %d", &weight))
12227 {
12228 weight_set = 1;
12229 }
12230 else
12231 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012232 }
12233
Dave Barach72d72232016-08-04 10:15:08 -040012234 if (locator_set_name_set == 0)
12235 {
12236 errmsg ("missing locator-set name");
12237 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012238 }
12239
Dave Barach72d72232016-08-04 10:15:08 -040012240 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12241 {
12242 errmsg ("missing sw_if_index");
12243 vec_free (locator_set_name);
12244 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012245 }
12246
Dave Barach72d72232016-08-04 10:15:08 -040012247 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
12248 {
12249 errmsg ("cannot use both params interface name and sw_if_index");
12250 vec_free (locator_set_name);
12251 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012252 }
12253
Dave Barach72d72232016-08-04 10:15:08 -040012254 if (priority_set == 0)
12255 {
12256 errmsg ("missing locator-set priority\n");
12257 vec_free (locator_set_name);
12258 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012259 }
12260
Dave Barach72d72232016-08-04 10:15:08 -040012261 if (weight_set == 0)
12262 {
12263 errmsg ("missing locator-set weight\n");
12264 vec_free (locator_set_name);
12265 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012266 }
12267
Dave Barach72d72232016-08-04 10:15:08 -040012268 if (vec_len (locator_set_name) > 64)
12269 {
12270 errmsg ("locator-set name too long\n");
12271 vec_free (locator_set_name);
12272 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012273 }
Dave Barach72d72232016-08-04 10:15:08 -040012274 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012275
Dave Barach72d72232016-08-04 10:15:08 -040012276 /* Construct the API message */
12277 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012278
Dave Barach72d72232016-08-04 10:15:08 -040012279 mp->is_add = is_add;
12280 mp->sw_if_index = ntohl (sw_if_index);
12281 mp->priority = priority;
12282 mp->weight = weight;
12283 clib_memcpy (mp->locator_set_name, locator_set_name,
12284 vec_len (locator_set_name));
12285 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012286
Dave Barach72d72232016-08-04 10:15:08 -040012287 /* send it... */
12288 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012289
Dave Barach72d72232016-08-04 10:15:08 -040012290 /* Wait for a reply... */
12291 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012292
Dave Barach72d72232016-08-04 10:15:08 -040012293 /* NOTREACHED */
12294 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012295}
12296
12297static int
Dave Barach72d72232016-08-04 10:15:08 -040012298api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012299{
Dave Barach72d72232016-08-04 10:15:08 -040012300 unformat_input_t *input = vam->input;
12301 vl_api_lisp_add_del_local_eid_t *mp;
12302 f64 timeout = ~0;
12303 u8 is_add = 1;
12304 u8 eid_set = 0;
12305 lisp_eid_vat_t _eid, *eid = &_eid;
12306 u8 *locator_set_name = 0;
12307 u8 locator_set_name_set = 0;
12308 u32 vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012309
Dave Barach72d72232016-08-04 10:15:08 -040012310 /* Parse args required to build the message */
12311 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12312 {
12313 if (unformat (input, "del"))
12314 {
12315 is_add = 0;
12316 }
12317 else if (unformat (input, "vni %d", &vni))
12318 {
12319 ;
12320 }
12321 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
12322 {
12323 eid_set = 1;
12324 }
12325 else if (unformat (input, "locator-set %s", &locator_set_name))
12326 {
12327 locator_set_name_set = 1;
12328 }
12329 else
12330 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012331 }
12332
Dave Barach72d72232016-08-04 10:15:08 -040012333 if (locator_set_name_set == 0)
12334 {
12335 errmsg ("missing locator-set name\n");
12336 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012337 }
12338
Dave Barach72d72232016-08-04 10:15:08 -040012339 if (0 == eid_set)
12340 {
12341 errmsg ("EID address not set!");
12342 vec_free (locator_set_name);
12343 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020012344 }
12345
Dave Barach72d72232016-08-04 10:15:08 -040012346 if (vec_len (locator_set_name) > 64)
12347 {
12348 errmsg ("locator-set name too long\n");
12349 vec_free (locator_set_name);
12350 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012351 }
Dave Barach72d72232016-08-04 10:15:08 -040012352 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012353
Dave Barach72d72232016-08-04 10:15:08 -040012354 /* Construct the API message */
12355 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012356
Dave Barach72d72232016-08-04 10:15:08 -040012357 mp->is_add = is_add;
12358 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
12359 mp->eid_type = eid->type;
12360 mp->prefix_len = eid->len;
12361 mp->vni = clib_host_to_net_u32 (vni);
12362 clib_memcpy (mp->locator_set_name, locator_set_name,
12363 vec_len (locator_set_name));
Florin Coras429e7952016-08-02 02:31:03 +020012364
Dave Barach72d72232016-08-04 10:15:08 -040012365 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012366
Dave Barach72d72232016-08-04 10:15:08 -040012367 /* send it... */
12368 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012369
Dave Barach72d72232016-08-04 10:15:08 -040012370 /* Wait for a reply... */
12371 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012372
Dave Barach72d72232016-08-04 10:15:08 -040012373 /* NOTREACHED */
12374 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012375}
12376
Dave Barach72d72232016-08-04 10:15:08 -040012377/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012378/** Used for transferring locators via VPP API */
12379typedef CLIB_PACKED(struct
12380{
Dave Barach72d72232016-08-04 10:15:08 -040012381 u8 is_ip4; /**< is locator an IPv4 address? */
12382 u8 priority; /**< locator priority */
12383 u8 weight; /**< locator weight */
12384 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020012385}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040012386/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012387
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012388static int
Dave Barach72d72232016-08-04 10:15:08 -040012389api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012390{
Dave Barach72d72232016-08-04 10:15:08 -040012391 unformat_input_t *input = vam->input;
12392 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
12393 f64 timeout = ~0;
12394 u8 is_add = 1;
12395 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
12396 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
12397 u8 rmt_eid_set = 0, lcl_eid_set = 0;
12398 u32 action = ~0, p, w;
12399 ip4_address_t rmt_rloc4, lcl_rloc4;
12400 ip6_address_t rmt_rloc6, lcl_rloc6;
12401 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012402
Dave Barach839fe3e2016-08-10 11:35:54 -040012403 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020012404
Dave Barach72d72232016-08-04 10:15:08 -040012405 /* Parse args required to build the message */
12406 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12407 {
12408 if (unformat (input, "del"))
12409 {
12410 is_add = 0;
12411 }
12412 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
12413 {
12414 rmt_eid_set = 1;
12415 }
12416 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
12417 {
12418 lcl_eid_set = 1;
12419 }
12420 else if (unformat (input, "p %d w %d", &p, &w))
12421 {
12422 if (!curr_rloc)
12423 {
12424 errmsg ("No RLOC configured for setting priority/weight!");
12425 return -99;
12426 }
12427 curr_rloc->priority = p;
12428 curr_rloc->weight = w;
12429 }
12430 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
12431 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
12432 {
12433 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020012434
Dave Barach72d72232016-08-04 10:15:08 -040012435 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020012436 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012437 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012438
Dave Barach72d72232016-08-04 10:15:08 -040012439 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
12440 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012441 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012442 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12443 }
Florin Coras7fbfad32016-08-05 16:57:33 +020012444 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040012445 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
12446 {
12447 rloc.is_ip4 = 0;
12448 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020012449 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012450 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012451
Dave Barach72d72232016-08-04 10:15:08 -040012452 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
12453 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012454 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012455 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12456 }
12457 else if (unformat (input, "action %d", &action))
12458 {
12459 ;
12460 }
12461 else
12462 {
12463 clib_warning ("parse error '%U'", format_unformat_error, input);
12464 return -99;
12465 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012466 }
12467
Dave Barach72d72232016-08-04 10:15:08 -040012468 if (!rmt_eid_set)
12469 {
12470 errmsg ("remote eid addresses not set\n");
12471 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012472 }
12473
Dave Barach72d72232016-08-04 10:15:08 -040012474 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
12475 {
12476 errmsg ("eid types don't match\n");
12477 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012478 }
12479
Dave Barach839fe3e2016-08-10 11:35:54 -040012480 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020012481 {
12482 errmsg ("action not set for negative mapping\n");
12483 return -99;
12484 }
12485
Dave Barach72d72232016-08-04 10:15:08 -040012486 /* Construct the API message */
12487 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012488
Dave Barach72d72232016-08-04 10:15:08 -040012489 mp->is_add = is_add;
12490 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
12491 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
12492 mp->eid_type = rmt_eid->type;
12493 mp->rmt_len = rmt_eid->len;
12494 mp->lcl_len = lcl_eid->len;
12495 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020012496
Florin Coras7fbfad32016-08-05 16:57:33 +020012497 if (0 != rmt_locs && 0 != lcl_locs)
12498 {
Dave Barach839fe3e2016-08-10 11:35:54 -040012499 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020012500 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012501 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012502 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012503 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012504 }
Dave Barach72d72232016-08-04 10:15:08 -040012505 vec_free (lcl_locs);
12506 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012507
Dave Barach72d72232016-08-04 10:15:08 -040012508 /* send it... */
12509 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012510
Dave Barach72d72232016-08-04 10:15:08 -040012511 /* Wait for a reply... */
12512 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012513
Dave Barach72d72232016-08-04 10:15:08 -040012514 /* NOTREACHED */
12515 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012516}
12517
12518static int
Dave Barach72d72232016-08-04 10:15:08 -040012519api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012520{
Dave Barach72d72232016-08-04 10:15:08 -040012521 unformat_input_t *input = vam->input;
12522 vl_api_lisp_add_del_map_resolver_t *mp;
12523 f64 timeout = ~0;
12524 u8 is_add = 1;
12525 u8 ipv4_set = 0;
12526 u8 ipv6_set = 0;
12527 ip4_address_t ipv4;
12528 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012529
Dave Barach72d72232016-08-04 10:15:08 -040012530 /* Parse args required to build the message */
12531 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12532 {
12533 if (unformat (input, "del"))
12534 {
12535 is_add = 0;
12536 }
12537 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
12538 {
12539 ipv4_set = 1;
12540 }
12541 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
12542 {
12543 ipv6_set = 1;
12544 }
12545 else
12546 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012547 }
12548
Dave Barach72d72232016-08-04 10:15:08 -040012549 if (ipv4_set && ipv6_set)
12550 {
12551 errmsg ("both eid v4 and v6 addresses set\n");
12552 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012553 }
12554
Dave Barach72d72232016-08-04 10:15:08 -040012555 if (!ipv4_set && !ipv6_set)
12556 {
12557 errmsg ("eid addresses not set\n");
12558 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012559 }
12560
Dave Barach72d72232016-08-04 10:15:08 -040012561 /* Construct the API message */
12562 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012563
Dave Barach72d72232016-08-04 10:15:08 -040012564 mp->is_add = is_add;
12565 if (ipv6_set)
12566 {
12567 mp->is_ipv6 = 1;
12568 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
12569 }
12570 else
12571 {
12572 mp->is_ipv6 = 0;
12573 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012574 }
12575
Dave Barach72d72232016-08-04 10:15:08 -040012576 /* send it... */
12577 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012578
Dave Barach72d72232016-08-04 10:15:08 -040012579 /* Wait for a reply... */
12580 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012581
Dave Barach72d72232016-08-04 10:15:08 -040012582 /* NOTREACHED */
12583 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012584}
12585
12586static int
Florin Coras577c3552016-04-21 00:45:40 +020012587api_lisp_gpe_enable_disable (vat_main_t * vam)
12588{
Dave Barach72d72232016-08-04 10:15:08 -040012589 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020012590 vl_api_lisp_gpe_enable_disable_t *mp;
12591 f64 timeout = ~0;
12592 u8 is_set = 0;
12593 u8 is_en = 1;
12594
12595 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040012596 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12597 {
12598 if (unformat (input, "enable"))
12599 {
12600 is_set = 1;
12601 is_en = 1;
12602 }
12603 else if (unformat (input, "disable"))
12604 {
12605 is_set = 1;
12606 is_en = 0;
12607 }
12608 else
12609 break;
12610 }
Florin Coras577c3552016-04-21 00:45:40 +020012611
Dave Barach72d72232016-08-04 10:15:08 -040012612 if (is_set == 0)
12613 {
12614 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020012615 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040012616 }
Florin Coras577c3552016-04-21 00:45:40 +020012617
12618 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012619 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020012620
12621 mp->is_en = is_en;
12622
12623 /* send it... */
12624 S;
12625
12626 /* Wait for a reply... */
12627 W;
12628
12629 /* NOTREACHED */
12630 return 0;
12631}
12632
12633static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020012634api_lisp_enable_disable (vat_main_t * vam)
12635{
Dave Barach72d72232016-08-04 10:15:08 -040012636 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020012637 vl_api_lisp_enable_disable_t *mp;
12638 f64 timeout = ~0;
12639 u8 is_set = 0;
12640 u8 is_en = 0;
12641
12642 /* Parse args required to build the message */
12643 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12644 {
12645 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040012646 {
12647 is_set = 1;
12648 is_en = 1;
12649 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020012650 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040012651 {
12652 is_set = 1;
12653 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020012654 else
Dave Barach72d72232016-08-04 10:15:08 -040012655 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020012656 }
12657
12658 if (!is_set)
12659 {
12660 errmsg ("Value not set\n");
12661 return -99;
12662 }
12663
12664 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012665 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020012666
12667 mp->is_en = is_en;
12668
12669 /* send it... */
12670 S;
12671
12672 /* Wait for a reply... */
12673 W;
12674
12675 /* NOTREACHED */
12676 return 0;
12677}
12678
Florin Corasdca88042016-09-14 16:01:38 +020012679static int
12680api_show_lisp_map_request_mode (vat_main_t * vam)
12681{
12682 f64 timeout = ~0;
12683 vl_api_show_lisp_map_request_mode_t *mp;
12684
12685 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
12686
12687 /* send */
12688 S;
12689
12690 /* wait for reply */
12691 W;
12692
12693 return 0;
12694}
12695
12696static int
12697api_lisp_map_request_mode (vat_main_t * vam)
12698{
12699 f64 timeout = ~0;
12700 unformat_input_t *input = vam->input;
12701 vl_api_lisp_map_request_mode_t *mp;
12702 u8 mode = 0;
12703
12704 /* Parse args required to build the message */
12705 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12706 {
12707 if (unformat (input, "dst-only"))
12708 mode = 0;
12709 else if (unformat (input, "src-dst"))
12710 mode = 1;
12711 else
12712 {
12713 errmsg ("parse error '%U'", format_unformat_error, input);
12714 return -99;
12715 }
12716 }
12717
12718 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
12719
12720 mp->mode = mode;
12721
12722 /* send */
12723 S;
12724
12725 /* wait for reply */
12726 W;
12727
12728 /* notreached */
12729 return 0;
12730}
12731
Filip Tehlar195bcee2016-05-13 17:37:35 +020012732/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020012733 * Enable/disable LISP proxy ITR.
12734 *
12735 * @param vam vpp API test context
12736 * @return return code
12737 */
12738static int
12739api_lisp_pitr_set_locator_set (vat_main_t * vam)
12740{
12741 f64 timeout = ~0;
12742 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012743 unformat_input_t *input = vam->input;
12744 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012745 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012746 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012747
12748 /* Parse args required to build the message */
12749 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12750 {
12751 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040012752 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012753 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040012754 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012755 else
Dave Barach72d72232016-08-04 10:15:08 -040012756 {
12757 errmsg ("parse error '%U'", format_unformat_error, input);
12758 return -99;
12759 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020012760 }
12761
12762 if (!ls_name_set)
12763 {
12764 errmsg ("locator-set name not set!");
12765 return -99;
12766 }
12767
Dave Barach72d72232016-08-04 10:15:08 -040012768 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020012769
12770 mp->is_add = is_add;
12771 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
12772 vec_free (ls_name);
12773
12774 /* send */
12775 S;
12776
12777 /* wait for reply */
12778 W;
12779
Dave Barach72d72232016-08-04 10:15:08 -040012780 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020012781 return 0;
12782}
12783
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012784static int
12785api_show_lisp_pitr (vat_main_t * vam)
12786{
Dave Barach72d72232016-08-04 10:15:08 -040012787 vl_api_show_lisp_pitr_t *mp;
12788 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012789
Dave Barach72d72232016-08-04 10:15:08 -040012790 if (!vam->json_output)
12791 {
12792 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012793 }
12794
Dave Barach72d72232016-08-04 10:15:08 -040012795 M (SHOW_LISP_PITR, show_lisp_pitr);
12796 /* send it... */
12797 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012798
Dave Barach72d72232016-08-04 10:15:08 -040012799 /* Wait for a reply... */
12800 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012801
Dave Barach72d72232016-08-04 10:15:08 -040012802 /* NOTREACHED */
12803 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012804}
12805
Filip Tehlar53f09e32016-05-19 14:25:44 +020012806/**
Filip Tehlar324112f2016-06-02 16:07:38 +020012807 * Add/delete mapping between vni and vrf
12808 */
12809static int
12810api_lisp_eid_table_add_del_map (vat_main_t * vam)
12811{
12812 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040012813 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020012814 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020012815 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
12816 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020012817
12818 /* Parse args required to build the message */
12819 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12820 {
12821 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040012822 is_add = 0;
12823 else if (unformat (input, "vrf %d", &vrf))
12824 vrf_set = 1;
12825 else if (unformat (input, "bd_index %d", &bd_index))
12826 bd_index_set = 1;
12827 else if (unformat (input, "vni %d", &vni))
12828 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020012829 else
Dave Barach72d72232016-08-04 10:15:08 -040012830 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020012831 }
12832
Florin Coras1a1adc72016-07-22 01:45:30 +020012833 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020012834 {
12835 errmsg ("missing arguments!");
12836 return -99;
12837 }
12838
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020012839 if (vrf_set && bd_index_set)
12840 {
12841 errmsg ("error: both vrf and bd entered!");
12842 return -99;
12843 }
12844
Dave Barach72d72232016-08-04 10:15:08 -040012845 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020012846
12847 mp->is_add = is_add;
12848 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020012849 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020012850 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020012851
12852 /* send */
12853 S;
12854
12855 /* wait for reply */
12856 W;
12857
Dave Barach72d72232016-08-04 10:15:08 -040012858 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020012859 return 0;
12860}
12861
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012862uword
12863unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
12864{
12865 u32 *action = va_arg (*args, u32 *);
12866 u8 *s = 0;
12867
12868 if (unformat (input, "%s", &s))
12869 {
12870 if (!strcmp ((char *) s, "no-action"))
12871 action[0] = 0;
12872 else if (!strcmp ((char *) s, "natively-forward"))
12873 action[0] = 1;
12874 else if (!strcmp ((char *) s, "send-map-request"))
12875 action[0] = 2;
12876 else if (!strcmp ((char *) s, "drop"))
12877 action[0] = 3;
12878 else
12879 {
12880 clib_warning ("invalid action: '%s'", s);
12881 action[0] = 3;
12882 }
12883 }
12884 else
12885 return 0;
12886
12887 vec_free (s);
12888 return 1;
12889}
12890
Filip Tehlar324112f2016-06-02 16:07:38 +020012891/**
Florin Corasf727db92016-06-23 15:01:58 +020012892 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020012893 *
12894 * @param vam vpp API test context
12895 * @return return code
12896 */
12897static int
12898api_lisp_add_del_remote_mapping (vat_main_t * vam)
12899{
Dave Barach72d72232016-08-04 10:15:08 -040012900 unformat_input_t *input = vam->input;
12901 vl_api_lisp_add_del_remote_mapping_t *mp;
12902 f64 timeout = ~0;
12903 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012904 lisp_eid_vat_t _eid, *eid = &_eid;
12905 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012906 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012907 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040012908 ip4_address_t rloc4;
12909 ip6_address_t rloc6;
12910 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012911
Dave Barach839fe3e2016-08-10 11:35:54 -040012912 memset (&rloc, 0, sizeof (rloc));
12913
Dave Barach72d72232016-08-04 10:15:08 -040012914 /* Parse args required to build the message */
12915 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12916 {
12917 if (unformat (input, "del-all"))
12918 {
12919 del_all = 1;
12920 }
12921 else if (unformat (input, "del"))
12922 {
12923 is_add = 0;
12924 }
12925 else if (unformat (input, "add"))
12926 {
12927 is_add = 1;
12928 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020012929 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040012930 {
12931 eid_set = 1;
12932 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012933 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040012934 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012935 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012936 }
12937 else if (unformat (input, "vni %d", &vni))
12938 {
12939 ;
12940 }
12941 else if (unformat (input, "p %d w %d", &p, &w))
12942 {
12943 if (!curr_rloc)
12944 {
12945 errmsg ("No RLOC configured for setting priority/weight!");
12946 return -99;
12947 }
12948 curr_rloc->priority = p;
12949 curr_rloc->weight = w;
12950 }
12951 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
12952 {
12953 rloc.is_ip4 = 1;
12954 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
12955 vec_add1 (rlocs, rloc);
12956 curr_rloc = &rlocs[vec_len (rlocs) - 1];
12957 }
12958 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
12959 {
12960 rloc.is_ip4 = 0;
12961 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
12962 vec_add1 (rlocs, rloc);
12963 curr_rloc = &rlocs[vec_len (rlocs) - 1];
12964 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012965 else if (unformat (input, "action %U",
12966 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040012967 {
12968 ;
12969 }
12970 else
12971 {
12972 clib_warning ("parse error '%U'", format_unformat_error, input);
12973 return -99;
12974 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020012975 }
12976
Dave Barach72d72232016-08-04 10:15:08 -040012977 if (0 == eid_set)
12978 {
12979 errmsg ("missing params!");
12980 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012981 }
12982
Dave Barach72d72232016-08-04 10:15:08 -040012983 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
12984 {
12985 errmsg ("no action set for negative map-reply!");
12986 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012987 }
12988
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012989 data_len = vec_len (rlocs) * sizeof (rloc_t);
12990
12991 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012992 mp->is_add = is_add;
12993 mp->vni = htonl (vni);
12994 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012995 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040012996 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012997 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040012998 mp->del_all = del_all;
12999 mp->eid_type = eid->type;
13000 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013001 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013002
Filip Tehlare3552c42016-08-26 12:44:38 +020013003 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013004 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013005 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013006
Dave Barach72d72232016-08-04 10:15:08 -040013007 /* send it... */
13008 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013009
Dave Barach72d72232016-08-04 10:15:08 -040013010 /* Wait for a reply... */
13011 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013012
Dave Barach72d72232016-08-04 10:15:08 -040013013 /* NOTREACHED */
13014 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013015}
13016
Florin Corasf727db92016-06-23 15:01:58 +020013017/**
13018 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
13019 * forwarding entries in data-plane accordingly.
13020 *
13021 * @param vam vpp API test context
13022 * @return return code
13023 */
13024static int
13025api_lisp_add_del_adjacency (vat_main_t * vam)
13026{
Dave Barach72d72232016-08-04 10:15:08 -040013027 unformat_input_t *input = vam->input;
13028 vl_api_lisp_add_del_adjacency_t *mp;
13029 f64 timeout = ~0;
13030 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013031 ip4_address_t leid4, reid4;
13032 ip6_address_t leid6, reid6;
13033 u8 reid_mac[6] = { 0 };
13034 u8 leid_mac[6] = { 0 };
13035 u8 reid_type, leid_type;
13036 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040013037 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020013038
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013039 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020013040
Dave Barach72d72232016-08-04 10:15:08 -040013041 /* Parse args required to build the message */
13042 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13043 {
13044 if (unformat (input, "del"))
13045 {
13046 is_add = 0;
13047 }
13048 else if (unformat (input, "add"))
13049 {
13050 is_add = 1;
13051 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013052 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
13053 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013054 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013055 reid_type = 0; /* ipv4 */
13056 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013057 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013058 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
13059 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013060 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013061 reid_type = 1; /* ipv6 */
13062 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013063 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013064 else if (unformat (input, "reid %U", unformat_ethernet_address,
13065 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013066 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013067 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013068 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013069 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
13070 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013071 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013072 leid_type = 0; /* ipv4 */
13073 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013074 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013075 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
13076 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013077 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013078 leid_type = 1; /* ipv6 */
13079 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013080 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013081 else if (unformat (input, "leid %U", unformat_ethernet_address,
13082 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013083 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013084 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013085 }
13086 else if (unformat (input, "vni %d", &vni))
13087 {
13088 ;
13089 }
13090 else
13091 {
13092 errmsg ("parse error '%U'", format_unformat_error, input);
13093 return -99;
13094 }
Florin Corasf727db92016-06-23 15:01:58 +020013095 }
13096
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013097 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013098 {
13099 errmsg ("missing params!");
13100 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013101 }
13102
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013103 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013104 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013105 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040013106 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013107 }
13108
Dave Barach72d72232016-08-04 10:15:08 -040013109 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
13110 mp->is_add = is_add;
13111 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013112 mp->leid_len = leid_len;
13113 mp->reid_len = reid_len;
13114 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020013115
Dave Barach72d72232016-08-04 10:15:08 -040013116 switch (mp->eid_type)
13117 {
Florin Corasf727db92016-06-23 15:01:58 +020013118 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013119 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
13120 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040013121 break;
Florin Corasf727db92016-06-23 15:01:58 +020013122 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013123 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
13124 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040013125 break;
Florin Corasf727db92016-06-23 15:01:58 +020013126 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013127 clib_memcpy (mp->leid, leid_mac, 6);
13128 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040013129 break;
Florin Corasf727db92016-06-23 15:01:58 +020013130 default:
Dave Barach72d72232016-08-04 10:15:08 -040013131 errmsg ("unknown EID type %d!", mp->eid_type);
13132 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013133 }
13134
Dave Barach72d72232016-08-04 10:15:08 -040013135 /* send it... */
13136 S;
Florin Corasf727db92016-06-23 15:01:58 +020013137
Dave Barach72d72232016-08-04 10:15:08 -040013138 /* Wait for a reply... */
13139 W;
Florin Corasf727db92016-06-23 15:01:58 +020013140
Dave Barach72d72232016-08-04 10:15:08 -040013141 /* NOTREACHED */
13142 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013143}
13144
Filip Tehlar46d4e362016-05-09 09:39:26 +020013145static int
Dave Barach72d72232016-08-04 10:15:08 -040013146api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013147{
Dave Barach72d72232016-08-04 10:15:08 -040013148 unformat_input_t *input = vam->input;
13149 vl_api_lisp_gpe_add_del_iface_t *mp;
13150 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020013151 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040013152 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013153
Dave Barach72d72232016-08-04 10:15:08 -040013154 /* Parse args required to build the message */
13155 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13156 {
13157 if (unformat (input, "up"))
13158 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013159 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013160 is_add = 1;
13161 }
13162 else if (unformat (input, "down"))
13163 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013164 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013165 is_add = 0;
13166 }
13167 else if (unformat (input, "table_id %d", &dp_table))
13168 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013169 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013170 }
13171 else if (unformat (input, "bd_id %d", &dp_table))
13172 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013173 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013174 is_l2 = 1;
13175 }
13176 else if (unformat (input, "vni %d", &vni))
13177 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013178 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013179 }
13180 else
13181 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013182 }
13183
Florin Coras7fbfad32016-08-05 16:57:33 +020013184 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040013185 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013186 errmsg ("Action not set\n");
13187 return -99;
13188 }
13189 if (dp_table_set == 0 || vni_set == 0)
13190 {
13191 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040013192 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013193 }
13194
Dave Barach72d72232016-08-04 10:15:08 -040013195 /* Construct the API message */
13196 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013197
Dave Barach72d72232016-08-04 10:15:08 -040013198 mp->is_add = is_add;
13199 mp->dp_table = dp_table;
13200 mp->is_l2 = is_l2;
13201 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013202
Dave Barach72d72232016-08-04 10:15:08 -040013203 /* send it... */
13204 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013205
Dave Barach72d72232016-08-04 10:15:08 -040013206 /* Wait for a reply... */
13207 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013208
Dave Barach72d72232016-08-04 10:15:08 -040013209 /* NOTREACHED */
13210 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013211}
13212
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013213/**
13214 * Add/del map request itr rlocs from LISP control plane and updates
13215 *
13216 * @param vam vpp API test context
13217 * @return return code
13218 */
13219static int
Dave Barach72d72232016-08-04 10:15:08 -040013220api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013221{
Dave Barach72d72232016-08-04 10:15:08 -040013222 unformat_input_t *input = vam->input;
13223 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
13224 f64 timeout = ~0;
13225 u8 *locator_set_name = 0;
13226 u8 locator_set_name_set = 0;
13227 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013228
Dave Barach72d72232016-08-04 10:15:08 -040013229 /* Parse args required to build the message */
13230 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013231 {
Dave Barach72d72232016-08-04 10:15:08 -040013232 if (unformat (input, "del"))
13233 {
13234 is_add = 0;
13235 }
13236 else if (unformat (input, "%_%v%_", &locator_set_name))
13237 {
13238 locator_set_name_set = 1;
13239 }
13240 else
13241 {
13242 clib_warning ("parse error '%U'", format_unformat_error, input);
13243 return -99;
13244 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013245 }
13246
Dave Barach72d72232016-08-04 10:15:08 -040013247 if (is_add && !locator_set_name_set)
13248 {
13249 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020013250 return -99;
13251 }
13252
Dave Barach72d72232016-08-04 10:15:08 -040013253 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020013254 {
Dave Barach72d72232016-08-04 10:15:08 -040013255 errmsg ("itr-rloc locator-set name too long\n");
13256 vec_free (locator_set_name);
13257 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013258 }
13259
Dave Barach72d72232016-08-04 10:15:08 -040013260 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
13261 mp->is_add = is_add;
13262 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013263 {
Dave Barach72d72232016-08-04 10:15:08 -040013264 clib_memcpy (mp->locator_set_name, locator_set_name,
13265 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013266 }
Dave Barach72d72232016-08-04 10:15:08 -040013267 else
13268 {
13269 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013270 }
Dave Barach72d72232016-08-04 10:15:08 -040013271 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013272
Dave Barach72d72232016-08-04 10:15:08 -040013273 /* send it... */
13274 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013275
Dave Barach72d72232016-08-04 10:15:08 -040013276 /* Wait for a reply... */
13277 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013278
Dave Barach72d72232016-08-04 10:15:08 -040013279 /* NOTREACHED */
13280 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013281}
13282
13283static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013284api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013285{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013286 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013287 vl_api_lisp_locator_dump_t *mp;
13288 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013289 u8 is_index_set = 0, is_name_set = 0;
13290 u8 *ls_name = 0;
13291 u32 ls_index = ~0;
13292
13293 /* Parse args required to build the message */
13294 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13295 {
13296 if (unformat (input, "ls_name %_%v%_", &ls_name))
13297 {
13298 is_name_set = 1;
13299 }
13300 else if (unformat (input, "ls_index %d", &ls_index))
13301 {
13302 is_index_set = 1;
13303 }
13304 else
13305 {
13306 errmsg ("parse error '%U'", format_unformat_error, input);
13307 return -99;
13308 }
13309 }
13310
13311 if (!is_index_set && !is_name_set)
13312 {
13313 errmsg ("error: expected one of index or name!\n");
13314 return -99;
13315 }
13316
13317 if (is_index_set && is_name_set)
13318 {
13319 errmsg ("error: only one param expected!\n");
13320 return -99;
13321 }
13322
Florin Coras042d2122016-09-21 16:38:19 +020013323 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020013324 {
13325 errmsg ("error: locator set name too long!");
13326 return -99;
13327 }
13328
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013329 if (!vam->json_output)
13330 {
13331 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
13332 "weight");
13333 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013334
Dave Barach72d72232016-08-04 10:15:08 -040013335 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013336 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013337
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013338 if (is_index_set)
13339 mp->ls_index = clib_host_to_net_u32 (ls_index);
13340 else
13341 {
13342 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020013343 strncpy ((char *) mp->ls_name, (char *) ls_name,
13344 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013345 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013346
Dave Barach72d72232016-08-04 10:15:08 -040013347 /* send it... */
13348 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013349
Dave Barach72d72232016-08-04 10:15:08 -040013350 /* Use a control ping for synchronization */
13351 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013352 vl_api_control_ping_t *mp;
13353 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013354 S;
13355 }
13356 /* Wait for a reply... */
13357 W;
Dave Barach72d72232016-08-04 10:15:08 -040013358
13359 /* NOTREACHED */
13360 return 0;
13361}
13362
13363static int
13364api_lisp_locator_set_dump (vat_main_t * vam)
13365{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013366 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040013367 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013368 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013369 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013370
13371 /* Parse args required to build the message */
13372 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13373 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013374 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040013375 {
13376 filter = 1;
13377 }
13378 else if (unformat (input, "remote"))
13379 {
13380 filter = 2;
13381 }
13382 else
13383 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013384 errmsg ("parse error '%U'", format_unformat_error, input);
13385 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013386 }
13387 }
13388
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013389 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040013390 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013391 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040013392 }
13393
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013394 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040013395
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013396 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040013397
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013398 /* send it... */
13399 S;
13400
13401 /* Use a control ping for synchronization */
13402 {
13403 vl_api_control_ping_t *mp;
13404 M (CONTROL_PING, control_ping);
13405 S;
13406 }
13407 /* Wait for a reply... */
13408 W;
13409
13410 /* NOTREACHED */
13411 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040013412}
13413
13414static int
13415api_lisp_eid_table_map_dump (vat_main_t * vam)
13416{
Filip Tehlarc0681792016-08-24 14:11:07 +020013417 u8 is_l2 = 0;
13418 u8 mode_set = 0;
13419 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013420 vl_api_lisp_eid_table_map_dump_t *mp;
13421 f64 timeout = ~0;
13422
Filip Tehlarc0681792016-08-24 14:11:07 +020013423 /* Parse args required to build the message */
13424 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13425 {
13426 if (unformat (input, "l2"))
13427 {
13428 is_l2 = 1;
13429 mode_set = 1;
13430 }
13431 else if (unformat (input, "l3"))
13432 {
13433 is_l2 = 0;
13434 mode_set = 1;
13435 }
13436 else
13437 {
13438 errmsg ("parse error '%U'", format_unformat_error, input);
13439 return -99;
13440 }
13441 }
13442
13443 if (!mode_set)
13444 {
13445 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
13446 return -99;
13447 }
13448
Dave Barach72d72232016-08-04 10:15:08 -040013449 if (!vam->json_output)
13450 {
Filip Tehlarc0681792016-08-24 14:11:07 +020013451 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040013452 }
13453
13454 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020013455 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040013456
13457 /* send it... */
13458 S;
13459
13460 /* Use a control ping for synchronization */
13461 {
13462 vl_api_control_ping_t *mp;
13463 M (CONTROL_PING, control_ping);
13464 S;
13465 }
13466 /* Wait for a reply... */
13467 W;
13468
13469 /* NOTREACHED */
13470 return 0;
13471}
13472
13473static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020013474api_lisp_eid_table_vni_dump (vat_main_t * vam)
13475{
13476 vl_api_lisp_eid_table_vni_dump_t *mp;
13477 f64 timeout = ~0;
13478
13479 if (!vam->json_output)
13480 {
13481 fformat (vam->ofp, "VNI\n");
13482 }
13483
13484 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
13485
13486 /* send it... */
13487 S;
13488
13489 /* Use a control ping for synchronization */
13490 {
13491 vl_api_control_ping_t *mp;
13492 M (CONTROL_PING, control_ping);
13493 S;
13494 }
13495 /* Wait for a reply... */
13496 W;
13497
13498 /* NOTREACHED */
13499 return 0;
13500}
13501
13502static int
Dave Barach72d72232016-08-04 10:15:08 -040013503api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013504{
Dave Barach72d72232016-08-04 10:15:08 -040013505 unformat_input_t *i = vam->input;
13506 vl_api_lisp_eid_table_dump_t *mp;
13507 f64 timeout = ~0;
13508 struct in_addr ip4;
13509 struct in6_addr ip6;
13510 u8 mac[6];
13511 u8 eid_type = ~0, eid_set = 0;
13512 u32 prefix_length = ~0, t, vni = 0;
13513 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013514
Dave Barach72d72232016-08-04 10:15:08 -040013515 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013516 {
Dave Barach72d72232016-08-04 10:15:08 -040013517 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
13518 {
13519 eid_set = 1;
13520 eid_type = 0;
13521 prefix_length = t;
13522 }
13523 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
13524 {
13525 eid_set = 1;
13526 eid_type = 1;
13527 prefix_length = t;
13528 }
13529 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
13530 {
13531 eid_set = 1;
13532 eid_type = 2;
13533 }
13534 else if (unformat (i, "vni %d", &t))
13535 {
13536 vni = t;
13537 }
13538 else if (unformat (i, "local"))
13539 {
13540 filter = 1;
13541 }
13542 else if (unformat (i, "remote"))
13543 {
13544 filter = 2;
13545 }
13546 else
13547 {
13548 errmsg ("parse error '%U'", format_unformat_error, i);
13549 return -99;
13550 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013551 }
13552
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013553 if (!vam->json_output)
13554 {
13555 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type",
13556 "ls_index", "ttl", "authoritative");
13557 }
13558
Dave Barach72d72232016-08-04 10:15:08 -040013559 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013560
Dave Barach72d72232016-08-04 10:15:08 -040013561 mp->filter = filter;
13562 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013563 {
Dave Barach72d72232016-08-04 10:15:08 -040013564 mp->eid_set = 1;
13565 mp->vni = htonl (vni);
13566 mp->eid_type = eid_type;
13567 switch (eid_type)
13568 {
13569 case 0:
13570 mp->prefix_length = prefix_length;
13571 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
13572 break;
13573 case 1:
13574 mp->prefix_length = prefix_length;
13575 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
13576 break;
13577 case 2:
13578 clib_memcpy (mp->eid, mac, sizeof (mac));
13579 break;
13580 default:
13581 errmsg ("unknown EID type %d!", eid_type);
13582 return -99;
13583 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013584 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013585
Dave Barach72d72232016-08-04 10:15:08 -040013586 /* send it... */
13587 S;
13588
13589 /* Use a control ping for synchronization */
13590 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013591 vl_api_control_ping_t *mp;
13592 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013593 S;
13594 }
13595
13596 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013597 W;
Dave Barach72d72232016-08-04 10:15:08 -040013598
13599 /* NOTREACHED */
13600 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013601}
13602
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013603static int
Dave Barach72d72232016-08-04 10:15:08 -040013604api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013605{
Dave Barach72d72232016-08-04 10:15:08 -040013606 vl_api_lisp_gpe_tunnel_dump_t *mp;
13607 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013608
Dave Barach72d72232016-08-04 10:15:08 -040013609 if (!vam->json_output)
13610 {
13611 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
13612 "%=16s%=16s%=16s%=16s%=16s\n",
13613 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
13614 "Decap next", "Lisp version", "Flags", "Next protocol",
13615 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013616 }
13617
Dave Barach72d72232016-08-04 10:15:08 -040013618 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
13619 /* send it... */
13620 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013621
Dave Barach72d72232016-08-04 10:15:08 -040013622 /* Use a control ping for synchronization */
13623 {
13624 vl_api_control_ping_t *mp;
13625 M (CONTROL_PING, control_ping);
13626 S;
13627 }
13628 /* Wait for a reply... */
13629 W;
13630
13631 /* NOTREACHED */
13632 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013633}
13634
Matus Fabian8a95a482016-05-06 15:14:13 +020013635static int
Dave Barach72d72232016-08-04 10:15:08 -040013636api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013637{
Dave Barach72d72232016-08-04 10:15:08 -040013638 vl_api_lisp_map_resolver_dump_t *mp;
13639 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013640
Dave Barach72d72232016-08-04 10:15:08 -040013641 if (!vam->json_output)
13642 {
13643 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013644 }
13645
Dave Barach72d72232016-08-04 10:15:08 -040013646 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
13647 /* send it... */
13648 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013649
Dave Barach72d72232016-08-04 10:15:08 -040013650 /* Use a control ping for synchronization */
13651 {
13652 vl_api_control_ping_t *mp;
13653 M (CONTROL_PING, control_ping);
13654 S;
13655 }
13656 /* Wait for a reply... */
13657 W;
13658
13659 /* NOTREACHED */
13660 return 0;
13661}
13662
13663static int
13664api_show_lisp_status (vat_main_t * vam)
13665{
13666 vl_api_show_lisp_status_t *mp;
13667 f64 timeout = ~0;
13668
13669 if (!vam->json_output)
13670 {
13671 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
13672 }
13673
13674 M (SHOW_LISP_STATUS, show_lisp_status);
13675 /* send it... */
13676 S;
13677 /* Wait for a reply... */
13678 W;
13679
13680 /* NOTREACHED */
13681 return 0;
13682}
13683
13684static int
13685api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
13686{
13687 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
13688 f64 timeout = ~0;
13689
13690 if (!vam->json_output)
13691 {
13692 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
13693 }
13694
13695 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
13696 /* send it... */
13697 S;
13698 /* Wait for a reply... */
13699 W;
13700
13701 /* NOTREACHED */
13702 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013703}
13704
13705static int
Matus Fabian8a95a482016-05-06 15:14:13 +020013706api_af_packet_create (vat_main_t * vam)
13707{
Dave Barach72d72232016-08-04 10:15:08 -040013708 unformat_input_t *i = vam->input;
13709 vl_api_af_packet_create_t *mp;
13710 f64 timeout;
13711 u8 *host_if_name = 0;
13712 u8 hw_addr[6];
13713 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020013714
Dave Barach72d72232016-08-04 10:15:08 -040013715 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020013716
Dave Barach72d72232016-08-04 10:15:08 -040013717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13718 {
13719 if (unformat (i, "name %s", &host_if_name))
13720 vec_add1 (host_if_name, 0);
13721 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
13722 random_hw_addr = 0;
13723 else
13724 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020013725 }
13726
Dave Barach72d72232016-08-04 10:15:08 -040013727 if (!vec_len (host_if_name))
13728 {
13729 errmsg ("host-interface name must be specified");
13730 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013731 }
13732
Dave Barach72d72232016-08-04 10:15:08 -040013733 if (vec_len (host_if_name) > 64)
13734 {
13735 errmsg ("host-interface name too long");
13736 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013737 }
13738
Dave Barach72d72232016-08-04 10:15:08 -040013739 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020013740
Dave Barach72d72232016-08-04 10:15:08 -040013741 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
13742 clib_memcpy (mp->hw_addr, hw_addr, 6);
13743 mp->use_random_hw_addr = random_hw_addr;
13744 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020013745
Dave Barach72d72232016-08-04 10:15:08 -040013746 S;
13747 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
13748 /* NOTREACHED */
13749 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013750}
13751
13752static int
13753api_af_packet_delete (vat_main_t * vam)
13754{
Dave Barach72d72232016-08-04 10:15:08 -040013755 unformat_input_t *i = vam->input;
13756 vl_api_af_packet_delete_t *mp;
13757 f64 timeout;
13758 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013759
Dave Barach72d72232016-08-04 10:15:08 -040013760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13761 {
13762 if (unformat (i, "name %s", &host_if_name))
13763 vec_add1 (host_if_name, 0);
13764 else
13765 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020013766 }
13767
Dave Barach72d72232016-08-04 10:15:08 -040013768 if (!vec_len (host_if_name))
13769 {
13770 errmsg ("host-interface name must be specified");
13771 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013772 }
13773
Dave Barach72d72232016-08-04 10:15:08 -040013774 if (vec_len (host_if_name) > 64)
13775 {
13776 errmsg ("host-interface name too long");
13777 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013778 }
13779
Dave Barach72d72232016-08-04 10:15:08 -040013780 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020013781
Dave Barach72d72232016-08-04 10:15:08 -040013782 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
13783 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020013784
Dave Barach72d72232016-08-04 10:15:08 -040013785 S;
13786 W;
13787 /* NOTREACHED */
13788 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013789}
13790
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013791static int
13792api_policer_add_del (vat_main_t * vam)
13793{
Dave Barach72d72232016-08-04 10:15:08 -040013794 unformat_input_t *i = vam->input;
13795 vl_api_policer_add_del_t *mp;
13796 f64 timeout;
13797 u8 is_add = 1;
13798 u8 *name = 0;
13799 u32 cir = 0;
13800 u32 eir = 0;
13801 u64 cb = 0;
13802 u64 eb = 0;
13803 u8 rate_type = 0;
13804 u8 round_type = 0;
13805 u8 type = 0;
13806 u8 color_aware = 0;
13807 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013808
Dave Barach839fe3e2016-08-10 11:35:54 -040013809 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
13810 conform_action.dscp = 0;
13811 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
13812 exceed_action.dscp = 0;
13813 violate_action.action_type = SSE2_QOS_ACTION_DROP;
13814 violate_action.dscp = 0;
13815
Dave Barach72d72232016-08-04 10:15:08 -040013816 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13817 {
13818 if (unformat (i, "del"))
13819 is_add = 0;
13820 else if (unformat (i, "name %s", &name))
13821 vec_add1 (name, 0);
13822 else if (unformat (i, "cir %u", &cir))
13823 ;
13824 else if (unformat (i, "eir %u", &eir))
13825 ;
13826 else if (unformat (i, "cb %u", &cb))
13827 ;
13828 else if (unformat (i, "eb %u", &eb))
13829 ;
13830 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
13831 &rate_type))
13832 ;
13833 else if (unformat (i, "round_type %U", unformat_policer_round_type,
13834 &round_type))
13835 ;
13836 else if (unformat (i, "type %U", unformat_policer_type, &type))
13837 ;
13838 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
13839 &conform_action))
13840 ;
13841 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
13842 &exceed_action))
13843 ;
13844 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
13845 &violate_action))
13846 ;
13847 else if (unformat (i, "color-aware"))
13848 color_aware = 1;
13849 else
13850 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013851 }
13852
Dave Barach72d72232016-08-04 10:15:08 -040013853 if (!vec_len (name))
13854 {
13855 errmsg ("policer name must be specified");
13856 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013857 }
13858
Dave Barach72d72232016-08-04 10:15:08 -040013859 if (vec_len (name) > 64)
13860 {
13861 errmsg ("policer name too long");
13862 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013863 }
13864
Dave Barach72d72232016-08-04 10:15:08 -040013865 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013866
Dave Barach72d72232016-08-04 10:15:08 -040013867 clib_memcpy (mp->name, name, vec_len (name));
13868 vec_free (name);
13869 mp->is_add = is_add;
13870 mp->cir = cir;
13871 mp->eir = eir;
13872 mp->cb = cb;
13873 mp->eb = eb;
13874 mp->rate_type = rate_type;
13875 mp->round_type = round_type;
13876 mp->type = type;
13877 mp->conform_action_type = conform_action.action_type;
13878 mp->conform_dscp = conform_action.dscp;
13879 mp->exceed_action_type = exceed_action.action_type;
13880 mp->exceed_dscp = exceed_action.dscp;
13881 mp->violate_action_type = violate_action.action_type;
13882 mp->violate_dscp = violate_action.dscp;
13883 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013884
Dave Barach72d72232016-08-04 10:15:08 -040013885 S;
13886 W;
13887 /* NOTREACHED */
13888 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013889}
13890
Matus Fabian82e29c42016-05-11 04:49:46 -070013891static int
Dave Barach72d72232016-08-04 10:15:08 -040013892api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070013893{
Dave Barach72d72232016-08-04 10:15:08 -040013894 unformat_input_t *i = vam->input;
13895 vl_api_policer_dump_t *mp;
13896 f64 timeout = ~0;
13897 u8 *match_name = 0;
13898 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070013899
Dave Barach72d72232016-08-04 10:15:08 -040013900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070013901 {
Dave Barach72d72232016-08-04 10:15:08 -040013902 if (unformat (i, "name %s", &match_name))
13903 {
13904 vec_add1 (match_name, 0);
13905 match_name_valid = 1;
13906 }
13907 else
13908 break;
Matus Fabiane8554802016-05-18 23:40:37 -070013909 }
Matus Fabiane8554802016-05-18 23:40:37 -070013910
Dave Barach72d72232016-08-04 10:15:08 -040013911 M (POLICER_DUMP, policer_dump);
13912 mp->match_name_valid = match_name_valid;
13913 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
13914 vec_free (match_name);
13915 /* send it... */
13916 S;
13917
13918 /* Use a control ping for synchronization */
13919 {
13920 vl_api_control_ping_t *mp;
13921 M (CONTROL_PING, control_ping);
13922 S;
13923 }
13924 /* Wait for a reply... */
13925 W;
13926
13927 /* NOTREACHED */
13928 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070013929}
13930
13931static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013932api_policer_classify_set_interface (vat_main_t * vam)
13933{
Dave Barach72d72232016-08-04 10:15:08 -040013934 unformat_input_t *i = vam->input;
13935 vl_api_policer_classify_set_interface_t *mp;
13936 f64 timeout;
13937 u32 sw_if_index;
13938 int sw_if_index_set;
13939 u32 ip4_table_index = ~0;
13940 u32 ip6_table_index = ~0;
13941 u32 l2_table_index = ~0;
13942 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013943
Dave Barach72d72232016-08-04 10:15:08 -040013944 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13945 {
13946 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
13947 sw_if_index_set = 1;
13948 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13949 sw_if_index_set = 1;
13950 else if (unformat (i, "del"))
13951 is_add = 0;
13952 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13953 ;
13954 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13955 ;
13956 else if (unformat (i, "l2-table %d", &l2_table_index))
13957 ;
13958 else
13959 {
13960 clib_warning ("parse error '%U'", format_unformat_error, i);
13961 return -99;
13962 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013963 }
13964
Dave Barach72d72232016-08-04 10:15:08 -040013965 if (sw_if_index_set == 0)
13966 {
13967 errmsg ("missing interface name or sw_if_index\n");
13968 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013969 }
13970
Dave Barach72d72232016-08-04 10:15:08 -040013971 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013972
Dave Barach72d72232016-08-04 10:15:08 -040013973 mp->sw_if_index = ntohl (sw_if_index);
13974 mp->ip4_table_index = ntohl (ip4_table_index);
13975 mp->ip6_table_index = ntohl (ip6_table_index);
13976 mp->l2_table_index = ntohl (l2_table_index);
13977 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013978
Dave Barach72d72232016-08-04 10:15:08 -040013979 S;
13980 W;
13981 /* NOTREACHED */
13982 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013983}
13984
13985static int
Dave Barach72d72232016-08-04 10:15:08 -040013986api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013987{
Dave Barach72d72232016-08-04 10:15:08 -040013988 unformat_input_t *i = vam->input;
13989 vl_api_policer_classify_dump_t *mp;
13990 f64 timeout = ~0;
13991 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013992
Dave Barach72d72232016-08-04 10:15:08 -040013993 if (unformat (i, "type %U", unformat_classify_table_type, &type))
13994 ;
13995 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013996 {
Dave Barach72d72232016-08-04 10:15:08 -040013997 errmsg ("classify table type must be specified\n");
13998 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013999 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014000
Dave Barach72d72232016-08-04 10:15:08 -040014001 if (!vam->json_output)
14002 {
14003 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
14004 }
14005
14006 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
14007 mp->type = type;
14008 /* send it... */
14009 S;
14010
14011 /* Use a control ping for synchronization */
14012 {
14013 vl_api_control_ping_t *mp;
14014 M (CONTROL_PING, control_ping);
14015 S;
14016 }
14017 /* Wait for a reply... */
14018 W;
14019
14020 /* NOTREACHED */
14021 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014022}
14023
14024static int
Matus Fabian82e29c42016-05-11 04:49:46 -070014025api_netmap_create (vat_main_t * vam)
14026{
Dave Barach72d72232016-08-04 10:15:08 -040014027 unformat_input_t *i = vam->input;
14028 vl_api_netmap_create_t *mp;
14029 f64 timeout;
14030 u8 *if_name = 0;
14031 u8 hw_addr[6];
14032 u8 random_hw_addr = 1;
14033 u8 is_pipe = 0;
14034 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014035
Dave Barach72d72232016-08-04 10:15:08 -040014036 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070014037
Dave Barach72d72232016-08-04 10:15:08 -040014038 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14039 {
14040 if (unformat (i, "name %s", &if_name))
14041 vec_add1 (if_name, 0);
14042 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14043 random_hw_addr = 0;
14044 else if (unformat (i, "pipe"))
14045 is_pipe = 1;
14046 else if (unformat (i, "master"))
14047 is_master = 1;
14048 else if (unformat (i, "slave"))
14049 is_master = 0;
14050 else
14051 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014052 }
14053
Dave Barach72d72232016-08-04 10:15:08 -040014054 if (!vec_len (if_name))
14055 {
14056 errmsg ("interface name must be specified");
14057 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014058 }
14059
Dave Barach72d72232016-08-04 10:15:08 -040014060 if (vec_len (if_name) > 64)
14061 {
14062 errmsg ("interface name too long");
14063 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014064 }
14065
Dave Barach72d72232016-08-04 10:15:08 -040014066 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070014067
Dave Barach72d72232016-08-04 10:15:08 -040014068 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14069 clib_memcpy (mp->hw_addr, hw_addr, 6);
14070 mp->use_random_hw_addr = random_hw_addr;
14071 mp->is_pipe = is_pipe;
14072 mp->is_master = is_master;
14073 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014074
Dave Barach72d72232016-08-04 10:15:08 -040014075 S;
14076 W;
14077 /* NOTREACHED */
14078 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014079}
14080
14081static int
14082api_netmap_delete (vat_main_t * vam)
14083{
Dave Barach72d72232016-08-04 10:15:08 -040014084 unformat_input_t *i = vam->input;
14085 vl_api_netmap_delete_t *mp;
14086 f64 timeout;
14087 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014088
Dave Barach72d72232016-08-04 10:15:08 -040014089 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14090 {
14091 if (unformat (i, "name %s", &if_name))
14092 vec_add1 (if_name, 0);
14093 else
14094 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014095 }
14096
Dave Barach72d72232016-08-04 10:15:08 -040014097 if (!vec_len (if_name))
14098 {
14099 errmsg ("interface name must be specified");
14100 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014101 }
14102
Dave Barach72d72232016-08-04 10:15:08 -040014103 if (vec_len (if_name) > 64)
14104 {
14105 errmsg ("interface name too long");
14106 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014107 }
14108
Dave Barach72d72232016-08-04 10:15:08 -040014109 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070014110
Dave Barach72d72232016-08-04 10:15:08 -040014111 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14112 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014113
Dave Barach72d72232016-08-04 10:15:08 -040014114 S;
14115 W;
14116 /* NOTREACHED */
14117 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014118}
14119
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014120static void vl_api_mpls_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014121 (vl_api_mpls_gre_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014122{
Dave Barach72d72232016-08-04 10:15:08 -040014123 vat_main_t *vam = &vat_main;
14124 i32 i;
14125 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014126
Dave Barach72d72232016-08-04 10:15:08 -040014127 if (mp->l2_only == 0)
14128 {
14129 fformat (vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
14130 ntohl (mp->tunnel_index),
14131 format_ip4_address, &mp->tunnel_src,
14132 format_ip4_address, &mp->tunnel_dst,
14133 format_ip4_address, &mp->intfc_address,
14134 ntohl (mp->mask_width));
14135 for (i = 0; i < len; i++)
14136 {
14137 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
14138 }
14139 fformat (vam->ofp, "\n");
14140 fformat (vam->ofp, " inner fib index %d, outer fib index %d\n",
14141 ntohl (mp->inner_fib_index), ntohl (mp->outer_fib_index));
14142 }
14143 else
14144 {
14145 fformat (vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
14146 ntohl (mp->tunnel_index),
14147 format_ip4_address, &mp->tunnel_src,
14148 format_ip4_address, &mp->tunnel_dst,
14149 format_ip4_address, &mp->intfc_address);
14150 for (i = 0; i < len; i++)
14151 {
14152 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
14153 }
14154 fformat (vam->ofp, "\n");
14155 fformat (vam->ofp, " l2 interface %d, outer fib index %d\n",
14156 ntohl (mp->hw_if_index), ntohl (mp->outer_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014157 }
14158}
14159
14160static void vl_api_mpls_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014161 (vl_api_mpls_gre_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014162{
Dave Barach72d72232016-08-04 10:15:08 -040014163 vat_main_t *vam = &vat_main;
14164 vat_json_node_t *node = NULL;
14165 struct in_addr ip4;
14166 i32 i;
14167 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014168
Dave Barach72d72232016-08-04 10:15:08 -040014169 if (VAT_JSON_ARRAY != vam->json_tree.type)
14170 {
14171 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14172 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014173 }
Dave Barach72d72232016-08-04 10:15:08 -040014174 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014175
Dave Barach72d72232016-08-04 10:15:08 -040014176 vat_json_init_object (node);
14177 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14178 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14179 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14180 vat_json_object_add_uint (node, "inner_fib_index",
14181 ntohl (mp->inner_fib_index));
14182 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14183 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14184 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14185 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14186 clib_memcpy (&ip4, &(mp->tunnel_src), sizeof (ip4));
14187 vat_json_object_add_ip4 (node, "tunnel_src", ip4);
14188 clib_memcpy (&ip4, &(mp->tunnel_dst), sizeof (ip4));
14189 vat_json_object_add_ip4 (node, "tunnel_dst", ip4);
14190 vat_json_object_add_uint (node, "outer_fib_index",
14191 ntohl (mp->outer_fib_index));
14192 vat_json_object_add_uint (node, "label_count", len);
14193 for (i = 0; i < len; i++)
14194 {
14195 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014196 }
14197}
14198
Dave Barach72d72232016-08-04 10:15:08 -040014199static int
14200api_mpls_gre_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014201{
Dave Barach72d72232016-08-04 10:15:08 -040014202 vl_api_mpls_gre_tunnel_dump_t *mp;
14203 f64 timeout;
14204 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014205
Dave Barach72d72232016-08-04 10:15:08 -040014206 /* Parse args required to build the message */
14207 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014208 {
Dave Barach72d72232016-08-04 10:15:08 -040014209 if (!unformat (vam->input, "tunnel_index %d", &index))
14210 {
14211 index = -1;
14212 break;
14213 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014214 }
Dave Barach72d72232016-08-04 10:15:08 -040014215
14216 fformat (vam->ofp, " tunnel_index %d\n", index);
14217
14218 M (MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
14219 mp->tunnel_index = htonl (index);
14220 S;
14221
14222 /* Use a control ping for synchronization */
14223 {
14224 vl_api_control_ping_t *mp;
14225 M (CONTROL_PING, control_ping);
14226 S;
14227 }
14228 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014229}
14230
14231static void vl_api_mpls_eth_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014232 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014233{
Dave Barach72d72232016-08-04 10:15:08 -040014234 vat_main_t *vam = &vat_main;
14235 i32 i;
14236 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014237
Dave Barach72d72232016-08-04 10:15:08 -040014238 fformat (vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
14239 ntohl (mp->tunnel_index),
14240 format_ethernet_address, &mp->tunnel_dst_mac,
14241 format_ip4_address, &mp->intfc_address, ntohl (mp->mask_width));
14242 for (i = 0; i < len; i++)
14243 {
14244 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014245 }
Dave Barach72d72232016-08-04 10:15:08 -040014246 fformat (vam->ofp, "\n");
14247 fformat (vam->ofp, " tx on %d, rx fib index %d\n",
14248 ntohl (mp->tx_sw_if_index), ntohl (mp->inner_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014249}
14250
14251static void vl_api_mpls_eth_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014252 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014253{
Dave Barach72d72232016-08-04 10:15:08 -040014254 vat_main_t *vam = &vat_main;
14255 vat_json_node_t *node = NULL;
14256 struct in_addr ip4;
14257 i32 i;
14258 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014259
Dave Barach72d72232016-08-04 10:15:08 -040014260 if (VAT_JSON_ARRAY != vam->json_tree.type)
14261 {
14262 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14263 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014264 }
Dave Barach72d72232016-08-04 10:15:08 -040014265 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014266
Dave Barach72d72232016-08-04 10:15:08 -040014267 vat_json_init_object (node);
14268 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14269 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14270 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14271 vat_json_object_add_uint (node, "inner_fib_index",
14272 ntohl (mp->inner_fib_index));
14273 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14274 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14275 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14276 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14277 vat_json_object_add_string_copy (node, "tunnel_dst_mac",
14278 format (0, "%U", format_ethernet_address,
14279 &mp->tunnel_dst_mac));
14280 vat_json_object_add_uint (node, "tx_sw_if_index",
14281 ntohl (mp->tx_sw_if_index));
14282 vat_json_object_add_uint (node, "label_count", len);
14283 for (i = 0; i < len; i++)
14284 {
14285 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014286 }
14287}
14288
Dave Barach72d72232016-08-04 10:15:08 -040014289static int
14290api_mpls_eth_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014291{
Dave Barach72d72232016-08-04 10:15:08 -040014292 vl_api_mpls_eth_tunnel_dump_t *mp;
14293 f64 timeout;
14294 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014295
Dave Barach72d72232016-08-04 10:15:08 -040014296 /* Parse args required to build the message */
14297 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014298 {
Dave Barach72d72232016-08-04 10:15:08 -040014299 if (!unformat (vam->input, "tunnel_index %d", &index))
14300 {
14301 index = -1;
14302 break;
14303 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014304 }
Dave Barach72d72232016-08-04 10:15:08 -040014305
14306 fformat (vam->ofp, " tunnel_index %d\n", index);
14307
14308 M (MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
14309 mp->tunnel_index = htonl (index);
14310 S;
14311
14312 /* Use a control ping for synchronization */
14313 {
14314 vl_api_control_ping_t *mp;
14315 M (CONTROL_PING, control_ping);
14316 S;
14317 }
14318 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014319}
14320
14321static void vl_api_mpls_fib_encap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014322 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014323{
Dave Barach72d72232016-08-04 10:15:08 -040014324 vat_main_t *vam = &vat_main;
14325 i32 i;
14326 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014327
Dave Barach72d72232016-08-04 10:15:08 -040014328 fformat (vam->ofp, "table %d, dest %U, label ",
14329 ntohl (mp->fib_index), format_ip4_address, &mp->dest, len);
14330 for (i = 0; i < len; i++)
14331 {
14332 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014333 }
Dave Barach72d72232016-08-04 10:15:08 -040014334 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014335}
14336
14337static void vl_api_mpls_fib_encap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014338 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014339{
Dave Barach72d72232016-08-04 10:15:08 -040014340 vat_main_t *vam = &vat_main;
14341 vat_json_node_t *node = NULL;
14342 i32 i;
14343 i32 len = ntohl (mp->nlabels);
14344 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014345
Dave Barach72d72232016-08-04 10:15:08 -040014346 if (VAT_JSON_ARRAY != vam->json_tree.type)
14347 {
14348 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14349 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014350 }
Dave Barach72d72232016-08-04 10:15:08 -040014351 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014352
Dave Barach72d72232016-08-04 10:15:08 -040014353 vat_json_init_object (node);
14354 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14355 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14356 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14357 vat_json_object_add_ip4 (node, "dest", ip4);
14358 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14359 vat_json_object_add_uint (node, "label_count", len);
14360 for (i = 0; i < len; i++)
14361 {
14362 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014363 }
14364}
14365
Dave Barach72d72232016-08-04 10:15:08 -040014366static int
14367api_mpls_fib_encap_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014368{
Dave Barach72d72232016-08-04 10:15:08 -040014369 vl_api_mpls_fib_encap_dump_t *mp;
14370 f64 timeout;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014371
Dave Barach72d72232016-08-04 10:15:08 -040014372 M (MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
14373 S;
14374
14375 /* Use a control ping for synchronization */
14376 {
14377 vl_api_control_ping_t *mp;
14378 M (CONTROL_PING, control_ping);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014379 S;
Dave Barach72d72232016-08-04 10:15:08 -040014380 }
14381 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014382}
14383
14384static void vl_api_mpls_fib_decap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014385 (vl_api_mpls_fib_decap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014386{
Dave Barach72d72232016-08-04 10:15:08 -040014387 vat_main_t *vam = &vat_main;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014388
Dave Barach72d72232016-08-04 10:15:08 -040014389 fformat (vam->ofp,
14390 "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
14391 ntohl (mp->rx_table_id), ntohl (mp->tx_table_id), mp->swif_tag,
14392 ntohl (mp->label), ntohl (mp->s_bit));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014393}
14394
14395static void vl_api_mpls_fib_decap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014396 (vl_api_mpls_fib_decap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014397{
Dave Barach72d72232016-08-04 10:15:08 -040014398 vat_main_t *vam = &vat_main;
14399 vat_json_node_t *node = NULL;
14400 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014401
Dave Barach72d72232016-08-04 10:15:08 -040014402 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014403 {
Dave Barach72d72232016-08-04 10:15:08 -040014404 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14405 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014406 }
Dave Barach72d72232016-08-04 10:15:08 -040014407 node = vat_json_array_add (&vam->json_tree);
14408
14409 vat_json_init_object (node);
14410 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14411 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14412 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14413 vat_json_object_add_ip4 (node, "dest", ip4);
14414 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14415 vat_json_object_add_uint (node, "label", ntohl (mp->label));
14416 vat_json_object_add_uint (node, "rx_table_id", ntohl (mp->rx_table_id));
14417 vat_json_object_add_uint (node, "tx_table_id", ntohl (mp->tx_table_id));
14418 vat_json_object_add_string_copy (node, "swif_tag", mp->swif_tag);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014419}
14420
Dave Barach72d72232016-08-04 10:15:08 -040014421static int
14422api_mpls_fib_decap_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014423{
Dave Barach72d72232016-08-04 10:15:08 -040014424 vl_api_mpls_fib_decap_dump_t *mp;
14425 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014426
Dave Barach72d72232016-08-04 10:15:08 -040014427 M (MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
14428 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014429
Dave Barach72d72232016-08-04 10:15:08 -040014430 /* Use a control ping for synchronization */
14431 {
14432 vl_api_control_ping_t *mp;
14433 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014434 S;
Dave Barach72d72232016-08-04 10:15:08 -040014435 }
14436 W;
14437}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014438
Dave Barach72d72232016-08-04 10:15:08 -040014439int
14440api_classify_table_ids (vat_main_t * vam)
14441{
14442 vl_api_classify_table_ids_t *mp;
14443 f64 timeout;
14444
14445 /* Construct the API message */
14446 M (CLASSIFY_TABLE_IDS, classify_table_ids);
14447 mp->context = 0;
14448
14449 S;
14450 W;
14451 /* NOTREACHED */
14452 return 0;
14453}
14454
14455int
14456api_classify_table_by_interface (vat_main_t * vam)
14457{
14458 unformat_input_t *input = vam->input;
14459 vl_api_classify_table_by_interface_t *mp;
14460 f64 timeout;
14461
14462 u32 sw_if_index = ~0;
14463 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014464 {
Dave Barach72d72232016-08-04 10:15:08 -040014465 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
14466 ;
14467 else if (unformat (input, "sw_if_index %d", &sw_if_index))
14468 ;
14469 else
14470 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014471 }
Dave Barach72d72232016-08-04 10:15:08 -040014472 if (sw_if_index == ~0)
14473 {
14474 errmsg ("missing interface name or sw_if_index\n");
14475 return -99;
14476 }
14477
14478 /* Construct the API message */
14479 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
14480 mp->context = 0;
14481 mp->sw_if_index = ntohl (sw_if_index);
14482
14483 S;
14484 W;
14485 /* NOTREACHED */
14486 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014487}
14488
Dave Barach72d72232016-08-04 10:15:08 -040014489int
14490api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014491{
Dave Barach72d72232016-08-04 10:15:08 -040014492 unformat_input_t *input = vam->input;
14493 vl_api_classify_table_info_t *mp;
14494 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014495
Dave Barach72d72232016-08-04 10:15:08 -040014496 u32 table_id = ~0;
14497 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14498 {
14499 if (unformat (input, "table_id %d", &table_id))
14500 ;
14501 else
14502 break;
14503 }
14504 if (table_id == ~0)
14505 {
14506 errmsg ("missing table id\n");
14507 return -99;
14508 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014509
Dave Barach72d72232016-08-04 10:15:08 -040014510 /* Construct the API message */
14511 M (CLASSIFY_TABLE_INFO, classify_table_info);
14512 mp->context = 0;
14513 mp->table_id = ntohl (table_id);
14514
14515 S;
14516 W;
14517 /* NOTREACHED */
14518 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014519}
14520
Dave Barach72d72232016-08-04 10:15:08 -040014521int
14522api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014523{
Dave Barach72d72232016-08-04 10:15:08 -040014524 unformat_input_t *input = vam->input;
14525 vl_api_classify_session_dump_t *mp;
14526 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014527
Dave Barach72d72232016-08-04 10:15:08 -040014528 u32 table_id = ~0;
14529 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14530 {
14531 if (unformat (input, "table_id %d", &table_id))
14532 ;
14533 else
14534 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014535 }
Dave Barach72d72232016-08-04 10:15:08 -040014536 if (table_id == ~0)
14537 {
14538 errmsg ("missing table id\n");
14539 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014540 }
14541
Dave Barach72d72232016-08-04 10:15:08 -040014542 /* Construct the API message */
14543 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
14544 mp->context = 0;
14545 mp->table_id = ntohl (table_id);
14546 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014547
Dave Barach72d72232016-08-04 10:15:08 -040014548 /* Use a control ping for synchronization */
14549 {
14550 vl_api_control_ping_t *mp;
14551 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040014552 S;
Dave Barach72d72232016-08-04 10:15:08 -040014553 }
14554 W;
14555 /* NOTREACHED */
14556 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040014557}
14558
Dave Barach72d72232016-08-04 10:15:08 -040014559static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014560vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070014561{
Dave Barach72d72232016-08-04 10:15:08 -040014562 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014563
Dave Barach72d72232016-08-04 10:15:08 -040014564 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014565 "src_address %U, vrf_id %d, path_mtu %u, "
14566 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040014567 format_ip4_address, mp->collector_address,
14568 ntohs (mp->collector_port),
14569 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014570 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
14571 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040014572
14573 vam->retval = 0;
14574 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014575}
14576
Dave Barach72d72232016-08-04 10:15:08 -040014577static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014578 vl_api_ipfix_exporter_details_t_handler_json
14579 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014580{
Dave Barach72d72232016-08-04 10:15:08 -040014581 vat_main_t *vam = &vat_main;
14582 vat_json_node_t node;
14583 struct in_addr collector_address;
14584 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014585
Dave Barach72d72232016-08-04 10:15:08 -040014586 vat_json_init_object (&node);
14587 clib_memcpy (&collector_address, &mp->collector_address,
14588 sizeof (collector_address));
14589 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
14590 vat_json_object_add_uint (&node, "collector_port",
14591 ntohs (mp->collector_port));
14592 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
14593 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014594 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040014595 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
14596 vat_json_object_add_uint (&node, "template_interval",
14597 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014598 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040014599
14600 vat_json_print (vam->ofp, &node);
14601 vat_json_free (&node);
14602 vam->retval = 0;
14603 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014604}
14605
Dave Barach72d72232016-08-04 10:15:08 -040014606int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014607api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070014608{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014609 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014610 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014611
Dave Barach72d72232016-08-04 10:15:08 -040014612 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014613 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014614 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014615
Dave Barach72d72232016-08-04 10:15:08 -040014616 S;
14617 W;
14618 /* NOTREACHED */
14619 return 0;
14620}
Ed Warnickecb9cada2015-12-08 15:45:58 -070014621
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014622static int
14623api_ipfix_classify_stream_dump (vat_main_t * vam)
14624{
14625 vl_api_ipfix_classify_stream_dump_t *mp;
14626 f64 timeout;
14627
14628 /* Construct the API message */
14629 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
14630 mp->context = 0;
14631
14632 S;
14633 W;
14634 /* NOTREACHED */
14635 return 0;
14636}
14637
14638static void
14639 vl_api_ipfix_classify_stream_details_t_handler
14640 (vl_api_ipfix_classify_stream_details_t * mp)
14641{
14642 vat_main_t *vam = &vat_main;
14643 fformat (vam->ofp, "domain_id %d, src_port %d\n",
14644 ntohl (mp->domain_id), ntohs (mp->src_port));
14645 vam->retval = 0;
14646 vam->result_ready = 1;
14647}
14648
14649static void
14650 vl_api_ipfix_classify_stream_details_t_handler_json
14651 (vl_api_ipfix_classify_stream_details_t * mp)
14652{
14653 vat_main_t *vam = &vat_main;
14654 vat_json_node_t node;
14655
14656 vat_json_init_object (&node);
14657 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
14658 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
14659
14660 vat_json_print (vam->ofp, &node);
14661 vat_json_free (&node);
14662 vam->retval = 0;
14663 vam->result_ready = 1;
14664}
14665
14666static int
14667api_ipfix_classify_table_dump (vat_main_t * vam)
14668{
14669 vl_api_ipfix_classify_table_dump_t *mp;
14670 f64 timeout;
14671
14672 if (!vam->json_output)
14673 {
14674 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
14675 "transport_protocol");
14676 }
14677
14678 /* Construct the API message */
14679 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
14680
14681 /* send it... */
14682 S;
14683
14684 /* Use a control ping for synchronization */
14685 {
14686 vl_api_control_ping_t *mp;
14687 M (CONTROL_PING, control_ping);
14688 S;
14689 }
14690 W;
14691}
14692
14693static void
14694 vl_api_ipfix_classify_table_details_t_handler
14695 (vl_api_ipfix_classify_table_details_t * mp)
14696{
14697 vat_main_t *vam = &vat_main;
14698 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
14699 mp->transport_protocol);
14700}
14701
14702static void
14703 vl_api_ipfix_classify_table_details_t_handler_json
14704 (vl_api_ipfix_classify_table_details_t * mp)
14705{
14706 vat_json_node_t *node = NULL;
14707 vat_main_t *vam = &vat_main;
14708
14709 if (VAT_JSON_ARRAY != vam->json_tree.type)
14710 {
14711 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14712 vat_json_init_array (&vam->json_tree);
14713 }
14714
14715 node = vat_json_array_add (&vam->json_tree);
14716 vat_json_init_object (node);
14717
14718 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
14719 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
14720 vat_json_object_add_uint (node, "transport_protocol",
14721 mp->transport_protocol);
14722}
14723
Dave Barach72d72232016-08-04 10:15:08 -040014724int
14725api_pg_create_interface (vat_main_t * vam)
14726{
14727 unformat_input_t *input = vam->input;
14728 vl_api_pg_create_interface_t *mp;
14729 f64 timeout;
14730
14731 u32 if_id = ~0;
14732 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14733 {
14734 if (unformat (input, "if_id %d", &if_id))
14735 ;
14736 else
14737 break;
14738 }
14739 if (if_id == ~0)
14740 {
14741 errmsg ("missing pg interface index\n");
14742 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014743 }
14744
Dave Barach72d72232016-08-04 10:15:08 -040014745 /* Construct the API message */
14746 M (PG_CREATE_INTERFACE, pg_create_interface);
14747 mp->context = 0;
14748 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070014749
Dave Barach72d72232016-08-04 10:15:08 -040014750 S;
14751 W;
14752 /* NOTREACHED */
14753 return 0;
14754}
14755
14756int
14757api_pg_capture (vat_main_t * vam)
14758{
14759 unformat_input_t *input = vam->input;
14760 vl_api_pg_capture_t *mp;
14761 f64 timeout;
14762
14763 u32 if_id = ~0;
14764 u8 enable = 1;
14765 u32 count = 1;
14766 u8 pcap_file_set = 0;
14767 u8 *pcap_file = 0;
14768 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14769 {
14770 if (unformat (input, "if_id %d", &if_id))
14771 ;
14772 else if (unformat (input, "pcap %s", &pcap_file))
14773 pcap_file_set = 1;
14774 else if (unformat (input, "count %d", &count))
14775 ;
14776 else if (unformat (input, "disable"))
14777 enable = 0;
14778 else
14779 break;
14780 }
14781 if (if_id == ~0)
14782 {
14783 errmsg ("missing pg interface index\n");
14784 return -99;
14785 }
14786 if (pcap_file_set > 0)
14787 {
14788 if (vec_len (pcap_file) > 255)
14789 {
14790 errmsg ("pcap file name is too long\n");
14791 return -99;
14792 }
14793 }
14794
14795 u32 name_len = vec_len (pcap_file);
14796 /* Construct the API message */
14797 M (PG_CAPTURE, pg_capture);
14798 mp->context = 0;
14799 mp->interface_id = ntohl (if_id);
14800 mp->is_enabled = enable;
14801 mp->count = ntohl (count);
14802 mp->pcap_name_length = ntohl (name_len);
14803 if (pcap_file_set != 0)
14804 {
14805 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
14806 }
14807 vec_free (pcap_file);
14808
14809 S;
14810 W;
14811 /* NOTREACHED */
14812 return 0;
14813}
14814
14815int
14816api_pg_enable_disable (vat_main_t * vam)
14817{
14818 unformat_input_t *input = vam->input;
14819 vl_api_pg_enable_disable_t *mp;
14820 f64 timeout;
14821
14822 u8 enable = 1;
14823 u8 stream_name_set = 0;
14824 u8 *stream_name = 0;
14825 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14826 {
14827 if (unformat (input, "stream %s", &stream_name))
14828 stream_name_set = 1;
14829 else if (unformat (input, "disable"))
14830 enable = 0;
14831 else
14832 break;
14833 }
14834
14835 if (stream_name_set > 0)
14836 {
14837 if (vec_len (stream_name) > 255)
14838 {
14839 errmsg ("stream name too long\n");
14840 return -99;
14841 }
14842 }
14843
14844 u32 name_len = vec_len (stream_name);
14845 /* Construct the API message */
14846 M (PG_ENABLE_DISABLE, pg_enable_disable);
14847 mp->context = 0;
14848 mp->is_enabled = enable;
14849 if (stream_name_set != 0)
14850 {
14851 mp->stream_name_length = ntohl (name_len);
14852 clib_memcpy (mp->stream_name, stream_name, name_len);
14853 }
14854 vec_free (stream_name);
14855
14856 S;
14857 W;
14858 /* NOTREACHED */
14859 return 0;
14860}
14861
14862int
14863api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
14864{
14865 unformat_input_t *input = vam->input;
14866 vl_api_ip_source_and_port_range_check_add_del_t *mp;
14867 f64 timeout;
14868
14869 u16 *low_ports = 0;
14870 u16 *high_ports = 0;
14871 u16 this_low;
14872 u16 this_hi;
14873 ip4_address_t ip4_addr;
14874 ip6_address_t ip6_addr;
14875 u32 length;
14876 u32 tmp, tmp2;
14877 u8 prefix_set = 0;
14878 u32 vrf_id = ~0;
14879 u8 is_add = 1;
14880 u8 is_ipv6 = 0;
14881
14882 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14883 {
14884 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
14885 {
14886 prefix_set = 1;
14887 }
14888 else
14889 if (unformat
14890 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
14891 {
14892 prefix_set = 1;
14893 is_ipv6 = 1;
14894 }
14895 else if (unformat (input, "vrf %d", &vrf_id))
14896 ;
14897 else if (unformat (input, "del"))
14898 is_add = 0;
14899 else if (unformat (input, "port %d", &tmp))
14900 {
14901 if (tmp == 0 || tmp > 65535)
14902 {
14903 errmsg ("port %d out of range", tmp);
14904 return -99;
14905 }
14906 this_low = tmp;
14907 this_hi = this_low + 1;
14908 vec_add1 (low_ports, this_low);
14909 vec_add1 (high_ports, this_hi);
14910 }
14911 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
14912 {
14913 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
14914 {
14915 errmsg ("incorrect range parameters\n");
14916 return -99;
14917 }
14918 this_low = tmp;
14919 /* Note: in debug CLI +1 is added to high before
14920 passing to real fn that does "the work"
14921 (ip_source_and_port_range_check_add_del).
14922 This fn is a wrapper around the binary API fn a
14923 control plane will call, which expects this increment
14924 to have occurred. Hence letting the binary API control
14925 plane fn do the increment for consistency between VAT
14926 and other control planes.
14927 */
14928 this_hi = tmp2;
14929 vec_add1 (low_ports, this_low);
14930 vec_add1 (high_ports, this_hi);
14931 }
14932 else
14933 break;
14934 }
14935
14936 if (prefix_set == 0)
14937 {
14938 errmsg ("<address>/<mask> not specified\n");
14939 return -99;
14940 }
14941
14942 if (vrf_id == ~0)
14943 {
14944 errmsg ("VRF ID required, not specified\n");
14945 return -99;
14946 }
14947
14948 if (vrf_id == 0)
14949 {
14950 errmsg
14951 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
14952 return -99;
14953 }
14954
14955 if (vec_len (low_ports) == 0)
14956 {
14957 errmsg ("At least one port or port range required\n");
14958 return -99;
14959 }
14960
14961 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
14962 ip_source_and_port_range_check_add_del);
14963
14964 mp->is_add = is_add;
14965
14966 if (is_ipv6)
14967 {
14968 mp->is_ipv6 = 1;
14969 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
14970 }
14971 else
14972 {
14973 mp->is_ipv6 = 0;
14974 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
14975 }
14976
14977 mp->mask_length = length;
14978 mp->number_of_ranges = vec_len (low_ports);
14979
14980 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
14981 vec_free (low_ports);
14982
14983 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
14984 vec_free (high_ports);
14985
14986 mp->vrf_id = ntohl (vrf_id);
14987
14988 S;
14989 W;
14990 /* NOTREACHED */
14991 return 0;
14992}
14993
14994int
14995api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
14996{
14997 unformat_input_t *input = vam->input;
14998 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
14999 f64 timeout;
15000 u32 sw_if_index = ~0;
15001 int vrf_set = 0;
15002 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
15003 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
15004 u8 is_add = 1;
15005
15006 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15007 {
15008 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15009 ;
15010 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15011 ;
15012 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
15013 vrf_set = 1;
15014 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
15015 vrf_set = 1;
15016 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
15017 vrf_set = 1;
15018 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
15019 vrf_set = 1;
15020 else if (unformat (input, "del"))
15021 is_add = 0;
15022 else
15023 break;
15024 }
15025
15026 if (sw_if_index == ~0)
15027 {
15028 errmsg ("Interface required but not specified\n");
15029 return -99;
15030 }
15031
15032 if (vrf_set == 0)
15033 {
15034 errmsg ("VRF ID required but not specified\n");
15035 return -99;
15036 }
15037
15038 if (tcp_out_vrf_id == 0
15039 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
15040 {
15041 errmsg
15042 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15043 return -99;
15044 }
15045
15046 /* Construct the API message */
15047 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
15048 ip_source_and_port_range_check_interface_add_del);
15049
15050 mp->sw_if_index = ntohl (sw_if_index);
15051 mp->is_add = is_add;
15052 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
15053 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
15054 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
15055 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
15056
15057 /* send it... */
15058 S;
15059
15060 /* Wait for a reply... */
15061 W;
15062}
15063
15064static int
Matus Fabian694265d2016-08-10 01:55:36 -070015065api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
15066{
15067 unformat_input_t *i = vam->input;
15068 vl_api_ipsec_gre_add_del_tunnel_t *mp;
15069 f64 timeout;
15070 u32 local_sa_id = 0;
15071 u32 remote_sa_id = 0;
15072 ip4_address_t src_address;
15073 ip4_address_t dst_address;
15074 u8 is_add = 1;
15075
15076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15077 {
15078 if (unformat (i, "local_sa %d", &local_sa_id))
15079 ;
15080 else if (unformat (i, "remote_sa %d", &remote_sa_id))
15081 ;
15082 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
15083 ;
15084 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
15085 ;
15086 else if (unformat (i, "del"))
15087 is_add = 0;
15088 else
15089 {
15090 clib_warning ("parse error '%U'", format_unformat_error, i);
15091 return -99;
15092 }
15093 }
15094
15095 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
15096
15097 mp->local_sa_id = ntohl (local_sa_id);
15098 mp->remote_sa_id = ntohl (remote_sa_id);
15099 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
15100 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
15101 mp->is_add = is_add;
15102
15103 S;
15104 W;
15105 /* NOTREACHED */
15106 return 0;
15107}
15108
15109static void vl_api_ipsec_gre_tunnel_details_t_handler
15110 (vl_api_ipsec_gre_tunnel_details_t * mp)
15111{
15112 vat_main_t *vam = &vat_main;
15113
15114 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
15115 ntohl (mp->sw_if_index),
15116 format_ip4_address, &mp->src_address,
15117 format_ip4_address, &mp->dst_address,
15118 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
15119}
15120
15121static void vl_api_ipsec_gre_tunnel_details_t_handler_json
15122 (vl_api_ipsec_gre_tunnel_details_t * mp)
15123{
15124 vat_main_t *vam = &vat_main;
15125 vat_json_node_t *node = NULL;
15126 struct in_addr ip4;
15127
15128 if (VAT_JSON_ARRAY != vam->json_tree.type)
15129 {
15130 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15131 vat_json_init_array (&vam->json_tree);
15132 }
15133 node = vat_json_array_add (&vam->json_tree);
15134
15135 vat_json_init_object (node);
15136 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
15137 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
15138 vat_json_object_add_ip4 (node, "src_address", ip4);
15139 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
15140 vat_json_object_add_ip4 (node, "dst_address", ip4);
15141 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
15142 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
15143}
15144
15145static int
15146api_ipsec_gre_tunnel_dump (vat_main_t * vam)
15147{
15148 unformat_input_t *i = vam->input;
15149 vl_api_ipsec_gre_tunnel_dump_t *mp;
15150 f64 timeout;
15151 u32 sw_if_index;
15152 u8 sw_if_index_set = 0;
15153
15154 /* Parse args required to build the message */
15155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15156 {
15157 if (unformat (i, "sw_if_index %d", &sw_if_index))
15158 sw_if_index_set = 1;
15159 else
15160 break;
15161 }
15162
15163 if (sw_if_index_set == 0)
15164 {
15165 sw_if_index = ~0;
15166 }
15167
15168 if (!vam->json_output)
15169 {
15170 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
15171 "sw_if_index", "src_address", "dst_address",
15172 "local_sa_id", "remote_sa_id");
15173 }
15174
15175 /* Get list of gre-tunnel interfaces */
15176 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
15177
15178 mp->sw_if_index = htonl (sw_if_index);
15179
15180 S;
15181
15182 /* Use a control ping for synchronization */
15183 {
15184 vl_api_control_ping_t *mp;
15185 M (CONTROL_PING, control_ping);
15186 S;
15187 }
15188 W;
15189}
15190
15191static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015192api_delete_subif (vat_main_t * vam)
15193{
15194 unformat_input_t *i = vam->input;
15195 vl_api_delete_subif_t *mp;
15196 f64 timeout;
15197 u32 sw_if_index = ~0;
15198
15199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15200 {
15201 if (unformat (i, "sw_if_index %d", &sw_if_index))
15202 ;
15203 else
15204 break;
15205 }
15206
15207 if (sw_if_index == ~0)
15208 {
15209 errmsg ("missing sw_if_index\n");
15210 return -99;
15211 }
15212
15213 /* Construct the API message */
15214 M (DELETE_SUBIF, delete_subif);
15215 mp->sw_if_index = ntohl (sw_if_index);
15216
15217 S;
15218 W;
15219}
15220
Pavel Kotucek95300d12016-08-26 16:11:36 +020015221#define foreach_pbb_vtr_op \
15222_("disable", L2_VTR_DISABLED) \
15223_("pop", L2_VTR_POP_2) \
15224_("push", L2_VTR_PUSH_2)
15225
15226static int
15227api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
15228{
15229 unformat_input_t *i = vam->input;
15230 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
15231 f64 timeout;
15232 u32 sw_if_index = ~0, vtr_op = ~0;
15233 u16 outer_tag = ~0;
15234 u8 dmac[6], smac[6];
15235 u8 dmac_set = 0, smac_set = 0;
15236 u16 vlanid = 0;
15237 u32 sid = ~0;
15238 u32 tmp;
15239
15240 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15241 {
15242 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15243 ;
15244 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15245 ;
15246 else if (unformat (i, "vtr_op %d", &vtr_op))
15247 ;
15248#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
15249 foreach_pbb_vtr_op
15250#undef _
15251 else if (unformat (i, "translate_pbb_stag"))
15252 {
15253 if (unformat (i, "%d", &tmp))
15254 {
15255 vtr_op = L2_VTR_TRANSLATE_2_1;
15256 outer_tag = tmp;
15257 }
15258 else
15259 {
15260 errmsg
15261 ("translate_pbb_stag operation requires outer tag definition\n");
15262 return -99;
15263 }
15264 }
15265 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
15266 dmac_set++;
15267 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
15268 smac_set++;
15269 else if (unformat (i, "sid %d", &sid))
15270 ;
15271 else if (unformat (i, "vlanid %d", &tmp))
15272 vlanid = tmp;
15273 else
15274 {
15275 clib_warning ("parse error '%U'", format_unformat_error, i);
15276 return -99;
15277 }
15278 }
15279
15280 if ((sw_if_index == ~0) || (vtr_op == ~0))
15281 {
15282 errmsg ("missing sw_if_index or vtr operation\n");
15283 return -99;
15284 }
15285 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
15286 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
15287 {
15288 errmsg
15289 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
15290 return -99;
15291 }
15292
15293 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
15294 mp->sw_if_index = ntohl (sw_if_index);
15295 mp->vtr_op = ntohl (vtr_op);
15296 mp->outer_tag = ntohs (outer_tag);
15297 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
15298 clib_memcpy (mp->b_smac, smac, sizeof (smac));
15299 mp->b_vlanid = ntohs (vlanid);
15300 mp->i_sid = ntohl (sid);
15301
15302 S;
15303 W;
15304 /* NOTREACHED */
15305 return 0;
15306}
15307
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015308static int
Dave Barach72d72232016-08-04 10:15:08 -040015309q_or_quit (vat_main_t * vam)
15310{
15311 longjmp (vam->jump_buf, 1);
15312 return 0; /* not so much */
15313}
15314
15315static int
15316q (vat_main_t * vam)
15317{
15318 return q_or_quit (vam);
15319}
15320
15321static int
15322quit (vat_main_t * vam)
15323{
15324 return q_or_quit (vam);
15325}
15326
15327static int
15328comment (vat_main_t * vam)
15329{
15330 return 0;
15331}
15332
15333static int
15334cmd_cmp (void *a1, void *a2)
15335{
15336 u8 **c1 = a1;
15337 u8 **c2 = a2;
15338
15339 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
15340}
15341
15342static int
15343help (vat_main_t * vam)
15344{
15345 u8 **cmds = 0;
15346 u8 *name = 0;
15347 hash_pair_t *p;
15348 unformat_input_t *i = vam->input;
15349 int j;
15350
15351 if (unformat (i, "%s", &name))
15352 {
15353 uword *hs;
15354
15355 vec_add1 (name, 0);
15356
15357 hs = hash_get_mem (vam->help_by_name, name);
15358 if (hs)
15359 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
15360 else
15361 fformat (vam->ofp, "No such msg / command '%s'\n", name);
15362 vec_free (name);
15363 return 0;
15364 }
15365
15366 fformat (vam->ofp, "Help is available for the following:\n");
15367
15368 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015369 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070015370 ({
Dave Barach72d72232016-08-04 10:15:08 -040015371 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015372 }));
Dave Barach72d72232016-08-04 10:15:08 -040015373 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015374
Dave Barach72d72232016-08-04 10:15:08 -040015375 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015376
Dave Barach72d72232016-08-04 10:15:08 -040015377 for (j = 0; j < vec_len (cmds); j++)
15378 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015379
Dave Barach72d72232016-08-04 10:15:08 -040015380 vec_free (cmds);
15381 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015382}
15383
Dave Barach72d72232016-08-04 10:15:08 -040015384static int
15385set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015386{
Dave Barach72d72232016-08-04 10:15:08 -040015387 u8 *name = 0, *value = 0;
15388 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015389
Dave Barach72d72232016-08-04 10:15:08 -040015390 if (unformat (i, "%s", &name))
15391 {
15392 /* The input buffer is a vector, not a string. */
15393 value = vec_dup (i->buffer);
15394 vec_delete (value, i->index, 0);
15395 /* Almost certainly has a trailing newline */
15396 if (value[vec_len (value) - 1] == '\n')
15397 value[vec_len (value) - 1] = 0;
15398 /* Make sure it's a proper string, one way or the other */
15399 vec_add1 (value, 0);
15400 (void) clib_macro_set_value (&vam->macro_main,
15401 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015402 }
Dave Barach72d72232016-08-04 10:15:08 -040015403 else
15404 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070015405
Dave Barach72d72232016-08-04 10:15:08 -040015406 vec_free (name);
15407 vec_free (value);
15408 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015409}
15410
Dave Barach72d72232016-08-04 10:15:08 -040015411static int
15412unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015413{
Dave Barach72d72232016-08-04 10:15:08 -040015414 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015415
Dave Barach72d72232016-08-04 10:15:08 -040015416 if (unformat (vam->input, "%s", &name))
15417 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
15418 errmsg ("unset: %s wasn't set\n", name);
15419 vec_free (name);
15420 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015421}
15422
Dave Barach72d72232016-08-04 10:15:08 -040015423typedef struct
15424{
15425 u8 *name;
15426 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015427} macro_sort_t;
15428
15429
Dave Barach72d72232016-08-04 10:15:08 -040015430static int
15431macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015432{
Dave Barach72d72232016-08-04 10:15:08 -040015433 macro_sort_t *s1 = a1;
15434 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015435
Dave Barach72d72232016-08-04 10:15:08 -040015436 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015437}
15438
Dave Barach72d72232016-08-04 10:15:08 -040015439static int
15440dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015441{
Dave Barach72d72232016-08-04 10:15:08 -040015442 macro_sort_t *sort_me = 0, *sm;
15443 int i;
15444 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015445
Dave Barach72d72232016-08-04 10:15:08 -040015446 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015447 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070015448 ({
Dave Barach72d72232016-08-04 10:15:08 -040015449 vec_add2 (sort_me, sm, 1);
15450 sm->name = (u8 *)(p->key);
15451 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015452 }));
Dave Barach72d72232016-08-04 10:15:08 -040015453 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015454
Dave Barach72d72232016-08-04 10:15:08 -040015455 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015456
Dave Barach72d72232016-08-04 10:15:08 -040015457 if (vec_len (sort_me))
15458 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
15459 else
15460 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070015461
Dave Barach72d72232016-08-04 10:15:08 -040015462 for (i = 0; i < vec_len (sort_me); i++)
15463 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
15464 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015465}
15466
Dave Barach72d72232016-08-04 10:15:08 -040015467static int
15468dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050015469{
Dave Barach72d72232016-08-04 10:15:08 -040015470 int i, j;
15471 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015472
Dave Barach72d72232016-08-04 10:15:08 -040015473 if (vec_len (vam->graph_nodes) == 0)
15474 {
15475 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
15476 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015477 }
15478
Dave Barach72d72232016-08-04 10:15:08 -040015479 for (i = 0; i < vec_len (vam->graph_nodes); i++)
15480 {
15481 node = vam->graph_nodes[i];
15482 fformat (vam->ofp, "[%d] %s\n", i, node->name);
15483 for (j = 0; j < vec_len (node->next_nodes); j++)
15484 {
15485 if (node->next_nodes[j] != ~0)
15486 {
15487 next_node = vam->graph_nodes[node->next_nodes[j]];
15488 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
15489 }
15490 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050015491 }
Dave Barach72d72232016-08-04 10:15:08 -040015492 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015493}
15494
Dave Barach72d72232016-08-04 10:15:08 -040015495static int
15496search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050015497{
Dave Barach72d72232016-08-04 10:15:08 -040015498 unformat_input_t *line_input = vam->input;
15499 u8 *node_to_find;
15500 int j;
15501 vlib_node_t *node, *next_node;
15502 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015503
Dave Barach72d72232016-08-04 10:15:08 -040015504 if (vam->graph_node_index_by_name == 0)
15505 {
15506 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
15507 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015508 }
15509
Dave Barach72d72232016-08-04 10:15:08 -040015510 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
15511 {
15512 if (unformat (line_input, "%s", &node_to_find))
15513 {
15514 vec_add1 (node_to_find, 0);
15515 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
15516 if (p == 0)
15517 {
15518 fformat (vam->ofp, "%s not found...\n", node_to_find);
15519 goto out;
15520 }
15521 node = vam->graph_nodes[p[0]];
15522 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
15523 for (j = 0; j < vec_len (node->next_nodes); j++)
15524 {
15525 if (node->next_nodes[j] != ~0)
15526 {
15527 next_node = vam->graph_nodes[node->next_nodes[j]];
15528 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
15529 }
15530 }
15531 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015532
Dave Barach72d72232016-08-04 10:15:08 -040015533 else
15534 {
15535 clib_warning ("parse error '%U'", format_unformat_error,
15536 line_input);
15537 return -99;
15538 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050015539
15540 out:
Dave Barach72d72232016-08-04 10:15:08 -040015541 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015542
Dave Barachb44e9bc2016-02-19 09:06:23 -050015543 }
15544
Dave Barach72d72232016-08-04 10:15:08 -040015545 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015546}
15547
15548
Dave Barach72d72232016-08-04 10:15:08 -040015549static int
15550script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015551{
Dave Barach72d72232016-08-04 10:15:08 -040015552 u8 *s = 0;
15553 char *save_current_file;
15554 unformat_input_t save_input;
15555 jmp_buf save_jump_buf;
15556 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015557
Dave Barach72d72232016-08-04 10:15:08 -040015558 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015559
Dave Barach72d72232016-08-04 10:15:08 -040015560 if (unformat (vam->input, "%s", &s))
15561 {
15562 new_fp = fopen ((char *) s, "r");
15563 if (new_fp == 0)
15564 {
15565 errmsg ("Couldn't open script file %s\n", s);
15566 vec_free (s);
15567 return -99;
15568 }
15569 }
15570 else
15571 {
15572 errmsg ("Missing script name\n");
15573 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015574 }
15575
Dave Barach72d72232016-08-04 10:15:08 -040015576 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
15577 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
15578 save_ifp = vam->ifp;
15579 save_line_number = vam->input_line_number;
15580 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015581
Dave Barach72d72232016-08-04 10:15:08 -040015582 vam->input_line_number = 0;
15583 vam->ifp = new_fp;
15584 vam->current_file = s;
15585 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015586
Dave Barach72d72232016-08-04 10:15:08 -040015587 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
15588 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
15589 vam->ifp = save_ifp;
15590 vam->input_line_number = save_line_number;
15591 vam->current_file = (u8 *) save_current_file;
15592 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015593
Dave Barach72d72232016-08-04 10:15:08 -040015594 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015595}
15596
Dave Barach72d72232016-08-04 10:15:08 -040015597static int
15598echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015599{
Dave Barach72d72232016-08-04 10:15:08 -040015600 fformat (vam->ofp, "%v", vam->input->buffer);
15601 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015602}
15603
15604/* List of API message constructors, CLI names map to api_xxx */
15605#define foreach_vpe_api_msg \
15606_(create_loopback,"[mac <mac-addr>]") \
15607_(sw_interface_dump,"") \
15608_(sw_interface_set_flags, \
15609 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
15610_(sw_interface_add_del_address, \
15611 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
15612_(sw_interface_set_table, \
15613 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
15614_(sw_interface_set_vpath, \
15615 "<intfc> | sw_if_index <id> enable | disable") \
15616_(sw_interface_set_l2_xconnect, \
15617 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15618 "enable | disable") \
15619_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040015620 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015621 "[shg <split-horizon-group>] [bvi]\n" \
15622 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010015623_(sw_interface_set_dpdk_hqos_pipe, \
15624 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
15625 "profile <profile-id>\n") \
15626_(sw_interface_set_dpdk_hqos_subport, \
15627 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
15628 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
15629_(sw_interface_set_dpdk_hqos_tctbl, \
15630 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015631_(bridge_domain_add_del, \
15632 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
15633_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
15634_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070015635 "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 -070015636_(l2_flags, \
15637 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
15638_(bridge_flags, \
15639 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
15640_(tap_connect, \
15641 "tapname <name> mac <mac-addr> | random-mac") \
15642_(tap_modify, \
15643 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
15644_(tap_delete, \
15645 "<vpp-if-name> | sw_if_index <id>") \
15646_(sw_interface_tap_dump, "") \
15647_(ip_add_del_route, \
15648 "<addr>/<mask> via <addr> [vrf <n>]\n" \
15649 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
15650 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
15651 "[multipath] [count <n>]") \
15652_(proxy_arp_add_del, \
15653 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
15654_(proxy_arp_intfc_enable_disable, \
15655 "<intfc> | sw_if_index <id> enable | disable") \
15656_(mpls_add_del_encap, \
15657 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
15658_(mpls_add_del_decap, \
15659 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
15660_(mpls_gre_add_del_tunnel, \
15661 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
15662 "adj <ip4-address>/<mask-width> [del]") \
15663_(sw_interface_set_unnumbered, \
15664 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
15665_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040015666 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
15667 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015668_(reset_vrf, "vrf <id> [ipv6]") \
15669_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
15670_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
15671 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
15672 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
15673 "[outer_vlan_id_any][inner_vlan_id_any]") \
15674_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
15675_(reset_fib, "vrf <n> [ipv6]") \
15676_(dhcp_proxy_config, \
15677 "svr <v46-address> src <v46-address>\n" \
15678 "insert-cid <n> [del]") \
15679_(dhcp_proxy_config_2, \
15680 "svr <v46-address> src <v46-address>\n" \
15681 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
15682_(dhcp_proxy_set_vss, \
15683 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
15684_(dhcp_client_config, \
15685 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
15686_(set_ip_flow_hash, \
15687 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
15688_(sw_interface_ip6_enable_disable, \
15689 "<intfc> | sw_if_index <id> enable | disable") \
15690_(sw_interface_ip6_set_link_local_address, \
15691 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
15692_(sw_interface_ip6nd_ra_prefix, \
15693 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
15694 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
15695 "[nolink] [isno]") \
15696_(sw_interface_ip6nd_ra_config, \
15697 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040015698 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015699 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
15700_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
15701_(l2_patch_add_del, \
15702 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15703 "enable | disable") \
15704_(mpls_ethernet_add_del_tunnel, \
15705 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
15706 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
15707_(mpls_ethernet_add_del_tunnel_2, \
15708 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
15709 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
15710_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070015711 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
15712 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
15713 "[policy <policy_name>]") \
15714_(sr_policy_add_del, \
15715 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
15716_(sr_multicast_map_add_del, \
15717 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015718_(classify_add_del_table, \
15719 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
15720 "[del] mask <mask-value>\n" \
15721 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
15722_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015723 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
15724 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
15725 " [l3 [ip4|ip6]]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015726_(classify_set_interface_ip_table, \
15727 "<intfc> | sw_if_index <nn> table <nn>") \
15728_(classify_set_interface_l2_tables, \
15729 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15730 " [other-table <nn>]") \
15731_(get_node_index, "node <node-name") \
15732_(add_node_next, "node <node-name> next <next-node-name>") \
15733_(l2tpv3_create_tunnel, \
15734 "client_address <ip6-addr> our_address <ip6-addr>\n" \
15735 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
15736 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
15737_(l2tpv3_set_tunnel_cookies, \
15738 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
15739 "[new_remote_cookie <nn>]\n") \
15740_(l2tpv3_interface_enable_disable, \
15741 "<intfc> | sw_if_index <nn> enable | disable") \
15742_(l2tpv3_set_lookup_key, \
15743 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
15744_(sw_if_l2tpv3_tunnel_dump, "") \
15745_(vxlan_add_del_tunnel, \
Chris Luke404be662016-05-27 12:11:24 -040015746 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015747 " [decap-next l2|ip4|ip6] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050015748_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040015749_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070015750 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040015751_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015752_(l2_fib_clear_table, "") \
15753_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
15754_(l2_interface_vlan_tag_rewrite, \
15755 "<intfc> | sw_if_index <nn> \n" \
15756 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
15757 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
15758_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000015759 "socket <filename> [server] [renumber <dev_instance>] " \
15760 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015761_(modify_vhost_user_if, \
15762 "<intfc> | sw_if_index <nn> socket <filename>\n" \
15763 "[server] [renumber <dev_instance>]") \
15764_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
15765_(sw_interface_vhost_user_dump, "") \
15766_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080015767_(vxlan_gpe_add_del_tunnel, \
15768 "local <addr> remote <addr> vni <nn>\n" \
15769 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
15770 "[next-ethernet] [next-nsh]\n") \
15771_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015772_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015773_(interface_name_renumber, \
15774 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
15775_(input_acl_set_interface, \
15776 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15777 " [l2-table <nn>] [del]") \
15778_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040015779_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015780_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15781_(ip_dump, "ipv4 | ipv6") \
15782_(ipsec_spd_add_del, "spd_id <n> [del]") \
15783_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15784 " spid_id <n> ") \
15785_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15786 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15787 " integ_alg <alg> integ_key <hex>") \
15788_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
15789 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15790 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15791 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
15792_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020015793_(ikev2_profile_add_del, "name <profile_name> [del]") \
15794_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
15795 "(auth_data 0x<data> | auth_data <data>)") \
15796_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
15797 "(id_data 0x<data> | id_data <data>) (local|remote)") \
15798_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
15799 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
15800 "(local|remote)") \
15801_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015802_(delete_loopback,"sw_if_index <nn>") \
15803_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15804_(map_add_domain, \
15805 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
15806 "ip6-src <ip6addr> " \
15807 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
15808_(map_del_domain, "index <n>") \
15809_(map_add_del_rule, \
15810 "index <n> psid <n> dst <ip6addr> [del]") \
15811_(map_domain_dump, "") \
15812_(map_rule_dump, "index <map-domain>") \
15813_(want_interface_events, "enable|disable") \
15814_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050015815_(get_first_msg_id, "client <name>") \
15816_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15817_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015818 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010015819_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000015820_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070015821_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15822_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020015823_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
15824 " sw_if_index <sw_if_index> p <priority> " \
15825 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015826_(lisp_add_del_locator, "locator-set <locator_name> " \
15827 "iface <intf> | sw_if_index <sw_if_index> " \
15828 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020015829_(lisp_add_del_local_eid,"vni <vni> eid " \
15830 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015831 "locator-set <locator_name> [del]") \
Florin Coras429e7952016-08-02 02:31:03 +020015832_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
15833 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015834_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020015835_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020015836_(lisp_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015837_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020015838_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
15839 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020015840 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020015841 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020015842 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020015843_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
15844 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020015845_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020015846_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020015847_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020015848_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020015849_(lisp_locator_set_dump, "[local | remote]") \
15850_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020015851_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
15852 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020015853_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020015854_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015855_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020015856_(lisp_map_resolver_dump, "") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020015857_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020015858_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020015859_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020015860_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020015861_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070015862_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070015863_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070015864_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015865_(policer_classify_set_interface, \
15866 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15867 " [l2-table <nn>] [del]") \
15868_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070015869_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
15870 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015871_(netmap_delete, "name <interface name>") \
15872_(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
15873_(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
15874_(mpls_fib_encap_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015875_(mpls_fib_decap_dump, "") \
15876_(classify_table_ids, "") \
15877_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15878_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015879_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015880_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15881 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15882 "[template_interval <nn>] [udp_checksum]") \
15883_(ipfix_exporter_dump, "") \
15884_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15885_(ipfix_classify_stream_dump, "") \
15886_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
15887_(ipfix_classify_table_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015888_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15889_(pg_create_interface, "if_id <nn>") \
15890_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040015891_(pg_enable_disable, "[stream <id>] disable") \
15892_(ip_source_and_port_range_check_add_del, \
15893 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15894_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070015895 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070015896 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15897_(ipsec_gre_add_del_tunnel, \
15898 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015899_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020015900_(delete_subif,"sub_sw_if_index <nn> sub_if_id <nn>") \
15901_(l2_interface_pbb_tag_rewrite, \
15902 "<intfc> | sw_if_index <nn> \n" \
15903 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
15904 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]")
Ed Warnickecb9cada2015-12-08 15:45:58 -070015905
15906/* List of command functions, CLI names map directly to functions */
15907#define foreach_cli_function \
15908_(comment, "usage: comment <ignore-rest-of-line>") \
15909_(dump_interface_table, "usage: dump_interface_table") \
15910_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15911_(dump_ipv4_table, "usage: dump_ipv4_table") \
15912_(dump_ipv6_table, "usage: dump_ipv6_table") \
15913_(dump_stats_table, "usage: dump_stats_table") \
15914_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015915_(dump_node_table, "usage: dump_node_table") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015916_(echo, "usage: echo <message>") \
15917_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020015918_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015919_(help, "usage: help") \
15920_(q, "usage: quit") \
15921_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015922_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015923_(set, "usage: set <variable-name> <value>") \
15924_(script, "usage: script <file-name>") \
15925_(unset, "usage: unset <variable-name>")
15926
15927#define _(N,n) \
15928 static void vl_api_##n##_t_handler_uni \
15929 (vl_api_##n##_t * mp) \
15930 { \
15931 vat_main_t * vam = &vat_main; \
15932 if (vam->json_output) { \
15933 vl_api_##n##_t_handler_json(mp); \
15934 } else { \
15935 vl_api_##n##_t_handler(mp); \
15936 } \
15937 }
15938foreach_vpe_api_reply_msg;
15939#undef _
15940
Dave Barach72d72232016-08-04 10:15:08 -040015941void
15942vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015943{
15944#define _(N,n) \
15945 vl_msg_api_set_handlers(VL_API_##N, #n, \
15946 vl_api_##n##_t_handler_uni, \
15947 vl_noop_handler, \
15948 vl_api_##n##_t_endian, \
15949 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015950 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040015951 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015952#undef _
15953
Dave Barach72d72232016-08-04 10:15:08 -040015954 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015955
Dave Barach72d72232016-08-04 10:15:08 -040015956 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015957
Dave Barach72d72232016-08-04 10:15:08 -040015958 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015959
Dave Barach72d72232016-08-04 10:15:08 -040015960 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015961
Dave Barach72d72232016-08-04 10:15:08 -040015962 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015963#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040015964 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015965#undef _
15966
Dave Barach72d72232016-08-04 10:15:08 -040015967 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015968#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040015969 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015970#undef _
15971
Dave Barach72d72232016-08-04 10:15:08 -040015972 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015973#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040015974 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015975#undef _
15976
Dave Barach72d72232016-08-04 10:15:08 -040015977 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015978#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040015979 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015980#undef _
15981}
15982
15983#undef vl_api_version
15984#define vl_api_version(n,v) static u32 vpe_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040015985#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070015986#undef vl_api_version
15987
Dave Barach72d72232016-08-04 10:15:08 -040015988void
15989vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015990{
Dave Barach72d72232016-08-04 10:15:08 -040015991 /*
15992 * Send the main API signature in slot 0. This bit of code must
15993 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
15994 */
15995 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015996}
Dave Barach72d72232016-08-04 10:15:08 -040015997
15998/*
15999 * fd.io coding-style-patch-verification: ON
16000 *
16001 * Local Variables:
16002 * eval: (c-set-style "gnu")
16003 * End:
16004 */