blob: 51beada2bd0b19e2d933862da2ee34127d12a2ee [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003 * api_format.c
4 *
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07005 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016 * limitations under the License.
Ed Warnickecb9cada2015-12-08 15:45:58 -070017 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
21#include <vlibapi/api.h>
22#include <vlibmemory/api.h>
23#include <vlibsocket/api.h>
24#include <vnet/ip/ip.h>
25#include <vnet/sr/sr_packet.h>
26#include <vnet/l2/l2_input.h>
27#include <vnet/l2tp/l2tp.h>
28#include <vnet/vxlan/vxlan.h>
Chris Luke27fe48f2016-04-28 13:44:38 -040029#include <vnet/gre/gre.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070030#include <vnet/vxlan-gpe/vxlan_gpe.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070031#include <vnet/lisp-gpe/lisp_gpe.h>
32
Dave Barachaa6920e2016-06-27 09:25:13 -040033#include <vpp-api/vpe_msg_enum.h>
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080034#include <vnet/l2/l2_classify.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070035#include <vnet/l2/l2_vtr.h>
36#include <vnet/classify/input_acl.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070037#include <vnet/classify/policer_classify.h>
Juraj Sloboda506b2452016-08-07 23:45:24 -070038#include <vnet/classify/flow_classify.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010039#include <vnet/mpls/mpls.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050040#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -070041#include <vnet/ipsec/ipsec.h>
Matus Fabiane5f42fe2016-04-08 11:18:08 +020042#include <vnet/ipsec/ikev2.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050043#else
44#include <inttypes.h>
45#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070046#include <vnet/map/map.h>
Dave Barachc07bf5d2016-02-17 17:52:26 -050047#include <vnet/cop/cop.h>
Shwetha20a64f52016-03-25 10:55:01 +000048#include <vnet/ip/ip6_hop_by_hop.h>
Dave Barach6f9bca22016-04-30 10:25:32 -040049#include <vnet/ip/ip_source_and_port_range_check.h>
Matus Fabian65fcd4d2016-05-13 05:44:48 -070050#include <vnet/policer/xlate.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070051#include <vnet/policer/policer.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070052#include <vnet/policer/police.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070053
54#include "vat/json_format.h"
55
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020056#include <sys/stat.h>
57
Dave Barach72d72232016-08-04 10:15:08 -040058#define vl_typedefs /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080059#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070060#undef vl_typedefs
61
62/* declare message handlers for each api */
63
Dave Barach72d72232016-08-04 10:15:08 -040064#define vl_endianfun /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080065#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070066#undef vl_endianfun
67
68/* instantiate all the print functions we know about */
69#define vl_print(handle, ...)
70#define vl_printfun
Dave Barachaa6920e2016-06-27 09:25:13 -040071#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070072#undef vl_printfun
73
Dave Barach72d72232016-08-04 10:15:08 -040074uword
75unformat_sw_if_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070076{
Dave Barach72d72232016-08-04 10:15:08 -040077 vat_main_t *vam = va_arg (*args, vat_main_t *);
78 u32 *result = va_arg (*args, u32 *);
79 u8 *if_name;
80 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081
82 if (!unformat (input, "%s", &if_name))
Dave Barach72d72232016-08-04 10:15:08 -040083 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070084
85 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
86 if (p == 0)
Dave Barach72d72232016-08-04 10:15:08 -040087 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070088 *result = p[0];
89 return 1;
90}
91
92/* Parse an IP4 address %d.%d.%d.%d. */
Dave Barach72d72232016-08-04 10:15:08 -040093uword
94unformat_ip4_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070095{
Dave Barach72d72232016-08-04 10:15:08 -040096 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070097 unsigned a[4];
98
Dave Barach72d72232016-08-04 10:15:08 -040099 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100 return 0;
101
102 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
103 return 0;
104
105 result[0] = a[0];
106 result[1] = a[1];
107 result[2] = a[2];
108 result[3] = a[3];
109
110 return 1;
111}
112
113
114uword
115unformat_ethernet_address (unformat_input_t * input, va_list * args)
116{
Dave Barach72d72232016-08-04 10:15:08 -0400117 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118 u32 i, a[6];
119
Dave Barach72d72232016-08-04 10:15:08 -0400120 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
121 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 return 0;
123
124 /* Check range. */
125 for (i = 0; i < 6; i++)
126 if (a[i] >= (1 << 8))
127 return 0;
128
129 for (i = 0; i < 6; i++)
130 result[i] = a[i];
131
132 return 1;
133}
134
135/* Returns ethernet type as an int in host byte order. */
136uword
137unformat_ethernet_type_host_byte_order (unformat_input_t * input,
138 va_list * args)
139{
Dave Barach72d72232016-08-04 10:15:08 -0400140 u16 *result = va_arg (*args, u16 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 int type;
142
143 /* Numeric type. */
Dave Barach72d72232016-08-04 10:15:08 -0400144 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145 {
146 if (type >= (1 << 16))
147 return 0;
148 *result = type;
149 return 1;
150 }
151 return 0;
152}
153
154/* Parse an IP6 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400155uword
156unformat_ip6_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700157{
Dave Barach72d72232016-08-04 10:15:08 -0400158 ip6_address_t *result = va_arg (*args, ip6_address_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159 u16 hex_quads[8];
160 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
161 uword c, n_colon, double_colon_index;
162
163 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
164 double_colon_index = ARRAY_LEN (hex_quads);
165 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
166 {
167 hex_digit = 16;
168 if (c >= '0' && c <= '9')
169 hex_digit = c - '0';
170 else if (c >= 'a' && c <= 'f')
171 hex_digit = c + 10 - 'a';
172 else if (c >= 'A' && c <= 'F')
173 hex_digit = c + 10 - 'A';
174 else if (c == ':' && n_colon < 2)
175 n_colon++;
176 else
177 {
178 unformat_put_input (input);
179 break;
180 }
181
182 /* Too many hex quads. */
183 if (n_hex_quads >= ARRAY_LEN (hex_quads))
184 return 0;
185
186 if (hex_digit < 16)
187 {
188 hex_quad = (hex_quad << 4) | hex_digit;
189
190 /* Hex quad must fit in 16 bits. */
191 if (n_hex_digits >= 4)
192 return 0;
193
194 n_colon = 0;
195 n_hex_digits++;
196 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800197
Ed Warnickecb9cada2015-12-08 15:45:58 -0700198 /* Save position of :: */
199 if (n_colon == 2)
200 {
201 /* More than one :: ? */
202 if (double_colon_index < ARRAY_LEN (hex_quads))
203 return 0;
204 double_colon_index = n_hex_quads;
205 }
206
207 if (n_colon > 0 && n_hex_digits > 0)
208 {
209 hex_quads[n_hex_quads++] = hex_quad;
210 hex_quad = 0;
211 n_hex_digits = 0;
212 }
213 }
214
215 if (n_hex_digits > 0)
216 hex_quads[n_hex_quads++] = hex_quad;
217
218 {
219 word i;
220
221 /* Expand :: to appropriate number of zero hex quads. */
222 if (double_colon_index < ARRAY_LEN (hex_quads))
223 {
224 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
225
226 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
227 hex_quads[n_zero + i] = hex_quads[i];
228
229 for (i = 0; i < n_zero; i++)
230 hex_quads[double_colon_index + i] = 0;
231
232 n_hex_quads = ARRAY_LEN (hex_quads);
233 }
234
235 /* Too few hex quads given. */
236 if (n_hex_quads < ARRAY_LEN (hex_quads))
237 return 0;
238
239 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
240 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
241
242 return 1;
243 }
244}
245
246uword
247unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
248{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500249#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400250 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251
Dave Barach72d72232016-08-04 10:15:08 -0400252 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
254 foreach_ipsec_policy_action
255#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400256 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700257 return 0;
258 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500259#else
260 return 0;
261#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262}
263
264uword
265unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
266{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500267#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400268 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269
Dave Barach72d72232016-08-04 10:15:08 -0400270 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700271#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
272 foreach_ipsec_crypto_alg
273#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400274 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700275 return 0;
276 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500277#else
278 return 0;
279#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700280}
281
282u8 *
283format_ipsec_crypto_alg (u8 * s, va_list * args)
284{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500285#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400287 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700288
289 switch (i)
290 {
291#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400292 foreach_ipsec_crypto_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700293#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400294 default:
295 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700296 }
297 return format (s, "%s", t);
Dave Barachbfdedbd2016-01-20 09:11:55 -0500298#else
299 return format (s, "Unimplemented");
300#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700301}
302
303uword
304unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
305{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500306#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400307 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308
Dave Barach72d72232016-08-04 10:15:08 -0400309 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
311 foreach_ipsec_integ_alg
312#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400313 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314 return 0;
315 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500316#else
317 return 0;
318#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700319}
320
321u8 *
322format_ipsec_integ_alg (u8 * s, va_list * args)
323{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500324#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -0700325 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400326 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700327
328 switch (i)
329 {
330#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400331 foreach_ipsec_integ_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700332#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400333 default:
334 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700335 }
336 return format (s, "%s", t);
Dave Barachbfdedbd2016-01-20 09:11:55 -0500337#else
338 return format (s, "Unsupported");
339#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700340}
341
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200342uword
343unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
344{
345#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400346 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200347
Dave Barach72d72232016-08-04 10:15:08 -0400348 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200349#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
350 foreach_ikev2_auth_method
351#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400352 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200353 return 0;
354 return 1;
355#else
356 return 0;
357#endif
358}
359
360uword
361unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
362{
363#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400364 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200365
Dave Barach72d72232016-08-04 10:15:08 -0400366 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200367#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
368 foreach_ikev2_id_type
369#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400370 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200371 return 0;
372 return 1;
373#else
374 return 0;
375#endif
376}
377
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700378uword
379unformat_policer_rate_type (unformat_input_t * input, va_list * args)
380{
Dave Barach72d72232016-08-04 10:15:08 -0400381 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700382
383 if (unformat (input, "kbps"))
384 *r = SSE2_QOS_RATE_KBPS;
Dave Barach72d72232016-08-04 10:15:08 -0400385 else if (unformat (input, "pps"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700386 *r = SSE2_QOS_RATE_PPS;
387 else
388 return 0;
389 return 1;
390}
391
392uword
393unformat_policer_round_type (unformat_input_t * input, va_list * args)
394{
Dave Barach72d72232016-08-04 10:15:08 -0400395 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700396
Dave Barach72d72232016-08-04 10:15:08 -0400397 if (unformat (input, "closest"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700398 *r = SSE2_QOS_ROUND_TO_CLOSEST;
399 else if (unformat (input, "up"))
400 *r = SSE2_QOS_ROUND_TO_UP;
401 else if (unformat (input, "down"))
402 *r = SSE2_QOS_ROUND_TO_DOWN;
403 else
404 return 0;
405 return 1;
406}
407
408uword
409unformat_policer_type (unformat_input_t * input, va_list * args)
410{
Dave Barach72d72232016-08-04 10:15:08 -0400411 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700412
413 if (unformat (input, "1r2c"))
414 *r = SSE2_QOS_POLICER_TYPE_1R2C;
415 else if (unformat (input, "1r3c"))
416 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
417 else if (unformat (input, "2r3c-2698"))
418 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
419 else if (unformat (input, "2r3c-4115"))
420 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
421 else if (unformat (input, "2r3c-mef5cf1"))
422 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
423 else
424 return 0;
425 return 1;
426}
427
Matus Fabian4ac74c92016-05-31 07:33:29 -0700428uword
429unformat_dscp (unformat_input_t * input, va_list * va)
430{
Dave Barach72d72232016-08-04 10:15:08 -0400431 u8 *r = va_arg (*va, u8 *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700432
Dave Barach72d72232016-08-04 10:15:08 -0400433 if (0);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700434#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
Dave Barach72d72232016-08-04 10:15:08 -0400435 foreach_vnet_dscp
Matus Fabian4ac74c92016-05-31 07:33:29 -0700436#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400437 else
Matus Fabian4ac74c92016-05-31 07:33:29 -0700438 return 0;
439 return 1;
440}
441
442uword
443unformat_policer_action_type (unformat_input_t * input, va_list * va)
444{
Dave Barach72d72232016-08-04 10:15:08 -0400445 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700446 = va_arg (*va, sse2_qos_pol_action_params_st *);
447
448 if (unformat (input, "drop"))
449 a->action_type = SSE2_QOS_ACTION_DROP;
450 else if (unformat (input, "transmit"))
451 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
452 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
453 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
454 else
455 return 0;
456 return 1;
457}
458
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700459uword
Juraj Sloboda506b2452016-08-07 23:45:24 -0700460unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700461{
Dave Barach72d72232016-08-04 10:15:08 -0400462 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700463 u32 tid;
464
465 if (unformat (input, "ip4"))
466 tid = POLICER_CLASSIFY_TABLE_IP4;
467 else if (unformat (input, "ip6"))
468 tid = POLICER_CLASSIFY_TABLE_IP6;
469 else if (unformat (input, "l2"))
470 tid = POLICER_CLASSIFY_TABLE_L2;
471 else
472 return 0;
473
474 *r = tid;
475 return 1;
476}
477
Juraj Sloboda506b2452016-08-07 23:45:24 -0700478uword
479unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
480{
481 u32 *r = va_arg (*va, u32 *);
482 u32 tid;
483
484 if (unformat (input, "ip4"))
485 tid = FLOW_CLASSIFY_TABLE_IP4;
486 else if (unformat (input, "ip6"))
487 tid = FLOW_CLASSIFY_TABLE_IP6;
488 else
489 return 0;
490
491 *r = tid;
492 return 1;
493}
494
Dave Barach72d72232016-08-04 10:15:08 -0400495u8 *
496format_ip4_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700497{
Dave Barach72d72232016-08-04 10:15:08 -0400498 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700499 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
500}
501
Dave Barach72d72232016-08-04 10:15:08 -0400502u8 *
503format_ip6_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504{
Dave Barach72d72232016-08-04 10:15:08 -0400505 ip6_address_t *a = va_arg (*args, ip6_address_t *);
506 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507
Dave Barach72d72232016-08-04 10:15:08 -0400508 i_max_n_zero = ARRAY_LEN (a->as_u16);
509 max_n_zeros = 0;
510 i_first_zero = i_max_n_zero;
511 n_zeros = 0;
512 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
513 {
514 u32 is_zero = a->as_u16[i] == 0;
515 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
516 {
517 i_first_zero = i;
518 n_zeros = 0;
519 }
520 n_zeros += is_zero;
521 if ((!is_zero && n_zeros > max_n_zeros)
522 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
523 {
524 i_max_n_zero = i_first_zero;
525 max_n_zeros = n_zeros;
526 i_first_zero = ARRAY_LEN (a->as_u16);
527 n_zeros = 0;
528 }
529 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700530
Dave Barach72d72232016-08-04 10:15:08 -0400531 last_double_colon = 0;
532 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
533 {
534 if (i == i_max_n_zero && max_n_zeros > 1)
535 {
536 s = format (s, "::");
537 i += max_n_zeros - 1;
538 last_double_colon = 1;
539 }
540 else
541 {
542 s = format (s, "%s%x",
543 (last_double_colon || i == 0) ? "" : ":",
544 clib_net_to_host_u16 (a->as_u16[i]));
545 last_double_colon = 0;
546 }
547 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700548
Dave Barach72d72232016-08-04 10:15:08 -0400549 return s;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700550}
551
Chris Luke99cb3352016-04-26 10:49:53 -0400552/* Format an IP46 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400553u8 *
554format_ip46_address (u8 * s, va_list * args)
Chris Luke99cb3352016-04-26 10:49:53 -0400555{
556 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
Damjan Marion86be4872016-05-24 23:19:11 +0200557 ip46_type_t type = va_arg (*args, ip46_type_t);
558 int is_ip4 = 1;
559
560 switch (type)
561 {
Dave Barach72d72232016-08-04 10:15:08 -0400562 case IP46_TYPE_ANY:
563 is_ip4 = ip46_address_is_ip4 (ip46);
564 break;
565 case IP46_TYPE_IP4:
566 is_ip4 = 1;
567 break;
568 case IP46_TYPE_IP6:
569 is_ip4 = 0;
570 break;
Damjan Marion86be4872016-05-24 23:19:11 +0200571 }
572
573 return is_ip4 ?
Dave Barach72d72232016-08-04 10:15:08 -0400574 format (s, "%U", format_ip4_address, &ip46->ip4) :
575 format (s, "%U", format_ip6_address, &ip46->ip6);
Chris Luke99cb3352016-04-26 10:49:53 -0400576}
577
Dave Barach72d72232016-08-04 10:15:08 -0400578u8 *
579format_ethernet_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580{
Dave Barach72d72232016-08-04 10:15:08 -0400581 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700582
583 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -0400584 a[0], a[1], a[2], a[3], a[4], a[5]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700585}
586
Dave Barach72d72232016-08-04 10:15:08 -0400587void
588increment_v4_address (ip4_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700589{
Dave Barach72d72232016-08-04 10:15:08 -0400590 u32 v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700591
Dave Barach72d72232016-08-04 10:15:08 -0400592 v = ntohl (a->as_u32) + 1;
593 a->as_u32 = ntohl (v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700594}
595
Dave Barach72d72232016-08-04 10:15:08 -0400596void
597increment_v6_address (ip6_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700598{
Dave Barach72d72232016-08-04 10:15:08 -0400599 u64 v0, v1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700600
Dave Barach72d72232016-08-04 10:15:08 -0400601 v0 = clib_net_to_host_u64 (a->as_u64[0]);
602 v1 = clib_net_to_host_u64 (a->as_u64[1]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700603
Dave Barach72d72232016-08-04 10:15:08 -0400604 v1 += 1;
605 if (v1 == 0)
606 v0 += 1;
607 a->as_u64[0] = clib_net_to_host_u64 (v0);
608 a->as_u64[1] = clib_net_to_host_u64 (v1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700609}
610
Dave Barach72d72232016-08-04 10:15:08 -0400611void
612increment_mac_address (u64 * mac)
Dave Barach41da02d2016-07-11 16:48:42 -0700613{
Dave Barach72d72232016-08-04 10:15:08 -0400614 u64 tmp = *mac;
Dave Barach41da02d2016-07-11 16:48:42 -0700615
Dave Barach72d72232016-08-04 10:15:08 -0400616 tmp = clib_net_to_host_u64 (tmp);
617 tmp += 1 << 16; /* skip unused (least significant) octets */
618 tmp = clib_host_to_net_u64 (tmp);
619 *mac = tmp;
Dave Barach41da02d2016-07-11 16:48:42 -0700620}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700621
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800622static void vl_api_create_loopback_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400623 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700624{
Dave Barach72d72232016-08-04 10:15:08 -0400625 vat_main_t *vam = &vat_main;
626 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700627
Dave Barach72d72232016-08-04 10:15:08 -0400628 vam->retval = retval;
629 vam->regenerate_interface_table = 1;
630 vam->sw_if_index = ntohl (mp->sw_if_index);
631 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700632}
633
634static void vl_api_create_loopback_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400635 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700636{
Dave Barach72d72232016-08-04 10:15:08 -0400637 vat_main_t *vam = &vat_main;
638 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700639
Dave Barach72d72232016-08-04 10:15:08 -0400640 vat_json_init_object (&node);
641 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
642 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700643
Dave Barach72d72232016-08-04 10:15:08 -0400644 vat_json_print (vam->ofp, &node);
645 vat_json_free (&node);
646 vam->retval = ntohl (mp->retval);
647 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700648}
649
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800650static void vl_api_af_packet_create_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400651 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700652{
Dave Barach72d72232016-08-04 10:15:08 -0400653 vat_main_t *vam = &vat_main;
654 i32 retval = ntohl (mp->retval);
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700655
Dave Barach72d72232016-08-04 10:15:08 -0400656 vam->retval = retval;
657 vam->regenerate_interface_table = 1;
658 vam->sw_if_index = ntohl (mp->sw_if_index);
659 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700660}
661
662static void vl_api_af_packet_create_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400663 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700664{
Dave Barach72d72232016-08-04 10:15:08 -0400665 vat_main_t *vam = &vat_main;
666 vat_json_node_t node;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700667
Dave Barach72d72232016-08-04 10:15:08 -0400668 vat_json_init_object (&node);
669 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
670 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700671
Dave Barach72d72232016-08-04 10:15:08 -0400672 vat_json_print (vam->ofp, &node);
673 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700674
Dave Barach72d72232016-08-04 10:15:08 -0400675 vam->retval = ntohl (mp->retval);
676 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700677}
678
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800679static void vl_api_create_vlan_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400680 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700681{
Dave Barach72d72232016-08-04 10:15:08 -0400682 vat_main_t *vam = &vat_main;
683 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700684
Dave Barach72d72232016-08-04 10:15:08 -0400685 vam->retval = retval;
686 vam->regenerate_interface_table = 1;
687 vam->sw_if_index = ntohl (mp->sw_if_index);
688 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700689}
690
691static void vl_api_create_vlan_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400692 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693{
Dave Barach72d72232016-08-04 10:15:08 -0400694 vat_main_t *vam = &vat_main;
695 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
Dave Barach72d72232016-08-04 10:15:08 -0400697 vat_json_init_object (&node);
698 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
699 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700
Dave Barach72d72232016-08-04 10:15:08 -0400701 vat_json_print (vam->ofp, &node);
702 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700703
Dave Barach72d72232016-08-04 10:15:08 -0400704 vam->retval = ntohl (mp->retval);
705 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700706}
707
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800708static void vl_api_create_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400709 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710{
Dave Barach72d72232016-08-04 10:15:08 -0400711 vat_main_t *vam = &vat_main;
712 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700713
Dave Barach72d72232016-08-04 10:15:08 -0400714 vam->retval = retval;
715 vam->regenerate_interface_table = 1;
716 vam->sw_if_index = ntohl (mp->sw_if_index);
717 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700718}
719
720static void vl_api_create_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400721 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700722{
Dave Barach72d72232016-08-04 10:15:08 -0400723 vat_main_t *vam = &vat_main;
724 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700725
Dave Barach72d72232016-08-04 10:15:08 -0400726 vat_json_init_object (&node);
727 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
728 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700729
Dave Barach72d72232016-08-04 10:15:08 -0400730 vat_json_print (vam->ofp, &node);
731 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700732
Dave Barach72d72232016-08-04 10:15:08 -0400733 vam->retval = ntohl (mp->retval);
734 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700735}
736
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800737static void vl_api_interface_name_renumber_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400738 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700739{
Dave Barach72d72232016-08-04 10:15:08 -0400740 vat_main_t *vam = &vat_main;
741 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700742
Dave Barach72d72232016-08-04 10:15:08 -0400743 vam->retval = retval;
744 vam->regenerate_interface_table = 1;
745 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700746}
747
748static void vl_api_interface_name_renumber_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400749 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700750{
Dave Barach72d72232016-08-04 10:15:08 -0400751 vat_main_t *vam = &vat_main;
752 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700753
Dave Barach72d72232016-08-04 10:15:08 -0400754 vat_json_init_object (&node);
755 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700756
Dave Barach72d72232016-08-04 10:15:08 -0400757 vat_json_print (vam->ofp, &node);
758 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700759
Dave Barach72d72232016-08-04 10:15:08 -0400760 vam->retval = ntohl (mp->retval);
761 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762}
763
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800764/*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700765 * Special-case: build the interface table, maintain
766 * the next loopback sw_if_index vbl.
767 */
768static void vl_api_sw_interface_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400769 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700770{
Dave Barach72d72232016-08-04 10:15:08 -0400771 vat_main_t *vam = &vat_main;
772 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700773
Dave Barach72d72232016-08-04 10:15:08 -0400774 hash_set_mem (vam->sw_if_index_by_interface_name, s,
775 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700776
Dave Barach72d72232016-08-04 10:15:08 -0400777 /* In sub interface case, fill the sub interface table entry */
778 if (mp->sw_if_index != mp->sup_sw_if_index)
779 {
780 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700781
Dave Barach72d72232016-08-04 10:15:08 -0400782 vec_add2 (vam->sw_if_subif_table, sub, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700783
Dave Barach72d72232016-08-04 10:15:08 -0400784 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
785 strncpy ((char *) sub->interface_name, (char *) s,
786 vec_len (sub->interface_name));
787 sub->sw_if_index = ntohl (mp->sw_if_index);
788 sub->sub_id = ntohl (mp->sub_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700789
Dave Barach72d72232016-08-04 10:15:08 -0400790 sub->sub_dot1ad = mp->sub_dot1ad;
791 sub->sub_number_of_tags = mp->sub_number_of_tags;
792 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
793 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
794 sub->sub_exact_match = mp->sub_exact_match;
795 sub->sub_default = mp->sub_default;
796 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
797 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700798
Dave Barach72d72232016-08-04 10:15:08 -0400799 /* vlan tag rewrite */
800 sub->vtr_op = ntohl (mp->vtr_op);
801 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
802 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
803 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700804 }
805}
806
807static void vl_api_sw_interface_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400808 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700809{
Dave Barach72d72232016-08-04 10:15:08 -0400810 vat_main_t *vam = &vat_main;
811 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700812
Dave Barach72d72232016-08-04 10:15:08 -0400813 if (VAT_JSON_ARRAY != vam->json_tree.type)
814 {
815 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
816 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700817 }
Dave Barach72d72232016-08-04 10:15:08 -0400818 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700819
Dave Barach72d72232016-08-04 10:15:08 -0400820 vat_json_init_object (node);
821 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
822 vat_json_object_add_uint (node, "sup_sw_if_index",
823 ntohl (mp->sup_sw_if_index));
824 vat_json_object_add_uint (node, "l2_address_length",
825 ntohl (mp->l2_address_length));
826 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
827 sizeof (mp->l2_address));
828 vat_json_object_add_string_copy (node, "interface_name",
829 mp->interface_name);
830 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
831 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
832 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
833 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
834 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
835 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
836 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
837 vat_json_object_add_uint (node, "sub_number_of_tags",
838 mp->sub_number_of_tags);
839 vat_json_object_add_uint (node, "sub_outer_vlan_id",
840 ntohs (mp->sub_outer_vlan_id));
841 vat_json_object_add_uint (node, "sub_inner_vlan_id",
842 ntohs (mp->sub_inner_vlan_id));
843 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
844 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
845 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
846 mp->sub_outer_vlan_id_any);
847 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
848 mp->sub_inner_vlan_id_any);
849 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
850 vat_json_object_add_uint (node, "vtr_push_dot1q",
851 ntohl (mp->vtr_push_dot1q));
852 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
853 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700854}
855
856static void vl_api_sw_interface_set_flags_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400857 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700858{
Dave Barach72d72232016-08-04 10:15:08 -0400859 vat_main_t *vam = &vat_main;
860 if (vam->interface_event_display)
861 errmsg ("interface flags: sw_if_index %d %s %s\n",
862 ntohl (mp->sw_if_index),
863 mp->admin_up_down ? "admin-up" : "admin-down",
864 mp->link_up_down ? "link-up" : "link-down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700865}
866
867static void vl_api_sw_interface_set_flags_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400868 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700869{
Dave Barach72d72232016-08-04 10:15:08 -0400870 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700871}
872
Dave Barach72d72232016-08-04 10:15:08 -0400873static void
874vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700875{
Dave Barach72d72232016-08-04 10:15:08 -0400876 vat_main_t *vam = &vat_main;
877 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700878
Dave Barach72d72232016-08-04 10:15:08 -0400879 vam->retval = retval;
880 vam->shmem_result = (u8 *) mp->reply_in_shmem;
881 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700882}
883
Dave Barach72d72232016-08-04 10:15:08 -0400884static void
885vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700886{
Dave Barach72d72232016-08-04 10:15:08 -0400887 vat_main_t *vam = &vat_main;
888 vat_json_node_t node;
889 api_main_t *am = &api_main;
890 void *oldheap;
891 u8 *reply;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700892
Dave Barach72d72232016-08-04 10:15:08 -0400893 vat_json_init_object (&node);
894 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
895 vat_json_object_add_uint (&node, "reply_in_shmem",
896 ntohl (mp->reply_in_shmem));
897 /* Toss the shared-memory original... */
898 pthread_mutex_lock (&am->vlib_rp->mutex);
899 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -0500900
Dave Barach72d72232016-08-04 10:15:08 -0400901 reply = (u8 *) (mp->reply_in_shmem);
902 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800903
Dave Barach72d72232016-08-04 10:15:08 -0400904 svm_pop_heap (oldheap);
905 pthread_mutex_unlock (&am->vlib_rp->mutex);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700906
Dave Barach72d72232016-08-04 10:15:08 -0400907 vat_json_print (vam->ofp, &node);
908 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700909
Dave Barach72d72232016-08-04 10:15:08 -0400910 vam->retval = ntohl (mp->retval);
911 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700912}
913
Ole Troanc27213a2016-08-31 14:50:49 +0200914static void
915vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
916{
917 vat_main_t *vam = &vat_main;
918 i32 retval = ntohl (mp->retval);
919
920 vam->retval = retval;
921 vam->cmd_reply = mp->reply;
922 vam->result_ready = 1;
923}
924
925static void
926vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
927{
928 vat_main_t *vam = &vat_main;
929 vat_json_node_t node;
930
931 vat_json_init_object (&node);
932 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
933 vat_json_object_add_string_copy (&node, "reply", mp->reply);
934
935 vat_json_print (vam->ofp, &node);
936 vat_json_free (&node);
937
938 vam->retval = ntohl (mp->retval);
939 vam->result_ready = 1;
940}
941
Ed Warnickecb9cada2015-12-08 15:45:58 -0700942static void vl_api_classify_add_del_table_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400943 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700944{
Dave Barach72d72232016-08-04 10:15:08 -0400945 vat_main_t *vam = &vat_main;
946 i32 retval = ntohl (mp->retval);
947 if (vam->async_mode)
948 {
949 vam->async_errors += (retval < 0);
950 }
951 else
952 {
953 vam->retval = retval;
954 if (retval == 0 &&
955 ((mp->new_table_index != 0xFFFFFFFF) ||
956 (mp->skip_n_vectors != 0xFFFFFFFF) ||
957 (mp->match_n_vectors != 0xFFFFFFFF)))
958 /*
959 * Note: this is just barely thread-safe, depends on
960 * the main thread spinning waiting for an answer...
961 */
962 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
963 ntohl (mp->new_table_index),
964 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
965 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700966 }
967}
968
969static void vl_api_classify_add_del_table_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400970 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700971{
Dave Barach72d72232016-08-04 10:15:08 -0400972 vat_main_t *vam = &vat_main;
973 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700974
Dave Barach72d72232016-08-04 10:15:08 -0400975 vat_json_init_object (&node);
976 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
977 vat_json_object_add_uint (&node, "new_table_index",
978 ntohl (mp->new_table_index));
979 vat_json_object_add_uint (&node, "skip_n_vectors",
980 ntohl (mp->skip_n_vectors));
981 vat_json_object_add_uint (&node, "match_n_vectors",
982 ntohl (mp->match_n_vectors));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700983
Dave Barach72d72232016-08-04 10:15:08 -0400984 vat_json_print (vam->ofp, &node);
985 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700986
Dave Barach72d72232016-08-04 10:15:08 -0400987 vam->retval = ntohl (mp->retval);
988 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700989}
990
991static void vl_api_get_node_index_reply_t_handler
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 i32 retval = ntohl (mp->retval);
996 if (vam->async_mode)
997 {
998 vam->async_errors += (retval < 0);
999 }
1000 else
1001 {
1002 vam->retval = retval;
1003 if (retval == 0)
1004 errmsg ("node index %d\n", ntohl (mp->node_index));
1005 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001006 }
1007}
1008
1009static void vl_api_get_node_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001010 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001011{
Dave Barach72d72232016-08-04 10:15:08 -04001012 vat_main_t *vam = &vat_main;
1013 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001014
Dave Barach72d72232016-08-04 10:15:08 -04001015 vat_json_init_object (&node);
1016 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1017 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001018
Dave Barach72d72232016-08-04 10:15:08 -04001019 vat_json_print (vam->ofp, &node);
1020 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001021
Dave Barach72d72232016-08-04 10:15:08 -04001022 vam->retval = ntohl (mp->retval);
1023 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001024}
1025
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001026static void vl_api_get_next_index_reply_t_handler
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 i32 retval = ntohl (mp->retval);
1031 if (vam->async_mode)
1032 {
1033 vam->async_errors += (retval < 0);
1034 }
1035 else
1036 {
1037 vam->retval = retval;
1038 if (retval == 0)
1039 errmsg ("next node index %d\n", ntohl (mp->next_index));
1040 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001041 }
1042}
1043
1044static void vl_api_get_next_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001045 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001046{
Dave Barach72d72232016-08-04 10:15:08 -04001047 vat_main_t *vam = &vat_main;
1048 vat_json_node_t node;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001049
Dave Barach72d72232016-08-04 10:15:08 -04001050 vat_json_init_object (&node);
1051 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1052 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001053
Dave Barach72d72232016-08-04 10:15:08 -04001054 vat_json_print (vam->ofp, &node);
1055 vat_json_free (&node);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001056
Dave Barach72d72232016-08-04 10:15:08 -04001057 vam->retval = ntohl (mp->retval);
1058 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001059}
1060
Ed Warnickecb9cada2015-12-08 15:45:58 -07001061static void vl_api_add_node_next_reply_t_handler
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 i32 retval = ntohl (mp->retval);
1066 if (vam->async_mode)
1067 {
1068 vam->async_errors += (retval < 0);
1069 }
1070 else
1071 {
1072 vam->retval = retval;
1073 if (retval == 0)
1074 errmsg ("next index %d\n", ntohl (mp->next_index));
1075 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001076 }
1077}
1078
1079static void vl_api_add_node_next_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001080 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001081{
Dave Barach72d72232016-08-04 10:15:08 -04001082 vat_main_t *vam = &vat_main;
1083 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001084
Dave Barach72d72232016-08-04 10:15:08 -04001085 vat_json_init_object (&node);
1086 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1087 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001088
Dave Barach72d72232016-08-04 10:15:08 -04001089 vat_json_print (vam->ofp, &node);
1090 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001091
Dave Barach72d72232016-08-04 10:15:08 -04001092 vam->retval = ntohl (mp->retval);
1093 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001094}
1095
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001096static void vl_api_show_version_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001097 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001098{
Dave Barach72d72232016-08-04 10:15:08 -04001099 vat_main_t *vam = &vat_main;
1100 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001101
Dave Barach72d72232016-08-04 10:15:08 -04001102 if (retval >= 0)
1103 {
1104 errmsg (" program: %s\n", mp->program);
1105 errmsg (" version: %s\n", mp->version);
1106 errmsg (" build date: %s\n", mp->build_date);
1107 errmsg ("build directory: %s\n", mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001108 }
Dave Barach72d72232016-08-04 10:15:08 -04001109 vam->retval = retval;
1110 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001111}
1112
1113static void vl_api_show_version_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001114 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001115{
Dave Barach72d72232016-08-04 10:15:08 -04001116 vat_main_t *vam = &vat_main;
1117 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001118
Dave Barach72d72232016-08-04 10:15:08 -04001119 vat_json_init_object (&node);
1120 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1121 vat_json_object_add_string_copy (&node, "program", mp->program);
1122 vat_json_object_add_string_copy (&node, "version", mp->version);
1123 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1124 vat_json_object_add_string_copy (&node, "build_directory",
1125 mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001126
Dave Barach72d72232016-08-04 10:15:08 -04001127 vat_json_print (vam->ofp, &node);
1128 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001129
Dave Barach72d72232016-08-04 10:15:08 -04001130 vam->retval = ntohl (mp->retval);
1131 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001132}
1133
Dave Barach72d72232016-08-04 10:15:08 -04001134static void
1135vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001136{
Dave Barach72d72232016-08-04 10:15:08 -04001137 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001138 errmsg ("arp %s event: address %U new mac %U sw_if_index %d\n",
1139 mp->mac_ip ? "mac/ip binding" : "address resolution",
Dave Barach72d72232016-08-04 10:15:08 -04001140 format_ip4_address, &mp->address,
1141 format_ethernet_address, mp->new_mac, mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001142}
1143
Dave Barach72d72232016-08-04 10:15:08 -04001144static void
1145vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001146{
Dave Barach72d72232016-08-04 10:15:08 -04001147 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001148}
1149
John Lo1edfba92016-08-27 01:11:57 -04001150static void
1151vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1152{
1153 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001154 errmsg ("ip6 nd %s event: address %U new mac %U sw_if_index %d\n",
1155 mp->mac_ip ? "mac/ip binding" : "address resolution",
John Lo1edfba92016-08-27 01:11:57 -04001156 format_ip6_address, mp->address,
1157 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1158}
1159
1160static void
1161vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1162{
1163 /* JSON output not supported */
1164}
1165
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001166/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001167 * Special-case: build the bridge domain table, maintain
1168 * the next bd id vbl.
1169 */
1170static void vl_api_bridge_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001171 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001172{
Dave Barach72d72232016-08-04 10:15:08 -04001173 vat_main_t *vam = &vat_main;
1174 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001175
Dave Barach72d72232016-08-04 10:15:08 -04001176 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1177 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001178
Dave Barach72d72232016-08-04 10:15:08 -04001179 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1180 ntohl (mp->bd_id), mp->learn, mp->forward,
1181 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001182
Dave Barach72d72232016-08-04 10:15:08 -04001183 if (n_sw_ifs)
1184 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1185 "Interface Name");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001186}
1187
1188static void vl_api_bridge_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001189 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001190{
Dave Barach72d72232016-08-04 10:15:08 -04001191 vat_main_t *vam = &vat_main;
1192 vat_json_node_t *node, *array = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001193
Dave Barach72d72232016-08-04 10:15:08 -04001194 if (VAT_JSON_ARRAY != vam->json_tree.type)
1195 {
1196 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1197 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001198 }
Dave Barach72d72232016-08-04 10:15:08 -04001199 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001200
Dave Barach72d72232016-08-04 10:15:08 -04001201 vat_json_init_object (node);
1202 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1203 vat_json_object_add_uint (node, "flood", mp->flood);
1204 vat_json_object_add_uint (node, "forward", mp->forward);
1205 vat_json_object_add_uint (node, "learn", mp->learn);
1206 vat_json_object_add_uint (node, "bvi_sw_if_index",
1207 ntohl (mp->bvi_sw_if_index));
1208 vat_json_object_add_uint (node, "n_sw_ifs", ntohl (mp->n_sw_ifs));
1209 array = vat_json_object_add (node, "sw_if");
1210 vat_json_init_array (array);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001211}
1212
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001213/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214 * Special-case: build the bridge domain sw if table.
1215 */
1216static void vl_api_bridge_domain_sw_if_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001217 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001218{
Dave Barach72d72232016-08-04 10:15:08 -04001219 vat_main_t *vam = &vat_main;
1220 hash_pair_t *p;
1221 u8 *sw_if_name = 0;
1222 u32 sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001223
Dave Barach72d72232016-08-04 10:15:08 -04001224 sw_if_index = ntohl (mp->sw_if_index);
1225 /* *INDENT-OFF* */
1226 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1227 ({
1228 if ((u32) p->value[0] == sw_if_index)
1229 {
1230 sw_if_name = (u8 *)(p->key);
1231 break;
1232 }
1233 }));
1234 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001235
Dave Barach72d72232016-08-04 10:15:08 -04001236 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1237 mp->shg, sw_if_name ? (char *) sw_if_name :
1238 "sw_if_index not found!");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001239}
1240
1241static void vl_api_bridge_domain_sw_if_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001242 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001243{
Dave Barach72d72232016-08-04 10:15:08 -04001244 vat_main_t *vam = &vat_main;
1245 vat_json_node_t *node = NULL;
1246 uword last_index = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001247
Dave Barach72d72232016-08-04 10:15:08 -04001248 ASSERT (VAT_JSON_ARRAY == vam->json_tree.type);
1249 ASSERT (vec_len (vam->json_tree.array) >= 1);
1250 last_index = vec_len (vam->json_tree.array) - 1;
1251 node = &vam->json_tree.array[last_index];
1252 node = vat_json_object_get_element (node, "sw_if");
1253 ASSERT (NULL != node);
1254 node = vat_json_array_add (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001255
Dave Barach72d72232016-08-04 10:15:08 -04001256 vat_json_init_object (node);
1257 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1258 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1259 vat_json_object_add_uint (node, "shg", mp->shg);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001260}
1261
1262static void vl_api_control_ping_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001263 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001264{
Dave Barach72d72232016-08-04 10:15:08 -04001265 vat_main_t *vam = &vat_main;
1266 i32 retval = ntohl (mp->retval);
1267 if (vam->async_mode)
1268 {
1269 vam->async_errors += (retval < 0);
1270 }
1271 else
1272 {
1273 vam->retval = retval;
1274 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001275 }
1276}
1277
1278static void vl_api_control_ping_reply_t_handler_json
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);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001283
Dave Barach72d72232016-08-04 10:15:08 -04001284 if (VAT_JSON_NONE != vam->json_tree.type)
1285 {
1286 vat_json_print (vam->ofp, &vam->json_tree);
1287 vat_json_free (&vam->json_tree);
1288 vam->json_tree.type = VAT_JSON_NONE;
1289 }
1290 else
1291 {
1292 /* just print [] */
1293 vat_json_init_array (&vam->json_tree);
1294 vat_json_print (vam->ofp, &vam->json_tree);
1295 vam->json_tree.type = VAT_JSON_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001296 }
1297
Dave Barach72d72232016-08-04 10:15:08 -04001298 vam->retval = retval;
1299 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001300}
1301
Dave Barach72d72232016-08-04 10:15:08 -04001302static void
1303vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001304{
Dave Barach72d72232016-08-04 10:15:08 -04001305 vat_main_t *vam = &vat_main;
1306 i32 retval = ntohl (mp->retval);
1307 if (vam->async_mode)
1308 {
1309 vam->async_errors += (retval < 0);
1310 }
1311 else
1312 {
1313 vam->retval = retval;
1314 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001315 }
1316}
1317
1318static void vl_api_l2_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001319 (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 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001323
Dave Barach72d72232016-08-04 10:15:08 -04001324 vat_json_init_object (&node);
1325 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1326 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1327 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001328
Dave Barach72d72232016-08-04 10:15:08 -04001329 vat_json_print (vam->ofp, &node);
1330 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001331
Dave Barach72d72232016-08-04 10:15:08 -04001332 vam->retval = ntohl (mp->retval);
1333 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001334}
1335
1336static void vl_api_bridge_flags_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001337 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001338{
Dave Barach72d72232016-08-04 10:15:08 -04001339 vat_main_t *vam = &vat_main;
1340 i32 retval = ntohl (mp->retval);
1341 if (vam->async_mode)
1342 {
1343 vam->async_errors += (retval < 0);
1344 }
1345 else
1346 {
1347 vam->retval = retval;
1348 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001349 }
1350}
1351
1352static void vl_api_bridge_flags_reply_t_handler_json
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 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001357
Dave Barach72d72232016-08-04 10:15:08 -04001358 vat_json_init_object (&node);
1359 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1360 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1361 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001362
Dave Barach72d72232016-08-04 10:15:08 -04001363 vat_json_print (vam->ofp, &node);
1364 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001365
Dave Barach72d72232016-08-04 10:15:08 -04001366 vam->retval = ntohl (mp->retval);
1367 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001368}
1369
1370static void vl_api_tap_connect_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001371 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001372{
Dave Barach72d72232016-08-04 10:15:08 -04001373 vat_main_t *vam = &vat_main;
1374 i32 retval = ntohl (mp->retval);
1375 if (vam->async_mode)
1376 {
1377 vam->async_errors += (retval < 0);
1378 }
1379 else
1380 {
1381 vam->retval = retval;
1382 vam->sw_if_index = ntohl (mp->sw_if_index);
1383 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001384 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001385
Ed Warnickecb9cada2015-12-08 15:45:58 -07001386}
1387
1388static void vl_api_tap_connect_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001389 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001390{
Dave Barach72d72232016-08-04 10:15:08 -04001391 vat_main_t *vam = &vat_main;
1392 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001393
Dave Barach72d72232016-08-04 10:15:08 -04001394 vat_json_init_object (&node);
1395 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1396 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001397
Dave Barach72d72232016-08-04 10:15:08 -04001398 vat_json_print (vam->ofp, &node);
1399 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001400
Dave Barach72d72232016-08-04 10:15:08 -04001401 vam->retval = ntohl (mp->retval);
1402 vam->result_ready = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001403
Ed Warnickecb9cada2015-12-08 15:45:58 -07001404}
1405
Dave Barach72d72232016-08-04 10:15:08 -04001406static void
1407vl_api_tap_modify_reply_t_handler (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001408{
Dave Barach72d72232016-08-04 10:15:08 -04001409 vat_main_t *vam = &vat_main;
1410 i32 retval = ntohl (mp->retval);
1411 if (vam->async_mode)
1412 {
1413 vam->async_errors += (retval < 0);
1414 }
1415 else
1416 {
1417 vam->retval = retval;
1418 vam->sw_if_index = ntohl (mp->sw_if_index);
1419 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001420 }
1421}
1422
1423static void vl_api_tap_modify_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001424 (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001425{
Dave Barach72d72232016-08-04 10:15:08 -04001426 vat_main_t *vam = &vat_main;
1427 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001428
Dave Barach72d72232016-08-04 10:15:08 -04001429 vat_json_init_object (&node);
1430 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1431 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001432
Dave Barach72d72232016-08-04 10:15:08 -04001433 vat_json_print (vam->ofp, &node);
1434 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001435
Dave Barach72d72232016-08-04 10:15:08 -04001436 vam->retval = ntohl (mp->retval);
1437 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001438}
1439
Dave Barach72d72232016-08-04 10:15:08 -04001440static void
1441vl_api_tap_delete_reply_t_handler (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001442{
Dave Barach72d72232016-08-04 10:15:08 -04001443 vat_main_t *vam = &vat_main;
1444 i32 retval = ntohl (mp->retval);
1445 if (vam->async_mode)
1446 {
1447 vam->async_errors += (retval < 0);
1448 }
1449 else
1450 {
1451 vam->retval = retval;
1452 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001453 }
1454}
1455
1456static void vl_api_tap_delete_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001457 (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 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001461
Dave Barach72d72232016-08-04 10:15:08 -04001462 vat_json_init_object (&node);
1463 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001464
Dave Barach72d72232016-08-04 10:15:08 -04001465 vat_json_print (vam->ofp, &node);
1466 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001467
Dave Barach72d72232016-08-04 10:15:08 -04001468 vam->retval = ntohl (mp->retval);
1469 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001470}
1471
1472static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001473 (vl_api_mpls_ethernet_add_del_tunnel_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 i32 retval = ntohl (mp->retval);
1477 if (vam->async_mode)
1478 {
1479 vam->async_errors += (retval < 0);
1480 }
1481 else
1482 {
1483 vam->retval = retval;
1484 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001485 }
1486}
1487
1488static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
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 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001493
Dave Barach72d72232016-08-04 10:15:08 -04001494 vat_json_init_object (&node);
1495 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1496 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
1497 ntohl (mp->tunnel_sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001498
Dave Barach72d72232016-08-04 10:15:08 -04001499 vat_json_print (vam->ofp, &node);
1500 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001501
Dave Barach72d72232016-08-04 10:15:08 -04001502 vam->retval = ntohl (mp->retval);
1503 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001504}
1505
1506static void vl_api_l2tpv3_create_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001507 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001508{
Dave Barach72d72232016-08-04 10:15:08 -04001509 vat_main_t *vam = &vat_main;
1510 i32 retval = ntohl (mp->retval);
1511 if (vam->async_mode)
1512 {
1513 vam->async_errors += (retval < 0);
1514 }
1515 else
1516 {
1517 vam->retval = retval;
1518 vam->sw_if_index = ntohl (mp->sw_if_index);
1519 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001520 }
1521}
1522
1523static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001524 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001525{
Dave Barach72d72232016-08-04 10:15:08 -04001526 vat_main_t *vam = &vat_main;
1527 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001528
Dave Barach72d72232016-08-04 10:15:08 -04001529 vat_json_init_object (&node);
1530 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1531 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001532
Dave Barach72d72232016-08-04 10:15:08 -04001533 vat_json_print (vam->ofp, &node);
1534 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001535
Dave Barach72d72232016-08-04 10:15:08 -04001536 vam->retval = ntohl (mp->retval);
1537 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001538}
1539
Filip Tehlar3a834602016-08-11 12:21:37 +02001540
1541static void vl_api_lisp_add_del_locator_set_reply_t_handler
1542 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1543{
1544 vat_main_t *vam = &vat_main;
1545 i32 retval = ntohl (mp->retval);
1546 if (vam->async_mode)
1547 {
1548 vam->async_errors += (retval < 0);
1549 }
1550 else
1551 {
1552 vam->retval = retval;
1553 vam->result_ready = 1;
1554 }
1555}
1556
1557static void vl_api_lisp_add_del_locator_set_reply_t_handler_json
1558 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1559{
1560 vat_main_t *vam = &vat_main;
1561 vat_json_node_t node;
1562
1563 vat_json_init_object (&node);
1564 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1565 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
1566
1567 vat_json_print (vam->ofp, &node);
1568 vat_json_free (&node);
1569
1570 vam->retval = ntohl (mp->retval);
1571 vam->result_ready = 1;
1572}
1573
Ed Warnickecb9cada2015-12-08 15:45:58 -07001574static void vl_api_vxlan_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001575 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001576{
Dave Barach72d72232016-08-04 10:15:08 -04001577 vat_main_t *vam = &vat_main;
1578 i32 retval = ntohl (mp->retval);
1579 if (vam->async_mode)
1580 {
1581 vam->async_errors += (retval < 0);
1582 }
1583 else
1584 {
1585 vam->retval = retval;
1586 vam->sw_if_index = ntohl (mp->sw_if_index);
1587 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001588 }
1589}
1590
1591static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001592 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001593{
Dave Barach72d72232016-08-04 10:15:08 -04001594 vat_main_t *vam = &vat_main;
1595 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001596
Dave Barach72d72232016-08-04 10:15:08 -04001597 vat_json_init_object (&node);
1598 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1599 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001600
Dave Barach72d72232016-08-04 10:15:08 -04001601 vat_json_print (vam->ofp, &node);
1602 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001603
Dave Barach72d72232016-08-04 10:15:08 -04001604 vam->retval = ntohl (mp->retval);
1605 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001606}
1607
Chris Luke27fe48f2016-04-28 13:44:38 -04001608static void vl_api_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001609 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001610{
Dave Barach72d72232016-08-04 10:15:08 -04001611 vat_main_t *vam = &vat_main;
1612 i32 retval = ntohl (mp->retval);
1613 if (vam->async_mode)
1614 {
1615 vam->async_errors += (retval < 0);
1616 }
1617 else
1618 {
1619 vam->retval = retval;
1620 vam->sw_if_index = ntohl (mp->sw_if_index);
1621 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001622 }
1623}
1624
1625static void vl_api_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001626 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001627{
Dave Barach72d72232016-08-04 10:15:08 -04001628 vat_main_t *vam = &vat_main;
1629 vat_json_node_t node;
Chris Luke27fe48f2016-04-28 13:44:38 -04001630
Dave Barach72d72232016-08-04 10:15:08 -04001631 vat_json_init_object (&node);
1632 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1633 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Chris Luke27fe48f2016-04-28 13:44:38 -04001634
Dave Barach72d72232016-08-04 10:15:08 -04001635 vat_json_print (vam->ofp, &node);
1636 vat_json_free (&node);
Chris Luke27fe48f2016-04-28 13:44:38 -04001637
Dave Barach72d72232016-08-04 10:15:08 -04001638 vam->retval = ntohl (mp->retval);
1639 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001640}
1641
Ed Warnickecb9cada2015-12-08 15:45:58 -07001642static void vl_api_create_vhost_user_if_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001643 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001644{
Dave Barach72d72232016-08-04 10:15:08 -04001645 vat_main_t *vam = &vat_main;
1646 i32 retval = ntohl (mp->retval);
1647 if (vam->async_mode)
1648 {
1649 vam->async_errors += (retval < 0);
1650 }
1651 else
1652 {
1653 vam->retval = retval;
1654 vam->sw_if_index = ntohl (mp->sw_if_index);
1655 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001656 }
1657}
1658
1659static void vl_api_create_vhost_user_if_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001660 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001661{
Dave Barach72d72232016-08-04 10:15:08 -04001662 vat_main_t *vam = &vat_main;
1663 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001664
Dave Barach72d72232016-08-04 10:15:08 -04001665 vat_json_init_object (&node);
1666 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1667 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001668
Dave Barach72d72232016-08-04 10:15:08 -04001669 vat_json_print (vam->ofp, &node);
1670 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001671
Dave Barach72d72232016-08-04 10:15:08 -04001672 vam->retval = ntohl (mp->retval);
1673 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001674}
1675
1676static void vl_api_ip_address_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001677 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001678{
Dave Barach72d72232016-08-04 10:15:08 -04001679 vat_main_t *vam = &vat_main;
1680 static ip_address_details_t empty_ip_address_details = { {0} };
1681 ip_address_details_t *address = NULL;
1682 ip_details_t *current_ip_details = NULL;
1683 ip_details_t *details = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001684
Dave Barach72d72232016-08-04 10:15:08 -04001685 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001686
Dave Barach72d72232016-08-04 10:15:08 -04001687 if (!details || vam->current_sw_if_index >= vec_len (details)
1688 || !details[vam->current_sw_if_index].present)
1689 {
1690 errmsg ("ip address details arrived but not stored\n");
1691 errmsg ("ip_dump should be called first\n");
1692 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001693 }
1694
Dave Barach72d72232016-08-04 10:15:08 -04001695 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001696
1697#define addresses (current_ip_details->addr)
1698
Dave Barach72d72232016-08-04 10:15:08 -04001699 vec_validate_init_empty (addresses, vec_len (addresses),
1700 empty_ip_address_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001701
Dave Barach72d72232016-08-04 10:15:08 -04001702 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001703
Dave Barach72d72232016-08-04 10:15:08 -04001704 clib_memcpy (&address->ip, &mp->ip, sizeof (address->ip));
1705 address->prefix_length = mp->prefix_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001706#undef addresses
1707}
1708
1709static void vl_api_ip_address_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001710 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001711{
Dave Barach72d72232016-08-04 10:15:08 -04001712 vat_main_t *vam = &vat_main;
1713 vat_json_node_t *node = NULL;
1714 struct in6_addr ip6;
1715 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001716
Dave Barach72d72232016-08-04 10:15:08 -04001717 if (VAT_JSON_ARRAY != vam->json_tree.type)
1718 {
1719 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1720 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001721 }
Dave Barach72d72232016-08-04 10:15:08 -04001722 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001723
Dave Barach72d72232016-08-04 10:15:08 -04001724 vat_json_init_object (node);
1725 if (vam->is_ipv6)
1726 {
1727 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
1728 vat_json_object_add_ip6 (node, "ip", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001729 }
Dave Barach72d72232016-08-04 10:15:08 -04001730 else
1731 {
1732 clib_memcpy (&ip4, mp->ip, sizeof (ip4));
1733 vat_json_object_add_ip4 (node, "ip", ip4);
1734 }
1735 vat_json_object_add_uint (node, "prefix_length", mp->prefix_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001736}
1737
Dave Barach72d72232016-08-04 10:15:08 -04001738static void
1739vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001740{
Dave Barach72d72232016-08-04 10:15:08 -04001741 vat_main_t *vam = &vat_main;
1742 static ip_details_t empty_ip_details = { 0 };
1743 ip_details_t *ip = NULL;
1744 u32 sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001745
Dave Barach72d72232016-08-04 10:15:08 -04001746 sw_if_index = ntohl (mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001747
Dave Barach72d72232016-08-04 10:15:08 -04001748 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1749 sw_if_index, empty_ip_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001750
Dave Barach72d72232016-08-04 10:15:08 -04001751 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1752 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001753
Dave Barach72d72232016-08-04 10:15:08 -04001754 ip->present = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001755}
1756
Dave Barach72d72232016-08-04 10:15:08 -04001757static void
1758vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001759{
Dave Barach72d72232016-08-04 10:15:08 -04001760 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001761
Dave Barach72d72232016-08-04 10:15:08 -04001762 if (VAT_JSON_ARRAY != vam->json_tree.type)
1763 {
1764 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1765 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001766 }
Dave Barach72d72232016-08-04 10:15:08 -04001767 vat_json_array_add_uint (&vam->json_tree,
1768 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001769}
1770
1771static void vl_api_map_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001772 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001773{
Dave Barach72d72232016-08-04 10:15:08 -04001774 vat_json_node_t *node = NULL;
1775 vat_main_t *vam = &vat_main;
1776 struct in6_addr ip6;
1777 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001778
Dave Barach72d72232016-08-04 10:15:08 -04001779 if (VAT_JSON_ARRAY != vam->json_tree.type)
1780 {
1781 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1782 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001783 }
1784
Dave Barach72d72232016-08-04 10:15:08 -04001785 node = vat_json_array_add (&vam->json_tree);
1786 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001787
Dave Barach72d72232016-08-04 10:15:08 -04001788 vat_json_object_add_uint (node, "domain_index",
1789 clib_net_to_host_u32 (mp->domain_index));
1790 clib_memcpy (&ip6, mp->ip6_prefix, sizeof (ip6));
1791 vat_json_object_add_ip6 (node, "ip6_prefix", ip6);
1792 clib_memcpy (&ip4, mp->ip4_prefix, sizeof (ip4));
1793 vat_json_object_add_ip4 (node, "ip4_prefix", ip4);
1794 clib_memcpy (&ip6, mp->ip6_src, sizeof (ip6));
1795 vat_json_object_add_ip6 (node, "ip6_src", ip6);
1796 vat_json_object_add_int (node, "ip6_prefix_len", mp->ip6_prefix_len);
1797 vat_json_object_add_int (node, "ip4_prefix_len", mp->ip4_prefix_len);
1798 vat_json_object_add_int (node, "ip6_src_len", mp->ip6_src_len);
1799 vat_json_object_add_int (node, "ea_bits_len", mp->ea_bits_len);
1800 vat_json_object_add_int (node, "psid_offset", mp->psid_offset);
1801 vat_json_object_add_int (node, "psid_length", mp->psid_length);
1802 vat_json_object_add_uint (node, "flags", mp->flags);
1803 vat_json_object_add_uint (node, "mtu", clib_net_to_host_u16 (mp->mtu));
1804 vat_json_object_add_int (node, "is_translation", mp->is_translation);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001805}
1806
1807static void vl_api_map_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001808 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001809{
Dave Barach72d72232016-08-04 10:15:08 -04001810 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001811
Dave Barach72d72232016-08-04 10:15:08 -04001812 if (mp->is_translation)
1813 {
1814 fformat (vam->ofp,
1815 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1816 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1817 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1818 format_ip6_address, mp->ip6_src, mp->ip6_src_len,
1819 clib_net_to_host_u32 (mp->domain_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001820 }
Dave Barach72d72232016-08-04 10:15:08 -04001821 else
1822 {
1823 fformat (vam->ofp,
1824 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1825 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1826 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1827 format_ip6_address, mp->ip6_src,
1828 clib_net_to_host_u32 (mp->domain_index));
1829 }
1830 fformat (vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1831 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu,
1832 mp->is_translation ? "map-t" : "");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001833}
1834
1835static void vl_api_map_rule_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001836 (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001837{
Dave Barach72d72232016-08-04 10:15:08 -04001838 struct in6_addr ip6;
1839 vat_json_node_t *node = NULL;
1840 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001841
Dave Barach72d72232016-08-04 10:15:08 -04001842 if (VAT_JSON_ARRAY != vam->json_tree.type)
1843 {
1844 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1845 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001846 }
1847
Dave Barach72d72232016-08-04 10:15:08 -04001848 node = vat_json_array_add (&vam->json_tree);
1849 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001850
Dave Barach72d72232016-08-04 10:15:08 -04001851 vat_json_object_add_uint (node, "psid", clib_net_to_host_u16 (mp->psid));
1852 clib_memcpy (&ip6, mp->ip6_dst, sizeof (ip6));
1853 vat_json_object_add_ip6 (node, "ip6_dst", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001854}
1855
Dave Barach72d72232016-08-04 10:15:08 -04001856static void
1857vl_api_map_rule_details_t_handler (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001858{
Dave Barach72d72232016-08-04 10:15:08 -04001859 vat_main_t *vam = &vat_main;
1860 fformat (vam->ofp, " %d (psid) %U (ip6-dst)\n",
1861 clib_net_to_host_u16 (mp->psid), format_ip6_address, mp->ip6_dst);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001862}
1863
Dave Barach72d72232016-08-04 10:15:08 -04001864static void
1865vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001866{
Dave Barach72d72232016-08-04 10:15:08 -04001867 vat_main_t *vam = &vat_main;
1868 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1869 "router_addr %U host_mac %U\n",
1870 mp->pid, mp->is_ipv6 ? "ipv6" : "ipv4", mp->hostname,
1871 format_ip4_address, &mp->host_address,
1872 format_ip4_address, &mp->router_address,
1873 format_ethernet_address, mp->host_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001874}
1875
1876static void vl_api_dhcp_compl_event_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001877 (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001878{
Dave Barach72d72232016-08-04 10:15:08 -04001879 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001880}
1881
Dave Barach72d72232016-08-04 10:15:08 -04001882static void
1883set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1884 u32 counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001885{
Dave Barach72d72232016-08-04 10:15:08 -04001886 vat_main_t *vam = &vat_main;
1887 static u64 default_counter = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001888
Dave Barach72d72232016-08-04 10:15:08 -04001889 vec_validate_init_empty (vam->simple_interface_counters, vnet_counter_type,
1890 NULL);
1891 vec_validate_init_empty (vam->simple_interface_counters[vnet_counter_type],
1892 sw_if_index, default_counter);
1893 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001894}
1895
Dave Barach72d72232016-08-04 10:15:08 -04001896static void
1897set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1898 interface_counter_t counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001899{
Dave Barach72d72232016-08-04 10:15:08 -04001900 vat_main_t *vam = &vat_main;
1901 static interface_counter_t default_counter = { 0, };
Ed Warnickecb9cada2015-12-08 15:45:58 -07001902
Dave Barach72d72232016-08-04 10:15:08 -04001903 vec_validate_init_empty (vam->combined_interface_counters,
1904 vnet_counter_type, NULL);
1905 vec_validate_init_empty (vam->combined_interface_counters
1906 [vnet_counter_type], sw_if_index, default_counter);
1907 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001908}
1909
1910static void vl_api_vnet_interface_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001911 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001912{
Dave Barach72d72232016-08-04 10:15:08 -04001913 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001914}
1915
1916static void vl_api_vnet_interface_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001917 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001918{
Dave Barach72d72232016-08-04 10:15:08 -04001919 interface_counter_t counter;
1920 vlib_counter_t *v;
1921 u64 *v_packets;
1922 u64 packets;
1923 u32 count;
1924 u32 first_sw_if_index;
1925 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001926
Dave Barach72d72232016-08-04 10:15:08 -04001927 count = ntohl (mp->count);
1928 first_sw_if_index = ntohl (mp->first_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001929
Dave Barach72d72232016-08-04 10:15:08 -04001930 if (!mp->is_combined)
1931 {
1932 v_packets = (u64 *) & mp->data;
1933 for (i = 0; i < count; i++)
1934 {
1935 packets =
1936 clib_net_to_host_u64 (clib_mem_unaligned (v_packets, u64));
1937 set_simple_interface_counter (mp->vnet_counter_type,
1938 first_sw_if_index + i, packets);
1939 v_packets++;
1940 }
1941 }
1942 else
1943 {
1944 v = (vlib_counter_t *) & mp->data;
1945 for (i = 0; i < count; i++)
1946 {
1947 counter.packets =
1948 clib_net_to_host_u64 (clib_mem_unaligned (&v->packets, u64));
1949 counter.bytes =
1950 clib_net_to_host_u64 (clib_mem_unaligned (&v->bytes, u64));
1951 set_combined_interface_counter (mp->vnet_counter_type,
1952 first_sw_if_index + i, counter);
1953 v++;
1954 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001955 }
1956}
1957
Dave Barach72d72232016-08-04 10:15:08 -04001958static u32
1959ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001960{
Dave Barach72d72232016-08-04 10:15:08 -04001961 vat_main_t *vam = &vat_main;
1962 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001963
Dave Barach72d72232016-08-04 10:15:08 -04001964 for (i = 0; i < vec_len (vam->ip4_fib_counters_vrf_id_by_index); i++)
1965 {
1966 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id)
1967 {
1968 return i;
1969 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001970 }
Dave Barach72d72232016-08-04 10:15:08 -04001971 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001972}
1973
Dave Barach72d72232016-08-04 10:15:08 -04001974static u32
1975ip6_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->ip6_fib_counters_vrf_id_by_index); i++)
1981 {
1982 if (vam->ip6_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
1990static void vl_api_vnet_ip4_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001991 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001992{
Dave Barach72d72232016-08-04 10:15:08 -04001993 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001994}
1995
1996static void vl_api_vnet_ip4_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001997 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001998{
Dave Barach72d72232016-08-04 10:15:08 -04001999 vat_main_t *vam = &vat_main;
2000 vl_api_ip4_fib_counter_t *v;
2001 ip4_fib_counter_t *counter;
2002 struct in_addr ip4;
2003 u32 vrf_id;
2004 u32 vrf_index;
2005 u32 count;
2006 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002007
Dave Barach72d72232016-08-04 10:15:08 -04002008 vrf_id = ntohl (mp->vrf_id);
2009 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2010 if (~0 == vrf_index)
2011 {
2012 vrf_index = vec_len (vam->ip4_fib_counters_vrf_id_by_index);
2013 vec_validate (vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
2014 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2015 vec_validate (vam->ip4_fib_counters, vrf_index);
2016 vam->ip4_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002017 }
2018
Dave Barach72d72232016-08-04 10:15:08 -04002019 vec_free (vam->ip4_fib_counters[vrf_index]);
2020 v = (vl_api_ip4_fib_counter_t *) & mp->c;
2021 count = ntohl (mp->count);
2022 for (i = 0; i < count; i++)
2023 {
2024 vec_validate (vam->ip4_fib_counters[vrf_index], i);
2025 counter = &vam->ip4_fib_counters[vrf_index][i];
2026 clib_memcpy (&ip4, &v->address, sizeof (ip4));
2027 counter->address = ip4;
2028 counter->address_length = v->address_length;
2029 counter->packets = clib_net_to_host_u64 (v->packets);
2030 counter->bytes = clib_net_to_host_u64 (v->bytes);
2031 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002032 }
2033}
2034
2035static void vl_api_vnet_ip6_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002036 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002037{
Dave Barach72d72232016-08-04 10:15:08 -04002038 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002039}
2040
2041static void vl_api_vnet_ip6_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002042 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002043{
Dave Barach72d72232016-08-04 10:15:08 -04002044 vat_main_t *vam = &vat_main;
2045 vl_api_ip6_fib_counter_t *v;
2046 ip6_fib_counter_t *counter;
2047 struct in6_addr ip6;
2048 u32 vrf_id;
2049 u32 vrf_index;
2050 u32 count;
2051 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002052
Dave Barach72d72232016-08-04 10:15:08 -04002053 vrf_id = ntohl (mp->vrf_id);
2054 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2055 if (~0 == vrf_index)
2056 {
2057 vrf_index = vec_len (vam->ip6_fib_counters_vrf_id_by_index);
2058 vec_validate (vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
2059 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2060 vec_validate (vam->ip6_fib_counters, vrf_index);
2061 vam->ip6_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002062 }
2063
Dave Barach72d72232016-08-04 10:15:08 -04002064 vec_free (vam->ip6_fib_counters[vrf_index]);
2065 v = (vl_api_ip6_fib_counter_t *) & mp->c;
2066 count = ntohl (mp->count);
2067 for (i = 0; i < count; i++)
2068 {
2069 vec_validate (vam->ip6_fib_counters[vrf_index], i);
2070 counter = &vam->ip6_fib_counters[vrf_index][i];
2071 clib_memcpy (&ip6, &v->address, sizeof (ip6));
2072 counter->address = ip6;
2073 counter->address_length = v->address_length;
2074 counter->packets = clib_net_to_host_u64 (v->packets);
2075 counter->bytes = clib_net_to_host_u64 (v->bytes);
2076 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002077 }
2078}
2079
2080static void vl_api_get_first_msg_id_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002081 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002082{
Dave Barach72d72232016-08-04 10:15:08 -04002083 vat_main_t *vam = &vat_main;
2084 i32 retval = ntohl (mp->retval);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002085
Dave Barach72d72232016-08-04 10:15:08 -04002086 if (vam->async_mode)
2087 {
2088 vam->async_errors += (retval < 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002089 }
Dave Barach72d72232016-08-04 10:15:08 -04002090 else
2091 {
2092 vam->retval = retval;
2093 vam->result_ready = 1;
2094 }
2095 if (retval >= 0)
2096 {
2097 errmsg ("first message id %d\n", ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002098 }
2099}
2100
2101static void vl_api_get_first_msg_id_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002102 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002103{
Dave Barach72d72232016-08-04 10:15:08 -04002104 vat_main_t *vam = &vat_main;
2105 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002106
Dave Barach72d72232016-08-04 10:15:08 -04002107 vat_json_init_object (&node);
2108 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2109 vat_json_object_add_uint (&node, "first_msg_id",
2110 (uint) ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002111
Dave Barach72d72232016-08-04 10:15:08 -04002112 vat_json_print (vam->ofp, &node);
2113 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002114
Dave Barach72d72232016-08-04 10:15:08 -04002115 vam->retval = ntohl (mp->retval);
2116 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002117}
2118
Dave Barachb44e9bc2016-02-19 09:06:23 -05002119static void vl_api_get_node_graph_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002120 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002121{
Dave Barach72d72232016-08-04 10:15:08 -04002122 vat_main_t *vam = &vat_main;
2123 api_main_t *am = &api_main;
2124 i32 retval = ntohl (mp->retval);
2125 u8 *pvt_copy, *reply;
2126 void *oldheap;
2127 vlib_node_t *node;
2128 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002129
Dave Barach72d72232016-08-04 10:15:08 -04002130 if (vam->async_mode)
2131 {
2132 vam->async_errors += (retval < 0);
2133 }
2134 else
2135 {
2136 vam->retval = retval;
2137 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002138 }
2139
Dave Barach72d72232016-08-04 10:15:08 -04002140 /* "Should never happen..." */
2141 if (retval != 0)
2142 return;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002143
Dave Barach72d72232016-08-04 10:15:08 -04002144 reply = (u8 *) (mp->reply_in_shmem);
2145 pvt_copy = vec_dup (reply);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002146
Dave Barach72d72232016-08-04 10:15:08 -04002147 /* Toss the shared-memory original... */
2148 pthread_mutex_lock (&am->vlib_rp->mutex);
2149 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002150
Dave Barach72d72232016-08-04 10:15:08 -04002151 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002152
Dave Barach72d72232016-08-04 10:15:08 -04002153 svm_pop_heap (oldheap);
2154 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002155
Dave Barach72d72232016-08-04 10:15:08 -04002156 if (vam->graph_nodes)
2157 {
2158 hash_free (vam->graph_node_index_by_name);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002159
Dave Barach72d72232016-08-04 10:15:08 -04002160 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2161 {
2162 node = vam->graph_nodes[i];
2163 vec_free (node->name);
2164 vec_free (node->next_nodes);
2165 vec_free (node);
2166 }
2167 vec_free (vam->graph_nodes);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002168 }
2169
Dave Barach72d72232016-08-04 10:15:08 -04002170 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2171 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2172 vec_free (pvt_copy);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002173
Dave Barach72d72232016-08-04 10:15:08 -04002174 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2175 {
2176 node = vam->graph_nodes[i];
2177 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002178 }
2179}
2180
2181static void vl_api_get_node_graph_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002182 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002183{
Dave Barach72d72232016-08-04 10:15:08 -04002184 vat_main_t *vam = &vat_main;
2185 api_main_t *am = &api_main;
2186 void *oldheap;
2187 vat_json_node_t node;
2188 u8 *reply;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002189
Dave Barach72d72232016-08-04 10:15:08 -04002190 /* $$$$ make this real? */
2191 vat_json_init_object (&node);
2192 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2193 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002194
Dave Barach72d72232016-08-04 10:15:08 -04002195 reply = (u8 *) (mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002196
Dave Barach72d72232016-08-04 10:15:08 -04002197 /* Toss the shared-memory original... */
2198 pthread_mutex_lock (&am->vlib_rp->mutex);
2199 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002200
Dave Barach72d72232016-08-04 10:15:08 -04002201 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002202
Dave Barach72d72232016-08-04 10:15:08 -04002203 svm_pop_heap (oldheap);
2204 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002205
Dave Barach72d72232016-08-04 10:15:08 -04002206 vat_json_print (vam->ofp, &node);
2207 vat_json_free (&node);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002208
Dave Barach72d72232016-08-04 10:15:08 -04002209 vam->retval = ntohl (mp->retval);
2210 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002211}
2212
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002213static void
Dave Barach72d72232016-08-04 10:15:08 -04002214vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002215{
Dave Barach72d72232016-08-04 10:15:08 -04002216 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002217 u8 *s = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002218
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002219 if (mp->local)
Dave Barach72d72232016-08-04 10:15:08 -04002220 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002221 s = format (s, "%=16d%=16d%=16d\n",
2222 ntohl (mp->sw_if_index), mp->priority, mp->weight);
Dave Barach72d72232016-08-04 10:15:08 -04002223 }
2224 else
2225 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002226 s = format (s, "%=16U%=16d%=16d\n",
2227 mp->is_ipv6 ? format_ip6_address :
2228 format_ip4_address,
2229 mp->ip_address, mp->priority, mp->weight);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002230 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002231
2232 fformat (vam->ofp, "%v", s);
2233 vec_free (s);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002234}
2235
2236static void
Dave Barach72d72232016-08-04 10:15:08 -04002237vl_api_lisp_locator_details_t_handler_json (vl_api_lisp_locator_details_t *
2238 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002239{
Dave Barach72d72232016-08-04 10:15:08 -04002240 vat_main_t *vam = &vat_main;
2241 vat_json_node_t *node = NULL;
Dave Barach72d72232016-08-04 10:15:08 -04002242 struct in6_addr ip6;
2243 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002244
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002245 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Barach72d72232016-08-04 10:15:08 -04002246 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002247 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2248 vat_json_init_array (&vam->json_tree);
2249 }
2250 node = vat_json_array_add (&vam->json_tree);
2251 vat_json_init_object (node);
2252
2253 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2254 vat_json_object_add_uint (node, "priority", mp->priority);
2255 vat_json_object_add_uint (node, "weight", mp->weight);
2256
2257 if (mp->local)
2258 vat_json_object_add_uint (node, "sw_if_index",
2259 clib_net_to_host_u32 (mp->sw_if_index));
2260 else
2261 {
2262 if (mp->is_ipv6)
Dave Barach72d72232016-08-04 10:15:08 -04002263 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002264 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2265 vat_json_object_add_ip6 (node, "address", ip6);
Dave Barach72d72232016-08-04 10:15:08 -04002266 }
2267 else
2268 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002269 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2270 vat_json_object_add_ip4 (node, "address", ip4);
Dave Barach72d72232016-08-04 10:15:08 -04002271 }
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002272 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002273}
2274
2275static void
2276vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
2277 mp)
2278{
2279 vat_main_t *vam = &vat_main;
2280 u8 *ls_name = 0;
2281
2282 ls_name = format (0, "%s", mp->ls_name);
2283
2284 fformat (vam->ofp, "%=10d%=15v\n", clib_net_to_host_u32 (mp->ls_index),
2285 ls_name);
2286 vec_free (ls_name);
2287}
2288
2289static void
2290 vl_api_lisp_locator_set_details_t_handler_json
2291 (vl_api_lisp_locator_set_details_t * mp)
2292{
2293 vat_main_t *vam = &vat_main;
2294 vat_json_node_t *node = 0;
2295 u8 *ls_name = 0;
2296
2297 ls_name = format (0, "%s", mp->ls_name);
2298 vec_add1 (ls_name, 0);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002299
Dave Barach72d72232016-08-04 10:15:08 -04002300 if (VAT_JSON_ARRAY != vam->json_tree.type)
2301 {
2302 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2303 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002304 }
Dave Barach72d72232016-08-04 10:15:08 -04002305 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002306
Dave Barach72d72232016-08-04 10:15:08 -04002307 vat_json_init_object (node);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002308 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2309 vat_json_object_add_uint (node, "ls_index",
2310 clib_net_to_host_u32 (mp->ls_index));
2311 vec_free (ls_name);
2312}
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002313
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002314static u8 *
2315format_lisp_flat_eid (u8 * s, va_list * args)
2316{
2317 u32 type = va_arg (*args, u32);
2318 u8 *eid = va_arg (*args, u8 *);
2319 u32 eid_len = va_arg (*args, u32);
2320
2321 switch (type)
Dave Barach72d72232016-08-04 10:15:08 -04002322 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002323 case 0:
2324 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2325 case 1:
2326 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2327 case 2:
2328 return format (s, "%U", format_ethernet_address, eid);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002329 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002330 return 0;
Dave Barach72d72232016-08-04 10:15:08 -04002331}
2332
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002333static u8 *
2334format_lisp_eid_vat (u8 * s, va_list * args)
Dave Barach72d72232016-08-04 10:15:08 -04002335{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002336 u32 type = va_arg (*args, u32);
2337 u8 *eid = va_arg (*args, u8 *);
2338 u32 eid_len = va_arg (*args, u32);
2339 u8 *seid = va_arg (*args, u8 *);
2340 u32 seid_len = va_arg (*args, u32);
2341 u32 is_src_dst = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -04002342
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002343 if (is_src_dst)
2344 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002345
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002346 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002347
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002348 return s;
Dave Barach72d72232016-08-04 10:15:08 -04002349}
2350
2351static void
Filip Tehlarc00617b2016-08-27 08:40:26 +02002352vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
2353{
2354 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002355 u8 *s = 0, *eid = 0;
2356
2357 if (~0 == mp->locator_set_index)
2358 s = format (0, "action: %d", mp->action);
2359 else
2360 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2361
2362 eid = format (0, "%U", format_lisp_eid_vat,
2363 mp->eid_type,
2364 mp->eid,
2365 mp->eid_prefix_len,
2366 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2367 vec_add1 (eid, 0);
2368
2369 fformat (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-d\n",
2370 clib_net_to_host_u32 (mp->vni),
2371 eid,
2372 mp->is_local ? "local" : "remote",
2373 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative);
2374 vec_free (s);
2375 vec_free (eid);
Filip Tehlarc00617b2016-08-27 08:40:26 +02002376}
2377
2378static void
Dave Barach72d72232016-08-04 10:15:08 -04002379vl_api_lisp_eid_table_details_t_handler_json (vl_api_lisp_eid_table_details_t
2380 * mp)
2381{
2382 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002383 vat_json_node_t *node = 0;
2384 u8 *eid = 0;
2385
2386 if (VAT_JSON_ARRAY != vam->json_tree.type)
2387 {
2388 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2389 vat_json_init_array (&vam->json_tree);
2390 }
2391 node = vat_json_array_add (&vam->json_tree);
2392
2393 vat_json_init_object (node);
2394 if (~0 == mp->locator_set_index)
2395 vat_json_object_add_uint (node, "action", mp->action);
2396 else
2397 vat_json_object_add_uint (node, "locator_set_index",
2398 clib_net_to_host_u32 (mp->locator_set_index));
2399
2400 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
2401 eid = format (0, "%U", format_lisp_eid_vat,
2402 mp->eid_type,
2403 mp->eid,
2404 mp->eid_prefix_len,
2405 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2406 vec_add1 (eid, 0);
2407 vat_json_object_add_string_copy (node, "eid", eid);
2408 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2409 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
2410 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
2411 vec_free (eid);
Dave Barach72d72232016-08-04 10:15:08 -04002412}
2413
2414static void
2415 vl_api_lisp_eid_table_map_details_t_handler
2416 (vl_api_lisp_eid_table_map_details_t * mp)
2417{
2418 vat_main_t *vam = &vat_main;
2419
2420 u8 *line = format (0, "%=10d%=10d",
2421 clib_net_to_host_u32 (mp->vni),
Filip Tehlarc0681792016-08-24 14:11:07 +02002422 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002423 fformat (vam->ofp, "%v\n", line);
2424 vec_free (line);
2425}
2426
2427static void
2428 vl_api_lisp_eid_table_map_details_t_handler_json
2429 (vl_api_lisp_eid_table_map_details_t * mp)
2430{
2431 vat_main_t *vam = &vat_main;
2432 vat_json_node_t *node = NULL;
2433
2434 if (VAT_JSON_ARRAY != vam->json_tree.type)
2435 {
2436 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2437 vat_json_init_array (&vam->json_tree);
2438 }
2439 node = vat_json_array_add (&vam->json_tree);
2440 vat_json_init_object (node);
Filip Tehlarc0681792016-08-24 14:11:07 +02002441 vat_json_object_add_uint (node, "dp_table",
2442 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002443 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
Filip Tehlar2f653d02016-07-13 13:17:15 +02002444}
2445
Filip Tehlar50a4e142016-08-24 11:28:02 +02002446static void
2447 vl_api_lisp_eid_table_vni_details_t_handler
2448 (vl_api_lisp_eid_table_vni_details_t * mp)
2449{
2450 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002451
Filip Tehlar50a4e142016-08-24 11:28:02 +02002452 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
2453 fformat (vam->ofp, "%v\n", line);
2454 vec_free (line);
2455}
2456
2457static void
2458 vl_api_lisp_eid_table_vni_details_t_handler_json
2459 (vl_api_lisp_eid_table_vni_details_t * mp)
2460{
2461 vat_main_t *vam = &vat_main;
2462 vat_json_node_t *node = NULL;
2463
2464 if (VAT_JSON_ARRAY != vam->json_tree.type)
2465 {
2466 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2467 vat_json_init_array (&vam->json_tree);
2468 }
2469 node = vat_json_array_add (&vam->json_tree);
2470 vat_json_init_object (node);
2471 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2472}
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002473
2474static u8 *
2475format_decap_next (u8 * s, va_list * args)
2476{
2477 u32 next_index = va_arg (*args, u32);
2478
2479 switch (next_index)
2480 {
2481 case LISP_GPE_INPUT_NEXT_DROP:
2482 return format (s, "drop");
2483 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2484 return format (s, "ip4");
2485 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2486 return format (s, "ip6");
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002487 default:
2488 return format (s, "unknown %d", next_index);
2489 }
2490 return s;
2491}
2492
2493static void
Dave Barach72d72232016-08-04 10:15:08 -04002494vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *
2495 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002496{
Dave Barach72d72232016-08-04 10:15:08 -04002497 vat_main_t *vam = &vat_main;
2498 u8 *iid_str;
2499 u8 *flag_str = NULL;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002500
Dave Barach72d72232016-08-04 10:15:08 -04002501 iid_str = format (0, "%d (0x%x)", ntohl (mp->iid), ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002502
2503#define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2504 foreach_lisp_gpe_flag_bit;
2505#undef _
2506
Dave Barach72d72232016-08-04 10:15:08 -04002507 fformat (vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2508 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2509 mp->tunnels,
2510 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2511 mp->source_ip,
2512 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2513 mp->destination_ip,
2514 ntohl (mp->encap_fib_id),
2515 ntohl (mp->decap_fib_id),
2516 format_decap_next, ntohl (mp->dcap_next),
2517 mp->ver_res >> 6,
2518 flag_str, mp->next_protocol, mp->ver_res, mp->res, iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002519
Dave Barach72d72232016-08-04 10:15:08 -04002520 vec_free (iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002521}
2522
2523static void
Dave Barach72d72232016-08-04 10:15:08 -04002524 vl_api_lisp_gpe_tunnel_details_t_handler_json
2525 (vl_api_lisp_gpe_tunnel_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002526{
Dave Barach72d72232016-08-04 10:15:08 -04002527 vat_main_t *vam = &vat_main;
2528 vat_json_node_t *node = NULL;
2529 struct in6_addr ip6;
2530 struct in_addr ip4;
2531 u8 *next_decap_str;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002532
Dave Barach72d72232016-08-04 10:15:08 -04002533 next_decap_str = format (0, "%U", format_decap_next, htonl (mp->dcap_next));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002534
Dave Barach72d72232016-08-04 10:15:08 -04002535 if (VAT_JSON_ARRAY != vam->json_tree.type)
2536 {
2537 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2538 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002539 }
Dave Barach72d72232016-08-04 10:15:08 -04002540 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002541
Dave Barach72d72232016-08-04 10:15:08 -04002542 vat_json_init_object (node);
2543 vat_json_object_add_uint (node, "tunel", mp->tunnels);
2544 if (mp->is_ipv6)
2545 {
2546 clib_memcpy (&ip6, mp->source_ip, sizeof (ip6));
2547 vat_json_object_add_ip6 (node, "source address", ip6);
2548 clib_memcpy (&ip6, mp->destination_ip, sizeof (ip6));
2549 vat_json_object_add_ip6 (node, "destination address", ip6);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002550 }
Dave Barach72d72232016-08-04 10:15:08 -04002551 else
2552 {
2553 clib_memcpy (&ip4, mp->source_ip, sizeof (ip4));
2554 vat_json_object_add_ip4 (node, "source address", ip4);
2555 clib_memcpy (&ip4, mp->destination_ip, sizeof (ip4));
2556 vat_json_object_add_ip4 (node, "destination address", ip4);
2557 }
2558 vat_json_object_add_uint (node, "fib encap", ntohl (mp->encap_fib_id));
2559 vat_json_object_add_uint (node, "fib decap", ntohl (mp->decap_fib_id));
2560 vat_json_object_add_string_copy (node, "decap next", next_decap_str);
2561 vat_json_object_add_uint (node, "lisp version", mp->ver_res >> 6);
2562 vat_json_object_add_uint (node, "flags", mp->flags);
2563 vat_json_object_add_uint (node, "next protocol", mp->next_protocol);
2564 vat_json_object_add_uint (node, "ver_res", mp->ver_res);
2565 vat_json_object_add_uint (node, "res", mp->res);
2566 vat_json_object_add_uint (node, "iid", ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002567
Dave Barach72d72232016-08-04 10:15:08 -04002568 vec_free (next_decap_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002569}
2570
2571static void
Filip Tehlar69a9b762016-09-23 10:00:52 +02002572 vl_api_lisp_adjacencies_get_reply_t_handler
2573 (vl_api_lisp_adjacencies_get_reply_t * mp)
2574{
2575 vat_main_t *vam = &vat_main;
2576 u32 i, n;
2577 int retval = clib_net_to_host_u32 (mp->retval);
2578 vl_api_lisp_adjacency_t *a;
2579
2580 if (retval)
2581 goto end;
2582
2583 n = clib_net_to_host_u32 (mp->count);
2584
2585 for (i = 0; i < n; i++)
2586 {
2587 a = &mp->adjacencies[i];
2588 fformat (vam->ofp, "%U %40U\n",
2589 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
2590 format_lisp_flat_eid, a->eid_type, a->reid,
2591 a->reid_prefix_len);
2592 }
2593
2594end:
2595 vam->retval = retval;
2596 vam->result_ready = 1;
2597}
2598
2599static void
2600 vl_api_lisp_adjacencies_get_reply_t_handler_json
2601 (vl_api_lisp_adjacencies_get_reply_t * mp)
2602{
2603 u8 *s = 0;
2604 vat_main_t *vam = &vat_main;
2605 vat_json_node_t *e = 0, root;
2606 u32 i, n;
2607 int retval = clib_net_to_host_u32 (mp->retval);
2608 vl_api_lisp_adjacency_t *a;
2609
2610 if (retval)
2611 goto end;
2612
2613 n = clib_net_to_host_u32 (mp->count);
2614 vat_json_init_array (&root);
2615
2616 for (i = 0; i < n; i++)
2617 {
2618 e = vat_json_array_add (&root);
2619 a = &mp->adjacencies[i];
2620
2621 vat_json_init_object (e);
2622 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
2623 a->leid_prefix_len);
2624 vec_add1 (s, 0);
2625 vat_json_object_add_string_copy (e, "leid", s);
2626 vec_free (s);
2627
2628 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
2629 a->reid_prefix_len);
2630 vec_add1 (s, 0);
2631 vat_json_object_add_string_copy (e, "reid", s);
2632 vec_free (s);
2633 }
2634
2635 vat_json_print (vam->ofp, &root);
2636 vat_json_free (&root);
2637
2638end:
2639 vam->retval = retval;
2640 vam->result_ready = 1;
2641}
2642
2643static void
Dave Barach72d72232016-08-04 10:15:08 -04002644vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
2645 * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002646{
Dave Barach72d72232016-08-04 10:15:08 -04002647 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002648
Dave Barach72d72232016-08-04 10:15:08 -04002649 fformat (vam->ofp, "%=20U\n",
2650 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2651 mp->ip_address);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002652}
2653
2654static void
Dave Barach72d72232016-08-04 10:15:08 -04002655 vl_api_lisp_map_resolver_details_t_handler_json
2656 (vl_api_lisp_map_resolver_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002657{
Dave Barach72d72232016-08-04 10:15:08 -04002658 vat_main_t *vam = &vat_main;
2659 vat_json_node_t *node = NULL;
2660 struct in6_addr ip6;
2661 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002662
Dave Barach72d72232016-08-04 10:15:08 -04002663 if (VAT_JSON_ARRAY != vam->json_tree.type)
2664 {
2665 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2666 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002667 }
Dave Barach72d72232016-08-04 10:15:08 -04002668 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002669
Dave Barach72d72232016-08-04 10:15:08 -04002670 vat_json_init_object (node);
2671 if (mp->is_ipv6)
2672 {
2673 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2674 vat_json_object_add_ip6 (node, "map resolver", ip6);
2675 }
2676 else
2677 {
2678 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2679 vat_json_object_add_ip4 (node, "map resolver", ip4);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002680 }
2681}
2682
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002683static void
Dave Barach72d72232016-08-04 10:15:08 -04002684 vl_api_show_lisp_status_reply_t_handler
2685 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002686{
Dave Barach72d72232016-08-04 10:15:08 -04002687 vat_main_t *vam = &vat_main;
2688 i32 retval = ntohl (mp->retval);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002689
Dave Barach72d72232016-08-04 10:15:08 -04002690 if (0 <= retval)
2691 {
2692 fformat (vam->ofp, "feature: %s\ngpe: %s\n",
2693 mp->feature_status ? "enabled" : "disabled",
2694 mp->gpe_status ? "enabled" : "disabled");
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002695 }
2696
Dave Barach72d72232016-08-04 10:15:08 -04002697 vam->retval = retval;
2698 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002699}
2700
2701static void
Dave Barach72d72232016-08-04 10:15:08 -04002702 vl_api_show_lisp_status_reply_t_handler_json
2703 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002704{
Dave Barach72d72232016-08-04 10:15:08 -04002705 vat_main_t *vam = &vat_main;
2706 vat_json_node_t node;
2707 u8 *gpe_status = NULL;
2708 u8 *feature_status = NULL;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002709
Dave Barach72d72232016-08-04 10:15:08 -04002710 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2711 feature_status = format (0, "%s",
2712 mp->feature_status ? "enabled" : "disabled");
2713 vec_add1 (gpe_status, 0);
2714 vec_add1 (feature_status, 0);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002715
Dave Barach72d72232016-08-04 10:15:08 -04002716 vat_json_init_object (&node);
2717 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
2718 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
Filip Tehlar46d4e362016-05-09 09:39:26 +02002719
Dave Barach72d72232016-08-04 10:15:08 -04002720 vec_free (gpe_status);
2721 vec_free (feature_status);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002722
Dave Barach72d72232016-08-04 10:15:08 -04002723 vat_json_print (vam->ofp, &node);
2724 vat_json_free (&node);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002725
Dave Barach72d72232016-08-04 10:15:08 -04002726 vam->retval = ntohl (mp->retval);
2727 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002728}
2729
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002730static void
Dave Barach72d72232016-08-04 10:15:08 -04002731 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
2732 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002733{
Dave Barach72d72232016-08-04 10:15:08 -04002734 vat_main_t *vam = &vat_main;
2735 i32 retval = ntohl (mp->retval);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002736
Dave Barach72d72232016-08-04 10:15:08 -04002737 if (retval >= 0)
2738 {
2739 fformat (vam->ofp, "%=20s\n", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002740 }
2741
Dave Barach72d72232016-08-04 10:15:08 -04002742 vam->retval = retval;
2743 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002744}
2745
2746static void
Dave Barach72d72232016-08-04 10:15:08 -04002747 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json
2748 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002749{
Dave Barach72d72232016-08-04 10:15:08 -04002750 vat_main_t *vam = &vat_main;
2751 vat_json_node_t *node = NULL;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002752
Dave Barach72d72232016-08-04 10:15:08 -04002753 if (VAT_JSON_ARRAY != vam->json_tree.type)
2754 {
2755 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2756 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002757 }
Dave Barach72d72232016-08-04 10:15:08 -04002758 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002759
Dave Barach72d72232016-08-04 10:15:08 -04002760 vat_json_init_object (node);
2761 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002762
Dave Barach72d72232016-08-04 10:15:08 -04002763 vat_json_print (vam->ofp, node);
2764 vat_json_free (node);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002765
Dave Barach72d72232016-08-04 10:15:08 -04002766 vam->retval = ntohl (mp->retval);
2767 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002768}
2769
Florin Corasdca88042016-09-14 16:01:38 +02002770static u8 *
2771format_lisp_map_request_mode (u8 * s, va_list * args)
2772{
2773 u32 mode = va_arg (*args, u32);
2774
2775 switch (mode)
2776 {
2777 case 0:
2778 return format (0, "dst-only");
2779 case 1:
2780 return format (0, "src-dst");
2781 }
2782 return 0;
2783}
2784
2785static void
2786 vl_api_show_lisp_map_request_mode_reply_t_handler
2787 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2788{
2789 vat_main_t *vam = &vat_main;
2790 i32 retval = ntohl (mp->retval);
2791
2792 if (0 <= retval)
2793 {
2794 u32 mode = mp->mode;
2795 fformat (vam->ofp, "map_request_mode: %U\n",
2796 format_lisp_map_request_mode, mode);
2797 }
2798
2799 vam->retval = retval;
2800 vam->result_ready = 1;
2801}
2802
2803static void
2804 vl_api_show_lisp_map_request_mode_reply_t_handler_json
2805 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2806{
2807 vat_main_t *vam = &vat_main;
2808 vat_json_node_t node;
2809 u8 *s = 0;
2810 u32 mode;
2811
2812 mode = mp->mode;
2813 s = format (0, "%U", format_lisp_map_request_mode, mode);
2814 vec_add1 (s, 0);
2815
2816 vat_json_init_object (&node);
2817 vat_json_object_add_string_copy (&node, "map_request_mode", s);
2818 vat_json_print (vam->ofp, &node);
2819 vat_json_free (&node);
2820
2821 vec_free (s);
2822 vam->retval = ntohl (mp->retval);
2823 vam->result_ready = 1;
2824}
2825
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002826static void
2827vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2828{
Dave Barach72d72232016-08-04 10:15:08 -04002829 vat_main_t *vam = &vat_main;
2830 i32 retval = ntohl (mp->retval);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002831
Dave Barach72d72232016-08-04 10:15:08 -04002832 if (0 <= retval)
2833 {
2834 fformat (vam->ofp, "%-20s%-16s\n",
2835 mp->status ? "enabled" : "disabled",
2836 mp->status ? (char *) mp->locator_set_name : "");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002837 }
2838
Dave Barach72d72232016-08-04 10:15:08 -04002839 vam->retval = retval;
2840 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002841}
2842
2843static void
Dave Barach72d72232016-08-04 10:15:08 -04002844vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t *
2845 mp)
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002846{
Dave Barach72d72232016-08-04 10:15:08 -04002847 vat_main_t *vam = &vat_main;
2848 vat_json_node_t node;
2849 u8 *status = 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002850
Dave Barach72d72232016-08-04 10:15:08 -04002851 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2852 vec_add1 (status, 0);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002853
Dave Barach72d72232016-08-04 10:15:08 -04002854 vat_json_init_object (&node);
2855 vat_json_object_add_string_copy (&node, "status", status);
2856 if (mp->status)
2857 {
2858 vat_json_object_add_string_copy (&node, "locator_set",
2859 mp->locator_set_name);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002860 }
2861
Dave Barach72d72232016-08-04 10:15:08 -04002862 vec_free (status);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002863
Dave Barach72d72232016-08-04 10:15:08 -04002864 vat_json_print (vam->ofp, &node);
2865 vat_json_free (&node);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002866
Dave Barach72d72232016-08-04 10:15:08 -04002867 vam->retval = ntohl (mp->retval);
2868 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002869}
2870
Dave Barach72d72232016-08-04 10:15:08 -04002871static u8 *
2872format_policer_type (u8 * s, va_list * va)
Matus Fabiane8554802016-05-18 23:40:37 -07002873{
Dave Barach72d72232016-08-04 10:15:08 -04002874 u32 i = va_arg (*va, u32);
Matus Fabiane8554802016-05-18 23:40:37 -07002875
Dave Barach72d72232016-08-04 10:15:08 -04002876 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2877 s = format (s, "1r2c");
2878 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2879 s = format (s, "1r3c");
2880 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2881 s = format (s, "2r3c-2698");
2882 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2883 s = format (s, "2r3c-4115");
2884 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2885 s = format (s, "2r3c-mef5cf1");
2886 else
2887 s = format (s, "ILLEGAL");
Matus Fabiane8554802016-05-18 23:40:37 -07002888 return s;
2889}
2890
Dave Barach72d72232016-08-04 10:15:08 -04002891static u8 *
2892format_policer_rate_type (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -07002893{
2894 u32 i = va_arg (*va, u32);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002895
Dave Barach72d72232016-08-04 10:15:08 -04002896 if (i == SSE2_QOS_RATE_KBPS)
2897 s = format (s, "kbps");
2898 else if (i == SSE2_QOS_RATE_PPS)
2899 s = format (s, "pps");
2900 else
2901 s = format (s, "ILLEGAL");
2902 return s;
2903}
2904
2905static u8 *
2906format_policer_round_type (u8 * s, va_list * va)
2907{
2908 u32 i = va_arg (*va, u32);
2909
2910 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2911 s = format (s, "closest");
2912 else if (i == SSE2_QOS_ROUND_TO_UP)
2913 s = format (s, "up");
2914 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2915 s = format (s, "down");
2916 else
2917 s = format (s, "ILLEGAL");
2918 return s;
2919}
2920
2921static u8 *
2922format_policer_action_type (u8 * s, va_list * va)
2923{
2924 u32 i = va_arg (*va, u32);
2925
2926 if (i == SSE2_QOS_ACTION_DROP)
2927 s = format (s, "drop");
2928 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2929 s = format (s, "transmit");
2930 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2931 s = format (s, "mark-and-transmit");
2932 else
2933 s = format (s, "ILLEGAL");
2934 return s;
2935}
2936
2937static u8 *
2938format_dscp (u8 * s, va_list * va)
2939{
2940 u32 i = va_arg (*va, u32);
2941 char *t = 0;
2942
2943 switch (i)
2944 {
2945#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2946 foreach_vnet_dscp
2947#undef _
Matus Fabian4ac74c92016-05-31 07:33:29 -07002948 default:
2949 return format (s, "ILLEGAL");
Dave Barach72d72232016-08-04 10:15:08 -04002950 }
Matus Fabian4ac74c92016-05-31 07:33:29 -07002951 s = format (s, "%s", t);
2952 return s;
2953}
2954
Dave Barach72d72232016-08-04 10:15:08 -04002955static void
2956vl_api_policer_details_t_handler (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 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
Matus Fabian4ac74c92016-05-31 07:33:29 -07002960
Dave Barach72d72232016-08-04 10:15:08 -04002961 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2962 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
2963 else
2964 conform_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002965
Dave Barach72d72232016-08-04 10:15:08 -04002966 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2967 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
2968 else
2969 exceed_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002970
Dave Barach72d72232016-08-04 10:15:08 -04002971 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2972 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
2973 else
2974 violate_dscp_str = format (0, "");
Matus Fabiane8554802016-05-18 23:40:37 -07002975
Dave Barach72d72232016-08-04 10:15:08 -04002976 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2977 "rate type %U, round type %U, %s rate, %s color-aware, "
2978 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2979 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2980 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2981 mp->name,
2982 format_policer_type, mp->type,
2983 ntohl (mp->cir),
2984 ntohl (mp->eir),
2985 clib_net_to_host_u64 (mp->cb),
2986 clib_net_to_host_u64 (mp->eb),
2987 format_policer_rate_type, mp->rate_type,
2988 format_policer_round_type, mp->round_type,
2989 mp->single_rate ? "single" : "dual",
2990 mp->color_aware ? "is" : "not",
2991 ntohl (mp->cir_tokens_per_period),
2992 ntohl (mp->pir_tokens_per_period),
2993 ntohl (mp->scale),
2994 ntohl (mp->current_limit),
2995 ntohl (mp->current_bucket),
2996 ntohl (mp->extended_limit),
2997 ntohl (mp->extended_bucket),
2998 clib_net_to_host_u64 (mp->last_update_time),
2999 format_policer_action_type, mp->conform_action_type,
3000 conform_dscp_str,
3001 format_policer_action_type, mp->exceed_action_type,
3002 exceed_dscp_str,
3003 format_policer_action_type, mp->violate_action_type,
3004 violate_dscp_str);
Matus Fabian4ac74c92016-05-31 07:33:29 -07003005
Dave Barach72d72232016-08-04 10:15:08 -04003006 vec_free (conform_dscp_str);
3007 vec_free (exceed_dscp_str);
3008 vec_free (violate_dscp_str);
Matus Fabiane8554802016-05-18 23:40:37 -07003009}
3010
3011static void vl_api_policer_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003012 (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07003013{
Dave Barach72d72232016-08-04 10:15:08 -04003014 vat_main_t *vam = &vat_main;
3015 vat_json_node_t *node;
3016 u8 *rate_type_str, *round_type_str, *type_str;
3017 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
Matus Fabiane8554802016-05-18 23:40:37 -07003018
Dave Barach72d72232016-08-04 10:15:08 -04003019 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
3020 round_type_str =
3021 format (0, "%U", format_policer_round_type, mp->round_type);
3022 type_str = format (0, "%U", format_policer_type, mp->type);
3023 conform_action_str = format (0, "%U", format_policer_action_type,
3024 mp->conform_action_type);
3025 exceed_action_str = format (0, "%U", format_policer_action_type,
3026 mp->exceed_action_type);
3027 violate_action_str = format (0, "%U", format_policer_action_type,
3028 mp->violate_action_type);
Matus Fabiane8554802016-05-18 23:40:37 -07003029
Dave Barach72d72232016-08-04 10:15:08 -04003030 if (VAT_JSON_ARRAY != vam->json_tree.type)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003031 {
Dave Barach72d72232016-08-04 10:15:08 -04003032 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3033 vat_json_init_array (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003034 }
Dave Barach72d72232016-08-04 10:15:08 -04003035 node = vat_json_array_add (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003036
Dave Barach72d72232016-08-04 10:15:08 -04003037 vat_json_init_object (node);
3038 vat_json_object_add_string_copy (node, "name", mp->name);
3039 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
3040 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
3041 vat_json_object_add_uint (node, "cb", ntohl (mp->cb));
3042 vat_json_object_add_uint (node, "eb", ntohl (mp->eb));
3043 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
3044 vat_json_object_add_string_copy (node, "round_type", round_type_str);
3045 vat_json_object_add_string_copy (node, "type", type_str);
3046 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
3047 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
3048 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
3049 vat_json_object_add_uint (node, "cir_tokens_per_period",
3050 ntohl (mp->cir_tokens_per_period));
3051 vat_json_object_add_uint (node, "eir_tokens_per_period",
3052 ntohl (mp->pir_tokens_per_period));
3053 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
3054 vat_json_object_add_uint (node, "current_bucket",
3055 ntohl (mp->current_bucket));
3056 vat_json_object_add_uint (node, "extended_limit",
3057 ntohl (mp->extended_limit));
3058 vat_json_object_add_uint (node, "extended_bucket",
3059 ntohl (mp->extended_bucket));
3060 vat_json_object_add_uint (node, "last_update_time",
3061 ntohl (mp->last_update_time));
3062 vat_json_object_add_string_copy (node, "conform_action",
3063 conform_action_str);
3064 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3065 {
3066 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3067 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
3068 vec_free (dscp_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003069 }
Dave Barach72d72232016-08-04 10:15:08 -04003070 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
3071 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3072 {
3073 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3074 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
3075 vec_free (dscp_str);
3076 }
3077 vat_json_object_add_string_copy (node, "violate_action",
3078 violate_action_str);
3079 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3080 {
3081 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3082 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
3083 vec_free (dscp_str);
3084 }
3085
3086 vec_free (rate_type_str);
3087 vec_free (round_type_str);
3088 vec_free (type_str);
3089 vec_free (conform_action_str);
3090 vec_free (exceed_action_str);
3091 vec_free (violate_action_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003092}
3093
Dave Barach72d72232016-08-04 10:15:08 -04003094static void
3095vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
3096 mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003097{
Dave Barach72d72232016-08-04 10:15:08 -04003098 vat_main_t *vam = &vat_main;
3099 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003100
Dave Barach72d72232016-08-04 10:15:08 -04003101 if (count > 0)
3102 fformat (vam->ofp, "classify table ids (%d) : ", count);
3103 for (i = 0; i < count; i++)
3104 {
3105 fformat (vam->ofp, "%d", ntohl (mp->ids[i]));
3106 fformat (vam->ofp, (i < count - 1) ? "," : "\n");
3107 }
3108 vam->retval = ntohl (mp->retval);
3109 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003110}
3111
Dave Barach72d72232016-08-04 10:15:08 -04003112static void
3113 vl_api_classify_table_ids_reply_t_handler_json
3114 (vl_api_classify_table_ids_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003115{
Dave Barach72d72232016-08-04 10:15:08 -04003116 vat_main_t *vam = &vat_main;
3117 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003118
Dave Barach72d72232016-08-04 10:15:08 -04003119 if (count > 0)
3120 {
3121 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003122
Dave Barach72d72232016-08-04 10:15:08 -04003123 vat_json_init_object (&node);
3124 for (i = 0; i < count; i++)
3125 {
3126 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
3127 }
3128 vat_json_print (vam->ofp, &node);
3129 vat_json_free (&node);
3130 }
3131 vam->retval = ntohl (mp->retval);
3132 vam->result_ready = 1;
3133}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003134
Dave Barach72d72232016-08-04 10:15:08 -04003135static void
3136 vl_api_classify_table_by_interface_reply_t_handler
3137 (vl_api_classify_table_by_interface_reply_t * mp)
3138{
3139 vat_main_t *vam = &vat_main;
3140 u32 table_id;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003141
Dave Barach72d72232016-08-04 10:15:08 -04003142 table_id = ntohl (mp->l2_table_id);
3143 if (table_id != ~0)
3144 fformat (vam->ofp, "l2 table id : %d\n", table_id);
3145 else
3146 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
3147 table_id = ntohl (mp->ip4_table_id);
3148 if (table_id != ~0)
3149 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
3150 else
3151 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
3152 table_id = ntohl (mp->ip6_table_id);
3153 if (table_id != ~0)
3154 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
3155 else
3156 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
3157 vam->retval = ntohl (mp->retval);
3158 vam->result_ready = 1;
3159}
3160
3161static void
3162 vl_api_classify_table_by_interface_reply_t_handler_json
3163 (vl_api_classify_table_by_interface_reply_t * mp)
3164{
3165 vat_main_t *vam = &vat_main;
3166 vat_json_node_t node;
3167
3168 vat_json_init_object (&node);
3169
3170 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
3171 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
3172 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
3173
3174 vat_json_print (vam->ofp, &node);
3175 vat_json_free (&node);
3176
3177 vam->retval = ntohl (mp->retval);
3178 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003179}
3180
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003181static void vl_api_policer_add_del_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003182 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003183{
Dave Barach72d72232016-08-04 10:15:08 -04003184 vat_main_t *vam = &vat_main;
3185 i32 retval = ntohl (mp->retval);
3186 if (vam->async_mode)
3187 {
3188 vam->async_errors += (retval < 0);
3189 }
3190 else
3191 {
3192 vam->retval = retval;
3193 vam->result_ready = 1;
3194 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3195 /*
3196 * Note: this is just barely thread-safe, depends on
3197 * the main thread spinning waiting for an answer...
3198 */
3199 errmsg ("policer index %d\n", ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003200 }
3201}
3202
3203static void vl_api_policer_add_del_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003204 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003205{
Dave Barach72d72232016-08-04 10:15:08 -04003206 vat_main_t *vam = &vat_main;
3207 vat_json_node_t node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003208
Dave Barach72d72232016-08-04 10:15:08 -04003209 vat_json_init_object (&node);
3210 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3211 vat_json_object_add_uint (&node, "policer_index",
3212 ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003213
Dave Barach72d72232016-08-04 10:15:08 -04003214 vat_json_print (vam->ofp, &node);
3215 vat_json_free (&node);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003216
Dave Barach72d72232016-08-04 10:15:08 -04003217 vam->retval = ntohl (mp->retval);
3218 vam->result_ready = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003219}
3220
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003221/* Format hex dump. */
Dave Barach72d72232016-08-04 10:15:08 -04003222u8 *
3223format_hex_bytes (u8 * s, va_list * va)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003224{
Dave Barach72d72232016-08-04 10:15:08 -04003225 u8 *bytes = va_arg (*va, u8 *);
3226 int n_bytes = va_arg (*va, int);
3227 uword i;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003228
Dave Barach72d72232016-08-04 10:15:08 -04003229 /* Print short or long form depending on byte count. */
3230 uword short_form = n_bytes <= 32;
3231 uword indent = format_get_indent (s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003232
Dave Barach72d72232016-08-04 10:15:08 -04003233 if (n_bytes == 0)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003234 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003235
Dave Barach72d72232016-08-04 10:15:08 -04003236 for (i = 0; i < n_bytes; i++)
3237 {
3238 if (!short_form && (i % 32) == 0)
3239 s = format (s, "%08x: ", i);
3240 s = format (s, "%02x", bytes[i]);
3241 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3242 s = format (s, "\n%U", format_white_space, indent);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003243 }
Dave Barach72d72232016-08-04 10:15:08 -04003244
3245 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003246}
3247
Dave Barach72d72232016-08-04 10:15:08 -04003248static void
3249vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3250 * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003251{
Dave Barach72d72232016-08-04 10:15:08 -04003252 vat_main_t *vam = &vat_main;
3253 i32 retval = ntohl (mp->retval);
3254 if (retval == 0)
3255 {
3256 fformat (vam->ofp, "classify table info :\n");
3257 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n",
3258 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3259 ntohl (mp->miss_next_index));
3260 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n",
3261 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3262 ntohl (mp->match_n_vectors));
3263 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask,
3264 ntohl (mp->mask_length));
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003265 }
Dave Barach72d72232016-08-04 10:15:08 -04003266 vam->retval = retval;
3267 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003268}
3269
Dave Barach72d72232016-08-04 10:15:08 -04003270static void
3271 vl_api_classify_table_info_reply_t_handler_json
3272 (vl_api_classify_table_info_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003273{
Dave Barach72d72232016-08-04 10:15:08 -04003274 vat_main_t *vam = &vat_main;
3275 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003276
Dave Barach72d72232016-08-04 10:15:08 -04003277 i32 retval = ntohl (mp->retval);
3278 if (retval == 0)
3279 {
3280 vat_json_init_object (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003281
Dave Barach72d72232016-08-04 10:15:08 -04003282 vat_json_object_add_int (&node, "sessions",
3283 ntohl (mp->active_sessions));
3284 vat_json_object_add_int (&node, "nexttbl",
3285 ntohl (mp->next_table_index));
3286 vat_json_object_add_int (&node, "nextnode",
3287 ntohl (mp->miss_next_index));
3288 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3289 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3290 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3291 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3292 ntohl (mp->mask_length), 0);
3293 vat_json_object_add_string_copy (&node, "mask", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003294
Dave Barach72d72232016-08-04 10:15:08 -04003295 vat_json_print (vam->ofp, &node);
3296 vat_json_free (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003297 }
Dave Barach72d72232016-08-04 10:15:08 -04003298 vam->retval = ntohl (mp->retval);
3299 vam->result_ready = 1;
3300}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003301
Dave Barach72d72232016-08-04 10:15:08 -04003302static void
3303vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3304 mp)
3305{
3306 vat_main_t *vam = &vat_main;
3307
3308 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3309 ntohl (mp->hit_next_index), ntohl (mp->advance),
3310 ntohl (mp->opaque_index));
3311 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match,
3312 ntohl (mp->match_length));
3313}
3314
3315static void
3316 vl_api_classify_session_details_t_handler_json
3317 (vl_api_classify_session_details_t * mp)
3318{
3319 vat_main_t *vam = &vat_main;
3320 vat_json_node_t *node = NULL;
3321
3322 if (VAT_JSON_ARRAY != vam->json_tree.type)
3323 {
3324 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3325 vat_json_init_array (&vam->json_tree);
3326 }
3327 node = vat_json_array_add (&vam->json_tree);
3328
3329 vat_json_init_object (node);
3330 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3331 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3332 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3333 u8 *s =
3334 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3335 0);
3336 vat_json_object_add_string_copy (node, "match", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003337}
Matus Fabiane8554802016-05-18 23:40:37 -07003338
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003339static void vl_api_pg_create_interface_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003340 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003341{
Dave Barach72d72232016-08-04 10:15:08 -04003342 vat_main_t *vam = &vat_main;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003343
Dave Barach72d72232016-08-04 10:15:08 -04003344 vam->retval = ntohl (mp->retval);
3345 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003346}
3347
3348static void vl_api_pg_create_interface_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003349 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003350{
Dave Barach72d72232016-08-04 10:15:08 -04003351 vat_main_t *vam = &vat_main;
3352 vat_json_node_t node;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003353
Dave Barach72d72232016-08-04 10:15:08 -04003354 i32 retval = ntohl (mp->retval);
3355 if (retval == 0)
3356 {
3357 vat_json_init_object (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003358
Dave Barach72d72232016-08-04 10:15:08 -04003359 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003360
Dave Barach72d72232016-08-04 10:15:08 -04003361 vat_json_print (vam->ofp, &node);
3362 vat_json_free (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003363 }
Dave Barach72d72232016-08-04 10:15:08 -04003364 vam->retval = ntohl (mp->retval);
3365 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003366}
3367
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003368static void vl_api_policer_classify_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003369 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003370{
Dave Barach72d72232016-08-04 10:15:08 -04003371 vat_main_t *vam = &vat_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003372
Dave Barach72d72232016-08-04 10:15:08 -04003373 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3374 ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003375}
3376
3377static void vl_api_policer_classify_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003378 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003379{
Dave Barach72d72232016-08-04 10:15:08 -04003380 vat_main_t *vam = &vat_main;
3381 vat_json_node_t *node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003382
Dave Barach72d72232016-08-04 10:15:08 -04003383 if (VAT_JSON_ARRAY != vam->json_tree.type)
3384 {
3385 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3386 vat_json_init_array (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003387 }
Dave Barach72d72232016-08-04 10:15:08 -04003388 node = vat_json_array_add (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003389
Dave Barach72d72232016-08-04 10:15:08 -04003390 vat_json_init_object (node);
3391 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3392 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003393}
3394
Matus Fabian694265d2016-08-10 01:55:36 -07003395static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
3396 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3397{
3398 vat_main_t *vam = &vat_main;
3399 i32 retval = ntohl (mp->retval);
3400 if (vam->async_mode)
3401 {
3402 vam->async_errors += (retval < 0);
3403 }
3404 else
3405 {
3406 vam->retval = retval;
3407 vam->sw_if_index = ntohl (mp->sw_if_index);
3408 vam->result_ready = 1;
3409 }
3410}
3411
3412static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
3413 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3414{
3415 vat_main_t *vam = &vat_main;
3416 vat_json_node_t node;
3417
3418 vat_json_init_object (&node);
3419 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3420 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
3421
3422 vat_json_print (vam->ofp, &node);
3423 vat_json_free (&node);
3424
3425 vam->retval = ntohl (mp->retval);
3426 vam->result_ready = 1;
3427}
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003428
Juraj Sloboda506b2452016-08-07 23:45:24 -07003429static void vl_api_flow_classify_details_t_handler
3430 (vl_api_flow_classify_details_t * mp)
3431{
3432 vat_main_t *vam = &vat_main;
3433
3434 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3435 ntohl (mp->table_index));
3436}
3437
3438static void vl_api_flow_classify_details_t_handler_json
3439 (vl_api_flow_classify_details_t * mp)
3440{
3441 vat_main_t *vam = &vat_main;
3442 vat_json_node_t *node;
3443
3444 if (VAT_JSON_ARRAY != vam->json_tree.type)
3445 {
3446 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3447 vat_json_init_array (&vam->json_tree);
3448 }
3449 node = vat_json_array_add (&vam->json_tree);
3450
3451 vat_json_init_object (node);
3452 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3453 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3454}
3455
3456
3457
Ed Warnickecb9cada2015-12-08 15:45:58 -07003458#define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
3459#define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
3460#define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
3461#define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
Filip Tehlar69a9b762016-09-23 10:00:52 +02003462#define vl_api_lisp_adjacencies_get_reply_t_endian vl_noop_handler
3463#define vl_api_lisp_adjacencies_get_reply_t_print vl_noop_handler
Ed Warnickecb9cada2015-12-08 15:45:58 -07003464
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003465/*
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003466 * Generate boilerplate reply handlers, which
Ed Warnickecb9cada2015-12-08 15:45:58 -07003467 * dig the return value out of the xxx_reply_t API message,
3468 * stick it into vam->retval, and set vam->result_ready
3469 *
3470 * Could also do this by pointing N message decode slots at
3471 * a single function, but that could break in subtle ways.
3472 */
3473
3474#define foreach_standard_reply_retval_handler \
3475_(sw_interface_set_flags_reply) \
3476_(sw_interface_add_del_address_reply) \
3477_(sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003478_(sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003479_(sw_interface_set_vpath_reply) \
3480_(sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003481_(sw_interface_set_dpdk_hqos_pipe_reply) \
3482_(sw_interface_set_dpdk_hqos_subport_reply) \
3483_(sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003484_(bridge_domain_add_del_reply) \
3485_(sw_interface_set_l2_xconnect_reply) \
3486_(l2fib_add_del_reply) \
3487_(ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003488_(mpls_route_add_del_reply) \
3489_(mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003490_(proxy_arp_add_del_reply) \
3491_(proxy_arp_intfc_enable_disable_reply) \
3492_(mpls_add_del_encap_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003493_(mpls_ethernet_add_del_tunnel_2_reply) \
3494_(sw_interface_set_unnumbered_reply) \
3495_(ip_neighbor_add_del_reply) \
3496_(reset_vrf_reply) \
3497_(oam_add_del_reply) \
3498_(reset_fib_reply) \
3499_(dhcp_proxy_config_reply) \
3500_(dhcp_proxy_config_2_reply) \
3501_(dhcp_proxy_set_vss_reply) \
3502_(dhcp_client_config_reply) \
3503_(set_ip_flow_hash_reply) \
3504_(sw_interface_ip6_enable_disable_reply) \
3505_(sw_interface_ip6_set_link_local_address_reply) \
3506_(sw_interface_ip6nd_ra_prefix_reply) \
3507_(sw_interface_ip6nd_ra_config_reply) \
3508_(set_arp_neighbor_limit_reply) \
3509_(l2_patch_add_del_reply) \
3510_(sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003511_(sr_policy_add_del_reply) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07003512_(sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003513_(classify_add_del_session_reply) \
3514_(classify_set_interface_ip_table_reply) \
3515_(classify_set_interface_l2_tables_reply) \
3516_(l2tpv3_set_tunnel_cookies_reply) \
3517_(l2tpv3_interface_enable_disable_reply) \
3518_(l2tpv3_set_lookup_key_reply) \
3519_(l2_fib_clear_table_reply) \
3520_(l2_interface_efp_filter_reply) \
3521_(l2_interface_vlan_tag_rewrite_reply) \
3522_(modify_vhost_user_if_reply) \
3523_(delete_vhost_user_if_reply) \
3524_(want_ip4_arp_events_reply) \
John Lo1edfba92016-08-27 01:11:57 -04003525_(want_ip6_nd_events_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003526_(input_acl_set_interface_reply) \
3527_(ipsec_spd_add_del_reply) \
3528_(ipsec_interface_add_del_spd_reply) \
3529_(ipsec_spd_add_del_entry_reply) \
3530_(ipsec_sad_add_del_entry_reply) \
3531_(ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003532_(ikev2_profile_add_del_reply) \
3533_(ikev2_profile_set_auth_reply) \
3534_(ikev2_profile_set_id_reply) \
3535_(ikev2_profile_set_ts_reply) \
3536_(ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003537_(delete_loopback_reply) \
3538_(bd_ip_mac_add_del_reply) \
3539_(map_del_domain_reply) \
3540_(map_add_del_rule_reply) \
3541_(want_interface_events_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003542_(want_stats_reply) \
3543_(cop_interface_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003544_(cop_whitelist_enable_disable_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003545_(sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003546_(ioam_enable_reply) \
3547_(ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003548_(lisp_add_del_locator_reply) \
3549_(lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003550_(lisp_add_del_remote_mapping_reply) \
3551_(lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003552_(lisp_gpe_add_del_fwd_entry_reply) \
3553_(lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003554_(lisp_gpe_enable_disable_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003555_(lisp_gpe_add_del_iface_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003556_(lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003557_(lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003558_(lisp_map_request_mode_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003559_(lisp_add_del_map_request_itr_rlocs_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003560_(lisp_eid_table_add_del_map_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003561_(vxlan_gpe_add_del_tunnel_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003562_(af_packet_delete_reply) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003563_(policer_classify_set_interface_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003564_(netmap_create_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003565_(netmap_delete_reply) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003566_(set_ipfix_exporter_reply) \
3567_(set_ipfix_classify_stream_reply) \
3568_(ipfix_classify_table_add_del_reply) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003569_(flow_classify_set_interface_reply) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003570_(pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003571_(pg_enable_disable_reply) \
3572_(ip_source_and_port_range_check_add_del_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003573_(ip_source_and_port_range_check_interface_add_del_reply)\
Pavel Kotucek95300d12016-08-26 16:11:36 +02003574_(delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003575_(l2_interface_pbb_tag_rewrite_reply) \
3576_(punt_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003577
3578#define _(n) \
3579 static void vl_api_##n##_t_handler \
3580 (vl_api_##n##_t * mp) \
3581 { \
3582 vat_main_t * vam = &vat_main; \
3583 i32 retval = ntohl(mp->retval); \
3584 if (vam->async_mode) { \
3585 vam->async_errors += (retval < 0); \
3586 } else { \
3587 vam->retval = retval; \
3588 vam->result_ready = 1; \
3589 } \
3590 }
3591foreach_standard_reply_retval_handler;
3592#undef _
3593
3594#define _(n) \
3595 static void vl_api_##n##_t_handler_json \
3596 (vl_api_##n##_t * mp) \
3597 { \
3598 vat_main_t * vam = &vat_main; \
3599 vat_json_node_t node; \
3600 vat_json_init_object(&node); \
3601 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3602 vat_json_print(vam->ofp, &node); \
3603 vam->retval = ntohl(mp->retval); \
3604 vam->result_ready = 1; \
3605 }
3606foreach_standard_reply_retval_handler;
3607#undef _
3608
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003609/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07003610 * Table of message reply handlers, must include boilerplate handlers
3611 * we just generated
3612 */
3613
3614#define foreach_vpe_api_reply_msg \
3615_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3616_(SW_INTERFACE_DETAILS, sw_interface_details) \
3617_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3618_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3619_(CONTROL_PING_REPLY, control_ping_reply) \
3620_(CLI_REPLY, cli_reply) \
Ole Troanc27213a2016-08-31 14:50:49 +02003621_(CLI_INBAND_REPLY, cli_inband_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003622_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3623 sw_interface_add_del_address_reply) \
3624_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003625_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003626_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3627_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3628 sw_interface_set_l2_xconnect_reply) \
3629_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3630 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003631_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3632 sw_interface_set_dpdk_hqos_pipe_reply) \
3633_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3634 sw_interface_set_dpdk_hqos_subport_reply) \
3635_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3636 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003637_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3638_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3639_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3640_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3641_(L2_FLAGS_REPLY, l2_flags_reply) \
3642_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3643_(TAP_CONNECT_REPLY, tap_connect_reply) \
3644_(TAP_MODIFY_REPLY, tap_modify_reply) \
3645_(TAP_DELETE_REPLY, tap_delete_reply) \
3646_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3647_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003648_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3649_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003650_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3651_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3652 proxy_arp_intfc_enable_disable_reply) \
3653_(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003654_(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3655 mpls_ethernet_add_del_tunnel_reply) \
3656_(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3657 mpls_ethernet_add_del_tunnel_2_reply) \
3658_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3659 sw_interface_set_unnumbered_reply) \
3660_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3661_(RESET_VRF_REPLY, reset_vrf_reply) \
3662_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3663_(CREATE_SUBIF_REPLY, create_subif_reply) \
3664_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3665_(RESET_FIB_REPLY, reset_fib_reply) \
3666_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3667_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3668_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3669_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3670_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3671_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3672 sw_interface_ip6_enable_disable_reply) \
3673_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3674 sw_interface_ip6_set_link_local_address_reply) \
3675_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3676 sw_interface_ip6nd_ra_prefix_reply) \
3677_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3678 sw_interface_ip6nd_ra_config_reply) \
3679_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3680_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3681_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003682_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3683_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003684_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3685_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3686_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3687classify_set_interface_ip_table_reply) \
3688_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3689 classify_set_interface_l2_tables_reply) \
3690_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3691_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3692_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3693_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3694_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3695 l2tpv3_interface_enable_disable_reply) \
3696_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3697_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3698_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003699_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003700_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3701_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003702_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3703_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3704_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3705_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3706_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3707_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3708_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3709_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003710_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003711_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3712_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003713_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3714_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3715_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003716_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3717_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003718_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3719_(IP_ADDRESS_DETAILS, ip_address_details) \
3720_(IP_DETAILS, ip_details) \
3721_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3722_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3723_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3724_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3725_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003726_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3727_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3728_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3729_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3730_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003731_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3732_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3733_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3734_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3735_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3736_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3737_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3738_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003739_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003740_(MAP_DOMAIN_DETAILS, map_domain_details) \
3741_(MAP_RULE_DETAILS, map_rule_details) \
3742_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3743_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003744_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3745_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003746_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003747_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003748_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003749_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3750_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003751_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3752_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3753_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003754_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3755_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003756_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3757_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003758_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003759_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003760_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003761_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003762_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003763_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3764_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003765_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003766_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003767_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003768_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003769_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003770_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Filip Tehlar69a9b762016-09-23 10:00:52 +02003771_(LISP_ADJACENCIES_GET_REPLY, lisp_adjacencies_get_reply) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003772_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003773_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3774 lisp_add_del_map_request_itr_rlocs_reply) \
3775_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3776 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003777_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003778_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003779_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003780_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003781_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003782_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003783_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3784_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003785_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003786_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003787_(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3788_(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003789_(MPLS_FIB_DETAILS, mpls_fib_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003790_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3791_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3792_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003793_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003794_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3795_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3796_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3797_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3798_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3799_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003800_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3801_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003802_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3803_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3804_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003805_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3806_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3807 ip_source_and_port_range_check_add_del_reply) \
3808_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003809 ip_source_and_port_range_check_interface_add_del_reply) \
3810_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003811_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
Pavel Kotucek95300d12016-08-26 16:11:36 +02003812_(DELETE_SUBIF_REPLY, delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003813_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3814_(PUNT_REPLY, punt_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003815
3816/* M: construct, but don't yet send a message */
3817
3818#define M(T,t) \
3819do { \
3820 vam->result_ready = 0; \
3821 mp = vl_msg_api_alloc(sizeof(*mp)); \
3822 memset (mp, 0, sizeof (*mp)); \
3823 mp->_vl_msg_id = ntohs (VL_API_##T); \
3824 mp->client_index = vam->my_client_index; \
3825} while(0);
3826
3827#define M2(T,t,n) \
3828do { \
3829 vam->result_ready = 0; \
3830 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3831 memset (mp, 0, sizeof (*mp)); \
3832 mp->_vl_msg_id = ntohs (VL_API_##T); \
3833 mp->client_index = vam->my_client_index; \
3834} while(0);
3835
3836
3837/* S: send a message */
3838#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3839
3840/* W: wait for results, with timeout */
3841#define W \
3842do { \
3843 timeout = vat_time_now (vam) + 1.0; \
3844 \
3845 while (vat_time_now (vam) < timeout) { \
3846 if (vam->result_ready == 1) { \
3847 return (vam->retval); \
3848 } \
3849 } \
3850 return -99; \
3851} while(0);
3852
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003853/* W2: wait for results, with timeout */
3854#define W2(body) \
3855do { \
3856 timeout = vat_time_now (vam) + 1.0; \
3857 \
3858 while (vat_time_now (vam) < timeout) { \
3859 if (vam->result_ready == 1) { \
3860 (body); \
3861 return (vam->retval); \
3862 } \
3863 } \
3864 return -99; \
3865} while(0);
3866
Dave Barach72d72232016-08-04 10:15:08 -04003867typedef struct
3868{
3869 u8 *name;
3870 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003871} name_sort_t;
3872
3873
3874#define STR_VTR_OP_CASE(op) \
3875 case L2_VTR_ ## op: \
3876 return "" # op;
3877
Dave Barach72d72232016-08-04 10:15:08 -04003878static const char *
3879str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003880{
Dave Barach72d72232016-08-04 10:15:08 -04003881 switch (vtr_op)
3882 {
3883 STR_VTR_OP_CASE (DISABLED);
3884 STR_VTR_OP_CASE (PUSH_1);
3885 STR_VTR_OP_CASE (PUSH_2);
3886 STR_VTR_OP_CASE (POP_1);
3887 STR_VTR_OP_CASE (POP_2);
3888 STR_VTR_OP_CASE (TRANSLATE_1_1);
3889 STR_VTR_OP_CASE (TRANSLATE_1_2);
3890 STR_VTR_OP_CASE (TRANSLATE_2_1);
3891 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003892 }
3893
Dave Barach72d72232016-08-04 10:15:08 -04003894 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07003895}
3896
Dave Barach72d72232016-08-04 10:15:08 -04003897static int
3898dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003899{
Dave Barach72d72232016-08-04 10:15:08 -04003900 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003901
Dave Barach72d72232016-08-04 10:15:08 -04003902 if (vam->json_output)
3903 {
3904 clib_warning
3905 ("JSON output supported only for VPE API calls and dump_stats_table");
3906 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003907 }
3908
Dave Barach72d72232016-08-04 10:15:08 -04003909 fformat (vam->ofp,
3910 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3911 "Interface", "sw_if_index",
3912 "sub id", "dot1ad", "tags", "outer id",
3913 "inner id", "exact", "default", "outer any", "inner any");
3914
3915 vec_foreach (sub, vam->sw_if_subif_table)
3916 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07003917 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003918 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3919 sub->interface_name,
3920 sub->sw_if_index,
3921 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3922 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3923 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3924 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3925 if (sub->vtr_op != L2_VTR_DISABLED)
3926 {
3927 fformat (vam->ofp,
3928 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3929 "tag1: %d tag2: %d ]\n",
3930 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3931 sub->vtr_tag1, sub->vtr_tag2);
3932 }
3933 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003934
Dave Barach72d72232016-08-04 10:15:08 -04003935 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003936}
3937
Dave Barach72d72232016-08-04 10:15:08 -04003938static int
3939name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003940{
Dave Barach72d72232016-08-04 10:15:08 -04003941 name_sort_t *n1 = a1;
3942 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003943
Dave Barach72d72232016-08-04 10:15:08 -04003944 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003945}
3946
Dave Barach72d72232016-08-04 10:15:08 -04003947static int
3948dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003949{
Dave Barach72d72232016-08-04 10:15:08 -04003950 hash_pair_t *p;
3951 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003952
Dave Barach72d72232016-08-04 10:15:08 -04003953 if (vam->json_output)
3954 {
3955 clib_warning
3956 ("JSON output supported only for VPE API calls and dump_stats_table");
3957 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003958 }
3959
Dave Barach72d72232016-08-04 10:15:08 -04003960 /* *INDENT-OFF* */
3961 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3962 ({
3963 vec_add2 (nses, ns, 1);
3964 ns->name = (u8 *)(p->key);
3965 ns->value = (u32) p->value[0];
3966 }));
3967 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003968
Dave Barach72d72232016-08-04 10:15:08 -04003969 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003970
Dave Barach72d72232016-08-04 10:15:08 -04003971 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3972 vec_foreach (ns, nses)
3973 {
3974 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3975 }
3976 vec_free (nses);
3977 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003978}
3979
Dave Barach72d72232016-08-04 10:15:08 -04003980static int
3981dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003982{
Dave Barach72d72232016-08-04 10:15:08 -04003983 const ip_details_t *det = NULL;
3984 const ip_address_details_t *address = NULL;
3985 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003986
Dave Barach72d72232016-08-04 10:15:08 -04003987 fformat (vam->ofp, "%-12s\n", "sw_if_index");
3988
Dave Barach72d72232016-08-04 10:15:08 -04003989 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3990 {
3991 i++;
3992 if (!det->present)
3993 {
3994 continue;
3995 }
3996 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003997 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003998 " %-30s%-13s\n", "Address", "Prefix length");
3999 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004000 {
Dave Barach72d72232016-08-04 10:15:08 -04004001 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004002 }
Dave Barach72d72232016-08-04 10:15:08 -04004003 vec_foreach (address, det->addr)
4004 {
4005 fformat (vam->ofp,
4006 " %-30U%-13d\n",
4007 is_ipv6 ? format_ip6_address : format_ip4_address,
4008 address->ip, address->prefix_length);
4009 }
4010 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004011
Dave Barach72d72232016-08-04 10:15:08 -04004012 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004013}
4014
Dave Barach72d72232016-08-04 10:15:08 -04004015static int
4016dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004017{
Dave Barach72d72232016-08-04 10:15:08 -04004018 if (vam->json_output)
4019 {
4020 clib_warning
4021 ("JSON output supported only for VPE API calls and dump_stats_table");
4022 return -99;
4023 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004024
Dave Barach72d72232016-08-04 10:15:08 -04004025 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004026}
4027
Dave Barach72d72232016-08-04 10:15:08 -04004028static int
4029dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004030{
Dave Barach72d72232016-08-04 10:15:08 -04004031 if (vam->json_output)
4032 {
4033 clib_warning
4034 ("JSON output supported only for VPE API calls and dump_stats_table");
4035 return -99;
4036 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004037
Dave Barach72d72232016-08-04 10:15:08 -04004038 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004039}
4040
Dave Barach72d72232016-08-04 10:15:08 -04004041static char *
4042counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004043{
Dave Barach72d72232016-08-04 10:15:08 -04004044 if (!is_combined)
4045 {
4046 switch (counter_type)
4047 {
4048 case VNET_INTERFACE_COUNTER_DROP:
4049 return "drop";
4050 case VNET_INTERFACE_COUNTER_PUNT:
4051 return "punt";
4052 case VNET_INTERFACE_COUNTER_IP4:
4053 return "ip4";
4054 case VNET_INTERFACE_COUNTER_IP6:
4055 return "ip6";
4056 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
4057 return "rx-no-buf";
4058 case VNET_INTERFACE_COUNTER_RX_MISS:
4059 return "rx-miss";
4060 case VNET_INTERFACE_COUNTER_RX_ERROR:
4061 return "rx-error";
4062 case VNET_INTERFACE_COUNTER_TX_ERROR:
4063 return "tx-error";
4064 default:
4065 return "INVALID-COUNTER-TYPE";
4066 }
4067 }
4068 else
4069 {
4070 switch (counter_type)
4071 {
4072 case VNET_INTERFACE_COUNTER_RX:
4073 return "rx";
4074 case VNET_INTERFACE_COUNTER_TX:
4075 return "tx";
4076 default:
4077 return "INVALID-COUNTER-TYPE";
4078 }
4079 }
4080}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004081
Dave Barach72d72232016-08-04 10:15:08 -04004082static int
4083dump_stats_table (vat_main_t * vam)
4084{
4085 vat_json_node_t node;
4086 vat_json_node_t *msg_array;
4087 vat_json_node_t *msg;
4088 vat_json_node_t *counter_array;
4089 vat_json_node_t *counter;
4090 interface_counter_t c;
4091 u64 packets;
4092 ip4_fib_counter_t *c4;
4093 ip6_fib_counter_t *c6;
4094 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004095
Dave Barach72d72232016-08-04 10:15:08 -04004096 if (!vam->json_output)
4097 {
4098 clib_warning ("dump_stats_table supported only in JSON format");
4099 return -99;
4100 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004101
Dave Barach72d72232016-08-04 10:15:08 -04004102 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004103
Dave Barach72d72232016-08-04 10:15:08 -04004104 /* interface counters */
4105 msg_array = vat_json_object_add (&node, "interface_counters");
4106 vat_json_init_array (msg_array);
4107 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4108 {
4109 msg = vat_json_array_add (msg_array);
4110 vat_json_init_object (msg);
4111 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4112 (u8 *) counter_type_to_str (i, 0));
4113 vat_json_object_add_int (msg, "is_combined", 0);
4114 counter_array = vat_json_object_add (msg, "data");
4115 vat_json_init_array (counter_array);
4116 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4117 {
4118 packets = vam->simple_interface_counters[i][j];
4119 vat_json_array_add_uint (counter_array, packets);
4120 }
4121 }
4122 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4123 {
4124 msg = vat_json_array_add (msg_array);
4125 vat_json_init_object (msg);
4126 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4127 (u8 *) counter_type_to_str (i, 1));
4128 vat_json_object_add_int (msg, "is_combined", 1);
4129 counter_array = vat_json_object_add (msg, "data");
4130 vat_json_init_array (counter_array);
4131 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4132 {
4133 c = vam->combined_interface_counters[i][j];
4134 counter = vat_json_array_add (counter_array);
4135 vat_json_init_object (counter);
4136 vat_json_object_add_uint (counter, "packets", c.packets);
4137 vat_json_object_add_uint (counter, "bytes", c.bytes);
4138 }
4139 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004140
Dave Barach72d72232016-08-04 10:15:08 -04004141 /* ip4 fib counters */
4142 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4143 vat_json_init_array (msg_array);
4144 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4145 {
4146 msg = vat_json_array_add (msg_array);
4147 vat_json_init_object (msg);
4148 vat_json_object_add_uint (msg, "vrf_id",
4149 vam->ip4_fib_counters_vrf_id_by_index[i]);
4150 counter_array = vat_json_object_add (msg, "c");
4151 vat_json_init_array (counter_array);
4152 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4153 {
4154 counter = vat_json_array_add (counter_array);
4155 vat_json_init_object (counter);
4156 c4 = &vam->ip4_fib_counters[i][j];
4157 vat_json_object_add_ip4 (counter, "address", c4->address);
4158 vat_json_object_add_uint (counter, "address_length",
4159 c4->address_length);
4160 vat_json_object_add_uint (counter, "packets", c4->packets);
4161 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4162 }
4163 }
4164
4165 /* ip6 fib counters */
4166 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4167 vat_json_init_array (msg_array);
4168 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4169 {
4170 msg = vat_json_array_add (msg_array);
4171 vat_json_init_object (msg);
4172 vat_json_object_add_uint (msg, "vrf_id",
4173 vam->ip6_fib_counters_vrf_id_by_index[i]);
4174 counter_array = vat_json_object_add (msg, "c");
4175 vat_json_init_array (counter_array);
4176 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4177 {
4178 counter = vat_json_array_add (counter_array);
4179 vat_json_init_object (counter);
4180 c6 = &vam->ip6_fib_counters[i][j];
4181 vat_json_object_add_ip6 (counter, "address", c6->address);
4182 vat_json_object_add_uint (counter, "address_length",
4183 c6->address_length);
4184 vat_json_object_add_uint (counter, "packets", c6->packets);
4185 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4186 }
4187 }
4188
4189 vat_json_print (vam->ofp, &node);
4190 vat_json_free (&node);
4191
4192 return 0;
4193}
4194
4195int
4196exec (vat_main_t * vam)
4197{
4198 api_main_t *am = &api_main;
4199 vl_api_cli_request_t *mp;
4200 f64 timeout;
4201 void *oldheap;
4202 u8 *cmd = 0;
4203 unformat_input_t *i = vam->input;
4204
4205 if (vec_len (i->buffer) == 0)
4206 return -1;
4207
4208 if (vam->exec_mode == 0 && unformat (i, "mode"))
4209 {
4210 vam->exec_mode = 1;
4211 return 0;
4212 }
4213 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4214 {
4215 vam->exec_mode = 0;
4216 return 0;
4217 }
4218
4219
4220 M (CLI_REQUEST, cli_request);
4221
4222 /*
4223 * Copy cmd into shared memory.
4224 * In order for the CLI command to work, it
4225 * must be a vector ending in \n, not a C-string ending
4226 * in \n\0.
4227 */
4228 pthread_mutex_lock (&am->vlib_rp->mutex);
4229 oldheap = svm_push_data_heap (am->vlib_rp);
4230
4231 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4232 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4233
4234 svm_pop_heap (oldheap);
4235 pthread_mutex_unlock (&am->vlib_rp->mutex);
4236
4237 mp->cmd_in_shmem = (u64) cmd;
4238 S;
4239 timeout = vat_time_now (vam) + 10.0;
4240
4241 while (vat_time_now (vam) < timeout)
4242 {
4243 if (vam->result_ready == 1)
4244 {
4245 u8 *free_me;
4246 if (vam->shmem_result != NULL)
4247 fformat (vam->ofp, "%s", vam->shmem_result);
4248 pthread_mutex_lock (&am->vlib_rp->mutex);
4249 oldheap = svm_push_data_heap (am->vlib_rp);
4250
4251 free_me = (u8 *) vam->shmem_result;
4252 vec_free (free_me);
4253
4254 svm_pop_heap (oldheap);
4255 pthread_mutex_unlock (&am->vlib_rp->mutex);
4256 return 0;
4257 }
4258 }
4259 return -99;
4260}
4261
Ole Troanc27213a2016-08-31 14:50:49 +02004262/*
4263 * Future replacement of exec() that passes CLI buffers directly in
4264 * the API messages instead of an additional shared memory area.
4265 */
4266static int
4267exec_inband (vat_main_t * vam)
4268{
4269 vl_api_cli_inband_t *mp;
4270 f64 timeout;
4271 unformat_input_t *i = vam->input;
4272
4273 if (vec_len (i->buffer) == 0)
4274 return -1;
4275
4276 if (vam->exec_mode == 0 && unformat (i, "mode"))
4277 {
4278 vam->exec_mode = 1;
4279 return 0;
4280 }
4281 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4282 {
4283 vam->exec_mode = 0;
4284 return 0;
4285 }
4286
4287 /*
4288 * In order for the CLI command to work, it
4289 * must be a vector ending in \n, not a C-string ending
4290 * in \n\0.
4291 */
4292 u32 len = vec_len (vam->input->buffer);
4293 M2 (CLI_INBAND, cli_inband, len);
4294 clib_memcpy (mp->cmd, vam->input->buffer, len);
4295 mp->length = htonl (len);
4296
4297 S;
4298 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4299}
4300
Dave Barach72d72232016-08-04 10:15:08 -04004301static int
4302api_create_loopback (vat_main_t * vam)
4303{
4304 unformat_input_t *i = vam->input;
4305 vl_api_create_loopback_t *mp;
4306 f64 timeout;
4307 u8 mac_address[6];
4308 u8 mac_set = 0;
4309
4310 memset (mac_address, 0, sizeof (mac_address));
4311
4312 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4313 {
4314 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4315 mac_set = 1;
4316 else
4317 break;
4318 }
4319
4320 /* Construct the API message */
4321 M (CREATE_LOOPBACK, create_loopback);
4322 if (mac_set)
4323 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4324
4325 S;
4326 W;
4327}
4328
4329static int
4330api_delete_loopback (vat_main_t * vam)
4331{
4332 unformat_input_t *i = vam->input;
4333 vl_api_delete_loopback_t *mp;
4334 f64 timeout;
4335 u32 sw_if_index = ~0;
4336
4337 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4338 {
4339 if (unformat (i, "sw_if_index %d", &sw_if_index))
4340 ;
4341 else
4342 break;
4343 }
4344
4345 if (sw_if_index == ~0)
4346 {
4347 errmsg ("missing sw_if_index\n");
4348 return -99;
4349 }
4350
4351 /* Construct the API message */
4352 M (DELETE_LOOPBACK, delete_loopback);
4353 mp->sw_if_index = ntohl (sw_if_index);
4354
4355 S;
4356 W;
4357}
4358
4359static int
4360api_want_stats (vat_main_t * vam)
4361{
4362 unformat_input_t *i = vam->input;
4363 vl_api_want_stats_t *mp;
4364 f64 timeout;
4365 int enable = -1;
4366
4367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4368 {
4369 if (unformat (i, "enable"))
4370 enable = 1;
4371 else if (unformat (i, "disable"))
4372 enable = 0;
4373 else
4374 break;
4375 }
4376
4377 if (enable == -1)
4378 {
4379 errmsg ("missing enable|disable\n");
4380 return -99;
4381 }
4382
4383 M (WANT_STATS, want_stats);
4384 mp->enable_disable = enable;
4385
4386 S;
4387 W;
4388}
4389
4390static int
4391api_want_interface_events (vat_main_t * vam)
4392{
4393 unformat_input_t *i = vam->input;
4394 vl_api_want_interface_events_t *mp;
4395 f64 timeout;
4396 int enable = -1;
4397
4398 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4399 {
4400 if (unformat (i, "enable"))
4401 enable = 1;
4402 else if (unformat (i, "disable"))
4403 enable = 0;
4404 else
4405 break;
4406 }
4407
4408 if (enable == -1)
4409 {
4410 errmsg ("missing enable|disable\n");
4411 return -99;
4412 }
4413
4414 M (WANT_INTERFACE_EVENTS, want_interface_events);
4415 mp->enable_disable = enable;
4416
4417 vam->interface_event_display = enable;
4418
4419 S;
4420 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004421}
4422
4423
4424/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004425int
4426api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004427{
Dave Barach72d72232016-08-04 10:15:08 -04004428 vl_api_sw_interface_dump_t *mp;
4429 f64 timeout;
4430 hash_pair_t *p;
4431 name_sort_t *nses = 0, *ns;
4432 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004433
Dave Barach72d72232016-08-04 10:15:08 -04004434 /* Toss the old name table */
4435 /* *INDENT-OFF* */
4436 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4437 ({
4438 vec_add2 (nses, ns, 1);
4439 ns->name = (u8 *)(p->key);
4440 ns->value = (u32) p->value[0];
4441 }));
4442 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004443
Dave Barach72d72232016-08-04 10:15:08 -04004444 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004445
Dave Barach72d72232016-08-04 10:15:08 -04004446 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004447
Dave Barach72d72232016-08-04 10:15:08 -04004448 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004449
Dave Barach72d72232016-08-04 10:15:08 -04004450 vec_foreach (sub, vam->sw_if_subif_table)
4451 {
4452 vec_free (sub->interface_name);
4453 }
4454 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004455
Dave Barach72d72232016-08-04 10:15:08 -04004456 /* recreate the interface name hash table */
4457 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004458
Dave Barach72d72232016-08-04 10:15:08 -04004459 /* Get list of ethernets */
4460 M (SW_INTERFACE_DUMP, sw_interface_dump);
4461 mp->name_filter_valid = 1;
4462 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4463 S;
4464
4465 /* and local / loopback interfaces */
4466 M (SW_INTERFACE_DUMP, sw_interface_dump);
4467 mp->name_filter_valid = 1;
4468 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4469 S;
4470
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004471 /* and packet-generator interfaces */
4472 M (SW_INTERFACE_DUMP, sw_interface_dump);
4473 mp->name_filter_valid = 1;
4474 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4475 S;
Dave Barach72d72232016-08-04 10:15:08 -04004476
4477 /* and vxlan-gpe tunnel interfaces */
4478 M (SW_INTERFACE_DUMP, sw_interface_dump);
4479 mp->name_filter_valid = 1;
4480 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4481 sizeof (mp->name_filter) - 1);
4482 S;
4483
4484 /* and vxlan tunnel interfaces */
4485 M (SW_INTERFACE_DUMP, sw_interface_dump);
4486 mp->name_filter_valid = 1;
4487 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4488 S;
4489
4490 /* and host (af_packet) interfaces */
4491 M (SW_INTERFACE_DUMP, sw_interface_dump);
4492 mp->name_filter_valid = 1;
4493 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4494 S;
4495
4496 /* and l2tpv3 tunnel interfaces */
4497 M (SW_INTERFACE_DUMP, sw_interface_dump);
4498 mp->name_filter_valid = 1;
4499 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4500 sizeof (mp->name_filter) - 1);
4501 S;
4502
4503 /* and GRE tunnel interfaces */
4504 M (SW_INTERFACE_DUMP, sw_interface_dump);
4505 mp->name_filter_valid = 1;
4506 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4507 S;
4508
Florin Corasce982752016-09-06 13:36:11 +02004509 /* and LISP-GPE interfaces */
4510 M (SW_INTERFACE_DUMP, sw_interface_dump);
4511 mp->name_filter_valid = 1;
4512 strncpy ((char *) mp->name_filter, "lisp_gpe",
4513 sizeof (mp->name_filter) - 1);
4514 S;
4515
Matus Fabian8fce3e32016-09-06 23:19:43 -07004516 /* and IPSEC tunnel interfaces */
4517 M (SW_INTERFACE_DUMP, sw_interface_dump);
4518 mp->name_filter_valid = 1;
4519 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4520 S;
4521
Dave Barach72d72232016-08-04 10:15:08 -04004522 /* Use a control ping for synchronization */
4523 {
4524 vl_api_control_ping_t *mp;
4525 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004526 S;
Dave Barach72d72232016-08-04 10:15:08 -04004527 }
4528 W;
4529}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004530
Dave Barach72d72232016-08-04 10:15:08 -04004531static int
4532api_sw_interface_set_flags (vat_main_t * vam)
4533{
4534 unformat_input_t *i = vam->input;
4535 vl_api_sw_interface_set_flags_t *mp;
4536 f64 timeout;
4537 u32 sw_if_index;
4538 u8 sw_if_index_set = 0;
4539 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004540
Dave Barach72d72232016-08-04 10:15:08 -04004541 /* Parse args required to build the message */
4542 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004543 {
Dave Barach72d72232016-08-04 10:15:08 -04004544 if (unformat (i, "admin-up"))
4545 admin_up = 1;
4546 else if (unformat (i, "admin-down"))
4547 admin_up = 0;
4548 else if (unformat (i, "link-up"))
4549 link_up = 1;
4550 else if (unformat (i, "link-down"))
4551 link_up = 0;
4552 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4553 sw_if_index_set = 1;
4554 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4555 sw_if_index_set = 1;
4556 else
4557 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004558 }
4559
Dave Barach72d72232016-08-04 10:15:08 -04004560 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004561 {
Dave Barach72d72232016-08-04 10:15:08 -04004562 errmsg ("missing interface name or sw_if_index\n");
4563 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004564 }
4565
Dave Barach72d72232016-08-04 10:15:08 -04004566 /* Construct the API message */
4567 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4568 mp->sw_if_index = ntohl (sw_if_index);
4569 mp->admin_up_down = admin_up;
4570 mp->link_up_down = link_up;
4571
4572 /* send it... */
4573 S;
4574
4575 /* Wait for a reply, return the good/bad news... */
4576 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004577}
4578
Dave Barach72d72232016-08-04 10:15:08 -04004579static int
4580api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004581{
Dave Barach72d72232016-08-04 10:15:08 -04004582 unformat_input_t *i = vam->input;
4583 vl_api_sw_interface_clear_stats_t *mp;
4584 f64 timeout;
4585 u32 sw_if_index;
4586 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004587
Dave Barach72d72232016-08-04 10:15:08 -04004588 /* Parse args required to build the message */
4589 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4590 {
4591 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4592 sw_if_index_set = 1;
4593 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4594 sw_if_index_set = 1;
4595 else
4596 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004597 }
4598
Dave Barach72d72232016-08-04 10:15:08 -04004599 /* Construct the API message */
4600 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004601
Dave Barach72d72232016-08-04 10:15:08 -04004602 if (sw_if_index_set == 1)
4603 mp->sw_if_index = ntohl (sw_if_index);
4604 else
4605 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004606
Dave Barach72d72232016-08-04 10:15:08 -04004607 /* send it... */
4608 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004609
Dave Barach72d72232016-08-04 10:15:08 -04004610 /* Wait for a reply, return the good/bad news... */
4611 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004612}
4613
Dave Barach72d72232016-08-04 10:15:08 -04004614static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004615api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4616{
4617 unformat_input_t *i = vam->input;
4618 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4619 f64 timeout;
4620 u32 sw_if_index;
4621 u8 sw_if_index_set = 0;
4622 u32 subport;
4623 u8 subport_set = 0;
4624 u32 pipe;
4625 u8 pipe_set = 0;
4626 u32 profile;
4627 u8 profile_set = 0;
4628
4629 /* Parse args required to build the message */
4630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4631 {
4632 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4633 sw_if_index_set = 1;
4634 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4635 sw_if_index_set = 1;
4636 else if (unformat (i, "subport %u", &subport))
4637 subport_set = 1;
4638 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4639 sw_if_index_set = 1;
4640 else if (unformat (i, "pipe %u", &pipe))
4641 pipe_set = 1;
4642 else if (unformat (i, "profile %u", &profile))
4643 profile_set = 1;
4644 else
4645 break;
4646 }
4647
4648 if (sw_if_index_set == 0)
4649 {
4650 errmsg ("missing interface name or sw_if_index\n");
4651 return -99;
4652 }
4653
4654 if (subport_set == 0)
4655 {
4656 errmsg ("missing subport \n");
4657 return -99;
4658 }
4659
4660 if (pipe_set == 0)
4661 {
4662 errmsg ("missing pipe\n");
4663 return -99;
4664 }
4665
4666 if (profile_set == 0)
4667 {
4668 errmsg ("missing profile\n");
4669 return -99;
4670 }
4671
4672 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4673
4674 mp->sw_if_index = ntohl (sw_if_index);
4675 mp->subport = ntohl (subport);
4676 mp->pipe = ntohl (pipe);
4677 mp->profile = ntohl (profile);
4678
4679
4680 S;
4681 W;
4682 /* NOTREACHED */
4683 return 0;
4684}
4685
4686static int
4687api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4688{
4689 unformat_input_t *i = vam->input;
4690 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4691 f64 timeout;
4692 u32 sw_if_index;
4693 u8 sw_if_index_set = 0;
4694 u32 subport;
4695 u8 subport_set = 0;
4696 u32 tb_rate = 1250000000; /* 10GbE */
4697 u32 tb_size = 1000000;
4698 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4699 u32 tc_period = 10;
4700
4701 /* Parse args required to build the message */
4702 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4703 {
4704 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4705 sw_if_index_set = 1;
4706 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4707 sw_if_index_set = 1;
4708 else if (unformat (i, "subport %u", &subport))
4709 subport_set = 1;
4710 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4711 sw_if_index_set = 1;
4712 else if (unformat (i, "rate %u", &tb_rate))
4713 {
4714 u32 tc_id;
4715
4716 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4717 tc_id++)
4718 tc_rate[tc_id] = tb_rate;
4719 }
4720 else if (unformat (i, "bktsize %u", &tb_size))
4721 ;
4722 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4723 ;
4724 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4725 ;
4726 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4727 ;
4728 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4729 ;
4730 else if (unformat (i, "period %u", &tc_period))
4731 ;
4732 else
4733 break;
4734 }
4735
4736 if (sw_if_index_set == 0)
4737 {
4738 errmsg ("missing interface name or sw_if_index\n");
4739 return -99;
4740 }
4741
4742 if (subport_set == 0)
4743 {
4744 errmsg ("missing subport \n");
4745 return -99;
4746 }
4747
4748 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4749
4750 mp->sw_if_index = ntohl (sw_if_index);
4751 mp->subport = ntohl (subport);
4752 mp->tb_rate = ntohl (tb_rate);
4753 mp->tb_size = ntohl (tb_size);
4754 mp->tc_rate[0] = ntohl (tc_rate[0]);
4755 mp->tc_rate[1] = ntohl (tc_rate[1]);
4756 mp->tc_rate[2] = ntohl (tc_rate[2]);
4757 mp->tc_rate[3] = ntohl (tc_rate[3]);
4758 mp->tc_period = ntohl (tc_period);
4759
4760 S;
4761 W;
4762 /* NOTREACHED */
4763 return 0;
4764}
4765
4766static int
4767api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4768{
4769 unformat_input_t *i = vam->input;
4770 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4771 f64 timeout;
4772 u32 sw_if_index;
4773 u8 sw_if_index_set = 0;
4774 u8 entry_set = 0;
4775 u8 tc_set = 0;
4776 u8 queue_set = 0;
4777 u32 entry, tc, queue;
4778
4779 /* Parse args required to build the message */
4780 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4781 {
4782 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4783 sw_if_index_set = 1;
4784 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4785 sw_if_index_set = 1;
4786 else if (unformat (i, "entry %d", &entry))
4787 entry_set = 1;
4788 else if (unformat (i, "tc %d", &tc))
4789 tc_set = 1;
4790 else if (unformat (i, "queue %d", &queue))
4791 queue_set = 1;
4792 else
4793 break;
4794 }
4795
4796 if (sw_if_index_set == 0)
4797 {
4798 errmsg ("missing interface name or sw_if_index\n");
4799 return -99;
4800 }
4801
4802 if (entry_set == 0)
4803 {
4804 errmsg ("missing entry \n");
4805 return -99;
4806 }
4807
4808 if (tc_set == 0)
4809 {
4810 errmsg ("missing traffic class \n");
4811 return -99;
4812 }
4813
4814 if (queue_set == 0)
4815 {
4816 errmsg ("missing queue \n");
4817 return -99;
4818 }
4819
4820 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4821
4822 mp->sw_if_index = ntohl (sw_if_index);
4823 mp->entry = ntohl (entry);
4824 mp->tc = ntohl (tc);
4825 mp->queue = ntohl (queue);
4826
4827 S;
4828 W;
4829 /* NOTREACHED */
4830 return 0;
4831}
4832
4833static int
Dave Barach72d72232016-08-04 10:15:08 -04004834api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004835{
Dave Barach72d72232016-08-04 10:15:08 -04004836 unformat_input_t *i = vam->input;
4837 vl_api_sw_interface_add_del_address_t *mp;
4838 f64 timeout;
4839 u32 sw_if_index;
4840 u8 sw_if_index_set = 0;
4841 u8 is_add = 1, del_all = 0;
4842 u32 address_length = 0;
4843 u8 v4_address_set = 0;
4844 u8 v6_address_set = 0;
4845 ip4_address_t v4address;
4846 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004847
Dave Barach72d72232016-08-04 10:15:08 -04004848 /* Parse args required to build the message */
4849 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4850 {
4851 if (unformat (i, "del-all"))
4852 del_all = 1;
4853 else if (unformat (i, "del"))
4854 is_add = 0;
4855 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4856 sw_if_index_set = 1;
4857 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4858 sw_if_index_set = 1;
4859 else if (unformat (i, "%U/%d",
4860 unformat_ip4_address, &v4address, &address_length))
4861 v4_address_set = 1;
4862 else if (unformat (i, "%U/%d",
4863 unformat_ip6_address, &v6address, &address_length))
4864 v6_address_set = 1;
4865 else
4866 break;
4867 }
4868
4869 if (sw_if_index_set == 0)
4870 {
4871 errmsg ("missing interface name or sw_if_index\n");
4872 return -99;
4873 }
4874 if (v4_address_set && v6_address_set)
4875 {
4876 errmsg ("both v4 and v6 addresses set\n");
4877 return -99;
4878 }
4879 if (!v4_address_set && !v6_address_set && !del_all)
4880 {
4881 errmsg ("no addresses set\n");
4882 return -99;
4883 }
4884
4885 /* Construct the API message */
4886 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4887
4888 mp->sw_if_index = ntohl (sw_if_index);
4889 mp->is_add = is_add;
4890 mp->del_all = del_all;
4891 if (v6_address_set)
4892 {
4893 mp->is_ipv6 = 1;
4894 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4895 }
4896 else
4897 {
4898 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4899 }
4900 mp->address_length = address_length;
4901
4902 /* send it... */
4903 S;
4904
4905 /* Wait for a reply, return good/bad news */
4906 W;
4907}
4908
4909static int
John Lo06b14b92016-10-24 20:20:11 -04004910api_sw_interface_set_mpls_enable (vat_main_t * vam)
4911{
4912 unformat_input_t *i = vam->input;
4913 vl_api_sw_interface_set_mpls_enable_t *mp;
4914 f64 timeout;
4915 u32 sw_if_index;
4916 u8 sw_if_index_set = 0;
4917 u8 enable = 1;
4918
4919 /* Parse args required to build the message */
4920 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4921 {
4922 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4923 sw_if_index_set = 1;
4924 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4925 sw_if_index_set = 1;
4926 else if (unformat (i, "disable"))
4927 enable = 0;
4928 else if (unformat (i, "dis"))
4929 enable = 0;
4930 else
4931 break;
4932 }
4933
4934 if (sw_if_index_set == 0)
4935 {
4936 errmsg ("missing interface name or sw_if_index\n");
4937 return -99;
4938 }
4939
4940 /* Construct the API message */
4941 M (SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable);
4942
4943 mp->sw_if_index = ntohl (sw_if_index);
4944 mp->enable = enable;
4945
4946 /* send it... */
4947 S;
4948
4949 /* Wait for a reply... */
4950 W;
4951}
4952
4953static int
Dave Barach72d72232016-08-04 10:15:08 -04004954api_sw_interface_set_table (vat_main_t * vam)
4955{
4956 unformat_input_t *i = vam->input;
4957 vl_api_sw_interface_set_table_t *mp;
4958 f64 timeout;
4959 u32 sw_if_index, vrf_id = 0;
4960 u8 sw_if_index_set = 0;
4961 u8 is_ipv6 = 0;
4962
4963 /* Parse args required to build the message */
4964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4965 {
4966 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4967 sw_if_index_set = 1;
4968 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4969 sw_if_index_set = 1;
4970 else if (unformat (i, "vrf %d", &vrf_id))
4971 ;
4972 else if (unformat (i, "ipv6"))
4973 is_ipv6 = 1;
4974 else
4975 break;
4976 }
4977
4978 if (sw_if_index_set == 0)
4979 {
4980 errmsg ("missing interface name or sw_if_index\n");
4981 return -99;
4982 }
4983
4984 /* Construct the API message */
4985 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4986
4987 mp->sw_if_index = ntohl (sw_if_index);
4988 mp->is_ipv6 = is_ipv6;
4989 mp->vrf_id = ntohl (vrf_id);
4990
4991 /* send it... */
4992 S;
4993
4994 /* Wait for a reply... */
4995 W;
4996}
4997
4998static int
4999api_sw_interface_set_vpath (vat_main_t * vam)
5000{
5001 unformat_input_t *i = vam->input;
5002 vl_api_sw_interface_set_vpath_t *mp;
5003 f64 timeout;
5004 u32 sw_if_index = 0;
5005 u8 sw_if_index_set = 0;
5006 u8 is_enable = 0;
5007
5008 /* Parse args required to build the message */
5009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5010 {
5011 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5012 sw_if_index_set = 1;
5013 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5014 sw_if_index_set = 1;
5015 else if (unformat (i, "enable"))
5016 is_enable = 1;
5017 else if (unformat (i, "disable"))
5018 is_enable = 0;
5019 else
5020 break;
5021 }
5022
5023 if (sw_if_index_set == 0)
5024 {
5025 errmsg ("missing interface name or sw_if_index\n");
5026 return -99;
5027 }
5028
5029 /* Construct the API message */
5030 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
5031
5032 mp->sw_if_index = ntohl (sw_if_index);
5033 mp->enable = is_enable;
5034
5035 /* send it... */
5036 S;
5037
5038 /* Wait for a reply... */
5039 W;
5040}
5041
5042static int
5043api_sw_interface_set_l2_xconnect (vat_main_t * vam)
5044{
5045 unformat_input_t *i = vam->input;
5046 vl_api_sw_interface_set_l2_xconnect_t *mp;
5047 f64 timeout;
5048 u32 rx_sw_if_index;
5049 u8 rx_sw_if_index_set = 0;
5050 u32 tx_sw_if_index;
5051 u8 tx_sw_if_index_set = 0;
5052 u8 enable = 1;
5053
5054 /* Parse args required to build the message */
5055 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5056 {
5057 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5058 rx_sw_if_index_set = 1;
5059 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5060 tx_sw_if_index_set = 1;
5061 else if (unformat (i, "rx"))
5062 {
5063 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5064 {
5065 if (unformat (i, "%U", unformat_sw_if_index, vam,
5066 &rx_sw_if_index))
5067 rx_sw_if_index_set = 1;
5068 }
5069 else
Dave Barach41da02d2016-07-11 16:48:42 -07005070 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005071 }
Dave Barach72d72232016-08-04 10:15:08 -04005072 else if (unformat (i, "tx"))
5073 {
5074 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5075 {
5076 if (unformat (i, "%U", unformat_sw_if_index, vam,
5077 &tx_sw_if_index))
5078 tx_sw_if_index_set = 1;
5079 }
5080 else
5081 break;
5082 }
5083 else if (unformat (i, "enable"))
5084 enable = 1;
5085 else if (unformat (i, "disable"))
5086 enable = 0;
5087 else
5088 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005089 }
5090
Dave Barach72d72232016-08-04 10:15:08 -04005091 if (rx_sw_if_index_set == 0)
5092 {
5093 errmsg ("missing rx interface name or rx_sw_if_index\n");
5094 return -99;
5095 }
Dave Barach41da02d2016-07-11 16:48:42 -07005096
Dave Barach72d72232016-08-04 10:15:08 -04005097 if (enable && (tx_sw_if_index_set == 0))
5098 {
5099 errmsg ("missing tx interface name or tx_sw_if_index\n");
5100 return -99;
5101 }
Dave Barach41da02d2016-07-11 16:48:42 -07005102
Dave Barach72d72232016-08-04 10:15:08 -04005103 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07005104
Dave Barach72d72232016-08-04 10:15:08 -04005105 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5106 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5107 mp->enable = enable;
5108
5109 S;
5110 W;
5111 /* NOTREACHED */
5112 return 0;
5113}
5114
5115static int
5116api_sw_interface_set_l2_bridge (vat_main_t * vam)
5117{
5118 unformat_input_t *i = vam->input;
5119 vl_api_sw_interface_set_l2_bridge_t *mp;
5120 f64 timeout;
5121 u32 rx_sw_if_index;
5122 u8 rx_sw_if_index_set = 0;
5123 u32 bd_id;
5124 u8 bd_id_set = 0;
5125 u8 bvi = 0;
5126 u32 shg = 0;
5127 u8 enable = 1;
5128
5129 /* Parse args required to build the message */
5130 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5131 {
5132 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
5133 rx_sw_if_index_set = 1;
5134 else if (unformat (i, "bd_id %d", &bd_id))
5135 bd_id_set = 1;
5136 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
5137 rx_sw_if_index_set = 1;
5138 else if (unformat (i, "shg %d", &shg))
5139 ;
5140 else if (unformat (i, "bvi"))
5141 bvi = 1;
5142 else if (unformat (i, "enable"))
5143 enable = 1;
5144 else if (unformat (i, "disable"))
5145 enable = 0;
5146 else
5147 break;
5148 }
5149
5150 if (rx_sw_if_index_set == 0)
5151 {
5152 errmsg ("missing rx interface name or sw_if_index\n");
5153 return -99;
5154 }
5155
5156 if (enable && (bd_id_set == 0))
5157 {
5158 errmsg ("missing bridge domain\n");
5159 return -99;
5160 }
5161
5162 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5163
5164 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5165 mp->bd_id = ntohl (bd_id);
5166 mp->shg = (u8) shg;
5167 mp->bvi = bvi;
5168 mp->enable = enable;
5169
5170 S;
5171 W;
5172 /* NOTREACHED */
5173 return 0;
5174}
5175
5176static int
5177api_bridge_domain_dump (vat_main_t * vam)
5178{
5179 unformat_input_t *i = vam->input;
5180 vl_api_bridge_domain_dump_t *mp;
5181 f64 timeout;
5182 u32 bd_id = ~0;
5183
5184 /* Parse args required to build the message */
5185 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5186 {
5187 if (unformat (i, "bd_id %d", &bd_id))
5188 ;
5189 else
5190 break;
5191 }
5192
5193 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5194 mp->bd_id = ntohl (bd_id);
5195 S;
5196
5197 /* Use a control ping for synchronization */
5198 {
5199 vl_api_control_ping_t *mp;
5200 M (CONTROL_PING, control_ping);
5201 S;
5202 }
5203
5204 W;
5205 /* NOTREACHED */
5206 return 0;
5207}
5208
5209static int
5210api_bridge_domain_add_del (vat_main_t * vam)
5211{
5212 unformat_input_t *i = vam->input;
5213 vl_api_bridge_domain_add_del_t *mp;
5214 f64 timeout;
5215 u32 bd_id = ~0;
5216 u8 is_add = 1;
5217 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5218
5219 /* Parse args required to build the message */
5220 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5221 {
5222 if (unformat (i, "bd_id %d", &bd_id))
5223 ;
5224 else if (unformat (i, "flood %d", &flood))
5225 ;
5226 else if (unformat (i, "uu-flood %d", &uu_flood))
5227 ;
5228 else if (unformat (i, "forward %d", &forward))
5229 ;
5230 else if (unformat (i, "learn %d", &learn))
5231 ;
5232 else if (unformat (i, "arp-term %d", &arp_term))
5233 ;
5234 else if (unformat (i, "del"))
5235 {
5236 is_add = 0;
5237 flood = uu_flood = forward = learn = 0;
5238 }
5239 else
5240 break;
5241 }
5242
5243 if (bd_id == ~0)
5244 {
5245 errmsg ("missing bridge domain\n");
5246 return -99;
5247 }
5248
5249 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5250
5251 mp->bd_id = ntohl (bd_id);
5252 mp->flood = flood;
5253 mp->uu_flood = uu_flood;
5254 mp->forward = forward;
5255 mp->learn = learn;
5256 mp->arp_term = arp_term;
5257 mp->is_add = is_add;
5258
5259 S;
5260 W;
5261 /* NOTREACHED */
5262 return 0;
5263}
5264
5265static int
5266api_l2fib_add_del (vat_main_t * vam)
5267{
5268 unformat_input_t *i = vam->input;
5269 vl_api_l2fib_add_del_t *mp;
5270 f64 timeout;
5271 u64 mac = 0;
5272 u8 mac_set = 0;
5273 u32 bd_id;
5274 u8 bd_id_set = 0;
5275 u32 sw_if_index;
5276 u8 sw_if_index_set = 0;
5277 u8 is_add = 1;
5278 u8 static_mac = 0;
5279 u8 filter_mac = 0;
5280 u8 bvi_mac = 0;
5281 int count = 1;
5282 f64 before = 0;
5283 int j;
5284
5285 /* Parse args required to build the message */
5286 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5287 {
5288 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5289 mac_set = 1;
5290 else if (unformat (i, "bd_id %d", &bd_id))
5291 bd_id_set = 1;
5292 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5293 sw_if_index_set = 1;
5294 else if (unformat (i, "sw_if"))
5295 {
5296 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5297 {
5298 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5299 sw_if_index_set = 1;
5300 }
5301 else
5302 break;
5303 }
5304 else if (unformat (i, "static"))
5305 static_mac = 1;
5306 else if (unformat (i, "filter"))
5307 {
5308 filter_mac = 1;
5309 static_mac = 1;
5310 }
5311 else if (unformat (i, "bvi"))
5312 {
5313 bvi_mac = 1;
5314 static_mac = 1;
5315 }
5316 else if (unformat (i, "del"))
5317 is_add = 0;
5318 else if (unformat (i, "count %d", &count))
5319 ;
5320 else
5321 break;
5322 }
5323
5324 if (mac_set == 0)
5325 {
5326 errmsg ("missing mac address\n");
5327 return -99;
5328 }
5329
5330 if (bd_id_set == 0)
5331 {
5332 errmsg ("missing bridge domain\n");
5333 return -99;
5334 }
5335
5336 if (is_add && (sw_if_index_set == 0))
5337 {
5338 errmsg ("missing interface name or sw_if_index\n");
5339 return -99;
5340 }
5341
5342 if (count > 1)
5343 {
5344 /* Turn on async mode */
5345 vam->async_mode = 1;
5346 vam->async_errors = 0;
5347 before = vat_time_now (vam);
5348 }
5349
5350 for (j = 0; j < count; j++)
5351 {
5352 M (L2FIB_ADD_DEL, l2fib_add_del);
5353
5354 mp->mac = mac;
5355 mp->bd_id = ntohl (bd_id);
5356 mp->is_add = is_add;
5357
5358 if (is_add)
5359 {
5360 mp->sw_if_index = ntohl (sw_if_index);
5361 mp->static_mac = static_mac;
5362 mp->filter_mac = filter_mac;
5363 mp->bvi_mac = bvi_mac;
5364 }
5365 increment_mac_address (&mac);
5366 /* send it... */
5367 S;
5368 }
5369
5370 if (count > 1)
5371 {
5372 vl_api_control_ping_t *mp;
5373 f64 after;
5374
5375 /* Shut off async mode */
5376 vam->async_mode = 0;
5377
5378 M (CONTROL_PING, control_ping);
5379 S;
5380
5381 timeout = vat_time_now (vam) + 1.0;
5382 while (vat_time_now (vam) < timeout)
5383 if (vam->result_ready == 1)
5384 goto out;
5385 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005386
5387 out:
Dave Barach72d72232016-08-04 10:15:08 -04005388 if (vam->retval == -99)
5389 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005390
Dave Barach72d72232016-08-04 10:15:08 -04005391 if (vam->async_errors > 0)
5392 {
5393 errmsg ("%d asynchronous errors\n", vam->async_errors);
5394 vam->retval = -98;
5395 }
5396 vam->async_errors = 0;
5397 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005398
Dave Barach72d72232016-08-04 10:15:08 -04005399 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5400 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005401 }
Dave Barach72d72232016-08-04 10:15:08 -04005402 else
5403 {
5404 /* Wait for a reply... */
5405 W;
5406 }
5407 /* Return the good/bad news */
5408 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005409}
5410
Dave Barach72d72232016-08-04 10:15:08 -04005411static int
5412api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005413{
Dave Barach72d72232016-08-04 10:15:08 -04005414 unformat_input_t *i = vam->input;
5415 vl_api_l2_flags_t *mp;
5416 f64 timeout;
5417 u32 sw_if_index;
5418 u32 feature_bitmap = 0;
5419 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005420
Dave Barach72d72232016-08-04 10:15:08 -04005421 /* Parse args required to build the message */
5422 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5423 {
5424 if (unformat (i, "sw_if_index %d", &sw_if_index))
5425 sw_if_index_set = 1;
5426 else if (unformat (i, "sw_if"))
5427 {
5428 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5429 {
5430 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5431 sw_if_index_set = 1;
5432 }
5433 else
5434 break;
5435 }
5436 else if (unformat (i, "learn"))
5437 feature_bitmap |= L2INPUT_FEAT_LEARN;
5438 else if (unformat (i, "forward"))
5439 feature_bitmap |= L2INPUT_FEAT_FWD;
5440 else if (unformat (i, "flood"))
5441 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5442 else if (unformat (i, "uu-flood"))
5443 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5444 else
5445 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005446 }
5447
Dave Barach72d72232016-08-04 10:15:08 -04005448 if (sw_if_index_set == 0)
5449 {
5450 errmsg ("missing interface name or sw_if_index\n");
5451 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005452 }
5453
Dave Barach72d72232016-08-04 10:15:08 -04005454 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005455
Dave Barach72d72232016-08-04 10:15:08 -04005456 mp->sw_if_index = ntohl (sw_if_index);
5457 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005458
Dave Barach72d72232016-08-04 10:15:08 -04005459 S;
5460 W;
5461 /* NOTREACHED */
5462 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005463}
5464
Dave Barach72d72232016-08-04 10:15:08 -04005465static int
5466api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005467{
Dave Barach72d72232016-08-04 10:15:08 -04005468 unformat_input_t *i = vam->input;
5469 vl_api_bridge_flags_t *mp;
5470 f64 timeout;
5471 u32 bd_id;
5472 u8 bd_id_set = 0;
5473 u8 is_set = 1;
5474 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005475
Dave Barach72d72232016-08-04 10:15:08 -04005476 /* Parse args required to build the message */
5477 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5478 {
5479 if (unformat (i, "bd_id %d", &bd_id))
5480 bd_id_set = 1;
5481 else if (unformat (i, "learn"))
5482 flags |= L2_LEARN;
5483 else if (unformat (i, "forward"))
5484 flags |= L2_FWD;
5485 else if (unformat (i, "flood"))
5486 flags |= L2_FLOOD;
5487 else if (unformat (i, "uu-flood"))
5488 flags |= L2_UU_FLOOD;
5489 else if (unformat (i, "arp-term"))
5490 flags |= L2_ARP_TERM;
5491 else if (unformat (i, "off"))
5492 is_set = 0;
5493 else if (unformat (i, "disable"))
5494 is_set = 0;
5495 else
5496 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005497 }
5498
Dave Barach72d72232016-08-04 10:15:08 -04005499 if (bd_id_set == 0)
5500 {
5501 errmsg ("missing bridge domain\n");
5502 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005503 }
5504
Dave Barach72d72232016-08-04 10:15:08 -04005505 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005506
Dave Barach72d72232016-08-04 10:15:08 -04005507 mp->bd_id = ntohl (bd_id);
5508 mp->feature_bitmap = ntohl (flags);
5509 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005510
Dave Barach72d72232016-08-04 10:15:08 -04005511 S;
5512 W;
5513 /* NOTREACHED */
5514 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005515}
5516
Dave Barach72d72232016-08-04 10:15:08 -04005517static int
5518api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005519{
Dave Barach72d72232016-08-04 10:15:08 -04005520 unformat_input_t *i = vam->input;
5521 vl_api_bd_ip_mac_add_del_t *mp;
5522 f64 timeout;
5523 u32 bd_id;
5524 u8 is_ipv6 = 0;
5525 u8 is_add = 1;
5526 u8 bd_id_set = 0;
5527 u8 ip_set = 0;
5528 u8 mac_set = 0;
5529 ip4_address_t v4addr;
5530 ip6_address_t v6addr;
5531 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005532
Ed Warnickecb9cada2015-12-08 15:45:58 -07005533
Dave Barach72d72232016-08-04 10:15:08 -04005534 /* Parse args required to build the message */
5535 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5536 {
5537 if (unformat (i, "bd_id %d", &bd_id))
5538 {
5539 bd_id_set++;
5540 }
5541 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5542 {
5543 ip_set++;
5544 }
5545 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5546 {
5547 ip_set++;
5548 is_ipv6++;
5549 }
5550 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5551 {
5552 mac_set++;
5553 }
5554 else if (unformat (i, "del"))
5555 is_add = 0;
5556 else
5557 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005558 }
5559
Dave Barach72d72232016-08-04 10:15:08 -04005560 if (bd_id_set == 0)
5561 {
5562 errmsg ("missing bridge domain\n");
5563 return -99;
5564 }
5565 else if (ip_set == 0)
5566 {
5567 errmsg ("missing IP address\n");
5568 return -99;
5569 }
5570 else if (mac_set == 0)
5571 {
5572 errmsg ("missing MAC address\n");
5573 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005574 }
5575
Dave Barach72d72232016-08-04 10:15:08 -04005576 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005577
Dave Barach72d72232016-08-04 10:15:08 -04005578 mp->bd_id = ntohl (bd_id);
5579 mp->is_ipv6 = is_ipv6;
5580 mp->is_add = is_add;
5581 if (is_ipv6)
5582 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5583 else
5584 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5585 clib_memcpy (mp->mac_address, macaddr, 6);
5586 S;
5587 W;
5588 /* NOTREACHED */
5589 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005590}
5591
Dave Barach72d72232016-08-04 10:15:08 -04005592static int
5593api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005594{
Dave Barach72d72232016-08-04 10:15:08 -04005595 unformat_input_t *i = vam->input;
5596 vl_api_tap_connect_t *mp;
5597 f64 timeout;
5598 u8 mac_address[6];
5599 u8 random_mac = 1;
5600 u8 name_set = 0;
5601 u8 *tap_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005602
Dave Barach72d72232016-08-04 10:15:08 -04005603 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005604
Dave Barach72d72232016-08-04 10:15:08 -04005605 /* Parse args required to build the message */
5606 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5607 {
5608 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5609 {
5610 random_mac = 0;
5611 }
5612 else if (unformat (i, "random-mac"))
5613 random_mac = 1;
5614 else if (unformat (i, "tapname %s", &tap_name))
5615 name_set = 1;
5616 else
5617 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005618 }
5619
Dave Barach72d72232016-08-04 10:15:08 -04005620 if (name_set == 0)
5621 {
5622 errmsg ("missing tap name\n");
5623 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005624 }
Dave Barach72d72232016-08-04 10:15:08 -04005625 if (vec_len (tap_name) > 63)
5626 {
5627 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005628 }
Dave Barach72d72232016-08-04 10:15:08 -04005629 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005630
Dave Barach72d72232016-08-04 10:15:08 -04005631 /* Construct the API message */
5632 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005633
Dave Barach72d72232016-08-04 10:15:08 -04005634 mp->use_random_mac = random_mac;
5635 clib_memcpy (mp->mac_address, mac_address, 6);
5636 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5637 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005638
Dave Barach72d72232016-08-04 10:15:08 -04005639 /* send it... */
5640 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005641
Dave Barach72d72232016-08-04 10:15:08 -04005642 /* Wait for a reply... */
5643 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005644}
5645
Dave Barach72d72232016-08-04 10:15:08 -04005646static int
5647api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005648{
Dave Barach72d72232016-08-04 10:15:08 -04005649 unformat_input_t *i = vam->input;
5650 vl_api_tap_modify_t *mp;
5651 f64 timeout;
5652 u8 mac_address[6];
5653 u8 random_mac = 1;
5654 u8 name_set = 0;
5655 u8 *tap_name;
5656 u32 sw_if_index = ~0;
5657 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005658
Dave Barach72d72232016-08-04 10:15:08 -04005659 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005660
Dave Barach72d72232016-08-04 10:15:08 -04005661 /* Parse args required to build the message */
5662 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5663 {
5664 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5665 sw_if_index_set = 1;
5666 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5667 sw_if_index_set = 1;
5668 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5669 {
5670 random_mac = 0;
5671 }
5672 else if (unformat (i, "random-mac"))
5673 random_mac = 1;
5674 else if (unformat (i, "tapname %s", &tap_name))
5675 name_set = 1;
5676 else
5677 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005678 }
5679
Dave Barach72d72232016-08-04 10:15:08 -04005680 if (sw_if_index_set == 0)
5681 {
5682 errmsg ("missing vpp interface name");
5683 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005684 }
Dave Barach72d72232016-08-04 10:15:08 -04005685 if (name_set == 0)
5686 {
5687 errmsg ("missing tap name\n");
5688 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005689 }
Dave Barach72d72232016-08-04 10:15:08 -04005690 if (vec_len (tap_name) > 63)
5691 {
5692 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005693 }
Dave Barach72d72232016-08-04 10:15:08 -04005694 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005695
Dave Barach72d72232016-08-04 10:15:08 -04005696 /* Construct the API message */
5697 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005698
Dave Barach72d72232016-08-04 10:15:08 -04005699 mp->use_random_mac = random_mac;
5700 mp->sw_if_index = ntohl (sw_if_index);
5701 clib_memcpy (mp->mac_address, mac_address, 6);
5702 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5703 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005704
Dave Barach72d72232016-08-04 10:15:08 -04005705 /* send it... */
5706 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005707
Dave Barach72d72232016-08-04 10:15:08 -04005708 /* Wait for a reply... */
5709 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005710}
5711
Dave Barach72d72232016-08-04 10:15:08 -04005712static int
5713api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005714{
Dave Barach72d72232016-08-04 10:15:08 -04005715 unformat_input_t *i = vam->input;
5716 vl_api_tap_delete_t *mp;
5717 f64 timeout;
5718 u32 sw_if_index = ~0;
5719 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005720
Dave Barach72d72232016-08-04 10:15:08 -04005721 /* Parse args required to build the message */
5722 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5723 {
5724 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5725 sw_if_index_set = 1;
5726 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5727 sw_if_index_set = 1;
5728 else
5729 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005730 }
5731
Dave Barach72d72232016-08-04 10:15:08 -04005732 if (sw_if_index_set == 0)
5733 {
5734 errmsg ("missing vpp interface name");
5735 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005736 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005737
Dave Barach72d72232016-08-04 10:15:08 -04005738 /* Construct the API message */
5739 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005740
Dave Barach72d72232016-08-04 10:15:08 -04005741 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005742
Dave Barach72d72232016-08-04 10:15:08 -04005743 /* send it... */
5744 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005745
Dave Barach72d72232016-08-04 10:15:08 -04005746 /* Wait for a reply... */
5747 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005748}
5749
Dave Barach72d72232016-08-04 10:15:08 -04005750static int
5751api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005752{
Dave Barach72d72232016-08-04 10:15:08 -04005753 unformat_input_t *i = vam->input;
5754 vl_api_ip_add_del_route_t *mp;
5755 f64 timeout;
5756 u32 sw_if_index = ~0, vrf_id = 0;
5757 u8 sw_if_index_set = 0;
5758 u8 is_ipv6 = 0;
5759 u8 is_local = 0, is_drop = 0;
5760 u8 create_vrf_if_needed = 0;
5761 u8 is_add = 1;
5762 u8 next_hop_weight = 1;
5763 u8 not_last = 0;
5764 u8 is_multipath = 0;
5765 u8 address_set = 0;
5766 u8 address_length_set = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005767 u32 next_hop_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005768 u32 resolve_attempts = 0;
5769 u32 dst_address_length = 0;
5770 u8 next_hop_set = 0;
5771 ip4_address_t v4_dst_address, v4_next_hop_address;
5772 ip6_address_t v6_dst_address, v6_next_hop_address;
5773 int count = 1;
5774 int j;
5775 f64 before = 0;
5776 u32 random_add_del = 0;
5777 u32 *random_vector = 0;
5778 uword *random_hash;
5779 u32 random_seed = 0xdeaddabe;
5780 u32 classify_table_index = ~0;
5781 u8 is_classify = 0;
Neale Ranns33a7dd52016-10-07 15:14:33 +01005782 u8 resolve_host = 0, resolve_attached = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005783 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005784
Dave Barach72d72232016-08-04 10:15:08 -04005785 /* Parse args required to build the message */
5786 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5787 {
5788 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5789 sw_if_index_set = 1;
5790 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5791 sw_if_index_set = 1;
5792 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
5793 {
5794 address_set = 1;
5795 is_ipv6 = 0;
5796 }
5797 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
5798 {
5799 address_set = 1;
5800 is_ipv6 = 1;
5801 }
5802 else if (unformat (i, "/%d", &dst_address_length))
5803 {
5804 address_length_set = 1;
5805 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005806
Dave Barach72d72232016-08-04 10:15:08 -04005807 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
5808 &v4_next_hop_address))
5809 {
5810 next_hop_set = 1;
5811 }
5812 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
5813 &v6_next_hop_address))
5814 {
5815 next_hop_set = 1;
5816 }
5817 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5818 ;
5819 else if (unformat (i, "weight %d", &next_hop_weight))
5820 ;
5821 else if (unformat (i, "drop"))
5822 {
5823 is_drop = 1;
5824 }
5825 else if (unformat (i, "local"))
5826 {
5827 is_local = 1;
5828 }
5829 else if (unformat (i, "classify %d", &classify_table_index))
5830 {
5831 is_classify = 1;
5832 }
5833 else if (unformat (i, "del"))
5834 is_add = 0;
5835 else if (unformat (i, "add"))
5836 is_add = 1;
5837 else if (unformat (i, "not-last"))
5838 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005839 else if (unformat (i, "resolve-via-host"))
5840 resolve_host = 1;
5841 else if (unformat (i, "resolve-via-attached"))
5842 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005843 else if (unformat (i, "multipath"))
5844 is_multipath = 1;
5845 else if (unformat (i, "vrf %d", &vrf_id))
5846 ;
5847 else if (unformat (i, "create-vrf"))
5848 create_vrf_if_needed = 1;
5849 else if (unformat (i, "count %d", &count))
5850 ;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005851 else if (unformat (i, "lookup-in-vrf %d", &next_hop_table_id))
5852 ;
5853 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
5854 ;
5855 else if (unformat (i, "out-label %d", &next_hop_out_label))
Dave Barach72d72232016-08-04 10:15:08 -04005856 ;
5857 else if (unformat (i, "random"))
5858 random_add_del = 1;
5859 else if (unformat (i, "seed %d", &random_seed))
5860 ;
5861 else
5862 {
5863 clib_warning ("parse error '%U'", format_unformat_error, i);
5864 return -99;
5865 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005866 }
5867
Dave Barach72d72232016-08-04 10:15:08 -04005868 if (resolve_attempts > 0 && sw_if_index_set == 0)
5869 {
5870 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
5871 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005872 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005873
Dave Barach72d72232016-08-04 10:15:08 -04005874 if (!next_hop_set && !is_drop && !is_local && !is_classify)
5875 {
5876 errmsg ("next hop / local / drop / classify not set\n");
5877 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005878 }
5879
Dave Barach72d72232016-08-04 10:15:08 -04005880 if (address_set == 0)
5881 {
5882 errmsg ("missing addresses\n");
5883 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005884 }
5885
Dave Barach72d72232016-08-04 10:15:08 -04005886 if (address_length_set == 0)
5887 {
5888 errmsg ("missing address length\n");
5889 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005890 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005891
Dave Barach72d72232016-08-04 10:15:08 -04005892 /* Generate a pile of unique, random routes */
5893 if (random_add_del)
5894 {
5895 u32 this_random_address;
5896 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005897
Dave Barach72d72232016-08-04 10:15:08 -04005898 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
5899 for (j = 0; j <= count; j++)
5900 {
5901 do
5902 {
5903 this_random_address = random_u32 (&random_seed);
5904 this_random_address =
5905 clib_host_to_net_u32 (this_random_address);
5906 }
5907 while (hash_get (random_hash, this_random_address));
5908 vec_add1 (random_vector, this_random_address);
5909 hash_set (random_hash, this_random_address, 1);
5910 }
5911 hash_free (random_hash);
5912 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07005913 }
5914
Dave Barach72d72232016-08-04 10:15:08 -04005915 if (count > 1)
5916 {
5917 /* Turn on async mode */
5918 vam->async_mode = 1;
5919 vam->async_errors = 0;
5920 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005921 }
5922
Dave Barach72d72232016-08-04 10:15:08 -04005923 for (j = 0; j < count; j++)
5924 {
5925 /* Construct the API message */
5926 M (IP_ADD_DEL_ROUTE, ip_add_del_route);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005927
Dave Barach72d72232016-08-04 10:15:08 -04005928 mp->next_hop_sw_if_index = ntohl (sw_if_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07005929 mp->table_id = ntohl (vrf_id);
Dave Barach72d72232016-08-04 10:15:08 -04005930 if (resolve_attempts > 0)
5931 {
5932 mp->resolve_attempts = ntohl (resolve_attempts);
5933 mp->resolve_if_needed = 1;
5934 }
5935 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005936
Dave Barach72d72232016-08-04 10:15:08 -04005937 mp->is_add = is_add;
5938 mp->is_drop = is_drop;
5939 mp->is_ipv6 = is_ipv6;
5940 mp->is_local = is_local;
5941 mp->is_classify = is_classify;
5942 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005943 mp->is_resolve_host = resolve_host;
5944 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04005945 mp->not_last = not_last;
5946 mp->next_hop_weight = next_hop_weight;
5947 mp->dst_address_length = dst_address_length;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005948 mp->next_hop_table_id = ntohl (next_hop_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04005949 mp->classify_table_index = ntohl (classify_table_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07005950 mp->next_hop_out_label = ntohl (next_hop_out_label);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005951
Dave Barach72d72232016-08-04 10:15:08 -04005952 if (is_ipv6)
5953 {
5954 clib_memcpy (mp->dst_address, &v6_dst_address,
5955 sizeof (v6_dst_address));
5956 if (next_hop_set)
5957 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
5958 sizeof (v6_next_hop_address));
5959 increment_v6_address (&v6_dst_address);
5960 }
5961 else
5962 {
5963 clib_memcpy (mp->dst_address, &v4_dst_address,
5964 sizeof (v4_dst_address));
5965 if (next_hop_set)
5966 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
5967 sizeof (v4_next_hop_address));
5968 if (random_add_del)
5969 v4_dst_address.as_u32 = random_vector[j + 1];
5970 else
5971 increment_v4_address (&v4_dst_address);
5972 }
5973 /* send it... */
5974 S;
Dave Barach477570e2016-10-09 17:43:22 -04005975 /* If we receive SIGTERM, stop now... */
5976 if (vam->do_exit)
5977 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005978 }
5979
Dave Barach72d72232016-08-04 10:15:08 -04005980 /* When testing multiple add/del ops, use a control-ping to sync */
5981 if (count > 1)
5982 {
5983 vl_api_control_ping_t *mp;
5984 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005985
Dave Barach72d72232016-08-04 10:15:08 -04005986 /* Shut off async mode */
5987 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005988
Dave Barach72d72232016-08-04 10:15:08 -04005989 M (CONTROL_PING, control_ping);
5990 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005991
Dave Barach72d72232016-08-04 10:15:08 -04005992 timeout = vat_time_now (vam) + 1.0;
5993 while (vat_time_now (vam) < timeout)
5994 if (vam->result_ready == 1)
5995 goto out;
5996 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005997
5998 out:
Dave Barach72d72232016-08-04 10:15:08 -04005999 if (vam->retval == -99)
6000 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006001
Dave Barach72d72232016-08-04 10:15:08 -04006002 if (vam->async_errors > 0)
6003 {
6004 errmsg ("%d asynchronous errors\n", vam->async_errors);
6005 vam->retval = -98;
6006 }
6007 vam->async_errors = 0;
6008 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006009
Dave Barach477570e2016-10-09 17:43:22 -04006010 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6011 if (j > 0)
6012 count = j;
6013
Dave Barach72d72232016-08-04 10:15:08 -04006014 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6015 count, after - before, count / (after - before));
6016 }
6017 else
6018 {
6019 /* Wait for a reply... */
6020 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006021 }
6022
Dave Barach72d72232016-08-04 10:15:08 -04006023 /* Return the good/bad news */
6024 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006025}
6026
Dave Barach72d72232016-08-04 10:15:08 -04006027static int
Neale Ranns1357f3b2016-10-16 12:01:42 -07006028api_mpls_route_add_del (vat_main_t * vam)
6029{
6030 unformat_input_t *i = vam->input;
6031 vl_api_mpls_route_add_del_t *mp;
6032 f64 timeout;
6033 u32 sw_if_index = ~0, table_id = 0;
6034 u8 create_table_if_needed = 0;
6035 u8 is_add = 1;
6036 u8 next_hop_weight = 1;
6037 u8 is_multipath = 0;
6038 u32 next_hop_table_id = 0;
6039 u8 next_hop_set = 0;
6040 ip4_address_t v4_next_hop_address = {
6041 .as_u32 = 0,
6042 };
6043 ip6_address_t v6_next_hop_address = { {0} };
6044 int count = 1;
6045 int j;
6046 f64 before = 0;
6047 u32 classify_table_index = ~0;
6048 u8 is_classify = 0;
6049 u8 resolve_host = 0, resolve_attached = 0;
6050 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6051 mpls_label_t local_label = MPLS_LABEL_INVALID;
6052 u8 is_eos = 1;
6053 u8 next_hop_proto_is_ip4 = 1;
6054
6055 /* Parse args required to build the message */
6056 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6057 {
6058 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6059 ;
6060 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6061 ;
6062 else if (unformat (i, "%d", &local_label))
6063 ;
6064 else if (unformat (i, "eos"))
6065 is_eos = 1;
6066 else if (unformat (i, "non-eos"))
6067 is_eos = 0;
6068 else if (unformat (i, "via %U", unformat_ip4_address,
6069 &v4_next_hop_address))
6070 {
6071 next_hop_set = 1;
6072 next_hop_proto_is_ip4 = 1;
6073 }
6074 else if (unformat (i, "via %U", unformat_ip6_address,
6075 &v6_next_hop_address))
6076 {
6077 next_hop_set = 1;
6078 next_hop_proto_is_ip4 = 0;
6079 }
6080 else if (unformat (i, "weight %d", &next_hop_weight))
6081 ;
6082 else if (unformat (i, "create-table"))
6083 create_table_if_needed = 1;
6084 else if (unformat (i, "classify %d", &classify_table_index))
6085 {
6086 is_classify = 1;
6087 }
6088 else if (unformat (i, "del"))
6089 is_add = 0;
6090 else if (unformat (i, "add"))
6091 is_add = 1;
6092 else if (unformat (i, "resolve-via-host"))
6093 resolve_host = 1;
6094 else if (unformat (i, "resolve-via-attached"))
6095 resolve_attached = 1;
6096 else if (unformat (i, "multipath"))
6097 is_multipath = 1;
6098 else if (unformat (i, "count %d", &count))
6099 ;
6100 else if (unformat (i, "lookup-in-ip4-table %d", &next_hop_table_id))
6101 {
6102 next_hop_set = 1;
6103 next_hop_proto_is_ip4 = 1;
6104 }
6105 else if (unformat (i, "lookup-in-ip6-table %d", &next_hop_table_id))
6106 {
6107 next_hop_set = 1;
6108 next_hop_proto_is_ip4 = 0;
6109 }
6110 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6111 ;
6112 else if (unformat (i, "out-label %d", &next_hop_out_label))
6113 ;
6114 else
6115 {
6116 clib_warning ("parse error '%U'", format_unformat_error, i);
6117 return -99;
6118 }
6119 }
6120
6121 if (!next_hop_set && !is_classify)
6122 {
6123 errmsg ("next hop / classify not set\n");
6124 return -99;
6125 }
6126
6127 if (MPLS_LABEL_INVALID == local_label)
6128 {
6129 errmsg ("missing label\n");
6130 return -99;
6131 }
6132
6133 if (count > 1)
6134 {
6135 /* Turn on async mode */
6136 vam->async_mode = 1;
6137 vam->async_errors = 0;
6138 before = vat_time_now (vam);
6139 }
6140
6141 for (j = 0; j < count; j++)
6142 {
6143 /* Construct the API message */
6144 M (MPLS_ROUTE_ADD_DEL, mpls_route_add_del);
6145
6146 mp->mr_next_hop_sw_if_index = ntohl (sw_if_index);
6147 mp->mr_table_id = ntohl (table_id);
6148 mp->mr_create_table_if_needed = create_table_if_needed;
6149
6150 mp->mr_is_add = is_add;
6151 mp->mr_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6152 mp->mr_is_classify = is_classify;
6153 mp->mr_is_multipath = is_multipath;
6154 mp->mr_is_resolve_host = resolve_host;
6155 mp->mr_is_resolve_attached = resolve_attached;
6156 mp->mr_next_hop_weight = next_hop_weight;
6157 mp->mr_next_hop_table_id = ntohl (next_hop_table_id);
6158 mp->mr_classify_table_index = ntohl (classify_table_index);
6159 mp->mr_next_hop_out_label = ntohl (next_hop_out_label);
6160 mp->mr_label = ntohl (local_label);
6161 mp->mr_eos = is_eos;
6162
6163 if (next_hop_set)
6164 {
6165 if (next_hop_proto_is_ip4)
6166 {
6167 clib_memcpy (mp->mr_next_hop,
6168 &v4_next_hop_address,
6169 sizeof (v4_next_hop_address));
6170 }
6171 else
6172 {
6173 clib_memcpy (mp->mr_next_hop,
6174 &v6_next_hop_address,
6175 sizeof (v6_next_hop_address));
6176 }
6177 }
6178 local_label++;
6179
6180 /* send it... */
6181 S;
6182 /* If we receive SIGTERM, stop now... */
6183 if (vam->do_exit)
6184 break;
6185 }
6186
6187 /* When testing multiple add/del ops, use a control-ping to sync */
6188 if (count > 1)
6189 {
6190 vl_api_control_ping_t *mp;
6191 f64 after;
6192
6193 /* Shut off async mode */
6194 vam->async_mode = 0;
6195
6196 M (CONTROL_PING, control_ping);
6197 S;
6198
6199 timeout = vat_time_now (vam) + 1.0;
6200 while (vat_time_now (vam) < timeout)
6201 if (vam->result_ready == 1)
6202 goto out;
6203 vam->retval = -99;
6204
6205 out:
6206 if (vam->retval == -99)
6207 errmsg ("timeout\n");
6208
6209 if (vam->async_errors > 0)
6210 {
6211 errmsg ("%d asynchronous errors\n", vam->async_errors);
6212 vam->retval = -98;
6213 }
6214 vam->async_errors = 0;
6215 after = vat_time_now (vam);
6216
6217 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6218 if (j > 0)
6219 count = j;
6220
6221 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6222 count, after - before, count / (after - before));
6223 }
6224 else
6225 {
6226 /* Wait for a reply... */
6227 W;
6228 }
6229
6230 /* Return the good/bad news */
6231 return (vam->retval);
6232}
6233
6234static int
6235api_mpls_ip_bind_unbind (vat_main_t * vam)
6236{
6237 unformat_input_t *i = vam->input;
6238 vl_api_mpls_ip_bind_unbind_t *mp;
6239 f64 timeout;
6240 u32 ip_table_id = 0;
6241 u8 create_table_if_needed = 0;
6242 u8 is_bind = 1;
6243 u8 is_ip4 = 1;
6244 ip4_address_t v4_address;
6245 ip6_address_t v6_address;
6246 u32 address_length;
6247 u8 address_set = 0;
6248 mpls_label_t local_label = MPLS_LABEL_INVALID;
6249
6250 /* Parse args required to build the message */
6251 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6252 {
6253 if (unformat (i, "%U/%d", unformat_ip4_address,
6254 &v4_address, &address_length))
6255 {
6256 is_ip4 = 1;
6257 address_set = 1;
6258 }
6259 else if (unformat (i, "%U/%d", unformat_ip6_address,
6260 &v6_address, &address_length))
6261 {
6262 is_ip4 = 0;
6263 address_set = 1;
6264 }
6265 else if (unformat (i, "%d", &local_label))
6266 ;
6267 else if (unformat (i, "create-table"))
6268 create_table_if_needed = 1;
6269 else if (unformat (i, "table-id %d", &ip_table_id))
6270 ;
6271 else if (unformat (i, "unbind"))
6272 is_bind = 0;
6273 else if (unformat (i, "bind"))
6274 is_bind = 1;
6275 else
6276 {
6277 clib_warning ("parse error '%U'", format_unformat_error, i);
6278 return -99;
6279 }
6280 }
6281
6282 if (!address_set)
6283 {
6284 errmsg ("IP addres not set\n");
6285 return -99;
6286 }
6287
6288 if (MPLS_LABEL_INVALID == local_label)
6289 {
6290 errmsg ("missing label\n");
6291 return -99;
6292 }
6293
6294 /* Construct the API message */
6295 M (MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind);
6296
6297 mp->mb_create_table_if_needed = create_table_if_needed;
6298 mp->mb_is_bind = is_bind;
6299 mp->mb_is_ip4 = is_ip4;
6300 mp->mb_ip_table_id = ntohl (ip_table_id);
6301 mp->mb_mpls_table_id = 0;
6302 mp->mb_label = ntohl (local_label);
6303 mp->mb_address_length = address_length;
6304
6305 if (is_ip4)
6306 clib_memcpy (mp->mb_address, &v4_address, sizeof (v4_address));
6307 else
6308 clib_memcpy (mp->mb_address, &v6_address, sizeof (v6_address));
6309
6310 /* send it... */
6311 S;
6312
6313 /* Wait for a reply... */
6314 W;
6315
6316 /* Return the good/bad news */
6317 return (vam->retval);
6318}
6319
6320static int
Dave Barach72d72232016-08-04 10:15:08 -04006321api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006322{
Dave Barach72d72232016-08-04 10:15:08 -04006323 unformat_input_t *i = vam->input;
6324 vl_api_proxy_arp_add_del_t *mp;
6325 f64 timeout;
6326 u32 vrf_id = 0;
6327 u8 is_add = 1;
6328 ip4_address_t lo, hi;
6329 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006330
Dave Barach72d72232016-08-04 10:15:08 -04006331 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6332 {
6333 if (unformat (i, "vrf %d", &vrf_id))
6334 ;
6335 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
6336 unformat_ip4_address, &hi))
6337 range_set = 1;
6338 else if (unformat (i, "del"))
6339 is_add = 0;
6340 else
6341 {
6342 clib_warning ("parse error '%U'", format_unformat_error, i);
6343 return -99;
6344 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006345 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006346
Dave Barach72d72232016-08-04 10:15:08 -04006347 if (range_set == 0)
6348 {
6349 errmsg ("address range not set\n");
6350 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006351 }
6352
Dave Barach72d72232016-08-04 10:15:08 -04006353 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006354
Dave Barach72d72232016-08-04 10:15:08 -04006355 mp->vrf_id = ntohl (vrf_id);
6356 mp->is_add = is_add;
6357 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
6358 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006359
Dave Barach72d72232016-08-04 10:15:08 -04006360 S;
6361 W;
6362 /* NOTREACHED */
6363 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006364}
6365
Dave Barach72d72232016-08-04 10:15:08 -04006366static int
6367api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006368{
Dave Barach72d72232016-08-04 10:15:08 -04006369 unformat_input_t *i = vam->input;
6370 vl_api_proxy_arp_intfc_enable_disable_t *mp;
6371 f64 timeout;
6372 u32 sw_if_index;
6373 u8 enable = 1;
6374 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006375
Dave Barach72d72232016-08-04 10:15:08 -04006376 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6377 {
6378 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6379 sw_if_index_set = 1;
6380 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6381 sw_if_index_set = 1;
6382 else if (unformat (i, "enable"))
6383 enable = 1;
6384 else if (unformat (i, "disable"))
6385 enable = 0;
6386 else
6387 {
6388 clib_warning ("parse error '%U'", format_unformat_error, i);
6389 return -99;
6390 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006391 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006392
Dave Barach72d72232016-08-04 10:15:08 -04006393 if (sw_if_index_set == 0)
6394 {
6395 errmsg ("missing interface name or sw_if_index\n");
6396 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006397 }
6398
Dave Barach72d72232016-08-04 10:15:08 -04006399 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006400
Dave Barach72d72232016-08-04 10:15:08 -04006401 mp->sw_if_index = ntohl (sw_if_index);
6402 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006403
Dave Barach72d72232016-08-04 10:15:08 -04006404 S;
6405 W;
6406 /* NOTREACHED */
6407 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006408}
6409
Dave Barach72d72232016-08-04 10:15:08 -04006410static int
Dave Barach72d72232016-08-04 10:15:08 -04006411api_mpls_add_del_encap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006412{
Dave Barach72d72232016-08-04 10:15:08 -04006413 unformat_input_t *i = vam->input;
6414 vl_api_mpls_add_del_encap_t *mp;
6415 f64 timeout;
6416 u32 vrf_id = 0;
6417 u32 *labels = 0;
6418 u32 label;
6419 ip4_address_t dst_address;
6420 u8 is_add = 1;
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 ;
6426 else if (unformat (i, "label %d", &label))
6427 vec_add1 (labels, ntohl (label));
6428 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6429 ;
6430 else if (unformat (i, "del"))
6431 is_add = 0;
6432 else
6433 {
6434 clib_warning ("parse error '%U'", format_unformat_error, i);
6435 return -99;
6436 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006437 }
6438
Dave Barach72d72232016-08-04 10:15:08 -04006439 if (vec_len (labels) == 0)
6440 {
6441 errmsg ("missing encap label stack\n");
6442 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006443 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006444
Dave Barach72d72232016-08-04 10:15:08 -04006445 M2 (MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
6446 sizeof (u32) * vec_len (labels));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006447
Dave Barach72d72232016-08-04 10:15:08 -04006448 mp->vrf_id = ntohl (vrf_id);
6449 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6450 mp->is_add = is_add;
6451 mp->nlabels = vec_len (labels);
6452 clib_memcpy (mp->labels, labels, sizeof (u32) * mp->nlabels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006453
Dave Barach72d72232016-08-04 10:15:08 -04006454 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006455
Dave Barach72d72232016-08-04 10:15:08 -04006456 S;
6457 W;
6458 /* NOTREACHED */
6459 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006460}
6461
Dave Barach72d72232016-08-04 10:15:08 -04006462static int
Dave Barach72d72232016-08-04 10:15:08 -04006463api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006464{
Dave Barach72d72232016-08-04 10:15:08 -04006465 unformat_input_t *i = vam->input;
6466 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
6467 f64 timeout;
6468 u32 inner_vrf_id = 0;
6469 ip4_address_t intfc_address;
6470 u8 dst_mac_address[6];
6471 int dst_set = 1;
6472 u32 tmp;
6473 u8 intfc_address_length = 0;
6474 u8 is_add = 1;
6475 u8 l2_only = 0;
6476 u32 tx_sw_if_index;
6477 int tx_sw_if_index_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006478
Dave Barach72d72232016-08-04 10:15:08 -04006479 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6480 {
6481 if (unformat (i, "vrf %d", &inner_vrf_id))
6482 ;
6483 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6484 &intfc_address, &tmp))
6485 intfc_address_length = tmp;
6486 else if (unformat (i, "%U", unformat_sw_if_index, vam, &tx_sw_if_index))
6487 tx_sw_if_index_set = 1;
6488 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6489 tx_sw_if_index_set = 1;
6490 else if (unformat (i, "dst %U", unformat_ethernet_address,
6491 dst_mac_address))
6492 dst_set = 1;
6493 else if (unformat (i, "l2-only"))
6494 l2_only = 1;
6495 else if (unformat (i, "del"))
6496 is_add = 0;
6497 else
6498 {
6499 clib_warning ("parse error '%U'", format_unformat_error, i);
6500 return -99;
6501 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006502 }
6503
Dave Barach72d72232016-08-04 10:15:08 -04006504 if (!dst_set)
6505 {
6506 errmsg ("dst (mac address) not set\n");
6507 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006508 }
Dave Barach72d72232016-08-04 10:15:08 -04006509 if (!tx_sw_if_index_set)
6510 {
6511 errmsg ("tx-intfc not set\n");
6512 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006513 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006514
Dave Barach72d72232016-08-04 10:15:08 -04006515 M (MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006516
Dave Barach72d72232016-08-04 10:15:08 -04006517 mp->vrf_id = ntohl (inner_vrf_id);
6518 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
6519 mp->adj_address_length = intfc_address_length;
6520 clib_memcpy (mp->dst_mac_address, dst_mac_address,
6521 sizeof (dst_mac_address));
6522 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6523 mp->l2_only = l2_only;
6524 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006525
Dave Barach72d72232016-08-04 10:15:08 -04006526 S;
6527 W;
6528 /* NOTREACHED */
6529 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006530}
6531
Dave Barach72d72232016-08-04 10:15:08 -04006532static int
6533api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006534{
Dave Barach72d72232016-08-04 10:15:08 -04006535 unformat_input_t *i = vam->input;
6536 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
6537 f64 timeout;
6538 u32 inner_vrf_id = 0;
6539 u32 outer_vrf_id = 0;
6540 ip4_address_t adj_address;
6541 int adj_address_set = 0;
6542 ip4_address_t next_hop_address;
6543 int next_hop_address_set = 0;
6544 u32 tmp;
6545 u8 adj_address_length = 0;
6546 u8 l2_only = 0;
6547 u8 is_add = 1;
6548 u32 resolve_attempts = 5;
6549 u8 resolve_if_needed = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006550
Dave Barach72d72232016-08-04 10:15:08 -04006551 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6552 {
6553 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6554 ;
6555 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6556 ;
6557 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6558 &adj_address, &tmp))
6559 {
6560 adj_address_length = tmp;
6561 adj_address_set = 1;
6562 }
6563 else if (unformat (i, "next-hop %U", unformat_ip4_address,
6564 &next_hop_address))
6565 next_hop_address_set = 1;
6566 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
6567 ;
6568 else if (unformat (i, "resolve-if-needed %d", &tmp))
6569 resolve_if_needed = tmp;
6570 else if (unformat (i, "l2-only"))
6571 l2_only = 1;
6572 else if (unformat (i, "del"))
6573 is_add = 0;
6574 else
6575 {
6576 clib_warning ("parse error '%U'", format_unformat_error, i);
6577 return -99;
6578 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006579 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006580
Dave Barach72d72232016-08-04 10:15:08 -04006581 if (!adj_address_set)
6582 {
6583 errmsg ("adjacency address/mask not set\n");
6584 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006585 }
Dave Barach72d72232016-08-04 10:15:08 -04006586 if (!next_hop_address_set)
6587 {
6588 errmsg ("ip4 next hop address (in outer fib) not set\n");
6589 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006590 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006591
Dave Barach72d72232016-08-04 10:15:08 -04006592 M (MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006593
Dave Barach72d72232016-08-04 10:15:08 -04006594 mp->inner_vrf_id = ntohl (inner_vrf_id);
6595 mp->outer_vrf_id = ntohl (outer_vrf_id);
6596 mp->resolve_attempts = ntohl (resolve_attempts);
6597 mp->resolve_if_needed = resolve_if_needed;
6598 mp->is_add = is_add;
6599 mp->l2_only = l2_only;
6600 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
6601 mp->adj_address_length = adj_address_length;
6602 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
6603 sizeof (next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006604
Dave Barach72d72232016-08-04 10:15:08 -04006605 S;
6606 W;
6607 /* NOTREACHED */
6608 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006609}
6610
Dave Barach72d72232016-08-04 10:15:08 -04006611static int
6612api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006613{
Dave Barach72d72232016-08-04 10:15:08 -04006614 unformat_input_t *i = vam->input;
6615 vl_api_sw_interface_set_unnumbered_t *mp;
6616 f64 timeout;
6617 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006618 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006619 u8 is_add = 1;
6620 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006621
Dave Barach72d72232016-08-04 10:15:08 -04006622 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6623 {
6624 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6625 sw_if_index_set = 1;
6626 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6627 sw_if_index_set = 1;
6628 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6629 ;
6630 else if (unformat (i, "del"))
6631 is_add = 0;
6632 else
6633 {
6634 clib_warning ("parse error '%U'", format_unformat_error, i);
6635 return -99;
6636 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006637 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006638
Dave Barach72d72232016-08-04 10:15:08 -04006639 if (sw_if_index_set == 0)
6640 {
6641 errmsg ("missing interface name or sw_if_index\n");
6642 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006643 }
6644
Dave Barach72d72232016-08-04 10:15:08 -04006645 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006646
Dave Barach72d72232016-08-04 10:15:08 -04006647 mp->sw_if_index = ntohl (sw_if_index);
6648 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6649 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006650
Dave Barach72d72232016-08-04 10:15:08 -04006651 S;
6652 W;
6653 /* NOTREACHED */
6654 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006655}
6656
Dave Barach72d72232016-08-04 10:15:08 -04006657static int
6658api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006659{
Dave Barach72d72232016-08-04 10:15:08 -04006660 unformat_input_t *i = vam->input;
6661 vl_api_ip_neighbor_add_del_t *mp;
6662 f64 timeout;
6663 u32 sw_if_index;
6664 u8 sw_if_index_set = 0;
6665 u32 vrf_id = 0;
6666 u8 is_add = 1;
6667 u8 is_static = 0;
6668 u8 mac_address[6];
6669 u8 mac_set = 0;
6670 u8 v4_address_set = 0;
6671 u8 v6_address_set = 0;
6672 ip4_address_t v4address;
6673 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006674
Dave Barach72d72232016-08-04 10:15:08 -04006675 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006676
Dave Barach72d72232016-08-04 10:15:08 -04006677 /* Parse args required to build the message */
6678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6679 {
6680 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6681 {
6682 mac_set = 1;
6683 }
6684 else if (unformat (i, "del"))
6685 is_add = 0;
6686 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6687 sw_if_index_set = 1;
6688 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6689 sw_if_index_set = 1;
6690 else if (unformat (i, "is_static"))
6691 is_static = 1;
6692 else if (unformat (i, "vrf %d", &vrf_id))
6693 ;
6694 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6695 v4_address_set = 1;
6696 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6697 v6_address_set = 1;
6698 else
6699 {
6700 clib_warning ("parse error '%U'", format_unformat_error, i);
6701 return -99;
6702 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006703 }
6704
Dave Barach72d72232016-08-04 10:15:08 -04006705 if (sw_if_index_set == 0)
6706 {
6707 errmsg ("missing interface name or sw_if_index\n");
6708 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006709 }
Dave Barach72d72232016-08-04 10:15:08 -04006710 if (v4_address_set && v6_address_set)
6711 {
6712 errmsg ("both v4 and v6 addresses set\n");
6713 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006714 }
Dave Barach72d72232016-08-04 10:15:08 -04006715 if (!v4_address_set && !v6_address_set)
6716 {
6717 errmsg ("no address set\n");
6718 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006719 }
6720
Dave Barach72d72232016-08-04 10:15:08 -04006721 /* Construct the API message */
6722 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006723
Dave Barach72d72232016-08-04 10:15:08 -04006724 mp->sw_if_index = ntohl (sw_if_index);
6725 mp->is_add = is_add;
6726 mp->vrf_id = ntohl (vrf_id);
6727 mp->is_static = is_static;
6728 if (mac_set)
6729 clib_memcpy (mp->mac_address, mac_address, 6);
6730 if (v6_address_set)
6731 {
6732 mp->is_ipv6 = 1;
6733 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6734 }
6735 else
6736 {
6737 /* mp->is_ipv6 = 0; via memset in M macro above */
6738 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006739 }
6740
Dave Barach72d72232016-08-04 10:15:08 -04006741 /* send it... */
6742 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006743
Dave Barach72d72232016-08-04 10:15:08 -04006744 /* Wait for a reply, return good/bad news */
6745 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006746
Dave Barach72d72232016-08-04 10:15:08 -04006747 /* NOTREACHED */
6748 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006749}
6750
Dave Barach72d72232016-08-04 10:15:08 -04006751static int
6752api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006753{
Dave Barach72d72232016-08-04 10:15:08 -04006754 unformat_input_t *i = vam->input;
6755 vl_api_reset_vrf_t *mp;
6756 f64 timeout;
6757 u32 vrf_id = 0;
6758 u8 is_ipv6 = 0;
6759 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006760
Dave Barach72d72232016-08-04 10:15:08 -04006761 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6762 {
6763 if (unformat (i, "vrf %d", &vrf_id))
6764 vrf_id_set = 1;
6765 else if (unformat (i, "ipv6"))
6766 is_ipv6 = 1;
6767 else
6768 {
6769 clib_warning ("parse error '%U'", format_unformat_error, i);
6770 return -99;
6771 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006772 }
6773
Dave Barach72d72232016-08-04 10:15:08 -04006774 if (vrf_id_set == 0)
6775 {
6776 errmsg ("missing vrf id\n");
6777 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006778 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006779
Dave Barach72d72232016-08-04 10:15:08 -04006780 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006781
Dave Barach72d72232016-08-04 10:15:08 -04006782 mp->vrf_id = ntohl (vrf_id);
6783 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006784
Dave Barach72d72232016-08-04 10:15:08 -04006785 S;
6786 W;
6787 /* NOTREACHED */
6788 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006789}
6790
Dave Barach72d72232016-08-04 10:15:08 -04006791static int
6792api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006793{
Dave Barach72d72232016-08-04 10:15:08 -04006794 unformat_input_t *i = vam->input;
6795 vl_api_create_vlan_subif_t *mp;
6796 f64 timeout;
6797 u32 sw_if_index;
6798 u8 sw_if_index_set = 0;
6799 u32 vlan_id;
6800 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006801
Dave Barach72d72232016-08-04 10:15:08 -04006802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6803 {
6804 if (unformat (i, "sw_if_index %d", &sw_if_index))
6805 sw_if_index_set = 1;
6806 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6807 sw_if_index_set = 1;
6808 else if (unformat (i, "vlan %d", &vlan_id))
6809 vlan_id_set = 1;
6810 else
6811 {
6812 clib_warning ("parse error '%U'", format_unformat_error, i);
6813 return -99;
6814 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006815 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006816
Dave Barach72d72232016-08-04 10:15:08 -04006817 if (sw_if_index_set == 0)
6818 {
6819 errmsg ("missing interface name or sw_if_index\n");
6820 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006821 }
6822
Dave Barach72d72232016-08-04 10:15:08 -04006823 if (vlan_id_set == 0)
6824 {
6825 errmsg ("missing vlan_id\n");
6826 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006827 }
Dave Barach72d72232016-08-04 10:15:08 -04006828 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006829
Dave Barach72d72232016-08-04 10:15:08 -04006830 mp->sw_if_index = ntohl (sw_if_index);
6831 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006832
Dave Barach72d72232016-08-04 10:15:08 -04006833 S;
6834 W;
6835 /* NOTREACHED */
6836 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006837}
6838
6839#define foreach_create_subif_bit \
6840_(no_tags) \
6841_(one_tag) \
6842_(two_tags) \
6843_(dot1ad) \
6844_(exact_match) \
6845_(default_sub) \
6846_(outer_vlan_id_any) \
6847_(inner_vlan_id_any)
6848
Dave Barach72d72232016-08-04 10:15:08 -04006849static int
6850api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006851{
Dave Barach72d72232016-08-04 10:15:08 -04006852 unformat_input_t *i = vam->input;
6853 vl_api_create_subif_t *mp;
6854 f64 timeout;
6855 u32 sw_if_index;
6856 u8 sw_if_index_set = 0;
6857 u32 sub_id;
6858 u8 sub_id_set = 0;
6859 u32 no_tags = 0;
6860 u32 one_tag = 0;
6861 u32 two_tags = 0;
6862 u32 dot1ad = 0;
6863 u32 exact_match = 0;
6864 u32 default_sub = 0;
6865 u32 outer_vlan_id_any = 0;
6866 u32 inner_vlan_id_any = 0;
6867 u32 tmp;
6868 u16 outer_vlan_id = 0;
6869 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006870
Dave Barach72d72232016-08-04 10:15:08 -04006871 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6872 {
6873 if (unformat (i, "sw_if_index %d", &sw_if_index))
6874 sw_if_index_set = 1;
6875 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6876 sw_if_index_set = 1;
6877 else if (unformat (i, "sub_id %d", &sub_id))
6878 sub_id_set = 1;
6879 else if (unformat (i, "outer_vlan_id %d", &tmp))
6880 outer_vlan_id = tmp;
6881 else if (unformat (i, "inner_vlan_id %d", &tmp))
6882 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006883
6884#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04006885 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07006886#undef _
Dave Barach72d72232016-08-04 10:15:08 -04006887 else
6888 {
6889 clib_warning ("parse error '%U'", format_unformat_error, i);
6890 return -99;
6891 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006892 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006893
Dave Barach72d72232016-08-04 10:15:08 -04006894 if (sw_if_index_set == 0)
6895 {
6896 errmsg ("missing interface name or sw_if_index\n");
6897 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006898 }
6899
Dave Barach72d72232016-08-04 10:15:08 -04006900 if (sub_id_set == 0)
6901 {
6902 errmsg ("missing sub_id\n");
6903 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006904 }
Dave Barach72d72232016-08-04 10:15:08 -04006905 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006906
Dave Barach72d72232016-08-04 10:15:08 -04006907 mp->sw_if_index = ntohl (sw_if_index);
6908 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006909
Ed Warnickecb9cada2015-12-08 15:45:58 -07006910#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04006911 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006912#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006913
Dave Barach72d72232016-08-04 10:15:08 -04006914 mp->outer_vlan_id = ntohs (outer_vlan_id);
6915 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006916
Dave Barach72d72232016-08-04 10:15:08 -04006917 S;
6918 W;
6919 /* NOTREACHED */
6920 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006921}
6922
Dave Barach72d72232016-08-04 10:15:08 -04006923static int
6924api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006925{
Dave Barach72d72232016-08-04 10:15:08 -04006926 unformat_input_t *i = vam->input;
6927 vl_api_oam_add_del_t *mp;
6928 f64 timeout;
6929 u32 vrf_id = 0;
6930 u8 is_add = 1;
6931 ip4_address_t src, dst;
6932 u8 src_set = 0;
6933 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006934
Dave Barach72d72232016-08-04 10:15:08 -04006935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6936 {
6937 if (unformat (i, "vrf %d", &vrf_id))
6938 ;
6939 else if (unformat (i, "src %U", unformat_ip4_address, &src))
6940 src_set = 1;
6941 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
6942 dst_set = 1;
6943 else if (unformat (i, "del"))
6944 is_add = 0;
6945 else
6946 {
6947 clib_warning ("parse error '%U'", format_unformat_error, i);
6948 return -99;
6949 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006950 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006951
Dave Barach72d72232016-08-04 10:15:08 -04006952 if (src_set == 0)
6953 {
6954 errmsg ("missing src addr\n");
6955 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006956 }
6957
Dave Barach72d72232016-08-04 10:15:08 -04006958 if (dst_set == 0)
6959 {
6960 errmsg ("missing dst addr\n");
6961 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006962 }
6963
Dave Barach72d72232016-08-04 10:15:08 -04006964 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006965
Dave Barach72d72232016-08-04 10:15:08 -04006966 mp->vrf_id = ntohl (vrf_id);
6967 mp->is_add = is_add;
6968 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
6969 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006970
Dave Barach72d72232016-08-04 10:15:08 -04006971 S;
6972 W;
6973 /* NOTREACHED */
6974 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006975}
6976
Dave Barach72d72232016-08-04 10:15:08 -04006977static int
6978api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006979{
Dave Barach72d72232016-08-04 10:15:08 -04006980 unformat_input_t *i = vam->input;
6981 vl_api_reset_fib_t *mp;
6982 f64 timeout;
6983 u32 vrf_id = 0;
6984 u8 is_ipv6 = 0;
6985 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006986
Dave Barach72d72232016-08-04 10:15:08 -04006987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6988 {
6989 if (unformat (i, "vrf %d", &vrf_id))
6990 vrf_id_set = 1;
6991 else if (unformat (i, "ipv6"))
6992 is_ipv6 = 1;
6993 else
6994 {
6995 clib_warning ("parse error '%U'", format_unformat_error, i);
6996 return -99;
6997 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006998 }
6999
Dave Barach72d72232016-08-04 10:15:08 -04007000 if (vrf_id_set == 0)
7001 {
7002 errmsg ("missing vrf id\n");
7003 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007004 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007005
Dave Barach72d72232016-08-04 10:15:08 -04007006 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007007
Dave Barach72d72232016-08-04 10:15:08 -04007008 mp->vrf_id = ntohl (vrf_id);
7009 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007010
Dave Barach72d72232016-08-04 10:15:08 -04007011 S;
7012 W;
7013 /* NOTREACHED */
7014 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007015}
7016
Dave Barach72d72232016-08-04 10:15:08 -04007017static int
7018api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007019{
Dave Barach72d72232016-08-04 10:15:08 -04007020 unformat_input_t *i = vam->input;
7021 vl_api_dhcp_proxy_config_t *mp;
7022 f64 timeout;
7023 u32 vrf_id = 0;
7024 u8 is_add = 1;
7025 u8 insert_cid = 1;
7026 u8 v4_address_set = 0;
7027 u8 v6_address_set = 0;
7028 ip4_address_t v4address;
7029 ip6_address_t v6address;
7030 u8 v4_src_address_set = 0;
7031 u8 v6_src_address_set = 0;
7032 ip4_address_t v4srcaddress;
7033 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007034
Dave Barach72d72232016-08-04 10:15:08 -04007035 /* Parse args required to build the message */
7036 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7037 {
7038 if (unformat (i, "del"))
7039 is_add = 0;
7040 else if (unformat (i, "vrf %d", &vrf_id))
7041 ;
7042 else if (unformat (i, "insert-cid %d", &insert_cid))
7043 ;
7044 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7045 v4_address_set = 1;
7046 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7047 v6_address_set = 1;
7048 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7049 v4_src_address_set = 1;
7050 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7051 v6_src_address_set = 1;
7052 else
7053 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007054 }
7055
Dave Barach72d72232016-08-04 10:15:08 -04007056 if (v4_address_set && v6_address_set)
7057 {
7058 errmsg ("both v4 and v6 server addresses set\n");
7059 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007060 }
Dave Barach72d72232016-08-04 10:15:08 -04007061 if (!v4_address_set && !v6_address_set)
7062 {
7063 errmsg ("no server addresses set\n");
7064 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007065 }
7066
Dave Barach72d72232016-08-04 10:15:08 -04007067 if (v4_src_address_set && v6_src_address_set)
7068 {
7069 errmsg ("both v4 and v6 src addresses set\n");
7070 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007071 }
Dave Barach72d72232016-08-04 10:15:08 -04007072 if (!v4_src_address_set && !v6_src_address_set)
7073 {
7074 errmsg ("no src addresses set\n");
7075 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007076 }
7077
Dave Barach72d72232016-08-04 10:15:08 -04007078 if (!(v4_src_address_set && v4_address_set) &&
7079 !(v6_src_address_set && v6_address_set))
7080 {
7081 errmsg ("no matching server and src addresses set\n");
7082 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007083 }
7084
Dave Barach72d72232016-08-04 10:15:08 -04007085 /* Construct the API message */
7086 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007087
Dave Barach72d72232016-08-04 10:15:08 -04007088 mp->insert_circuit_id = insert_cid;
7089 mp->is_add = is_add;
7090 mp->vrf_id = ntohl (vrf_id);
7091 if (v6_address_set)
7092 {
7093 mp->is_ipv6 = 1;
7094 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7095 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7096 }
7097 else
7098 {
7099 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7100 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007101 }
7102
Dave Barach72d72232016-08-04 10:15:08 -04007103 /* send it... */
7104 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007105
Dave Barach72d72232016-08-04 10:15:08 -04007106 /* Wait for a reply, return good/bad news */
7107 W;
7108 /* NOTREACHED */
7109 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007110}
7111
Dave Barach72d72232016-08-04 10:15:08 -04007112static int
7113api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007114{
Dave Barach72d72232016-08-04 10:15:08 -04007115 unformat_input_t *i = vam->input;
7116 vl_api_dhcp_proxy_config_2_t *mp;
7117 f64 timeout;
7118 u32 rx_vrf_id = 0;
7119 u32 server_vrf_id = 0;
7120 u8 is_add = 1;
7121 u8 insert_cid = 1;
7122 u8 v4_address_set = 0;
7123 u8 v6_address_set = 0;
7124 ip4_address_t v4address;
7125 ip6_address_t v6address;
7126 u8 v4_src_address_set = 0;
7127 u8 v6_src_address_set = 0;
7128 ip4_address_t v4srcaddress;
7129 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007130
Dave Barach72d72232016-08-04 10:15:08 -04007131 /* Parse args required to build the message */
7132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7133 {
7134 if (unformat (i, "del"))
7135 is_add = 0;
7136 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
7137 ;
7138 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
7139 ;
7140 else if (unformat (i, "insert-cid %d", &insert_cid))
7141 ;
7142 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7143 v4_address_set = 1;
7144 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7145 v6_address_set = 1;
7146 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7147 v4_src_address_set = 1;
7148 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7149 v6_src_address_set = 1;
7150 else
7151 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007152 }
7153
Dave Barach72d72232016-08-04 10:15:08 -04007154 if (v4_address_set && v6_address_set)
7155 {
7156 errmsg ("both v4 and v6 server addresses set\n");
7157 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007158 }
Dave Barach72d72232016-08-04 10:15:08 -04007159 if (!v4_address_set && !v6_address_set)
7160 {
7161 errmsg ("no server addresses set\n");
7162 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007163 }
7164
Dave Barach72d72232016-08-04 10:15:08 -04007165 if (v4_src_address_set && v6_src_address_set)
7166 {
7167 errmsg ("both v4 and v6 src addresses set\n");
7168 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007169 }
Dave Barach72d72232016-08-04 10:15:08 -04007170 if (!v4_src_address_set && !v6_src_address_set)
7171 {
7172 errmsg ("no src addresses set\n");
7173 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007174 }
7175
Dave Barach72d72232016-08-04 10:15:08 -04007176 if (!(v4_src_address_set && v4_address_set) &&
7177 !(v6_src_address_set && v6_address_set))
7178 {
7179 errmsg ("no matching server and src addresses set\n");
7180 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007181 }
7182
Dave Barach72d72232016-08-04 10:15:08 -04007183 /* Construct the API message */
7184 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007185
Dave Barach72d72232016-08-04 10:15:08 -04007186 mp->insert_circuit_id = insert_cid;
7187 mp->is_add = is_add;
7188 mp->rx_vrf_id = ntohl (rx_vrf_id);
7189 mp->server_vrf_id = ntohl (server_vrf_id);
7190 if (v6_address_set)
7191 {
7192 mp->is_ipv6 = 1;
7193 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7194 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7195 }
7196 else
7197 {
7198 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7199 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007200 }
7201
Dave Barach72d72232016-08-04 10:15:08 -04007202 /* send it... */
7203 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007204
Dave Barach72d72232016-08-04 10:15:08 -04007205 /* Wait for a reply, return good/bad news */
7206 W;
7207 /* NOTREACHED */
7208 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007209}
7210
Dave Barach72d72232016-08-04 10:15:08 -04007211static int
7212api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007213{
Dave Barach72d72232016-08-04 10:15:08 -04007214 unformat_input_t *i = vam->input;
7215 vl_api_dhcp_proxy_set_vss_t *mp;
7216 f64 timeout;
7217 u8 is_ipv6 = 0;
7218 u8 is_add = 1;
7219 u32 tbl_id;
7220 u8 tbl_id_set = 0;
7221 u32 oui;
7222 u8 oui_set = 0;
7223 u32 fib_id;
7224 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007225
Dave Barach72d72232016-08-04 10:15:08 -04007226 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7227 {
7228 if (unformat (i, "tbl_id %d", &tbl_id))
7229 tbl_id_set = 1;
7230 if (unformat (i, "fib_id %d", &fib_id))
7231 fib_id_set = 1;
7232 if (unformat (i, "oui %d", &oui))
7233 oui_set = 1;
7234 else if (unformat (i, "ipv6"))
7235 is_ipv6 = 1;
7236 else if (unformat (i, "del"))
7237 is_add = 0;
7238 else
7239 {
7240 clib_warning ("parse error '%U'", format_unformat_error, i);
7241 return -99;
7242 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007243 }
7244
Dave Barach72d72232016-08-04 10:15:08 -04007245 if (tbl_id_set == 0)
7246 {
7247 errmsg ("missing tbl id\n");
7248 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007249 }
7250
Dave Barach72d72232016-08-04 10:15:08 -04007251 if (fib_id_set == 0)
7252 {
7253 errmsg ("missing fib id\n");
7254 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007255 }
Dave Barach72d72232016-08-04 10:15:08 -04007256 if (oui_set == 0)
7257 {
7258 errmsg ("missing oui\n");
7259 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007260 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007261
Dave Barach72d72232016-08-04 10:15:08 -04007262 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
7263 mp->tbl_id = ntohl (tbl_id);
7264 mp->fib_id = ntohl (fib_id);
7265 mp->oui = ntohl (oui);
7266 mp->is_ipv6 = is_ipv6;
7267 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007268
Dave Barach72d72232016-08-04 10:15:08 -04007269 S;
7270 W;
7271 /* NOTREACHED */
7272 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007273}
7274
Dave Barach72d72232016-08-04 10:15:08 -04007275static int
7276api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007277{
Dave Barach72d72232016-08-04 10:15:08 -04007278 unformat_input_t *i = vam->input;
7279 vl_api_dhcp_client_config_t *mp;
7280 f64 timeout;
7281 u32 sw_if_index;
7282 u8 sw_if_index_set = 0;
7283 u8 is_add = 1;
7284 u8 *hostname = 0;
7285 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007286
Dave Barach72d72232016-08-04 10:15:08 -04007287 /* Parse args required to build the message */
7288 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7289 {
7290 if (unformat (i, "del"))
7291 is_add = 0;
7292 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7293 sw_if_index_set = 1;
7294 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7295 sw_if_index_set = 1;
7296 else if (unformat (i, "hostname %s", &hostname))
7297 ;
7298 else if (unformat (i, "disable_event"))
7299 disable_event = 1;
7300 else
7301 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007302 }
7303
Dave Barach72d72232016-08-04 10:15:08 -04007304 if (sw_if_index_set == 0)
7305 {
7306 errmsg ("missing interface name or sw_if_index\n");
7307 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007308 }
7309
Dave Barach72d72232016-08-04 10:15:08 -04007310 if (vec_len (hostname) > 63)
7311 {
7312 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07007313 }
Dave Barach72d72232016-08-04 10:15:08 -04007314 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007315
Dave Barach72d72232016-08-04 10:15:08 -04007316 /* Construct the API message */
7317 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007318
Dave Barach72d72232016-08-04 10:15:08 -04007319 mp->sw_if_index = ntohl (sw_if_index);
7320 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
7321 vec_free (hostname);
7322 mp->is_add = is_add;
7323 mp->want_dhcp_event = disable_event ? 0 : 1;
7324 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007325
Dave Barach72d72232016-08-04 10:15:08 -04007326 /* send it... */
7327 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007328
Dave Barach72d72232016-08-04 10:15:08 -04007329 /* Wait for a reply, return good/bad news */
7330 W;
7331 /* NOTREACHED */
7332 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007333}
7334
Dave Barach72d72232016-08-04 10:15:08 -04007335static int
7336api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007337{
Dave Barach72d72232016-08-04 10:15:08 -04007338 unformat_input_t *i = vam->input;
7339 vl_api_set_ip_flow_hash_t *mp;
7340 f64 timeout;
7341 u32 vrf_id = 0;
7342 u8 is_ipv6 = 0;
7343 u8 vrf_id_set = 0;
7344 u8 src = 0;
7345 u8 dst = 0;
7346 u8 sport = 0;
7347 u8 dport = 0;
7348 u8 proto = 0;
7349 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007350
Dave Barach72d72232016-08-04 10:15:08 -04007351 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7352 {
7353 if (unformat (i, "vrf %d", &vrf_id))
7354 vrf_id_set = 1;
7355 else if (unformat (i, "ipv6"))
7356 is_ipv6 = 1;
7357 else if (unformat (i, "src"))
7358 src = 1;
7359 else if (unformat (i, "dst"))
7360 dst = 1;
7361 else if (unformat (i, "sport"))
7362 sport = 1;
7363 else if (unformat (i, "dport"))
7364 dport = 1;
7365 else if (unformat (i, "proto"))
7366 proto = 1;
7367 else if (unformat (i, "reverse"))
7368 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007369
Dave Barach72d72232016-08-04 10:15:08 -04007370 else
7371 {
7372 clib_warning ("parse error '%U'", format_unformat_error, i);
7373 return -99;
7374 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007375 }
7376
Dave Barach72d72232016-08-04 10:15:08 -04007377 if (vrf_id_set == 0)
7378 {
7379 errmsg ("missing vrf id\n");
7380 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007381 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007382
Dave Barach72d72232016-08-04 10:15:08 -04007383 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7384 mp->src = src;
7385 mp->dst = dst;
7386 mp->sport = sport;
7387 mp->dport = dport;
7388 mp->proto = proto;
7389 mp->reverse = reverse;
7390 mp->vrf_id = ntohl (vrf_id);
7391 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007392
Dave Barach72d72232016-08-04 10:15:08 -04007393 S;
7394 W;
7395 /* NOTREACHED */
7396 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007397}
7398
Dave Barach72d72232016-08-04 10:15:08 -04007399static int
7400api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007401{
Dave Barach72d72232016-08-04 10:15:08 -04007402 unformat_input_t *i = vam->input;
7403 vl_api_sw_interface_ip6_enable_disable_t *mp;
7404 f64 timeout;
7405 u32 sw_if_index;
7406 u8 sw_if_index_set = 0;
7407 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007408
Dave Barach72d72232016-08-04 10:15:08 -04007409 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7410 {
7411 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7412 sw_if_index_set = 1;
7413 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7414 sw_if_index_set = 1;
7415 else if (unformat (i, "enable"))
7416 enable = 1;
7417 else if (unformat (i, "disable"))
7418 enable = 0;
7419 else
7420 {
7421 clib_warning ("parse error '%U'", format_unformat_error, i);
7422 return -99;
7423 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007424 }
7425
Dave Barach72d72232016-08-04 10:15:08 -04007426 if (sw_if_index_set == 0)
7427 {
7428 errmsg ("missing interface name or sw_if_index\n");
7429 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007430 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007431
Dave Barach72d72232016-08-04 10:15:08 -04007432 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007433
Dave Barach72d72232016-08-04 10:15:08 -04007434 mp->sw_if_index = ntohl (sw_if_index);
7435 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007436
Dave Barach72d72232016-08-04 10:15:08 -04007437 S;
7438 W;
7439 /* NOTREACHED */
7440 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007441}
7442
Dave Barach72d72232016-08-04 10:15:08 -04007443static int
7444api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007445{
Dave Barach72d72232016-08-04 10:15:08 -04007446 unformat_input_t *i = vam->input;
7447 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7448 f64 timeout;
7449 u32 sw_if_index;
7450 u8 sw_if_index_set = 0;
7451 u32 address_length = 0;
7452 u8 v6_address_set = 0;
7453 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007454
Dave Barach72d72232016-08-04 10:15:08 -04007455 /* Parse args required to build the message */
7456 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7457 {
7458 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7459 sw_if_index_set = 1;
7460 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7461 sw_if_index_set = 1;
7462 else if (unformat (i, "%U/%d",
7463 unformat_ip6_address, &v6address, &address_length))
7464 v6_address_set = 1;
7465 else
7466 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007467 }
7468
Dave Barach72d72232016-08-04 10:15:08 -04007469 if (sw_if_index_set == 0)
7470 {
7471 errmsg ("missing interface name or sw_if_index\n");
7472 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007473 }
Dave Barach72d72232016-08-04 10:15:08 -04007474 if (!v6_address_set)
7475 {
7476 errmsg ("no address set\n");
7477 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007478 }
7479
Dave Barach72d72232016-08-04 10:15:08 -04007480 /* Construct the API message */
7481 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7482 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007483
Dave Barach72d72232016-08-04 10:15:08 -04007484 mp->sw_if_index = ntohl (sw_if_index);
7485 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7486 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007487
Dave Barach72d72232016-08-04 10:15:08 -04007488 /* send it... */
7489 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007490
Dave Barach72d72232016-08-04 10:15:08 -04007491 /* Wait for a reply, return good/bad news */
7492 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007493
Dave Barach72d72232016-08-04 10:15:08 -04007494 /* NOTREACHED */
7495 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007496}
7497
7498
Dave Barach72d72232016-08-04 10:15:08 -04007499static int
7500api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007501{
Dave Barach72d72232016-08-04 10:15:08 -04007502 unformat_input_t *i = vam->input;
7503 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7504 f64 timeout;
7505 u32 sw_if_index;
7506 u8 sw_if_index_set = 0;
7507 u32 address_length = 0;
7508 u8 v6_address_set = 0;
7509 ip6_address_t v6address;
7510 u8 use_default = 0;
7511 u8 no_advertise = 0;
7512 u8 off_link = 0;
7513 u8 no_autoconfig = 0;
7514 u8 no_onlink = 0;
7515 u8 is_no = 0;
7516 u32 val_lifetime = 0;
7517 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007518
Dave Barach72d72232016-08-04 10:15:08 -04007519 /* Parse args required to build the message */
7520 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7521 {
7522 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7523 sw_if_index_set = 1;
7524 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7525 sw_if_index_set = 1;
7526 else if (unformat (i, "%U/%d",
7527 unformat_ip6_address, &v6address, &address_length))
7528 v6_address_set = 1;
7529 else if (unformat (i, "val_life %d", &val_lifetime))
7530 ;
7531 else if (unformat (i, "pref_life %d", &pref_lifetime))
7532 ;
7533 else if (unformat (i, "def"))
7534 use_default = 1;
7535 else if (unformat (i, "noadv"))
7536 no_advertise = 1;
7537 else if (unformat (i, "offl"))
7538 off_link = 1;
7539 else if (unformat (i, "noauto"))
7540 no_autoconfig = 1;
7541 else if (unformat (i, "nolink"))
7542 no_onlink = 1;
7543 else if (unformat (i, "isno"))
7544 is_no = 1;
7545 else
7546 {
7547 clib_warning ("parse error '%U'", format_unformat_error, i);
7548 return -99;
7549 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007550 }
7551
Dave Barach72d72232016-08-04 10:15:08 -04007552 if (sw_if_index_set == 0)
7553 {
7554 errmsg ("missing interface name or sw_if_index\n");
7555 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007556 }
Dave Barach72d72232016-08-04 10:15:08 -04007557 if (!v6_address_set)
7558 {
7559 errmsg ("no address set\n");
7560 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007561 }
7562
Dave Barach72d72232016-08-04 10:15:08 -04007563 /* Construct the API message */
7564 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007565
Dave Barach72d72232016-08-04 10:15:08 -04007566 mp->sw_if_index = ntohl (sw_if_index);
7567 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7568 mp->address_length = address_length;
7569 mp->use_default = use_default;
7570 mp->no_advertise = no_advertise;
7571 mp->off_link = off_link;
7572 mp->no_autoconfig = no_autoconfig;
7573 mp->no_onlink = no_onlink;
7574 mp->is_no = is_no;
7575 mp->val_lifetime = ntohl (val_lifetime);
7576 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007577
Dave Barach72d72232016-08-04 10:15:08 -04007578 /* send it... */
7579 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007580
Dave Barach72d72232016-08-04 10:15:08 -04007581 /* Wait for a reply, return good/bad news */
7582 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007583
Dave Barach72d72232016-08-04 10:15:08 -04007584 /* NOTREACHED */
7585 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007586}
7587
Dave Barach72d72232016-08-04 10:15:08 -04007588static int
7589api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007590{
Dave Barach72d72232016-08-04 10:15:08 -04007591 unformat_input_t *i = vam->input;
7592 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7593 f64 timeout;
7594 u32 sw_if_index;
7595 u8 sw_if_index_set = 0;
7596 u8 suppress = 0;
7597 u8 managed = 0;
7598 u8 other = 0;
7599 u8 ll_option = 0;
7600 u8 send_unicast = 0;
7601 u8 cease = 0;
7602 u8 is_no = 0;
7603 u8 default_router = 0;
7604 u32 max_interval = 0;
7605 u32 min_interval = 0;
7606 u32 lifetime = 0;
7607 u32 initial_count = 0;
7608 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007609
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007610
Dave Barach72d72232016-08-04 10:15:08 -04007611 /* Parse args required to build the message */
7612 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7613 {
7614 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7615 sw_if_index_set = 1;
7616 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7617 sw_if_index_set = 1;
7618 else if (unformat (i, "maxint %d", &max_interval))
7619 ;
7620 else if (unformat (i, "minint %d", &min_interval))
7621 ;
7622 else if (unformat (i, "life %d", &lifetime))
7623 ;
7624 else if (unformat (i, "count %d", &initial_count))
7625 ;
7626 else if (unformat (i, "interval %d", &initial_interval))
7627 ;
7628 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7629 suppress = 1;
7630 else if (unformat (i, "managed"))
7631 managed = 1;
7632 else if (unformat (i, "other"))
7633 other = 1;
7634 else if (unformat (i, "ll"))
7635 ll_option = 1;
7636 else if (unformat (i, "send"))
7637 send_unicast = 1;
7638 else if (unformat (i, "cease"))
7639 cease = 1;
7640 else if (unformat (i, "isno"))
7641 is_no = 1;
7642 else if (unformat (i, "def"))
7643 default_router = 1;
7644 else
7645 {
7646 clib_warning ("parse error '%U'", format_unformat_error, i);
7647 return -99;
7648 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007649 }
7650
Dave Barach72d72232016-08-04 10:15:08 -04007651 if (sw_if_index_set == 0)
7652 {
7653 errmsg ("missing interface name or sw_if_index\n");
7654 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007655 }
7656
Dave Barach72d72232016-08-04 10:15:08 -04007657 /* Construct the API message */
7658 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007659
Dave Barach72d72232016-08-04 10:15:08 -04007660 mp->sw_if_index = ntohl (sw_if_index);
7661 mp->max_interval = ntohl (max_interval);
7662 mp->min_interval = ntohl (min_interval);
7663 mp->lifetime = ntohl (lifetime);
7664 mp->initial_count = ntohl (initial_count);
7665 mp->initial_interval = ntohl (initial_interval);
7666 mp->suppress = suppress;
7667 mp->managed = managed;
7668 mp->other = other;
7669 mp->ll_option = ll_option;
7670 mp->send_unicast = send_unicast;
7671 mp->cease = cease;
7672 mp->is_no = is_no;
7673 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007674
Dave Barach72d72232016-08-04 10:15:08 -04007675 /* send it... */
7676 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007677
Dave Barach72d72232016-08-04 10:15:08 -04007678 /* Wait for a reply, return good/bad news */
7679 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007680
Dave Barach72d72232016-08-04 10:15:08 -04007681 /* NOTREACHED */
7682 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007683}
7684
Dave Barach72d72232016-08-04 10:15:08 -04007685static int
7686api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007687{
Dave Barach72d72232016-08-04 10:15:08 -04007688 unformat_input_t *i = vam->input;
7689 vl_api_set_arp_neighbor_limit_t *mp;
7690 f64 timeout;
7691 u32 arp_nbr_limit;
7692 u8 limit_set = 0;
7693 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007694
Dave Barach72d72232016-08-04 10:15:08 -04007695 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7696 {
7697 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7698 limit_set = 1;
7699 else if (unformat (i, "ipv6"))
7700 is_ipv6 = 1;
7701 else
7702 {
7703 clib_warning ("parse error '%U'", format_unformat_error, i);
7704 return -99;
7705 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007706 }
7707
Dave Barach72d72232016-08-04 10:15:08 -04007708 if (limit_set == 0)
7709 {
7710 errmsg ("missing limit value\n");
7711 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007712 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007713
Dave Barach72d72232016-08-04 10:15:08 -04007714 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007715
Dave Barach72d72232016-08-04 10:15:08 -04007716 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7717 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007718
Dave Barach72d72232016-08-04 10:15:08 -04007719 S;
7720 W;
7721 /* NOTREACHED */
7722 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007723}
7724
Dave Barach72d72232016-08-04 10:15:08 -04007725static int
7726api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007727{
Dave Barach72d72232016-08-04 10:15:08 -04007728 unformat_input_t *i = vam->input;
7729 vl_api_l2_patch_add_del_t *mp;
7730 f64 timeout;
7731 u32 rx_sw_if_index;
7732 u8 rx_sw_if_index_set = 0;
7733 u32 tx_sw_if_index;
7734 u8 tx_sw_if_index_set = 0;
7735 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007736
Dave Barach72d72232016-08-04 10:15:08 -04007737 /* Parse args required to build the message */
7738 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7739 {
7740 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7741 rx_sw_if_index_set = 1;
7742 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7743 tx_sw_if_index_set = 1;
7744 else if (unformat (i, "rx"))
7745 {
7746 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7747 {
7748 if (unformat (i, "%U", unformat_sw_if_index, vam,
7749 &rx_sw_if_index))
7750 rx_sw_if_index_set = 1;
7751 }
7752 else
7753 break;
7754 }
7755 else if (unformat (i, "tx"))
7756 {
7757 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7758 {
7759 if (unformat (i, "%U", unformat_sw_if_index, vam,
7760 &tx_sw_if_index))
7761 tx_sw_if_index_set = 1;
7762 }
7763 else
7764 break;
7765 }
7766 else if (unformat (i, "del"))
7767 is_add = 0;
7768 else
7769 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007770 }
7771
Dave Barach72d72232016-08-04 10:15:08 -04007772 if (rx_sw_if_index_set == 0)
7773 {
7774 errmsg ("missing rx interface name or rx_sw_if_index\n");
7775 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007776 }
7777
Dave Barach72d72232016-08-04 10:15:08 -04007778 if (tx_sw_if_index_set == 0)
7779 {
7780 errmsg ("missing tx interface name or tx_sw_if_index\n");
7781 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007782 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007783
Dave Barach72d72232016-08-04 10:15:08 -04007784 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007785
Dave Barach72d72232016-08-04 10:15:08 -04007786 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7787 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7788 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007789
Dave Barach72d72232016-08-04 10:15:08 -04007790 S;
7791 W;
7792 /* NOTREACHED */
7793 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007794}
Dave Barach72d72232016-08-04 10:15:08 -04007795
7796static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007797api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007798{
Dave Barach72d72232016-08-04 10:15:08 -04007799 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007800 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007801 f64 timeout;
7802 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007803 int has_trace_option = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007804 int has_pow_option = 0;
7805 int has_ppc_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007806
Shwetha20a64f52016-03-25 10:55:01 +00007807 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7808 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007809 if (unformat (input, "trace"))
7810 has_trace_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007811 else if (unformat (input, "pow"))
Dave Barach72d72232016-08-04 10:15:08 -04007812 has_pow_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007813 else if (unformat (input, "ppc encap"))
Dave Barach72d72232016-08-04 10:15:08 -04007814 has_ppc_option = PPC_ENCAP;
Shwetha20a64f52016-03-25 10:55:01 +00007815 else if (unformat (input, "ppc decap"))
Dave Barach72d72232016-08-04 10:15:08 -04007816 has_ppc_option = PPC_DECAP;
Shwetha20a64f52016-03-25 10:55:01 +00007817 else if (unformat (input, "ppc none"))
Dave Barach72d72232016-08-04 10:15:08 -04007818 has_ppc_option = PPC_NONE;
Shwetha20a64f52016-03-25 10:55:01 +00007819 else
Dave Barach72d72232016-08-04 10:15:08 -04007820 break;
Shwetha20a64f52016-03-25 10:55:01 +00007821 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007822 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007823 mp->id = htons (id);
Shwetha20a64f52016-03-25 10:55:01 +00007824 mp->trace_ppc = has_ppc_option;
Shwetha20a64f52016-03-25 10:55:01 +00007825 mp->pow_enable = has_pow_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007826 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007827
Dave Barach72d72232016-08-04 10:15:08 -04007828 S;
7829 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007830
Dave Barach72d72232016-08-04 10:15:08 -04007831 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007832
Shwetha20a64f52016-03-25 10:55:01 +00007833}
Dave Barach72d72232016-08-04 10:15:08 -04007834
Shwetha20a64f52016-03-25 10:55:01 +00007835
Dave Barach72d72232016-08-04 10:15:08 -04007836static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007837api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007838{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007839 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007840 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007841
Vengada Govindan07d2f842016-08-25 10:34:34 -07007842 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04007843 S;
7844 W;
7845 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00007846}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007847
Dave Barach72d72232016-08-04 10:15:08 -04007848static int
7849api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007850{
Dave Barach72d72232016-08-04 10:15:08 -04007851 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007852 vl_api_sr_tunnel_add_del_t *mp;
7853 f64 timeout;
7854 int is_del = 0;
7855 int pl_index;
7856 ip6_address_t src_address;
7857 int src_address_set = 0;
7858 ip6_address_t dst_address;
7859 u32 dst_mask_width;
7860 int dst_address_set = 0;
7861 u16 flags = 0;
7862 u32 rx_table_id = 0;
7863 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007864 ip6_address_t *segments = 0;
7865 ip6_address_t *this_seg;
7866 ip6_address_t *tags = 0;
7867 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007868 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04007869 u8 *name = 0;
7870 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007871
7872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7873 {
7874 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007875 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007876 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04007877 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007878 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007879 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007880 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007881 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007882 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007883 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007884 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04007885 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007886 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04007887 unformat_ip6_address, &dst_address, &dst_mask_width))
7888 dst_address_set = 1;
7889 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
7890 {
7891 vec_add2 (segments, this_seg, 1);
7892 clib_memcpy (this_seg->as_u8, next_address.as_u8,
7893 sizeof (*this_seg));
7894 }
7895 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
7896 {
7897 vec_add2 (tags, this_tag, 1);
7898 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
7899 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007900 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04007901 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007902 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04007903 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007904 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007905 {
7906 if (pl_index <= 0 || pl_index > 4)
7907 {
7908 pl_index_range_error:
7909 errmsg ("pl index %d out of range\n", pl_index);
7910 return -99;
7911 }
7912 flags |=
7913 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
7914 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007915 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007916 {
7917 if (pl_index <= 0 || pl_index > 4)
7918 goto pl_index_range_error;
7919 flags |=
7920 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
7921 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007922 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007923 {
7924 if (pl_index <= 0 || pl_index > 4)
7925 goto pl_index_range_error;
7926 flags |=
7927 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
7928 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007929 else
Dave Barach72d72232016-08-04 10:15:08 -04007930 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007931 }
7932
7933 if (!src_address_set)
7934 {
7935 errmsg ("src address required\n");
7936 return -99;
7937 }
7938
7939 if (!dst_address_set)
7940 {
7941 errmsg ("dst address required\n");
7942 return -99;
7943 }
7944
7945 if (!segments)
7946 {
7947 errmsg ("at least one sr segment required\n");
7948 return -99;
7949 }
7950
Dave Barach72d72232016-08-04 10:15:08 -04007951 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
7952 vec_len (segments) * sizeof (ip6_address_t)
7953 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007954
Damjan Marionf1213b82016-03-13 02:22:06 +01007955 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
7956 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007957 mp->dst_mask_width = dst_mask_width;
7958 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
7959 mp->n_segments = vec_len (segments);
7960 mp->n_tags = vec_len (tags);
7961 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007962 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04007963 vec_len (segments) * sizeof (ip6_address_t));
7964 clib_memcpy (mp->segs_and_tags +
7965 vec_len (segments) * sizeof (ip6_address_t), tags,
7966 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007967
7968 mp->outer_vrf_id = ntohl (rx_table_id);
7969 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04007970 memcpy (mp->name, name, vec_len (name));
7971 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007972
7973 vec_free (segments);
7974 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007975
Dave Barach72d72232016-08-04 10:15:08 -04007976 S;
7977 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007978 /* NOTREACHED */
7979}
7980
Dave Barach72d72232016-08-04 10:15:08 -04007981static int
7982api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007983{
Dave Barach72d72232016-08-04 10:15:08 -04007984 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007985 vl_api_sr_policy_add_del_t *mp;
7986 f64 timeout;
7987 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007988 u8 *name = 0;
7989 u8 *tunnel_name = 0;
7990 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007991
Dave Barach72d72232016-08-04 10:15:08 -04007992 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007993 int tunnel_set = 0;
7994 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007995 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
7996 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 -07007997
7998 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7999 {
8000 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008001 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008002 else if (unformat (input, "name %s", &name))
8003 name_set = 1;
8004 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04008005 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008006 if (tunnel_name)
8007 {
8008 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008009 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04008010 - length = #bytes to store in serial vector
8011 - +1 = byte to store that length
8012 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008013 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008014 tunnel_set = 1;
8015 tunnel_name = 0;
8016 }
Dave Barach72d72232016-08-04 10:15:08 -04008017 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008018 else
Dave Barach72d72232016-08-04 10:15:08 -04008019 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008020 }
8021
8022 if (!name_set)
8023 {
8024 errmsg ("policy name required\n");
8025 return -99;
8026 }
8027
8028 if ((!tunnel_set) && (!is_del))
8029 {
8030 errmsg ("tunnel name required\n");
8031 return -99;
8032 }
8033
Dave Barach72d72232016-08-04 10:15:08 -04008034 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008035
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008036
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008037
8038 mp->is_add = !is_del;
8039
Dave Barach72d72232016-08-04 10:15:08 -04008040 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008041 // 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 -04008042 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008043 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04008044 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
8045 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008046
Dave Barach72d72232016-08-04 10:15:08 -04008047 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008048 {
8049 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04008050 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
8051 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008052 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04008053 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008054 }
Dave Barach72d72232016-08-04 10:15:08 -04008055 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 -07008056
8057 vec_free (tunnel_names);
8058 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008059
Dave Barach72d72232016-08-04 10:15:08 -04008060 S;
8061 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008062 /* NOTREACHED */
8063}
8064
Dave Barach72d72232016-08-04 10:15:08 -04008065static int
8066api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008067{
Dave Barach72d72232016-08-04 10:15:08 -04008068 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008069 vl_api_sr_multicast_map_add_del_t *mp;
8070 f64 timeout;
8071 int is_del = 0;
8072 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04008073 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008074 int multicast_address_set = 0;
8075
8076 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8077 {
8078 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008079 is_del = 1;
8080 else
8081 if (unformat
8082 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008083 multicast_address_set = 1;
8084 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008085 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008086 else
Dave Barach72d72232016-08-04 10:15:08 -04008087 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008088 }
8089
8090 if (!is_del && !policy_name)
8091 {
8092 errmsg ("sr-policy name required\n");
8093 return -99;
8094 }
8095
8096
8097 if (!multicast_address_set)
8098 {
8099 errmsg ("address required\n");
8100 return -99;
8101 }
8102
Dave Barach72d72232016-08-04 10:15:08 -04008103 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008104
8105 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04008106 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
8107 clib_memcpy (mp->multicast_address, &multicast_address,
8108 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008109
8110
8111 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008112
Dave Barach72d72232016-08-04 10:15:08 -04008113 S;
8114 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008115 /* NOTREACHED */
8116}
8117
Ed Warnickecb9cada2015-12-08 15:45:58 -07008118
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008119#define foreach_tcp_proto_field \
8120_(src_port) \
8121_(dst_port)
8122
8123#define foreach_udp_proto_field \
8124_(src_port) \
8125_(dst_port)
8126
Ed Warnickecb9cada2015-12-08 15:45:58 -07008127#define foreach_ip4_proto_field \
8128_(src_address) \
8129_(dst_address) \
8130_(tos) \
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008131_(length) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008132_(fragment_id) \
8133_(ttl) \
8134_(protocol) \
8135_(checksum)
8136
Dave Barach72d72232016-08-04 10:15:08 -04008137uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008138unformat_tcp_mask (unformat_input_t * input, va_list * args)
8139{
8140 u8 **maskp = va_arg (*args, u8 **);
8141 u8 *mask = 0;
8142 u8 found_something = 0;
8143 tcp_header_t *tcp;
8144
8145#define _(a) u8 a=0;
8146 foreach_tcp_proto_field;
8147#undef _
8148
8149 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8150 {
8151 if (0);
8152#define _(a) else if (unformat (input, #a)) a=1;
8153 foreach_tcp_proto_field
8154#undef _
8155 else
8156 break;
8157 }
8158
8159#define _(a) found_something += a;
8160 foreach_tcp_proto_field;
8161#undef _
8162
8163 if (found_something == 0)
8164 return 0;
8165
8166 vec_validate (mask, sizeof (*tcp) - 1);
8167
8168 tcp = (tcp_header_t *) mask;
8169
8170#define _(a) if (a) memset (&tcp->a, 0xff, sizeof (tcp->a));
8171 foreach_tcp_proto_field;
8172#undef _
8173
8174 *maskp = mask;
8175 return 1;
8176}
8177
8178uword
8179unformat_udp_mask (unformat_input_t * input, va_list * args)
8180{
8181 u8 **maskp = va_arg (*args, u8 **);
8182 u8 *mask = 0;
8183 u8 found_something = 0;
8184 udp_header_t *udp;
8185
8186#define _(a) u8 a=0;
8187 foreach_udp_proto_field;
8188#undef _
8189
8190 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8191 {
8192 if (0);
8193#define _(a) else if (unformat (input, #a)) a=1;
8194 foreach_udp_proto_field
8195#undef _
8196 else
8197 break;
8198 }
8199
8200#define _(a) found_something += a;
8201 foreach_udp_proto_field;
8202#undef _
8203
8204 if (found_something == 0)
8205 return 0;
8206
8207 vec_validate (mask, sizeof (*udp) - 1);
8208
8209 udp = (udp_header_t *) mask;
8210
8211#define _(a) if (a) memset (&udp->a, 0xff, sizeof (udp->a));
8212 foreach_udp_proto_field;
8213#undef _
8214
8215 *maskp = mask;
8216 return 1;
8217}
8218
8219typedef struct
8220{
8221 u16 src_port, dst_port;
8222} tcpudp_header_t;
8223
8224uword
8225unformat_l4_mask (unformat_input_t * input, va_list * args)
8226{
8227 u8 **maskp = va_arg (*args, u8 **);
8228 u16 src_port = 0, dst_port = 0;
8229 tcpudp_header_t *tcpudp;
8230
8231 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8232 {
8233 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
8234 return 1;
8235 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
8236 return 1;
8237 else if (unformat (input, "src_port"))
8238 src_port = 0xFFFF;
8239 else if (unformat (input, "dst_port"))
8240 dst_port = 0xFFFF;
8241 else
8242 return 0;
8243 }
8244
8245 if (!src_port && !dst_port)
8246 return 0;
8247
8248 u8 *mask = 0;
8249 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
8250
8251 tcpudp = (tcpudp_header_t *) mask;
8252 tcpudp->src_port = src_port;
8253 tcpudp->dst_port = dst_port;
8254
8255 *maskp = mask;
8256
8257 return 1;
8258}
8259
8260uword
Dave Barach72d72232016-08-04 10:15:08 -04008261unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008262{
Dave Barach72d72232016-08-04 10:15:08 -04008263 u8 **maskp = va_arg (*args, u8 **);
8264 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008265 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008266 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008267
Ed Warnickecb9cada2015-12-08 15:45:58 -07008268#define _(a) u8 a=0;
8269 foreach_ip4_proto_field;
8270#undef _
8271 u8 version = 0;
8272 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008273
8274
8275 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008276 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008277 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008278 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008279 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04008280 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008281 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008282 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008283 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008284 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008285 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008286 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008287
Ed Warnickecb9cada2015-12-08 15:45:58 -07008288#define _(a) else if (unformat (input, #a)) a=1;
8289 foreach_ip4_proto_field
8290#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008291 else
8292 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008293 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008294
Ed Warnickecb9cada2015-12-08 15:45:58 -07008295#define _(a) found_something += a;
8296 foreach_ip4_proto_field;
8297#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008298
Ed Warnickecb9cada2015-12-08 15:45:58 -07008299 if (found_something == 0)
8300 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008301
Ed Warnickecb9cada2015-12-08 15:45:58 -07008302 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008303
Ed Warnickecb9cada2015-12-08 15:45:58 -07008304 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008305
Ed Warnickecb9cada2015-12-08 15:45:58 -07008306#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8307 foreach_ip4_proto_field;
8308#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008309
Ed Warnickecb9cada2015-12-08 15:45:58 -07008310 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008311
Ed Warnickecb9cada2015-12-08 15:45:58 -07008312 if (version)
8313 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008314
Ed Warnickecb9cada2015-12-08 15:45:58 -07008315 if (hdr_length)
8316 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008317
Ed Warnickecb9cada2015-12-08 15:45:58 -07008318 *maskp = mask;
8319 return 1;
8320}
8321
8322#define foreach_ip6_proto_field \
8323_(src_address) \
8324_(dst_address) \
8325_(payload_length) \
8326_(hop_limit) \
8327_(protocol)
8328
Dave Barach72d72232016-08-04 10:15:08 -04008329uword
8330unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008331{
Dave Barach72d72232016-08-04 10:15:08 -04008332 u8 **maskp = va_arg (*args, u8 **);
8333 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008334 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008335 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008336 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008337
Ed Warnickecb9cada2015-12-08 15:45:58 -07008338#define _(a) u8 a=0;
8339 foreach_ip6_proto_field;
8340#undef _
8341 u8 version = 0;
8342 u8 traffic_class = 0;
8343 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008344
8345 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008346 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008347 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008348 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008349 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04008350 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008351 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04008352 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008353 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008354 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008355 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008356 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008357 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008358 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008359
Ed Warnickecb9cada2015-12-08 15:45:58 -07008360#define _(a) else if (unformat (input, #a)) a=1;
8361 foreach_ip6_proto_field
8362#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008363 else
8364 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008365 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008366
Ed Warnickecb9cada2015-12-08 15:45:58 -07008367#define _(a) found_something += a;
8368 foreach_ip6_proto_field;
8369#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008370
Ed Warnickecb9cada2015-12-08 15:45:58 -07008371 if (found_something == 0)
8372 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008373
Ed Warnickecb9cada2015-12-08 15:45:58 -07008374 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008375
Ed Warnickecb9cada2015-12-08 15:45:58 -07008376 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008377
Ed Warnickecb9cada2015-12-08 15:45:58 -07008378#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8379 foreach_ip6_proto_field;
8380#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008381
Ed Warnickecb9cada2015-12-08 15:45:58 -07008382 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008383
Ed Warnickecb9cada2015-12-08 15:45:58 -07008384 if (version)
8385 ip_version_traffic_class_and_flow_label |= 0xF0000000;
8386
8387 if (traffic_class)
8388 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
8389
8390 if (flow_label)
8391 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
8392
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008393 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008394 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008395
Ed Warnickecb9cada2015-12-08 15:45:58 -07008396 *maskp = mask;
8397 return 1;
8398}
8399
Dave Barach72d72232016-08-04 10:15:08 -04008400uword
8401unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008402{
Dave Barach72d72232016-08-04 10:15:08 -04008403 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008404
Dave Barach72d72232016-08-04 10:15:08 -04008405 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8406 {
8407 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
8408 return 1;
8409 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
8410 return 1;
8411 else
8412 break;
8413 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008414 return 0;
8415}
8416
Dave Barach72d72232016-08-04 10:15:08 -04008417uword
8418unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008419{
Dave Barach72d72232016-08-04 10:15:08 -04008420 u8 **maskp = va_arg (*args, u8 **);
8421 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008422 u8 src = 0;
8423 u8 dst = 0;
8424 u8 proto = 0;
8425 u8 tag1 = 0;
8426 u8 tag2 = 0;
8427 u8 ignore_tag1 = 0;
8428 u8 ignore_tag2 = 0;
8429 u8 cos1 = 0;
8430 u8 cos2 = 0;
8431 u8 dot1q = 0;
8432 u8 dot1ad = 0;
8433 int len = 14;
8434
Dave Barach72d72232016-08-04 10:15:08 -04008435 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8436 {
8437 if (unformat (input, "src"))
8438 src = 1;
8439 else if (unformat (input, "dst"))
8440 dst = 1;
8441 else if (unformat (input, "proto"))
8442 proto = 1;
8443 else if (unformat (input, "tag1"))
8444 tag1 = 1;
8445 else if (unformat (input, "tag2"))
8446 tag2 = 1;
8447 else if (unformat (input, "ignore-tag1"))
8448 ignore_tag1 = 1;
8449 else if (unformat (input, "ignore-tag2"))
8450 ignore_tag2 = 1;
8451 else if (unformat (input, "cos1"))
8452 cos1 = 1;
8453 else if (unformat (input, "cos2"))
8454 cos2 = 1;
8455 else if (unformat (input, "dot1q"))
8456 dot1q = 1;
8457 else if (unformat (input, "dot1ad"))
8458 dot1ad = 1;
8459 else
8460 break;
8461 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008462 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04008463 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008464 return 0;
8465
8466 if (tag1 || ignore_tag1 || cos1 || dot1q)
8467 len = 18;
8468 if (tag2 || ignore_tag2 || cos2 || dot1ad)
8469 len = 22;
8470
Dave Barach72d72232016-08-04 10:15:08 -04008471 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008472
8473 if (dst)
8474 memset (mask, 0xff, 6);
8475
8476 if (src)
8477 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008478
Ed Warnickecb9cada2015-12-08 15:45:58 -07008479 if (tag2 || dot1ad)
8480 {
8481 /* inner vlan tag */
8482 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008483 {
8484 mask[19] = 0xff;
8485 mask[18] = 0x0f;
8486 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008487 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008488 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008489 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008490 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008491 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008492 {
8493 mask[15] = 0xff;
8494 mask[14] = 0x0f;
8495 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008496 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008497 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008498 *maskp = mask;
8499 return 1;
8500 }
8501 if (tag1 | dot1q)
8502 {
8503 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008504 {
8505 mask[15] = 0xff;
8506 mask[14] = 0x0f;
8507 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008508 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008509 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008510 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008511 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008512
8513 *maskp = mask;
8514 return 1;
8515 }
8516 if (cos2)
8517 mask[18] |= 0xe0;
8518 if (cos1)
8519 mask[14] |= 0xe0;
8520 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008521 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008522
Ed Warnickecb9cada2015-12-08 15:45:58 -07008523 *maskp = mask;
8524 return 1;
8525}
8526
Dave Barach72d72232016-08-04 10:15:08 -04008527uword
8528unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008529{
Dave Barach72d72232016-08-04 10:15:08 -04008530 u8 **maskp = va_arg (*args, u8 **);
8531 u32 *skipp = va_arg (*args, u32 *);
8532 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008533 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008534 u8 *mask = 0;
8535 u8 *l2 = 0;
8536 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008537 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008538 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008539
Dave Barach72d72232016-08-04 10:15:08 -04008540 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8541 {
8542 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8543 ;
8544 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8545 ;
8546 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8547 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008548 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
8549 ;
Dave Barach72d72232016-08-04 10:15:08 -04008550 else
8551 break;
8552 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008553
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008554 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008555 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008556 vec_free (mask);
8557 vec_free (l2);
8558 vec_free (l4);
8559 return 0;
8560 }
8561
8562 if (mask || l2 || l3 || l4)
8563 {
8564 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04008565 {
8566 /* "With a free Ethernet header in every package" */
8567 if (l2 == 0)
8568 vec_validate (l2, 13);
8569 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008570 if (vec_len (l3))
8571 {
8572 vec_append (mask, l3);
8573 vec_free (l3);
8574 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008575 if (vec_len (l4))
8576 {
8577 vec_append (mask, l4);
8578 vec_free (l4);
8579 }
Dave Barach72d72232016-08-04 10:15:08 -04008580 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008581
8582 /* Scan forward looking for the first significant mask octet */
8583 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008584 if (mask[i])
8585 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008586
8587 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008588 *skipp = i / sizeof (u32x4);
8589 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008590
8591 /* Pad mask to an even multiple of the vector size */
8592 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008593 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008594
8595 match = vec_len (mask) / sizeof (u32x4);
8596
Dave Barach72d72232016-08-04 10:15:08 -04008597 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8598 {
8599 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8600 if (*tmp || *(tmp + 1))
8601 break;
8602 match--;
8603 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008604 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008605 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008606
Dave Barach72d72232016-08-04 10:15:08 -04008607 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008608
8609 *matchp = match;
8610 *maskp = mask;
8611
8612 return 1;
8613 }
8614
8615 return 0;
8616}
8617
8618#define foreach_l2_next \
8619_(drop, DROP) \
8620_(ethernet, ETHERNET_INPUT) \
8621_(ip4, IP4_INPUT) \
8622_(ip6, IP6_INPUT)
8623
Dave Barach72d72232016-08-04 10:15:08 -04008624uword
8625unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008626{
Dave Barach72d72232016-08-04 10:15:08 -04008627 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008628 u32 next_index = 0;
8629 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008630
Ed Warnickecb9cada2015-12-08 15:45:58 -07008631#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008632 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008633 foreach_l2_next;
8634#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008635
Ed Warnickecb9cada2015-12-08 15:45:58 -07008636 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008637 {
8638 next_index = tmp;
8639 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008640 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008641
Ed Warnickecb9cada2015-12-08 15:45:58 -07008642 return 0;
8643
Dave Barach72d72232016-08-04 10:15:08 -04008644out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008645 *miss_next_indexp = next_index;
8646 return 1;
8647}
8648
8649#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008650_(drop, DROP) \
8651_(local, LOCAL) \
8652_(rewrite, REWRITE)
8653
Dave Barach72d72232016-08-04 10:15:08 -04008654uword
8655unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008656{
Dave Barach72d72232016-08-04 10:15:08 -04008657 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008658 u32 next_index = 0;
8659 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008660
Ed Warnickecb9cada2015-12-08 15:45:58 -07008661#define _(n,N) \
8662 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8663 foreach_ip_next;
8664#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008665
Ed Warnickecb9cada2015-12-08 15:45:58 -07008666 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008667 {
8668 next_index = tmp;
8669 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008670 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008671
Ed Warnickecb9cada2015-12-08 15:45:58 -07008672 return 0;
8673
Dave Barach72d72232016-08-04 10:15:08 -04008674out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008675 *miss_next_indexp = next_index;
8676 return 1;
8677}
8678
8679#define foreach_acl_next \
8680_(deny, DENY)
8681
Dave Barach72d72232016-08-04 10:15:08 -04008682uword
8683unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008684{
Dave Barach72d72232016-08-04 10:15:08 -04008685 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008686 u32 next_index = 0;
8687 u32 tmp;
8688
8689#define _(n,N) \
8690 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8691 foreach_acl_next;
8692#undef _
8693
8694 if (unformat (input, "permit"))
8695 {
8696 next_index = ~0;
8697 goto out;
8698 }
8699 else if (unformat (input, "%d", &tmp))
8700 {
8701 next_index = tmp;
8702 goto out;
8703 }
8704
8705 return 0;
8706
Dave Barach72d72232016-08-04 10:15:08 -04008707out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008708 *miss_next_indexp = next_index;
8709 return 1;
8710}
8711
Dave Barach72d72232016-08-04 10:15:08 -04008712uword
8713unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008714{
Dave Barach72d72232016-08-04 10:15:08 -04008715 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008716
8717 if (unformat (input, "conform-color"))
8718 *r = POLICE_CONFORM;
8719 else if (unformat (input, "exceed-color"))
8720 *r = POLICE_EXCEED;
8721 else
8722 return 0;
8723
8724 return 1;
8725}
8726
Dave Barach72d72232016-08-04 10:15:08 -04008727static int
8728api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008729{
Dave Barach72d72232016-08-04 10:15:08 -04008730 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008731 vl_api_classify_add_del_table_t *mp;
8732
8733 u32 nbuckets = 2;
8734 u32 skip = ~0;
8735 u32 match = ~0;
8736 int is_add = 1;
8737 u32 table_index = ~0;
8738 u32 next_table_index = ~0;
8739 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008740 u32 memory_size = 32 << 20;
8741 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008742 f64 timeout;
8743
Dave Barach72d72232016-08-04 10:15:08 -04008744 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8745 {
8746 if (unformat (i, "del"))
8747 is_add = 0;
8748 else if (unformat (i, "buckets %d", &nbuckets))
8749 ;
8750 else if (unformat (i, "memory_size %d", &memory_size))
8751 ;
8752 else if (unformat (i, "skip %d", &skip))
8753 ;
8754 else if (unformat (i, "match %d", &match))
8755 ;
8756 else if (unformat (i, "table %d", &table_index))
8757 ;
8758 else if (unformat (i, "mask %U", unformat_classify_mask,
8759 &mask, &skip, &match))
8760 ;
8761 else if (unformat (i, "next-table %d", &next_table_index))
8762 ;
8763 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8764 &miss_next_index))
8765 ;
8766 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8767 &miss_next_index))
8768 ;
8769 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8770 &miss_next_index))
8771 ;
8772 else
8773 break;
8774 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008775
Dave Barach72d72232016-08-04 10:15:08 -04008776 if (is_add && mask == 0)
8777 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008778 errmsg ("Mask required\n");
8779 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008780 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008781
Dave Barach72d72232016-08-04 10:15:08 -04008782 if (is_add && skip == ~0)
8783 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008784 errmsg ("skip count required\n");
8785 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008786 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008787
Dave Barach72d72232016-08-04 10:15:08 -04008788 if (is_add && match == ~0)
8789 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008790 errmsg ("match count required\n");
8791 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008792 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008793
Dave Barach72d72232016-08-04 10:15:08 -04008794 if (!is_add && table_index == ~0)
8795 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008796 errmsg ("table index required for delete\n");
8797 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008798 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008799
Dave Barach72d72232016-08-04 10:15:08 -04008800 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008801
8802 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008803 mp->table_index = ntohl (table_index);
8804 mp->nbuckets = ntohl (nbuckets);
8805 mp->memory_size = ntohl (memory_size);
8806 mp->skip_n_vectors = ntohl (skip);
8807 mp->match_n_vectors = ntohl (match);
8808 mp->next_table_index = ntohl (next_table_index);
8809 mp->miss_next_index = ntohl (miss_next_index);
8810 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008811
Dave Barach72d72232016-08-04 10:15:08 -04008812 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008813
Dave Barach72d72232016-08-04 10:15:08 -04008814 S;
8815 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008816 /* NOTREACHED */
8817}
8818
Dave Barach72d72232016-08-04 10:15:08 -04008819uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008820unformat_l4_match (unformat_input_t * input, va_list * args)
8821{
8822 u8 **matchp = va_arg (*args, u8 **);
8823
8824 u8 *proto_header = 0;
8825 int src_port = 0;
8826 int dst_port = 0;
8827
8828 tcpudp_header_t h;
8829
8830 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8831 {
8832 if (unformat (input, "src_port %d", &src_port))
8833 ;
8834 else if (unformat (input, "dst_port %d", &dst_port))
8835 ;
8836 else
8837 return 0;
8838 }
8839
8840 h.src_port = clib_host_to_net_u16 (src_port);
8841 h.dst_port = clib_host_to_net_u16 (dst_port);
8842 vec_validate (proto_header, sizeof (h) - 1);
8843 memcpy (proto_header, &h, sizeof (h));
8844
8845 *matchp = proto_header;
8846
8847 return 1;
8848}
8849
8850uword
Dave Barach72d72232016-08-04 10:15:08 -04008851unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008852{
Dave Barach72d72232016-08-04 10:15:08 -04008853 u8 **matchp = va_arg (*args, u8 **);
8854 u8 *match = 0;
8855 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008856 int version = 0;
8857 u32 version_val;
8858 int hdr_length = 0;
8859 u32 hdr_length_val;
8860 int src = 0, dst = 0;
8861 ip4_address_t src_val, dst_val;
8862 int proto = 0;
8863 u32 proto_val;
8864 int tos = 0;
8865 u32 tos_val;
8866 int length = 0;
8867 u32 length_val;
8868 int fragment_id = 0;
8869 u32 fragment_id_val;
8870 int ttl = 0;
8871 int ttl_val;
8872 int checksum = 0;
8873 u32 checksum_val;
8874
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008875 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008876 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008877 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008878 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008879 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008880 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008881 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008882 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008883 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008884 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008885 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008886 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008887 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04008888 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008889 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008890 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008891 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04008892 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008893 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04008894 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008895 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04008896 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008897 else
Dave Barach72d72232016-08-04 10:15:08 -04008898 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008899 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008900
Ed Warnickecb9cada2015-12-08 15:45:58 -07008901 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8902 + ttl + checksum == 0)
8903 return 0;
8904
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008905 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008906 * Aligned because we use the real comparison functions
8907 */
Dave Barach72d72232016-08-04 10:15:08 -04008908 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008909
Ed Warnickecb9cada2015-12-08 15:45:58 -07008910 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008911
Ed Warnickecb9cada2015-12-08 15:45:58 -07008912 /* These are realistically matched in practice */
8913 if (src)
8914 ip->src_address.as_u32 = src_val.as_u32;
8915
8916 if (dst)
8917 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008918
Ed Warnickecb9cada2015-12-08 15:45:58 -07008919 if (proto)
8920 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008921
Ed Warnickecb9cada2015-12-08 15:45:58 -07008922
8923 /* These are not, but they're included for completeness */
8924 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04008925 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008926
8927 if (hdr_length)
8928 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008929
Ed Warnickecb9cada2015-12-08 15:45:58 -07008930 if (tos)
8931 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008932
Ed Warnickecb9cada2015-12-08 15:45:58 -07008933 if (length)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008934 ip->length = clib_host_to_net_u16 (length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008935
Ed Warnickecb9cada2015-12-08 15:45:58 -07008936 if (ttl)
8937 ip->ttl = ttl_val;
8938
8939 if (checksum)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008940 ip->checksum = clib_host_to_net_u16 (checksum_val);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008941
8942 *matchp = match;
8943 return 1;
8944}
8945
Dave Barach72d72232016-08-04 10:15:08 -04008946uword
8947unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008948{
Dave Barach72d72232016-08-04 10:15:08 -04008949 u8 **matchp = va_arg (*args, u8 **);
8950 u8 *match = 0;
8951 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008952 int version = 0;
8953 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04008954 u8 traffic_class = 0;
8955 u32 traffic_class_val = 0;
8956 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008957 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008958 int src = 0, dst = 0;
8959 ip6_address_t src_val, dst_val;
8960 int proto = 0;
8961 u32 proto_val;
8962 int payload_length = 0;
8963 u32 payload_length_val;
8964 int hop_limit = 0;
8965 int hop_limit_val;
8966 u32 ip_version_traffic_class_and_flow_label;
8967
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008968 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008969 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008970 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008971 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008972 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04008973 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008974 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04008975 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008976 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008977 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008978 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008979 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008980 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008981 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008982 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008983 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008984 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04008985 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008986 else
Dave Barach72d72232016-08-04 10:15:08 -04008987 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008988 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008989
Ed Warnickecb9cada2015-12-08 15:45:58 -07008990 if (version + traffic_class + flow_label + src + dst + proto +
8991 payload_length + hop_limit == 0)
8992 return 0;
8993
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008994 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008995 * Aligned because we use the real comparison functions
8996 */
Dave Barach72d72232016-08-04 10:15:08 -04008997 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008998
Ed Warnickecb9cada2015-12-08 15:45:58 -07008999 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009000
Ed Warnickecb9cada2015-12-08 15:45:58 -07009001 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009002 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009003
9004 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009005 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009006
Ed Warnickecb9cada2015-12-08 15:45:58 -07009007 if (proto)
9008 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009009
Ed Warnickecb9cada2015-12-08 15:45:58 -07009010 ip_version_traffic_class_and_flow_label = 0;
9011
9012 if (version)
9013 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
9014
9015 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04009016 ip_version_traffic_class_and_flow_label |=
9017 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009018
9019 if (flow_label)
9020 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009021
9022 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07009023 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
9024
9025 if (payload_length)
9026 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009027
Ed Warnickecb9cada2015-12-08 15:45:58 -07009028 if (hop_limit)
9029 ip->hop_limit = hop_limit_val;
9030
9031 *matchp = match;
9032 return 1;
9033}
9034
Dave Barach72d72232016-08-04 10:15:08 -04009035uword
9036unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009037{
Dave Barach72d72232016-08-04 10:15:08 -04009038 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009039
Dave Barach72d72232016-08-04 10:15:08 -04009040 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9041 {
9042 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
9043 return 1;
9044 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
9045 return 1;
9046 else
9047 break;
9048 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009049 return 0;
9050}
9051
Dave Barach72d72232016-08-04 10:15:08 -04009052uword
9053unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009054{
Dave Barach72d72232016-08-04 10:15:08 -04009055 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009056 u32 tag;
9057
Dave Barach72d72232016-08-04 10:15:08 -04009058 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07009059 {
Dave Barach72d72232016-08-04 10:15:08 -04009060 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009061 tagp[1] = tag & 0xFF;
9062 return 1;
9063 }
9064
9065 return 0;
9066}
9067
Dave Barach72d72232016-08-04 10:15:08 -04009068uword
9069unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009070{
Dave Barach72d72232016-08-04 10:15:08 -04009071 u8 **matchp = va_arg (*args, u8 **);
9072 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009073 u8 src = 0;
9074 u8 src_val[6];
9075 u8 dst = 0;
9076 u8 dst_val[6];
9077 u8 proto = 0;
9078 u16 proto_val;
9079 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009080 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009081 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009082 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009083 int len = 14;
9084 u8 ignore_tag1 = 0;
9085 u8 ignore_tag2 = 0;
9086 u8 cos1 = 0;
9087 u8 cos2 = 0;
9088 u32 cos1_val = 0;
9089 u32 cos2_val = 0;
9090
Dave Barach72d72232016-08-04 10:15:08 -04009091 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9092 {
9093 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
9094 src = 1;
9095 else
9096 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
9097 dst = 1;
9098 else if (unformat (input, "proto %U",
9099 unformat_ethernet_type_host_byte_order, &proto_val))
9100 proto = 1;
9101 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
9102 tag1 = 1;
9103 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
9104 tag2 = 1;
9105 else if (unformat (input, "ignore-tag1"))
9106 ignore_tag1 = 1;
9107 else if (unformat (input, "ignore-tag2"))
9108 ignore_tag2 = 1;
9109 else if (unformat (input, "cos1 %d", &cos1_val))
9110 cos1 = 1;
9111 else if (unformat (input, "cos2 %d", &cos2_val))
9112 cos2 = 1;
9113 else
9114 break;
9115 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009116 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04009117 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009118 return 0;
9119
9120 if (tag1 || ignore_tag1 || cos1)
9121 len = 18;
9122 if (tag2 || ignore_tag2 || cos2)
9123 len = 22;
9124
Dave Barach72d72232016-08-04 10:15:08 -04009125 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009126
9127 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009128 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009129
9130 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009131 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009132
Ed Warnickecb9cada2015-12-08 15:45:58 -07009133 if (tag2)
9134 {
9135 /* inner vlan tag */
9136 match[19] = tag2_val[1];
9137 match[18] = tag2_val[0];
9138 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009139 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009140 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009141 {
9142 match[21] = proto_val & 0xff;
9143 match[20] = proto_val >> 8;
9144 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009145 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04009146 {
9147 match[15] = tag1_val[1];
9148 match[14] = tag1_val[0];
9149 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009150 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009151 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009152 *matchp = match;
9153 return 1;
9154 }
9155 if (tag1)
9156 {
Dave Barach72d72232016-08-04 10:15:08 -04009157 match[15] = tag1_val[1];
9158 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009159 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009160 {
9161 match[17] = proto_val & 0xff;
9162 match[16] = proto_val >> 8;
9163 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009164 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009165 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009166
9167 *matchp = match;
9168 return 1;
9169 }
9170 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009171 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009172 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009173 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009174 if (proto)
9175 {
9176 match[13] = proto_val & 0xff;
9177 match[12] = proto_val >> 8;
9178 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009179
Ed Warnickecb9cada2015-12-08 15:45:58 -07009180 *matchp = match;
9181 return 1;
9182}
9183
9184
Dave Barach72d72232016-08-04 10:15:08 -04009185uword
9186unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009187{
Dave Barach72d72232016-08-04 10:15:08 -04009188 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009189 u32 skip_n_vectors = va_arg (*args, u32);
9190 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009191
Dave Barach72d72232016-08-04 10:15:08 -04009192 u8 *match = 0;
9193 u8 *l2 = 0;
9194 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009195 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009196
Dave Barach72d72232016-08-04 10:15:08 -04009197 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9198 {
9199 if (unformat (input, "hex %U", unformat_hex_string, &match))
9200 ;
9201 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
9202 ;
9203 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
9204 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009205 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
9206 ;
Dave Barach72d72232016-08-04 10:15:08 -04009207 else
9208 break;
9209 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009210
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009211 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009212 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009213 vec_free (match);
9214 vec_free (l2);
9215 vec_free (l4);
9216 return 0;
9217 }
9218
9219 if (match || l2 || l3 || l4)
9220 {
9221 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04009222 {
9223 /* "Win a free Ethernet header in every packet" */
9224 if (l2 == 0)
9225 vec_validate_aligned (l2, 13, sizeof (u32x4));
9226 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04009227 if (vec_len (l3))
9228 {
9229 vec_append_aligned (match, l3, sizeof (u32x4));
9230 vec_free (l3);
9231 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009232 if (vec_len (l4))
9233 {
9234 vec_append_aligned (match, l4, sizeof (u32x4));
9235 vec_free (l4);
9236 }
Dave Barach72d72232016-08-04 10:15:08 -04009237 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009238
9239 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009240 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04009241 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
9242 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009243
Dave Barach72d72232016-08-04 10:15:08 -04009244 /* Set size, include skipped vectors */
9245 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009246
9247 *matchp = match;
9248
9249 return 1;
9250 }
9251
9252 return 0;
9253}
9254
Dave Barach72d72232016-08-04 10:15:08 -04009255static int
9256api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009257{
Dave Barach72d72232016-08-04 10:15:08 -04009258 unformat_input_t *i = vam->input;
9259 vl_api_classify_add_del_session_t *mp;
9260 int is_add = 1;
9261 u32 table_index = ~0;
9262 u32 hit_next_index = ~0;
9263 u32 opaque_index = ~0;
9264 u8 *match = 0;
9265 i32 advance = 0;
9266 f64 timeout;
9267 u32 skip_n_vectors = 0;
9268 u32 match_n_vectors = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009269
Dave Barach72d72232016-08-04 10:15:08 -04009270 /*
9271 * Warning: you have to supply skip_n and match_n
9272 * because the API client cant simply look at the classify
9273 * table object.
9274 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009275
Dave Barach72d72232016-08-04 10:15:08 -04009276 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9277 {
9278 if (unformat (i, "del"))
9279 is_add = 0;
9280 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
9281 &hit_next_index))
9282 ;
9283 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
9284 &hit_next_index))
9285 ;
9286 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
9287 &hit_next_index))
9288 ;
9289 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
9290 ;
9291 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
9292 ;
9293 else if (unformat (i, "opaque-index %d", &opaque_index))
9294 ;
9295 else if (unformat (i, "skip_n %d", &skip_n_vectors))
9296 ;
9297 else if (unformat (i, "match_n %d", &match_n_vectors))
9298 ;
9299 else if (unformat (i, "match %U", unformat_classify_match,
9300 &match, skip_n_vectors, match_n_vectors))
9301 ;
9302 else if (unformat (i, "advance %d", &advance))
9303 ;
9304 else if (unformat (i, "table-index %d", &table_index))
9305 ;
9306 else
9307 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009308 }
9309
Dave Barach72d72232016-08-04 10:15:08 -04009310 if (table_index == ~0)
9311 {
9312 errmsg ("Table index required\n");
9313 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009314 }
9315
Dave Barach72d72232016-08-04 10:15:08 -04009316 if (is_add && match == 0)
9317 {
9318 errmsg ("Match value required\n");
9319 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009320 }
9321
Dave Barach72d72232016-08-04 10:15:08 -04009322 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009323
Dave Barach72d72232016-08-04 10:15:08 -04009324 mp->is_add = is_add;
9325 mp->table_index = ntohl (table_index);
9326 mp->hit_next_index = ntohl (hit_next_index);
9327 mp->opaque_index = ntohl (opaque_index);
9328 mp->advance = ntohl (advance);
9329 clib_memcpy (mp->match, match, vec_len (match));
9330 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009331
Dave Barach72d72232016-08-04 10:15:08 -04009332 S;
9333 W;
9334 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009335}
9336
Dave Barach72d72232016-08-04 10:15:08 -04009337static int
9338api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009339{
Dave Barach72d72232016-08-04 10:15:08 -04009340 unformat_input_t *i = vam->input;
9341 vl_api_classify_set_interface_ip_table_t *mp;
9342 f64 timeout;
9343 u32 sw_if_index;
9344 int sw_if_index_set;
9345 u32 table_index = ~0;
9346 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009347
Dave Barach72d72232016-08-04 10:15:08 -04009348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9349 {
9350 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9351 sw_if_index_set = 1;
9352 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9353 sw_if_index_set = 1;
9354 else if (unformat (i, "table %d", &table_index))
9355 ;
9356 else
9357 {
9358 clib_warning ("parse error '%U'", format_unformat_error, i);
9359 return -99;
9360 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009361 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009362
Dave Barach72d72232016-08-04 10:15:08 -04009363 if (sw_if_index_set == 0)
9364 {
9365 errmsg ("missing interface name or sw_if_index\n");
9366 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009367 }
9368
9369
Dave Barach72d72232016-08-04 10:15:08 -04009370 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009371
Dave Barach72d72232016-08-04 10:15:08 -04009372 mp->sw_if_index = ntohl (sw_if_index);
9373 mp->table_index = ntohl (table_index);
9374 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009375
Dave Barach72d72232016-08-04 10:15:08 -04009376 S;
9377 W;
9378 /* NOTREACHED */
9379 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009380}
9381
Dave Barach72d72232016-08-04 10:15:08 -04009382static int
9383api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009384{
Dave Barach72d72232016-08-04 10:15:08 -04009385 unformat_input_t *i = vam->input;
9386 vl_api_classify_set_interface_l2_tables_t *mp;
9387 f64 timeout;
9388 u32 sw_if_index;
9389 int sw_if_index_set;
9390 u32 ip4_table_index = ~0;
9391 u32 ip6_table_index = ~0;
9392 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04009393 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009394
Dave Barach72d72232016-08-04 10:15:08 -04009395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9396 {
9397 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9398 sw_if_index_set = 1;
9399 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9400 sw_if_index_set = 1;
9401 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9402 ;
9403 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9404 ;
9405 else if (unformat (i, "other-table %d", &other_table_index))
9406 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04009407 else if (unformat (i, "is-input %d", &is_input))
9408 ;
Dave Barach72d72232016-08-04 10:15:08 -04009409 else
9410 {
9411 clib_warning ("parse error '%U'", format_unformat_error, i);
9412 return -99;
9413 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009414 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009415
Dave Barach72d72232016-08-04 10:15:08 -04009416 if (sw_if_index_set == 0)
9417 {
9418 errmsg ("missing interface name or sw_if_index\n");
9419 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009420 }
9421
9422
Dave Barach72d72232016-08-04 10:15:08 -04009423 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009424
Dave Barach72d72232016-08-04 10:15:08 -04009425 mp->sw_if_index = ntohl (sw_if_index);
9426 mp->ip4_table_index = ntohl (ip4_table_index);
9427 mp->ip6_table_index = ntohl (ip6_table_index);
9428 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04009429 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009430
Dave Barach72d72232016-08-04 10:15:08 -04009431 S;
9432 W;
9433 /* NOTREACHED */
9434 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009435}
9436
Dave Barach72d72232016-08-04 10:15:08 -04009437static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009438api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009439{
Dave Barach72d72232016-08-04 10:15:08 -04009440 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009441 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04009442 ip4_address_t collector_address;
9443 u8 collector_address_set = 0;
9444 u32 collector_port = ~0;
9445 ip4_address_t src_address;
9446 u8 src_address_set = 0;
9447 u32 vrf_id = ~0;
9448 u32 path_mtu = ~0;
9449 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009450 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009451 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009452
Dave Barach72d72232016-08-04 10:15:08 -04009453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9454 {
9455 if (unformat (i, "collector_address %U", unformat_ip4_address,
9456 &collector_address))
9457 collector_address_set = 1;
9458 else if (unformat (i, "collector_port %d", &collector_port))
9459 ;
9460 else if (unformat (i, "src_address %U", unformat_ip4_address,
9461 &src_address))
9462 src_address_set = 1;
9463 else if (unformat (i, "vrf_id %d", &vrf_id))
9464 ;
9465 else if (unformat (i, "path_mtu %d", &path_mtu))
9466 ;
9467 else if (unformat (i, "template_interval %d", &template_interval))
9468 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009469 else if (unformat (i, "udp_checksum"))
9470 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009471 else
9472 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009473 }
9474
Dave Barach72d72232016-08-04 10:15:08 -04009475 if (collector_address_set == 0)
9476 {
9477 errmsg ("collector_address required\n");
9478 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009479 }
9480
Dave Barach72d72232016-08-04 10:15:08 -04009481 if (src_address_set == 0)
9482 {
9483 errmsg ("src_address required\n");
9484 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009485 }
9486
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009487 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009488
Dave Barach72d72232016-08-04 10:15:08 -04009489 memcpy (mp->collector_address, collector_address.data,
9490 sizeof (collector_address.data));
9491 mp->collector_port = htons ((u16) collector_port);
9492 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
9493 mp->vrf_id = htonl (vrf_id);
9494 mp->path_mtu = htonl (path_mtu);
9495 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009496 mp->udp_checksum = udp_checksum;
9497
9498 S;
9499 W;
9500 /* NOTREACHED */
9501}
9502
9503static int
9504api_set_ipfix_classify_stream (vat_main_t * vam)
9505{
9506 unformat_input_t *i = vam->input;
9507 vl_api_set_ipfix_classify_stream_t *mp;
9508 u32 domain_id = 0;
9509 u32 src_port = UDP_DST_PORT_ipfix;
9510 f64 timeout;
9511
9512 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9513 {
9514 if (unformat (i, "domain %d", &domain_id))
9515 ;
9516 else if (unformat (i, "src_port %d", &src_port))
9517 ;
9518 else
9519 {
9520 errmsg ("unknown input `%U'", format_unformat_error, i);
9521 return -99;
9522 }
9523 }
9524
9525 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
9526
9527 mp->domain_id = htonl (domain_id);
9528 mp->src_port = htons ((u16) src_port);
9529
9530 S;
9531 W;
9532 /* NOTREACHED */
9533}
9534
9535static int
9536api_ipfix_classify_table_add_del (vat_main_t * vam)
9537{
9538 unformat_input_t *i = vam->input;
9539 vl_api_ipfix_classify_table_add_del_t *mp;
9540 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009541 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009542 u8 ip_version = 0;
9543 u8 transport_protocol = 255;
9544 f64 timeout;
9545
9546 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9547 {
9548 if (unformat (i, "add"))
9549 is_add = 1;
9550 else if (unformat (i, "del"))
9551 is_add = 0;
9552 else if (unformat (i, "table %d", &classify_table_index))
9553 ;
9554 else if (unformat (i, "ip4"))
9555 ip_version = 4;
9556 else if (unformat (i, "ip6"))
9557 ip_version = 6;
9558 else if (unformat (i, "tcp"))
9559 transport_protocol = 6;
9560 else if (unformat (i, "udp"))
9561 transport_protocol = 17;
9562 else
9563 {
9564 errmsg ("unknown input `%U'", format_unformat_error, i);
9565 return -99;
9566 }
9567 }
9568
9569 if (is_add == -1)
9570 {
9571 errmsg ("expecting: add|del");
9572 return -99;
9573 }
9574 if (classify_table_index == ~0)
9575 {
9576 errmsg ("classifier table not specified");
9577 return -99;
9578 }
9579 if (ip_version == 0)
9580 {
9581 errmsg ("IP version not specified");
9582 return -99;
9583 }
9584
9585 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9586
9587 mp->is_add = is_add;
9588 mp->table_id = htonl (classify_table_index);
9589 mp->ip_version = ip_version;
9590 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009591
Dave Barach72d72232016-08-04 10:15:08 -04009592 S;
9593 W;
9594 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009595}
9596
Dave Barach72d72232016-08-04 10:15:08 -04009597static int
9598api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009599{
Dave Barach72d72232016-08-04 10:15:08 -04009600 unformat_input_t *i = vam->input;
9601 vl_api_get_node_index_t *mp;
9602 f64 timeout;
9603 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009604
Dave Barach72d72232016-08-04 10:15:08 -04009605 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9606 {
9607 if (unformat (i, "node %s", &name))
9608 ;
9609 else
9610 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009611 }
Dave Barach72d72232016-08-04 10:15:08 -04009612 if (name == 0)
9613 {
9614 errmsg ("node name required\n");
9615 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009616 }
Dave Barach72d72232016-08-04 10:15:08 -04009617 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9618 {
9619 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9620 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009621 }
9622
Dave Barach72d72232016-08-04 10:15:08 -04009623 M (GET_NODE_INDEX, get_node_index);
9624 clib_memcpy (mp->node_name, name, vec_len (name));
9625 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009626
Dave Barach72d72232016-08-04 10:15:08 -04009627 S;
9628 W;
9629 /* NOTREACHED */
9630 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009631}
9632
Dave Barach72d72232016-08-04 10:15:08 -04009633static int
9634api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009635{
Dave Barach72d72232016-08-04 10:15:08 -04009636 unformat_input_t *i = vam->input;
9637 vl_api_get_next_index_t *mp;
9638 f64 timeout;
9639 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009640
Dave Barach72d72232016-08-04 10:15:08 -04009641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9642 {
9643 if (unformat (i, "node-name %s", &node_name))
9644 ;
9645 else if (unformat (i, "next-node-name %s", &next_node_name))
9646 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009647 }
9648
Dave Barach72d72232016-08-04 10:15:08 -04009649 if (node_name == 0)
9650 {
9651 errmsg ("node name required\n");
9652 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009653 }
Dave Barach72d72232016-08-04 10:15:08 -04009654 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9655 {
9656 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9657 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009658 }
9659
Dave Barach72d72232016-08-04 10:15:08 -04009660 if (next_node_name == 0)
9661 {
9662 errmsg ("next node name required\n");
9663 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009664 }
Dave Barach72d72232016-08-04 10:15:08 -04009665 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9666 {
9667 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9668 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009669 }
9670
Dave Barach72d72232016-08-04 10:15:08 -04009671 M (GET_NEXT_INDEX, get_next_index);
9672 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9673 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9674 vec_free (node_name);
9675 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009676
Dave Barach72d72232016-08-04 10:15:08 -04009677 S;
9678 W;
9679 /* NOTREACHED */
9680 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009681}
9682
Dave Barach72d72232016-08-04 10:15:08 -04009683static int
9684api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009685{
Dave Barach72d72232016-08-04 10:15:08 -04009686 unformat_input_t *i = vam->input;
9687 vl_api_add_node_next_t *mp;
9688 f64 timeout;
9689 u8 *name = 0;
9690 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009691
Dave Barach72d72232016-08-04 10:15:08 -04009692 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9693 {
9694 if (unformat (i, "node %s", &name))
9695 ;
9696 else if (unformat (i, "next %s", &next))
9697 ;
9698 else
9699 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009700 }
Dave Barach72d72232016-08-04 10:15:08 -04009701 if (name == 0)
9702 {
9703 errmsg ("node name required\n");
9704 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009705 }
Dave Barach72d72232016-08-04 10:15:08 -04009706 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9707 {
9708 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9709 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009710 }
Dave Barach72d72232016-08-04 10:15:08 -04009711 if (next == 0)
9712 {
9713 errmsg ("next node required\n");
9714 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009715 }
Dave Barach72d72232016-08-04 10:15:08 -04009716 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9717 {
9718 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9719 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009720 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009721
Dave Barach72d72232016-08-04 10:15:08 -04009722 M (ADD_NODE_NEXT, add_node_next);
9723 clib_memcpy (mp->node_name, name, vec_len (name));
9724 clib_memcpy (mp->next_name, next, vec_len (next));
9725 vec_free (name);
9726 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009727
Dave Barach72d72232016-08-04 10:15:08 -04009728 S;
9729 W;
9730 /* NOTREACHED */
9731 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009732}
9733
Dave Barach72d72232016-08-04 10:15:08 -04009734static int
9735api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009736{
Dave Barach72d72232016-08-04 10:15:08 -04009737 unformat_input_t *i = vam->input;
9738 ip6_address_t client_address, our_address;
9739 int client_address_set = 0;
9740 int our_address_set = 0;
9741 u32 local_session_id = 0;
9742 u32 remote_session_id = 0;
9743 u64 local_cookie = 0;
9744 u64 remote_cookie = 0;
9745 u8 l2_sublayer_present = 0;
9746 vl_api_l2tpv3_create_tunnel_t *mp;
9747 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009748
Dave Barach72d72232016-08-04 10:15:08 -04009749 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9750 {
9751 if (unformat (i, "client_address %U", unformat_ip6_address,
9752 &client_address))
9753 client_address_set = 1;
9754 else if (unformat (i, "our_address %U", unformat_ip6_address,
9755 &our_address))
9756 our_address_set = 1;
9757 else if (unformat (i, "local_session_id %d", &local_session_id))
9758 ;
9759 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9760 ;
9761 else if (unformat (i, "local_cookie %lld", &local_cookie))
9762 ;
9763 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9764 ;
9765 else if (unformat (i, "l2-sublayer-present"))
9766 l2_sublayer_present = 1;
9767 else
9768 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009769 }
9770
Dave Barach72d72232016-08-04 10:15:08 -04009771 if (client_address_set == 0)
9772 {
9773 errmsg ("client_address required\n");
9774 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009775 }
9776
Dave Barach72d72232016-08-04 10:15:08 -04009777 if (our_address_set == 0)
9778 {
9779 errmsg ("our_address required\n");
9780 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009781 }
9782
Dave Barach72d72232016-08-04 10:15:08 -04009783 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009784
Dave Barach72d72232016-08-04 10:15:08 -04009785 clib_memcpy (mp->client_address, client_address.as_u8,
9786 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009787
Dave Barach72d72232016-08-04 10:15:08 -04009788 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009789
Dave Barach72d72232016-08-04 10:15:08 -04009790 mp->local_session_id = ntohl (local_session_id);
9791 mp->remote_session_id = ntohl (remote_session_id);
9792 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9793 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9794 mp->l2_sublayer_present = l2_sublayer_present;
9795 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009796
Dave Barach72d72232016-08-04 10:15:08 -04009797 S;
9798 W;
9799 /* NOTREACHED */
9800 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009801}
9802
Dave Barach72d72232016-08-04 10:15:08 -04009803static int
9804api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009805{
Dave Barach72d72232016-08-04 10:15:08 -04009806 unformat_input_t *i = vam->input;
9807 u32 sw_if_index;
9808 u8 sw_if_index_set = 0;
9809 u64 new_local_cookie = 0;
9810 u64 new_remote_cookie = 0;
9811 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9812 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009813
Dave Barach72d72232016-08-04 10:15:08 -04009814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9815 {
9816 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9817 sw_if_index_set = 1;
9818 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9819 sw_if_index_set = 1;
9820 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9821 ;
9822 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
9823 ;
9824 else
9825 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009826 }
9827
Dave Barach72d72232016-08-04 10:15:08 -04009828 if (sw_if_index_set == 0)
9829 {
9830 errmsg ("missing interface name or sw_if_index\n");
9831 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009832 }
9833
Dave Barach72d72232016-08-04 10:15:08 -04009834 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009835
Dave Barach72d72232016-08-04 10:15:08 -04009836 mp->sw_if_index = ntohl (sw_if_index);
9837 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
9838 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009839
Dave Barach72d72232016-08-04 10:15:08 -04009840 S;
9841 W;
9842 /* NOTREACHED */
9843 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009844}
9845
Dave Barach72d72232016-08-04 10:15:08 -04009846static int
9847api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009848{
Dave Barach72d72232016-08-04 10:15:08 -04009849 unformat_input_t *i = vam->input;
9850 vl_api_l2tpv3_interface_enable_disable_t *mp;
9851 f64 timeout;
9852 u32 sw_if_index;
9853 u8 sw_if_index_set = 0;
9854 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009855
Dave Barach72d72232016-08-04 10:15:08 -04009856 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9857 {
9858 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9859 sw_if_index_set = 1;
9860 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9861 sw_if_index_set = 1;
9862 else if (unformat (i, "enable"))
9863 enable_disable = 1;
9864 else if (unformat (i, "disable"))
9865 enable_disable = 0;
9866 else
9867 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009868 }
9869
Dave Barach72d72232016-08-04 10:15:08 -04009870 if (sw_if_index_set == 0)
9871 {
9872 errmsg ("missing interface name or sw_if_index\n");
9873 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009874 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009875
Dave Barach72d72232016-08-04 10:15:08 -04009876 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009877
Dave Barach72d72232016-08-04 10:15:08 -04009878 mp->sw_if_index = ntohl (sw_if_index);
9879 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009880
Dave Barach72d72232016-08-04 10:15:08 -04009881 S;
9882 W;
9883 /* NOTREACHED */
9884 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009885}
9886
Dave Barach72d72232016-08-04 10:15:08 -04009887static int
9888api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009889{
Dave Barach72d72232016-08-04 10:15:08 -04009890 unformat_input_t *i = vam->input;
9891 vl_api_l2tpv3_set_lookup_key_t *mp;
9892 f64 timeout;
9893 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009894
Dave Barach72d72232016-08-04 10:15:08 -04009895 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9896 {
9897 if (unformat (i, "lookup_v6_src"))
9898 key = L2T_LOOKUP_SRC_ADDRESS;
9899 else if (unformat (i, "lookup_v6_dst"))
9900 key = L2T_LOOKUP_DST_ADDRESS;
9901 else if (unformat (i, "lookup_session_id"))
9902 key = L2T_LOOKUP_SESSION_ID;
9903 else
9904 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009905 }
9906
Dave Barach72d72232016-08-04 10:15:08 -04009907 if (key == (u8) ~ 0)
9908 {
9909 errmsg ("l2tp session lookup key unset\n");
9910 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009911 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009912
Dave Barach72d72232016-08-04 10:15:08 -04009913 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009914
Dave Barach72d72232016-08-04 10:15:08 -04009915 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009916
Dave Barach72d72232016-08-04 10:15:08 -04009917 S;
9918 W;
9919 /* NOTREACHED */
9920 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009921}
9922
9923static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009924 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009925{
Dave Barach72d72232016-08-04 10:15:08 -04009926 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009927
Dave Barach72d72232016-08-04 10:15:08 -04009928 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
9929 format_ip6_address, mp->our_address,
9930 format_ip6_address, mp->client_address,
9931 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009932
Dave Barach72d72232016-08-04 10:15:08 -04009933 fformat (vam->ofp,
9934 " local cookies %016llx %016llx remote cookie %016llx\n",
9935 clib_net_to_host_u64 (mp->local_cookie[0]),
9936 clib_net_to_host_u64 (mp->local_cookie[1]),
9937 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009938
Dave Barach72d72232016-08-04 10:15:08 -04009939 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
9940 clib_net_to_host_u32 (mp->local_session_id),
9941 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009942
Dave Barach72d72232016-08-04 10:15:08 -04009943 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
9944 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009945
9946}
9947
9948static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009949 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009950{
Dave Barach72d72232016-08-04 10:15:08 -04009951 vat_main_t *vam = &vat_main;
9952 vat_json_node_t *node = NULL;
9953 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009954
Dave Barach72d72232016-08-04 10:15:08 -04009955 if (VAT_JSON_ARRAY != vam->json_tree.type)
9956 {
9957 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9958 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009959 }
Dave Barach72d72232016-08-04 10:15:08 -04009960 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009961
Dave Barach72d72232016-08-04 10:15:08 -04009962 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009963
Dave Barach72d72232016-08-04 10:15:08 -04009964 clib_memcpy (&addr, mp->our_address, sizeof (addr));
9965 vat_json_object_add_ip6 (node, "our_address", addr);
9966 clib_memcpy (&addr, mp->client_address, sizeof (addr));
9967 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009968
Dave Barach72d72232016-08-04 10:15:08 -04009969 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
9970 vat_json_init_array (lc);
9971 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
9972 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
9973 vat_json_object_add_uint (node, "remote_cookie",
9974 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009975
Dave Barach72d72232016-08-04 10:15:08 -04009976 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
9977 vat_json_object_add_uint (node, "local_session_id",
9978 clib_net_to_host_u32 (mp->local_session_id));
9979 vat_json_object_add_uint (node, "remote_session_id",
9980 clib_net_to_host_u32 (mp->remote_session_id));
9981 vat_json_object_add_string_copy (node, "l2_sublayer",
9982 mp->l2_sublayer_present ? (u8 *) "present"
9983 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009984}
9985
Dave Barach72d72232016-08-04 10:15:08 -04009986static int
9987api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009988{
Dave Barach72d72232016-08-04 10:15:08 -04009989 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
9990 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009991
Dave Barach72d72232016-08-04 10:15:08 -04009992 /* Get list of l2tpv3-tunnel interfaces */
9993 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
9994 S;
9995
9996 /* Use a control ping for synchronization */
9997 {
9998 vl_api_control_ping_t *mp;
9999 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010000 S;
Dave Barach72d72232016-08-04 10:15:08 -040010001 }
10002 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010003}
10004
10005
10006static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010007 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010008{
Dave Barach72d72232016-08-04 10:15:08 -040010009 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010010
Dave Barach72d72232016-08-04 10:15:08 -040010011 fformat (vam->ofp, "%-16s %d\n",
10012 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010013}
10014
10015static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010016 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010017{
Dave Barach72d72232016-08-04 10:15:08 -040010018 vat_main_t *vam = &vat_main;
10019 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010020
Dave Barach72d72232016-08-04 10:15:08 -040010021 if (VAT_JSON_ARRAY != vam->json_tree.type)
10022 {
10023 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10024 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010025 }
Dave Barach72d72232016-08-04 10:15:08 -040010026 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010027
Dave Barach72d72232016-08-04 10:15:08 -040010028 vat_json_init_object (node);
10029 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10030 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010031}
10032
Dave Barach72d72232016-08-04 10:15:08 -040010033static int
10034api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010035{
Dave Barach72d72232016-08-04 10:15:08 -040010036 vl_api_sw_interface_tap_dump_t *mp;
10037 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010038
Dave Barach72d72232016-08-04 10:15:08 -040010039 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
10040 /* Get list of tap interfaces */
10041 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
10042 S;
10043
10044 /* Use a control ping for synchronization */
10045 {
10046 vl_api_control_ping_t *mp;
10047 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010048 S;
Dave Barach72d72232016-08-04 10:15:08 -040010049 }
10050 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010051}
10052
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010053static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -040010054 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010055{
Dave Barach72d72232016-08-04 10:15:08 -040010056 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010057 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010058
Ed Warnickecb9cada2015-12-08 15:45:58 -070010059 if (unformat (input, "drop"))
10060 *result = VXLAN_INPUT_NEXT_DROP;
10061 else if (unformat (input, "ip4"))
10062 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
10063 else if (unformat (input, "ip6"))
10064 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
10065 else if (unformat (input, "l2"))
10066 *result = VXLAN_INPUT_NEXT_L2_INPUT;
10067 else if (unformat (input, "%d", &tmp))
10068 *result = tmp;
10069 else
10070 return 0;
10071 return 1;
10072}
10073
Dave Barach72d72232016-08-04 10:15:08 -040010074static int
10075api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010076{
Dave Barach72d72232016-08-04 10:15:08 -040010077 unformat_input_t *line_input = vam->input;
10078 vl_api_vxlan_add_del_tunnel_t *mp;
10079 f64 timeout;
10080 ip4_address_t src4, dst4;
10081 ip6_address_t src6, dst6;
10082 u8 is_add = 1;
10083 u8 ipv4_set = 0, ipv6_set = 0;
10084 u8 src_set = 0;
10085 u8 dst_set = 0;
10086 u32 encap_vrf_id = 0;
10087 u32 decap_next_index = ~0;
10088 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010089
Dave Barach72d72232016-08-04 10:15:08 -040010090 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10091 {
10092 if (unformat (line_input, "del"))
10093 is_add = 0;
10094 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10095 {
10096 ipv4_set = 1;
10097 src_set = 1;
10098 }
10099 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10100 {
10101 ipv4_set = 1;
10102 dst_set = 1;
10103 }
10104 else if (unformat (line_input, "src %U", unformat_ip6_address, &src6))
10105 {
10106 ipv6_set = 1;
10107 src_set = 1;
10108 }
10109 else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst6))
10110 {
10111 ipv6_set = 1;
10112 dst_set = 1;
10113 }
10114 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10115 ;
10116 else if (unformat (line_input, "decap-next %U",
10117 unformat_vxlan_decap_next, &decap_next_index))
10118 ;
10119 else if (unformat (line_input, "vni %d", &vni))
10120 ;
10121 else
10122 {
10123 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10124 return -99;
10125 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010126 }
10127
Dave Barach72d72232016-08-04 10:15:08 -040010128 if (src_set == 0)
10129 {
10130 errmsg ("tunnel src address not specified\n");
10131 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010132 }
Dave Barach72d72232016-08-04 10:15:08 -040010133 if (dst_set == 0)
10134 {
10135 errmsg ("tunnel dst address not specified\n");
10136 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010137 }
10138
Dave Barach72d72232016-08-04 10:15:08 -040010139 if (ipv4_set && ipv6_set)
10140 {
10141 errmsg ("both IPv4 and IPv6 addresses specified");
10142 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -040010143 }
10144
Dave Barach72d72232016-08-04 10:15:08 -040010145 if ((vni == 0) || (vni >> 24))
10146 {
10147 errmsg ("vni not specified or out of range\n");
10148 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010149 }
10150
Dave Barach72d72232016-08-04 10:15:08 -040010151 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -040010152
Dave Barach72d72232016-08-04 10:15:08 -040010153 if (ipv6_set)
10154 {
10155 clib_memcpy (&mp->src_address, &src6, sizeof (src6));
10156 clib_memcpy (&mp->dst_address, &dst6, sizeof (dst6));
Chris Luke99cb3352016-04-26 10:49:53 -040010157 }
Dave Barach72d72232016-08-04 10:15:08 -040010158 else
10159 {
10160 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10161 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10162 }
10163 mp->encap_vrf_id = ntohl (encap_vrf_id);
10164 mp->decap_next_index = ntohl (decap_next_index);
10165 mp->vni = ntohl (vni);
10166 mp->is_add = is_add;
10167 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010168
Dave Barach72d72232016-08-04 10:15:08 -040010169 S;
10170 W;
10171 /* NOTREACHED */
10172 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010173}
10174
Dave Wallace60231f32015-12-17 21:04:30 -050010175static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010176 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010177{
Dave Barach72d72232016-08-04 10:15:08 -040010178 vat_main_t *vam = &vat_main;
Dave Wallace60231f32015-12-17 21:04:30 -050010179
Dave Barach72d72232016-08-04 10:15:08 -040010180 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
10181 ntohl (mp->sw_if_index),
10182 format_ip46_address, &(mp->src_address[0]),
10183 IP46_TYPE_ANY,
10184 format_ip46_address, &(mp->dst_address[0]),
10185 IP46_TYPE_ANY,
10186 ntohl (mp->encap_vrf_id),
10187 ntohl (mp->decap_next_index), ntohl (mp->vni));
Dave Wallace60231f32015-12-17 21:04:30 -050010188}
10189
10190static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010191 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010192{
Dave Barach72d72232016-08-04 10:15:08 -040010193 vat_main_t *vam = &vat_main;
10194 vat_json_node_t *node = NULL;
10195 struct in_addr ip4;
10196 struct in6_addr ip6;
Dave Wallace60231f32015-12-17 21:04:30 -050010197
Dave Barach72d72232016-08-04 10:15:08 -040010198 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -050010199 {
Dave Barach72d72232016-08-04 10:15:08 -040010200 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10201 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -050010202 }
Dave Barach72d72232016-08-04 10:15:08 -040010203 node = vat_json_array_add (&vam->json_tree);
10204
10205 vat_json_init_object (node);
10206 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10207 if (mp->is_ipv6)
10208 {
10209 clib_memcpy (&ip6, &(mp->src_address[0]), sizeof (ip6));
10210 vat_json_object_add_ip6 (node, "src_address", ip6);
10211 clib_memcpy (&ip6, &(mp->dst_address[0]), sizeof (ip6));
10212 vat_json_object_add_ip6 (node, "dst_address", ip6);
10213 }
10214 else
10215 {
10216 clib_memcpy (&ip4, &(mp->src_address[0]), sizeof (ip4));
10217 vat_json_object_add_ip4 (node, "src_address", ip4);
10218 clib_memcpy (&ip4, &(mp->dst_address[0]), sizeof (ip4));
10219 vat_json_object_add_ip4 (node, "dst_address", ip4);
10220 }
10221 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10222 vat_json_object_add_uint (node, "decap_next_index",
10223 ntohl (mp->decap_next_index));
10224 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10225 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Dave Wallace60231f32015-12-17 21:04:30 -050010226}
10227
Dave Barach72d72232016-08-04 10:15:08 -040010228static int
10229api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -040010230{
Dave Barach72d72232016-08-04 10:15:08 -040010231 unformat_input_t *i = vam->input;
10232 vl_api_vxlan_tunnel_dump_t *mp;
10233 f64 timeout;
10234 u32 sw_if_index;
10235 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010236
Dave Barach72d72232016-08-04 10:15:08 -040010237 /* Parse args required to build the message */
10238 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10239 {
10240 if (unformat (i, "sw_if_index %d", &sw_if_index))
10241 sw_if_index_set = 1;
10242 else
10243 break;
Chris Luke27fe48f2016-04-28 13:44:38 -040010244 }
10245
Dave Barach72d72232016-08-04 10:15:08 -040010246 if (sw_if_index_set == 0)
10247 {
10248 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010249 }
Dave Barach72d72232016-08-04 10:15:08 -040010250
10251 if (!vam->json_output)
10252 {
10253 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
10254 "sw_if_index", "src_address", "dst_address",
10255 "encap_vrf_id", "decap_next_index", "vni");
10256 }
10257
10258 /* Get list of vxlan-tunnel interfaces */
10259 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
10260
10261 mp->sw_if_index = htonl (sw_if_index);
10262
10263 S;
10264
10265 /* Use a control ping for synchronization */
10266 {
10267 vl_api_control_ping_t *mp;
10268 M (CONTROL_PING, control_ping);
10269 S;
10270 }
10271 W;
10272}
10273
10274static int
10275api_gre_add_del_tunnel (vat_main_t * vam)
10276{
10277 unformat_input_t *line_input = vam->input;
10278 vl_api_gre_add_del_tunnel_t *mp;
10279 f64 timeout;
10280 ip4_address_t src4, dst4;
10281 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -070010282 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010283 u8 src_set = 0;
10284 u8 dst_set = 0;
10285 u32 outer_fib_id = 0;
10286
10287 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10288 {
10289 if (unformat (line_input, "del"))
10290 is_add = 0;
10291 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10292 src_set = 1;
10293 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10294 dst_set = 1;
10295 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
10296 ;
David Hothama8cd3092016-09-19 09:55:07 -070010297 else if (unformat (line_input, "teb"))
10298 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -040010299 else
10300 {
10301 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10302 return -99;
10303 }
10304 }
10305
10306 if (src_set == 0)
10307 {
10308 errmsg ("tunnel src address not specified\n");
10309 return -99;
10310 }
10311 if (dst_set == 0)
10312 {
10313 errmsg ("tunnel dst address not specified\n");
10314 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -040010315 }
10316
10317
Dave Barach72d72232016-08-04 10:15:08 -040010318 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -040010319
Dave Barach72d72232016-08-04 10:15:08 -040010320 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10321 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10322 mp->outer_fib_id = ntohl (outer_fib_id);
10323 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -070010324 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -040010325
Dave Barach72d72232016-08-04 10:15:08 -040010326 S;
10327 W;
10328 /* NOTREACHED */
10329 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010330}
10331
10332static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010333 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010334{
Dave Barach72d72232016-08-04 10:15:08 -040010335 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -040010336
David Hothama8cd3092016-09-19 09:55:07 -070010337 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010338 ntohl (mp->sw_if_index),
10339 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -070010340 format_ip4_address, &mp->dst_address,
10341 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010342}
10343
10344static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010345 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010346{
Dave Barach72d72232016-08-04 10:15:08 -040010347 vat_main_t *vam = &vat_main;
10348 vat_json_node_t *node = NULL;
10349 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -040010350
Dave Barach72d72232016-08-04 10:15:08 -040010351 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -040010352 {
Dave Barach72d72232016-08-04 10:15:08 -040010353 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10354 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -040010355 }
Dave Barach72d72232016-08-04 10:15:08 -040010356 node = vat_json_array_add (&vam->json_tree);
10357
10358 vat_json_init_object (node);
10359 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10360 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
10361 vat_json_object_add_ip4 (node, "src_address", ip4);
10362 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
10363 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -070010364 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -040010365 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010366}
10367
Dave Barach72d72232016-08-04 10:15:08 -040010368static int
10369api_gre_tunnel_dump (vat_main_t * vam)
10370{
10371 unformat_input_t *i = vam->input;
10372 vl_api_gre_tunnel_dump_t *mp;
10373 f64 timeout;
10374 u32 sw_if_index;
10375 u8 sw_if_index_set = 0;
10376
10377 /* Parse args required to build the message */
10378 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10379 {
10380 if (unformat (i, "sw_if_index %d", &sw_if_index))
10381 sw_if_index_set = 1;
10382 else
10383 break;
10384 }
10385
10386 if (sw_if_index_set == 0)
10387 {
10388 sw_if_index = ~0;
10389 }
10390
10391 if (!vam->json_output)
10392 {
David Hothama8cd3092016-09-19 09:55:07 -070010393 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
10394 "sw_if_index", "src_address", "dst_address", "teb",
10395 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -040010396 }
10397
10398 /* Get list of gre-tunnel interfaces */
10399 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
10400
10401 mp->sw_if_index = htonl (sw_if_index);
10402
10403 S;
10404
10405 /* Use a control ping for synchronization */
10406 {
10407 vl_api_control_ping_t *mp;
10408 M (CONTROL_PING, control_ping);
10409 S;
10410 }
10411 W;
10412}
10413
10414static int
10415api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010416{
10417// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040010418 vl_api_l2_fib_clear_table_t *mp;
10419 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010420
Dave Barach72d72232016-08-04 10:15:08 -040010421 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010422
Dave Barach72d72232016-08-04 10:15:08 -040010423 S;
10424 W;
10425 /* NOTREACHED */
10426 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010427}
10428
Dave Barach72d72232016-08-04 10:15:08 -040010429static int
10430api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010431{
Dave Barach72d72232016-08-04 10:15:08 -040010432 unformat_input_t *i = vam->input;
10433 vl_api_l2_interface_efp_filter_t *mp;
10434 f64 timeout;
10435 u32 sw_if_index;
10436 u8 enable = 1;
10437 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010438
Dave Barach72d72232016-08-04 10:15:08 -040010439 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10440 {
10441 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10442 sw_if_index_set = 1;
10443 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10444 sw_if_index_set = 1;
10445 else if (unformat (i, "enable"))
10446 enable = 1;
10447 else if (unformat (i, "disable"))
10448 enable = 0;
10449 else
10450 {
10451 clib_warning ("parse error '%U'", format_unformat_error, i);
10452 return -99;
10453 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010454 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010455
Dave Barach72d72232016-08-04 10:15:08 -040010456 if (sw_if_index_set == 0)
10457 {
10458 errmsg ("missing sw_if_index\n");
10459 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010460 }
10461
Dave Barach72d72232016-08-04 10:15:08 -040010462 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010463
Dave Barach72d72232016-08-04 10:15:08 -040010464 mp->sw_if_index = ntohl (sw_if_index);
10465 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010466
Dave Barach72d72232016-08-04 10:15:08 -040010467 S;
10468 W;
10469 /* NOTREACHED */
10470 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010471}
10472
10473#define foreach_vtr_op \
10474_("disable", L2_VTR_DISABLED) \
10475_("push-1", L2_VTR_PUSH_1) \
10476_("push-2", L2_VTR_PUSH_2) \
10477_("pop-1", L2_VTR_POP_1) \
10478_("pop-2", L2_VTR_POP_2) \
10479_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
10480_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
10481_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
10482_("translate-2-2", L2_VTR_TRANSLATE_2_2)
10483
Dave Barach72d72232016-08-04 10:15:08 -040010484static int
10485api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010486{
Dave Barach72d72232016-08-04 10:15:08 -040010487 unformat_input_t *i = vam->input;
10488 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
10489 f64 timeout;
10490 u32 sw_if_index;
10491 u8 sw_if_index_set = 0;
10492 u8 vtr_op_set = 0;
10493 u32 vtr_op = 0;
10494 u32 push_dot1q = 1;
10495 u32 tag1 = ~0;
10496 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010497
Dave Barach72d72232016-08-04 10:15:08 -040010498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10499 {
10500 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10501 sw_if_index_set = 1;
10502 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10503 sw_if_index_set = 1;
10504 else if (unformat (i, "vtr_op %d", &vtr_op))
10505 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010506#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -040010507 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -070010508#undef _
Dave Barach72d72232016-08-04 10:15:08 -040010509 else if (unformat (i, "push_dot1q %d", &push_dot1q))
10510 ;
10511 else if (unformat (i, "tag1 %d", &tag1))
10512 ;
10513 else if (unformat (i, "tag2 %d", &tag2))
10514 ;
10515 else
10516 {
10517 clib_warning ("parse error '%U'", format_unformat_error, i);
10518 return -99;
10519 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010520 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010521
Dave Barach72d72232016-08-04 10:15:08 -040010522 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
10523 {
10524 errmsg ("missing vtr operation or sw_if_index\n");
10525 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010526 }
10527
Dave Barach72d72232016-08-04 10:15:08 -040010528 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
10529 mp->sw_if_index = ntohl (sw_if_index);
10530 mp->vtr_op = ntohl (vtr_op);
10531 mp->push_dot1q = ntohl (push_dot1q);
10532 mp->tag1 = ntohl (tag1);
10533 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010534
Dave Barach72d72232016-08-04 10:15:08 -040010535 S;
10536 W;
10537 /* NOTREACHED */
10538 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010539}
10540
Dave Barach72d72232016-08-04 10:15:08 -040010541static int
10542api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010543{
Dave Barach72d72232016-08-04 10:15:08 -040010544 unformat_input_t *i = vam->input;
10545 vl_api_create_vhost_user_if_t *mp;
10546 f64 timeout;
10547 u8 *file_name;
10548 u8 is_server = 0;
10549 u8 file_name_set = 0;
10550 u32 custom_dev_instance = ~0;
10551 u8 hwaddr[6];
10552 u8 use_custom_mac = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010553
Dave Barach72d72232016-08-04 10:15:08 -040010554 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10555 {
10556 if (unformat (i, "socket %s", &file_name))
10557 {
10558 file_name_set = 1;
10559 }
10560 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10561 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010562 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010563 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010564 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010565 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010566 else
Dave Barach72d72232016-08-04 10:15:08 -040010567 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010568 }
10569
Dave Barach72d72232016-08-04 10:15:08 -040010570 if (file_name_set == 0)
10571 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010572 errmsg ("missing socket file name\n");
10573 return -99;
10574 }
10575
Dave Barach72d72232016-08-04 10:15:08 -040010576 if (vec_len (file_name) > 255)
10577 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010578 errmsg ("socket file name too long\n");
10579 return -99;
10580 }
Dave Barach72d72232016-08-04 10:15:08 -040010581 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010582
Dave Barach72d72232016-08-04 10:15:08 -040010583 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010584
Dave Barach72d72232016-08-04 10:15:08 -040010585 mp->is_server = is_server;
10586 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10587 vec_free (file_name);
10588 if (custom_dev_instance != ~0)
10589 {
10590 mp->renumber = 1;
10591 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010592 }
Dave Barach72d72232016-08-04 10:15:08 -040010593 mp->use_custom_mac = use_custom_mac;
10594 clib_memcpy (mp->mac_address, hwaddr, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010595
Dave Barach72d72232016-08-04 10:15:08 -040010596 S;
10597 W;
10598 /* NOTREACHED */
10599 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010600}
10601
Dave Barach72d72232016-08-04 10:15:08 -040010602static int
10603api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010604{
Dave Barach72d72232016-08-04 10:15:08 -040010605 unformat_input_t *i = vam->input;
10606 vl_api_modify_vhost_user_if_t *mp;
10607 f64 timeout;
10608 u8 *file_name;
10609 u8 is_server = 0;
10610 u8 file_name_set = 0;
10611 u32 custom_dev_instance = ~0;
10612 u8 sw_if_index_set = 0;
10613 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010614
Dave Barach72d72232016-08-04 10:15:08 -040010615 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10616 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010617 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010618 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010619 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010620 sw_if_index_set = 1;
10621 else if (unformat (i, "socket %s", &file_name))
10622 {
10623 file_name_set = 1;
10624 }
10625 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10626 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010627 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010628 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010629 else
Dave Barach72d72232016-08-04 10:15:08 -040010630 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010631 }
10632
Dave Barach72d72232016-08-04 10:15:08 -040010633 if (sw_if_index_set == 0)
10634 {
10635 errmsg ("missing sw_if_index or interface name\n");
10636 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010637 }
10638
Dave Barach72d72232016-08-04 10:15:08 -040010639 if (file_name_set == 0)
10640 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010641 errmsg ("missing socket file name\n");
10642 return -99;
10643 }
10644
Dave Barach72d72232016-08-04 10:15:08 -040010645 if (vec_len (file_name) > 255)
10646 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010647 errmsg ("socket file name too long\n");
10648 return -99;
10649 }
Dave Barach72d72232016-08-04 10:15:08 -040010650 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010651
Dave Barach72d72232016-08-04 10:15:08 -040010652 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010653
Dave Barach72d72232016-08-04 10:15:08 -040010654 mp->sw_if_index = ntohl (sw_if_index);
10655 mp->is_server = is_server;
10656 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10657 vec_free (file_name);
10658 if (custom_dev_instance != ~0)
10659 {
10660 mp->renumber = 1;
10661 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010662 }
10663
Dave Barach72d72232016-08-04 10:15:08 -040010664 S;
10665 W;
10666 /* NOTREACHED */
10667 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010668}
10669
Dave Barach72d72232016-08-04 10:15:08 -040010670static int
10671api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010672{
Dave Barach72d72232016-08-04 10:15:08 -040010673 unformat_input_t *i = vam->input;
10674 vl_api_delete_vhost_user_if_t *mp;
10675 f64 timeout;
10676 u32 sw_if_index = ~0;
10677 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010678
Dave Barach72d72232016-08-04 10:15:08 -040010679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10680 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010681 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010682 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010683 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010684 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010685 else
Dave Barach72d72232016-08-04 10:15:08 -040010686 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010687 }
10688
Dave Barach72d72232016-08-04 10:15:08 -040010689 if (sw_if_index_set == 0)
10690 {
10691 errmsg ("missing sw_if_index or interface name\n");
10692 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010693 }
10694
10695
Dave Barach72d72232016-08-04 10:15:08 -040010696 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010697
Dave Barach72d72232016-08-04 10:15:08 -040010698 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010699
Dave Barach72d72232016-08-04 10:15:08 -040010700 S;
10701 W;
10702 /* NOTREACHED */
10703 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010704}
10705
10706static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010707 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010708{
Dave Barach72d72232016-08-04 10:15:08 -040010709 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010710
Dave Barach72d72232016-08-04 10:15:08 -040010711 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10712 (char *) mp->interface_name,
10713 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10714 clib_net_to_host_u64 (mp->features), mp->is_server,
10715 ntohl (mp->num_regions), (char *) mp->sock_filename);
10716 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010717}
10718
10719static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010720 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010721{
Dave Barach72d72232016-08-04 10:15:08 -040010722 vat_main_t *vam = &vat_main;
10723 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010724
Dave Barach72d72232016-08-04 10:15:08 -040010725 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010726 {
Dave Barach72d72232016-08-04 10:15:08 -040010727 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10728 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010729 }
Dave Barach72d72232016-08-04 10:15:08 -040010730 node = vat_json_array_add (&vam->json_tree);
10731
10732 vat_json_init_object (node);
10733 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10734 vat_json_object_add_string_copy (node, "interface_name",
10735 mp->interface_name);
10736 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10737 ntohl (mp->virtio_net_hdr_sz));
10738 vat_json_object_add_uint (node, "features",
10739 clib_net_to_host_u64 (mp->features));
10740 vat_json_object_add_uint (node, "is_server", mp->is_server);
10741 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10742 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10743 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010744}
10745
Dave Barach72d72232016-08-04 10:15:08 -040010746static int
10747api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010748{
Dave Barach72d72232016-08-04 10:15:08 -040010749 vl_api_sw_interface_vhost_user_dump_t *mp;
10750 f64 timeout;
10751 fformat (vam->ofp,
10752 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010753
Dave Barach72d72232016-08-04 10:15:08 -040010754 /* Get list of vhost-user interfaces */
10755 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10756 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010757
Dave Barach72d72232016-08-04 10:15:08 -040010758 /* Use a control ping for synchronization */
10759 {
10760 vl_api_control_ping_t *mp;
10761 M (CONTROL_PING, control_ping);
10762 S;
10763 }
10764 W;
10765}
10766
10767static int
10768api_show_version (vat_main_t * vam)
10769{
10770 vl_api_show_version_t *mp;
10771 f64 timeout;
10772
10773 M (SHOW_VERSION, show_version);
10774
10775 S;
10776 W;
10777 /* NOTREACHED */
10778 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010779}
10780
Ed Warnickecb9cada2015-12-08 15:45:58 -070010781
Dave Barach72d72232016-08-04 10:15:08 -040010782static int
10783api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010784{
Dave Barach72d72232016-08-04 10:15:08 -040010785 unformat_input_t *line_input = vam->input;
10786 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10787 f64 timeout;
10788 ip4_address_t local4, remote4;
10789 ip6_address_t local6, remote6;
10790 u8 is_add = 1;
10791 u8 ipv4_set = 0, ipv6_set = 0;
10792 u8 local_set = 0;
10793 u8 remote_set = 0;
10794 u32 encap_vrf_id = 0;
10795 u32 decap_vrf_id = 0;
10796 u8 protocol = ~0;
10797 u32 vni;
10798 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010799
Dave Barach72d72232016-08-04 10:15:08 -040010800 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10801 {
10802 if (unformat (line_input, "del"))
10803 is_add = 0;
10804 else if (unformat (line_input, "local %U",
10805 unformat_ip4_address, &local4))
10806 {
10807 local_set = 1;
10808 ipv4_set = 1;
10809 }
10810 else if (unformat (line_input, "remote %U",
10811 unformat_ip4_address, &remote4))
10812 {
10813 remote_set = 1;
10814 ipv4_set = 1;
10815 }
10816 else if (unformat (line_input, "local %U",
10817 unformat_ip6_address, &local6))
10818 {
10819 local_set = 1;
10820 ipv6_set = 1;
10821 }
10822 else if (unformat (line_input, "remote %U",
10823 unformat_ip6_address, &remote6))
10824 {
10825 remote_set = 1;
10826 ipv6_set = 1;
10827 }
10828 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10829 ;
10830 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10831 ;
10832 else if (unformat (line_input, "vni %d", &vni))
10833 vni_set = 1;
10834 else if (unformat (line_input, "next-ip4"))
10835 protocol = 1;
10836 else if (unformat (line_input, "next-ip6"))
10837 protocol = 2;
10838 else if (unformat (line_input, "next-ethernet"))
10839 protocol = 3;
10840 else if (unformat (line_input, "next-nsh"))
10841 protocol = 4;
10842 else
10843 {
10844 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10845 return -99;
10846 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010847 }
10848
Dave Barach72d72232016-08-04 10:15:08 -040010849 if (local_set == 0)
10850 {
10851 errmsg ("tunnel local address not specified\n");
10852 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010853 }
Dave Barach72d72232016-08-04 10:15:08 -040010854 if (remote_set == 0)
10855 {
10856 errmsg ("tunnel remote address not specified\n");
10857 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010858 }
Dave Barach72d72232016-08-04 10:15:08 -040010859 if (ipv4_set && ipv6_set)
10860 {
10861 errmsg ("both IPv4 and IPv6 addresses specified");
10862 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080010863 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010864
Dave Barach72d72232016-08-04 10:15:08 -040010865 if (vni_set == 0)
10866 {
10867 errmsg ("vni not specified\n");
10868 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010869 }
10870
Dave Barach72d72232016-08-04 10:15:08 -040010871 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010872
Hongjun Nidf921cc2016-05-25 01:16:19 +080010873
Dave Barach72d72232016-08-04 10:15:08 -040010874 if (ipv6_set)
10875 {
10876 clib_memcpy (&mp->local, &local6, sizeof (local6));
10877 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
10878 }
10879 else
10880 {
10881 clib_memcpy (&mp->local, &local4, sizeof (local4));
10882 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080010883 }
10884
Dave Barach72d72232016-08-04 10:15:08 -040010885 mp->encap_vrf_id = ntohl (encap_vrf_id);
10886 mp->decap_vrf_id = ntohl (decap_vrf_id);
10887 mp->protocol = ntohl (protocol);
10888 mp->vni = ntohl (vni);
10889 mp->is_add = is_add;
10890 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010891
Dave Barach72d72232016-08-04 10:15:08 -040010892 S;
10893 W;
10894 /* NOTREACHED */
10895 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010896}
10897
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010898static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010899 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010900{
Dave Barach72d72232016-08-04 10:15:08 -040010901 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010902
Dave Barach72d72232016-08-04 10:15:08 -040010903 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
10904 ntohl (mp->sw_if_index),
10905 format_ip46_address, &(mp->local[0]),
10906 format_ip46_address, &(mp->remote[0]),
10907 ntohl (mp->vni),
10908 ntohl (mp->protocol),
10909 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010910}
10911
10912static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010913 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010914{
Dave Barach72d72232016-08-04 10:15:08 -040010915 vat_main_t *vam = &vat_main;
10916 vat_json_node_t *node = NULL;
10917 struct in_addr ip4;
10918 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010919
Dave Barach72d72232016-08-04 10:15:08 -040010920 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010921 {
Dave Barach72d72232016-08-04 10:15:08 -040010922 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10923 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010924 }
Dave Barach72d72232016-08-04 10:15:08 -040010925 node = vat_json_array_add (&vam->json_tree);
10926
10927 vat_json_init_object (node);
10928 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10929 if (mp->is_ipv6)
10930 {
10931 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
10932 vat_json_object_add_ip6 (node, "local", ip6);
10933 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
10934 vat_json_object_add_ip6 (node, "remote", ip6);
10935 }
10936 else
10937 {
10938 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
10939 vat_json_object_add_ip4 (node, "local", ip4);
10940 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
10941 vat_json_object_add_ip4 (node, "remote", ip4);
10942 }
10943 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10944 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10945 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10946 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10947 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010948}
10949
Dave Barach72d72232016-08-04 10:15:08 -040010950static int
10951api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010952{
Dave Barach72d72232016-08-04 10:15:08 -040010953 unformat_input_t *i = vam->input;
10954 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10955 f64 timeout;
10956 u32 sw_if_index;
10957 u8 sw_if_index_set = 0;
10958
10959 /* Parse args required to build the message */
10960 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10961 {
10962 if (unformat (i, "sw_if_index %d", &sw_if_index))
10963 sw_if_index_set = 1;
10964 else
10965 break;
10966 }
10967
10968 if (sw_if_index_set == 0)
10969 {
10970 sw_if_index = ~0;
10971 }
10972
10973 if (!vam->json_output)
10974 {
10975 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
10976 "sw_if_index", "local", "remote", "vni",
10977 "protocol", "encap_vrf_id", "decap_vrf_id");
10978 }
10979
10980 /* Get list of vxlan-tunnel interfaces */
10981 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
10982
10983 mp->sw_if_index = htonl (sw_if_index);
10984
10985 S;
10986
10987 /* Use a control ping for synchronization */
10988 {
10989 vl_api_control_ping_t *mp;
10990 M (CONTROL_PING, control_ping);
10991 S;
10992 }
10993 W;
10994}
10995
10996u8 *
10997format_l2_fib_mac_address (u8 * s, va_list * args)
10998{
10999 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011000
11001 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040011002 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011003}
11004
11005static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011006 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011007{
Dave Barach72d72232016-08-04 10:15:08 -040011008 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011009
Dave Barach72d72232016-08-04 10:15:08 -040011010 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
11011 " %d %d %d\n",
11012 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
11013 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
11014 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011015}
11016
11017static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011018 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011019{
Dave Barach72d72232016-08-04 10:15:08 -040011020 vat_main_t *vam = &vat_main;
11021 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011022
Dave Barach72d72232016-08-04 10:15:08 -040011023 if (VAT_JSON_ARRAY != vam->json_tree.type)
11024 {
11025 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11026 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011027 }
Dave Barach72d72232016-08-04 10:15:08 -040011028 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011029
Dave Barach72d72232016-08-04 10:15:08 -040011030 vat_json_init_object (node);
11031 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
11032 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
11033 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11034 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
11035 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
11036 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011037}
11038
Dave Barach72d72232016-08-04 10:15:08 -040011039static int
11040api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011041{
Dave Barach72d72232016-08-04 10:15:08 -040011042 unformat_input_t *i = vam->input;
11043 vl_api_l2_fib_table_dump_t *mp;
11044 f64 timeout;
11045 u32 bd_id;
11046 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011047
Dave Barach72d72232016-08-04 10:15:08 -040011048 /* Parse args required to build the message */
11049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011050 {
Dave Barach72d72232016-08-04 10:15:08 -040011051 if (unformat (i, "bd_id %d", &bd_id))
11052 bd_id_set = 1;
11053 else
11054 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011055 }
Dave Barach72d72232016-08-04 10:15:08 -040011056
11057 if (bd_id_set == 0)
11058 {
11059 errmsg ("missing bridge domain\n");
11060 return -99;
11061 }
11062
11063 fformat (vam->ofp,
11064 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
11065
11066 /* Get list of l2 fib entries */
11067 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
11068
11069 mp->bd_id = ntohl (bd_id);
11070 S;
11071
11072 /* Use a control ping for synchronization */
11073 {
11074 vl_api_control_ping_t *mp;
11075 M (CONTROL_PING, control_ping);
11076 S;
11077 }
11078 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011079}
11080
11081
11082static int
11083api_interface_name_renumber (vat_main_t * vam)
11084{
Dave Barach72d72232016-08-04 10:15:08 -040011085 unformat_input_t *line_input = vam->input;
11086 vl_api_interface_name_renumber_t *mp;
11087 u32 sw_if_index = ~0;
11088 f64 timeout;
11089 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011090
Dave Barach72d72232016-08-04 10:15:08 -040011091 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11092 {
11093 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
11094 &sw_if_index))
11095 ;
11096 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11097 ;
11098 else if (unformat (line_input, "new_show_dev_instance %d",
11099 &new_show_dev_instance))
11100 ;
11101 else
11102 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011103 }
11104
Dave Barach72d72232016-08-04 10:15:08 -040011105 if (sw_if_index == ~0)
11106 {
11107 errmsg ("missing interface name or sw_if_index\n");
11108 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011109 }
11110
Dave Barach72d72232016-08-04 10:15:08 -040011111 if (new_show_dev_instance == ~0)
11112 {
11113 errmsg ("missing new_show_dev_instance\n");
11114 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011115 }
11116
Dave Barach72d72232016-08-04 10:15:08 -040011117 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011118
Dave Barach72d72232016-08-04 10:15:08 -040011119 mp->sw_if_index = ntohl (sw_if_index);
11120 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011121
Dave Barach72d72232016-08-04 10:15:08 -040011122 S;
11123 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011124}
11125
11126static int
11127api_want_ip4_arp_events (vat_main_t * vam)
11128{
Dave Barach72d72232016-08-04 10:15:08 -040011129 unformat_input_t *line_input = vam->input;
11130 vl_api_want_ip4_arp_events_t *mp;
11131 f64 timeout;
11132 ip4_address_t address;
11133 int address_set = 0;
11134 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011135
Dave Barach72d72232016-08-04 10:15:08 -040011136 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11137 {
11138 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
11139 address_set = 1;
11140 else if (unformat (line_input, "del"))
11141 enable_disable = 0;
11142 else
11143 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011144 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011145
Dave Barach72d72232016-08-04 10:15:08 -040011146 if (address_set == 0)
11147 {
11148 errmsg ("missing addresses\n");
11149 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011150 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011151
Dave Barach72d72232016-08-04 10:15:08 -040011152 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
11153 mp->enable_disable = enable_disable;
11154 mp->pid = getpid ();
11155 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011156
Dave Barach72d72232016-08-04 10:15:08 -040011157 S;
11158 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011159}
11160
Dave Barach72d72232016-08-04 10:15:08 -040011161static int
John Lo1edfba92016-08-27 01:11:57 -040011162api_want_ip6_nd_events (vat_main_t * vam)
11163{
11164 unformat_input_t *line_input = vam->input;
11165 vl_api_want_ip6_nd_events_t *mp;
11166 f64 timeout;
11167 ip6_address_t address;
11168 int address_set = 0;
11169 u32 enable_disable = 1;
11170
11171 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11172 {
11173 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
11174 address_set = 1;
11175 else if (unformat (line_input, "del"))
11176 enable_disable = 0;
11177 else
11178 break;
11179 }
11180
11181 if (address_set == 0)
11182 {
11183 errmsg ("missing addresses\n");
11184 return -99;
11185 }
11186
11187 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
11188 mp->enable_disable = enable_disable;
11189 mp->pid = getpid ();
11190 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
11191
11192 S;
11193 W;
11194}
11195
11196static int
Dave Barach72d72232016-08-04 10:15:08 -040011197api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011198{
Dave Barach72d72232016-08-04 10:15:08 -040011199 unformat_input_t *i = vam->input;
11200 vl_api_input_acl_set_interface_t *mp;
11201 f64 timeout;
11202 u32 sw_if_index;
11203 int sw_if_index_set;
11204 u32 ip4_table_index = ~0;
11205 u32 ip6_table_index = ~0;
11206 u32 l2_table_index = ~0;
11207 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011208
Dave Barach72d72232016-08-04 10:15:08 -040011209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11210 {
11211 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11212 sw_if_index_set = 1;
11213 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11214 sw_if_index_set = 1;
11215 else if (unformat (i, "del"))
11216 is_add = 0;
11217 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11218 ;
11219 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11220 ;
11221 else if (unformat (i, "l2-table %d", &l2_table_index))
11222 ;
11223 else
11224 {
11225 clib_warning ("parse error '%U'", format_unformat_error, i);
11226 return -99;
11227 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011228 }
11229
Dave Barach72d72232016-08-04 10:15:08 -040011230 if (sw_if_index_set == 0)
11231 {
11232 errmsg ("missing interface name or sw_if_index\n");
11233 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011234 }
11235
Dave Barach72d72232016-08-04 10:15:08 -040011236 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011237
Dave Barach72d72232016-08-04 10:15:08 -040011238 mp->sw_if_index = ntohl (sw_if_index);
11239 mp->ip4_table_index = ntohl (ip4_table_index);
11240 mp->ip6_table_index = ntohl (ip6_table_index);
11241 mp->l2_table_index = ntohl (l2_table_index);
11242 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011243
Dave Barach72d72232016-08-04 10:15:08 -040011244 S;
11245 W;
11246 /* NOTREACHED */
11247 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011248}
11249
11250static int
11251api_ip_address_dump (vat_main_t * vam)
11252{
Dave Barach72d72232016-08-04 10:15:08 -040011253 unformat_input_t *i = vam->input;
11254 vl_api_ip_address_dump_t *mp;
11255 u32 sw_if_index = ~0;
11256 u8 sw_if_index_set = 0;
11257 u8 ipv4_set = 0;
11258 u8 ipv6_set = 0;
11259 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011260
Dave Barach72d72232016-08-04 10:15:08 -040011261 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011262 {
Dave Barach72d72232016-08-04 10:15:08 -040011263 if (unformat (i, "sw_if_index %d", &sw_if_index))
11264 sw_if_index_set = 1;
11265 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11266 sw_if_index_set = 1;
11267 else if (unformat (i, "ipv4"))
11268 ipv4_set = 1;
11269 else if (unformat (i, "ipv6"))
11270 ipv6_set = 1;
11271 else
11272 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011273 }
Dave Barach72d72232016-08-04 10:15:08 -040011274
11275 if (ipv4_set && ipv6_set)
11276 {
11277 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11278 return -99;
11279 }
11280
11281 if ((!ipv4_set) && (!ipv6_set))
11282 {
11283 errmsg ("no ipv4 nor ipv6 flag set\n");
11284 return -99;
11285 }
11286
11287 if (sw_if_index_set == 0)
11288 {
11289 errmsg ("missing interface name or sw_if_index\n");
11290 return -99;
11291 }
11292
11293 vam->current_sw_if_index = sw_if_index;
11294 vam->is_ipv6 = ipv6_set;
11295
11296 M (IP_ADDRESS_DUMP, ip_address_dump);
11297 mp->sw_if_index = ntohl (sw_if_index);
11298 mp->is_ipv6 = ipv6_set;
11299 S;
11300
11301 /* Use a control ping for synchronization */
11302 {
11303 vl_api_control_ping_t *mp;
11304 M (CONTROL_PING, control_ping);
11305 S;
11306 }
11307 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011308}
11309
11310static int
11311api_ip_dump (vat_main_t * vam)
11312{
Dave Barach72d72232016-08-04 10:15:08 -040011313 vl_api_ip_dump_t *mp;
11314 unformat_input_t *in = vam->input;
11315 int ipv4_set = 0;
11316 int ipv6_set = 0;
11317 int is_ipv6;
11318 f64 timeout;
11319 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011320
Dave Barach72d72232016-08-04 10:15:08 -040011321 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011322 {
Dave Barach72d72232016-08-04 10:15:08 -040011323 if (unformat (in, "ipv4"))
11324 ipv4_set = 1;
11325 else if (unformat (in, "ipv6"))
11326 ipv6_set = 1;
11327 else
11328 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011329 }
Dave Barach72d72232016-08-04 10:15:08 -040011330
11331 if (ipv4_set && ipv6_set)
11332 {
11333 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11334 return -99;
11335 }
11336
11337 if ((!ipv4_set) && (!ipv6_set))
11338 {
11339 errmsg ("no ipv4 nor ipv6 flag set\n");
11340 return -99;
11341 }
11342
11343 is_ipv6 = ipv6_set;
11344 vam->is_ipv6 = is_ipv6;
11345
11346 /* free old data */
11347 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
11348 {
11349 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
11350 }
11351 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
11352
11353 M (IP_DUMP, ip_dump);
11354 mp->is_ipv6 = ipv6_set;
11355 S;
11356
11357 /* Use a control ping for synchronization */
11358 {
11359 vl_api_control_ping_t *mp;
11360 M (CONTROL_PING, control_ping);
11361 S;
11362 }
11363 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011364}
11365
11366static int
11367api_ipsec_spd_add_del (vat_main_t * vam)
11368{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011369#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011370 unformat_input_t *i = vam->input;
11371 vl_api_ipsec_spd_add_del_t *mp;
11372 f64 timeout;
11373 u32 spd_id = ~0;
11374 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011375
Dave Barach72d72232016-08-04 10:15:08 -040011376 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11377 {
11378 if (unformat (i, "spd_id %d", &spd_id))
11379 ;
11380 else if (unformat (i, "del"))
11381 is_add = 0;
11382 else
11383 {
11384 clib_warning ("parse error '%U'", format_unformat_error, i);
11385 return -99;
11386 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011387 }
Dave Barach72d72232016-08-04 10:15:08 -040011388 if (spd_id == ~0)
11389 {
11390 errmsg ("spd_id must be set\n");
11391 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011392 }
11393
Dave Barach72d72232016-08-04 10:15:08 -040011394 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011395
Dave Barach72d72232016-08-04 10:15:08 -040011396 mp->spd_id = ntohl (spd_id);
11397 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011398
Dave Barach72d72232016-08-04 10:15:08 -040011399 S;
11400 W;
11401 /* NOTREACHED */
11402 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011403#else
Dave Barach72d72232016-08-04 10:15:08 -040011404 clib_warning ("unsupported (no dpdk)");
11405 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011406#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011407}
11408
11409static int
11410api_ipsec_interface_add_del_spd (vat_main_t * vam)
11411{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011412#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011413 unformat_input_t *i = vam->input;
11414 vl_api_ipsec_interface_add_del_spd_t *mp;
11415 f64 timeout;
11416 u32 sw_if_index;
11417 u8 sw_if_index_set = 0;
11418 u32 spd_id = (u32) ~ 0;
11419 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011420
Dave Barach72d72232016-08-04 10:15:08 -040011421 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11422 {
11423 if (unformat (i, "del"))
11424 is_add = 0;
11425 else if (unformat (i, "spd_id %d", &spd_id))
11426 ;
11427 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11428 sw_if_index_set = 1;
11429 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11430 sw_if_index_set = 1;
11431 else
11432 {
11433 clib_warning ("parse error '%U'", format_unformat_error, i);
11434 return -99;
11435 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011436
11437 }
11438
Dave Barach72d72232016-08-04 10:15:08 -040011439 if (spd_id == (u32) ~ 0)
11440 {
11441 errmsg ("spd_id must be set\n");
11442 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011443 }
11444
Dave Barach72d72232016-08-04 10:15:08 -040011445 if (sw_if_index_set == 0)
11446 {
11447 errmsg ("missing interface name or sw_if_index\n");
11448 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011449 }
11450
Dave Barach72d72232016-08-04 10:15:08 -040011451 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011452
Dave Barach72d72232016-08-04 10:15:08 -040011453 mp->spd_id = ntohl (spd_id);
11454 mp->sw_if_index = ntohl (sw_if_index);
11455 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011456
Dave Barach72d72232016-08-04 10:15:08 -040011457 S;
11458 W;
11459 /* NOTREACHED */
11460 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011461#else
Dave Barach72d72232016-08-04 10:15:08 -040011462 clib_warning ("unsupported (no dpdk)");
11463 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011464#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011465}
11466
11467static int
11468api_ipsec_spd_add_del_entry (vat_main_t * vam)
11469{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011470#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011471 unformat_input_t *i = vam->input;
11472 vl_api_ipsec_spd_add_del_entry_t *mp;
11473 f64 timeout;
11474 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040011475 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040011476 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011477 u32 rport_start = 0, rport_stop = (u32) ~ 0;
11478 u32 lport_start = 0, lport_stop = (u32) ~ 0;
11479 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
11480 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011481
Dave Barach72d72232016-08-04 10:15:08 -040011482 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
11483 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
11484 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
11485 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
11486 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
11487 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011488
Dave Barach72d72232016-08-04 10:15:08 -040011489 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11490 {
11491 if (unformat (i, "del"))
11492 is_add = 0;
11493 if (unformat (i, "outbound"))
11494 is_outbound = 1;
11495 if (unformat (i, "inbound"))
11496 is_outbound = 0;
11497 else if (unformat (i, "spd_id %d", &spd_id))
11498 ;
11499 else if (unformat (i, "sa_id %d", &sa_id))
11500 ;
11501 else if (unformat (i, "priority %d", &priority))
11502 ;
11503 else if (unformat (i, "protocol %d", &protocol))
11504 ;
11505 else if (unformat (i, "lport_start %d", &lport_start))
11506 ;
11507 else if (unformat (i, "lport_stop %d", &lport_stop))
11508 ;
11509 else if (unformat (i, "rport_start %d", &rport_start))
11510 ;
11511 else if (unformat (i, "rport_stop %d", &rport_stop))
11512 ;
11513 else
11514 if (unformat
11515 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
11516 {
11517 is_ipv6 = 0;
11518 is_ip_any = 0;
11519 }
11520 else
11521 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
11522 {
11523 is_ipv6 = 0;
11524 is_ip_any = 0;
11525 }
11526 else
11527 if (unformat
11528 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
11529 {
11530 is_ipv6 = 0;
11531 is_ip_any = 0;
11532 }
11533 else
11534 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11535 {
11536 is_ipv6 = 0;
11537 is_ip_any = 0;
11538 }
11539 else
11540 if (unformat
11541 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11542 {
11543 is_ipv6 = 1;
11544 is_ip_any = 0;
11545 }
11546 else
11547 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11548 {
11549 is_ipv6 = 1;
11550 is_ip_any = 0;
11551 }
11552 else
11553 if (unformat
11554 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11555 {
11556 is_ipv6 = 1;
11557 is_ip_any = 0;
11558 }
11559 else
11560 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11561 {
11562 is_ipv6 = 1;
11563 is_ip_any = 0;
11564 }
11565 else
11566 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11567 {
11568 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11569 {
11570 clib_warning ("unsupported action: 'resolve'");
11571 return -99;
11572 }
11573 }
11574 else
11575 {
11576 clib_warning ("parse error '%U'", format_unformat_error, i);
11577 return -99;
11578 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011579
11580 }
11581
Dave Barach72d72232016-08-04 10:15:08 -040011582 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011583
Dave Barach72d72232016-08-04 10:15:08 -040011584 mp->spd_id = ntohl (spd_id);
11585 mp->priority = ntohl (priority);
11586 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011587
Dave Barach72d72232016-08-04 10:15:08 -040011588 mp->is_ipv6 = is_ipv6;
11589 if (is_ipv6 || is_ip_any)
11590 {
11591 clib_memcpy (mp->remote_address_start, &raddr6_start,
11592 sizeof (ip6_address_t));
11593 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11594 sizeof (ip6_address_t));
11595 clib_memcpy (mp->local_address_start, &laddr6_start,
11596 sizeof (ip6_address_t));
11597 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11598 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011599 }
Dave Barach72d72232016-08-04 10:15:08 -040011600 else
11601 {
11602 clib_memcpy (mp->remote_address_start, &raddr4_start,
11603 sizeof (ip4_address_t));
11604 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11605 sizeof (ip4_address_t));
11606 clib_memcpy (mp->local_address_start, &laddr4_start,
11607 sizeof (ip4_address_t));
11608 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11609 sizeof (ip4_address_t));
11610 }
11611 mp->protocol = (u8) protocol;
11612 mp->local_port_start = ntohs ((u16) lport_start);
11613 mp->local_port_stop = ntohs ((u16) lport_stop);
11614 mp->remote_port_start = ntohs ((u16) rport_start);
11615 mp->remote_port_stop = ntohs ((u16) rport_stop);
11616 mp->policy = (u8) policy;
11617 mp->sa_id = ntohl (sa_id);
11618 mp->is_add = is_add;
11619 mp->is_ip_any = is_ip_any;
11620 S;
11621 W;
11622 /* NOTREACHED */
11623 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011624#else
Dave Barach72d72232016-08-04 10:15:08 -040011625 clib_warning ("unsupported (no dpdk)");
11626 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011627#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011628}
11629
11630static int
11631api_ipsec_sad_add_del_entry (vat_main_t * vam)
11632{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011633#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011634 unformat_input_t *i = vam->input;
11635 vl_api_ipsec_sad_add_del_entry_t *mp;
11636 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011637 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011638 u8 *ck = 0, *ik = 0;
11639 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011640
Dave Barach72d72232016-08-04 10:15:08 -040011641 u8 protocol = IPSEC_PROTOCOL_AH;
11642 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11643 u32 crypto_alg = 0, integ_alg = 0;
11644 ip4_address_t tun_src4;
11645 ip4_address_t tun_dst4;
11646 ip6_address_t tun_src6;
11647 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011648
Dave Barach72d72232016-08-04 10:15:08 -040011649 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11650 {
11651 if (unformat (i, "del"))
11652 is_add = 0;
11653 else if (unformat (i, "sad_id %d", &sad_id))
11654 ;
11655 else if (unformat (i, "spi %d", &spi))
11656 ;
11657 else if (unformat (i, "esp"))
11658 protocol = IPSEC_PROTOCOL_ESP;
11659 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11660 {
11661 is_tunnel = 1;
11662 is_tunnel_ipv6 = 0;
11663 }
11664 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11665 {
11666 is_tunnel = 1;
11667 is_tunnel_ipv6 = 0;
11668 }
11669 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11670 {
11671 is_tunnel = 1;
11672 is_tunnel_ipv6 = 1;
11673 }
11674 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11675 {
11676 is_tunnel = 1;
11677 is_tunnel_ipv6 = 1;
11678 }
11679 else
11680 if (unformat
11681 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11682 {
11683 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
11684 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256)
11685 {
11686 clib_warning ("unsupported crypto-alg: '%U'",
11687 format_ipsec_crypto_alg, crypto_alg);
11688 return -99;
11689 }
11690 }
11691 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11692 ;
11693 else
11694 if (unformat
11695 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11696 {
11697 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
11698 integ_alg > IPSEC_INTEG_ALG_SHA_512_256)
11699 {
11700 clib_warning ("unsupported integ-alg: '%U'",
11701 format_ipsec_integ_alg, integ_alg);
11702 return -99;
11703 }
11704 }
11705 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11706 ;
11707 else
11708 {
11709 clib_warning ("parse error '%U'", format_unformat_error, i);
11710 return -99;
11711 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011712
11713 }
11714
Dave Barach72d72232016-08-04 10:15:08 -040011715 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011716
Dave Barach72d72232016-08-04 10:15:08 -040011717 mp->sad_id = ntohl (sad_id);
11718 mp->is_add = is_add;
11719 mp->protocol = protocol;
11720 mp->spi = ntohl (spi);
11721 mp->is_tunnel = is_tunnel;
11722 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11723 mp->crypto_algorithm = crypto_alg;
11724 mp->integrity_algorithm = integ_alg;
11725 mp->crypto_key_length = vec_len (ck);
11726 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011727
Dave Barach72d72232016-08-04 10:15:08 -040011728 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11729 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011730
Dave Barach72d72232016-08-04 10:15:08 -040011731 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11732 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011733
Dave Barach839fe3e2016-08-10 11:35:54 -040011734 if (ck)
11735 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11736 if (ik)
11737 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011738
Dave Barach72d72232016-08-04 10:15:08 -040011739 if (is_tunnel)
11740 {
11741 if (is_tunnel_ipv6)
11742 {
11743 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11744 sizeof (ip6_address_t));
11745 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
11746 sizeof (ip6_address_t));
11747 }
11748 else
11749 {
11750 clib_memcpy (mp->tunnel_src_address, &tun_src4,
11751 sizeof (ip4_address_t));
11752 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
11753 sizeof (ip4_address_t));
11754 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011755 }
11756
Dave Barach72d72232016-08-04 10:15:08 -040011757 S;
11758 W;
11759 /* NOTREACHED */
11760 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011761#else
Dave Barach72d72232016-08-04 10:15:08 -040011762 clib_warning ("unsupported (no dpdk)");
11763 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011764#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011765}
11766
11767static int
11768api_ipsec_sa_set_key (vat_main_t * vam)
11769{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011770#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011771 unformat_input_t *i = vam->input;
11772 vl_api_ipsec_sa_set_key_t *mp;
11773 f64 timeout;
11774 u32 sa_id;
11775 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011776
Dave Barach72d72232016-08-04 10:15:08 -040011777 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11778 {
11779 if (unformat (i, "sa_id %d", &sa_id))
11780 ;
11781 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11782 ;
11783 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11784 ;
11785 else
11786 {
11787 clib_warning ("parse error '%U'", format_unformat_error, i);
11788 return -99;
11789 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011790 }
11791
Dave Barach72d72232016-08-04 10:15:08 -040011792 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011793
Dave Barach72d72232016-08-04 10:15:08 -040011794 mp->sa_id = ntohl (sa_id);
11795 mp->crypto_key_length = vec_len (ck);
11796 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011797
Dave Barach72d72232016-08-04 10:15:08 -040011798 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11799 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011800
Dave Barach72d72232016-08-04 10:15:08 -040011801 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11802 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011803
Dave Barach839fe3e2016-08-10 11:35:54 -040011804 if (ck)
11805 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11806 if (ik)
11807 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011808
Dave Barach72d72232016-08-04 10:15:08 -040011809 S;
11810 W;
11811 /* NOTREACHED */
11812 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011813#else
Dave Barach72d72232016-08-04 10:15:08 -040011814 clib_warning ("unsupported (no dpdk)");
11815 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011816#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011817}
11818
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011819static int
11820api_ikev2_profile_add_del (vat_main_t * vam)
11821{
11822#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011823 unformat_input_t *i = vam->input;
11824 vl_api_ikev2_profile_add_del_t *mp;
11825 f64 timeout;
11826 u8 is_add = 1;
11827 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011828
Dave Barach72d72232016-08-04 10:15:08 -040011829 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011830
Dave Barach72d72232016-08-04 10:15:08 -040011831 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11832 {
11833 if (unformat (i, "del"))
11834 is_add = 0;
11835 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11836 vec_add1 (name, 0);
11837 else
11838 {
11839 errmsg ("parse error '%U'", format_unformat_error, i);
11840 return -99;
11841 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011842 }
11843
Dave Barach72d72232016-08-04 10:15:08 -040011844 if (!vec_len (name))
11845 {
11846 errmsg ("profile name must be specified");
11847 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011848 }
11849
Dave Barach72d72232016-08-04 10:15:08 -040011850 if (vec_len (name) > 64)
11851 {
11852 errmsg ("profile name too long");
11853 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011854 }
11855
Dave Barach72d72232016-08-04 10:15:08 -040011856 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011857
Dave Barach72d72232016-08-04 10:15:08 -040011858 clib_memcpy (mp->name, name, vec_len (name));
11859 mp->is_add = is_add;
11860 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011861
Dave Barach72d72232016-08-04 10:15:08 -040011862 S;
11863 W;
11864 /* NOTREACHED */
11865 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011866#else
Dave Barach72d72232016-08-04 10:15:08 -040011867 clib_warning ("unsupported (no dpdk)");
11868 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011869#endif
11870}
11871
11872static int
11873api_ikev2_profile_set_auth (vat_main_t * vam)
11874{
11875#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011876 unformat_input_t *i = vam->input;
11877 vl_api_ikev2_profile_set_auth_t *mp;
11878 f64 timeout;
11879 u8 *name = 0;
11880 u8 *data = 0;
11881 u32 auth_method = 0;
11882 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011883
Dave Barach72d72232016-08-04 10:15:08 -040011884 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011885
Dave Barach72d72232016-08-04 10:15:08 -040011886 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11887 {
11888 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11889 vec_add1 (name, 0);
11890 else if (unformat (i, "auth_method %U",
11891 unformat_ikev2_auth_method, &auth_method))
11892 ;
11893 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
11894 is_hex = 1;
11895 else if (unformat (i, "auth_data %v", &data))
11896 ;
11897 else
11898 {
11899 errmsg ("parse error '%U'", format_unformat_error, i);
11900 return -99;
11901 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011902 }
11903
Dave Barach72d72232016-08-04 10:15:08 -040011904 if (!vec_len (name))
11905 {
11906 errmsg ("profile name must be specified");
11907 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011908 }
11909
Dave Barach72d72232016-08-04 10:15:08 -040011910 if (vec_len (name) > 64)
11911 {
11912 errmsg ("profile name too long");
11913 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011914 }
11915
Dave Barach72d72232016-08-04 10:15:08 -040011916 if (!vec_len (data))
11917 {
11918 errmsg ("auth_data must be specified");
11919 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011920 }
11921
Dave Barach72d72232016-08-04 10:15:08 -040011922 if (!auth_method)
11923 {
11924 errmsg ("auth_method must be specified");
11925 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011926 }
11927
Dave Barach72d72232016-08-04 10:15:08 -040011928 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011929
Dave Barach72d72232016-08-04 10:15:08 -040011930 mp->is_hex = is_hex;
11931 mp->auth_method = (u8) auth_method;
11932 mp->data_len = vec_len (data);
11933 clib_memcpy (mp->name, name, vec_len (name));
11934 clib_memcpy (mp->data, data, vec_len (data));
11935 vec_free (name);
11936 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011937
Dave Barach72d72232016-08-04 10:15:08 -040011938 S;
11939 W;
11940 /* NOTREACHED */
11941 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011942#else
Dave Barach72d72232016-08-04 10:15:08 -040011943 clib_warning ("unsupported (no dpdk)");
11944 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011945#endif
11946}
11947
11948static int
11949api_ikev2_profile_set_id (vat_main_t * vam)
11950{
11951#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011952 unformat_input_t *i = vam->input;
11953 vl_api_ikev2_profile_set_id_t *mp;
11954 f64 timeout;
11955 u8 *name = 0;
11956 u8 *data = 0;
11957 u8 is_local = 0;
11958 u32 id_type = 0;
11959 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011960
Dave Barach72d72232016-08-04 10:15:08 -040011961 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011962
Dave Barach72d72232016-08-04 10:15:08 -040011963 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11964 {
11965 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11966 vec_add1 (name, 0);
11967 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
11968 ;
11969 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
11970 {
11971 data = vec_new (u8, 4);
11972 clib_memcpy (data, ip4.as_u8, 4);
11973 }
11974 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
11975 ;
11976 else if (unformat (i, "id_data %v", &data))
11977 ;
11978 else if (unformat (i, "local"))
11979 is_local = 1;
11980 else if (unformat (i, "remote"))
11981 is_local = 0;
11982 else
11983 {
11984 errmsg ("parse error '%U'", format_unformat_error, i);
11985 return -99;
11986 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011987 }
11988
Dave Barach72d72232016-08-04 10:15:08 -040011989 if (!vec_len (name))
11990 {
11991 errmsg ("profile name must be specified");
11992 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011993 }
11994
Dave Barach72d72232016-08-04 10:15:08 -040011995 if (vec_len (name) > 64)
11996 {
11997 errmsg ("profile name too long");
11998 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011999 }
12000
Dave Barach72d72232016-08-04 10:15:08 -040012001 if (!vec_len (data))
12002 {
12003 errmsg ("id_data must be specified");
12004 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012005 }
12006
Dave Barach72d72232016-08-04 10:15:08 -040012007 if (!id_type)
12008 {
12009 errmsg ("id_type must be specified");
12010 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012011 }
12012
Dave Barach72d72232016-08-04 10:15:08 -040012013 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012014
Dave Barach72d72232016-08-04 10:15:08 -040012015 mp->is_local = is_local;
12016 mp->id_type = (u8) id_type;
12017 mp->data_len = vec_len (data);
12018 clib_memcpy (mp->name, name, vec_len (name));
12019 clib_memcpy (mp->data, data, vec_len (data));
12020 vec_free (name);
12021 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012022
Dave Barach72d72232016-08-04 10:15:08 -040012023 S;
12024 W;
12025 /* NOTREACHED */
12026 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012027#else
Dave Barach72d72232016-08-04 10:15:08 -040012028 clib_warning ("unsupported (no dpdk)");
12029 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012030#endif
12031}
12032
12033static int
12034api_ikev2_profile_set_ts (vat_main_t * vam)
12035{
12036#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040012037 unformat_input_t *i = vam->input;
12038 vl_api_ikev2_profile_set_ts_t *mp;
12039 f64 timeout;
12040 u8 *name = 0;
12041 u8 is_local = 0;
12042 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
12043 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012044
Dave Barach72d72232016-08-04 10:15:08 -040012045 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012046
Dave Barach72d72232016-08-04 10:15:08 -040012047 start_addr.as_u32 = 0;
12048 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012049
Dave Barach72d72232016-08-04 10:15:08 -040012050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12051 {
12052 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12053 vec_add1 (name, 0);
12054 else if (unformat (i, "protocol %d", &proto))
12055 ;
12056 else if (unformat (i, "start_port %d", &start_port))
12057 ;
12058 else if (unformat (i, "end_port %d", &end_port))
12059 ;
12060 else
12061 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
12062 ;
12063 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
12064 ;
12065 else if (unformat (i, "local"))
12066 is_local = 1;
12067 else if (unformat (i, "remote"))
12068 is_local = 0;
12069 else
12070 {
12071 errmsg ("parse error '%U'", format_unformat_error, i);
12072 return -99;
12073 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012074 }
12075
Dave Barach72d72232016-08-04 10:15:08 -040012076 if (!vec_len (name))
12077 {
12078 errmsg ("profile name must be specified");
12079 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012080 }
12081
Dave Barach72d72232016-08-04 10:15:08 -040012082 if (vec_len (name) > 64)
12083 {
12084 errmsg ("profile name too long");
12085 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012086 }
12087
Dave Barach72d72232016-08-04 10:15:08 -040012088 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012089
Dave Barach72d72232016-08-04 10:15:08 -040012090 mp->is_local = is_local;
12091 mp->proto = (u8) proto;
12092 mp->start_port = (u16) start_port;
12093 mp->end_port = (u16) end_port;
12094 mp->start_addr = start_addr.as_u32;
12095 mp->end_addr = end_addr.as_u32;
12096 clib_memcpy (mp->name, name, vec_len (name));
12097 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012098
Dave Barach72d72232016-08-04 10:15:08 -040012099 S;
12100 W;
12101 /* NOTREACHED */
12102 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012103#else
Dave Barach72d72232016-08-04 10:15:08 -040012104 clib_warning ("unsupported (no dpdk)");
12105 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012106#endif
12107}
12108
12109static int
12110api_ikev2_set_local_key (vat_main_t * vam)
12111{
12112#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040012113 unformat_input_t *i = vam->input;
12114 vl_api_ikev2_set_local_key_t *mp;
12115 f64 timeout;
12116 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012117
Dave Barach72d72232016-08-04 10:15:08 -040012118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12119 {
12120 if (unformat (i, "file %v", &file))
12121 vec_add1 (file, 0);
12122 else
12123 {
12124 errmsg ("parse error '%U'", format_unformat_error, i);
12125 return -99;
12126 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012127 }
12128
Dave Barach72d72232016-08-04 10:15:08 -040012129 if (!vec_len (file))
12130 {
12131 errmsg ("RSA key file must be specified");
12132 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012133 }
12134
Dave Barach72d72232016-08-04 10:15:08 -040012135 if (vec_len (file) > 256)
12136 {
12137 errmsg ("file name too long");
12138 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012139 }
12140
Dave Barach72d72232016-08-04 10:15:08 -040012141 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012142
Dave Barach72d72232016-08-04 10:15:08 -040012143 clib_memcpy (mp->key_file, file, vec_len (file));
12144 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012145
Dave Barach72d72232016-08-04 10:15:08 -040012146 S;
12147 W;
12148 /* NOTREACHED */
12149 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012150#else
Dave Barach72d72232016-08-04 10:15:08 -040012151 clib_warning ("unsupported (no dpdk)");
12152 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012153#endif
12154}
12155
Ed Warnickecb9cada2015-12-08 15:45:58 -070012156/*
12157 * MAP
12158 */
Dave Barach72d72232016-08-04 10:15:08 -040012159static int
12160api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012161{
12162 unformat_input_t *i = vam->input;
12163 vl_api_map_add_domain_t *mp;
12164 f64 timeout;
12165
12166 ip4_address_t ip4_prefix;
12167 ip6_address_t ip6_prefix;
12168 ip6_address_t ip6_src;
12169 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012170 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
12171 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012172 u8 is_translation = 0;
12173 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020012174 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012175
Dave Barach72d72232016-08-04 10:15:08 -040012176 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12177 {
12178 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
12179 &ip4_prefix, &ip4_prefix_len))
12180 num_m_args++;
12181 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
12182 &ip6_prefix, &ip6_prefix_len))
12183 num_m_args++;
12184 else
12185 if (unformat
12186 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
12187 &ip6_src_len))
12188 num_m_args++;
12189 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
12190 num_m_args++;
12191 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
12192 num_m_args++;
12193 else if (unformat (i, "psid-offset %d", &psid_offset))
12194 num_m_args++;
12195 else if (unformat (i, "psid-len %d", &psid_length))
12196 num_m_args++;
12197 else if (unformat (i, "mtu %d", &mtu))
12198 num_m_args++;
12199 else if (unformat (i, "map-t"))
12200 is_translation = 1;
12201 else
12202 {
12203 clib_warning ("parse error '%U'", format_unformat_error, i);
12204 return -99;
12205 }
12206 }
12207
Ole Troan07e7eab2016-08-25 00:24:08 +020012208 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040012209 {
12210 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012211 return -99;
12212 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012213
12214 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012215 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012216
Dave Barach72d72232016-08-04 10:15:08 -040012217 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012218 mp->ip4_prefix_len = ip4_prefix_len;
12219
Dave Barach72d72232016-08-04 10:15:08 -040012220 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012221 mp->ip6_prefix_len = ip6_prefix_len;
12222
Dave Barach72d72232016-08-04 10:15:08 -040012223 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012224 mp->ip6_src_prefix_len = ip6_src_len;
12225
12226 mp->ea_bits_len = ea_bits_len;
12227 mp->psid_offset = psid_offset;
12228 mp->psid_length = psid_length;
12229 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040012230 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012231
12232 /* send it... */
12233 S;
12234
12235 /* Wait for a reply, return good/bad news */
12236 W;
12237}
12238
Dave Barach72d72232016-08-04 10:15:08 -040012239static int
12240api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012241{
12242 unformat_input_t *i = vam->input;
12243 vl_api_map_del_domain_t *mp;
12244 f64 timeout;
12245
12246 u32 num_m_args = 0;
12247 u32 index;
12248
Dave Barach72d72232016-08-04 10:15:08 -040012249 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12250 {
12251 if (unformat (i, "index %d", &index))
12252 num_m_args++;
12253 else
12254 {
12255 clib_warning ("parse error '%U'", format_unformat_error, i);
12256 return -99;
12257 }
12258 }
12259
12260 if (num_m_args != 1)
12261 {
12262 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012263 return -99;
12264 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012265
12266 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012267 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012268
Dave Barach72d72232016-08-04 10:15:08 -040012269 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012270
12271 /* send it... */
12272 S;
12273
12274 /* Wait for a reply, return good/bad news */
12275 W;
12276}
12277
Dave Barach72d72232016-08-04 10:15:08 -040012278static int
12279api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012280{
12281 unformat_input_t *i = vam->input;
12282 vl_api_map_add_del_rule_t *mp;
12283 f64 timeout;
12284 u8 is_add = 1;
12285 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040012286 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012287
Dave Barach72d72232016-08-04 10:15:08 -040012288 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12289 {
12290 if (unformat (i, "index %d", &index))
12291 num_m_args++;
12292 else if (unformat (i, "psid %d", &psid))
12293 num_m_args++;
12294 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
12295 num_m_args++;
12296 else if (unformat (i, "del"))
12297 {
12298 is_add = 0;
12299 }
12300 else
12301 {
12302 clib_warning ("parse error '%U'", format_unformat_error, i);
12303 return -99;
12304 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012305 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012306
12307 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012308 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012309
Dave Barach72d72232016-08-04 10:15:08 -040012310 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012311 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040012312 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
12313 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012314
12315 /* send it... */
12316 S;
12317
12318 /* Wait for a reply, return good/bad news */
12319 W;
12320}
12321
Dave Barach72d72232016-08-04 10:15:08 -040012322static int
12323api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012324{
Dave Barach72d72232016-08-04 10:15:08 -040012325 vl_api_map_domain_dump_t *mp;
12326 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012327
Dave Barach72d72232016-08-04 10:15:08 -040012328 /* Construct the API message */
12329 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012330
Dave Barach72d72232016-08-04 10:15:08 -040012331 /* send it... */
12332 S;
12333
12334 /* Use a control ping for synchronization */
12335 {
12336 vl_api_control_ping_t *mp;
12337 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012338 S;
Dave Barach72d72232016-08-04 10:15:08 -040012339 }
12340 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012341}
12342
Dave Barach72d72232016-08-04 10:15:08 -040012343static int
12344api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012345{
Dave Barach72d72232016-08-04 10:15:08 -040012346 unformat_input_t *i = vam->input;
12347 vl_api_map_rule_dump_t *mp;
12348 f64 timeout;
12349 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012350
Dave Barach72d72232016-08-04 10:15:08 -040012351 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012352 {
Dave Barach72d72232016-08-04 10:15:08 -040012353 if (unformat (i, "index %u", &domain_index))
12354 ;
12355 else
12356 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012357 }
Dave Barach72d72232016-08-04 10:15:08 -040012358
12359 if (domain_index == ~0)
12360 {
12361 clib_warning ("parse error: domain index expected");
12362 return -99;
12363 }
12364
12365 /* Construct the API message */
12366 M (MAP_RULE_DUMP, map_rule_dump);
12367
12368 mp->domain_index = htonl (domain_index);
12369
12370 /* send it... */
12371 S;
12372
12373 /* Use a control ping for synchronization */
12374 {
12375 vl_api_control_ping_t *mp;
12376 M (CONTROL_PING, control_ping);
12377 S;
12378 }
12379 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012380}
12381
12382static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040012383 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012384{
Dave Barach72d72232016-08-04 10:15:08 -040012385 vat_main_t *vam = &vat_main;
12386 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012387
Dave Barach72d72232016-08-04 10:15:08 -040012388 if (vam->async_mode)
12389 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012390 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040012391 }
12392 else
12393 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012394 vam->retval = retval;
12395 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012396 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012397}
12398
12399static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040012400 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012401{
Dave Barach72d72232016-08-04 10:15:08 -040012402 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012403 vat_json_node_t node;
12404
Dave Barach72d72232016-08-04 10:15:08 -040012405 vat_json_init_object (&node);
12406 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
12407 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012408
Dave Barach72d72232016-08-04 10:15:08 -040012409 vat_json_print (vam->ofp, &node);
12410 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012411
Dave Barach72d72232016-08-04 10:15:08 -040012412 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012413 vam->result_ready = 1;
12414}
12415
12416static int
12417api_get_first_msg_id (vat_main_t * vam)
12418{
Dave Barach72d72232016-08-04 10:15:08 -040012419 vl_api_get_first_msg_id_t *mp;
12420 f64 timeout;
12421 unformat_input_t *i = vam->input;
12422 u8 *name;
12423 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012424
Dave Barach72d72232016-08-04 10:15:08 -040012425 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12426 {
12427 if (unformat (i, "client %s", &name))
12428 name_set = 1;
12429 else
12430 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012431 }
12432
Dave Barach72d72232016-08-04 10:15:08 -040012433 if (name_set == 0)
12434 {
12435 errmsg ("missing client name\n");
12436 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012437 }
Dave Barach72d72232016-08-04 10:15:08 -040012438 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012439
Dave Barach72d72232016-08-04 10:15:08 -040012440 if (vec_len (name) > 63)
12441 {
12442 errmsg ("client name too long\n");
12443 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012444 }
12445
Dave Barach72d72232016-08-04 10:15:08 -040012446 M (GET_FIRST_MSG_ID, get_first_msg_id);
12447 clib_memcpy (mp->name, name, vec_len (name));
12448 S;
12449 W;
12450 /* NOTREACHED */
12451 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012452}
12453
Dave Barach72d72232016-08-04 10:15:08 -040012454static int
12455api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012456{
Dave Barach72d72232016-08-04 10:15:08 -040012457 unformat_input_t *line_input = vam->input;
12458 vl_api_cop_interface_enable_disable_t *mp;
12459 f64 timeout;
12460 u32 sw_if_index = ~0;
12461 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012462
Dave Barach72d72232016-08-04 10:15:08 -040012463 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12464 {
12465 if (unformat (line_input, "disable"))
12466 enable_disable = 0;
12467 if (unformat (line_input, "enable"))
12468 enable_disable = 1;
12469 else if (unformat (line_input, "%U", unformat_sw_if_index,
12470 vam, &sw_if_index))
12471 ;
12472 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12473 ;
12474 else
12475 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012476 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012477
Dave Barach72d72232016-08-04 10:15:08 -040012478 if (sw_if_index == ~0)
12479 {
12480 errmsg ("missing interface name or sw_if_index\n");
12481 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012482 }
12483
Dave Barach72d72232016-08-04 10:15:08 -040012484 /* Construct the API message */
12485 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
12486 mp->sw_if_index = ntohl (sw_if_index);
12487 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012488
Dave Barach72d72232016-08-04 10:15:08 -040012489 /* send it... */
12490 S;
12491 /* Wait for the reply */
12492 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012493}
12494
Dave Barach72d72232016-08-04 10:15:08 -040012495static int
12496api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012497{
Dave Barach72d72232016-08-04 10:15:08 -040012498 unformat_input_t *line_input = vam->input;
12499 vl_api_cop_whitelist_enable_disable_t *mp;
12500 f64 timeout;
12501 u32 sw_if_index = ~0;
12502 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012503 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012504
Dave Barach72d72232016-08-04 10:15:08 -040012505 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12506 {
12507 if (unformat (line_input, "ip4"))
12508 ip4 = 1;
12509 else if (unformat (line_input, "ip6"))
12510 ip6 = 1;
12511 else if (unformat (line_input, "default"))
12512 default_cop = 1;
12513 else if (unformat (line_input, "%U", unformat_sw_if_index,
12514 vam, &sw_if_index))
12515 ;
12516 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12517 ;
12518 else if (unformat (line_input, "fib-id %d", &fib_id))
12519 ;
12520 else
12521 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012522 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012523
Dave Barach72d72232016-08-04 10:15:08 -040012524 if (sw_if_index == ~0)
12525 {
12526 errmsg ("missing interface name or sw_if_index\n");
12527 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012528 }
12529
Dave Barach72d72232016-08-04 10:15:08 -040012530 /* Construct the API message */
12531 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
12532 mp->sw_if_index = ntohl (sw_if_index);
12533 mp->fib_id = ntohl (fib_id);
12534 mp->ip4 = ip4;
12535 mp->ip6 = ip6;
12536 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012537
Dave Barach72d72232016-08-04 10:15:08 -040012538 /* send it... */
12539 S;
12540 /* Wait for the reply */
12541 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012542}
12543
Dave Barach72d72232016-08-04 10:15:08 -040012544static int
12545api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012546{
Dave Barach72d72232016-08-04 10:15:08 -040012547 vl_api_get_node_graph_t *mp;
12548 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012549
Dave Barach72d72232016-08-04 10:15:08 -040012550 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012551
Dave Barach72d72232016-08-04 10:15:08 -040012552 /* send it... */
12553 S;
12554 /* Wait for the reply */
12555 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012556}
12557
Dave Barach72d72232016-08-04 10:15:08 -040012558/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012559/** Used for parsing LISP eids */
12560typedef CLIB_PACKED(struct{
12561 u8 addr[16]; /**< eid address */
12562 u32 len; /**< prefix length if IP */
12563 u8 type; /**< type of eid */
12564}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012565/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012566
12567static uword
12568unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12569{
Dave Barach72d72232016-08-04 10:15:08 -040012570 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012571
Dave Barach72d72232016-08-04 10:15:08 -040012572 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012573
Dave Barach72d72232016-08-04 10:15:08 -040012574 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12575 {
12576 a->type = 0; /* ipv4 type */
12577 }
12578 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12579 {
12580 a->type = 1; /* ipv6 type */
12581 }
12582 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12583 {
12584 a->type = 2; /* mac type */
12585 }
12586 else
12587 {
Florin Coras429e7952016-08-02 02:31:03 +020012588 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012589 }
Florin Coras429e7952016-08-02 02:31:03 +020012590
Dave Barach72d72232016-08-04 10:15:08 -040012591 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12592 {
Florin Coras429e7952016-08-02 02:31:03 +020012593 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012594 }
Florin Coras429e7952016-08-02 02:31:03 +020012595
12596 return 1;
12597}
12598
12599static int
12600lisp_eid_size_vat (u8 type)
12601{
Dave Barach72d72232016-08-04 10:15:08 -040012602 switch (type)
12603 {
Florin Coras429e7952016-08-02 02:31:03 +020012604 case 0:
12605 return 4;
12606 case 1:
12607 return 16;
12608 case 2:
12609 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012610 }
Florin Coras429e7952016-08-02 02:31:03 +020012611 return 0;
12612}
12613
12614static void
12615lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12616{
Dave Barach72d72232016-08-04 10:15:08 -040012617 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012618}
12619
Dave Barach72d72232016-08-04 10:15:08 -040012620/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012621/** Used for transferring locators via VPP API */
12622typedef CLIB_PACKED(struct
12623{
Dave Barach72d72232016-08-04 10:15:08 -040012624 u32 sw_if_index; /**< locator sw_if_index */
12625 u8 priority; /**< locator priority */
12626 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012627}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012628/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012629
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012630static int
Dave Barach72d72232016-08-04 10:15:08 -040012631api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012632{
Dave Barach72d72232016-08-04 10:15:08 -040012633 unformat_input_t *input = vam->input;
12634 vl_api_lisp_add_del_locator_set_t *mp;
12635 f64 timeout = ~0;
12636 u8 is_add = 1;
12637 u8 *locator_set_name = NULL;
12638 u8 locator_set_name_set = 0;
12639 ls_locator_t locator, *locators = 0;
12640 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012641 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012642
Dave Barach72d72232016-08-04 10:15:08 -040012643 /* Parse args required to build the message */
12644 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12645 {
12646 if (unformat (input, "del"))
12647 {
12648 is_add = 0;
12649 }
12650 else if (unformat (input, "locator-set %s", &locator_set_name))
12651 {
12652 locator_set_name_set = 1;
12653 }
12654 else if (unformat (input, "sw_if_index %u p %u w %u",
12655 &sw_if_index, &priority, &weight))
12656 {
12657 locator.sw_if_index = htonl (sw_if_index);
12658 locator.priority = priority;
12659 locator.weight = weight;
12660 vec_add1 (locators, locator);
12661 }
12662 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12663 vam, &sw_if_index, &priority, &weight))
12664 {
12665 locator.sw_if_index = htonl (sw_if_index);
12666 locator.priority = priority;
12667 locator.weight = weight;
12668 vec_add1 (locators, locator);
12669 }
12670 else
12671 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012672 }
12673
Dave Barach72d72232016-08-04 10:15:08 -040012674 if (locator_set_name_set == 0)
12675 {
12676 errmsg ("missing locator-set name");
12677 vec_free (locators);
12678 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012679 }
12680
Dave Barach72d72232016-08-04 10:15:08 -040012681 if (vec_len (locator_set_name) > 64)
12682 {
12683 errmsg ("locator-set name too long\n");
12684 vec_free (locator_set_name);
12685 vec_free (locators);
12686 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012687 }
Dave Barach72d72232016-08-04 10:15:08 -040012688 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012689
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012690 data_len = sizeof (ls_locator_t) * vec_len (locators);
12691
Dave Barach72d72232016-08-04 10:15:08 -040012692 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012693 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012694
Dave Barach72d72232016-08-04 10:15:08 -040012695 mp->is_add = is_add;
12696 clib_memcpy (mp->locator_set_name, locator_set_name,
12697 vec_len (locator_set_name));
12698 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012699
Filip Tehlare3552c42016-08-26 12:44:38 +020012700 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012701 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012702 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012703 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012704
Dave Barach72d72232016-08-04 10:15:08 -040012705 /* send it... */
12706 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012707
Dave Barach72d72232016-08-04 10:15:08 -040012708 /* Wait for a reply... */
12709 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012710
Dave Barach72d72232016-08-04 10:15:08 -040012711 /* NOTREACHED */
12712 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012713}
12714
12715static int
Dave Barach72d72232016-08-04 10:15:08 -040012716api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012717{
Dave Barach72d72232016-08-04 10:15:08 -040012718 unformat_input_t *input = vam->input;
12719 vl_api_lisp_add_del_locator_t *mp;
12720 f64 timeout = ~0;
12721 u32 tmp_if_index = ~0;
12722 u32 sw_if_index = ~0;
12723 u8 sw_if_index_set = 0;
12724 u8 sw_if_index_if_name_set = 0;
12725 u32 priority = ~0;
12726 u8 priority_set = 0;
12727 u32 weight = ~0;
12728 u8 weight_set = 0;
12729 u8 is_add = 1;
12730 u8 *locator_set_name = NULL;
12731 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012732
Dave Barach72d72232016-08-04 10:15:08 -040012733 /* Parse args required to build the message */
12734 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12735 {
12736 if (unformat (input, "del"))
12737 {
12738 is_add = 0;
12739 }
12740 else if (unformat (input, "locator-set %s", &locator_set_name))
12741 {
12742 locator_set_name_set = 1;
12743 }
12744 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12745 &tmp_if_index))
12746 {
12747 sw_if_index_if_name_set = 1;
12748 sw_if_index = tmp_if_index;
12749 }
12750 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12751 {
12752 sw_if_index_set = 1;
12753 sw_if_index = tmp_if_index;
12754 }
12755 else if (unformat (input, "p %d", &priority))
12756 {
12757 priority_set = 1;
12758 }
12759 else if (unformat (input, "w %d", &weight))
12760 {
12761 weight_set = 1;
12762 }
12763 else
12764 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012765 }
12766
Dave Barach72d72232016-08-04 10:15:08 -040012767 if (locator_set_name_set == 0)
12768 {
12769 errmsg ("missing locator-set name");
12770 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012771 }
12772
Dave Barach72d72232016-08-04 10:15:08 -040012773 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12774 {
12775 errmsg ("missing sw_if_index");
12776 vec_free (locator_set_name);
12777 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012778 }
12779
Dave Barach72d72232016-08-04 10:15:08 -040012780 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
12781 {
12782 errmsg ("cannot use both params interface name and sw_if_index");
12783 vec_free (locator_set_name);
12784 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012785 }
12786
Dave Barach72d72232016-08-04 10:15:08 -040012787 if (priority_set == 0)
12788 {
12789 errmsg ("missing locator-set priority\n");
12790 vec_free (locator_set_name);
12791 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012792 }
12793
Dave Barach72d72232016-08-04 10:15:08 -040012794 if (weight_set == 0)
12795 {
12796 errmsg ("missing locator-set weight\n");
12797 vec_free (locator_set_name);
12798 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012799 }
12800
Dave Barach72d72232016-08-04 10:15:08 -040012801 if (vec_len (locator_set_name) > 64)
12802 {
12803 errmsg ("locator-set name too long\n");
12804 vec_free (locator_set_name);
12805 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012806 }
Dave Barach72d72232016-08-04 10:15:08 -040012807 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012808
Dave Barach72d72232016-08-04 10:15:08 -040012809 /* Construct the API message */
12810 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012811
Dave Barach72d72232016-08-04 10:15:08 -040012812 mp->is_add = is_add;
12813 mp->sw_if_index = ntohl (sw_if_index);
12814 mp->priority = priority;
12815 mp->weight = weight;
12816 clib_memcpy (mp->locator_set_name, locator_set_name,
12817 vec_len (locator_set_name));
12818 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012819
Dave Barach72d72232016-08-04 10:15:08 -040012820 /* send it... */
12821 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012822
Dave Barach72d72232016-08-04 10:15:08 -040012823 /* Wait for a reply... */
12824 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012825
Dave Barach72d72232016-08-04 10:15:08 -040012826 /* NOTREACHED */
12827 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012828}
12829
12830static int
Dave Barach72d72232016-08-04 10:15:08 -040012831api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012832{
Dave Barach72d72232016-08-04 10:15:08 -040012833 unformat_input_t *input = vam->input;
12834 vl_api_lisp_add_del_local_eid_t *mp;
12835 f64 timeout = ~0;
12836 u8 is_add = 1;
12837 u8 eid_set = 0;
12838 lisp_eid_vat_t _eid, *eid = &_eid;
12839 u8 *locator_set_name = 0;
12840 u8 locator_set_name_set = 0;
12841 u32 vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012842
Dave Barach72d72232016-08-04 10:15:08 -040012843 /* Parse args required to build the message */
12844 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12845 {
12846 if (unformat (input, "del"))
12847 {
12848 is_add = 0;
12849 }
12850 else if (unformat (input, "vni %d", &vni))
12851 {
12852 ;
12853 }
12854 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
12855 {
12856 eid_set = 1;
12857 }
12858 else if (unformat (input, "locator-set %s", &locator_set_name))
12859 {
12860 locator_set_name_set = 1;
12861 }
12862 else
12863 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012864 }
12865
Dave Barach72d72232016-08-04 10:15:08 -040012866 if (locator_set_name_set == 0)
12867 {
12868 errmsg ("missing locator-set name\n");
12869 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012870 }
12871
Dave Barach72d72232016-08-04 10:15:08 -040012872 if (0 == eid_set)
12873 {
12874 errmsg ("EID address not set!");
12875 vec_free (locator_set_name);
12876 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020012877 }
12878
Dave Barach72d72232016-08-04 10:15:08 -040012879 if (vec_len (locator_set_name) > 64)
12880 {
12881 errmsg ("locator-set name too long\n");
12882 vec_free (locator_set_name);
12883 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012884 }
Dave Barach72d72232016-08-04 10:15:08 -040012885 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012886
Dave Barach72d72232016-08-04 10:15:08 -040012887 /* Construct the API message */
12888 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012889
Dave Barach72d72232016-08-04 10:15:08 -040012890 mp->is_add = is_add;
12891 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
12892 mp->eid_type = eid->type;
12893 mp->prefix_len = eid->len;
12894 mp->vni = clib_host_to_net_u32 (vni);
12895 clib_memcpy (mp->locator_set_name, locator_set_name,
12896 vec_len (locator_set_name));
Florin Coras429e7952016-08-02 02:31:03 +020012897
Dave Barach72d72232016-08-04 10:15:08 -040012898 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012899
Dave Barach72d72232016-08-04 10:15:08 -040012900 /* send it... */
12901 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012902
Dave Barach72d72232016-08-04 10:15:08 -040012903 /* Wait for a reply... */
12904 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012905
Dave Barach72d72232016-08-04 10:15:08 -040012906 /* NOTREACHED */
12907 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012908}
12909
Dave Barach72d72232016-08-04 10:15:08 -040012910/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012911/** Used for transferring locators via VPP API */
12912typedef CLIB_PACKED(struct
12913{
Dave Barach72d72232016-08-04 10:15:08 -040012914 u8 is_ip4; /**< is locator an IPv4 address? */
12915 u8 priority; /**< locator priority */
12916 u8 weight; /**< locator weight */
12917 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020012918}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040012919/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012920
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012921static int
Dave Barach72d72232016-08-04 10:15:08 -040012922api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012923{
Dave Barach72d72232016-08-04 10:15:08 -040012924 unformat_input_t *input = vam->input;
12925 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
12926 f64 timeout = ~0;
12927 u8 is_add = 1;
12928 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
12929 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
12930 u8 rmt_eid_set = 0, lcl_eid_set = 0;
12931 u32 action = ~0, p, w;
12932 ip4_address_t rmt_rloc4, lcl_rloc4;
12933 ip6_address_t rmt_rloc6, lcl_rloc6;
12934 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012935
Dave Barach839fe3e2016-08-10 11:35:54 -040012936 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020012937
Dave Barach72d72232016-08-04 10:15:08 -040012938 /* Parse args required to build the message */
12939 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12940 {
12941 if (unformat (input, "del"))
12942 {
12943 is_add = 0;
12944 }
12945 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
12946 {
12947 rmt_eid_set = 1;
12948 }
12949 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
12950 {
12951 lcl_eid_set = 1;
12952 }
12953 else if (unformat (input, "p %d w %d", &p, &w))
12954 {
12955 if (!curr_rloc)
12956 {
12957 errmsg ("No RLOC configured for setting priority/weight!");
12958 return -99;
12959 }
12960 curr_rloc->priority = p;
12961 curr_rloc->weight = w;
12962 }
12963 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
12964 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
12965 {
12966 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020012967
Dave Barach72d72232016-08-04 10:15:08 -040012968 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020012969 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012970 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012971
Dave Barach72d72232016-08-04 10:15:08 -040012972 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
12973 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012974 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012975 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12976 }
Florin Coras7fbfad32016-08-05 16:57:33 +020012977 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040012978 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
12979 {
12980 rloc.is_ip4 = 0;
12981 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020012982 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012983 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012984
Dave Barach72d72232016-08-04 10:15:08 -040012985 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
12986 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012987 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012988 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12989 }
12990 else if (unformat (input, "action %d", &action))
12991 {
12992 ;
12993 }
12994 else
12995 {
12996 clib_warning ("parse error '%U'", format_unformat_error, input);
12997 return -99;
12998 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012999 }
13000
Dave Barach72d72232016-08-04 10:15:08 -040013001 if (!rmt_eid_set)
13002 {
13003 errmsg ("remote eid addresses not set\n");
13004 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013005 }
13006
Dave Barach72d72232016-08-04 10:15:08 -040013007 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
13008 {
13009 errmsg ("eid types don't match\n");
13010 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013011 }
13012
Dave Barach839fe3e2016-08-10 11:35:54 -040013013 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020013014 {
13015 errmsg ("action not set for negative mapping\n");
13016 return -99;
13017 }
13018
Dave Barach72d72232016-08-04 10:15:08 -040013019 /* Construct the API message */
13020 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013021
Dave Barach72d72232016-08-04 10:15:08 -040013022 mp->is_add = is_add;
13023 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
13024 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
13025 mp->eid_type = rmt_eid->type;
13026 mp->rmt_len = rmt_eid->len;
13027 mp->lcl_len = lcl_eid->len;
13028 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020013029
Florin Coras7fbfad32016-08-05 16:57:33 +020013030 if (0 != rmt_locs && 0 != lcl_locs)
13031 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013032 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020013033 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013034 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013035 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013036 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013037 }
Dave Barach72d72232016-08-04 10:15:08 -040013038 vec_free (lcl_locs);
13039 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013040
Dave Barach72d72232016-08-04 10:15:08 -040013041 /* send it... */
13042 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013043
Dave Barach72d72232016-08-04 10:15:08 -040013044 /* Wait for a reply... */
13045 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013046
Dave Barach72d72232016-08-04 10:15:08 -040013047 /* NOTREACHED */
13048 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013049}
13050
13051static int
Dave Barach72d72232016-08-04 10:15:08 -040013052api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013053{
Dave Barach72d72232016-08-04 10:15:08 -040013054 unformat_input_t *input = vam->input;
13055 vl_api_lisp_add_del_map_resolver_t *mp;
13056 f64 timeout = ~0;
13057 u8 is_add = 1;
13058 u8 ipv4_set = 0;
13059 u8 ipv6_set = 0;
13060 ip4_address_t ipv4;
13061 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013062
Dave Barach72d72232016-08-04 10:15:08 -040013063 /* Parse args required to build the message */
13064 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13065 {
13066 if (unformat (input, "del"))
13067 {
13068 is_add = 0;
13069 }
13070 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13071 {
13072 ipv4_set = 1;
13073 }
13074 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13075 {
13076 ipv6_set = 1;
13077 }
13078 else
13079 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013080 }
13081
Dave Barach72d72232016-08-04 10:15:08 -040013082 if (ipv4_set && ipv6_set)
13083 {
13084 errmsg ("both eid v4 and v6 addresses set\n");
13085 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013086 }
13087
Dave Barach72d72232016-08-04 10:15:08 -040013088 if (!ipv4_set && !ipv6_set)
13089 {
13090 errmsg ("eid addresses not set\n");
13091 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013092 }
13093
Dave Barach72d72232016-08-04 10:15:08 -040013094 /* Construct the API message */
13095 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013096
Dave Barach72d72232016-08-04 10:15:08 -040013097 mp->is_add = is_add;
13098 if (ipv6_set)
13099 {
13100 mp->is_ipv6 = 1;
13101 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13102 }
13103 else
13104 {
13105 mp->is_ipv6 = 0;
13106 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013107 }
13108
Dave Barach72d72232016-08-04 10:15:08 -040013109 /* send it... */
13110 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013111
Dave Barach72d72232016-08-04 10:15:08 -040013112 /* Wait for a reply... */
13113 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013114
Dave Barach72d72232016-08-04 10:15:08 -040013115 /* NOTREACHED */
13116 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013117}
13118
13119static int
Florin Coras577c3552016-04-21 00:45:40 +020013120api_lisp_gpe_enable_disable (vat_main_t * vam)
13121{
Dave Barach72d72232016-08-04 10:15:08 -040013122 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020013123 vl_api_lisp_gpe_enable_disable_t *mp;
13124 f64 timeout = ~0;
13125 u8 is_set = 0;
13126 u8 is_en = 1;
13127
13128 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040013129 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13130 {
13131 if (unformat (input, "enable"))
13132 {
13133 is_set = 1;
13134 is_en = 1;
13135 }
13136 else if (unformat (input, "disable"))
13137 {
13138 is_set = 1;
13139 is_en = 0;
13140 }
13141 else
13142 break;
13143 }
Florin Coras577c3552016-04-21 00:45:40 +020013144
Dave Barach72d72232016-08-04 10:15:08 -040013145 if (is_set == 0)
13146 {
13147 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020013148 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013149 }
Florin Coras577c3552016-04-21 00:45:40 +020013150
13151 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013152 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020013153
13154 mp->is_en = is_en;
13155
13156 /* send it... */
13157 S;
13158
13159 /* Wait for a reply... */
13160 W;
13161
13162 /* NOTREACHED */
13163 return 0;
13164}
13165
13166static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020013167api_lisp_enable_disable (vat_main_t * vam)
13168{
Dave Barach72d72232016-08-04 10:15:08 -040013169 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013170 vl_api_lisp_enable_disable_t *mp;
13171 f64 timeout = ~0;
13172 u8 is_set = 0;
13173 u8 is_en = 0;
13174
13175 /* Parse args required to build the message */
13176 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13177 {
13178 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040013179 {
13180 is_set = 1;
13181 is_en = 1;
13182 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013183 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040013184 {
13185 is_set = 1;
13186 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013187 else
Dave Barach72d72232016-08-04 10:15:08 -040013188 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013189 }
13190
13191 if (!is_set)
13192 {
13193 errmsg ("Value not set\n");
13194 return -99;
13195 }
13196
13197 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013198 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020013199
13200 mp->is_en = is_en;
13201
13202 /* send it... */
13203 S;
13204
13205 /* Wait for a reply... */
13206 W;
13207
13208 /* NOTREACHED */
13209 return 0;
13210}
13211
Florin Corasdca88042016-09-14 16:01:38 +020013212static int
13213api_show_lisp_map_request_mode (vat_main_t * vam)
13214{
13215 f64 timeout = ~0;
13216 vl_api_show_lisp_map_request_mode_t *mp;
13217
13218 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
13219
13220 /* send */
13221 S;
13222
13223 /* wait for reply */
13224 W;
13225
13226 return 0;
13227}
13228
13229static int
13230api_lisp_map_request_mode (vat_main_t * vam)
13231{
13232 f64 timeout = ~0;
13233 unformat_input_t *input = vam->input;
13234 vl_api_lisp_map_request_mode_t *mp;
13235 u8 mode = 0;
13236
13237 /* Parse args required to build the message */
13238 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13239 {
13240 if (unformat (input, "dst-only"))
13241 mode = 0;
13242 else if (unformat (input, "src-dst"))
13243 mode = 1;
13244 else
13245 {
13246 errmsg ("parse error '%U'", format_unformat_error, input);
13247 return -99;
13248 }
13249 }
13250
13251 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
13252
13253 mp->mode = mode;
13254
13255 /* send */
13256 S;
13257
13258 /* wait for reply */
13259 W;
13260
13261 /* notreached */
13262 return 0;
13263}
13264
Filip Tehlar195bcee2016-05-13 17:37:35 +020013265/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020013266 * Enable/disable LISP proxy ITR.
13267 *
13268 * @param vam vpp API test context
13269 * @return return code
13270 */
13271static int
13272api_lisp_pitr_set_locator_set (vat_main_t * vam)
13273{
13274 f64 timeout = ~0;
13275 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013276 unformat_input_t *input = vam->input;
13277 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013278 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013279 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013280
13281 /* Parse args required to build the message */
13282 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13283 {
13284 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013285 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013286 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040013287 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013288 else
Dave Barach72d72232016-08-04 10:15:08 -040013289 {
13290 errmsg ("parse error '%U'", format_unformat_error, input);
13291 return -99;
13292 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020013293 }
13294
13295 if (!ls_name_set)
13296 {
13297 errmsg ("locator-set name not set!");
13298 return -99;
13299 }
13300
Dave Barach72d72232016-08-04 10:15:08 -040013301 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020013302
13303 mp->is_add = is_add;
13304 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
13305 vec_free (ls_name);
13306
13307 /* send */
13308 S;
13309
13310 /* wait for reply */
13311 W;
13312
Dave Barach72d72232016-08-04 10:15:08 -040013313 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020013314 return 0;
13315}
13316
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013317static int
13318api_show_lisp_pitr (vat_main_t * vam)
13319{
Dave Barach72d72232016-08-04 10:15:08 -040013320 vl_api_show_lisp_pitr_t *mp;
13321 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013322
Dave Barach72d72232016-08-04 10:15:08 -040013323 if (!vam->json_output)
13324 {
13325 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013326 }
13327
Dave Barach72d72232016-08-04 10:15:08 -040013328 M (SHOW_LISP_PITR, show_lisp_pitr);
13329 /* send it... */
13330 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013331
Dave Barach72d72232016-08-04 10:15:08 -040013332 /* Wait for a reply... */
13333 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013334
Dave Barach72d72232016-08-04 10:15:08 -040013335 /* NOTREACHED */
13336 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013337}
13338
Filip Tehlar53f09e32016-05-19 14:25:44 +020013339/**
Filip Tehlar324112f2016-06-02 16:07:38 +020013340 * Add/delete mapping between vni and vrf
13341 */
13342static int
13343api_lisp_eid_table_add_del_map (vat_main_t * vam)
13344{
13345 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013346 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020013347 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020013348 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
13349 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020013350
13351 /* Parse args required to build the message */
13352 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13353 {
13354 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013355 is_add = 0;
13356 else if (unformat (input, "vrf %d", &vrf))
13357 vrf_set = 1;
13358 else if (unformat (input, "bd_index %d", &bd_index))
13359 bd_index_set = 1;
13360 else if (unformat (input, "vni %d", &vni))
13361 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020013362 else
Dave Barach72d72232016-08-04 10:15:08 -040013363 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020013364 }
13365
Florin Coras1a1adc72016-07-22 01:45:30 +020013366 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020013367 {
13368 errmsg ("missing arguments!");
13369 return -99;
13370 }
13371
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013372 if (vrf_set && bd_index_set)
13373 {
13374 errmsg ("error: both vrf and bd entered!");
13375 return -99;
13376 }
13377
Dave Barach72d72232016-08-04 10:15:08 -040013378 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020013379
13380 mp->is_add = is_add;
13381 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013382 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020013383 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020013384
13385 /* send */
13386 S;
13387
13388 /* wait for reply */
13389 W;
13390
Dave Barach72d72232016-08-04 10:15:08 -040013391 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020013392 return 0;
13393}
13394
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013395uword
13396unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
13397{
13398 u32 *action = va_arg (*args, u32 *);
13399 u8 *s = 0;
13400
13401 if (unformat (input, "%s", &s))
13402 {
13403 if (!strcmp ((char *) s, "no-action"))
13404 action[0] = 0;
13405 else if (!strcmp ((char *) s, "natively-forward"))
13406 action[0] = 1;
13407 else if (!strcmp ((char *) s, "send-map-request"))
13408 action[0] = 2;
13409 else if (!strcmp ((char *) s, "drop"))
13410 action[0] = 3;
13411 else
13412 {
13413 clib_warning ("invalid action: '%s'", s);
13414 action[0] = 3;
13415 }
13416 }
13417 else
13418 return 0;
13419
13420 vec_free (s);
13421 return 1;
13422}
13423
Filip Tehlar324112f2016-06-02 16:07:38 +020013424/**
Florin Corasf727db92016-06-23 15:01:58 +020013425 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020013426 *
13427 * @param vam vpp API test context
13428 * @return return code
13429 */
13430static int
13431api_lisp_add_del_remote_mapping (vat_main_t * vam)
13432{
Dave Barach72d72232016-08-04 10:15:08 -040013433 unformat_input_t *input = vam->input;
13434 vl_api_lisp_add_del_remote_mapping_t *mp;
13435 f64 timeout = ~0;
13436 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013437 lisp_eid_vat_t _eid, *eid = &_eid;
13438 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013439 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013440 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040013441 ip4_address_t rloc4;
13442 ip6_address_t rloc6;
13443 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013444
Dave Barach839fe3e2016-08-10 11:35:54 -040013445 memset (&rloc, 0, sizeof (rloc));
13446
Dave Barach72d72232016-08-04 10:15:08 -040013447 /* Parse args required to build the message */
13448 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13449 {
13450 if (unformat (input, "del-all"))
13451 {
13452 del_all = 1;
13453 }
13454 else if (unformat (input, "del"))
13455 {
13456 is_add = 0;
13457 }
13458 else if (unformat (input, "add"))
13459 {
13460 is_add = 1;
13461 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020013462 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040013463 {
13464 eid_set = 1;
13465 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013466 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040013467 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013468 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013469 }
13470 else if (unformat (input, "vni %d", &vni))
13471 {
13472 ;
13473 }
13474 else if (unformat (input, "p %d w %d", &p, &w))
13475 {
13476 if (!curr_rloc)
13477 {
13478 errmsg ("No RLOC configured for setting priority/weight!");
13479 return -99;
13480 }
13481 curr_rloc->priority = p;
13482 curr_rloc->weight = w;
13483 }
13484 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
13485 {
13486 rloc.is_ip4 = 1;
13487 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
13488 vec_add1 (rlocs, rloc);
13489 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13490 }
13491 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
13492 {
13493 rloc.is_ip4 = 0;
13494 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
13495 vec_add1 (rlocs, rloc);
13496 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13497 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013498 else if (unformat (input, "action %U",
13499 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040013500 {
13501 ;
13502 }
13503 else
13504 {
13505 clib_warning ("parse error '%U'", format_unformat_error, input);
13506 return -99;
13507 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020013508 }
13509
Dave Barach72d72232016-08-04 10:15:08 -040013510 if (0 == eid_set)
13511 {
13512 errmsg ("missing params!");
13513 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013514 }
13515
Dave Barach72d72232016-08-04 10:15:08 -040013516 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
13517 {
13518 errmsg ("no action set for negative map-reply!");
13519 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013520 }
13521
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013522 data_len = vec_len (rlocs) * sizeof (rloc_t);
13523
13524 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013525 mp->is_add = is_add;
13526 mp->vni = htonl (vni);
13527 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013528 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040013529 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013530 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040013531 mp->del_all = del_all;
13532 mp->eid_type = eid->type;
13533 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013534 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013535
Filip Tehlare3552c42016-08-26 12:44:38 +020013536 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013537 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013538 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013539
Dave Barach72d72232016-08-04 10:15:08 -040013540 /* send it... */
13541 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013542
Dave Barach72d72232016-08-04 10:15:08 -040013543 /* Wait for a reply... */
13544 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013545
Dave Barach72d72232016-08-04 10:15:08 -040013546 /* NOTREACHED */
13547 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013548}
13549
Florin Corasf727db92016-06-23 15:01:58 +020013550/**
13551 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
13552 * forwarding entries in data-plane accordingly.
13553 *
13554 * @param vam vpp API test context
13555 * @return return code
13556 */
13557static int
13558api_lisp_add_del_adjacency (vat_main_t * vam)
13559{
Dave Barach72d72232016-08-04 10:15:08 -040013560 unformat_input_t *input = vam->input;
13561 vl_api_lisp_add_del_adjacency_t *mp;
13562 f64 timeout = ~0;
13563 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013564 ip4_address_t leid4, reid4;
13565 ip6_address_t leid6, reid6;
13566 u8 reid_mac[6] = { 0 };
13567 u8 leid_mac[6] = { 0 };
13568 u8 reid_type, leid_type;
13569 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040013570 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020013571
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013572 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020013573
Dave Barach72d72232016-08-04 10:15:08 -040013574 /* Parse args required to build the message */
13575 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13576 {
13577 if (unformat (input, "del"))
13578 {
13579 is_add = 0;
13580 }
13581 else if (unformat (input, "add"))
13582 {
13583 is_add = 1;
13584 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013585 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
13586 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013587 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013588 reid_type = 0; /* ipv4 */
13589 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013590 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013591 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
13592 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013593 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013594 reid_type = 1; /* ipv6 */
13595 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013596 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013597 else if (unformat (input, "reid %U", unformat_ethernet_address,
13598 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013599 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013600 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013601 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013602 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
13603 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013604 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013605 leid_type = 0; /* ipv4 */
13606 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013607 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013608 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
13609 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013610 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013611 leid_type = 1; /* ipv6 */
13612 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013613 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013614 else if (unformat (input, "leid %U", unformat_ethernet_address,
13615 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013616 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013617 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013618 }
13619 else if (unformat (input, "vni %d", &vni))
13620 {
13621 ;
13622 }
13623 else
13624 {
13625 errmsg ("parse error '%U'", format_unformat_error, input);
13626 return -99;
13627 }
Florin Corasf727db92016-06-23 15:01:58 +020013628 }
13629
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013630 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013631 {
13632 errmsg ("missing params!");
13633 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013634 }
13635
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013636 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013637 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013638 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040013639 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013640 }
13641
Dave Barach72d72232016-08-04 10:15:08 -040013642 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
13643 mp->is_add = is_add;
13644 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013645 mp->leid_len = leid_len;
13646 mp->reid_len = reid_len;
13647 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020013648
Dave Barach72d72232016-08-04 10:15:08 -040013649 switch (mp->eid_type)
13650 {
Florin Corasf727db92016-06-23 15:01:58 +020013651 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013652 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
13653 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040013654 break;
Florin Corasf727db92016-06-23 15:01:58 +020013655 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013656 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
13657 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040013658 break;
Florin Corasf727db92016-06-23 15:01:58 +020013659 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013660 clib_memcpy (mp->leid, leid_mac, 6);
13661 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040013662 break;
Florin Corasf727db92016-06-23 15:01:58 +020013663 default:
Dave Barach72d72232016-08-04 10:15:08 -040013664 errmsg ("unknown EID type %d!", mp->eid_type);
13665 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013666 }
13667
Dave Barach72d72232016-08-04 10:15:08 -040013668 /* send it... */
13669 S;
Florin Corasf727db92016-06-23 15:01:58 +020013670
Dave Barach72d72232016-08-04 10:15:08 -040013671 /* Wait for a reply... */
13672 W;
Florin Corasf727db92016-06-23 15:01:58 +020013673
Dave Barach72d72232016-08-04 10:15:08 -040013674 /* NOTREACHED */
13675 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013676}
13677
Filip Tehlar46d4e362016-05-09 09:39:26 +020013678static int
Dave Barach72d72232016-08-04 10:15:08 -040013679api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013680{
Dave Barach72d72232016-08-04 10:15:08 -040013681 unformat_input_t *input = vam->input;
13682 vl_api_lisp_gpe_add_del_iface_t *mp;
13683 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020013684 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040013685 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013686
Dave Barach72d72232016-08-04 10:15:08 -040013687 /* Parse args required to build the message */
13688 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13689 {
13690 if (unformat (input, "up"))
13691 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013692 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013693 is_add = 1;
13694 }
13695 else if (unformat (input, "down"))
13696 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013697 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013698 is_add = 0;
13699 }
13700 else if (unformat (input, "table_id %d", &dp_table))
13701 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013702 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013703 }
13704 else if (unformat (input, "bd_id %d", &dp_table))
13705 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013706 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013707 is_l2 = 1;
13708 }
13709 else if (unformat (input, "vni %d", &vni))
13710 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013711 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013712 }
13713 else
13714 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013715 }
13716
Florin Coras7fbfad32016-08-05 16:57:33 +020013717 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040013718 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013719 errmsg ("Action not set\n");
13720 return -99;
13721 }
13722 if (dp_table_set == 0 || vni_set == 0)
13723 {
13724 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040013725 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013726 }
13727
Dave Barach72d72232016-08-04 10:15:08 -040013728 /* Construct the API message */
13729 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013730
Dave Barach72d72232016-08-04 10:15:08 -040013731 mp->is_add = is_add;
13732 mp->dp_table = dp_table;
13733 mp->is_l2 = is_l2;
13734 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013735
Dave Barach72d72232016-08-04 10:15:08 -040013736 /* send it... */
13737 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013738
Dave Barach72d72232016-08-04 10:15:08 -040013739 /* Wait for a reply... */
13740 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013741
Dave Barach72d72232016-08-04 10:15:08 -040013742 /* NOTREACHED */
13743 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013744}
13745
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013746/**
13747 * Add/del map request itr rlocs from LISP control plane and updates
13748 *
13749 * @param vam vpp API test context
13750 * @return return code
13751 */
13752static int
Dave Barach72d72232016-08-04 10:15:08 -040013753api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013754{
Dave Barach72d72232016-08-04 10:15:08 -040013755 unformat_input_t *input = vam->input;
13756 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
13757 f64 timeout = ~0;
13758 u8 *locator_set_name = 0;
13759 u8 locator_set_name_set = 0;
13760 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013761
Dave Barach72d72232016-08-04 10:15:08 -040013762 /* Parse args required to build the message */
13763 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013764 {
Dave Barach72d72232016-08-04 10:15:08 -040013765 if (unformat (input, "del"))
13766 {
13767 is_add = 0;
13768 }
13769 else if (unformat (input, "%_%v%_", &locator_set_name))
13770 {
13771 locator_set_name_set = 1;
13772 }
13773 else
13774 {
13775 clib_warning ("parse error '%U'", format_unformat_error, input);
13776 return -99;
13777 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013778 }
13779
Dave Barach72d72232016-08-04 10:15:08 -040013780 if (is_add && !locator_set_name_set)
13781 {
13782 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020013783 return -99;
13784 }
13785
Dave Barach72d72232016-08-04 10:15:08 -040013786 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020013787 {
Dave Barach72d72232016-08-04 10:15:08 -040013788 errmsg ("itr-rloc locator-set name too long\n");
13789 vec_free (locator_set_name);
13790 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013791 }
13792
Dave Barach72d72232016-08-04 10:15:08 -040013793 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
13794 mp->is_add = is_add;
13795 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013796 {
Dave Barach72d72232016-08-04 10:15:08 -040013797 clib_memcpy (mp->locator_set_name, locator_set_name,
13798 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013799 }
Dave Barach72d72232016-08-04 10:15:08 -040013800 else
13801 {
13802 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013803 }
Dave Barach72d72232016-08-04 10:15:08 -040013804 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013805
Dave Barach72d72232016-08-04 10:15:08 -040013806 /* send it... */
13807 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013808
Dave Barach72d72232016-08-04 10:15:08 -040013809 /* Wait for a reply... */
13810 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013811
Dave Barach72d72232016-08-04 10:15:08 -040013812 /* NOTREACHED */
13813 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013814}
13815
13816static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013817api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013818{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013819 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013820 vl_api_lisp_locator_dump_t *mp;
13821 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013822 u8 is_index_set = 0, is_name_set = 0;
13823 u8 *ls_name = 0;
13824 u32 ls_index = ~0;
13825
13826 /* Parse args required to build the message */
13827 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13828 {
13829 if (unformat (input, "ls_name %_%v%_", &ls_name))
13830 {
13831 is_name_set = 1;
13832 }
13833 else if (unformat (input, "ls_index %d", &ls_index))
13834 {
13835 is_index_set = 1;
13836 }
13837 else
13838 {
13839 errmsg ("parse error '%U'", format_unformat_error, input);
13840 return -99;
13841 }
13842 }
13843
13844 if (!is_index_set && !is_name_set)
13845 {
13846 errmsg ("error: expected one of index or name!\n");
13847 return -99;
13848 }
13849
13850 if (is_index_set && is_name_set)
13851 {
13852 errmsg ("error: only one param expected!\n");
13853 return -99;
13854 }
13855
Florin Coras042d2122016-09-21 16:38:19 +020013856 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020013857 {
13858 errmsg ("error: locator set name too long!");
13859 return -99;
13860 }
13861
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013862 if (!vam->json_output)
13863 {
13864 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
13865 "weight");
13866 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013867
Dave Barach72d72232016-08-04 10:15:08 -040013868 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013869 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013870
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013871 if (is_index_set)
13872 mp->ls_index = clib_host_to_net_u32 (ls_index);
13873 else
13874 {
13875 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020013876 strncpy ((char *) mp->ls_name, (char *) ls_name,
13877 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013878 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013879
Dave Barach72d72232016-08-04 10:15:08 -040013880 /* send it... */
13881 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013882
Dave Barach72d72232016-08-04 10:15:08 -040013883 /* Use a control ping for synchronization */
13884 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013885 vl_api_control_ping_t *mp;
13886 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013887 S;
13888 }
13889 /* Wait for a reply... */
13890 W;
Dave Barach72d72232016-08-04 10:15:08 -040013891
13892 /* NOTREACHED */
13893 return 0;
13894}
13895
13896static int
13897api_lisp_locator_set_dump (vat_main_t * vam)
13898{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013899 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040013900 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013901 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013902 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013903
13904 /* Parse args required to build the message */
13905 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13906 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013907 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040013908 {
13909 filter = 1;
13910 }
13911 else if (unformat (input, "remote"))
13912 {
13913 filter = 2;
13914 }
13915 else
13916 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013917 errmsg ("parse error '%U'", format_unformat_error, input);
13918 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013919 }
13920 }
13921
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013922 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040013923 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013924 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040013925 }
13926
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013927 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040013928
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013929 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040013930
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013931 /* send it... */
13932 S;
13933
13934 /* Use a control ping for synchronization */
13935 {
13936 vl_api_control_ping_t *mp;
13937 M (CONTROL_PING, control_ping);
13938 S;
13939 }
13940 /* Wait for a reply... */
13941 W;
13942
13943 /* NOTREACHED */
13944 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040013945}
13946
13947static int
13948api_lisp_eid_table_map_dump (vat_main_t * vam)
13949{
Filip Tehlarc0681792016-08-24 14:11:07 +020013950 u8 is_l2 = 0;
13951 u8 mode_set = 0;
13952 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013953 vl_api_lisp_eid_table_map_dump_t *mp;
13954 f64 timeout = ~0;
13955
Filip Tehlarc0681792016-08-24 14:11:07 +020013956 /* Parse args required to build the message */
13957 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13958 {
13959 if (unformat (input, "l2"))
13960 {
13961 is_l2 = 1;
13962 mode_set = 1;
13963 }
13964 else if (unformat (input, "l3"))
13965 {
13966 is_l2 = 0;
13967 mode_set = 1;
13968 }
13969 else
13970 {
13971 errmsg ("parse error '%U'", format_unformat_error, input);
13972 return -99;
13973 }
13974 }
13975
13976 if (!mode_set)
13977 {
13978 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
13979 return -99;
13980 }
13981
Dave Barach72d72232016-08-04 10:15:08 -040013982 if (!vam->json_output)
13983 {
Filip Tehlarc0681792016-08-24 14:11:07 +020013984 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040013985 }
13986
13987 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020013988 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040013989
13990 /* send it... */
13991 S;
13992
13993 /* Use a control ping for synchronization */
13994 {
13995 vl_api_control_ping_t *mp;
13996 M (CONTROL_PING, control_ping);
13997 S;
13998 }
13999 /* Wait for a reply... */
14000 W;
14001
14002 /* NOTREACHED */
14003 return 0;
14004}
14005
14006static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020014007api_lisp_eid_table_vni_dump (vat_main_t * vam)
14008{
14009 vl_api_lisp_eid_table_vni_dump_t *mp;
14010 f64 timeout = ~0;
14011
14012 if (!vam->json_output)
14013 {
14014 fformat (vam->ofp, "VNI\n");
14015 }
14016
14017 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
14018
14019 /* send it... */
14020 S;
14021
14022 /* Use a control ping for synchronization */
14023 {
14024 vl_api_control_ping_t *mp;
14025 M (CONTROL_PING, control_ping);
14026 S;
14027 }
14028 /* Wait for a reply... */
14029 W;
14030
14031 /* NOTREACHED */
14032 return 0;
14033}
14034
14035static int
Dave Barach72d72232016-08-04 10:15:08 -040014036api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014037{
Dave Barach72d72232016-08-04 10:15:08 -040014038 unformat_input_t *i = vam->input;
14039 vl_api_lisp_eid_table_dump_t *mp;
14040 f64 timeout = ~0;
14041 struct in_addr ip4;
14042 struct in6_addr ip6;
14043 u8 mac[6];
14044 u8 eid_type = ~0, eid_set = 0;
14045 u32 prefix_length = ~0, t, vni = 0;
14046 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014047
Dave Barach72d72232016-08-04 10:15:08 -040014048 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014049 {
Dave Barach72d72232016-08-04 10:15:08 -040014050 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
14051 {
14052 eid_set = 1;
14053 eid_type = 0;
14054 prefix_length = t;
14055 }
14056 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
14057 {
14058 eid_set = 1;
14059 eid_type = 1;
14060 prefix_length = t;
14061 }
14062 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
14063 {
14064 eid_set = 1;
14065 eid_type = 2;
14066 }
14067 else if (unformat (i, "vni %d", &t))
14068 {
14069 vni = t;
14070 }
14071 else if (unformat (i, "local"))
14072 {
14073 filter = 1;
14074 }
14075 else if (unformat (i, "remote"))
14076 {
14077 filter = 2;
14078 }
14079 else
14080 {
14081 errmsg ("parse error '%U'", format_unformat_error, i);
14082 return -99;
14083 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014084 }
14085
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014086 if (!vam->json_output)
14087 {
14088 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type",
14089 "ls_index", "ttl", "authoritative");
14090 }
14091
Dave Barach72d72232016-08-04 10:15:08 -040014092 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014093
Dave Barach72d72232016-08-04 10:15:08 -040014094 mp->filter = filter;
14095 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014096 {
Dave Barach72d72232016-08-04 10:15:08 -040014097 mp->eid_set = 1;
14098 mp->vni = htonl (vni);
14099 mp->eid_type = eid_type;
14100 switch (eid_type)
14101 {
14102 case 0:
14103 mp->prefix_length = prefix_length;
14104 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
14105 break;
14106 case 1:
14107 mp->prefix_length = prefix_length;
14108 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
14109 break;
14110 case 2:
14111 clib_memcpy (mp->eid, mac, sizeof (mac));
14112 break;
14113 default:
14114 errmsg ("unknown EID type %d!", eid_type);
14115 return -99;
14116 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014117 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014118
Dave Barach72d72232016-08-04 10:15:08 -040014119 /* send it... */
14120 S;
14121
14122 /* Use a control ping for synchronization */
14123 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014124 vl_api_control_ping_t *mp;
14125 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014126 S;
14127 }
14128
14129 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014130 W;
Dave Barach72d72232016-08-04 10:15:08 -040014131
14132 /* NOTREACHED */
14133 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014134}
14135
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014136static int
Dave Barach72d72232016-08-04 10:15:08 -040014137api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014138{
Dave Barach72d72232016-08-04 10:15:08 -040014139 vl_api_lisp_gpe_tunnel_dump_t *mp;
14140 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014141
Dave Barach72d72232016-08-04 10:15:08 -040014142 if (!vam->json_output)
14143 {
14144 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
14145 "%=16s%=16s%=16s%=16s%=16s\n",
14146 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
14147 "Decap next", "Lisp version", "Flags", "Next protocol",
14148 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014149 }
14150
Dave Barach72d72232016-08-04 10:15:08 -040014151 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
14152 /* send it... */
14153 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014154
Dave Barach72d72232016-08-04 10:15:08 -040014155 /* Use a control ping for synchronization */
14156 {
14157 vl_api_control_ping_t *mp;
14158 M (CONTROL_PING, control_ping);
14159 S;
14160 }
14161 /* Wait for a reply... */
14162 W;
14163
14164 /* NOTREACHED */
14165 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014166}
14167
Matus Fabian8a95a482016-05-06 15:14:13 +020014168static int
Filip Tehlar69a9b762016-09-23 10:00:52 +020014169api_lisp_adjacencies_get (vat_main_t * vam)
14170{
14171 unformat_input_t *i = vam->input;
14172 vl_api_lisp_adjacencies_get_t *mp;
14173 f64 timeout = ~0;
14174 u8 vni_set = 0;
14175 u32 vni = ~0;
14176
14177 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14178 {
14179 if (unformat (i, "vni %d", &vni))
14180 {
14181 vni_set = 1;
14182 }
14183 else
14184 {
14185 errmsg ("parse error '%U'\n", format_unformat_error, i);
14186 return -99;
14187 }
14188 }
14189
14190 if (!vni_set)
14191 {
14192 errmsg ("vni not set!\n");
14193 return -99;
14194 }
14195
14196 if (!vam->json_output)
14197 {
14198 fformat (vam->ofp, "%s %40s\n", "leid", "reid");
14199 }
14200
14201 M (LISP_ADJACENCIES_GET, lisp_adjacencies_get);
14202 mp->vni = clib_host_to_net_u32 (vni);
14203
14204 /* send it... */
14205 S;
14206
14207 /* Wait for a reply... */
14208 W;
14209
14210 /* NOTREACHED */
14211 return 0;
14212}
14213
14214static int
Dave Barach72d72232016-08-04 10:15:08 -040014215api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014216{
Dave Barach72d72232016-08-04 10:15:08 -040014217 vl_api_lisp_map_resolver_dump_t *mp;
14218 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014219
Dave Barach72d72232016-08-04 10:15:08 -040014220 if (!vam->json_output)
14221 {
14222 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014223 }
14224
Dave Barach72d72232016-08-04 10:15:08 -040014225 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
14226 /* send it... */
14227 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014228
Dave Barach72d72232016-08-04 10:15:08 -040014229 /* Use a control ping for synchronization */
14230 {
14231 vl_api_control_ping_t *mp;
14232 M (CONTROL_PING, control_ping);
14233 S;
14234 }
14235 /* Wait for a reply... */
14236 W;
14237
14238 /* NOTREACHED */
14239 return 0;
14240}
14241
14242static int
14243api_show_lisp_status (vat_main_t * vam)
14244{
14245 vl_api_show_lisp_status_t *mp;
14246 f64 timeout = ~0;
14247
14248 if (!vam->json_output)
14249 {
14250 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
14251 }
14252
14253 M (SHOW_LISP_STATUS, show_lisp_status);
14254 /* send it... */
14255 S;
14256 /* Wait for a reply... */
14257 W;
14258
14259 /* NOTREACHED */
14260 return 0;
14261}
14262
14263static int
14264api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
14265{
14266 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
14267 f64 timeout = ~0;
14268
14269 if (!vam->json_output)
14270 {
14271 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
14272 }
14273
14274 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
14275 /* send it... */
14276 S;
14277 /* Wait for a reply... */
14278 W;
14279
14280 /* NOTREACHED */
14281 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014282}
14283
14284static int
Matus Fabian8a95a482016-05-06 15:14:13 +020014285api_af_packet_create (vat_main_t * vam)
14286{
Dave Barach72d72232016-08-04 10:15:08 -040014287 unformat_input_t *i = vam->input;
14288 vl_api_af_packet_create_t *mp;
14289 f64 timeout;
14290 u8 *host_if_name = 0;
14291 u8 hw_addr[6];
14292 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020014293
Dave Barach72d72232016-08-04 10:15:08 -040014294 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020014295
Dave Barach72d72232016-08-04 10:15:08 -040014296 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14297 {
14298 if (unformat (i, "name %s", &host_if_name))
14299 vec_add1 (host_if_name, 0);
14300 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14301 random_hw_addr = 0;
14302 else
14303 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014304 }
14305
Dave Barach72d72232016-08-04 10:15:08 -040014306 if (!vec_len (host_if_name))
14307 {
14308 errmsg ("host-interface name must be specified");
14309 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014310 }
14311
Dave Barach72d72232016-08-04 10:15:08 -040014312 if (vec_len (host_if_name) > 64)
14313 {
14314 errmsg ("host-interface name too long");
14315 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014316 }
14317
Dave Barach72d72232016-08-04 10:15:08 -040014318 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020014319
Dave Barach72d72232016-08-04 10:15:08 -040014320 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14321 clib_memcpy (mp->hw_addr, hw_addr, 6);
14322 mp->use_random_hw_addr = random_hw_addr;
14323 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014324
Dave Barach72d72232016-08-04 10:15:08 -040014325 S;
14326 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
14327 /* NOTREACHED */
14328 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014329}
14330
14331static int
14332api_af_packet_delete (vat_main_t * vam)
14333{
Dave Barach72d72232016-08-04 10:15:08 -040014334 unformat_input_t *i = vam->input;
14335 vl_api_af_packet_delete_t *mp;
14336 f64 timeout;
14337 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014338
Dave Barach72d72232016-08-04 10:15:08 -040014339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14340 {
14341 if (unformat (i, "name %s", &host_if_name))
14342 vec_add1 (host_if_name, 0);
14343 else
14344 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014345 }
14346
Dave Barach72d72232016-08-04 10:15:08 -040014347 if (!vec_len (host_if_name))
14348 {
14349 errmsg ("host-interface name must be specified");
14350 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014351 }
14352
Dave Barach72d72232016-08-04 10:15:08 -040014353 if (vec_len (host_if_name) > 64)
14354 {
14355 errmsg ("host-interface name too long");
14356 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014357 }
14358
Dave Barach72d72232016-08-04 10:15:08 -040014359 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020014360
Dave Barach72d72232016-08-04 10:15:08 -040014361 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14362 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014363
Dave Barach72d72232016-08-04 10:15:08 -040014364 S;
14365 W;
14366 /* NOTREACHED */
14367 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014368}
14369
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014370static int
14371api_policer_add_del (vat_main_t * vam)
14372{
Dave Barach72d72232016-08-04 10:15:08 -040014373 unformat_input_t *i = vam->input;
14374 vl_api_policer_add_del_t *mp;
14375 f64 timeout;
14376 u8 is_add = 1;
14377 u8 *name = 0;
14378 u32 cir = 0;
14379 u32 eir = 0;
14380 u64 cb = 0;
14381 u64 eb = 0;
14382 u8 rate_type = 0;
14383 u8 round_type = 0;
14384 u8 type = 0;
14385 u8 color_aware = 0;
14386 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014387
Dave Barach839fe3e2016-08-10 11:35:54 -040014388 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
14389 conform_action.dscp = 0;
14390 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
14391 exceed_action.dscp = 0;
14392 violate_action.action_type = SSE2_QOS_ACTION_DROP;
14393 violate_action.dscp = 0;
14394
Dave Barach72d72232016-08-04 10:15:08 -040014395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14396 {
14397 if (unformat (i, "del"))
14398 is_add = 0;
14399 else if (unformat (i, "name %s", &name))
14400 vec_add1 (name, 0);
14401 else if (unformat (i, "cir %u", &cir))
14402 ;
14403 else if (unformat (i, "eir %u", &eir))
14404 ;
14405 else if (unformat (i, "cb %u", &cb))
14406 ;
14407 else if (unformat (i, "eb %u", &eb))
14408 ;
14409 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
14410 &rate_type))
14411 ;
14412 else if (unformat (i, "round_type %U", unformat_policer_round_type,
14413 &round_type))
14414 ;
14415 else if (unformat (i, "type %U", unformat_policer_type, &type))
14416 ;
14417 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
14418 &conform_action))
14419 ;
14420 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
14421 &exceed_action))
14422 ;
14423 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
14424 &violate_action))
14425 ;
14426 else if (unformat (i, "color-aware"))
14427 color_aware = 1;
14428 else
14429 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014430 }
14431
Dave Barach72d72232016-08-04 10:15:08 -040014432 if (!vec_len (name))
14433 {
14434 errmsg ("policer name must be specified");
14435 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014436 }
14437
Dave Barach72d72232016-08-04 10:15:08 -040014438 if (vec_len (name) > 64)
14439 {
14440 errmsg ("policer name too long");
14441 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014442 }
14443
Dave Barach72d72232016-08-04 10:15:08 -040014444 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014445
Dave Barach72d72232016-08-04 10:15:08 -040014446 clib_memcpy (mp->name, name, vec_len (name));
14447 vec_free (name);
14448 mp->is_add = is_add;
14449 mp->cir = cir;
14450 mp->eir = eir;
14451 mp->cb = cb;
14452 mp->eb = eb;
14453 mp->rate_type = rate_type;
14454 mp->round_type = round_type;
14455 mp->type = type;
14456 mp->conform_action_type = conform_action.action_type;
14457 mp->conform_dscp = conform_action.dscp;
14458 mp->exceed_action_type = exceed_action.action_type;
14459 mp->exceed_dscp = exceed_action.dscp;
14460 mp->violate_action_type = violate_action.action_type;
14461 mp->violate_dscp = violate_action.dscp;
14462 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014463
Dave Barach72d72232016-08-04 10:15:08 -040014464 S;
14465 W;
14466 /* NOTREACHED */
14467 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014468}
14469
Matus Fabian82e29c42016-05-11 04:49:46 -070014470static int
Dave Barach72d72232016-08-04 10:15:08 -040014471api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070014472{
Dave Barach72d72232016-08-04 10:15:08 -040014473 unformat_input_t *i = vam->input;
14474 vl_api_policer_dump_t *mp;
14475 f64 timeout = ~0;
14476 u8 *match_name = 0;
14477 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014478
Dave Barach72d72232016-08-04 10:15:08 -040014479 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070014480 {
Dave Barach72d72232016-08-04 10:15:08 -040014481 if (unformat (i, "name %s", &match_name))
14482 {
14483 vec_add1 (match_name, 0);
14484 match_name_valid = 1;
14485 }
14486 else
14487 break;
Matus Fabiane8554802016-05-18 23:40:37 -070014488 }
Matus Fabiane8554802016-05-18 23:40:37 -070014489
Dave Barach72d72232016-08-04 10:15:08 -040014490 M (POLICER_DUMP, policer_dump);
14491 mp->match_name_valid = match_name_valid;
14492 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
14493 vec_free (match_name);
14494 /* send it... */
14495 S;
14496
14497 /* Use a control ping for synchronization */
14498 {
14499 vl_api_control_ping_t *mp;
14500 M (CONTROL_PING, control_ping);
14501 S;
14502 }
14503 /* Wait for a reply... */
14504 W;
14505
14506 /* NOTREACHED */
14507 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014508}
14509
14510static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014511api_policer_classify_set_interface (vat_main_t * vam)
14512{
Dave Barach72d72232016-08-04 10:15:08 -040014513 unformat_input_t *i = vam->input;
14514 vl_api_policer_classify_set_interface_t *mp;
14515 f64 timeout;
14516 u32 sw_if_index;
14517 int sw_if_index_set;
14518 u32 ip4_table_index = ~0;
14519 u32 ip6_table_index = ~0;
14520 u32 l2_table_index = ~0;
14521 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014522
Dave Barach72d72232016-08-04 10:15:08 -040014523 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14524 {
14525 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
14526 sw_if_index_set = 1;
14527 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14528 sw_if_index_set = 1;
14529 else if (unformat (i, "del"))
14530 is_add = 0;
14531 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14532 ;
14533 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14534 ;
14535 else if (unformat (i, "l2-table %d", &l2_table_index))
14536 ;
14537 else
14538 {
14539 clib_warning ("parse error '%U'", format_unformat_error, i);
14540 return -99;
14541 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014542 }
14543
Dave Barach72d72232016-08-04 10:15:08 -040014544 if (sw_if_index_set == 0)
14545 {
14546 errmsg ("missing interface name or sw_if_index\n");
14547 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014548 }
14549
Dave Barach72d72232016-08-04 10:15:08 -040014550 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014551
Dave Barach72d72232016-08-04 10:15:08 -040014552 mp->sw_if_index = ntohl (sw_if_index);
14553 mp->ip4_table_index = ntohl (ip4_table_index);
14554 mp->ip6_table_index = ntohl (ip6_table_index);
14555 mp->l2_table_index = ntohl (l2_table_index);
14556 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014557
Dave Barach72d72232016-08-04 10:15:08 -040014558 S;
14559 W;
14560 /* NOTREACHED */
14561 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014562}
14563
14564static int
Dave Barach72d72232016-08-04 10:15:08 -040014565api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014566{
Dave Barach72d72232016-08-04 10:15:08 -040014567 unformat_input_t *i = vam->input;
14568 vl_api_policer_classify_dump_t *mp;
14569 f64 timeout = ~0;
14570 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014571
Juraj Sloboda506b2452016-08-07 23:45:24 -070014572 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
Dave Barach72d72232016-08-04 10:15:08 -040014573 ;
14574 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014575 {
Dave Barach72d72232016-08-04 10:15:08 -040014576 errmsg ("classify table type must be specified\n");
14577 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014578 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014579
Dave Barach72d72232016-08-04 10:15:08 -040014580 if (!vam->json_output)
14581 {
14582 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
14583 }
14584
14585 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
14586 mp->type = type;
14587 /* send it... */
14588 S;
14589
14590 /* Use a control ping for synchronization */
14591 {
14592 vl_api_control_ping_t *mp;
14593 M (CONTROL_PING, control_ping);
14594 S;
14595 }
14596 /* Wait for a reply... */
14597 W;
14598
14599 /* NOTREACHED */
14600 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014601}
14602
14603static int
Matus Fabian82e29c42016-05-11 04:49:46 -070014604api_netmap_create (vat_main_t * vam)
14605{
Dave Barach72d72232016-08-04 10:15:08 -040014606 unformat_input_t *i = vam->input;
14607 vl_api_netmap_create_t *mp;
14608 f64 timeout;
14609 u8 *if_name = 0;
14610 u8 hw_addr[6];
14611 u8 random_hw_addr = 1;
14612 u8 is_pipe = 0;
14613 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014614
Dave Barach72d72232016-08-04 10:15:08 -040014615 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070014616
Dave Barach72d72232016-08-04 10:15:08 -040014617 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14618 {
14619 if (unformat (i, "name %s", &if_name))
14620 vec_add1 (if_name, 0);
14621 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14622 random_hw_addr = 0;
14623 else if (unformat (i, "pipe"))
14624 is_pipe = 1;
14625 else if (unformat (i, "master"))
14626 is_master = 1;
14627 else if (unformat (i, "slave"))
14628 is_master = 0;
14629 else
14630 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014631 }
14632
Dave Barach72d72232016-08-04 10:15:08 -040014633 if (!vec_len (if_name))
14634 {
14635 errmsg ("interface name must be specified");
14636 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014637 }
14638
Dave Barach72d72232016-08-04 10:15:08 -040014639 if (vec_len (if_name) > 64)
14640 {
14641 errmsg ("interface name too long");
14642 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014643 }
14644
Dave Barach72d72232016-08-04 10:15:08 -040014645 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070014646
Dave Barach72d72232016-08-04 10:15:08 -040014647 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14648 clib_memcpy (mp->hw_addr, hw_addr, 6);
14649 mp->use_random_hw_addr = random_hw_addr;
14650 mp->is_pipe = is_pipe;
14651 mp->is_master = is_master;
14652 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014653
Dave Barach72d72232016-08-04 10:15:08 -040014654 S;
14655 W;
14656 /* NOTREACHED */
14657 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014658}
14659
14660static int
14661api_netmap_delete (vat_main_t * vam)
14662{
Dave Barach72d72232016-08-04 10:15:08 -040014663 unformat_input_t *i = vam->input;
14664 vl_api_netmap_delete_t *mp;
14665 f64 timeout;
14666 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014667
Dave Barach72d72232016-08-04 10:15:08 -040014668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14669 {
14670 if (unformat (i, "name %s", &if_name))
14671 vec_add1 (if_name, 0);
14672 else
14673 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014674 }
14675
Dave Barach72d72232016-08-04 10:15:08 -040014676 if (!vec_len (if_name))
14677 {
14678 errmsg ("interface name must be specified");
14679 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014680 }
14681
Dave Barach72d72232016-08-04 10:15:08 -040014682 if (vec_len (if_name) > 64)
14683 {
14684 errmsg ("interface name too long");
14685 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014686 }
14687
Dave Barach72d72232016-08-04 10:15:08 -040014688 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070014689
Dave Barach72d72232016-08-04 10:15:08 -040014690 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14691 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014692
Dave Barach72d72232016-08-04 10:15:08 -040014693 S;
14694 W;
14695 /* NOTREACHED */
14696 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014697}
14698
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014699static void vl_api_mpls_eth_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014700 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014701{
Dave Barach72d72232016-08-04 10:15:08 -040014702 vat_main_t *vam = &vat_main;
14703 i32 i;
14704 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014705
Dave Barach72d72232016-08-04 10:15:08 -040014706 fformat (vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
14707 ntohl (mp->tunnel_index),
14708 format_ethernet_address, &mp->tunnel_dst_mac,
14709 format_ip4_address, &mp->intfc_address, ntohl (mp->mask_width));
14710 for (i = 0; i < len; i++)
14711 {
14712 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014713 }
Dave Barach72d72232016-08-04 10:15:08 -040014714 fformat (vam->ofp, "\n");
14715 fformat (vam->ofp, " tx on %d, rx fib index %d\n",
14716 ntohl (mp->tx_sw_if_index), ntohl (mp->inner_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014717}
14718
14719static void vl_api_mpls_eth_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014720 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014721{
Dave Barach72d72232016-08-04 10:15:08 -040014722 vat_main_t *vam = &vat_main;
14723 vat_json_node_t *node = NULL;
14724 struct in_addr ip4;
14725 i32 i;
14726 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014727
Dave Barach72d72232016-08-04 10:15:08 -040014728 if (VAT_JSON_ARRAY != vam->json_tree.type)
14729 {
14730 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14731 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014732 }
Dave Barach72d72232016-08-04 10:15:08 -040014733 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014734
Dave Barach72d72232016-08-04 10:15:08 -040014735 vat_json_init_object (node);
14736 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14737 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14738 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14739 vat_json_object_add_uint (node, "inner_fib_index",
14740 ntohl (mp->inner_fib_index));
14741 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14742 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14743 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14744 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14745 vat_json_object_add_string_copy (node, "tunnel_dst_mac",
14746 format (0, "%U", format_ethernet_address,
14747 &mp->tunnel_dst_mac));
14748 vat_json_object_add_uint (node, "tx_sw_if_index",
14749 ntohl (mp->tx_sw_if_index));
14750 vat_json_object_add_uint (node, "label_count", len);
14751 for (i = 0; i < len; i++)
14752 {
14753 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014754 }
14755}
14756
Dave Barach72d72232016-08-04 10:15:08 -040014757static int
14758api_mpls_eth_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014759{
Dave Barach72d72232016-08-04 10:15:08 -040014760 vl_api_mpls_eth_tunnel_dump_t *mp;
14761 f64 timeout;
14762 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014763
Dave Barach72d72232016-08-04 10:15:08 -040014764 /* Parse args required to build the message */
14765 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014766 {
Dave Barach72d72232016-08-04 10:15:08 -040014767 if (!unformat (vam->input, "tunnel_index %d", &index))
14768 {
14769 index = -1;
14770 break;
14771 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014772 }
Dave Barach72d72232016-08-04 10:15:08 -040014773
14774 fformat (vam->ofp, " tunnel_index %d\n", index);
14775
14776 M (MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
14777 mp->tunnel_index = htonl (index);
14778 S;
14779
14780 /* Use a control ping for synchronization */
14781 {
14782 vl_api_control_ping_t *mp;
14783 M (CONTROL_PING, control_ping);
14784 S;
14785 }
14786 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014787}
14788
14789static void vl_api_mpls_fib_encap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014790 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014791{
Dave Barach72d72232016-08-04 10:15:08 -040014792 vat_main_t *vam = &vat_main;
14793 i32 i;
14794 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014795
Dave Barach72d72232016-08-04 10:15:08 -040014796 fformat (vam->ofp, "table %d, dest %U, label ",
14797 ntohl (mp->fib_index), format_ip4_address, &mp->dest, len);
14798 for (i = 0; i < len; i++)
14799 {
14800 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014801 }
Dave Barach72d72232016-08-04 10:15:08 -040014802 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014803}
14804
14805static void vl_api_mpls_fib_encap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014806 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014807{
Dave Barach72d72232016-08-04 10:15:08 -040014808 vat_main_t *vam = &vat_main;
14809 vat_json_node_t *node = NULL;
14810 i32 i;
14811 i32 len = ntohl (mp->nlabels);
14812 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014813
Dave Barach72d72232016-08-04 10:15:08 -040014814 if (VAT_JSON_ARRAY != vam->json_tree.type)
14815 {
14816 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14817 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014818 }
Dave Barach72d72232016-08-04 10:15:08 -040014819 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014820
Dave Barach72d72232016-08-04 10:15:08 -040014821 vat_json_init_object (node);
14822 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14823 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14824 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14825 vat_json_object_add_ip4 (node, "dest", ip4);
14826 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14827 vat_json_object_add_uint (node, "label_count", len);
14828 for (i = 0; i < len; i++)
14829 {
14830 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014831 }
14832}
14833
Dave Barach72d72232016-08-04 10:15:08 -040014834static int
14835api_mpls_fib_encap_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014836{
Dave Barach72d72232016-08-04 10:15:08 -040014837 vl_api_mpls_fib_encap_dump_t *mp;
14838 f64 timeout;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014839
Dave Barach72d72232016-08-04 10:15:08 -040014840 M (MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
14841 S;
14842
14843 /* Use a control ping for synchronization */
14844 {
14845 vl_api_control_ping_t *mp;
14846 M (CONTROL_PING, control_ping);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014847 S;
Dave Barach72d72232016-08-04 10:15:08 -040014848 }
14849 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014850}
14851
Neale Ranns1357f3b2016-10-16 12:01:42 -070014852static void
14853vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014854{
Dave Barach72d72232016-08-04 10:15:08 -040014855 vat_main_t *vam = &vat_main;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014856
Dave Barach72d72232016-08-04 10:15:08 -040014857 fformat (vam->ofp,
Neale Ranns1357f3b2016-10-16 12:01:42 -070014858 "table-id %d, label %u, ess_bit %u\n",
14859 ntohl (mp->table_id), ntohl (mp->label), mp->eos_bit);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014860}
14861
Neale Ranns1357f3b2016-10-16 12:01:42 -070014862static void vl_api_mpls_fib_details_t_handler_json
14863 (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014864{
Dave Barach72d72232016-08-04 10:15:08 -040014865 vat_main_t *vam = &vat_main;
14866 vat_json_node_t *node = NULL;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014867
Dave Barach72d72232016-08-04 10:15:08 -040014868 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014869 {
Dave Barach72d72232016-08-04 10:15:08 -040014870 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14871 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014872 }
Dave Barach72d72232016-08-04 10:15:08 -040014873 node = vat_json_array_add (&vam->json_tree);
14874
14875 vat_json_init_object (node);
Neale Ranns1357f3b2016-10-16 12:01:42 -070014876 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
14877 vat_json_object_add_uint (node, "s_bit", mp->eos_bit);
Dave Barach72d72232016-08-04 10:15:08 -040014878 vat_json_object_add_uint (node, "label", ntohl (mp->label));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014879}
14880
Dave Barach72d72232016-08-04 10:15:08 -040014881static int
Neale Ranns1357f3b2016-10-16 12:01:42 -070014882api_mpls_fib_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014883{
Neale Ranns1357f3b2016-10-16 12:01:42 -070014884 vl_api_mpls_fib_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014885 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014886
Neale Ranns1357f3b2016-10-16 12:01:42 -070014887 M (MPLS_FIB_DUMP, mpls_fib_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014888 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014889
Dave Barach72d72232016-08-04 10:15:08 -040014890 /* Use a control ping for synchronization */
14891 {
14892 vl_api_control_ping_t *mp;
14893 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014894 S;
Dave Barach72d72232016-08-04 10:15:08 -040014895 }
14896 W;
14897}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014898
Dave Barach72d72232016-08-04 10:15:08 -040014899int
14900api_classify_table_ids (vat_main_t * vam)
14901{
14902 vl_api_classify_table_ids_t *mp;
14903 f64 timeout;
14904
14905 /* Construct the API message */
14906 M (CLASSIFY_TABLE_IDS, classify_table_ids);
14907 mp->context = 0;
14908
14909 S;
14910 W;
14911 /* NOTREACHED */
14912 return 0;
14913}
14914
14915int
14916api_classify_table_by_interface (vat_main_t * vam)
14917{
14918 unformat_input_t *input = vam->input;
14919 vl_api_classify_table_by_interface_t *mp;
14920 f64 timeout;
14921
14922 u32 sw_if_index = ~0;
14923 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014924 {
Dave Barach72d72232016-08-04 10:15:08 -040014925 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
14926 ;
14927 else if (unformat (input, "sw_if_index %d", &sw_if_index))
14928 ;
14929 else
14930 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014931 }
Dave Barach72d72232016-08-04 10:15:08 -040014932 if (sw_if_index == ~0)
14933 {
14934 errmsg ("missing interface name or sw_if_index\n");
14935 return -99;
14936 }
14937
14938 /* Construct the API message */
14939 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
14940 mp->context = 0;
14941 mp->sw_if_index = ntohl (sw_if_index);
14942
14943 S;
14944 W;
14945 /* NOTREACHED */
14946 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014947}
14948
Dave Barach72d72232016-08-04 10:15:08 -040014949int
14950api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014951{
Dave Barach72d72232016-08-04 10:15:08 -040014952 unformat_input_t *input = vam->input;
14953 vl_api_classify_table_info_t *mp;
14954 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014955
Dave Barach72d72232016-08-04 10:15:08 -040014956 u32 table_id = ~0;
14957 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14958 {
14959 if (unformat (input, "table_id %d", &table_id))
14960 ;
14961 else
14962 break;
14963 }
14964 if (table_id == ~0)
14965 {
14966 errmsg ("missing table id\n");
14967 return -99;
14968 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014969
Dave Barach72d72232016-08-04 10:15:08 -040014970 /* Construct the API message */
14971 M (CLASSIFY_TABLE_INFO, classify_table_info);
14972 mp->context = 0;
14973 mp->table_id = ntohl (table_id);
14974
14975 S;
14976 W;
14977 /* NOTREACHED */
14978 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014979}
14980
Dave Barach72d72232016-08-04 10:15:08 -040014981int
14982api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014983{
Dave Barach72d72232016-08-04 10:15:08 -040014984 unformat_input_t *input = vam->input;
14985 vl_api_classify_session_dump_t *mp;
14986 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014987
Dave Barach72d72232016-08-04 10:15:08 -040014988 u32 table_id = ~0;
14989 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14990 {
14991 if (unformat (input, "table_id %d", &table_id))
14992 ;
14993 else
14994 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014995 }
Dave Barach72d72232016-08-04 10:15:08 -040014996 if (table_id == ~0)
14997 {
14998 errmsg ("missing table id\n");
14999 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015000 }
15001
Dave Barach72d72232016-08-04 10:15:08 -040015002 /* Construct the API message */
15003 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
15004 mp->context = 0;
15005 mp->table_id = ntohl (table_id);
15006 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015007
Dave Barach72d72232016-08-04 10:15:08 -040015008 /* Use a control ping for synchronization */
15009 {
15010 vl_api_control_ping_t *mp;
15011 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040015012 S;
Dave Barach72d72232016-08-04 10:15:08 -040015013 }
15014 W;
15015 /* NOTREACHED */
15016 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040015017}
15018
Dave Barach72d72232016-08-04 10:15:08 -040015019static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015020vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015021{
Dave Barach72d72232016-08-04 10:15:08 -040015022 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015023
Dave Barach72d72232016-08-04 10:15:08 -040015024 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015025 "src_address %U, vrf_id %d, path_mtu %u, "
15026 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040015027 format_ip4_address, mp->collector_address,
15028 ntohs (mp->collector_port),
15029 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015030 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
15031 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015032
15033 vam->retval = 0;
15034 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015035}
15036
Dave Barach72d72232016-08-04 10:15:08 -040015037static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015038 vl_api_ipfix_exporter_details_t_handler_json
15039 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015040{
Dave Barach72d72232016-08-04 10:15:08 -040015041 vat_main_t *vam = &vat_main;
15042 vat_json_node_t node;
15043 struct in_addr collector_address;
15044 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015045
Dave Barach72d72232016-08-04 10:15:08 -040015046 vat_json_init_object (&node);
15047 clib_memcpy (&collector_address, &mp->collector_address,
15048 sizeof (collector_address));
15049 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
15050 vat_json_object_add_uint (&node, "collector_port",
15051 ntohs (mp->collector_port));
15052 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
15053 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015054 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040015055 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
15056 vat_json_object_add_uint (&node, "template_interval",
15057 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015058 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015059
15060 vat_json_print (vam->ofp, &node);
15061 vat_json_free (&node);
15062 vam->retval = 0;
15063 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015064}
15065
Dave Barach72d72232016-08-04 10:15:08 -040015066int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015067api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015068{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015069 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015070 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015071
Dave Barach72d72232016-08-04 10:15:08 -040015072 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015073 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015074 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015075
Dave Barach72d72232016-08-04 10:15:08 -040015076 S;
15077 W;
15078 /* NOTREACHED */
15079 return 0;
15080}
Ed Warnickecb9cada2015-12-08 15:45:58 -070015081
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015082static int
15083api_ipfix_classify_stream_dump (vat_main_t * vam)
15084{
15085 vl_api_ipfix_classify_stream_dump_t *mp;
15086 f64 timeout;
15087
15088 /* Construct the API message */
15089 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
15090 mp->context = 0;
15091
15092 S;
15093 W;
15094 /* NOTREACHED */
15095 return 0;
15096}
15097
15098static void
15099 vl_api_ipfix_classify_stream_details_t_handler
15100 (vl_api_ipfix_classify_stream_details_t * mp)
15101{
15102 vat_main_t *vam = &vat_main;
15103 fformat (vam->ofp, "domain_id %d, src_port %d\n",
15104 ntohl (mp->domain_id), ntohs (mp->src_port));
15105 vam->retval = 0;
15106 vam->result_ready = 1;
15107}
15108
15109static void
15110 vl_api_ipfix_classify_stream_details_t_handler_json
15111 (vl_api_ipfix_classify_stream_details_t * mp)
15112{
15113 vat_main_t *vam = &vat_main;
15114 vat_json_node_t node;
15115
15116 vat_json_init_object (&node);
15117 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
15118 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
15119
15120 vat_json_print (vam->ofp, &node);
15121 vat_json_free (&node);
15122 vam->retval = 0;
15123 vam->result_ready = 1;
15124}
15125
15126static int
15127api_ipfix_classify_table_dump (vat_main_t * vam)
15128{
15129 vl_api_ipfix_classify_table_dump_t *mp;
15130 f64 timeout;
15131
15132 if (!vam->json_output)
15133 {
15134 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
15135 "transport_protocol");
15136 }
15137
15138 /* Construct the API message */
15139 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
15140
15141 /* send it... */
15142 S;
15143
15144 /* Use a control ping for synchronization */
15145 {
15146 vl_api_control_ping_t *mp;
15147 M (CONTROL_PING, control_ping);
15148 S;
15149 }
15150 W;
15151}
15152
15153static void
15154 vl_api_ipfix_classify_table_details_t_handler
15155 (vl_api_ipfix_classify_table_details_t * mp)
15156{
15157 vat_main_t *vam = &vat_main;
15158 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
15159 mp->transport_protocol);
15160}
15161
15162static void
15163 vl_api_ipfix_classify_table_details_t_handler_json
15164 (vl_api_ipfix_classify_table_details_t * mp)
15165{
15166 vat_json_node_t *node = NULL;
15167 vat_main_t *vam = &vat_main;
15168
15169 if (VAT_JSON_ARRAY != vam->json_tree.type)
15170 {
15171 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15172 vat_json_init_array (&vam->json_tree);
15173 }
15174
15175 node = vat_json_array_add (&vam->json_tree);
15176 vat_json_init_object (node);
15177
15178 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
15179 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
15180 vat_json_object_add_uint (node, "transport_protocol",
15181 mp->transport_protocol);
15182}
15183
Dave Barach72d72232016-08-04 10:15:08 -040015184int
15185api_pg_create_interface (vat_main_t * vam)
15186{
15187 unformat_input_t *input = vam->input;
15188 vl_api_pg_create_interface_t *mp;
15189 f64 timeout;
15190
15191 u32 if_id = ~0;
15192 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15193 {
15194 if (unformat (input, "if_id %d", &if_id))
15195 ;
15196 else
15197 break;
15198 }
15199 if (if_id == ~0)
15200 {
15201 errmsg ("missing pg interface index\n");
15202 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015203 }
15204
Dave Barach72d72232016-08-04 10:15:08 -040015205 /* Construct the API message */
15206 M (PG_CREATE_INTERFACE, pg_create_interface);
15207 mp->context = 0;
15208 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015209
Dave Barach72d72232016-08-04 10:15:08 -040015210 S;
15211 W;
15212 /* NOTREACHED */
15213 return 0;
15214}
15215
15216int
15217api_pg_capture (vat_main_t * vam)
15218{
15219 unformat_input_t *input = vam->input;
15220 vl_api_pg_capture_t *mp;
15221 f64 timeout;
15222
15223 u32 if_id = ~0;
15224 u8 enable = 1;
15225 u32 count = 1;
15226 u8 pcap_file_set = 0;
15227 u8 *pcap_file = 0;
15228 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15229 {
15230 if (unformat (input, "if_id %d", &if_id))
15231 ;
15232 else if (unformat (input, "pcap %s", &pcap_file))
15233 pcap_file_set = 1;
15234 else if (unformat (input, "count %d", &count))
15235 ;
15236 else if (unformat (input, "disable"))
15237 enable = 0;
15238 else
15239 break;
15240 }
15241 if (if_id == ~0)
15242 {
15243 errmsg ("missing pg interface index\n");
15244 return -99;
15245 }
15246 if (pcap_file_set > 0)
15247 {
15248 if (vec_len (pcap_file) > 255)
15249 {
15250 errmsg ("pcap file name is too long\n");
15251 return -99;
15252 }
15253 }
15254
15255 u32 name_len = vec_len (pcap_file);
15256 /* Construct the API message */
15257 M (PG_CAPTURE, pg_capture);
15258 mp->context = 0;
15259 mp->interface_id = ntohl (if_id);
15260 mp->is_enabled = enable;
15261 mp->count = ntohl (count);
15262 mp->pcap_name_length = ntohl (name_len);
15263 if (pcap_file_set != 0)
15264 {
15265 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
15266 }
15267 vec_free (pcap_file);
15268
15269 S;
15270 W;
15271 /* NOTREACHED */
15272 return 0;
15273}
15274
15275int
15276api_pg_enable_disable (vat_main_t * vam)
15277{
15278 unformat_input_t *input = vam->input;
15279 vl_api_pg_enable_disable_t *mp;
15280 f64 timeout;
15281
15282 u8 enable = 1;
15283 u8 stream_name_set = 0;
15284 u8 *stream_name = 0;
15285 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15286 {
15287 if (unformat (input, "stream %s", &stream_name))
15288 stream_name_set = 1;
15289 else if (unformat (input, "disable"))
15290 enable = 0;
15291 else
15292 break;
15293 }
15294
15295 if (stream_name_set > 0)
15296 {
15297 if (vec_len (stream_name) > 255)
15298 {
15299 errmsg ("stream name too long\n");
15300 return -99;
15301 }
15302 }
15303
15304 u32 name_len = vec_len (stream_name);
15305 /* Construct the API message */
15306 M (PG_ENABLE_DISABLE, pg_enable_disable);
15307 mp->context = 0;
15308 mp->is_enabled = enable;
15309 if (stream_name_set != 0)
15310 {
15311 mp->stream_name_length = ntohl (name_len);
15312 clib_memcpy (mp->stream_name, stream_name, name_len);
15313 }
15314 vec_free (stream_name);
15315
15316 S;
15317 W;
15318 /* NOTREACHED */
15319 return 0;
15320}
15321
15322int
15323api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
15324{
15325 unformat_input_t *input = vam->input;
15326 vl_api_ip_source_and_port_range_check_add_del_t *mp;
15327 f64 timeout;
15328
15329 u16 *low_ports = 0;
15330 u16 *high_ports = 0;
15331 u16 this_low;
15332 u16 this_hi;
15333 ip4_address_t ip4_addr;
15334 ip6_address_t ip6_addr;
15335 u32 length;
15336 u32 tmp, tmp2;
15337 u8 prefix_set = 0;
15338 u32 vrf_id = ~0;
15339 u8 is_add = 1;
15340 u8 is_ipv6 = 0;
15341
15342 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15343 {
15344 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
15345 {
15346 prefix_set = 1;
15347 }
15348 else
15349 if (unformat
15350 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
15351 {
15352 prefix_set = 1;
15353 is_ipv6 = 1;
15354 }
15355 else if (unformat (input, "vrf %d", &vrf_id))
15356 ;
15357 else if (unformat (input, "del"))
15358 is_add = 0;
15359 else if (unformat (input, "port %d", &tmp))
15360 {
15361 if (tmp == 0 || tmp > 65535)
15362 {
15363 errmsg ("port %d out of range", tmp);
15364 return -99;
15365 }
15366 this_low = tmp;
15367 this_hi = this_low + 1;
15368 vec_add1 (low_ports, this_low);
15369 vec_add1 (high_ports, this_hi);
15370 }
15371 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
15372 {
15373 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
15374 {
15375 errmsg ("incorrect range parameters\n");
15376 return -99;
15377 }
15378 this_low = tmp;
15379 /* Note: in debug CLI +1 is added to high before
15380 passing to real fn that does "the work"
15381 (ip_source_and_port_range_check_add_del).
15382 This fn is a wrapper around the binary API fn a
15383 control plane will call, which expects this increment
15384 to have occurred. Hence letting the binary API control
15385 plane fn do the increment for consistency between VAT
15386 and other control planes.
15387 */
15388 this_hi = tmp2;
15389 vec_add1 (low_ports, this_low);
15390 vec_add1 (high_ports, this_hi);
15391 }
15392 else
15393 break;
15394 }
15395
15396 if (prefix_set == 0)
15397 {
15398 errmsg ("<address>/<mask> not specified\n");
15399 return -99;
15400 }
15401
15402 if (vrf_id == ~0)
15403 {
15404 errmsg ("VRF ID required, not specified\n");
15405 return -99;
15406 }
15407
15408 if (vrf_id == 0)
15409 {
15410 errmsg
15411 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15412 return -99;
15413 }
15414
15415 if (vec_len (low_ports) == 0)
15416 {
15417 errmsg ("At least one port or port range required\n");
15418 return -99;
15419 }
15420
15421 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
15422 ip_source_and_port_range_check_add_del);
15423
15424 mp->is_add = is_add;
15425
15426 if (is_ipv6)
15427 {
15428 mp->is_ipv6 = 1;
15429 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
15430 }
15431 else
15432 {
15433 mp->is_ipv6 = 0;
15434 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
15435 }
15436
15437 mp->mask_length = length;
15438 mp->number_of_ranges = vec_len (low_ports);
15439
15440 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
15441 vec_free (low_ports);
15442
15443 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
15444 vec_free (high_ports);
15445
15446 mp->vrf_id = ntohl (vrf_id);
15447
15448 S;
15449 W;
15450 /* NOTREACHED */
15451 return 0;
15452}
15453
15454int
15455api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
15456{
15457 unformat_input_t *input = vam->input;
15458 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
15459 f64 timeout;
15460 u32 sw_if_index = ~0;
15461 int vrf_set = 0;
15462 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
15463 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
15464 u8 is_add = 1;
15465
15466 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15467 {
15468 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15469 ;
15470 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15471 ;
15472 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
15473 vrf_set = 1;
15474 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
15475 vrf_set = 1;
15476 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
15477 vrf_set = 1;
15478 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
15479 vrf_set = 1;
15480 else if (unformat (input, "del"))
15481 is_add = 0;
15482 else
15483 break;
15484 }
15485
15486 if (sw_if_index == ~0)
15487 {
15488 errmsg ("Interface required but not specified\n");
15489 return -99;
15490 }
15491
15492 if (vrf_set == 0)
15493 {
15494 errmsg ("VRF ID required but not specified\n");
15495 return -99;
15496 }
15497
15498 if (tcp_out_vrf_id == 0
15499 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
15500 {
15501 errmsg
15502 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15503 return -99;
15504 }
15505
15506 /* Construct the API message */
15507 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
15508 ip_source_and_port_range_check_interface_add_del);
15509
15510 mp->sw_if_index = ntohl (sw_if_index);
15511 mp->is_add = is_add;
15512 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
15513 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
15514 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
15515 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
15516
15517 /* send it... */
15518 S;
15519
15520 /* Wait for a reply... */
15521 W;
15522}
15523
15524static int
Matus Fabian694265d2016-08-10 01:55:36 -070015525api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
15526{
15527 unformat_input_t *i = vam->input;
15528 vl_api_ipsec_gre_add_del_tunnel_t *mp;
15529 f64 timeout;
15530 u32 local_sa_id = 0;
15531 u32 remote_sa_id = 0;
15532 ip4_address_t src_address;
15533 ip4_address_t dst_address;
15534 u8 is_add = 1;
15535
15536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15537 {
15538 if (unformat (i, "local_sa %d", &local_sa_id))
15539 ;
15540 else if (unformat (i, "remote_sa %d", &remote_sa_id))
15541 ;
15542 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
15543 ;
15544 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
15545 ;
15546 else if (unformat (i, "del"))
15547 is_add = 0;
15548 else
15549 {
15550 clib_warning ("parse error '%U'", format_unformat_error, i);
15551 return -99;
15552 }
15553 }
15554
15555 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
15556
15557 mp->local_sa_id = ntohl (local_sa_id);
15558 mp->remote_sa_id = ntohl (remote_sa_id);
15559 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
15560 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
15561 mp->is_add = is_add;
15562
15563 S;
15564 W;
15565 /* NOTREACHED */
15566 return 0;
15567}
15568
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070015569static int
15570api_punt (vat_main_t * vam)
15571{
15572 unformat_input_t *i = vam->input;
15573 vl_api_punt_t *mp;
15574 f64 timeout;
15575 u32 ipv = ~0;
15576 u32 protocol = ~0;
15577 u32 port = ~0;
15578 int is_add = 1;
15579
15580 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15581 {
15582 if (unformat (i, "ip %d", &ipv))
15583 ;
15584 else if (unformat (i, "protocol %d", &protocol))
15585 ;
15586 else if (unformat (i, "port %d", &port))
15587 ;
15588 else if (unformat (i, "del"))
15589 is_add = 0;
15590 else
15591 {
15592 clib_warning ("parse error '%U'", format_unformat_error, i);
15593 return -99;
15594 }
15595 }
15596
15597 M (PUNT, punt);
15598
15599 mp->is_add = (u8) is_add;
15600 mp->ipv = (u8) ipv;
15601 mp->l4_protocol = (u8) protocol;
15602 mp->l4_port = htons ((u16) port);
15603
15604 S;
15605 W;
15606 /* NOTREACHED */
15607 return 0;
15608}
15609
Matus Fabian694265d2016-08-10 01:55:36 -070015610static void vl_api_ipsec_gre_tunnel_details_t_handler
15611 (vl_api_ipsec_gre_tunnel_details_t * mp)
15612{
15613 vat_main_t *vam = &vat_main;
15614
15615 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
15616 ntohl (mp->sw_if_index),
15617 format_ip4_address, &mp->src_address,
15618 format_ip4_address, &mp->dst_address,
15619 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
15620}
15621
15622static void vl_api_ipsec_gre_tunnel_details_t_handler_json
15623 (vl_api_ipsec_gre_tunnel_details_t * mp)
15624{
15625 vat_main_t *vam = &vat_main;
15626 vat_json_node_t *node = NULL;
15627 struct in_addr ip4;
15628
15629 if (VAT_JSON_ARRAY != vam->json_tree.type)
15630 {
15631 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15632 vat_json_init_array (&vam->json_tree);
15633 }
15634 node = vat_json_array_add (&vam->json_tree);
15635
15636 vat_json_init_object (node);
15637 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
15638 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
15639 vat_json_object_add_ip4 (node, "src_address", ip4);
15640 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
15641 vat_json_object_add_ip4 (node, "dst_address", ip4);
15642 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
15643 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
15644}
15645
15646static int
15647api_ipsec_gre_tunnel_dump (vat_main_t * vam)
15648{
15649 unformat_input_t *i = vam->input;
15650 vl_api_ipsec_gre_tunnel_dump_t *mp;
15651 f64 timeout;
15652 u32 sw_if_index;
15653 u8 sw_if_index_set = 0;
15654
15655 /* Parse args required to build the message */
15656 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15657 {
15658 if (unformat (i, "sw_if_index %d", &sw_if_index))
15659 sw_if_index_set = 1;
15660 else
15661 break;
15662 }
15663
15664 if (sw_if_index_set == 0)
15665 {
15666 sw_if_index = ~0;
15667 }
15668
15669 if (!vam->json_output)
15670 {
15671 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
15672 "sw_if_index", "src_address", "dst_address",
15673 "local_sa_id", "remote_sa_id");
15674 }
15675
15676 /* Get list of gre-tunnel interfaces */
15677 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
15678
15679 mp->sw_if_index = htonl (sw_if_index);
15680
15681 S;
15682
15683 /* Use a control ping for synchronization */
15684 {
15685 vl_api_control_ping_t *mp;
15686 M (CONTROL_PING, control_ping);
15687 S;
15688 }
15689 W;
15690}
15691
15692static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015693api_delete_subif (vat_main_t * vam)
15694{
15695 unformat_input_t *i = vam->input;
15696 vl_api_delete_subif_t *mp;
15697 f64 timeout;
15698 u32 sw_if_index = ~0;
15699
15700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15701 {
15702 if (unformat (i, "sw_if_index %d", &sw_if_index))
15703 ;
15704 else
15705 break;
15706 }
15707
15708 if (sw_if_index == ~0)
15709 {
15710 errmsg ("missing sw_if_index\n");
15711 return -99;
15712 }
15713
15714 /* Construct the API message */
15715 M (DELETE_SUBIF, delete_subif);
15716 mp->sw_if_index = ntohl (sw_if_index);
15717
15718 S;
15719 W;
15720}
15721
Pavel Kotucek95300d12016-08-26 16:11:36 +020015722#define foreach_pbb_vtr_op \
15723_("disable", L2_VTR_DISABLED) \
15724_("pop", L2_VTR_POP_2) \
15725_("push", L2_VTR_PUSH_2)
15726
15727static int
15728api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
15729{
15730 unformat_input_t *i = vam->input;
15731 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
15732 f64 timeout;
15733 u32 sw_if_index = ~0, vtr_op = ~0;
15734 u16 outer_tag = ~0;
15735 u8 dmac[6], smac[6];
15736 u8 dmac_set = 0, smac_set = 0;
15737 u16 vlanid = 0;
15738 u32 sid = ~0;
15739 u32 tmp;
15740
15741 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15742 {
15743 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15744 ;
15745 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15746 ;
15747 else if (unformat (i, "vtr_op %d", &vtr_op))
15748 ;
15749#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
15750 foreach_pbb_vtr_op
15751#undef _
15752 else if (unformat (i, "translate_pbb_stag"))
15753 {
15754 if (unformat (i, "%d", &tmp))
15755 {
15756 vtr_op = L2_VTR_TRANSLATE_2_1;
15757 outer_tag = tmp;
15758 }
15759 else
15760 {
15761 errmsg
15762 ("translate_pbb_stag operation requires outer tag definition\n");
15763 return -99;
15764 }
15765 }
15766 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
15767 dmac_set++;
15768 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
15769 smac_set++;
15770 else if (unformat (i, "sid %d", &sid))
15771 ;
15772 else if (unformat (i, "vlanid %d", &tmp))
15773 vlanid = tmp;
15774 else
15775 {
15776 clib_warning ("parse error '%U'", format_unformat_error, i);
15777 return -99;
15778 }
15779 }
15780
15781 if ((sw_if_index == ~0) || (vtr_op == ~0))
15782 {
15783 errmsg ("missing sw_if_index or vtr operation\n");
15784 return -99;
15785 }
15786 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
15787 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
15788 {
15789 errmsg
15790 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
15791 return -99;
15792 }
15793
15794 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
15795 mp->sw_if_index = ntohl (sw_if_index);
15796 mp->vtr_op = ntohl (vtr_op);
15797 mp->outer_tag = ntohs (outer_tag);
15798 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
15799 clib_memcpy (mp->b_smac, smac, sizeof (smac));
15800 mp->b_vlanid = ntohs (vlanid);
15801 mp->i_sid = ntohl (sid);
15802
15803 S;
15804 W;
15805 /* NOTREACHED */
15806 return 0;
15807}
15808
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015809static int
Juraj Sloboda506b2452016-08-07 23:45:24 -070015810api_flow_classify_set_interface (vat_main_t * vam)
15811{
15812 unformat_input_t *i = vam->input;
15813 vl_api_flow_classify_set_interface_t *mp;
15814 f64 timeout;
15815 u32 sw_if_index;
15816 int sw_if_index_set;
15817 u32 ip4_table_index = ~0;
15818 u32 ip6_table_index = ~0;
15819 u8 is_add = 1;
15820
15821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15822 {
15823 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15824 sw_if_index_set = 1;
15825 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15826 sw_if_index_set = 1;
15827 else if (unformat (i, "del"))
15828 is_add = 0;
15829 else if (unformat (i, "ip4-table %d", &ip4_table_index))
15830 ;
15831 else if (unformat (i, "ip6-table %d", &ip6_table_index))
15832 ;
15833 else
15834 {
15835 clib_warning ("parse error '%U'", format_unformat_error, i);
15836 return -99;
15837 }
15838 }
15839
15840 if (sw_if_index_set == 0)
15841 {
15842 errmsg ("missing interface name or sw_if_index\n");
15843 return -99;
15844 }
15845
15846 M (FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface);
15847
15848 mp->sw_if_index = ntohl (sw_if_index);
15849 mp->ip4_table_index = ntohl (ip4_table_index);
15850 mp->ip6_table_index = ntohl (ip6_table_index);
15851 mp->is_add = is_add;
15852
15853 S;
15854 W;
15855 /* NOTREACHED */
15856 return 0;
15857}
15858
15859static int
15860api_flow_classify_dump (vat_main_t * vam)
15861{
15862 unformat_input_t *i = vam->input;
15863 vl_api_flow_classify_dump_t *mp;
15864 f64 timeout = ~0;
15865 u8 type = FLOW_CLASSIFY_N_TABLES;
15866
15867 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
15868 ;
15869 else
15870 {
15871 errmsg ("classify table type must be specified\n");
15872 return -99;
15873 }
15874
15875 if (!vam->json_output)
15876 {
15877 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
15878 }
15879
15880 M (FLOW_CLASSIFY_DUMP, flow_classify_dump);
15881 mp->type = type;
15882 /* send it... */
15883 S;
15884
15885 /* Use a control ping for synchronization */
15886 {
15887 vl_api_control_ping_t *mp;
15888 M (CONTROL_PING, control_ping);
15889 S;
15890 }
15891 /* Wait for a reply... */
15892 W;
15893
15894 /* NOTREACHED */
15895 return 0;
15896}
15897
15898static int
Dave Barach72d72232016-08-04 10:15:08 -040015899q_or_quit (vat_main_t * vam)
15900{
15901 longjmp (vam->jump_buf, 1);
15902 return 0; /* not so much */
15903}
15904
15905static int
15906q (vat_main_t * vam)
15907{
15908 return q_or_quit (vam);
15909}
15910
15911static int
15912quit (vat_main_t * vam)
15913{
15914 return q_or_quit (vam);
15915}
15916
15917static int
15918comment (vat_main_t * vam)
15919{
15920 return 0;
15921}
15922
15923static int
15924cmd_cmp (void *a1, void *a2)
15925{
15926 u8 **c1 = a1;
15927 u8 **c2 = a2;
15928
15929 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
15930}
15931
15932static int
15933help (vat_main_t * vam)
15934{
15935 u8 **cmds = 0;
15936 u8 *name = 0;
15937 hash_pair_t *p;
15938 unformat_input_t *i = vam->input;
15939 int j;
15940
15941 if (unformat (i, "%s", &name))
15942 {
15943 uword *hs;
15944
15945 vec_add1 (name, 0);
15946
15947 hs = hash_get_mem (vam->help_by_name, name);
15948 if (hs)
15949 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
15950 else
15951 fformat (vam->ofp, "No such msg / command '%s'\n", name);
15952 vec_free (name);
15953 return 0;
15954 }
15955
15956 fformat (vam->ofp, "Help is available for the following:\n");
15957
15958 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015959 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070015960 ({
Dave Barach72d72232016-08-04 10:15:08 -040015961 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015962 }));
Dave Barach72d72232016-08-04 10:15:08 -040015963 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015964
Dave Barach72d72232016-08-04 10:15:08 -040015965 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015966
Dave Barach72d72232016-08-04 10:15:08 -040015967 for (j = 0; j < vec_len (cmds); j++)
15968 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015969
Dave Barach72d72232016-08-04 10:15:08 -040015970 vec_free (cmds);
15971 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015972}
15973
Dave Barach72d72232016-08-04 10:15:08 -040015974static int
15975set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015976{
Dave Barach72d72232016-08-04 10:15:08 -040015977 u8 *name = 0, *value = 0;
15978 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015979
Dave Barach72d72232016-08-04 10:15:08 -040015980 if (unformat (i, "%s", &name))
15981 {
15982 /* The input buffer is a vector, not a string. */
15983 value = vec_dup (i->buffer);
15984 vec_delete (value, i->index, 0);
15985 /* Almost certainly has a trailing newline */
15986 if (value[vec_len (value) - 1] == '\n')
15987 value[vec_len (value) - 1] = 0;
15988 /* Make sure it's a proper string, one way or the other */
15989 vec_add1 (value, 0);
15990 (void) clib_macro_set_value (&vam->macro_main,
15991 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015992 }
Dave Barach72d72232016-08-04 10:15:08 -040015993 else
15994 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070015995
Dave Barach72d72232016-08-04 10:15:08 -040015996 vec_free (name);
15997 vec_free (value);
15998 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015999}
16000
Dave Barach72d72232016-08-04 10:15:08 -040016001static int
16002unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016003{
Dave Barach72d72232016-08-04 10:15:08 -040016004 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016005
Dave Barach72d72232016-08-04 10:15:08 -040016006 if (unformat (vam->input, "%s", &name))
16007 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
16008 errmsg ("unset: %s wasn't set\n", name);
16009 vec_free (name);
16010 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016011}
16012
Dave Barach72d72232016-08-04 10:15:08 -040016013typedef struct
16014{
16015 u8 *name;
16016 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016017} macro_sort_t;
16018
16019
Dave Barach72d72232016-08-04 10:15:08 -040016020static int
16021macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016022{
Dave Barach72d72232016-08-04 10:15:08 -040016023 macro_sort_t *s1 = a1;
16024 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016025
Dave Barach72d72232016-08-04 10:15:08 -040016026 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016027}
16028
Dave Barach72d72232016-08-04 10:15:08 -040016029static int
16030dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016031{
Dave Barach72d72232016-08-04 10:15:08 -040016032 macro_sort_t *sort_me = 0, *sm;
16033 int i;
16034 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016035
Dave Barach72d72232016-08-04 10:15:08 -040016036 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016037 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070016038 ({
Dave Barach72d72232016-08-04 10:15:08 -040016039 vec_add2 (sort_me, sm, 1);
16040 sm->name = (u8 *)(p->key);
16041 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016042 }));
Dave Barach72d72232016-08-04 10:15:08 -040016043 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016044
Dave Barach72d72232016-08-04 10:15:08 -040016045 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016046
Dave Barach72d72232016-08-04 10:15:08 -040016047 if (vec_len (sort_me))
16048 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
16049 else
16050 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070016051
Dave Barach72d72232016-08-04 10:15:08 -040016052 for (i = 0; i < vec_len (sort_me); i++)
16053 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
16054 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016055}
16056
Dave Barach72d72232016-08-04 10:15:08 -040016057static int
16058dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050016059{
Dave Barach72d72232016-08-04 10:15:08 -040016060 int i, j;
16061 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016062
Dave Barach72d72232016-08-04 10:15:08 -040016063 if (vec_len (vam->graph_nodes) == 0)
16064 {
16065 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
16066 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016067 }
16068
Dave Barach72d72232016-08-04 10:15:08 -040016069 for (i = 0; i < vec_len (vam->graph_nodes); i++)
16070 {
16071 node = vam->graph_nodes[i];
16072 fformat (vam->ofp, "[%d] %s\n", i, node->name);
16073 for (j = 0; j < vec_len (node->next_nodes); j++)
16074 {
16075 if (node->next_nodes[j] != ~0)
16076 {
16077 next_node = vam->graph_nodes[node->next_nodes[j]];
16078 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
16079 }
16080 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050016081 }
Dave Barach72d72232016-08-04 10:15:08 -040016082 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016083}
16084
Dave Barach72d72232016-08-04 10:15:08 -040016085static int
16086search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050016087{
Dave Barach72d72232016-08-04 10:15:08 -040016088 unformat_input_t *line_input = vam->input;
16089 u8 *node_to_find;
16090 int j;
16091 vlib_node_t *node, *next_node;
16092 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016093
Dave Barach72d72232016-08-04 10:15:08 -040016094 if (vam->graph_node_index_by_name == 0)
16095 {
16096 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
16097 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016098 }
16099
Dave Barach72d72232016-08-04 10:15:08 -040016100 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
16101 {
16102 if (unformat (line_input, "%s", &node_to_find))
16103 {
16104 vec_add1 (node_to_find, 0);
16105 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
16106 if (p == 0)
16107 {
16108 fformat (vam->ofp, "%s not found...\n", node_to_find);
16109 goto out;
16110 }
16111 node = vam->graph_nodes[p[0]];
16112 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
16113 for (j = 0; j < vec_len (node->next_nodes); j++)
16114 {
16115 if (node->next_nodes[j] != ~0)
16116 {
16117 next_node = vam->graph_nodes[node->next_nodes[j]];
16118 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
16119 }
16120 }
16121 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016122
Dave Barach72d72232016-08-04 10:15:08 -040016123 else
16124 {
16125 clib_warning ("parse error '%U'", format_unformat_error,
16126 line_input);
16127 return -99;
16128 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050016129
16130 out:
Dave Barach72d72232016-08-04 10:15:08 -040016131 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016132
Dave Barachb44e9bc2016-02-19 09:06:23 -050016133 }
16134
Dave Barach72d72232016-08-04 10:15:08 -040016135 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016136}
16137
16138
Dave Barach72d72232016-08-04 10:15:08 -040016139static int
16140script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016141{
Dave Barach72d72232016-08-04 10:15:08 -040016142 u8 *s = 0;
16143 char *save_current_file;
16144 unformat_input_t save_input;
16145 jmp_buf save_jump_buf;
16146 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016147
Dave Barach72d72232016-08-04 10:15:08 -040016148 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016149
Dave Barach72d72232016-08-04 10:15:08 -040016150 if (unformat (vam->input, "%s", &s))
16151 {
16152 new_fp = fopen ((char *) s, "r");
16153 if (new_fp == 0)
16154 {
16155 errmsg ("Couldn't open script file %s\n", s);
16156 vec_free (s);
16157 return -99;
16158 }
16159 }
16160 else
16161 {
16162 errmsg ("Missing script name\n");
16163 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016164 }
16165
Dave Barach72d72232016-08-04 10:15:08 -040016166 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
16167 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
16168 save_ifp = vam->ifp;
16169 save_line_number = vam->input_line_number;
16170 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016171
Dave Barach72d72232016-08-04 10:15:08 -040016172 vam->input_line_number = 0;
16173 vam->ifp = new_fp;
16174 vam->current_file = s;
16175 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016176
Dave Barach72d72232016-08-04 10:15:08 -040016177 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
16178 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
16179 vam->ifp = save_ifp;
16180 vam->input_line_number = save_line_number;
16181 vam->current_file = (u8 *) save_current_file;
16182 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016183
Dave Barach72d72232016-08-04 10:15:08 -040016184 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016185}
16186
Dave Barach72d72232016-08-04 10:15:08 -040016187static int
16188echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016189{
Dave Barach72d72232016-08-04 10:15:08 -040016190 fformat (vam->ofp, "%v", vam->input->buffer);
16191 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016192}
16193
16194/* List of API message constructors, CLI names map to api_xxx */
16195#define foreach_vpe_api_msg \
16196_(create_loopback,"[mac <mac-addr>]") \
16197_(sw_interface_dump,"") \
16198_(sw_interface_set_flags, \
16199 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
16200_(sw_interface_add_del_address, \
16201 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
16202_(sw_interface_set_table, \
16203 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
John Lo06b14b92016-10-24 20:20:11 -040016204_(sw_interface_set_mpls_enable, \
16205 "<intfc> | sw_if_index [disable | dis]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016206_(sw_interface_set_vpath, \
16207 "<intfc> | sw_if_index <id> enable | disable") \
16208_(sw_interface_set_l2_xconnect, \
16209 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
16210 "enable | disable") \
16211_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040016212 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016213 "[shg <split-horizon-group>] [bvi]\n" \
16214 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010016215_(sw_interface_set_dpdk_hqos_pipe, \
16216 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
16217 "profile <profile-id>\n") \
16218_(sw_interface_set_dpdk_hqos_subport, \
16219 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
16220 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
16221_(sw_interface_set_dpdk_hqos_tctbl, \
16222 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016223_(bridge_domain_add_del, \
16224 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
16225_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
16226_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070016227 "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 -070016228_(l2_flags, \
16229 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
16230_(bridge_flags, \
16231 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
16232_(tap_connect, \
16233 "tapname <name> mac <mac-addr> | random-mac") \
16234_(tap_modify, \
16235 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
16236_(tap_delete, \
16237 "<vpp-if-name> | sw_if_index <id>") \
16238_(sw_interface_tap_dump, "") \
16239_(ip_add_del_route, \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016240 "<addr>/<mask> via <addr> [table-id <n>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016241 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
16242 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
16243 "[multipath] [count <n>]") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016244_(mpls_route_add_del, \
16245 "<label> <eos> via <addr> [table-id <n>]\n" \
16246 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
16247 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
16248 "[multipath] [count <n>]") \
16249_(mpls_ip_bind_unbind, \
16250 "<label> <addr/len>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016251_(proxy_arp_add_del, \
16252 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
16253_(proxy_arp_intfc_enable_disable, \
16254 "<intfc> | sw_if_index <id> enable | disable") \
16255_(mpls_add_del_encap, \
16256 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016257_(sw_interface_set_unnumbered, \
16258 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
16259_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040016260 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
16261 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016262_(reset_vrf, "vrf <id> [ipv6]") \
16263_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
16264_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
16265 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
16266 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
16267 "[outer_vlan_id_any][inner_vlan_id_any]") \
16268_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
16269_(reset_fib, "vrf <n> [ipv6]") \
16270_(dhcp_proxy_config, \
16271 "svr <v46-address> src <v46-address>\n" \
16272 "insert-cid <n> [del]") \
16273_(dhcp_proxy_config_2, \
16274 "svr <v46-address> src <v46-address>\n" \
16275 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
16276_(dhcp_proxy_set_vss, \
16277 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
16278_(dhcp_client_config, \
16279 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
16280_(set_ip_flow_hash, \
16281 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
16282_(sw_interface_ip6_enable_disable, \
16283 "<intfc> | sw_if_index <id> enable | disable") \
16284_(sw_interface_ip6_set_link_local_address, \
16285 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
16286_(sw_interface_ip6nd_ra_prefix, \
16287 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
16288 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
16289 "[nolink] [isno]") \
16290_(sw_interface_ip6nd_ra_config, \
16291 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040016292 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016293 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
16294_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
16295_(l2_patch_add_del, \
16296 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
16297 "enable | disable") \
16298_(mpls_ethernet_add_del_tunnel, \
16299 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
16300 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
16301_(mpls_ethernet_add_del_tunnel_2, \
16302 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
16303 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
16304_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070016305 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
16306 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
16307 "[policy <policy_name>]") \
16308_(sr_policy_add_del, \
16309 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
16310_(sr_multicast_map_add_del, \
16311 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016312_(classify_add_del_table, \
16313 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
16314 "[del] mask <mask-value>\n" \
16315 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
16316_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070016317 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
16318 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
16319 " [l3 [ip4|ip6]]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016320_(classify_set_interface_ip_table, \
16321 "<intfc> | sw_if_index <nn> table <nn>") \
16322_(classify_set_interface_l2_tables, \
16323 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16324 " [other-table <nn>]") \
16325_(get_node_index, "node <node-name") \
16326_(add_node_next, "node <node-name> next <next-node-name>") \
16327_(l2tpv3_create_tunnel, \
16328 "client_address <ip6-addr> our_address <ip6-addr>\n" \
16329 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
16330 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
16331_(l2tpv3_set_tunnel_cookies, \
16332 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
16333 "[new_remote_cookie <nn>]\n") \
16334_(l2tpv3_interface_enable_disable, \
16335 "<intfc> | sw_if_index <nn> enable | disable") \
16336_(l2tpv3_set_lookup_key, \
16337 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
16338_(sw_if_l2tpv3_tunnel_dump, "") \
16339_(vxlan_add_del_tunnel, \
Chris Luke404be662016-05-27 12:11:24 -040016340 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016341 " [decap-next l2|ip4|ip6] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050016342_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040016343_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070016344 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040016345_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016346_(l2_fib_clear_table, "") \
16347_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
16348_(l2_interface_vlan_tag_rewrite, \
16349 "<intfc> | sw_if_index <nn> \n" \
16350 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
16351 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
16352_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000016353 "socket <filename> [server] [renumber <dev_instance>] " \
16354 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016355_(modify_vhost_user_if, \
16356 "<intfc> | sw_if_index <nn> socket <filename>\n" \
16357 "[server] [renumber <dev_instance>]") \
16358_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
16359_(sw_interface_vhost_user_dump, "") \
16360_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080016361_(vxlan_gpe_add_del_tunnel, \
16362 "local <addr> remote <addr> vni <nn>\n" \
16363 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
16364 "[next-ethernet] [next-nsh]\n") \
16365_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016366_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016367_(interface_name_renumber, \
16368 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
16369_(input_acl_set_interface, \
16370 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16371 " [l2-table <nn>] [del]") \
16372_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040016373_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016374_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
16375_(ip_dump, "ipv4 | ipv6") \
16376_(ipsec_spd_add_del, "spd_id <n> [del]") \
16377_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
16378 " spid_id <n> ") \
16379_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
16380 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
16381 " integ_alg <alg> integ_key <hex>") \
16382_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
16383 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
16384 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
16385 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
16386_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020016387_(ikev2_profile_add_del, "name <profile_name> [del]") \
16388_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
16389 "(auth_data 0x<data> | auth_data <data>)") \
16390_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
16391 "(id_data 0x<data> | id_data <data>) (local|remote)") \
16392_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
16393 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
16394 "(local|remote)") \
16395_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016396_(delete_loopback,"sw_if_index <nn>") \
16397_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
16398_(map_add_domain, \
16399 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
16400 "ip6-src <ip6addr> " \
16401 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
16402_(map_del_domain, "index <n>") \
16403_(map_add_del_rule, \
16404 "index <n> psid <n> dst <ip6addr> [del]") \
16405_(map_domain_dump, "") \
16406_(map_rule_dump, "index <map-domain>") \
16407_(want_interface_events, "enable|disable") \
16408_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050016409_(get_first_msg_id, "client <name>") \
16410_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
16411_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016412 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010016413_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000016414_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070016415_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
16416_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020016417_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
16418 " sw_if_index <sw_if_index> p <priority> " \
16419 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016420_(lisp_add_del_locator, "locator-set <locator_name> " \
16421 "iface <intf> | sw_if_index <sw_if_index> " \
16422 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020016423_(lisp_add_del_local_eid,"vni <vni> eid " \
16424 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016425 "locator-set <locator_name> [del]") \
Florin Coras429e7952016-08-02 02:31:03 +020016426_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
16427 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016428_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020016429_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020016430_(lisp_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016431_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020016432_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
16433 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020016434 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020016435 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020016436 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020016437_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
16438 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020016439_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020016440_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020016441_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020016442_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020016443_(lisp_locator_set_dump, "[local | remote]") \
16444_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020016445_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
16446 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020016447_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020016448_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016449_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020016450_(lisp_map_resolver_dump, "") \
Filip Tehlar69a9b762016-09-23 10:00:52 +020016451_(lisp_adjacencies_get, "vni <vni>") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020016452_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020016453_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020016454_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020016455_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020016456_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070016457_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070016458_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070016459_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070016460_(policer_classify_set_interface, \
16461 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16462 " [l2-table <nn>] [del]") \
16463_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070016464_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
16465 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020016466_(netmap_delete, "name <interface name>") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020016467_(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
16468_(mpls_fib_encap_dump, "") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016469_(mpls_fib_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020016470_(classify_table_ids, "") \
16471_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
16472_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070016473_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070016474_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
16475 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
16476 "[template_interval <nn>] [udp_checksum]") \
16477_(ipfix_exporter_dump, "") \
16478_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
16479_(ipfix_classify_stream_dump, "") \
16480_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
16481_(ipfix_classify_table_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020016482_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
16483_(pg_create_interface, "if_id <nn>") \
16484_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040016485_(pg_enable_disable, "[stream <id>] disable") \
16486_(ip_source_and_port_range_check_add_del, \
16487 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
16488_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070016489 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070016490 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
16491_(ipsec_gre_add_del_tunnel, \
16492 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016493_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020016494_(delete_subif,"sub_sw_if_index <nn> sub_if_id <nn>") \
16495_(l2_interface_pbb_tag_rewrite, \
16496 "<intfc> | sw_if_index <nn> \n" \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070016497 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
16498 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Juraj Sloboda506b2452016-08-07 23:45:24 -070016499_(punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
16500_(flow_classify_set_interface, \
16501 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
16502_(flow_classify_dump, "type [ip4|ip6]")
Ed Warnickecb9cada2015-12-08 15:45:58 -070016503
16504/* List of command functions, CLI names map directly to functions */
16505#define foreach_cli_function \
16506_(comment, "usage: comment <ignore-rest-of-line>") \
16507_(dump_interface_table, "usage: dump_interface_table") \
16508_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
16509_(dump_ipv4_table, "usage: dump_ipv4_table") \
16510_(dump_ipv6_table, "usage: dump_ipv6_table") \
16511_(dump_stats_table, "usage: dump_stats_table") \
16512_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016513_(dump_node_table, "usage: dump_node_table") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016514_(echo, "usage: echo <message>") \
16515_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020016516_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016517_(help, "usage: help") \
16518_(q, "usage: quit") \
16519_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016520_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016521_(set, "usage: set <variable-name> <value>") \
16522_(script, "usage: script <file-name>") \
16523_(unset, "usage: unset <variable-name>")
16524
16525#define _(N,n) \
16526 static void vl_api_##n##_t_handler_uni \
16527 (vl_api_##n##_t * mp) \
16528 { \
16529 vat_main_t * vam = &vat_main; \
16530 if (vam->json_output) { \
16531 vl_api_##n##_t_handler_json(mp); \
16532 } else { \
16533 vl_api_##n##_t_handler(mp); \
16534 } \
16535 }
16536foreach_vpe_api_reply_msg;
16537#undef _
16538
Dave Barach72d72232016-08-04 10:15:08 -040016539void
16540vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016541{
16542#define _(N,n) \
16543 vl_msg_api_set_handlers(VL_API_##N, #n, \
16544 vl_api_##n##_t_handler_uni, \
16545 vl_noop_handler, \
16546 vl_api_##n##_t_endian, \
16547 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016548 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040016549 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016550#undef _
16551
Dave Barach72d72232016-08-04 10:15:08 -040016552 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016553
Dave Barach72d72232016-08-04 10:15:08 -040016554 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016555
Dave Barach72d72232016-08-04 10:15:08 -040016556 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016557
Dave Barach72d72232016-08-04 10:15:08 -040016558 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016559
Dave Barach72d72232016-08-04 10:15:08 -040016560 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016561#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040016562 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016563#undef _
16564
Dave Barach72d72232016-08-04 10:15:08 -040016565 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016566#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040016567 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016568#undef _
16569
Dave Barach72d72232016-08-04 10:15:08 -040016570 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016571#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040016572 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016573#undef _
16574
Dave Barach72d72232016-08-04 10:15:08 -040016575 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016576#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040016577 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016578#undef _
16579}
16580
16581#undef vl_api_version
16582#define vl_api_version(n,v) static u32 vpe_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040016583#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070016584#undef vl_api_version
16585
Dave Barach72d72232016-08-04 10:15:08 -040016586void
16587vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016588{
Dave Barach72d72232016-08-04 10:15:08 -040016589 /*
16590 * Send the main API signature in slot 0. This bit of code must
16591 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
16592 */
16593 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016594}
Dave Barach72d72232016-08-04 10:15:08 -040016595
16596/*
16597 * fd.io coding-style-patch-verification: ON
16598 *
16599 * Local Variables:
16600 * eval: (c-set-style "gnu")
16601 * End:
16602 */