blob: d9c13ad8644515ccb2350c14ff5d40aa79c8a93c [file] [log] [blame]
Damjan Marion7cd468a2016-12-19 23:05:39 +01001/*
2 *------------------------------------------------------------------
3 * api_format.c
4 *
5 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
Neale Ranns86327be2018-11-02 09:14:01 -070021#include <vpp/api/types.h>
Dave Barach59b25652017-09-10 15:04:27 -040022#include <vppinfra/socket.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010023#include <vlibapi/api.h>
24#include <vlibmemory/api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010025#include <vnet/ip/ip.h>
John Lo7f358b32018-04-28 01:19:24 -040026#include <vnet/ip/ip_neighbor.h>
Neale Ranns37029302018-08-10 05:30:06 -070027#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010028#include <vnet/l2/l2_input.h>
29#include <vnet/l2tp/l2tp.h>
30#include <vnet/vxlan/vxlan.h>
Marco Varleseb598f1d2017-09-19 14:25:28 +020031#include <vnet/geneve/geneve.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010032#include <vnet/gre/gre.h>
33#include <vnet/vxlan-gpe/vxlan_gpe.h>
34#include <vnet/lisp-gpe/lisp_gpe.h>
35
36#include <vpp/api/vpe_msg_enum.h>
37#include <vnet/l2/l2_classify.h>
38#include <vnet/l2/l2_vtr.h>
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010039#include <vnet/classify/in_out_acl.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010040#include <vnet/classify/policer_classify.h>
41#include <vnet/classify/flow_classify.h>
42#include <vnet/mpls/mpls.h>
43#include <vnet/ipsec/ipsec.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010044#include <inttypes.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010045#include <vnet/cop/cop.h>
46#include <vnet/ip/ip6_hop_by_hop.h>
47#include <vnet/ip/ip_source_and_port_range_check.h>
48#include <vnet/policer/xlate.h>
49#include <vnet/span/span.h>
50#include <vnet/policer/policer.h>
51#include <vnet/policer/police.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000052#include <vnet/mfib/mfib_types.h>
John Lo70bfcaf2017-11-14 13:19:26 -050053#include <vnet/dhcp/dhcp_proxy.h>
Steven9cd2d7a2017-12-20 12:43:01 -080054#include <vnet/bonding/node.h>
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070055#include <vnet/qos/qos_types.h>
Neale Ranns37029302018-08-10 05:30:06 -070056#include <vnet/ethernet/ethernet_types_api.h>
57#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010058#include "vat/json_format.h"
Neale Ranns86327be2018-11-02 09:14:01 -070059#include <vnet/ip/ip_types_api.h>
60#include <vnet/ethernet/ethernet_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010061
62#include <inttypes.h>
63#include <sys/stat.h>
64
65#define vl_typedefs /* define message structures */
66#include <vpp/api/vpe_all_api_h.h>
67#undef vl_typedefs
68
69/* declare message handlers for each api */
70
71#define vl_endianfun /* define message structures */
72#include <vpp/api/vpe_all_api_h.h>
73#undef vl_endianfun
74
75/* instantiate all the print functions we know about */
Dave Barachf35a0722019-06-12 16:50:38 -040076#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010077#define vl_print(handle, ...)
Dave Barachf35a0722019-06-12 16:50:38 -040078#else
79#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
80#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010081#define vl_printfun
82#include <vpp/api/vpe_all_api_h.h>
83#undef vl_printfun
84
Dave Barach2d6b2d62017-01-25 16:32:08 -050085#define __plugin_msg_base 0
Dave Barachfe6bdfd2017-01-20 19:50:09 -050086#include <vlibapi/vat_helper_macros.h>
87
Dave Barach59b25652017-09-10 15:04:27 -040088#if VPP_API_TEST_BUILTIN == 0
89#include <netdb.h>
90
91u32
92vl (void *p)
93{
94 return vec_len (p);
95}
96
97int
98vat_socket_connect (vat_main_t * vam)
99{
Florin Coras66a10032018-12-21 16:23:09 -0800100 int rv;
Florin Coras90a63982017-12-19 04:50:01 -0800101 vam->socket_client_main = &socket_client_main;
Florin Coras66a10032018-12-21 16:23:09 -0800102 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
103 "vpp_api_test",
104 0 /* default socket rx, tx buffer */ )))
105 return rv;
106 /* vpp expects the client index in network order */
107 vam->my_client_index = htonl (socket_client_main.client_index);
108 return 0;
Dave Barach59b25652017-09-10 15:04:27 -0400109}
110#else /* vpp built-in case, we don't do sockets... */
111int
112vat_socket_connect (vat_main_t * vam)
113{
114 return 0;
115}
116
Florin Coras90a63982017-12-19 04:50:01 -0800117int
118vl_socket_client_read (int wait)
Dave Barach59b25652017-09-10 15:04:27 -0400119{
Florin Coras90a63982017-12-19 04:50:01 -0800120 return -1;
Dave Barach59b25652017-09-10 15:04:27 -0400121};
Florin Coras90a63982017-12-19 04:50:01 -0800122
123int
124vl_socket_client_write ()
125{
126 return -1;
127};
128
129void *
130vl_socket_client_msg_alloc (int nbytes)
131{
132 return 0;
133}
Dave Barach59b25652017-09-10 15:04:27 -0400134#endif
135
136
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500137f64
138vat_time_now (vat_main_t * vam)
139{
140#if VPP_API_TEST_BUILTIN
141 return vlib_time_now (vam->vlib_main);
142#else
143 return clib_time_now (&vam->clib_time);
144#endif
145}
146
147void
148errmsg (char *fmt, ...)
149{
150 vat_main_t *vam = &vat_main;
151 va_list va;
152 u8 *s;
153
154 va_start (va, fmt);
155 s = va_format (0, fmt, &va);
156 va_end (va);
157
158 vec_add1 (s, 0);
159
160#if VPP_API_TEST_BUILTIN
161 vlib_cli_output (vam->vlib_main, (char *) s);
162#else
163 {
164 if (vam->ifp != stdin)
165 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
166 vam->input_line_number);
167 fformat (vam->ofp, (char *) s);
168 fflush (vam->ofp);
169 }
170#endif
171
172 vec_free (s);
173}
174
Dave Barach4a3f69c2017-02-22 12:44:56 -0500175#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +0100176static uword
177api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
178{
179 vat_main_t *vam = va_arg (*args, vat_main_t *);
180 u32 *result = va_arg (*args, u32 *);
181 u8 *if_name;
182 uword *p;
183
184 if (!unformat (input, "%s", &if_name))
185 return 0;
186
187 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
188 if (p == 0)
189 return 0;
190 *result = p[0];
191 return 1;
192}
193
eyal bariaf86a482018-04-17 11:20:27 +0300194static uword
195api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
196{
197 return 0;
198}
199
Damjan Marion7cd468a2016-12-19 23:05:39 +0100200/* Parse an IP4 address %d.%d.%d.%d. */
201uword
202unformat_ip4_address (unformat_input_t * input, va_list * args)
203{
204 u8 *result = va_arg (*args, u8 *);
205 unsigned a[4];
206
207 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
208 return 0;
209
210 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
211 return 0;
212
213 result[0] = a[0];
214 result[1] = a[1];
215 result[2] = a[2];
216 result[3] = a[3];
217
218 return 1;
219}
220
221uword
222unformat_ethernet_address (unformat_input_t * input, va_list * args)
223{
224 u8 *result = va_arg (*args, u8 *);
225 u32 i, a[6];
226
227 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
228 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
229 return 0;
230
231 /* Check range. */
232 for (i = 0; i < 6; i++)
233 if (a[i] >= (1 << 8))
234 return 0;
235
236 for (i = 0; i < 6; i++)
237 result[i] = a[i];
238
239 return 1;
240}
241
242/* Returns ethernet type as an int in host byte order. */
243uword
244unformat_ethernet_type_host_byte_order (unformat_input_t * input,
245 va_list * args)
246{
247 u16 *result = va_arg (*args, u16 *);
248 int type;
249
250 /* Numeric type. */
251 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
252 {
253 if (type >= (1 << 16))
254 return 0;
255 *result = type;
256 return 1;
257 }
258 return 0;
259}
260
261/* Parse an IP6 address. */
262uword
263unformat_ip6_address (unformat_input_t * input, va_list * args)
264{
265 ip6_address_t *result = va_arg (*args, ip6_address_t *);
266 u16 hex_quads[8];
267 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
268 uword c, n_colon, double_colon_index;
269
270 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
271 double_colon_index = ARRAY_LEN (hex_quads);
272 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
273 {
274 hex_digit = 16;
275 if (c >= '0' && c <= '9')
276 hex_digit = c - '0';
277 else if (c >= 'a' && c <= 'f')
278 hex_digit = c + 10 - 'a';
279 else if (c >= 'A' && c <= 'F')
280 hex_digit = c + 10 - 'A';
281 else if (c == ':' && n_colon < 2)
282 n_colon++;
283 else
284 {
285 unformat_put_input (input);
286 break;
287 }
288
289 /* Too many hex quads. */
290 if (n_hex_quads >= ARRAY_LEN (hex_quads))
291 return 0;
292
293 if (hex_digit < 16)
294 {
295 hex_quad = (hex_quad << 4) | hex_digit;
296
297 /* Hex quad must fit in 16 bits. */
298 if (n_hex_digits >= 4)
299 return 0;
300
301 n_colon = 0;
302 n_hex_digits++;
303 }
304
305 /* Save position of :: */
306 if (n_colon == 2)
307 {
308 /* More than one :: ? */
309 if (double_colon_index < ARRAY_LEN (hex_quads))
310 return 0;
311 double_colon_index = n_hex_quads;
312 }
313
314 if (n_colon > 0 && n_hex_digits > 0)
315 {
316 hex_quads[n_hex_quads++] = hex_quad;
317 hex_quad = 0;
318 n_hex_digits = 0;
319 }
320 }
321
322 if (n_hex_digits > 0)
323 hex_quads[n_hex_quads++] = hex_quad;
324
325 {
326 word i;
327
328 /* Expand :: to appropriate number of zero hex quads. */
329 if (double_colon_index < ARRAY_LEN (hex_quads))
330 {
331 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
332
333 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
334 hex_quads[n_zero + i] = hex_quads[i];
335
336 for (i = 0; i < n_zero; i++)
337 hex_quads[double_colon_index + i] = 0;
338
339 n_hex_quads = ARRAY_LEN (hex_quads);
340 }
341
342 /* Too few hex quads given. */
343 if (n_hex_quads < ARRAY_LEN (hex_quads))
344 return 0;
345
346 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
347 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
348
349 return 1;
350 }
351}
352
353uword
354unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
355{
356 u32 *r = va_arg (*args, u32 *);
357
358 if (0);
359#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
360 foreach_ipsec_policy_action
361#undef _
362 else
363 return 0;
364 return 1;
365}
366
Damjan Marion7cd468a2016-12-19 23:05:39 +0100367u8 *
368format_ipsec_crypto_alg (u8 * s, va_list * args)
369{
370 u32 i = va_arg (*args, u32);
371 u8 *t = 0;
372
373 switch (i)
374 {
375#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
376 foreach_ipsec_crypto_alg
377#undef _
378 default:
379 return format (s, "unknown");
380 }
381 return format (s, "%s", t);
382}
383
Damjan Marion7cd468a2016-12-19 23:05:39 +0100384u8 *
385format_ipsec_integ_alg (u8 * s, va_list * args)
386{
387 u32 i = va_arg (*args, u32);
388 u8 *t = 0;
389
390 switch (i)
391 {
392#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
393 foreach_ipsec_integ_alg
394#undef _
395 default:
396 return format (s, "unknown");
397 }
398 return format (s, "%s", t);
399}
400
Dave Barach4a3f69c2017-02-22 12:44:56 -0500401#else /* VPP_API_TEST_BUILTIN == 1 */
402static uword
403api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
404{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200405 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500406 vnet_main_t *vnm = vnet_get_main ();
407 u32 *result = va_arg (*args, u32 *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500408
eyal bariaf86a482018-04-17 11:20:27 +0300409 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500410}
eyal bariaf86a482018-04-17 11:20:27 +0300411
412static uword
413api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
414{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200415 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
eyal bariaf86a482018-04-17 11:20:27 +0300416 vnet_main_t *vnm = vnet_get_main ();
417 u32 *result = va_arg (*args, u32 *);
418
419 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
420}
421
Damjan Marion7cd468a2016-12-19 23:05:39 +0100422#endif /* VPP_API_TEST_BUILTIN */
423
Neale Ranns17dcec02019-01-09 21:22:20 -0800424uword
425unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
426{
427 u32 *r = va_arg (*args, u32 *);
428
429 if (0);
430#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
431 foreach_ipsec_crypto_alg
432#undef _
433 else
434 return 0;
435 return 1;
436}
437
438uword
439unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
440{
441 u32 *r = va_arg (*args, u32 *);
442
443 if (0);
444#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
445 foreach_ipsec_integ_alg
446#undef _
447 else
448 return 0;
449 return 1;
450}
451
Damjan Marion7cd468a2016-12-19 23:05:39 +0100452static uword
453unformat_policer_rate_type (unformat_input_t * input, va_list * args)
454{
455 u8 *r = va_arg (*args, u8 *);
456
457 if (unformat (input, "kbps"))
458 *r = SSE2_QOS_RATE_KBPS;
459 else if (unformat (input, "pps"))
460 *r = SSE2_QOS_RATE_PPS;
461 else
462 return 0;
463 return 1;
464}
465
466static uword
467unformat_policer_round_type (unformat_input_t * input, va_list * args)
468{
469 u8 *r = va_arg (*args, u8 *);
470
471 if (unformat (input, "closest"))
472 *r = SSE2_QOS_ROUND_TO_CLOSEST;
473 else if (unformat (input, "up"))
474 *r = SSE2_QOS_ROUND_TO_UP;
475 else if (unformat (input, "down"))
476 *r = SSE2_QOS_ROUND_TO_DOWN;
477 else
478 return 0;
479 return 1;
480}
481
482static uword
483unformat_policer_type (unformat_input_t * input, va_list * args)
484{
485 u8 *r = va_arg (*args, u8 *);
486
487 if (unformat (input, "1r2c"))
488 *r = SSE2_QOS_POLICER_TYPE_1R2C;
489 else if (unformat (input, "1r3c"))
490 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
491 else if (unformat (input, "2r3c-2698"))
492 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
493 else if (unformat (input, "2r3c-4115"))
494 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
495 else if (unformat (input, "2r3c-mef5cf1"))
496 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
497 else
498 return 0;
499 return 1;
500}
501
502static uword
503unformat_dscp (unformat_input_t * input, va_list * va)
504{
505 u8 *r = va_arg (*va, u8 *);
506
507 if (0);
508#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
509 foreach_vnet_dscp
510#undef _
511 else
512 return 0;
513 return 1;
514}
515
516static uword
517unformat_policer_action_type (unformat_input_t * input, va_list * va)
518{
519 sse2_qos_pol_action_params_st *a
520 = va_arg (*va, sse2_qos_pol_action_params_st *);
521
522 if (unformat (input, "drop"))
523 a->action_type = SSE2_QOS_ACTION_DROP;
524 else if (unformat (input, "transmit"))
525 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
526 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
527 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
528 else
529 return 0;
530 return 1;
531}
532
533static uword
534unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
535{
536 u32 *r = va_arg (*va, u32 *);
537 u32 tid;
538
539 if (unformat (input, "ip4"))
540 tid = POLICER_CLASSIFY_TABLE_IP4;
541 else if (unformat (input, "ip6"))
542 tid = POLICER_CLASSIFY_TABLE_IP6;
543 else if (unformat (input, "l2"))
544 tid = POLICER_CLASSIFY_TABLE_L2;
545 else
546 return 0;
547
548 *r = tid;
549 return 1;
550}
551
552static uword
553unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
554{
555 u32 *r = va_arg (*va, u32 *);
556 u32 tid;
557
558 if (unformat (input, "ip4"))
559 tid = FLOW_CLASSIFY_TABLE_IP4;
560 else if (unformat (input, "ip6"))
561 tid = FLOW_CLASSIFY_TABLE_IP6;
562 else
563 return 0;
564
565 *r = tid;
566 return 1;
567}
568
Benoît Ganne49ee6842019-04-30 11:50:46 +0200569#if (VPP_API_TEST_BUILTIN==0)
570
Neale Ranns32e1c012016-11-22 17:07:28 +0000571static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
572static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
573static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
574static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
575
576uword
577unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
578{
579 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
580 mfib_itf_attribute_t attr;
581
582 old = *iflags;
583 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
584 {
585 if (unformat (input, mfib_itf_flag_long_names[attr]))
586 *iflags |= (1 << attr);
587 }
588 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
589 {
590 if (unformat (input, mfib_itf_flag_names[attr]))
591 *iflags |= (1 << attr);
592 }
593
594 return (old == *iflags ? 0 : 1);
595}
596
597uword
598unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
599{
600 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
601 mfib_entry_attribute_t attr;
602
603 old = *eflags;
604 FOR_EACH_MFIB_ATTRIBUTE (attr)
605 {
606 if (unformat (input, mfib_flag_long_names[attr]))
607 *eflags |= (1 << attr);
608 }
609 FOR_EACH_MFIB_ATTRIBUTE (attr)
610 {
611 if (unformat (input, mfib_flag_names[attr]))
612 *eflags |= (1 << attr);
613 }
614
615 return (old == *eflags ? 0 : 1);
616}
617
Damjan Marion7cd468a2016-12-19 23:05:39 +0100618u8 *
619format_ip4_address (u8 * s, va_list * args)
620{
621 u8 *a = va_arg (*args, u8 *);
622 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
623}
624
625u8 *
626format_ip6_address (u8 * s, va_list * args)
627{
628 ip6_address_t *a = va_arg (*args, ip6_address_t *);
629 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
630
631 i_max_n_zero = ARRAY_LEN (a->as_u16);
632 max_n_zeros = 0;
633 i_first_zero = i_max_n_zero;
634 n_zeros = 0;
635 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
636 {
637 u32 is_zero = a->as_u16[i] == 0;
638 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
639 {
640 i_first_zero = i;
641 n_zeros = 0;
642 }
643 n_zeros += is_zero;
644 if ((!is_zero && n_zeros > max_n_zeros)
645 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
646 {
647 i_max_n_zero = i_first_zero;
648 max_n_zeros = n_zeros;
649 i_first_zero = ARRAY_LEN (a->as_u16);
650 n_zeros = 0;
651 }
652 }
653
654 last_double_colon = 0;
655 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
656 {
657 if (i == i_max_n_zero && max_n_zeros > 1)
658 {
659 s = format (s, "::");
660 i += max_n_zeros - 1;
661 last_double_colon = 1;
662 }
663 else
664 {
665 s = format (s, "%s%x",
666 (last_double_colon || i == 0) ? "" : ":",
667 clib_net_to_host_u16 (a->as_u16[i]));
668 last_double_colon = 0;
669 }
670 }
671
672 return s;
673}
674
675/* Format an IP46 address. */
676u8 *
677format_ip46_address (u8 * s, va_list * args)
678{
679 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
680 ip46_type_t type = va_arg (*args, ip46_type_t);
681 int is_ip4 = 1;
682
683 switch (type)
684 {
685 case IP46_TYPE_ANY:
686 is_ip4 = ip46_address_is_ip4 (ip46);
687 break;
688 case IP46_TYPE_IP4:
689 is_ip4 = 1;
690 break;
691 case IP46_TYPE_IP6:
692 is_ip4 = 0;
693 break;
694 }
695
696 return is_ip4 ?
697 format (s, "%U", format_ip4_address, &ip46->ip4) :
698 format (s, "%U", format_ip6_address, &ip46->ip6);
699}
700
701u8 *
702format_ethernet_address (u8 * s, va_list * args)
703{
704 u8 *a = va_arg (*args, u8 *);
705
706 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
707 a[0], a[1], a[2], a[3], a[4], a[5]);
708}
709#endif
710
711static void
Neale Ranns097fa662018-05-01 05:17:55 -0700712increment_v4_address (vl_api_ip4_address_t * i)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100713{
Neale Ranns097fa662018-05-01 05:17:55 -0700714 ip4_address_t *a = (ip4_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100715 u32 v;
716
717 v = ntohl (a->as_u32) + 1;
718 a->as_u32 = ntohl (v);
719}
720
721static void
Neale Ranns097fa662018-05-01 05:17:55 -0700722increment_v6_address (vl_api_ip6_address_t * i)
Neale Ranns2b5ba952019-04-02 10:15:40 +0000723{
Neale Ranns097fa662018-05-01 05:17:55 -0700724 ip6_address_t *a = (ip6_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100725 u64 v0, v1;
726
727 v0 = clib_net_to_host_u64 (a->as_u64[0]);
728 v1 = clib_net_to_host_u64 (a->as_u64[1]);
729
730 v1 += 1;
731 if (v1 == 0)
732 v0 += 1;
733 a->as_u64[0] = clib_net_to_host_u64 (v0);
734 a->as_u64[1] = clib_net_to_host_u64 (v1);
735}
736
737static void
Neale Ranns097fa662018-05-01 05:17:55 -0700738increment_address (vl_api_address_t * a)
739{
740 if (a->af == ADDRESS_IP4)
741 increment_v4_address (&a->un.ip4);
742 else if (a->af == ADDRESS_IP6)
743 increment_v6_address (&a->un.ip6);
744}
745
746static void
747set_ip4_address (vl_api_address_t * a, u32 v)
748{
749 if (a->af == ADDRESS_IP4)
750 {
751 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
752 i->as_u32 = v;
753 }
754}
755
756static void
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200757increment_mac_address (u8 * mac)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100758{
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200759 u64 tmp = *((u64 *) mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100760 tmp = clib_net_to_host_u64 (tmp);
761 tmp += 1 << 16; /* skip unused (least significant) octets */
762 tmp = clib_host_to_net_u64 (tmp);
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200763
764 clib_memcpy (mac, &tmp, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100765}
766
Neale Ranns097fa662018-05-01 05:17:55 -0700767static void
768vat_json_object_add_address (vat_json_node_t * node,
769 const char *str, const vl_api_address_t * addr)
770{
771 if (ADDRESS_IP6 == addr->af)
772 {
773 struct in6_addr ip6;
774
775 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
776 vat_json_object_add_ip6 (node, str, ip6);
777 }
778 else
779 {
780 struct in_addr ip4;
781
782 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
783 vat_json_object_add_ip4 (node, str, ip4);
784 }
785}
786
787static void
788vat_json_object_add_prefix (vat_json_node_t * node,
789 const vl_api_prefix_t * prefix)
790{
Paul Vinciguerraab055082019-06-06 14:07:55 -0400791 vat_json_object_add_uint (node, "len", prefix->len);
792 vat_json_object_add_address (node, "address", &prefix->address);
Neale Ranns097fa662018-05-01 05:17:55 -0700793}
794
Damjan Marion7cd468a2016-12-19 23:05:39 +0100795static void vl_api_create_loopback_reply_t_handler
796 (vl_api_create_loopback_reply_t * mp)
797{
798 vat_main_t *vam = &vat_main;
799 i32 retval = ntohl (mp->retval);
800
801 vam->retval = retval;
802 vam->regenerate_interface_table = 1;
803 vam->sw_if_index = ntohl (mp->sw_if_index);
804 vam->result_ready = 1;
805}
806
807static void vl_api_create_loopback_reply_t_handler_json
808 (vl_api_create_loopback_reply_t * mp)
809{
810 vat_main_t *vam = &vat_main;
811 vat_json_node_t node;
812
813 vat_json_init_object (&node);
814 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
815 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
816
817 vat_json_print (vam->ofp, &node);
818 vat_json_free (&node);
819 vam->retval = ntohl (mp->retval);
820 vam->result_ready = 1;
821}
822
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600823static void vl_api_create_loopback_instance_reply_t_handler
824 (vl_api_create_loopback_instance_reply_t * mp)
825{
826 vat_main_t *vam = &vat_main;
827 i32 retval = ntohl (mp->retval);
828
829 vam->retval = retval;
830 vam->regenerate_interface_table = 1;
831 vam->sw_if_index = ntohl (mp->sw_if_index);
832 vam->result_ready = 1;
833}
834
835static void vl_api_create_loopback_instance_reply_t_handler_json
836 (vl_api_create_loopback_instance_reply_t * mp)
837{
838 vat_main_t *vam = &vat_main;
839 vat_json_node_t node;
840
841 vat_json_init_object (&node);
842 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
843 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
844
845 vat_json_print (vam->ofp, &node);
846 vat_json_free (&node);
847 vam->retval = ntohl (mp->retval);
848 vam->result_ready = 1;
849}
850
Damjan Marion7cd468a2016-12-19 23:05:39 +0100851static void vl_api_af_packet_create_reply_t_handler
852 (vl_api_af_packet_create_reply_t * mp)
853{
854 vat_main_t *vam = &vat_main;
855 i32 retval = ntohl (mp->retval);
856
857 vam->retval = retval;
858 vam->regenerate_interface_table = 1;
859 vam->sw_if_index = ntohl (mp->sw_if_index);
860 vam->result_ready = 1;
861}
862
863static void vl_api_af_packet_create_reply_t_handler_json
864 (vl_api_af_packet_create_reply_t * mp)
865{
866 vat_main_t *vam = &vat_main;
867 vat_json_node_t node;
868
869 vat_json_init_object (&node);
870 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
871 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
872
873 vat_json_print (vam->ofp, &node);
874 vat_json_free (&node);
875
876 vam->retval = ntohl (mp->retval);
877 vam->result_ready = 1;
878}
879
880static void vl_api_create_vlan_subif_reply_t_handler
881 (vl_api_create_vlan_subif_reply_t * mp)
882{
883 vat_main_t *vam = &vat_main;
884 i32 retval = ntohl (mp->retval);
885
886 vam->retval = retval;
887 vam->regenerate_interface_table = 1;
888 vam->sw_if_index = ntohl (mp->sw_if_index);
889 vam->result_ready = 1;
890}
891
892static void vl_api_create_vlan_subif_reply_t_handler_json
893 (vl_api_create_vlan_subif_reply_t * mp)
894{
895 vat_main_t *vam = &vat_main;
896 vat_json_node_t node;
897
898 vat_json_init_object (&node);
899 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
900 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
901
902 vat_json_print (vam->ofp, &node);
903 vat_json_free (&node);
904
905 vam->retval = ntohl (mp->retval);
906 vam->result_ready = 1;
907}
908
909static void vl_api_create_subif_reply_t_handler
910 (vl_api_create_subif_reply_t * mp)
911{
912 vat_main_t *vam = &vat_main;
913 i32 retval = ntohl (mp->retval);
914
915 vam->retval = retval;
916 vam->regenerate_interface_table = 1;
917 vam->sw_if_index = ntohl (mp->sw_if_index);
918 vam->result_ready = 1;
919}
920
921static void vl_api_create_subif_reply_t_handler_json
922 (vl_api_create_subif_reply_t * mp)
923{
924 vat_main_t *vam = &vat_main;
925 vat_json_node_t node;
926
927 vat_json_init_object (&node);
928 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
929 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
930
931 vat_json_print (vam->ofp, &node);
932 vat_json_free (&node);
933
934 vam->retval = ntohl (mp->retval);
935 vam->result_ready = 1;
936}
937
938static void vl_api_interface_name_renumber_reply_t_handler
939 (vl_api_interface_name_renumber_reply_t * mp)
940{
941 vat_main_t *vam = &vat_main;
942 i32 retval = ntohl (mp->retval);
943
944 vam->retval = retval;
945 vam->regenerate_interface_table = 1;
946 vam->result_ready = 1;
947}
948
949static void vl_api_interface_name_renumber_reply_t_handler_json
950 (vl_api_interface_name_renumber_reply_t * mp)
951{
952 vat_main_t *vam = &vat_main;
953 vat_json_node_t node;
954
955 vat_json_init_object (&node);
956 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
957
958 vat_json_print (vam->ofp, &node);
959 vat_json_free (&node);
960
961 vam->retval = ntohl (mp->retval);
962 vam->result_ready = 1;
963}
964
965/*
966 * Special-case: build the interface table, maintain
967 * the next loopback sw_if_index vbl.
968 */
969static void vl_api_sw_interface_details_t_handler
970 (vl_api_sw_interface_details_t * mp)
971{
972 vat_main_t *vam = &vat_main;
973 u8 *s = format (0, "%s%c", mp->interface_name, 0);
974
975 hash_set_mem (vam->sw_if_index_by_interface_name, s,
976 ntohl (mp->sw_if_index));
977
978 /* In sub interface case, fill the sub interface table entry */
979 if (mp->sw_if_index != mp->sup_sw_if_index)
980 {
981 sw_interface_subif_t *sub = NULL;
982
983 vec_add2 (vam->sw_if_subif_table, sub, 1);
984
985 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
986 strncpy ((char *) sub->interface_name, (char *) s,
987 vec_len (sub->interface_name));
988 sub->sw_if_index = ntohl (mp->sw_if_index);
989 sub->sub_id = ntohl (mp->sub_id);
990
Ole Trøan3b0d7e42019-03-15 16:14:41 +0000991 sub->sub_dot1ad = mp->sub_dot1ad;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100992 sub->sub_number_of_tags = mp->sub_number_of_tags;
993 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
994 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
Ole Trøan3b0d7e42019-03-15 16:14:41 +0000995 sub->sub_exact_match = mp->sub_exact_match;
996 sub->sub_default = mp->sub_default;
997 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
998 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100999
1000 /* vlan tag rewrite */
1001 sub->vtr_op = ntohl (mp->vtr_op);
1002 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1003 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1004 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1005 }
1006}
1007
1008static void vl_api_sw_interface_details_t_handler_json
1009 (vl_api_sw_interface_details_t * mp)
1010{
1011 vat_main_t *vam = &vat_main;
1012 vat_json_node_t *node = NULL;
1013
1014 if (VAT_JSON_ARRAY != vam->json_tree.type)
1015 {
1016 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1017 vat_json_init_array (&vam->json_tree);
1018 }
1019 node = vat_json_array_add (&vam->json_tree);
1020
1021 vat_json_init_object (node);
1022 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1023 vat_json_object_add_uint (node, "sup_sw_if_index",
1024 ntohl (mp->sup_sw_if_index));
Ole Trøan3b0d7e42019-03-15 16:14:41 +00001025 vat_json_object_add_uint (node, "l2_address_length",
1026 ntohl (mp->l2_address_length));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001027 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1028 sizeof (mp->l2_address));
1029 vat_json_object_add_string_copy (node, "interface_name",
Ole Trøan3b0d7e42019-03-15 16:14:41 +00001030 mp->interface_name);
1031 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
1032 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001033 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1034 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001035 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001036 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
Ole Trøan3b0d7e42019-03-15 16:14:41 +00001037 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001038 vat_json_object_add_uint (node, "sub_number_of_tags",
1039 mp->sub_number_of_tags);
1040 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1041 ntohs (mp->sub_outer_vlan_id));
1042 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1043 ntohs (mp->sub_inner_vlan_id));
Ole Trøan3b0d7e42019-03-15 16:14:41 +00001044 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
1045 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
1046 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
1047 mp->sub_outer_vlan_id_any);
1048 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
1049 mp->sub_inner_vlan_id_any);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001050 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1051 vat_json_object_add_uint (node, "vtr_push_dot1q",
1052 ntohl (mp->vtr_push_dot1q));
1053 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1054 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Ole Trøan3b0d7e42019-03-15 16:14:41 +00001055 if (mp->sub_dot1ah)
Pavel Kotucek65e84572017-01-16 17:01:56 +01001056 {
1057 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1058 format (0, "%U",
1059 format_ethernet_address,
1060 &mp->b_dmac));
1061 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1062 format (0, "%U",
1063 format_ethernet_address,
1064 &mp->b_smac));
1065 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1066 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1067 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001068}
1069
Dave Baracha1a093d2017-03-02 13:13:23 -05001070#if VPP_API_TEST_BUILTIN == 0
Neale Rannsa07bd702017-08-07 07:53:49 -07001071static void vl_api_sw_interface_event_t_handler
1072 (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001073{
1074 vat_main_t *vam = &vat_main;
1075 if (vam->interface_event_display)
1076 errmsg ("interface flags: sw_if_index %d %s %s",
1077 ntohl (mp->sw_if_index),
Ole Trøan3b0d7e42019-03-15 16:14:41 +00001078 mp->admin_up_down ? "admin-up" : "admin-down",
1079 mp->link_up_down ? "link-up" : "link-down");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001080}
Dave Baracha1a093d2017-03-02 13:13:23 -05001081#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +01001082
Benoît Ganne49ee6842019-04-30 11:50:46 +02001083__clib_unused static void
1084vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001085{
1086 /* JSON output not supported */
1087}
1088
1089static void
1090vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1091{
1092 vat_main_t *vam = &vat_main;
1093 i32 retval = ntohl (mp->retval);
1094
1095 vam->retval = retval;
Damjan Marion7bee80c2017-04-26 15:32:12 +02001096 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001097 vam->result_ready = 1;
1098}
1099
1100static void
1101vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1102{
1103 vat_main_t *vam = &vat_main;
1104 vat_json_node_t node;
1105 api_main_t *am = &api_main;
1106 void *oldheap;
1107 u8 *reply;
1108
1109 vat_json_init_object (&node);
1110 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1111 vat_json_object_add_uint (&node, "reply_in_shmem",
1112 ntohl (mp->reply_in_shmem));
1113 /* Toss the shared-memory original... */
1114 pthread_mutex_lock (&am->vlib_rp->mutex);
1115 oldheap = svm_push_data_heap (am->vlib_rp);
1116
Damjan Marion7bee80c2017-04-26 15:32:12 +02001117 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001118 vec_free (reply);
1119
1120 svm_pop_heap (oldheap);
1121 pthread_mutex_unlock (&am->vlib_rp->mutex);
1122
1123 vat_json_print (vam->ofp, &node);
1124 vat_json_free (&node);
1125
1126 vam->retval = ntohl (mp->retval);
1127 vam->result_ready = 1;
1128}
1129
1130static void
1131vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1132{
1133 vat_main_t *vam = &vat_main;
1134 i32 retval = ntohl (mp->retval);
Ole Troan413f4a52018-11-28 11:36:05 +01001135 u32 length = vl_api_string_len (&mp->reply);
Dave Barach59b25652017-09-10 15:04:27 -04001136
1137 vec_reset_length (vam->cmd_reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001138
1139 vam->retval = retval;
Dave Barach59b25652017-09-10 15:04:27 -04001140 if (retval == 0)
1141 {
1142 vec_validate (vam->cmd_reply, length);
Ole Troan413f4a52018-11-28 11:36:05 +01001143 clib_memcpy ((char *) (vam->cmd_reply),
1144 vl_api_from_api_string (&mp->reply), length);
Dave Barach59b25652017-09-10 15:04:27 -04001145 vam->cmd_reply[length] = 0;
1146 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001147 vam->result_ready = 1;
1148}
1149
1150static void
1151vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1152{
1153 vat_main_t *vam = &vat_main;
1154 vat_json_node_t node;
1155
Dave Barach59b25652017-09-10 15:04:27 -04001156 vec_reset_length (vam->cmd_reply);
1157
Damjan Marion7cd468a2016-12-19 23:05:39 +01001158 vat_json_init_object (&node);
1159 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troan413f4a52018-11-28 11:36:05 +01001160 vat_json_object_add_string_copy (&node, "reply",
1161 vl_api_from_api_string (&mp->reply));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001162
1163 vat_json_print (vam->ofp, &node);
1164 vat_json_free (&node);
1165
1166 vam->retval = ntohl (mp->retval);
1167 vam->result_ready = 1;
1168}
1169
1170static void vl_api_classify_add_del_table_reply_t_handler
1171 (vl_api_classify_add_del_table_reply_t * mp)
1172{
1173 vat_main_t *vam = &vat_main;
1174 i32 retval = ntohl (mp->retval);
1175 if (vam->async_mode)
1176 {
1177 vam->async_errors += (retval < 0);
1178 }
1179 else
1180 {
1181 vam->retval = retval;
1182 if (retval == 0 &&
1183 ((mp->new_table_index != 0xFFFFFFFF) ||
1184 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1185 (mp->match_n_vectors != 0xFFFFFFFF)))
1186 /*
1187 * Note: this is just barely thread-safe, depends on
1188 * the main thread spinning waiting for an answer...
1189 */
1190 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1191 ntohl (mp->new_table_index),
1192 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1193 vam->result_ready = 1;
1194 }
1195}
1196
1197static void vl_api_classify_add_del_table_reply_t_handler_json
1198 (vl_api_classify_add_del_table_reply_t * mp)
1199{
1200 vat_main_t *vam = &vat_main;
1201 vat_json_node_t node;
1202
1203 vat_json_init_object (&node);
1204 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1205 vat_json_object_add_uint (&node, "new_table_index",
1206 ntohl (mp->new_table_index));
1207 vat_json_object_add_uint (&node, "skip_n_vectors",
1208 ntohl (mp->skip_n_vectors));
1209 vat_json_object_add_uint (&node, "match_n_vectors",
1210 ntohl (mp->match_n_vectors));
1211
1212 vat_json_print (vam->ofp, &node);
1213 vat_json_free (&node);
1214
1215 vam->retval = ntohl (mp->retval);
1216 vam->result_ready = 1;
1217}
1218
1219static void vl_api_get_node_index_reply_t_handler
1220 (vl_api_get_node_index_reply_t * mp)
1221{
1222 vat_main_t *vam = &vat_main;
1223 i32 retval = ntohl (mp->retval);
1224 if (vam->async_mode)
1225 {
1226 vam->async_errors += (retval < 0);
1227 }
1228 else
1229 {
1230 vam->retval = retval;
1231 if (retval == 0)
1232 errmsg ("node index %d", ntohl (mp->node_index));
1233 vam->result_ready = 1;
1234 }
1235}
1236
1237static void vl_api_get_node_index_reply_t_handler_json
1238 (vl_api_get_node_index_reply_t * mp)
1239{
1240 vat_main_t *vam = &vat_main;
1241 vat_json_node_t node;
1242
1243 vat_json_init_object (&node);
1244 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1245 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1246
1247 vat_json_print (vam->ofp, &node);
1248 vat_json_free (&node);
1249
1250 vam->retval = ntohl (mp->retval);
1251 vam->result_ready = 1;
1252}
1253
1254static void vl_api_get_next_index_reply_t_handler
1255 (vl_api_get_next_index_reply_t * mp)
1256{
1257 vat_main_t *vam = &vat_main;
1258 i32 retval = ntohl (mp->retval);
1259 if (vam->async_mode)
1260 {
1261 vam->async_errors += (retval < 0);
1262 }
1263 else
1264 {
1265 vam->retval = retval;
1266 if (retval == 0)
1267 errmsg ("next node index %d", ntohl (mp->next_index));
1268 vam->result_ready = 1;
1269 }
1270}
1271
1272static void vl_api_get_next_index_reply_t_handler_json
1273 (vl_api_get_next_index_reply_t * mp)
1274{
1275 vat_main_t *vam = &vat_main;
1276 vat_json_node_t node;
1277
1278 vat_json_init_object (&node);
1279 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1280 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1281
1282 vat_json_print (vam->ofp, &node);
1283 vat_json_free (&node);
1284
1285 vam->retval = ntohl (mp->retval);
1286 vam->result_ready = 1;
1287}
1288
1289static void vl_api_add_node_next_reply_t_handler
1290 (vl_api_add_node_next_reply_t * mp)
1291{
1292 vat_main_t *vam = &vat_main;
1293 i32 retval = ntohl (mp->retval);
1294 if (vam->async_mode)
1295 {
1296 vam->async_errors += (retval < 0);
1297 }
1298 else
1299 {
1300 vam->retval = retval;
1301 if (retval == 0)
1302 errmsg ("next index %d", ntohl (mp->next_index));
1303 vam->result_ready = 1;
1304 }
1305}
1306
1307static void vl_api_add_node_next_reply_t_handler_json
1308 (vl_api_add_node_next_reply_t * mp)
1309{
1310 vat_main_t *vam = &vat_main;
1311 vat_json_node_t node;
1312
1313 vat_json_init_object (&node);
1314 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1315 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1316
1317 vat_json_print (vam->ofp, &node);
1318 vat_json_free (&node);
1319
1320 vam->retval = ntohl (mp->retval);
1321 vam->result_ready = 1;
1322}
1323
1324static void vl_api_show_version_reply_t_handler
1325 (vl_api_show_version_reply_t * mp)
1326{
1327 vat_main_t *vam = &vat_main;
1328 i32 retval = ntohl (mp->retval);
1329
1330 if (retval >= 0)
1331 {
Ole Troan283cd2e2019-06-12 14:28:14 +02001332 u8 *s = 0;
Ole Troan413f4a52018-11-28 11:36:05 +01001333 char *p = (char *) &mp->program;
Ole Troand6e9aec2018-12-16 23:44:54 +01001334
Ole Troan283cd2e2019-06-12 14:28:14 +02001335 s = vl_api_from_api_to_vec ((vl_api_string_t *) p);
1336 errmsg (" program: %v\n", s);
1337 vec_free (s);
Ole Troand6e9aec2018-12-16 23:44:54 +01001338
1339 p +=
1340 vl_api_string_len ((vl_api_string_t *) p) + sizeof (vl_api_string_t);
Ole Troan283cd2e2019-06-12 14:28:14 +02001341 s = vl_api_from_api_to_vec ((vl_api_string_t *) p);
1342 errmsg (" version: %v\n", s);
1343 vec_free (s);
Ole Troand6e9aec2018-12-16 23:44:54 +01001344
1345 p +=
1346 vl_api_string_len ((vl_api_string_t *) p) + sizeof (vl_api_string_t);
Ole Troan283cd2e2019-06-12 14:28:14 +02001347 s = vl_api_from_api_to_vec ((vl_api_string_t *) p);
1348 errmsg (" build date: %v\n", s);
1349 vec_free (s);
Ole Troand6e9aec2018-12-16 23:44:54 +01001350
1351 p +=
1352 vl_api_string_len ((vl_api_string_t *) p) + sizeof (vl_api_string_t);
Ole Troan283cd2e2019-06-12 14:28:14 +02001353 s = vl_api_from_api_to_vec ((vl_api_string_t *) p);
Ole Troan283cd2e2019-06-12 14:28:14 +02001354 errmsg ("build directory: %v\n", s);
Ole Troanff55c812019-06-20 11:53:33 +02001355 vec_free (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001356 }
1357 vam->retval = retval;
1358 vam->result_ready = 1;
1359}
1360
1361static void vl_api_show_version_reply_t_handler_json
1362 (vl_api_show_version_reply_t * mp)
1363{
1364 vat_main_t *vam = &vat_main;
1365 vat_json_node_t node;
1366
1367 vat_json_init_object (&node);
1368 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troan413f4a52018-11-28 11:36:05 +01001369 char *p = (char *) &mp->program;
1370 vat_json_object_add_string_copy (&node, "program",
1371 vl_api_from_api_string ((vl_api_string_t *)
1372 p));
1373 p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32);
1374 vat_json_object_add_string_copy (&node, "version",
1375 vl_api_from_api_string ((vl_api_string_t *)
1376 p));
1377 p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32);
1378 vat_json_object_add_string_copy (&node, "build_date",
1379 vl_api_from_api_string ((vl_api_string_t *)
1380 p));
1381 p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001382 vat_json_object_add_string_copy (&node, "build_directory",
Ole Troan413f4a52018-11-28 11:36:05 +01001383 vl_api_from_api_string ((vl_api_string_t *)
1384 p));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001385
1386 vat_json_print (vam->ofp, &node);
1387 vat_json_free (&node);
1388
1389 vam->retval = ntohl (mp->retval);
1390 vam->result_ready = 1;
1391}
1392
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001393static void vl_api_show_threads_reply_t_handler
1394 (vl_api_show_threads_reply_t * mp)
1395{
1396 vat_main_t *vam = &vat_main;
1397 i32 retval = ntohl (mp->retval);
1398 int i, count = 0;
1399
1400 if (retval >= 0)
1401 count = ntohl (mp->count);
1402
1403 for (i = 0; i < count; i++)
1404 print (vam->ofp,
1405 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1406 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1407 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1408 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1409 ntohl (mp->thread_data[i].cpu_socket));
1410
1411 vam->retval = retval;
1412 vam->result_ready = 1;
1413}
1414
1415static void vl_api_show_threads_reply_t_handler_json
1416 (vl_api_show_threads_reply_t * mp)
1417{
1418 vat_main_t *vam = &vat_main;
1419 vat_json_node_t node;
1420 vl_api_thread_data_t *td;
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001421 i32 retval = ntohl (mp->retval);
1422 int i, count = 0;
1423
1424 if (retval >= 0)
1425 count = ntohl (mp->count);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001426
1427 vat_json_init_object (&node);
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001428 vat_json_object_add_int (&node, "retval", retval);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001429 vat_json_object_add_uint (&node, "count", count);
1430
1431 for (i = 0; i < count; i++)
1432 {
1433 td = &mp->thread_data[i];
1434 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1435 vat_json_object_add_string_copy (&node, "name", td->name);
1436 vat_json_object_add_string_copy (&node, "type", td->type);
1437 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1438 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1439 vat_json_object_add_int (&node, "core", ntohl (td->id));
1440 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1441 }
1442
1443 vat_json_print (vam->ofp, &node);
1444 vat_json_free (&node);
1445
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001446 vam->retval = retval;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001447 vam->result_ready = 1;
1448}
1449
1450static int
1451api_show_threads (vat_main_t * vam)
1452{
1453 vl_api_show_threads_t *mp;
1454 int ret;
1455
1456 print (vam->ofp,
1457 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1458 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1459
1460 M (SHOW_THREADS, mp);
1461
1462 S (mp);
1463 W (ret);
1464 return ret;
1465}
1466
Damjan Marion7cd468a2016-12-19 23:05:39 +01001467static void
1468vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
1469{
Wojciech Dec09a38a62017-03-07 19:30:39 +01001470 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo20e1f2a2017-03-29 13:35:43 -04001471 errmsg ("arp %s event: pid %d address %U new mac %U sw_if_index %d\n",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001472 mp->mac_ip ? "mac/ip binding" : "address resolution",
Neale Ranns37029302018-08-10 05:30:06 -07001473 ntohl (mp->pid), format_ip4_address, mp->ip,
1474 format_vl_api_mac_address, &mp->mac, sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001475}
1476
1477static void
1478vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
1479{
1480 /* JSON output not supported */
1481}
1482
1483static void
1484vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1485{
Wojciech Dec09a38a62017-03-07 19:30:39 +01001486 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo20e1f2a2017-03-29 13:35:43 -04001487 errmsg ("ip6 nd %s event: pid %d address %U new mac %U sw_if_index %d\n",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001488 mp->mac_ip ? "mac/ip binding" : "address resolution",
Neale Ranns37029302018-08-10 05:30:06 -07001489 ntohl (mp->pid), format_vl_api_ip6_address, mp->ip,
1490 format_vl_api_mac_address, mp->mac, sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001491}
1492
1493static void
1494vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1495{
1496 /* JSON output not supported */
1497}
1498
John Lo8d00fff2017-08-03 00:35:36 -04001499static void
1500vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1501{
1502 u32 n_macs = ntohl (mp->n_macs);
Paul Vinciguerraec11b132018-09-24 05:25:00 -07001503 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
John Lo8d00fff2017-08-03 00:35:36 -04001504 ntohl (mp->pid), mp->client_index, n_macs);
1505 int i;
1506 for (i = 0; i < n_macs; i++)
1507 {
1508 vl_api_mac_entry_t *mac = &mp->mac[i];
John Loe23c99e2018-03-13 21:53:18 -04001509 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
John Lo8d00fff2017-08-03 00:35:36 -04001510 i + 1, ntohl (mac->sw_if_index),
John Loe23c99e2018-03-13 21:53:18 -04001511 format_ethernet_address, mac->mac_addr, mac->action);
John Lo8d00fff2017-08-03 00:35:36 -04001512 if (i == 1000)
1513 break;
1514 }
1515}
1516
1517static void
1518vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1519{
1520 /* JSON output not supported */
1521}
1522
Ole Troan01384fe2017-05-12 11:55:35 +02001523#define vl_api_bridge_domain_details_t_endian vl_noop_handler
1524#define vl_api_bridge_domain_details_t_print vl_noop_handler
1525
Damjan Marion7cd468a2016-12-19 23:05:39 +01001526/*
1527 * Special-case: build the bridge domain table, maintain
1528 * the next bd id vbl.
1529 */
1530static void vl_api_bridge_domain_details_t_handler
1531 (vl_api_bridge_domain_details_t * mp)
1532{
1533 vat_main_t *vam = &vat_main;
1534 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ole Troan01384fe2017-05-12 11:55:35 +02001535 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001536
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001537 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1538 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001539
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001540 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001541 ntohl (mp->bd_id), mp->learn, mp->forward,
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001542 mp->flood, ntohl (mp->bvi_sw_if_index),
1543 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001544
1545 if (n_sw_ifs)
Ole Troan01384fe2017-05-12 11:55:35 +02001546 {
1547 vl_api_bridge_domain_sw_if_t *sw_ifs;
1548 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1549 "Interface Name");
1550
1551 sw_ifs = mp->sw_if_details;
1552 for (i = 0; i < n_sw_ifs; i++)
1553 {
1554 u8 *sw_if_name = 0;
1555 u32 sw_if_index;
1556 hash_pair_t *p;
1557
1558 sw_if_index = ntohl (sw_ifs->sw_if_index);
1559
1560 /* *INDENT-OFF* */
1561 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1562 ({
1563 if ((u32) p->value[0] == sw_if_index)
1564 {
1565 sw_if_name = (u8 *)(p->key);
1566 break;
1567 }
1568 }));
1569 /* *INDENT-ON* */
1570 print (vam->ofp, "%7d %3d %s", sw_if_index,
1571 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1572 "sw_if_index not found!");
1573
1574 sw_ifs++;
1575 }
1576 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001577}
1578
1579static void vl_api_bridge_domain_details_t_handler_json
1580 (vl_api_bridge_domain_details_t * mp)
1581{
1582 vat_main_t *vam = &vat_main;
1583 vat_json_node_t *node, *array = NULL;
Ole Troan01384fe2017-05-12 11:55:35 +02001584 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001585
1586 if (VAT_JSON_ARRAY != vam->json_tree.type)
1587 {
1588 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1589 vat_json_init_array (&vam->json_tree);
1590 }
1591 node = vat_json_array_add (&vam->json_tree);
1592
1593 vat_json_init_object (node);
1594 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1595 vat_json_object_add_uint (node, "flood", mp->flood);
1596 vat_json_object_add_uint (node, "forward", mp->forward);
1597 vat_json_object_add_uint (node, "learn", mp->learn);
1598 vat_json_object_add_uint (node, "bvi_sw_if_index",
1599 ntohl (mp->bvi_sw_if_index));
Ole Troan01384fe2017-05-12 11:55:35 +02001600 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001601 array = vat_json_object_add (node, "sw_if");
1602 vat_json_init_array (array);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001603
Damjan Marion7cd468a2016-12-19 23:05:39 +01001604
Damjan Marion7cd468a2016-12-19 23:05:39 +01001605
Ole Troan01384fe2017-05-12 11:55:35 +02001606 if (n_sw_ifs)
1607 {
1608 vl_api_bridge_domain_sw_if_t *sw_ifs;
1609 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001610
Ole Troan01384fe2017-05-12 11:55:35 +02001611 sw_ifs = mp->sw_if_details;
1612 for (i = 0; i < n_sw_ifs; i++)
1613 {
1614 node = vat_json_array_add (array);
1615 vat_json_init_object (node);
1616 vat_json_object_add_uint (node, "sw_if_index",
1617 ntohl (sw_ifs->sw_if_index));
1618 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1619 sw_ifs++;
1620 }
1621 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001622}
1623
1624static void vl_api_control_ping_reply_t_handler
1625 (vl_api_control_ping_reply_t * mp)
1626{
1627 vat_main_t *vam = &vat_main;
1628 i32 retval = ntohl (mp->retval);
1629 if (vam->async_mode)
1630 {
1631 vam->async_errors += (retval < 0);
1632 }
1633 else
1634 {
1635 vam->retval = retval;
1636 vam->result_ready = 1;
1637 }
Florin Coras90a63982017-12-19 04:50:01 -08001638 if (vam->socket_client_main)
1639 vam->socket_client_main->control_pings_outstanding--;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001640}
1641
1642static void vl_api_control_ping_reply_t_handler_json
1643 (vl_api_control_ping_reply_t * mp)
1644{
1645 vat_main_t *vam = &vat_main;
1646 i32 retval = ntohl (mp->retval);
1647
1648 if (VAT_JSON_NONE != vam->json_tree.type)
1649 {
1650 vat_json_print (vam->ofp, &vam->json_tree);
1651 vat_json_free (&vam->json_tree);
1652 vam->json_tree.type = VAT_JSON_NONE;
1653 }
1654 else
1655 {
1656 /* just print [] */
1657 vat_json_init_array (&vam->json_tree);
1658 vat_json_print (vam->ofp, &vam->json_tree);
1659 vam->json_tree.type = VAT_JSON_NONE;
1660 }
1661
1662 vam->retval = retval;
1663 vam->result_ready = 1;
1664}
1665
1666static void
Eyal Barifead6702017-04-04 04:46:32 +03001667 vl_api_bridge_domain_set_mac_age_reply_t_handler
1668 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1669{
1670 vat_main_t *vam = &vat_main;
1671 i32 retval = ntohl (mp->retval);
1672 if (vam->async_mode)
1673 {
1674 vam->async_errors += (retval < 0);
1675 }
1676 else
1677 {
1678 vam->retval = retval;
1679 vam->result_ready = 1;
1680 }
1681}
1682
1683static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1684 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1685{
1686 vat_main_t *vam = &vat_main;
1687 vat_json_node_t node;
1688
1689 vat_json_init_object (&node);
1690 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1691
1692 vat_json_print (vam->ofp, &node);
1693 vat_json_free (&node);
1694
1695 vam->retval = ntohl (mp->retval);
1696 vam->result_ready = 1;
1697}
1698
1699static void
Damjan Marion7cd468a2016-12-19 23:05:39 +01001700vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1701{
1702 vat_main_t *vam = &vat_main;
1703 i32 retval = ntohl (mp->retval);
1704 if (vam->async_mode)
1705 {
1706 vam->async_errors += (retval < 0);
1707 }
1708 else
1709 {
1710 vam->retval = retval;
1711 vam->result_ready = 1;
1712 }
1713}
1714
1715static void vl_api_l2_flags_reply_t_handler_json
1716 (vl_api_l2_flags_reply_t * mp)
1717{
1718 vat_main_t *vam = &vat_main;
1719 vat_json_node_t node;
1720
1721 vat_json_init_object (&node);
1722 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1723 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1724 ntohl (mp->resulting_feature_bitmap));
1725
1726 vat_json_print (vam->ofp, &node);
1727 vat_json_free (&node);
1728
1729 vam->retval = ntohl (mp->retval);
1730 vam->result_ready = 1;
1731}
1732
1733static void vl_api_bridge_flags_reply_t_handler
1734 (vl_api_bridge_flags_reply_t * mp)
1735{
1736 vat_main_t *vam = &vat_main;
1737 i32 retval = ntohl (mp->retval);
1738 if (vam->async_mode)
1739 {
1740 vam->async_errors += (retval < 0);
1741 }
1742 else
1743 {
1744 vam->retval = retval;
1745 vam->result_ready = 1;
1746 }
1747}
1748
1749static void vl_api_bridge_flags_reply_t_handler_json
1750 (vl_api_bridge_flags_reply_t * mp)
1751{
1752 vat_main_t *vam = &vat_main;
1753 vat_json_node_t node;
1754
1755 vat_json_init_object (&node);
1756 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1757 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1758 ntohl (mp->resulting_feature_bitmap));
1759
1760 vat_json_print (vam->ofp, &node);
1761 vat_json_free (&node);
1762
1763 vam->retval = ntohl (mp->retval);
1764 vam->result_ready = 1;
1765}
1766
Damjan Marion8389fb92017-10-13 18:29:53 +02001767static void
1768vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1769{
1770 vat_main_t *vam = &vat_main;
1771 i32 retval = ntohl (mp->retval);
1772 if (vam->async_mode)
1773 {
1774 vam->async_errors += (retval < 0);
1775 }
1776 else
1777 {
1778 vam->retval = retval;
1779 vam->sw_if_index = ntohl (mp->sw_if_index);
1780 vam->result_ready = 1;
1781 }
1782
1783}
1784
1785static void vl_api_tap_create_v2_reply_t_handler_json
1786 (vl_api_tap_create_v2_reply_t * mp)
1787{
1788 vat_main_t *vam = &vat_main;
1789 vat_json_node_t node;
1790
1791 vat_json_init_object (&node);
1792 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1793 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1794
1795 vat_json_print (vam->ofp, &node);
1796 vat_json_free (&node);
1797
1798 vam->retval = ntohl (mp->retval);
1799 vam->result_ready = 1;
1800
1801}
1802
1803static void
1804vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1805{
1806 vat_main_t *vam = &vat_main;
1807 i32 retval = ntohl (mp->retval);
1808 if (vam->async_mode)
1809 {
1810 vam->async_errors += (retval < 0);
1811 }
1812 else
1813 {
1814 vam->retval = retval;
1815 vam->result_ready = 1;
1816 }
1817}
1818
1819static void vl_api_tap_delete_v2_reply_t_handler_json
1820 (vl_api_tap_delete_v2_reply_t * mp)
1821{
1822 vat_main_t *vam = &vat_main;
1823 vat_json_node_t node;
1824
1825 vat_json_init_object (&node);
1826 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1827
1828 vat_json_print (vam->ofp, &node);
1829 vat_json_free (&node);
1830
1831 vam->retval = ntohl (mp->retval);
1832 vam->result_ready = 1;
1833}
1834
Steven9cd2d7a2017-12-20 12:43:01 -08001835static void
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01001836vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1837 mp)
1838{
1839 vat_main_t *vam = &vat_main;
1840 i32 retval = ntohl (mp->retval);
1841 if (vam->async_mode)
1842 {
1843 vam->async_errors += (retval < 0);
1844 }
1845 else
1846 {
1847 vam->retval = retval;
1848 vam->sw_if_index = ntohl (mp->sw_if_index);
1849 vam->result_ready = 1;
1850 }
1851}
1852
1853static void vl_api_virtio_pci_create_reply_t_handler_json
1854 (vl_api_virtio_pci_create_reply_t * mp)
1855{
1856 vat_main_t *vam = &vat_main;
1857 vat_json_node_t node;
1858
1859 vat_json_init_object (&node);
1860 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1861 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1862
1863 vat_json_print (vam->ofp, &node);
1864 vat_json_free (&node);
1865
1866 vam->retval = ntohl (mp->retval);
1867 vam->result_ready = 1;
1868
1869}
1870
1871static void
1872vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1873 mp)
1874{
1875 vat_main_t *vam = &vat_main;
1876 i32 retval = ntohl (mp->retval);
1877 if (vam->async_mode)
1878 {
1879 vam->async_errors += (retval < 0);
1880 }
1881 else
1882 {
1883 vam->retval = retval;
1884 vam->result_ready = 1;
1885 }
1886}
1887
1888static void vl_api_virtio_pci_delete_reply_t_handler_json
1889 (vl_api_virtio_pci_delete_reply_t * mp)
1890{
1891 vat_main_t *vam = &vat_main;
1892 vat_json_node_t node;
1893
1894 vat_json_init_object (&node);
1895 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1896
1897 vat_json_print (vam->ofp, &node);
1898 vat_json_free (&node);
1899
1900 vam->retval = ntohl (mp->retval);
1901 vam->result_ready = 1;
1902}
1903
1904static void
Steven9cd2d7a2017-12-20 12:43:01 -08001905vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1906{
1907 vat_main_t *vam = &vat_main;
1908 i32 retval = ntohl (mp->retval);
1909
1910 if (vam->async_mode)
1911 {
1912 vam->async_errors += (retval < 0);
1913 }
1914 else
1915 {
1916 vam->retval = retval;
1917 vam->sw_if_index = ntohl (mp->sw_if_index);
1918 vam->result_ready = 1;
1919 }
1920}
1921
1922static void vl_api_bond_create_reply_t_handler_json
1923 (vl_api_bond_create_reply_t * mp)
1924{
1925 vat_main_t *vam = &vat_main;
1926 vat_json_node_t node;
1927
1928 vat_json_init_object (&node);
1929 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1930 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1931
1932 vat_json_print (vam->ofp, &node);
1933 vat_json_free (&node);
1934
1935 vam->retval = ntohl (mp->retval);
1936 vam->result_ready = 1;
1937}
1938
1939static void
1940vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1941{
1942 vat_main_t *vam = &vat_main;
1943 i32 retval = ntohl (mp->retval);
1944
1945 if (vam->async_mode)
1946 {
1947 vam->async_errors += (retval < 0);
1948 }
1949 else
1950 {
1951 vam->retval = retval;
1952 vam->result_ready = 1;
1953 }
1954}
1955
1956static void vl_api_bond_delete_reply_t_handler_json
1957 (vl_api_bond_delete_reply_t * mp)
1958{
1959 vat_main_t *vam = &vat_main;
1960 vat_json_node_t node;
1961
1962 vat_json_init_object (&node);
1963 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1964
1965 vat_json_print (vam->ofp, &node);
1966 vat_json_free (&node);
1967
1968 vam->retval = ntohl (mp->retval);
1969 vam->result_ready = 1;
1970}
1971
1972static void
1973vl_api_bond_enslave_reply_t_handler (vl_api_bond_enslave_reply_t * mp)
1974{
1975 vat_main_t *vam = &vat_main;
1976 i32 retval = ntohl (mp->retval);
1977
1978 if (vam->async_mode)
1979 {
1980 vam->async_errors += (retval < 0);
1981 }
1982 else
1983 {
1984 vam->retval = retval;
1985 vam->result_ready = 1;
1986 }
1987}
1988
1989static void vl_api_bond_enslave_reply_t_handler_json
1990 (vl_api_bond_enslave_reply_t * mp)
1991{
1992 vat_main_t *vam = &vat_main;
1993 vat_json_node_t node;
1994
1995 vat_json_init_object (&node);
1996 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1997
1998 vat_json_print (vam->ofp, &node);
1999 vat_json_free (&node);
2000
2001 vam->retval = ntohl (mp->retval);
2002 vam->result_ready = 1;
2003}
2004
2005static void
2006vl_api_bond_detach_slave_reply_t_handler (vl_api_bond_detach_slave_reply_t *
2007 mp)
2008{
2009 vat_main_t *vam = &vat_main;
2010 i32 retval = ntohl (mp->retval);
2011
2012 if (vam->async_mode)
2013 {
2014 vam->async_errors += (retval < 0);
2015 }
2016 else
2017 {
2018 vam->retval = retval;
2019 vam->result_ready = 1;
2020 }
2021}
2022
2023static void vl_api_bond_detach_slave_reply_t_handler_json
2024 (vl_api_bond_detach_slave_reply_t * mp)
2025{
2026 vat_main_t *vam = &vat_main;
2027 vat_json_node_t node;
2028
2029 vat_json_init_object (&node);
2030 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2031
2032 vat_json_print (vam->ofp, &node);
2033 vat_json_free (&node);
2034
2035 vam->retval = ntohl (mp->retval);
2036 vam->result_ready = 1;
2037}
2038
2039static void vl_api_sw_interface_bond_details_t_handler
2040 (vl_api_sw_interface_bond_details_t * mp)
2041{
2042 vat_main_t *vam = &vat_main;
2043
2044 print (vam->ofp,
2045 "%-16s %-12d %-12U %-13U %-14u %-14u",
2046 mp->interface_name, ntohl (mp->sw_if_index),
2047 format_bond_mode, mp->mode, format_bond_load_balance, mp->lb,
2048 ntohl (mp->active_slaves), ntohl (mp->slaves));
2049}
2050
2051static void vl_api_sw_interface_bond_details_t_handler_json
2052 (vl_api_sw_interface_bond_details_t * mp)
2053{
2054 vat_main_t *vam = &vat_main;
2055 vat_json_node_t *node = NULL;
2056
2057 if (VAT_JSON_ARRAY != vam->json_tree.type)
2058 {
2059 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2060 vat_json_init_array (&vam->json_tree);
2061 }
2062 node = vat_json_array_add (&vam->json_tree);
2063
2064 vat_json_init_object (node);
2065 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2066 vat_json_object_add_string_copy (node, "interface_name",
2067 mp->interface_name);
2068 vat_json_object_add_uint (node, "mode", mp->mode);
2069 vat_json_object_add_uint (node, "load_balance", mp->lb);
2070 vat_json_object_add_uint (node, "active_slaves", ntohl (mp->active_slaves));
2071 vat_json_object_add_uint (node, "slaves", ntohl (mp->slaves));
2072}
2073
2074static int
2075api_sw_interface_bond_dump (vat_main_t * vam)
2076{
2077 vl_api_sw_interface_bond_dump_t *mp;
2078 vl_api_control_ping_t *mp_ping;
2079 int ret;
2080
2081 print (vam->ofp,
2082 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2083 "interface name", "sw_if_index", "mode", "load balance",
2084 "active slaves", "slaves");
2085
2086 /* Get list of bond interfaces */
2087 M (SW_INTERFACE_BOND_DUMP, mp);
2088 S (mp);
2089
2090 /* Use a control ping for synchronization */
2091 MPING (CONTROL_PING, mp_ping);
2092 S (mp_ping);
2093
2094 W (ret);
2095 return ret;
2096}
2097
2098static void vl_api_sw_interface_slave_details_t_handler
2099 (vl_api_sw_interface_slave_details_t * mp)
2100{
2101 vat_main_t *vam = &vat_main;
2102
2103 print (vam->ofp,
2104 "%-25s %-12d %-12d %d", mp->interface_name,
2105 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout);
2106}
2107
2108static void vl_api_sw_interface_slave_details_t_handler_json
2109 (vl_api_sw_interface_slave_details_t * mp)
2110{
2111 vat_main_t *vam = &vat_main;
2112 vat_json_node_t *node = NULL;
2113
2114 if (VAT_JSON_ARRAY != vam->json_tree.type)
2115 {
2116 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2117 vat_json_init_array (&vam->json_tree);
2118 }
2119 node = vat_json_array_add (&vam->json_tree);
2120
2121 vat_json_init_object (node);
2122 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2123 vat_json_object_add_string_copy (node, "interface_name",
2124 mp->interface_name);
2125 vat_json_object_add_uint (node, "passive", mp->is_passive);
2126 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2127}
2128
2129static int
2130api_sw_interface_slave_dump (vat_main_t * vam)
2131{
2132 unformat_input_t *i = vam->input;
2133 vl_api_sw_interface_slave_dump_t *mp;
2134 vl_api_control_ping_t *mp_ping;
2135 u32 sw_if_index = ~0;
2136 u8 sw_if_index_set = 0;
2137 int ret;
2138
2139 /* Parse args required to build the message */
2140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2141 {
2142 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2143 sw_if_index_set = 1;
2144 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2145 sw_if_index_set = 1;
2146 else
2147 break;
2148 }
2149
2150 if (sw_if_index_set == 0)
2151 {
2152 errmsg ("missing vpp interface name. ");
2153 return -99;
2154 }
2155
2156 print (vam->ofp,
2157 "\n%-25s %-12s %-12s %s",
2158 "slave interface name", "sw_if_index", "passive", "long_timeout");
2159
2160 /* Get list of bond interfaces */
2161 M (SW_INTERFACE_SLAVE_DUMP, mp);
2162 mp->sw_if_index = ntohl (sw_if_index);
2163 S (mp);
2164
2165 /* Use a control ping for synchronization */
2166 MPING (CONTROL_PING, mp_ping);
2167 S (mp_ping);
2168
2169 W (ret);
2170 return ret;
2171}
2172
Damjan Marion7cd468a2016-12-19 23:05:39 +01002173static void vl_api_mpls_tunnel_add_del_reply_t_handler
2174 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2175{
2176 vat_main_t *vam = &vat_main;
2177 i32 retval = ntohl (mp->retval);
2178 if (vam->async_mode)
2179 {
2180 vam->async_errors += (retval < 0);
2181 }
2182 else
2183 {
2184 vam->retval = retval;
John Lo06fda9c2018-10-03 16:32:44 -04002185 vam->sw_if_index = ntohl (mp->sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002186 vam->result_ready = 1;
2187 }
John Lo06fda9c2018-10-03 16:32:44 -04002188 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002189}
2190
2191static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2192 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2193{
2194 vat_main_t *vam = &vat_main;
2195 vat_json_node_t node;
2196
2197 vat_json_init_object (&node);
2198 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2199 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2200 ntohl (mp->sw_if_index));
2201
2202 vat_json_print (vam->ofp, &node);
2203 vat_json_free (&node);
2204
2205 vam->retval = ntohl (mp->retval);
2206 vam->result_ready = 1;
2207}
2208
2209static void vl_api_l2tpv3_create_tunnel_reply_t_handler
2210 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2211{
2212 vat_main_t *vam = &vat_main;
2213 i32 retval = ntohl (mp->retval);
2214 if (vam->async_mode)
2215 {
2216 vam->async_errors += (retval < 0);
2217 }
2218 else
2219 {
2220 vam->retval = retval;
2221 vam->sw_if_index = ntohl (mp->sw_if_index);
2222 vam->result_ready = 1;
2223 }
2224}
2225
2226static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
2227 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2228{
2229 vat_main_t *vam = &vat_main;
2230 vat_json_node_t node;
2231
2232 vat_json_init_object (&node);
2233 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2234 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2235
2236 vat_json_print (vam->ofp, &node);
2237 vat_json_free (&node);
2238
2239 vam->retval = ntohl (mp->retval);
2240 vam->result_ready = 1;
2241}
2242
Filip Tehlar560274d2017-06-05 13:40:13 +02002243static void vl_api_gpe_add_del_fwd_entry_reply_t_handler
2244 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2245{
2246 vat_main_t *vam = &vat_main;
2247 i32 retval = ntohl (mp->retval);
2248 if (vam->async_mode)
2249 {
2250 vam->async_errors += (retval < 0);
2251 }
2252 else
2253 {
2254 vam->retval = retval;
2255 vam->result_ready = 1;
2256 }
2257}
2258
2259static void vl_api_gpe_add_del_fwd_entry_reply_t_handler_json
2260 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2261{
2262 vat_main_t *vam = &vat_main;
2263 vat_json_node_t node;
2264
2265 vat_json_init_object (&node);
2266 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2267 vat_json_object_add_uint (&node, "fwd_entry_index",
2268 clib_net_to_host_u32 (mp->fwd_entry_index));
2269
2270 vat_json_print (vam->ofp, &node);
2271 vat_json_free (&node);
2272
2273 vam->retval = ntohl (mp->retval);
2274 vam->result_ready = 1;
2275}
Damjan Marion7cd468a2016-12-19 23:05:39 +01002276
Filip Tehlara4980b82017-09-27 14:32:02 +02002277u8 *
2278format_lisp_transport_protocol (u8 * s, va_list * args)
2279{
2280 u32 proto = va_arg (*args, u32);
2281
2282 switch (proto)
2283 {
2284 case 1:
2285 return format (s, "udp");
2286 case 2:
2287 return format (s, "api");
2288 default:
2289 return 0;
2290 }
2291 return 0;
2292}
2293
2294static void vl_api_one_get_transport_protocol_reply_t_handler
2295 (vl_api_one_get_transport_protocol_reply_t * mp)
2296{
2297 vat_main_t *vam = &vat_main;
2298 i32 retval = ntohl (mp->retval);
2299 if (vam->async_mode)
2300 {
2301 vam->async_errors += (retval < 0);
2302 }
2303 else
2304 {
2305 u32 proto = mp->protocol;
2306 print (vam->ofp, "Transport protocol: %U",
2307 format_lisp_transport_protocol, proto);
2308 vam->retval = retval;
2309 vam->result_ready = 1;
2310 }
2311}
2312
2313static void vl_api_one_get_transport_protocol_reply_t_handler_json
2314 (vl_api_one_get_transport_protocol_reply_t * mp)
2315{
2316 vat_main_t *vam = &vat_main;
2317 vat_json_node_t node;
2318 u8 *s;
2319
2320 s = format (0, "%U", format_lisp_transport_protocol, mp->protocol);
2321 vec_add1 (s, 0);
2322
2323 vat_json_init_object (&node);
2324 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2325 vat_json_object_add_string_copy (&node, "transport-protocol", s);
2326
2327 vec_free (s);
2328 vat_json_print (vam->ofp, &node);
2329 vat_json_free (&node);
2330
2331 vam->retval = ntohl (mp->retval);
2332 vam->result_ready = 1;
2333}
2334
Filip Tehlar694396d2017-02-17 14:29:11 +01002335static void vl_api_one_add_del_locator_set_reply_t_handler
2336 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002337{
2338 vat_main_t *vam = &vat_main;
2339 i32 retval = ntohl (mp->retval);
2340 if (vam->async_mode)
2341 {
2342 vam->async_errors += (retval < 0);
2343 }
2344 else
2345 {
2346 vam->retval = retval;
2347 vam->result_ready = 1;
2348 }
2349}
2350
Filip Tehlar694396d2017-02-17 14:29:11 +01002351static void vl_api_one_add_del_locator_set_reply_t_handler_json
2352 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002353{
2354 vat_main_t *vam = &vat_main;
2355 vat_json_node_t node;
2356
2357 vat_json_init_object (&node);
2358 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2359 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
2360
2361 vat_json_print (vam->ofp, &node);
2362 vat_json_free (&node);
2363
2364 vam->retval = ntohl (mp->retval);
2365 vam->result_ready = 1;
2366}
2367
2368static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2369 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2370{
2371 vat_main_t *vam = &vat_main;
2372 i32 retval = ntohl (mp->retval);
2373 if (vam->async_mode)
2374 {
2375 vam->async_errors += (retval < 0);
2376 }
2377 else
2378 {
2379 vam->retval = retval;
2380 vam->sw_if_index = ntohl (mp->sw_if_index);
2381 vam->result_ready = 1;
2382 }
Dave Barachf72212e2018-01-11 10:25:07 -05002383 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002384}
2385
2386static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2387 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2388{
2389 vat_main_t *vam = &vat_main;
2390 vat_json_node_t node;
2391
2392 vat_json_init_object (&node);
2393 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2394 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2395
2396 vat_json_print (vam->ofp, &node);
2397 vat_json_free (&node);
2398
2399 vam->retval = ntohl (mp->retval);
2400 vam->result_ready = 1;
2401}
2402
eyal bariaf86a482018-04-17 11:20:27 +03002403static void vl_api_vxlan_offload_rx_reply_t_handler
2404 (vl_api_vxlan_offload_rx_reply_t * mp)
2405{
2406 vat_main_t *vam = &vat_main;
2407 i32 retval = ntohl (mp->retval);
2408 if (vam->async_mode)
2409 {
2410 vam->async_errors += (retval < 0);
2411 }
2412 else
2413 {
2414 vam->retval = retval;
2415 vam->result_ready = 1;
2416 }
2417}
2418
2419static void vl_api_vxlan_offload_rx_reply_t_handler_json
2420 (vl_api_vxlan_offload_rx_reply_t * mp)
2421{
2422 vat_main_t *vam = &vat_main;
2423 vat_json_node_t node;
2424
2425 vat_json_init_object (&node);
2426 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2427
2428 vat_json_print (vam->ofp, &node);
2429 vat_json_free (&node);
2430
2431 vam->retval = ntohl (mp->retval);
2432 vam->result_ready = 1;
2433}
2434
Marco Varleseb598f1d2017-09-19 14:25:28 +02002435static void vl_api_geneve_add_del_tunnel_reply_t_handler
2436 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2437{
2438 vat_main_t *vam = &vat_main;
2439 i32 retval = ntohl (mp->retval);
2440 if (vam->async_mode)
2441 {
2442 vam->async_errors += (retval < 0);
2443 }
2444 else
2445 {
2446 vam->retval = retval;
2447 vam->sw_if_index = ntohl (mp->sw_if_index);
2448 vam->result_ready = 1;
2449 }
2450}
2451
2452static void vl_api_geneve_add_del_tunnel_reply_t_handler_json
2453 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2454{
2455 vat_main_t *vam = &vat_main;
2456 vat_json_node_t node;
2457
2458 vat_json_init_object (&node);
2459 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2460 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2461
2462 vat_json_print (vam->ofp, &node);
2463 vat_json_free (&node);
2464
2465 vam->retval = ntohl (mp->retval);
2466 vam->result_ready = 1;
2467}
2468
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002469static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2470 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2471{
2472 vat_main_t *vam = &vat_main;
2473 i32 retval = ntohl (mp->retval);
2474 if (vam->async_mode)
2475 {
2476 vam->async_errors += (retval < 0);
2477 }
2478 else
2479 {
2480 vam->retval = retval;
2481 vam->sw_if_index = ntohl (mp->sw_if_index);
2482 vam->result_ready = 1;
2483 }
Dave Barachf72212e2018-01-11 10:25:07 -05002484 vam->regenerate_interface_table = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002485}
2486
2487static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2488 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2489{
2490 vat_main_t *vam = &vat_main;
2491 vat_json_node_t node;
2492
2493 vat_json_init_object (&node);
2494 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2495 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2496
2497 vat_json_print (vam->ofp, &node);
2498 vat_json_free (&node);
2499
2500 vam->retval = ntohl (mp->retval);
2501 vam->result_ready = 1;
2502}
2503
Neale Ranns5a8844b2019-04-16 07:15:35 +00002504static void vl_api_gre_tunnel_add_del_reply_t_handler
2505 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002506{
2507 vat_main_t *vam = &vat_main;
2508 i32 retval = ntohl (mp->retval);
2509 if (vam->async_mode)
2510 {
2511 vam->async_errors += (retval < 0);
2512 }
2513 else
2514 {
2515 vam->retval = retval;
2516 vam->sw_if_index = ntohl (mp->sw_if_index);
2517 vam->result_ready = 1;
2518 }
2519}
2520
Neale Ranns5a8844b2019-04-16 07:15:35 +00002521static void vl_api_gre_tunnel_add_del_reply_t_handler_json
2522 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002523{
2524 vat_main_t *vam = &vat_main;
2525 vat_json_node_t node;
2526
2527 vat_json_init_object (&node);
2528 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2529 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2530
2531 vat_json_print (vam->ofp, &node);
2532 vat_json_free (&node);
2533
2534 vam->retval = ntohl (mp->retval);
2535 vam->result_ready = 1;
2536}
2537
2538static void vl_api_create_vhost_user_if_reply_t_handler
2539 (vl_api_create_vhost_user_if_reply_t * mp)
2540{
2541 vat_main_t *vam = &vat_main;
2542 i32 retval = ntohl (mp->retval);
2543 if (vam->async_mode)
2544 {
2545 vam->async_errors += (retval < 0);
2546 }
2547 else
2548 {
2549 vam->retval = retval;
2550 vam->sw_if_index = ntohl (mp->sw_if_index);
2551 vam->result_ready = 1;
2552 }
Dave Barachf72212e2018-01-11 10:25:07 -05002553 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002554}
2555
2556static void vl_api_create_vhost_user_if_reply_t_handler_json
2557 (vl_api_create_vhost_user_if_reply_t * mp)
2558{
2559 vat_main_t *vam = &vat_main;
2560 vat_json_node_t node;
2561
2562 vat_json_init_object (&node);
2563 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2564 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2565
2566 vat_json_print (vam->ofp, &node);
2567 vat_json_free (&node);
2568
2569 vam->retval = ntohl (mp->retval);
2570 vam->result_ready = 1;
2571}
2572
Dave Barach65457162017-10-10 17:53:14 -04002573static void vl_api_dns_resolve_name_reply_t_handler
2574 (vl_api_dns_resolve_name_reply_t * mp)
2575{
2576 vat_main_t *vam = &vat_main;
2577 i32 retval = ntohl (mp->retval);
2578 if (vam->async_mode)
2579 {
2580 vam->async_errors += (retval < 0);
2581 }
2582 else
2583 {
2584 vam->retval = retval;
2585 vam->result_ready = 1;
2586
2587 if (retval == 0)
2588 {
2589 if (mp->ip4_set)
2590 clib_warning ("ip4 address %U", format_ip4_address,
2591 (ip4_address_t *) mp->ip4_address);
2592 if (mp->ip6_set)
2593 clib_warning ("ip6 address %U", format_ip6_address,
2594 (ip6_address_t *) mp->ip6_address);
2595 }
2596 else
2597 clib_warning ("retval %d", retval);
2598 }
2599}
2600
2601static void vl_api_dns_resolve_name_reply_t_handler_json
2602 (vl_api_dns_resolve_name_reply_t * mp)
2603{
Dave Barachd2080152017-10-20 09:21:35 -04002604 clib_warning ("not implemented");
Dave Barach65457162017-10-10 17:53:14 -04002605}
Dave Barach59b25652017-09-10 15:04:27 -04002606
Dave Barachd2080152017-10-20 09:21:35 -04002607static void vl_api_dns_resolve_ip_reply_t_handler
2608 (vl_api_dns_resolve_ip_reply_t * mp)
2609{
2610 vat_main_t *vam = &vat_main;
2611 i32 retval = ntohl (mp->retval);
2612 if (vam->async_mode)
2613 {
2614 vam->async_errors += (retval < 0);
2615 }
2616 else
2617 {
2618 vam->retval = retval;
2619 vam->result_ready = 1;
2620
2621 if (retval == 0)
2622 {
2623 clib_warning ("canonical name %s", mp->name);
2624 }
2625 else
2626 clib_warning ("retval %d", retval);
2627 }
2628}
2629
2630static void vl_api_dns_resolve_ip_reply_t_handler_json
2631 (vl_api_dns_resolve_ip_reply_t * mp)
2632{
2633 clib_warning ("not implemented");
2634}
2635
2636
Damjan Marion7cd468a2016-12-19 23:05:39 +01002637static void vl_api_ip_address_details_t_handler
2638 (vl_api_ip_address_details_t * mp)
2639{
2640 vat_main_t *vam = &vat_main;
2641 static ip_address_details_t empty_ip_address_details = { {0} };
2642 ip_address_details_t *address = NULL;
2643 ip_details_t *current_ip_details = NULL;
2644 ip_details_t *details = NULL;
2645
2646 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2647
2648 if (!details || vam->current_sw_if_index >= vec_len (details)
2649 || !details[vam->current_sw_if_index].present)
2650 {
2651 errmsg ("ip address details arrived but not stored");
2652 errmsg ("ip_dump should be called first");
2653 return;
2654 }
2655
2656 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2657
2658#define addresses (current_ip_details->addr)
2659
2660 vec_validate_init_empty (addresses, vec_len (addresses),
2661 empty_ip_address_details);
2662
2663 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2664
Neale Ranns097fa662018-05-01 05:17:55 -07002665 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
Paul Vinciguerraab055082019-06-06 14:07:55 -04002666 address->prefix_length = mp->prefix.len;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002667#undef addresses
2668}
2669
2670static void vl_api_ip_address_details_t_handler_json
2671 (vl_api_ip_address_details_t * mp)
2672{
2673 vat_main_t *vam = &vat_main;
2674 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002675
2676 if (VAT_JSON_ARRAY != vam->json_tree.type)
2677 {
2678 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2679 vat_json_init_array (&vam->json_tree);
2680 }
2681 node = vat_json_array_add (&vam->json_tree);
2682
2683 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -07002684 vat_json_object_add_prefix (node, &mp->prefix);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002685}
2686
2687static void
2688vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2689{
2690 vat_main_t *vam = &vat_main;
2691 static ip_details_t empty_ip_details = { 0 };
2692 ip_details_t *ip = NULL;
2693 u32 sw_if_index = ~0;
2694
2695 sw_if_index = ntohl (mp->sw_if_index);
2696
2697 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2698 sw_if_index, empty_ip_details);
2699
2700 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2701 sw_if_index);
2702
2703 ip->present = 1;
2704}
2705
2706static void
2707vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2708{
2709 vat_main_t *vam = &vat_main;
2710
2711 if (VAT_JSON_ARRAY != vam->json_tree.type)
2712 {
2713 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2714 vat_json_init_array (&vam->json_tree);
2715 }
2716 vat_json_array_add_uint (&vam->json_tree,
2717 clib_net_to_host_u32 (mp->sw_if_index));
2718}
2719
Damjan Marion7cd468a2016-12-19 23:05:39 +01002720static void
2721vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
2722{
jackiechen198556bc7382019-04-29 12:00:43 +08002723 u8 *s, i;
2724
Dave Baracha4ef82e2019-05-14 08:12:36 -04002725 s = format (0, "DHCP compl event: pid %d %s hostname %s host_addr %U "
jackiechen198556bc7382019-04-29 12:00:43 +08002726 "host_mac %U router_addr %U",
2727 ntohl (mp->pid), mp->lease.is_ipv6 ? "ipv6" : "ipv4",
2728 mp->lease.hostname,
2729 format_ip4_address, mp->lease.host_address,
2730 format_ethernet_address, mp->lease.host_mac,
2731 format_ip4_address, mp->lease.router_address);
2732
2733 for (i = 0; i < mp->lease.count; i++)
2734 s =
2735 format (s, " domain_server_addr %U", format_ip4_address,
2736 mp->lease.domain_server[i].address);
2737
2738 errmsg ((char *) s);
Dave Baracha4ef82e2019-05-14 08:12:36 -04002739 vec_free (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002740}
2741
2742static void vl_api_dhcp_compl_event_t_handler_json
2743 (vl_api_dhcp_compl_event_t * mp)
2744{
2745 /* JSON output not supported */
2746}
2747
Damjan Marion7cd468a2016-12-19 23:05:39 +01002748static void vl_api_get_first_msg_id_reply_t_handler
2749 (vl_api_get_first_msg_id_reply_t * mp)
2750{
2751 vat_main_t *vam = &vat_main;
2752 i32 retval = ntohl (mp->retval);
2753
2754 if (vam->async_mode)
2755 {
2756 vam->async_errors += (retval < 0);
2757 }
2758 else
2759 {
2760 vam->retval = retval;
2761 vam->result_ready = 1;
2762 }
2763 if (retval >= 0)
2764 {
2765 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2766 }
2767}
2768
2769static void vl_api_get_first_msg_id_reply_t_handler_json
2770 (vl_api_get_first_msg_id_reply_t * mp)
2771{
2772 vat_main_t *vam = &vat_main;
2773 vat_json_node_t node;
2774
2775 vat_json_init_object (&node);
2776 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2777 vat_json_object_add_uint (&node, "first_msg_id",
2778 (uint) ntohs (mp->first_msg_id));
2779
2780 vat_json_print (vam->ofp, &node);
2781 vat_json_free (&node);
2782
2783 vam->retval = ntohl (mp->retval);
2784 vam->result_ready = 1;
2785}
2786
2787static void vl_api_get_node_graph_reply_t_handler
2788 (vl_api_get_node_graph_reply_t * mp)
2789{
2790 vat_main_t *vam = &vat_main;
2791 api_main_t *am = &api_main;
2792 i32 retval = ntohl (mp->retval);
2793 u8 *pvt_copy, *reply;
2794 void *oldheap;
2795 vlib_node_t *node;
2796 int i;
2797
2798 if (vam->async_mode)
2799 {
2800 vam->async_errors += (retval < 0);
2801 }
2802 else
2803 {
2804 vam->retval = retval;
2805 vam->result_ready = 1;
2806 }
2807
2808 /* "Should never happen..." */
2809 if (retval != 0)
2810 return;
2811
Damjan Marion7bee80c2017-04-26 15:32:12 +02002812 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002813 pvt_copy = vec_dup (reply);
2814
2815 /* Toss the shared-memory original... */
2816 pthread_mutex_lock (&am->vlib_rp->mutex);
2817 oldheap = svm_push_data_heap (am->vlib_rp);
2818
2819 vec_free (reply);
2820
2821 svm_pop_heap (oldheap);
2822 pthread_mutex_unlock (&am->vlib_rp->mutex);
2823
2824 if (vam->graph_nodes)
2825 {
2826 hash_free (vam->graph_node_index_by_name);
2827
Dave Barach1ddbc012018-06-13 09:26:05 -04002828 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002829 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002830 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002831 vec_free (node->name);
2832 vec_free (node->next_nodes);
2833 vec_free (node);
2834 }
Dave Barach1ddbc012018-06-13 09:26:05 -04002835 vec_free (vam->graph_nodes[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002836 vec_free (vam->graph_nodes);
2837 }
2838
2839 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2840 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2841 vec_free (pvt_copy);
2842
Dave Barach1ddbc012018-06-13 09:26:05 -04002843 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002844 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002845 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002846 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2847 }
2848}
2849
2850static void vl_api_get_node_graph_reply_t_handler_json
2851 (vl_api_get_node_graph_reply_t * mp)
2852{
2853 vat_main_t *vam = &vat_main;
2854 api_main_t *am = &api_main;
2855 void *oldheap;
2856 vat_json_node_t node;
2857 u8 *reply;
2858
2859 /* $$$$ make this real? */
2860 vat_json_init_object (&node);
2861 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2862 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2863
Damjan Marion7bee80c2017-04-26 15:32:12 +02002864 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002865
2866 /* Toss the shared-memory original... */
2867 pthread_mutex_lock (&am->vlib_rp->mutex);
2868 oldheap = svm_push_data_heap (am->vlib_rp);
2869
2870 vec_free (reply);
2871
2872 svm_pop_heap (oldheap);
2873 pthread_mutex_unlock (&am->vlib_rp->mutex);
2874
2875 vat_json_print (vam->ofp, &node);
2876 vat_json_free (&node);
2877
2878 vam->retval = ntohl (mp->retval);
2879 vam->result_ready = 1;
2880}
2881
2882static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002883vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002884{
2885 vat_main_t *vam = &vat_main;
2886 u8 *s = 0;
2887
2888 if (mp->local)
2889 {
2890 s = format (s, "%=16d%=16d%=16d",
2891 ntohl (mp->sw_if_index), mp->priority, mp->weight);
2892 }
2893 else
2894 {
2895 s = format (s, "%=16U%=16d%=16d",
2896 mp->is_ipv6 ? format_ip6_address :
2897 format_ip4_address,
2898 mp->ip_address, mp->priority, mp->weight);
2899 }
2900
2901 print (vam->ofp, "%v", s);
2902 vec_free (s);
2903}
2904
2905static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002906vl_api_one_locator_details_t_handler_json (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002907{
2908 vat_main_t *vam = &vat_main;
2909 vat_json_node_t *node = NULL;
2910 struct in6_addr ip6;
2911 struct in_addr ip4;
2912
2913 if (VAT_JSON_ARRAY != vam->json_tree.type)
2914 {
2915 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2916 vat_json_init_array (&vam->json_tree);
2917 }
2918 node = vat_json_array_add (&vam->json_tree);
2919 vat_json_init_object (node);
2920
2921 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2922 vat_json_object_add_uint (node, "priority", mp->priority);
2923 vat_json_object_add_uint (node, "weight", mp->weight);
2924
2925 if (mp->local)
2926 vat_json_object_add_uint (node, "sw_if_index",
2927 clib_net_to_host_u32 (mp->sw_if_index));
2928 else
2929 {
2930 if (mp->is_ipv6)
2931 {
2932 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2933 vat_json_object_add_ip6 (node, "address", ip6);
2934 }
2935 else
2936 {
2937 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2938 vat_json_object_add_ip4 (node, "address", ip4);
2939 }
2940 }
2941}
2942
2943static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002944vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
2945 mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002946{
2947 vat_main_t *vam = &vat_main;
2948 u8 *ls_name = 0;
2949
2950 ls_name = format (0, "%s", mp->ls_name);
2951
2952 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
2953 ls_name);
2954 vec_free (ls_name);
2955}
2956
2957static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002958 vl_api_one_locator_set_details_t_handler_json
2959 (vl_api_one_locator_set_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002960{
2961 vat_main_t *vam = &vat_main;
2962 vat_json_node_t *node = 0;
2963 u8 *ls_name = 0;
2964
2965 ls_name = format (0, "%s", mp->ls_name);
2966 vec_add1 (ls_name, 0);
2967
2968 if (VAT_JSON_ARRAY != vam->json_tree.type)
2969 {
2970 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2971 vat_json_init_array (&vam->json_tree);
2972 }
2973 node = vat_json_array_add (&vam->json_tree);
2974
2975 vat_json_init_object (node);
2976 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2977 vat_json_object_add_uint (node, "ls_index",
2978 clib_net_to_host_u32 (mp->ls_index));
2979 vec_free (ls_name);
2980}
2981
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002982typedef struct
2983{
2984 u32 spi;
2985 u8 si;
2986} __attribute__ ((__packed__)) lisp_nsh_api_t;
2987
2988uword
2989unformat_nsh_address (unformat_input_t * input, va_list * args)
2990{
2991 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
2992 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
2993}
2994
2995u8 *
2996format_nsh_address_vat (u8 * s, va_list * args)
2997{
2998 nsh_t *a = va_arg (*args, nsh_t *);
2999 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
3000}
3001
Damjan Marion7cd468a2016-12-19 23:05:39 +01003002static u8 *
3003format_lisp_flat_eid (u8 * s, va_list * args)
3004{
3005 u32 type = va_arg (*args, u32);
3006 u8 *eid = va_arg (*args, u8 *);
3007 u32 eid_len = va_arg (*args, u32);
3008
3009 switch (type)
3010 {
3011 case 0:
3012 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
3013 case 1:
3014 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
3015 case 2:
3016 return format (s, "%U", format_ethernet_address, eid);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003017 case 3:
3018 return format (s, "%U", format_nsh_address_vat, eid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01003019 }
3020 return 0;
3021}
3022
3023static u8 *
3024format_lisp_eid_vat (u8 * s, va_list * args)
3025{
3026 u32 type = va_arg (*args, u32);
3027 u8 *eid = va_arg (*args, u8 *);
3028 u32 eid_len = va_arg (*args, u32);
3029 u8 *seid = va_arg (*args, u8 *);
3030 u32 seid_len = va_arg (*args, u32);
3031 u32 is_src_dst = va_arg (*args, u32);
3032
3033 if (is_src_dst)
3034 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
3035
3036 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
3037
3038 return s;
3039}
3040
3041static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003042vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003043{
3044 vat_main_t *vam = &vat_main;
3045 u8 *s = 0, *eid = 0;
3046
3047 if (~0 == mp->locator_set_index)
3048 s = format (0, "action: %d", mp->action);
3049 else
3050 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
3051
3052 eid = format (0, "%U", format_lisp_eid_vat,
3053 mp->eid_type,
3054 mp->eid,
3055 mp->eid_prefix_len,
3056 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
3057 vec_add1 (eid, 0);
3058
3059 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
3060 clib_net_to_host_u32 (mp->vni),
3061 eid,
3062 mp->is_local ? "local" : "remote",
3063 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
3064 clib_net_to_host_u16 (mp->key_id), mp->key);
3065
3066 vec_free (s);
3067 vec_free (eid);
3068}
3069
3070static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003071vl_api_one_eid_table_details_t_handler_json (vl_api_one_eid_table_details_t
3072 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003073{
3074 vat_main_t *vam = &vat_main;
3075 vat_json_node_t *node = 0;
3076 u8 *eid = 0;
3077
3078 if (VAT_JSON_ARRAY != vam->json_tree.type)
3079 {
3080 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3081 vat_json_init_array (&vam->json_tree);
3082 }
3083 node = vat_json_array_add (&vam->json_tree);
3084
3085 vat_json_init_object (node);
3086 if (~0 == mp->locator_set_index)
3087 vat_json_object_add_uint (node, "action", mp->action);
3088 else
3089 vat_json_object_add_uint (node, "locator_set_index",
3090 clib_net_to_host_u32 (mp->locator_set_index));
3091
3092 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003093 if (mp->eid_type == 3)
3094 {
3095 vat_json_node_t *nsh_json = vat_json_object_add (node, "eid");
3096 vat_json_init_object (nsh_json);
3097 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) mp->eid;
3098 vat_json_object_add_uint (nsh_json, "spi",
3099 clib_net_to_host_u32 (nsh->spi));
3100 vat_json_object_add_uint (nsh_json, "si", nsh->si);
3101 }
3102 else
3103 {
3104 eid = format (0, "%U", format_lisp_eid_vat,
3105 mp->eid_type,
3106 mp->eid,
3107 mp->eid_prefix_len,
3108 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
3109 vec_add1 (eid, 0);
3110 vat_json_object_add_string_copy (node, "eid", eid);
3111 vec_free (eid);
3112 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003113 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3114 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
3115 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
3116
3117 if (mp->key_id)
3118 {
3119 vat_json_object_add_uint (node, "key_id",
3120 clib_net_to_host_u16 (mp->key_id));
3121 vat_json_object_add_string_copy (node, "key", mp->key);
3122 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003123}
3124
3125static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003126vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
3127{
3128 vat_main_t *vam = &vat_main;
3129 u8 *seid = 0, *deid = 0;
3130 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3131
3132 deid = format (0, "%U", format_lisp_eid_vat,
3133 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3134
3135 seid = format (0, "%U", format_lisp_eid_vat,
3136 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3137
3138 vec_add1 (deid, 0);
3139 vec_add1 (seid, 0);
3140
3141 if (mp->is_ip4)
3142 format_ip_address_fcn = format_ip4_address;
3143 else
3144 format_ip_address_fcn = format_ip6_address;
3145
3146
3147 print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
3148 clib_net_to_host_u32 (mp->vni),
3149 seid, deid,
3150 format_ip_address_fcn, mp->lloc,
3151 format_ip_address_fcn, mp->rloc,
3152 clib_net_to_host_u32 (mp->pkt_count),
3153 clib_net_to_host_u32 (mp->bytes));
3154
3155 vec_free (deid);
3156 vec_free (seid);
3157}
3158
3159static void
3160vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp)
3161{
3162 struct in6_addr ip6;
3163 struct in_addr ip4;
3164 vat_main_t *vam = &vat_main;
3165 vat_json_node_t *node = 0;
3166 u8 *deid = 0, *seid = 0;
3167
3168 if (VAT_JSON_ARRAY != vam->json_tree.type)
3169 {
3170 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3171 vat_json_init_array (&vam->json_tree);
3172 }
3173 node = vat_json_array_add (&vam->json_tree);
3174
3175 vat_json_init_object (node);
3176 deid = format (0, "%U", format_lisp_eid_vat,
3177 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3178
3179 seid = format (0, "%U", format_lisp_eid_vat,
3180 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3181
3182 vec_add1 (deid, 0);
3183 vec_add1 (seid, 0);
3184
3185 vat_json_object_add_string_copy (node, "seid", seid);
3186 vat_json_object_add_string_copy (node, "deid", deid);
3187 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3188
3189 if (mp->is_ip4)
3190 {
3191 clib_memcpy (&ip4, mp->lloc, sizeof (ip4));
3192 vat_json_object_add_ip4 (node, "lloc", ip4);
3193 clib_memcpy (&ip4, mp->rloc, sizeof (ip4));
3194 vat_json_object_add_ip4 (node, "rloc", ip4);
3195 }
3196 else
3197 {
3198 clib_memcpy (&ip6, mp->lloc, sizeof (ip6));
3199 vat_json_object_add_ip6 (node, "lloc", ip6);
3200 clib_memcpy (&ip6, mp->rloc, sizeof (ip6));
3201 vat_json_object_add_ip6 (node, "rloc", ip6);
3202 }
3203 vat_json_object_add_uint (node, "pkt_count",
3204 clib_net_to_host_u32 (mp->pkt_count));
3205 vat_json_object_add_uint (node, "bytes", clib_net_to_host_u32 (mp->bytes));
3206
3207 vec_free (deid);
3208 vec_free (seid);
3209}
3210
3211static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003212 vl_api_one_eid_table_map_details_t_handler
3213 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003214{
3215 vat_main_t *vam = &vat_main;
3216
3217 u8 *line = format (0, "%=10d%=10d",
3218 clib_net_to_host_u32 (mp->vni),
3219 clib_net_to_host_u32 (mp->dp_table));
3220 print (vam->ofp, "%v", line);
3221 vec_free (line);
3222}
3223
3224static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003225 vl_api_one_eid_table_map_details_t_handler_json
3226 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003227{
3228 vat_main_t *vam = &vat_main;
3229 vat_json_node_t *node = NULL;
3230
3231 if (VAT_JSON_ARRAY != vam->json_tree.type)
3232 {
3233 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3234 vat_json_init_array (&vam->json_tree);
3235 }
3236 node = vat_json_array_add (&vam->json_tree);
3237 vat_json_init_object (node);
3238 vat_json_object_add_uint (node, "dp_table",
3239 clib_net_to_host_u32 (mp->dp_table));
3240 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3241}
3242
3243static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003244 vl_api_one_eid_table_vni_details_t_handler
3245 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003246{
3247 vat_main_t *vam = &vat_main;
3248
3249 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
3250 print (vam->ofp, "%v", line);
3251 vec_free (line);
3252}
3253
3254static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003255 vl_api_one_eid_table_vni_details_t_handler_json
3256 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003257{
3258 vat_main_t *vam = &vat_main;
3259 vat_json_node_t *node = NULL;
3260
3261 if (VAT_JSON_ARRAY != vam->json_tree.type)
3262 {
3263 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3264 vat_json_init_array (&vam->json_tree);
3265 }
3266 node = vat_json_array_add (&vam->json_tree);
3267 vat_json_init_object (node);
3268 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3269}
3270
Damjan Marion7cd468a2016-12-19 23:05:39 +01003271static void
Filip Tehlar7048ff12017-07-27 08:09:14 +02003272 vl_api_show_one_map_register_fallback_threshold_reply_t_handler
3273 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3274{
3275 vat_main_t *vam = &vat_main;
3276 int retval = clib_net_to_host_u32 (mp->retval);
3277
3278 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3279 print (vam->ofp, "fallback threshold value: %d", mp->value);
3280
3281 vam->retval = retval;
3282 vam->result_ready = 1;
3283}
3284
3285static void
3286 vl_api_show_one_map_register_fallback_threshold_reply_t_handler_json
3287 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3288{
3289 vat_main_t *vam = &vat_main;
3290 vat_json_node_t _node, *node = &_node;
3291 int retval = clib_net_to_host_u32 (mp->retval);
3292
3293 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3294 vat_json_init_object (node);
3295 vat_json_object_add_uint (node, "value", mp->value);
3296
3297 vat_json_print (vam->ofp, node);
3298 vat_json_free (node);
3299
3300 vam->retval = retval;
3301 vam->result_ready = 1;
3302}
3303
3304static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003305 vl_api_show_one_map_register_state_reply_t_handler
3306 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003307{
3308 vat_main_t *vam = &vat_main;
3309 int retval = clib_net_to_host_u32 (mp->retval);
3310
3311 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3312
3313 vam->retval = retval;
3314 vam->result_ready = 1;
3315}
3316
3317static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003318 vl_api_show_one_map_register_state_reply_t_handler_json
3319 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003320{
3321 vat_main_t *vam = &vat_main;
3322 vat_json_node_t _node, *node = &_node;
3323 int retval = clib_net_to_host_u32 (mp->retval);
3324
3325 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3326
3327 vat_json_init_object (node);
3328 vat_json_object_add_string_copy (node, "state", s);
3329
3330 vat_json_print (vam->ofp, node);
3331 vat_json_free (node);
3332
3333 vam->retval = retval;
3334 vam->result_ready = 1;
3335 vec_free (s);
3336}
3337
3338static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003339 vl_api_show_one_rloc_probe_state_reply_t_handler
3340 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003341{
3342 vat_main_t *vam = &vat_main;
3343 int retval = clib_net_to_host_u32 (mp->retval);
3344
3345 if (retval)
3346 goto end;
3347
3348 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3349end:
3350 vam->retval = retval;
3351 vam->result_ready = 1;
3352}
3353
3354static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003355 vl_api_show_one_rloc_probe_state_reply_t_handler_json
3356 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003357{
3358 vat_main_t *vam = &vat_main;
3359 vat_json_node_t _node, *node = &_node;
3360 int retval = clib_net_to_host_u32 (mp->retval);
3361
3362 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3363 vat_json_init_object (node);
3364 vat_json_object_add_string_copy (node, "state", s);
3365
3366 vat_json_print (vam->ofp, node);
3367 vat_json_free (node);
3368
3369 vam->retval = retval;
3370 vam->result_ready = 1;
3371 vec_free (s);
3372}
3373
3374static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003375 vl_api_show_one_stats_enable_disable_reply_t_handler
3376 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3377{
3378 vat_main_t *vam = &vat_main;
3379 int retval = clib_net_to_host_u32 (mp->retval);
3380
3381 if (retval)
3382 goto end;
3383
3384 print (vam->ofp, "%s", mp->is_en ? "enabled" : "disabled");
3385end:
3386 vam->retval = retval;
3387 vam->result_ready = 1;
3388}
3389
3390static void
3391 vl_api_show_one_stats_enable_disable_reply_t_handler_json
3392 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3393{
3394 vat_main_t *vam = &vat_main;
3395 vat_json_node_t _node, *node = &_node;
3396 int retval = clib_net_to_host_u32 (mp->retval);
3397
3398 u8 *s = format (0, "%s", mp->is_en ? "enabled" : "disabled");
3399 vat_json_init_object (node);
3400 vat_json_object_add_string_copy (node, "state", s);
3401
3402 vat_json_print (vam->ofp, node);
3403 vat_json_free (node);
3404
3405 vam->retval = retval;
3406 vam->result_ready = 1;
3407 vec_free (s);
3408}
3409
3410static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003411api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003412{
3413 e->dp_table = clib_net_to_host_u32 (e->dp_table);
3414 e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003415 e->vni = clib_net_to_host_u32 (e->vni);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003416}
3417
3418static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003419 gpe_fwd_entries_get_reply_t_net_to_host
3420 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003421{
3422 u32 i;
3423
3424 mp->count = clib_net_to_host_u32 (mp->count);
3425 for (i = 0; i < mp->count; i++)
3426 {
Filip Tehlar82786c42017-02-20 15:20:37 +01003427 api_gpe_fwd_entry_net_to_host (&mp->entries[i]);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003428 }
3429}
3430
Filip Tehlar3e7b56932017-02-21 18:28:34 +01003431static u8 *
3432format_gpe_encap_mode (u8 * s, va_list * args)
3433{
3434 u32 mode = va_arg (*args, u32);
3435
3436 switch (mode)
3437 {
3438 case 0:
3439 return format (s, "lisp");
3440 case 1:
3441 return format (s, "vxlan");
3442 }
3443 return 0;
3444}
3445
3446static void
3447 vl_api_gpe_get_encap_mode_reply_t_handler
3448 (vl_api_gpe_get_encap_mode_reply_t * mp)
3449{
3450 vat_main_t *vam = &vat_main;
3451
3452 print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode);
3453 vam->retval = ntohl (mp->retval);
3454 vam->result_ready = 1;
3455}
3456
3457static void
3458 vl_api_gpe_get_encap_mode_reply_t_handler_json
3459 (vl_api_gpe_get_encap_mode_reply_t * mp)
3460{
3461 vat_main_t *vam = &vat_main;
3462 vat_json_node_t node;
3463
3464 u8 *encap_mode = format (0, "%U", format_gpe_encap_mode, mp->encap_mode);
3465 vec_add1 (encap_mode, 0);
3466
3467 vat_json_init_object (&node);
3468 vat_json_object_add_string_copy (&node, "gpe_mode", encap_mode);
3469
3470 vec_free (encap_mode);
3471 vat_json_print (vam->ofp, &node);
3472 vat_json_free (&node);
3473
3474 vam->retval = ntohl (mp->retval);
3475 vam->result_ready = 1;
3476}
3477
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003478static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003479 vl_api_gpe_fwd_entry_path_details_t_handler
3480 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003481{
3482 vat_main_t *vam = &vat_main;
3483 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3484
3485 if (mp->lcl_loc.is_ip4)
3486 format_ip_address_fcn = format_ip4_address;
3487 else
3488 format_ip_address_fcn = format_ip6_address;
3489
3490 print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight,
3491 format_ip_address_fcn, &mp->lcl_loc,
3492 format_ip_address_fcn, &mp->rmt_loc);
3493}
3494
3495static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003496lisp_fill_locator_node (vat_json_node_t * n, vl_api_gpe_locator_t * loc)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003497{
3498 struct in6_addr ip6;
3499 struct in_addr ip4;
3500
3501 if (loc->is_ip4)
3502 {
3503 clib_memcpy (&ip4, loc->addr, sizeof (ip4));
3504 vat_json_object_add_ip4 (n, "address", ip4);
3505 }
3506 else
3507 {
3508 clib_memcpy (&ip6, loc->addr, sizeof (ip6));
3509 vat_json_object_add_ip6 (n, "address", ip6);
3510 }
3511 vat_json_object_add_uint (n, "weight", loc->weight);
3512}
3513
3514static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003515 vl_api_gpe_fwd_entry_path_details_t_handler_json
3516 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003517{
3518 vat_main_t *vam = &vat_main;
3519 vat_json_node_t *node = NULL;
3520 vat_json_node_t *loc_node;
3521
3522 if (VAT_JSON_ARRAY != vam->json_tree.type)
3523 {
3524 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3525 vat_json_init_array (&vam->json_tree);
3526 }
3527 node = vat_json_array_add (&vam->json_tree);
3528 vat_json_init_object (node);
3529
3530 loc_node = vat_json_object_add (node, "local_locator");
3531 vat_json_init_object (loc_node);
3532 lisp_fill_locator_node (loc_node, &mp->lcl_loc);
3533
3534 loc_node = vat_json_object_add (node, "remote_locator");
3535 vat_json_init_object (loc_node);
3536 lisp_fill_locator_node (loc_node, &mp->rmt_loc);
3537}
3538
3539static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003540 vl_api_gpe_fwd_entries_get_reply_t_handler
3541 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003542{
3543 vat_main_t *vam = &vat_main;
3544 u32 i;
3545 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003546 vl_api_gpe_fwd_entry_t *e;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003547
3548 if (retval)
3549 goto end;
3550
Filip Tehlar82786c42017-02-20 15:20:37 +01003551 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003552
3553 for (i = 0; i < mp->count; i++)
3554 {
3555 e = &mp->entries[i];
3556 print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table,
3557 format_lisp_flat_eid, e->eid_type, e->leid, e->leid_prefix_len,
3558 format_lisp_flat_eid, e->eid_type, e->reid, e->reid_prefix_len);
3559 }
3560
3561end:
3562 vam->retval = retval;
3563 vam->result_ready = 1;
3564}
3565
3566static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003567 vl_api_gpe_fwd_entries_get_reply_t_handler_json
3568 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003569{
3570 u8 *s = 0;
3571 vat_main_t *vam = &vat_main;
3572 vat_json_node_t *e = 0, root;
3573 u32 i;
3574 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003575 vl_api_gpe_fwd_entry_t *fwd;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003576
3577 if (retval)
3578 goto end;
3579
Filip Tehlar82786c42017-02-20 15:20:37 +01003580 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003581 vat_json_init_array (&root);
3582
3583 for (i = 0; i < mp->count; i++)
3584 {
3585 e = vat_json_array_add (&root);
3586 fwd = &mp->entries[i];
3587
3588 vat_json_init_object (e);
3589 vat_json_object_add_int (e, "fwd_entry_index", fwd->fwd_entry_index);
3590 vat_json_object_add_int (e, "dp_table", fwd->dp_table);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003591 vat_json_object_add_int (e, "vni", fwd->vni);
3592 vat_json_object_add_int (e, "action", fwd->action);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003593
3594 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->leid,
3595 fwd->leid_prefix_len);
3596 vec_add1 (s, 0);
3597 vat_json_object_add_string_copy (e, "leid", s);
3598 vec_free (s);
3599
3600 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->reid,
3601 fwd->reid_prefix_len);
3602 vec_add1 (s, 0);
3603 vat_json_object_add_string_copy (e, "reid", s);
3604 vec_free (s);
3605 }
3606
3607 vat_json_print (vam->ofp, &root);
3608 vat_json_free (&root);
3609
3610end:
3611 vam->retval = retval;
3612 vam->result_ready = 1;
3613}
3614
3615static void
Filip Tehlarb4243aa2017-06-14 14:39:42 +02003616 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler
3617 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3618{
3619 vat_main_t *vam = &vat_main;
3620 u32 i, n;
3621 int retval = clib_net_to_host_u32 (mp->retval);
3622 vl_api_gpe_native_fwd_rpath_t *r;
3623
3624 if (retval)
3625 goto end;
3626
3627 n = clib_net_to_host_u32 (mp->count);
3628
3629 for (i = 0; i < n; i++)
3630 {
3631 r = &mp->entries[i];
3632 print (vam->ofp, "fib_index: %d sw_if_index %d nh %U",
3633 clib_net_to_host_u32 (r->fib_index),
3634 clib_net_to_host_u32 (r->nh_sw_if_index),
3635 r->is_ip4 ? format_ip4_address : format_ip6_address, r->nh_addr);
3636 }
3637
3638end:
3639 vam->retval = retval;
3640 vam->result_ready = 1;
3641}
3642
3643static void
3644 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler_json
3645 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3646{
3647 vat_main_t *vam = &vat_main;
3648 vat_json_node_t root, *e;
3649 u32 i, n;
3650 int retval = clib_net_to_host_u32 (mp->retval);
3651 vl_api_gpe_native_fwd_rpath_t *r;
3652 u8 *s;
3653
3654 if (retval)
3655 goto end;
3656
3657 n = clib_net_to_host_u32 (mp->count);
3658 vat_json_init_array (&root);
3659
3660 for (i = 0; i < n; i++)
3661 {
3662 e = vat_json_array_add (&root);
3663 vat_json_init_object (e);
3664 r = &mp->entries[i];
3665 s =
3666 format (0, "%U", r->is_ip4 ? format_ip4_address : format_ip6_address,
3667 r->nh_addr);
3668 vec_add1 (s, 0);
3669 vat_json_object_add_string_copy (e, "ip4", s);
3670 vec_free (s);
3671
3672 vat_json_object_add_uint (e, "fib_index",
3673 clib_net_to_host_u32 (r->fib_index));
3674 vat_json_object_add_uint (e, "nh_sw_if_index",
3675 clib_net_to_host_u32 (r->nh_sw_if_index));
3676 }
3677
3678 vat_json_print (vam->ofp, &root);
3679 vat_json_free (&root);
3680
3681end:
3682 vam->retval = retval;
3683 vam->result_ready = 1;
3684}
3685
3686static void
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003687 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler
3688 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3689{
3690 vat_main_t *vam = &vat_main;
3691 u32 i, n;
3692 int retval = clib_net_to_host_u32 (mp->retval);
3693
3694 if (retval)
3695 goto end;
3696
3697 n = clib_net_to_host_u32 (mp->count);
3698
3699 for (i = 0; i < n; i++)
3700 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i]));
3701
3702end:
3703 vam->retval = retval;
3704 vam->result_ready = 1;
3705}
3706
3707static void
3708 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler_json
3709 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3710{
3711 vat_main_t *vam = &vat_main;
3712 vat_json_node_t root;
3713 u32 i, n;
3714 int retval = clib_net_to_host_u32 (mp->retval);
3715
3716 if (retval)
3717 goto end;
3718
3719 n = clib_net_to_host_u32 (mp->count);
3720 vat_json_init_array (&root);
3721
3722 for (i = 0; i < n; i++)
3723 vat_json_array_add_uint (&root, clib_net_to_host_u32 (mp->vnis[i]));
3724
3725 vat_json_print (vam->ofp, &root);
3726 vat_json_free (&root);
3727
3728end:
3729 vam->retval = retval;
3730 vam->result_ready = 1;
3731}
3732
3733static void
Filip Tehlar05879992017-09-05 15:46:09 +02003734 vl_api_one_ndp_entries_get_reply_t_handler
3735 (vl_api_one_ndp_entries_get_reply_t * mp)
3736{
3737 vat_main_t *vam = &vat_main;
3738 u32 i, n;
3739 int retval = clib_net_to_host_u32 (mp->retval);
3740
3741 if (retval)
3742 goto end;
3743
3744 n = clib_net_to_host_u32 (mp->count);
3745
3746 for (i = 0; i < n; i++)
3747 print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
3748 format_ethernet_address, mp->entries[i].mac);
3749
3750end:
3751 vam->retval = retval;
3752 vam->result_ready = 1;
3753}
3754
3755static void
3756 vl_api_one_ndp_entries_get_reply_t_handler_json
3757 (vl_api_one_ndp_entries_get_reply_t * mp)
3758{
3759 u8 *s = 0;
3760 vat_main_t *vam = &vat_main;
3761 vat_json_node_t *e = 0, root;
3762 u32 i, n;
3763 int retval = clib_net_to_host_u32 (mp->retval);
3764 vl_api_one_ndp_entry_t *arp_entry;
3765
3766 if (retval)
3767 goto end;
3768
3769 n = clib_net_to_host_u32 (mp->count);
3770 vat_json_init_array (&root);
3771
3772 for (i = 0; i < n; i++)
3773 {
3774 e = vat_json_array_add (&root);
3775 arp_entry = &mp->entries[i];
3776
3777 vat_json_init_object (e);
3778 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3779 vec_add1 (s, 0);
3780
3781 vat_json_object_add_string_copy (e, "mac", s);
3782 vec_free (s);
3783
3784 s = format (0, "%U", format_ip6_address, &arp_entry->ip6);
3785 vec_add1 (s, 0);
3786 vat_json_object_add_string_copy (e, "ip6", s);
3787 vec_free (s);
3788 }
3789
3790 vat_json_print (vam->ofp, &root);
3791 vat_json_free (&root);
3792
3793end:
3794 vam->retval = retval;
3795 vam->result_ready = 1;
3796}
3797
3798static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003799 vl_api_one_l2_arp_entries_get_reply_t_handler
3800 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3801{
3802 vat_main_t *vam = &vat_main;
3803 u32 i, n;
3804 int retval = clib_net_to_host_u32 (mp->retval);
3805
3806 if (retval)
3807 goto end;
3808
3809 n = clib_net_to_host_u32 (mp->count);
3810
3811 for (i = 0; i < n; i++)
3812 print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
3813 format_ethernet_address, mp->entries[i].mac);
3814
3815end:
3816 vam->retval = retval;
3817 vam->result_ready = 1;
3818}
3819
3820static void
3821 vl_api_one_l2_arp_entries_get_reply_t_handler_json
3822 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3823{
3824 u8 *s = 0;
3825 vat_main_t *vam = &vat_main;
3826 vat_json_node_t *e = 0, root;
3827 u32 i, n;
3828 int retval = clib_net_to_host_u32 (mp->retval);
3829 vl_api_one_l2_arp_entry_t *arp_entry;
3830
3831 if (retval)
3832 goto end;
3833
3834 n = clib_net_to_host_u32 (mp->count);
3835 vat_json_init_array (&root);
3836
3837 for (i = 0; i < n; i++)
3838 {
3839 e = vat_json_array_add (&root);
3840 arp_entry = &mp->entries[i];
3841
3842 vat_json_init_object (e);
3843 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3844 vec_add1 (s, 0);
3845
3846 vat_json_object_add_string_copy (e, "mac", s);
3847 vec_free (s);
3848
3849 s = format (0, "%U", format_ip4_address, &arp_entry->ip4);
3850 vec_add1 (s, 0);
3851 vat_json_object_add_string_copy (e, "ip4", s);
3852 vec_free (s);
3853 }
3854
3855 vat_json_print (vam->ofp, &root);
3856 vat_json_free (&root);
3857
3858end:
3859 vam->retval = retval;
3860 vam->result_ready = 1;
3861}
3862
3863static void
Filip Tehlar05879992017-09-05 15:46:09 +02003864vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
3865{
3866 vat_main_t *vam = &vat_main;
3867 u32 i, n;
3868 int retval = clib_net_to_host_u32 (mp->retval);
3869
3870 if (retval)
3871 goto end;
3872
3873 n = clib_net_to_host_u32 (mp->count);
3874
3875 for (i = 0; i < n; i++)
3876 {
3877 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3878 }
3879
3880end:
3881 vam->retval = retval;
3882 vam->result_ready = 1;
3883}
3884
3885static void
3886 vl_api_one_ndp_bd_get_reply_t_handler_json
3887 (vl_api_one_ndp_bd_get_reply_t * mp)
3888{
3889 vat_main_t *vam = &vat_main;
3890 vat_json_node_t root;
3891 u32 i, n;
3892 int retval = clib_net_to_host_u32 (mp->retval);
3893
3894 if (retval)
3895 goto end;
3896
3897 n = clib_net_to_host_u32 (mp->count);
3898 vat_json_init_array (&root);
3899
3900 for (i = 0; i < n; i++)
3901 {
3902 vat_json_array_add_uint (&root,
3903 clib_net_to_host_u32 (mp->bridge_domains[i]));
3904 }
3905
3906 vat_json_print (vam->ofp, &root);
3907 vat_json_free (&root);
3908
3909end:
3910 vam->retval = retval;
3911 vam->result_ready = 1;
3912}
3913
3914static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003915 vl_api_one_l2_arp_bd_get_reply_t_handler
3916 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3917{
3918 vat_main_t *vam = &vat_main;
3919 u32 i, n;
3920 int retval = clib_net_to_host_u32 (mp->retval);
3921
3922 if (retval)
3923 goto end;
3924
3925 n = clib_net_to_host_u32 (mp->count);
3926
3927 for (i = 0; i < n; i++)
3928 {
3929 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3930 }
3931
3932end:
3933 vam->retval = retval;
3934 vam->result_ready = 1;
3935}
3936
3937static void
3938 vl_api_one_l2_arp_bd_get_reply_t_handler_json
3939 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3940{
3941 vat_main_t *vam = &vat_main;
3942 vat_json_node_t root;
3943 u32 i, n;
3944 int retval = clib_net_to_host_u32 (mp->retval);
3945
3946 if (retval)
3947 goto end;
3948
3949 n = clib_net_to_host_u32 (mp->count);
3950 vat_json_init_array (&root);
3951
3952 for (i = 0; i < n; i++)
3953 {
3954 vat_json_array_add_uint (&root,
3955 clib_net_to_host_u32 (mp->bridge_domains[i]));
3956 }
3957
3958 vat_json_print (vam->ofp, &root);
3959 vat_json_free (&root);
3960
3961end:
3962 vam->retval = retval;
3963 vam->result_ready = 1;
3964}
3965
3966static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003967 vl_api_one_adjacencies_get_reply_t_handler
3968 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003969{
3970 vat_main_t *vam = &vat_main;
3971 u32 i, n;
3972 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003973 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003974
3975 if (retval)
3976 goto end;
3977
3978 n = clib_net_to_host_u32 (mp->count);
3979
3980 for (i = 0; i < n; i++)
3981 {
3982 a = &mp->adjacencies[i];
3983 print (vam->ofp, "%U %40U",
3984 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
3985 format_lisp_flat_eid, a->eid_type, a->reid, a->reid_prefix_len);
3986 }
3987
3988end:
3989 vam->retval = retval;
3990 vam->result_ready = 1;
3991}
3992
3993static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003994 vl_api_one_adjacencies_get_reply_t_handler_json
3995 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003996{
3997 u8 *s = 0;
3998 vat_main_t *vam = &vat_main;
3999 vat_json_node_t *e = 0, root;
4000 u32 i, n;
4001 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01004002 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01004003
4004 if (retval)
4005 goto end;
4006
4007 n = clib_net_to_host_u32 (mp->count);
4008 vat_json_init_array (&root);
4009
4010 for (i = 0; i < n; i++)
4011 {
4012 e = vat_json_array_add (&root);
4013 a = &mp->adjacencies[i];
4014
4015 vat_json_init_object (e);
4016 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
4017 a->leid_prefix_len);
4018 vec_add1 (s, 0);
4019 vat_json_object_add_string_copy (e, "leid", s);
4020 vec_free (s);
4021
4022 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
4023 a->reid_prefix_len);
4024 vec_add1 (s, 0);
4025 vat_json_object_add_string_copy (e, "reid", s);
4026 vec_free (s);
4027 }
4028
4029 vat_json_print (vam->ofp, &root);
4030 vat_json_free (&root);
4031
4032end:
4033 vam->retval = retval;
4034 vam->result_ready = 1;
4035}
4036
4037static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004038vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004039{
4040 vat_main_t *vam = &vat_main;
4041
4042 print (vam->ofp, "%=20U",
4043 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
4044 mp->ip_address);
4045}
4046
4047static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004048 vl_api_one_map_server_details_t_handler_json
4049 (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004050{
4051 vat_main_t *vam = &vat_main;
4052 vat_json_node_t *node = NULL;
4053 struct in6_addr ip6;
4054 struct in_addr ip4;
4055
4056 if (VAT_JSON_ARRAY != vam->json_tree.type)
4057 {
4058 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4059 vat_json_init_array (&vam->json_tree);
4060 }
4061 node = vat_json_array_add (&vam->json_tree);
4062
4063 vat_json_init_object (node);
4064 if (mp->is_ipv6)
4065 {
4066 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
4067 vat_json_object_add_ip6 (node, "map-server", ip6);
4068 }
4069 else
4070 {
4071 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
4072 vat_json_object_add_ip4 (node, "map-server", ip4);
4073 }
4074}
4075
4076static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004077vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
4078 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004079{
4080 vat_main_t *vam = &vat_main;
4081
4082 print (vam->ofp, "%=20U",
4083 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
4084 mp->ip_address);
4085}
4086
4087static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004088 vl_api_one_map_resolver_details_t_handler_json
4089 (vl_api_one_map_resolver_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004090{
4091 vat_main_t *vam = &vat_main;
4092 vat_json_node_t *node = NULL;
4093 struct in6_addr ip6;
4094 struct in_addr ip4;
4095
4096 if (VAT_JSON_ARRAY != vam->json_tree.type)
4097 {
4098 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4099 vat_json_init_array (&vam->json_tree);
4100 }
4101 node = vat_json_array_add (&vam->json_tree);
4102
4103 vat_json_init_object (node);
4104 if (mp->is_ipv6)
4105 {
4106 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
4107 vat_json_object_add_ip6 (node, "map resolver", ip6);
4108 }
4109 else
4110 {
4111 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
4112 vat_json_object_add_ip4 (node, "map resolver", ip4);
4113 }
4114}
4115
4116static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004117vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004118{
4119 vat_main_t *vam = &vat_main;
4120 i32 retval = ntohl (mp->retval);
4121
4122 if (0 <= retval)
4123 {
4124 print (vam->ofp, "feature: %s\ngpe: %s",
4125 mp->feature_status ? "enabled" : "disabled",
4126 mp->gpe_status ? "enabled" : "disabled");
4127 }
4128
4129 vam->retval = retval;
4130 vam->result_ready = 1;
4131}
4132
4133static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004134 vl_api_show_one_status_reply_t_handler_json
4135 (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004136{
4137 vat_main_t *vam = &vat_main;
4138 vat_json_node_t node;
4139 u8 *gpe_status = NULL;
4140 u8 *feature_status = NULL;
4141
4142 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
4143 feature_status = format (0, "%s",
4144 mp->feature_status ? "enabled" : "disabled");
4145 vec_add1 (gpe_status, 0);
4146 vec_add1 (feature_status, 0);
4147
4148 vat_json_init_object (&node);
4149 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
4150 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
4151
4152 vec_free (gpe_status);
4153 vec_free (feature_status);
4154
4155 vat_json_print (vam->ofp, &node);
4156 vat_json_free (&node);
4157
4158 vam->retval = ntohl (mp->retval);
4159 vam->result_ready = 1;
4160}
4161
4162static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004163 vl_api_one_get_map_request_itr_rlocs_reply_t_handler
4164 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004165{
4166 vat_main_t *vam = &vat_main;
4167 i32 retval = ntohl (mp->retval);
4168
4169 if (retval >= 0)
4170 {
4171 print (vam->ofp, "%=20s", mp->locator_set_name);
4172 }
4173
4174 vam->retval = retval;
4175 vam->result_ready = 1;
4176}
4177
4178static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004179 vl_api_one_get_map_request_itr_rlocs_reply_t_handler_json
4180 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004181{
4182 vat_main_t *vam = &vat_main;
4183 vat_json_node_t *node = NULL;
4184
4185 if (VAT_JSON_ARRAY != vam->json_tree.type)
4186 {
4187 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4188 vat_json_init_array (&vam->json_tree);
4189 }
4190 node = vat_json_array_add (&vam->json_tree);
4191
4192 vat_json_init_object (node);
4193 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
4194
4195 vat_json_print (vam->ofp, node);
4196 vat_json_free (node);
4197
4198 vam->retval = ntohl (mp->retval);
4199 vam->result_ready = 1;
4200}
4201
4202static u8 *
4203format_lisp_map_request_mode (u8 * s, va_list * args)
4204{
4205 u32 mode = va_arg (*args, u32);
4206
4207 switch (mode)
4208 {
4209 case 0:
4210 return format (0, "dst-only");
4211 case 1:
4212 return format (0, "src-dst");
4213 }
4214 return 0;
4215}
4216
4217static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004218 vl_api_show_one_map_request_mode_reply_t_handler
4219 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004220{
4221 vat_main_t *vam = &vat_main;
4222 i32 retval = ntohl (mp->retval);
4223
4224 if (0 <= retval)
4225 {
4226 u32 mode = mp->mode;
4227 print (vam->ofp, "map_request_mode: %U",
4228 format_lisp_map_request_mode, mode);
4229 }
4230
4231 vam->retval = retval;
4232 vam->result_ready = 1;
4233}
4234
4235static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004236 vl_api_show_one_map_request_mode_reply_t_handler_json
4237 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004238{
4239 vat_main_t *vam = &vat_main;
4240 vat_json_node_t node;
4241 u8 *s = 0;
4242 u32 mode;
4243
4244 mode = mp->mode;
4245 s = format (0, "%U", format_lisp_map_request_mode, mode);
4246 vec_add1 (s, 0);
4247
4248 vat_json_init_object (&node);
4249 vat_json_object_add_string_copy (&node, "map_request_mode", s);
4250 vat_json_print (vam->ofp, &node);
4251 vat_json_free (&node);
4252
4253 vec_free (s);
4254 vam->retval = ntohl (mp->retval);
4255 vam->result_ready = 1;
4256}
4257
4258static void
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004259 vl_api_one_show_xtr_mode_reply_t_handler
4260 (vl_api_one_show_xtr_mode_reply_t * mp)
4261{
4262 vat_main_t *vam = &vat_main;
4263 i32 retval = ntohl (mp->retval);
4264
4265 if (0 <= retval)
4266 {
4267 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4268 }
4269
4270 vam->retval = retval;
4271 vam->result_ready = 1;
4272}
4273
4274static void
4275 vl_api_one_show_xtr_mode_reply_t_handler_json
4276 (vl_api_one_show_xtr_mode_reply_t * mp)
4277{
4278 vat_main_t *vam = &vat_main;
4279 vat_json_node_t node;
4280 u8 *status = 0;
4281
4282 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4283 vec_add1 (status, 0);
4284
4285 vat_json_init_object (&node);
4286 vat_json_object_add_string_copy (&node, "status", status);
4287
4288 vec_free (status);
4289
4290 vat_json_print (vam->ofp, &node);
4291 vat_json_free (&node);
4292
4293 vam->retval = ntohl (mp->retval);
4294 vam->result_ready = 1;
4295}
4296
4297static void
4298 vl_api_one_show_pitr_mode_reply_t_handler
4299 (vl_api_one_show_pitr_mode_reply_t * mp)
4300{
4301 vat_main_t *vam = &vat_main;
4302 i32 retval = ntohl (mp->retval);
4303
4304 if (0 <= retval)
4305 {
4306 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4307 }
4308
4309 vam->retval = retval;
4310 vam->result_ready = 1;
4311}
4312
4313static void
4314 vl_api_one_show_pitr_mode_reply_t_handler_json
4315 (vl_api_one_show_pitr_mode_reply_t * mp)
4316{
4317 vat_main_t *vam = &vat_main;
4318 vat_json_node_t node;
4319 u8 *status = 0;
4320
4321 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4322 vec_add1 (status, 0);
4323
4324 vat_json_init_object (&node);
4325 vat_json_object_add_string_copy (&node, "status", status);
4326
4327 vec_free (status);
4328
4329 vat_json_print (vam->ofp, &node);
4330 vat_json_free (&node);
4331
4332 vam->retval = ntohl (mp->retval);
4333 vam->result_ready = 1;
4334}
4335
4336static void
4337 vl_api_one_show_petr_mode_reply_t_handler
4338 (vl_api_one_show_petr_mode_reply_t * mp)
4339{
4340 vat_main_t *vam = &vat_main;
4341 i32 retval = ntohl (mp->retval);
4342
4343 if (0 <= retval)
4344 {
4345 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4346 }
4347
4348 vam->retval = retval;
4349 vam->result_ready = 1;
4350}
4351
4352static void
4353 vl_api_one_show_petr_mode_reply_t_handler_json
4354 (vl_api_one_show_petr_mode_reply_t * mp)
4355{
4356 vat_main_t *vam = &vat_main;
4357 vat_json_node_t node;
4358 u8 *status = 0;
4359
4360 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4361 vec_add1 (status, 0);
4362
4363 vat_json_init_object (&node);
4364 vat_json_object_add_string_copy (&node, "status", status);
4365
4366 vec_free (status);
4367
4368 vat_json_print (vam->ofp, &node);
4369 vat_json_free (&node);
4370
4371 vam->retval = ntohl (mp->retval);
4372 vam->result_ready = 1;
4373}
4374
4375static void
Filip Tehlar67a99f82017-03-10 13:18:02 +01004376 vl_api_show_one_use_petr_reply_t_handler
4377 (vl_api_show_one_use_petr_reply_t * mp)
4378{
4379 vat_main_t *vam = &vat_main;
4380 i32 retval = ntohl (mp->retval);
4381
4382 if (0 <= retval)
4383 {
4384 print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
4385 if (mp->status)
4386 {
4387 print (vam->ofp, "Proxy-ETR address; %U",
4388 mp->is_ip4 ? format_ip4_address : format_ip6_address,
4389 mp->address);
4390 }
4391 }
4392
4393 vam->retval = retval;
4394 vam->result_ready = 1;
4395}
4396
4397static void
4398 vl_api_show_one_use_petr_reply_t_handler_json
4399 (vl_api_show_one_use_petr_reply_t * mp)
4400{
4401 vat_main_t *vam = &vat_main;
4402 vat_json_node_t node;
4403 u8 *status = 0;
4404 struct in_addr ip4;
4405 struct in6_addr ip6;
4406
4407 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4408 vec_add1 (status, 0);
4409
4410 vat_json_init_object (&node);
4411 vat_json_object_add_string_copy (&node, "status", status);
4412 if (mp->status)
4413 {
4414 if (mp->is_ip4)
4415 {
4416 clib_memcpy (&ip6, mp->address, sizeof (ip6));
4417 vat_json_object_add_ip6 (&node, "address", ip6);
4418 }
4419 else
4420 {
4421 clib_memcpy (&ip4, mp->address, sizeof (ip4));
4422 vat_json_object_add_ip4 (&node, "address", ip4);
4423 }
4424 }
4425
4426 vec_free (status);
4427
4428 vat_json_print (vam->ofp, &node);
4429 vat_json_free (&node);
4430
4431 vam->retval = ntohl (mp->retval);
4432 vam->result_ready = 1;
4433}
4434
4435static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02004436 vl_api_show_one_nsh_mapping_reply_t_handler
4437 (vl_api_show_one_nsh_mapping_reply_t * mp)
4438{
4439 vat_main_t *vam = &vat_main;
4440 i32 retval = ntohl (mp->retval);
4441
4442 if (0 <= retval)
4443 {
4444 print (vam->ofp, "%-20s%-16s",
4445 mp->is_set ? "set" : "not-set",
4446 mp->is_set ? (char *) mp->locator_set_name : "");
4447 }
4448
4449 vam->retval = retval;
4450 vam->result_ready = 1;
4451}
4452
4453static void
4454 vl_api_show_one_nsh_mapping_reply_t_handler_json
4455 (vl_api_show_one_nsh_mapping_reply_t * mp)
4456{
4457 vat_main_t *vam = &vat_main;
4458 vat_json_node_t node;
4459 u8 *status = 0;
4460
4461 status = format (0, "%s", mp->is_set ? "yes" : "no");
4462 vec_add1 (status, 0);
4463
4464 vat_json_init_object (&node);
4465 vat_json_object_add_string_copy (&node, "is_set", status);
4466 if (mp->is_set)
4467 {
4468 vat_json_object_add_string_copy (&node, "locator_set",
4469 mp->locator_set_name);
4470 }
4471
4472 vec_free (status);
4473
4474 vat_json_print (vam->ofp, &node);
4475 vat_json_free (&node);
4476
4477 vam->retval = ntohl (mp->retval);
4478 vam->result_ready = 1;
4479}
4480
4481static void
Filip Tehlar1e553a02017-08-02 12:45:07 +02004482 vl_api_show_one_map_register_ttl_reply_t_handler
4483 (vl_api_show_one_map_register_ttl_reply_t * mp)
4484{
4485 vat_main_t *vam = &vat_main;
4486 i32 retval = ntohl (mp->retval);
4487
4488 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4489
4490 if (0 <= retval)
4491 {
4492 print (vam->ofp, "ttl: %u", mp->ttl);
4493 }
4494
4495 vam->retval = retval;
4496 vam->result_ready = 1;
4497}
4498
4499static void
4500 vl_api_show_one_map_register_ttl_reply_t_handler_json
4501 (vl_api_show_one_map_register_ttl_reply_t * mp)
4502{
4503 vat_main_t *vam = &vat_main;
4504 vat_json_node_t node;
4505
4506 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4507 vat_json_init_object (&node);
4508 vat_json_object_add_uint (&node, "ttl", mp->ttl);
4509
4510 vat_json_print (vam->ofp, &node);
4511 vat_json_free (&node);
4512
4513 vam->retval = ntohl (mp->retval);
4514 vam->result_ready = 1;
4515}
4516
4517static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004518vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004519{
4520 vat_main_t *vam = &vat_main;
4521 i32 retval = ntohl (mp->retval);
4522
4523 if (0 <= retval)
4524 {
4525 print (vam->ofp, "%-20s%-16s",
4526 mp->status ? "enabled" : "disabled",
4527 mp->status ? (char *) mp->locator_set_name : "");
4528 }
4529
4530 vam->retval = retval;
4531 vam->result_ready = 1;
4532}
4533
4534static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004535vl_api_show_one_pitr_reply_t_handler_json (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004536{
4537 vat_main_t *vam = &vat_main;
4538 vat_json_node_t node;
4539 u8 *status = 0;
4540
4541 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4542 vec_add1 (status, 0);
4543
4544 vat_json_init_object (&node);
4545 vat_json_object_add_string_copy (&node, "status", status);
4546 if (mp->status)
4547 {
4548 vat_json_object_add_string_copy (&node, "locator_set",
4549 mp->locator_set_name);
4550 }
4551
4552 vec_free (status);
4553
4554 vat_json_print (vam->ofp, &node);
4555 vat_json_free (&node);
4556
4557 vam->retval = ntohl (mp->retval);
4558 vam->result_ready = 1;
4559}
4560
4561static u8 *
4562format_policer_type (u8 * s, va_list * va)
4563{
4564 u32 i = va_arg (*va, u32);
4565
4566 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
4567 s = format (s, "1r2c");
4568 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
4569 s = format (s, "1r3c");
4570 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
4571 s = format (s, "2r3c-2698");
4572 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
4573 s = format (s, "2r3c-4115");
4574 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
4575 s = format (s, "2r3c-mef5cf1");
4576 else
4577 s = format (s, "ILLEGAL");
4578 return s;
4579}
4580
4581static u8 *
4582format_policer_rate_type (u8 * s, va_list * va)
4583{
4584 u32 i = va_arg (*va, u32);
4585
4586 if (i == SSE2_QOS_RATE_KBPS)
4587 s = format (s, "kbps");
4588 else if (i == SSE2_QOS_RATE_PPS)
4589 s = format (s, "pps");
4590 else
4591 s = format (s, "ILLEGAL");
4592 return s;
4593}
4594
4595static u8 *
4596format_policer_round_type (u8 * s, va_list * va)
4597{
4598 u32 i = va_arg (*va, u32);
4599
4600 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
4601 s = format (s, "closest");
4602 else if (i == SSE2_QOS_ROUND_TO_UP)
4603 s = format (s, "up");
4604 else if (i == SSE2_QOS_ROUND_TO_DOWN)
4605 s = format (s, "down");
4606 else
4607 s = format (s, "ILLEGAL");
4608 return s;
4609}
4610
4611static u8 *
4612format_policer_action_type (u8 * s, va_list * va)
4613{
4614 u32 i = va_arg (*va, u32);
4615
4616 if (i == SSE2_QOS_ACTION_DROP)
4617 s = format (s, "drop");
4618 else if (i == SSE2_QOS_ACTION_TRANSMIT)
4619 s = format (s, "transmit");
4620 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4621 s = format (s, "mark-and-transmit");
4622 else
4623 s = format (s, "ILLEGAL");
4624 return s;
4625}
4626
4627static u8 *
4628format_dscp (u8 * s, va_list * va)
4629{
4630 u32 i = va_arg (*va, u32);
4631 char *t = 0;
4632
4633 switch (i)
4634 {
4635#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
4636 foreach_vnet_dscp
4637#undef _
4638 default:
4639 return format (s, "ILLEGAL");
4640 }
4641 s = format (s, "%s", t);
4642 return s;
4643}
4644
4645static void
4646vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
4647{
4648 vat_main_t *vam = &vat_main;
4649 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
4650
4651 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4652 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4653 else
4654 conform_dscp_str = format (0, "");
4655
4656 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4657 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4658 else
4659 exceed_dscp_str = format (0, "");
4660
4661 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4662 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4663 else
4664 violate_dscp_str = format (0, "");
4665
4666 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
4667 "rate type %U, round type %U, %s rate, %s color-aware, "
4668 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
4669 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
4670 "conform action %U%s, exceed action %U%s, violate action %U%s",
4671 mp->name,
4672 format_policer_type, mp->type,
4673 ntohl (mp->cir),
4674 ntohl (mp->eir),
4675 clib_net_to_host_u64 (mp->cb),
4676 clib_net_to_host_u64 (mp->eb),
4677 format_policer_rate_type, mp->rate_type,
4678 format_policer_round_type, mp->round_type,
4679 mp->single_rate ? "single" : "dual",
4680 mp->color_aware ? "is" : "not",
4681 ntohl (mp->cir_tokens_per_period),
4682 ntohl (mp->pir_tokens_per_period),
4683 ntohl (mp->scale),
4684 ntohl (mp->current_limit),
4685 ntohl (mp->current_bucket),
4686 ntohl (mp->extended_limit),
4687 ntohl (mp->extended_bucket),
4688 clib_net_to_host_u64 (mp->last_update_time),
4689 format_policer_action_type, mp->conform_action_type,
4690 conform_dscp_str,
4691 format_policer_action_type, mp->exceed_action_type,
4692 exceed_dscp_str,
4693 format_policer_action_type, mp->violate_action_type,
4694 violate_dscp_str);
4695
4696 vec_free (conform_dscp_str);
4697 vec_free (exceed_dscp_str);
4698 vec_free (violate_dscp_str);
4699}
4700
4701static void vl_api_policer_details_t_handler_json
4702 (vl_api_policer_details_t * mp)
4703{
4704 vat_main_t *vam = &vat_main;
4705 vat_json_node_t *node;
4706 u8 *rate_type_str, *round_type_str, *type_str;
4707 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
4708
4709 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
4710 round_type_str =
4711 format (0, "%U", format_policer_round_type, mp->round_type);
4712 type_str = format (0, "%U", format_policer_type, mp->type);
4713 conform_action_str = format (0, "%U", format_policer_action_type,
4714 mp->conform_action_type);
4715 exceed_action_str = format (0, "%U", format_policer_action_type,
4716 mp->exceed_action_type);
4717 violate_action_str = format (0, "%U", format_policer_action_type,
4718 mp->violate_action_type);
4719
4720 if (VAT_JSON_ARRAY != vam->json_tree.type)
4721 {
4722 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4723 vat_json_init_array (&vam->json_tree);
4724 }
4725 node = vat_json_array_add (&vam->json_tree);
4726
4727 vat_json_init_object (node);
4728 vat_json_object_add_string_copy (node, "name", mp->name);
4729 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
4730 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
Marek Gradzki59ed4902017-03-21 11:51:54 +01004731 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
4732 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
Damjan Marion7cd468a2016-12-19 23:05:39 +01004733 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
4734 vat_json_object_add_string_copy (node, "round_type", round_type_str);
4735 vat_json_object_add_string_copy (node, "type", type_str);
4736 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
4737 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
4738 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
4739 vat_json_object_add_uint (node, "cir_tokens_per_period",
4740 ntohl (mp->cir_tokens_per_period));
4741 vat_json_object_add_uint (node, "eir_tokens_per_period",
4742 ntohl (mp->pir_tokens_per_period));
4743 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
4744 vat_json_object_add_uint (node, "current_bucket",
4745 ntohl (mp->current_bucket));
4746 vat_json_object_add_uint (node, "extended_limit",
4747 ntohl (mp->extended_limit));
4748 vat_json_object_add_uint (node, "extended_bucket",
4749 ntohl (mp->extended_bucket));
4750 vat_json_object_add_uint (node, "last_update_time",
4751 ntohl (mp->last_update_time));
4752 vat_json_object_add_string_copy (node, "conform_action",
4753 conform_action_str);
4754 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4755 {
4756 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4757 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
4758 vec_free (dscp_str);
4759 }
4760 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
4761 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4762 {
4763 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4764 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
4765 vec_free (dscp_str);
4766 }
4767 vat_json_object_add_string_copy (node, "violate_action",
4768 violate_action_str);
4769 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4770 {
4771 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4772 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
4773 vec_free (dscp_str);
4774 }
4775
4776 vec_free (rate_type_str);
4777 vec_free (round_type_str);
4778 vec_free (type_str);
4779 vec_free (conform_action_str);
4780 vec_free (exceed_action_str);
4781 vec_free (violate_action_str);
4782}
4783
4784static void
4785vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
4786 mp)
4787{
4788 vat_main_t *vam = &vat_main;
4789 int i, count = ntohl (mp->count);
4790
4791 if (count > 0)
4792 print (vam->ofp, "classify table ids (%d) : ", count);
4793 for (i = 0; i < count; i++)
4794 {
4795 print (vam->ofp, "%d", ntohl (mp->ids[i]));
4796 print (vam->ofp, (i < count - 1) ? "," : "");
4797 }
4798 vam->retval = ntohl (mp->retval);
4799 vam->result_ready = 1;
4800}
4801
4802static void
4803 vl_api_classify_table_ids_reply_t_handler_json
4804 (vl_api_classify_table_ids_reply_t * mp)
4805{
4806 vat_main_t *vam = &vat_main;
4807 int i, count = ntohl (mp->count);
4808
4809 if (count > 0)
4810 {
4811 vat_json_node_t node;
4812
4813 vat_json_init_object (&node);
4814 for (i = 0; i < count; i++)
4815 {
4816 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
4817 }
4818 vat_json_print (vam->ofp, &node);
4819 vat_json_free (&node);
4820 }
4821 vam->retval = ntohl (mp->retval);
4822 vam->result_ready = 1;
4823}
4824
4825static void
4826 vl_api_classify_table_by_interface_reply_t_handler
4827 (vl_api_classify_table_by_interface_reply_t * mp)
4828{
4829 vat_main_t *vam = &vat_main;
4830 u32 table_id;
4831
4832 table_id = ntohl (mp->l2_table_id);
4833 if (table_id != ~0)
4834 print (vam->ofp, "l2 table id : %d", table_id);
4835 else
4836 print (vam->ofp, "l2 table id : No input ACL tables configured");
4837 table_id = ntohl (mp->ip4_table_id);
4838 if (table_id != ~0)
4839 print (vam->ofp, "ip4 table id : %d", table_id);
4840 else
4841 print (vam->ofp, "ip4 table id : No input ACL tables configured");
4842 table_id = ntohl (mp->ip6_table_id);
4843 if (table_id != ~0)
4844 print (vam->ofp, "ip6 table id : %d", table_id);
4845 else
4846 print (vam->ofp, "ip6 table id : No input ACL tables configured");
4847 vam->retval = ntohl (mp->retval);
4848 vam->result_ready = 1;
4849}
4850
4851static void
4852 vl_api_classify_table_by_interface_reply_t_handler_json
4853 (vl_api_classify_table_by_interface_reply_t * mp)
4854{
4855 vat_main_t *vam = &vat_main;
4856 vat_json_node_t node;
4857
4858 vat_json_init_object (&node);
4859
4860 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
4861 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
4862 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
4863
4864 vat_json_print (vam->ofp, &node);
4865 vat_json_free (&node);
4866
4867 vam->retval = ntohl (mp->retval);
4868 vam->result_ready = 1;
4869}
4870
4871static void vl_api_policer_add_del_reply_t_handler
4872 (vl_api_policer_add_del_reply_t * mp)
4873{
4874 vat_main_t *vam = &vat_main;
4875 i32 retval = ntohl (mp->retval);
4876 if (vam->async_mode)
4877 {
4878 vam->async_errors += (retval < 0);
4879 }
4880 else
4881 {
4882 vam->retval = retval;
4883 vam->result_ready = 1;
4884 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
4885 /*
4886 * Note: this is just barely thread-safe, depends on
4887 * the main thread spinning waiting for an answer...
4888 */
4889 errmsg ("policer index %d", ntohl (mp->policer_index));
4890 }
4891}
4892
4893static void vl_api_policer_add_del_reply_t_handler_json
4894 (vl_api_policer_add_del_reply_t * mp)
4895{
4896 vat_main_t *vam = &vat_main;
4897 vat_json_node_t node;
4898
4899 vat_json_init_object (&node);
4900 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4901 vat_json_object_add_uint (&node, "policer_index",
4902 ntohl (mp->policer_index));
4903
4904 vat_json_print (vam->ofp, &node);
4905 vat_json_free (&node);
4906
4907 vam->retval = ntohl (mp->retval);
4908 vam->result_ready = 1;
4909}
4910
4911/* Format hex dump. */
4912u8 *
4913format_hex_bytes (u8 * s, va_list * va)
4914{
4915 u8 *bytes = va_arg (*va, u8 *);
4916 int n_bytes = va_arg (*va, int);
4917 uword i;
4918
4919 /* Print short or long form depending on byte count. */
4920 uword short_form = n_bytes <= 32;
Christophe Fontained3c008d2017-10-02 18:10:54 +02004921 u32 indent = format_get_indent (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004922
4923 if (n_bytes == 0)
4924 return s;
4925
4926 for (i = 0; i < n_bytes; i++)
4927 {
4928 if (!short_form && (i % 32) == 0)
4929 s = format (s, "%08x: ", i);
4930 s = format (s, "%02x", bytes[i]);
4931 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
4932 s = format (s, "\n%U", format_white_space, indent);
4933 }
4934
4935 return s;
4936}
4937
4938static void
4939vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
4940 * mp)
4941{
4942 vat_main_t *vam = &vat_main;
4943 i32 retval = ntohl (mp->retval);
4944 if (retval == 0)
4945 {
4946 print (vam->ofp, "classify table info :");
4947 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
4948 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
4949 ntohl (mp->miss_next_index));
4950 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
4951 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
4952 ntohl (mp->match_n_vectors));
4953 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
4954 ntohl (mp->mask_length));
4955 }
4956 vam->retval = retval;
4957 vam->result_ready = 1;
4958}
4959
4960static void
4961 vl_api_classify_table_info_reply_t_handler_json
4962 (vl_api_classify_table_info_reply_t * mp)
4963{
4964 vat_main_t *vam = &vat_main;
4965 vat_json_node_t node;
4966
4967 i32 retval = ntohl (mp->retval);
4968 if (retval == 0)
4969 {
4970 vat_json_init_object (&node);
4971
4972 vat_json_object_add_int (&node, "sessions",
4973 ntohl (mp->active_sessions));
4974 vat_json_object_add_int (&node, "nexttbl",
4975 ntohl (mp->next_table_index));
4976 vat_json_object_add_int (&node, "nextnode",
4977 ntohl (mp->miss_next_index));
4978 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
4979 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
4980 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
4981 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
4982 ntohl (mp->mask_length), 0);
4983 vat_json_object_add_string_copy (&node, "mask", s);
4984
4985 vat_json_print (vam->ofp, &node);
4986 vat_json_free (&node);
4987 }
4988 vam->retval = ntohl (mp->retval);
4989 vam->result_ready = 1;
4990}
4991
4992static void
4993vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
4994 mp)
4995{
4996 vat_main_t *vam = &vat_main;
4997
4998 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
4999 ntohl (mp->hit_next_index), ntohl (mp->advance),
5000 ntohl (mp->opaque_index));
5001 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
5002 ntohl (mp->match_length));
5003}
5004
5005static void
5006 vl_api_classify_session_details_t_handler_json
5007 (vl_api_classify_session_details_t * mp)
5008{
5009 vat_main_t *vam = &vat_main;
5010 vat_json_node_t *node = NULL;
5011
5012 if (VAT_JSON_ARRAY != vam->json_tree.type)
5013 {
5014 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5015 vat_json_init_array (&vam->json_tree);
5016 }
5017 node = vat_json_array_add (&vam->json_tree);
5018
5019 vat_json_init_object (node);
5020 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
5021 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
5022 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
5023 u8 *s =
5024 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
5025 0);
5026 vat_json_object_add_string_copy (node, "match", s);
5027}
5028
5029static void vl_api_pg_create_interface_reply_t_handler
5030 (vl_api_pg_create_interface_reply_t * mp)
5031{
5032 vat_main_t *vam = &vat_main;
5033
5034 vam->retval = ntohl (mp->retval);
5035 vam->result_ready = 1;
5036}
5037
5038static void vl_api_pg_create_interface_reply_t_handler_json
5039 (vl_api_pg_create_interface_reply_t * mp)
5040{
5041 vat_main_t *vam = &vat_main;
5042 vat_json_node_t node;
5043
5044 i32 retval = ntohl (mp->retval);
5045 if (retval == 0)
5046 {
5047 vat_json_init_object (&node);
5048
5049 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
5050
5051 vat_json_print (vam->ofp, &node);
5052 vat_json_free (&node);
5053 }
5054 vam->retval = ntohl (mp->retval);
5055 vam->result_ready = 1;
5056}
5057
5058static void vl_api_policer_classify_details_t_handler
5059 (vl_api_policer_classify_details_t * mp)
5060{
5061 vat_main_t *vam = &vat_main;
5062
5063 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
5064 ntohl (mp->table_index));
5065}
5066
5067static void vl_api_policer_classify_details_t_handler_json
5068 (vl_api_policer_classify_details_t * mp)
5069{
5070 vat_main_t *vam = &vat_main;
5071 vat_json_node_t *node;
5072
5073 if (VAT_JSON_ARRAY != vam->json_tree.type)
5074 {
5075 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5076 vat_json_init_array (&vam->json_tree);
5077 }
5078 node = vat_json_array_add (&vam->json_tree);
5079
5080 vat_json_init_object (node);
5081 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5082 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5083}
5084
Damjan Marion7cd468a2016-12-19 23:05:39 +01005085static void vl_api_flow_classify_details_t_handler
5086 (vl_api_flow_classify_details_t * mp)
5087{
5088 vat_main_t *vam = &vat_main;
5089
5090 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
5091 ntohl (mp->table_index));
5092}
5093
5094static void vl_api_flow_classify_details_t_handler_json
5095 (vl_api_flow_classify_details_t * mp)
5096{
5097 vat_main_t *vam = &vat_main;
5098 vat_json_node_t *node;
5099
5100 if (VAT_JSON_ARRAY != vam->json_tree.type)
5101 {
5102 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5103 vat_json_init_array (&vam->json_tree);
5104 }
5105 node = vat_json_array_add (&vam->json_tree);
5106
5107 vat_json_init_object (node);
5108 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5109 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5110}
5111
Filip Tehlar694396d2017-02-17 14:29:11 +01005112#define vl_api_one_adjacencies_get_reply_t_endian vl_noop_handler
5113#define vl_api_one_adjacencies_get_reply_t_print vl_noop_handler
Filip Tehlard5a65db2017-05-17 17:21:10 +02005114#define vl_api_one_l2_arp_bd_get_reply_t_print vl_noop_handler
5115#define vl_api_one_l2_arp_entries_get_reply_t_endian vl_noop_handler
5116#define vl_api_one_l2_arp_entries_get_reply_t_print vl_noop_handler
5117#define vl_api_one_l2_arp_bd_get_reply_t_endian vl_noop_handler
Filip Tehlar05879992017-09-05 15:46:09 +02005118#define vl_api_one_ndp_bd_get_reply_t_endian vl_noop_handler
5119#define vl_api_one_ndp_bd_get_reply_t_print vl_noop_handler
5120#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
5121#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +01005122
5123/*
5124 * Generate boilerplate reply handlers, which
5125 * dig the return value out of the xxx_reply_t API message,
5126 * stick it into vam->retval, and set vam->result_ready
5127 *
5128 * Could also do this by pointing N message decode slots at
5129 * a single function, but that could break in subtle ways.
5130 */
5131
5132#define foreach_standard_reply_retval_handler \
5133_(sw_interface_set_flags_reply) \
5134_(sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005135_(sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005136_(sw_interface_set_rx_placement_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005137_(sw_interface_set_table_reply) \
5138_(sw_interface_set_mpls_enable_reply) \
5139_(sw_interface_set_vpath_reply) \
5140_(sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005141_(sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005142_(sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005143_(sw_interface_set_l2_bridge_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005144_(bridge_domain_add_del_reply) \
5145_(sw_interface_set_l2_xconnect_reply) \
5146_(l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005147_(l2fib_flush_int_reply) \
5148_(l2fib_flush_bd_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005149_(ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005150_(ip_table_add_del_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005151_(ip_mroute_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005152_(mpls_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005153_(mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005154_(mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005155_(bier_route_add_del_reply) \
5156_(bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005157_(proxy_arp_add_del_reply) \
5158_(proxy_arp_intfc_enable_disable_reply) \
5159_(sw_interface_set_unnumbered_reply) \
5160_(ip_neighbor_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005161_(reset_fib_reply) \
5162_(dhcp_proxy_config_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005163_(dhcp_proxy_set_vss_reply) \
5164_(dhcp_client_config_reply) \
5165_(set_ip_flow_hash_reply) \
5166_(sw_interface_ip6_enable_disable_reply) \
Neale Ranns3f844d02017-02-18 00:03:54 -08005167_(ip6nd_proxy_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005168_(sw_interface_ip6nd_ra_prefix_reply) \
5169_(sw_interface_ip6nd_ra_config_reply) \
5170_(set_arp_neighbor_limit_reply) \
5171_(l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005172_(sr_mpls_policy_add_reply) \
5173_(sr_mpls_policy_mod_reply) \
5174_(sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005175_(sr_policy_add_reply) \
5176_(sr_policy_mod_reply) \
5177_(sr_policy_del_reply) \
5178_(sr_localsid_add_del_reply) \
5179_(sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005180_(classify_add_del_session_reply) \
5181_(classify_set_interface_ip_table_reply) \
5182_(classify_set_interface_l2_tables_reply) \
5183_(l2tpv3_set_tunnel_cookies_reply) \
5184_(l2tpv3_interface_enable_disable_reply) \
5185_(l2tpv3_set_lookup_key_reply) \
5186_(l2_fib_clear_table_reply) \
5187_(l2_interface_efp_filter_reply) \
5188_(l2_interface_vlan_tag_rewrite_reply) \
5189_(modify_vhost_user_if_reply) \
5190_(delete_vhost_user_if_reply) \
John Loc7b43042018-04-13 16:46:22 -04005191_(ip_probe_neighbor_reply) \
John Lo7f358b32018-04-28 01:19:24 -04005192_(ip_scan_neighbor_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005193_(want_ip4_arp_events_reply) \
5194_(want_ip6_nd_events_reply) \
John Lo8d00fff2017-08-03 00:35:36 -04005195_(want_l2_macs_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005196_(input_acl_set_interface_reply) \
5197_(ipsec_spd_add_del_reply) \
5198_(ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005199_(ipsec_spd_entry_add_del_reply) \
5200_(ipsec_sad_entry_add_del_reply) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005201_(ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005202_(ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005203_(delete_loopback_reply) \
5204_(bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005205_(bd_ip_mac_flush_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005206_(want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005207_(cop_interface_enable_disable_reply) \
5208_(cop_whitelist_enable_disable_reply) \
5209_(sw_interface_clear_stats_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005210_(ioam_enable_reply) \
5211_(ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005212_(one_add_del_locator_reply) \
5213_(one_add_del_local_eid_reply) \
5214_(one_add_del_remote_mapping_reply) \
5215_(one_add_del_adjacency_reply) \
5216_(one_add_del_map_resolver_reply) \
5217_(one_add_del_map_server_reply) \
5218_(one_enable_disable_reply) \
5219_(one_rloc_probe_enable_disable_reply) \
5220_(one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005221_(one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005222_(one_set_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005223_(one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005224_(one_pitr_set_locator_set_reply) \
5225_(one_map_request_mode_reply) \
5226_(one_add_del_map_request_itr_rlocs_reply) \
5227_(one_eid_table_add_del_map_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005228_(one_use_petr_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005229_(one_stats_enable_disable_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005230_(one_add_del_l2_arp_entry_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005231_(one_add_del_ndp_entry_reply) \
Filip Tehlar21511912017-04-07 10:41:42 +02005232_(one_stats_flush_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005233_(one_enable_disable_xtr_mode_reply) \
5234_(one_enable_disable_pitr_mode_reply) \
5235_(one_enable_disable_petr_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005236_(gpe_enable_disable_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005237_(gpe_set_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005238_(gpe_add_del_iface_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005239_(gpe_add_del_native_fwd_rpath_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005240_(af_packet_delete_reply) \
5241_(policer_classify_set_interface_reply) \
5242_(netmap_create_reply) \
5243_(netmap_delete_reply) \
5244_(set_ipfix_exporter_reply) \
5245_(set_ipfix_classify_stream_reply) \
5246_(ipfix_classify_table_add_del_reply) \
5247_(flow_classify_set_interface_reply) \
5248_(sw_interface_span_enable_disable_reply) \
5249_(pg_capture_reply) \
5250_(pg_enable_disable_reply) \
5251_(ip_source_and_port_range_check_add_del_reply) \
5252_(ip_source_and_port_range_check_interface_add_del_reply)\
5253_(delete_subif_reply) \
5254_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005255_(set_punt_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005256_(feature_enable_disable_reply) \
5257_(sw_interface_tag_add_del_reply) \
Ole Troand7231612018-06-07 10:17:57 +02005258_(hw_interface_set_mtu_reply) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005259_(p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005260_(p2p_ethernet_del_reply) \
5261_(lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005262_(sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005263_(tcp_configure_src_addresses_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005264_(dns_enable_disable_reply) \
Florin Coras1c710452017-10-17 00:03:13 -07005265_(dns_name_server_add_del_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005266_(session_rule_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005267_(ip_container_proxy_add_del_reply) \
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -07005268_(output_acl_set_interface_reply) \
5269_(qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005270
5271#define _(n) \
5272 static void vl_api_##n##_t_handler \
5273 (vl_api_##n##_t * mp) \
5274 { \
5275 vat_main_t * vam = &vat_main; \
5276 i32 retval = ntohl(mp->retval); \
5277 if (vam->async_mode) { \
5278 vam->async_errors += (retval < 0); \
5279 } else { \
5280 vam->retval = retval; \
5281 vam->result_ready = 1; \
5282 } \
5283 }
5284foreach_standard_reply_retval_handler;
5285#undef _
5286
5287#define _(n) \
5288 static void vl_api_##n##_t_handler_json \
5289 (vl_api_##n##_t * mp) \
5290 { \
5291 vat_main_t * vam = &vat_main; \
5292 vat_json_node_t node; \
5293 vat_json_init_object(&node); \
5294 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
5295 vat_json_print(vam->ofp, &node); \
5296 vam->retval = ntohl(mp->retval); \
5297 vam->result_ready = 1; \
5298 }
5299foreach_standard_reply_retval_handler;
5300#undef _
5301
5302/*
5303 * Table of message reply handlers, must include boilerplate handlers
5304 * we just generated
5305 */
5306
5307#define foreach_vpe_api_reply_msg \
5308_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005309_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005310_(SW_INTERFACE_DETAILS, sw_interface_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005311_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
5312_(CONTROL_PING_REPLY, control_ping_reply) \
5313_(CLI_REPLY, cli_reply) \
5314_(CLI_INBAND_REPLY, cli_inband_reply) \
5315_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
5316 sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005317_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005318_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02005319_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005320_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
5321_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
5322_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
5323_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005324_(SW_INTERFACE_SET_GENEVE_BYPASS_REPLY, sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005325_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005326_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
5327 sw_interface_set_l2_xconnect_reply) \
5328_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
5329 sw_interface_set_l2_bridge_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005330_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
5331_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
Eyal Barifead6702017-04-04 04:46:32 +03005332_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005333_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005334_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
5335_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005336_(L2_FLAGS_REPLY, l2_flags_reply) \
5337_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
Damjan Marion8389fb92017-10-13 18:29:53 +02005338_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
5339_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
5340_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01005341_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
5342_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
5343_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
Steven9cd2d7a2017-12-20 12:43:01 -08005344_(BOND_CREATE_REPLY, bond_create_reply) \
5345_(BOND_DELETE_REPLY, bond_delete_reply) \
5346_(BOND_ENSLAVE_REPLY, bond_enslave_reply) \
5347_(BOND_DETACH_SLAVE_REPLY, bond_detach_slave_reply) \
5348_(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details) \
5349_(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005350_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005351_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005352_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005353_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005354_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
5355_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005356_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
5357_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005358_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
5359_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
5360 proxy_arp_intfc_enable_disable_reply) \
5361_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
5362_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
5363 sw_interface_set_unnumbered_reply) \
5364_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005365_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
5366_(CREATE_SUBIF_REPLY, create_subif_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005367_(RESET_FIB_REPLY, reset_fib_reply) \
5368_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005369_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
Neale Ranns20a175a2017-02-14 07:28:41 -08005370_(DHCP_PROXY_DETAILS, dhcp_proxy_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005371_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
5372_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
5373_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
5374 sw_interface_ip6_enable_disable_reply) \
Neale Ranns3f844d02017-02-18 00:03:54 -08005375_(IP6ND_PROXY_ADD_DEL_REPLY, ip6nd_proxy_add_del_reply) \
5376_(IP6ND_PROXY_DETAILS, ip6nd_proxy_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005377_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
5378 sw_interface_ip6nd_ra_prefix_reply) \
5379_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
5380 sw_interface_ip6nd_ra_config_reply) \
5381_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
5382_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005383_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
5384_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
5385_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005386_(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
5387_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
5388_(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
5389_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
5390_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005391_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
5392_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
5393_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
5394classify_set_interface_ip_table_reply) \
5395_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
5396 classify_set_interface_l2_tables_reply) \
5397_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
5398_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
5399_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
5400_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
5401_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
5402 l2tpv3_interface_enable_disable_reply) \
5403_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
5404_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
5405_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
eyal bariaf86a482018-04-17 11:20:27 +03005406_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005407_(GENEVE_ADD_DEL_TUNNEL_REPLY, geneve_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005408_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005409_(GENEVE_TUNNEL_DETAILS, geneve_tunnel_details) \
Neale Ranns5a8844b2019-04-16 07:15:35 +00005410_(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005411_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
5412_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
5413_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
5414_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
5415_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
5416_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
5417_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
5418_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
5419_(SHOW_VERSION_REPLY, show_version_reply) \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02005420_(SHOW_THREADS_REPLY, show_threads_reply) \
Ole Troan01384fe2017-05-12 11:55:35 +02005421_(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
John Loc7b43042018-04-13 16:46:22 -04005422_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005423_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
5424_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
John Loc7b43042018-04-13 16:46:22 -04005425_(IP_PROBE_NEIGHBOR_REPLY, ip_probe_neighbor_reply) \
John Lo7f358b32018-04-28 01:19:24 -04005426_(IP_SCAN_NEIGHBOR_ENABLE_DISABLE_REPLY, ip_scan_neighbor_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005427_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
5428_(IP4_ARP_EVENT, ip4_arp_event) \
5429_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
5430_(IP6_ND_EVENT, ip6_nd_event) \
John Lo8d00fff2017-08-03 00:35:36 -04005431_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
5432_(L2_MACS_EVENT, l2_macs_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005433_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
5434_(IP_ADDRESS_DETAILS, ip_address_details) \
5435_(IP_DETAILS, ip_details) \
5436_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
5437_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005438_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
5439_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
Matthew Smith28029532017-09-26 13:33:44 -05005440_(IPSEC_SA_DETAILS, ipsec_sa_details) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005441_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005442_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005443_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
5444_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005445_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02005446_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005447_(DHCP_COMPL_EVENT, dhcp_compl_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005448_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005449_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
5450_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
5451_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
5452_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
5453_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
5454_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
5455_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005456_(ONE_ADD_DEL_LOCATOR_SET_REPLY, one_add_del_locator_set_reply) \
5457_(ONE_ADD_DEL_LOCATOR_REPLY, one_add_del_locator_reply) \
5458_(ONE_ADD_DEL_LOCAL_EID_REPLY, one_add_del_local_eid_reply) \
5459_(ONE_ADD_DEL_REMOTE_MAPPING_REPLY, one_add_del_remote_mapping_reply) \
5460_(ONE_ADD_DEL_ADJACENCY_REPLY, one_add_del_adjacency_reply) \
5461_(ONE_ADD_DEL_MAP_RESOLVER_REPLY, one_add_del_map_resolver_reply) \
5462_(ONE_ADD_DEL_MAP_SERVER_REPLY, one_add_del_map_server_reply) \
5463_(ONE_ENABLE_DISABLE_REPLY, one_enable_disable_reply) \
5464_(ONE_MAP_REGISTER_ENABLE_DISABLE_REPLY, \
5465 one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005466_(ONE_MAP_REGISTER_SET_TTL_REPLY, one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005467_(ONE_SET_TRANSPORT_PROTOCOL_REPLY, one_set_transport_protocol_reply) \
5468_(ONE_GET_TRANSPORT_PROTOCOL_REPLY, one_get_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005469_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5470 one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005471_(ONE_RLOC_PROBE_ENABLE_DISABLE_REPLY, \
5472 one_rloc_probe_enable_disable_reply) \
5473_(ONE_PITR_SET_LOCATOR_SET_REPLY, one_pitr_set_locator_set_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005474_(ONE_USE_PETR_REPLY, one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005475_(ONE_MAP_REQUEST_MODE_REPLY, one_map_request_mode_reply) \
5476_(ONE_EID_TABLE_ADD_DEL_MAP_REPLY, one_eid_table_add_del_map_reply) \
5477_(ONE_LOCATOR_SET_DETAILS, one_locator_set_details) \
5478_(ONE_LOCATOR_DETAILS, one_locator_details) \
5479_(ONE_EID_TABLE_DETAILS, one_eid_table_details) \
5480_(ONE_EID_TABLE_MAP_DETAILS, one_eid_table_map_details) \
5481_(ONE_EID_TABLE_VNI_DETAILS, one_eid_table_vni_details) \
5482_(ONE_MAP_RESOLVER_DETAILS, one_map_resolver_details) \
5483_(ONE_MAP_SERVER_DETAILS, one_map_server_details) \
5484_(ONE_ADJACENCIES_GET_REPLY, one_adjacencies_get_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005485_(ONE_STATS_DETAILS, one_stats_details) \
Filip Tehlar21511912017-04-07 10:41:42 +02005486_(ONE_STATS_FLUSH_REPLY, one_stats_flush_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005487_(ONE_STATS_ENABLE_DISABLE_REPLY, one_stats_enable_disable_reply) \
5488_(SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, \
5489 show_one_stats_enable_disable_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005490_(ONE_ADD_DEL_NDP_ENTRY_REPLY, one_add_del_ndp_entry_reply) \
5491_(ONE_NDP_BD_GET_REPLY, one_ndp_bd_get_reply) \
5492_(ONE_NDP_ENTRIES_GET_REPLY, one_ndp_entries_get_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005493_(ONE_ADD_DEL_L2_ARP_ENTRY_REPLY, one_add_del_l2_arp_entry_reply) \
5494_(ONE_L2_ARP_BD_GET_REPLY, one_l2_arp_bd_get_reply) \
5495_(ONE_L2_ARP_ENTRIES_GET_REPLY, one_l2_arp_entries_get_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005496_(ONE_ENABLE_DISABLE_XTR_MODE_REPLY, one_enable_disable_xtr_mode_reply) \
5497_(ONE_ENABLE_DISABLE_PITR_MODE_REPLY, \
5498 one_enable_disable_pitr_mode_reply) \
5499_(ONE_ENABLE_DISABLE_PETR_MODE_REPLY, \
5500 one_enable_disable_petr_mode_reply) \
5501_(ONE_SHOW_XTR_MODE_REPLY, one_show_xtr_mode_reply) \
5502_(ONE_SHOW_PITR_MODE_REPLY, one_show_pitr_mode_reply) \
5503_(ONE_SHOW_PETR_MODE_REPLY, one_show_petr_mode_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005504_(GPE_SET_ENCAP_MODE_REPLY, gpe_set_encap_mode_reply) \
5505_(GPE_GET_ENCAP_MODE_REPLY, gpe_get_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005506_(GPE_ADD_DEL_IFACE_REPLY, gpe_add_del_iface_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005507_(GPE_ENABLE_DISABLE_REPLY, gpe_enable_disable_reply) \
5508_(GPE_ADD_DEL_FWD_ENTRY_REPLY, gpe_add_del_fwd_entry_reply) \
Filip Tehlar0eb874e2017-05-18 14:23:32 +02005509_(GPE_FWD_ENTRY_VNIS_GET_REPLY, gpe_fwd_entry_vnis_get_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005510_(GPE_FWD_ENTRIES_GET_REPLY, gpe_fwd_entries_get_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005511_(GPE_NATIVE_FWD_RPATHS_GET_REPLY, gpe_native_fwd_rpaths_get_reply) \
5512_(GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY, \
5513 gpe_add_del_native_fwd_rpath_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005514_(GPE_FWD_ENTRY_PATH_DETAILS, \
5515 gpe_fwd_entry_path_details) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005516_(SHOW_ONE_STATUS_REPLY, show_one_status_reply) \
5517_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
5518 one_add_del_map_request_itr_rlocs_reply) \
5519_(ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
5520 one_get_map_request_itr_rlocs_reply) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02005521_(SHOW_ONE_NSH_MAPPING_REPLY, show_one_nsh_mapping_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005522_(SHOW_ONE_PITR_REPLY, show_one_pitr_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005523_(SHOW_ONE_USE_PETR_REPLY, show_one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005524_(SHOW_ONE_MAP_REQUEST_MODE_REPLY, show_one_map_request_mode_reply) \
5525_(SHOW_ONE_RLOC_PROBE_STATE_REPLY, show_one_rloc_probe_state_reply) \
5526_(SHOW_ONE_MAP_REGISTER_STATE_REPLY, \
5527 show_one_map_register_state_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005528_(SHOW_ONE_MAP_REGISTER_TTL_REPLY, show_one_map_register_ttl_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005529_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5530 show_one_map_register_fallback_threshold_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005531_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
5532_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +02005533_(AF_PACKET_DETAILS, af_packet_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005534_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
5535_(POLICER_DETAILS, policer_details) \
5536_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
5537_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
5538_(NETMAP_CREATE_REPLY, netmap_create_reply) \
5539_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
5540_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005541_(MPLS_TABLE_DETAILS, mpls_table_details) \
5542_(MPLS_ROUTE_DETAILS, mpls_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005543_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
5544_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
5545_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
5546_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
5547_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
5548_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
5549_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
5550_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
5551_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
5552_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
5553_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
5554_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
5555_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
5556_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
5557_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
5558_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
5559_(PG_CAPTURE_REPLY, pg_capture_reply) \
5560_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
5561_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
5562 ip_source_and_port_range_check_add_del_reply) \
5563_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
5564 ip_source_and_port_range_check_interface_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005565_(DELETE_SUBIF_REPLY, delete_subif_reply) \
5566_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005567_(SET_PUNT_REPLY, set_punt_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005568_(IP_TABLE_DETAILS, ip_table_details) \
5569_(IP_ROUTE_DETAILS, ip_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005570_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
5571_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
5572_(L2_XCONNECT_DETAILS, l2_xconnect_details) \
Ole Troand7231612018-06-07 10:17:57 +02005573_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005574_(IP_NEIGHBOR_DETAILS, ip_neighbor_details) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005575_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
5576_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005577_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
5578_(LLDP_CONFIG_REPLY, lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005579_(SW_INTERFACE_SET_LLDP_REPLY, sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005580_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005581_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
5582_(DNS_ENABLE_DISABLE_REPLY, dns_enable_disable_reply) \
5583_(DNS_NAME_SERVER_ADD_DEL_REPLY, dns_name_server_add_del_reply) \
Dave Barachd2080152017-10-20 09:21:35 -04005584_(DNS_RESOLVE_NAME_REPLY, dns_resolve_name_reply) \
Florin Coras1c710452017-10-17 00:03:13 -07005585_(DNS_RESOLVE_IP_REPLY, dns_resolve_ip_reply) \
Florin Coras6c36f532017-11-03 18:32:34 -07005586_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005587_(SESSION_RULES_DETAILS, session_rules_details) \
5588_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005589_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
Ole Troane906aac2018-06-14 14:42:14 +02005590_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005591
Dave Baracha1a093d2017-03-02 13:13:23 -05005592#define foreach_standalone_reply_msg \
Ole Troanf49ba0e2018-11-13 14:04:50 +01005593_(SW_INTERFACE_EVENT, sw_interface_event)
Dave Baracha1a093d2017-03-02 13:13:23 -05005594
Damjan Marion7cd468a2016-12-19 23:05:39 +01005595typedef struct
5596{
5597 u8 *name;
5598 u32 value;
5599} name_sort_t;
5600
Damjan Marion7cd468a2016-12-19 23:05:39 +01005601#define STR_VTR_OP_CASE(op) \
5602 case L2_VTR_ ## op: \
5603 return "" # op;
5604
5605static const char *
5606str_vtr_op (u32 vtr_op)
5607{
5608 switch (vtr_op)
5609 {
5610 STR_VTR_OP_CASE (DISABLED);
5611 STR_VTR_OP_CASE (PUSH_1);
5612 STR_VTR_OP_CASE (PUSH_2);
5613 STR_VTR_OP_CASE (POP_1);
5614 STR_VTR_OP_CASE (POP_2);
5615 STR_VTR_OP_CASE (TRANSLATE_1_1);
5616 STR_VTR_OP_CASE (TRANSLATE_1_2);
5617 STR_VTR_OP_CASE (TRANSLATE_2_1);
5618 STR_VTR_OP_CASE (TRANSLATE_2_2);
5619 }
5620
5621 return "UNKNOWN";
5622}
5623
5624static int
5625dump_sub_interface_table (vat_main_t * vam)
5626{
5627 const sw_interface_subif_t *sub = NULL;
5628
5629 if (vam->json_output)
5630 {
5631 clib_warning
5632 ("JSON output supported only for VPE API calls and dump_stats_table");
5633 return -99;
5634 }
5635
5636 print (vam->ofp,
5637 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
5638 "Interface", "sw_if_index",
5639 "sub id", "dot1ad", "tags", "outer id",
5640 "inner id", "exact", "default", "outer any", "inner any");
5641
5642 vec_foreach (sub, vam->sw_if_subif_table)
5643 {
5644 print (vam->ofp,
5645 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
5646 sub->interface_name,
5647 sub->sw_if_index,
5648 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
5649 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
5650 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
5651 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
5652 if (sub->vtr_op != L2_VTR_DISABLED)
5653 {
5654 print (vam->ofp,
5655 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
5656 "tag1: %d tag2: %d ]",
5657 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
5658 sub->vtr_tag1, sub->vtr_tag2);
5659 }
5660 }
5661
5662 return 0;
5663}
5664
5665static int
5666name_sort_cmp (void *a1, void *a2)
5667{
5668 name_sort_t *n1 = a1;
5669 name_sort_t *n2 = a2;
5670
5671 return strcmp ((char *) n1->name, (char *) n2->name);
5672}
5673
5674static int
5675dump_interface_table (vat_main_t * vam)
5676{
5677 hash_pair_t *p;
5678 name_sort_t *nses = 0, *ns;
5679
5680 if (vam->json_output)
5681 {
5682 clib_warning
5683 ("JSON output supported only for VPE API calls and dump_stats_table");
5684 return -99;
5685 }
5686
5687 /* *INDENT-OFF* */
5688 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5689 ({
5690 vec_add2 (nses, ns, 1);
5691 ns->name = (u8 *)(p->key);
5692 ns->value = (u32) p->value[0];
5693 }));
5694 /* *INDENT-ON* */
5695
5696 vec_sort_with_function (nses, name_sort_cmp);
5697
5698 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
5699 vec_foreach (ns, nses)
5700 {
5701 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
5702 }
5703 vec_free (nses);
5704 return 0;
5705}
5706
5707static int
5708dump_ip_table (vat_main_t * vam, int is_ipv6)
5709{
5710 const ip_details_t *det = NULL;
5711 const ip_address_details_t *address = NULL;
5712 u32 i = ~0;
5713
5714 print (vam->ofp, "%-12s", "sw_if_index");
5715
5716 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
5717 {
5718 i++;
5719 if (!det->present)
5720 {
5721 continue;
5722 }
5723 print (vam->ofp, "%-12d", i);
5724 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
5725 if (!det->addr)
5726 {
5727 continue;
5728 }
5729 vec_foreach (address, det->addr)
5730 {
5731 print (vam->ofp,
5732 " %-30U%-13d",
5733 is_ipv6 ? format_ip6_address : format_ip4_address,
5734 address->ip, address->prefix_length);
5735 }
5736 }
5737
5738 return 0;
5739}
5740
5741static int
5742dump_ipv4_table (vat_main_t * vam)
5743{
5744 if (vam->json_output)
5745 {
5746 clib_warning
5747 ("JSON output supported only for VPE API calls and dump_stats_table");
5748 return -99;
5749 }
5750
5751 return dump_ip_table (vam, 0);
5752}
5753
5754static int
5755dump_ipv6_table (vat_main_t * vam)
5756{
5757 if (vam->json_output)
5758 {
5759 clib_warning
5760 ("JSON output supported only for VPE API calls and dump_stats_table");
5761 return -99;
5762 }
5763
5764 return dump_ip_table (vam, 1);
5765}
5766
Damjan Marion7cd468a2016-12-19 23:05:39 +01005767/*
Dave Barach59b25652017-09-10 15:04:27 -04005768 * Pass CLI buffers directly in the CLI_INBAND API message,
5769 * instead of an additional shared memory area.
Damjan Marion7cd468a2016-12-19 23:05:39 +01005770 */
5771static int
5772exec_inband (vat_main_t * vam)
5773{
5774 vl_api_cli_inband_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005775 unformat_input_t *i = vam->input;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005776 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005777
5778 if (vec_len (i->buffer) == 0)
5779 return -1;
5780
5781 if (vam->exec_mode == 0 && unformat (i, "mode"))
5782 {
5783 vam->exec_mode = 1;
5784 return 0;
5785 }
5786 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
5787 {
5788 vam->exec_mode = 0;
5789 return 0;
5790 }
5791
5792 /*
5793 * In order for the CLI command to work, it
5794 * must be a vector ending in \n, not a C-string ending
5795 * in \n\0.
5796 */
5797 u32 len = vec_len (vam->input->buffer);
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005798 M2 (CLI_INBAND, mp, len);
Ole Troan884f0af2018-12-14 20:34:29 +01005799 vl_api_to_api_string (len - 1, (const char *) vam->input->buffer, &mp->cmd);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005800
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005801 S (mp);
Dave Barach59b25652017-09-10 15:04:27 -04005802 W (ret);
5803 /* json responses may or may not include a useful reply... */
5804 if (vec_len (vam->cmd_reply))
Dave Barachcf5e8482017-10-17 11:48:29 -04005805 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
Jon Loeliger56c7b012017-02-01 12:31:41 -06005806 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005807}
5808
Dave Barach59b25652017-09-10 15:04:27 -04005809int
5810exec (vat_main_t * vam)
5811{
5812 return exec_inband (vam);
5813}
5814
Damjan Marion7cd468a2016-12-19 23:05:39 +01005815static int
5816api_create_loopback (vat_main_t * vam)
5817{
5818 unformat_input_t *i = vam->input;
5819 vl_api_create_loopback_t *mp;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005820 vl_api_create_loopback_instance_t *mp_lbi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005821 u8 mac_address[6];
5822 u8 mac_set = 0;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005823 u8 is_specified = 0;
5824 u32 user_instance = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005825 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005826
Dave Barachb7b92992018-10-17 10:38:51 -04005827 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01005828
5829 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5830 {
5831 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5832 mac_set = 1;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005833 if (unformat (i, "instance %d", &user_instance))
5834 is_specified = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005835 else
5836 break;
5837 }
5838
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005839 if (is_specified)
5840 {
5841 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
5842 mp_lbi->is_specified = is_specified;
5843 if (is_specified)
5844 mp_lbi->user_instance = htonl (user_instance);
5845 if (mac_set)
5846 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
5847 S (mp_lbi);
5848 }
5849 else
5850 {
5851 /* Construct the API message */
5852 M (CREATE_LOOPBACK, mp);
5853 if (mac_set)
5854 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
5855 S (mp);
5856 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01005857
Jon Loeliger56c7b012017-02-01 12:31:41 -06005858 W (ret);
5859 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005860}
5861
5862static int
5863api_delete_loopback (vat_main_t * vam)
5864{
5865 unformat_input_t *i = vam->input;
5866 vl_api_delete_loopback_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005867 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005868 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005869
5870 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5871 {
5872 if (unformat (i, "sw_if_index %d", &sw_if_index))
5873 ;
5874 else
5875 break;
5876 }
5877
5878 if (sw_if_index == ~0)
5879 {
5880 errmsg ("missing sw_if_index");
5881 return -99;
5882 }
5883
5884 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005885 M (DELETE_LOOPBACK, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005886 mp->sw_if_index = ntohl (sw_if_index);
5887
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005888 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005889 W (ret);
5890 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005891}
5892
5893static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01005894api_want_interface_events (vat_main_t * vam)
5895{
5896 unformat_input_t *i = vam->input;
5897 vl_api_want_interface_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005898 int enable = -1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005899 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005900
5901 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5902 {
5903 if (unformat (i, "enable"))
5904 enable = 1;
5905 else if (unformat (i, "disable"))
5906 enable = 0;
5907 else
5908 break;
5909 }
5910
5911 if (enable == -1)
5912 {
5913 errmsg ("missing enable|disable");
5914 return -99;
5915 }
5916
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005917 M (WANT_INTERFACE_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005918 mp->enable_disable = enable;
5919
5920 vam->interface_event_display = enable;
5921
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005922 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005923 W (ret);
5924 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005925}
5926
5927
5928/* Note: non-static, called once to set up the initial intfc table */
5929int
5930api_sw_interface_dump (vat_main_t * vam)
5931{
5932 vl_api_sw_interface_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005933 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005934 hash_pair_t *p;
5935 name_sort_t *nses = 0, *ns;
5936 sw_interface_subif_t *sub = NULL;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005937 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005938
5939 /* Toss the old name table */
5940 /* *INDENT-OFF* */
5941 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5942 ({
5943 vec_add2 (nses, ns, 1);
5944 ns->name = (u8 *)(p->key);
5945 ns->value = (u32) p->value[0];
5946 }));
5947 /* *INDENT-ON* */
5948
5949 hash_free (vam->sw_if_index_by_interface_name);
5950
5951 vec_foreach (ns, nses) vec_free (ns->name);
5952
5953 vec_free (nses);
5954
5955 vec_foreach (sub, vam->sw_if_subif_table)
5956 {
5957 vec_free (sub->interface_name);
5958 }
5959 vec_free (vam->sw_if_subif_table);
5960
5961 /* recreate the interface name hash table */
5962 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
5963
Dave Barachf72212e2018-01-11 10:25:07 -05005964 /*
5965 * Ask for all interface names. Otherwise, the epic catalog of
5966 * name filters becomes ridiculously long, and vat ends up needing
5967 * to be taught about new interface types.
5968 */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005969 M (SW_INTERFACE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005970 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005971
5972 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04005973 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005974 S (mp_ping);
5975
Jon Loeliger56c7b012017-02-01 12:31:41 -06005976 W (ret);
5977 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005978}
5979
5980static int
5981api_sw_interface_set_flags (vat_main_t * vam)
5982{
5983 unformat_input_t *i = vam->input;
5984 vl_api_sw_interface_set_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005985 u32 sw_if_index;
5986 u8 sw_if_index_set = 0;
Neale Rannsa07bd702017-08-07 07:53:49 -07005987 u8 admin_up = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005988 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005989
5990 /* Parse args required to build the message */
5991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5992 {
5993 if (unformat (i, "admin-up"))
5994 admin_up = 1;
5995 else if (unformat (i, "admin-down"))
5996 admin_up = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005997 else
5998 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5999 sw_if_index_set = 1;
6000 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6001 sw_if_index_set = 1;
6002 else
6003 break;
6004 }
6005
6006 if (sw_if_index_set == 0)
6007 {
6008 errmsg ("missing interface name or sw_if_index");
6009 return -99;
6010 }
6011
6012 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006013 M (SW_INTERFACE_SET_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006014 mp->sw_if_index = ntohl (sw_if_index);
Ole Trøan3b0d7e42019-03-15 16:14:41 +00006015 mp->admin_up_down = admin_up;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006016
6017 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006018 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006019
6020 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006021 W (ret);
6022 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006023}
6024
6025static int
Stevenad8015b2017-10-29 22:10:46 -07006026api_sw_interface_set_rx_mode (vat_main_t * vam)
6027{
6028 unformat_input_t *i = vam->input;
6029 vl_api_sw_interface_set_rx_mode_t *mp;
6030 u32 sw_if_index;
6031 u8 sw_if_index_set = 0;
6032 int ret;
6033 u8 queue_id_valid = 0;
6034 u32 queue_id;
6035 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
6036
6037 /* Parse args required to build the message */
6038 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6039 {
6040 if (unformat (i, "queue %d", &queue_id))
6041 queue_id_valid = 1;
6042 else if (unformat (i, "polling"))
6043 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
6044 else if (unformat (i, "interrupt"))
6045 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
6046 else if (unformat (i, "adaptive"))
6047 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
6048 else
6049 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6050 sw_if_index_set = 1;
6051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6052 sw_if_index_set = 1;
6053 else
6054 break;
6055 }
6056
6057 if (sw_if_index_set == 0)
6058 {
6059 errmsg ("missing interface name or sw_if_index");
6060 return -99;
6061 }
6062 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
6063 {
6064 errmsg ("missing rx-mode");
6065 return -99;
6066 }
6067
6068 /* Construct the API message */
6069 M (SW_INTERFACE_SET_RX_MODE, mp);
6070 mp->sw_if_index = ntohl (sw_if_index);
6071 mp->mode = mode;
6072 mp->queue_id_valid = queue_id_valid;
6073 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
6074
6075 /* send it... */
6076 S (mp);
6077
6078 /* Wait for a reply, return the good/bad news... */
6079 W (ret);
6080 return ret;
6081}
6082
6083static int
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006084api_sw_interface_set_rx_placement (vat_main_t * vam)
6085{
6086 unformat_input_t *i = vam->input;
6087 vl_api_sw_interface_set_rx_placement_t *mp;
6088 u32 sw_if_index;
6089 u8 sw_if_index_set = 0;
6090 int ret;
6091 u8 is_main = 0;
6092 u32 queue_id, thread_index;
6093
6094 /* Parse args required to build the message */
6095 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6096 {
6097 if (unformat (i, "queue %d", &queue_id))
6098 ;
6099 else if (unformat (i, "main"))
6100 is_main = 1;
6101 else if (unformat (i, "worker %d", &thread_index))
6102 ;
6103 else
6104 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6105 sw_if_index_set = 1;
6106 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6107 sw_if_index_set = 1;
6108 else
6109 break;
6110 }
6111
6112 if (sw_if_index_set == 0)
6113 {
6114 errmsg ("missing interface name or sw_if_index");
6115 return -99;
6116 }
6117
6118 if (is_main)
6119 thread_index = 0;
6120 /* Construct the API message */
6121 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
6122 mp->sw_if_index = ntohl (sw_if_index);
6123 mp->worker_id = ntohl (thread_index);
6124 mp->queue_id = ntohl (queue_id);
6125 mp->is_main = is_main;
6126
6127 /* send it... */
6128 S (mp);
6129 /* Wait for a reply, return the good/bad news... */
6130 W (ret);
6131 return ret;
6132}
6133
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02006134static void vl_api_sw_interface_rx_placement_details_t_handler
6135 (vl_api_sw_interface_rx_placement_details_t * mp)
6136{
6137 vat_main_t *vam = &vat_main;
6138 u32 worker_id = ntohl (mp->worker_id);
6139
6140 print (vam->ofp,
6141 "\n%-11d %-11s %-6d %-5d %-9s",
6142 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
6143 worker_id, ntohl (mp->queue_id),
6144 (mp->mode ==
6145 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
6146}
6147
6148static void vl_api_sw_interface_rx_placement_details_t_handler_json
6149 (vl_api_sw_interface_rx_placement_details_t * mp)
6150{
6151 vat_main_t *vam = &vat_main;
6152 vat_json_node_t *node = NULL;
6153
6154 if (VAT_JSON_ARRAY != vam->json_tree.type)
6155 {
6156 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6157 vat_json_init_array (&vam->json_tree);
6158 }
6159 node = vat_json_array_add (&vam->json_tree);
6160
6161 vat_json_init_object (node);
6162 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6163 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
6164 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
6165 vat_json_object_add_uint (node, "mode", mp->mode);
6166}
6167
6168static int
6169api_sw_interface_rx_placement_dump (vat_main_t * vam)
6170{
6171 unformat_input_t *i = vam->input;
6172 vl_api_sw_interface_rx_placement_dump_t *mp;
6173 vl_api_control_ping_t *mp_ping;
6174 int ret;
6175 u32 sw_if_index;
6176 u8 sw_if_index_set = 0;
6177
6178 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6179 {
6180 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6181 sw_if_index_set++;
6182 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6183 sw_if_index_set++;
6184 else
6185 break;
6186 }
6187
6188 print (vam->ofp,
6189 "\n%-11s %-11s %-6s %-5s %-4s",
6190 "sw_if_index", "main/worker", "thread", "queue", "mode");
6191
6192 /* Dump Interface rx placement */
6193 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
6194
6195 if (sw_if_index_set)
6196 mp->sw_if_index = htonl (sw_if_index);
6197 else
6198 mp->sw_if_index = ~0;
6199
6200 S (mp);
6201
6202 /* Use a control ping for synchronization */
6203 MPING (CONTROL_PING, mp_ping);
6204 S (mp_ping);
6205
6206 W (ret);
6207 return ret;
6208}
6209
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006210static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006211api_sw_interface_clear_stats (vat_main_t * vam)
6212{
6213 unformat_input_t *i = vam->input;
6214 vl_api_sw_interface_clear_stats_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006215 u32 sw_if_index;
6216 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006217 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006218
6219 /* Parse args required to build the message */
6220 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6221 {
6222 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6223 sw_if_index_set = 1;
6224 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6225 sw_if_index_set = 1;
6226 else
6227 break;
6228 }
6229
6230 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006231 M (SW_INTERFACE_CLEAR_STATS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006232
6233 if (sw_if_index_set == 1)
6234 mp->sw_if_index = ntohl (sw_if_index);
6235 else
6236 mp->sw_if_index = ~0;
6237
6238 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006239 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006240
6241 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006242 W (ret);
6243 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006244}
6245
Damjan Marion7cd468a2016-12-19 23:05:39 +01006246static int
6247api_sw_interface_add_del_address (vat_main_t * vam)
6248{
6249 unformat_input_t *i = vam->input;
6250 vl_api_sw_interface_add_del_address_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006251 u32 sw_if_index;
6252 u8 sw_if_index_set = 0;
6253 u8 is_add = 1, del_all = 0;
6254 u32 address_length = 0;
6255 u8 v4_address_set = 0;
6256 u8 v6_address_set = 0;
6257 ip4_address_t v4address;
6258 ip6_address_t v6address;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006259 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006260
6261 /* Parse args required to build the message */
6262 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6263 {
6264 if (unformat (i, "del-all"))
6265 del_all = 1;
6266 else if (unformat (i, "del"))
6267 is_add = 0;
6268 else
6269 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6270 sw_if_index_set = 1;
6271 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6272 sw_if_index_set = 1;
6273 else if (unformat (i, "%U/%d",
6274 unformat_ip4_address, &v4address, &address_length))
6275 v4_address_set = 1;
6276 else if (unformat (i, "%U/%d",
6277 unformat_ip6_address, &v6address, &address_length))
6278 v6_address_set = 1;
6279 else
6280 break;
6281 }
6282
6283 if (sw_if_index_set == 0)
6284 {
6285 errmsg ("missing interface name or sw_if_index");
6286 return -99;
6287 }
6288 if (v4_address_set && v6_address_set)
6289 {
6290 errmsg ("both v4 and v6 addresses set");
6291 return -99;
6292 }
6293 if (!v4_address_set && !v6_address_set && !del_all)
6294 {
6295 errmsg ("no addresses set");
6296 return -99;
6297 }
6298
6299 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006300 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006301
6302 mp->sw_if_index = ntohl (sw_if_index);
6303 mp->is_add = is_add;
6304 mp->del_all = del_all;
6305 if (v6_address_set)
6306 {
Ole Trøan3b0d7e42019-03-15 16:14:41 +00006307 mp->is_ipv6 = 1;
6308 clib_memcpy (mp->address, &v6address, sizeof (v6address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006309 }
6310 else
6311 {
Ole Trøan3b0d7e42019-03-15 16:14:41 +00006312 clib_memcpy (mp->address, &v4address, sizeof (v4address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006313 }
Ole Trøan3b0d7e42019-03-15 16:14:41 +00006314 mp->address_length = address_length;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006315
6316 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006317 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006318
6319 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006320 W (ret);
6321 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006322}
6323
6324static int
6325api_sw_interface_set_mpls_enable (vat_main_t * vam)
6326{
6327 unformat_input_t *i = vam->input;
6328 vl_api_sw_interface_set_mpls_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006329 u32 sw_if_index;
6330 u8 sw_if_index_set = 0;
6331 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006332 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006333
6334 /* Parse args required to build the message */
6335 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6336 {
6337 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6338 sw_if_index_set = 1;
6339 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6340 sw_if_index_set = 1;
6341 else if (unformat (i, "disable"))
6342 enable = 0;
6343 else if (unformat (i, "dis"))
6344 enable = 0;
6345 else
6346 break;
6347 }
6348
6349 if (sw_if_index_set == 0)
6350 {
6351 errmsg ("missing interface name or sw_if_index");
6352 return -99;
6353 }
6354
6355 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006356 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006357
6358 mp->sw_if_index = ntohl (sw_if_index);
6359 mp->enable = enable;
6360
6361 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006362 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006363
6364 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006365 W (ret);
6366 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006367}
6368
6369static int
6370api_sw_interface_set_table (vat_main_t * vam)
6371{
6372 unformat_input_t *i = vam->input;
6373 vl_api_sw_interface_set_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006374 u32 sw_if_index, vrf_id = 0;
6375 u8 sw_if_index_set = 0;
6376 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006377 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006378
6379 /* Parse args required to build the message */
6380 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6381 {
6382 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6383 sw_if_index_set = 1;
6384 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6385 sw_if_index_set = 1;
6386 else if (unformat (i, "vrf %d", &vrf_id))
6387 ;
6388 else if (unformat (i, "ipv6"))
6389 is_ipv6 = 1;
6390 else
6391 break;
6392 }
6393
6394 if (sw_if_index_set == 0)
6395 {
6396 errmsg ("missing interface name or sw_if_index");
6397 return -99;
6398 }
6399
6400 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006401 M (SW_INTERFACE_SET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006402
6403 mp->sw_if_index = ntohl (sw_if_index);
6404 mp->is_ipv6 = is_ipv6;
6405 mp->vrf_id = ntohl (vrf_id);
6406
6407 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006408 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006409
6410 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006411 W (ret);
6412 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006413}
6414
6415static void vl_api_sw_interface_get_table_reply_t_handler
6416 (vl_api_sw_interface_get_table_reply_t * mp)
6417{
6418 vat_main_t *vam = &vat_main;
6419
6420 print (vam->ofp, "%d", ntohl (mp->vrf_id));
6421
6422 vam->retval = ntohl (mp->retval);
6423 vam->result_ready = 1;
6424
6425}
6426
6427static void vl_api_sw_interface_get_table_reply_t_handler_json
6428 (vl_api_sw_interface_get_table_reply_t * mp)
6429{
6430 vat_main_t *vam = &vat_main;
6431 vat_json_node_t node;
6432
6433 vat_json_init_object (&node);
6434 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
6435 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
6436
6437 vat_json_print (vam->ofp, &node);
6438 vat_json_free (&node);
6439
6440 vam->retval = ntohl (mp->retval);
6441 vam->result_ready = 1;
6442}
6443
6444static int
6445api_sw_interface_get_table (vat_main_t * vam)
6446{
6447 unformat_input_t *i = vam->input;
6448 vl_api_sw_interface_get_table_t *mp;
6449 u32 sw_if_index;
6450 u8 sw_if_index_set = 0;
6451 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006452 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006453
6454 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6455 {
6456 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6457 sw_if_index_set = 1;
6458 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6459 sw_if_index_set = 1;
6460 else if (unformat (i, "ipv6"))
6461 is_ipv6 = 1;
6462 else
6463 break;
6464 }
6465
6466 if (sw_if_index_set == 0)
6467 {
6468 errmsg ("missing interface name or sw_if_index");
6469 return -99;
6470 }
6471
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006472 M (SW_INTERFACE_GET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006473 mp->sw_if_index = htonl (sw_if_index);
6474 mp->is_ipv6 = is_ipv6;
6475
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006476 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006477 W (ret);
6478 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006479}
6480
6481static int
6482api_sw_interface_set_vpath (vat_main_t * vam)
6483{
6484 unformat_input_t *i = vam->input;
6485 vl_api_sw_interface_set_vpath_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006486 u32 sw_if_index = 0;
6487 u8 sw_if_index_set = 0;
6488 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006489 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006490
6491 /* Parse args required to build the message */
6492 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6493 {
6494 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6495 sw_if_index_set = 1;
6496 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6497 sw_if_index_set = 1;
6498 else if (unformat (i, "enable"))
6499 is_enable = 1;
6500 else if (unformat (i, "disable"))
6501 is_enable = 0;
6502 else
6503 break;
6504 }
6505
6506 if (sw_if_index_set == 0)
6507 {
6508 errmsg ("missing interface name or sw_if_index");
6509 return -99;
6510 }
6511
6512 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006513 M (SW_INTERFACE_SET_VPATH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006514
6515 mp->sw_if_index = ntohl (sw_if_index);
6516 mp->enable = is_enable;
6517
6518 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006519 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006520
6521 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006522 W (ret);
6523 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006524}
6525
6526static int
6527api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
6528{
6529 unformat_input_t *i = vam->input;
6530 vl_api_sw_interface_set_vxlan_bypass_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006531 u32 sw_if_index = 0;
6532 u8 sw_if_index_set = 0;
John Lo2b81eb82017-01-30 13:12:10 -05006533 u8 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006534 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006535 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006536
6537 /* Parse args required to build the message */
6538 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6539 {
6540 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6541 sw_if_index_set = 1;
6542 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6543 sw_if_index_set = 1;
6544 else if (unformat (i, "enable"))
6545 is_enable = 1;
6546 else if (unformat (i, "disable"))
6547 is_enable = 0;
6548 else if (unformat (i, "ip4"))
6549 is_ipv6 = 0;
6550 else if (unformat (i, "ip6"))
6551 is_ipv6 = 1;
6552 else
6553 break;
6554 }
6555
6556 if (sw_if_index_set == 0)
6557 {
6558 errmsg ("missing interface name or sw_if_index");
6559 return -99;
6560 }
6561
6562 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006563 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006564
6565 mp->sw_if_index = ntohl (sw_if_index);
6566 mp->enable = is_enable;
6567 mp->is_ipv6 = is_ipv6;
6568
6569 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006570 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006571
6572 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006573 W (ret);
6574 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006575}
6576
Marco Varleseb598f1d2017-09-19 14:25:28 +02006577static int
6578api_sw_interface_set_geneve_bypass (vat_main_t * vam)
6579{
6580 unformat_input_t *i = vam->input;
6581 vl_api_sw_interface_set_geneve_bypass_t *mp;
6582 u32 sw_if_index = 0;
6583 u8 sw_if_index_set = 0;
6584 u8 is_enable = 1;
6585 u8 is_ipv6 = 0;
6586 int ret;
6587
6588 /* Parse args required to build the message */
6589 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6590 {
6591 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6592 sw_if_index_set = 1;
6593 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6594 sw_if_index_set = 1;
6595 else if (unformat (i, "enable"))
6596 is_enable = 1;
6597 else if (unformat (i, "disable"))
6598 is_enable = 0;
6599 else if (unformat (i, "ip4"))
6600 is_ipv6 = 0;
6601 else if (unformat (i, "ip6"))
6602 is_ipv6 = 1;
6603 else
6604 break;
6605 }
6606
6607 if (sw_if_index_set == 0)
6608 {
6609 errmsg ("missing interface name or sw_if_index");
6610 return -99;
6611 }
6612
6613 /* Construct the API message */
6614 M (SW_INTERFACE_SET_GENEVE_BYPASS, mp);
6615
6616 mp->sw_if_index = ntohl (sw_if_index);
6617 mp->enable = is_enable;
6618 mp->is_ipv6 = is_ipv6;
6619
6620 /* send it... */
6621 S (mp);
6622
6623 /* Wait for a reply... */
6624 W (ret);
6625 return ret;
6626}
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08006627
Damjan Marion7cd468a2016-12-19 23:05:39 +01006628static int
6629api_sw_interface_set_l2_xconnect (vat_main_t * vam)
6630{
6631 unformat_input_t *i = vam->input;
6632 vl_api_sw_interface_set_l2_xconnect_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006633 u32 rx_sw_if_index;
6634 u8 rx_sw_if_index_set = 0;
6635 u32 tx_sw_if_index;
6636 u8 tx_sw_if_index_set = 0;
6637 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006638 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006639
6640 /* Parse args required to build the message */
6641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6642 {
6643 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6644 rx_sw_if_index_set = 1;
6645 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6646 tx_sw_if_index_set = 1;
6647 else if (unformat (i, "rx"))
6648 {
6649 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6650 {
6651 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6652 &rx_sw_if_index))
6653 rx_sw_if_index_set = 1;
6654 }
6655 else
6656 break;
6657 }
6658 else if (unformat (i, "tx"))
6659 {
6660 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6661 {
6662 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6663 &tx_sw_if_index))
6664 tx_sw_if_index_set = 1;
6665 }
6666 else
6667 break;
6668 }
6669 else if (unformat (i, "enable"))
6670 enable = 1;
6671 else if (unformat (i, "disable"))
6672 enable = 0;
6673 else
6674 break;
6675 }
6676
6677 if (rx_sw_if_index_set == 0)
6678 {
6679 errmsg ("missing rx interface name or rx_sw_if_index");
6680 return -99;
6681 }
6682
6683 if (enable && (tx_sw_if_index_set == 0))
6684 {
6685 errmsg ("missing tx interface name or tx_sw_if_index");
6686 return -99;
6687 }
6688
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006689 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006690
6691 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6692 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6693 mp->enable = enable;
6694
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006695 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006696 W (ret);
6697 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006698}
6699
6700static int
6701api_sw_interface_set_l2_bridge (vat_main_t * vam)
6702{
6703 unformat_input_t *i = vam->input;
6704 vl_api_sw_interface_set_l2_bridge_t *mp;
Neale Rannsb4743802018-09-05 09:13:57 -07006705 vl_api_l2_port_type_t port_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006706 u32 rx_sw_if_index;
6707 u8 rx_sw_if_index_set = 0;
6708 u32 bd_id;
6709 u8 bd_id_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006710 u32 shg = 0;
6711 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006712 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006713
Neale Rannsb4743802018-09-05 09:13:57 -07006714 port_type = L2_API_PORT_TYPE_NORMAL;
6715
Damjan Marion7cd468a2016-12-19 23:05:39 +01006716 /* Parse args required to build the message */
6717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6718 {
6719 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
6720 rx_sw_if_index_set = 1;
6721 else if (unformat (i, "bd_id %d", &bd_id))
6722 bd_id_set = 1;
6723 else
6724 if (unformat
6725 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
6726 rx_sw_if_index_set = 1;
6727 else if (unformat (i, "shg %d", &shg))
6728 ;
6729 else if (unformat (i, "bvi"))
Neale Rannsb4743802018-09-05 09:13:57 -07006730 port_type = L2_API_PORT_TYPE_BVI;
6731 else if (unformat (i, "uu-fwd"))
6732 port_type = L2_API_PORT_TYPE_UU_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006733 else if (unformat (i, "enable"))
6734 enable = 1;
6735 else if (unformat (i, "disable"))
6736 enable = 0;
6737 else
6738 break;
6739 }
6740
6741 if (rx_sw_if_index_set == 0)
6742 {
6743 errmsg ("missing rx interface name or sw_if_index");
6744 return -99;
6745 }
6746
6747 if (enable && (bd_id_set == 0))
6748 {
6749 errmsg ("missing bridge domain");
6750 return -99;
6751 }
6752
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006753 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006754
6755 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6756 mp->bd_id = ntohl (bd_id);
6757 mp->shg = (u8) shg;
Neale Rannsb4743802018-09-05 09:13:57 -07006758 mp->port_type = ntohl (port_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006759 mp->enable = enable;
6760
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006761 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006762 W (ret);
6763 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006764}
6765
6766static int
6767api_bridge_domain_dump (vat_main_t * vam)
6768{
6769 unformat_input_t *i = vam->input;
6770 vl_api_bridge_domain_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006771 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006772 u32 bd_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006773 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006774
6775 /* Parse args required to build the message */
6776 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6777 {
6778 if (unformat (i, "bd_id %d", &bd_id))
6779 ;
6780 else
6781 break;
6782 }
6783
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006784 M (BRIDGE_DOMAIN_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006785 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006786 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006787
6788 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04006789 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006790 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006791
Jon Loeliger56c7b012017-02-01 12:31:41 -06006792 W (ret);
6793 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006794}
6795
6796static int
6797api_bridge_domain_add_del (vat_main_t * vam)
6798{
6799 unformat_input_t *i = vam->input;
6800 vl_api_bridge_domain_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006801 u32 bd_id = ~0;
6802 u8 is_add = 1;
6803 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006804 u8 *bd_tag = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006805 u32 mac_age = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006806 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006807
6808 /* Parse args required to build the message */
6809 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6810 {
6811 if (unformat (i, "bd_id %d", &bd_id))
6812 ;
6813 else if (unformat (i, "flood %d", &flood))
6814 ;
6815 else if (unformat (i, "uu-flood %d", &uu_flood))
6816 ;
6817 else if (unformat (i, "forward %d", &forward))
6818 ;
6819 else if (unformat (i, "learn %d", &learn))
6820 ;
6821 else if (unformat (i, "arp-term %d", &arp_term))
6822 ;
6823 else if (unformat (i, "mac-age %d", &mac_age))
6824 ;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006825 else if (unformat (i, "bd-tag %s", &bd_tag))
6826 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006827 else if (unformat (i, "del"))
6828 {
6829 is_add = 0;
6830 flood = uu_flood = forward = learn = 0;
6831 }
6832 else
6833 break;
6834 }
6835
6836 if (bd_id == ~0)
6837 {
6838 errmsg ("missing bridge domain");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006839 ret = -99;
6840 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006841 }
6842
6843 if (mac_age > 255)
6844 {
6845 errmsg ("mac age must be less than 256 ");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006846 ret = -99;
6847 goto done;
6848 }
6849
John Lo70bfcaf2017-11-14 13:19:26 -05006850 if ((bd_tag) && (vec_len (bd_tag) > 63))
Jerome Tollet50570ec2017-09-14 12:53:56 +01006851 {
6852 errmsg ("bd-tag cannot be longer than 63");
6853 ret = -99;
6854 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006855 }
6856
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006857 M (BRIDGE_DOMAIN_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006858
6859 mp->bd_id = ntohl (bd_id);
6860 mp->flood = flood;
6861 mp->uu_flood = uu_flood;
6862 mp->forward = forward;
6863 mp->learn = learn;
6864 mp->arp_term = arp_term;
6865 mp->is_add = is_add;
6866 mp->mac_age = (u8) mac_age;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006867 if (bd_tag)
John Lo70bfcaf2017-11-14 13:19:26 -05006868 {
6869 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
6870 mp->bd_tag[vec_len (bd_tag)] = 0;
6871 }
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006872 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006873 W (ret);
Jerome Tollet50570ec2017-09-14 12:53:56 +01006874
6875done:
6876 vec_free (bd_tag);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006877 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006878}
6879
6880static int
Eyal Barif24991c2017-04-05 05:33:21 +03006881api_l2fib_flush_bd (vat_main_t * vam)
6882{
6883 unformat_input_t *i = vam->input;
6884 vl_api_l2fib_flush_bd_t *mp;
6885 u32 bd_id = ~0;
6886 int ret;
6887
6888 /* Parse args required to build the message */
6889 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6890 {
6891 if (unformat (i, "bd_id %d", &bd_id));
6892 else
6893 break;
6894 }
6895
6896 if (bd_id == ~0)
6897 {
6898 errmsg ("missing bridge domain");
6899 return -99;
6900 }
6901
6902 M (L2FIB_FLUSH_BD, mp);
6903
6904 mp->bd_id = htonl (bd_id);
6905
6906 S (mp);
6907 W (ret);
6908 return ret;
6909}
6910
6911static int
6912api_l2fib_flush_int (vat_main_t * vam)
6913{
6914 unformat_input_t *i = vam->input;
6915 vl_api_l2fib_flush_int_t *mp;
6916 u32 sw_if_index = ~0;
6917 int ret;
6918
6919 /* Parse args required to build the message */
6920 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6921 {
6922 if (unformat (i, "sw_if_index %d", &sw_if_index));
6923 else
6924 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
6925 else
6926 break;
6927 }
6928
6929 if (sw_if_index == ~0)
6930 {
6931 errmsg ("missing interface name or sw_if_index");
6932 return -99;
6933 }
6934
6935 M (L2FIB_FLUSH_INT, mp);
6936
6937 mp->sw_if_index = ntohl (sw_if_index);
6938
6939 S (mp);
6940 W (ret);
6941 return ret;
6942}
6943
6944static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006945api_l2fib_add_del (vat_main_t * vam)
6946{
6947 unformat_input_t *i = vam->input;
6948 vl_api_l2fib_add_del_t *mp;
6949 f64 timeout;
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006950 u8 mac[6] = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01006951 u8 mac_set = 0;
6952 u32 bd_id;
6953 u8 bd_id_set = 0;
John Lo7dbd7262018-05-31 10:25:18 -04006954 u32 sw_if_index = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006955 u8 sw_if_index_set = 0;
6956 u8 is_add = 1;
6957 u8 static_mac = 0;
6958 u8 filter_mac = 0;
6959 u8 bvi_mac = 0;
6960 int count = 1;
6961 f64 before = 0;
6962 int j;
6963
6964 /* Parse args required to build the message */
6965 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6966 {
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006967 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01006968 mac_set = 1;
6969 else if (unformat (i, "bd_id %d", &bd_id))
6970 bd_id_set = 1;
6971 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6972 sw_if_index_set = 1;
6973 else if (unformat (i, "sw_if"))
6974 {
6975 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6976 {
6977 if (unformat
6978 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6979 sw_if_index_set = 1;
6980 }
6981 else
6982 break;
6983 }
6984 else if (unformat (i, "static"))
6985 static_mac = 1;
6986 else if (unformat (i, "filter"))
6987 {
6988 filter_mac = 1;
6989 static_mac = 1;
6990 }
6991 else if (unformat (i, "bvi"))
6992 {
6993 bvi_mac = 1;
6994 static_mac = 1;
6995 }
6996 else if (unformat (i, "del"))
6997 is_add = 0;
6998 else if (unformat (i, "count %d", &count))
6999 ;
7000 else
7001 break;
7002 }
7003
7004 if (mac_set == 0)
7005 {
7006 errmsg ("missing mac address");
7007 return -99;
7008 }
7009
7010 if (bd_id_set == 0)
7011 {
7012 errmsg ("missing bridge domain");
7013 return -99;
7014 }
7015
7016 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
7017 {
7018 errmsg ("missing interface name or sw_if_index");
7019 return -99;
7020 }
7021
7022 if (count > 1)
7023 {
7024 /* Turn on async mode */
7025 vam->async_mode = 1;
7026 vam->async_errors = 0;
7027 before = vat_time_now (vam);
7028 }
7029
7030 for (j = 0; j < count; j++)
7031 {
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007032 M (L2FIB_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007033
Mohsin Kazmi57938f62017-10-27 21:28:07 +02007034 clib_memcpy (mp->mac, mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007035 mp->bd_id = ntohl (bd_id);
7036 mp->is_add = is_add;
John Lo7dbd7262018-05-31 10:25:18 -04007037 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007038
7039 if (is_add)
7040 {
Damjan Marion7cd468a2016-12-19 23:05:39 +01007041 mp->static_mac = static_mac;
7042 mp->filter_mac = filter_mac;
7043 mp->bvi_mac = bvi_mac;
7044 }
Mohsin Kazmi57938f62017-10-27 21:28:07 +02007045 increment_mac_address (mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007046 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007047 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007048 }
7049
7050 if (count > 1)
7051 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06007052 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007053 f64 after;
7054
7055 /* Shut off async mode */
7056 vam->async_mode = 0;
7057
Dave Barach59b25652017-09-10 15:04:27 -04007058 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06007059 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007060
7061 timeout = vat_time_now (vam) + 1.0;
7062 while (vat_time_now (vam) < timeout)
7063 if (vam->result_ready == 1)
7064 goto out;
7065 vam->retval = -99;
7066
7067 out:
7068 if (vam->retval == -99)
7069 errmsg ("timeout");
7070
7071 if (vam->async_errors > 0)
7072 {
7073 errmsg ("%d asynchronous errors", vam->async_errors);
7074 vam->retval = -98;
7075 }
7076 vam->async_errors = 0;
7077 after = vat_time_now (vam);
7078
7079 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
7080 count, after - before, count / (after - before));
7081 }
7082 else
7083 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06007084 int ret;
7085
Damjan Marion7cd468a2016-12-19 23:05:39 +01007086 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06007087 W (ret);
7088 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007089 }
7090 /* Return the good/bad news */
7091 return (vam->retval);
7092}
7093
7094static int
Eyal Barifead6702017-04-04 04:46:32 +03007095api_bridge_domain_set_mac_age (vat_main_t * vam)
7096{
7097 unformat_input_t *i = vam->input;
7098 vl_api_bridge_domain_set_mac_age_t *mp;
7099 u32 bd_id = ~0;
7100 u32 mac_age = 0;
7101 int ret;
7102
7103 /* Parse args required to build the message */
7104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7105 {
7106 if (unformat (i, "bd_id %d", &bd_id));
7107 else if (unformat (i, "mac-age %d", &mac_age));
7108 else
7109 break;
7110 }
7111
7112 if (bd_id == ~0)
7113 {
7114 errmsg ("missing bridge domain");
7115 return -99;
7116 }
7117
7118 if (mac_age > 255)
7119 {
7120 errmsg ("mac age must be less than 256 ");
7121 return -99;
7122 }
7123
7124 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
7125
7126 mp->bd_id = htonl (bd_id);
7127 mp->mac_age = (u8) mac_age;
7128
7129 S (mp);
7130 W (ret);
7131 return ret;
7132}
7133
7134static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01007135api_l2_flags (vat_main_t * vam)
7136{
7137 unformat_input_t *i = vam->input;
7138 vl_api_l2_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007139 u32 sw_if_index;
John Lo8d00fff2017-08-03 00:35:36 -04007140 u32 flags = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007141 u8 sw_if_index_set = 0;
John Lo8d00fff2017-08-03 00:35:36 -04007142 u8 is_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007143 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007144
7145 /* Parse args required to build the message */
7146 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7147 {
7148 if (unformat (i, "sw_if_index %d", &sw_if_index))
7149 sw_if_index_set = 1;
7150 else if (unformat (i, "sw_if"))
7151 {
7152 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7153 {
7154 if (unformat
7155 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7156 sw_if_index_set = 1;
7157 }
7158 else
7159 break;
7160 }
7161 else if (unformat (i, "learn"))
John Lo8d00fff2017-08-03 00:35:36 -04007162 flags |= L2_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007163 else if (unformat (i, "forward"))
John Lo8d00fff2017-08-03 00:35:36 -04007164 flags |= L2_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007165 else if (unformat (i, "flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007166 flags |= L2_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007167 else if (unformat (i, "uu-flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007168 flags |= L2_UU_FLOOD;
7169 else if (unformat (i, "arp-term"))
7170 flags |= L2_ARP_TERM;
7171 else if (unformat (i, "off"))
7172 is_set = 0;
7173 else if (unformat (i, "disable"))
7174 is_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007175 else
7176 break;
7177 }
7178
7179 if (sw_if_index_set == 0)
7180 {
7181 errmsg ("missing interface name or sw_if_index");
7182 return -99;
7183 }
7184
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007185 M (L2_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007186
7187 mp->sw_if_index = ntohl (sw_if_index);
John Lo8d00fff2017-08-03 00:35:36 -04007188 mp->feature_bitmap = ntohl (flags);
7189 mp->is_set = is_set;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007190
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007191 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007192 W (ret);
7193 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007194}
7195
7196static int
7197api_bridge_flags (vat_main_t * vam)
7198{
7199 unformat_input_t *i = vam->input;
7200 vl_api_bridge_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007201 u32 bd_id;
7202 u8 bd_id_set = 0;
7203 u8 is_set = 1;
Neale Rannsb4743802018-09-05 09:13:57 -07007204 bd_flags_t flags = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007205 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007206
7207 /* Parse args required to build the message */
7208 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7209 {
7210 if (unformat (i, "bd_id %d", &bd_id))
7211 bd_id_set = 1;
7212 else if (unformat (i, "learn"))
Neale Rannsb4743802018-09-05 09:13:57 -07007213 flags |= BRIDGE_API_FLAG_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007214 else if (unformat (i, "forward"))
Neale Rannsb4743802018-09-05 09:13:57 -07007215 flags |= BRIDGE_API_FLAG_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007216 else if (unformat (i, "flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007217 flags |= BRIDGE_API_FLAG_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007218 else if (unformat (i, "uu-flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007219 flags |= BRIDGE_API_FLAG_UU_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007220 else if (unformat (i, "arp-term"))
Neale Rannsb4743802018-09-05 09:13:57 -07007221 flags |= BRIDGE_API_FLAG_ARP_TERM;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007222 else if (unformat (i, "off"))
7223 is_set = 0;
7224 else if (unformat (i, "disable"))
7225 is_set = 0;
7226 else
7227 break;
7228 }
7229
7230 if (bd_id_set == 0)
7231 {
7232 errmsg ("missing bridge domain");
7233 return -99;
7234 }
7235
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007236 M (BRIDGE_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007237
7238 mp->bd_id = ntohl (bd_id);
Neale Rannsb4743802018-09-05 09:13:57 -07007239 mp->flags = ntohl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007240 mp->is_set = is_set;
7241
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007242 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007243 W (ret);
7244 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007245}
7246
7247static int
7248api_bd_ip_mac_add_del (vat_main_t * vam)
7249{
Neale Ranns4d5b9172018-10-24 02:57:49 -07007250 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
Ole Troan8006c6a2018-12-17 12:02:26 +01007251 vl_api_mac_address_t mac = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01007252 unformat_input_t *i = vam->input;
7253 vl_api_bd_ip_mac_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007254 u32 bd_id;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007255 u8 is_add = 1;
7256 u8 bd_id_set = 0;
7257 u8 ip_set = 0;
7258 u8 mac_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007259 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007260
7261
7262 /* Parse args required to build the message */
7263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7264 {
7265 if (unformat (i, "bd_id %d", &bd_id))
7266 {
7267 bd_id_set++;
7268 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007269 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007270 {
7271 ip_set++;
7272 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007273 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007274 {
7275 mac_set++;
7276 }
7277 else if (unformat (i, "del"))
7278 is_add = 0;
7279 else
7280 break;
7281 }
7282
7283 if (bd_id_set == 0)
7284 {
7285 errmsg ("missing bridge domain");
7286 return -99;
7287 }
7288 else if (ip_set == 0)
7289 {
7290 errmsg ("missing IP address");
7291 return -99;
7292 }
7293 else if (mac_set == 0)
7294 {
7295 errmsg ("missing MAC address");
7296 return -99;
7297 }
7298
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007299 M (BD_IP_MAC_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007300
Neale Rannsbc764c82019-06-19 07:07:13 -07007301 mp->entry.bd_id = ntohl (bd_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007302 mp->is_add = is_add;
Neale Ranns4d5b9172018-10-24 02:57:49 -07007303
Neale Rannsbc764c82019-06-19 07:07:13 -07007304 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
7305 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
Neale Ranns4d5b9172018-10-24 02:57:49 -07007306
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007307 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007308 W (ret);
7309 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007310}
7311
John Loe26c81f2019-01-07 15:16:33 -05007312static int
7313api_bd_ip_mac_flush (vat_main_t * vam)
7314{
7315 unformat_input_t *i = vam->input;
7316 vl_api_bd_ip_mac_flush_t *mp;
7317 u32 bd_id;
7318 u8 bd_id_set = 0;
7319 int ret;
7320
7321 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7322 {
7323 if (unformat (i, "bd_id %d", &bd_id))
7324 {
7325 bd_id_set++;
7326 }
7327 else
7328 break;
7329 }
7330
7331 if (bd_id_set == 0)
7332 {
7333 errmsg ("missing bridge domain");
7334 return -99;
7335 }
7336
7337 M (BD_IP_MAC_FLUSH, mp);
7338
7339 mp->bd_id = ntohl (bd_id);
7340
7341 S (mp);
7342 W (ret);
7343 return ret;
7344}
7345
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007346static void vl_api_bd_ip_mac_details_t_handler
7347 (vl_api_bd_ip_mac_details_t * mp)
7348{
7349 vat_main_t *vam = &vat_main;
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007350
7351 print (vam->ofp,
Neale Rannsbc764c82019-06-19 07:07:13 -07007352 "\n%-5d %U %U",
7353 ntohl (mp->entry.bd_id),
7354 format_vl_api_mac_address, mp->entry.mac,
7355 format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007356}
7357
7358static void vl_api_bd_ip_mac_details_t_handler_json
7359 (vl_api_bd_ip_mac_details_t * mp)
7360{
7361 vat_main_t *vam = &vat_main;
7362 vat_json_node_t *node = NULL;
7363
7364 if (VAT_JSON_ARRAY != vam->json_tree.type)
7365 {
7366 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7367 vat_json_init_array (&vam->json_tree);
7368 }
7369 node = vat_json_array_add (&vam->json_tree);
7370
7371 vat_json_init_object (node);
Neale Rannsbc764c82019-06-19 07:07:13 -07007372 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007373 vat_json_object_add_string_copy (node, "mac_address",
Neale Rannsbc764c82019-06-19 07:07:13 -07007374 format (0, "%U", format_vl_api_mac_address,
7375 &mp->entry.mac));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007376 u8 *ip = 0;
7377
Neale Rannsbc764c82019-06-19 07:07:13 -07007378 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007379 vat_json_object_add_string_copy (node, "ip_address", ip);
7380 vec_free (ip);
7381}
7382
7383static int
7384api_bd_ip_mac_dump (vat_main_t * vam)
7385{
7386 unformat_input_t *i = vam->input;
7387 vl_api_bd_ip_mac_dump_t *mp;
7388 vl_api_control_ping_t *mp_ping;
7389 int ret;
7390 u32 bd_id;
7391 u8 bd_id_set = 0;
7392
7393 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7394 {
7395 if (unformat (i, "bd_id %d", &bd_id))
7396 {
7397 bd_id_set++;
7398 }
7399 else
7400 break;
7401 }
7402
7403 print (vam->ofp,
7404 "\n%-5s %-7s %-20s %-30s",
7405 "bd_id", "is_ipv6", "mac_address", "ip_address");
7406
7407 /* Dump Bridge Domain Ip to Mac entries */
7408 M (BD_IP_MAC_DUMP, mp);
7409
7410 if (bd_id_set)
7411 mp->bd_id = htonl (bd_id);
7412 else
7413 mp->bd_id = ~0;
7414
7415 S (mp);
7416
7417 /* Use a control ping for synchronization */
7418 MPING (CONTROL_PING, mp_ping);
7419 S (mp_ping);
7420
7421 W (ret);
7422 return ret;
7423}
7424
Damjan Marion7cd468a2016-12-19 23:05:39 +01007425static int
Damjan Marion8389fb92017-10-13 18:29:53 +02007426api_tap_create_v2 (vat_main_t * vam)
7427{
7428 unformat_input_t *i = vam->input;
7429 vl_api_tap_create_v2_t *mp;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007430#define TAP_FLAG_GSO (1 << 0)
Damjan Marion8389fb92017-10-13 18:29:53 +02007431 u8 mac_address[6];
7432 u8 random_mac = 1;
Damjan Marion2df39092017-12-04 20:03:37 +01007433 u32 id = ~0;
7434 u8 *host_if_name = 0;
7435 u8 *host_ns = 0;
7436 u8 host_mac_addr[6];
7437 u8 host_mac_addr_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007438 u8 *host_bridge = 0;
7439 ip4_address_t host_ip4_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007440 ip4_address_t host_ip4_gw;
7441 u8 host_ip4_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007442 u32 host_ip4_prefix_len = 0;
7443 ip6_address_t host_ip6_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007444 ip6_address_t host_ip6_gw;
7445 u8 host_ip6_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007446 u32 host_ip6_prefix_len = 0;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007447 u8 host_mtu_set = 0;
7448 u32 host_mtu_size = 0;
7449 u32 tap_flags = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007450 int ret;
Steven9e635692018-03-01 09:36:01 -08007451 u32 rx_ring_sz = 0, tx_ring_sz = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007452
Dave Barachb7b92992018-10-17 10:38:51 -04007453 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion8389fb92017-10-13 18:29:53 +02007454
7455 /* Parse args required to build the message */
7456 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7457 {
7458 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7459 {
7460 random_mac = 0;
7461 }
Steven9e635692018-03-01 09:36:01 -08007462 else if (unformat (i, "id %u", &id))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007463 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007464 else if (unformat (i, "host-if-name %s", &host_if_name))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007465 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007466 else if (unformat (i, "host-ns %s", &host_ns))
7467 ;
7468 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
7469 host_mac_addr))
7470 host_mac_addr_set = 1;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007471 else if (unformat (i, "host-bridge %s", &host_bridge))
7472 ;
7473 else if (unformat (i, "host-ip4-addr %U/%d", unformat_ip4_address,
7474 &host_ip4_addr, &host_ip4_prefix_len))
7475 ;
7476 else if (unformat (i, "host-ip6-addr %U/%d", unformat_ip6_address,
7477 &host_ip6_addr, &host_ip6_prefix_len))
7478 ;
Damjan Marion7866c452018-01-18 13:35:11 +01007479 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
7480 &host_ip4_gw))
7481 host_ip4_gw_set = 1;
7482 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
7483 &host_ip6_gw))
7484 host_ip6_gw_set = 1;
Damjan Marion8389fb92017-10-13 18:29:53 +02007485 else if (unformat (i, "rx-ring-size %d", &rx_ring_sz))
7486 ;
7487 else if (unformat (i, "tx-ring-size %d", &tx_ring_sz))
7488 ;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007489 else if (unformat (i, "host-mtu-size %d", &host_mtu_size))
7490 host_mtu_set = 1;
7491 else if (unformat (i, "no-gso"))
7492 tap_flags &= ~TAP_FLAG_GSO;
7493 else if (unformat (i, "gso"))
7494 tap_flags |= TAP_FLAG_GSO;
Damjan Marion8389fb92017-10-13 18:29:53 +02007495 else
7496 break;
7497 }
7498
Damjan Marion2df39092017-12-04 20:03:37 +01007499 if (vec_len (host_if_name) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007500 {
7501 errmsg ("tap name too long. ");
7502 return -99;
7503 }
Damjan Marion2df39092017-12-04 20:03:37 +01007504 if (vec_len (host_ns) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007505 {
7506 errmsg ("host name space too long. ");
7507 return -99;
7508 }
Damjan Marion91c6ef72017-12-01 13:34:24 +01007509 if (vec_len (host_bridge) > 63)
7510 {
7511 errmsg ("host bridge name too long. ");
7512 return -99;
7513 }
7514 if (host_ip4_prefix_len > 32)
7515 {
7516 errmsg ("host ip4 prefix length not valid. ");
7517 return -99;
7518 }
7519 if (host_ip6_prefix_len > 128)
7520 {
7521 errmsg ("host ip6 prefix length not valid. ");
7522 return -99;
7523 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007524 if (!is_pow2 (rx_ring_sz))
7525 {
7526 errmsg ("rx ring size must be power of 2. ");
7527 return -99;
7528 }
7529 if (rx_ring_sz > 32768)
7530 {
7531 errmsg ("rx ring size must be 32768 or lower. ");
7532 return -99;
7533 }
7534 if (!is_pow2 (tx_ring_sz))
7535 {
7536 errmsg ("tx ring size must be power of 2. ");
7537 return -99;
7538 }
7539 if (tx_ring_sz > 32768)
7540 {
7541 errmsg ("tx ring size must be 32768 or lower. ");
7542 return -99;
7543 }
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007544 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
7545 {
7546 errmsg ("host MTU size must be in between 64 and 65355. ");
7547 return -99;
7548 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007549
Damjan Marion8389fb92017-10-13 18:29:53 +02007550 /* Construct the API message */
7551 M (TAP_CREATE_V2, mp);
7552
7553 mp->use_random_mac = random_mac;
Damjan Marion2df39092017-12-04 20:03:37 +01007554
Steven9e635692018-03-01 09:36:01 -08007555 mp->id = ntohl (id);
Damjan Marion2df39092017-12-04 20:03:37 +01007556 mp->host_namespace_set = host_ns != 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007557 mp->host_bridge_set = host_bridge != 0;
7558 mp->host_ip4_addr_set = host_ip4_prefix_len != 0;
7559 mp->host_ip6_addr_set = host_ip6_prefix_len != 0;
Steven9e635692018-03-01 09:36:01 -08007560 mp->rx_ring_sz = ntohs (rx_ring_sz);
7561 mp->tx_ring_sz = ntohs (tx_ring_sz);
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007562 mp->host_mtu_set = host_mtu_set;
7563 mp->host_mtu_size = ntohl (host_mtu_size);
7564 mp->tap_flags = ntohl (tap_flags);
Damjan Marion2df39092017-12-04 20:03:37 +01007565
Steven9e635692018-03-01 09:36:01 -08007566 if (random_mac == 0)
Damjan Marion2df39092017-12-04 20:03:37 +01007567 clib_memcpy (mp->mac_address, mac_address, 6);
7568 if (host_mac_addr_set)
7569 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
7570 if (host_if_name)
7571 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
7572 if (host_ns)
7573 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
Damjan Marion91c6ef72017-12-01 13:34:24 +01007574 if (host_bridge)
7575 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
7576 if (host_ip4_prefix_len)
7577 clib_memcpy (mp->host_ip4_addr, &host_ip4_addr, 4);
Michal Cmarada87460d02018-10-17 13:40:32 +02007578 if (host_ip6_prefix_len)
Damjan Marion91c6ef72017-12-01 13:34:24 +01007579 clib_memcpy (mp->host_ip6_addr, &host_ip6_addr, 16);
Damjan Marion7866c452018-01-18 13:35:11 +01007580 if (host_ip4_gw_set)
7581 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
7582 if (host_ip6_gw_set)
7583 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
Damjan Marion8389fb92017-10-13 18:29:53 +02007584
Damjan Marion2df39092017-12-04 20:03:37 +01007585 vec_free (host_ns);
7586 vec_free (host_if_name);
7587 vec_free (host_bridge);
Damjan Marion8389fb92017-10-13 18:29:53 +02007588
7589 /* send it... */
7590 S (mp);
7591
7592 /* Wait for a reply... */
7593 W (ret);
7594 return ret;
7595}
7596
7597static int
7598api_tap_delete_v2 (vat_main_t * vam)
7599{
7600 unformat_input_t *i = vam->input;
7601 vl_api_tap_delete_v2_t *mp;
7602 u32 sw_if_index = ~0;
7603 u8 sw_if_index_set = 0;
7604 int ret;
7605
7606 /* Parse args required to build the message */
7607 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7608 {
7609 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7610 sw_if_index_set = 1;
7611 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7612 sw_if_index_set = 1;
7613 else
7614 break;
7615 }
7616
7617 if (sw_if_index_set == 0)
7618 {
7619 errmsg ("missing vpp interface name. ");
7620 return -99;
7621 }
7622
7623 /* Construct the API message */
7624 M (TAP_DELETE_V2, mp);
7625
7626 mp->sw_if_index = ntohl (sw_if_index);
7627
7628 /* send it... */
7629 S (mp);
7630
7631 /* Wait for a reply... */
7632 W (ret);
7633 return ret;
7634}
7635
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007636uword
7637unformat_pci_addr (unformat_input_t * input, va_list * args)
7638{
7639 struct pci_addr_t
7640 {
7641 u16 domain;
7642 u8 bus;
7643 u8 slot:5;
7644 u8 function:3;
7645 } *addr;
7646 addr = va_arg (*args, struct pci_addr_t *);
7647 u32 x[4];
7648
7649 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
7650 return 0;
7651
7652 addr->domain = x[0];
7653 addr->bus = x[1];
7654 addr->slot = x[2];
7655 addr->function = x[3];
7656
7657 return 1;
7658}
7659
7660static int
7661api_virtio_pci_create (vat_main_t * vam)
7662{
7663 unformat_input_t *i = vam->input;
7664 vl_api_virtio_pci_create_t *mp;
7665 u8 mac_address[6];
7666 u8 random_mac = 1;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007667 u8 gso_enabled = 0;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007668 u32 pci_addr = 0;
7669 u64 features = (u64) ~ (0ULL);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007670 int ret;
7671
7672 clib_memset (mac_address, 0, sizeof (mac_address));
7673
7674 /* Parse args required to build the message */
7675 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7676 {
7677 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7678 {
7679 random_mac = 0;
7680 }
7681 else if (unformat (i, "pci-addr %U", unformat_pci_addr, &pci_addr))
7682 ;
7683 else if (unformat (i, "features 0x%llx", &features))
7684 ;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007685 else if (unformat (i, "gso-enabled"))
7686 gso_enabled = 1;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007687 else
7688 break;
7689 }
7690
7691 if (pci_addr == 0)
7692 {
7693 errmsg ("pci address must be non zero. ");
7694 return -99;
7695 }
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007696
7697 /* Construct the API message */
7698 M (VIRTIO_PCI_CREATE, mp);
7699
7700 mp->use_random_mac = random_mac;
7701
7702 mp->pci_addr = htonl (pci_addr);
7703 mp->features = clib_host_to_net_u64 (features);
Benoît Ganne49ee6842019-04-30 11:50:46 +02007704 mp->gso_enabled = gso_enabled;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007705
7706 if (random_mac == 0)
7707 clib_memcpy (mp->mac_address, mac_address, 6);
7708
7709 /* send it... */
7710 S (mp);
7711
7712 /* Wait for a reply... */
7713 W (ret);
7714 return ret;
7715}
7716
7717static int
7718api_virtio_pci_delete (vat_main_t * vam)
7719{
7720 unformat_input_t *i = vam->input;
7721 vl_api_virtio_pci_delete_t *mp;
7722 u32 sw_if_index = ~0;
7723 u8 sw_if_index_set = 0;
7724 int ret;
7725
7726 /* Parse args required to build the message */
7727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7728 {
7729 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7730 sw_if_index_set = 1;
7731 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7732 sw_if_index_set = 1;
7733 else
7734 break;
7735 }
7736
7737 if (sw_if_index_set == 0)
7738 {
7739 errmsg ("missing vpp interface name. ");
7740 return -99;
7741 }
7742
7743 /* Construct the API message */
7744 M (VIRTIO_PCI_DELETE, mp);
7745
7746 mp->sw_if_index = htonl (sw_if_index);
7747
7748 /* send it... */
7749 S (mp);
7750
7751 /* Wait for a reply... */
7752 W (ret);
7753 return ret;
7754}
7755
Damjan Marion8389fb92017-10-13 18:29:53 +02007756static int
Steven9cd2d7a2017-12-20 12:43:01 -08007757api_bond_create (vat_main_t * vam)
7758{
7759 unformat_input_t *i = vam->input;
7760 vl_api_bond_create_t *mp;
7761 u8 mac_address[6];
7762 u8 custom_mac = 0;
7763 int ret;
7764 u8 mode;
7765 u8 lb;
7766 u8 mode_is_set = 0;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007767 u32 id = ~0;
Steven9cd2d7a2017-12-20 12:43:01 -08007768
Dave Barachb7b92992018-10-17 10:38:51 -04007769 clib_memset (mac_address, 0, sizeof (mac_address));
Steven9cd2d7a2017-12-20 12:43:01 -08007770 lb = BOND_LB_L2;
7771
7772 /* Parse args required to build the message */
7773 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7774 {
7775 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
7776 mode_is_set = 1;
7777 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
7778 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
7779 ;
7780 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
7781 mac_address))
7782 custom_mac = 1;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007783 else if (unformat (i, "id %u", &id))
7784 ;
Steven9cd2d7a2017-12-20 12:43:01 -08007785 else
7786 break;
7787 }
7788
7789 if (mode_is_set == 0)
7790 {
7791 errmsg ("Missing bond mode. ");
7792 return -99;
7793 }
7794
7795 /* Construct the API message */
7796 M (BOND_CREATE, mp);
7797
7798 mp->use_custom_mac = custom_mac;
7799
7800 mp->mode = mode;
7801 mp->lb = lb;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007802 mp->id = htonl (id);
Steven9cd2d7a2017-12-20 12:43:01 -08007803
7804 if (custom_mac)
7805 clib_memcpy (mp->mac_address, mac_address, 6);
7806
7807 /* send it... */
7808 S (mp);
7809
7810 /* Wait for a reply... */
7811 W (ret);
7812 return ret;
7813}
7814
7815static int
7816api_bond_delete (vat_main_t * vam)
7817{
7818 unformat_input_t *i = vam->input;
7819 vl_api_bond_delete_t *mp;
7820 u32 sw_if_index = ~0;
7821 u8 sw_if_index_set = 0;
7822 int ret;
7823
7824 /* Parse args required to build the message */
7825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7826 {
7827 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7828 sw_if_index_set = 1;
7829 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7830 sw_if_index_set = 1;
7831 else
7832 break;
7833 }
7834
7835 if (sw_if_index_set == 0)
7836 {
7837 errmsg ("missing vpp interface name. ");
7838 return -99;
7839 }
7840
7841 /* Construct the API message */
7842 M (BOND_DELETE, mp);
7843
7844 mp->sw_if_index = ntohl (sw_if_index);
7845
7846 /* send it... */
7847 S (mp);
7848
7849 /* Wait for a reply... */
7850 W (ret);
7851 return ret;
7852}
7853
7854static int
7855api_bond_enslave (vat_main_t * vam)
7856{
7857 unformat_input_t *i = vam->input;
7858 vl_api_bond_enslave_t *mp;
7859 u32 bond_sw_if_index;
7860 int ret;
7861 u8 is_passive;
7862 u8 is_long_timeout;
7863 u32 bond_sw_if_index_is_set = 0;
7864 u32 sw_if_index;
7865 u8 sw_if_index_is_set = 0;
7866
7867 /* Parse args required to build the message */
7868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7869 {
7870 if (unformat (i, "sw_if_index %d", &sw_if_index))
7871 sw_if_index_is_set = 1;
7872 else if (unformat (i, "bond %u", &bond_sw_if_index))
7873 bond_sw_if_index_is_set = 1;
7874 else if (unformat (i, "passive %d", &is_passive))
7875 ;
7876 else if (unformat (i, "long-timeout %d", &is_long_timeout))
7877 ;
7878 else
7879 break;
7880 }
7881
7882 if (bond_sw_if_index_is_set == 0)
7883 {
7884 errmsg ("Missing bond sw_if_index. ");
7885 return -99;
7886 }
7887 if (sw_if_index_is_set == 0)
7888 {
7889 errmsg ("Missing slave sw_if_index. ");
7890 return -99;
7891 }
7892
7893 /* Construct the API message */
7894 M (BOND_ENSLAVE, mp);
7895
7896 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
7897 mp->sw_if_index = ntohl (sw_if_index);
7898 mp->is_long_timeout = is_long_timeout;
7899 mp->is_passive = is_passive;
7900
7901 /* send it... */
7902 S (mp);
7903
7904 /* Wait for a reply... */
7905 W (ret);
7906 return ret;
7907}
7908
7909static int
7910api_bond_detach_slave (vat_main_t * vam)
7911{
7912 unformat_input_t *i = vam->input;
7913 vl_api_bond_detach_slave_t *mp;
7914 u32 sw_if_index = ~0;
7915 u8 sw_if_index_set = 0;
7916 int ret;
7917
7918 /* Parse args required to build the message */
7919 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7920 {
7921 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7922 sw_if_index_set = 1;
7923 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7924 sw_if_index_set = 1;
7925 else
7926 break;
7927 }
7928
7929 if (sw_if_index_set == 0)
7930 {
7931 errmsg ("missing vpp interface name. ");
7932 return -99;
7933 }
7934
7935 /* Construct the API message */
7936 M (BOND_DETACH_SLAVE, mp);
7937
7938 mp->sw_if_index = ntohl (sw_if_index);
7939
7940 /* send it... */
7941 S (mp);
7942
7943 /* Wait for a reply... */
7944 W (ret);
7945 return ret;
7946}
7947
7948static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007949api_ip_table_add_del (vat_main_t * vam)
7950{
7951 unformat_input_t *i = vam->input;
7952 vl_api_ip_table_add_del_t *mp;
7953 u32 table_id = ~0;
7954 u8 is_ipv6 = 0;
7955 u8 is_add = 1;
7956 int ret = 0;
7957
7958 /* Parse args required to build the message */
7959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7960 {
7961 if (unformat (i, "ipv6"))
7962 is_ipv6 = 1;
7963 else if (unformat (i, "del"))
7964 is_add = 0;
7965 else if (unformat (i, "add"))
7966 is_add = 1;
7967 else if (unformat (i, "table %d", &table_id))
7968 ;
7969 else
7970 {
7971 clib_warning ("parse error '%U'", format_unformat_error, i);
7972 return -99;
7973 }
7974 }
7975
7976 if (~0 == table_id)
7977 {
7978 errmsg ("missing table-ID");
7979 return -99;
7980 }
7981
7982 /* Construct the API message */
7983 M (IP_TABLE_ADD_DEL, mp);
7984
Neale Ranns097fa662018-05-01 05:17:55 -07007985 mp->table.table_id = ntohl (table_id);
7986 mp->table.is_ip6 = is_ipv6;
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007987 mp->is_add = is_add;
7988
7989 /* send it... */
7990 S (mp);
7991
7992 /* Wait for a reply... */
7993 W (ret);
7994
7995 return ret;
7996}
7997
Neale Ranns097fa662018-05-01 05:17:55 -07007998uword
7999unformat_fib_path (unformat_input_t * input, va_list * args)
8000{
8001 vat_main_t *vam = va_arg (*args, vat_main_t *);
8002 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
8003 u32 weight, preference;
8004 mpls_label_t out_label;
8005
8006 clib_memset (path, 0, sizeof (*path));
8007 path->weight = 1;
8008 path->sw_if_index = ~0;
8009 path->rpf_id = ~0;
8010 path->n_labels = 0;
8011
8012 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8013 {
8014 if (unformat (input, "%U %U",
8015 unformat_vl_api_ip4_address,
8016 &path->nh.address.ip4,
8017 api_unformat_sw_if_index, vam, &path->sw_if_index))
8018 {
8019 path->proto = FIB_API_PATH_NH_PROTO_IP4;
8020 }
8021 else if (unformat (input, "%U %U",
8022 unformat_vl_api_ip6_address,
8023 &path->nh.address.ip6,
8024 api_unformat_sw_if_index, vam, &path->sw_if_index))
8025 {
8026 path->proto = FIB_API_PATH_NH_PROTO_IP6;
8027 }
8028 else if (unformat (input, "weight %u", &weight))
8029 {
8030 path->weight = weight;
8031 }
8032 else if (unformat (input, "preference %u", &preference))
8033 {
8034 path->preference = preference;
8035 }
8036 else if (unformat (input, "%U next-hop-table %d",
8037 unformat_vl_api_ip4_address,
8038 &path->nh.address.ip4, &path->table_id))
8039 {
8040 path->proto = FIB_API_PATH_NH_PROTO_IP4;
8041 }
8042 else if (unformat (input, "%U next-hop-table %d",
8043 unformat_vl_api_ip6_address,
8044 &path->nh.address.ip6, &path->table_id))
8045 {
8046 path->proto = FIB_API_PATH_NH_PROTO_IP6;
8047 }
8048 else if (unformat (input, "%U",
8049 unformat_vl_api_ip4_address, &path->nh.address.ip4))
8050 {
8051 /*
8052 * the recursive next-hops are by default in the default table
8053 */
8054 path->table_id = 0;
8055 path->sw_if_index = ~0;
8056 path->proto = FIB_API_PATH_NH_PROTO_IP4;
8057 }
8058 else if (unformat (input, "%U",
8059 unformat_vl_api_ip6_address, &path->nh.address.ip6))
8060 {
8061 /*
8062 * the recursive next-hops are by default in the default table
8063 */
8064 path->table_id = 0;
8065 path->sw_if_index = ~0;
8066 path->proto = FIB_API_PATH_NH_PROTO_IP6;
8067 }
8068 else if (unformat (input, "resolve-via-host"))
8069 {
8070 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
8071 }
8072 else if (unformat (input, "resolve-via-attached"))
8073 {
8074 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
8075 }
8076 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
8077 {
8078 path->type = FIB_API_PATH_TYPE_LOCAL;
8079 path->sw_if_index = ~0;
8080 path->proto = FIB_API_PATH_NH_PROTO_IP4;
8081 }
8082 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
8083 {
8084 path->type = FIB_API_PATH_TYPE_LOCAL;
8085 path->sw_if_index = ~0;
8086 path->proto = FIB_API_PATH_NH_PROTO_IP6;
8087 }
8088 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
8089 ;
8090 else if (unformat (input, "via-label %d", &path->nh.via_label))
8091 {
8092 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
8093 path->sw_if_index = ~0;
8094 }
8095 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
8096 {
8097 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
8098 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
8099 }
8100 else if (unformat (input, "local"))
8101 {
8102 path->type = FIB_API_PATH_TYPE_LOCAL;
8103 }
8104 else if (unformat (input, "out-labels"))
8105 {
8106 while (unformat (input, "%d", &out_label))
8107 {
8108 path->label_stack[path->n_labels].label = out_label;
8109 path->label_stack[path->n_labels].is_uniform = 0;
8110 path->label_stack[path->n_labels].ttl = 64;
8111 path->n_labels++;
8112 }
8113 }
8114 else if (unformat (input, "via"))
8115 {
8116 /* new path, back up and return */
8117 unformat_put_input (input);
8118 unformat_put_input (input);
8119 unformat_put_input (input);
8120 unformat_put_input (input);
8121 break;
8122 }
8123 else
8124 {
8125 return (0);
8126 }
8127 }
8128
8129 path->proto = ntohl (path->proto);
8130 path->type = ntohl (path->type);
8131 path->flags = ntohl (path->flags);
8132 path->table_id = ntohl (path->table_id);
8133 path->sw_if_index = ntohl (path->sw_if_index);
8134
8135 return (1);
8136}
8137
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008138static int
Neale Ranns097fa662018-05-01 05:17:55 -07008139api_ip_route_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008140{
8141 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008142 vl_api_ip_route_add_del_t *mp;
8143 u32 vrf_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008144 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008145 u8 is_multipath = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008146 u8 prefix_set = 0;
8147 u8 path_count = 0;
8148 vl_api_prefix_t pfx = { };
8149 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008150 int count = 1;
8151 int j;
8152 f64 before = 0;
8153 u32 random_add_del = 0;
8154 u32 *random_vector = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008155 u32 random_seed = 0xdeaddabe;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008156
8157 /* Parse args required to build the message */
8158 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8159 {
Neale Ranns097fa662018-05-01 05:17:55 -07008160 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8161 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008162 else if (unformat (i, "del"))
8163 is_add = 0;
8164 else if (unformat (i, "add"))
8165 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008166 else if (unformat (i, "vrf %d", &vrf_id))
8167 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008168 else if (unformat (i, "count %d", &count))
8169 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008170 else if (unformat (i, "random"))
8171 random_add_del = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008172 else if (unformat (i, "multipath"))
8173 is_multipath = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008174 else if (unformat (i, "seed %d", &random_seed))
8175 ;
8176 else
Neale Ranns097fa662018-05-01 05:17:55 -07008177 if (unformat
8178 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
8179 {
8180 path_count++;
8181 if (8 == path_count)
8182 {
8183 errmsg ("max 8 paths");
8184 return -99;
8185 }
8186 }
8187 else
Damjan Marion7cd468a2016-12-19 23:05:39 +01008188 {
8189 clib_warning ("parse error '%U'", format_unformat_error, i);
8190 return -99;
8191 }
8192 }
8193
Neale Ranns097fa662018-05-01 05:17:55 -07008194 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008195 {
Neale Ranns097fa662018-05-01 05:17:55 -07008196 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008197 return -99;
8198 }
Neale Ranns097fa662018-05-01 05:17:55 -07008199 if (prefix_set == 0)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008200 {
Neale Ranns097fa662018-05-01 05:17:55 -07008201 errmsg ("missing prefix");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008202 return -99;
8203 }
8204
8205 /* Generate a pile of unique, random routes */
8206 if (random_add_del)
8207 {
Neale Ranns097fa662018-05-01 05:17:55 -07008208 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008209 u32 this_random_address;
Neale Ranns097fa662018-05-01 05:17:55 -07008210 uword *random_hash;
8211
Damjan Marion7cd468a2016-12-19 23:05:39 +01008212 random_hash = hash_create (count, sizeof (uword));
8213
Neale Ranns097fa662018-05-01 05:17:55 -07008214 hash_set (random_hash, i->as_u32, 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008215 for (j = 0; j <= count; j++)
8216 {
8217 do
8218 {
8219 this_random_address = random_u32 (&random_seed);
8220 this_random_address =
8221 clib_host_to_net_u32 (this_random_address);
8222 }
8223 while (hash_get (random_hash, this_random_address));
8224 vec_add1 (random_vector, this_random_address);
8225 hash_set (random_hash, this_random_address, 1);
8226 }
8227 hash_free (random_hash);
Neale Ranns097fa662018-05-01 05:17:55 -07008228 set_ip4_address (&pfx.address, random_vector[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008229 }
8230
8231 if (count > 1)
8232 {
8233 /* Turn on async mode */
8234 vam->async_mode = 1;
8235 vam->async_errors = 0;
8236 before = vat_time_now (vam);
8237 }
8238
8239 for (j = 0; j < count; j++)
8240 {
8241 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008242 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008243
8244 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008245 mp->is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008246
Neale Ranns097fa662018-05-01 05:17:55 -07008247 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8248 mp->route.table_id = ntohl (vrf_id);
8249 mp->route.n_paths = path_count;
8250
8251 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
8252
8253 if (random_add_del)
8254 set_ip4_address (&pfx.address, random_vector[j + 1]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008255 else
Neale Ranns097fa662018-05-01 05:17:55 -07008256 increment_address (&pfx.address);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008257 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008258 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008259 /* If we receive SIGTERM, stop now... */
8260 if (vam->do_exit)
8261 break;
8262 }
8263
8264 /* When testing multiple add/del ops, use a control-ping to sync */
8265 if (count > 1)
8266 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008267 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008268 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008269 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008270
8271 /* Shut off async mode */
8272 vam->async_mode = 0;
8273
Dave Barach59b25652017-09-10 15:04:27 -04008274 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008275 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008276
8277 timeout = vat_time_now (vam) + 1.0;
8278 while (vat_time_now (vam) < timeout)
8279 if (vam->result_ready == 1)
8280 goto out;
8281 vam->retval = -99;
8282
8283 out:
8284 if (vam->retval == -99)
8285 errmsg ("timeout");
8286
8287 if (vam->async_errors > 0)
8288 {
8289 errmsg ("%d asynchronous errors", vam->async_errors);
8290 vam->retval = -98;
8291 }
8292 vam->async_errors = 0;
8293 after = vat_time_now (vam);
8294
8295 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8296 if (j > 0)
8297 count = j;
8298
8299 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8300 count, after - before, count / (after - before));
8301 }
8302 else
8303 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008304 int ret;
8305
Damjan Marion7cd468a2016-12-19 23:05:39 +01008306 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008307 W (ret);
8308 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008309 }
8310
8311 /* Return the good/bad news */
8312 return (vam->retval);
8313}
8314
8315static int
Neale Ranns32e1c012016-11-22 17:07:28 +00008316api_ip_mroute_add_del (vat_main_t * vam)
8317{
8318 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008319 u8 path_set = 0, prefix_set = 0, is_add = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008320 vl_api_ip_mroute_add_del_t *mp;
Neale Ranns32e1c012016-11-22 17:07:28 +00008321 mfib_entry_flags_t eflags = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008322 vl_api_mfib_path_t path;
8323 vl_api_mprefix_t pfx = { };
8324 u32 vrf_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008325 int ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008326
8327 /* Parse args required to build the message */
8328 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8329 {
Neale Ranns097fa662018-05-01 05:17:55 -07008330 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
Neale Ranns32e1c012016-11-22 17:07:28 +00008331 {
Neale Ranns097fa662018-05-01 05:17:55 -07008332 prefix_set = 1;
8333 pfx.grp_address_length = htons (pfx.grp_address_length);
Neale Ranns32e1c012016-11-22 17:07:28 +00008334 }
8335 else if (unformat (i, "del"))
8336 is_add = 0;
8337 else if (unformat (i, "add"))
8338 is_add = 1;
8339 else if (unformat (i, "vrf %d", &vrf_id))
8340 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008341 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
8342 path.itf_flags = htonl (path.itf_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008343 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
8344 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008345 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
8346 path_set = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008347 else
8348 {
8349 clib_warning ("parse error '%U'", format_unformat_error, i);
8350 return -99;
8351 }
8352 }
8353
Neale Ranns097fa662018-05-01 05:17:55 -07008354 if (prefix_set == 0)
Neale Ranns32e1c012016-11-22 17:07:28 +00008355 {
8356 errmsg ("missing addresses\n");
8357 return -99;
8358 }
Neale Ranns097fa662018-05-01 05:17:55 -07008359 if (path_set == 0)
8360 {
8361 errmsg ("missing path\n");
8362 return -99;
8363 }
Neale Ranns32e1c012016-11-22 17:07:28 +00008364
8365 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008366 M (IP_MROUTE_ADD_DEL, mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008367
Neale Ranns32e1c012016-11-22 17:07:28 +00008368 mp->is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008369 mp->is_multipath = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008370
Neale Ranns097fa662018-05-01 05:17:55 -07008371 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8372 mp->route.table_id = htonl (vrf_id);
8373 mp->route.n_paths = 1;
8374 mp->route.entry_flags = htonl (eflags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008375
Neale Ranns097fa662018-05-01 05:17:55 -07008376 clib_memcpy (&mp->route.paths, &path, sizeof (path));
Neale Ranns32e1c012016-11-22 17:07:28 +00008377
8378 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008379 S (mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008380 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008381 W (ret);
8382 return ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008383}
8384
8385static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008386api_mpls_table_add_del (vat_main_t * vam)
8387{
8388 unformat_input_t *i = vam->input;
8389 vl_api_mpls_table_add_del_t *mp;
8390 u32 table_id = ~0;
8391 u8 is_add = 1;
8392 int ret = 0;
8393
8394 /* Parse args required to build the message */
8395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8396 {
Florin Corasd0a59722017-10-15 17:41:21 +00008397 if (unformat (i, "table %d", &table_id))
8398 ;
8399 else if (unformat (i, "del"))
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008400 is_add = 0;
8401 else if (unformat (i, "add"))
8402 is_add = 1;
8403 else
8404 {
8405 clib_warning ("parse error '%U'", format_unformat_error, i);
8406 return -99;
8407 }
8408 }
8409
8410 if (~0 == table_id)
8411 {
8412 errmsg ("missing table-ID");
8413 return -99;
8414 }
8415
8416 /* Construct the API message */
8417 M (MPLS_TABLE_ADD_DEL, mp);
8418
Neale Ranns097fa662018-05-01 05:17:55 -07008419 mp->mt_table.mt_table_id = ntohl (table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008420 mp->mt_is_add = is_add;
8421
8422 /* send it... */
8423 S (mp);
8424
8425 /* Wait for a reply... */
8426 W (ret);
8427
8428 return ret;
8429}
8430
8431static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008432api_mpls_route_add_del (vat_main_t * vam)
8433{
Neale Ranns097fa662018-05-01 05:17:55 -07008434 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
8435 mpls_label_t local_label = MPLS_LABEL_INVALID;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008436 unformat_input_t *i = vam->input;
8437 vl_api_mpls_route_add_del_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07008438 vl_api_fib_path_t paths[8];
8439 int count = 1, j;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008440 f64 before = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008441
8442 /* Parse args required to build the message */
8443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8444 {
Neale Ranns097fa662018-05-01 05:17:55 -07008445 if (unformat (i, "%d", &local_label))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008446 ;
8447 else if (unformat (i, "eos"))
8448 is_eos = 1;
8449 else if (unformat (i, "non-eos"))
8450 is_eos = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008451 else if (unformat (i, "del"))
8452 is_add = 0;
8453 else if (unformat (i, "add"))
8454 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008455 else if (unformat (i, "multipath"))
8456 is_multipath = 1;
8457 else if (unformat (i, "count %d", &count))
8458 ;
John Loe166fd92018-09-13 14:08:59 -04008459 else
8460 if (unformat
Neale Ranns097fa662018-05-01 05:17:55 -07008461 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Loe166fd92018-09-13 14:08:59 -04008462 {
Neale Ranns097fa662018-05-01 05:17:55 -07008463 path_count++;
8464 if (8 == path_count)
8465 {
8466 errmsg ("max 8 paths");
8467 return -99;
8468 }
John Loe166fd92018-09-13 14:08:59 -04008469 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008470 else
8471 {
8472 clib_warning ("parse error '%U'", format_unformat_error, i);
8473 return -99;
8474 }
8475 }
8476
Neale Ranns097fa662018-05-01 05:17:55 -07008477 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008478 {
Neale Ranns097fa662018-05-01 05:17:55 -07008479 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008480 return -99;
8481 }
8482
8483 if (MPLS_LABEL_INVALID == local_label)
8484 {
8485 errmsg ("missing label");
8486 return -99;
8487 }
8488
8489 if (count > 1)
8490 {
8491 /* Turn on async mode */
8492 vam->async_mode = 1;
8493 vam->async_errors = 0;
8494 before = vat_time_now (vam);
8495 }
8496
8497 for (j = 0; j < count; j++)
8498 {
8499 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008500 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008501
8502 mp->mr_is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008503 mp->mr_is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008504
Neale Ranns097fa662018-05-01 05:17:55 -07008505 mp->mr_route.mr_label = local_label;
8506 mp->mr_route.mr_eos = is_eos;
8507 mp->mr_route.mr_table_id = 0;
8508 mp->mr_route.mr_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008509
Neale Ranns097fa662018-05-01 05:17:55 -07008510 clib_memcpy (&mp->mr_route.mr_paths, paths,
8511 sizeof (paths[0]) * path_count);
Neale Rannsda78f952017-05-24 09:15:43 -07008512
Damjan Marion7cd468a2016-12-19 23:05:39 +01008513 local_label++;
8514
8515 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008516 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008517 /* If we receive SIGTERM, stop now... */
8518 if (vam->do_exit)
8519 break;
8520 }
8521
8522 /* When testing multiple add/del ops, use a control-ping to sync */
8523 if (count > 1)
8524 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008525 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008526 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008527 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008528
8529 /* Shut off async mode */
8530 vam->async_mode = 0;
8531
Dave Barach59b25652017-09-10 15:04:27 -04008532 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008533 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008534
8535 timeout = vat_time_now (vam) + 1.0;
8536 while (vat_time_now (vam) < timeout)
8537 if (vam->result_ready == 1)
8538 goto out;
8539 vam->retval = -99;
8540
8541 out:
8542 if (vam->retval == -99)
8543 errmsg ("timeout");
8544
8545 if (vam->async_errors > 0)
8546 {
8547 errmsg ("%d asynchronous errors", vam->async_errors);
8548 vam->retval = -98;
8549 }
8550 vam->async_errors = 0;
8551 after = vat_time_now (vam);
8552
8553 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8554 if (j > 0)
8555 count = j;
8556
8557 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8558 count, after - before, count / (after - before));
8559 }
8560 else
8561 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008562 int ret;
8563
Damjan Marion7cd468a2016-12-19 23:05:39 +01008564 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008565 W (ret);
8566 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008567 }
8568
8569 /* Return the good/bad news */
8570 return (vam->retval);
Neale Ranns097fa662018-05-01 05:17:55 -07008571 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008572}
8573
8574static int
8575api_mpls_ip_bind_unbind (vat_main_t * vam)
8576{
8577 unformat_input_t *i = vam->input;
8578 vl_api_mpls_ip_bind_unbind_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008579 u32 ip_table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008580 u8 is_bind = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008581 vl_api_prefix_t pfx;
8582 u8 prefix_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008583 mpls_label_t local_label = MPLS_LABEL_INVALID;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008584 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008585
8586 /* Parse args required to build the message */
8587 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8588 {
Neale Ranns097fa662018-05-01 05:17:55 -07008589 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8590 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008591 else if (unformat (i, "%d", &local_label))
8592 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008593 else if (unformat (i, "table-id %d", &ip_table_id))
8594 ;
8595 else if (unformat (i, "unbind"))
8596 is_bind = 0;
8597 else if (unformat (i, "bind"))
8598 is_bind = 1;
8599 else
8600 {
8601 clib_warning ("parse error '%U'", format_unformat_error, i);
8602 return -99;
8603 }
8604 }
8605
Neale Ranns097fa662018-05-01 05:17:55 -07008606 if (!prefix_set)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008607 {
Neale Ranns097fa662018-05-01 05:17:55 -07008608 errmsg ("IP prefix not set");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008609 return -99;
8610 }
8611
8612 if (MPLS_LABEL_INVALID == local_label)
8613 {
8614 errmsg ("missing label");
8615 return -99;
8616 }
8617
8618 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008619 M (MPLS_IP_BIND_UNBIND, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008620
Damjan Marion7cd468a2016-12-19 23:05:39 +01008621 mp->mb_is_bind = is_bind;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008622 mp->mb_ip_table_id = ntohl (ip_table_id);
8623 mp->mb_mpls_table_id = 0;
8624 mp->mb_label = ntohl (local_label);
Neale Ranns097fa662018-05-01 05:17:55 -07008625 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008626
8627 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008628 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008629
8630 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008631 W (ret);
8632 return ret;
Neale Ranns097fa662018-05-01 05:17:55 -07008633 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008634}
8635
8636static int
John Loe166fd92018-09-13 14:08:59 -04008637api_sr_mpls_policy_add (vat_main_t * vam)
8638{
8639 unformat_input_t *i = vam->input;
8640 vl_api_sr_mpls_policy_add_t *mp;
8641 u32 bsid = 0;
8642 u32 weight = 1;
8643 u8 type = 0;
8644 u8 n_segments = 0;
8645 u32 sid;
8646 u32 *segments = NULL;
8647 int ret;
8648
8649 /* Parse args required to build the message */
8650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8651 {
8652 if (unformat (i, "bsid %d", &bsid))
8653 ;
8654 else if (unformat (i, "weight %d", &weight))
8655 ;
8656 else if (unformat (i, "spray"))
8657 type = 1;
8658 else if (unformat (i, "next %d", &sid))
8659 {
8660 n_segments += 1;
8661 vec_add1 (segments, htonl (sid));
8662 }
8663 else
8664 {
8665 clib_warning ("parse error '%U'", format_unformat_error, i);
8666 return -99;
8667 }
8668 }
8669
8670 if (bsid == 0)
8671 {
8672 errmsg ("bsid not set");
8673 return -99;
8674 }
8675
8676 if (n_segments == 0)
8677 {
8678 errmsg ("no sid in segment stack");
8679 return -99;
8680 }
8681
8682 /* Construct the API message */
8683 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
8684
8685 mp->bsid = htonl (bsid);
8686 mp->weight = htonl (weight);
8687 mp->type = type;
8688 mp->n_segments = n_segments;
8689 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
8690 vec_free (segments);
8691
8692 /* send it... */
8693 S (mp);
8694
8695 /* Wait for a reply... */
8696 W (ret);
8697 return ret;
8698}
8699
8700static int
8701api_sr_mpls_policy_del (vat_main_t * vam)
8702{
8703 unformat_input_t *i = vam->input;
8704 vl_api_sr_mpls_policy_del_t *mp;
8705 u32 bsid = 0;
8706 int ret;
8707
8708 /* Parse args required to build the message */
8709 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8710 {
8711 if (unformat (i, "bsid %d", &bsid))
8712 ;
8713 else
8714 {
8715 clib_warning ("parse error '%U'", format_unformat_error, i);
8716 return -99;
8717 }
8718 }
8719
8720 if (bsid == 0)
8721 {
8722 errmsg ("bsid not set");
8723 return -99;
8724 }
8725
8726 /* Construct the API message */
8727 M (SR_MPLS_POLICY_DEL, mp);
8728
8729 mp->bsid = htonl (bsid);
8730
8731 /* send it... */
8732 S (mp);
8733
8734 /* Wait for a reply... */
8735 W (ret);
8736 return ret;
8737}
8738
8739static int
Neale Rannsd792d9c2017-10-21 10:53:20 -07008740api_bier_table_add_del (vat_main_t * vam)
8741{
8742 unformat_input_t *i = vam->input;
8743 vl_api_bier_table_add_del_t *mp;
8744 u8 is_add = 1;
8745 u32 set = 0, sub_domain = 0, hdr_len = 3;
8746 mpls_label_t local_label = MPLS_LABEL_INVALID;
8747 int ret;
8748
8749 /* Parse args required to build the message */
8750 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8751 {
8752 if (unformat (i, "sub-domain %d", &sub_domain))
8753 ;
8754 else if (unformat (i, "set %d", &set))
8755 ;
8756 else if (unformat (i, "label %d", &local_label))
8757 ;
8758 else if (unformat (i, "hdr-len %d", &hdr_len))
8759 ;
8760 else if (unformat (i, "add"))
8761 is_add = 1;
8762 else if (unformat (i, "del"))
8763 is_add = 0;
8764 else
8765 {
8766 clib_warning ("parse error '%U'", format_unformat_error, i);
8767 return -99;
8768 }
8769 }
8770
8771 if (MPLS_LABEL_INVALID == local_label)
8772 {
8773 errmsg ("missing label\n");
8774 return -99;
8775 }
8776
8777 /* Construct the API message */
8778 M (BIER_TABLE_ADD_DEL, mp);
8779
8780 mp->bt_is_add = is_add;
8781 mp->bt_label = ntohl (local_label);
8782 mp->bt_tbl_id.bt_set = set;
8783 mp->bt_tbl_id.bt_sub_domain = sub_domain;
8784 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
8785
8786 /* send it... */
8787 S (mp);
8788
8789 /* Wait for a reply... */
8790 W (ret);
8791
8792 return (ret);
8793}
8794
8795static int
8796api_bier_route_add_del (vat_main_t * vam)
8797{
8798 unformat_input_t *i = vam->input;
8799 vl_api_bier_route_add_del_t *mp;
8800 u8 is_add = 1;
8801 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
8802 ip4_address_t v4_next_hop_address;
8803 ip6_address_t v6_next_hop_address;
8804 u8 next_hop_set = 0;
8805 u8 next_hop_proto_is_ip4 = 1;
8806 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
8807 int ret;
8808
8809 /* Parse args required to build the message */
8810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8811 {
8812 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
8813 {
8814 next_hop_proto_is_ip4 = 1;
8815 next_hop_set = 1;
8816 }
8817 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
8818 {
8819 next_hop_proto_is_ip4 = 0;
8820 next_hop_set = 1;
8821 }
8822 if (unformat (i, "sub-domain %d", &sub_domain))
8823 ;
8824 else if (unformat (i, "set %d", &set))
8825 ;
8826 else if (unformat (i, "hdr-len %d", &hdr_len))
8827 ;
8828 else if (unformat (i, "bp %d", &bp))
8829 ;
8830 else if (unformat (i, "add"))
8831 is_add = 1;
8832 else if (unformat (i, "del"))
8833 is_add = 0;
8834 else if (unformat (i, "out-label %d", &next_hop_out_label))
8835 ;
8836 else
8837 {
8838 clib_warning ("parse error '%U'", format_unformat_error, i);
8839 return -99;
8840 }
8841 }
8842
8843 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
8844 {
8845 errmsg ("next hop / label set\n");
8846 return -99;
8847 }
8848 if (0 == bp)
8849 {
8850 errmsg ("bit=position not set\n");
8851 return -99;
8852 }
8853
8854 /* Construct the API message */
Neale Ranns31ed7442018-02-23 05:29:09 -08008855 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
Neale Rannsd792d9c2017-10-21 10:53:20 -07008856
8857 mp->br_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008858 mp->br_route.br_tbl_id.bt_set = set;
8859 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
8860 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
8861 mp->br_route.br_bp = ntohs (bp);
8862 mp->br_route.br_n_paths = 1;
8863 mp->br_route.br_paths[0].n_labels = 1;
8864 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
8865 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
8866 FIB_API_PATH_NH_PROTO_IP4 :
8867 FIB_API_PATH_NH_PROTO_IP6);
Neale Rannsd792d9c2017-10-21 10:53:20 -07008868
8869 if (next_hop_proto_is_ip4)
8870 {
Neale Ranns097fa662018-05-01 05:17:55 -07008871 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008872 &v4_next_hop_address, sizeof (v4_next_hop_address));
8873 }
8874 else
8875 {
Neale Ranns097fa662018-05-01 05:17:55 -07008876 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008877 &v6_next_hop_address, sizeof (v6_next_hop_address));
8878 }
8879
8880 /* send it... */
8881 S (mp);
8882
8883 /* Wait for a reply... */
8884 W (ret);
8885
8886 return (ret);
8887}
8888
8889static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008890api_proxy_arp_add_del (vat_main_t * vam)
8891{
8892 unformat_input_t *i = vam->input;
8893 vl_api_proxy_arp_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008894 u32 vrf_id = 0;
8895 u8 is_add = 1;
Neale Ranns37029302018-08-10 05:30:06 -07008896 vl_api_ip4_address_t lo, hi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008897 u8 range_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008898 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008899
8900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8901 {
8902 if (unformat (i, "vrf %d", &vrf_id))
8903 ;
Neale Ranns37029302018-08-10 05:30:06 -07008904 else if (unformat (i, "%U - %U", unformat_vl_api_ip4_address, &lo,
8905 unformat_vl_api_ip4_address, &hi))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008906 range_set = 1;
8907 else if (unformat (i, "del"))
8908 is_add = 0;
8909 else
8910 {
8911 clib_warning ("parse error '%U'", format_unformat_error, i);
8912 return -99;
8913 }
8914 }
8915
8916 if (range_set == 0)
8917 {
8918 errmsg ("address range not set");
8919 return -99;
8920 }
8921
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008922 M (PROXY_ARP_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008923
Neale Ranns37029302018-08-10 05:30:06 -07008924 mp->proxy.table_id = ntohl (vrf_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008925 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -07008926 clib_memcpy (mp->proxy.low, &lo, sizeof (lo));
8927 clib_memcpy (mp->proxy.hi, &hi, sizeof (hi));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008928
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008929 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008930 W (ret);
8931 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008932}
8933
8934static int
8935api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
8936{
8937 unformat_input_t *i = vam->input;
8938 vl_api_proxy_arp_intfc_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008939 u32 sw_if_index;
8940 u8 enable = 1;
8941 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008942 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008943
8944 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8945 {
8946 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8947 sw_if_index_set = 1;
8948 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8949 sw_if_index_set = 1;
8950 else if (unformat (i, "enable"))
8951 enable = 1;
8952 else if (unformat (i, "disable"))
8953 enable = 0;
8954 else
8955 {
8956 clib_warning ("parse error '%U'", format_unformat_error, i);
8957 return -99;
8958 }
8959 }
8960
8961 if (sw_if_index_set == 0)
8962 {
8963 errmsg ("missing interface name or sw_if_index");
8964 return -99;
8965 }
8966
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008967 M (PROXY_ARP_INTFC_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008968
8969 mp->sw_if_index = ntohl (sw_if_index);
8970 mp->enable_disable = enable;
8971
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008972 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008973 W (ret);
8974 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008975}
8976
8977static int
8978api_mpls_tunnel_add_del (vat_main_t * vam)
8979{
8980 unformat_input_t *i = vam->input;
8981 vl_api_mpls_tunnel_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008982
Neale Ranns097fa662018-05-01 05:17:55 -07008983 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008984 u32 sw_if_index = ~0;
Neale Ranns097fa662018-05-01 05:17:55 -07008985 u8 path_count = 0;
8986 u8 l2_only = 0;
8987 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008988 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008989
8990 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8991 {
8992 if (unformat (i, "add"))
8993 is_add = 1;
John Lo06fda9c2018-10-03 16:32:44 -04008994 else
8995 if (unformat
8996 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
8997 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008998 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
8999 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009000 else if (unformat (i, "l2-only"))
9001 l2_only = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07009002 else
9003 if (unformat
9004 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Lo06fda9c2018-10-03 16:32:44 -04009005 {
Neale Ranns097fa662018-05-01 05:17:55 -07009006 path_count++;
9007 if (8 == path_count)
9008 {
9009 errmsg ("max 8 paths");
9010 return -99;
9011 }
John Lo06fda9c2018-10-03 16:32:44 -04009012 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01009013 else
9014 {
9015 clib_warning ("parse error '%U'", format_unformat_error, i);
9016 return -99;
9017 }
9018 }
9019
Neale Ranns097fa662018-05-01 05:17:55 -07009020 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009021
Damjan Marion7cd468a2016-12-19 23:05:39 +01009022 mp->mt_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07009023 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
9024 mp->mt_tunnel.mt_l2_only = l2_only;
9025 mp->mt_tunnel.mt_is_multicast = 0;
9026 mp->mt_tunnel.mt_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009027
Neale Ranns097fa662018-05-01 05:17:55 -07009028 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
9029 sizeof (paths[0]) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009030
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009031 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009032 W (ret);
9033 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009034}
9035
9036static int
9037api_sw_interface_set_unnumbered (vat_main_t * vam)
9038{
9039 unformat_input_t *i = vam->input;
9040 vl_api_sw_interface_set_unnumbered_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009041 u32 sw_if_index;
9042 u32 unnum_sw_index = ~0;
9043 u8 is_add = 1;
9044 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009045 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009046
9047 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9048 {
9049 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9050 sw_if_index_set = 1;
9051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9052 sw_if_index_set = 1;
9053 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
9054 ;
9055 else if (unformat (i, "del"))
9056 is_add = 0;
9057 else
9058 {
9059 clib_warning ("parse error '%U'", format_unformat_error, i);
9060 return -99;
9061 }
9062 }
9063
9064 if (sw_if_index_set == 0)
9065 {
9066 errmsg ("missing interface name or sw_if_index");
9067 return -99;
9068 }
9069
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009070 M (SW_INTERFACE_SET_UNNUMBERED, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009071
9072 mp->sw_if_index = ntohl (sw_if_index);
9073 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
9074 mp->is_add = is_add;
9075
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009076 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009077 W (ret);
9078 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009079}
9080
9081static int
9082api_ip_neighbor_add_del (vat_main_t * vam)
9083{
Neale Ranns37029302018-08-10 05:30:06 -07009084 vl_api_mac_address_t mac_address;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009085 unformat_input_t *i = vam->input;
9086 vl_api_ip_neighbor_add_del_t *mp;
Neale Ranns37029302018-08-10 05:30:06 -07009087 vl_api_address_t ip_address;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009088 u32 sw_if_index;
9089 u8 sw_if_index_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009090 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009091 u8 mac_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -07009092 u8 address_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009093 int ret;
Neale Ranns37029302018-08-10 05:30:06 -07009094 ip_neighbor_flags_t flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009095
Neale Ranns37029302018-08-10 05:30:06 -07009096 flags = IP_NEIGHBOR_FLAG_NONE;
9097 clib_memset (&ip_address, 0, sizeof (ip_address));
9098 clib_memset (&mac_address, 0, sizeof (mac_address));
Neale Ranns097fa662018-05-01 05:17:55 -07009099
Damjan Marion7cd468a2016-12-19 23:05:39 +01009100 /* Parse args required to build the message */
9101 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9102 {
Neale Ranns37029302018-08-10 05:30:06 -07009103 if (unformat (i, "mac %U", unformat_vl_api_mac_address, &mac_address))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009104 {
9105 mac_set = 1;
9106 }
9107 else if (unformat (i, "del"))
9108 is_add = 0;
9109 else
9110 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9111 sw_if_index_set = 1;
9112 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9113 sw_if_index_set = 1;
Neale Ranns37029302018-08-10 05:30:06 -07009114 else if (unformat (i, "static"))
9115 flags |= IP_NEIGHBOR_FLAG_STATIC;
Neale Rannsb3b2de72017-03-08 05:17:22 -08009116 else if (unformat (i, "no-fib-entry"))
Neale Ranns37029302018-08-10 05:30:06 -07009117 flags |= IP_NEIGHBOR_FLAG_NO_FIB_ENTRY;
9118 else if (unformat (i, "dst %U", unformat_vl_api_address, &ip_address))
9119 address_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009120 else
9121 {
9122 clib_warning ("parse error '%U'", format_unformat_error, i);
9123 return -99;
9124 }
9125 }
9126
9127 if (sw_if_index_set == 0)
9128 {
9129 errmsg ("missing interface name or sw_if_index");
9130 return -99;
9131 }
Neale Ranns37029302018-08-10 05:30:06 -07009132 if (!address_set)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009133 {
9134 errmsg ("no address set");
9135 return -99;
9136 }
9137
9138 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009139 M (IP_NEIGHBOR_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009140
Neale Ranns37029302018-08-10 05:30:06 -07009141 mp->neighbor.sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009142 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -07009143 mp->neighbor.flags = htonl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009144 if (mac_set)
Neale Ranns37029302018-08-10 05:30:06 -07009145 clib_memcpy (&mp->neighbor.mac_address, &mac_address,
9146 sizeof (mac_address));
9147 if (address_set)
9148 clib_memcpy (&mp->neighbor.ip_address, &ip_address, sizeof (ip_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009149
9150 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009151 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009152
9153 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009154 W (ret);
9155 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009156}
9157
9158static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009159api_create_vlan_subif (vat_main_t * vam)
9160{
9161 unformat_input_t *i = vam->input;
9162 vl_api_create_vlan_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009163 u32 sw_if_index;
9164 u8 sw_if_index_set = 0;
9165 u32 vlan_id;
9166 u8 vlan_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009167 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009168
9169 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9170 {
9171 if (unformat (i, "sw_if_index %d", &sw_if_index))
9172 sw_if_index_set = 1;
9173 else
9174 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9175 sw_if_index_set = 1;
9176 else if (unformat (i, "vlan %d", &vlan_id))
9177 vlan_id_set = 1;
9178 else
9179 {
9180 clib_warning ("parse error '%U'", format_unformat_error, i);
9181 return -99;
9182 }
9183 }
9184
9185 if (sw_if_index_set == 0)
9186 {
9187 errmsg ("missing interface name or sw_if_index");
9188 return -99;
9189 }
9190
9191 if (vlan_id_set == 0)
9192 {
9193 errmsg ("missing vlan_id");
9194 return -99;
9195 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009196 M (CREATE_VLAN_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009197
9198 mp->sw_if_index = ntohl (sw_if_index);
9199 mp->vlan_id = ntohl (vlan_id);
9200
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009201 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009202 W (ret);
9203 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009204}
9205
9206#define foreach_create_subif_bit \
9207_(no_tags) \
9208_(one_tag) \
9209_(two_tags) \
9210_(dot1ad) \
9211_(exact_match) \
9212_(default_sub) \
9213_(outer_vlan_id_any) \
9214_(inner_vlan_id_any)
9215
9216static int
9217api_create_subif (vat_main_t * vam)
9218{
9219 unformat_input_t *i = vam->input;
9220 vl_api_create_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009221 u32 sw_if_index;
9222 u8 sw_if_index_set = 0;
9223 u32 sub_id;
9224 u8 sub_id_set = 0;
9225 u32 no_tags = 0;
9226 u32 one_tag = 0;
9227 u32 two_tags = 0;
9228 u32 dot1ad = 0;
9229 u32 exact_match = 0;
9230 u32 default_sub = 0;
9231 u32 outer_vlan_id_any = 0;
9232 u32 inner_vlan_id_any = 0;
9233 u32 tmp;
9234 u16 outer_vlan_id = 0;
9235 u16 inner_vlan_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009236 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009237
9238 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9239 {
9240 if (unformat (i, "sw_if_index %d", &sw_if_index))
9241 sw_if_index_set = 1;
9242 else
9243 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9244 sw_if_index_set = 1;
9245 else if (unformat (i, "sub_id %d", &sub_id))
9246 sub_id_set = 1;
9247 else if (unformat (i, "outer_vlan_id %d", &tmp))
9248 outer_vlan_id = tmp;
9249 else if (unformat (i, "inner_vlan_id %d", &tmp))
9250 inner_vlan_id = tmp;
9251
9252#define _(a) else if (unformat (i, #a)) a = 1 ;
9253 foreach_create_subif_bit
9254#undef _
9255 else
9256 {
9257 clib_warning ("parse error '%U'", format_unformat_error, i);
9258 return -99;
9259 }
9260 }
9261
9262 if (sw_if_index_set == 0)
9263 {
9264 errmsg ("missing interface name or sw_if_index");
9265 return -99;
9266 }
9267
9268 if (sub_id_set == 0)
9269 {
9270 errmsg ("missing sub_id");
9271 return -99;
9272 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009273 M (CREATE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009274
9275 mp->sw_if_index = ntohl (sw_if_index);
9276 mp->sub_id = ntohl (sub_id);
9277
Ole Trøan3b0d7e42019-03-15 16:14:41 +00009278#define _(a) mp->a = a;
9279 foreach_create_subif_bit;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009280#undef _
9281
9282 mp->outer_vlan_id = ntohs (outer_vlan_id);
9283 mp->inner_vlan_id = ntohs (inner_vlan_id);
9284
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009285 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009286 W (ret);
9287 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009288}
9289
9290static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009291api_reset_fib (vat_main_t * vam)
9292{
9293 unformat_input_t *i = vam->input;
9294 vl_api_reset_fib_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009295 u32 vrf_id = 0;
9296 u8 is_ipv6 = 0;
9297 u8 vrf_id_set = 0;
9298
Jon Loeliger56c7b012017-02-01 12:31:41 -06009299 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009300 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9301 {
9302 if (unformat (i, "vrf %d", &vrf_id))
9303 vrf_id_set = 1;
9304 else if (unformat (i, "ipv6"))
9305 is_ipv6 = 1;
9306 else
9307 {
9308 clib_warning ("parse error '%U'", format_unformat_error, i);
9309 return -99;
9310 }
9311 }
9312
9313 if (vrf_id_set == 0)
9314 {
9315 errmsg ("missing vrf id");
9316 return -99;
9317 }
9318
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009319 M (RESET_FIB, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009320
9321 mp->vrf_id = ntohl (vrf_id);
9322 mp->is_ipv6 = is_ipv6;
9323
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009324 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009325 W (ret);
9326 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009327}
9328
9329static int
9330api_dhcp_proxy_config (vat_main_t * vam)
9331{
9332 unformat_input_t *i = vam->input;
9333 vl_api_dhcp_proxy_config_t *mp;
Neale Ranns20a175a2017-02-14 07:28:41 -08009334 u32 rx_vrf_id = 0;
9335 u32 server_vrf_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009336 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009337 u8 v4_address_set = 0;
9338 u8 v6_address_set = 0;
9339 ip4_address_t v4address;
9340 ip6_address_t v6address;
9341 u8 v4_src_address_set = 0;
9342 u8 v6_src_address_set = 0;
9343 ip4_address_t v4srcaddress;
9344 ip6_address_t v6srcaddress;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009345 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009346
9347 /* Parse args required to build the message */
9348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9349 {
9350 if (unformat (i, "del"))
9351 is_add = 0;
Neale Ranns20a175a2017-02-14 07:28:41 -08009352 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009353 ;
Neale Ranns20a175a2017-02-14 07:28:41 -08009354 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009355 ;
9356 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
9357 v4_address_set = 1;
9358 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
9359 v6_address_set = 1;
9360 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
9361 v4_src_address_set = 1;
9362 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
9363 v6_src_address_set = 1;
9364 else
9365 break;
9366 }
9367
9368 if (v4_address_set && v6_address_set)
9369 {
9370 errmsg ("both v4 and v6 server addresses set");
9371 return -99;
9372 }
9373 if (!v4_address_set && !v6_address_set)
9374 {
9375 errmsg ("no server addresses set");
9376 return -99;
9377 }
9378
9379 if (v4_src_address_set && v6_src_address_set)
9380 {
9381 errmsg ("both v4 and v6 src addresses set");
9382 return -99;
9383 }
9384 if (!v4_src_address_set && !v6_src_address_set)
9385 {
9386 errmsg ("no src addresses set");
9387 return -99;
9388 }
9389
9390 if (!(v4_src_address_set && v4_address_set) &&
9391 !(v6_src_address_set && v6_address_set))
9392 {
9393 errmsg ("no matching server and src addresses set");
9394 return -99;
9395 }
9396
9397 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009398 M (DHCP_PROXY_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009399
Damjan Marion7cd468a2016-12-19 23:05:39 +01009400 mp->is_add = is_add;
Neale Ranns20a175a2017-02-14 07:28:41 -08009401 mp->rx_vrf_id = ntohl (rx_vrf_id);
9402 mp->server_vrf_id = ntohl (server_vrf_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009403 if (v6_address_set)
9404 {
9405 mp->is_ipv6 = 1;
9406 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
9407 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
9408 }
9409 else
9410 {
9411 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
9412 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
9413 }
9414
9415 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009416 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009417
9418 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009419 W (ret);
9420 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009421}
9422
Neale Ranns20a175a2017-02-14 07:28:41 -08009423#define vl_api_dhcp_proxy_details_t_endian vl_noop_handler
9424#define vl_api_dhcp_proxy_details_t_print vl_noop_handler
9425
9426static void
9427vl_api_dhcp_proxy_details_t_handler (vl_api_dhcp_proxy_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009428{
Neale Ranns20a175a2017-02-14 07:28:41 -08009429 vat_main_t *vam = &vat_main;
Neale Ranns3466c302017-02-16 07:45:03 -08009430 u32 i, count = mp->count;
9431 vl_api_dhcp_server_t *s;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009432
Neale Ranns20a175a2017-02-14 07:28:41 -08009433 if (mp->is_ipv6)
9434 print (vam->ofp,
John Lo70bfcaf2017-11-14 13:19:26 -05009435 "RX Table-ID %d, Source Address %U, VSS Type %d, "
Igor Mikhailov (imichail)26f341a2018-02-12 13:45:51 -08009436 "VSS ASCII VPN-ID '%s', VSS RFC2685 VPN-ID (oui:id) %d:%d",
Neale Ranns20a175a2017-02-14 07:28:41 -08009437 ntohl (mp->rx_vrf_id),
Neale Ranns20a175a2017-02-14 07:28:41 -08009438 format_ip6_address, mp->dhcp_src_address,
John Lo70bfcaf2017-11-14 13:19:26 -05009439 mp->vss_type, mp->vss_vpn_ascii_id,
Neale Ranns20a175a2017-02-14 07:28:41 -08009440 ntohl (mp->vss_oui), ntohl (mp->vss_fib_id));
9441 else
9442 print (vam->ofp,
John Lo70bfcaf2017-11-14 13:19:26 -05009443 "RX Table-ID %d, Source Address %U, VSS Type %d, "
Igor Mikhailov (imichail)26f341a2018-02-12 13:45:51 -08009444 "VSS ASCII VPN-ID '%s', VSS RFC2685 VPN-ID (oui:id) %d:%d",
Neale Ranns20a175a2017-02-14 07:28:41 -08009445 ntohl (mp->rx_vrf_id),
Neale Ranns20a175a2017-02-14 07:28:41 -08009446 format_ip4_address, mp->dhcp_src_address,
John Lo70bfcaf2017-11-14 13:19:26 -05009447 mp->vss_type, mp->vss_vpn_ascii_id,
Neale Ranns20a175a2017-02-14 07:28:41 -08009448 ntohl (mp->vss_oui), ntohl (mp->vss_fib_id));
Neale Ranns3466c302017-02-16 07:45:03 -08009449
9450 for (i = 0; i < count; i++)
9451 {
9452 s = &mp->servers[i];
9453
9454 if (mp->is_ipv6)
9455 print (vam->ofp,
9456 " Server Table-ID %d, Server Address %U",
9457 ntohl (s->server_vrf_id), format_ip6_address, s->dhcp_server);
9458 else
9459 print (vam->ofp,
9460 " Server Table-ID %d, Server Address %U",
9461 ntohl (s->server_vrf_id), format_ip4_address, s->dhcp_server);
9462 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009463}
Damjan Marion7cd468a2016-12-19 23:05:39 +01009464
Neale Ranns20a175a2017-02-14 07:28:41 -08009465static void vl_api_dhcp_proxy_details_t_handler_json
9466 (vl_api_dhcp_proxy_details_t * mp)
9467{
9468 vat_main_t *vam = &vat_main;
9469 vat_json_node_t *node = NULL;
Neale Ranns3466c302017-02-16 07:45:03 -08009470 u32 i, count = mp->count;
Neale Ranns20a175a2017-02-14 07:28:41 -08009471 struct in_addr ip4;
9472 struct in6_addr ip6;
Neale Ranns3466c302017-02-16 07:45:03 -08009473 vl_api_dhcp_server_t *s;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009474
Neale Ranns20a175a2017-02-14 07:28:41 -08009475 if (VAT_JSON_ARRAY != vam->json_tree.type)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009476 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009477 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9478 vat_json_init_array (&vam->json_tree);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009479 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009480 node = vat_json_array_add (&vam->json_tree);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009481
Neale Ranns20a175a2017-02-14 07:28:41 -08009482 vat_json_init_object (node);
9483 vat_json_object_add_uint (node, "rx-table-id", ntohl (mp->rx_vrf_id));
John Lo70bfcaf2017-11-14 13:19:26 -05009484 vat_json_object_add_bytes (node, "vss-type", &mp->vss_type,
9485 sizeof (mp->vss_type));
9486 vat_json_object_add_string_copy (node, "vss-vpn-ascii-id",
9487 mp->vss_vpn_ascii_id);
Neale Ranns3466c302017-02-16 07:45:03 -08009488 vat_json_object_add_uint (node, "vss-fib-id", ntohl (mp->vss_fib_id));
9489 vat_json_object_add_uint (node, "vss-oui", ntohl (mp->vss_oui));
9490
Neale Ranns20a175a2017-02-14 07:28:41 -08009491 if (mp->is_ipv6)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009492 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009493 clib_memcpy (&ip6, &mp->dhcp_src_address, sizeof (ip6));
9494 vat_json_object_add_ip6 (node, "src_address", ip6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009495 }
9496 else
9497 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009498 clib_memcpy (&ip4, &mp->dhcp_src_address, sizeof (ip4));
9499 vat_json_object_add_ip4 (node, "src_address", ip4);
9500 }
Neale Ranns3466c302017-02-16 07:45:03 -08009501
9502 for (i = 0; i < count; i++)
9503 {
9504 s = &mp->servers[i];
9505
9506 vat_json_object_add_uint (node, "server-table-id",
9507 ntohl (s->server_vrf_id));
9508
9509 if (mp->is_ipv6)
9510 {
9511 clib_memcpy (&ip4, &s->dhcp_server, sizeof (ip4));
9512 vat_json_object_add_ip4 (node, "src_address", ip4);
9513 }
9514 else
9515 {
9516 clib_memcpy (&ip6, &s->dhcp_server, sizeof (ip6));
9517 vat_json_object_add_ip6 (node, "server_address", ip6);
9518 }
9519 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009520}
9521
9522static int
9523api_dhcp_proxy_dump (vat_main_t * vam)
9524{
9525 unformat_input_t *i = vam->input;
9526 vl_api_control_ping_t *mp_ping;
9527 vl_api_dhcp_proxy_dump_t *mp;
9528 u8 is_ipv6 = 0;
9529 int ret;
9530
9531 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9532 {
9533 if (unformat (i, "ipv6"))
9534 is_ipv6 = 1;
9535 else
9536 {
9537 clib_warning ("parse error '%U'", format_unformat_error, i);
9538 return -99;
9539 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01009540 }
9541
Neale Ranns20a175a2017-02-14 07:28:41 -08009542 M (DHCP_PROXY_DUMP, mp);
9543
9544 mp->is_ip6 = is_ipv6;
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009545 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009546
Neale Ranns20a175a2017-02-14 07:28:41 -08009547 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04009548 MPING (CONTROL_PING, mp_ping);
Neale Ranns20a175a2017-02-14 07:28:41 -08009549 S (mp_ping);
9550
Jon Loeliger56c7b012017-02-01 12:31:41 -06009551 W (ret);
9552 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009553}
9554
9555static int
9556api_dhcp_proxy_set_vss (vat_main_t * vam)
9557{
9558 unformat_input_t *i = vam->input;
9559 vl_api_dhcp_proxy_set_vss_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009560 u8 is_ipv6 = 0;
9561 u8 is_add = 1;
John Lo70bfcaf2017-11-14 13:19:26 -05009562 u32 tbl_id = ~0;
9563 u8 vss_type = VSS_TYPE_DEFAULT;
9564 u8 *vpn_ascii_id = 0;
9565 u32 oui = 0;
9566 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009567 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009568
9569 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9570 {
9571 if (unformat (i, "tbl_id %d", &tbl_id))
John Lo70bfcaf2017-11-14 13:19:26 -05009572 ;
9573 else if (unformat (i, "vpn_ascii_id %s", &vpn_ascii_id))
9574 vss_type = VSS_TYPE_ASCII;
9575 else if (unformat (i, "fib_id %d", &fib_id))
9576 vss_type = VSS_TYPE_VPN_ID;
9577 else if (unformat (i, "oui %d", &oui))
9578 vss_type = VSS_TYPE_VPN_ID;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009579 else if (unformat (i, "ipv6"))
9580 is_ipv6 = 1;
9581 else if (unformat (i, "del"))
9582 is_add = 0;
9583 else
John Lo70bfcaf2017-11-14 13:19:26 -05009584 break;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009585 }
9586
John Lo70bfcaf2017-11-14 13:19:26 -05009587 if (tbl_id == ~0)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009588 {
John Lo70bfcaf2017-11-14 13:19:26 -05009589 errmsg ("missing tbl_id ");
9590 vec_free (vpn_ascii_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009591 return -99;
9592 }
9593
John Lo70bfcaf2017-11-14 13:19:26 -05009594 if ((vpn_ascii_id) && (vec_len (vpn_ascii_id) > 128))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009595 {
John Lo70bfcaf2017-11-14 13:19:26 -05009596 errmsg ("vpn_ascii_id cannot be longer than 128 ");
9597 vec_free (vpn_ascii_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009598 return -99;
9599 }
9600
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009601 M (DHCP_PROXY_SET_VSS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009602 mp->tbl_id = ntohl (tbl_id);
John Lo70bfcaf2017-11-14 13:19:26 -05009603 mp->vss_type = vss_type;
9604 if (vpn_ascii_id)
9605 {
9606 clib_memcpy (mp->vpn_ascii_id, vpn_ascii_id, vec_len (vpn_ascii_id));
9607 mp->vpn_ascii_id[vec_len (vpn_ascii_id)] = 0;
9608 }
9609 mp->vpn_index = ntohl (fib_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009610 mp->oui = ntohl (oui);
9611 mp->is_ipv6 = is_ipv6;
9612 mp->is_add = is_add;
9613
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009614 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009615 W (ret);
John Lo70bfcaf2017-11-14 13:19:26 -05009616
9617 vec_free (vpn_ascii_id);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009618 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009619}
9620
9621static int
9622api_dhcp_client_config (vat_main_t * vam)
9623{
9624 unformat_input_t *i = vam->input;
9625 vl_api_dhcp_client_config_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009626 u32 sw_if_index;
9627 u8 sw_if_index_set = 0;
9628 u8 is_add = 1;
9629 u8 *hostname = 0;
9630 u8 disable_event = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009631 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009632
9633 /* Parse args required to build the message */
9634 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9635 {
9636 if (unformat (i, "del"))
9637 is_add = 0;
9638 else
9639 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9640 sw_if_index_set = 1;
9641 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9642 sw_if_index_set = 1;
9643 else if (unformat (i, "hostname %s", &hostname))
9644 ;
9645 else if (unformat (i, "disable_event"))
9646 disable_event = 1;
9647 else
9648 break;
9649 }
9650
9651 if (sw_if_index_set == 0)
9652 {
9653 errmsg ("missing interface name or sw_if_index");
9654 return -99;
9655 }
9656
9657 if (vec_len (hostname) > 63)
9658 {
9659 errmsg ("hostname too long");
9660 }
9661 vec_add1 (hostname, 0);
9662
9663 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009664 M (DHCP_CLIENT_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009665
Damjan Marion7cd468a2016-12-19 23:05:39 +01009666 mp->is_add = is_add;
Neale Rannsdaff1782018-05-16 04:12:18 -07009667 mp->client.sw_if_index = htonl (sw_if_index);
9668 clib_memcpy (mp->client.hostname, hostname, vec_len (hostname));
9669 vec_free (hostname);
9670 mp->client.want_dhcp_event = disable_event ? 0 : 1;
9671 mp->client.pid = htonl (getpid ());
Damjan Marion7cd468a2016-12-19 23:05:39 +01009672
9673 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009674 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009675
9676 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009677 W (ret);
9678 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009679}
9680
9681static int
9682api_set_ip_flow_hash (vat_main_t * vam)
9683{
9684 unformat_input_t *i = vam->input;
9685 vl_api_set_ip_flow_hash_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009686 u32 vrf_id = 0;
9687 u8 is_ipv6 = 0;
9688 u8 vrf_id_set = 0;
9689 u8 src = 0;
9690 u8 dst = 0;
9691 u8 sport = 0;
9692 u8 dport = 0;
9693 u8 proto = 0;
9694 u8 reverse = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009695 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009696
9697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9698 {
9699 if (unformat (i, "vrf %d", &vrf_id))
9700 vrf_id_set = 1;
9701 else if (unformat (i, "ipv6"))
9702 is_ipv6 = 1;
9703 else if (unformat (i, "src"))
9704 src = 1;
9705 else if (unformat (i, "dst"))
9706 dst = 1;
9707 else if (unformat (i, "sport"))
9708 sport = 1;
9709 else if (unformat (i, "dport"))
9710 dport = 1;
9711 else if (unformat (i, "proto"))
9712 proto = 1;
9713 else if (unformat (i, "reverse"))
9714 reverse = 1;
9715
9716 else
9717 {
9718 clib_warning ("parse error '%U'", format_unformat_error, i);
9719 return -99;
9720 }
9721 }
9722
9723 if (vrf_id_set == 0)
9724 {
9725 errmsg ("missing vrf id");
9726 return -99;
9727 }
9728
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009729 M (SET_IP_FLOW_HASH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009730 mp->src = src;
9731 mp->dst = dst;
9732 mp->sport = sport;
9733 mp->dport = dport;
9734 mp->proto = proto;
9735 mp->reverse = reverse;
9736 mp->vrf_id = ntohl (vrf_id);
9737 mp->is_ipv6 = is_ipv6;
9738
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009739 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009740 W (ret);
9741 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009742}
9743
9744static int
9745api_sw_interface_ip6_enable_disable (vat_main_t * vam)
9746{
9747 unformat_input_t *i = vam->input;
9748 vl_api_sw_interface_ip6_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009749 u32 sw_if_index;
9750 u8 sw_if_index_set = 0;
9751 u8 enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009752 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009753
9754 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9755 {
9756 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9757 sw_if_index_set = 1;
9758 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9759 sw_if_index_set = 1;
9760 else if (unformat (i, "enable"))
9761 enable = 1;
9762 else if (unformat (i, "disable"))
9763 enable = 0;
9764 else
9765 {
9766 clib_warning ("parse error '%U'", format_unformat_error, i);
9767 return -99;
9768 }
9769 }
9770
9771 if (sw_if_index_set == 0)
9772 {
9773 errmsg ("missing interface name or sw_if_index");
9774 return -99;
9775 }
9776
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009777 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009778
9779 mp->sw_if_index = ntohl (sw_if_index);
9780 mp->enable = enable;
9781
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009782 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009783 W (ret);
9784 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009785}
9786
9787static int
Neale Ranns3f844d02017-02-18 00:03:54 -08009788api_ip6nd_proxy_add_del (vat_main_t * vam)
9789{
9790 unformat_input_t *i = vam->input;
9791 vl_api_ip6nd_proxy_add_del_t *mp;
9792 u32 sw_if_index = ~0;
9793 u8 v6_address_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -07009794 vl_api_ip6_address_t v6address;
Neale Ranns3f844d02017-02-18 00:03:54 -08009795 u8 is_del = 0;
9796 int ret;
9797
9798 /* Parse args required to build the message */
9799 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9800 {
9801 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9802 ;
9803 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9804 ;
Neale Ranns37029302018-08-10 05:30:06 -07009805 else if (unformat (i, "%U", unformat_vl_api_ip6_address, &v6address))
Neale Ranns3f844d02017-02-18 00:03:54 -08009806 v6_address_set = 1;
9807 if (unformat (i, "del"))
9808 is_del = 1;
9809 else
9810 {
9811 clib_warning ("parse error '%U'", format_unformat_error, i);
9812 return -99;
9813 }
9814 }
9815
9816 if (sw_if_index == ~0)
9817 {
9818 errmsg ("missing interface name or sw_if_index");
9819 return -99;
9820 }
9821 if (!v6_address_set)
9822 {
9823 errmsg ("no address set");
9824 return -99;
9825 }
9826
9827 /* Construct the API message */
9828 M (IP6ND_PROXY_ADD_DEL, mp);
9829
9830 mp->is_del = is_del;
9831 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07009832 clib_memcpy (mp->ip, v6address, sizeof (v6address));
Neale Ranns3f844d02017-02-18 00:03:54 -08009833
9834 /* send it... */
9835 S (mp);
9836
9837 /* Wait for a reply, return good/bad news */
9838 W (ret);
9839 return ret;
9840}
9841
9842static int
9843api_ip6nd_proxy_dump (vat_main_t * vam)
9844{
9845 vl_api_ip6nd_proxy_dump_t *mp;
9846 vl_api_control_ping_t *mp_ping;
9847 int ret;
9848
9849 M (IP6ND_PROXY_DUMP, mp);
9850
9851 S (mp);
9852
9853 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04009854 MPING (CONTROL_PING, mp_ping);
Neale Ranns3f844d02017-02-18 00:03:54 -08009855 S (mp_ping);
9856
9857 W (ret);
9858 return ret;
9859}
9860
9861static void vl_api_ip6nd_proxy_details_t_handler
9862 (vl_api_ip6nd_proxy_details_t * mp)
9863{
9864 vat_main_t *vam = &vat_main;
9865
9866 print (vam->ofp, "host %U sw_if_index %d",
Neale Ranns37029302018-08-10 05:30:06 -07009867 format_vl_api_ip6_address, mp->ip, ntohl (mp->sw_if_index));
Neale Ranns3f844d02017-02-18 00:03:54 -08009868}
9869
9870static void vl_api_ip6nd_proxy_details_t_handler_json
9871 (vl_api_ip6nd_proxy_details_t * mp)
9872{
9873 vat_main_t *vam = &vat_main;
9874 struct in6_addr ip6;
9875 vat_json_node_t *node = NULL;
9876
9877 if (VAT_JSON_ARRAY != vam->json_tree.type)
9878 {
9879 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9880 vat_json_init_array (&vam->json_tree);
9881 }
9882 node = vat_json_array_add (&vam->json_tree);
9883
9884 vat_json_init_object (node);
9885 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9886
Neale Ranns37029302018-08-10 05:30:06 -07009887 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
Neale Ranns3f844d02017-02-18 00:03:54 -08009888 vat_json_object_add_ip6 (node, "host", ip6);
9889}
Damjan Marion7cd468a2016-12-19 23:05:39 +01009890
9891static int
9892api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
9893{
9894 unformat_input_t *i = vam->input;
9895 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009896 u32 sw_if_index;
9897 u8 sw_if_index_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009898 u8 v6_address_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -07009899 vl_api_prefix_t pfx;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009900 u8 use_default = 0;
9901 u8 no_advertise = 0;
9902 u8 off_link = 0;
9903 u8 no_autoconfig = 0;
9904 u8 no_onlink = 0;
9905 u8 is_no = 0;
9906 u32 val_lifetime = 0;
9907 u32 pref_lifetime = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009908 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009909
9910 /* Parse args required to build the message */
9911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9912 {
9913 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9914 sw_if_index_set = 1;
9915 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9916 sw_if_index_set = 1;
Neale Ranns37029302018-08-10 05:30:06 -07009917 else if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009918 v6_address_set = 1;
9919 else if (unformat (i, "val_life %d", &val_lifetime))
9920 ;
9921 else if (unformat (i, "pref_life %d", &pref_lifetime))
9922 ;
9923 else if (unformat (i, "def"))
9924 use_default = 1;
9925 else if (unformat (i, "noadv"))
9926 no_advertise = 1;
9927 else if (unformat (i, "offl"))
9928 off_link = 1;
9929 else if (unformat (i, "noauto"))
9930 no_autoconfig = 1;
9931 else if (unformat (i, "nolink"))
9932 no_onlink = 1;
9933 else if (unformat (i, "isno"))
9934 is_no = 1;
9935 else
9936 {
9937 clib_warning ("parse error '%U'", format_unformat_error, i);
9938 return -99;
9939 }
9940 }
9941
9942 if (sw_if_index_set == 0)
9943 {
9944 errmsg ("missing interface name or sw_if_index");
9945 return -99;
9946 }
9947 if (!v6_address_set)
9948 {
9949 errmsg ("no address set");
9950 return -99;
9951 }
9952
9953 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009954 M (SW_INTERFACE_IP6ND_RA_PREFIX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009955
9956 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07009957 clib_memcpy (&mp->prefix, &pfx, sizeof (pfx));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009958 mp->use_default = use_default;
9959 mp->no_advertise = no_advertise;
9960 mp->off_link = off_link;
9961 mp->no_autoconfig = no_autoconfig;
9962 mp->no_onlink = no_onlink;
9963 mp->is_no = is_no;
9964 mp->val_lifetime = ntohl (val_lifetime);
9965 mp->pref_lifetime = ntohl (pref_lifetime);
9966
9967 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009968 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009969
9970 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009971 W (ret);
9972 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009973}
9974
9975static int
9976api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
9977{
9978 unformat_input_t *i = vam->input;
9979 vl_api_sw_interface_ip6nd_ra_config_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009980 u32 sw_if_index;
9981 u8 sw_if_index_set = 0;
9982 u8 suppress = 0;
9983 u8 managed = 0;
9984 u8 other = 0;
9985 u8 ll_option = 0;
9986 u8 send_unicast = 0;
9987 u8 cease = 0;
9988 u8 is_no = 0;
9989 u8 default_router = 0;
9990 u32 max_interval = 0;
9991 u32 min_interval = 0;
9992 u32 lifetime = 0;
9993 u32 initial_count = 0;
9994 u32 initial_interval = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009995 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009996
9997
9998 /* Parse args required to build the message */
9999 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10000 {
10001 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10002 sw_if_index_set = 1;
10003 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10004 sw_if_index_set = 1;
10005 else if (unformat (i, "maxint %d", &max_interval))
10006 ;
10007 else if (unformat (i, "minint %d", &min_interval))
10008 ;
10009 else if (unformat (i, "life %d", &lifetime))
10010 ;
10011 else if (unformat (i, "count %d", &initial_count))
10012 ;
10013 else if (unformat (i, "interval %d", &initial_interval))
10014 ;
10015 else if (unformat (i, "suppress") || unformat (i, "surpress"))
10016 suppress = 1;
10017 else if (unformat (i, "managed"))
10018 managed = 1;
10019 else if (unformat (i, "other"))
10020 other = 1;
10021 else if (unformat (i, "ll"))
10022 ll_option = 1;
10023 else if (unformat (i, "send"))
10024 send_unicast = 1;
10025 else if (unformat (i, "cease"))
10026 cease = 1;
10027 else if (unformat (i, "isno"))
10028 is_no = 1;
10029 else if (unformat (i, "def"))
10030 default_router = 1;
10031 else
10032 {
10033 clib_warning ("parse error '%U'", format_unformat_error, i);
10034 return -99;
10035 }
10036 }
10037
10038 if (sw_if_index_set == 0)
10039 {
10040 errmsg ("missing interface name or sw_if_index");
10041 return -99;
10042 }
10043
10044 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010045 M (SW_INTERFACE_IP6ND_RA_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010046
10047 mp->sw_if_index = ntohl (sw_if_index);
10048 mp->max_interval = ntohl (max_interval);
10049 mp->min_interval = ntohl (min_interval);
10050 mp->lifetime = ntohl (lifetime);
10051 mp->initial_count = ntohl (initial_count);
10052 mp->initial_interval = ntohl (initial_interval);
10053 mp->suppress = suppress;
10054 mp->managed = managed;
10055 mp->other = other;
10056 mp->ll_option = ll_option;
10057 mp->send_unicast = send_unicast;
10058 mp->cease = cease;
10059 mp->is_no = is_no;
10060 mp->default_router = default_router;
10061
10062 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010063 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010064
10065 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -060010066 W (ret);
10067 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010068}
10069
10070static int
10071api_set_arp_neighbor_limit (vat_main_t * vam)
10072{
10073 unformat_input_t *i = vam->input;
10074 vl_api_set_arp_neighbor_limit_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010075 u32 arp_nbr_limit;
10076 u8 limit_set = 0;
10077 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010078 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010079
10080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10081 {
10082 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
10083 limit_set = 1;
10084 else if (unformat (i, "ipv6"))
10085 is_ipv6 = 1;
10086 else
10087 {
10088 clib_warning ("parse error '%U'", format_unformat_error, i);
10089 return -99;
10090 }
10091 }
10092
10093 if (limit_set == 0)
10094 {
10095 errmsg ("missing limit value");
10096 return -99;
10097 }
10098
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010099 M (SET_ARP_NEIGHBOR_LIMIT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010100
10101 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
10102 mp->is_ipv6 = is_ipv6;
10103
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010104 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010105 W (ret);
10106 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010107}
10108
10109static int
10110api_l2_patch_add_del (vat_main_t * vam)
10111{
10112 unformat_input_t *i = vam->input;
10113 vl_api_l2_patch_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010114 u32 rx_sw_if_index;
10115 u8 rx_sw_if_index_set = 0;
10116 u32 tx_sw_if_index;
10117 u8 tx_sw_if_index_set = 0;
10118 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010119 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010120
10121 /* Parse args required to build the message */
10122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10123 {
10124 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
10125 rx_sw_if_index_set = 1;
10126 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
10127 tx_sw_if_index_set = 1;
10128 else if (unformat (i, "rx"))
10129 {
10130 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10131 {
10132 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
10133 &rx_sw_if_index))
10134 rx_sw_if_index_set = 1;
10135 }
10136 else
10137 break;
10138 }
10139 else if (unformat (i, "tx"))
10140 {
10141 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10142 {
10143 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
10144 &tx_sw_if_index))
10145 tx_sw_if_index_set = 1;
10146 }
10147 else
10148 break;
10149 }
10150 else if (unformat (i, "del"))
10151 is_add = 0;
10152 else
10153 break;
10154 }
10155
10156 if (rx_sw_if_index_set == 0)
10157 {
10158 errmsg ("missing rx interface name or rx_sw_if_index");
10159 return -99;
10160 }
10161
10162 if (tx_sw_if_index_set == 0)
10163 {
10164 errmsg ("missing tx interface name or tx_sw_if_index");
10165 return -99;
10166 }
10167
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010168 M (L2_PATCH_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010169
10170 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
10171 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
10172 mp->is_add = is_add;
10173
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010174 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010175 W (ret);
10176 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010177}
10178
Pablo Camarillofb380952016-12-07 18:34:18 +010010179u8 is_del;
10180u8 localsid_addr[16];
10181u8 end_psp;
10182u8 behavior;
10183u32 sw_if_index;
10184u32 vlan_index;
10185u32 fib_table;
10186u8 nh_addr[16];
10187
10188static int
10189api_sr_localsid_add_del (vat_main_t * vam)
10190{
10191 unformat_input_t *i = vam->input;
10192 vl_api_sr_localsid_add_del_t *mp;
10193
10194 u8 is_del;
10195 ip6_address_t localsid;
10196 u8 end_psp = 0;
10197 u8 behavior = ~0;
10198 u32 sw_if_index;
10199 u32 fib_table = ~(u32) 0;
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010200 ip6_address_t nh_addr6;
10201 ip4_address_t nh_addr4;
Dave Barachb7b92992018-10-17 10:38:51 -040010202 clib_memset (&nh_addr6, 0, sizeof (ip6_address_t));
10203 clib_memset (&nh_addr4, 0, sizeof (ip4_address_t));
Pablo Camarillofb380952016-12-07 18:34:18 +010010204
10205 bool nexthop_set = 0;
10206
10207 int ret;
10208
10209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10210 {
10211 if (unformat (i, "del"))
10212 is_del = 1;
10213 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010214 else if (unformat (i, "next-hop %U", unformat_ip4_address, &nh_addr4))
10215 nexthop_set = 1;
10216 else if (unformat (i, "next-hop %U", unformat_ip6_address, &nh_addr6))
Pablo Camarillofb380952016-12-07 18:34:18 +010010217 nexthop_set = 1;
10218 else if (unformat (i, "behavior %u", &behavior));
10219 else if (unformat (i, "sw_if_index %u", &sw_if_index));
10220 else if (unformat (i, "fib-table %u", &fib_table));
10221 else if (unformat (i, "end.psp %u", &behavior));
10222 else
10223 break;
10224 }
10225
10226 M (SR_LOCALSID_ADD_DEL, mp);
10227
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010228 clib_memcpy (mp->localsid.addr, &localsid, sizeof (mp->localsid));
Pablo Camarillofb380952016-12-07 18:34:18 +010010229 if (nexthop_set)
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010230 {
Lijian Zhangec2a9bb2018-08-28 10:18:24 +080010231 clib_memcpy (mp->nh_addr6, &nh_addr6, sizeof (mp->nh_addr6));
10232 clib_memcpy (mp->nh_addr4, &nh_addr4, sizeof (mp->nh_addr4));
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010233 }
Pablo Camarillofb380952016-12-07 18:34:18 +010010234 mp->behavior = behavior;
10235 mp->sw_if_index = ntohl (sw_if_index);
10236 mp->fib_table = ntohl (fib_table);
10237 mp->end_psp = end_psp;
10238 mp->is_del = is_del;
10239
10240 S (mp);
10241 W (ret);
10242 return ret;
10243}
10244
Damjan Marion7cd468a2016-12-19 23:05:39 +010010245static int
10246api_ioam_enable (vat_main_t * vam)
10247{
10248 unformat_input_t *input = vam->input;
10249 vl_api_ioam_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010250 u32 id = 0;
10251 int has_trace_option = 0;
10252 int has_pot_option = 0;
10253 int has_seqno_option = 0;
10254 int has_analyse_option = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010255 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010256
10257 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10258 {
10259 if (unformat (input, "trace"))
10260 has_trace_option = 1;
10261 else if (unformat (input, "pot"))
10262 has_pot_option = 1;
10263 else if (unformat (input, "seqno"))
10264 has_seqno_option = 1;
10265 else if (unformat (input, "analyse"))
10266 has_analyse_option = 1;
10267 else
10268 break;
10269 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010270 M (IOAM_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010271 mp->id = htons (id);
10272 mp->seqno = has_seqno_option;
10273 mp->analyse = has_analyse_option;
10274 mp->pot_enable = has_pot_option;
10275 mp->trace_enable = has_trace_option;
10276
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010277 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010278 W (ret);
10279 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010280}
10281
10282
10283static int
10284api_ioam_disable (vat_main_t * vam)
10285{
10286 vl_api_ioam_disable_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010287 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010288
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010289 M (IOAM_DISABLE, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010290 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010291 W (ret);
10292 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010293}
10294
Damjan Marion7cd468a2016-12-19 23:05:39 +010010295#define foreach_tcp_proto_field \
10296_(src_port) \
10297_(dst_port)
10298
10299#define foreach_udp_proto_field \
10300_(src_port) \
10301_(dst_port)
10302
10303#define foreach_ip4_proto_field \
10304_(src_address) \
10305_(dst_address) \
10306_(tos) \
10307_(length) \
10308_(fragment_id) \
10309_(ttl) \
10310_(protocol) \
10311_(checksum)
10312
Dave Barach4a3f69c2017-02-22 12:44:56 -050010313typedef struct
10314{
10315 u16 src_port, dst_port;
10316} tcpudp_header_t;
10317
10318#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010010319uword
10320unformat_tcp_mask (unformat_input_t * input, va_list * args)
10321{
10322 u8 **maskp = va_arg (*args, u8 **);
10323 u8 *mask = 0;
10324 u8 found_something = 0;
10325 tcp_header_t *tcp;
10326
10327#define _(a) u8 a=0;
10328 foreach_tcp_proto_field;
10329#undef _
10330
10331 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10332 {
10333 if (0);
10334#define _(a) else if (unformat (input, #a)) a=1;
10335 foreach_tcp_proto_field
10336#undef _
10337 else
10338 break;
10339 }
10340
10341#define _(a) found_something += a;
10342 foreach_tcp_proto_field;
10343#undef _
10344
10345 if (found_something == 0)
10346 return 0;
10347
10348 vec_validate (mask, sizeof (*tcp) - 1);
10349
10350 tcp = (tcp_header_t *) mask;
10351
Dave Barachb7b92992018-10-17 10:38:51 -040010352#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010353 foreach_tcp_proto_field;
10354#undef _
10355
10356 *maskp = mask;
10357 return 1;
10358}
10359
10360uword
10361unformat_udp_mask (unformat_input_t * input, va_list * args)
10362{
10363 u8 **maskp = va_arg (*args, u8 **);
10364 u8 *mask = 0;
10365 u8 found_something = 0;
10366 udp_header_t *udp;
10367
10368#define _(a) u8 a=0;
10369 foreach_udp_proto_field;
10370#undef _
10371
10372 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10373 {
10374 if (0);
10375#define _(a) else if (unformat (input, #a)) a=1;
10376 foreach_udp_proto_field
10377#undef _
10378 else
10379 break;
10380 }
10381
10382#define _(a) found_something += a;
10383 foreach_udp_proto_field;
10384#undef _
10385
10386 if (found_something == 0)
10387 return 0;
10388
10389 vec_validate (mask, sizeof (*udp) - 1);
10390
10391 udp = (udp_header_t *) mask;
10392
Dave Barachb7b92992018-10-17 10:38:51 -040010393#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010394 foreach_udp_proto_field;
10395#undef _
10396
10397 *maskp = mask;
10398 return 1;
10399}
10400
Damjan Marion7cd468a2016-12-19 23:05:39 +010010401uword
10402unformat_l4_mask (unformat_input_t * input, va_list * args)
10403{
10404 u8 **maskp = va_arg (*args, u8 **);
10405 u16 src_port = 0, dst_port = 0;
10406 tcpudp_header_t *tcpudp;
10407
10408 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10409 {
10410 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
10411 return 1;
10412 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
10413 return 1;
10414 else if (unformat (input, "src_port"))
10415 src_port = 0xFFFF;
10416 else if (unformat (input, "dst_port"))
10417 dst_port = 0xFFFF;
10418 else
10419 return 0;
10420 }
10421
10422 if (!src_port && !dst_port)
10423 return 0;
10424
10425 u8 *mask = 0;
10426 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
10427
10428 tcpudp = (tcpudp_header_t *) mask;
10429 tcpudp->src_port = src_port;
10430 tcpudp->dst_port = dst_port;
10431
10432 *maskp = mask;
10433
10434 return 1;
10435}
10436
10437uword
10438unformat_ip4_mask (unformat_input_t * input, va_list * args)
10439{
10440 u8 **maskp = va_arg (*args, u8 **);
10441 u8 *mask = 0;
10442 u8 found_something = 0;
10443 ip4_header_t *ip;
10444
10445#define _(a) u8 a=0;
10446 foreach_ip4_proto_field;
10447#undef _
10448 u8 version = 0;
10449 u8 hdr_length = 0;
10450
10451
10452 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10453 {
10454 if (unformat (input, "version"))
10455 version = 1;
10456 else if (unformat (input, "hdr_length"))
10457 hdr_length = 1;
10458 else if (unformat (input, "src"))
10459 src_address = 1;
10460 else if (unformat (input, "dst"))
10461 dst_address = 1;
10462 else if (unformat (input, "proto"))
10463 protocol = 1;
10464
10465#define _(a) else if (unformat (input, #a)) a=1;
10466 foreach_ip4_proto_field
10467#undef _
10468 else
10469 break;
10470 }
10471
10472#define _(a) found_something += a;
10473 foreach_ip4_proto_field;
10474#undef _
10475
10476 if (found_something == 0)
10477 return 0;
10478
10479 vec_validate (mask, sizeof (*ip) - 1);
10480
10481 ip = (ip4_header_t *) mask;
10482
Dave Barachb7b92992018-10-17 10:38:51 -040010483#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010484 foreach_ip4_proto_field;
10485#undef _
10486
10487 ip->ip_version_and_header_length = 0;
10488
10489 if (version)
10490 ip->ip_version_and_header_length |= 0xF0;
10491
10492 if (hdr_length)
10493 ip->ip_version_and_header_length |= 0x0F;
10494
10495 *maskp = mask;
10496 return 1;
10497}
10498
10499#define foreach_ip6_proto_field \
10500_(src_address) \
10501_(dst_address) \
10502_(payload_length) \
10503_(hop_limit) \
10504_(protocol)
10505
10506uword
10507unformat_ip6_mask (unformat_input_t * input, va_list * args)
10508{
10509 u8 **maskp = va_arg (*args, u8 **);
10510 u8 *mask = 0;
10511 u8 found_something = 0;
10512 ip6_header_t *ip;
10513 u32 ip_version_traffic_class_and_flow_label;
10514
10515#define _(a) u8 a=0;
10516 foreach_ip6_proto_field;
10517#undef _
10518 u8 version = 0;
10519 u8 traffic_class = 0;
10520 u8 flow_label = 0;
10521
10522 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10523 {
10524 if (unformat (input, "version"))
10525 version = 1;
10526 else if (unformat (input, "traffic-class"))
10527 traffic_class = 1;
10528 else if (unformat (input, "flow-label"))
10529 flow_label = 1;
10530 else if (unformat (input, "src"))
10531 src_address = 1;
10532 else if (unformat (input, "dst"))
10533 dst_address = 1;
10534 else if (unformat (input, "proto"))
10535 protocol = 1;
10536
10537#define _(a) else if (unformat (input, #a)) a=1;
10538 foreach_ip6_proto_field
10539#undef _
10540 else
10541 break;
10542 }
10543
10544#define _(a) found_something += a;
10545 foreach_ip6_proto_field;
10546#undef _
10547
10548 if (found_something == 0)
10549 return 0;
10550
10551 vec_validate (mask, sizeof (*ip) - 1);
10552
10553 ip = (ip6_header_t *) mask;
10554
Dave Barachb7b92992018-10-17 10:38:51 -040010555#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010556 foreach_ip6_proto_field;
10557#undef _
10558
10559 ip_version_traffic_class_and_flow_label = 0;
10560
10561 if (version)
10562 ip_version_traffic_class_and_flow_label |= 0xF0000000;
10563
10564 if (traffic_class)
10565 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
10566
10567 if (flow_label)
10568 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
10569
10570 ip->ip_version_traffic_class_and_flow_label =
10571 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
10572
10573 *maskp = mask;
10574 return 1;
10575}
10576
10577uword
10578unformat_l3_mask (unformat_input_t * input, va_list * args)
10579{
10580 u8 **maskp = va_arg (*args, u8 **);
10581
10582 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10583 {
10584 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
10585 return 1;
10586 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
10587 return 1;
10588 else
10589 break;
10590 }
10591 return 0;
10592}
10593
10594uword
10595unformat_l2_mask (unformat_input_t * input, va_list * args)
10596{
10597 u8 **maskp = va_arg (*args, u8 **);
10598 u8 *mask = 0;
10599 u8 src = 0;
10600 u8 dst = 0;
10601 u8 proto = 0;
10602 u8 tag1 = 0;
10603 u8 tag2 = 0;
10604 u8 ignore_tag1 = 0;
10605 u8 ignore_tag2 = 0;
10606 u8 cos1 = 0;
10607 u8 cos2 = 0;
10608 u8 dot1q = 0;
10609 u8 dot1ad = 0;
10610 int len = 14;
10611
10612 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10613 {
10614 if (unformat (input, "src"))
10615 src = 1;
10616 else if (unformat (input, "dst"))
10617 dst = 1;
10618 else if (unformat (input, "proto"))
10619 proto = 1;
10620 else if (unformat (input, "tag1"))
10621 tag1 = 1;
10622 else if (unformat (input, "tag2"))
10623 tag2 = 1;
10624 else if (unformat (input, "ignore-tag1"))
10625 ignore_tag1 = 1;
10626 else if (unformat (input, "ignore-tag2"))
10627 ignore_tag2 = 1;
10628 else if (unformat (input, "cos1"))
10629 cos1 = 1;
10630 else if (unformat (input, "cos2"))
10631 cos2 = 1;
10632 else if (unformat (input, "dot1q"))
10633 dot1q = 1;
10634 else if (unformat (input, "dot1ad"))
10635 dot1ad = 1;
10636 else
10637 break;
10638 }
10639 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
10640 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
10641 return 0;
10642
10643 if (tag1 || ignore_tag1 || cos1 || dot1q)
10644 len = 18;
10645 if (tag2 || ignore_tag2 || cos2 || dot1ad)
10646 len = 22;
10647
10648 vec_validate (mask, len - 1);
10649
10650 if (dst)
Dave Barachb7b92992018-10-17 10:38:51 -040010651 clib_memset (mask, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010652
10653 if (src)
Dave Barachb7b92992018-10-17 10:38:51 -040010654 clib_memset (mask + 6, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010655
10656 if (tag2 || dot1ad)
10657 {
10658 /* inner vlan tag */
10659 if (tag2)
10660 {
10661 mask[19] = 0xff;
10662 mask[18] = 0x0f;
10663 }
10664 if (cos2)
10665 mask[18] |= 0xe0;
10666 if (proto)
10667 mask[21] = mask[20] = 0xff;
10668 if (tag1)
10669 {
10670 mask[15] = 0xff;
10671 mask[14] = 0x0f;
10672 }
10673 if (cos1)
10674 mask[14] |= 0xe0;
10675 *maskp = mask;
10676 return 1;
10677 }
10678 if (tag1 | dot1q)
10679 {
10680 if (tag1)
10681 {
10682 mask[15] = 0xff;
10683 mask[14] = 0x0f;
10684 }
10685 if (cos1)
10686 mask[14] |= 0xe0;
10687 if (proto)
10688 mask[16] = mask[17] = 0xff;
10689
10690 *maskp = mask;
10691 return 1;
10692 }
10693 if (cos2)
10694 mask[18] |= 0xe0;
10695 if (cos1)
10696 mask[14] |= 0xe0;
10697 if (proto)
10698 mask[12] = mask[13] = 0xff;
10699
10700 *maskp = mask;
10701 return 1;
10702}
10703
10704uword
10705unformat_classify_mask (unformat_input_t * input, va_list * args)
10706{
10707 u8 **maskp = va_arg (*args, u8 **);
10708 u32 *skipp = va_arg (*args, u32 *);
10709 u32 *matchp = va_arg (*args, u32 *);
10710 u32 match;
10711 u8 *mask = 0;
10712 u8 *l2 = 0;
10713 u8 *l3 = 0;
10714 u8 *l4 = 0;
10715 int i;
10716
10717 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10718 {
10719 if (unformat (input, "hex %U", unformat_hex_string, &mask))
10720 ;
10721 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
10722 ;
10723 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
10724 ;
10725 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
10726 ;
10727 else
10728 break;
10729 }
10730
10731 if (l4 && !l3)
10732 {
10733 vec_free (mask);
10734 vec_free (l2);
10735 vec_free (l4);
10736 return 0;
10737 }
10738
10739 if (mask || l2 || l3 || l4)
10740 {
10741 if (l2 || l3 || l4)
10742 {
10743 /* "With a free Ethernet header in every package" */
10744 if (l2 == 0)
10745 vec_validate (l2, 13);
10746 mask = l2;
10747 if (vec_len (l3))
10748 {
10749 vec_append (mask, l3);
10750 vec_free (l3);
10751 }
10752 if (vec_len (l4))
10753 {
10754 vec_append (mask, l4);
10755 vec_free (l4);
10756 }
10757 }
10758
10759 /* Scan forward looking for the first significant mask octet */
10760 for (i = 0; i < vec_len (mask); i++)
10761 if (mask[i])
10762 break;
10763
10764 /* compute (skip, match) params */
10765 *skipp = i / sizeof (u32x4);
10766 vec_delete (mask, *skipp * sizeof (u32x4), 0);
10767
10768 /* Pad mask to an even multiple of the vector size */
10769 while (vec_len (mask) % sizeof (u32x4))
10770 vec_add1 (mask, 0);
10771
10772 match = vec_len (mask) / sizeof (u32x4);
10773
10774 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
10775 {
10776 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
10777 if (*tmp || *(tmp + 1))
10778 break;
10779 match--;
10780 }
10781 if (match == 0)
10782 clib_warning ("BUG: match 0");
10783
10784 _vec_len (mask) = match * sizeof (u32x4);
10785
10786 *matchp = match;
10787 *maskp = mask;
10788
10789 return 1;
10790 }
10791
10792 return 0;
10793}
Dave Barach4a3f69c2017-02-22 12:44:56 -050010794#endif /* VPP_API_TEST_BUILTIN */
Damjan Marion7cd468a2016-12-19 23:05:39 +010010795
10796#define foreach_l2_next \
10797_(drop, DROP) \
10798_(ethernet, ETHERNET_INPUT) \
10799_(ip4, IP4_INPUT) \
10800_(ip6, IP6_INPUT)
10801
10802uword
10803unformat_l2_next_index (unformat_input_t * input, va_list * args)
10804{
10805 u32 *miss_next_indexp = va_arg (*args, u32 *);
10806 u32 next_index = 0;
10807 u32 tmp;
10808
10809#define _(n,N) \
10810 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
10811 foreach_l2_next;
10812#undef _
10813
10814 if (unformat (input, "%d", &tmp))
10815 {
10816 next_index = tmp;
10817 goto out;
10818 }
10819
10820 return 0;
10821
10822out:
10823 *miss_next_indexp = next_index;
10824 return 1;
10825}
10826
10827#define foreach_ip_next \
10828_(drop, DROP) \
10829_(local, LOCAL) \
10830_(rewrite, REWRITE)
10831
10832uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050010833api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010010834{
10835 u32 *miss_next_indexp = va_arg (*args, u32 *);
10836 u32 next_index = 0;
10837 u32 tmp;
10838
10839#define _(n,N) \
10840 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
10841 foreach_ip_next;
10842#undef _
10843
10844 if (unformat (input, "%d", &tmp))
10845 {
10846 next_index = tmp;
10847 goto out;
10848 }
10849
10850 return 0;
10851
10852out:
10853 *miss_next_indexp = next_index;
10854 return 1;
10855}
10856
10857#define foreach_acl_next \
10858_(deny, DENY)
10859
10860uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050010861api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010010862{
10863 u32 *miss_next_indexp = va_arg (*args, u32 *);
10864 u32 next_index = 0;
10865 u32 tmp;
10866
10867#define _(n,N) \
10868 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
10869 foreach_acl_next;
10870#undef _
10871
10872 if (unformat (input, "permit"))
10873 {
10874 next_index = ~0;
10875 goto out;
10876 }
10877 else if (unformat (input, "%d", &tmp))
10878 {
10879 next_index = tmp;
10880 goto out;
10881 }
10882
10883 return 0;
10884
10885out:
10886 *miss_next_indexp = next_index;
10887 return 1;
10888}
10889
10890uword
10891unformat_policer_precolor (unformat_input_t * input, va_list * args)
10892{
10893 u32 *r = va_arg (*args, u32 *);
10894
10895 if (unformat (input, "conform-color"))
10896 *r = POLICE_CONFORM;
10897 else if (unformat (input, "exceed-color"))
10898 *r = POLICE_EXCEED;
10899 else
10900 return 0;
10901
10902 return 1;
10903}
10904
10905static int
10906api_classify_add_del_table (vat_main_t * vam)
10907{
10908 unformat_input_t *i = vam->input;
10909 vl_api_classify_add_del_table_t *mp;
10910
10911 u32 nbuckets = 2;
10912 u32 skip = ~0;
10913 u32 match = ~0;
10914 int is_add = 1;
10915 int del_chain = 0;
10916 u32 table_index = ~0;
10917 u32 next_table_index = ~0;
10918 u32 miss_next_index = ~0;
10919 u32 memory_size = 32 << 20;
10920 u8 *mask = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010921 u32 current_data_flag = 0;
10922 int current_data_offset = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010923 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010924
10925 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10926 {
10927 if (unformat (i, "del"))
10928 is_add = 0;
10929 else if (unformat (i, "del-chain"))
10930 {
10931 is_add = 0;
10932 del_chain = 1;
10933 }
10934 else if (unformat (i, "buckets %d", &nbuckets))
10935 ;
10936 else if (unformat (i, "memory_size %d", &memory_size))
10937 ;
10938 else if (unformat (i, "skip %d", &skip))
10939 ;
10940 else if (unformat (i, "match %d", &match))
10941 ;
10942 else if (unformat (i, "table %d", &table_index))
10943 ;
10944 else if (unformat (i, "mask %U", unformat_classify_mask,
10945 &mask, &skip, &match))
10946 ;
10947 else if (unformat (i, "next-table %d", &next_table_index))
10948 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010949 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010950 &miss_next_index))
10951 ;
10952 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
10953 &miss_next_index))
10954 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010955 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010956 &miss_next_index))
10957 ;
10958 else if (unformat (i, "current-data-flag %d", &current_data_flag))
10959 ;
10960 else if (unformat (i, "current-data-offset %d", &current_data_offset))
10961 ;
10962 else
10963 break;
10964 }
10965
10966 if (is_add && mask == 0)
10967 {
10968 errmsg ("Mask required");
10969 return -99;
10970 }
10971
10972 if (is_add && skip == ~0)
10973 {
10974 errmsg ("skip count required");
10975 return -99;
10976 }
10977
10978 if (is_add && match == ~0)
10979 {
10980 errmsg ("match count required");
10981 return -99;
10982 }
10983
10984 if (!is_add && table_index == ~0)
10985 {
10986 errmsg ("table index required for delete");
10987 return -99;
10988 }
10989
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010990 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010991
10992 mp->is_add = is_add;
10993 mp->del_chain = del_chain;
10994 mp->table_index = ntohl (table_index);
10995 mp->nbuckets = ntohl (nbuckets);
10996 mp->memory_size = ntohl (memory_size);
10997 mp->skip_n_vectors = ntohl (skip);
10998 mp->match_n_vectors = ntohl (match);
10999 mp->next_table_index = ntohl (next_table_index);
11000 mp->miss_next_index = ntohl (miss_next_index);
11001 mp->current_data_flag = ntohl (current_data_flag);
11002 mp->current_data_offset = ntohl (current_data_offset);
Juraj Sloboda75282452018-06-12 14:20:49 +020011003 mp->mask_len = ntohl (vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011004 clib_memcpy (mp->mask, mask, vec_len (mask));
11005
11006 vec_free (mask);
11007
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011008 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011009 W (ret);
11010 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011011}
11012
Dave Barach4a3f69c2017-02-22 12:44:56 -050011013#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010011014uword
11015unformat_l4_match (unformat_input_t * input, va_list * args)
11016{
11017 u8 **matchp = va_arg (*args, u8 **);
11018
11019 u8 *proto_header = 0;
11020 int src_port = 0;
11021 int dst_port = 0;
11022
11023 tcpudp_header_t h;
11024
11025 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11026 {
11027 if (unformat (input, "src_port %d", &src_port))
11028 ;
11029 else if (unformat (input, "dst_port %d", &dst_port))
11030 ;
11031 else
11032 return 0;
11033 }
11034
11035 h.src_port = clib_host_to_net_u16 (src_port);
11036 h.dst_port = clib_host_to_net_u16 (dst_port);
11037 vec_validate (proto_header, sizeof (h) - 1);
11038 memcpy (proto_header, &h, sizeof (h));
11039
11040 *matchp = proto_header;
11041
11042 return 1;
11043}
11044
11045uword
11046unformat_ip4_match (unformat_input_t * input, va_list * args)
11047{
11048 u8 **matchp = va_arg (*args, u8 **);
11049 u8 *match = 0;
11050 ip4_header_t *ip;
11051 int version = 0;
11052 u32 version_val;
11053 int hdr_length = 0;
11054 u32 hdr_length_val;
11055 int src = 0, dst = 0;
11056 ip4_address_t src_val, dst_val;
11057 int proto = 0;
11058 u32 proto_val;
11059 int tos = 0;
11060 u32 tos_val;
11061 int length = 0;
11062 u32 length_val;
11063 int fragment_id = 0;
11064 u32 fragment_id_val;
11065 int ttl = 0;
11066 int ttl_val;
11067 int checksum = 0;
11068 u32 checksum_val;
11069
11070 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11071 {
11072 if (unformat (input, "version %d", &version_val))
11073 version = 1;
11074 else if (unformat (input, "hdr_length %d", &hdr_length_val))
11075 hdr_length = 1;
11076 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
11077 src = 1;
11078 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
11079 dst = 1;
11080 else if (unformat (input, "proto %d", &proto_val))
11081 proto = 1;
11082 else if (unformat (input, "tos %d", &tos_val))
11083 tos = 1;
11084 else if (unformat (input, "length %d", &length_val))
11085 length = 1;
11086 else if (unformat (input, "fragment_id %d", &fragment_id_val))
11087 fragment_id = 1;
11088 else if (unformat (input, "ttl %d", &ttl_val))
11089 ttl = 1;
11090 else if (unformat (input, "checksum %d", &checksum_val))
11091 checksum = 1;
11092 else
11093 break;
11094 }
11095
11096 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
11097 + ttl + checksum == 0)
11098 return 0;
11099
11100 /*
11101 * Aligned because we use the real comparison functions
11102 */
11103 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
11104
11105 ip = (ip4_header_t *) match;
11106
11107 /* These are realistically matched in practice */
11108 if (src)
11109 ip->src_address.as_u32 = src_val.as_u32;
11110
11111 if (dst)
11112 ip->dst_address.as_u32 = dst_val.as_u32;
11113
11114 if (proto)
11115 ip->protocol = proto_val;
11116
11117
11118 /* These are not, but they're included for completeness */
11119 if (version)
11120 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
11121
11122 if (hdr_length)
11123 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
11124
11125 if (tos)
11126 ip->tos = tos_val;
11127
11128 if (length)
11129 ip->length = clib_host_to_net_u16 (length_val);
11130
11131 if (ttl)
11132 ip->ttl = ttl_val;
11133
11134 if (checksum)
11135 ip->checksum = clib_host_to_net_u16 (checksum_val);
11136
11137 *matchp = match;
11138 return 1;
11139}
11140
11141uword
11142unformat_ip6_match (unformat_input_t * input, va_list * args)
11143{
11144 u8 **matchp = va_arg (*args, u8 **);
11145 u8 *match = 0;
11146 ip6_header_t *ip;
11147 int version = 0;
11148 u32 version_val;
11149 u8 traffic_class = 0;
11150 u32 traffic_class_val = 0;
11151 u8 flow_label = 0;
11152 u8 flow_label_val;
11153 int src = 0, dst = 0;
11154 ip6_address_t src_val, dst_val;
11155 int proto = 0;
11156 u32 proto_val;
11157 int payload_length = 0;
11158 u32 payload_length_val;
11159 int hop_limit = 0;
11160 int hop_limit_val;
11161 u32 ip_version_traffic_class_and_flow_label;
11162
11163 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11164 {
11165 if (unformat (input, "version %d", &version_val))
11166 version = 1;
11167 else if (unformat (input, "traffic_class %d", &traffic_class_val))
11168 traffic_class = 1;
11169 else if (unformat (input, "flow_label %d", &flow_label_val))
11170 flow_label = 1;
11171 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
11172 src = 1;
11173 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
11174 dst = 1;
11175 else if (unformat (input, "proto %d", &proto_val))
11176 proto = 1;
11177 else if (unformat (input, "payload_length %d", &payload_length_val))
11178 payload_length = 1;
11179 else if (unformat (input, "hop_limit %d", &hop_limit_val))
11180 hop_limit = 1;
11181 else
11182 break;
11183 }
11184
11185 if (version + traffic_class + flow_label + src + dst + proto +
11186 payload_length + hop_limit == 0)
11187 return 0;
11188
11189 /*
11190 * Aligned because we use the real comparison functions
11191 */
11192 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
11193
11194 ip = (ip6_header_t *) match;
11195
11196 if (src)
11197 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
11198
11199 if (dst)
11200 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
11201
11202 if (proto)
11203 ip->protocol = proto_val;
11204
11205 ip_version_traffic_class_and_flow_label = 0;
11206
11207 if (version)
11208 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
11209
11210 if (traffic_class)
11211 ip_version_traffic_class_and_flow_label |=
11212 (traffic_class_val & 0xFF) << 20;
11213
11214 if (flow_label)
11215 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
11216
11217 ip->ip_version_traffic_class_and_flow_label =
11218 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
11219
11220 if (payload_length)
11221 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
11222
11223 if (hop_limit)
11224 ip->hop_limit = hop_limit_val;
11225
11226 *matchp = match;
11227 return 1;
11228}
11229
11230uword
11231unformat_l3_match (unformat_input_t * input, va_list * args)
11232{
11233 u8 **matchp = va_arg (*args, u8 **);
11234
11235 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11236 {
11237 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
11238 return 1;
11239 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
11240 return 1;
11241 else
11242 break;
11243 }
11244 return 0;
11245}
11246
11247uword
11248unformat_vlan_tag (unformat_input_t * input, va_list * args)
11249{
11250 u8 *tagp = va_arg (*args, u8 *);
11251 u32 tag;
11252
11253 if (unformat (input, "%d", &tag))
11254 {
11255 tagp[0] = (tag >> 8) & 0x0F;
11256 tagp[1] = tag & 0xFF;
11257 return 1;
11258 }
11259
11260 return 0;
11261}
11262
11263uword
11264unformat_l2_match (unformat_input_t * input, va_list * args)
11265{
11266 u8 **matchp = va_arg (*args, u8 **);
11267 u8 *match = 0;
11268 u8 src = 0;
11269 u8 src_val[6];
11270 u8 dst = 0;
11271 u8 dst_val[6];
11272 u8 proto = 0;
11273 u16 proto_val;
11274 u8 tag1 = 0;
11275 u8 tag1_val[2];
11276 u8 tag2 = 0;
11277 u8 tag2_val[2];
11278 int len = 14;
11279 u8 ignore_tag1 = 0;
11280 u8 ignore_tag2 = 0;
11281 u8 cos1 = 0;
11282 u8 cos2 = 0;
11283 u32 cos1_val = 0;
11284 u32 cos2_val = 0;
11285
11286 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11287 {
11288 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
11289 src = 1;
11290 else
11291 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
11292 dst = 1;
11293 else if (unformat (input, "proto %U",
11294 unformat_ethernet_type_host_byte_order, &proto_val))
11295 proto = 1;
11296 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
11297 tag1 = 1;
11298 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
11299 tag2 = 1;
11300 else if (unformat (input, "ignore-tag1"))
11301 ignore_tag1 = 1;
11302 else if (unformat (input, "ignore-tag2"))
11303 ignore_tag2 = 1;
11304 else if (unformat (input, "cos1 %d", &cos1_val))
11305 cos1 = 1;
11306 else if (unformat (input, "cos2 %d", &cos2_val))
11307 cos2 = 1;
11308 else
11309 break;
11310 }
11311 if ((src + dst + proto + tag1 + tag2 +
11312 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
11313 return 0;
11314
11315 if (tag1 || ignore_tag1 || cos1)
11316 len = 18;
11317 if (tag2 || ignore_tag2 || cos2)
11318 len = 22;
11319
11320 vec_validate_aligned (match, len - 1, sizeof (u32x4));
11321
11322 if (dst)
11323 clib_memcpy (match, dst_val, 6);
11324
11325 if (src)
11326 clib_memcpy (match + 6, src_val, 6);
11327
11328 if (tag2)
11329 {
11330 /* inner vlan tag */
11331 match[19] = tag2_val[1];
11332 match[18] = tag2_val[0];
11333 if (cos2)
11334 match[18] |= (cos2_val & 0x7) << 5;
11335 if (proto)
11336 {
11337 match[21] = proto_val & 0xff;
11338 match[20] = proto_val >> 8;
11339 }
11340 if (tag1)
11341 {
11342 match[15] = tag1_val[1];
11343 match[14] = tag1_val[0];
11344 }
11345 if (cos1)
11346 match[14] |= (cos1_val & 0x7) << 5;
11347 *matchp = match;
11348 return 1;
11349 }
11350 if (tag1)
11351 {
11352 match[15] = tag1_val[1];
11353 match[14] = tag1_val[0];
11354 if (proto)
11355 {
11356 match[17] = proto_val & 0xff;
11357 match[16] = proto_val >> 8;
11358 }
11359 if (cos1)
11360 match[14] |= (cos1_val & 0x7) << 5;
11361
11362 *matchp = match;
11363 return 1;
11364 }
11365 if (cos2)
11366 match[18] |= (cos2_val & 0x7) << 5;
11367 if (cos1)
11368 match[14] |= (cos1_val & 0x7) << 5;
11369 if (proto)
11370 {
11371 match[13] = proto_val & 0xff;
11372 match[12] = proto_val >> 8;
11373 }
11374
11375 *matchp = match;
11376 return 1;
11377}
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070011378
11379uword
11380unformat_qos_source (unformat_input_t * input, va_list * args)
11381{
11382 int *qs = va_arg (*args, int *);
11383
11384 if (unformat (input, "ip"))
11385 *qs = QOS_SOURCE_IP;
11386 else if (unformat (input, "mpls"))
11387 *qs = QOS_SOURCE_MPLS;
11388 else if (unformat (input, "ext"))
11389 *qs = QOS_SOURCE_EXT;
11390 else if (unformat (input, "vlan"))
11391 *qs = QOS_SOURCE_VLAN;
11392 else
11393 return 0;
11394
11395 return 1;
11396}
Dave Barach4a3f69c2017-02-22 12:44:56 -050011397#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010011398
11399uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050011400api_unformat_classify_match (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010011401{
11402 u8 **matchp = va_arg (*args, u8 **);
11403 u32 skip_n_vectors = va_arg (*args, u32);
11404 u32 match_n_vectors = va_arg (*args, u32);
11405
11406 u8 *match = 0;
11407 u8 *l2 = 0;
11408 u8 *l3 = 0;
11409 u8 *l4 = 0;
11410
11411 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11412 {
11413 if (unformat (input, "hex %U", unformat_hex_string, &match))
11414 ;
11415 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
11416 ;
11417 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
11418 ;
11419 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
11420 ;
11421 else
11422 break;
11423 }
11424
11425 if (l4 && !l3)
11426 {
11427 vec_free (match);
11428 vec_free (l2);
11429 vec_free (l4);
11430 return 0;
11431 }
11432
11433 if (match || l2 || l3 || l4)
11434 {
11435 if (l2 || l3 || l4)
11436 {
11437 /* "Win a free Ethernet header in every packet" */
11438 if (l2 == 0)
11439 vec_validate_aligned (l2, 13, sizeof (u32x4));
11440 match = l2;
11441 if (vec_len (l3))
11442 {
11443 vec_append_aligned (match, l3, sizeof (u32x4));
11444 vec_free (l3);
11445 }
11446 if (vec_len (l4))
11447 {
11448 vec_append_aligned (match, l4, sizeof (u32x4));
11449 vec_free (l4);
11450 }
11451 }
11452
11453 /* Make sure the vector is big enough even if key is all 0's */
11454 vec_validate_aligned
11455 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
11456 sizeof (u32x4));
11457
11458 /* Set size, include skipped vectors */
11459 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
11460
11461 *matchp = match;
11462
11463 return 1;
11464 }
11465
11466 return 0;
11467}
11468
11469static int
11470api_classify_add_del_session (vat_main_t * vam)
11471{
11472 unformat_input_t *i = vam->input;
11473 vl_api_classify_add_del_session_t *mp;
11474 int is_add = 1;
11475 u32 table_index = ~0;
11476 u32 hit_next_index = ~0;
11477 u32 opaque_index = ~0;
11478 u8 *match = 0;
11479 i32 advance = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011480 u32 skip_n_vectors = 0;
11481 u32 match_n_vectors = 0;
11482 u32 action = 0;
11483 u32 metadata = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011484 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011485
11486 /*
11487 * Warning: you have to supply skip_n and match_n
11488 * because the API client cant simply look at the classify
11489 * table object.
11490 */
11491
11492 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11493 {
11494 if (unformat (i, "del"))
11495 is_add = 0;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011496 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011497 &hit_next_index))
11498 ;
11499 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
11500 &hit_next_index))
11501 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011502 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011503 &hit_next_index))
11504 ;
11505 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
11506 ;
11507 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
11508 ;
11509 else if (unformat (i, "opaque-index %d", &opaque_index))
11510 ;
11511 else if (unformat (i, "skip_n %d", &skip_n_vectors))
11512 ;
11513 else if (unformat (i, "match_n %d", &match_n_vectors))
11514 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011515 else if (unformat (i, "match %U", api_unformat_classify_match,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011516 &match, skip_n_vectors, match_n_vectors))
11517 ;
11518 else if (unformat (i, "advance %d", &advance))
11519 ;
11520 else if (unformat (i, "table-index %d", &table_index))
11521 ;
11522 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
11523 action = 1;
11524 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
11525 action = 2;
11526 else if (unformat (i, "action %d", &action))
11527 ;
11528 else if (unformat (i, "metadata %d", &metadata))
11529 ;
11530 else
11531 break;
11532 }
11533
11534 if (table_index == ~0)
11535 {
11536 errmsg ("Table index required");
11537 return -99;
11538 }
11539
11540 if (is_add && match == 0)
11541 {
11542 errmsg ("Match value required");
11543 return -99;
11544 }
11545
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011546 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011547
11548 mp->is_add = is_add;
11549 mp->table_index = ntohl (table_index);
11550 mp->hit_next_index = ntohl (hit_next_index);
11551 mp->opaque_index = ntohl (opaque_index);
11552 mp->advance = ntohl (advance);
11553 mp->action = action;
11554 mp->metadata = ntohl (metadata);
Juraj Sloboda75282452018-06-12 14:20:49 +020011555 mp->match_len = ntohl (vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011556 clib_memcpy (mp->match, match, vec_len (match));
11557 vec_free (match);
11558
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011559 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011560 W (ret);
11561 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011562}
11563
11564static int
11565api_classify_set_interface_ip_table (vat_main_t * vam)
11566{
11567 unformat_input_t *i = vam->input;
11568 vl_api_classify_set_interface_ip_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011569 u32 sw_if_index;
11570 int sw_if_index_set;
11571 u32 table_index = ~0;
11572 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011573 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011574
11575 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11576 {
11577 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11578 sw_if_index_set = 1;
11579 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11580 sw_if_index_set = 1;
11581 else if (unformat (i, "table %d", &table_index))
11582 ;
11583 else
11584 {
11585 clib_warning ("parse error '%U'", format_unformat_error, i);
11586 return -99;
11587 }
11588 }
11589
11590 if (sw_if_index_set == 0)
11591 {
11592 errmsg ("missing interface name or sw_if_index");
11593 return -99;
11594 }
11595
11596
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011597 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011598
11599 mp->sw_if_index = ntohl (sw_if_index);
11600 mp->table_index = ntohl (table_index);
11601 mp->is_ipv6 = is_ipv6;
11602
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011603 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011604 W (ret);
11605 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011606}
11607
11608static int
11609api_classify_set_interface_l2_tables (vat_main_t * vam)
11610{
11611 unformat_input_t *i = vam->input;
11612 vl_api_classify_set_interface_l2_tables_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011613 u32 sw_if_index;
11614 int sw_if_index_set;
11615 u32 ip4_table_index = ~0;
11616 u32 ip6_table_index = ~0;
11617 u32 other_table_index = ~0;
11618 u32 is_input = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011619 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011620
11621 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11622 {
11623 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11624 sw_if_index_set = 1;
11625 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11626 sw_if_index_set = 1;
11627 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11628 ;
11629 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11630 ;
11631 else if (unformat (i, "other-table %d", &other_table_index))
11632 ;
11633 else if (unformat (i, "is-input %d", &is_input))
11634 ;
11635 else
11636 {
11637 clib_warning ("parse error '%U'", format_unformat_error, i);
11638 return -99;
11639 }
11640 }
11641
11642 if (sw_if_index_set == 0)
11643 {
11644 errmsg ("missing interface name or sw_if_index");
11645 return -99;
11646 }
11647
11648
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011649 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011650
11651 mp->sw_if_index = ntohl (sw_if_index);
11652 mp->ip4_table_index = ntohl (ip4_table_index);
11653 mp->ip6_table_index = ntohl (ip6_table_index);
11654 mp->other_table_index = ntohl (other_table_index);
11655 mp->is_input = (u8) is_input;
11656
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011657 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011658 W (ret);
11659 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011660}
11661
11662static int
11663api_set_ipfix_exporter (vat_main_t * vam)
11664{
11665 unformat_input_t *i = vam->input;
11666 vl_api_set_ipfix_exporter_t *mp;
11667 ip4_address_t collector_address;
11668 u8 collector_address_set = 0;
11669 u32 collector_port = ~0;
11670 ip4_address_t src_address;
11671 u8 src_address_set = 0;
11672 u32 vrf_id = ~0;
11673 u32 path_mtu = ~0;
11674 u32 template_interval = ~0;
11675 u8 udp_checksum = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011676 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011677
11678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11679 {
11680 if (unformat (i, "collector_address %U", unformat_ip4_address,
11681 &collector_address))
11682 collector_address_set = 1;
11683 else if (unformat (i, "collector_port %d", &collector_port))
11684 ;
11685 else if (unformat (i, "src_address %U", unformat_ip4_address,
11686 &src_address))
11687 src_address_set = 1;
11688 else if (unformat (i, "vrf_id %d", &vrf_id))
11689 ;
11690 else if (unformat (i, "path_mtu %d", &path_mtu))
11691 ;
11692 else if (unformat (i, "template_interval %d", &template_interval))
11693 ;
11694 else if (unformat (i, "udp_checksum"))
11695 udp_checksum = 1;
11696 else
11697 break;
11698 }
11699
11700 if (collector_address_set == 0)
11701 {
11702 errmsg ("collector_address required");
11703 return -99;
11704 }
11705
11706 if (src_address_set == 0)
11707 {
11708 errmsg ("src_address required");
11709 return -99;
11710 }
11711
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011712 M (SET_IPFIX_EXPORTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011713
11714 memcpy (mp->collector_address, collector_address.data,
11715 sizeof (collector_address.data));
11716 mp->collector_port = htons ((u16) collector_port);
11717 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
11718 mp->vrf_id = htonl (vrf_id);
11719 mp->path_mtu = htonl (path_mtu);
11720 mp->template_interval = htonl (template_interval);
11721 mp->udp_checksum = udp_checksum;
11722
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011723 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011724 W (ret);
11725 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011726}
11727
11728static int
11729api_set_ipfix_classify_stream (vat_main_t * vam)
11730{
11731 unformat_input_t *i = vam->input;
11732 vl_api_set_ipfix_classify_stream_t *mp;
11733 u32 domain_id = 0;
11734 u32 src_port = UDP_DST_PORT_ipfix;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011735 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011736
11737 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11738 {
11739 if (unformat (i, "domain %d", &domain_id))
11740 ;
11741 else if (unformat (i, "src_port %d", &src_port))
11742 ;
11743 else
11744 {
11745 errmsg ("unknown input `%U'", format_unformat_error, i);
11746 return -99;
11747 }
11748 }
11749
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011750 M (SET_IPFIX_CLASSIFY_STREAM, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011751
11752 mp->domain_id = htonl (domain_id);
11753 mp->src_port = htons ((u16) src_port);
11754
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011755 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011756 W (ret);
11757 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011758}
11759
11760static int
11761api_ipfix_classify_table_add_del (vat_main_t * vam)
11762{
11763 unformat_input_t *i = vam->input;
11764 vl_api_ipfix_classify_table_add_del_t *mp;
11765 int is_add = -1;
11766 u32 classify_table_index = ~0;
11767 u8 ip_version = 0;
11768 u8 transport_protocol = 255;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011769 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011770
11771 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11772 {
11773 if (unformat (i, "add"))
11774 is_add = 1;
11775 else if (unformat (i, "del"))
11776 is_add = 0;
11777 else if (unformat (i, "table %d", &classify_table_index))
11778 ;
11779 else if (unformat (i, "ip4"))
11780 ip_version = 4;
11781 else if (unformat (i, "ip6"))
11782 ip_version = 6;
11783 else if (unformat (i, "tcp"))
11784 transport_protocol = 6;
11785 else if (unformat (i, "udp"))
11786 transport_protocol = 17;
11787 else
11788 {
11789 errmsg ("unknown input `%U'", format_unformat_error, i);
11790 return -99;
11791 }
11792 }
11793
11794 if (is_add == -1)
11795 {
11796 errmsg ("expecting: add|del");
11797 return -99;
11798 }
11799 if (classify_table_index == ~0)
11800 {
11801 errmsg ("classifier table not specified");
11802 return -99;
11803 }
11804 if (ip_version == 0)
11805 {
11806 errmsg ("IP version not specified");
11807 return -99;
11808 }
11809
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011810 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011811
11812 mp->is_add = is_add;
11813 mp->table_id = htonl (classify_table_index);
11814 mp->ip_version = ip_version;
11815 mp->transport_protocol = transport_protocol;
11816
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011817 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011818 W (ret);
11819 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011820}
11821
11822static int
11823api_get_node_index (vat_main_t * vam)
11824{
11825 unformat_input_t *i = vam->input;
11826 vl_api_get_node_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011827 u8 *name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011828 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011829
11830 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11831 {
11832 if (unformat (i, "node %s", &name))
11833 ;
11834 else
11835 break;
11836 }
11837 if (name == 0)
11838 {
11839 errmsg ("node name required");
11840 return -99;
11841 }
11842 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
11843 {
11844 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11845 return -99;
11846 }
11847
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011848 M (GET_NODE_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011849 clib_memcpy (mp->node_name, name, vec_len (name));
11850 vec_free (name);
11851
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011852 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011853 W (ret);
11854 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011855}
11856
11857static int
11858api_get_next_index (vat_main_t * vam)
11859{
11860 unformat_input_t *i = vam->input;
11861 vl_api_get_next_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011862 u8 *node_name = 0, *next_node_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011863 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011864
11865 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11866 {
11867 if (unformat (i, "node-name %s", &node_name))
11868 ;
11869 else if (unformat (i, "next-node-name %s", &next_node_name))
11870 break;
11871 }
11872
11873 if (node_name == 0)
11874 {
11875 errmsg ("node name required");
11876 return -99;
11877 }
11878 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
11879 {
11880 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11881 return -99;
11882 }
11883
11884 if (next_node_name == 0)
11885 {
11886 errmsg ("next node name required");
11887 return -99;
11888 }
11889 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
11890 {
11891 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
11892 return -99;
11893 }
11894
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011895 M (GET_NEXT_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011896 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
11897 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
11898 vec_free (node_name);
11899 vec_free (next_node_name);
11900
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011901 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011902 W (ret);
11903 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011904}
11905
11906static int
11907api_add_node_next (vat_main_t * vam)
11908{
11909 unformat_input_t *i = vam->input;
11910 vl_api_add_node_next_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011911 u8 *name = 0;
11912 u8 *next = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011913 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011914
11915 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11916 {
11917 if (unformat (i, "node %s", &name))
11918 ;
11919 else if (unformat (i, "next %s", &next))
11920 ;
11921 else
11922 break;
11923 }
11924 if (name == 0)
11925 {
11926 errmsg ("node name required");
11927 return -99;
11928 }
11929 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
11930 {
11931 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11932 return -99;
11933 }
11934 if (next == 0)
11935 {
11936 errmsg ("next node required");
11937 return -99;
11938 }
11939 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
11940 {
11941 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
11942 return -99;
11943 }
11944
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011945 M (ADD_NODE_NEXT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011946 clib_memcpy (mp->node_name, name, vec_len (name));
11947 clib_memcpy (mp->next_name, next, vec_len (next));
11948 vec_free (name);
11949 vec_free (next);
11950
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011951 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011952 W (ret);
11953 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011954}
11955
11956static int
11957api_l2tpv3_create_tunnel (vat_main_t * vam)
11958{
11959 unformat_input_t *i = vam->input;
11960 ip6_address_t client_address, our_address;
11961 int client_address_set = 0;
11962 int our_address_set = 0;
11963 u32 local_session_id = 0;
11964 u32 remote_session_id = 0;
11965 u64 local_cookie = 0;
11966 u64 remote_cookie = 0;
11967 u8 l2_sublayer_present = 0;
11968 vl_api_l2tpv3_create_tunnel_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011969 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011970
11971 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11972 {
11973 if (unformat (i, "client_address %U", unformat_ip6_address,
11974 &client_address))
11975 client_address_set = 1;
11976 else if (unformat (i, "our_address %U", unformat_ip6_address,
11977 &our_address))
11978 our_address_set = 1;
11979 else if (unformat (i, "local_session_id %d", &local_session_id))
11980 ;
11981 else if (unformat (i, "remote_session_id %d", &remote_session_id))
11982 ;
11983 else if (unformat (i, "local_cookie %lld", &local_cookie))
11984 ;
11985 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
11986 ;
11987 else if (unformat (i, "l2-sublayer-present"))
11988 l2_sublayer_present = 1;
11989 else
11990 break;
11991 }
11992
11993 if (client_address_set == 0)
11994 {
11995 errmsg ("client_address required");
11996 return -99;
11997 }
11998
11999 if (our_address_set == 0)
12000 {
12001 errmsg ("our_address required");
12002 return -99;
12003 }
12004
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012005 M (L2TPV3_CREATE_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012006
12007 clib_memcpy (mp->client_address, client_address.as_u8,
12008 sizeof (mp->client_address));
12009
12010 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
12011
12012 mp->local_session_id = ntohl (local_session_id);
12013 mp->remote_session_id = ntohl (remote_session_id);
12014 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
12015 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
12016 mp->l2_sublayer_present = l2_sublayer_present;
12017 mp->is_ipv6 = 1;
12018
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012019 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012020 W (ret);
12021 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012022}
12023
12024static int
12025api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
12026{
12027 unformat_input_t *i = vam->input;
12028 u32 sw_if_index;
12029 u8 sw_if_index_set = 0;
12030 u64 new_local_cookie = 0;
12031 u64 new_remote_cookie = 0;
12032 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012033 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012034
12035 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12036 {
12037 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12038 sw_if_index_set = 1;
12039 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12040 sw_if_index_set = 1;
12041 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
12042 ;
12043 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
12044 ;
12045 else
12046 break;
12047 }
12048
12049 if (sw_if_index_set == 0)
12050 {
12051 errmsg ("missing interface name or sw_if_index");
12052 return -99;
12053 }
12054
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012055 M (L2TPV3_SET_TUNNEL_COOKIES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012056
12057 mp->sw_if_index = ntohl (sw_if_index);
12058 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
12059 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
12060
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012061 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012062 W (ret);
12063 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012064}
12065
12066static int
12067api_l2tpv3_interface_enable_disable (vat_main_t * vam)
12068{
12069 unformat_input_t *i = vam->input;
12070 vl_api_l2tpv3_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012071 u32 sw_if_index;
12072 u8 sw_if_index_set = 0;
12073 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012074 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012075
12076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12077 {
12078 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12079 sw_if_index_set = 1;
12080 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12081 sw_if_index_set = 1;
12082 else if (unformat (i, "enable"))
12083 enable_disable = 1;
12084 else if (unformat (i, "disable"))
12085 enable_disable = 0;
12086 else
12087 break;
12088 }
12089
12090 if (sw_if_index_set == 0)
12091 {
12092 errmsg ("missing interface name or sw_if_index");
12093 return -99;
12094 }
12095
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012096 M (L2TPV3_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012097
12098 mp->sw_if_index = ntohl (sw_if_index);
12099 mp->enable_disable = enable_disable;
12100
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012101 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012102 W (ret);
12103 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012104}
12105
12106static int
12107api_l2tpv3_set_lookup_key (vat_main_t * vam)
12108{
12109 unformat_input_t *i = vam->input;
12110 vl_api_l2tpv3_set_lookup_key_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012111 u8 key = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012112 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012113
12114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12115 {
12116 if (unformat (i, "lookup_v6_src"))
12117 key = L2T_LOOKUP_SRC_ADDRESS;
12118 else if (unformat (i, "lookup_v6_dst"))
12119 key = L2T_LOOKUP_DST_ADDRESS;
12120 else if (unformat (i, "lookup_session_id"))
12121 key = L2T_LOOKUP_SESSION_ID;
12122 else
12123 break;
12124 }
12125
12126 if (key == (u8) ~ 0)
12127 {
12128 errmsg ("l2tp session lookup key unset");
12129 return -99;
12130 }
12131
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012132 M (L2TPV3_SET_LOOKUP_KEY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012133
12134 mp->key = key;
12135
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012136 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012137 W (ret);
12138 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012139}
12140
12141static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
12142 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
12143{
12144 vat_main_t *vam = &vat_main;
12145
12146 print (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)",
12147 format_ip6_address, mp->our_address,
12148 format_ip6_address, mp->client_address,
12149 clib_net_to_host_u32 (mp->sw_if_index));
12150
12151 print (vam->ofp,
12152 " local cookies %016llx %016llx remote cookie %016llx",
12153 clib_net_to_host_u64 (mp->local_cookie[0]),
12154 clib_net_to_host_u64 (mp->local_cookie[1]),
12155 clib_net_to_host_u64 (mp->remote_cookie));
12156
12157 print (vam->ofp, " local session-id %d remote session-id %d",
12158 clib_net_to_host_u32 (mp->local_session_id),
12159 clib_net_to_host_u32 (mp->remote_session_id));
12160
12161 print (vam->ofp, " l2 specific sublayer %s\n",
12162 mp->l2_sublayer_present ? "preset" : "absent");
12163
12164}
12165
12166static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
12167 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
12168{
12169 vat_main_t *vam = &vat_main;
12170 vat_json_node_t *node = NULL;
12171 struct in6_addr addr;
12172
12173 if (VAT_JSON_ARRAY != vam->json_tree.type)
12174 {
12175 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12176 vat_json_init_array (&vam->json_tree);
12177 }
12178 node = vat_json_array_add (&vam->json_tree);
12179
12180 vat_json_init_object (node);
12181
12182 clib_memcpy (&addr, mp->our_address, sizeof (addr));
12183 vat_json_object_add_ip6 (node, "our_address", addr);
12184 clib_memcpy (&addr, mp->client_address, sizeof (addr));
12185 vat_json_object_add_ip6 (node, "client_address", addr);
12186
12187 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
12188 vat_json_init_array (lc);
12189 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
12190 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
12191 vat_json_object_add_uint (node, "remote_cookie",
12192 clib_net_to_host_u64 (mp->remote_cookie));
12193
12194 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
12195 vat_json_object_add_uint (node, "local_session_id",
12196 clib_net_to_host_u32 (mp->local_session_id));
12197 vat_json_object_add_uint (node, "remote_session_id",
12198 clib_net_to_host_u32 (mp->remote_session_id));
12199 vat_json_object_add_string_copy (node, "l2_sublayer",
12200 mp->l2_sublayer_present ? (u8 *) "present"
12201 : (u8 *) "absent");
12202}
12203
12204static int
12205api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
12206{
12207 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012208 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012209 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012210
12211 /* Get list of l2tpv3-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012212 M (SW_IF_L2TPV3_TUNNEL_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012213 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012214
12215 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012216 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012217 S (mp_ping);
12218
Jon Loeliger56c7b012017-02-01 12:31:41 -060012219 W (ret);
12220 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012221}
12222
12223
Damjan Marion8389fb92017-10-13 18:29:53 +020012224static void vl_api_sw_interface_tap_v2_details_t_handler
12225 (vl_api_sw_interface_tap_v2_details_t * mp)
12226{
12227 vat_main_t *vam = &vat_main;
12228
Milan Lenco73e7f422017-12-14 10:04:25 +010012229 u8 *ip4 = format (0, "%U/%d", format_ip4_address, mp->host_ip4_addr,
12230 mp->host_ip4_prefix_len);
12231 u8 *ip6 = format (0, "%U/%d", format_ip6_address, mp->host_ip6_addr,
12232 mp->host_ip6_prefix_len);
12233
12234 print (vam->ofp,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012235 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
Milan Lenco73e7f422017-12-14 10:04:25 +010012236 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
12237 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
12238 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012239 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
Milan Lenco73e7f422017-12-14 10:04:25 +010012240
12241 vec_free (ip4);
12242 vec_free (ip6);
Damjan Marion8389fb92017-10-13 18:29:53 +020012243}
12244
12245static void vl_api_sw_interface_tap_v2_details_t_handler_json
12246 (vl_api_sw_interface_tap_v2_details_t * mp)
12247{
12248 vat_main_t *vam = &vat_main;
12249 vat_json_node_t *node = NULL;
12250
12251 if (VAT_JSON_ARRAY != vam->json_tree.type)
12252 {
12253 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12254 vat_json_init_array (&vam->json_tree);
12255 }
12256 node = vat_json_array_add (&vam->json_tree);
12257
12258 vat_json_init_object (node);
Milan Lenco73e7f422017-12-14 10:04:25 +010012259 vat_json_object_add_uint (node, "id", ntohl (mp->id));
Damjan Marion8389fb92017-10-13 18:29:53 +020012260 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012261 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
Damjan Marion8389fb92017-10-13 18:29:53 +020012262 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Milan Lenco73e7f422017-12-14 10:04:25 +010012263 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
12264 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
12265 vat_json_object_add_string_copy (node, "host_mac_addr",
12266 format (0, "%U", format_ethernet_address,
12267 &mp->host_mac_addr));
12268 vat_json_object_add_string_copy (node, "host_namespace",
12269 mp->host_namespace);
12270 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
12271 vat_json_object_add_string_copy (node, "host_ip4_addr",
12272 format (0, "%U/%d", format_ip4_address,
12273 mp->host_ip4_addr,
12274 mp->host_ip4_prefix_len));
12275 vat_json_object_add_string_copy (node, "host_ip6_addr",
12276 format (0, "%U/%d", format_ip6_address,
12277 mp->host_ip6_addr,
12278 mp->host_ip6_prefix_len));
12279
Damjan Marion8389fb92017-10-13 18:29:53 +020012280}
12281
12282static int
12283api_sw_interface_tap_v2_dump (vat_main_t * vam)
12284{
12285 vl_api_sw_interface_tap_v2_dump_t *mp;
12286 vl_api_control_ping_t *mp_ping;
12287 int ret;
12288
Milan Lenco73e7f422017-12-14 10:04:25 +010012289 print (vam->ofp,
12290 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
12291 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
12292 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
12293 "host_ip6_addr");
12294
Damjan Marion8389fb92017-10-13 18:29:53 +020012295 /* Get list of tap interfaces */
12296 M (SW_INTERFACE_TAP_V2_DUMP, mp);
12297 S (mp);
12298
12299 /* Use a control ping for synchronization */
12300 MPING (CONTROL_PING, mp_ping);
12301 S (mp_ping);
12302
12303 W (ret);
12304 return ret;
12305}
12306
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010012307static void vl_api_sw_interface_virtio_pci_details_t_handler
12308 (vl_api_sw_interface_virtio_pci_details_t * mp)
12309{
12310 vat_main_t *vam = &vat_main;
12311
12312 typedef union
12313 {
12314 struct
12315 {
12316 u16 domain;
12317 u8 bus;
12318 u8 slot:5;
12319 u8 function:3;
12320 };
12321 u32 as_u32;
12322 } pci_addr_t;
12323 pci_addr_t addr;
12324 addr.as_u32 = ntohl (mp->pci_addr);
12325 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
12326 addr.slot, addr.function);
12327
12328 print (vam->ofp,
12329 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
12330 pci_addr, ntohl (mp->sw_if_index),
12331 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
12332 format_ethernet_address, mp->mac_addr,
12333 clib_net_to_host_u64 (mp->features));
12334 vec_free (pci_addr);
12335}
12336
12337static void vl_api_sw_interface_virtio_pci_details_t_handler_json
12338 (vl_api_sw_interface_virtio_pci_details_t * mp)
12339{
12340 vat_main_t *vam = &vat_main;
12341 vat_json_node_t *node = NULL;
12342
12343 if (VAT_JSON_ARRAY != vam->json_tree.type)
12344 {
12345 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12346 vat_json_init_array (&vam->json_tree);
12347 }
12348 node = vat_json_array_add (&vam->json_tree);
12349
12350 vat_json_init_object (node);
12351 vat_json_object_add_uint (node, "pci-addr", ntohl (mp->pci_addr));
12352 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12353 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
12354 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
12355 vat_json_object_add_uint (node, "features",
12356 clib_net_to_host_u64 (mp->features));
12357 vat_json_object_add_string_copy (node, "mac_addr",
12358 format (0, "%U", format_ethernet_address,
12359 &mp->mac_addr));
12360}
12361
12362static int
12363api_sw_interface_virtio_pci_dump (vat_main_t * vam)
12364{
12365 vl_api_sw_interface_virtio_pci_dump_t *mp;
12366 vl_api_control_ping_t *mp_ping;
12367 int ret;
12368
12369 print (vam->ofp,
12370 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
12371 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
12372 "mac_addr", "features");
12373
12374 /* Get list of tap interfaces */
12375 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
12376 S (mp);
12377
12378 /* Use a control ping for synchronization */
12379 MPING (CONTROL_PING, mp_ping);
12380 S (mp_ping);
12381
12382 W (ret);
12383 return ret;
12384}
12385
eyal bariaf86a482018-04-17 11:20:27 +030012386static int
12387api_vxlan_offload_rx (vat_main_t * vam)
12388{
12389 unformat_input_t *line_input = vam->input;
12390 vl_api_vxlan_offload_rx_t *mp;
12391 u32 hw_if_index = ~0, rx_if_index = ~0;
12392 u8 is_add = 1;
12393 int ret;
12394
12395 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12396 {
12397 if (unformat (line_input, "del"))
12398 is_add = 0;
12399 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
12400 &hw_if_index))
12401 ;
12402 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
12403 ;
12404 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
12405 &rx_if_index))
12406 ;
12407 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
12408 ;
12409 else
12410 {
12411 errmsg ("parse error '%U'", format_unformat_error, line_input);
12412 return -99;
12413 }
12414 }
12415
12416 if (hw_if_index == ~0)
12417 {
12418 errmsg ("no hw interface");
12419 return -99;
12420 }
12421
12422 if (rx_if_index == ~0)
12423 {
12424 errmsg ("no rx tunnel");
12425 return -99;
12426 }
12427
12428 M (VXLAN_OFFLOAD_RX, mp);
12429
12430 mp->hw_if_index = ntohl (hw_if_index);
12431 mp->sw_if_index = ntohl (rx_if_index);
12432 mp->enable = is_add;
12433
12434 S (mp);
12435 W (ret);
12436 return ret;
12437}
12438
Damjan Marion7cd468a2016-12-19 23:05:39 +010012439static uword unformat_vxlan_decap_next
12440 (unformat_input_t * input, va_list * args)
12441{
12442 u32 *result = va_arg (*args, u32 *);
12443 u32 tmp;
12444
12445 if (unformat (input, "l2"))
12446 *result = VXLAN_INPUT_NEXT_L2_INPUT;
12447 else if (unformat (input, "%d", &tmp))
12448 *result = tmp;
12449 else
12450 return 0;
12451 return 1;
12452}
12453
12454static int
12455api_vxlan_add_del_tunnel (vat_main_t * vam)
12456{
12457 unformat_input_t *line_input = vam->input;
12458 vl_api_vxlan_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012459 ip46_address_t src, dst;
12460 u8 is_add = 1;
12461 u8 ipv4_set = 0, ipv6_set = 0;
12462 u8 src_set = 0;
12463 u8 dst_set = 0;
12464 u8 grp_set = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012465 u32 instance = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012466 u32 mcast_sw_if_index = ~0;
12467 u32 encap_vrf_id = 0;
12468 u32 decap_next_index = ~0;
12469 u32 vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012470 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012471
12472 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040012473 clib_memset (&src, 0, sizeof src);
12474 clib_memset (&dst, 0, sizeof dst);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012475
12476 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12477 {
12478 if (unformat (line_input, "del"))
12479 is_add = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012480 else if (unformat (line_input, "instance %d", &instance))
12481 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012482 else
12483 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
12484 {
12485 ipv4_set = 1;
12486 src_set = 1;
12487 }
12488 else
12489 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
12490 {
12491 ipv4_set = 1;
12492 dst_set = 1;
12493 }
12494 else
12495 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
12496 {
12497 ipv6_set = 1;
12498 src_set = 1;
12499 }
12500 else
12501 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
12502 {
12503 ipv6_set = 1;
12504 dst_set = 1;
12505 }
12506 else if (unformat (line_input, "group %U %U",
12507 unformat_ip4_address, &dst.ip4,
12508 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12509 {
12510 grp_set = dst_set = 1;
12511 ipv4_set = 1;
12512 }
12513 else if (unformat (line_input, "group %U",
12514 unformat_ip4_address, &dst.ip4))
12515 {
12516 grp_set = dst_set = 1;
12517 ipv4_set = 1;
12518 }
12519 else if (unformat (line_input, "group %U %U",
12520 unformat_ip6_address, &dst.ip6,
12521 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12522 {
12523 grp_set = dst_set = 1;
12524 ipv6_set = 1;
12525 }
12526 else if (unformat (line_input, "group %U",
12527 unformat_ip6_address, &dst.ip6))
12528 {
12529 grp_set = dst_set = 1;
12530 ipv6_set = 1;
12531 }
12532 else
12533 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
12534 ;
12535 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
12536 ;
12537 else if (unformat (line_input, "decap-next %U",
12538 unformat_vxlan_decap_next, &decap_next_index))
12539 ;
12540 else if (unformat (line_input, "vni %d", &vni))
12541 ;
12542 else
12543 {
12544 errmsg ("parse error '%U'", format_unformat_error, line_input);
12545 return -99;
12546 }
12547 }
12548
12549 if (src_set == 0)
12550 {
12551 errmsg ("tunnel src address not specified");
12552 return -99;
12553 }
12554 if (dst_set == 0)
12555 {
12556 errmsg ("tunnel dst address not specified");
12557 return -99;
12558 }
12559
12560 if (grp_set && !ip46_address_is_multicast (&dst))
12561 {
12562 errmsg ("tunnel group address not multicast");
12563 return -99;
12564 }
12565 if (grp_set && mcast_sw_if_index == ~0)
12566 {
12567 errmsg ("tunnel nonexistent multicast device");
12568 return -99;
12569 }
12570 if (grp_set == 0 && ip46_address_is_multicast (&dst))
12571 {
12572 errmsg ("tunnel dst address must be unicast");
12573 return -99;
12574 }
12575
12576
12577 if (ipv4_set && ipv6_set)
12578 {
12579 errmsg ("both IPv4 and IPv6 addresses specified");
12580 return -99;
12581 }
12582
12583 if ((vni == 0) || (vni >> 24))
12584 {
12585 errmsg ("vni not specified or out of range");
12586 return -99;
12587 }
12588
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012589 M (VXLAN_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012590
12591 if (ipv6_set)
12592 {
12593 clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
12594 clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
12595 }
12596 else
12597 {
12598 clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
12599 clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
12600 }
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012601
12602 mp->instance = htonl (instance);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012603 mp->encap_vrf_id = ntohl (encap_vrf_id);
12604 mp->decap_next_index = ntohl (decap_next_index);
12605 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
12606 mp->vni = ntohl (vni);
12607 mp->is_add = is_add;
12608 mp->is_ipv6 = ipv6_set;
12609
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012610 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012611 W (ret);
12612 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012613}
12614
12615static void vl_api_vxlan_tunnel_details_t_handler
12616 (vl_api_vxlan_tunnel_details_t * mp)
12617{
12618 vat_main_t *vam = &vat_main;
Eyal Barie101e1f2017-03-15 08:23:42 +020012619 ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
12620 ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012621
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012622 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012623 ntohl (mp->sw_if_index),
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012624 ntohl (mp->instance),
Damjan Marion7cd468a2016-12-19 23:05:39 +010012625 format_ip46_address, &src, IP46_TYPE_ANY,
12626 format_ip46_address, &dst, IP46_TYPE_ANY,
12627 ntohl (mp->encap_vrf_id),
12628 ntohl (mp->decap_next_index), ntohl (mp->vni),
12629 ntohl (mp->mcast_sw_if_index));
12630}
12631
12632static void vl_api_vxlan_tunnel_details_t_handler_json
12633 (vl_api_vxlan_tunnel_details_t * mp)
12634{
12635 vat_main_t *vam = &vat_main;
12636 vat_json_node_t *node = NULL;
12637
12638 if (VAT_JSON_ARRAY != vam->json_tree.type)
12639 {
12640 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12641 vat_json_init_array (&vam->json_tree);
12642 }
12643 node = vat_json_array_add (&vam->json_tree);
12644
12645 vat_json_init_object (node);
12646 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012647
12648 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
12649
Damjan Marion7cd468a2016-12-19 23:05:39 +010012650 if (mp->is_ipv6)
12651 {
12652 struct in6_addr ip6;
12653
12654 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
12655 vat_json_object_add_ip6 (node, "src_address", ip6);
12656 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
12657 vat_json_object_add_ip6 (node, "dst_address", ip6);
12658 }
12659 else
12660 {
12661 struct in_addr ip4;
12662
12663 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
12664 vat_json_object_add_ip4 (node, "src_address", ip4);
12665 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
12666 vat_json_object_add_ip4 (node, "dst_address", ip4);
12667 }
12668 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12669 vat_json_object_add_uint (node, "decap_next_index",
12670 ntohl (mp->decap_next_index));
12671 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
12672 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
12673 vat_json_object_add_uint (node, "mcast_sw_if_index",
12674 ntohl (mp->mcast_sw_if_index));
12675}
12676
12677static int
12678api_vxlan_tunnel_dump (vat_main_t * vam)
12679{
12680 unformat_input_t *i = vam->input;
12681 vl_api_vxlan_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012682 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012683 u32 sw_if_index;
12684 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012685 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012686
12687 /* Parse args required to build the message */
12688 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12689 {
12690 if (unformat (i, "sw_if_index %d", &sw_if_index))
12691 sw_if_index_set = 1;
12692 else
12693 break;
12694 }
12695
12696 if (sw_if_index_set == 0)
12697 {
12698 sw_if_index = ~0;
12699 }
12700
12701 if (!vam->json_output)
12702 {
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012703 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
12704 "sw_if_index", "instance", "src_address", "dst_address",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012705 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
12706 }
12707
12708 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012709 M (VXLAN_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012710
12711 mp->sw_if_index = htonl (sw_if_index);
12712
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012713 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012714
12715 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012716 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012717 S (mp_ping);
12718
Jon Loeliger56c7b012017-02-01 12:31:41 -060012719 W (ret);
12720 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012721}
12722
Marco Varleseb598f1d2017-09-19 14:25:28 +020012723static uword unformat_geneve_decap_next
12724 (unformat_input_t * input, va_list * args)
12725{
12726 u32 *result = va_arg (*args, u32 *);
12727 u32 tmp;
12728
12729 if (unformat (input, "l2"))
12730 *result = GENEVE_INPUT_NEXT_L2_INPUT;
12731 else if (unformat (input, "%d", &tmp))
12732 *result = tmp;
12733 else
12734 return 0;
12735 return 1;
12736}
12737
12738static int
12739api_geneve_add_del_tunnel (vat_main_t * vam)
12740{
12741 unformat_input_t *line_input = vam->input;
12742 vl_api_geneve_add_del_tunnel_t *mp;
12743 ip46_address_t src, dst;
12744 u8 is_add = 1;
12745 u8 ipv4_set = 0, ipv6_set = 0;
12746 u8 src_set = 0;
12747 u8 dst_set = 0;
12748 u8 grp_set = 0;
12749 u32 mcast_sw_if_index = ~0;
12750 u32 encap_vrf_id = 0;
12751 u32 decap_next_index = ~0;
12752 u32 vni = 0;
12753 int ret;
12754
12755 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040012756 clib_memset (&src, 0, sizeof src);
12757 clib_memset (&dst, 0, sizeof dst);
Marco Varleseb598f1d2017-09-19 14:25:28 +020012758
12759 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12760 {
12761 if (unformat (line_input, "del"))
12762 is_add = 0;
12763 else
12764 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
12765 {
12766 ipv4_set = 1;
12767 src_set = 1;
12768 }
12769 else
12770 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
12771 {
12772 ipv4_set = 1;
12773 dst_set = 1;
12774 }
12775 else
12776 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
12777 {
12778 ipv6_set = 1;
12779 src_set = 1;
12780 }
12781 else
12782 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
12783 {
12784 ipv6_set = 1;
12785 dst_set = 1;
12786 }
12787 else if (unformat (line_input, "group %U %U",
12788 unformat_ip4_address, &dst.ip4,
12789 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12790 {
12791 grp_set = dst_set = 1;
12792 ipv4_set = 1;
12793 }
12794 else if (unformat (line_input, "group %U",
12795 unformat_ip4_address, &dst.ip4))
12796 {
12797 grp_set = dst_set = 1;
12798 ipv4_set = 1;
12799 }
12800 else if (unformat (line_input, "group %U %U",
12801 unformat_ip6_address, &dst.ip6,
12802 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12803 {
12804 grp_set = dst_set = 1;
12805 ipv6_set = 1;
12806 }
12807 else if (unformat (line_input, "group %U",
12808 unformat_ip6_address, &dst.ip6))
12809 {
12810 grp_set = dst_set = 1;
12811 ipv6_set = 1;
12812 }
12813 else
12814 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
12815 ;
12816 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
12817 ;
12818 else if (unformat (line_input, "decap-next %U",
12819 unformat_geneve_decap_next, &decap_next_index))
12820 ;
12821 else if (unformat (line_input, "vni %d", &vni))
12822 ;
12823 else
12824 {
12825 errmsg ("parse error '%U'", format_unformat_error, line_input);
12826 return -99;
12827 }
12828 }
12829
12830 if (src_set == 0)
12831 {
12832 errmsg ("tunnel src address not specified");
12833 return -99;
12834 }
12835 if (dst_set == 0)
12836 {
12837 errmsg ("tunnel dst address not specified");
12838 return -99;
12839 }
12840
12841 if (grp_set && !ip46_address_is_multicast (&dst))
12842 {
12843 errmsg ("tunnel group address not multicast");
12844 return -99;
12845 }
12846 if (grp_set && mcast_sw_if_index == ~0)
12847 {
12848 errmsg ("tunnel nonexistent multicast device");
12849 return -99;
12850 }
12851 if (grp_set == 0 && ip46_address_is_multicast (&dst))
12852 {
12853 errmsg ("tunnel dst address must be unicast");
12854 return -99;
12855 }
12856
12857
12858 if (ipv4_set && ipv6_set)
12859 {
12860 errmsg ("both IPv4 and IPv6 addresses specified");
12861 return -99;
12862 }
12863
12864 if ((vni == 0) || (vni >> 24))
12865 {
12866 errmsg ("vni not specified or out of range");
12867 return -99;
12868 }
12869
12870 M (GENEVE_ADD_DEL_TUNNEL, mp);
12871
12872 if (ipv6_set)
12873 {
12874 clib_memcpy (mp->local_address, &src.ip6, sizeof (src.ip6));
12875 clib_memcpy (mp->remote_address, &dst.ip6, sizeof (dst.ip6));
12876 }
12877 else
12878 {
12879 clib_memcpy (mp->local_address, &src.ip4, sizeof (src.ip4));
12880 clib_memcpy (mp->remote_address, &dst.ip4, sizeof (dst.ip4));
12881 }
12882 mp->encap_vrf_id = ntohl (encap_vrf_id);
12883 mp->decap_next_index = ntohl (decap_next_index);
12884 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
12885 mp->vni = ntohl (vni);
12886 mp->is_add = is_add;
12887 mp->is_ipv6 = ipv6_set;
12888
12889 S (mp);
12890 W (ret);
12891 return ret;
12892}
12893
12894static void vl_api_geneve_tunnel_details_t_handler
12895 (vl_api_geneve_tunnel_details_t * mp)
12896{
12897 vat_main_t *vam = &vat_main;
12898 ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
12899 ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
12900
12901 print (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d",
12902 ntohl (mp->sw_if_index),
12903 format_ip46_address, &src, IP46_TYPE_ANY,
12904 format_ip46_address, &dst, IP46_TYPE_ANY,
12905 ntohl (mp->encap_vrf_id),
12906 ntohl (mp->decap_next_index), ntohl (mp->vni),
12907 ntohl (mp->mcast_sw_if_index));
12908}
12909
12910static void vl_api_geneve_tunnel_details_t_handler_json
12911 (vl_api_geneve_tunnel_details_t * mp)
12912{
12913 vat_main_t *vam = &vat_main;
12914 vat_json_node_t *node = NULL;
12915
12916 if (VAT_JSON_ARRAY != vam->json_tree.type)
12917 {
12918 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12919 vat_json_init_array (&vam->json_tree);
12920 }
12921 node = vat_json_array_add (&vam->json_tree);
12922
12923 vat_json_init_object (node);
12924 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12925 if (mp->is_ipv6)
12926 {
12927 struct in6_addr ip6;
12928
12929 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
12930 vat_json_object_add_ip6 (node, "src_address", ip6);
12931 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
12932 vat_json_object_add_ip6 (node, "dst_address", ip6);
12933 }
12934 else
12935 {
12936 struct in_addr ip4;
12937
12938 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
12939 vat_json_object_add_ip4 (node, "src_address", ip4);
12940 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
12941 vat_json_object_add_ip4 (node, "dst_address", ip4);
12942 }
12943 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12944 vat_json_object_add_uint (node, "decap_next_index",
12945 ntohl (mp->decap_next_index));
12946 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
12947 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
12948 vat_json_object_add_uint (node, "mcast_sw_if_index",
12949 ntohl (mp->mcast_sw_if_index));
12950}
12951
12952static int
12953api_geneve_tunnel_dump (vat_main_t * vam)
12954{
12955 unformat_input_t *i = vam->input;
12956 vl_api_geneve_tunnel_dump_t *mp;
12957 vl_api_control_ping_t *mp_ping;
12958 u32 sw_if_index;
12959 u8 sw_if_index_set = 0;
12960 int ret;
12961
12962 /* Parse args required to build the message */
12963 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12964 {
12965 if (unformat (i, "sw_if_index %d", &sw_if_index))
12966 sw_if_index_set = 1;
12967 else
12968 break;
12969 }
12970
12971 if (sw_if_index_set == 0)
12972 {
12973 sw_if_index = ~0;
12974 }
12975
12976 if (!vam->json_output)
12977 {
12978 print (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s",
12979 "sw_if_index", "local_address", "remote_address",
12980 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
12981 }
12982
12983 /* Get list of geneve-tunnel interfaces */
12984 M (GENEVE_TUNNEL_DUMP, mp);
12985
12986 mp->sw_if_index = htonl (sw_if_index);
12987
12988 S (mp);
12989
12990 /* Use a control ping for synchronization */
12991 M (CONTROL_PING, mp_ping);
12992 S (mp_ping);
12993
12994 W (ret);
12995 return ret;
12996}
12997
Damjan Marion7cd468a2016-12-19 23:05:39 +010012998static int
Neale Ranns5a8844b2019-04-16 07:15:35 +000012999api_gre_tunnel_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013000{
13001 unformat_input_t *line_input = vam->input;
Neale Ranns5a8844b2019-04-16 07:15:35 +000013002 vl_api_address_t src = { }, dst =
13003 {
13004 };
13005 vl_api_gre_tunnel_add_del_t *mp;
13006 vl_api_gre_tunnel_type_t t_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013007 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013008 u8 src_set = 0;
13009 u8 dst_set = 0;
13010 u32 outer_fib_id = 0;
John Loa43ccae2018-02-13 17:15:23 -050013011 u32 session_id = 0;
13012 u32 instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013013 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013014
Neale Ranns5a8844b2019-04-16 07:15:35 +000013015 t_type = GRE_API_TUNNEL_TYPE_L3;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013016
Damjan Marion7cd468a2016-12-19 23:05:39 +010013017 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13018 {
13019 if (unformat (line_input, "del"))
13020 is_add = 0;
John Loa43ccae2018-02-13 17:15:23 -050013021 else if (unformat (line_input, "instance %d", &instance))
13022 ;
Neale Ranns5a8844b2019-04-16 07:15:35 +000013023 else if (unformat (line_input, "src %U", unformat_vl_api_address, &src))
Ciara Loftus7eac9162016-09-30 15:47:03 +010013024 {
13025 src_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013026 }
Neale Ranns5a8844b2019-04-16 07:15:35 +000013027 else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst))
Ciara Loftus7eac9162016-09-30 15:47:03 +010013028 {
13029 dst_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013030 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010013031 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
13032 ;
13033 else if (unformat (line_input, "teb"))
Neale Ranns5a8844b2019-04-16 07:15:35 +000013034 t_type = GRE_API_TUNNEL_TYPE_TEB;
John Loa43ccae2018-02-13 17:15:23 -050013035 else if (unformat (line_input, "erspan %d", &session_id))
Neale Ranns5a8844b2019-04-16 07:15:35 +000013036 t_type = GRE_API_TUNNEL_TYPE_ERSPAN;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013037 else
13038 {
13039 errmsg ("parse error '%U'", format_unformat_error, line_input);
13040 return -99;
13041 }
13042 }
13043
13044 if (src_set == 0)
13045 {
13046 errmsg ("tunnel src address not specified");
13047 return -99;
13048 }
13049 if (dst_set == 0)
13050 {
13051 errmsg ("tunnel dst address not specified");
13052 return -99;
13053 }
13054
Neale Ranns5a8844b2019-04-16 07:15:35 +000013055 M (GRE_TUNNEL_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013056
Neale Ranns5a8844b2019-04-16 07:15:35 +000013057 clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src));
13058 clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013059
Neale Ranns5a8844b2019-04-16 07:15:35 +000013060 mp->tunnel.instance = htonl (instance);
13061 mp->tunnel.outer_fib_id = htonl (outer_fib_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013062 mp->is_add = is_add;
Neale Ranns5a8844b2019-04-16 07:15:35 +000013063 mp->tunnel.session_id = htons ((u16) session_id);
13064 mp->tunnel.type = htonl (t_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013065
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013066 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013067 W (ret);
13068 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013069}
13070
13071static void vl_api_gre_tunnel_details_t_handler
13072 (vl_api_gre_tunnel_details_t * mp)
13073{
13074 vat_main_t *vam = &vat_main;
13075
John Loa43ccae2018-02-13 17:15:23 -050013076 print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d",
Neale Ranns5a8844b2019-04-16 07:15:35 +000013077 ntohl (mp->tunnel.sw_if_index),
13078 ntohl (mp->tunnel.instance),
13079 format_vl_api_address, &mp->tunnel.src,
13080 format_vl_api_address, &mp->tunnel.dst,
13081 mp->tunnel.type, ntohl (mp->tunnel.outer_fib_id),
13082 ntohl (mp->tunnel.session_id));
13083}
13084
Damjan Marion7cd468a2016-12-19 23:05:39 +010013085static void vl_api_gre_tunnel_details_t_handler_json
13086 (vl_api_gre_tunnel_details_t * mp)
13087{
13088 vat_main_t *vam = &vat_main;
13089 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013090
13091 if (VAT_JSON_ARRAY != vam->json_tree.type)
13092 {
13093 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13094 vat_json_init_array (&vam->json_tree);
13095 }
13096 node = vat_json_array_add (&vam->json_tree);
13097
13098 vat_json_init_object (node);
Neale Ranns5a8844b2019-04-16 07:15:35 +000013099 vat_json_object_add_uint (node, "sw_if_index",
13100 ntohl (mp->tunnel.sw_if_index));
13101 vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance));
13102
13103 vat_json_object_add_address (node, "src", &mp->tunnel.src);
13104 vat_json_object_add_address (node, "dst", &mp->tunnel.dst);
13105 vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type);
13106 vat_json_object_add_uint (node, "outer_fib_id",
13107 ntohl (mp->tunnel.outer_fib_id));
13108 vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013109}
13110
13111static int
13112api_gre_tunnel_dump (vat_main_t * vam)
13113{
13114 unformat_input_t *i = vam->input;
13115 vl_api_gre_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013116 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013117 u32 sw_if_index;
13118 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013119 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013120
13121 /* Parse args required to build the message */
13122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13123 {
13124 if (unformat (i, "sw_if_index %d", &sw_if_index))
13125 sw_if_index_set = 1;
13126 else
13127 break;
13128 }
13129
13130 if (sw_if_index_set == 0)
13131 {
13132 sw_if_index = ~0;
13133 }
13134
13135 if (!vam->json_output)
13136 {
John Loa43ccae2018-02-13 17:15:23 -050013137 print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s",
13138 "sw_if_index", "instance", "src_address", "dst_address",
13139 "tunnel_type", "outer_fib_id", "session_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013140 }
13141
13142 /* Get list of gre-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013143 M (GRE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013144
13145 mp->sw_if_index = htonl (sw_if_index);
13146
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013147 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013148
13149 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013150 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013151 S (mp_ping);
13152
Jon Loeliger56c7b012017-02-01 12:31:41 -060013153 W (ret);
13154 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013155}
13156
13157static int
13158api_l2_fib_clear_table (vat_main_t * vam)
13159{
13160// unformat_input_t * i = vam->input;
13161 vl_api_l2_fib_clear_table_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013162 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013163
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013164 M (L2_FIB_CLEAR_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013165
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013166 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013167 W (ret);
13168 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013169}
13170
13171static int
13172api_l2_interface_efp_filter (vat_main_t * vam)
13173{
13174 unformat_input_t *i = vam->input;
13175 vl_api_l2_interface_efp_filter_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013176 u32 sw_if_index;
13177 u8 enable = 1;
13178 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013179 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013180
13181 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13182 {
13183 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13184 sw_if_index_set = 1;
13185 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13186 sw_if_index_set = 1;
13187 else if (unformat (i, "enable"))
13188 enable = 1;
13189 else if (unformat (i, "disable"))
13190 enable = 0;
13191 else
13192 {
13193 clib_warning ("parse error '%U'", format_unformat_error, i);
13194 return -99;
13195 }
13196 }
13197
13198 if (sw_if_index_set == 0)
13199 {
13200 errmsg ("missing sw_if_index");
13201 return -99;
13202 }
13203
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013204 M (L2_INTERFACE_EFP_FILTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013205
13206 mp->sw_if_index = ntohl (sw_if_index);
13207 mp->enable_disable = enable;
13208
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013209 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013210 W (ret);
13211 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013212}
13213
13214#define foreach_vtr_op \
13215_("disable", L2_VTR_DISABLED) \
13216_("push-1", L2_VTR_PUSH_1) \
13217_("push-2", L2_VTR_PUSH_2) \
13218_("pop-1", L2_VTR_POP_1) \
13219_("pop-2", L2_VTR_POP_2) \
13220_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
13221_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
13222_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
13223_("translate-2-2", L2_VTR_TRANSLATE_2_2)
13224
13225static int
13226api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
13227{
13228 unformat_input_t *i = vam->input;
13229 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013230 u32 sw_if_index;
13231 u8 sw_if_index_set = 0;
13232 u8 vtr_op_set = 0;
13233 u32 vtr_op = 0;
13234 u32 push_dot1q = 1;
13235 u32 tag1 = ~0;
13236 u32 tag2 = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013237 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013238
13239 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13240 {
13241 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13242 sw_if_index_set = 1;
13243 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13244 sw_if_index_set = 1;
13245 else if (unformat (i, "vtr_op %d", &vtr_op))
13246 vtr_op_set = 1;
13247#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
13248 foreach_vtr_op
13249#undef _
13250 else if (unformat (i, "push_dot1q %d", &push_dot1q))
13251 ;
13252 else if (unformat (i, "tag1 %d", &tag1))
13253 ;
13254 else if (unformat (i, "tag2 %d", &tag2))
13255 ;
13256 else
13257 {
13258 clib_warning ("parse error '%U'", format_unformat_error, i);
13259 return -99;
13260 }
13261 }
13262
13263 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
13264 {
13265 errmsg ("missing vtr operation or sw_if_index");
13266 return -99;
13267 }
13268
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013269 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
13270 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013271 mp->vtr_op = ntohl (vtr_op);
13272 mp->push_dot1q = ntohl (push_dot1q);
13273 mp->tag1 = ntohl (tag1);
13274 mp->tag2 = ntohl (tag2);
13275
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013276 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013277 W (ret);
13278 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013279}
13280
13281static int
13282api_create_vhost_user_if (vat_main_t * vam)
13283{
13284 unformat_input_t *i = vam->input;
13285 vl_api_create_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013286 u8 *file_name;
13287 u8 is_server = 0;
13288 u8 file_name_set = 0;
13289 u32 custom_dev_instance = ~0;
13290 u8 hwaddr[6];
13291 u8 use_custom_mac = 0;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013292 u8 disable_mrg_rxbuf = 0;
13293 u8 disable_indirect_desc = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013294 u8 *tag = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013295 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013296
13297 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040013298 clib_memset (hwaddr, 0, sizeof (hwaddr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013299
13300 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13301 {
13302 if (unformat (i, "socket %s", &file_name))
13303 {
13304 file_name_set = 1;
13305 }
13306 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
13307 ;
13308 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
13309 use_custom_mac = 1;
13310 else if (unformat (i, "server"))
13311 is_server = 1;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013312 else if (unformat (i, "disable_mrg_rxbuf"))
13313 disable_mrg_rxbuf = 1;
13314 else if (unformat (i, "disable_indirect_desc"))
13315 disable_indirect_desc = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013316 else if (unformat (i, "tag %s", &tag))
13317 ;
13318 else
13319 break;
13320 }
13321
13322 if (file_name_set == 0)
13323 {
13324 errmsg ("missing socket file name");
13325 return -99;
13326 }
13327
13328 if (vec_len (file_name) > 255)
13329 {
13330 errmsg ("socket file name too long");
13331 return -99;
13332 }
13333 vec_add1 (file_name, 0);
13334
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013335 M (CREATE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013336
13337 mp->is_server = is_server;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013338 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
13339 mp->disable_indirect_desc = disable_indirect_desc;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013340 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
13341 vec_free (file_name);
13342 if (custom_dev_instance != ~0)
13343 {
13344 mp->renumber = 1;
13345 mp->custom_dev_instance = ntohl (custom_dev_instance);
13346 }
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013347
Damjan Marion7cd468a2016-12-19 23:05:39 +010013348 mp->use_custom_mac = use_custom_mac;
13349 clib_memcpy (mp->mac_address, hwaddr, 6);
13350 if (tag)
13351 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13352 vec_free (tag);
13353
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013354 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013355 W (ret);
13356 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013357}
13358
13359static int
13360api_modify_vhost_user_if (vat_main_t * vam)
13361{
13362 unformat_input_t *i = vam->input;
13363 vl_api_modify_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013364 u8 *file_name;
13365 u8 is_server = 0;
13366 u8 file_name_set = 0;
13367 u32 custom_dev_instance = ~0;
13368 u8 sw_if_index_set = 0;
13369 u32 sw_if_index = (u32) ~ 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013370 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013371
13372 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13373 {
13374 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13375 sw_if_index_set = 1;
13376 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13377 sw_if_index_set = 1;
13378 else if (unformat (i, "socket %s", &file_name))
13379 {
13380 file_name_set = 1;
13381 }
13382 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
13383 ;
13384 else if (unformat (i, "server"))
13385 is_server = 1;
13386 else
13387 break;
13388 }
13389
13390 if (sw_if_index_set == 0)
13391 {
13392 errmsg ("missing sw_if_index or interface name");
13393 return -99;
13394 }
13395
13396 if (file_name_set == 0)
13397 {
13398 errmsg ("missing socket file name");
13399 return -99;
13400 }
13401
13402 if (vec_len (file_name) > 255)
13403 {
13404 errmsg ("socket file name too long");
13405 return -99;
13406 }
13407 vec_add1 (file_name, 0);
13408
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013409 M (MODIFY_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013410
13411 mp->sw_if_index = ntohl (sw_if_index);
13412 mp->is_server = is_server;
13413 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
13414 vec_free (file_name);
13415 if (custom_dev_instance != ~0)
13416 {
13417 mp->renumber = 1;
13418 mp->custom_dev_instance = ntohl (custom_dev_instance);
13419 }
13420
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013421 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013422 W (ret);
13423 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013424}
13425
13426static int
13427api_delete_vhost_user_if (vat_main_t * vam)
13428{
13429 unformat_input_t *i = vam->input;
13430 vl_api_delete_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013431 u32 sw_if_index = ~0;
13432 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013433 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013434
13435 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13436 {
13437 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13438 sw_if_index_set = 1;
13439 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13440 sw_if_index_set = 1;
13441 else
13442 break;
13443 }
13444
13445 if (sw_if_index_set == 0)
13446 {
13447 errmsg ("missing sw_if_index or interface name");
13448 return -99;
13449 }
13450
13451
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013452 M (DELETE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013453
13454 mp->sw_if_index = ntohl (sw_if_index);
13455
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013456 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013457 W (ret);
13458 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013459}
13460
13461static void vl_api_sw_interface_vhost_user_details_t_handler
13462 (vl_api_sw_interface_vhost_user_details_t * mp)
13463{
13464 vat_main_t *vam = &vat_main;
13465
Stevenf3b53642017-05-01 14:03:02 -070013466 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013467 (char *) mp->interface_name,
13468 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
13469 clib_net_to_host_u64 (mp->features), mp->is_server,
Stevenf3b53642017-05-01 14:03:02 -070013470 ntohl (mp->num_regions), (char *) mp->sock_filename);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013471 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
13472}
13473
13474static void vl_api_sw_interface_vhost_user_details_t_handler_json
13475 (vl_api_sw_interface_vhost_user_details_t * mp)
13476{
13477 vat_main_t *vam = &vat_main;
13478 vat_json_node_t *node = NULL;
13479
13480 if (VAT_JSON_ARRAY != vam->json_tree.type)
13481 {
13482 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13483 vat_json_init_array (&vam->json_tree);
13484 }
13485 node = vat_json_array_add (&vam->json_tree);
13486
13487 vat_json_init_object (node);
13488 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13489 vat_json_object_add_string_copy (node, "interface_name",
13490 mp->interface_name);
13491 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
13492 ntohl (mp->virtio_net_hdr_sz));
13493 vat_json_object_add_uint (node, "features",
13494 clib_net_to_host_u64 (mp->features));
13495 vat_json_object_add_uint (node, "is_server", mp->is_server);
13496 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
13497 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
13498 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
13499}
13500
13501static int
13502api_sw_interface_vhost_user_dump (vat_main_t * vam)
13503{
13504 vl_api_sw_interface_vhost_user_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013505 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013506 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013507 print (vam->ofp,
Stevenf3b53642017-05-01 14:03:02 -070013508 "Interface name idx hdr_sz features server regions filename");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013509
13510 /* Get list of vhost-user interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013511 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013512 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013513
13514 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013515 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013516 S (mp_ping);
13517
Jon Loeliger56c7b012017-02-01 12:31:41 -060013518 W (ret);
13519 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013520}
13521
13522static int
13523api_show_version (vat_main_t * vam)
13524{
13525 vl_api_show_version_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013526 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013527
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013528 M (SHOW_VERSION, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013529
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013530 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013531 W (ret);
13532 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013533}
13534
13535
13536static int
13537api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
13538{
13539 unformat_input_t *line_input = vam->input;
13540 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013541 ip4_address_t local4, remote4;
13542 ip6_address_t local6, remote6;
13543 u8 is_add = 1;
13544 u8 ipv4_set = 0, ipv6_set = 0;
13545 u8 local_set = 0;
13546 u8 remote_set = 0;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013547 u8 grp_set = 0;
13548 u32 mcast_sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013549 u32 encap_vrf_id = 0;
13550 u32 decap_vrf_id = 0;
13551 u8 protocol = ~0;
13552 u32 vni;
13553 u8 vni_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013554 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013555
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013556 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040013557 clib_memset (&local4, 0, sizeof local4);
13558 clib_memset (&remote4, 0, sizeof remote4);
13559 clib_memset (&local6, 0, sizeof local6);
13560 clib_memset (&remote6, 0, sizeof remote6);
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013561
Damjan Marion7cd468a2016-12-19 23:05:39 +010013562 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13563 {
13564 if (unformat (line_input, "del"))
13565 is_add = 0;
13566 else if (unformat (line_input, "local %U",
13567 unformat_ip4_address, &local4))
13568 {
13569 local_set = 1;
13570 ipv4_set = 1;
13571 }
13572 else if (unformat (line_input, "remote %U",
13573 unformat_ip4_address, &remote4))
13574 {
13575 remote_set = 1;
13576 ipv4_set = 1;
13577 }
13578 else if (unformat (line_input, "local %U",
13579 unformat_ip6_address, &local6))
13580 {
13581 local_set = 1;
13582 ipv6_set = 1;
13583 }
13584 else if (unformat (line_input, "remote %U",
13585 unformat_ip6_address, &remote6))
13586 {
13587 remote_set = 1;
13588 ipv6_set = 1;
13589 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013590 else if (unformat (line_input, "group %U %U",
13591 unformat_ip4_address, &remote4,
13592 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13593 {
13594 grp_set = remote_set = 1;
13595 ipv4_set = 1;
13596 }
13597 else if (unformat (line_input, "group %U",
13598 unformat_ip4_address, &remote4))
13599 {
13600 grp_set = remote_set = 1;
13601 ipv4_set = 1;
13602 }
13603 else if (unformat (line_input, "group %U %U",
13604 unformat_ip6_address, &remote6,
13605 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13606 {
13607 grp_set = remote_set = 1;
13608 ipv6_set = 1;
13609 }
13610 else if (unformat (line_input, "group %U",
13611 unformat_ip6_address, &remote6))
13612 {
13613 grp_set = remote_set = 1;
13614 ipv6_set = 1;
13615 }
13616 else
13617 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
13618 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013619 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
13620 ;
13621 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
13622 ;
13623 else if (unformat (line_input, "vni %d", &vni))
13624 vni_set = 1;
13625 else if (unformat (line_input, "next-ip4"))
13626 protocol = 1;
13627 else if (unformat (line_input, "next-ip6"))
13628 protocol = 2;
13629 else if (unformat (line_input, "next-ethernet"))
13630 protocol = 3;
13631 else if (unformat (line_input, "next-nsh"))
13632 protocol = 4;
13633 else
13634 {
13635 errmsg ("parse error '%U'", format_unformat_error, line_input);
13636 return -99;
13637 }
13638 }
13639
13640 if (local_set == 0)
13641 {
13642 errmsg ("tunnel local address not specified");
13643 return -99;
13644 }
13645 if (remote_set == 0)
13646 {
13647 errmsg ("tunnel remote address not specified");
13648 return -99;
13649 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013650 if (grp_set && mcast_sw_if_index == ~0)
13651 {
13652 errmsg ("tunnel nonexistent multicast device");
13653 return -99;
13654 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010013655 if (ipv4_set && ipv6_set)
13656 {
13657 errmsg ("both IPv4 and IPv6 addresses specified");
13658 return -99;
13659 }
13660
13661 if (vni_set == 0)
13662 {
13663 errmsg ("vni not specified");
13664 return -99;
13665 }
13666
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013667 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013668
13669
13670 if (ipv6_set)
13671 {
13672 clib_memcpy (&mp->local, &local6, sizeof (local6));
13673 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
13674 }
13675 else
13676 {
13677 clib_memcpy (&mp->local, &local4, sizeof (local4));
13678 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
13679 }
13680
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013681 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013682 mp->encap_vrf_id = ntohl (encap_vrf_id);
13683 mp->decap_vrf_id = ntohl (decap_vrf_id);
13684 mp->protocol = protocol;
13685 mp->vni = ntohl (vni);
13686 mp->is_add = is_add;
13687 mp->is_ipv6 = ipv6_set;
13688
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013689 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013690 W (ret);
13691 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013692}
13693
13694static void vl_api_vxlan_gpe_tunnel_details_t_handler
13695 (vl_api_vxlan_gpe_tunnel_details_t * mp)
13696{
13697 vat_main_t *vam = &vat_main;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013698 ip46_address_t local = to_ip46 (mp->is_ipv6, mp->local);
13699 ip46_address_t remote = to_ip46 (mp->is_ipv6, mp->remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013700
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013701 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013702 ntohl (mp->sw_if_index),
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013703 format_ip46_address, &local, IP46_TYPE_ANY,
13704 format_ip46_address, &remote, IP46_TYPE_ANY,
13705 ntohl (mp->vni), mp->protocol,
13706 ntohl (mp->mcast_sw_if_index),
Damjan Marion7cd468a2016-12-19 23:05:39 +010013707 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
13708}
13709
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013710
Damjan Marion7cd468a2016-12-19 23:05:39 +010013711static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
13712 (vl_api_vxlan_gpe_tunnel_details_t * mp)
13713{
13714 vat_main_t *vam = &vat_main;
13715 vat_json_node_t *node = NULL;
13716 struct in_addr ip4;
13717 struct in6_addr ip6;
13718
13719 if (VAT_JSON_ARRAY != vam->json_tree.type)
13720 {
13721 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13722 vat_json_init_array (&vam->json_tree);
13723 }
13724 node = vat_json_array_add (&vam->json_tree);
13725
13726 vat_json_init_object (node);
13727 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13728 if (mp->is_ipv6)
13729 {
13730 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
13731 vat_json_object_add_ip6 (node, "local", ip6);
13732 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
13733 vat_json_object_add_ip6 (node, "remote", ip6);
13734 }
13735 else
13736 {
13737 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
13738 vat_json_object_add_ip4 (node, "local", ip4);
13739 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
13740 vat_json_object_add_ip4 (node, "remote", ip4);
13741 }
13742 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
13743 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013744 vat_json_object_add_uint (node, "mcast_sw_if_index",
13745 ntohl (mp->mcast_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013746 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
13747 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
13748 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
13749}
13750
13751static int
13752api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
13753{
13754 unformat_input_t *i = vam->input;
13755 vl_api_vxlan_gpe_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013756 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013757 u32 sw_if_index;
13758 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013759 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013760
13761 /* Parse args required to build the message */
13762 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13763 {
13764 if (unformat (i, "sw_if_index %d", &sw_if_index))
13765 sw_if_index_set = 1;
13766 else
13767 break;
13768 }
13769
13770 if (sw_if_index_set == 0)
13771 {
13772 sw_if_index = ~0;
13773 }
13774
13775 if (!vam->json_output)
13776 {
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013777 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013778 "sw_if_index", "local", "remote", "vni",
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013779 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013780 }
13781
13782 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013783 M (VXLAN_GPE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013784
13785 mp->sw_if_index = htonl (sw_if_index);
13786
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013787 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013788
13789 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013790 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013791 S (mp_ping);
13792
Jon Loeliger56c7b012017-02-01 12:31:41 -060013793 W (ret);
13794 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013795}
13796
Ole Troan01384fe2017-05-12 11:55:35 +020013797static void vl_api_l2_fib_table_details_t_handler
13798 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013799{
13800 vat_main_t *vam = &vat_main;
13801
13802 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
13803 " %d %d %d",
Mohsin Kazmi57938f62017-10-27 21:28:07 +020013804 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
Damjan Marion7cd468a2016-12-19 23:05:39 +010013805 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
13806 mp->bvi_mac);
13807}
13808
Ole Troan01384fe2017-05-12 11:55:35 +020013809static void vl_api_l2_fib_table_details_t_handler_json
13810 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013811{
13812 vat_main_t *vam = &vat_main;
13813 vat_json_node_t *node = NULL;
13814
13815 if (VAT_JSON_ARRAY != vam->json_tree.type)
13816 {
13817 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13818 vat_json_init_array (&vam->json_tree);
13819 }
13820 node = vat_json_array_add (&vam->json_tree);
13821
13822 vat_json_init_object (node);
13823 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
Mohsin Kazmi57938f62017-10-27 21:28:07 +020013824 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013825 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13826 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
13827 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
13828 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
13829}
13830
13831static int
13832api_l2_fib_table_dump (vat_main_t * vam)
13833{
13834 unformat_input_t *i = vam->input;
13835 vl_api_l2_fib_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013836 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013837 u32 bd_id;
13838 u8 bd_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013839 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013840
13841 /* Parse args required to build the message */
13842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13843 {
13844 if (unformat (i, "bd_id %d", &bd_id))
13845 bd_id_set = 1;
13846 else
13847 break;
13848 }
13849
13850 if (bd_id_set == 0)
13851 {
13852 errmsg ("missing bridge domain");
13853 return -99;
13854 }
13855
13856 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
13857
13858 /* Get list of l2 fib entries */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013859 M (L2_FIB_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013860
13861 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013862 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013863
13864 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013865 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013866 S (mp_ping);
13867
Jon Loeliger56c7b012017-02-01 12:31:41 -060013868 W (ret);
13869 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013870}
13871
13872
13873static int
13874api_interface_name_renumber (vat_main_t * vam)
13875{
13876 unformat_input_t *line_input = vam->input;
13877 vl_api_interface_name_renumber_t *mp;
13878 u32 sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013879 u32 new_show_dev_instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013880 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013881
13882 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13883 {
13884 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
13885 &sw_if_index))
13886 ;
13887 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
13888 ;
13889 else if (unformat (line_input, "new_show_dev_instance %d",
13890 &new_show_dev_instance))
13891 ;
13892 else
13893 break;
13894 }
13895
13896 if (sw_if_index == ~0)
13897 {
13898 errmsg ("missing interface name or sw_if_index");
13899 return -99;
13900 }
13901
13902 if (new_show_dev_instance == ~0)
13903 {
13904 errmsg ("missing new_show_dev_instance");
13905 return -99;
13906 }
13907
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013908 M (INTERFACE_NAME_RENUMBER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013909
13910 mp->sw_if_index = ntohl (sw_if_index);
13911 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
13912
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013913 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013914 W (ret);
13915 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013916}
13917
13918static int
John Loc7b43042018-04-13 16:46:22 -040013919api_ip_probe_neighbor (vat_main_t * vam)
13920{
13921 unformat_input_t *i = vam->input;
13922 vl_api_ip_probe_neighbor_t *mp;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013923 vl_api_address_t dst_adr = { };
John Loc7b43042018-04-13 16:46:22 -040013924 u8 int_set = 0;
13925 u8 adr_set = 0;
John Loc7b43042018-04-13 16:46:22 -040013926 u32 sw_if_index;
13927 int ret;
13928
13929 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13930 {
13931 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13932 int_set = 1;
13933 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13934 int_set = 1;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013935 else if (unformat (i, "address %U", unformat_vl_api_address, &dst_adr))
John Loc7b43042018-04-13 16:46:22 -040013936 adr_set = 1;
John Loc7b43042018-04-13 16:46:22 -040013937 else
13938 break;
13939 }
13940
13941 if (int_set == 0)
13942 {
13943 errmsg ("missing interface");
13944 return -99;
13945 }
13946
13947 if (adr_set == 0)
13948 {
13949 errmsg ("missing addresses");
13950 return -99;
13951 }
13952
13953 M (IP_PROBE_NEIGHBOR, mp);
13954
13955 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -070013956 clib_memcpy (&mp->dst, &dst_adr, sizeof (dst_adr));
John Loc7b43042018-04-13 16:46:22 -040013957
13958 S (mp);
13959 W (ret);
13960 return ret;
13961}
13962
13963static int
John Lo7f358b32018-04-28 01:19:24 -040013964api_ip_scan_neighbor_enable_disable (vat_main_t * vam)
13965{
13966 unformat_input_t *i = vam->input;
13967 vl_api_ip_scan_neighbor_enable_disable_t *mp;
13968 u8 mode = IP_SCAN_V46_NEIGHBORS;
13969 u32 interval = 0, time = 0, update = 0, delay = 0, stale = 0;
13970 int ret;
13971
13972 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13973 {
13974 if (unformat (i, "ip4"))
13975 mode = IP_SCAN_V4_NEIGHBORS;
13976 else if (unformat (i, "ip6"))
13977 mode = IP_SCAN_V6_NEIGHBORS;
13978 if (unformat (i, "both"))
13979 mode = IP_SCAN_V46_NEIGHBORS;
13980 else if (unformat (i, "disable"))
13981 mode = IP_SCAN_DISABLED;
13982 else if (unformat (i, "interval %d", &interval))
13983 ;
13984 else if (unformat (i, "max-time %d", &time))
13985 ;
13986 else if (unformat (i, "max-update %d", &update))
13987 ;
13988 else if (unformat (i, "delay %d", &delay))
13989 ;
13990 else if (unformat (i, "stale %d", &stale))
13991 ;
13992 else
13993 break;
13994 }
13995
13996 if (interval > 255)
13997 {
13998 errmsg ("interval cannot exceed 255 minutes.");
13999 return -99;
14000 }
14001 if (time > 255)
14002 {
14003 errmsg ("max-time cannot exceed 255 usec.");
14004 return -99;
14005 }
14006 if (update > 255)
14007 {
14008 errmsg ("max-update cannot exceed 255.");
14009 return -99;
14010 }
14011 if (delay > 255)
14012 {
14013 errmsg ("delay cannot exceed 255 msec.");
14014 return -99;
14015 }
14016 if (stale > 255)
14017 {
14018 errmsg ("stale cannot exceed 255 minutes.");
14019 return -99;
14020 }
14021
14022 M (IP_SCAN_NEIGHBOR_ENABLE_DISABLE, mp);
14023 mp->mode = mode;
14024 mp->scan_interval = interval;
14025 mp->max_proc_time = time;
14026 mp->max_update = update;
14027 mp->scan_int_delay = delay;
14028 mp->stale_threshold = stale;
14029
14030 S (mp);
14031 W (ret);
14032 return ret;
14033}
14034
14035static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014036api_want_ip4_arp_events (vat_main_t * vam)
14037{
14038 unformat_input_t *line_input = vam->input;
14039 vl_api_want_ip4_arp_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014040 ip4_address_t address;
14041 int address_set = 0;
14042 u32 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014043 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014044
14045 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14046 {
14047 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
14048 address_set = 1;
14049 else if (unformat (line_input, "del"))
14050 enable_disable = 0;
14051 else
14052 break;
14053 }
14054
14055 if (address_set == 0)
14056 {
14057 errmsg ("missing addresses");
14058 return -99;
14059 }
14060
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014061 M (WANT_IP4_ARP_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014062 mp->enable_disable = enable_disable;
John Lo20e1f2a2017-03-29 13:35:43 -040014063 mp->pid = htonl (getpid ());
Neale Ranns37029302018-08-10 05:30:06 -070014064 clib_memcpy (mp->ip, &address, sizeof (address));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014065
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014066 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014067 W (ret);
14068 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014069}
14070
14071static int
14072api_want_ip6_nd_events (vat_main_t * vam)
14073{
14074 unformat_input_t *line_input = vam->input;
14075 vl_api_want_ip6_nd_events_t *mp;
Neale Ranns37029302018-08-10 05:30:06 -070014076 vl_api_ip6_address_t address;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014077 int address_set = 0;
14078 u32 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014079 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014080
14081 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14082 {
Neale Ranns37029302018-08-10 05:30:06 -070014083 if (unformat
14084 (line_input, "address %U", unformat_vl_api_ip6_address, &address))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014085 address_set = 1;
14086 else if (unformat (line_input, "del"))
14087 enable_disable = 0;
14088 else
14089 break;
14090 }
14091
14092 if (address_set == 0)
14093 {
14094 errmsg ("missing addresses");
14095 return -99;
14096 }
14097
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014098 M (WANT_IP6_ND_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014099 mp->enable_disable = enable_disable;
John Lo20e1f2a2017-03-29 13:35:43 -040014100 mp->pid = htonl (getpid ());
Neale Ranns37029302018-08-10 05:30:06 -070014101 clib_memcpy (&mp->ip, &address, sizeof (address));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014102
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014103 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014104 W (ret);
14105 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014106}
14107
14108static int
John Lo8d00fff2017-08-03 00:35:36 -040014109api_want_l2_macs_events (vat_main_t * vam)
14110{
14111 unformat_input_t *line_input = vam->input;
14112 vl_api_want_l2_macs_events_t *mp;
14113 u8 enable_disable = 1;
14114 u32 scan_delay = 0;
14115 u32 max_macs_in_event = 0;
14116 u32 learn_limit = 0;
14117 int ret;
14118
14119 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14120 {
14121 if (unformat (line_input, "learn-limit %d", &learn_limit))
14122 ;
14123 else if (unformat (line_input, "scan-delay %d", &scan_delay))
14124 ;
14125 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
14126 ;
14127 else if (unformat (line_input, "disable"))
14128 enable_disable = 0;
14129 else
14130 break;
14131 }
14132
14133 M (WANT_L2_MACS_EVENTS, mp);
14134 mp->enable_disable = enable_disable;
14135 mp->pid = htonl (getpid ());
14136 mp->learn_limit = htonl (learn_limit);
14137 mp->scan_delay = (u8) scan_delay;
14138 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
14139 S (mp);
14140 W (ret);
14141 return ret;
14142}
14143
14144static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014145api_input_acl_set_interface (vat_main_t * vam)
14146{
14147 unformat_input_t *i = vam->input;
14148 vl_api_input_acl_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014149 u32 sw_if_index;
14150 int sw_if_index_set;
14151 u32 ip4_table_index = ~0;
14152 u32 ip6_table_index = ~0;
14153 u32 l2_table_index = ~0;
14154 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014155 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014156
14157 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14158 {
14159 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14160 sw_if_index_set = 1;
14161 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14162 sw_if_index_set = 1;
14163 else if (unformat (i, "del"))
14164 is_add = 0;
14165 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14166 ;
14167 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14168 ;
14169 else if (unformat (i, "l2-table %d", &l2_table_index))
14170 ;
14171 else
14172 {
14173 clib_warning ("parse error '%U'", format_unformat_error, i);
14174 return -99;
14175 }
14176 }
14177
14178 if (sw_if_index_set == 0)
14179 {
14180 errmsg ("missing interface name or sw_if_index");
14181 return -99;
14182 }
14183
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014184 M (INPUT_ACL_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014185
14186 mp->sw_if_index = ntohl (sw_if_index);
14187 mp->ip4_table_index = ntohl (ip4_table_index);
14188 mp->ip6_table_index = ntohl (ip6_table_index);
14189 mp->l2_table_index = ntohl (l2_table_index);
14190 mp->is_add = is_add;
14191
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014192 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014193 W (ret);
14194 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014195}
14196
14197static int
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010014198api_output_acl_set_interface (vat_main_t * vam)
14199{
14200 unformat_input_t *i = vam->input;
14201 vl_api_output_acl_set_interface_t *mp;
14202 u32 sw_if_index;
14203 int sw_if_index_set;
14204 u32 ip4_table_index = ~0;
14205 u32 ip6_table_index = ~0;
14206 u32 l2_table_index = ~0;
14207 u8 is_add = 1;
14208 int ret;
14209
14210 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14211 {
14212 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14213 sw_if_index_set = 1;
14214 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14215 sw_if_index_set = 1;
14216 else if (unformat (i, "del"))
14217 is_add = 0;
14218 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14219 ;
14220 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14221 ;
14222 else if (unformat (i, "l2-table %d", &l2_table_index))
14223 ;
14224 else
14225 {
14226 clib_warning ("parse error '%U'", format_unformat_error, i);
14227 return -99;
14228 }
14229 }
14230
14231 if (sw_if_index_set == 0)
14232 {
14233 errmsg ("missing interface name or sw_if_index");
14234 return -99;
14235 }
14236
14237 M (OUTPUT_ACL_SET_INTERFACE, mp);
14238
14239 mp->sw_if_index = ntohl (sw_if_index);
14240 mp->ip4_table_index = ntohl (ip4_table_index);
14241 mp->ip6_table_index = ntohl (ip6_table_index);
14242 mp->l2_table_index = ntohl (l2_table_index);
14243 mp->is_add = is_add;
14244
14245 S (mp);
14246 W (ret);
14247 return ret;
14248}
14249
14250static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014251api_ip_address_dump (vat_main_t * vam)
14252{
14253 unformat_input_t *i = vam->input;
14254 vl_api_ip_address_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014255 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014256 u32 sw_if_index = ~0;
14257 u8 sw_if_index_set = 0;
14258 u8 ipv4_set = 0;
14259 u8 ipv6_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014260 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014261
14262 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14263 {
14264 if (unformat (i, "sw_if_index %d", &sw_if_index))
14265 sw_if_index_set = 1;
14266 else
14267 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14268 sw_if_index_set = 1;
14269 else if (unformat (i, "ipv4"))
14270 ipv4_set = 1;
14271 else if (unformat (i, "ipv6"))
14272 ipv6_set = 1;
14273 else
14274 break;
14275 }
14276
14277 if (ipv4_set && ipv6_set)
14278 {
14279 errmsg ("ipv4 and ipv6 flags cannot be both set");
14280 return -99;
14281 }
14282
14283 if ((!ipv4_set) && (!ipv6_set))
14284 {
14285 errmsg ("no ipv4 nor ipv6 flag set");
14286 return -99;
14287 }
14288
14289 if (sw_if_index_set == 0)
14290 {
14291 errmsg ("missing interface name or sw_if_index");
14292 return -99;
14293 }
14294
14295 vam->current_sw_if_index = sw_if_index;
14296 vam->is_ipv6 = ipv6_set;
14297
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014298 M (IP_ADDRESS_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014299 mp->sw_if_index = ntohl (sw_if_index);
14300 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014301 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014302
14303 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014304 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014305 S (mp_ping);
14306
Jon Loeliger56c7b012017-02-01 12:31:41 -060014307 W (ret);
14308 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014309}
14310
14311static int
14312api_ip_dump (vat_main_t * vam)
14313{
14314 vl_api_ip_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014315 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014316 unformat_input_t *in = vam->input;
14317 int ipv4_set = 0;
14318 int ipv6_set = 0;
14319 int is_ipv6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014320 int i;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014321 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014322
14323 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
14324 {
14325 if (unformat (in, "ipv4"))
14326 ipv4_set = 1;
14327 else if (unformat (in, "ipv6"))
14328 ipv6_set = 1;
14329 else
14330 break;
14331 }
14332
14333 if (ipv4_set && ipv6_set)
14334 {
14335 errmsg ("ipv4 and ipv6 flags cannot be both set");
14336 return -99;
14337 }
14338
14339 if ((!ipv4_set) && (!ipv6_set))
14340 {
14341 errmsg ("no ipv4 nor ipv6 flag set");
14342 return -99;
14343 }
14344
14345 is_ipv6 = ipv6_set;
14346 vam->is_ipv6 = is_ipv6;
14347
14348 /* free old data */
14349 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
14350 {
14351 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
14352 }
14353 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
14354
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014355 M (IP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014356 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014357 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014358
14359 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014360 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014361 S (mp_ping);
14362
Jon Loeliger56c7b012017-02-01 12:31:41 -060014363 W (ret);
14364 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014365}
14366
14367static int
14368api_ipsec_spd_add_del (vat_main_t * vam)
14369{
14370 unformat_input_t *i = vam->input;
14371 vl_api_ipsec_spd_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014372 u32 spd_id = ~0;
14373 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014374 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014375
14376 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14377 {
14378 if (unformat (i, "spd_id %d", &spd_id))
14379 ;
14380 else if (unformat (i, "del"))
14381 is_add = 0;
14382 else
14383 {
14384 clib_warning ("parse error '%U'", format_unformat_error, i);
14385 return -99;
14386 }
14387 }
14388 if (spd_id == ~0)
14389 {
14390 errmsg ("spd_id must be set");
14391 return -99;
14392 }
14393
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014394 M (IPSEC_SPD_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014395
14396 mp->spd_id = ntohl (spd_id);
14397 mp->is_add = is_add;
14398
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014399 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014400 W (ret);
14401 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014402}
14403
14404static int
14405api_ipsec_interface_add_del_spd (vat_main_t * vam)
14406{
14407 unformat_input_t *i = vam->input;
14408 vl_api_ipsec_interface_add_del_spd_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014409 u32 sw_if_index;
14410 u8 sw_if_index_set = 0;
14411 u32 spd_id = (u32) ~ 0;
14412 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014413 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014414
14415 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14416 {
14417 if (unformat (i, "del"))
14418 is_add = 0;
14419 else if (unformat (i, "spd_id %d", &spd_id))
14420 ;
14421 else
14422 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14423 sw_if_index_set = 1;
14424 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14425 sw_if_index_set = 1;
14426 else
14427 {
14428 clib_warning ("parse error '%U'", format_unformat_error, i);
14429 return -99;
14430 }
14431
14432 }
14433
14434 if (spd_id == (u32) ~ 0)
14435 {
14436 errmsg ("spd_id must be set");
14437 return -99;
14438 }
14439
14440 if (sw_if_index_set == 0)
14441 {
14442 errmsg ("missing interface name or sw_if_index");
14443 return -99;
14444 }
14445
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014446 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014447
14448 mp->spd_id = ntohl (spd_id);
14449 mp->sw_if_index = ntohl (sw_if_index);
14450 mp->is_add = is_add;
14451
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014452 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014453 W (ret);
14454 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014455}
14456
14457static int
Neale Ranns17dcec02019-01-09 21:22:20 -080014458api_ipsec_spd_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014459{
14460 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080014461 vl_api_ipsec_spd_entry_add_del_t *mp;
Benoît Ganne49ee6842019-04-30 11:50:46 +020014462 u8 is_add = 1, is_outbound = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014463 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
14464 i32 priority = 0;
14465 u32 rport_start = 0, rport_stop = (u32) ~ 0;
14466 u32 lport_start = 0, lport_stop = (u32) ~ 0;
Neale Ranns17dcec02019-01-09 21:22:20 -080014467 vl_api_address_t laddr_start = { }, laddr_stop =
14468 {
14469 }, raddr_start =
14470 {
14471 }, raddr_stop =
14472 {
14473 };
Jon Loeliger56c7b012017-02-01 12:31:41 -060014474 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014475
Damjan Marion7cd468a2016-12-19 23:05:39 +010014476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14477 {
14478 if (unformat (i, "del"))
14479 is_add = 0;
14480 if (unformat (i, "outbound"))
14481 is_outbound = 1;
14482 if (unformat (i, "inbound"))
14483 is_outbound = 0;
14484 else if (unformat (i, "spd_id %d", &spd_id))
14485 ;
14486 else if (unformat (i, "sa_id %d", &sa_id))
14487 ;
14488 else if (unformat (i, "priority %d", &priority))
14489 ;
14490 else if (unformat (i, "protocol %d", &protocol))
14491 ;
14492 else if (unformat (i, "lport_start %d", &lport_start))
14493 ;
14494 else if (unformat (i, "lport_stop %d", &lport_stop))
14495 ;
14496 else if (unformat (i, "rport_start %d", &rport_start))
14497 ;
14498 else if (unformat (i, "rport_stop %d", &rport_stop))
14499 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014500 else if (unformat (i, "laddr_start %U",
14501 unformat_vl_api_address, &laddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014502 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014503 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
14504 &laddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014505 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014506 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
14507 &raddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014508 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014509 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
14510 &raddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014511 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014512 else
14513 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
14514 {
14515 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
14516 {
14517 clib_warning ("unsupported action: 'resolve'");
14518 return -99;
14519 }
14520 }
14521 else
14522 {
14523 clib_warning ("parse error '%U'", format_unformat_error, i);
14524 return -99;
14525 }
14526
14527 }
14528
Neale Ranns17dcec02019-01-09 21:22:20 -080014529 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014530
Damjan Marion7cd468a2016-12-19 23:05:39 +010014531 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080014532
14533 mp->entry.spd_id = ntohl (spd_id);
14534 mp->entry.priority = ntohl (priority);
14535 mp->entry.is_outbound = is_outbound;
14536
14537 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
14538 sizeof (vl_api_address_t));
14539 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
14540 sizeof (vl_api_address_t));
14541 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
14542 sizeof (vl_api_address_t));
14543 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
14544 sizeof (vl_api_address_t));
14545
14546 mp->entry.protocol = (u8) protocol;
14547 mp->entry.local_port_start = ntohs ((u16) lport_start);
14548 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
14549 mp->entry.remote_port_start = ntohs ((u16) rport_start);
14550 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
14551 mp->entry.policy = (u8) policy;
14552 mp->entry.sa_id = ntohl (sa_id);
Neale Ranns17dcec02019-01-09 21:22:20 -080014553
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014554 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014555 W (ret);
14556 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014557}
14558
14559static int
Neale Ranns17dcec02019-01-09 21:22:20 -080014560api_ipsec_sad_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014561{
14562 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080014563 vl_api_ipsec_sad_entry_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014564 u32 sad_id = 0, spi = 0;
14565 u8 *ck = 0, *ik = 0;
14566 u8 is_add = 1;
14567
Neale Ranns17dcec02019-01-09 21:22:20 -080014568 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
14569 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
14570 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
14571 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
14572 vl_api_address_t tun_src, tun_dst;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014573 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014574
14575 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14576 {
14577 if (unformat (i, "del"))
14578 is_add = 0;
14579 else if (unformat (i, "sad_id %d", &sad_id))
14580 ;
14581 else if (unformat (i, "spi %d", &spi))
14582 ;
14583 else if (unformat (i, "esp"))
Neale Ranns17dcec02019-01-09 21:22:20 -080014584 protocol = IPSEC_API_PROTO_ESP;
14585 else
14586 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014587 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014588 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
14589 if (ADDRESS_IP6 == tun_src.af)
14590 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014591 }
14592 else
Neale Ranns17dcec02019-01-09 21:22:20 -080014593 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014594 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014595 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
14596 if (ADDRESS_IP6 == tun_src.af)
14597 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014598 }
Neale Ranns17dcec02019-01-09 21:22:20 -080014599 else
14600 if (unformat (i, "crypto_alg %U",
14601 unformat_ipsec_api_crypto_alg, &crypto_alg))
14602 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014603 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
14604 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014605 else if (unformat (i, "integ_alg %U",
14606 unformat_ipsec_api_integ_alg, &integ_alg))
14607 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014608 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
14609 ;
14610 else
14611 {
14612 clib_warning ("parse error '%U'", format_unformat_error, i);
14613 return -99;
14614 }
14615
14616 }
14617
Neale Ranns17dcec02019-01-09 21:22:20 -080014618 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014619
Damjan Marion7cd468a2016-12-19 23:05:39 +010014620 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080014621 mp->entry.sad_id = ntohl (sad_id);
14622 mp->entry.protocol = protocol;
14623 mp->entry.spi = ntohl (spi);
14624 mp->entry.flags = flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014625
Neale Ranns17dcec02019-01-09 21:22:20 -080014626 mp->entry.crypto_algorithm = crypto_alg;
14627 mp->entry.integrity_algorithm = integ_alg;
14628 mp->entry.crypto_key.length = vec_len (ck);
14629 mp->entry.integrity_key.length = vec_len (ik);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014630
Neale Ranns17dcec02019-01-09 21:22:20 -080014631 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
14632 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
14633
14634 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
14635 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014636
14637 if (ck)
Neale Ranns17dcec02019-01-09 21:22:20 -080014638 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014639 if (ik)
Neale Ranns17dcec02019-01-09 21:22:20 -080014640 clib_memcpy (mp->entry.integrity_key.data, ik,
14641 mp->entry.integrity_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014642
Neale Ranns17dcec02019-01-09 21:22:20 -080014643 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014644 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014645 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
14646 sizeof (mp->entry.tunnel_src));
14647 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
14648 sizeof (mp->entry.tunnel_dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014649 }
14650
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014651 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014652 W (ret);
14653 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014654}
14655
14656static int
Matthew Smithb0972cb2017-05-02 16:20:41 -050014657api_ipsec_tunnel_if_add_del (vat_main_t * vam)
14658{
14659 unformat_input_t *i = vam->input;
14660 vl_api_ipsec_tunnel_if_add_del_t *mp;
14661 u32 local_spi = 0, remote_spi = 0;
14662 u32 crypto_alg = 0, integ_alg = 0;
14663 u8 *lck = NULL, *rck = NULL;
14664 u8 *lik = NULL, *rik = NULL;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040014665 vl_api_address_t local_ip = { 0 };
14666 vl_api_address_t remote_ip = { 0 };
Neale Ranns2b5ba952019-04-02 10:15:40 +000014667 f64 before = 0;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014668 u8 is_add = 1;
14669 u8 esn = 0;
14670 u8 anti_replay = 0;
Matthew Smith8e1039a2018-04-12 07:32:56 -050014671 u8 renumber = 0;
14672 u32 instance = ~0;
Neale Ranns2b5ba952019-04-02 10:15:40 +000014673 u32 count = 1, jj;
Benoît Ganne49ee6842019-04-30 11:50:46 +020014674 int ret = -1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014675
14676 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14677 {
14678 if (unformat (i, "del"))
14679 is_add = 0;
14680 else if (unformat (i, "esn"))
14681 esn = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000014682 else if (unformat (i, "anti-replay"))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014683 anti_replay = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000014684 else if (unformat (i, "count %d", &count))
14685 ;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014686 else if (unformat (i, "local_spi %d", &local_spi))
14687 ;
14688 else if (unformat (i, "remote_spi %d", &remote_spi))
14689 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040014690 else
14691 if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014692 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040014693 else
14694 if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014695 ;
14696 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
14697 ;
14698 else
14699 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
14700 ;
14701 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
14702 ;
14703 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
14704 ;
14705 else
14706 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080014707 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014708 {
Dave Baracha8d47642018-07-13 11:22:23 -040014709 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014710 {
14711 errmsg ("unsupported crypto-alg: '%U'\n",
14712 format_ipsec_crypto_alg, crypto_alg);
14713 return -99;
14714 }
14715 }
14716 else
14717 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080014718 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014719 {
Dave Baracha8d47642018-07-13 11:22:23 -040014720 if (integ_alg >= IPSEC_INTEG_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014721 {
14722 errmsg ("unsupported integ-alg: '%U'\n",
14723 format_ipsec_integ_alg, integ_alg);
14724 return -99;
14725 }
14726 }
Matthew Smith8e1039a2018-04-12 07:32:56 -050014727 else if (unformat (i, "instance %u", &instance))
14728 renumber = 1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014729 else
14730 {
14731 errmsg ("parse error '%U'\n", format_unformat_error, i);
14732 return -99;
14733 }
14734 }
14735
Neale Ranns2b5ba952019-04-02 10:15:40 +000014736 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014737 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000014738 /* Turn on async mode */
14739 vam->async_mode = 1;
14740 vam->async_errors = 0;
14741 before = vat_time_now (vam);
Matthew Smithb0972cb2017-05-02 16:20:41 -050014742 }
14743
Neale Ranns2b5ba952019-04-02 10:15:40 +000014744 for (jj = 0; jj < count; jj++)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014745 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000014746 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
14747
14748 mp->is_add = is_add;
14749 mp->esn = esn;
14750 mp->anti_replay = anti_replay;
14751
14752 if (jj > 0)
Neale Ranns097fa662018-05-01 05:17:55 -070014753 increment_address (&remote_ip);
Neale Ranns2b5ba952019-04-02 10:15:40 +000014754
14755 clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
14756 clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
14757
14758 mp->local_spi = htonl (local_spi + jj);
14759 mp->remote_spi = htonl (remote_spi + jj);
14760 mp->crypto_alg = (u8) crypto_alg;
14761
14762 mp->local_crypto_key_len = 0;
14763 if (lck)
14764 {
14765 mp->local_crypto_key_len = vec_len (lck);
14766 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
14767 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
14768 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
14769 }
14770
14771 mp->remote_crypto_key_len = 0;
14772 if (rck)
14773 {
14774 mp->remote_crypto_key_len = vec_len (rck);
14775 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
14776 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
14777 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
14778 }
14779
14780 mp->integ_alg = (u8) integ_alg;
14781
14782 mp->local_integ_key_len = 0;
14783 if (lik)
14784 {
14785 mp->local_integ_key_len = vec_len (lik);
14786 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
14787 mp->local_integ_key_len = sizeof (mp->local_integ_key);
14788 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
14789 }
14790
14791 mp->remote_integ_key_len = 0;
14792 if (rik)
14793 {
14794 mp->remote_integ_key_len = vec_len (rik);
14795 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
14796 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
14797 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
14798 }
14799
14800 if (renumber)
14801 {
14802 mp->renumber = renumber;
14803 mp->show_instance = ntohl (instance);
14804 }
14805 S (mp);
Matthew Smithb0972cb2017-05-02 16:20:41 -050014806 }
14807
Neale Ranns2b5ba952019-04-02 10:15:40 +000014808 /* When testing multiple add/del ops, use a control-ping to sync */
14809 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014810 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000014811 vl_api_control_ping_t *mp_ping;
14812 f64 after;
14813 f64 timeout;
14814
14815 /* Shut off async mode */
14816 vam->async_mode = 0;
14817
14818 MPING (CONTROL_PING, mp_ping);
14819 S (mp_ping);
14820
14821 timeout = vat_time_now (vam) + 1.0;
14822 while (vat_time_now (vam) < timeout)
14823 if (vam->result_ready == 1)
14824 goto out;
14825 vam->retval = -99;
14826
14827 out:
14828 if (vam->retval == -99)
14829 errmsg ("timeout");
14830
14831 if (vam->async_errors > 0)
14832 {
14833 errmsg ("%d asynchronous errors", vam->async_errors);
14834 vam->retval = -98;
14835 }
14836 vam->async_errors = 0;
14837 after = vat_time_now (vam);
14838
14839 /* slim chance, but we might have eaten SIGTERM on the first iteration */
14840 if (jj > 0)
14841 count = jj;
14842
14843 print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec",
14844 count, after - before, count / (after - before));
14845 }
14846 else
14847 {
14848 /* Wait for a reply... */
14849 W (ret);
14850 return ret;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014851 }
14852
Matthew Smithb0972cb2017-05-02 16:20:41 -050014853 return ret;
14854}
14855
Matthew Smith28029532017-09-26 13:33:44 -050014856static void
14857vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
14858{
14859 vat_main_t *vam = &vat_main;
14860
14861 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
Neale Ranns8d7c5022019-02-06 01:41:05 -080014862 "crypto_key %U integ_alg %u integ_key %U flags %x "
Matthew Smith28029532017-09-26 13:33:44 -050014863 "tunnel_src_addr %U tunnel_dst_addr %U "
14864 "salt %u seq_outbound %lu last_seq_inbound %lu "
Neale Rannseba31ec2019-02-17 18:04:27 +000014865 "replay_window %lu\n",
Neale Ranns8d7c5022019-02-06 01:41:05 -080014866 ntohl (mp->entry.sad_id),
14867 ntohl (mp->sw_if_index),
14868 ntohl (mp->entry.spi),
14869 ntohl (mp->entry.protocol),
14870 ntohl (mp->entry.crypto_algorithm),
14871 format_hex_bytes, mp->entry.crypto_key.data,
14872 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
14873 format_hex_bytes, mp->entry.integrity_key.data,
14874 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
14875 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
14876 &mp->entry.tunnel_dst, ntohl (mp->salt),
Matthew Smith28029532017-09-26 13:33:44 -050014877 clib_net_to_host_u64 (mp->seq_outbound),
14878 clib_net_to_host_u64 (mp->last_seq_inbound),
Neale Rannseba31ec2019-02-17 18:04:27 +000014879 clib_net_to_host_u64 (mp->replay_window));
Matthew Smith28029532017-09-26 13:33:44 -050014880}
14881
14882#define vl_api_ipsec_sa_details_t_endian vl_noop_handler
14883#define vl_api_ipsec_sa_details_t_print vl_noop_handler
14884
14885static void vl_api_ipsec_sa_details_t_handler_json
14886 (vl_api_ipsec_sa_details_t * mp)
14887{
14888 vat_main_t *vam = &vat_main;
14889 vat_json_node_t *node = NULL;
Neale Ranns8d7c5022019-02-06 01:41:05 -080014890 vl_api_ipsec_sad_flags_t flags;
Matthew Smith28029532017-09-26 13:33:44 -050014891
14892 if (VAT_JSON_ARRAY != vam->json_tree.type)
14893 {
14894 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14895 vat_json_init_array (&vam->json_tree);
14896 }
14897 node = vat_json_array_add (&vam->json_tree);
14898
14899 vat_json_init_object (node);
Neale Ranns8d7c5022019-02-06 01:41:05 -080014900 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
Matthew Smith28029532017-09-26 13:33:44 -050014901 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Neale Ranns8d7c5022019-02-06 01:41:05 -080014902 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
14903 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
14904 vat_json_object_add_uint (node, "crypto_alg",
14905 ntohl (mp->entry.crypto_algorithm));
14906 vat_json_object_add_uint (node, "integ_alg",
14907 ntohl (mp->entry.integrity_algorithm));
14908 flags = ntohl (mp->entry.flags);
14909 vat_json_object_add_uint (node, "use_esn",
Damjan Marion1e3aa5e2019-03-28 10:58:59 +010014910 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
Neale Ranns8d7c5022019-02-06 01:41:05 -080014911 vat_json_object_add_uint (node, "use_anti_replay",
14912 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
14913 vat_json_object_add_uint (node, "is_tunnel",
14914 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
14915 vat_json_object_add_uint (node, "is_tunnel_ip6",
14916 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
14917 vat_json_object_add_uint (node, "udp_encap",
14918 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
14919 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
14920 mp->entry.crypto_key.length);
14921 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
14922 mp->entry.integrity_key.length);
Neale Ranns5a8844b2019-04-16 07:15:35 +000014923 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
14924 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
Matthew Smith28029532017-09-26 13:33:44 -050014925 vat_json_object_add_uint (node, "replay_window",
14926 clib_net_to_host_u64 (mp->replay_window));
Matthew Smith28029532017-09-26 13:33:44 -050014927}
14928
14929static int
14930api_ipsec_sa_dump (vat_main_t * vam)
14931{
14932 unformat_input_t *i = vam->input;
14933 vl_api_ipsec_sa_dump_t *mp;
14934 vl_api_control_ping_t *mp_ping;
14935 u32 sa_id = ~0;
14936 int ret;
14937
14938 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14939 {
14940 if (unformat (i, "sa_id %d", &sa_id))
14941 ;
14942 else
14943 {
14944 clib_warning ("parse error '%U'", format_unformat_error, i);
14945 return -99;
14946 }
14947 }
14948
14949 M (IPSEC_SA_DUMP, mp);
14950
14951 mp->sa_id = ntohl (sa_id);
14952
14953 S (mp);
14954
14955 /* Use a control ping for synchronization */
14956 M (CONTROL_PING, mp_ping);
14957 S (mp_ping);
14958
14959 W (ret);
14960 return ret;
14961}
14962
Matthew Smithb0972cb2017-05-02 16:20:41 -050014963static int
Matthew Smithca514fd2017-10-12 12:06:59 -050014964api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
14965{
14966 unformat_input_t *i = vam->input;
14967 vl_api_ipsec_tunnel_if_set_sa_t *mp;
14968 u32 sw_if_index = ~0;
14969 u32 sa_id = ~0;
14970 u8 is_outbound = (u8) ~ 0;
14971 int ret;
14972
14973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14974 {
14975 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14976 ;
14977 else if (unformat (i, "sa_id %d", &sa_id))
14978 ;
14979 else if (unformat (i, "outbound"))
14980 is_outbound = 1;
14981 else if (unformat (i, "inbound"))
14982 is_outbound = 0;
14983 else
14984 {
14985 clib_warning ("parse error '%U'", format_unformat_error, i);
14986 return -99;
14987 }
14988 }
14989
14990 if (sw_if_index == ~0)
14991 {
14992 errmsg ("interface must be specified");
14993 return -99;
14994 }
14995
14996 if (sa_id == ~0)
14997 {
14998 errmsg ("SA ID must be specified");
14999 return -99;
15000 }
15001
15002 M (IPSEC_TUNNEL_IF_SET_SA, mp);
15003
15004 mp->sw_if_index = htonl (sw_if_index);
15005 mp->sa_id = htonl (sa_id);
15006 mp->is_outbound = is_outbound;
15007
15008 S (mp);
15009 W (ret);
15010
15011 return ret;
15012}
15013
15014static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010015015api_get_first_msg_id (vat_main_t * vam)
15016{
15017 vl_api_get_first_msg_id_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015018 unformat_input_t *i = vam->input;
15019 u8 *name;
15020 u8 name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015021 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015022
15023 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15024 {
15025 if (unformat (i, "client %s", &name))
15026 name_set = 1;
15027 else
15028 break;
15029 }
15030
15031 if (name_set == 0)
15032 {
15033 errmsg ("missing client name");
15034 return -99;
15035 }
15036 vec_add1 (name, 0);
15037
15038 if (vec_len (name) > 63)
15039 {
15040 errmsg ("client name too long");
15041 return -99;
15042 }
15043
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015044 M (GET_FIRST_MSG_ID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015045 clib_memcpy (mp->name, name, vec_len (name));
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015046 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015047 W (ret);
15048 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015049}
15050
15051static int
15052api_cop_interface_enable_disable (vat_main_t * vam)
15053{
15054 unformat_input_t *line_input = vam->input;
15055 vl_api_cop_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015056 u32 sw_if_index = ~0;
15057 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015058 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015059
15060 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
15061 {
15062 if (unformat (line_input, "disable"))
15063 enable_disable = 0;
15064 if (unformat (line_input, "enable"))
15065 enable_disable = 1;
15066 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
15067 vam, &sw_if_index))
15068 ;
15069 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
15070 ;
15071 else
15072 break;
15073 }
15074
15075 if (sw_if_index == ~0)
15076 {
15077 errmsg ("missing interface name or sw_if_index");
15078 return -99;
15079 }
15080
15081 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015082 M (COP_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015083 mp->sw_if_index = ntohl (sw_if_index);
15084 mp->enable_disable = enable_disable;
15085
15086 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015087 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015088 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015089 W (ret);
15090 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015091}
15092
15093static int
15094api_cop_whitelist_enable_disable (vat_main_t * vam)
15095{
15096 unformat_input_t *line_input = vam->input;
15097 vl_api_cop_whitelist_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015098 u32 sw_if_index = ~0;
15099 u8 ip4 = 0, ip6 = 0, default_cop = 0;
15100 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015101 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015102
15103 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
15104 {
15105 if (unformat (line_input, "ip4"))
15106 ip4 = 1;
15107 else if (unformat (line_input, "ip6"))
15108 ip6 = 1;
15109 else if (unformat (line_input, "default"))
15110 default_cop = 1;
15111 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
15112 vam, &sw_if_index))
15113 ;
15114 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
15115 ;
15116 else if (unformat (line_input, "fib-id %d", &fib_id))
15117 ;
15118 else
15119 break;
15120 }
15121
15122 if (sw_if_index == ~0)
15123 {
15124 errmsg ("missing interface name or sw_if_index");
15125 return -99;
15126 }
15127
15128 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015129 M (COP_WHITELIST_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015130 mp->sw_if_index = ntohl (sw_if_index);
15131 mp->fib_id = ntohl (fib_id);
15132 mp->ip4 = ip4;
15133 mp->ip6 = ip6;
15134 mp->default_cop = default_cop;
15135
15136 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015137 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015138 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015139 W (ret);
15140 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015141}
15142
15143static int
15144api_get_node_graph (vat_main_t * vam)
15145{
15146 vl_api_get_node_graph_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015147 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015148
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015149 M (GET_NODE_GRAPH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015150
15151 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015152 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015153 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015154 W (ret);
15155 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015156}
15157
15158/* *INDENT-OFF* */
15159/** Used for parsing LISP eids */
15160typedef CLIB_PACKED(struct{
15161 u8 addr[16]; /**< eid address */
15162 u32 len; /**< prefix length if IP */
15163 u8 type; /**< type of eid */
15164}) lisp_eid_vat_t;
15165/* *INDENT-ON* */
15166
15167static uword
15168unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
15169{
15170 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
15171
Dave Barachb7b92992018-10-17 10:38:51 -040015172 clib_memset (a, 0, sizeof (a[0]));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015173
15174 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
15175 {
15176 a->type = 0; /* ipv4 type */
15177 }
15178 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
15179 {
15180 a->type = 1; /* ipv6 type */
15181 }
15182 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
15183 {
15184 a->type = 2; /* mac type */
15185 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015186 else if (unformat (input, "%U", unformat_nsh_address, a->addr))
15187 {
15188 a->type = 3; /* NSH type */
15189 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) a->addr;
15190 nsh->spi = clib_host_to_net_u32 (nsh->spi);
15191 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010015192 else
15193 {
15194 return 0;
15195 }
15196
15197 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
15198 {
15199 return 0;
15200 }
15201
15202 return 1;
15203}
15204
15205static int
15206lisp_eid_size_vat (u8 type)
15207{
15208 switch (type)
15209 {
15210 case 0:
15211 return 4;
15212 case 1:
15213 return 16;
15214 case 2:
15215 return 6;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015216 case 3:
15217 return 5;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015218 }
15219 return 0;
15220}
15221
15222static void
15223lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
15224{
15225 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
15226}
15227
Damjan Marion7cd468a2016-12-19 23:05:39 +010015228static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015229api_one_add_del_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015230{
15231 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015232 vl_api_one_add_del_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015233 u8 is_add = 1;
15234 u8 *locator_set_name = NULL;
15235 u8 locator_set_name_set = 0;
Filip Tehlar05a057b2017-02-01 08:50:31 +010015236 vl_api_local_locator_t locator, *locators = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015237 u32 sw_if_index, priority, weight;
15238 u32 data_len = 0;
15239
Jon Loeliger56c7b012017-02-01 12:31:41 -060015240 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015241 /* Parse args required to build the message */
15242 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15243 {
15244 if (unformat (input, "del"))
15245 {
15246 is_add = 0;
15247 }
15248 else if (unformat (input, "locator-set %s", &locator_set_name))
15249 {
15250 locator_set_name_set = 1;
15251 }
15252 else if (unformat (input, "sw_if_index %u p %u w %u",
15253 &sw_if_index, &priority, &weight))
15254 {
15255 locator.sw_if_index = htonl (sw_if_index);
15256 locator.priority = priority;
15257 locator.weight = weight;
15258 vec_add1 (locators, locator);
15259 }
15260 else
15261 if (unformat
15262 (input, "iface %U p %u w %u", api_unformat_sw_if_index, vam,
15263 &sw_if_index, &priority, &weight))
15264 {
15265 locator.sw_if_index = htonl (sw_if_index);
15266 locator.priority = priority;
15267 locator.weight = weight;
15268 vec_add1 (locators, locator);
15269 }
15270 else
15271 break;
15272 }
15273
15274 if (locator_set_name_set == 0)
15275 {
15276 errmsg ("missing locator-set name");
15277 vec_free (locators);
15278 return -99;
15279 }
15280
15281 if (vec_len (locator_set_name) > 64)
15282 {
15283 errmsg ("locator-set name too long");
15284 vec_free (locator_set_name);
15285 vec_free (locators);
15286 return -99;
15287 }
15288 vec_add1 (locator_set_name, 0);
15289
Filip Tehlar05a057b2017-02-01 08:50:31 +010015290 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015291
15292 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015293 M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015294
15295 mp->is_add = is_add;
15296 clib_memcpy (mp->locator_set_name, locator_set_name,
15297 vec_len (locator_set_name));
15298 vec_free (locator_set_name);
15299
15300 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
15301 if (locators)
15302 clib_memcpy (mp->locators, locators, data_len);
15303 vec_free (locators);
15304
15305 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015306 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015307
15308 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015309 W (ret);
15310 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015311}
15312
Filip Tehlar694396d2017-02-17 14:29:11 +010015313#define api_lisp_add_del_locator_set api_one_add_del_locator_set
15314
Damjan Marion7cd468a2016-12-19 23:05:39 +010015315static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015316api_one_add_del_locator (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015317{
15318 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015319 vl_api_one_add_del_locator_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015320 u32 tmp_if_index = ~0;
15321 u32 sw_if_index = ~0;
15322 u8 sw_if_index_set = 0;
15323 u8 sw_if_index_if_name_set = 0;
15324 u32 priority = ~0;
15325 u8 priority_set = 0;
15326 u32 weight = ~0;
15327 u8 weight_set = 0;
15328 u8 is_add = 1;
15329 u8 *locator_set_name = NULL;
15330 u8 locator_set_name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015331 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015332
15333 /* Parse args required to build the message */
15334 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15335 {
15336 if (unformat (input, "del"))
15337 {
15338 is_add = 0;
15339 }
15340 else if (unformat (input, "locator-set %s", &locator_set_name))
15341 {
15342 locator_set_name_set = 1;
15343 }
15344 else if (unformat (input, "iface %U", api_unformat_sw_if_index, vam,
15345 &tmp_if_index))
15346 {
15347 sw_if_index_if_name_set = 1;
15348 sw_if_index = tmp_if_index;
15349 }
15350 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
15351 {
15352 sw_if_index_set = 1;
15353 sw_if_index = tmp_if_index;
15354 }
15355 else if (unformat (input, "p %d", &priority))
15356 {
15357 priority_set = 1;
15358 }
15359 else if (unformat (input, "w %d", &weight))
15360 {
15361 weight_set = 1;
15362 }
15363 else
15364 break;
15365 }
15366
15367 if (locator_set_name_set == 0)
15368 {
15369 errmsg ("missing locator-set name");
15370 return -99;
15371 }
15372
15373 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
15374 {
15375 errmsg ("missing sw_if_index");
15376 vec_free (locator_set_name);
15377 return -99;
15378 }
15379
15380 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
15381 {
15382 errmsg ("cannot use both params interface name and sw_if_index");
15383 vec_free (locator_set_name);
15384 return -99;
15385 }
15386
15387 if (priority_set == 0)
15388 {
15389 errmsg ("missing locator-set priority");
15390 vec_free (locator_set_name);
15391 return -99;
15392 }
15393
15394 if (weight_set == 0)
15395 {
15396 errmsg ("missing locator-set weight");
15397 vec_free (locator_set_name);
15398 return -99;
15399 }
15400
15401 if (vec_len (locator_set_name) > 64)
15402 {
15403 errmsg ("locator-set name too long");
15404 vec_free (locator_set_name);
15405 return -99;
15406 }
15407 vec_add1 (locator_set_name, 0);
15408
15409 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015410 M (ONE_ADD_DEL_LOCATOR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015411
15412 mp->is_add = is_add;
15413 mp->sw_if_index = ntohl (sw_if_index);
15414 mp->priority = priority;
15415 mp->weight = weight;
15416 clib_memcpy (mp->locator_set_name, locator_set_name,
15417 vec_len (locator_set_name));
15418 vec_free (locator_set_name);
15419
15420 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015421 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015422
15423 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015424 W (ret);
15425 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015426}
15427
Filip Tehlar694396d2017-02-17 14:29:11 +010015428#define api_lisp_add_del_locator api_one_add_del_locator
15429
Damjan Marion7cd468a2016-12-19 23:05:39 +010015430uword
15431unformat_hmac_key_id (unformat_input_t * input, va_list * args)
15432{
15433 u32 *key_id = va_arg (*args, u32 *);
15434 u8 *s = 0;
15435
15436 if (unformat (input, "%s", &s))
15437 {
15438 if (!strcmp ((char *) s, "sha1"))
15439 key_id[0] = HMAC_SHA_1_96;
15440 else if (!strcmp ((char *) s, "sha256"))
15441 key_id[0] = HMAC_SHA_256_128;
15442 else
15443 {
15444 clib_warning ("invalid key_id: '%s'", s);
15445 key_id[0] = HMAC_NO_KEY;
15446 }
15447 }
15448 else
15449 return 0;
15450
15451 vec_free (s);
15452 return 1;
15453}
15454
15455static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015456api_one_add_del_local_eid (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015457{
15458 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015459 vl_api_one_add_del_local_eid_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015460 u8 is_add = 1;
15461 u8 eid_set = 0;
15462 lisp_eid_vat_t _eid, *eid = &_eid;
15463 u8 *locator_set_name = 0;
15464 u8 locator_set_name_set = 0;
15465 u32 vni = 0;
15466 u16 key_id = 0;
15467 u8 *key = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015468 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015469
15470 /* Parse args required to build the message */
15471 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15472 {
15473 if (unformat (input, "del"))
15474 {
15475 is_add = 0;
15476 }
15477 else if (unformat (input, "vni %d", &vni))
15478 {
15479 ;
15480 }
15481 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
15482 {
15483 eid_set = 1;
15484 }
15485 else if (unformat (input, "locator-set %s", &locator_set_name))
15486 {
15487 locator_set_name_set = 1;
15488 }
15489 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
15490 ;
15491 else if (unformat (input, "secret-key %_%v%_", &key))
15492 ;
15493 else
15494 break;
15495 }
15496
15497 if (locator_set_name_set == 0)
15498 {
15499 errmsg ("missing locator-set name");
15500 return -99;
15501 }
15502
15503 if (0 == eid_set)
15504 {
15505 errmsg ("EID address not set!");
15506 vec_free (locator_set_name);
15507 return -99;
15508 }
15509
15510 if (key && (0 == key_id))
15511 {
15512 errmsg ("invalid key_id!");
15513 return -99;
15514 }
15515
15516 if (vec_len (key) > 64)
15517 {
15518 errmsg ("key too long");
15519 vec_free (key);
15520 return -99;
15521 }
15522
15523 if (vec_len (locator_set_name) > 64)
15524 {
15525 errmsg ("locator-set name too long");
15526 vec_free (locator_set_name);
15527 return -99;
15528 }
15529 vec_add1 (locator_set_name, 0);
15530
15531 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015532 M (ONE_ADD_DEL_LOCAL_EID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015533
15534 mp->is_add = is_add;
15535 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
15536 mp->eid_type = eid->type;
15537 mp->prefix_len = eid->len;
15538 mp->vni = clib_host_to_net_u32 (vni);
15539 mp->key_id = clib_host_to_net_u16 (key_id);
15540 clib_memcpy (mp->locator_set_name, locator_set_name,
15541 vec_len (locator_set_name));
15542 clib_memcpy (mp->key, key, vec_len (key));
15543
15544 vec_free (locator_set_name);
15545 vec_free (key);
15546
15547 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015548 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015549
15550 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015551 W (ret);
15552 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015553}
15554
Filip Tehlar694396d2017-02-17 14:29:11 +010015555#define api_lisp_add_del_local_eid api_one_add_del_local_eid
Damjan Marion7cd468a2016-12-19 23:05:39 +010015556
15557static int
15558api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
15559{
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015560 u32 dp_table = 0, vni = 0;;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015561 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010015562 vl_api_gpe_add_del_fwd_entry_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015563 u8 is_add = 1;
15564 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
15565 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
15566 u8 rmt_eid_set = 0, lcl_eid_set = 0;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015567 u32 action = ~0, w;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015568 ip4_address_t rmt_rloc4, lcl_rloc4;
15569 ip6_address_t rmt_rloc6, lcl_rloc6;
Filip Tehlar82786c42017-02-20 15:20:37 +010015570 vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015571 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015572
Dave Barachb7b92992018-10-17 10:38:51 -040015573 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015574
15575 /* Parse args required to build the message */
15576 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15577 {
15578 if (unformat (input, "del"))
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015579 is_add = 0;
15580 else if (unformat (input, "add"))
15581 is_add = 1;
15582 else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015583 {
15584 rmt_eid_set = 1;
15585 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015586 else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015587 {
15588 lcl_eid_set = 1;
15589 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015590 else if (unformat (input, "vrf %d", &dp_table))
15591 ;
15592 else if (unformat (input, "bd %d", &dp_table))
15593 ;
15594 else if (unformat (input, "vni %d", &vni))
15595 ;
15596 else if (unformat (input, "w %d", &w))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015597 {
15598 if (!curr_rloc)
15599 {
15600 errmsg ("No RLOC configured for setting priority/weight!");
15601 return -99;
15602 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010015603 curr_rloc->weight = w;
15604 }
15605 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
15606 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
15607 {
15608 rloc.is_ip4 = 1;
15609
15610 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015611 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015612 vec_add1 (lcl_locs, rloc);
15613
15614 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
15615 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015616 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010015617 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
15618 }
15619 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
15620 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
15621 {
15622 rloc.is_ip4 = 0;
15623 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015624 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015625 vec_add1 (lcl_locs, rloc);
15626
15627 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
15628 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015629 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010015630 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
15631 }
15632 else if (unformat (input, "action %d", &action))
15633 {
15634 ;
15635 }
15636 else
15637 {
15638 clib_warning ("parse error '%U'", format_unformat_error, input);
15639 return -99;
15640 }
15641 }
15642
15643 if (!rmt_eid_set)
15644 {
15645 errmsg ("remote eid addresses not set");
15646 return -99;
15647 }
15648
15649 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
15650 {
15651 errmsg ("eid types don't match");
15652 return -99;
15653 }
15654
15655 if (0 == rmt_locs && (u32) ~ 0 == action)
15656 {
15657 errmsg ("action not set for negative mapping");
15658 return -99;
15659 }
15660
15661 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010015662 M2 (GPE_ADD_DEL_FWD_ENTRY, mp,
15663 sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015664
15665 mp->is_add = is_add;
15666 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
15667 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
15668 mp->eid_type = rmt_eid->type;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015669 mp->dp_table = clib_host_to_net_u32 (dp_table);
15670 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015671 mp->rmt_len = rmt_eid->len;
15672 mp->lcl_len = lcl_eid->len;
15673 mp->action = action;
15674
15675 if (0 != rmt_locs && 0 != lcl_locs)
15676 {
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015677 mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2);
15678 clib_memcpy (mp->locs, lcl_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010015679 (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs)));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015680
Filip Tehlar82786c42017-02-20 15:20:37 +010015681 u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015682 clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010015683 (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs)));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015684 }
15685 vec_free (lcl_locs);
15686 vec_free (rmt_locs);
15687
15688 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015689 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015690
15691 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015692 W (ret);
15693 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015694}
15695
15696static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015697api_one_add_del_map_server (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015698{
15699 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015700 vl_api_one_add_del_map_server_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015701 u8 is_add = 1;
15702 u8 ipv4_set = 0;
15703 u8 ipv6_set = 0;
15704 ip4_address_t ipv4;
15705 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015706 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015707
15708 /* Parse args required to build the message */
15709 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15710 {
15711 if (unformat (input, "del"))
15712 {
15713 is_add = 0;
15714 }
15715 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
15716 {
15717 ipv4_set = 1;
15718 }
15719 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
15720 {
15721 ipv6_set = 1;
15722 }
15723 else
15724 break;
15725 }
15726
15727 if (ipv4_set && ipv6_set)
15728 {
15729 errmsg ("both eid v4 and v6 addresses set");
15730 return -99;
15731 }
15732
15733 if (!ipv4_set && !ipv6_set)
15734 {
15735 errmsg ("eid addresses not set");
15736 return -99;
15737 }
15738
15739 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015740 M (ONE_ADD_DEL_MAP_SERVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015741
15742 mp->is_add = is_add;
15743 if (ipv6_set)
15744 {
15745 mp->is_ipv6 = 1;
15746 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
15747 }
15748 else
15749 {
15750 mp->is_ipv6 = 0;
15751 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
15752 }
15753
15754 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015755 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015756
15757 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015758 W (ret);
15759 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015760}
15761
Filip Tehlar694396d2017-02-17 14:29:11 +010015762#define api_lisp_add_del_map_server api_one_add_del_map_server
15763
Damjan Marion7cd468a2016-12-19 23:05:39 +010015764static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015765api_one_add_del_map_resolver (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015766{
15767 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015768 vl_api_one_add_del_map_resolver_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015769 u8 is_add = 1;
15770 u8 ipv4_set = 0;
15771 u8 ipv6_set = 0;
15772 ip4_address_t ipv4;
15773 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015774 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015775
15776 /* Parse args required to build the message */
15777 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15778 {
15779 if (unformat (input, "del"))
15780 {
15781 is_add = 0;
15782 }
15783 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
15784 {
15785 ipv4_set = 1;
15786 }
15787 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
15788 {
15789 ipv6_set = 1;
15790 }
15791 else
15792 break;
15793 }
15794
15795 if (ipv4_set && ipv6_set)
15796 {
15797 errmsg ("both eid v4 and v6 addresses set");
15798 return -99;
15799 }
15800
15801 if (!ipv4_set && !ipv6_set)
15802 {
15803 errmsg ("eid addresses not set");
15804 return -99;
15805 }
15806
15807 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015808 M (ONE_ADD_DEL_MAP_RESOLVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015809
15810 mp->is_add = is_add;
15811 if (ipv6_set)
15812 {
15813 mp->is_ipv6 = 1;
15814 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
15815 }
15816 else
15817 {
15818 mp->is_ipv6 = 0;
15819 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
15820 }
15821
15822 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015823 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015824
15825 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015826 W (ret);
15827 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015828}
15829
Filip Tehlar694396d2017-02-17 14:29:11 +010015830#define api_lisp_add_del_map_resolver api_one_add_del_map_resolver
15831
Damjan Marion7cd468a2016-12-19 23:05:39 +010015832static int
15833api_lisp_gpe_enable_disable (vat_main_t * vam)
15834{
15835 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010015836 vl_api_gpe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015837 u8 is_set = 0;
15838 u8 is_en = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015839 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015840
15841 /* Parse args required to build the message */
15842 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15843 {
15844 if (unformat (input, "enable"))
15845 {
15846 is_set = 1;
15847 is_en = 1;
15848 }
15849 else if (unformat (input, "disable"))
15850 {
15851 is_set = 1;
15852 is_en = 0;
15853 }
15854 else
15855 break;
15856 }
15857
15858 if (is_set == 0)
15859 {
15860 errmsg ("Value not set");
15861 return -99;
15862 }
15863
15864 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010015865 M (GPE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015866
15867 mp->is_en = is_en;
15868
15869 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015870 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015871
15872 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015873 W (ret);
15874 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015875}
15876
15877static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015878api_one_rloc_probe_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015879{
15880 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015881 vl_api_one_rloc_probe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015882 u8 is_set = 0;
15883 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015884 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015885
15886 /* Parse args required to build the message */
15887 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15888 {
15889 if (unformat (input, "enable"))
15890 {
15891 is_set = 1;
15892 is_en = 1;
15893 }
15894 else if (unformat (input, "disable"))
15895 is_set = 1;
15896 else
15897 break;
15898 }
15899
15900 if (!is_set)
15901 {
15902 errmsg ("Value not set");
15903 return -99;
15904 }
15905
15906 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015907 M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015908
15909 mp->is_enabled = is_en;
15910
15911 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015912 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015913
15914 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015915 W (ret);
15916 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015917}
15918
Filip Tehlar694396d2017-02-17 14:29:11 +010015919#define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
15920
Damjan Marion7cd468a2016-12-19 23:05:39 +010015921static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015922api_one_map_register_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015923{
15924 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015925 vl_api_one_map_register_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015926 u8 is_set = 0;
15927 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015928 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015929
15930 /* Parse args required to build the message */
15931 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15932 {
15933 if (unformat (input, "enable"))
15934 {
15935 is_set = 1;
15936 is_en = 1;
15937 }
15938 else if (unformat (input, "disable"))
15939 is_set = 1;
15940 else
15941 break;
15942 }
15943
15944 if (!is_set)
15945 {
15946 errmsg ("Value not set");
15947 return -99;
15948 }
15949
15950 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015951 M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015952
15953 mp->is_enabled = is_en;
15954
15955 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015956 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015957
15958 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015959 W (ret);
15960 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015961}
15962
Filip Tehlar694396d2017-02-17 14:29:11 +010015963#define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
15964
Damjan Marion7cd468a2016-12-19 23:05:39 +010015965static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015966api_one_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015967{
15968 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015969 vl_api_one_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015970 u8 is_set = 0;
15971 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015972 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015973
15974 /* Parse args required to build the message */
15975 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15976 {
15977 if (unformat (input, "enable"))
15978 {
15979 is_set = 1;
15980 is_en = 1;
15981 }
15982 else if (unformat (input, "disable"))
15983 {
15984 is_set = 1;
15985 }
15986 else
15987 break;
15988 }
15989
15990 if (!is_set)
15991 {
15992 errmsg ("Value not set");
15993 return -99;
15994 }
15995
15996 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015997 M (ONE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015998
15999 mp->is_en = is_en;
16000
16001 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016002 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016003
16004 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016005 W (ret);
16006 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016007}
16008
Filip Tehlar694396d2017-02-17 14:29:11 +010016009#define api_lisp_enable_disable api_one_enable_disable
16010
Damjan Marion7cd468a2016-12-19 23:05:39 +010016011static int
Filip Tehlar0a8840d2017-10-16 05:48:23 -070016012api_one_enable_disable_xtr_mode (vat_main_t * vam)
16013{
16014 unformat_input_t *input = vam->input;
16015 vl_api_one_enable_disable_xtr_mode_t *mp;
16016 u8 is_set = 0;
16017 u8 is_en = 0;
16018 int ret;
16019
16020 /* Parse args required to build the message */
16021 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16022 {
16023 if (unformat (input, "enable"))
16024 {
16025 is_set = 1;
16026 is_en = 1;
16027 }
16028 else if (unformat (input, "disable"))
16029 {
16030 is_set = 1;
16031 }
16032 else
16033 break;
16034 }
16035
16036 if (!is_set)
16037 {
16038 errmsg ("Value not set");
16039 return -99;
16040 }
16041
16042 /* Construct the API message */
16043 M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
16044
16045 mp->is_en = is_en;
16046
16047 /* send it... */
16048 S (mp);
16049
16050 /* Wait for a reply... */
16051 W (ret);
16052 return ret;
16053}
16054
16055static int
16056api_one_show_xtr_mode (vat_main_t * vam)
16057{
16058 vl_api_one_show_xtr_mode_t *mp;
16059 int ret;
16060
16061 /* Construct the API message */
16062 M (ONE_SHOW_XTR_MODE, mp);
16063
16064 /* send it... */
16065 S (mp);
16066
16067 /* Wait for a reply... */
16068 W (ret);
16069 return ret;
16070}
16071
16072static int
16073api_one_enable_disable_pitr_mode (vat_main_t * vam)
16074{
16075 unformat_input_t *input = vam->input;
16076 vl_api_one_enable_disable_pitr_mode_t *mp;
16077 u8 is_set = 0;
16078 u8 is_en = 0;
16079 int ret;
16080
16081 /* Parse args required to build the message */
16082 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16083 {
16084 if (unformat (input, "enable"))
16085 {
16086 is_set = 1;
16087 is_en = 1;
16088 }
16089 else if (unformat (input, "disable"))
16090 {
16091 is_set = 1;
16092 }
16093 else
16094 break;
16095 }
16096
16097 if (!is_set)
16098 {
16099 errmsg ("Value not set");
16100 return -99;
16101 }
16102
16103 /* Construct the API message */
16104 M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
16105
16106 mp->is_en = is_en;
16107
16108 /* send it... */
16109 S (mp);
16110
16111 /* Wait for a reply... */
16112 W (ret);
16113 return ret;
16114}
16115
16116static int
16117api_one_show_pitr_mode (vat_main_t * vam)
16118{
16119 vl_api_one_show_pitr_mode_t *mp;
16120 int ret;
16121
16122 /* Construct the API message */
16123 M (ONE_SHOW_PITR_MODE, mp);
16124
16125 /* send it... */
16126 S (mp);
16127
16128 /* Wait for a reply... */
16129 W (ret);
16130 return ret;
16131}
16132
16133static int
16134api_one_enable_disable_petr_mode (vat_main_t * vam)
16135{
16136 unformat_input_t *input = vam->input;
16137 vl_api_one_enable_disable_petr_mode_t *mp;
16138 u8 is_set = 0;
16139 u8 is_en = 0;
16140 int ret;
16141
16142 /* Parse args required to build the message */
16143 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16144 {
16145 if (unformat (input, "enable"))
16146 {
16147 is_set = 1;
16148 is_en = 1;
16149 }
16150 else if (unformat (input, "disable"))
16151 {
16152 is_set = 1;
16153 }
16154 else
16155 break;
16156 }
16157
16158 if (!is_set)
16159 {
16160 errmsg ("Value not set");
16161 return -99;
16162 }
16163
16164 /* Construct the API message */
16165 M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
16166
16167 mp->is_en = is_en;
16168
16169 /* send it... */
16170 S (mp);
16171
16172 /* Wait for a reply... */
16173 W (ret);
16174 return ret;
16175}
16176
16177static int
16178api_one_show_petr_mode (vat_main_t * vam)
16179{
16180 vl_api_one_show_petr_mode_t *mp;
16181 int ret;
16182
16183 /* Construct the API message */
16184 M (ONE_SHOW_PETR_MODE, mp);
16185
16186 /* send it... */
16187 S (mp);
16188
16189 /* Wait for a reply... */
16190 W (ret);
16191 return ret;
16192}
16193
16194static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016195api_show_one_map_register_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016196{
Filip Tehlar694396d2017-02-17 14:29:11 +010016197 vl_api_show_one_map_register_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016198 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016199
Filip Tehlar694396d2017-02-17 14:29:11 +010016200 M (SHOW_ONE_MAP_REGISTER_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016201
16202 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016203 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016204
16205 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016206 W (ret);
16207 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016208}
16209
Filip Tehlar694396d2017-02-17 14:29:11 +010016210#define api_show_lisp_map_register_state api_show_one_map_register_state
16211
Damjan Marion7cd468a2016-12-19 23:05:39 +010016212static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016213api_show_one_rloc_probe_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016214{
Filip Tehlar694396d2017-02-17 14:29:11 +010016215 vl_api_show_one_rloc_probe_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016216 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016217
Filip Tehlar694396d2017-02-17 14:29:11 +010016218 M (SHOW_ONE_RLOC_PROBE_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016219
16220 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016221 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016222
16223 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016224 W (ret);
16225 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016226}
16227
Filip Tehlar694396d2017-02-17 14:29:11 +010016228#define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
16229
Damjan Marion7cd468a2016-12-19 23:05:39 +010016230static int
Filip Tehlar05879992017-09-05 15:46:09 +020016231api_one_add_del_ndp_entry (vat_main_t * vam)
16232{
16233 vl_api_one_add_del_ndp_entry_t *mp;
16234 unformat_input_t *input = vam->input;
16235 u8 is_add = 1;
16236 u8 mac_set = 0;
16237 u8 bd_set = 0;
16238 u8 ip_set = 0;
16239 u8 mac[6] = { 0, };
16240 u8 ip6[16] = { 0, };
16241 u32 bd = ~0;
16242 int ret;
16243
16244 /* Parse args required to build the message */
16245 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16246 {
16247 if (unformat (input, "del"))
16248 is_add = 0;
16249 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
16250 mac_set = 1;
16251 else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
16252 ip_set = 1;
16253 else if (unformat (input, "bd %d", &bd))
16254 bd_set = 1;
16255 else
16256 {
16257 errmsg ("parse error '%U'", format_unformat_error, input);
16258 return -99;
16259 }
16260 }
16261
16262 if (!bd_set || !ip_set || (!mac_set && is_add))
16263 {
16264 errmsg ("Missing BD, IP or MAC!");
16265 return -99;
16266 }
16267
16268 M (ONE_ADD_DEL_NDP_ENTRY, mp);
16269 mp->is_add = is_add;
16270 clib_memcpy (mp->mac, mac, 6);
16271 mp->bd = clib_host_to_net_u32 (bd);
16272 clib_memcpy (mp->ip6, ip6, sizeof (mp->ip6));
16273
16274 /* send */
16275 S (mp);
16276
16277 /* wait for reply */
16278 W (ret);
16279 return ret;
16280}
16281
16282static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020016283api_one_add_del_l2_arp_entry (vat_main_t * vam)
16284{
16285 vl_api_one_add_del_l2_arp_entry_t *mp;
16286 unformat_input_t *input = vam->input;
16287 u8 is_add = 1;
16288 u8 mac_set = 0;
16289 u8 bd_set = 0;
16290 u8 ip_set = 0;
16291 u8 mac[6] = { 0, };
16292 u32 ip4 = 0, bd = ~0;
16293 int ret;
16294
16295 /* Parse args required to build the message */
16296 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16297 {
16298 if (unformat (input, "del"))
16299 is_add = 0;
16300 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
16301 mac_set = 1;
16302 else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
16303 ip_set = 1;
16304 else if (unformat (input, "bd %d", &bd))
16305 bd_set = 1;
16306 else
16307 {
16308 errmsg ("parse error '%U'", format_unformat_error, input);
16309 return -99;
16310 }
16311 }
16312
16313 if (!bd_set || !ip_set || (!mac_set && is_add))
16314 {
16315 errmsg ("Missing BD, IP or MAC!");
16316 return -99;
16317 }
16318
16319 M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
16320 mp->is_add = is_add;
16321 clib_memcpy (mp->mac, mac, 6);
16322 mp->bd = clib_host_to_net_u32 (bd);
16323 mp->ip4 = ip4;
16324
16325 /* send */
16326 S (mp);
16327
16328 /* wait for reply */
16329 W (ret);
16330 return ret;
16331}
16332
16333static int
Filip Tehlar05879992017-09-05 15:46:09 +020016334api_one_ndp_bd_get (vat_main_t * vam)
16335{
16336 vl_api_one_ndp_bd_get_t *mp;
16337 int ret;
16338
16339 M (ONE_NDP_BD_GET, mp);
16340
16341 /* send */
16342 S (mp);
16343
16344 /* wait for reply */
16345 W (ret);
16346 return ret;
16347}
16348
16349static int
16350api_one_ndp_entries_get (vat_main_t * vam)
16351{
16352 vl_api_one_ndp_entries_get_t *mp;
16353 unformat_input_t *input = vam->input;
16354 u8 bd_set = 0;
16355 u32 bd = ~0;
16356 int ret;
16357
16358 /* Parse args required to build the message */
16359 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16360 {
16361 if (unformat (input, "bd %d", &bd))
16362 bd_set = 1;
16363 else
16364 {
16365 errmsg ("parse error '%U'", format_unformat_error, input);
16366 return -99;
16367 }
16368 }
16369
16370 if (!bd_set)
16371 {
16372 errmsg ("Expected bridge domain!");
16373 return -99;
16374 }
16375
16376 M (ONE_NDP_ENTRIES_GET, mp);
16377 mp->bd = clib_host_to_net_u32 (bd);
16378
16379 /* send */
16380 S (mp);
16381
16382 /* wait for reply */
16383 W (ret);
16384 return ret;
16385}
16386
16387static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020016388api_one_l2_arp_bd_get (vat_main_t * vam)
16389{
16390 vl_api_one_l2_arp_bd_get_t *mp;
16391 int ret;
16392
16393 M (ONE_L2_ARP_BD_GET, mp);
16394
16395 /* send */
16396 S (mp);
16397
16398 /* wait for reply */
16399 W (ret);
16400 return ret;
16401}
16402
16403static int
16404api_one_l2_arp_entries_get (vat_main_t * vam)
16405{
16406 vl_api_one_l2_arp_entries_get_t *mp;
16407 unformat_input_t *input = vam->input;
16408 u8 bd_set = 0;
16409 u32 bd = ~0;
16410 int ret;
16411
16412 /* Parse args required to build the message */
16413 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16414 {
16415 if (unformat (input, "bd %d", &bd))
16416 bd_set = 1;
16417 else
16418 {
16419 errmsg ("parse error '%U'", format_unformat_error, input);
16420 return -99;
16421 }
16422 }
16423
16424 if (!bd_set)
16425 {
16426 errmsg ("Expected bridge domain!");
16427 return -99;
16428 }
16429
16430 M (ONE_L2_ARP_ENTRIES_GET, mp);
16431 mp->bd = clib_host_to_net_u32 (bd);
16432
16433 /* send */
16434 S (mp);
16435
16436 /* wait for reply */
16437 W (ret);
16438 return ret;
16439}
16440
16441static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010016442api_one_stats_enable_disable (vat_main_t * vam)
16443{
16444 vl_api_one_stats_enable_disable_t *mp;
16445 unformat_input_t *input = vam->input;
16446 u8 is_set = 0;
16447 u8 is_en = 0;
16448 int ret;
16449
16450 /* Parse args required to build the message */
16451 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16452 {
16453 if (unformat (input, "enable"))
16454 {
16455 is_set = 1;
16456 is_en = 1;
16457 }
16458 else if (unformat (input, "disable"))
16459 {
16460 is_set = 1;
16461 }
16462 else
16463 break;
16464 }
16465
16466 if (!is_set)
16467 {
16468 errmsg ("Value not set");
16469 return -99;
16470 }
16471
16472 M (ONE_STATS_ENABLE_DISABLE, mp);
16473 mp->is_en = is_en;
16474
16475 /* send */
16476 S (mp);
16477
16478 /* wait for reply */
16479 W (ret);
16480 return ret;
16481}
16482
16483static int
16484api_show_one_stats_enable_disable (vat_main_t * vam)
16485{
16486 vl_api_show_one_stats_enable_disable_t *mp;
16487 int ret;
16488
16489 M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
16490
16491 /* send */
16492 S (mp);
16493
16494 /* wait for reply */
16495 W (ret);
16496 return ret;
16497}
16498
16499static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016500api_show_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016501{
Filip Tehlar694396d2017-02-17 14:29:11 +010016502 vl_api_show_one_map_request_mode_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016503 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016504
Filip Tehlar694396d2017-02-17 14:29:11 +010016505 M (SHOW_ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016506
16507 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016508 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016509
16510 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016511 W (ret);
16512 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016513}
16514
Filip Tehlar694396d2017-02-17 14:29:11 +010016515#define api_show_lisp_map_request_mode api_show_one_map_request_mode
16516
Damjan Marion7cd468a2016-12-19 23:05:39 +010016517static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016518api_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016519{
Damjan Marion7cd468a2016-12-19 23:05:39 +010016520 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016521 vl_api_one_map_request_mode_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016522 u8 mode = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016523 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016524
16525 /* Parse args required to build the message */
16526 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16527 {
16528 if (unformat (input, "dst-only"))
16529 mode = 0;
16530 else if (unformat (input, "src-dst"))
16531 mode = 1;
16532 else
16533 {
16534 errmsg ("parse error '%U'", format_unformat_error, input);
16535 return -99;
16536 }
16537 }
16538
Filip Tehlar694396d2017-02-17 14:29:11 +010016539 M (ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016540
16541 mp->mode = mode;
16542
16543 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016544 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016545
16546 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016547 W (ret);
16548 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016549}
16550
Filip Tehlar694396d2017-02-17 14:29:11 +010016551#define api_lisp_map_request_mode api_one_map_request_mode
16552
Damjan Marion7cd468a2016-12-19 23:05:39 +010016553/**
Filip Tehlar694396d2017-02-17 14:29:11 +010016554 * Enable/disable ONE proxy ITR.
Damjan Marion7cd468a2016-12-19 23:05:39 +010016555 *
16556 * @param vam vpp API test context
16557 * @return return code
16558 */
16559static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016560api_one_pitr_set_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016561{
Damjan Marion7cd468a2016-12-19 23:05:39 +010016562 u8 ls_name_set = 0;
16563 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016564 vl_api_one_pitr_set_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016565 u8 is_add = 1;
16566 u8 *ls_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016567 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016568
16569 /* Parse args required to build the message */
16570 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16571 {
16572 if (unformat (input, "del"))
16573 is_add = 0;
16574 else if (unformat (input, "locator-set %s", &ls_name))
16575 ls_name_set = 1;
16576 else
16577 {
16578 errmsg ("parse error '%U'", format_unformat_error, input);
16579 return -99;
16580 }
16581 }
16582
16583 if (!ls_name_set)
16584 {
16585 errmsg ("locator-set name not set!");
16586 return -99;
16587 }
16588
Filip Tehlar694396d2017-02-17 14:29:11 +010016589 M (ONE_PITR_SET_LOCATOR_SET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016590
16591 mp->is_add = is_add;
16592 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
16593 vec_free (ls_name);
16594
16595 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016596 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016597
16598 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016599 W (ret);
16600 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016601}
16602
Filip Tehlar694396d2017-02-17 14:29:11 +010016603#define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
16604
Damjan Marion7cd468a2016-12-19 23:05:39 +010016605static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016606api_one_nsh_set_locator_set (vat_main_t * vam)
16607{
16608 u8 ls_name_set = 0;
16609 unformat_input_t *input = vam->input;
16610 vl_api_one_nsh_set_locator_set_t *mp;
16611 u8 is_add = 1;
16612 u8 *ls_name = 0;
16613 int ret;
16614
16615 /* Parse args required to build the message */
16616 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16617 {
16618 if (unformat (input, "del"))
16619 is_add = 0;
16620 else if (unformat (input, "ls %s", &ls_name))
16621 ls_name_set = 1;
16622 else
16623 {
16624 errmsg ("parse error '%U'", format_unformat_error, input);
16625 return -99;
16626 }
16627 }
16628
16629 if (!ls_name_set && is_add)
16630 {
16631 errmsg ("locator-set name not set!");
16632 return -99;
16633 }
16634
16635 M (ONE_NSH_SET_LOCATOR_SET, mp);
16636
16637 mp->is_add = is_add;
16638 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
16639 vec_free (ls_name);
16640
16641 /* send */
16642 S (mp);
16643
16644 /* wait for reply */
16645 W (ret);
16646 return ret;
16647}
16648
16649static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016650api_show_one_pitr (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016651{
Filip Tehlar694396d2017-02-17 14:29:11 +010016652 vl_api_show_one_pitr_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016653 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016654
16655 if (!vam->json_output)
16656 {
16657 print (vam->ofp, "%=20s", "lisp status:");
16658 }
16659
Filip Tehlar694396d2017-02-17 14:29:11 +010016660 M (SHOW_ONE_PITR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016661 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016662 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016663
16664 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016665 W (ret);
16666 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016667}
16668
Filip Tehlar694396d2017-02-17 14:29:11 +010016669#define api_show_lisp_pitr api_show_one_pitr
16670
Filip Tehlar67a99f82017-03-10 13:18:02 +010016671static int
16672api_one_use_petr (vat_main_t * vam)
16673{
16674 unformat_input_t *input = vam->input;
16675 vl_api_one_use_petr_t *mp;
16676 u8 is_add = 0;
16677 ip_address_t ip;
16678 int ret;
16679
Dave Barachb7b92992018-10-17 10:38:51 -040016680 clib_memset (&ip, 0, sizeof (ip));
Filip Tehlar67a99f82017-03-10 13:18:02 +010016681
16682 /* Parse args required to build the message */
16683 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16684 {
16685 if (unformat (input, "disable"))
16686 is_add = 0;
16687 else
16688 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
16689 {
16690 is_add = 1;
16691 ip_addr_version (&ip) = IP4;
16692 }
16693 else
16694 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
16695 {
16696 is_add = 1;
16697 ip_addr_version (&ip) = IP6;
16698 }
16699 else
16700 {
16701 errmsg ("parse error '%U'", format_unformat_error, input);
16702 return -99;
16703 }
16704 }
16705
16706 M (ONE_USE_PETR, mp);
16707
16708 mp->is_add = is_add;
16709 if (is_add)
16710 {
16711 mp->is_ip4 = ip_addr_version (&ip) == IP4 ? 1 : 0;
16712 if (mp->is_ip4)
16713 clib_memcpy (mp->address, &ip, 4);
16714 else
16715 clib_memcpy (mp->address, &ip, 16);
16716 }
16717
16718 /* send */
16719 S (mp);
16720
16721 /* wait for reply */
16722 W (ret);
16723 return ret;
16724}
16725
16726#define api_lisp_use_petr api_one_use_petr
16727
16728static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016729api_show_one_nsh_mapping (vat_main_t * vam)
16730{
16731 vl_api_show_one_use_petr_t *mp;
16732 int ret;
16733
16734 if (!vam->json_output)
16735 {
16736 print (vam->ofp, "%=20s", "local ONE NSH mapping:");
16737 }
16738
16739 M (SHOW_ONE_NSH_MAPPING, mp);
16740 /* send it... */
16741 S (mp);
16742
16743 /* Wait for a reply... */
16744 W (ret);
16745 return ret;
16746}
16747
16748static int
Filip Tehlar67a99f82017-03-10 13:18:02 +010016749api_show_one_use_petr (vat_main_t * vam)
16750{
16751 vl_api_show_one_use_petr_t *mp;
16752 int ret;
16753
16754 if (!vam->json_output)
16755 {
16756 print (vam->ofp, "%=20s", "Proxy-ETR status:");
16757 }
16758
16759 M (SHOW_ONE_USE_PETR, mp);
16760 /* send it... */
16761 S (mp);
16762
16763 /* Wait for a reply... */
16764 W (ret);
16765 return ret;
16766}
16767
16768#define api_show_lisp_use_petr api_show_one_use_petr
16769
Damjan Marion7cd468a2016-12-19 23:05:39 +010016770/**
16771 * Add/delete mapping between vni and vrf
16772 */
16773static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016774api_one_eid_table_add_del_map (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016775{
Damjan Marion7cd468a2016-12-19 23:05:39 +010016776 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016777 vl_api_one_eid_table_add_del_map_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016778 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
16779 u32 vni, vrf, bd_index;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016780 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016781
16782 /* Parse args required to build the message */
16783 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16784 {
16785 if (unformat (input, "del"))
16786 is_add = 0;
16787 else if (unformat (input, "vrf %d", &vrf))
16788 vrf_set = 1;
16789 else if (unformat (input, "bd_index %d", &bd_index))
16790 bd_index_set = 1;
16791 else if (unformat (input, "vni %d", &vni))
16792 vni_set = 1;
16793 else
16794 break;
16795 }
16796
16797 if (!vni_set || (!vrf_set && !bd_index_set))
16798 {
16799 errmsg ("missing arguments!");
16800 return -99;
16801 }
16802
16803 if (vrf_set && bd_index_set)
16804 {
16805 errmsg ("error: both vrf and bd entered!");
16806 return -99;
16807 }
16808
Filip Tehlar694396d2017-02-17 14:29:11 +010016809 M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016810
16811 mp->is_add = is_add;
16812 mp->vni = htonl (vni);
16813 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
16814 mp->is_l2 = bd_index_set;
16815
16816 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016817 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016818
16819 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016820 W (ret);
16821 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016822}
16823
Filip Tehlar694396d2017-02-17 14:29:11 +010016824#define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
16825
Damjan Marion7cd468a2016-12-19 23:05:39 +010016826uword
16827unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
16828{
16829 u32 *action = va_arg (*args, u32 *);
16830 u8 *s = 0;
16831
16832 if (unformat (input, "%s", &s))
16833 {
16834 if (!strcmp ((char *) s, "no-action"))
16835 action[0] = 0;
16836 else if (!strcmp ((char *) s, "natively-forward"))
16837 action[0] = 1;
16838 else if (!strcmp ((char *) s, "send-map-request"))
16839 action[0] = 2;
16840 else if (!strcmp ((char *) s, "drop"))
16841 action[0] = 3;
16842 else
16843 {
16844 clib_warning ("invalid action: '%s'", s);
16845 action[0] = 3;
16846 }
16847 }
16848 else
16849 return 0;
16850
16851 vec_free (s);
16852 return 1;
16853}
16854
16855/**
Filip Tehlar694396d2017-02-17 14:29:11 +010016856 * Add/del remote mapping to/from ONE control plane
Damjan Marion7cd468a2016-12-19 23:05:39 +010016857 *
16858 * @param vam vpp API test context
16859 * @return return code
16860 */
16861static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016862api_one_add_del_remote_mapping (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016863{
16864 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016865 vl_api_one_add_del_remote_mapping_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016866 u32 vni = 0;
16867 lisp_eid_vat_t _eid, *eid = &_eid;
16868 lisp_eid_vat_t _seid, *seid = &_seid;
16869 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
16870 u32 action = ~0, p, w, data_len;
16871 ip4_address_t rloc4;
16872 ip6_address_t rloc6;
Filip Tehlar05a057b2017-02-01 08:50:31 +010016873 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016874 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016875
Dave Barachb7b92992018-10-17 10:38:51 -040016876 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010016877
16878 /* Parse args required to build the message */
16879 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16880 {
16881 if (unformat (input, "del-all"))
16882 {
16883 del_all = 1;
16884 }
16885 else if (unformat (input, "del"))
16886 {
16887 is_add = 0;
16888 }
16889 else if (unformat (input, "add"))
16890 {
16891 is_add = 1;
16892 }
16893 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
16894 {
16895 eid_set = 1;
16896 }
16897 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
16898 {
16899 seid_set = 1;
16900 }
16901 else if (unformat (input, "vni %d", &vni))
16902 {
16903 ;
16904 }
16905 else if (unformat (input, "p %d w %d", &p, &w))
16906 {
16907 if (!curr_rloc)
16908 {
16909 errmsg ("No RLOC configured for setting priority/weight!");
16910 return -99;
16911 }
16912 curr_rloc->priority = p;
16913 curr_rloc->weight = w;
16914 }
16915 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
16916 {
16917 rloc.is_ip4 = 1;
16918 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
16919 vec_add1 (rlocs, rloc);
16920 curr_rloc = &rlocs[vec_len (rlocs) - 1];
16921 }
16922 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
16923 {
16924 rloc.is_ip4 = 0;
16925 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
16926 vec_add1 (rlocs, rloc);
16927 curr_rloc = &rlocs[vec_len (rlocs) - 1];
16928 }
16929 else if (unformat (input, "action %U",
16930 unformat_negative_mapping_action, &action))
16931 {
16932 ;
16933 }
16934 else
16935 {
16936 clib_warning ("parse error '%U'", format_unformat_error, input);
16937 return -99;
16938 }
16939 }
16940
16941 if (0 == eid_set)
16942 {
16943 errmsg ("missing params!");
16944 return -99;
16945 }
16946
16947 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
16948 {
16949 errmsg ("no action set for negative map-reply!");
16950 return -99;
16951 }
16952
Filip Tehlar05a057b2017-02-01 08:50:31 +010016953 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016954
Filip Tehlar694396d2017-02-17 14:29:11 +010016955 M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016956 mp->is_add = is_add;
16957 mp->vni = htonl (vni);
16958 mp->action = (u8) action;
16959 mp->is_src_dst = seid_set;
16960 mp->eid_len = eid->len;
16961 mp->seid_len = seid->len;
16962 mp->del_all = del_all;
16963 mp->eid_type = eid->type;
16964 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
16965 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
16966
16967 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
16968 clib_memcpy (mp->rlocs, rlocs, data_len);
16969 vec_free (rlocs);
16970
16971 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016972 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016973
16974 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016975 W (ret);
16976 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016977}
16978
Filip Tehlar694396d2017-02-17 14:29:11 +010016979#define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
16980
Damjan Marion7cd468a2016-12-19 23:05:39 +010016981/**
Filip Tehlar694396d2017-02-17 14:29:11 +010016982 * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010016983 * forwarding entries in data-plane accordingly.
16984 *
16985 * @param vam vpp API test context
16986 * @return return code
16987 */
16988static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016989api_one_add_del_adjacency (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016990{
16991 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016992 vl_api_one_add_del_adjacency_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016993 u32 vni = 0;
16994 ip4_address_t leid4, reid4;
16995 ip6_address_t leid6, reid6;
16996 u8 reid_mac[6] = { 0 };
16997 u8 leid_mac[6] = { 0 };
16998 u8 reid_type, leid_type;
16999 u32 leid_len = 0, reid_len = 0, len;
17000 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017001 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017002
17003 leid_type = reid_type = (u8) ~ 0;
17004
17005 /* Parse args required to build the message */
17006 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17007 {
17008 if (unformat (input, "del"))
17009 {
17010 is_add = 0;
17011 }
17012 else if (unformat (input, "add"))
17013 {
17014 is_add = 1;
17015 }
17016 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
17017 &reid4, &len))
17018 {
17019 reid_type = 0; /* ipv4 */
17020 reid_len = len;
17021 }
17022 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
17023 &reid6, &len))
17024 {
17025 reid_type = 1; /* ipv6 */
17026 reid_len = len;
17027 }
17028 else if (unformat (input, "reid %U", unformat_ethernet_address,
17029 reid_mac))
17030 {
17031 reid_type = 2; /* mac */
17032 }
17033 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
17034 &leid4, &len))
17035 {
17036 leid_type = 0; /* ipv4 */
17037 leid_len = len;
17038 }
17039 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
17040 &leid6, &len))
17041 {
17042 leid_type = 1; /* ipv6 */
17043 leid_len = len;
17044 }
17045 else if (unformat (input, "leid %U", unformat_ethernet_address,
17046 leid_mac))
17047 {
17048 leid_type = 2; /* mac */
17049 }
17050 else if (unformat (input, "vni %d", &vni))
17051 {
17052 ;
17053 }
17054 else
17055 {
17056 errmsg ("parse error '%U'", format_unformat_error, input);
17057 return -99;
17058 }
17059 }
17060
17061 if ((u8) ~ 0 == reid_type)
17062 {
17063 errmsg ("missing params!");
17064 return -99;
17065 }
17066
17067 if (leid_type != reid_type)
17068 {
17069 errmsg ("remote and local EIDs are of different types!");
17070 return -99;
17071 }
17072
Filip Tehlar694396d2017-02-17 14:29:11 +010017073 M (ONE_ADD_DEL_ADJACENCY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017074 mp->is_add = is_add;
17075 mp->vni = htonl (vni);
17076 mp->leid_len = leid_len;
17077 mp->reid_len = reid_len;
17078 mp->eid_type = reid_type;
17079
17080 switch (mp->eid_type)
17081 {
17082 case 0:
17083 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
17084 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
17085 break;
17086 case 1:
17087 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
17088 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
17089 break;
17090 case 2:
17091 clib_memcpy (mp->leid, leid_mac, 6);
17092 clib_memcpy (mp->reid, reid_mac, 6);
17093 break;
17094 default:
17095 errmsg ("unknown EID type %d!", mp->eid_type);
17096 return 0;
17097 }
17098
17099 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017100 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017101
17102 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017103 W (ret);
17104 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017105}
17106
Filip Tehlar694396d2017-02-17 14:29:11 +010017107#define api_lisp_add_del_adjacency api_one_add_del_adjacency
17108
Filip Tehlar3e7b56932017-02-21 18:28:34 +010017109uword
17110unformat_gpe_encap_mode (unformat_input_t * input, va_list * args)
17111{
17112 u32 *mode = va_arg (*args, u32 *);
17113
17114 if (unformat (input, "lisp"))
17115 *mode = 0;
17116 else if (unformat (input, "vxlan"))
17117 *mode = 1;
17118 else
17119 return 0;
17120
17121 return 1;
17122}
17123
17124static int
17125api_gpe_get_encap_mode (vat_main_t * vam)
17126{
17127 vl_api_gpe_get_encap_mode_t *mp;
17128 int ret;
17129
17130 /* Construct the API message */
17131 M (GPE_GET_ENCAP_MODE, mp);
17132
17133 /* send it... */
17134 S (mp);
17135
17136 /* Wait for a reply... */
17137 W (ret);
17138 return ret;
17139}
17140
17141static int
17142api_gpe_set_encap_mode (vat_main_t * vam)
17143{
17144 unformat_input_t *input = vam->input;
17145 vl_api_gpe_set_encap_mode_t *mp;
17146 int ret;
17147 u32 mode = 0;
17148
17149 /* Parse args required to build the message */
17150 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17151 {
17152 if (unformat (input, "%U", unformat_gpe_encap_mode, &mode))
17153 ;
17154 else
17155 break;
17156 }
17157
17158 /* Construct the API message */
17159 M (GPE_SET_ENCAP_MODE, mp);
17160
17161 mp->mode = mode;
17162
17163 /* send it... */
17164 S (mp);
17165
17166 /* Wait for a reply... */
17167 W (ret);
17168 return ret;
17169}
17170
Damjan Marion7cd468a2016-12-19 23:05:39 +010017171static int
17172api_lisp_gpe_add_del_iface (vat_main_t * vam)
17173{
17174 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010017175 vl_api_gpe_add_del_iface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017176 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
17177 u32 dp_table = 0, vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017178 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017179
17180 /* Parse args required to build the message */
17181 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17182 {
17183 if (unformat (input, "up"))
17184 {
17185 action_set = 1;
17186 is_add = 1;
17187 }
17188 else if (unformat (input, "down"))
17189 {
17190 action_set = 1;
17191 is_add = 0;
17192 }
17193 else if (unformat (input, "table_id %d", &dp_table))
17194 {
17195 dp_table_set = 1;
17196 }
17197 else if (unformat (input, "bd_id %d", &dp_table))
17198 {
17199 dp_table_set = 1;
17200 is_l2 = 1;
17201 }
17202 else if (unformat (input, "vni %d", &vni))
17203 {
17204 vni_set = 1;
17205 }
17206 else
17207 break;
17208 }
17209
17210 if (action_set == 0)
17211 {
17212 errmsg ("Action not set");
17213 return -99;
17214 }
17215 if (dp_table_set == 0 || vni_set == 0)
17216 {
17217 errmsg ("vni and dp_table must be set");
17218 return -99;
17219 }
17220
17221 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010017222 M (GPE_ADD_DEL_IFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017223
17224 mp->is_add = is_add;
Florin Corasf53a8ad2017-06-15 15:07:32 -070017225 mp->dp_table = clib_host_to_net_u32 (dp_table);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017226 mp->is_l2 = is_l2;
Florin Corasf53a8ad2017-06-15 15:07:32 -070017227 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017228
17229 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017230 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017231
17232 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017233 W (ret);
17234 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017235}
17236
Filip Tehlar1e553a02017-08-02 12:45:07 +020017237static int
Filip Tehlar7048ff12017-07-27 08:09:14 +020017238api_one_map_register_fallback_threshold (vat_main_t * vam)
17239{
17240 unformat_input_t *input = vam->input;
17241 vl_api_one_map_register_fallback_threshold_t *mp;
17242 u32 value = 0;
17243 u8 is_set = 0;
17244 int ret;
17245
17246 /* Parse args required to build the message */
17247 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17248 {
17249 if (unformat (input, "%u", &value))
17250 is_set = 1;
17251 else
17252 {
17253 clib_warning ("parse error '%U'", format_unformat_error, input);
17254 return -99;
17255 }
17256 }
17257
17258 if (!is_set)
17259 {
17260 errmsg ("fallback threshold value is missing!");
17261 return -99;
17262 }
17263
17264 M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
17265 mp->value = clib_host_to_net_u32 (value);
17266
17267 /* send it... */
17268 S (mp);
17269
17270 /* Wait for a reply... */
17271 W (ret);
17272 return ret;
17273}
17274
17275static int
17276api_show_one_map_register_fallback_threshold (vat_main_t * vam)
17277{
17278 vl_api_show_one_map_register_fallback_threshold_t *mp;
17279 int ret;
17280
17281 M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
17282
17283 /* send it... */
17284 S (mp);
17285
17286 /* Wait for a reply... */
17287 W (ret);
17288 return ret;
17289}
17290
Filip Tehlara4980b82017-09-27 14:32:02 +020017291uword
17292unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args)
17293{
17294 u32 *proto = va_arg (*args, u32 *);
17295
17296 if (unformat (input, "udp"))
17297 *proto = 1;
17298 else if (unformat (input, "api"))
17299 *proto = 2;
17300 else
17301 return 0;
17302
17303 return 1;
17304}
17305
17306static int
17307api_one_set_transport_protocol (vat_main_t * vam)
17308{
17309 unformat_input_t *input = vam->input;
17310 vl_api_one_set_transport_protocol_t *mp;
17311 u8 is_set = 0;
17312 u32 protocol = 0;
17313 int ret;
17314
17315 /* Parse args required to build the message */
17316 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17317 {
17318 if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol))
17319 is_set = 1;
17320 else
17321 {
17322 clib_warning ("parse error '%U'", format_unformat_error, input);
17323 return -99;
17324 }
17325 }
17326
17327 if (!is_set)
17328 {
17329 errmsg ("Transport protocol missing!");
17330 return -99;
17331 }
17332
17333 M (ONE_SET_TRANSPORT_PROTOCOL, mp);
17334 mp->protocol = (u8) protocol;
17335
17336 /* send it... */
17337 S (mp);
17338
17339 /* Wait for a reply... */
17340 W (ret);
17341 return ret;
17342}
17343
17344static int
17345api_one_get_transport_protocol (vat_main_t * vam)
17346{
17347 vl_api_one_get_transport_protocol_t *mp;
17348 int ret;
17349
17350 M (ONE_GET_TRANSPORT_PROTOCOL, mp);
17351
17352 /* send it... */
17353 S (mp);
17354
17355 /* Wait for a reply... */
17356 W (ret);
17357 return ret;
17358}
17359
Filip Tehlar7048ff12017-07-27 08:09:14 +020017360static int
Filip Tehlar1e553a02017-08-02 12:45:07 +020017361api_one_map_register_set_ttl (vat_main_t * vam)
17362{
17363 unformat_input_t *input = vam->input;
17364 vl_api_one_map_register_set_ttl_t *mp;
17365 u32 ttl = 0;
17366 u8 is_set = 0;
17367 int ret;
17368
17369 /* Parse args required to build the message */
17370 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17371 {
17372 if (unformat (input, "%u", &ttl))
17373 is_set = 1;
17374 else
17375 {
17376 clib_warning ("parse error '%U'", format_unformat_error, input);
17377 return -99;
17378 }
17379 }
17380
17381 if (!is_set)
17382 {
17383 errmsg ("TTL value missing!");
17384 return -99;
17385 }
17386
17387 M (ONE_MAP_REGISTER_SET_TTL, mp);
17388 mp->ttl = clib_host_to_net_u32 (ttl);
17389
17390 /* send it... */
17391 S (mp);
17392
17393 /* Wait for a reply... */
17394 W (ret);
17395 return ret;
17396}
17397
17398static int
17399api_show_one_map_register_ttl (vat_main_t * vam)
17400{
17401 vl_api_show_one_map_register_ttl_t *mp;
17402 int ret;
17403
17404 M (SHOW_ONE_MAP_REGISTER_TTL, mp);
17405
17406 /* send it... */
17407 S (mp);
17408
17409 /* Wait for a reply... */
17410 W (ret);
17411 return ret;
17412}
17413
Damjan Marion7cd468a2016-12-19 23:05:39 +010017414/**
Filip Tehlar694396d2017-02-17 14:29:11 +010017415 * Add/del map request itr rlocs from ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010017416 *
17417 * @param vam vpp API test context
17418 * @return return code
17419 */
17420static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017421api_one_add_del_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017422{
17423 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017424 vl_api_one_add_del_map_request_itr_rlocs_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017425 u8 *locator_set_name = 0;
17426 u8 locator_set_name_set = 0;
17427 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017428 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017429
17430 /* Parse args required to build the message */
17431 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17432 {
17433 if (unformat (input, "del"))
17434 {
17435 is_add = 0;
17436 }
17437 else if (unformat (input, "%_%v%_", &locator_set_name))
17438 {
17439 locator_set_name_set = 1;
17440 }
17441 else
17442 {
17443 clib_warning ("parse error '%U'", format_unformat_error, input);
17444 return -99;
17445 }
17446 }
17447
17448 if (is_add && !locator_set_name_set)
17449 {
17450 errmsg ("itr-rloc is not set!");
17451 return -99;
17452 }
17453
17454 if (is_add && vec_len (locator_set_name) > 64)
17455 {
17456 errmsg ("itr-rloc locator-set name too long");
17457 vec_free (locator_set_name);
17458 return -99;
17459 }
17460
Filip Tehlar694396d2017-02-17 14:29:11 +010017461 M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017462 mp->is_add = is_add;
17463 if (is_add)
17464 {
17465 clib_memcpy (mp->locator_set_name, locator_set_name,
17466 vec_len (locator_set_name));
17467 }
17468 else
17469 {
Dave Barachb7b92992018-10-17 10:38:51 -040017470 clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017471 }
17472 vec_free (locator_set_name);
17473
17474 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017475 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017476
17477 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017478 W (ret);
17479 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017480}
17481
Filip Tehlar694396d2017-02-17 14:29:11 +010017482#define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs
17483
Damjan Marion7cd468a2016-12-19 23:05:39 +010017484static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017485api_one_locator_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017486{
17487 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017488 vl_api_one_locator_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017489 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017490 u8 is_index_set = 0, is_name_set = 0;
17491 u8 *ls_name = 0;
17492 u32 ls_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017493 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017494
17495 /* Parse args required to build the message */
17496 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17497 {
17498 if (unformat (input, "ls_name %_%v%_", &ls_name))
17499 {
17500 is_name_set = 1;
17501 }
17502 else if (unformat (input, "ls_index %d", &ls_index))
17503 {
17504 is_index_set = 1;
17505 }
17506 else
17507 {
17508 errmsg ("parse error '%U'", format_unformat_error, input);
17509 return -99;
17510 }
17511 }
17512
17513 if (!is_index_set && !is_name_set)
17514 {
17515 errmsg ("error: expected one of index or name!");
17516 return -99;
17517 }
17518
17519 if (is_index_set && is_name_set)
17520 {
17521 errmsg ("error: only one param expected!");
17522 return -99;
17523 }
17524
17525 if (vec_len (ls_name) > 62)
17526 {
17527 errmsg ("error: locator set name too long!");
17528 return -99;
17529 }
17530
17531 if (!vam->json_output)
17532 {
17533 print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
17534 }
17535
Filip Tehlar694396d2017-02-17 14:29:11 +010017536 M (ONE_LOCATOR_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017537 mp->is_index_set = is_index_set;
17538
17539 if (is_index_set)
17540 mp->ls_index = clib_host_to_net_u32 (ls_index);
17541 else
17542 {
17543 vec_add1 (ls_name, 0);
17544 strncpy ((char *) mp->ls_name, (char *) ls_name,
17545 sizeof (mp->ls_name) - 1);
17546 }
17547
17548 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017549 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017550
17551 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017552 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017553 S (mp_ping);
17554
Damjan Marion7cd468a2016-12-19 23:05:39 +010017555 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017556 W (ret);
17557 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017558}
17559
Filip Tehlar694396d2017-02-17 14:29:11 +010017560#define api_lisp_locator_dump api_one_locator_dump
17561
Damjan Marion7cd468a2016-12-19 23:05:39 +010017562static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017563api_one_locator_set_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017564{
Filip Tehlar694396d2017-02-17 14:29:11 +010017565 vl_api_one_locator_set_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017566 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017567 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017568 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017569 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017570
17571 /* Parse args required to build the message */
17572 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17573 {
17574 if (unformat (input, "local"))
17575 {
17576 filter = 1;
17577 }
17578 else if (unformat (input, "remote"))
17579 {
17580 filter = 2;
17581 }
17582 else
17583 {
17584 errmsg ("parse error '%U'", format_unformat_error, input);
17585 return -99;
17586 }
17587 }
17588
17589 if (!vam->json_output)
17590 {
17591 print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
17592 }
17593
Filip Tehlar694396d2017-02-17 14:29:11 +010017594 M (ONE_LOCATOR_SET_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017595
17596 mp->filter = filter;
17597
17598 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017599 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017600
17601 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017602 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017603 S (mp_ping);
17604
Damjan Marion7cd468a2016-12-19 23:05:39 +010017605 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017606 W (ret);
17607 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017608}
17609
Filip Tehlar694396d2017-02-17 14:29:11 +010017610#define api_lisp_locator_set_dump api_one_locator_set_dump
17611
Damjan Marion7cd468a2016-12-19 23:05:39 +010017612static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017613api_one_eid_table_map_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017614{
17615 u8 is_l2 = 0;
17616 u8 mode_set = 0;
17617 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017618 vl_api_one_eid_table_map_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017619 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017620 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017621
17622 /* Parse args required to build the message */
17623 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17624 {
17625 if (unformat (input, "l2"))
17626 {
17627 is_l2 = 1;
17628 mode_set = 1;
17629 }
17630 else if (unformat (input, "l3"))
17631 {
17632 is_l2 = 0;
17633 mode_set = 1;
17634 }
17635 else
17636 {
17637 errmsg ("parse error '%U'", format_unformat_error, input);
17638 return -99;
17639 }
17640 }
17641
17642 if (!mode_set)
17643 {
17644 errmsg ("expected one of 'l2' or 'l3' parameter!");
17645 return -99;
17646 }
17647
17648 if (!vam->json_output)
17649 {
17650 print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
17651 }
17652
Filip Tehlar694396d2017-02-17 14:29:11 +010017653 M (ONE_EID_TABLE_MAP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017654 mp->is_l2 = is_l2;
17655
17656 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017657 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017658
17659 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017660 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017661 S (mp_ping);
17662
Damjan Marion7cd468a2016-12-19 23:05:39 +010017663 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017664 W (ret);
17665 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017666}
17667
Filip Tehlar694396d2017-02-17 14:29:11 +010017668#define api_lisp_eid_table_map_dump api_one_eid_table_map_dump
17669
Damjan Marion7cd468a2016-12-19 23:05:39 +010017670static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017671api_one_eid_table_vni_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017672{
Filip Tehlar694396d2017-02-17 14:29:11 +010017673 vl_api_one_eid_table_vni_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017674 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017675 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017676
17677 if (!vam->json_output)
17678 {
17679 print (vam->ofp, "VNI");
17680 }
17681
Filip Tehlar694396d2017-02-17 14:29:11 +010017682 M (ONE_EID_TABLE_VNI_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017683
17684 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017685 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017686
17687 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017688 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017689 S (mp_ping);
17690
Damjan Marion7cd468a2016-12-19 23:05:39 +010017691 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017692 W (ret);
17693 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017694}
17695
Filip Tehlar694396d2017-02-17 14:29:11 +010017696#define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump
17697
Damjan Marion7cd468a2016-12-19 23:05:39 +010017698static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017699api_one_eid_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017700{
17701 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017702 vl_api_one_eid_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017703 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017704 struct in_addr ip4;
17705 struct in6_addr ip6;
17706 u8 mac[6];
17707 u8 eid_type = ~0, eid_set = 0;
17708 u32 prefix_length = ~0, t, vni = 0;
17709 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017710 int ret;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017711 lisp_nsh_api_t nsh;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017712
17713 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17714 {
17715 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
17716 {
17717 eid_set = 1;
17718 eid_type = 0;
17719 prefix_length = t;
17720 }
17721 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
17722 {
17723 eid_set = 1;
17724 eid_type = 1;
17725 prefix_length = t;
17726 }
17727 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
17728 {
17729 eid_set = 1;
17730 eid_type = 2;
17731 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017732 else if (unformat (i, "eid %U", unformat_nsh_address, &nsh))
17733 {
17734 eid_set = 1;
17735 eid_type = 3;
17736 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010017737 else if (unformat (i, "vni %d", &t))
17738 {
17739 vni = t;
17740 }
17741 else if (unformat (i, "local"))
17742 {
17743 filter = 1;
17744 }
17745 else if (unformat (i, "remote"))
17746 {
17747 filter = 2;
17748 }
17749 else
17750 {
17751 errmsg ("parse error '%U'", format_unformat_error, i);
17752 return -99;
17753 }
17754 }
17755
17756 if (!vam->json_output)
17757 {
17758 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
17759 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
17760 }
17761
Filip Tehlar694396d2017-02-17 14:29:11 +010017762 M (ONE_EID_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017763
17764 mp->filter = filter;
17765 if (eid_set)
17766 {
17767 mp->eid_set = 1;
17768 mp->vni = htonl (vni);
17769 mp->eid_type = eid_type;
17770 switch (eid_type)
17771 {
17772 case 0:
17773 mp->prefix_length = prefix_length;
17774 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
17775 break;
17776 case 1:
17777 mp->prefix_length = prefix_length;
17778 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
17779 break;
17780 case 2:
17781 clib_memcpy (mp->eid, mac, sizeof (mac));
17782 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017783 case 3:
17784 clib_memcpy (mp->eid, &nsh, sizeof (nsh));
17785 break;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017786 default:
17787 errmsg ("unknown EID type %d!", eid_type);
17788 return -99;
17789 }
17790 }
17791
17792 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017793 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017794
17795 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017796 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017797 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017798
17799 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017800 W (ret);
17801 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017802}
17803
Filip Tehlar694396d2017-02-17 14:29:11 +010017804#define api_lisp_eid_table_dump api_one_eid_table_dump
17805
Damjan Marion7cd468a2016-12-19 23:05:39 +010017806static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017807api_lisp_gpe_fwd_entries_get (vat_main_t * vam)
17808{
17809 unformat_input_t *i = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010017810 vl_api_gpe_fwd_entries_get_t *mp;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017811 u8 vni_set = 0;
17812 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017813 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017814
17815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17816 {
17817 if (unformat (i, "vni %d", &vni))
17818 {
17819 vni_set = 1;
17820 }
17821 else
17822 {
17823 errmsg ("parse error '%U'", format_unformat_error, i);
17824 return -99;
17825 }
17826 }
17827
17828 if (!vni_set)
17829 {
17830 errmsg ("vni not set!");
17831 return -99;
17832 }
17833
17834 if (!vam->json_output)
17835 {
17836 print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table",
17837 "leid", "reid");
17838 }
17839
Filip Tehlar82786c42017-02-20 15:20:37 +010017840 M (GPE_FWD_ENTRIES_GET, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017841 mp->vni = clib_host_to_net_u32 (vni);
17842
17843 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017844 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017845
17846 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017847 W (ret);
17848 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017849}
17850
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017851#define vl_api_gpe_native_fwd_rpaths_get_reply_t_endian vl_noop_handler
17852#define vl_api_gpe_native_fwd_rpaths_get_reply_t_print vl_noop_handler
Filip Tehlar0eb874e2017-05-18 14:23:32 +020017853#define vl_api_gpe_fwd_entry_vnis_get_reply_t_endian vl_noop_handler
17854#define vl_api_gpe_fwd_entry_vnis_get_reply_t_print vl_noop_handler
Filip Tehlar82786c42017-02-20 15:20:37 +010017855#define vl_api_gpe_fwd_entries_get_reply_t_endian vl_noop_handler
17856#define vl_api_gpe_fwd_entries_get_reply_t_print vl_noop_handler
17857#define vl_api_gpe_fwd_entry_path_details_t_endian vl_noop_handler
17858#define vl_api_gpe_fwd_entry_path_details_t_print vl_noop_handler
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017859
17860static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017861api_one_adjacencies_get (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017862{
17863 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017864 vl_api_one_adjacencies_get_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017865 u8 vni_set = 0;
17866 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017867 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017868
17869 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17870 {
17871 if (unformat (i, "vni %d", &vni))
17872 {
17873 vni_set = 1;
17874 }
17875 else
17876 {
17877 errmsg ("parse error '%U'", format_unformat_error, i);
17878 return -99;
17879 }
17880 }
17881
17882 if (!vni_set)
17883 {
17884 errmsg ("vni not set!");
17885 return -99;
17886 }
17887
17888 if (!vam->json_output)
17889 {
17890 print (vam->ofp, "%s %40s", "leid", "reid");
17891 }
17892
Filip Tehlar694396d2017-02-17 14:29:11 +010017893 M (ONE_ADJACENCIES_GET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017894 mp->vni = clib_host_to_net_u32 (vni);
17895
17896 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017897 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017898
17899 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017900 W (ret);
17901 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017902}
17903
Filip Tehlar694396d2017-02-17 14:29:11 +010017904#define api_lisp_adjacencies_get api_one_adjacencies_get
17905
Damjan Marion7cd468a2016-12-19 23:05:39 +010017906static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017907api_gpe_native_fwd_rpaths_get (vat_main_t * vam)
17908{
17909 unformat_input_t *i = vam->input;
17910 vl_api_gpe_native_fwd_rpaths_get_t *mp;
17911 int ret;
17912 u8 ip_family_set = 0, is_ip4 = 1;
17913
17914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17915 {
17916 if (unformat (i, "ip4"))
17917 {
17918 ip_family_set = 1;
17919 is_ip4 = 1;
17920 }
17921 else if (unformat (i, "ip6"))
17922 {
17923 ip_family_set = 1;
17924 is_ip4 = 0;
17925 }
17926 else
17927 {
17928 errmsg ("parse error '%U'", format_unformat_error, i);
17929 return -99;
17930 }
17931 }
17932
17933 if (!ip_family_set)
17934 {
17935 errmsg ("ip family not set!");
17936 return -99;
17937 }
17938
17939 M (GPE_NATIVE_FWD_RPATHS_GET, mp);
17940 mp->is_ip4 = is_ip4;
17941
17942 /* send it... */
17943 S (mp);
17944
17945 /* Wait for a reply... */
17946 W (ret);
17947 return ret;
17948}
17949
17950static int
Filip Tehlar0eb874e2017-05-18 14:23:32 +020017951api_gpe_fwd_entry_vnis_get (vat_main_t * vam)
17952{
17953 vl_api_gpe_fwd_entry_vnis_get_t *mp;
17954 int ret;
17955
17956 if (!vam->json_output)
17957 {
17958 print (vam->ofp, "VNIs");
17959 }
17960
17961 M (GPE_FWD_ENTRY_VNIS_GET, mp);
17962
17963 /* send it... */
17964 S (mp);
17965
17966 /* Wait for a reply... */
17967 W (ret);
17968 return ret;
17969}
17970
17971static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017972api_gpe_add_del_native_fwd_rpath (vat_main_t * vam)
17973{
17974 unformat_input_t *i = vam->input;
17975 vl_api_gpe_add_del_native_fwd_rpath_t *mp;
17976 int ret = 0;
17977 u8 is_add = 1, ip_set = 0, is_ip4 = 1;
17978 struct in_addr ip4;
17979 struct in6_addr ip6;
17980 u32 table_id = 0, nh_sw_if_index = ~0;
17981
Dave Barachb7b92992018-10-17 10:38:51 -040017982 clib_memset (&ip4, 0, sizeof (ip4));
17983 clib_memset (&ip6, 0, sizeof (ip6));
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017984
17985 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17986 {
17987 if (unformat (i, "del"))
17988 is_add = 0;
17989 else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4,
17990 api_unformat_sw_if_index, vam, &nh_sw_if_index))
17991 {
17992 ip_set = 1;
17993 is_ip4 = 1;
17994 }
17995 else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6,
17996 api_unformat_sw_if_index, vam, &nh_sw_if_index))
17997 {
17998 ip_set = 1;
17999 is_ip4 = 0;
18000 }
18001 else if (unformat (i, "via %U", unformat_ip4_address, &ip4))
18002 {
18003 ip_set = 1;
18004 is_ip4 = 1;
18005 nh_sw_if_index = ~0;
18006 }
18007 else if (unformat (i, "via %U", unformat_ip6_address, &ip6))
18008 {
18009 ip_set = 1;
18010 is_ip4 = 0;
18011 nh_sw_if_index = ~0;
18012 }
18013 else if (unformat (i, "table %d", &table_id))
18014 ;
18015 else
18016 {
18017 errmsg ("parse error '%U'", format_unformat_error, i);
18018 return -99;
18019 }
18020 }
18021
18022 if (!ip_set)
18023 {
18024 errmsg ("nh addr not set!");
18025 return -99;
18026 }
18027
18028 M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp);
18029 mp->is_add = is_add;
18030 mp->table_id = clib_host_to_net_u32 (table_id);
18031 mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index);
18032 mp->is_ip4 = is_ip4;
18033 if (is_ip4)
18034 clib_memcpy (mp->nh_addr, &ip4, sizeof (ip4));
18035 else
18036 clib_memcpy (mp->nh_addr, &ip6, sizeof (ip6));
18037
18038 /* send it... */
18039 S (mp);
18040
18041 /* Wait for a reply... */
18042 W (ret);
18043 return ret;
18044}
18045
18046static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018047api_one_map_server_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018048{
Filip Tehlar694396d2017-02-17 14:29:11 +010018049 vl_api_one_map_server_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018050 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018051 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018052
18053 if (!vam->json_output)
18054 {
18055 print (vam->ofp, "%=20s", "Map server");
18056 }
18057
Filip Tehlar694396d2017-02-17 14:29:11 +010018058 M (ONE_MAP_SERVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018059 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018060 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018061
18062 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018063 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018064 S (mp_ping);
18065
Damjan Marion7cd468a2016-12-19 23:05:39 +010018066 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018067 W (ret);
18068 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018069}
18070
Filip Tehlar694396d2017-02-17 14:29:11 +010018071#define api_lisp_map_server_dump api_one_map_server_dump
18072
Damjan Marion7cd468a2016-12-19 23:05:39 +010018073static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018074api_one_map_resolver_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018075{
Filip Tehlar694396d2017-02-17 14:29:11 +010018076 vl_api_one_map_resolver_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018077 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018078 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018079
18080 if (!vam->json_output)
18081 {
18082 print (vam->ofp, "%=20s", "Map resolver");
18083 }
18084
Filip Tehlar694396d2017-02-17 14:29:11 +010018085 M (ONE_MAP_RESOLVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018086 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018087 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018088
18089 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018090 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018091 S (mp_ping);
18092
Damjan Marion7cd468a2016-12-19 23:05:39 +010018093 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018094 W (ret);
18095 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018096}
18097
Filip Tehlar694396d2017-02-17 14:29:11 +010018098#define api_lisp_map_resolver_dump api_one_map_resolver_dump
18099
Damjan Marion7cd468a2016-12-19 23:05:39 +010018100static int
Filip Tehlar21511912017-04-07 10:41:42 +020018101api_one_stats_flush (vat_main_t * vam)
18102{
18103 vl_api_one_stats_flush_t *mp;
18104 int ret = 0;
18105
18106 M (ONE_STATS_FLUSH, mp);
18107 S (mp);
18108 W (ret);
18109 return ret;
18110}
18111
18112static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010018113api_one_stats_dump (vat_main_t * vam)
18114{
18115 vl_api_one_stats_dump_t *mp;
18116 vl_api_control_ping_t *mp_ping;
18117 int ret;
18118
18119 M (ONE_STATS_DUMP, mp);
18120 /* send it... */
18121 S (mp);
18122
18123 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018124 MPING (CONTROL_PING, mp_ping);
Filip Tehlar4868ff62017-03-09 16:48:39 +010018125 S (mp_ping);
18126
18127 /* Wait for a reply... */
18128 W (ret);
18129 return ret;
18130}
18131
18132static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018133api_show_one_status (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018134{
Filip Tehlar694396d2017-02-17 14:29:11 +010018135 vl_api_show_one_status_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018136 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018137
18138 if (!vam->json_output)
18139 {
Filip Tehlar694396d2017-02-17 14:29:11 +010018140 print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
Damjan Marion7cd468a2016-12-19 23:05:39 +010018141 }
18142
Filip Tehlar694396d2017-02-17 14:29:11 +010018143 M (SHOW_ONE_STATUS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018144 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018145 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018146 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018147 W (ret);
18148 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018149}
18150
Filip Tehlar694396d2017-02-17 14:29:11 +010018151#define api_show_lisp_status api_show_one_status
18152
Damjan Marion7cd468a2016-12-19 23:05:39 +010018153static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018154api_lisp_gpe_fwd_entry_path_dump (vat_main_t * vam)
18155{
Filip Tehlar82786c42017-02-20 15:20:37 +010018156 vl_api_gpe_fwd_entry_path_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018157 vl_api_control_ping_t *mp_ping;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018158 unformat_input_t *i = vam->input;
18159 u32 fwd_entry_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018160 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018161
18162 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18163 {
18164 if (unformat (i, "index %d", &fwd_entry_index))
18165 ;
18166 else
18167 break;
18168 }
18169
18170 if (~0 == fwd_entry_index)
18171 {
18172 errmsg ("no index specified!");
18173 return -99;
18174 }
18175
18176 if (!vam->json_output)
18177 {
18178 print (vam->ofp, "first line");
18179 }
18180
Filip Tehlar82786c42017-02-20 15:20:37 +010018181 M (GPE_FWD_ENTRY_PATH_DUMP, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018182
18183 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018184 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018185 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018186 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018187 S (mp_ping);
18188
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018189 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018190 W (ret);
18191 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018192}
18193
18194static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018195api_one_get_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018196{
Filip Tehlar694396d2017-02-17 14:29:11 +010018197 vl_api_one_get_map_request_itr_rlocs_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018198 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018199
18200 if (!vam->json_output)
18201 {
18202 print (vam->ofp, "%=20s", "itr-rlocs:");
18203 }
18204
Filip Tehlar694396d2017-02-17 14:29:11 +010018205 M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018206 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018207 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018208 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018209 W (ret);
18210 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018211}
18212
Filip Tehlar694396d2017-02-17 14:29:11 +010018213#define api_lisp_get_map_request_itr_rlocs api_one_get_map_request_itr_rlocs
18214
Damjan Marion7cd468a2016-12-19 23:05:39 +010018215static int
18216api_af_packet_create (vat_main_t * vam)
18217{
18218 unformat_input_t *i = vam->input;
18219 vl_api_af_packet_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018220 u8 *host_if_name = 0;
18221 u8 hw_addr[6];
18222 u8 random_hw_addr = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018223 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018224
Dave Barachb7b92992018-10-17 10:38:51 -040018225 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018226
18227 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18228 {
18229 if (unformat (i, "name %s", &host_if_name))
18230 vec_add1 (host_if_name, 0);
18231 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
18232 random_hw_addr = 0;
18233 else
18234 break;
18235 }
18236
18237 if (!vec_len (host_if_name))
18238 {
18239 errmsg ("host-interface name must be specified");
18240 return -99;
18241 }
18242
18243 if (vec_len (host_if_name) > 64)
18244 {
18245 errmsg ("host-interface name too long");
18246 return -99;
18247 }
18248
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018249 M (AF_PACKET_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018250
18251 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
18252 clib_memcpy (mp->hw_addr, hw_addr, 6);
18253 mp->use_random_hw_addr = random_hw_addr;
18254 vec_free (host_if_name);
18255
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018256 S (mp);
Dave Baracha1a093d2017-03-02 13:13:23 -050018257
18258 /* *INDENT-OFF* */
18259 W2 (ret,
18260 ({
18261 if (ret == 0)
18262 fprintf (vam->ofp ? vam->ofp : stderr,
18263 " new sw_if_index = %d\n", vam->sw_if_index);
18264 }));
18265 /* *INDENT-ON* */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018266 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018267}
18268
18269static int
18270api_af_packet_delete (vat_main_t * vam)
18271{
18272 unformat_input_t *i = vam->input;
18273 vl_api_af_packet_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018274 u8 *host_if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018275 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018276
18277 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18278 {
18279 if (unformat (i, "name %s", &host_if_name))
18280 vec_add1 (host_if_name, 0);
18281 else
18282 break;
18283 }
18284
18285 if (!vec_len (host_if_name))
18286 {
18287 errmsg ("host-interface name must be specified");
18288 return -99;
18289 }
18290
18291 if (vec_len (host_if_name) > 64)
18292 {
18293 errmsg ("host-interface name too long");
18294 return -99;
18295 }
18296
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018297 M (AF_PACKET_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018298
18299 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
18300 vec_free (host_if_name);
18301
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018302 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018303 W (ret);
18304 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018305}
18306
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020018307static void vl_api_af_packet_details_t_handler
18308 (vl_api_af_packet_details_t * mp)
18309{
18310 vat_main_t *vam = &vat_main;
18311
18312 print (vam->ofp, "%-16s %d",
18313 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
18314}
18315
18316static void vl_api_af_packet_details_t_handler_json
18317 (vl_api_af_packet_details_t * mp)
18318{
18319 vat_main_t *vam = &vat_main;
18320 vat_json_node_t *node = NULL;
18321
18322 if (VAT_JSON_ARRAY != vam->json_tree.type)
18323 {
18324 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18325 vat_json_init_array (&vam->json_tree);
18326 }
18327 node = vat_json_array_add (&vam->json_tree);
18328
18329 vat_json_init_object (node);
18330 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
18331 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
18332}
18333
18334static int
18335api_af_packet_dump (vat_main_t * vam)
18336{
18337 vl_api_af_packet_dump_t *mp;
18338 vl_api_control_ping_t *mp_ping;
18339 int ret;
18340
18341 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
18342 /* Get list of tap interfaces */
18343 M (AF_PACKET_DUMP, mp);
18344 S (mp);
18345
18346 /* Use a control ping for synchronization */
18347 MPING (CONTROL_PING, mp_ping);
18348 S (mp_ping);
18349
18350 W (ret);
18351 return ret;
18352}
18353
Damjan Marion7cd468a2016-12-19 23:05:39 +010018354static int
18355api_policer_add_del (vat_main_t * vam)
18356{
18357 unformat_input_t *i = vam->input;
18358 vl_api_policer_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018359 u8 is_add = 1;
18360 u8 *name = 0;
18361 u32 cir = 0;
18362 u32 eir = 0;
18363 u64 cb = 0;
18364 u64 eb = 0;
18365 u8 rate_type = 0;
18366 u8 round_type = 0;
18367 u8 type = 0;
18368 u8 color_aware = 0;
18369 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018370 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018371
18372 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
18373 conform_action.dscp = 0;
18374 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
18375 exceed_action.dscp = 0;
18376 violate_action.action_type = SSE2_QOS_ACTION_DROP;
18377 violate_action.dscp = 0;
18378
18379 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18380 {
18381 if (unformat (i, "del"))
18382 is_add = 0;
18383 else if (unformat (i, "name %s", &name))
18384 vec_add1 (name, 0);
18385 else if (unformat (i, "cir %u", &cir))
18386 ;
18387 else if (unformat (i, "eir %u", &eir))
18388 ;
18389 else if (unformat (i, "cb %u", &cb))
18390 ;
18391 else if (unformat (i, "eb %u", &eb))
18392 ;
18393 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
18394 &rate_type))
18395 ;
18396 else if (unformat (i, "round_type %U", unformat_policer_round_type,
18397 &round_type))
18398 ;
18399 else if (unformat (i, "type %U", unformat_policer_type, &type))
18400 ;
18401 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
18402 &conform_action))
18403 ;
18404 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
18405 &exceed_action))
18406 ;
18407 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
18408 &violate_action))
18409 ;
18410 else if (unformat (i, "color-aware"))
18411 color_aware = 1;
18412 else
18413 break;
18414 }
18415
18416 if (!vec_len (name))
18417 {
18418 errmsg ("policer name must be specified");
18419 return -99;
18420 }
18421
18422 if (vec_len (name) > 64)
18423 {
18424 errmsg ("policer name too long");
18425 return -99;
18426 }
18427
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018428 M (POLICER_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018429
18430 clib_memcpy (mp->name, name, vec_len (name));
18431 vec_free (name);
18432 mp->is_add = is_add;
Neale Rannsd91c1db2017-07-31 02:30:50 -070018433 mp->cir = ntohl (cir);
18434 mp->eir = ntohl (eir);
18435 mp->cb = clib_net_to_host_u64 (cb);
18436 mp->eb = clib_net_to_host_u64 (eb);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018437 mp->rate_type = rate_type;
18438 mp->round_type = round_type;
18439 mp->type = type;
18440 mp->conform_action_type = conform_action.action_type;
18441 mp->conform_dscp = conform_action.dscp;
18442 mp->exceed_action_type = exceed_action.action_type;
18443 mp->exceed_dscp = exceed_action.dscp;
18444 mp->violate_action_type = violate_action.action_type;
18445 mp->violate_dscp = violate_action.dscp;
18446 mp->color_aware = color_aware;
18447
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018448 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018449 W (ret);
18450 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018451}
18452
18453static int
18454api_policer_dump (vat_main_t * vam)
18455{
18456 unformat_input_t *i = vam->input;
18457 vl_api_policer_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018458 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018459 u8 *match_name = 0;
18460 u8 match_name_valid = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018461 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018462
18463 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18464 {
18465 if (unformat (i, "name %s", &match_name))
18466 {
18467 vec_add1 (match_name, 0);
18468 match_name_valid = 1;
18469 }
18470 else
18471 break;
18472 }
18473
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018474 M (POLICER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018475 mp->match_name_valid = match_name_valid;
18476 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
18477 vec_free (match_name);
18478 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018479 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018480
18481 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018482 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018483 S (mp_ping);
18484
Damjan Marion7cd468a2016-12-19 23:05:39 +010018485 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018486 W (ret);
18487 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018488}
18489
18490static int
18491api_policer_classify_set_interface (vat_main_t * vam)
18492{
18493 unformat_input_t *i = vam->input;
18494 vl_api_policer_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018495 u32 sw_if_index;
18496 int sw_if_index_set;
18497 u32 ip4_table_index = ~0;
18498 u32 ip6_table_index = ~0;
18499 u32 l2_table_index = ~0;
18500 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018501 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018502
18503 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18504 {
18505 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18506 sw_if_index_set = 1;
18507 else if (unformat (i, "sw_if_index %d", &sw_if_index))
18508 sw_if_index_set = 1;
18509 else if (unformat (i, "del"))
18510 is_add = 0;
18511 else if (unformat (i, "ip4-table %d", &ip4_table_index))
18512 ;
18513 else if (unformat (i, "ip6-table %d", &ip6_table_index))
18514 ;
18515 else if (unformat (i, "l2-table %d", &l2_table_index))
18516 ;
18517 else
18518 {
18519 clib_warning ("parse error '%U'", format_unformat_error, i);
18520 return -99;
18521 }
18522 }
18523
18524 if (sw_if_index_set == 0)
18525 {
18526 errmsg ("missing interface name or sw_if_index");
18527 return -99;
18528 }
18529
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018530 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018531
18532 mp->sw_if_index = ntohl (sw_if_index);
18533 mp->ip4_table_index = ntohl (ip4_table_index);
18534 mp->ip6_table_index = ntohl (ip6_table_index);
18535 mp->l2_table_index = ntohl (l2_table_index);
18536 mp->is_add = is_add;
18537
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018538 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018539 W (ret);
18540 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018541}
18542
18543static int
18544api_policer_classify_dump (vat_main_t * vam)
18545{
18546 unformat_input_t *i = vam->input;
18547 vl_api_policer_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018548 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018549 u8 type = POLICER_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018550 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018551
18552 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
18553 ;
18554 else
18555 {
18556 errmsg ("classify table type must be specified");
18557 return -99;
18558 }
18559
18560 if (!vam->json_output)
18561 {
18562 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
18563 }
18564
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018565 M (POLICER_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018566 mp->type = type;
18567 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018568 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018569
18570 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018571 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018572 S (mp_ping);
18573
Damjan Marion7cd468a2016-12-19 23:05:39 +010018574 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018575 W (ret);
18576 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018577}
18578
18579static int
18580api_netmap_create (vat_main_t * vam)
18581{
18582 unformat_input_t *i = vam->input;
18583 vl_api_netmap_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018584 u8 *if_name = 0;
18585 u8 hw_addr[6];
18586 u8 random_hw_addr = 1;
18587 u8 is_pipe = 0;
18588 u8 is_master = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018589 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018590
Dave Barachb7b92992018-10-17 10:38:51 -040018591 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018592
18593 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18594 {
18595 if (unformat (i, "name %s", &if_name))
18596 vec_add1 (if_name, 0);
18597 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
18598 random_hw_addr = 0;
18599 else if (unformat (i, "pipe"))
18600 is_pipe = 1;
18601 else if (unformat (i, "master"))
18602 is_master = 1;
18603 else if (unformat (i, "slave"))
18604 is_master = 0;
18605 else
18606 break;
18607 }
18608
18609 if (!vec_len (if_name))
18610 {
18611 errmsg ("interface name must be specified");
18612 return -99;
18613 }
18614
18615 if (vec_len (if_name) > 64)
18616 {
18617 errmsg ("interface name too long");
18618 return -99;
18619 }
18620
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018621 M (NETMAP_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018622
18623 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
18624 clib_memcpy (mp->hw_addr, hw_addr, 6);
18625 mp->use_random_hw_addr = random_hw_addr;
18626 mp->is_pipe = is_pipe;
18627 mp->is_master = is_master;
18628 vec_free (if_name);
18629
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018630 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018631 W (ret);
18632 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018633}
18634
18635static int
18636api_netmap_delete (vat_main_t * vam)
18637{
18638 unformat_input_t *i = vam->input;
18639 vl_api_netmap_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018640 u8 *if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018641 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018642
18643 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18644 {
18645 if (unformat (i, "name %s", &if_name))
18646 vec_add1 (if_name, 0);
18647 else
18648 break;
18649 }
18650
18651 if (!vec_len (if_name))
18652 {
18653 errmsg ("interface name must be specified");
18654 return -99;
18655 }
18656
18657 if (vec_len (if_name) > 64)
18658 {
18659 errmsg ("interface name too long");
18660 return -99;
18661 }
18662
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018663 M (NETMAP_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018664
18665 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
18666 vec_free (if_name);
18667
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018668 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018669 W (ret);
18670 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018671}
18672
Neale Ranns097fa662018-05-01 05:17:55 -070018673static u8 *
18674format_fib_api_path_nh_proto (u8 * s, va_list * args)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018675{
Neale Ranns097fa662018-05-01 05:17:55 -070018676 vl_api_fib_path_nh_proto_t proto =
18677 va_arg (*args, vl_api_fib_path_nh_proto_t);
18678
18679 switch (proto)
18680 {
18681 case FIB_API_PATH_NH_PROTO_IP4:
18682 s = format (s, "ip4");
18683 break;
18684 case FIB_API_PATH_NH_PROTO_IP6:
18685 s = format (s, "ip6");
18686 break;
18687 case FIB_API_PATH_NH_PROTO_MPLS:
18688 s = format (s, "mpls");
18689 break;
18690 case FIB_API_PATH_NH_PROTO_BIER:
18691 s = format (s, "bier");
18692 break;
18693 case FIB_API_PATH_NH_PROTO_ETHERNET:
18694 s = format (s, "ethernet");
18695 break;
18696 }
18697
18698 return (s);
18699}
18700
18701static u8 *
18702format_vl_api_ip_address_union (u8 * s, va_list * args)
18703{
18704 vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
18705 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
18706
18707 switch (af)
18708 {
18709 case ADDRESS_IP4:
18710 s = format (s, "%U", format_ip4_address, u->ip4);
18711 break;
18712 case ADDRESS_IP6:
18713 s = format (s, "%U", format_ip6_address, u->ip6);
18714 break;
18715 }
18716 return (s);
18717}
18718
18719static u8 *
18720format_vl_api_fib_path_type (u8 * s, va_list * args)
18721{
18722 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
18723
18724 switch (t)
18725 {
18726 case FIB_API_PATH_TYPE_NORMAL:
18727 s = format (s, "normal");
18728 break;
18729 case FIB_API_PATH_TYPE_LOCAL:
18730 s = format (s, "local");
18731 break;
18732 case FIB_API_PATH_TYPE_DROP:
18733 s = format (s, "drop");
18734 break;
18735 case FIB_API_PATH_TYPE_UDP_ENCAP:
18736 s = format (s, "udp-encap");
18737 break;
18738 case FIB_API_PATH_TYPE_BIER_IMP:
18739 s = format (s, "bier-imp");
18740 break;
18741 case FIB_API_PATH_TYPE_ICMP_UNREACH:
18742 s = format (s, "unreach");
18743 break;
18744 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
18745 s = format (s, "prohibit");
18746 break;
18747 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
18748 s = format (s, "src-lookup");
18749 break;
18750 case FIB_API_PATH_TYPE_DVR:
18751 s = format (s, "dvr");
18752 break;
18753 case FIB_API_PATH_TYPE_INTERFACE_RX:
18754 s = format (s, "interface-rx");
18755 break;
18756 case FIB_API_PATH_TYPE_CLASSIFY:
18757 s = format (s, "classify");
18758 break;
18759 }
18760
18761 return (s);
18762}
18763
18764static void
18765vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
18766{
18767 print (vam->ofp,
18768 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
18769 ntohl (fp->weight), ntohl (fp->sw_if_index),
18770 format_vl_api_fib_path_type, fp->type,
18771 format_fib_api_path_nh_proto, fp->proto,
18772 format_vl_api_ip_address_union, &fp->nh.address);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018773}
18774
18775static void
18776vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
Neale Ranns31ed7442018-02-23 05:29:09 -080018777 vl_api_fib_path_t * fp)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018778{
18779 struct in_addr ip4;
18780 struct in6_addr ip6;
18781
18782 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
18783 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
Neale Ranns097fa662018-05-01 05:17:55 -070018784 vat_json_object_add_uint (node, "type", fp->type);
18785 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
18786 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018787 {
Neale Ranns097fa662018-05-01 05:17:55 -070018788 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018789 vat_json_object_add_ip4 (node, "next_hop", ip4);
18790 }
Neale Ranns097fa662018-05-01 05:17:55 -070018791 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018792 {
Neale Ranns097fa662018-05-01 05:17:55 -070018793 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018794 vat_json_object_add_ip6 (node, "next_hop", ip6);
18795 }
18796}
18797
18798static void
18799vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018800{
18801 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070018802 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080018803 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018804 i32 i;
18805
Neale Ranns097fa662018-05-01 05:17:55 -070018806 print (vam->ofp, "sw_if_index %d via:",
18807 ntohl (mp->mt_tunnel.mt_sw_if_index));
18808 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018809 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018810 {
Neale Ranns097fa662018-05-01 05:17:55 -070018811 vl_api_fib_path_print (vam, fp);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018812 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018813 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018814
Damjan Marion7cd468a2016-12-19 23:05:39 +010018815 print (vam->ofp, "");
18816}
18817
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018818#define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
18819#define vl_api_mpls_tunnel_details_t_print vl_noop_handler
18820
18821static void
18822vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018823{
18824 vat_main_t *vam = &vat_main;
18825 vat_json_node_t *node = NULL;
Neale Ranns097fa662018-05-01 05:17:55 -070018826 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080018827 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018828 i32 i;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018829
18830 if (VAT_JSON_ARRAY != vam->json_tree.type)
18831 {
18832 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18833 vat_json_init_array (&vam->json_tree);
18834 }
18835 node = vat_json_array_add (&vam->json_tree);
18836
18837 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070018838 vat_json_object_add_uint (node, "sw_if_index",
18839 ntohl (mp->mt_tunnel.mt_sw_if_index));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018840
Neale Ranns097fa662018-05-01 05:17:55 -070018841 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018842
Neale Ranns097fa662018-05-01 05:17:55 -070018843 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018844 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018845 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018846 vl_api_mpls_fib_path_json_print (node, fp);
18847 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018848 }
18849}
18850
18851static int
18852api_mpls_tunnel_dump (vat_main_t * vam)
18853{
18854 vl_api_mpls_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018855 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018856 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018857
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018858 M (MPLS_TUNNEL_DUMP, mp);
Neale Ranns097fa662018-05-01 05:17:55 -070018859
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018860 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018861
18862 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018863 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018864 S (mp_ping);
18865
Jon Loeliger56c7b012017-02-01 12:31:41 -060018866 W (ret);
18867 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018868}
18869
Neale Ranns097fa662018-05-01 05:17:55 -070018870#define vl_api_mpls_table_details_t_endian vl_noop_handler
18871#define vl_api_mpls_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010018872
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018873
Damjan Marion7cd468a2016-12-19 23:05:39 +010018874static void
Neale Ranns097fa662018-05-01 05:17:55 -070018875vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018876{
18877 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070018878
18879 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
18880}
18881
18882static void vl_api_mpls_table_details_t_handler_json
18883 (vl_api_mpls_table_details_t * mp)
18884{
18885 vat_main_t *vam = &vat_main;
18886 vat_json_node_t *node = NULL;
18887
18888 if (VAT_JSON_ARRAY != vam->json_tree.type)
18889 {
18890 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18891 vat_json_init_array (&vam->json_tree);
18892 }
18893 node = vat_json_array_add (&vam->json_tree);
18894
18895 vat_json_init_object (node);
18896 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
18897}
18898
18899static int
18900api_mpls_table_dump (vat_main_t * vam)
18901{
18902 vl_api_mpls_table_dump_t *mp;
18903 vl_api_control_ping_t *mp_ping;
18904 int ret;
18905
18906 M (MPLS_TABLE_DUMP, mp);
18907 S (mp);
18908
18909 /* Use a control ping for synchronization */
18910 MPING (CONTROL_PING, mp_ping);
18911 S (mp_ping);
18912
18913 W (ret);
18914 return ret;
18915}
18916
18917#define vl_api_mpls_route_details_t_endian vl_noop_handler
18918#define vl_api_mpls_route_details_t_print vl_noop_handler
18919
18920static void
18921vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
18922{
18923 vat_main_t *vam = &vat_main;
18924 int count = ntohl (mp->mr_route.mr_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080018925 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018926 int i;
18927
18928 print (vam->ofp,
18929 "table-id %d, label %u, ess_bit %u",
Neale Ranns097fa662018-05-01 05:17:55 -070018930 ntohl (mp->mr_route.mr_table_id),
18931 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
18932 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018933 for (i = 0; i < count; i++)
18934 {
Neale Ranns097fa662018-05-01 05:17:55 -070018935 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018936 fp++;
18937 }
18938}
18939
Neale Ranns097fa662018-05-01 05:17:55 -070018940static void vl_api_mpls_route_details_t_handler_json
18941 (vl_api_mpls_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018942{
18943 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070018944 int count = ntohl (mp->mr_route.mr_n_paths);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018945 vat_json_node_t *node = NULL;
Neale Ranns31ed7442018-02-23 05:29:09 -080018946 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018947 int i;
18948
18949 if (VAT_JSON_ARRAY != vam->json_tree.type)
18950 {
18951 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18952 vat_json_init_array (&vam->json_tree);
18953 }
18954 node = vat_json_array_add (&vam->json_tree);
18955
18956 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070018957 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
18958 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
18959 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018960 vat_json_object_add_uint (node, "path_count", count);
Neale Ranns097fa662018-05-01 05:17:55 -070018961 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018962 for (i = 0; i < count; i++)
18963 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018964 vl_api_mpls_fib_path_json_print (node, fp);
18965 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018966 }
18967}
18968
18969static int
Neale Ranns097fa662018-05-01 05:17:55 -070018970api_mpls_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018971{
Neale Ranns097fa662018-05-01 05:17:55 -070018972 unformat_input_t *input = vam->input;
18973 vl_api_mpls_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018974 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070018975 u32 table_id;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018976 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018977
Neale Ranns097fa662018-05-01 05:17:55 -070018978 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18979 {
18980 if (unformat (input, "table_id %d", &table_id))
18981 ;
18982 else
18983 break;
18984 }
18985 if (table_id == ~0)
18986 {
18987 errmsg ("missing table id");
18988 return -99;
18989 }
18990
18991 M (MPLS_ROUTE_DUMP, mp);
18992
18993 mp->table.mt_table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018994 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018995
18996 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018997 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018998 S (mp_ping);
18999
Jon Loeliger56c7b012017-02-01 12:31:41 -060019000 W (ret);
19001 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019002}
19003
Neale Ranns097fa662018-05-01 05:17:55 -070019004#define vl_api_ip_table_details_t_endian vl_noop_handler
19005#define vl_api_ip_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010019006
19007static void
Neale Ranns097fa662018-05-01 05:17:55 -070019008vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019009{
19010 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019011
19012 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070019013 "%s; table-id %d, prefix %U/%d",
19014 mp->table.name, ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019015}
19016
Neale Ranns097fa662018-05-01 05:17:55 -070019017
19018static void vl_api_ip_table_details_t_handler_json
19019 (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019020{
19021 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019022 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019023
19024 if (VAT_JSON_ARRAY != vam->json_tree.type)
19025 {
19026 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19027 vat_json_init_array (&vam->json_tree);
19028 }
19029 node = vat_json_array_add (&vam->json_tree);
19030
19031 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070019032 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019033}
19034
19035static int
Neale Ranns097fa662018-05-01 05:17:55 -070019036api_ip_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019037{
Neale Ranns097fa662018-05-01 05:17:55 -070019038 vl_api_ip_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019039 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019040 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019041
Neale Ranns097fa662018-05-01 05:17:55 -070019042 M (IP_TABLE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019043 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019044
19045 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019046 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019047 S (mp_ping);
19048
Jon Loeliger56c7b012017-02-01 12:31:41 -060019049 W (ret);
19050 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019051}
19052
Neale Ranns5a8123b2017-01-26 01:18:23 -080019053static int
Neale Ranns097fa662018-05-01 05:17:55 -070019054api_ip_mtable_dump (vat_main_t * vam)
Neale Ranns5a8123b2017-01-26 01:18:23 -080019055{
Neale Ranns097fa662018-05-01 05:17:55 -070019056 vl_api_ip_mtable_dump_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -080019057 vl_api_control_ping_t *mp_ping;
19058 int ret;
19059
Neale Ranns097fa662018-05-01 05:17:55 -070019060 M (IP_MTABLE_DUMP, mp);
19061 S (mp);
19062
19063 /* Use a control ping for synchronization */
19064 MPING (CONTROL_PING, mp_ping);
19065 S (mp_ping);
19066
19067 W (ret);
19068 return ret;
19069}
19070
19071static int
19072api_ip_mroute_dump (vat_main_t * vam)
19073{
19074 unformat_input_t *input = vam->input;
19075 vl_api_control_ping_t *mp_ping;
19076 vl_api_ip_mroute_dump_t *mp;
19077 int ret, is_ip6;
19078 u32 table_id;
19079
19080 is_ip6 = 0;
19081 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19082 {
19083 if (unformat (input, "table_id %d", &table_id))
19084 ;
19085 else if (unformat (input, "ip6"))
19086 is_ip6 = 1;
19087 else if (unformat (input, "ip4"))
19088 is_ip6 = 0;
19089 else
19090 break;
19091 }
19092 if (table_id == ~0)
19093 {
19094 errmsg ("missing table id");
19095 return -99;
19096 }
19097
19098 M (IP_MROUTE_DUMP, mp);
19099 mp->table.table_id = table_id;
19100 mp->table.is_ip6 = is_ip6;
Neale Ranns5a8123b2017-01-26 01:18:23 -080019101 S (mp);
19102
19103 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019104 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080019105 S (mp_ping);
19106
19107 W (ret);
19108 return ret;
19109}
19110
Damjan Marion7cd468a2016-12-19 23:05:39 +010019111static void vl_api_ip_neighbor_details_t_handler
19112 (vl_api_ip_neighbor_details_t * mp)
19113{
19114 vat_main_t *vam = &vat_main;
19115
19116 print (vam->ofp, "%c %U %U",
Neale Ranns37029302018-08-10 05:30:06 -070019117 (ntohl (mp->neighbor.flags) & IP_NEIGHBOR_FLAG_STATIC) ? 'S' : 'D',
19118 format_vl_api_mac_address, &mp->neighbor.mac_address,
19119 format_vl_api_address, &mp->neighbor.ip_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019120}
19121
19122static void vl_api_ip_neighbor_details_t_handler_json
19123 (vl_api_ip_neighbor_details_t * mp)
19124{
19125
19126 vat_main_t *vam = &vat_main;
19127 vat_json_node_t *node;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019128
19129 if (VAT_JSON_ARRAY != vam->json_tree.type)
19130 {
19131 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19132 vat_json_init_array (&vam->json_tree);
19133 }
19134 node = vat_json_array_add (&vam->json_tree);
19135
19136 vat_json_init_object (node);
Neale Ranns37029302018-08-10 05:30:06 -070019137 vat_json_object_add_string_copy
19138 (node, "flag",
19139 ((ntohl (mp->neighbor.flags) & IP_NEIGHBOR_FLAG_STATIC) ?
19140 (u8 *) "static" : (u8 *) "dynamic"));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019141
19142 vat_json_object_add_string_copy (node, "link_layer",
Neale Ranns37029302018-08-10 05:30:06 -070019143 format (0, "%U", format_vl_api_mac_address,
19144 &mp->neighbor.mac_address));
Neale Ranns5a8844b2019-04-16 07:15:35 +000019145 vat_json_object_add_address (node, "ip", &mp->neighbor.ip_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019146}
19147
19148static int
19149api_ip_neighbor_dump (vat_main_t * vam)
19150{
19151 unformat_input_t *i = vam->input;
19152 vl_api_ip_neighbor_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019153 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019154 u8 is_ipv6 = 0;
19155 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019156 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019157
19158 /* Parse args required to build the message */
19159 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19160 {
19161 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19162 ;
19163 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19164 ;
19165 else if (unformat (i, "ip6"))
19166 is_ipv6 = 1;
19167 else
19168 break;
19169 }
19170
19171 if (sw_if_index == ~0)
19172 {
19173 errmsg ("missing interface name or sw_if_index");
19174 return -99;
19175 }
19176
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019177 M (IP_NEIGHBOR_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019178 mp->is_ipv6 = (u8) is_ipv6;
19179 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019180 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019181
19182 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019183 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019184 S (mp_ping);
19185
Jon Loeliger56c7b012017-02-01 12:31:41 -060019186 W (ret);
19187 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019188}
19189
Neale Ranns097fa662018-05-01 05:17:55 -070019190#define vl_api_ip_route_details_t_endian vl_noop_handler
19191#define vl_api_ip_route_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010019192
19193static void
Neale Ranns097fa662018-05-01 05:17:55 -070019194vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019195{
19196 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070019197 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019198 vl_api_fib_path_t *fp;
19199 int i;
19200
19201 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070019202 "table-id %d, prefix %U/%d",
19203 ntohl (mp->route.table_id),
Paul Vinciguerraab055082019-06-06 14:07:55 -040019204 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019205 for (i = 0; i < count; i++)
19206 {
Neale Ranns097fa662018-05-01 05:17:55 -070019207 fp = &mp->route.paths[i];
19208
19209 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019210 fp++;
19211 }
19212}
19213
Neale Ranns097fa662018-05-01 05:17:55 -070019214static void vl_api_ip_route_details_t_handler_json
19215 (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019216{
19217 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070019218 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019219 vat_json_node_t *node = NULL;
19220 struct in_addr ip4;
19221 struct in6_addr ip6;
19222 vl_api_fib_path_t *fp;
19223 int i;
19224
19225 if (VAT_JSON_ARRAY != vam->json_tree.type)
19226 {
19227 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19228 vat_json_init_array (&vam->json_tree);
19229 }
19230 node = vat_json_array_add (&vam->json_tree);
19231
19232 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070019233 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
19234 if (ADDRESS_IP6 == mp->route.prefix.address.af)
19235 {
19236 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
19237 vat_json_object_add_ip6 (node, "prefix", ip6);
19238 }
19239 else
19240 {
19241 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
19242 vat_json_object_add_ip4 (node, "prefix", ip4);
19243 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040019244 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019245 vat_json_object_add_uint (node, "path_count", count);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019246 for (i = 0; i < count; i++)
19247 {
Neale Ranns097fa662018-05-01 05:17:55 -070019248 fp = &mp->route.paths[i];
19249 vl_api_mpls_fib_path_json_print (node, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019250 }
19251}
19252
19253static int
Neale Ranns097fa662018-05-01 05:17:55 -070019254api_ip_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019255{
Neale Ranns097fa662018-05-01 05:17:55 -070019256 unformat_input_t *input = vam->input;
19257 vl_api_ip_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019258 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070019259 u32 table_id;
19260 u8 is_ip6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019261 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019262
Neale Ranns097fa662018-05-01 05:17:55 -070019263 is_ip6 = 0;
19264 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19265 {
19266 if (unformat (input, "table_id %d", &table_id))
19267 ;
19268 else if (unformat (input, "ip6"))
19269 is_ip6 = 1;
19270 else if (unformat (input, "ip4"))
19271 is_ip6 = 0;
19272 else
19273 break;
19274 }
19275 if (table_id == ~0)
19276 {
19277 errmsg ("missing table id");
19278 return -99;
19279 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010019280
Neale Ranns097fa662018-05-01 05:17:55 -070019281 M (IP_ROUTE_DUMP, mp);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019282
Neale Ranns097fa662018-05-01 05:17:55 -070019283 mp->table.table_id = table_id;
19284 mp->table.is_ip6 = is_ip6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019285
Neale Ranns5a8123b2017-01-26 01:18:23 -080019286 S (mp);
19287
19288 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019289 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080019290 S (mp_ping);
19291
19292 W (ret);
19293 return ret;
19294}
19295
Damjan Marion7cd468a2016-12-19 23:05:39 +010019296int
19297api_classify_table_ids (vat_main_t * vam)
19298{
19299 vl_api_classify_table_ids_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019300 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019301
19302 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019303 M (CLASSIFY_TABLE_IDS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019304 mp->context = 0;
19305
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019306 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019307 W (ret);
19308 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019309}
19310
19311int
19312api_classify_table_by_interface (vat_main_t * vam)
19313{
19314 unformat_input_t *input = vam->input;
19315 vl_api_classify_table_by_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019316
19317 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019318 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019319 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19320 {
19321 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19322 ;
19323 else if (unformat (input, "sw_if_index %d", &sw_if_index))
19324 ;
19325 else
19326 break;
19327 }
19328 if (sw_if_index == ~0)
19329 {
19330 errmsg ("missing interface name or sw_if_index");
19331 return -99;
19332 }
19333
19334 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019335 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019336 mp->context = 0;
19337 mp->sw_if_index = ntohl (sw_if_index);
19338
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019339 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019340 W (ret);
19341 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019342}
19343
19344int
19345api_classify_table_info (vat_main_t * vam)
19346{
19347 unformat_input_t *input = vam->input;
19348 vl_api_classify_table_info_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019349
19350 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019351 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019352 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19353 {
19354 if (unformat (input, "table_id %d", &table_id))
19355 ;
19356 else
19357 break;
19358 }
19359 if (table_id == ~0)
19360 {
19361 errmsg ("missing table id");
19362 return -99;
19363 }
19364
19365 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019366 M (CLASSIFY_TABLE_INFO, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019367 mp->context = 0;
19368 mp->table_id = ntohl (table_id);
19369
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019370 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019371 W (ret);
19372 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019373}
19374
19375int
19376api_classify_session_dump (vat_main_t * vam)
19377{
19378 unformat_input_t *input = vam->input;
19379 vl_api_classify_session_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019380 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019381
19382 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019383 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019384 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19385 {
19386 if (unformat (input, "table_id %d", &table_id))
19387 ;
19388 else
19389 break;
19390 }
19391 if (table_id == ~0)
19392 {
19393 errmsg ("missing table id");
19394 return -99;
19395 }
19396
19397 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019398 M (CLASSIFY_SESSION_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019399 mp->context = 0;
19400 mp->table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019401 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019402
19403 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019404 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019405 S (mp_ping);
19406
Jon Loeliger56c7b012017-02-01 12:31:41 -060019407 W (ret);
19408 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019409}
19410
19411static void
19412vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
19413{
19414 vat_main_t *vam = &vat_main;
19415
19416 print (vam->ofp, "collector_address %U, collector_port %d, "
19417 "src_address %U, vrf_id %d, path_mtu %u, "
19418 "template_interval %u, udp_checksum %d",
19419 format_ip4_address, mp->collector_address,
19420 ntohs (mp->collector_port),
19421 format_ip4_address, mp->src_address,
19422 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
19423 ntohl (mp->template_interval), mp->udp_checksum);
19424
19425 vam->retval = 0;
19426 vam->result_ready = 1;
19427}
19428
19429static void
19430 vl_api_ipfix_exporter_details_t_handler_json
19431 (vl_api_ipfix_exporter_details_t * mp)
19432{
19433 vat_main_t *vam = &vat_main;
19434 vat_json_node_t node;
19435 struct in_addr collector_address;
19436 struct in_addr src_address;
19437
19438 vat_json_init_object (&node);
19439 clib_memcpy (&collector_address, &mp->collector_address,
19440 sizeof (collector_address));
19441 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
19442 vat_json_object_add_uint (&node, "collector_port",
19443 ntohs (mp->collector_port));
19444 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
19445 vat_json_object_add_ip4 (&node, "src_address", src_address);
19446 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
19447 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
19448 vat_json_object_add_uint (&node, "template_interval",
19449 ntohl (mp->template_interval));
19450 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
19451
19452 vat_json_print (vam->ofp, &node);
19453 vat_json_free (&node);
19454 vam->retval = 0;
19455 vam->result_ready = 1;
19456}
19457
19458int
19459api_ipfix_exporter_dump (vat_main_t * vam)
19460{
19461 vl_api_ipfix_exporter_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019462 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019463
19464 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019465 M (IPFIX_EXPORTER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019466 mp->context = 0;
19467
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019468 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019469 W (ret);
19470 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019471}
19472
19473static int
19474api_ipfix_classify_stream_dump (vat_main_t * vam)
19475{
19476 vl_api_ipfix_classify_stream_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019477 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019478
19479 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019480 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019481 mp->context = 0;
19482
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019483 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019484 W (ret);
19485 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019486 /* NOTREACHED */
19487 return 0;
19488}
19489
19490static void
19491 vl_api_ipfix_classify_stream_details_t_handler
19492 (vl_api_ipfix_classify_stream_details_t * mp)
19493{
19494 vat_main_t *vam = &vat_main;
19495 print (vam->ofp, "domain_id %d, src_port %d",
19496 ntohl (mp->domain_id), ntohs (mp->src_port));
19497 vam->retval = 0;
19498 vam->result_ready = 1;
19499}
19500
19501static void
19502 vl_api_ipfix_classify_stream_details_t_handler_json
19503 (vl_api_ipfix_classify_stream_details_t * mp)
19504{
19505 vat_main_t *vam = &vat_main;
19506 vat_json_node_t node;
19507
19508 vat_json_init_object (&node);
19509 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
19510 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
19511
19512 vat_json_print (vam->ofp, &node);
19513 vat_json_free (&node);
19514 vam->retval = 0;
19515 vam->result_ready = 1;
19516}
19517
19518static int
19519api_ipfix_classify_table_dump (vat_main_t * vam)
19520{
19521 vl_api_ipfix_classify_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019522 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019523 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019524
19525 if (!vam->json_output)
19526 {
19527 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
19528 "transport_protocol");
19529 }
19530
19531 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019532 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019533
19534 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019535 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019536
19537 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019538 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019539 S (mp_ping);
19540
Jon Loeliger56c7b012017-02-01 12:31:41 -060019541 W (ret);
19542 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019543}
19544
19545static void
19546 vl_api_ipfix_classify_table_details_t_handler
19547 (vl_api_ipfix_classify_table_details_t * mp)
19548{
19549 vat_main_t *vam = &vat_main;
19550 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
19551 mp->transport_protocol);
19552}
19553
19554static void
19555 vl_api_ipfix_classify_table_details_t_handler_json
19556 (vl_api_ipfix_classify_table_details_t * mp)
19557{
19558 vat_json_node_t *node = NULL;
19559 vat_main_t *vam = &vat_main;
19560
19561 if (VAT_JSON_ARRAY != vam->json_tree.type)
19562 {
19563 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19564 vat_json_init_array (&vam->json_tree);
19565 }
19566
19567 node = vat_json_array_add (&vam->json_tree);
19568 vat_json_init_object (node);
19569
19570 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
19571 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
19572 vat_json_object_add_uint (node, "transport_protocol",
19573 mp->transport_protocol);
19574}
19575
19576static int
19577api_sw_interface_span_enable_disable (vat_main_t * vam)
19578{
19579 unformat_input_t *i = vam->input;
19580 vl_api_sw_interface_span_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019581 u32 src_sw_if_index = ~0;
19582 u32 dst_sw_if_index = ~0;
19583 u8 state = 3;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019584 int ret;
Eyal Bari001fd402017-07-16 09:34:53 +030019585 u8 is_l2 = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019586
19587 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19588 {
19589 if (unformat
19590 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
19591 ;
19592 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
19593 ;
19594 else
19595 if (unformat
19596 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
19597 ;
19598 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
19599 ;
19600 else if (unformat (i, "disable"))
19601 state = 0;
19602 else if (unformat (i, "rx"))
19603 state = 1;
19604 else if (unformat (i, "tx"))
19605 state = 2;
19606 else if (unformat (i, "both"))
19607 state = 3;
Eyal Bari001fd402017-07-16 09:34:53 +030019608 else if (unformat (i, "l2"))
19609 is_l2 = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019610 else
19611 break;
19612 }
19613
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019614 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019615
19616 mp->sw_if_index_from = htonl (src_sw_if_index);
19617 mp->sw_if_index_to = htonl (dst_sw_if_index);
19618 mp->state = state;
Eyal Bari001fd402017-07-16 09:34:53 +030019619 mp->is_l2 = is_l2;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019620
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019621 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019622 W (ret);
19623 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019624}
19625
19626static void
19627vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
19628 * mp)
19629{
19630 vat_main_t *vam = &vat_main;
19631 u8 *sw_if_from_name = 0;
19632 u8 *sw_if_to_name = 0;
19633 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
19634 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
19635 char *states[] = { "none", "rx", "tx", "both" };
19636 hash_pair_t *p;
19637
19638 /* *INDENT-OFF* */
19639 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
19640 ({
19641 if ((u32) p->value[0] == sw_if_index_from)
19642 {
19643 sw_if_from_name = (u8 *)(p->key);
19644 if (sw_if_to_name)
19645 break;
19646 }
19647 if ((u32) p->value[0] == sw_if_index_to)
19648 {
19649 sw_if_to_name = (u8 *)(p->key);
19650 if (sw_if_from_name)
19651 break;
19652 }
19653 }));
19654 /* *INDENT-ON* */
Jon Loeliger179ab362018-03-12 14:50:08 -050019655 print (vam->ofp, "%20s => %20s (%s) %s",
19656 sw_if_from_name, sw_if_to_name, states[mp->state],
19657 mp->is_l2 ? "l2" : "device");
Damjan Marion7cd468a2016-12-19 23:05:39 +010019658}
19659
19660static void
19661 vl_api_sw_interface_span_details_t_handler_json
19662 (vl_api_sw_interface_span_details_t * mp)
19663{
19664 vat_main_t *vam = &vat_main;
19665 vat_json_node_t *node = NULL;
19666 u8 *sw_if_from_name = 0;
19667 u8 *sw_if_to_name = 0;
19668 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
19669 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
19670 hash_pair_t *p;
19671
19672 /* *INDENT-OFF* */
19673 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
19674 ({
19675 if ((u32) p->value[0] == sw_if_index_from)
19676 {
19677 sw_if_from_name = (u8 *)(p->key);
19678 if (sw_if_to_name)
19679 break;
19680 }
19681 if ((u32) p->value[0] == sw_if_index_to)
19682 {
19683 sw_if_to_name = (u8 *)(p->key);
19684 if (sw_if_from_name)
19685 break;
19686 }
19687 }));
19688 /* *INDENT-ON* */
19689
19690 if (VAT_JSON_ARRAY != vam->json_tree.type)
19691 {
19692 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19693 vat_json_init_array (&vam->json_tree);
19694 }
19695 node = vat_json_array_add (&vam->json_tree);
19696
19697 vat_json_init_object (node);
19698 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
19699 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
19700 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
Neale Ranns05b2bf22017-01-30 06:44:58 -080019701 if (0 != sw_if_to_name)
19702 {
19703 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
19704 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010019705 vat_json_object_add_uint (node, "state", mp->state);
Jon Loeliger179ab362018-03-12 14:50:08 -050019706 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019707}
19708
19709static int
19710api_sw_interface_span_dump (vat_main_t * vam)
19711{
Eyal Bari5b311202017-07-31 13:12:30 +030019712 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019713 vl_api_sw_interface_span_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019714 vl_api_control_ping_t *mp_ping;
Eyal Bari5b311202017-07-31 13:12:30 +030019715 u8 is_l2 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019716 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019717
Eyal Bari5b311202017-07-31 13:12:30 +030019718 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19719 {
19720 if (unformat (input, "l2"))
19721 is_l2 = 1;
19722 else
19723 break;
19724 }
19725
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019726 M (SW_INTERFACE_SPAN_DUMP, mp);
Eyal Bari5b311202017-07-31 13:12:30 +030019727 mp->is_l2 = is_l2;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019728 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019729
19730 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019731 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019732 S (mp_ping);
19733
Jon Loeliger56c7b012017-02-01 12:31:41 -060019734 W (ret);
19735 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019736}
19737
19738int
19739api_pg_create_interface (vat_main_t * vam)
19740{
19741 unformat_input_t *input = vam->input;
19742 vl_api_pg_create_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019743
19744 u32 if_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019745 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019746 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19747 {
19748 if (unformat (input, "if_id %d", &if_id))
19749 ;
19750 else
19751 break;
19752 }
19753 if (if_id == ~0)
19754 {
19755 errmsg ("missing pg interface index");
19756 return -99;
19757 }
19758
19759 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019760 M (PG_CREATE_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019761 mp->context = 0;
19762 mp->interface_id = ntohl (if_id);
19763
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019764 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019765 W (ret);
19766 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019767}
19768
19769int
19770api_pg_capture (vat_main_t * vam)
19771{
19772 unformat_input_t *input = vam->input;
19773 vl_api_pg_capture_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019774
19775 u32 if_id = ~0;
19776 u8 enable = 1;
19777 u32 count = 1;
19778 u8 pcap_file_set = 0;
19779 u8 *pcap_file = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019780 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019781 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19782 {
19783 if (unformat (input, "if_id %d", &if_id))
19784 ;
19785 else if (unformat (input, "pcap %s", &pcap_file))
19786 pcap_file_set = 1;
19787 else if (unformat (input, "count %d", &count))
19788 ;
19789 else if (unformat (input, "disable"))
19790 enable = 0;
19791 else
19792 break;
19793 }
19794 if (if_id == ~0)
19795 {
19796 errmsg ("missing pg interface index");
19797 return -99;
19798 }
19799 if (pcap_file_set > 0)
19800 {
19801 if (vec_len (pcap_file) > 255)
19802 {
19803 errmsg ("pcap file name is too long");
19804 return -99;
19805 }
19806 }
19807
19808 u32 name_len = vec_len (pcap_file);
19809 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019810 M (PG_CAPTURE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019811 mp->context = 0;
19812 mp->interface_id = ntohl (if_id);
19813 mp->is_enabled = enable;
19814 mp->count = ntohl (count);
19815 mp->pcap_name_length = ntohl (name_len);
19816 if (pcap_file_set != 0)
19817 {
19818 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
19819 }
19820 vec_free (pcap_file);
19821
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019822 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019823 W (ret);
19824 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019825}
19826
19827int
19828api_pg_enable_disable (vat_main_t * vam)
19829{
19830 unformat_input_t *input = vam->input;
19831 vl_api_pg_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019832
19833 u8 enable = 1;
19834 u8 stream_name_set = 0;
19835 u8 *stream_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019836 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019837 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19838 {
19839 if (unformat (input, "stream %s", &stream_name))
19840 stream_name_set = 1;
19841 else if (unformat (input, "disable"))
19842 enable = 0;
19843 else
19844 break;
19845 }
19846
19847 if (stream_name_set > 0)
19848 {
19849 if (vec_len (stream_name) > 255)
19850 {
19851 errmsg ("stream name too long");
19852 return -99;
19853 }
19854 }
19855
19856 u32 name_len = vec_len (stream_name);
19857 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019858 M (PG_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019859 mp->context = 0;
19860 mp->is_enabled = enable;
19861 if (stream_name_set != 0)
19862 {
19863 mp->stream_name_length = ntohl (name_len);
19864 clib_memcpy (mp->stream_name, stream_name, name_len);
19865 }
19866 vec_free (stream_name);
19867
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019868 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019869 W (ret);
19870 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019871}
19872
19873int
19874api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
19875{
19876 unformat_input_t *input = vam->input;
19877 vl_api_ip_source_and_port_range_check_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019878
19879 u16 *low_ports = 0;
19880 u16 *high_ports = 0;
19881 u16 this_low;
19882 u16 this_hi;
Neale Ranns37029302018-08-10 05:30:06 -070019883 vl_api_prefix_t prefix;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019884 u32 tmp, tmp2;
19885 u8 prefix_set = 0;
19886 u32 vrf_id = ~0;
19887 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019888 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019889
19890 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19891 {
Neale Ranns37029302018-08-10 05:30:06 -070019892 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
19893 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019894 else if (unformat (input, "vrf %d", &vrf_id))
19895 ;
19896 else if (unformat (input, "del"))
19897 is_add = 0;
19898 else if (unformat (input, "port %d", &tmp))
19899 {
19900 if (tmp == 0 || tmp > 65535)
19901 {
19902 errmsg ("port %d out of range", tmp);
19903 return -99;
19904 }
19905 this_low = tmp;
19906 this_hi = this_low + 1;
19907 vec_add1 (low_ports, this_low);
19908 vec_add1 (high_ports, this_hi);
19909 }
19910 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
19911 {
19912 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
19913 {
19914 errmsg ("incorrect range parameters");
19915 return -99;
19916 }
19917 this_low = tmp;
19918 /* Note: in debug CLI +1 is added to high before
19919 passing to real fn that does "the work"
19920 (ip_source_and_port_range_check_add_del).
19921 This fn is a wrapper around the binary API fn a
19922 control plane will call, which expects this increment
19923 to have occurred. Hence letting the binary API control
19924 plane fn do the increment for consistency between VAT
19925 and other control planes.
19926 */
19927 this_hi = tmp2;
19928 vec_add1 (low_ports, this_low);
19929 vec_add1 (high_ports, this_hi);
19930 }
19931 else
19932 break;
19933 }
19934
19935 if (prefix_set == 0)
19936 {
19937 errmsg ("<address>/<mask> not specified");
19938 return -99;
19939 }
19940
19941 if (vrf_id == ~0)
19942 {
19943 errmsg ("VRF ID required, not specified");
19944 return -99;
19945 }
19946
19947 if (vrf_id == 0)
19948 {
19949 errmsg
19950 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
19951 return -99;
19952 }
19953
19954 if (vec_len (low_ports) == 0)
19955 {
19956 errmsg ("At least one port or port range required");
19957 return -99;
19958 }
19959
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019960 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019961
19962 mp->is_add = is_add;
19963
Neale Ranns37029302018-08-10 05:30:06 -070019964 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019965
Damjan Marion7cd468a2016-12-19 23:05:39 +010019966 mp->number_of_ranges = vec_len (low_ports);
19967
19968 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
19969 vec_free (low_ports);
19970
19971 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
19972 vec_free (high_ports);
19973
19974 mp->vrf_id = ntohl (vrf_id);
19975
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019976 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019977 W (ret);
19978 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019979}
19980
19981int
19982api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
19983{
19984 unformat_input_t *input = vam->input;
19985 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019986 u32 sw_if_index = ~0;
19987 int vrf_set = 0;
19988 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
19989 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
19990 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019991 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019992
19993 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19994 {
19995 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19996 ;
19997 else if (unformat (input, "sw_if_index %d", &sw_if_index))
19998 ;
19999 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
20000 vrf_set = 1;
20001 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
20002 vrf_set = 1;
20003 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
20004 vrf_set = 1;
20005 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
20006 vrf_set = 1;
20007 else if (unformat (input, "del"))
20008 is_add = 0;
20009 else
20010 break;
20011 }
20012
20013 if (sw_if_index == ~0)
20014 {
20015 errmsg ("Interface required but not specified");
20016 return -99;
20017 }
20018
20019 if (vrf_set == 0)
20020 {
20021 errmsg ("VRF ID required but not specified");
20022 return -99;
20023 }
20024
20025 if (tcp_out_vrf_id == 0
20026 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
20027 {
20028 errmsg
20029 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
20030 return -99;
20031 }
20032
20033 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020034 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020035
20036 mp->sw_if_index = ntohl (sw_if_index);
20037 mp->is_add = is_add;
20038 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
20039 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
20040 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
20041 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
20042
20043 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020044 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020045
20046 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060020047 W (ret);
20048 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020049}
20050
20051static int
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020052api_set_punt (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010020053{
20054 unformat_input_t *i = vam->input;
Neale Ranns50f0ac02019-05-15 02:13:37 -070020055 vl_api_address_family_t af;
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020056 vl_api_set_punt_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020057 u32 protocol = ~0;
20058 u32 port = ~0;
20059 int is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020060 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020061
20062 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20063 {
Neale Ranns50f0ac02019-05-15 02:13:37 -070020064 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
Damjan Marion7cd468a2016-12-19 23:05:39 +010020065 ;
20066 else if (unformat (i, "protocol %d", &protocol))
20067 ;
20068 else if (unformat (i, "port %d", &port))
20069 ;
20070 else if (unformat (i, "del"))
20071 is_add = 0;
20072 else
20073 {
20074 clib_warning ("parse error '%U'", format_unformat_error, i);
20075 return -99;
20076 }
20077 }
20078
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020079 M (SET_PUNT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020080
20081 mp->is_add = (u8) is_add;
Neale Ranns50f0ac02019-05-15 02:13:37 -070020082 mp->punt.type = PUNT_API_TYPE_L4;
20083 mp->punt.punt.l4.af = af;
20084 mp->punt.punt.l4.protocol = (u8) protocol;
20085 mp->punt.punt.l4.port = htons ((u16) port);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020086
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020087 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020088 W (ret);
20089 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020090}
20091
Damjan Marion7cd468a2016-12-19 23:05:39 +010020092static int
20093api_delete_subif (vat_main_t * vam)
20094{
20095 unformat_input_t *i = vam->input;
20096 vl_api_delete_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020097 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020098 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020099
20100 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20101 {
20102 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20103 ;
20104 if (unformat (i, "sw_if_index %d", &sw_if_index))
20105 ;
20106 else
20107 break;
20108 }
20109
20110 if (sw_if_index == ~0)
20111 {
20112 errmsg ("missing sw_if_index");
20113 return -99;
20114 }
20115
20116 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020117 M (DELETE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020118 mp->sw_if_index = ntohl (sw_if_index);
20119
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020120 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020121 W (ret);
20122 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020123}
20124
20125#define foreach_pbb_vtr_op \
20126_("disable", L2_VTR_DISABLED) \
20127_("pop", L2_VTR_POP_2) \
20128_("push", L2_VTR_PUSH_2)
20129
20130static int
20131api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
20132{
20133 unformat_input_t *i = vam->input;
20134 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020135 u32 sw_if_index = ~0, vtr_op = ~0;
20136 u16 outer_tag = ~0;
20137 u8 dmac[6], smac[6];
20138 u8 dmac_set = 0, smac_set = 0;
20139 u16 vlanid = 0;
20140 u32 sid = ~0;
20141 u32 tmp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020142 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020143
20144 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040020145 clib_memset (dmac, 0, sizeof (dmac));
20146 clib_memset (smac, 0, sizeof (smac));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020147
20148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20149 {
20150 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20151 ;
20152 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20153 ;
20154 else if (unformat (i, "vtr_op %d", &vtr_op))
20155 ;
20156#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
20157 foreach_pbb_vtr_op
20158#undef _
20159 else if (unformat (i, "translate_pbb_stag"))
20160 {
20161 if (unformat (i, "%d", &tmp))
20162 {
20163 vtr_op = L2_VTR_TRANSLATE_2_1;
20164 outer_tag = tmp;
20165 }
20166 else
20167 {
20168 errmsg
20169 ("translate_pbb_stag operation requires outer tag definition");
20170 return -99;
20171 }
20172 }
20173 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
20174 dmac_set++;
20175 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
20176 smac_set++;
20177 else if (unformat (i, "sid %d", &sid))
20178 ;
20179 else if (unformat (i, "vlanid %d", &tmp))
20180 vlanid = tmp;
20181 else
20182 {
20183 clib_warning ("parse error '%U'", format_unformat_error, i);
20184 return -99;
20185 }
20186 }
20187
20188 if ((sw_if_index == ~0) || (vtr_op == ~0))
20189 {
20190 errmsg ("missing sw_if_index or vtr operation");
20191 return -99;
20192 }
20193 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
20194 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
20195 {
20196 errmsg
20197 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
20198 return -99;
20199 }
20200
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020201 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020202 mp->sw_if_index = ntohl (sw_if_index);
20203 mp->vtr_op = ntohl (vtr_op);
20204 mp->outer_tag = ntohs (outer_tag);
20205 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
20206 clib_memcpy (mp->b_smac, smac, sizeof (smac));
20207 mp->b_vlanid = ntohs (vlanid);
20208 mp->i_sid = ntohl (sid);
20209
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020210 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020211 W (ret);
20212 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020213}
20214
20215static int
20216api_flow_classify_set_interface (vat_main_t * vam)
20217{
20218 unformat_input_t *i = vam->input;
20219 vl_api_flow_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020220 u32 sw_if_index;
20221 int sw_if_index_set;
20222 u32 ip4_table_index = ~0;
20223 u32 ip6_table_index = ~0;
20224 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020225 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020226
20227 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20228 {
20229 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20230 sw_if_index_set = 1;
20231 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20232 sw_if_index_set = 1;
20233 else if (unformat (i, "del"))
20234 is_add = 0;
20235 else if (unformat (i, "ip4-table %d", &ip4_table_index))
20236 ;
20237 else if (unformat (i, "ip6-table %d", &ip6_table_index))
20238 ;
20239 else
20240 {
20241 clib_warning ("parse error '%U'", format_unformat_error, i);
20242 return -99;
20243 }
20244 }
20245
20246 if (sw_if_index_set == 0)
20247 {
20248 errmsg ("missing interface name or sw_if_index");
20249 return -99;
20250 }
20251
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020252 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020253
20254 mp->sw_if_index = ntohl (sw_if_index);
20255 mp->ip4_table_index = ntohl (ip4_table_index);
20256 mp->ip6_table_index = ntohl (ip6_table_index);
20257 mp->is_add = is_add;
20258
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020259 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020260 W (ret);
20261 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020262}
20263
20264static int
20265api_flow_classify_dump (vat_main_t * vam)
20266{
20267 unformat_input_t *i = vam->input;
20268 vl_api_flow_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020269 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020270 u8 type = FLOW_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020271 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020272
20273 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
20274 ;
20275 else
20276 {
20277 errmsg ("classify table type must be specified");
20278 return -99;
20279 }
20280
20281 if (!vam->json_output)
20282 {
20283 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
20284 }
20285
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020286 M (FLOW_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020287 mp->type = type;
20288 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020289 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020290
20291 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020292 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020293 S (mp_ping);
20294
Damjan Marion7cd468a2016-12-19 23:05:39 +010020295 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060020296 W (ret);
20297 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020298}
20299
20300static int
20301api_feature_enable_disable (vat_main_t * vam)
20302{
20303 unformat_input_t *i = vam->input;
20304 vl_api_feature_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020305 u8 *arc_name = 0;
20306 u8 *feature_name = 0;
20307 u32 sw_if_index = ~0;
20308 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020309 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020310
20311 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20312 {
20313 if (unformat (i, "arc_name %s", &arc_name))
20314 ;
20315 else if (unformat (i, "feature_name %s", &feature_name))
20316 ;
20317 else
20318 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20319 ;
20320 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20321 ;
20322 else if (unformat (i, "disable"))
20323 enable = 0;
20324 else
20325 break;
20326 }
20327
20328 if (arc_name == 0)
20329 {
20330 errmsg ("missing arc name");
20331 return -99;
20332 }
20333 if (vec_len (arc_name) > 63)
20334 {
20335 errmsg ("arc name too long");
20336 }
20337
20338 if (feature_name == 0)
20339 {
20340 errmsg ("missing feature name");
20341 return -99;
20342 }
20343 if (vec_len (feature_name) > 63)
20344 {
20345 errmsg ("feature name too long");
20346 }
20347
20348 if (sw_if_index == ~0)
20349 {
20350 errmsg ("missing interface name or sw_if_index");
20351 return -99;
20352 }
20353
20354 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020355 M (FEATURE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020356 mp->sw_if_index = ntohl (sw_if_index);
20357 mp->enable = enable;
20358 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
20359 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
20360 vec_free (arc_name);
20361 vec_free (feature_name);
20362
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020363 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020364 W (ret);
20365 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020366}
20367
20368static int
20369api_sw_interface_tag_add_del (vat_main_t * vam)
20370{
20371 unformat_input_t *i = vam->input;
20372 vl_api_sw_interface_tag_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020373 u32 sw_if_index = ~0;
20374 u8 *tag = 0;
20375 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020376 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020377
20378 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20379 {
20380 if (unformat (i, "tag %s", &tag))
20381 ;
20382 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20383 ;
20384 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20385 ;
20386 else if (unformat (i, "del"))
20387 enable = 0;
20388 else
20389 break;
20390 }
20391
20392 if (sw_if_index == ~0)
20393 {
20394 errmsg ("missing interface name or sw_if_index");
20395 return -99;
20396 }
20397
20398 if (enable && (tag == 0))
20399 {
20400 errmsg ("no tag specified");
20401 return -99;
20402 }
20403
20404 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020405 M (SW_INTERFACE_TAG_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020406 mp->sw_if_index = ntohl (sw_if_index);
20407 mp->is_add = enable;
20408 if (enable)
Ole Trøan3b0d7e42019-03-15 16:14:41 +000020409 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020410 vec_free (tag);
20411
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020412 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020413 W (ret);
20414 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020415}
20416
20417static void vl_api_l2_xconnect_details_t_handler
20418 (vl_api_l2_xconnect_details_t * mp)
20419{
20420 vat_main_t *vam = &vat_main;
20421
20422 print (vam->ofp, "%15d%15d",
20423 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
20424}
20425
20426static void vl_api_l2_xconnect_details_t_handler_json
20427 (vl_api_l2_xconnect_details_t * mp)
20428{
20429 vat_main_t *vam = &vat_main;
20430 vat_json_node_t *node = NULL;
20431
20432 if (VAT_JSON_ARRAY != vam->json_tree.type)
20433 {
20434 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20435 vat_json_init_array (&vam->json_tree);
20436 }
20437 node = vat_json_array_add (&vam->json_tree);
20438
20439 vat_json_init_object (node);
20440 vat_json_object_add_uint (node, "rx_sw_if_index",
20441 ntohl (mp->rx_sw_if_index));
20442 vat_json_object_add_uint (node, "tx_sw_if_index",
20443 ntohl (mp->tx_sw_if_index));
20444}
20445
20446static int
20447api_l2_xconnect_dump (vat_main_t * vam)
20448{
20449 vl_api_l2_xconnect_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020450 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020451 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020452
20453 if (!vam->json_output)
20454 {
20455 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
20456 }
20457
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020458 M (L2_XCONNECT_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020459
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020460 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020461
20462 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020463 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020464 S (mp_ping);
20465
Jon Loeliger56c7b012017-02-01 12:31:41 -060020466 W (ret);
20467 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020468}
20469
20470static int
Ole Troand7231612018-06-07 10:17:57 +020020471api_hw_interface_set_mtu (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010020472{
20473 unformat_input_t *i = vam->input;
Ole Troand7231612018-06-07 10:17:57 +020020474 vl_api_hw_interface_set_mtu_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020475 u32 sw_if_index = ~0;
20476 u32 mtu = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020477 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020478
20479 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20480 {
20481 if (unformat (i, "mtu %d", &mtu))
20482 ;
20483 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20484 ;
20485 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20486 ;
20487 else
20488 break;
20489 }
20490
20491 if (sw_if_index == ~0)
20492 {
20493 errmsg ("missing interface name or sw_if_index");
20494 return -99;
20495 }
20496
20497 if (mtu == 0)
20498 {
20499 errmsg ("no mtu specified");
20500 return -99;
20501 }
20502
20503 /* Construct the API message */
Ole Troand7231612018-06-07 10:17:57 +020020504 M (HW_INTERFACE_SET_MTU, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020505 mp->sw_if_index = ntohl (sw_if_index);
20506 mp->mtu = ntohs ((u16) mtu);
20507
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020508 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020509 W (ret);
20510 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020511}
20512
Pavel Kotucek6899a302017-06-08 08:46:10 +020020513static int
20514api_p2p_ethernet_add (vat_main_t * vam)
20515{
20516 unformat_input_t *i = vam->input;
20517 vl_api_p2p_ethernet_add_t *mp;
20518 u32 parent_if_index = ~0;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020519 u32 sub_id = ~0;
Pavel Kotucek6899a302017-06-08 08:46:10 +020020520 u8 remote_mac[6];
20521 u8 mac_set = 0;
20522 int ret;
20523
Dave Barachb7b92992018-10-17 10:38:51 -040020524 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020020525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20526 {
20527 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
20528 ;
20529 else if (unformat (i, "sw_if_index %d", &parent_if_index))
20530 ;
20531 else
20532 if (unformat
20533 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
20534 mac_set++;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020535 else if (unformat (i, "sub_id %d", &sub_id))
20536 ;
Pavel Kotucek6899a302017-06-08 08:46:10 +020020537 else
20538 {
20539 clib_warning ("parse error '%U'", format_unformat_error, i);
20540 return -99;
20541 }
20542 }
20543
20544 if (parent_if_index == ~0)
20545 {
20546 errmsg ("missing interface name or sw_if_index");
20547 return -99;
20548 }
20549 if (mac_set == 0)
20550 {
20551 errmsg ("missing remote mac address");
20552 return -99;
20553 }
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020554 if (sub_id == ~0)
20555 {
20556 errmsg ("missing sub-interface id");
20557 return -99;
20558 }
Pavel Kotucek6899a302017-06-08 08:46:10 +020020559
20560 M (P2P_ETHERNET_ADD, mp);
20561 mp->parent_if_index = ntohl (parent_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020562 mp->subif_id = ntohl (sub_id);
Pavel Kotucek6899a302017-06-08 08:46:10 +020020563 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
20564
20565 S (mp);
20566 W (ret);
20567 return ret;
20568}
20569
20570static int
20571api_p2p_ethernet_del (vat_main_t * vam)
20572{
20573 unformat_input_t *i = vam->input;
20574 vl_api_p2p_ethernet_del_t *mp;
20575 u32 parent_if_index = ~0;
20576 u8 remote_mac[6];
20577 u8 mac_set = 0;
20578 int ret;
20579
Dave Barachb7b92992018-10-17 10:38:51 -040020580 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020020581 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20582 {
20583 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
20584 ;
20585 else if (unformat (i, "sw_if_index %d", &parent_if_index))
20586 ;
20587 else
20588 if (unformat
20589 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
20590 mac_set++;
20591 else
20592 {
20593 clib_warning ("parse error '%U'", format_unformat_error, i);
20594 return -99;
20595 }
20596 }
20597
20598 if (parent_if_index == ~0)
20599 {
20600 errmsg ("missing interface name or sw_if_index");
20601 return -99;
20602 }
20603 if (mac_set == 0)
20604 {
20605 errmsg ("missing remote mac address");
20606 return -99;
20607 }
20608
20609 M (P2P_ETHERNET_DEL, mp);
20610 mp->parent_if_index = ntohl (parent_if_index);
20611 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
20612
20613 S (mp);
20614 W (ret);
20615 return ret;
20616}
Damjan Marion7cd468a2016-12-19 23:05:39 +010020617
20618static int
Steve Shin99a0e602017-07-01 04:16:20 +000020619api_lldp_config (vat_main_t * vam)
20620{
20621 unformat_input_t *i = vam->input;
20622 vl_api_lldp_config_t *mp;
20623 int tx_hold = 0;
20624 int tx_interval = 0;
20625 u8 *sys_name = NULL;
20626 int ret;
20627
20628 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20629 {
20630 if (unformat (i, "system-name %s", &sys_name))
20631 ;
20632 else if (unformat (i, "tx-hold %d", &tx_hold))
20633 ;
20634 else if (unformat (i, "tx-interval %d", &tx_interval))
20635 ;
20636 else
20637 {
20638 clib_warning ("parse error '%U'", format_unformat_error, i);
20639 return -99;
20640 }
20641 }
20642
20643 vec_add1 (sys_name, 0);
20644
20645 M (LLDP_CONFIG, mp);
20646 mp->tx_hold = htonl (tx_hold);
20647 mp->tx_interval = htonl (tx_interval);
20648 clib_memcpy (mp->system_name, sys_name, vec_len (sys_name));
20649 vec_free (sys_name);
20650
20651 S (mp);
20652 W (ret);
20653 return ret;
20654}
20655
20656static int
20657api_sw_interface_set_lldp (vat_main_t * vam)
20658{
20659 unformat_input_t *i = vam->input;
20660 vl_api_sw_interface_set_lldp_t *mp;
20661 u32 sw_if_index = ~0;
20662 u32 enable = 1;
Steve Shin9a6fcef2017-10-11 13:55:16 -070020663 u8 *port_desc = NULL, *mgmt_oid = NULL;
20664 ip4_address_t ip4_addr;
20665 ip6_address_t ip6_addr;
Steve Shin99a0e602017-07-01 04:16:20 +000020666 int ret;
20667
Dave Barachb7b92992018-10-17 10:38:51 -040020668 clib_memset (&ip4_addr, 0, sizeof (ip4_addr));
20669 clib_memset (&ip6_addr, 0, sizeof (ip6_addr));
Steve Shin9a6fcef2017-10-11 13:55:16 -070020670
Steve Shin99a0e602017-07-01 04:16:20 +000020671 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20672 {
20673 if (unformat (i, "disable"))
20674 enable = 0;
20675 else
20676 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20677 ;
20678 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20679 ;
20680 else if (unformat (i, "port-desc %s", &port_desc))
20681 ;
Steve Shin9a6fcef2017-10-11 13:55:16 -070020682 else if (unformat (i, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
20683 ;
20684 else if (unformat (i, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
20685 ;
20686 else if (unformat (i, "mgmt-oid %s", &mgmt_oid))
20687 ;
Steve Shin99a0e602017-07-01 04:16:20 +000020688 else
20689 break;
20690 }
20691
20692 if (sw_if_index == ~0)
20693 {
20694 errmsg ("missing interface name or sw_if_index");
20695 return -99;
20696 }
20697
20698 /* Construct the API message */
20699 vec_add1 (port_desc, 0);
Steve Shin9a6fcef2017-10-11 13:55:16 -070020700 vec_add1 (mgmt_oid, 0);
Steve Shin99a0e602017-07-01 04:16:20 +000020701 M (SW_INTERFACE_SET_LLDP, mp);
20702 mp->sw_if_index = ntohl (sw_if_index);
20703 mp->enable = enable;
20704 clib_memcpy (mp->port_desc, port_desc, vec_len (port_desc));
Steve Shin9a6fcef2017-10-11 13:55:16 -070020705 clib_memcpy (mp->mgmt_oid, mgmt_oid, vec_len (mgmt_oid));
20706 clib_memcpy (mp->mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
20707 clib_memcpy (mp->mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
Steve Shin99a0e602017-07-01 04:16:20 +000020708 vec_free (port_desc);
Steve Shin9a6fcef2017-10-11 13:55:16 -070020709 vec_free (mgmt_oid);
Steve Shin99a0e602017-07-01 04:16:20 +000020710
20711 S (mp);
20712 W (ret);
20713 return ret;
20714}
20715
20716static int
Dave Barach3bbcfab2017-08-15 19:03:44 -040020717api_tcp_configure_src_addresses (vat_main_t * vam)
20718{
20719 vl_api_tcp_configure_src_addresses_t *mp;
20720 unformat_input_t *i = vam->input;
20721 ip4_address_t v4first, v4last;
20722 ip6_address_t v6first, v6last;
20723 u8 range_set = 0;
20724 u32 vrf_id = 0;
20725 int ret;
20726
20727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20728 {
20729 if (unformat (i, "%U - %U",
20730 unformat_ip4_address, &v4first,
20731 unformat_ip4_address, &v4last))
20732 {
20733 if (range_set)
20734 {
20735 errmsg ("one range per message (range already set)");
20736 return -99;
20737 }
20738 range_set = 1;
20739 }
20740 else if (unformat (i, "%U - %U",
20741 unformat_ip6_address, &v6first,
20742 unformat_ip6_address, &v6last))
20743 {
20744 if (range_set)
20745 {
20746 errmsg ("one range per message (range already set)");
20747 return -99;
20748 }
20749 range_set = 2;
20750 }
20751 else if (unformat (i, "vrf %d", &vrf_id))
20752 ;
20753 else
20754 break;
20755 }
20756
20757 if (range_set == 0)
20758 {
20759 errmsg ("address range not set");
20760 return -99;
20761 }
20762
20763 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
20764 mp->vrf_id = ntohl (vrf_id);
20765 /* ipv6? */
20766 if (range_set == 2)
20767 {
20768 mp->is_ipv6 = 1;
20769 clib_memcpy (mp->first_address, &v6first, sizeof (v6first));
20770 clib_memcpy (mp->last_address, &v6last, sizeof (v6last));
20771 }
20772 else
20773 {
20774 mp->is_ipv6 = 0;
20775 clib_memcpy (mp->first_address, &v4first, sizeof (v4first));
20776 clib_memcpy (mp->last_address, &v4last, sizeof (v4last));
20777 }
20778 S (mp);
20779 W (ret);
20780 return ret;
20781}
20782
Florin Coras6e8c6672017-11-10 09:03:54 -080020783static void vl_api_app_namespace_add_del_reply_t_handler
20784 (vl_api_app_namespace_add_del_reply_t * mp)
20785{
20786 vat_main_t *vam = &vat_main;
20787 i32 retval = ntohl (mp->retval);
20788 if (vam->async_mode)
20789 {
20790 vam->async_errors += (retval < 0);
20791 }
20792 else
20793 {
20794 vam->retval = retval;
20795 if (retval == 0)
20796 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
20797 vam->result_ready = 1;
20798 }
20799}
20800
20801static void vl_api_app_namespace_add_del_reply_t_handler_json
20802 (vl_api_app_namespace_add_del_reply_t * mp)
20803{
20804 vat_main_t *vam = &vat_main;
20805 vat_json_node_t node;
20806
20807 vat_json_init_object (&node);
20808 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
20809 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
20810
20811 vat_json_print (vam->ofp, &node);
20812 vat_json_free (&node);
20813
20814 vam->retval = ntohl (mp->retval);
20815 vam->result_ready = 1;
20816}
20817
Dave Barach3bbcfab2017-08-15 19:03:44 -040020818static int
Florin Corascea194d2017-10-02 00:18:51 -070020819api_app_namespace_add_del (vat_main_t * vam)
20820{
20821 vl_api_app_namespace_add_del_t *mp;
20822 unformat_input_t *i = vam->input;
20823 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
20824 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
20825 u64 secret;
20826 int ret;
20827
20828 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20829 {
20830 if (unformat (i, "id %_%v%_", &ns_id))
20831 ;
20832 else if (unformat (i, "secret %lu", &secret))
20833 secret_set = 1;
20834 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20835 sw_if_index_set = 1;
20836 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
20837 ;
20838 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
20839 ;
20840 else
20841 break;
20842 }
20843 if (!ns_id || !secret_set || !sw_if_index_set)
20844 {
20845 errmsg ("namespace id, secret and sw_if_index must be set");
20846 return -99;
20847 }
20848 if (vec_len (ns_id) > 64)
20849 {
20850 errmsg ("namespace id too long");
20851 return -99;
20852 }
20853 M (APP_NAMESPACE_ADD_DEL, mp);
20854
20855 clib_memcpy (mp->namespace_id, ns_id, vec_len (ns_id));
20856 mp->namespace_id_len = vec_len (ns_id);
Florin Coras9a9adb22017-10-26 08:16:59 -070020857 mp->secret = clib_host_to_net_u64 (secret);
Florin Corascea194d2017-10-02 00:18:51 -070020858 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
20859 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
20860 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
20861 vec_free (ns_id);
20862 S (mp);
20863 W (ret);
20864 return ret;
20865}
20866
20867static int
Florin Coras90a63982017-12-19 04:50:01 -080020868api_sock_init_shm (vat_main_t * vam)
20869{
20870#if VPP_API_TEST_BUILTIN == 0
20871 unformat_input_t *i = vam->input;
20872 vl_api_shm_elem_config_t *config = 0;
20873 u64 size = 64 << 20;
20874 int rv;
20875
20876 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20877 {
20878 if (unformat (i, "size %U", unformat_memory_size, &size))
20879 ;
20880 else
20881 break;
20882 }
20883
Dave Barach78958722018-05-10 16:44:27 -040020884 /*
20885 * Canned custom ring allocator config.
20886 * Should probably parse all of this
20887 */
20888 vec_validate (config, 6);
Florin Coras90a63982017-12-19 04:50:01 -080020889 config[0].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080020890 config[0].size = 256;
Dave Barach78958722018-05-10 16:44:27 -040020891 config[0].count = 32;
20892
20893 config[1].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080020894 config[1].size = 1024;
Dave Barach78958722018-05-10 16:44:27 -040020895 config[1].count = 16;
20896
20897 config[2].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080020898 config[2].size = 4096;
Dave Barach78958722018-05-10 16:44:27 -040020899 config[2].count = 2;
20900
20901 config[3].type = VL_API_CLIENT_RING;
20902 config[3].size = 256;
20903 config[3].count = 32;
20904
20905 config[4].type = VL_API_CLIENT_RING;
20906 config[4].size = 1024;
20907 config[4].count = 16;
20908
20909 config[5].type = VL_API_CLIENT_RING;
20910 config[5].size = 4096;
20911 config[5].count = 2;
20912
20913 config[6].type = VL_API_QUEUE;
20914 config[6].count = 128;
20915 config[6].size = sizeof (uword);
20916
Tomasz Kulasek97dcf5b2019-01-31 18:26:32 +010020917 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
Florin Coras90a63982017-12-19 04:50:01 -080020918 if (!rv)
20919 vam->client_index_invalid = 1;
20920 return rv;
20921#else
20922 return -99;
20923#endif
20924}
20925
20926static int
Dave Barach65457162017-10-10 17:53:14 -040020927api_dns_enable_disable (vat_main_t * vam)
20928{
20929 unformat_input_t *line_input = vam->input;
20930 vl_api_dns_enable_disable_t *mp;
20931 u8 enable_disable = 1;
20932 int ret;
20933
20934 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
20935 {
20936 if (unformat (line_input, "disable"))
20937 enable_disable = 0;
20938 if (unformat (line_input, "enable"))
20939 enable_disable = 1;
20940 else
20941 break;
20942 }
20943
20944 /* Construct the API message */
20945 M (DNS_ENABLE_DISABLE, mp);
20946 mp->enable = enable_disable;
20947
20948 /* send it... */
20949 S (mp);
20950 /* Wait for the reply */
20951 W (ret);
20952 return ret;
20953}
20954
20955static int
20956api_dns_resolve_name (vat_main_t * vam)
20957{
20958 unformat_input_t *line_input = vam->input;
20959 vl_api_dns_resolve_name_t *mp;
20960 u8 *name = 0;
20961 int ret;
20962
20963 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
20964 {
20965 if (unformat (line_input, "%s", &name))
20966 ;
20967 else
20968 break;
20969 }
20970
20971 if (vec_len (name) > 127)
20972 {
20973 errmsg ("name too long");
20974 return -99;
20975 }
20976
20977 /* Construct the API message */
20978 M (DNS_RESOLVE_NAME, mp);
20979 memcpy (mp->name, name, vec_len (name));
20980 vec_free (name);
20981
20982 /* send it... */
20983 S (mp);
20984 /* Wait for the reply */
20985 W (ret);
20986 return ret;
20987}
20988
20989static int
Dave Barachd2080152017-10-20 09:21:35 -040020990api_dns_resolve_ip (vat_main_t * vam)
20991{
20992 unformat_input_t *line_input = vam->input;
20993 vl_api_dns_resolve_ip_t *mp;
20994 int is_ip6 = -1;
20995 ip4_address_t addr4;
20996 ip6_address_t addr6;
20997 int ret;
20998
20999 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
21000 {
21001 if (unformat (line_input, "%U", unformat_ip6_address, &addr6))
21002 is_ip6 = 1;
21003 else if (unformat (line_input, "%U", unformat_ip4_address, &addr4))
21004 is_ip6 = 0;
21005 else
21006 break;
21007 }
21008
21009 if (is_ip6 == -1)
21010 {
21011 errmsg ("missing address");
21012 return -99;
21013 }
21014
21015 /* Construct the API message */
21016 M (DNS_RESOLVE_IP, mp);
21017 mp->is_ip6 = is_ip6;
21018 if (is_ip6)
21019 memcpy (mp->address, &addr6, sizeof (addr6));
21020 else
21021 memcpy (mp->address, &addr4, sizeof (addr4));
21022
21023 /* send it... */
21024 S (mp);
21025 /* Wait for the reply */
21026 W (ret);
21027 return ret;
21028}
21029
21030static int
Dave Barach65457162017-10-10 17:53:14 -040021031api_dns_name_server_add_del (vat_main_t * vam)
21032{
21033 unformat_input_t *i = vam->input;
21034 vl_api_dns_name_server_add_del_t *mp;
21035 u8 is_add = 1;
21036 ip6_address_t ip6_server;
21037 ip4_address_t ip4_server;
21038 int ip6_set = 0;
21039 int ip4_set = 0;
21040 int ret = 0;
21041
21042 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21043 {
21044 if (unformat (i, "%U", unformat_ip6_address, &ip6_server))
21045 ip6_set = 1;
21046 else if (unformat (i, "%U", unformat_ip4_address, &ip4_server))
21047 ip4_set = 1;
21048 else if (unformat (i, "del"))
21049 is_add = 0;
21050 else
21051 {
21052 clib_warning ("parse error '%U'", format_unformat_error, i);
21053 return -99;
21054 }
21055 }
21056
21057 if (ip4_set && ip6_set)
21058 {
21059 errmsg ("Only one server address allowed per message");
21060 return -99;
21061 }
21062 if ((ip4_set + ip6_set) == 0)
21063 {
21064 errmsg ("Server address required");
21065 return -99;
21066 }
21067
21068 /* Construct the API message */
21069 M (DNS_NAME_SERVER_ADD_DEL, mp);
21070
21071 if (ip6_set)
21072 {
21073 memcpy (mp->server_address, &ip6_server, sizeof (ip6_address_t));
21074 mp->is_ip6 = 1;
21075 }
21076 else
21077 {
21078 memcpy (mp->server_address, &ip4_server, sizeof (ip4_address_t));
21079 mp->is_ip6 = 0;
21080 }
21081
21082 mp->is_add = is_add;
21083
21084 /* send it... */
21085 S (mp);
21086
21087 /* Wait for a reply, return good/bad news */
21088 W (ret);
21089 return ret;
21090}
21091
Florin Coras6c36f532017-11-03 18:32:34 -070021092static void
21093vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
21094{
21095 vat_main_t *vam = &vat_main;
21096
21097 if (mp->is_ip4)
21098 {
Florin Corasc97a7392017-11-05 23:07:07 -080021099 print (vam->ofp,
21100 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080021101 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
21102 mp->scope, format_ip4_address, &mp->lcl_ip, mp->lcl_plen,
21103 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
21104 &mp->rmt_ip, mp->rmt_plen, clib_net_to_host_u16 (mp->rmt_port),
21105 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070021106 }
21107 else
21108 {
Florin Corasc97a7392017-11-05 23:07:07 -080021109 print (vam->ofp,
21110 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080021111 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
21112 mp->scope, format_ip6_address, &mp->lcl_ip, mp->lcl_plen,
21113 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
21114 &mp->rmt_ip, mp->rmt_plen, clib_net_to_host_u16 (mp->rmt_port),
21115 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070021116 }
21117}
21118
21119static void
21120vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
21121 mp)
21122{
21123 vat_main_t *vam = &vat_main;
21124 vat_json_node_t *node = NULL;
21125 struct in6_addr ip6;
21126 struct in_addr ip4;
21127
21128 if (VAT_JSON_ARRAY != vam->json_tree.type)
21129 {
21130 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
21131 vat_json_init_array (&vam->json_tree);
21132 }
21133 node = vat_json_array_add (&vam->json_tree);
21134 vat_json_init_object (node);
21135
21136 vat_json_object_add_uint (node, "is_ip4", mp->is_ip4 ? 1 : 0);
21137 vat_json_object_add_uint (node, "appns_index",
21138 clib_net_to_host_u32 (mp->appns_index));
21139 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
21140 vat_json_object_add_uint (node, "scope", mp->scope);
21141 vat_json_object_add_uint (node, "action_index",
21142 clib_net_to_host_u32 (mp->action_index));
21143 vat_json_object_add_uint (node, "lcl_port",
21144 clib_net_to_host_u16 (mp->lcl_port));
21145 vat_json_object_add_uint (node, "rmt_port",
21146 clib_net_to_host_u16 (mp->rmt_port));
21147 vat_json_object_add_uint (node, "lcl_plen", mp->lcl_plen);
21148 vat_json_object_add_uint (node, "rmt_plen", mp->rmt_plen);
Florin Corasc97a7392017-11-05 23:07:07 -080021149 vat_json_object_add_string_copy (node, "tag", mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070021150 if (mp->is_ip4)
21151 {
21152 clib_memcpy (&ip4, mp->lcl_ip, sizeof (ip4));
21153 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
21154 clib_memcpy (&ip4, mp->rmt_ip, sizeof (ip4));
21155 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
21156 }
21157 else
21158 {
21159 clib_memcpy (&ip6, mp->lcl_ip, sizeof (ip6));
21160 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
21161 clib_memcpy (&ip6, mp->rmt_ip, sizeof (ip6));
21162 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
21163 }
21164}
21165
Florin Coras1c710452017-10-17 00:03:13 -070021166static int
21167api_session_rule_add_del (vat_main_t * vam)
21168{
21169 vl_api_session_rule_add_del_t *mp;
21170 unformat_input_t *i = vam->input;
21171 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
21172 u32 appns_index = 0, scope = 0;
21173 ip4_address_t lcl_ip4, rmt_ip4;
21174 ip6_address_t lcl_ip6, rmt_ip6;
21175 u8 is_ip4 = 1, conn_set = 0;
Florin Corasc97a7392017-11-05 23:07:07 -080021176 u8 is_add = 1, *tag = 0;
Florin Coras1c710452017-10-17 00:03:13 -070021177 int ret;
21178
21179 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21180 {
21181 if (unformat (i, "del"))
21182 is_add = 0;
21183 else if (unformat (i, "add"))
21184 ;
21185 else if (unformat (i, "proto tcp"))
21186 proto = 0;
21187 else if (unformat (i, "proto udp"))
21188 proto = 1;
21189 else if (unformat (i, "appns %d", &appns_index))
21190 ;
21191 else if (unformat (i, "scope %d", &scope))
21192 ;
Florin Corasc97a7392017-11-05 23:07:07 -080021193 else if (unformat (i, "tag %_%v%_", &tag))
21194 ;
Florin Coras1c710452017-10-17 00:03:13 -070021195 else
21196 if (unformat
21197 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
21198 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
21199 &rmt_port))
21200 {
21201 is_ip4 = 1;
21202 conn_set = 1;
21203 }
21204 else
21205 if (unformat
21206 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
21207 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
21208 &rmt_port))
21209 {
21210 is_ip4 = 0;
21211 conn_set = 1;
21212 }
21213 else if (unformat (i, "action %d", &action))
21214 ;
21215 else
21216 break;
21217 }
21218 if (proto == ~0 || !conn_set || action == ~0)
21219 {
21220 errmsg ("transport proto, connection and action must be set");
21221 return -99;
21222 }
21223
21224 if (scope > 3)
21225 {
21226 errmsg ("scope should be 0-3");
21227 return -99;
21228 }
21229
21230 M (SESSION_RULE_ADD_DEL, mp);
21231
21232 mp->is_ip4 = is_ip4;
21233 mp->transport_proto = proto;
Florin Corasc97a7392017-11-05 23:07:07 -080021234 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
21235 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
21236 mp->lcl_plen = lcl_plen;
21237 mp->rmt_plen = rmt_plen;
Florin Coras1c710452017-10-17 00:03:13 -070021238 mp->action_index = clib_host_to_net_u32 (action);
21239 mp->appns_index = clib_host_to_net_u32 (appns_index);
21240 mp->scope = scope;
21241 mp->is_add = is_add;
21242 if (is_ip4)
21243 {
21244 clib_memcpy (mp->lcl_ip, &lcl_ip4, sizeof (lcl_ip4));
21245 clib_memcpy (mp->rmt_ip, &rmt_ip4, sizeof (rmt_ip4));
21246 }
21247 else
21248 {
21249 clib_memcpy (mp->lcl_ip, &lcl_ip6, sizeof (lcl_ip6));
21250 clib_memcpy (mp->rmt_ip, &rmt_ip6, sizeof (rmt_ip6));
21251 }
Florin Corasc97a7392017-11-05 23:07:07 -080021252 if (tag)
21253 {
21254 clib_memcpy (mp->tag, tag, vec_len (tag));
21255 vec_free (tag);
21256 }
Florin Coras1c710452017-10-17 00:03:13 -070021257
21258 S (mp);
21259 W (ret);
21260 return ret;
21261}
Dave Barach65457162017-10-10 17:53:14 -040021262
21263static int
Florin Coras6c36f532017-11-03 18:32:34 -070021264api_session_rules_dump (vat_main_t * vam)
21265{
21266 vl_api_session_rules_dump_t *mp;
21267 vl_api_control_ping_t *mp_ping;
21268 int ret;
21269
21270 if (!vam->json_output)
21271 {
21272 print (vam->ofp, "%=20s", "Session Rules");
21273 }
21274
21275 M (SESSION_RULES_DUMP, mp);
21276 /* send it... */
21277 S (mp);
21278
21279 /* Use a control ping for synchronization */
21280 MPING (CONTROL_PING, mp_ping);
21281 S (mp_ping);
21282
21283 /* Wait for a reply... */
21284 W (ret);
21285 return ret;
21286}
21287
21288static int
Florin Coras595992c2017-11-06 17:17:08 -080021289api_ip_container_proxy_add_del (vat_main_t * vam)
21290{
21291 vl_api_ip_container_proxy_add_del_t *mp;
21292 unformat_input_t *i = vam->input;
Neale Ranns37029302018-08-10 05:30:06 -070021293 u32 sw_if_index = ~0;
21294 vl_api_prefix_t pfx = { };
Florin Coras595992c2017-11-06 17:17:08 -080021295 u8 is_add = 1;
21296 int ret;
21297
21298 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21299 {
21300 if (unformat (i, "del"))
21301 is_add = 0;
21302 else if (unformat (i, "add"))
21303 ;
Neale Ranns37029302018-08-10 05:30:06 -070021304 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
21305 ;
Florin Coras595992c2017-11-06 17:17:08 -080021306 else if (unformat (i, "sw_if_index %u", &sw_if_index))
21307 ;
21308 else
21309 break;
21310 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040021311 if (sw_if_index == ~0 || pfx.len == 0)
Florin Coras595992c2017-11-06 17:17:08 -080021312 {
21313 errmsg ("address and sw_if_index must be set");
21314 return -99;
21315 }
21316
21317 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
21318
Florin Coras595992c2017-11-06 17:17:08 -080021319 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
Florin Coras595992c2017-11-06 17:17:08 -080021320 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -070021321 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
Florin Coras595992c2017-11-06 17:17:08 -080021322
21323 S (mp);
21324 W (ret);
21325 return ret;
21326}
21327
21328static int
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070021329api_qos_record_enable_disable (vat_main_t * vam)
21330{
21331 unformat_input_t *i = vam->input;
21332 vl_api_qos_record_enable_disable_t *mp;
21333 u32 sw_if_index, qs = 0xff;
21334 u8 sw_if_index_set = 0;
21335 u8 enable = 1;
21336 int ret;
21337
21338 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21339 {
21340 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21341 sw_if_index_set = 1;
21342 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21343 sw_if_index_set = 1;
21344 else if (unformat (i, "%U", unformat_qos_source, &qs))
21345 ;
21346 else if (unformat (i, "disable"))
21347 enable = 0;
21348 else
21349 {
21350 clib_warning ("parse error '%U'", format_unformat_error, i);
21351 return -99;
21352 }
21353 }
21354
21355 if (sw_if_index_set == 0)
21356 {
21357 errmsg ("missing interface name or sw_if_index");
21358 return -99;
21359 }
21360 if (qs == 0xff)
21361 {
21362 errmsg ("input location must be specified");
21363 return -99;
21364 }
21365
21366 M (QOS_RECORD_ENABLE_DISABLE, mp);
21367
21368 mp->sw_if_index = ntohl (sw_if_index);
21369 mp->input_source = qs;
21370 mp->enable = enable;
21371
21372 S (mp);
21373 W (ret);
21374 return ret;
21375}
21376
Dave Barach048a4e52018-06-01 18:52:25 -040021377
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070021378static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010021379q_or_quit (vat_main_t * vam)
21380{
Dave Barachdef19da2017-02-22 17:29:20 -050021381#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010021382 longjmp (vam->jump_buf, 1);
Dave Barachdef19da2017-02-22 17:29:20 -050021383#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021384 return 0; /* not so much */
21385}
21386
21387static int
21388q (vat_main_t * vam)
21389{
21390 return q_or_quit (vam);
21391}
21392
21393static int
21394quit (vat_main_t * vam)
21395{
21396 return q_or_quit (vam);
21397}
21398
21399static int
21400comment (vat_main_t * vam)
21401{
21402 return 0;
21403}
21404
21405static int
Dave Barach048a4e52018-06-01 18:52:25 -040021406statseg (vat_main_t * vam)
21407{
21408 ssvm_private_t *ssvmp = &vam->stat_segment;
21409 ssvm_shared_header_t *shared_header = ssvmp->sh;
21410 vlib_counter_t **counters;
21411 u64 thread0_index1_packets;
21412 u64 thread0_index1_bytes;
21413 f64 vector_rate, input_rate;
21414 uword *p;
21415
21416 uword *counter_vector_by_name;
21417 if (vam->stat_segment_lockp == 0)
21418 {
21419 errmsg ("Stat segment not mapped...");
21420 return -99;
21421 }
21422
21423 /* look up "/if/rx for sw_if_index 1 as a test */
21424
21425 clib_spinlock_lock (vam->stat_segment_lockp);
21426
21427 counter_vector_by_name = (uword *) shared_header->opaque[1];
21428
21429 p = hash_get_mem (counter_vector_by_name, "/if/rx");
21430 if (p == 0)
21431 {
21432 clib_spinlock_unlock (vam->stat_segment_lockp);
21433 errmsg ("/if/tx not found?");
21434 return -99;
21435 }
21436
21437 /* Fish per-thread vector of combined counters from shared memory */
21438 counters = (vlib_counter_t **) p[0];
21439
21440 if (vec_len (counters[0]) < 2)
21441 {
21442 clib_spinlock_unlock (vam->stat_segment_lockp);
21443 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
21444 return -99;
21445 }
21446
21447 /* Read thread 0 sw_if_index 1 counter */
21448 thread0_index1_packets = counters[0][1].packets;
21449 thread0_index1_bytes = counters[0][1].bytes;
21450
21451 p = hash_get_mem (counter_vector_by_name, "vector_rate");
21452 if (p == 0)
21453 {
21454 clib_spinlock_unlock (vam->stat_segment_lockp);
21455 errmsg ("vector_rate not found?");
21456 return -99;
21457 }
21458
21459 vector_rate = *(f64 *) (p[0]);
21460 p = hash_get_mem (counter_vector_by_name, "input_rate");
21461 if (p == 0)
21462 {
21463 clib_spinlock_unlock (vam->stat_segment_lockp);
21464 errmsg ("input_rate not found?");
21465 return -99;
21466 }
21467 input_rate = *(f64 *) (p[0]);
21468
21469 clib_spinlock_unlock (vam->stat_segment_lockp);
21470
21471 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
21472 vector_rate, input_rate);
21473 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
21474 thread0_index1_packets, thread0_index1_bytes);
21475
21476 return 0;
21477}
21478
21479static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010021480cmd_cmp (void *a1, void *a2)
21481{
21482 u8 **c1 = a1;
21483 u8 **c2 = a2;
21484
21485 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
21486}
21487
21488static int
21489help (vat_main_t * vam)
21490{
21491 u8 **cmds = 0;
21492 u8 *name = 0;
21493 hash_pair_t *p;
21494 unformat_input_t *i = vam->input;
21495 int j;
21496
21497 if (unformat (i, "%s", &name))
21498 {
21499 uword *hs;
21500
21501 vec_add1 (name, 0);
21502
21503 hs = hash_get_mem (vam->help_by_name, name);
21504 if (hs)
21505 print (vam->ofp, "usage: %s %s", name, hs[0]);
21506 else
21507 print (vam->ofp, "No such msg / command '%s'", name);
21508 vec_free (name);
21509 return 0;
21510 }
21511
21512 print (vam->ofp, "Help is available for the following:");
21513
21514 /* *INDENT-OFF* */
21515 hash_foreach_pair (p, vam->function_by_name,
21516 ({
21517 vec_add1 (cmds, (u8 *)(p->key));
21518 }));
21519 /* *INDENT-ON* */
21520
21521 vec_sort_with_function (cmds, cmd_cmp);
21522
21523 for (j = 0; j < vec_len (cmds); j++)
21524 print (vam->ofp, "%s", cmds[j]);
21525
21526 vec_free (cmds);
21527 return 0;
21528}
21529
21530static int
21531set (vat_main_t * vam)
21532{
21533 u8 *name = 0, *value = 0;
21534 unformat_input_t *i = vam->input;
21535
21536 if (unformat (i, "%s", &name))
21537 {
21538 /* The input buffer is a vector, not a string. */
21539 value = vec_dup (i->buffer);
21540 vec_delete (value, i->index, 0);
21541 /* Almost certainly has a trailing newline */
21542 if (value[vec_len (value) - 1] == '\n')
21543 value[vec_len (value) - 1] = 0;
21544 /* Make sure it's a proper string, one way or the other */
21545 vec_add1 (value, 0);
21546 (void) clib_macro_set_value (&vam->macro_main,
21547 (char *) name, (char *) value);
21548 }
21549 else
21550 errmsg ("usage: set <name> <value>");
21551
21552 vec_free (name);
21553 vec_free (value);
21554 return 0;
21555}
21556
21557static int
21558unset (vat_main_t * vam)
21559{
21560 u8 *name = 0;
21561
21562 if (unformat (vam->input, "%s", &name))
21563 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
21564 errmsg ("unset: %s wasn't set", name);
21565 vec_free (name);
21566 return 0;
21567}
21568
21569typedef struct
21570{
21571 u8 *name;
21572 u8 *value;
21573} macro_sort_t;
21574
21575
21576static int
21577macro_sort_cmp (void *a1, void *a2)
21578{
21579 macro_sort_t *s1 = a1;
21580 macro_sort_t *s2 = a2;
21581
21582 return strcmp ((char *) (s1->name), (char *) (s2->name));
21583}
21584
21585static int
21586dump_macro_table (vat_main_t * vam)
21587{
21588 macro_sort_t *sort_me = 0, *sm;
21589 int i;
21590 hash_pair_t *p;
21591
21592 /* *INDENT-OFF* */
21593 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
21594 ({
21595 vec_add2 (sort_me, sm, 1);
21596 sm->name = (u8 *)(p->key);
21597 sm->value = (u8 *) (p->value[0]);
21598 }));
21599 /* *INDENT-ON* */
21600
21601 vec_sort_with_function (sort_me, macro_sort_cmp);
21602
21603 if (vec_len (sort_me))
21604 print (vam->ofp, "%-15s%s", "Name", "Value");
21605 else
21606 print (vam->ofp, "The macro table is empty...");
21607
21608 for (i = 0; i < vec_len (sort_me); i++)
21609 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
21610 return 0;
21611}
21612
21613static int
21614dump_node_table (vat_main_t * vam)
21615{
21616 int i, j;
21617 vlib_node_t *node, *next_node;
21618
21619 if (vec_len (vam->graph_nodes) == 0)
21620 {
21621 print (vam->ofp, "Node table empty, issue get_node_graph...");
21622 return 0;
21623 }
21624
Dave Barach1ddbc012018-06-13 09:26:05 -040021625 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010021626 {
Dave Barach1ddbc012018-06-13 09:26:05 -040021627 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +010021628 print (vam->ofp, "[%d] %s", i, node->name);
21629 for (j = 0; j < vec_len (node->next_nodes); j++)
21630 {
21631 if (node->next_nodes[j] != ~0)
21632 {
Dave Barach1ddbc012018-06-13 09:26:05 -040021633 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010021634 print (vam->ofp, " [%d] %s", j, next_node->name);
21635 }
21636 }
21637 }
21638 return 0;
21639}
21640
21641static int
21642value_sort_cmp (void *a1, void *a2)
21643{
21644 name_sort_t *n1 = a1;
21645 name_sort_t *n2 = a2;
21646
21647 if (n1->value < n2->value)
21648 return -1;
21649 if (n1->value > n2->value)
21650 return 1;
21651 return 0;
21652}
21653
21654
21655static int
21656dump_msg_api_table (vat_main_t * vam)
21657{
21658 api_main_t *am = &api_main;
21659 name_sort_t *nses = 0, *ns;
21660 hash_pair_t *hp;
21661 int i;
21662
21663 /* *INDENT-OFF* */
21664 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
21665 ({
21666 vec_add2 (nses, ns, 1);
21667 ns->name = (u8 *)(hp->key);
21668 ns->value = (u32) hp->value[0];
21669 }));
21670 /* *INDENT-ON* */
21671
21672 vec_sort_with_function (nses, value_sort_cmp);
21673
21674 for (i = 0; i < vec_len (nses); i++)
21675 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
21676 vec_free (nses);
21677 return 0;
21678}
21679
21680static int
21681get_msg_id (vat_main_t * vam)
21682{
21683 u8 *name_and_crc;
21684 u32 message_index;
21685
21686 if (unformat (vam->input, "%s", &name_and_crc))
21687 {
Florin Corase86a8ed2018-01-05 03:20:25 -080021688 message_index = vl_msg_api_get_msg_index (name_and_crc);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021689 if (message_index == ~0)
21690 {
21691 print (vam->ofp, " '%s' not found", name_and_crc);
21692 return 0;
21693 }
21694 print (vam->ofp, " '%s' has message index %d",
21695 name_and_crc, message_index);
21696 return 0;
21697 }
21698 errmsg ("name_and_crc required...");
21699 return 0;
21700}
21701
21702static int
21703search_node_table (vat_main_t * vam)
21704{
21705 unformat_input_t *line_input = vam->input;
21706 u8 *node_to_find;
21707 int j;
21708 vlib_node_t *node, *next_node;
21709 uword *p;
21710
21711 if (vam->graph_node_index_by_name == 0)
21712 {
21713 print (vam->ofp, "Node table empty, issue get_node_graph...");
21714 return 0;
21715 }
21716
21717 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
21718 {
21719 if (unformat (line_input, "%s", &node_to_find))
21720 {
21721 vec_add1 (node_to_find, 0);
21722 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
21723 if (p == 0)
21724 {
21725 print (vam->ofp, "%s not found...", node_to_find);
21726 goto out;
21727 }
Dave Barach1ddbc012018-06-13 09:26:05 -040021728 node = vam->graph_nodes[0][p[0]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010021729 print (vam->ofp, "[%d] %s", p[0], node->name);
21730 for (j = 0; j < vec_len (node->next_nodes); j++)
21731 {
21732 if (node->next_nodes[j] != ~0)
21733 {
Dave Barach1ddbc012018-06-13 09:26:05 -040021734 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010021735 print (vam->ofp, " [%d] %s", j, next_node->name);
21736 }
21737 }
21738 }
21739
21740 else
21741 {
21742 clib_warning ("parse error '%U'", format_unformat_error,
21743 line_input);
21744 return -99;
21745 }
21746
21747 out:
21748 vec_free (node_to_find);
21749
21750 }
21751
21752 return 0;
21753}
21754
21755
21756static int
21757script (vat_main_t * vam)
21758{
21759#if (VPP_API_TEST_BUILTIN==0)
21760 u8 *s = 0;
21761 char *save_current_file;
21762 unformat_input_t save_input;
21763 jmp_buf save_jump_buf;
21764 u32 save_line_number;
21765
21766 FILE *new_fp, *save_ifp;
21767
21768 if (unformat (vam->input, "%s", &s))
21769 {
21770 new_fp = fopen ((char *) s, "r");
21771 if (new_fp == 0)
21772 {
21773 errmsg ("Couldn't open script file %s", s);
21774 vec_free (s);
21775 return -99;
21776 }
21777 }
21778 else
21779 {
21780 errmsg ("Missing script name");
21781 return -99;
21782 }
21783
21784 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
21785 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
21786 save_ifp = vam->ifp;
21787 save_line_number = vam->input_line_number;
21788 save_current_file = (char *) vam->current_file;
21789
21790 vam->input_line_number = 0;
21791 vam->ifp = new_fp;
21792 vam->current_file = s;
21793 do_one_file (vam);
21794
Sirshak Dasb0861822018-05-29 21:13:21 -050021795 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
Damjan Marion7cd468a2016-12-19 23:05:39 +010021796 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
21797 vam->ifp = save_ifp;
21798 vam->input_line_number = save_line_number;
21799 vam->current_file = (u8 *) save_current_file;
21800 vec_free (s);
21801
21802 return 0;
21803#else
21804 clib_warning ("use the exec command...");
21805 return -99;
21806#endif
21807}
21808
21809static int
21810echo (vat_main_t * vam)
21811{
21812 print (vam->ofp, "%v", vam->input->buffer);
21813 return 0;
21814}
21815
21816/* List of API message constructors, CLI names map to api_xxx */
21817#define foreach_vpe_api_msg \
Jon Loeligerc83c3b72017-02-23 13:57:35 -060021818_(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021819_(sw_interface_dump,"") \
21820_(sw_interface_set_flags, \
21821 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
21822_(sw_interface_add_del_address, \
21823 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
Stevenad8015b2017-10-29 22:10:46 -070021824_(sw_interface_set_rx_mode, \
21825 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +020021826_(sw_interface_set_rx_placement, \
21827 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +020021828_(sw_interface_rx_placement_dump, \
21829 "[<intfc> | sw_if_index <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021830_(sw_interface_set_table, \
21831 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
21832_(sw_interface_set_mpls_enable, \
21833 "<intfc> | sw_if_index [disable | dis]") \
21834_(sw_interface_set_vpath, \
21835 "<intfc> | sw_if_index <id> enable | disable") \
21836_(sw_interface_set_vxlan_bypass, \
John Lo2b81eb82017-01-30 13:12:10 -050021837 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020021838_(sw_interface_set_geneve_bypass, \
21839 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021840_(sw_interface_set_l2_xconnect, \
21841 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
21842 "enable | disable") \
21843_(sw_interface_set_l2_bridge, \
Eyal Barif24991c2017-04-05 05:33:21 +030021844 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021845 "[shg <split-horizon-group>] [bvi]\n" \
21846 "enable | disable") \
Eyal Barif24991c2017-04-05 05:33:21 +030021847_(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021848_(bridge_domain_add_del, \
John Lo70bfcaf2017-11-14 13:19:26 -050021849 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [mac-age 0-255] [bd-tag <text>] [del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021850_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
21851_(l2fib_add_del, \
21852 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
Eyal Barif24991c2017-04-05 05:33:21 +030021853_(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
21854_(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021855_(l2_flags, \
John Lo8d00fff2017-08-03 00:35:36 -040021856 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021857_(bridge_flags, \
21858 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion8389fb92017-10-13 18:29:53 +020021859_(tap_create_v2, \
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020021860 "id <num> [hw-addr <mac-addr>] [host-ns <name>] [rx-ring-size <num> [tx-ring-size <num>] [host-mtu-size <mtu>] [gso | no-gso]") \
Damjan Marion8389fb92017-10-13 18:29:53 +020021861_(tap_delete_v2, \
21862 "<vpp-if-name> | sw_if_index <id>") \
21863_(sw_interface_tap_v2_dump, "") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010021864_(virtio_pci_create, \
Mohsin Kazmibbd6b742019-05-02 13:54:59 +020021865 "pci-addr <pci-address> [use_random_mac | hw-addr <mac-addr>] [features <hex-value>] [gso-enabled]") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010021866_(virtio_pci_delete, \
21867 "<vpp-if-name> | sw_if_index <id>") \
21868_(sw_interface_virtio_pci_dump, "") \
Steven9cd2d7a2017-12-20 12:43:01 -080021869_(bond_create, \
21870 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
Alexander Chernavinad9d5282018-12-13 09:08:09 -050021871 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
21872 "[id <if-id>]") \
Steven9cd2d7a2017-12-20 12:43:01 -080021873_(bond_delete, \
21874 "<vpp-if-name> | sw_if_index <id>") \
21875_(bond_enslave, \
21876 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
21877_(bond_detach_slave, \
21878 "sw_if_index <n>") \
21879_(sw_interface_bond_dump, "") \
21880_(sw_interface_slave_dump, \
21881 "<vpp-if-name> | sw_if_index <id>") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070021882_(ip_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040021883 "table <n> [ipv6] [add | del]\n") \
Neale Ranns097fa662018-05-01 05:17:55 -070021884_(ip_route_add_del, \
John Lo22030432018-09-20 16:07:00 -040021885 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
21886 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
John Lo06fda9c2018-10-03 16:32:44 -040021887 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
21888 "[multipath] [count <n>] [del]") \
Neale Ranns32e1c012016-11-22 17:07:28 +000021889_(ip_mroute_add_del, \
21890 "<src> <grp>/<mask> [table-id <n>]\n" \
21891 "[<intfc> | sw_if_index <id>] [local] [del]") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070021892_(mpls_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040021893 "table <n> [add | del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021894_(mpls_route_add_del, \
John Loe166fd92018-09-13 14:08:59 -040021895 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
21896 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
21897 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
21898 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
John Lo06fda9c2018-10-03 16:32:44 -040021899 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
21900 "[count <n>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021901_(mpls_ip_bind_unbind, \
21902 "<label> <addr/len>") \
21903_(mpls_tunnel_add_del, \
John Lo06fda9c2018-10-03 16:32:44 -040021904 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
21905 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
21906 "[l2-only] [out-label <n>]") \
John Loe166fd92018-09-13 14:08:59 -040021907_(sr_mpls_policy_add, \
21908 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
21909_(sr_mpls_policy_del, \
21910 "bsid <id>") \
Neale Rannsd792d9c2017-10-21 10:53:20 -070021911_(bier_table_add_del, \
21912 "<label> <sub-domain> <set> <bsl> [del]") \
21913_(bier_route_add_del, \
21914 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
21915 "[<intfc> | sw_if_index <id>]" \
21916 "[weight <n>] [del] [multipath]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021917_(proxy_arp_add_del, \
21918 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
21919_(proxy_arp_intfc_enable_disable, \
21920 "<intfc> | sw_if_index <id> enable | disable") \
21921_(sw_interface_set_unnumbered, \
21922 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
21923_(ip_neighbor_add_del, \
21924 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
21925 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021926_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
21927_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
21928 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
21929 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
21930 "[outer_vlan_id_any][inner_vlan_id_any]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021931_(reset_fib, "vrf <n> [ipv6]") \
21932_(dhcp_proxy_config, \
21933 "svr <v46-address> src <v46-address>\n" \
Neale Ranns20a175a2017-02-14 07:28:41 -080021934 "rx_vrf_id <nn> server_vrf_id <nn> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021935_(dhcp_proxy_set_vss, \
John Lo70bfcaf2017-11-14 13:19:26 -050021936 "tbl_id <n> [fib_id <n> oui <n> | vpn_ascii_id <text>] [ipv6] [del]") \
Neale Ranns20a175a2017-02-14 07:28:41 -080021937_(dhcp_proxy_dump, "ip6") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021938_(dhcp_client_config, \
21939 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
21940_(set_ip_flow_hash, \
21941 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
21942_(sw_interface_ip6_enable_disable, \
21943 "<intfc> | sw_if_index <id> enable | disable") \
Neale Ranns3f844d02017-02-18 00:03:54 -080021944_(ip6nd_proxy_add_del, \
21945 "<intfc> | sw_if_index <id> <ip6-address>") \
21946_(ip6nd_proxy_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021947_(sw_interface_ip6nd_ra_prefix, \
21948 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
21949 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
21950 "[nolink] [isno]") \
21951_(sw_interface_ip6nd_ra_config, \
21952 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
21953 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
21954 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
21955_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
21956_(l2_patch_add_del, \
21957 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
21958 "enable | disable") \
Pablo Camarillofb380952016-12-07 18:34:18 +010021959_(sr_localsid_add_del, \
21960 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
21961 "fib-table <num> (end.psp) sw_if_index <num>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021962_(classify_add_del_table, \
21963 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
21964 " [del] [del-chain] mask <mask-value>\n" \
21965 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
21966 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
21967_(classify_add_del_session, \
21968 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
21969 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
21970 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
21971 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
21972_(classify_set_interface_ip_table, \
21973 "<intfc> | sw_if_index <nn> table <nn>") \
21974_(classify_set_interface_l2_tables, \
21975 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
21976 " [other-table <nn>]") \
21977_(get_node_index, "node <node-name") \
21978_(add_node_next, "node <node-name> next <next-node-name>") \
21979_(l2tpv3_create_tunnel, \
21980 "client_address <ip6-addr> our_address <ip6-addr>\n" \
21981 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n" \
21982 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
21983_(l2tpv3_set_tunnel_cookies, \
21984 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
21985 "[new_remote_cookie <nn>]\n") \
21986_(l2tpv3_interface_enable_disable, \
21987 "<intfc> | sw_if_index <nn> enable | disable") \
21988_(l2tpv3_set_lookup_key, \
21989 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
21990_(sw_if_l2tpv3_tunnel_dump, "") \
eyal bariaf86a482018-04-17 11:20:27 +030021991_(vxlan_offload_rx, \
21992 "hw { <interface name> | hw_if_index <nn>} " \
21993 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021994_(vxlan_add_del_tunnel, \
21995 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
Jon Loeliger3d460bd2018-02-01 16:36:12 -060021996 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021997 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020021998_(geneve_add_del_tunnel, \
21999 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
22000 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
22001 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022002_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020022003_(geneve_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Neale Ranns5a8844b2019-04-16 07:15:35 +000022004_(gre_tunnel_add_del, \
John Loa43ccae2018-02-13 17:15:23 -050022005 "src <ip-addr> dst <ip-addr> [outer-fib-id <nn>] [instance <n>]\n" \
22006 "[teb | erspan <session-id>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022007_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
22008_(l2_fib_clear_table, "") \
22009_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
22010_(l2_interface_vlan_tag_rewrite, \
22011 "<intfc> | sw_if_index <nn> \n" \
22012 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
22013 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
22014_(create_vhost_user_if, \
22015 "socket <filename> [server] [renumber <dev_instance>] " \
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020022016 "[disable_mrg_rxbuf] [disable_indirect_desc] " \
Stevenf3b53642017-05-01 14:03:02 -070022017 "[mac <mac_address>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022018_(modify_vhost_user_if, \
22019 "<intfc> | sw_if_index <nn> socket <filename>\n" \
Stevenf3b53642017-05-01 14:03:02 -070022020 "[server] [renumber <dev_instance>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022021_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
22022_(sw_interface_vhost_user_dump, "") \
22023_(show_version, "") \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020022024_(show_threads, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022025_(vxlan_gpe_add_del_tunnel, \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080022026 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
22027 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
22028 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
22029 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022030_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
22031_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
22032_(interface_name_renumber, \
22033 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
22034_(input_acl_set_interface, \
22035 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
22036 " [l2-table <nn>] [del]") \
John Loc7b43042018-04-13 16:46:22 -040022037_(ip_probe_neighbor, "(<intc> | sw_if_index <nn>) address <ip4|ip6-addr>") \
John Lo7f358b32018-04-28 01:19:24 -040022038_(ip_scan_neighbor_enable_disable, "[ip4|ip6|both|disable] [interval <n-min>]\n" \
22039 " [max-time <n-usec>] [max-update <n>] [delay <n-msec>] [stale <n-min>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022040_(want_ip4_arp_events, "address <ip4-address> [del]") \
22041_(want_ip6_nd_events, "address <ip6-address> [del]") \
John Lo8d00fff2017-08-03 00:35:36 -040022042_(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022043_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
22044_(ip_dump, "ipv4 | ipv6") \
22045_(ipsec_spd_add_del, "spd_id <n> [del]") \
22046_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
22047 " spid_id <n> ") \
Neale Ranns17dcec02019-01-09 21:22:20 -080022048_(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022049 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
22050 " integ_alg <alg> integ_key <hex>") \
Neale Ranns17dcec02019-01-09 21:22:20 -080022051_(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022052 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
22053 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
22054 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
Matthew Smithb0972cb2017-05-02 16:20:41 -050022055_(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
22056 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
22057 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
Matthew Smith8e1039a2018-04-12 07:32:56 -050022058 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
22059 " [instance <n>]") \
Matthew Smith28029532017-09-26 13:33:44 -050022060_(ipsec_sa_dump, "[sa_id <n>]") \
Matthew Smithca514fd2017-10-12 12:06:59 -050022061_(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022062_(delete_loopback,"sw_if_index <nn>") \
22063_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
John Loe26c81f2019-01-07 15:16:33 -050022064_(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
22065_(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022066_(want_interface_events, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022067_(get_first_msg_id, "client <name>") \
22068_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
22069_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
22070 "fib-id <nn> [ip4][ip6][default]") \
22071_(get_node_graph, " ") \
22072_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
22073_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
22074_(ioam_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022075_(one_add_del_locator_set, "locator-set <locator_name> [iface <intf> |" \
22076 " sw_if_index <sw_if_index> p <priority> " \
22077 "w <weight>] [del]") \
22078_(one_add_del_locator, "locator-set <locator_name> " \
22079 "iface <intf> | sw_if_index <sw_if_index> " \
22080 "p <priority> w <weight> [del]") \
22081_(one_add_del_local_eid,"vni <vni> eid " \
22082 "<ipv4|ipv6>/<prefix> | <L2 address> " \
22083 "locator-set <locator_name> [del]" \
22084 "[key-id sha1|sha256 secret-key <secret-key>]")\
22085_(one_add_del_map_resolver, "<ip4|6-addr> [del]") \
22086_(one_add_del_map_server, "<ip4|6-addr> [del]") \
22087_(one_enable_disable, "enable|disable") \
22088_(one_map_register_enable_disable, "enable|disable") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020022089_(one_map_register_fallback_threshold, "<value>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022090_(one_rloc_probe_enable_disable, "enable|disable") \
22091_(one_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
22092 "[seid <seid>] " \
22093 "rloc <locator> p <prio> " \
22094 "w <weight> [rloc <loc> ... ] " \
22095 "action <action> [del-all]") \
22096_(one_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
22097 "<local-eid>") \
22098_(one_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010022099_(one_use_petr, "ip-address> | disable") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022100_(one_map_request_mode, "src-dst|dst-only") \
22101_(one_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
22102_(one_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
22103_(one_locator_set_dump, "[local | remote]") \
22104_(one_locator_dump, "ls_index <index> | ls_name <name>") \
22105_(one_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
22106 "[local] | [remote]") \
Filip Tehlar05879992017-09-05 15:46:09 +020022107_(one_add_del_ndp_entry, "[del] mac <mac> bd <bd> ip6 <ip6>") \
22108_(one_ndp_bd_get, "") \
22109_(one_ndp_entries_get, "bd <bridge-domain>") \
Filip Tehlard5a65db2017-05-17 17:21:10 +020022110_(one_add_del_l2_arp_entry, "[del] mac <mac> bd <bd> ip4 <ip4>") \
22111_(one_l2_arp_bd_get, "") \
22112_(one_l2_arp_entries_get, "bd <bridge-domain>") \
Paul Vinciguerraec11b132018-09-24 05:25:00 -070022113_(one_stats_enable_disable, "enable|disable") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010022114_(show_one_stats_enable_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022115_(one_eid_table_vni_dump, "") \
22116_(one_eid_table_map_dump, "l2|l3") \
22117_(one_map_resolver_dump, "") \
22118_(one_map_server_dump, "") \
22119_(one_adjacencies_get, "vni <vni>") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020022120_(one_nsh_set_locator_set, "[del] ls <locator-set-name>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022121_(show_one_rloc_probe_state, "") \
22122_(show_one_map_register_state, "") \
22123_(show_one_status, "") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010022124_(one_stats_dump, "") \
Filip Tehlar21511912017-04-07 10:41:42 +020022125_(one_stats_flush, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022126_(one_get_map_request_itr_rlocs, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020022127_(one_map_register_set_ttl, "<ttl>") \
Filip Tehlara4980b82017-09-27 14:32:02 +020022128_(one_set_transport_protocol, "udp|api") \
22129_(one_get_transport_protocol, "") \
Filip Tehlar0a8840d2017-10-16 05:48:23 -070022130_(one_enable_disable_xtr_mode, "enable|disable") \
22131_(one_show_xtr_mode, "") \
22132_(one_enable_disable_pitr_mode, "enable|disable") \
22133_(one_show_pitr_mode, "") \
22134_(one_enable_disable_petr_mode, "enable|disable") \
22135_(one_show_petr_mode, "") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020022136_(show_one_nsh_mapping, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022137_(show_one_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010022138_(show_one_use_petr, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022139_(show_one_map_request_mode, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020022140_(show_one_map_register_ttl, "") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020022141_(show_one_map_register_fallback_threshold, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022142_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
Damjan Marion7cd468a2016-12-19 23:05:39 +010022143 " sw_if_index <sw_if_index> p <priority> " \
22144 "w <weight>] [del]") \
22145_(lisp_add_del_locator, "locator-set <locator_name> " \
22146 "iface <intf> | sw_if_index <sw_if_index> " \
22147 "p <priority> w <weight> [del]") \
22148_(lisp_add_del_local_eid,"vni <vni> eid " \
22149 "<ipv4|ipv6>/<prefix> | <L2 address> " \
22150 "locator-set <locator_name> [del]" \
22151 "[key-id sha1|sha256 secret-key <secret-key>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022152_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
22153_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022154_(lisp_enable_disable, "enable|disable") \
22155_(lisp_map_register_enable_disable, "enable|disable") \
22156_(lisp_rloc_probe_enable_disable, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022157_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
22158 "[seid <seid>] " \
22159 "rloc <locator> p <prio> " \
22160 "w <weight> [rloc <loc> ... ] " \
22161 "action <action> [del-all]") \
22162_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
22163 "<local-eid>") \
22164_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010022165_(lisp_use_petr, "<ip-address> | disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022166_(lisp_map_request_mode, "src-dst|dst-only") \
22167_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
22168_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
22169_(lisp_locator_set_dump, "[local | remote]") \
22170_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
22171_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
22172 "[local] | [remote]") \
22173_(lisp_eid_table_vni_dump, "") \
22174_(lisp_eid_table_map_dump, "l2|l3") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022175_(lisp_map_resolver_dump, "") \
22176_(lisp_map_server_dump, "") \
22177_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar0eb874e2017-05-18 14:23:32 +020022178_(gpe_fwd_entry_vnis_get, "") \
Filip Tehlarb4243aa2017-06-14 14:39:42 +020022179_(gpe_native_fwd_rpaths_get, "ip4 | ip6") \
22180_(gpe_add_del_native_fwd_rpath, "[del] via <nh-ip-addr> [iface] " \
22181 "[table <table-id>]") \
Filip Tehlar5fae99c2017-01-18 12:57:37 +010022182_(lisp_gpe_fwd_entries_get, "vni <vni>") \
22183_(lisp_gpe_fwd_entry_path_dump, "index <fwd_entry_index>") \
Filip Tehlar3e7b56932017-02-21 18:28:34 +010022184_(gpe_set_encap_mode, "lisp|vxlan") \
22185_(gpe_get_encap_mode, "") \
Filip Tehlar82786c42017-02-20 15:20:37 +010022186_(lisp_gpe_add_del_iface, "up|down") \
22187_(lisp_gpe_enable_disable, "enable|disable") \
22188_(lisp_gpe_add_del_fwd_entry, "reid <eid> [leid <eid>] vni <vni>" \
22189 "vrf/bd <dp_table> loc-pair <lcl_loc> <rmt_loc> w <weight>... [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022190_(show_lisp_rloc_probe_state, "") \
22191_(show_lisp_map_register_state, "") \
22192_(show_lisp_status, "") \
22193_(lisp_get_map_request_itr_rlocs, "") \
22194_(show_lisp_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010022195_(show_lisp_use_petr, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022196_(show_lisp_map_request_mode, "") \
22197_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
22198_(af_packet_delete, "name <host interface name>") \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020022199_(af_packet_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022200_(policer_add_del, "name <policer name> <params> [del]") \
22201_(policer_dump, "[name <policer name>]") \
22202_(policer_classify_set_interface, \
22203 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
22204 " [l2-table <nn>] [del]") \
22205_(policer_classify_dump, "type [ip4|ip6|l2]") \
22206_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
22207 "[master|slave]") \
22208_(netmap_delete, "name <interface name>") \
22209_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns097fa662018-05-01 05:17:55 -070022210_(mpls_table_dump, "") \
22211_(mpls_route_dump, "table-id <ID>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022212_(classify_table_ids, "") \
22213_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
22214_(classify_table_info, "table_id <nn>") \
22215_(classify_session_dump, "table_id <nn>") \
22216_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
22217 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
22218 "[template_interval <nn>] [udp_checksum]") \
22219_(ipfix_exporter_dump, "") \
22220_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
22221_(ipfix_classify_stream_dump, "") \
22222_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
22223_(ipfix_classify_table_dump, "") \
Eyal Bari001fd402017-07-16 09:34:53 +030022224_(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
Eyal Bari5b311202017-07-31 13:12:30 +030022225_(sw_interface_span_dump, "[l2]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022226_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
22227_(pg_create_interface, "if_id <nn>") \
22228_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
22229_(pg_enable_disable, "[stream <id>] disable") \
22230_(ip_source_and_port_range_check_add_del, \
22231 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
22232_(ip_source_and_port_range_check_interface_add_del, \
22233 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
22234 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022235_(delete_subif,"<intfc> | sw_if_index <nn>") \
22236_(l2_interface_pbb_tag_rewrite, \
22237 "<intfc> | sw_if_index <nn> \n" \
22238 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
22239 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Pavel Kotuceke88865d2018-11-28 07:42:11 +010022240_(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022241_(flow_classify_set_interface, \
22242 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
22243_(flow_classify_dump, "type [ip4|ip6]") \
Neale Ranns097fa662018-05-01 05:17:55 -070022244_(ip_table_dump, "") \
22245_(ip_route_dump, "table-id [ip4|ip6]") \
22246_(ip_mtable_dump, "") \
22247_(ip_mroute_dump, "table-id [ip4|ip6]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022248_(feature_enable_disable, "arc_name <arc_name> " \
22249 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
22250_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
22251"[disable]") \
22252_(l2_xconnect_dump, "") \
Ole Troand7231612018-06-07 10:17:57 +020022253_(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022254_(ip_neighbor_dump, "[ip6] <intfc> | sw_if_index <nn>") \
Pavel Kotucek6899a302017-06-08 08:46:10 +020022255_(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020022256_(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
Steve Shin99a0e602017-07-01 04:16:20 +000022257_(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020022258_(lldp_config, "system-name <name> tx-hold <nn> tx-interval <nn>") \
Steve Shin9a6fcef2017-10-11 13:55:16 -070022259_(sw_interface_set_lldp, "<intfc> | sw_if_index <nn> [port-desc <description>]\n" \
22260 " [mgmt-ip4 <ip4>] [mgmt-ip6 <ip6>] [mgmt-oid <object id>] [disable]") \
Dave Barach59b25652017-09-10 15:04:27 -040022261_(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
Florin Coras90a63982017-12-19 04:50:01 -080022262_(sock_init_shm, "size <nnn>") \
Florin Corascea194d2017-10-02 00:18:51 -070022263_(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
Dave Barach65457162017-10-10 17:53:14 -040022264_(dns_enable_disable, "[enable][disable]") \
22265_(dns_name_server_add_del, "<ip-address> [del]") \
Dave Barachd2080152017-10-20 09:21:35 -040022266_(dns_resolve_name, "<hostname>") \
Florin Coras1c710452017-10-17 00:03:13 -070022267_(dns_resolve_ip, "<ip4|ip6>") \
22268_(dns_name_server_add_del, "<ip-address> [del]") \
22269_(dns_resolve_name, "<hostname>") \
22270_(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
22271 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
Florin Coras6c36f532017-11-03 18:32:34 -070022272_(session_rules_dump, "") \
Florin Coras595992c2017-11-06 17:17:08 -080022273_(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010022274_(output_acl_set_interface, \
22275 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
22276 " [l2-table <nn>] [del]") \
Ole Troane906aac2018-06-14 14:42:14 +020022277_(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
Damjan Marion7cd468a2016-12-19 23:05:39 +010022278
22279/* List of command functions, CLI names map directly to functions */
22280#define foreach_cli_function \
22281_(comment, "usage: comment <ignore-rest-of-line>") \
22282_(dump_interface_table, "usage: dump_interface_table") \
22283_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
22284_(dump_ipv4_table, "usage: dump_ipv4_table") \
22285_(dump_ipv6_table, "usage: dump_ipv6_table") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022286_(dump_macro_table, "usage: dump_macro_table ") \
22287_(dump_node_table, "usage: dump_node_table") \
22288_(dump_msg_api_table, "usage: dump_msg_api_table") \
22289_(get_msg_id, "usage: get_msg_id name_and_crc") \
22290_(echo, "usage: echo <message>") \
22291_(exec, "usage: exec <vpe-debug-CLI-command>") \
22292_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
22293_(help, "usage: help") \
22294_(q, "usage: quit") \
22295_(quit, "usage: quit") \
22296_(search_node_table, "usage: search_node_table <name>...") \
22297_(set, "usage: set <variable-name> <value>") \
22298_(script, "usage: script <file-name>") \
Neale Ranns097fa662018-05-01 05:17:55 -070022299_(statseg, "usage: statseg") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022300_(unset, "usage: unset <variable-name>")
Dave Barach048a4e52018-06-01 18:52:25 -040022301
Damjan Marion7cd468a2016-12-19 23:05:39 +010022302#define _(N,n) \
22303 static void vl_api_##n##_t_handler_uni \
22304 (vl_api_##n##_t * mp) \
22305 { \
22306 vat_main_t * vam = &vat_main; \
22307 if (vam->json_output) { \
22308 vl_api_##n##_t_handler_json(mp); \
22309 } else { \
22310 vl_api_##n##_t_handler(mp); \
22311 } \
22312 }
22313foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050022314#if VPP_API_TEST_BUILTIN == 0
22315foreach_standalone_reply_msg;
22316#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010022317#undef _
22318
22319void
22320vat_api_hookup (vat_main_t * vam)
22321{
22322#define _(N,n) \
22323 vl_msg_api_set_handlers(VL_API_##N, #n, \
22324 vl_api_##n##_t_handler_uni, \
22325 vl_noop_handler, \
22326 vl_api_##n##_t_endian, \
22327 vl_api_##n##_t_print, \
22328 sizeof(vl_api_##n##_t), 1);
22329 foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050022330#if VPP_API_TEST_BUILTIN == 0
22331 foreach_standalone_reply_msg;
22332#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010022333#undef _
22334
22335#if (VPP_API_TEST_BUILTIN==0)
22336 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Damjan Marion7cd468a2016-12-19 23:05:39 +010022337
22338 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
22339
22340 vam->function_by_name = hash_create_string (0, sizeof (uword));
22341
22342 vam->help_by_name = hash_create_string (0, sizeof (uword));
Dave Barach45e4f362017-03-07 12:52:31 -050022343#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010022344
22345 /* API messages we can send */
22346#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
22347 foreach_vpe_api_msg;
22348#undef _
22349
22350 /* Help strings */
22351#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
22352 foreach_vpe_api_msg;
22353#undef _
Damjan Marion7cd468a2016-12-19 23:05:39 +010022354
22355 /* CLI functions */
22356#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
22357 foreach_cli_function;
22358#undef _
22359
22360 /* Help strings */
22361#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
22362 foreach_cli_function;
22363#undef _
22364}
22365
Dave Baracha1a093d2017-03-02 13:13:23 -050022366#if VPP_API_TEST_BUILTIN
22367static clib_error_t *
22368vat_api_hookup_shim (vlib_main_t * vm)
22369{
22370 vat_api_hookup (&vat_main);
22371 return 0;
22372}
22373
22374VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
22375#endif
22376
Damjan Marion7cd468a2016-12-19 23:05:39 +010022377/*
22378 * fd.io coding-style-patch-verification: ON
22379 *
22380 * Local Variables:
22381 * eval: (c-set-style "gnu")
22382 * End:
22383 */