blob: 16abf45e3d951253a0adb90698d8611e7cf47157 [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>
jialv01082ebeb2019-09-10 00:23:55 +080021#include <vlib/pci/pci.h>
Neale Ranns86327be2018-11-02 09:14:01 -070022#include <vpp/api/types.h>
Dave Barach59b25652017-09-10 15:04:27 -040023#include <vppinfra/socket.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010024#include <vlibapi/api.h>
25#include <vlibmemory/api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010026#include <vnet/ip/ip.h>
John Lo7f358b32018-04-28 01:19:24 -040027#include <vnet/ip/ip_neighbor.h>
Neale Ranns37029302018-08-10 05:30:06 -070028#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010029#include <vnet/l2/l2_input.h>
30#include <vnet/l2tp/l2tp.h>
31#include <vnet/vxlan/vxlan.h>
Marco Varleseb598f1d2017-09-19 14:25:28 +020032#include <vnet/geneve/geneve.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010033#include <vnet/gre/gre.h>
34#include <vnet/vxlan-gpe/vxlan_gpe.h>
35#include <vnet/lisp-gpe/lisp_gpe.h>
36
37#include <vpp/api/vpe_msg_enum.h>
38#include <vnet/l2/l2_classify.h>
39#include <vnet/l2/l2_vtr.h>
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010040#include <vnet/classify/in_out_acl.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010041#include <vnet/classify/policer_classify.h>
42#include <vnet/classify/flow_classify.h>
43#include <vnet/mpls/mpls.h>
44#include <vnet/ipsec/ipsec.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010045#include <inttypes.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010046#include <vnet/cop/cop.h>
47#include <vnet/ip/ip6_hop_by_hop.h>
48#include <vnet/ip/ip_source_and_port_range_check.h>
49#include <vnet/policer/xlate.h>
50#include <vnet/span/span.h>
51#include <vnet/policer/policer.h>
52#include <vnet/policer/police.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000053#include <vnet/mfib/mfib_types.h>
John Lo70bfcaf2017-11-14 13:19:26 -050054#include <vnet/dhcp/dhcp_proxy.h>
Steven9cd2d7a2017-12-20 12:43:01 -080055#include <vnet/bonding/node.h>
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070056#include <vnet/qos/qos_types.h>
Neale Ranns37029302018-08-10 05:30:06 -070057#include <vnet/ethernet/ethernet_types_api.h>
58#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010059#include "vat/json_format.h"
Neale Ranns86327be2018-11-02 09:14:01 -070060#include <vnet/ip/ip_types_api.h>
61#include <vnet/ethernet/ethernet_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010062
63#include <inttypes.h>
64#include <sys/stat.h>
65
66#define vl_typedefs /* define message structures */
67#include <vpp/api/vpe_all_api_h.h>
68#undef vl_typedefs
69
70/* declare message handlers for each api */
71
72#define vl_endianfun /* define message structures */
73#include <vpp/api/vpe_all_api_h.h>
74#undef vl_endianfun
75
76/* instantiate all the print functions we know about */
Dave Barachf35a0722019-06-12 16:50:38 -040077#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010078#define vl_print(handle, ...)
Dave Barachf35a0722019-06-12 16:50:38 -040079#else
80#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
81#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010082#define vl_printfun
83#include <vpp/api/vpe_all_api_h.h>
84#undef vl_printfun
85
Dave Barach2d6b2d62017-01-25 16:32:08 -050086#define __plugin_msg_base 0
Dave Barachfe6bdfd2017-01-20 19:50:09 -050087#include <vlibapi/vat_helper_macros.h>
88
Ole Troan33a58172019-09-04 09:12:29 +020089#include <vnet/format_fns.h>
90
Dave Barachb09f4d02019-07-15 16:00:03 -040091void vl_api_set_elog_main (elog_main_t * m);
92int vl_api_set_elog_trace_api_messages (int enable);
93
Dave Barach59b25652017-09-10 15:04:27 -040094#if VPP_API_TEST_BUILTIN == 0
95#include <netdb.h>
96
97u32
98vl (void *p)
99{
100 return vec_len (p);
101}
102
103int
104vat_socket_connect (vat_main_t * vam)
105{
Florin Coras66a10032018-12-21 16:23:09 -0800106 int rv;
Florin Coras90a63982017-12-19 04:50:01 -0800107 vam->socket_client_main = &socket_client_main;
Florin Coras66a10032018-12-21 16:23:09 -0800108 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
109 "vpp_api_test",
110 0 /* default socket rx, tx buffer */ )))
111 return rv;
112 /* vpp expects the client index in network order */
113 vam->my_client_index = htonl (socket_client_main.client_index);
114 return 0;
Dave Barach59b25652017-09-10 15:04:27 -0400115}
116#else /* vpp built-in case, we don't do sockets... */
117int
118vat_socket_connect (vat_main_t * vam)
119{
120 return 0;
121}
122
Florin Coras90a63982017-12-19 04:50:01 -0800123int
124vl_socket_client_read (int wait)
Dave Barach59b25652017-09-10 15:04:27 -0400125{
Florin Coras90a63982017-12-19 04:50:01 -0800126 return -1;
Dave Barach59b25652017-09-10 15:04:27 -0400127};
Florin Coras90a63982017-12-19 04:50:01 -0800128
129int
130vl_socket_client_write ()
131{
132 return -1;
133};
134
135void *
136vl_socket_client_msg_alloc (int nbytes)
137{
138 return 0;
139}
Dave Barach59b25652017-09-10 15:04:27 -0400140#endif
141
142
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500143f64
144vat_time_now (vat_main_t * vam)
145{
146#if VPP_API_TEST_BUILTIN
147 return vlib_time_now (vam->vlib_main);
148#else
149 return clib_time_now (&vam->clib_time);
150#endif
151}
152
153void
154errmsg (char *fmt, ...)
155{
156 vat_main_t *vam = &vat_main;
157 va_list va;
158 u8 *s;
159
160 va_start (va, fmt);
161 s = va_format (0, fmt, &va);
162 va_end (va);
163
164 vec_add1 (s, 0);
165
166#if VPP_API_TEST_BUILTIN
167 vlib_cli_output (vam->vlib_main, (char *) s);
168#else
169 {
170 if (vam->ifp != stdin)
171 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
172 vam->input_line_number);
Dave Barachb09f4d02019-07-15 16:00:03 -0400173 else
174 fformat (vam->ofp, "%s\n", (char *) s);
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500175 fflush (vam->ofp);
176 }
177#endif
178
179 vec_free (s);
180}
181
Dave Barach4a3f69c2017-02-22 12:44:56 -0500182#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +0100183static uword
184api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
185{
186 vat_main_t *vam = va_arg (*args, vat_main_t *);
187 u32 *result = va_arg (*args, u32 *);
188 u8 *if_name;
189 uword *p;
190
191 if (!unformat (input, "%s", &if_name))
192 return 0;
193
194 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
195 if (p == 0)
196 return 0;
197 *result = p[0];
198 return 1;
199}
200
eyal bariaf86a482018-04-17 11:20:27 +0300201static uword
202api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
203{
204 return 0;
205}
206
Damjan Marion7cd468a2016-12-19 23:05:39 +0100207/* Parse an IP4 address %d.%d.%d.%d. */
208uword
209unformat_ip4_address (unformat_input_t * input, va_list * args)
210{
211 u8 *result = va_arg (*args, u8 *);
212 unsigned a[4];
213
214 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
215 return 0;
216
217 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
218 return 0;
219
220 result[0] = a[0];
221 result[1] = a[1];
222 result[2] = a[2];
223 result[3] = a[3];
224
225 return 1;
226}
227
228uword
229unformat_ethernet_address (unformat_input_t * input, va_list * args)
230{
231 u8 *result = va_arg (*args, u8 *);
232 u32 i, a[6];
233
234 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
235 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
236 return 0;
237
238 /* Check range. */
239 for (i = 0; i < 6; i++)
240 if (a[i] >= (1 << 8))
241 return 0;
242
243 for (i = 0; i < 6; i++)
244 result[i] = a[i];
245
246 return 1;
247}
248
249/* Returns ethernet type as an int in host byte order. */
250uword
251unformat_ethernet_type_host_byte_order (unformat_input_t * input,
252 va_list * args)
253{
254 u16 *result = va_arg (*args, u16 *);
255 int type;
256
257 /* Numeric type. */
258 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
259 {
260 if (type >= (1 << 16))
261 return 0;
262 *result = type;
263 return 1;
264 }
265 return 0;
266}
267
268/* Parse an IP6 address. */
269uword
270unformat_ip6_address (unformat_input_t * input, va_list * args)
271{
272 ip6_address_t *result = va_arg (*args, ip6_address_t *);
273 u16 hex_quads[8];
274 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
275 uword c, n_colon, double_colon_index;
276
277 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
278 double_colon_index = ARRAY_LEN (hex_quads);
279 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
280 {
281 hex_digit = 16;
282 if (c >= '0' && c <= '9')
283 hex_digit = c - '0';
284 else if (c >= 'a' && c <= 'f')
285 hex_digit = c + 10 - 'a';
286 else if (c >= 'A' && c <= 'F')
287 hex_digit = c + 10 - 'A';
288 else if (c == ':' && n_colon < 2)
289 n_colon++;
290 else
291 {
292 unformat_put_input (input);
293 break;
294 }
295
296 /* Too many hex quads. */
297 if (n_hex_quads >= ARRAY_LEN (hex_quads))
298 return 0;
299
300 if (hex_digit < 16)
301 {
302 hex_quad = (hex_quad << 4) | hex_digit;
303
304 /* Hex quad must fit in 16 bits. */
305 if (n_hex_digits >= 4)
306 return 0;
307
308 n_colon = 0;
309 n_hex_digits++;
310 }
311
312 /* Save position of :: */
313 if (n_colon == 2)
314 {
315 /* More than one :: ? */
316 if (double_colon_index < ARRAY_LEN (hex_quads))
317 return 0;
318 double_colon_index = n_hex_quads;
319 }
320
321 if (n_colon > 0 && n_hex_digits > 0)
322 {
323 hex_quads[n_hex_quads++] = hex_quad;
324 hex_quad = 0;
325 n_hex_digits = 0;
326 }
327 }
328
329 if (n_hex_digits > 0)
330 hex_quads[n_hex_quads++] = hex_quad;
331
332 {
333 word i;
334
335 /* Expand :: to appropriate number of zero hex quads. */
336 if (double_colon_index < ARRAY_LEN (hex_quads))
337 {
338 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
339
340 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
341 hex_quads[n_zero + i] = hex_quads[i];
342
343 for (i = 0; i < n_zero; i++)
344 hex_quads[double_colon_index + i] = 0;
345
346 n_hex_quads = ARRAY_LEN (hex_quads);
347 }
348
349 /* Too few hex quads given. */
350 if (n_hex_quads < ARRAY_LEN (hex_quads))
351 return 0;
352
353 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
354 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
355
356 return 1;
357 }
358}
359
360uword
361unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
362{
363 u32 *r = va_arg (*args, u32 *);
364
365 if (0);
366#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
367 foreach_ipsec_policy_action
368#undef _
369 else
370 return 0;
371 return 1;
372}
373
Damjan Marion7cd468a2016-12-19 23:05:39 +0100374u8 *
375format_ipsec_crypto_alg (u8 * s, va_list * args)
376{
377 u32 i = va_arg (*args, u32);
378 u8 *t = 0;
379
380 switch (i)
381 {
382#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
383 foreach_ipsec_crypto_alg
384#undef _
385 default:
386 return format (s, "unknown");
387 }
388 return format (s, "%s", t);
389}
390
Damjan Marion7cd468a2016-12-19 23:05:39 +0100391u8 *
392format_ipsec_integ_alg (u8 * s, va_list * args)
393{
394 u32 i = va_arg (*args, u32);
395 u8 *t = 0;
396
397 switch (i)
398 {
399#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
400 foreach_ipsec_integ_alg
401#undef _
402 default:
403 return format (s, "unknown");
404 }
405 return format (s, "%s", t);
406}
407
Dave Barach4a3f69c2017-02-22 12:44:56 -0500408#else /* VPP_API_TEST_BUILTIN == 1 */
409static uword
410api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
411{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200412 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500413 vnet_main_t *vnm = vnet_get_main ();
414 u32 *result = va_arg (*args, u32 *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500415
eyal bariaf86a482018-04-17 11:20:27 +0300416 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500417}
eyal bariaf86a482018-04-17 11:20:27 +0300418
419static uword
420api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
421{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200422 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
eyal bariaf86a482018-04-17 11:20:27 +0300423 vnet_main_t *vnm = vnet_get_main ();
424 u32 *result = va_arg (*args, u32 *);
425
426 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
427}
428
Damjan Marion7cd468a2016-12-19 23:05:39 +0100429#endif /* VPP_API_TEST_BUILTIN */
430
Neale Ranns17dcec02019-01-09 21:22:20 -0800431uword
432unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
433{
434 u32 *r = va_arg (*args, u32 *);
435
436 if (0);
437#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
438 foreach_ipsec_crypto_alg
439#undef _
440 else
441 return 0;
442 return 1;
443}
444
445uword
446unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
447{
448 u32 *r = va_arg (*args, u32 *);
449
450 if (0);
451#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
452 foreach_ipsec_integ_alg
453#undef _
454 else
455 return 0;
456 return 1;
457}
458
Damjan Marion7cd468a2016-12-19 23:05:39 +0100459static uword
460unformat_policer_rate_type (unformat_input_t * input, va_list * args)
461{
462 u8 *r = va_arg (*args, u8 *);
463
464 if (unformat (input, "kbps"))
465 *r = SSE2_QOS_RATE_KBPS;
466 else if (unformat (input, "pps"))
467 *r = SSE2_QOS_RATE_PPS;
468 else
469 return 0;
470 return 1;
471}
472
473static uword
474unformat_policer_round_type (unformat_input_t * input, va_list * args)
475{
476 u8 *r = va_arg (*args, u8 *);
477
478 if (unformat (input, "closest"))
479 *r = SSE2_QOS_ROUND_TO_CLOSEST;
480 else if (unformat (input, "up"))
481 *r = SSE2_QOS_ROUND_TO_UP;
482 else if (unformat (input, "down"))
483 *r = SSE2_QOS_ROUND_TO_DOWN;
484 else
485 return 0;
486 return 1;
487}
488
489static uword
490unformat_policer_type (unformat_input_t * input, va_list * args)
491{
492 u8 *r = va_arg (*args, u8 *);
493
494 if (unformat (input, "1r2c"))
495 *r = SSE2_QOS_POLICER_TYPE_1R2C;
496 else if (unformat (input, "1r3c"))
497 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
498 else if (unformat (input, "2r3c-2698"))
499 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
500 else if (unformat (input, "2r3c-4115"))
501 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
502 else if (unformat (input, "2r3c-mef5cf1"))
503 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
504 else
505 return 0;
506 return 1;
507}
508
509static uword
510unformat_dscp (unformat_input_t * input, va_list * va)
511{
512 u8 *r = va_arg (*va, u8 *);
513
514 if (0);
515#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
516 foreach_vnet_dscp
517#undef _
518 else
519 return 0;
520 return 1;
521}
522
523static uword
524unformat_policer_action_type (unformat_input_t * input, va_list * va)
525{
526 sse2_qos_pol_action_params_st *a
527 = va_arg (*va, sse2_qos_pol_action_params_st *);
528
529 if (unformat (input, "drop"))
530 a->action_type = SSE2_QOS_ACTION_DROP;
531 else if (unformat (input, "transmit"))
532 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
533 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
534 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
535 else
536 return 0;
537 return 1;
538}
539
540static uword
541unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
542{
543 u32 *r = va_arg (*va, u32 *);
544 u32 tid;
545
546 if (unformat (input, "ip4"))
547 tid = POLICER_CLASSIFY_TABLE_IP4;
548 else if (unformat (input, "ip6"))
549 tid = POLICER_CLASSIFY_TABLE_IP6;
550 else if (unformat (input, "l2"))
551 tid = POLICER_CLASSIFY_TABLE_L2;
552 else
553 return 0;
554
555 *r = tid;
556 return 1;
557}
558
559static uword
560unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
561{
562 u32 *r = va_arg (*va, u32 *);
563 u32 tid;
564
565 if (unformat (input, "ip4"))
566 tid = FLOW_CLASSIFY_TABLE_IP4;
567 else if (unformat (input, "ip6"))
568 tid = FLOW_CLASSIFY_TABLE_IP6;
569 else
570 return 0;
571
572 *r = tid;
573 return 1;
574}
575
Benoît Ganne49ee6842019-04-30 11:50:46 +0200576#if (VPP_API_TEST_BUILTIN==0)
577
Neale Ranns32e1c012016-11-22 17:07:28 +0000578static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
579static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
580static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
581static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
582
583uword
584unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
585{
586 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
587 mfib_itf_attribute_t attr;
588
589 old = *iflags;
590 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
591 {
592 if (unformat (input, mfib_itf_flag_long_names[attr]))
593 *iflags |= (1 << attr);
594 }
595 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
596 {
597 if (unformat (input, mfib_itf_flag_names[attr]))
598 *iflags |= (1 << attr);
599 }
600
601 return (old == *iflags ? 0 : 1);
602}
603
604uword
605unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
606{
607 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
608 mfib_entry_attribute_t attr;
609
610 old = *eflags;
611 FOR_EACH_MFIB_ATTRIBUTE (attr)
612 {
613 if (unformat (input, mfib_flag_long_names[attr]))
614 *eflags |= (1 << attr);
615 }
616 FOR_EACH_MFIB_ATTRIBUTE (attr)
617 {
618 if (unformat (input, mfib_flag_names[attr]))
619 *eflags |= (1 << attr);
620 }
621
622 return (old == *eflags ? 0 : 1);
623}
624
Damjan Marion7cd468a2016-12-19 23:05:39 +0100625u8 *
626format_ip4_address (u8 * s, va_list * args)
627{
628 u8 *a = va_arg (*args, u8 *);
629 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
630}
631
632u8 *
633format_ip6_address (u8 * s, va_list * args)
634{
635 ip6_address_t *a = va_arg (*args, ip6_address_t *);
636 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
637
638 i_max_n_zero = ARRAY_LEN (a->as_u16);
639 max_n_zeros = 0;
640 i_first_zero = i_max_n_zero;
641 n_zeros = 0;
642 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
643 {
644 u32 is_zero = a->as_u16[i] == 0;
645 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
646 {
647 i_first_zero = i;
648 n_zeros = 0;
649 }
650 n_zeros += is_zero;
651 if ((!is_zero && n_zeros > max_n_zeros)
652 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
653 {
654 i_max_n_zero = i_first_zero;
655 max_n_zeros = n_zeros;
656 i_first_zero = ARRAY_LEN (a->as_u16);
657 n_zeros = 0;
658 }
659 }
660
661 last_double_colon = 0;
662 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
663 {
664 if (i == i_max_n_zero && max_n_zeros > 1)
665 {
666 s = format (s, "::");
667 i += max_n_zeros - 1;
668 last_double_colon = 1;
669 }
670 else
671 {
672 s = format (s, "%s%x",
673 (last_double_colon || i == 0) ? "" : ":",
674 clib_net_to_host_u16 (a->as_u16[i]));
675 last_double_colon = 0;
676 }
677 }
678
679 return s;
680}
681
682/* Format an IP46 address. */
683u8 *
684format_ip46_address (u8 * s, va_list * args)
685{
686 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
687 ip46_type_t type = va_arg (*args, ip46_type_t);
688 int is_ip4 = 1;
689
690 switch (type)
691 {
692 case IP46_TYPE_ANY:
693 is_ip4 = ip46_address_is_ip4 (ip46);
694 break;
695 case IP46_TYPE_IP4:
696 is_ip4 = 1;
697 break;
698 case IP46_TYPE_IP6:
699 is_ip4 = 0;
700 break;
701 }
702
703 return is_ip4 ?
704 format (s, "%U", format_ip4_address, &ip46->ip4) :
705 format (s, "%U", format_ip6_address, &ip46->ip6);
706}
707
708u8 *
709format_ethernet_address (u8 * s, va_list * args)
710{
711 u8 *a = va_arg (*args, u8 *);
712
713 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
714 a[0], a[1], a[2], a[3], a[4], a[5]);
715}
716#endif
717
718static void
Neale Ranns097fa662018-05-01 05:17:55 -0700719increment_v4_address (vl_api_ip4_address_t * i)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100720{
Neale Ranns097fa662018-05-01 05:17:55 -0700721 ip4_address_t *a = (ip4_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100722 u32 v;
723
724 v = ntohl (a->as_u32) + 1;
725 a->as_u32 = ntohl (v);
726}
727
728static void
Neale Ranns097fa662018-05-01 05:17:55 -0700729increment_v6_address (vl_api_ip6_address_t * i)
Neale Ranns2b5ba952019-04-02 10:15:40 +0000730{
Neale Ranns097fa662018-05-01 05:17:55 -0700731 ip6_address_t *a = (ip6_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100732 u64 v0, v1;
733
734 v0 = clib_net_to_host_u64 (a->as_u64[0]);
735 v1 = clib_net_to_host_u64 (a->as_u64[1]);
736
737 v1 += 1;
738 if (v1 == 0)
739 v0 += 1;
740 a->as_u64[0] = clib_net_to_host_u64 (v0);
741 a->as_u64[1] = clib_net_to_host_u64 (v1);
742}
743
744static void
Neale Ranns097fa662018-05-01 05:17:55 -0700745increment_address (vl_api_address_t * a)
746{
Neale Rannsb34f99c2019-07-03 08:00:53 +0000747 if (clib_net_to_host_u32 (a->af) == ADDRESS_IP4)
Neale Ranns097fa662018-05-01 05:17:55 -0700748 increment_v4_address (&a->un.ip4);
Neale Rannsb34f99c2019-07-03 08:00:53 +0000749 else if (clib_net_to_host_u32 (a->af) == ADDRESS_IP6)
Neale Ranns097fa662018-05-01 05:17:55 -0700750 increment_v6_address (&a->un.ip6);
751}
752
753static void
754set_ip4_address (vl_api_address_t * a, u32 v)
755{
756 if (a->af == ADDRESS_IP4)
757 {
758 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
759 i->as_u32 = v;
760 }
761}
762
763static void
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200764increment_mac_address (u8 * mac)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100765{
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200766 u64 tmp = *((u64 *) mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100767 tmp = clib_net_to_host_u64 (tmp);
768 tmp += 1 << 16; /* skip unused (least significant) octets */
769 tmp = clib_host_to_net_u64 (tmp);
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200770
771 clib_memcpy (mac, &tmp, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100772}
773
Neale Ranns097fa662018-05-01 05:17:55 -0700774static void
775vat_json_object_add_address (vat_json_node_t * node,
776 const char *str, const vl_api_address_t * addr)
777{
778 if (ADDRESS_IP6 == addr->af)
779 {
780 struct in6_addr ip6;
781
782 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
783 vat_json_object_add_ip6 (node, str, ip6);
784 }
785 else
786 {
787 struct in_addr ip4;
788
789 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
790 vat_json_object_add_ip4 (node, str, ip4);
791 }
792}
793
794static void
795vat_json_object_add_prefix (vat_json_node_t * node,
796 const vl_api_prefix_t * prefix)
797{
Paul Vinciguerraab055082019-06-06 14:07:55 -0400798 vat_json_object_add_uint (node, "len", prefix->len);
799 vat_json_object_add_address (node, "address", &prefix->address);
Neale Ranns097fa662018-05-01 05:17:55 -0700800}
801
Damjan Marion7cd468a2016-12-19 23:05:39 +0100802static void vl_api_create_loopback_reply_t_handler
803 (vl_api_create_loopback_reply_t * mp)
804{
805 vat_main_t *vam = &vat_main;
806 i32 retval = ntohl (mp->retval);
807
808 vam->retval = retval;
809 vam->regenerate_interface_table = 1;
810 vam->sw_if_index = ntohl (mp->sw_if_index);
811 vam->result_ready = 1;
812}
813
814static void vl_api_create_loopback_reply_t_handler_json
815 (vl_api_create_loopback_reply_t * mp)
816{
817 vat_main_t *vam = &vat_main;
818 vat_json_node_t node;
819
820 vat_json_init_object (&node);
821 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
822 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
823
824 vat_json_print (vam->ofp, &node);
825 vat_json_free (&node);
826 vam->retval = ntohl (mp->retval);
827 vam->result_ready = 1;
828}
829
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600830static void vl_api_create_loopback_instance_reply_t_handler
831 (vl_api_create_loopback_instance_reply_t * mp)
832{
833 vat_main_t *vam = &vat_main;
834 i32 retval = ntohl (mp->retval);
835
836 vam->retval = retval;
837 vam->regenerate_interface_table = 1;
838 vam->sw_if_index = ntohl (mp->sw_if_index);
839 vam->result_ready = 1;
840}
841
842static void vl_api_create_loopback_instance_reply_t_handler_json
843 (vl_api_create_loopback_instance_reply_t * mp)
844{
845 vat_main_t *vam = &vat_main;
846 vat_json_node_t node;
847
848 vat_json_init_object (&node);
849 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
850 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
851
852 vat_json_print (vam->ofp, &node);
853 vat_json_free (&node);
854 vam->retval = ntohl (mp->retval);
855 vam->result_ready = 1;
856}
857
Damjan Marion7cd468a2016-12-19 23:05:39 +0100858static void vl_api_af_packet_create_reply_t_handler
859 (vl_api_af_packet_create_reply_t * mp)
860{
861 vat_main_t *vam = &vat_main;
862 i32 retval = ntohl (mp->retval);
863
864 vam->retval = retval;
865 vam->regenerate_interface_table = 1;
866 vam->sw_if_index = ntohl (mp->sw_if_index);
867 vam->result_ready = 1;
868}
869
870static void vl_api_af_packet_create_reply_t_handler_json
871 (vl_api_af_packet_create_reply_t * mp)
872{
873 vat_main_t *vam = &vat_main;
874 vat_json_node_t node;
875
876 vat_json_init_object (&node);
877 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
878 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
879
880 vat_json_print (vam->ofp, &node);
881 vat_json_free (&node);
882
883 vam->retval = ntohl (mp->retval);
884 vam->result_ready = 1;
885}
886
887static void vl_api_create_vlan_subif_reply_t_handler
888 (vl_api_create_vlan_subif_reply_t * mp)
889{
890 vat_main_t *vam = &vat_main;
891 i32 retval = ntohl (mp->retval);
892
893 vam->retval = retval;
894 vam->regenerate_interface_table = 1;
895 vam->sw_if_index = ntohl (mp->sw_if_index);
896 vam->result_ready = 1;
897}
898
899static void vl_api_create_vlan_subif_reply_t_handler_json
900 (vl_api_create_vlan_subif_reply_t * mp)
901{
902 vat_main_t *vam = &vat_main;
903 vat_json_node_t node;
904
905 vat_json_init_object (&node);
906 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
907 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
908
909 vat_json_print (vam->ofp, &node);
910 vat_json_free (&node);
911
912 vam->retval = ntohl (mp->retval);
913 vam->result_ready = 1;
914}
915
916static void vl_api_create_subif_reply_t_handler
917 (vl_api_create_subif_reply_t * mp)
918{
919 vat_main_t *vam = &vat_main;
920 i32 retval = ntohl (mp->retval);
921
922 vam->retval = retval;
923 vam->regenerate_interface_table = 1;
924 vam->sw_if_index = ntohl (mp->sw_if_index);
925 vam->result_ready = 1;
926}
927
928static void vl_api_create_subif_reply_t_handler_json
929 (vl_api_create_subif_reply_t * mp)
930{
931 vat_main_t *vam = &vat_main;
932 vat_json_node_t node;
933
934 vat_json_init_object (&node);
935 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
936 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
937
938 vat_json_print (vam->ofp, &node);
939 vat_json_free (&node);
940
941 vam->retval = ntohl (mp->retval);
942 vam->result_ready = 1;
943}
944
945static void vl_api_interface_name_renumber_reply_t_handler
946 (vl_api_interface_name_renumber_reply_t * mp)
947{
948 vat_main_t *vam = &vat_main;
949 i32 retval = ntohl (mp->retval);
950
951 vam->retval = retval;
952 vam->regenerate_interface_table = 1;
953 vam->result_ready = 1;
954}
955
956static void vl_api_interface_name_renumber_reply_t_handler_json
957 (vl_api_interface_name_renumber_reply_t * mp)
958{
959 vat_main_t *vam = &vat_main;
960 vat_json_node_t node;
961
962 vat_json_init_object (&node);
963 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
964
965 vat_json_print (vam->ofp, &node);
966 vat_json_free (&node);
967
968 vam->retval = ntohl (mp->retval);
969 vam->result_ready = 1;
970}
971
972/*
973 * Special-case: build the interface table, maintain
974 * the next loopback sw_if_index vbl.
975 */
976static void vl_api_sw_interface_details_t_handler
977 (vl_api_sw_interface_details_t * mp)
978{
979 vat_main_t *vam = &vat_main;
Ole Troane5ff5a32019-08-23 22:55:18 +0200980 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100981
982 hash_set_mem (vam->sw_if_index_by_interface_name, s,
983 ntohl (mp->sw_if_index));
984
985 /* In sub interface case, fill the sub interface table entry */
986 if (mp->sw_if_index != mp->sup_sw_if_index)
987 {
988 sw_interface_subif_t *sub = NULL;
989
990 vec_add2 (vam->sw_if_subif_table, sub, 1);
991
992 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
993 strncpy ((char *) sub->interface_name, (char *) s,
994 vec_len (sub->interface_name));
995 sub->sw_if_index = ntohl (mp->sw_if_index);
996 sub->sub_id = ntohl (mp->sub_id);
997
Jakub Grajciar053204a2019-03-18 13:17:53 +0100998 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
999
Damjan Marion7cd468a2016-12-19 23:05:39 +01001000 sub->sub_number_of_tags = mp->sub_number_of_tags;
1001 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1002 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001003
1004 /* vlan tag rewrite */
1005 sub->vtr_op = ntohl (mp->vtr_op);
1006 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1007 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1008 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1009 }
1010}
1011
1012static void vl_api_sw_interface_details_t_handler_json
1013 (vl_api_sw_interface_details_t * mp)
1014{
1015 vat_main_t *vam = &vat_main;
1016 vat_json_node_t *node = NULL;
1017
1018 if (VAT_JSON_ARRAY != vam->json_tree.type)
1019 {
1020 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1021 vat_json_init_array (&vam->json_tree);
1022 }
1023 node = vat_json_array_add (&vam->json_tree);
1024
1025 vat_json_init_object (node);
1026 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1027 vat_json_object_add_uint (node, "sup_sw_if_index",
1028 ntohl (mp->sup_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001029 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1030 sizeof (mp->l2_address));
1031 vat_json_object_add_string_copy (node, "interface_name",
Ole Troane5ff5a32019-08-23 22:55:18 +02001032 mp->interface_name);
Jakub Grajciar053204a2019-03-18 13:17:53 +01001033 vat_json_object_add_uint (node, "flags", mp->flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001034 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1035 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001036 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001037 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
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));
Jakub Grajciar053204a2019-03-18 13:17:53 +01001044 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001045 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1046 vat_json_object_add_uint (node, "vtr_push_dot1q",
1047 ntohl (mp->vtr_push_dot1q));
1048 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1049 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Jakub Grajciar053204a2019-03-18 13:17:53 +01001050 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
Pavel Kotucek65e84572017-01-16 17:01:56 +01001051 {
1052 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1053 format (0, "%U",
1054 format_ethernet_address,
1055 &mp->b_dmac));
1056 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1057 format (0, "%U",
1058 format_ethernet_address,
1059 &mp->b_smac));
1060 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1061 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1062 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001063}
1064
Dave Baracha1a093d2017-03-02 13:13:23 -05001065#if VPP_API_TEST_BUILTIN == 0
Neale Rannsa07bd702017-08-07 07:53:49 -07001066static void vl_api_sw_interface_event_t_handler
1067 (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001068{
1069 vat_main_t *vam = &vat_main;
1070 if (vam->interface_event_display)
1071 errmsg ("interface flags: sw_if_index %d %s %s",
1072 ntohl (mp->sw_if_index),
Jakub Grajciar053204a2019-03-18 13:17:53 +01001073 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1074 "admin-up" : "admin-down",
1075 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1076 "link-up" : "link-down");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001077}
Dave Baracha1a093d2017-03-02 13:13:23 -05001078#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +01001079
Benoît Ganne49ee6842019-04-30 11:50:46 +02001080__clib_unused static void
1081vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001082{
1083 /* JSON output not supported */
1084}
1085
1086static void
1087vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1088{
1089 vat_main_t *vam = &vat_main;
1090 i32 retval = ntohl (mp->retval);
1091
1092 vam->retval = retval;
Damjan Marion7bee80c2017-04-26 15:32:12 +02001093 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001094 vam->result_ready = 1;
1095}
1096
1097static void
1098vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1099{
1100 vat_main_t *vam = &vat_main;
1101 vat_json_node_t node;
1102 api_main_t *am = &api_main;
1103 void *oldheap;
1104 u8 *reply;
1105
1106 vat_json_init_object (&node);
1107 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1108 vat_json_object_add_uint (&node, "reply_in_shmem",
1109 ntohl (mp->reply_in_shmem));
1110 /* Toss the shared-memory original... */
1111 pthread_mutex_lock (&am->vlib_rp->mutex);
1112 oldheap = svm_push_data_heap (am->vlib_rp);
1113
Damjan Marion7bee80c2017-04-26 15:32:12 +02001114 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001115 vec_free (reply);
1116
1117 svm_pop_heap (oldheap);
1118 pthread_mutex_unlock (&am->vlib_rp->mutex);
1119
1120 vat_json_print (vam->ofp, &node);
1121 vat_json_free (&node);
1122
1123 vam->retval = ntohl (mp->retval);
1124 vam->result_ready = 1;
1125}
1126
1127static void
1128vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1129{
1130 vat_main_t *vam = &vat_main;
1131 i32 retval = ntohl (mp->retval);
Ole Troan413f4a52018-11-28 11:36:05 +01001132 u32 length = vl_api_string_len (&mp->reply);
Dave Barach59b25652017-09-10 15:04:27 -04001133
1134 vec_reset_length (vam->cmd_reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001135
1136 vam->retval = retval;
Dave Barach59b25652017-09-10 15:04:27 -04001137 if (retval == 0)
1138 {
1139 vec_validate (vam->cmd_reply, length);
Ole Troan413f4a52018-11-28 11:36:05 +01001140 clib_memcpy ((char *) (vam->cmd_reply),
1141 vl_api_from_api_string (&mp->reply), length);
Dave Barach59b25652017-09-10 15:04:27 -04001142 vam->cmd_reply[length] = 0;
1143 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001144 vam->result_ready = 1;
1145}
1146
1147static void
1148vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1149{
1150 vat_main_t *vam = &vat_main;
1151 vat_json_node_t node;
1152
Dave Barach59b25652017-09-10 15:04:27 -04001153 vec_reset_length (vam->cmd_reply);
1154
Damjan Marion7cd468a2016-12-19 23:05:39 +01001155 vat_json_init_object (&node);
1156 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troan413f4a52018-11-28 11:36:05 +01001157 vat_json_object_add_string_copy (&node, "reply",
1158 vl_api_from_api_string (&mp->reply));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001159
1160 vat_json_print (vam->ofp, &node);
1161 vat_json_free (&node);
1162
1163 vam->retval = ntohl (mp->retval);
1164 vam->result_ready = 1;
1165}
1166
1167static void vl_api_classify_add_del_table_reply_t_handler
1168 (vl_api_classify_add_del_table_reply_t * mp)
1169{
1170 vat_main_t *vam = &vat_main;
1171 i32 retval = ntohl (mp->retval);
1172 if (vam->async_mode)
1173 {
1174 vam->async_errors += (retval < 0);
1175 }
1176 else
1177 {
1178 vam->retval = retval;
1179 if (retval == 0 &&
1180 ((mp->new_table_index != 0xFFFFFFFF) ||
1181 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1182 (mp->match_n_vectors != 0xFFFFFFFF)))
1183 /*
1184 * Note: this is just barely thread-safe, depends on
1185 * the main thread spinning waiting for an answer...
1186 */
1187 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1188 ntohl (mp->new_table_index),
1189 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1190 vam->result_ready = 1;
1191 }
1192}
1193
1194static void vl_api_classify_add_del_table_reply_t_handler_json
1195 (vl_api_classify_add_del_table_reply_t * mp)
1196{
1197 vat_main_t *vam = &vat_main;
1198 vat_json_node_t node;
1199
1200 vat_json_init_object (&node);
1201 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1202 vat_json_object_add_uint (&node, "new_table_index",
1203 ntohl (mp->new_table_index));
1204 vat_json_object_add_uint (&node, "skip_n_vectors",
1205 ntohl (mp->skip_n_vectors));
1206 vat_json_object_add_uint (&node, "match_n_vectors",
1207 ntohl (mp->match_n_vectors));
1208
1209 vat_json_print (vam->ofp, &node);
1210 vat_json_free (&node);
1211
1212 vam->retval = ntohl (mp->retval);
1213 vam->result_ready = 1;
1214}
1215
1216static void vl_api_get_node_index_reply_t_handler
1217 (vl_api_get_node_index_reply_t * mp)
1218{
1219 vat_main_t *vam = &vat_main;
1220 i32 retval = ntohl (mp->retval);
1221 if (vam->async_mode)
1222 {
1223 vam->async_errors += (retval < 0);
1224 }
1225 else
1226 {
1227 vam->retval = retval;
1228 if (retval == 0)
1229 errmsg ("node index %d", ntohl (mp->node_index));
1230 vam->result_ready = 1;
1231 }
1232}
1233
1234static void vl_api_get_node_index_reply_t_handler_json
1235 (vl_api_get_node_index_reply_t * mp)
1236{
1237 vat_main_t *vam = &vat_main;
1238 vat_json_node_t node;
1239
1240 vat_json_init_object (&node);
1241 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1242 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1243
1244 vat_json_print (vam->ofp, &node);
1245 vat_json_free (&node);
1246
1247 vam->retval = ntohl (mp->retval);
1248 vam->result_ready = 1;
1249}
1250
1251static void vl_api_get_next_index_reply_t_handler
1252 (vl_api_get_next_index_reply_t * mp)
1253{
1254 vat_main_t *vam = &vat_main;
1255 i32 retval = ntohl (mp->retval);
1256 if (vam->async_mode)
1257 {
1258 vam->async_errors += (retval < 0);
1259 }
1260 else
1261 {
1262 vam->retval = retval;
1263 if (retval == 0)
1264 errmsg ("next node index %d", ntohl (mp->next_index));
1265 vam->result_ready = 1;
1266 }
1267}
1268
1269static void vl_api_get_next_index_reply_t_handler_json
1270 (vl_api_get_next_index_reply_t * mp)
1271{
1272 vat_main_t *vam = &vat_main;
1273 vat_json_node_t node;
1274
1275 vat_json_init_object (&node);
1276 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1277 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1278
1279 vat_json_print (vam->ofp, &node);
1280 vat_json_free (&node);
1281
1282 vam->retval = ntohl (mp->retval);
1283 vam->result_ready = 1;
1284}
1285
1286static void vl_api_add_node_next_reply_t_handler
1287 (vl_api_add_node_next_reply_t * mp)
1288{
1289 vat_main_t *vam = &vat_main;
1290 i32 retval = ntohl (mp->retval);
1291 if (vam->async_mode)
1292 {
1293 vam->async_errors += (retval < 0);
1294 }
1295 else
1296 {
1297 vam->retval = retval;
1298 if (retval == 0)
1299 errmsg ("next index %d", ntohl (mp->next_index));
1300 vam->result_ready = 1;
1301 }
1302}
1303
1304static void vl_api_add_node_next_reply_t_handler_json
1305 (vl_api_add_node_next_reply_t * mp)
1306{
1307 vat_main_t *vam = &vat_main;
1308 vat_json_node_t node;
1309
1310 vat_json_init_object (&node);
1311 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1312 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1313
1314 vat_json_print (vam->ofp, &node);
1315 vat_json_free (&node);
1316
1317 vam->retval = ntohl (mp->retval);
1318 vam->result_ready = 1;
1319}
1320
1321static void vl_api_show_version_reply_t_handler
1322 (vl_api_show_version_reply_t * mp)
1323{
1324 vat_main_t *vam = &vat_main;
1325 i32 retval = ntohl (mp->retval);
1326
1327 if (retval >= 0)
1328 {
Ole Troane5ff5a32019-08-23 22:55:18 +02001329 errmsg (" program: %s", mp->program);
1330 errmsg (" version: %s", mp->version);
1331 errmsg (" build date: %s", mp->build_date);
1332 errmsg ("build directory: %s", mp->build_directory);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001333 }
1334 vam->retval = retval;
1335 vam->result_ready = 1;
1336}
1337
1338static void vl_api_show_version_reply_t_handler_json
1339 (vl_api_show_version_reply_t * mp)
1340{
1341 vat_main_t *vam = &vat_main;
1342 vat_json_node_t node;
1343
1344 vat_json_init_object (&node);
1345 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troane5ff5a32019-08-23 22:55:18 +02001346 vat_json_object_add_string_copy (&node, "program", mp->program);
1347 vat_json_object_add_string_copy (&node, "version", mp->version);
1348 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001349 vat_json_object_add_string_copy (&node, "build_directory",
Ole Troane5ff5a32019-08-23 22:55:18 +02001350 mp->build_directory);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001351
1352 vat_json_print (vam->ofp, &node);
1353 vat_json_free (&node);
1354
1355 vam->retval = ntohl (mp->retval);
1356 vam->result_ready = 1;
1357}
1358
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001359static void vl_api_show_threads_reply_t_handler
1360 (vl_api_show_threads_reply_t * mp)
1361{
1362 vat_main_t *vam = &vat_main;
1363 i32 retval = ntohl (mp->retval);
1364 int i, count = 0;
1365
1366 if (retval >= 0)
1367 count = ntohl (mp->count);
1368
1369 for (i = 0; i < count; i++)
1370 print (vam->ofp,
1371 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1372 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1373 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1374 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1375 ntohl (mp->thread_data[i].cpu_socket));
1376
1377 vam->retval = retval;
1378 vam->result_ready = 1;
1379}
1380
1381static void vl_api_show_threads_reply_t_handler_json
1382 (vl_api_show_threads_reply_t * mp)
1383{
1384 vat_main_t *vam = &vat_main;
1385 vat_json_node_t node;
1386 vl_api_thread_data_t *td;
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001387 i32 retval = ntohl (mp->retval);
1388 int i, count = 0;
1389
1390 if (retval >= 0)
1391 count = ntohl (mp->count);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001392
1393 vat_json_init_object (&node);
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001394 vat_json_object_add_int (&node, "retval", retval);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001395 vat_json_object_add_uint (&node, "count", count);
1396
1397 for (i = 0; i < count; i++)
1398 {
1399 td = &mp->thread_data[i];
1400 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1401 vat_json_object_add_string_copy (&node, "name", td->name);
1402 vat_json_object_add_string_copy (&node, "type", td->type);
1403 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1404 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1405 vat_json_object_add_int (&node, "core", ntohl (td->id));
1406 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1407 }
1408
1409 vat_json_print (vam->ofp, &node);
1410 vat_json_free (&node);
1411
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001412 vam->retval = retval;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001413 vam->result_ready = 1;
1414}
1415
1416static int
1417api_show_threads (vat_main_t * vam)
1418{
1419 vl_api_show_threads_t *mp;
1420 int ret;
1421
1422 print (vam->ofp,
1423 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1424 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1425
1426 M (SHOW_THREADS, mp);
1427
1428 S (mp);
1429 W (ret);
1430 return ret;
1431}
1432
Damjan Marion7cd468a2016-12-19 23:05:39 +01001433static void
1434vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
1435{
Wojciech Dec09a38a62017-03-07 19:30:39 +01001436 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo20e1f2a2017-03-29 13:35:43 -04001437 errmsg ("arp %s event: pid %d address %U new mac %U sw_if_index %d\n",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001438 mp->mac_ip ? "mac/ip binding" : "address resolution",
Neale Ranns37029302018-08-10 05:30:06 -07001439 ntohl (mp->pid), format_ip4_address, mp->ip,
1440 format_vl_api_mac_address, &mp->mac, sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001441}
1442
1443static void
1444vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
1445{
1446 /* JSON output not supported */
1447}
1448
1449static void
1450vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1451{
Wojciech Dec09a38a62017-03-07 19:30:39 +01001452 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo20e1f2a2017-03-29 13:35:43 -04001453 errmsg ("ip6 nd %s event: pid %d address %U new mac %U sw_if_index %d\n",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001454 mp->mac_ip ? "mac/ip binding" : "address resolution",
Neale Ranns37029302018-08-10 05:30:06 -07001455 ntohl (mp->pid), format_vl_api_ip6_address, mp->ip,
1456 format_vl_api_mac_address, mp->mac, sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001457}
1458
1459static void
1460vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1461{
1462 /* JSON output not supported */
1463}
1464
John Lo8d00fff2017-08-03 00:35:36 -04001465static void
1466vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1467{
1468 u32 n_macs = ntohl (mp->n_macs);
Paul Vinciguerraec11b132018-09-24 05:25:00 -07001469 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
John Lo8d00fff2017-08-03 00:35:36 -04001470 ntohl (mp->pid), mp->client_index, n_macs);
1471 int i;
1472 for (i = 0; i < n_macs; i++)
1473 {
1474 vl_api_mac_entry_t *mac = &mp->mac[i];
John Loe23c99e2018-03-13 21:53:18 -04001475 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
John Lo8d00fff2017-08-03 00:35:36 -04001476 i + 1, ntohl (mac->sw_if_index),
John Loe23c99e2018-03-13 21:53:18 -04001477 format_ethernet_address, mac->mac_addr, mac->action);
John Lo8d00fff2017-08-03 00:35:36 -04001478 if (i == 1000)
1479 break;
1480 }
1481}
1482
1483static void
1484vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1485{
1486 /* JSON output not supported */
1487}
1488
Ole Troan01384fe2017-05-12 11:55:35 +02001489#define vl_api_bridge_domain_details_t_endian vl_noop_handler
1490#define vl_api_bridge_domain_details_t_print vl_noop_handler
1491
Damjan Marion7cd468a2016-12-19 23:05:39 +01001492/*
1493 * Special-case: build the bridge domain table, maintain
1494 * the next bd id vbl.
1495 */
1496static void vl_api_bridge_domain_details_t_handler
1497 (vl_api_bridge_domain_details_t * mp)
1498{
1499 vat_main_t *vam = &vat_main;
1500 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ole Troan01384fe2017-05-12 11:55:35 +02001501 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001502
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001503 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1504 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001505
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001506 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001507 ntohl (mp->bd_id), mp->learn, mp->forward,
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001508 mp->flood, ntohl (mp->bvi_sw_if_index),
1509 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001510
1511 if (n_sw_ifs)
Ole Troan01384fe2017-05-12 11:55:35 +02001512 {
1513 vl_api_bridge_domain_sw_if_t *sw_ifs;
1514 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1515 "Interface Name");
1516
1517 sw_ifs = mp->sw_if_details;
1518 for (i = 0; i < n_sw_ifs; i++)
1519 {
1520 u8 *sw_if_name = 0;
1521 u32 sw_if_index;
1522 hash_pair_t *p;
1523
1524 sw_if_index = ntohl (sw_ifs->sw_if_index);
1525
1526 /* *INDENT-OFF* */
1527 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1528 ({
1529 if ((u32) p->value[0] == sw_if_index)
1530 {
1531 sw_if_name = (u8 *)(p->key);
1532 break;
1533 }
1534 }));
1535 /* *INDENT-ON* */
1536 print (vam->ofp, "%7d %3d %s", sw_if_index,
1537 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1538 "sw_if_index not found!");
1539
1540 sw_ifs++;
1541 }
1542 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001543}
1544
1545static void vl_api_bridge_domain_details_t_handler_json
1546 (vl_api_bridge_domain_details_t * mp)
1547{
1548 vat_main_t *vam = &vat_main;
1549 vat_json_node_t *node, *array = NULL;
Ole Troan01384fe2017-05-12 11:55:35 +02001550 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001551
1552 if (VAT_JSON_ARRAY != vam->json_tree.type)
1553 {
1554 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1555 vat_json_init_array (&vam->json_tree);
1556 }
1557 node = vat_json_array_add (&vam->json_tree);
1558
1559 vat_json_init_object (node);
1560 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1561 vat_json_object_add_uint (node, "flood", mp->flood);
1562 vat_json_object_add_uint (node, "forward", mp->forward);
1563 vat_json_object_add_uint (node, "learn", mp->learn);
1564 vat_json_object_add_uint (node, "bvi_sw_if_index",
1565 ntohl (mp->bvi_sw_if_index));
Ole Troan01384fe2017-05-12 11:55:35 +02001566 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001567 array = vat_json_object_add (node, "sw_if");
1568 vat_json_init_array (array);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001569
Damjan Marion7cd468a2016-12-19 23:05:39 +01001570
Damjan Marion7cd468a2016-12-19 23:05:39 +01001571
Ole Troan01384fe2017-05-12 11:55:35 +02001572 if (n_sw_ifs)
1573 {
1574 vl_api_bridge_domain_sw_if_t *sw_ifs;
1575 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001576
Ole Troan01384fe2017-05-12 11:55:35 +02001577 sw_ifs = mp->sw_if_details;
1578 for (i = 0; i < n_sw_ifs; i++)
1579 {
1580 node = vat_json_array_add (array);
1581 vat_json_init_object (node);
1582 vat_json_object_add_uint (node, "sw_if_index",
1583 ntohl (sw_ifs->sw_if_index));
1584 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1585 sw_ifs++;
1586 }
1587 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001588}
1589
1590static void vl_api_control_ping_reply_t_handler
1591 (vl_api_control_ping_reply_t * mp)
1592{
1593 vat_main_t *vam = &vat_main;
1594 i32 retval = ntohl (mp->retval);
1595 if (vam->async_mode)
1596 {
1597 vam->async_errors += (retval < 0);
1598 }
1599 else
1600 {
1601 vam->retval = retval;
1602 vam->result_ready = 1;
1603 }
Florin Coras90a63982017-12-19 04:50:01 -08001604 if (vam->socket_client_main)
1605 vam->socket_client_main->control_pings_outstanding--;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001606}
1607
1608static void vl_api_control_ping_reply_t_handler_json
1609 (vl_api_control_ping_reply_t * mp)
1610{
1611 vat_main_t *vam = &vat_main;
1612 i32 retval = ntohl (mp->retval);
1613
1614 if (VAT_JSON_NONE != vam->json_tree.type)
1615 {
1616 vat_json_print (vam->ofp, &vam->json_tree);
1617 vat_json_free (&vam->json_tree);
1618 vam->json_tree.type = VAT_JSON_NONE;
1619 }
1620 else
1621 {
1622 /* just print [] */
1623 vat_json_init_array (&vam->json_tree);
1624 vat_json_print (vam->ofp, &vam->json_tree);
1625 vam->json_tree.type = VAT_JSON_NONE;
1626 }
1627
1628 vam->retval = retval;
1629 vam->result_ready = 1;
1630}
1631
1632static void
Eyal Barifead6702017-04-04 04:46:32 +03001633 vl_api_bridge_domain_set_mac_age_reply_t_handler
1634 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1635{
1636 vat_main_t *vam = &vat_main;
1637 i32 retval = ntohl (mp->retval);
1638 if (vam->async_mode)
1639 {
1640 vam->async_errors += (retval < 0);
1641 }
1642 else
1643 {
1644 vam->retval = retval;
1645 vam->result_ready = 1;
1646 }
1647}
1648
1649static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1650 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1651{
1652 vat_main_t *vam = &vat_main;
1653 vat_json_node_t node;
1654
1655 vat_json_init_object (&node);
1656 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1657
1658 vat_json_print (vam->ofp, &node);
1659 vat_json_free (&node);
1660
1661 vam->retval = ntohl (mp->retval);
1662 vam->result_ready = 1;
1663}
1664
1665static void
Damjan Marion7cd468a2016-12-19 23:05:39 +01001666vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1667{
1668 vat_main_t *vam = &vat_main;
1669 i32 retval = ntohl (mp->retval);
1670 if (vam->async_mode)
1671 {
1672 vam->async_errors += (retval < 0);
1673 }
1674 else
1675 {
1676 vam->retval = retval;
1677 vam->result_ready = 1;
1678 }
1679}
1680
1681static void vl_api_l2_flags_reply_t_handler_json
1682 (vl_api_l2_flags_reply_t * mp)
1683{
1684 vat_main_t *vam = &vat_main;
1685 vat_json_node_t node;
1686
1687 vat_json_init_object (&node);
1688 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1689 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1690 ntohl (mp->resulting_feature_bitmap));
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 vl_api_bridge_flags_reply_t_handler
1700 (vl_api_bridge_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_bridge_flags_reply_t_handler_json
1716 (vl_api_bridge_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
Damjan Marion8389fb92017-10-13 18:29:53 +02001733static void
1734vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_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->sw_if_index = ntohl (mp->sw_if_index);
1746 vam->result_ready = 1;
1747 }
1748
1749}
1750
1751static void vl_api_tap_create_v2_reply_t_handler_json
1752 (vl_api_tap_create_v2_reply_t * mp)
1753{
1754 vat_main_t *vam = &vat_main;
1755 vat_json_node_t node;
1756
1757 vat_json_init_object (&node);
1758 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1759 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1760
1761 vat_json_print (vam->ofp, &node);
1762 vat_json_free (&node);
1763
1764 vam->retval = ntohl (mp->retval);
1765 vam->result_ready = 1;
1766
1767}
1768
1769static void
1770vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1771{
1772 vat_main_t *vam = &vat_main;
1773 i32 retval = ntohl (mp->retval);
1774 if (vam->async_mode)
1775 {
1776 vam->async_errors += (retval < 0);
1777 }
1778 else
1779 {
1780 vam->retval = retval;
1781 vam->result_ready = 1;
1782 }
1783}
1784
1785static void vl_api_tap_delete_v2_reply_t_handler_json
1786 (vl_api_tap_delete_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
1794 vat_json_print (vam->ofp, &node);
1795 vat_json_free (&node);
1796
1797 vam->retval = ntohl (mp->retval);
1798 vam->result_ready = 1;
1799}
1800
Steven9cd2d7a2017-12-20 12:43:01 -08001801static void
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01001802vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1803 mp)
1804{
1805 vat_main_t *vam = &vat_main;
1806 i32 retval = ntohl (mp->retval);
1807 if (vam->async_mode)
1808 {
1809 vam->async_errors += (retval < 0);
1810 }
1811 else
1812 {
1813 vam->retval = retval;
1814 vam->sw_if_index = ntohl (mp->sw_if_index);
1815 vam->result_ready = 1;
1816 }
1817}
1818
1819static void vl_api_virtio_pci_create_reply_t_handler_json
1820 (vl_api_virtio_pci_create_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 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1828
1829 vat_json_print (vam->ofp, &node);
1830 vat_json_free (&node);
1831
1832 vam->retval = ntohl (mp->retval);
1833 vam->result_ready = 1;
1834
1835}
1836
1837static void
1838vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1839 mp)
1840{
1841 vat_main_t *vam = &vat_main;
1842 i32 retval = ntohl (mp->retval);
1843 if (vam->async_mode)
1844 {
1845 vam->async_errors += (retval < 0);
1846 }
1847 else
1848 {
1849 vam->retval = retval;
1850 vam->result_ready = 1;
1851 }
1852}
1853
1854static void vl_api_virtio_pci_delete_reply_t_handler_json
1855 (vl_api_virtio_pci_delete_reply_t * mp)
1856{
1857 vat_main_t *vam = &vat_main;
1858 vat_json_node_t node;
1859
1860 vat_json_init_object (&node);
1861 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
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
1870static void
Steven9cd2d7a2017-12-20 12:43:01 -08001871vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1872{
1873 vat_main_t *vam = &vat_main;
1874 i32 retval = ntohl (mp->retval);
1875
1876 if (vam->async_mode)
1877 {
1878 vam->async_errors += (retval < 0);
1879 }
1880 else
1881 {
1882 vam->retval = retval;
1883 vam->sw_if_index = ntohl (mp->sw_if_index);
1884 vam->result_ready = 1;
1885 }
1886}
1887
1888static void vl_api_bond_create_reply_t_handler_json
1889 (vl_api_bond_create_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 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1897
1898 vat_json_print (vam->ofp, &node);
1899 vat_json_free (&node);
1900
1901 vam->retval = ntohl (mp->retval);
1902 vam->result_ready = 1;
1903}
1904
1905static void
1906vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1907{
1908 vat_main_t *vam = &vat_main;
1909 i32 retval = ntohl (mp->retval);
1910
1911 if (vam->async_mode)
1912 {
1913 vam->async_errors += (retval < 0);
1914 }
1915 else
1916 {
1917 vam->retval = retval;
1918 vam->result_ready = 1;
1919 }
1920}
1921
1922static void vl_api_bond_delete_reply_t_handler_json
1923 (vl_api_bond_delete_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
1931 vat_json_print (vam->ofp, &node);
1932 vat_json_free (&node);
1933
1934 vam->retval = ntohl (mp->retval);
1935 vam->result_ready = 1;
1936}
1937
1938static void
1939vl_api_bond_enslave_reply_t_handler (vl_api_bond_enslave_reply_t * mp)
1940{
1941 vat_main_t *vam = &vat_main;
1942 i32 retval = ntohl (mp->retval);
1943
1944 if (vam->async_mode)
1945 {
1946 vam->async_errors += (retval < 0);
1947 }
1948 else
1949 {
1950 vam->retval = retval;
1951 vam->result_ready = 1;
1952 }
1953}
1954
1955static void vl_api_bond_enslave_reply_t_handler_json
1956 (vl_api_bond_enslave_reply_t * mp)
1957{
1958 vat_main_t *vam = &vat_main;
1959 vat_json_node_t node;
1960
1961 vat_json_init_object (&node);
1962 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1963
1964 vat_json_print (vam->ofp, &node);
1965 vat_json_free (&node);
1966
1967 vam->retval = ntohl (mp->retval);
1968 vam->result_ready = 1;
1969}
1970
1971static void
1972vl_api_bond_detach_slave_reply_t_handler (vl_api_bond_detach_slave_reply_t *
1973 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_detach_slave_reply_t_handler_json
1990 (vl_api_bond_detach_slave_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
Steven Luonga1876b82019-08-20 16:58:00 -07002005static int
2006api_sw_interface_set_bond_weight (vat_main_t * vam)
2007{
2008 unformat_input_t *i = vam->input;
2009 vl_api_sw_interface_set_bond_weight_t *mp;
2010 u32 sw_if_index = ~0;
2011 u32 weight = 0;
2012 u8 weight_enter = 0;
2013 int ret;
2014
2015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2016 {
2017 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2018 ;
2019 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2020 ;
2021 else if (unformat (i, "weight %u", &weight))
2022 weight_enter = 1;
2023 else
2024 break;
2025 }
2026
2027 if (sw_if_index == ~0)
2028 {
2029 errmsg ("missing interface name or sw_if_index");
2030 return -99;
2031 }
2032 if (weight_enter == 0)
2033 {
2034 errmsg ("missing valid weight");
2035 return -99;
2036 }
2037
2038 /* Construct the API message */
2039 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2040 mp->sw_if_index = ntohl (sw_if_index);
2041 mp->weight = ntohl (weight);
2042
2043 S (mp);
2044 W (ret);
2045 return ret;
2046}
2047
Steven9cd2d7a2017-12-20 12:43:01 -08002048static void vl_api_sw_interface_bond_details_t_handler
2049 (vl_api_sw_interface_bond_details_t * mp)
2050{
2051 vat_main_t *vam = &vat_main;
2052
2053 print (vam->ofp,
2054 "%-16s %-12d %-12U %-13U %-14u %-14u",
2055 mp->interface_name, ntohl (mp->sw_if_index),
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02002056 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2057 ntohl (mp->lb), ntohl (mp->active_slaves), ntohl (mp->slaves));
Steven9cd2d7a2017-12-20 12:43:01 -08002058}
2059
2060static void vl_api_sw_interface_bond_details_t_handler_json
2061 (vl_api_sw_interface_bond_details_t * mp)
2062{
2063 vat_main_t *vam = &vat_main;
2064 vat_json_node_t *node = NULL;
2065
2066 if (VAT_JSON_ARRAY != vam->json_tree.type)
2067 {
2068 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2069 vat_json_init_array (&vam->json_tree);
2070 }
2071 node = vat_json_array_add (&vam->json_tree);
2072
2073 vat_json_init_object (node);
2074 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2075 vat_json_object_add_string_copy (node, "interface_name",
2076 mp->interface_name);
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02002077 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2078 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
Steven9cd2d7a2017-12-20 12:43:01 -08002079 vat_json_object_add_uint (node, "active_slaves", ntohl (mp->active_slaves));
2080 vat_json_object_add_uint (node, "slaves", ntohl (mp->slaves));
2081}
2082
2083static int
2084api_sw_interface_bond_dump (vat_main_t * vam)
2085{
2086 vl_api_sw_interface_bond_dump_t *mp;
2087 vl_api_control_ping_t *mp_ping;
2088 int ret;
2089
2090 print (vam->ofp,
2091 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2092 "interface name", "sw_if_index", "mode", "load balance",
2093 "active slaves", "slaves");
2094
2095 /* Get list of bond interfaces */
2096 M (SW_INTERFACE_BOND_DUMP, mp);
2097 S (mp);
2098
2099 /* Use a control ping for synchronization */
2100 MPING (CONTROL_PING, mp_ping);
2101 S (mp_ping);
2102
2103 W (ret);
2104 return ret;
2105}
2106
2107static void vl_api_sw_interface_slave_details_t_handler
2108 (vl_api_sw_interface_slave_details_t * mp)
2109{
2110 vat_main_t *vam = &vat_main;
2111
2112 print (vam->ofp,
Steven Luonga1876b82019-08-20 16:58:00 -07002113 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2114 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2115 ntohl (mp->weight), mp->is_local_numa);
Steven9cd2d7a2017-12-20 12:43:01 -08002116}
2117
2118static void vl_api_sw_interface_slave_details_t_handler_json
2119 (vl_api_sw_interface_slave_details_t * mp)
2120{
2121 vat_main_t *vam = &vat_main;
2122 vat_json_node_t *node = NULL;
2123
2124 if (VAT_JSON_ARRAY != vam->json_tree.type)
2125 {
2126 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2127 vat_json_init_array (&vam->json_tree);
2128 }
2129 node = vat_json_array_add (&vam->json_tree);
2130
2131 vat_json_init_object (node);
2132 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2133 vat_json_object_add_string_copy (node, "interface_name",
2134 mp->interface_name);
2135 vat_json_object_add_uint (node, "passive", mp->is_passive);
2136 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
Steven Luonga1876b82019-08-20 16:58:00 -07002137 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2138 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
Steven9cd2d7a2017-12-20 12:43:01 -08002139}
2140
2141static int
2142api_sw_interface_slave_dump (vat_main_t * vam)
2143{
2144 unformat_input_t *i = vam->input;
2145 vl_api_sw_interface_slave_dump_t *mp;
2146 vl_api_control_ping_t *mp_ping;
2147 u32 sw_if_index = ~0;
2148 u8 sw_if_index_set = 0;
2149 int ret;
2150
2151 /* Parse args required to build the message */
2152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2153 {
2154 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2155 sw_if_index_set = 1;
2156 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2157 sw_if_index_set = 1;
2158 else
2159 break;
2160 }
2161
2162 if (sw_if_index_set == 0)
2163 {
2164 errmsg ("missing vpp interface name. ");
2165 return -99;
2166 }
2167
2168 print (vam->ofp,
Steven Luonga1876b82019-08-20 16:58:00 -07002169 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2170 "slave interface name", "sw_if_index", "passive", "long_timeout",
2171 "weight", "local numa");
Steven9cd2d7a2017-12-20 12:43:01 -08002172
2173 /* Get list of bond interfaces */
2174 M (SW_INTERFACE_SLAVE_DUMP, mp);
2175 mp->sw_if_index = ntohl (sw_if_index);
2176 S (mp);
2177
2178 /* Use a control ping for synchronization */
2179 MPING (CONTROL_PING, mp_ping);
2180 S (mp_ping);
2181
2182 W (ret);
2183 return ret;
2184}
2185
Damjan Marion7cd468a2016-12-19 23:05:39 +01002186static void vl_api_mpls_tunnel_add_del_reply_t_handler
2187 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2188{
2189 vat_main_t *vam = &vat_main;
2190 i32 retval = ntohl (mp->retval);
2191 if (vam->async_mode)
2192 {
2193 vam->async_errors += (retval < 0);
2194 }
2195 else
2196 {
2197 vam->retval = retval;
John Lo06fda9c2018-10-03 16:32:44 -04002198 vam->sw_if_index = ntohl (mp->sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002199 vam->result_ready = 1;
2200 }
John Lo06fda9c2018-10-03 16:32:44 -04002201 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002202}
2203
2204static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2205 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2206{
2207 vat_main_t *vam = &vat_main;
2208 vat_json_node_t node;
2209
2210 vat_json_init_object (&node);
2211 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2212 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2213 ntohl (mp->sw_if_index));
2214
2215 vat_json_print (vam->ofp, &node);
2216 vat_json_free (&node);
2217
2218 vam->retval = ntohl (mp->retval);
2219 vam->result_ready = 1;
2220}
2221
2222static void vl_api_l2tpv3_create_tunnel_reply_t_handler
2223 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2224{
2225 vat_main_t *vam = &vat_main;
2226 i32 retval = ntohl (mp->retval);
2227 if (vam->async_mode)
2228 {
2229 vam->async_errors += (retval < 0);
2230 }
2231 else
2232 {
2233 vam->retval = retval;
2234 vam->sw_if_index = ntohl (mp->sw_if_index);
2235 vam->result_ready = 1;
2236 }
2237}
2238
2239static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
2240 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2241{
2242 vat_main_t *vam = &vat_main;
2243 vat_json_node_t node;
2244
2245 vat_json_init_object (&node);
2246 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2247 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2248
2249 vat_json_print (vam->ofp, &node);
2250 vat_json_free (&node);
2251
2252 vam->retval = ntohl (mp->retval);
2253 vam->result_ready = 1;
2254}
2255
Filip Tehlar560274d2017-06-05 13:40:13 +02002256static void vl_api_gpe_add_del_fwd_entry_reply_t_handler
2257 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2258{
2259 vat_main_t *vam = &vat_main;
2260 i32 retval = ntohl (mp->retval);
2261 if (vam->async_mode)
2262 {
2263 vam->async_errors += (retval < 0);
2264 }
2265 else
2266 {
2267 vam->retval = retval;
2268 vam->result_ready = 1;
2269 }
2270}
2271
2272static void vl_api_gpe_add_del_fwd_entry_reply_t_handler_json
2273 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2274{
2275 vat_main_t *vam = &vat_main;
2276 vat_json_node_t node;
2277
2278 vat_json_init_object (&node);
2279 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2280 vat_json_object_add_uint (&node, "fwd_entry_index",
2281 clib_net_to_host_u32 (mp->fwd_entry_index));
2282
2283 vat_json_print (vam->ofp, &node);
2284 vat_json_free (&node);
2285
2286 vam->retval = ntohl (mp->retval);
2287 vam->result_ready = 1;
2288}
Damjan Marion7cd468a2016-12-19 23:05:39 +01002289
Filip Tehlara4980b82017-09-27 14:32:02 +02002290u8 *
2291format_lisp_transport_protocol (u8 * s, va_list * args)
2292{
2293 u32 proto = va_arg (*args, u32);
2294
2295 switch (proto)
2296 {
2297 case 1:
2298 return format (s, "udp");
2299 case 2:
2300 return format (s, "api");
2301 default:
2302 return 0;
2303 }
2304 return 0;
2305}
2306
2307static void vl_api_one_get_transport_protocol_reply_t_handler
2308 (vl_api_one_get_transport_protocol_reply_t * mp)
2309{
2310 vat_main_t *vam = &vat_main;
2311 i32 retval = ntohl (mp->retval);
2312 if (vam->async_mode)
2313 {
2314 vam->async_errors += (retval < 0);
2315 }
2316 else
2317 {
2318 u32 proto = mp->protocol;
2319 print (vam->ofp, "Transport protocol: %U",
2320 format_lisp_transport_protocol, proto);
2321 vam->retval = retval;
2322 vam->result_ready = 1;
2323 }
2324}
2325
2326static void vl_api_one_get_transport_protocol_reply_t_handler_json
2327 (vl_api_one_get_transport_protocol_reply_t * mp)
2328{
2329 vat_main_t *vam = &vat_main;
2330 vat_json_node_t node;
2331 u8 *s;
2332
2333 s = format (0, "%U", format_lisp_transport_protocol, mp->protocol);
2334 vec_add1 (s, 0);
2335
2336 vat_json_init_object (&node);
2337 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2338 vat_json_object_add_string_copy (&node, "transport-protocol", s);
2339
2340 vec_free (s);
2341 vat_json_print (vam->ofp, &node);
2342 vat_json_free (&node);
2343
2344 vam->retval = ntohl (mp->retval);
2345 vam->result_ready = 1;
2346}
2347
Filip Tehlar694396d2017-02-17 14:29:11 +01002348static void vl_api_one_add_del_locator_set_reply_t_handler
2349 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002350{
2351 vat_main_t *vam = &vat_main;
2352 i32 retval = ntohl (mp->retval);
2353 if (vam->async_mode)
2354 {
2355 vam->async_errors += (retval < 0);
2356 }
2357 else
2358 {
2359 vam->retval = retval;
2360 vam->result_ready = 1;
2361 }
2362}
2363
Filip Tehlar694396d2017-02-17 14:29:11 +01002364static void vl_api_one_add_del_locator_set_reply_t_handler_json
2365 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002366{
2367 vat_main_t *vam = &vat_main;
2368 vat_json_node_t node;
2369
2370 vat_json_init_object (&node);
2371 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2372 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
2373
2374 vat_json_print (vam->ofp, &node);
2375 vat_json_free (&node);
2376
2377 vam->retval = ntohl (mp->retval);
2378 vam->result_ready = 1;
2379}
2380
2381static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2382 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2383{
2384 vat_main_t *vam = &vat_main;
2385 i32 retval = ntohl (mp->retval);
2386 if (vam->async_mode)
2387 {
2388 vam->async_errors += (retval < 0);
2389 }
2390 else
2391 {
2392 vam->retval = retval;
2393 vam->sw_if_index = ntohl (mp->sw_if_index);
2394 vam->result_ready = 1;
2395 }
Dave Barachf72212e2018-01-11 10:25:07 -05002396 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002397}
2398
2399static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2400 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2401{
2402 vat_main_t *vam = &vat_main;
2403 vat_json_node_t node;
2404
2405 vat_json_init_object (&node);
2406 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2407 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2408
2409 vat_json_print (vam->ofp, &node);
2410 vat_json_free (&node);
2411
2412 vam->retval = ntohl (mp->retval);
2413 vam->result_ready = 1;
2414}
2415
eyal bariaf86a482018-04-17 11:20:27 +03002416static void vl_api_vxlan_offload_rx_reply_t_handler
2417 (vl_api_vxlan_offload_rx_reply_t * mp)
2418{
2419 vat_main_t *vam = &vat_main;
2420 i32 retval = ntohl (mp->retval);
2421 if (vam->async_mode)
2422 {
2423 vam->async_errors += (retval < 0);
2424 }
2425 else
2426 {
2427 vam->retval = retval;
2428 vam->result_ready = 1;
2429 }
2430}
2431
2432static void vl_api_vxlan_offload_rx_reply_t_handler_json
2433 (vl_api_vxlan_offload_rx_reply_t * mp)
2434{
2435 vat_main_t *vam = &vat_main;
2436 vat_json_node_t node;
2437
2438 vat_json_init_object (&node);
2439 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2440
2441 vat_json_print (vam->ofp, &node);
2442 vat_json_free (&node);
2443
2444 vam->retval = ntohl (mp->retval);
2445 vam->result_ready = 1;
2446}
2447
Marco Varleseb598f1d2017-09-19 14:25:28 +02002448static void vl_api_geneve_add_del_tunnel_reply_t_handler
2449 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2450{
2451 vat_main_t *vam = &vat_main;
2452 i32 retval = ntohl (mp->retval);
2453 if (vam->async_mode)
2454 {
2455 vam->async_errors += (retval < 0);
2456 }
2457 else
2458 {
2459 vam->retval = retval;
2460 vam->sw_if_index = ntohl (mp->sw_if_index);
2461 vam->result_ready = 1;
2462 }
2463}
2464
2465static void vl_api_geneve_add_del_tunnel_reply_t_handler_json
2466 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2467{
2468 vat_main_t *vam = &vat_main;
2469 vat_json_node_t node;
2470
2471 vat_json_init_object (&node);
2472 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2473 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2474
2475 vat_json_print (vam->ofp, &node);
2476 vat_json_free (&node);
2477
2478 vam->retval = ntohl (mp->retval);
2479 vam->result_ready = 1;
2480}
2481
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002482static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2483 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2484{
2485 vat_main_t *vam = &vat_main;
2486 i32 retval = ntohl (mp->retval);
2487 if (vam->async_mode)
2488 {
2489 vam->async_errors += (retval < 0);
2490 }
2491 else
2492 {
2493 vam->retval = retval;
2494 vam->sw_if_index = ntohl (mp->sw_if_index);
2495 vam->result_ready = 1;
2496 }
Dave Barachf72212e2018-01-11 10:25:07 -05002497 vam->regenerate_interface_table = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002498}
2499
2500static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2501 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2502{
2503 vat_main_t *vam = &vat_main;
2504 vat_json_node_t node;
2505
2506 vat_json_init_object (&node);
2507 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2508 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2509
2510 vat_json_print (vam->ofp, &node);
2511 vat_json_free (&node);
2512
2513 vam->retval = ntohl (mp->retval);
2514 vam->result_ready = 1;
2515}
2516
Neale Ranns5a8844b2019-04-16 07:15:35 +00002517static void vl_api_gre_tunnel_add_del_reply_t_handler
2518 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002519{
2520 vat_main_t *vam = &vat_main;
2521 i32 retval = ntohl (mp->retval);
2522 if (vam->async_mode)
2523 {
2524 vam->async_errors += (retval < 0);
2525 }
2526 else
2527 {
2528 vam->retval = retval;
2529 vam->sw_if_index = ntohl (mp->sw_if_index);
2530 vam->result_ready = 1;
2531 }
2532}
2533
Neale Ranns5a8844b2019-04-16 07:15:35 +00002534static void vl_api_gre_tunnel_add_del_reply_t_handler_json
2535 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002536{
2537 vat_main_t *vam = &vat_main;
2538 vat_json_node_t node;
2539
2540 vat_json_init_object (&node);
2541 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2542 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2543
2544 vat_json_print (vam->ofp, &node);
2545 vat_json_free (&node);
2546
2547 vam->retval = ntohl (mp->retval);
2548 vam->result_ready = 1;
2549}
2550
2551static void vl_api_create_vhost_user_if_reply_t_handler
2552 (vl_api_create_vhost_user_if_reply_t * mp)
2553{
2554 vat_main_t *vam = &vat_main;
2555 i32 retval = ntohl (mp->retval);
2556 if (vam->async_mode)
2557 {
2558 vam->async_errors += (retval < 0);
2559 }
2560 else
2561 {
2562 vam->retval = retval;
2563 vam->sw_if_index = ntohl (mp->sw_if_index);
2564 vam->result_ready = 1;
2565 }
Dave Barachf72212e2018-01-11 10:25:07 -05002566 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002567}
2568
2569static void vl_api_create_vhost_user_if_reply_t_handler_json
2570 (vl_api_create_vhost_user_if_reply_t * mp)
2571{
2572 vat_main_t *vam = &vat_main;
2573 vat_json_node_t node;
2574
2575 vat_json_init_object (&node);
2576 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2577 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2578
2579 vat_json_print (vam->ofp, &node);
2580 vat_json_free (&node);
2581
2582 vam->retval = ntohl (mp->retval);
2583 vam->result_ready = 1;
2584}
2585
2586static void vl_api_ip_address_details_t_handler
2587 (vl_api_ip_address_details_t * mp)
2588{
2589 vat_main_t *vam = &vat_main;
2590 static ip_address_details_t empty_ip_address_details = { {0} };
2591 ip_address_details_t *address = NULL;
2592 ip_details_t *current_ip_details = NULL;
2593 ip_details_t *details = NULL;
2594
2595 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2596
2597 if (!details || vam->current_sw_if_index >= vec_len (details)
2598 || !details[vam->current_sw_if_index].present)
2599 {
2600 errmsg ("ip address details arrived but not stored");
2601 errmsg ("ip_dump should be called first");
2602 return;
2603 }
2604
2605 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2606
2607#define addresses (current_ip_details->addr)
2608
2609 vec_validate_init_empty (addresses, vec_len (addresses),
2610 empty_ip_address_details);
2611
2612 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2613
Neale Ranns097fa662018-05-01 05:17:55 -07002614 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
Paul Vinciguerraab055082019-06-06 14:07:55 -04002615 address->prefix_length = mp->prefix.len;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002616#undef addresses
2617}
2618
2619static void vl_api_ip_address_details_t_handler_json
2620 (vl_api_ip_address_details_t * mp)
2621{
2622 vat_main_t *vam = &vat_main;
2623 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002624
2625 if (VAT_JSON_ARRAY != vam->json_tree.type)
2626 {
2627 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2628 vat_json_init_array (&vam->json_tree);
2629 }
2630 node = vat_json_array_add (&vam->json_tree);
2631
2632 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -07002633 vat_json_object_add_prefix (node, &mp->prefix);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002634}
2635
2636static void
2637vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2638{
2639 vat_main_t *vam = &vat_main;
2640 static ip_details_t empty_ip_details = { 0 };
2641 ip_details_t *ip = NULL;
2642 u32 sw_if_index = ~0;
2643
2644 sw_if_index = ntohl (mp->sw_if_index);
2645
2646 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2647 sw_if_index, empty_ip_details);
2648
2649 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2650 sw_if_index);
2651
2652 ip->present = 1;
2653}
2654
2655static void
2656vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2657{
2658 vat_main_t *vam = &vat_main;
2659
2660 if (VAT_JSON_ARRAY != vam->json_tree.type)
2661 {
2662 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2663 vat_json_init_array (&vam->json_tree);
2664 }
2665 vat_json_array_add_uint (&vam->json_tree,
2666 clib_net_to_host_u32 (mp->sw_if_index));
2667}
2668
Damjan Marion7cd468a2016-12-19 23:05:39 +01002669static void
2670vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
2671{
jackiechen198556bc7382019-04-29 12:00:43 +08002672 u8 *s, i;
2673
Jakub Grajciar103ba6b2019-10-01 11:30:56 +02002674 s = format (0, "DHCP compl event: pid %d hostname %s host_addr %U "
jackiechen198556bc7382019-04-29 12:00:43 +08002675 "host_mac %U router_addr %U",
Jakub Grajciar103ba6b2019-10-01 11:30:56 +02002676 ntohl (mp->pid), mp->lease.hostname,
jackiechen198556bc7382019-04-29 12:00:43 +08002677 format_ip4_address, mp->lease.host_address,
2678 format_ethernet_address, mp->lease.host_mac,
2679 format_ip4_address, mp->lease.router_address);
2680
2681 for (i = 0; i < mp->lease.count; i++)
2682 s =
2683 format (s, " domain_server_addr %U", format_ip4_address,
2684 mp->lease.domain_server[i].address);
2685
2686 errmsg ((char *) s);
Dave Baracha4ef82e2019-05-14 08:12:36 -04002687 vec_free (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002688}
2689
2690static void vl_api_dhcp_compl_event_t_handler_json
2691 (vl_api_dhcp_compl_event_t * mp)
2692{
2693 /* JSON output not supported */
2694}
2695
Damjan Marion7cd468a2016-12-19 23:05:39 +01002696static void vl_api_get_first_msg_id_reply_t_handler
2697 (vl_api_get_first_msg_id_reply_t * mp)
2698{
2699 vat_main_t *vam = &vat_main;
2700 i32 retval = ntohl (mp->retval);
2701
2702 if (vam->async_mode)
2703 {
2704 vam->async_errors += (retval < 0);
2705 }
2706 else
2707 {
2708 vam->retval = retval;
2709 vam->result_ready = 1;
2710 }
2711 if (retval >= 0)
2712 {
2713 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2714 }
2715}
2716
2717static void vl_api_get_first_msg_id_reply_t_handler_json
2718 (vl_api_get_first_msg_id_reply_t * mp)
2719{
2720 vat_main_t *vam = &vat_main;
2721 vat_json_node_t node;
2722
2723 vat_json_init_object (&node);
2724 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2725 vat_json_object_add_uint (&node, "first_msg_id",
2726 (uint) ntohs (mp->first_msg_id));
2727
2728 vat_json_print (vam->ofp, &node);
2729 vat_json_free (&node);
2730
2731 vam->retval = ntohl (mp->retval);
2732 vam->result_ready = 1;
2733}
2734
2735static void vl_api_get_node_graph_reply_t_handler
2736 (vl_api_get_node_graph_reply_t * mp)
2737{
2738 vat_main_t *vam = &vat_main;
2739 api_main_t *am = &api_main;
2740 i32 retval = ntohl (mp->retval);
2741 u8 *pvt_copy, *reply;
2742 void *oldheap;
2743 vlib_node_t *node;
2744 int i;
2745
2746 if (vam->async_mode)
2747 {
2748 vam->async_errors += (retval < 0);
2749 }
2750 else
2751 {
2752 vam->retval = retval;
2753 vam->result_ready = 1;
2754 }
2755
2756 /* "Should never happen..." */
2757 if (retval != 0)
2758 return;
2759
Damjan Marion7bee80c2017-04-26 15:32:12 +02002760 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002761 pvt_copy = vec_dup (reply);
2762
2763 /* Toss the shared-memory original... */
2764 pthread_mutex_lock (&am->vlib_rp->mutex);
2765 oldheap = svm_push_data_heap (am->vlib_rp);
2766
2767 vec_free (reply);
2768
2769 svm_pop_heap (oldheap);
2770 pthread_mutex_unlock (&am->vlib_rp->mutex);
2771
2772 if (vam->graph_nodes)
2773 {
2774 hash_free (vam->graph_node_index_by_name);
2775
Dave Barach1ddbc012018-06-13 09:26:05 -04002776 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002777 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002778 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002779 vec_free (node->name);
2780 vec_free (node->next_nodes);
2781 vec_free (node);
2782 }
Dave Barach1ddbc012018-06-13 09:26:05 -04002783 vec_free (vam->graph_nodes[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002784 vec_free (vam->graph_nodes);
2785 }
2786
2787 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2788 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2789 vec_free (pvt_copy);
2790
Dave Barach1ddbc012018-06-13 09:26:05 -04002791 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002792 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002793 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002794 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2795 }
2796}
2797
2798static void vl_api_get_node_graph_reply_t_handler_json
2799 (vl_api_get_node_graph_reply_t * mp)
2800{
2801 vat_main_t *vam = &vat_main;
2802 api_main_t *am = &api_main;
2803 void *oldheap;
2804 vat_json_node_t node;
2805 u8 *reply;
2806
2807 /* $$$$ make this real? */
2808 vat_json_init_object (&node);
2809 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2810 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
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
2814 /* Toss the shared-memory original... */
2815 pthread_mutex_lock (&am->vlib_rp->mutex);
2816 oldheap = svm_push_data_heap (am->vlib_rp);
2817
2818 vec_free (reply);
2819
2820 svm_pop_heap (oldheap);
2821 pthread_mutex_unlock (&am->vlib_rp->mutex);
2822
2823 vat_json_print (vam->ofp, &node);
2824 vat_json_free (&node);
2825
2826 vam->retval = ntohl (mp->retval);
2827 vam->result_ready = 1;
2828}
2829
2830static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002831vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002832{
2833 vat_main_t *vam = &vat_main;
2834 u8 *s = 0;
2835
2836 if (mp->local)
2837 {
2838 s = format (s, "%=16d%=16d%=16d",
2839 ntohl (mp->sw_if_index), mp->priority, mp->weight);
2840 }
2841 else
2842 {
2843 s = format (s, "%=16U%=16d%=16d",
2844 mp->is_ipv6 ? format_ip6_address :
2845 format_ip4_address,
2846 mp->ip_address, mp->priority, mp->weight);
2847 }
2848
2849 print (vam->ofp, "%v", s);
2850 vec_free (s);
2851}
2852
2853static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002854vl_api_one_locator_details_t_handler_json (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002855{
2856 vat_main_t *vam = &vat_main;
2857 vat_json_node_t *node = NULL;
2858 struct in6_addr ip6;
2859 struct in_addr ip4;
2860
2861 if (VAT_JSON_ARRAY != vam->json_tree.type)
2862 {
2863 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2864 vat_json_init_array (&vam->json_tree);
2865 }
2866 node = vat_json_array_add (&vam->json_tree);
2867 vat_json_init_object (node);
2868
2869 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2870 vat_json_object_add_uint (node, "priority", mp->priority);
2871 vat_json_object_add_uint (node, "weight", mp->weight);
2872
2873 if (mp->local)
2874 vat_json_object_add_uint (node, "sw_if_index",
2875 clib_net_to_host_u32 (mp->sw_if_index));
2876 else
2877 {
2878 if (mp->is_ipv6)
2879 {
2880 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2881 vat_json_object_add_ip6 (node, "address", ip6);
2882 }
2883 else
2884 {
2885 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2886 vat_json_object_add_ip4 (node, "address", ip4);
2887 }
2888 }
2889}
2890
2891static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002892vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
2893 mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002894{
2895 vat_main_t *vam = &vat_main;
2896 u8 *ls_name = 0;
2897
2898 ls_name = format (0, "%s", mp->ls_name);
2899
2900 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
2901 ls_name);
2902 vec_free (ls_name);
2903}
2904
2905static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002906 vl_api_one_locator_set_details_t_handler_json
2907 (vl_api_one_locator_set_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002908{
2909 vat_main_t *vam = &vat_main;
2910 vat_json_node_t *node = 0;
2911 u8 *ls_name = 0;
2912
2913 ls_name = format (0, "%s", mp->ls_name);
2914 vec_add1 (ls_name, 0);
2915
2916 if (VAT_JSON_ARRAY != vam->json_tree.type)
2917 {
2918 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2919 vat_json_init_array (&vam->json_tree);
2920 }
2921 node = vat_json_array_add (&vam->json_tree);
2922
2923 vat_json_init_object (node);
2924 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2925 vat_json_object_add_uint (node, "ls_index",
2926 clib_net_to_host_u32 (mp->ls_index));
2927 vec_free (ls_name);
2928}
2929
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002930typedef struct
2931{
2932 u32 spi;
2933 u8 si;
2934} __attribute__ ((__packed__)) lisp_nsh_api_t;
2935
2936uword
2937unformat_nsh_address (unformat_input_t * input, va_list * args)
2938{
2939 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
2940 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
2941}
2942
2943u8 *
2944format_nsh_address_vat (u8 * s, va_list * args)
2945{
2946 nsh_t *a = va_arg (*args, nsh_t *);
2947 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
2948}
2949
Damjan Marion7cd468a2016-12-19 23:05:39 +01002950static u8 *
2951format_lisp_flat_eid (u8 * s, va_list * args)
2952{
2953 u32 type = va_arg (*args, u32);
2954 u8 *eid = va_arg (*args, u8 *);
2955 u32 eid_len = va_arg (*args, u32);
2956
2957 switch (type)
2958 {
2959 case 0:
2960 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2961 case 1:
2962 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2963 case 2:
2964 return format (s, "%U", format_ethernet_address, eid);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002965 case 3:
2966 return format (s, "%U", format_nsh_address_vat, eid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002967 }
2968 return 0;
2969}
2970
2971static u8 *
2972format_lisp_eid_vat (u8 * s, va_list * args)
2973{
2974 u32 type = va_arg (*args, u32);
2975 u8 *eid = va_arg (*args, u8 *);
2976 u32 eid_len = va_arg (*args, u32);
2977 u8 *seid = va_arg (*args, u8 *);
2978 u32 seid_len = va_arg (*args, u32);
2979 u32 is_src_dst = va_arg (*args, u32);
2980
2981 if (is_src_dst)
2982 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
2983
2984 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
2985
2986 return s;
2987}
2988
2989static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002990vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002991{
2992 vat_main_t *vam = &vat_main;
2993 u8 *s = 0, *eid = 0;
2994
2995 if (~0 == mp->locator_set_index)
2996 s = format (0, "action: %d", mp->action);
2997 else
2998 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2999
3000 eid = format (0, "%U", format_lisp_eid_vat,
3001 mp->eid_type,
3002 mp->eid,
3003 mp->eid_prefix_len,
3004 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
3005 vec_add1 (eid, 0);
3006
3007 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
3008 clib_net_to_host_u32 (mp->vni),
3009 eid,
3010 mp->is_local ? "local" : "remote",
3011 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
3012 clib_net_to_host_u16 (mp->key_id), mp->key);
3013
3014 vec_free (s);
3015 vec_free (eid);
3016}
3017
3018static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003019vl_api_one_eid_table_details_t_handler_json (vl_api_one_eid_table_details_t
3020 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003021{
3022 vat_main_t *vam = &vat_main;
3023 vat_json_node_t *node = 0;
3024 u8 *eid = 0;
3025
3026 if (VAT_JSON_ARRAY != vam->json_tree.type)
3027 {
3028 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3029 vat_json_init_array (&vam->json_tree);
3030 }
3031 node = vat_json_array_add (&vam->json_tree);
3032
3033 vat_json_init_object (node);
3034 if (~0 == mp->locator_set_index)
3035 vat_json_object_add_uint (node, "action", mp->action);
3036 else
3037 vat_json_object_add_uint (node, "locator_set_index",
3038 clib_net_to_host_u32 (mp->locator_set_index));
3039
3040 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003041 if (mp->eid_type == 3)
3042 {
3043 vat_json_node_t *nsh_json = vat_json_object_add (node, "eid");
3044 vat_json_init_object (nsh_json);
3045 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) mp->eid;
3046 vat_json_object_add_uint (nsh_json, "spi",
3047 clib_net_to_host_u32 (nsh->spi));
3048 vat_json_object_add_uint (nsh_json, "si", nsh->si);
3049 }
3050 else
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 vat_json_object_add_string_copy (node, "eid", eid);
3059 vec_free (eid);
3060 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003061 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3062 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
3063 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
3064
3065 if (mp->key_id)
3066 {
3067 vat_json_object_add_uint (node, "key_id",
3068 clib_net_to_host_u16 (mp->key_id));
3069 vat_json_object_add_string_copy (node, "key", mp->key);
3070 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003071}
3072
3073static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003074vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
3075{
3076 vat_main_t *vam = &vat_main;
3077 u8 *seid = 0, *deid = 0;
3078 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3079
3080 deid = format (0, "%U", format_lisp_eid_vat,
3081 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3082
3083 seid = format (0, "%U", format_lisp_eid_vat,
3084 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3085
3086 vec_add1 (deid, 0);
3087 vec_add1 (seid, 0);
3088
3089 if (mp->is_ip4)
3090 format_ip_address_fcn = format_ip4_address;
3091 else
3092 format_ip_address_fcn = format_ip6_address;
3093
3094
3095 print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
3096 clib_net_to_host_u32 (mp->vni),
3097 seid, deid,
3098 format_ip_address_fcn, mp->lloc,
3099 format_ip_address_fcn, mp->rloc,
3100 clib_net_to_host_u32 (mp->pkt_count),
3101 clib_net_to_host_u32 (mp->bytes));
3102
3103 vec_free (deid);
3104 vec_free (seid);
3105}
3106
3107static void
3108vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp)
3109{
3110 struct in6_addr ip6;
3111 struct in_addr ip4;
3112 vat_main_t *vam = &vat_main;
3113 vat_json_node_t *node = 0;
3114 u8 *deid = 0, *seid = 0;
3115
3116 if (VAT_JSON_ARRAY != vam->json_tree.type)
3117 {
3118 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3119 vat_json_init_array (&vam->json_tree);
3120 }
3121 node = vat_json_array_add (&vam->json_tree);
3122
3123 vat_json_init_object (node);
3124 deid = format (0, "%U", format_lisp_eid_vat,
3125 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3126
3127 seid = format (0, "%U", format_lisp_eid_vat,
3128 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3129
3130 vec_add1 (deid, 0);
3131 vec_add1 (seid, 0);
3132
3133 vat_json_object_add_string_copy (node, "seid", seid);
3134 vat_json_object_add_string_copy (node, "deid", deid);
3135 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3136
3137 if (mp->is_ip4)
3138 {
3139 clib_memcpy (&ip4, mp->lloc, sizeof (ip4));
3140 vat_json_object_add_ip4 (node, "lloc", ip4);
3141 clib_memcpy (&ip4, mp->rloc, sizeof (ip4));
3142 vat_json_object_add_ip4 (node, "rloc", ip4);
3143 }
3144 else
3145 {
3146 clib_memcpy (&ip6, mp->lloc, sizeof (ip6));
3147 vat_json_object_add_ip6 (node, "lloc", ip6);
3148 clib_memcpy (&ip6, mp->rloc, sizeof (ip6));
3149 vat_json_object_add_ip6 (node, "rloc", ip6);
3150 }
3151 vat_json_object_add_uint (node, "pkt_count",
3152 clib_net_to_host_u32 (mp->pkt_count));
3153 vat_json_object_add_uint (node, "bytes", clib_net_to_host_u32 (mp->bytes));
3154
3155 vec_free (deid);
3156 vec_free (seid);
3157}
3158
3159static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003160 vl_api_one_eid_table_map_details_t_handler
3161 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003162{
3163 vat_main_t *vam = &vat_main;
3164
3165 u8 *line = format (0, "%=10d%=10d",
3166 clib_net_to_host_u32 (mp->vni),
3167 clib_net_to_host_u32 (mp->dp_table));
3168 print (vam->ofp, "%v", line);
3169 vec_free (line);
3170}
3171
3172static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003173 vl_api_one_eid_table_map_details_t_handler_json
3174 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003175{
3176 vat_main_t *vam = &vat_main;
3177 vat_json_node_t *node = NULL;
3178
3179 if (VAT_JSON_ARRAY != vam->json_tree.type)
3180 {
3181 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3182 vat_json_init_array (&vam->json_tree);
3183 }
3184 node = vat_json_array_add (&vam->json_tree);
3185 vat_json_init_object (node);
3186 vat_json_object_add_uint (node, "dp_table",
3187 clib_net_to_host_u32 (mp->dp_table));
3188 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3189}
3190
3191static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003192 vl_api_one_eid_table_vni_details_t_handler
3193 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003194{
3195 vat_main_t *vam = &vat_main;
3196
3197 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
3198 print (vam->ofp, "%v", line);
3199 vec_free (line);
3200}
3201
3202static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003203 vl_api_one_eid_table_vni_details_t_handler_json
3204 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003205{
3206 vat_main_t *vam = &vat_main;
3207 vat_json_node_t *node = NULL;
3208
3209 if (VAT_JSON_ARRAY != vam->json_tree.type)
3210 {
3211 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3212 vat_json_init_array (&vam->json_tree);
3213 }
3214 node = vat_json_array_add (&vam->json_tree);
3215 vat_json_init_object (node);
3216 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3217}
3218
Damjan Marion7cd468a2016-12-19 23:05:39 +01003219static void
Filip Tehlar7048ff12017-07-27 08:09:14 +02003220 vl_api_show_one_map_register_fallback_threshold_reply_t_handler
3221 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3222{
3223 vat_main_t *vam = &vat_main;
3224 int retval = clib_net_to_host_u32 (mp->retval);
3225
3226 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3227 print (vam->ofp, "fallback threshold value: %d", mp->value);
3228
3229 vam->retval = retval;
3230 vam->result_ready = 1;
3231}
3232
3233static void
3234 vl_api_show_one_map_register_fallback_threshold_reply_t_handler_json
3235 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3236{
3237 vat_main_t *vam = &vat_main;
3238 vat_json_node_t _node, *node = &_node;
3239 int retval = clib_net_to_host_u32 (mp->retval);
3240
3241 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3242 vat_json_init_object (node);
3243 vat_json_object_add_uint (node, "value", mp->value);
3244
3245 vat_json_print (vam->ofp, node);
3246 vat_json_free (node);
3247
3248 vam->retval = retval;
3249 vam->result_ready = 1;
3250}
3251
3252static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003253 vl_api_show_one_map_register_state_reply_t_handler
3254 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003255{
3256 vat_main_t *vam = &vat_main;
3257 int retval = clib_net_to_host_u32 (mp->retval);
3258
3259 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3260
3261 vam->retval = retval;
3262 vam->result_ready = 1;
3263}
3264
3265static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003266 vl_api_show_one_map_register_state_reply_t_handler_json
3267 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003268{
3269 vat_main_t *vam = &vat_main;
3270 vat_json_node_t _node, *node = &_node;
3271 int retval = clib_net_to_host_u32 (mp->retval);
3272
3273 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3274
3275 vat_json_init_object (node);
3276 vat_json_object_add_string_copy (node, "state", s);
3277
3278 vat_json_print (vam->ofp, node);
3279 vat_json_free (node);
3280
3281 vam->retval = retval;
3282 vam->result_ready = 1;
3283 vec_free (s);
3284}
3285
3286static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003287 vl_api_show_one_rloc_probe_state_reply_t_handler
3288 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003289{
3290 vat_main_t *vam = &vat_main;
3291 int retval = clib_net_to_host_u32 (mp->retval);
3292
3293 if (retval)
3294 goto end;
3295
3296 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3297end:
3298 vam->retval = retval;
3299 vam->result_ready = 1;
3300}
3301
3302static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003303 vl_api_show_one_rloc_probe_state_reply_t_handler_json
3304 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003305{
3306 vat_main_t *vam = &vat_main;
3307 vat_json_node_t _node, *node = &_node;
3308 int retval = clib_net_to_host_u32 (mp->retval);
3309
3310 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3311 vat_json_init_object (node);
3312 vat_json_object_add_string_copy (node, "state", s);
3313
3314 vat_json_print (vam->ofp, node);
3315 vat_json_free (node);
3316
3317 vam->retval = retval;
3318 vam->result_ready = 1;
3319 vec_free (s);
3320}
3321
3322static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003323 vl_api_show_one_stats_enable_disable_reply_t_handler
3324 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3325{
3326 vat_main_t *vam = &vat_main;
3327 int retval = clib_net_to_host_u32 (mp->retval);
3328
3329 if (retval)
3330 goto end;
3331
3332 print (vam->ofp, "%s", mp->is_en ? "enabled" : "disabled");
3333end:
3334 vam->retval = retval;
3335 vam->result_ready = 1;
3336}
3337
3338static void
3339 vl_api_show_one_stats_enable_disable_reply_t_handler_json
3340 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3341{
3342 vat_main_t *vam = &vat_main;
3343 vat_json_node_t _node, *node = &_node;
3344 int retval = clib_net_to_host_u32 (mp->retval);
3345
3346 u8 *s = format (0, "%s", mp->is_en ? "enabled" : "disabled");
3347 vat_json_init_object (node);
3348 vat_json_object_add_string_copy (node, "state", s);
3349
3350 vat_json_print (vam->ofp, node);
3351 vat_json_free (node);
3352
3353 vam->retval = retval;
3354 vam->result_ready = 1;
3355 vec_free (s);
3356}
3357
3358static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003359api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003360{
3361 e->dp_table = clib_net_to_host_u32 (e->dp_table);
3362 e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003363 e->vni = clib_net_to_host_u32 (e->vni);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003364}
3365
3366static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003367 gpe_fwd_entries_get_reply_t_net_to_host
3368 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003369{
3370 u32 i;
3371
3372 mp->count = clib_net_to_host_u32 (mp->count);
3373 for (i = 0; i < mp->count; i++)
3374 {
Filip Tehlar82786c42017-02-20 15:20:37 +01003375 api_gpe_fwd_entry_net_to_host (&mp->entries[i]);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003376 }
3377}
3378
Filip Tehlar3e7b56932017-02-21 18:28:34 +01003379static u8 *
3380format_gpe_encap_mode (u8 * s, va_list * args)
3381{
3382 u32 mode = va_arg (*args, u32);
3383
3384 switch (mode)
3385 {
3386 case 0:
3387 return format (s, "lisp");
3388 case 1:
3389 return format (s, "vxlan");
3390 }
3391 return 0;
3392}
3393
3394static void
3395 vl_api_gpe_get_encap_mode_reply_t_handler
3396 (vl_api_gpe_get_encap_mode_reply_t * mp)
3397{
3398 vat_main_t *vam = &vat_main;
3399
3400 print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode);
3401 vam->retval = ntohl (mp->retval);
3402 vam->result_ready = 1;
3403}
3404
3405static void
3406 vl_api_gpe_get_encap_mode_reply_t_handler_json
3407 (vl_api_gpe_get_encap_mode_reply_t * mp)
3408{
3409 vat_main_t *vam = &vat_main;
3410 vat_json_node_t node;
3411
3412 u8 *encap_mode = format (0, "%U", format_gpe_encap_mode, mp->encap_mode);
3413 vec_add1 (encap_mode, 0);
3414
3415 vat_json_init_object (&node);
3416 vat_json_object_add_string_copy (&node, "gpe_mode", encap_mode);
3417
3418 vec_free (encap_mode);
3419 vat_json_print (vam->ofp, &node);
3420 vat_json_free (&node);
3421
3422 vam->retval = ntohl (mp->retval);
3423 vam->result_ready = 1;
3424}
3425
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003426static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003427 vl_api_gpe_fwd_entry_path_details_t_handler
3428 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003429{
3430 vat_main_t *vam = &vat_main;
3431 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3432
3433 if (mp->lcl_loc.is_ip4)
3434 format_ip_address_fcn = format_ip4_address;
3435 else
3436 format_ip_address_fcn = format_ip6_address;
3437
3438 print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight,
3439 format_ip_address_fcn, &mp->lcl_loc,
3440 format_ip_address_fcn, &mp->rmt_loc);
3441}
3442
3443static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003444lisp_fill_locator_node (vat_json_node_t * n, vl_api_gpe_locator_t * loc)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003445{
3446 struct in6_addr ip6;
3447 struct in_addr ip4;
3448
3449 if (loc->is_ip4)
3450 {
3451 clib_memcpy (&ip4, loc->addr, sizeof (ip4));
3452 vat_json_object_add_ip4 (n, "address", ip4);
3453 }
3454 else
3455 {
3456 clib_memcpy (&ip6, loc->addr, sizeof (ip6));
3457 vat_json_object_add_ip6 (n, "address", ip6);
3458 }
3459 vat_json_object_add_uint (n, "weight", loc->weight);
3460}
3461
3462static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003463 vl_api_gpe_fwd_entry_path_details_t_handler_json
3464 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003465{
3466 vat_main_t *vam = &vat_main;
3467 vat_json_node_t *node = NULL;
3468 vat_json_node_t *loc_node;
3469
3470 if (VAT_JSON_ARRAY != vam->json_tree.type)
3471 {
3472 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3473 vat_json_init_array (&vam->json_tree);
3474 }
3475 node = vat_json_array_add (&vam->json_tree);
3476 vat_json_init_object (node);
3477
3478 loc_node = vat_json_object_add (node, "local_locator");
3479 vat_json_init_object (loc_node);
3480 lisp_fill_locator_node (loc_node, &mp->lcl_loc);
3481
3482 loc_node = vat_json_object_add (node, "remote_locator");
3483 vat_json_init_object (loc_node);
3484 lisp_fill_locator_node (loc_node, &mp->rmt_loc);
3485}
3486
3487static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003488 vl_api_gpe_fwd_entries_get_reply_t_handler
3489 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003490{
3491 vat_main_t *vam = &vat_main;
3492 u32 i;
3493 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003494 vl_api_gpe_fwd_entry_t *e;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003495
3496 if (retval)
3497 goto end;
3498
Filip Tehlar82786c42017-02-20 15:20:37 +01003499 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003500
3501 for (i = 0; i < mp->count; i++)
3502 {
3503 e = &mp->entries[i];
3504 print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table,
3505 format_lisp_flat_eid, e->eid_type, e->leid, e->leid_prefix_len,
3506 format_lisp_flat_eid, e->eid_type, e->reid, e->reid_prefix_len);
3507 }
3508
3509end:
3510 vam->retval = retval;
3511 vam->result_ready = 1;
3512}
3513
3514static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003515 vl_api_gpe_fwd_entries_get_reply_t_handler_json
3516 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003517{
3518 u8 *s = 0;
3519 vat_main_t *vam = &vat_main;
3520 vat_json_node_t *e = 0, root;
3521 u32 i;
3522 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003523 vl_api_gpe_fwd_entry_t *fwd;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003524
3525 if (retval)
3526 goto end;
3527
Filip Tehlar82786c42017-02-20 15:20:37 +01003528 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003529 vat_json_init_array (&root);
3530
3531 for (i = 0; i < mp->count; i++)
3532 {
3533 e = vat_json_array_add (&root);
3534 fwd = &mp->entries[i];
3535
3536 vat_json_init_object (e);
3537 vat_json_object_add_int (e, "fwd_entry_index", fwd->fwd_entry_index);
3538 vat_json_object_add_int (e, "dp_table", fwd->dp_table);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003539 vat_json_object_add_int (e, "vni", fwd->vni);
3540 vat_json_object_add_int (e, "action", fwd->action);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003541
3542 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->leid,
3543 fwd->leid_prefix_len);
3544 vec_add1 (s, 0);
3545 vat_json_object_add_string_copy (e, "leid", s);
3546 vec_free (s);
3547
3548 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->reid,
3549 fwd->reid_prefix_len);
3550 vec_add1 (s, 0);
3551 vat_json_object_add_string_copy (e, "reid", s);
3552 vec_free (s);
3553 }
3554
3555 vat_json_print (vam->ofp, &root);
3556 vat_json_free (&root);
3557
3558end:
3559 vam->retval = retval;
3560 vam->result_ready = 1;
3561}
3562
3563static void
Filip Tehlarb4243aa2017-06-14 14:39:42 +02003564 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler
3565 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3566{
3567 vat_main_t *vam = &vat_main;
3568 u32 i, n;
3569 int retval = clib_net_to_host_u32 (mp->retval);
3570 vl_api_gpe_native_fwd_rpath_t *r;
3571
3572 if (retval)
3573 goto end;
3574
3575 n = clib_net_to_host_u32 (mp->count);
3576
3577 for (i = 0; i < n; i++)
3578 {
3579 r = &mp->entries[i];
3580 print (vam->ofp, "fib_index: %d sw_if_index %d nh %U",
3581 clib_net_to_host_u32 (r->fib_index),
3582 clib_net_to_host_u32 (r->nh_sw_if_index),
3583 r->is_ip4 ? format_ip4_address : format_ip6_address, r->nh_addr);
3584 }
3585
3586end:
3587 vam->retval = retval;
3588 vam->result_ready = 1;
3589}
3590
3591static void
3592 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler_json
3593 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3594{
3595 vat_main_t *vam = &vat_main;
3596 vat_json_node_t root, *e;
3597 u32 i, n;
3598 int retval = clib_net_to_host_u32 (mp->retval);
3599 vl_api_gpe_native_fwd_rpath_t *r;
3600 u8 *s;
3601
3602 if (retval)
3603 goto end;
3604
3605 n = clib_net_to_host_u32 (mp->count);
3606 vat_json_init_array (&root);
3607
3608 for (i = 0; i < n; i++)
3609 {
3610 e = vat_json_array_add (&root);
3611 vat_json_init_object (e);
3612 r = &mp->entries[i];
3613 s =
3614 format (0, "%U", r->is_ip4 ? format_ip4_address : format_ip6_address,
3615 r->nh_addr);
3616 vec_add1 (s, 0);
3617 vat_json_object_add_string_copy (e, "ip4", s);
3618 vec_free (s);
3619
3620 vat_json_object_add_uint (e, "fib_index",
3621 clib_net_to_host_u32 (r->fib_index));
3622 vat_json_object_add_uint (e, "nh_sw_if_index",
3623 clib_net_to_host_u32 (r->nh_sw_if_index));
3624 }
3625
3626 vat_json_print (vam->ofp, &root);
3627 vat_json_free (&root);
3628
3629end:
3630 vam->retval = retval;
3631 vam->result_ready = 1;
3632}
3633
3634static void
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003635 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler
3636 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3637{
3638 vat_main_t *vam = &vat_main;
3639 u32 i, n;
3640 int retval = clib_net_to_host_u32 (mp->retval);
3641
3642 if (retval)
3643 goto end;
3644
3645 n = clib_net_to_host_u32 (mp->count);
3646
3647 for (i = 0; i < n; i++)
3648 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i]));
3649
3650end:
3651 vam->retval = retval;
3652 vam->result_ready = 1;
3653}
3654
3655static void
3656 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler_json
3657 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3658{
3659 vat_main_t *vam = &vat_main;
3660 vat_json_node_t root;
3661 u32 i, n;
3662 int retval = clib_net_to_host_u32 (mp->retval);
3663
3664 if (retval)
3665 goto end;
3666
3667 n = clib_net_to_host_u32 (mp->count);
3668 vat_json_init_array (&root);
3669
3670 for (i = 0; i < n; i++)
3671 vat_json_array_add_uint (&root, clib_net_to_host_u32 (mp->vnis[i]));
3672
3673 vat_json_print (vam->ofp, &root);
3674 vat_json_free (&root);
3675
3676end:
3677 vam->retval = retval;
3678 vam->result_ready = 1;
3679}
3680
3681static void
Filip Tehlar05879992017-09-05 15:46:09 +02003682 vl_api_one_ndp_entries_get_reply_t_handler
3683 (vl_api_one_ndp_entries_get_reply_t * mp)
3684{
3685 vat_main_t *vam = &vat_main;
3686 u32 i, n;
3687 int retval = clib_net_to_host_u32 (mp->retval);
3688
3689 if (retval)
3690 goto end;
3691
3692 n = clib_net_to_host_u32 (mp->count);
3693
3694 for (i = 0; i < n; i++)
3695 print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
3696 format_ethernet_address, mp->entries[i].mac);
3697
3698end:
3699 vam->retval = retval;
3700 vam->result_ready = 1;
3701}
3702
3703static void
3704 vl_api_one_ndp_entries_get_reply_t_handler_json
3705 (vl_api_one_ndp_entries_get_reply_t * mp)
3706{
3707 u8 *s = 0;
3708 vat_main_t *vam = &vat_main;
3709 vat_json_node_t *e = 0, root;
3710 u32 i, n;
3711 int retval = clib_net_to_host_u32 (mp->retval);
3712 vl_api_one_ndp_entry_t *arp_entry;
3713
3714 if (retval)
3715 goto end;
3716
3717 n = clib_net_to_host_u32 (mp->count);
3718 vat_json_init_array (&root);
3719
3720 for (i = 0; i < n; i++)
3721 {
3722 e = vat_json_array_add (&root);
3723 arp_entry = &mp->entries[i];
3724
3725 vat_json_init_object (e);
3726 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3727 vec_add1 (s, 0);
3728
3729 vat_json_object_add_string_copy (e, "mac", s);
3730 vec_free (s);
3731
3732 s = format (0, "%U", format_ip6_address, &arp_entry->ip6);
3733 vec_add1 (s, 0);
3734 vat_json_object_add_string_copy (e, "ip6", s);
3735 vec_free (s);
3736 }
3737
3738 vat_json_print (vam->ofp, &root);
3739 vat_json_free (&root);
3740
3741end:
3742 vam->retval = retval;
3743 vam->result_ready = 1;
3744}
3745
3746static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003747 vl_api_one_l2_arp_entries_get_reply_t_handler
3748 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3749{
3750 vat_main_t *vam = &vat_main;
3751 u32 i, n;
3752 int retval = clib_net_to_host_u32 (mp->retval);
3753
3754 if (retval)
3755 goto end;
3756
3757 n = clib_net_to_host_u32 (mp->count);
3758
3759 for (i = 0; i < n; i++)
3760 print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
3761 format_ethernet_address, mp->entries[i].mac);
3762
3763end:
3764 vam->retval = retval;
3765 vam->result_ready = 1;
3766}
3767
3768static void
3769 vl_api_one_l2_arp_entries_get_reply_t_handler_json
3770 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3771{
3772 u8 *s = 0;
3773 vat_main_t *vam = &vat_main;
3774 vat_json_node_t *e = 0, root;
3775 u32 i, n;
3776 int retval = clib_net_to_host_u32 (mp->retval);
3777 vl_api_one_l2_arp_entry_t *arp_entry;
3778
3779 if (retval)
3780 goto end;
3781
3782 n = clib_net_to_host_u32 (mp->count);
3783 vat_json_init_array (&root);
3784
3785 for (i = 0; i < n; i++)
3786 {
3787 e = vat_json_array_add (&root);
3788 arp_entry = &mp->entries[i];
3789
3790 vat_json_init_object (e);
3791 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3792 vec_add1 (s, 0);
3793
3794 vat_json_object_add_string_copy (e, "mac", s);
3795 vec_free (s);
3796
3797 s = format (0, "%U", format_ip4_address, &arp_entry->ip4);
3798 vec_add1 (s, 0);
3799 vat_json_object_add_string_copy (e, "ip4", s);
3800 vec_free (s);
3801 }
3802
3803 vat_json_print (vam->ofp, &root);
3804 vat_json_free (&root);
3805
3806end:
3807 vam->retval = retval;
3808 vam->result_ready = 1;
3809}
3810
3811static void
Filip Tehlar05879992017-09-05 15:46:09 +02003812vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
3813{
3814 vat_main_t *vam = &vat_main;
3815 u32 i, n;
3816 int retval = clib_net_to_host_u32 (mp->retval);
3817
3818 if (retval)
3819 goto end;
3820
3821 n = clib_net_to_host_u32 (mp->count);
3822
3823 for (i = 0; i < n; i++)
3824 {
3825 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3826 }
3827
3828end:
3829 vam->retval = retval;
3830 vam->result_ready = 1;
3831}
3832
3833static void
3834 vl_api_one_ndp_bd_get_reply_t_handler_json
3835 (vl_api_one_ndp_bd_get_reply_t * mp)
3836{
3837 vat_main_t *vam = &vat_main;
3838 vat_json_node_t root;
3839 u32 i, n;
3840 int retval = clib_net_to_host_u32 (mp->retval);
3841
3842 if (retval)
3843 goto end;
3844
3845 n = clib_net_to_host_u32 (mp->count);
3846 vat_json_init_array (&root);
3847
3848 for (i = 0; i < n; i++)
3849 {
3850 vat_json_array_add_uint (&root,
3851 clib_net_to_host_u32 (mp->bridge_domains[i]));
3852 }
3853
3854 vat_json_print (vam->ofp, &root);
3855 vat_json_free (&root);
3856
3857end:
3858 vam->retval = retval;
3859 vam->result_ready = 1;
3860}
3861
3862static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003863 vl_api_one_l2_arp_bd_get_reply_t_handler
3864 (vl_api_one_l2_arp_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_l2_arp_bd_get_reply_t_handler_json
3887 (vl_api_one_l2_arp_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 Tehlar694396d2017-02-17 14:29:11 +01003915 vl_api_one_adjacencies_get_reply_t_handler
3916 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003917{
3918 vat_main_t *vam = &vat_main;
3919 u32 i, n;
3920 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003921 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003922
3923 if (retval)
3924 goto end;
3925
3926 n = clib_net_to_host_u32 (mp->count);
3927
3928 for (i = 0; i < n; i++)
3929 {
3930 a = &mp->adjacencies[i];
3931 print (vam->ofp, "%U %40U",
3932 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
3933 format_lisp_flat_eid, a->eid_type, a->reid, a->reid_prefix_len);
3934 }
3935
3936end:
3937 vam->retval = retval;
3938 vam->result_ready = 1;
3939}
3940
3941static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003942 vl_api_one_adjacencies_get_reply_t_handler_json
3943 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003944{
3945 u8 *s = 0;
3946 vat_main_t *vam = &vat_main;
3947 vat_json_node_t *e = 0, root;
3948 u32 i, n;
3949 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003950 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003951
3952 if (retval)
3953 goto end;
3954
3955 n = clib_net_to_host_u32 (mp->count);
3956 vat_json_init_array (&root);
3957
3958 for (i = 0; i < n; i++)
3959 {
3960 e = vat_json_array_add (&root);
3961 a = &mp->adjacencies[i];
3962
3963 vat_json_init_object (e);
3964 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
3965 a->leid_prefix_len);
3966 vec_add1 (s, 0);
3967 vat_json_object_add_string_copy (e, "leid", s);
3968 vec_free (s);
3969
3970 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
3971 a->reid_prefix_len);
3972 vec_add1 (s, 0);
3973 vat_json_object_add_string_copy (e, "reid", s);
3974 vec_free (s);
3975 }
3976
3977 vat_json_print (vam->ofp, &root);
3978 vat_json_free (&root);
3979
3980end:
3981 vam->retval = retval;
3982 vam->result_ready = 1;
3983}
3984
3985static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003986vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003987{
3988 vat_main_t *vam = &vat_main;
3989
3990 print (vam->ofp, "%=20U",
3991 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
3992 mp->ip_address);
3993}
3994
3995static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003996 vl_api_one_map_server_details_t_handler_json
3997 (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003998{
3999 vat_main_t *vam = &vat_main;
4000 vat_json_node_t *node = NULL;
4001 struct in6_addr ip6;
4002 struct in_addr ip4;
4003
4004 if (VAT_JSON_ARRAY != vam->json_tree.type)
4005 {
4006 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4007 vat_json_init_array (&vam->json_tree);
4008 }
4009 node = vat_json_array_add (&vam->json_tree);
4010
4011 vat_json_init_object (node);
4012 if (mp->is_ipv6)
4013 {
4014 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
4015 vat_json_object_add_ip6 (node, "map-server", ip6);
4016 }
4017 else
4018 {
4019 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
4020 vat_json_object_add_ip4 (node, "map-server", ip4);
4021 }
4022}
4023
4024static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004025vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
4026 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004027{
4028 vat_main_t *vam = &vat_main;
4029
4030 print (vam->ofp, "%=20U",
4031 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
4032 mp->ip_address);
4033}
4034
4035static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004036 vl_api_one_map_resolver_details_t_handler_json
4037 (vl_api_one_map_resolver_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004038{
4039 vat_main_t *vam = &vat_main;
4040 vat_json_node_t *node = NULL;
4041 struct in6_addr ip6;
4042 struct in_addr ip4;
4043
4044 if (VAT_JSON_ARRAY != vam->json_tree.type)
4045 {
4046 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4047 vat_json_init_array (&vam->json_tree);
4048 }
4049 node = vat_json_array_add (&vam->json_tree);
4050
4051 vat_json_init_object (node);
4052 if (mp->is_ipv6)
4053 {
4054 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
4055 vat_json_object_add_ip6 (node, "map resolver", ip6);
4056 }
4057 else
4058 {
4059 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
4060 vat_json_object_add_ip4 (node, "map resolver", ip4);
4061 }
4062}
4063
4064static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004065vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004066{
4067 vat_main_t *vam = &vat_main;
4068 i32 retval = ntohl (mp->retval);
4069
4070 if (0 <= retval)
4071 {
4072 print (vam->ofp, "feature: %s\ngpe: %s",
4073 mp->feature_status ? "enabled" : "disabled",
4074 mp->gpe_status ? "enabled" : "disabled");
4075 }
4076
4077 vam->retval = retval;
4078 vam->result_ready = 1;
4079}
4080
4081static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004082 vl_api_show_one_status_reply_t_handler_json
4083 (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004084{
4085 vat_main_t *vam = &vat_main;
4086 vat_json_node_t node;
4087 u8 *gpe_status = NULL;
4088 u8 *feature_status = NULL;
4089
4090 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
4091 feature_status = format (0, "%s",
4092 mp->feature_status ? "enabled" : "disabled");
4093 vec_add1 (gpe_status, 0);
4094 vec_add1 (feature_status, 0);
4095
4096 vat_json_init_object (&node);
4097 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
4098 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
4099
4100 vec_free (gpe_status);
4101 vec_free (feature_status);
4102
4103 vat_json_print (vam->ofp, &node);
4104 vat_json_free (&node);
4105
4106 vam->retval = ntohl (mp->retval);
4107 vam->result_ready = 1;
4108}
4109
4110static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004111 vl_api_one_get_map_request_itr_rlocs_reply_t_handler
4112 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004113{
4114 vat_main_t *vam = &vat_main;
4115 i32 retval = ntohl (mp->retval);
4116
4117 if (retval >= 0)
4118 {
4119 print (vam->ofp, "%=20s", mp->locator_set_name);
4120 }
4121
4122 vam->retval = retval;
4123 vam->result_ready = 1;
4124}
4125
4126static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004127 vl_api_one_get_map_request_itr_rlocs_reply_t_handler_json
4128 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004129{
4130 vat_main_t *vam = &vat_main;
4131 vat_json_node_t *node = NULL;
4132
4133 if (VAT_JSON_ARRAY != vam->json_tree.type)
4134 {
4135 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4136 vat_json_init_array (&vam->json_tree);
4137 }
4138 node = vat_json_array_add (&vam->json_tree);
4139
4140 vat_json_init_object (node);
4141 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
4142
4143 vat_json_print (vam->ofp, node);
4144 vat_json_free (node);
4145
4146 vam->retval = ntohl (mp->retval);
4147 vam->result_ready = 1;
4148}
4149
4150static u8 *
4151format_lisp_map_request_mode (u8 * s, va_list * args)
4152{
4153 u32 mode = va_arg (*args, u32);
4154
4155 switch (mode)
4156 {
4157 case 0:
4158 return format (0, "dst-only");
4159 case 1:
4160 return format (0, "src-dst");
4161 }
4162 return 0;
4163}
4164
4165static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004166 vl_api_show_one_map_request_mode_reply_t_handler
4167 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004168{
4169 vat_main_t *vam = &vat_main;
4170 i32 retval = ntohl (mp->retval);
4171
4172 if (0 <= retval)
4173 {
4174 u32 mode = mp->mode;
4175 print (vam->ofp, "map_request_mode: %U",
4176 format_lisp_map_request_mode, mode);
4177 }
4178
4179 vam->retval = retval;
4180 vam->result_ready = 1;
4181}
4182
4183static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004184 vl_api_show_one_map_request_mode_reply_t_handler_json
4185 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004186{
4187 vat_main_t *vam = &vat_main;
4188 vat_json_node_t node;
4189 u8 *s = 0;
4190 u32 mode;
4191
4192 mode = mp->mode;
4193 s = format (0, "%U", format_lisp_map_request_mode, mode);
4194 vec_add1 (s, 0);
4195
4196 vat_json_init_object (&node);
4197 vat_json_object_add_string_copy (&node, "map_request_mode", s);
4198 vat_json_print (vam->ofp, &node);
4199 vat_json_free (&node);
4200
4201 vec_free (s);
4202 vam->retval = ntohl (mp->retval);
4203 vam->result_ready = 1;
4204}
4205
4206static void
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004207 vl_api_one_show_xtr_mode_reply_t_handler
4208 (vl_api_one_show_xtr_mode_reply_t * mp)
4209{
4210 vat_main_t *vam = &vat_main;
4211 i32 retval = ntohl (mp->retval);
4212
4213 if (0 <= retval)
4214 {
4215 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4216 }
4217
4218 vam->retval = retval;
4219 vam->result_ready = 1;
4220}
4221
4222static void
4223 vl_api_one_show_xtr_mode_reply_t_handler_json
4224 (vl_api_one_show_xtr_mode_reply_t * mp)
4225{
4226 vat_main_t *vam = &vat_main;
4227 vat_json_node_t node;
4228 u8 *status = 0;
4229
4230 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4231 vec_add1 (status, 0);
4232
4233 vat_json_init_object (&node);
4234 vat_json_object_add_string_copy (&node, "status", status);
4235
4236 vec_free (status);
4237
4238 vat_json_print (vam->ofp, &node);
4239 vat_json_free (&node);
4240
4241 vam->retval = ntohl (mp->retval);
4242 vam->result_ready = 1;
4243}
4244
4245static void
4246 vl_api_one_show_pitr_mode_reply_t_handler
4247 (vl_api_one_show_pitr_mode_reply_t * mp)
4248{
4249 vat_main_t *vam = &vat_main;
4250 i32 retval = ntohl (mp->retval);
4251
4252 if (0 <= retval)
4253 {
4254 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4255 }
4256
4257 vam->retval = retval;
4258 vam->result_ready = 1;
4259}
4260
4261static void
4262 vl_api_one_show_pitr_mode_reply_t_handler_json
4263 (vl_api_one_show_pitr_mode_reply_t * mp)
4264{
4265 vat_main_t *vam = &vat_main;
4266 vat_json_node_t node;
4267 u8 *status = 0;
4268
4269 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4270 vec_add1 (status, 0);
4271
4272 vat_json_init_object (&node);
4273 vat_json_object_add_string_copy (&node, "status", status);
4274
4275 vec_free (status);
4276
4277 vat_json_print (vam->ofp, &node);
4278 vat_json_free (&node);
4279
4280 vam->retval = ntohl (mp->retval);
4281 vam->result_ready = 1;
4282}
4283
4284static void
4285 vl_api_one_show_petr_mode_reply_t_handler
4286 (vl_api_one_show_petr_mode_reply_t * mp)
4287{
4288 vat_main_t *vam = &vat_main;
4289 i32 retval = ntohl (mp->retval);
4290
4291 if (0 <= retval)
4292 {
4293 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4294 }
4295
4296 vam->retval = retval;
4297 vam->result_ready = 1;
4298}
4299
4300static void
4301 vl_api_one_show_petr_mode_reply_t_handler_json
4302 (vl_api_one_show_petr_mode_reply_t * mp)
4303{
4304 vat_main_t *vam = &vat_main;
4305 vat_json_node_t node;
4306 u8 *status = 0;
4307
4308 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4309 vec_add1 (status, 0);
4310
4311 vat_json_init_object (&node);
4312 vat_json_object_add_string_copy (&node, "status", status);
4313
4314 vec_free (status);
4315
4316 vat_json_print (vam->ofp, &node);
4317 vat_json_free (&node);
4318
4319 vam->retval = ntohl (mp->retval);
4320 vam->result_ready = 1;
4321}
4322
4323static void
Filip Tehlar67a99f82017-03-10 13:18:02 +01004324 vl_api_show_one_use_petr_reply_t_handler
4325 (vl_api_show_one_use_petr_reply_t * mp)
4326{
4327 vat_main_t *vam = &vat_main;
4328 i32 retval = ntohl (mp->retval);
4329
4330 if (0 <= retval)
4331 {
4332 print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
4333 if (mp->status)
4334 {
4335 print (vam->ofp, "Proxy-ETR address; %U",
4336 mp->is_ip4 ? format_ip4_address : format_ip6_address,
4337 mp->address);
4338 }
4339 }
4340
4341 vam->retval = retval;
4342 vam->result_ready = 1;
4343}
4344
4345static void
4346 vl_api_show_one_use_petr_reply_t_handler_json
4347 (vl_api_show_one_use_petr_reply_t * mp)
4348{
4349 vat_main_t *vam = &vat_main;
4350 vat_json_node_t node;
4351 u8 *status = 0;
4352 struct in_addr ip4;
4353 struct in6_addr ip6;
4354
4355 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4356 vec_add1 (status, 0);
4357
4358 vat_json_init_object (&node);
4359 vat_json_object_add_string_copy (&node, "status", status);
4360 if (mp->status)
4361 {
4362 if (mp->is_ip4)
4363 {
4364 clib_memcpy (&ip6, mp->address, sizeof (ip6));
4365 vat_json_object_add_ip6 (&node, "address", ip6);
4366 }
4367 else
4368 {
4369 clib_memcpy (&ip4, mp->address, sizeof (ip4));
4370 vat_json_object_add_ip4 (&node, "address", ip4);
4371 }
4372 }
4373
4374 vec_free (status);
4375
4376 vat_json_print (vam->ofp, &node);
4377 vat_json_free (&node);
4378
4379 vam->retval = ntohl (mp->retval);
4380 vam->result_ready = 1;
4381}
4382
4383static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02004384 vl_api_show_one_nsh_mapping_reply_t_handler
4385 (vl_api_show_one_nsh_mapping_reply_t * mp)
4386{
4387 vat_main_t *vam = &vat_main;
4388 i32 retval = ntohl (mp->retval);
4389
4390 if (0 <= retval)
4391 {
4392 print (vam->ofp, "%-20s%-16s",
4393 mp->is_set ? "set" : "not-set",
4394 mp->is_set ? (char *) mp->locator_set_name : "");
4395 }
4396
4397 vam->retval = retval;
4398 vam->result_ready = 1;
4399}
4400
4401static void
4402 vl_api_show_one_nsh_mapping_reply_t_handler_json
4403 (vl_api_show_one_nsh_mapping_reply_t * mp)
4404{
4405 vat_main_t *vam = &vat_main;
4406 vat_json_node_t node;
4407 u8 *status = 0;
4408
4409 status = format (0, "%s", mp->is_set ? "yes" : "no");
4410 vec_add1 (status, 0);
4411
4412 vat_json_init_object (&node);
4413 vat_json_object_add_string_copy (&node, "is_set", status);
4414 if (mp->is_set)
4415 {
4416 vat_json_object_add_string_copy (&node, "locator_set",
4417 mp->locator_set_name);
4418 }
4419
4420 vec_free (status);
4421
4422 vat_json_print (vam->ofp, &node);
4423 vat_json_free (&node);
4424
4425 vam->retval = ntohl (mp->retval);
4426 vam->result_ready = 1;
4427}
4428
4429static void
Filip Tehlar1e553a02017-08-02 12:45:07 +02004430 vl_api_show_one_map_register_ttl_reply_t_handler
4431 (vl_api_show_one_map_register_ttl_reply_t * mp)
4432{
4433 vat_main_t *vam = &vat_main;
4434 i32 retval = ntohl (mp->retval);
4435
4436 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4437
4438 if (0 <= retval)
4439 {
4440 print (vam->ofp, "ttl: %u", mp->ttl);
4441 }
4442
4443 vam->retval = retval;
4444 vam->result_ready = 1;
4445}
4446
4447static void
4448 vl_api_show_one_map_register_ttl_reply_t_handler_json
4449 (vl_api_show_one_map_register_ttl_reply_t * mp)
4450{
4451 vat_main_t *vam = &vat_main;
4452 vat_json_node_t node;
4453
4454 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4455 vat_json_init_object (&node);
4456 vat_json_object_add_uint (&node, "ttl", mp->ttl);
4457
4458 vat_json_print (vam->ofp, &node);
4459 vat_json_free (&node);
4460
4461 vam->retval = ntohl (mp->retval);
4462 vam->result_ready = 1;
4463}
4464
4465static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004466vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004467{
4468 vat_main_t *vam = &vat_main;
4469 i32 retval = ntohl (mp->retval);
4470
4471 if (0 <= retval)
4472 {
4473 print (vam->ofp, "%-20s%-16s",
4474 mp->status ? "enabled" : "disabled",
4475 mp->status ? (char *) mp->locator_set_name : "");
4476 }
4477
4478 vam->retval = retval;
4479 vam->result_ready = 1;
4480}
4481
4482static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004483vl_api_show_one_pitr_reply_t_handler_json (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004484{
4485 vat_main_t *vam = &vat_main;
4486 vat_json_node_t node;
4487 u8 *status = 0;
4488
4489 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4490 vec_add1 (status, 0);
4491
4492 vat_json_init_object (&node);
4493 vat_json_object_add_string_copy (&node, "status", status);
4494 if (mp->status)
4495 {
4496 vat_json_object_add_string_copy (&node, "locator_set",
4497 mp->locator_set_name);
4498 }
4499
4500 vec_free (status);
4501
4502 vat_json_print (vam->ofp, &node);
4503 vat_json_free (&node);
4504
4505 vam->retval = ntohl (mp->retval);
4506 vam->result_ready = 1;
4507}
4508
4509static u8 *
4510format_policer_type (u8 * s, va_list * va)
4511{
4512 u32 i = va_arg (*va, u32);
4513
4514 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
4515 s = format (s, "1r2c");
4516 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
4517 s = format (s, "1r3c");
4518 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
4519 s = format (s, "2r3c-2698");
4520 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
4521 s = format (s, "2r3c-4115");
4522 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
4523 s = format (s, "2r3c-mef5cf1");
4524 else
4525 s = format (s, "ILLEGAL");
4526 return s;
4527}
4528
4529static u8 *
4530format_policer_rate_type (u8 * s, va_list * va)
4531{
4532 u32 i = va_arg (*va, u32);
4533
4534 if (i == SSE2_QOS_RATE_KBPS)
4535 s = format (s, "kbps");
4536 else if (i == SSE2_QOS_RATE_PPS)
4537 s = format (s, "pps");
4538 else
4539 s = format (s, "ILLEGAL");
4540 return s;
4541}
4542
4543static u8 *
4544format_policer_round_type (u8 * s, va_list * va)
4545{
4546 u32 i = va_arg (*va, u32);
4547
4548 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
4549 s = format (s, "closest");
4550 else if (i == SSE2_QOS_ROUND_TO_UP)
4551 s = format (s, "up");
4552 else if (i == SSE2_QOS_ROUND_TO_DOWN)
4553 s = format (s, "down");
4554 else
4555 s = format (s, "ILLEGAL");
4556 return s;
4557}
4558
4559static u8 *
4560format_policer_action_type (u8 * s, va_list * va)
4561{
4562 u32 i = va_arg (*va, u32);
4563
4564 if (i == SSE2_QOS_ACTION_DROP)
4565 s = format (s, "drop");
4566 else if (i == SSE2_QOS_ACTION_TRANSMIT)
4567 s = format (s, "transmit");
4568 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4569 s = format (s, "mark-and-transmit");
4570 else
4571 s = format (s, "ILLEGAL");
4572 return s;
4573}
4574
4575static u8 *
4576format_dscp (u8 * s, va_list * va)
4577{
4578 u32 i = va_arg (*va, u32);
4579 char *t = 0;
4580
4581 switch (i)
4582 {
4583#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
4584 foreach_vnet_dscp
4585#undef _
4586 default:
4587 return format (s, "ILLEGAL");
4588 }
4589 s = format (s, "%s", t);
4590 return s;
4591}
4592
4593static void
4594vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
4595{
4596 vat_main_t *vam = &vat_main;
4597 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
4598
4599 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4600 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4601 else
4602 conform_dscp_str = format (0, "");
4603
4604 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4605 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4606 else
4607 exceed_dscp_str = format (0, "");
4608
4609 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4610 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4611 else
4612 violate_dscp_str = format (0, "");
4613
4614 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
4615 "rate type %U, round type %U, %s rate, %s color-aware, "
4616 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
4617 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
4618 "conform action %U%s, exceed action %U%s, violate action %U%s",
4619 mp->name,
4620 format_policer_type, mp->type,
4621 ntohl (mp->cir),
4622 ntohl (mp->eir),
4623 clib_net_to_host_u64 (mp->cb),
4624 clib_net_to_host_u64 (mp->eb),
4625 format_policer_rate_type, mp->rate_type,
4626 format_policer_round_type, mp->round_type,
4627 mp->single_rate ? "single" : "dual",
4628 mp->color_aware ? "is" : "not",
4629 ntohl (mp->cir_tokens_per_period),
4630 ntohl (mp->pir_tokens_per_period),
4631 ntohl (mp->scale),
4632 ntohl (mp->current_limit),
4633 ntohl (mp->current_bucket),
4634 ntohl (mp->extended_limit),
4635 ntohl (mp->extended_bucket),
4636 clib_net_to_host_u64 (mp->last_update_time),
4637 format_policer_action_type, mp->conform_action_type,
4638 conform_dscp_str,
4639 format_policer_action_type, mp->exceed_action_type,
4640 exceed_dscp_str,
4641 format_policer_action_type, mp->violate_action_type,
4642 violate_dscp_str);
4643
4644 vec_free (conform_dscp_str);
4645 vec_free (exceed_dscp_str);
4646 vec_free (violate_dscp_str);
4647}
4648
4649static void vl_api_policer_details_t_handler_json
4650 (vl_api_policer_details_t * mp)
4651{
4652 vat_main_t *vam = &vat_main;
4653 vat_json_node_t *node;
4654 u8 *rate_type_str, *round_type_str, *type_str;
4655 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
4656
4657 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
4658 round_type_str =
4659 format (0, "%U", format_policer_round_type, mp->round_type);
4660 type_str = format (0, "%U", format_policer_type, mp->type);
4661 conform_action_str = format (0, "%U", format_policer_action_type,
4662 mp->conform_action_type);
4663 exceed_action_str = format (0, "%U", format_policer_action_type,
4664 mp->exceed_action_type);
4665 violate_action_str = format (0, "%U", format_policer_action_type,
4666 mp->violate_action_type);
4667
4668 if (VAT_JSON_ARRAY != vam->json_tree.type)
4669 {
4670 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4671 vat_json_init_array (&vam->json_tree);
4672 }
4673 node = vat_json_array_add (&vam->json_tree);
4674
4675 vat_json_init_object (node);
4676 vat_json_object_add_string_copy (node, "name", mp->name);
4677 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
4678 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
Marek Gradzki59ed4902017-03-21 11:51:54 +01004679 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
4680 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
Damjan Marion7cd468a2016-12-19 23:05:39 +01004681 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
4682 vat_json_object_add_string_copy (node, "round_type", round_type_str);
4683 vat_json_object_add_string_copy (node, "type", type_str);
4684 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
4685 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
4686 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
4687 vat_json_object_add_uint (node, "cir_tokens_per_period",
4688 ntohl (mp->cir_tokens_per_period));
4689 vat_json_object_add_uint (node, "eir_tokens_per_period",
4690 ntohl (mp->pir_tokens_per_period));
4691 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
4692 vat_json_object_add_uint (node, "current_bucket",
4693 ntohl (mp->current_bucket));
4694 vat_json_object_add_uint (node, "extended_limit",
4695 ntohl (mp->extended_limit));
4696 vat_json_object_add_uint (node, "extended_bucket",
4697 ntohl (mp->extended_bucket));
4698 vat_json_object_add_uint (node, "last_update_time",
4699 ntohl (mp->last_update_time));
4700 vat_json_object_add_string_copy (node, "conform_action",
4701 conform_action_str);
4702 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4703 {
4704 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4705 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
4706 vec_free (dscp_str);
4707 }
4708 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
4709 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4710 {
4711 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4712 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
4713 vec_free (dscp_str);
4714 }
4715 vat_json_object_add_string_copy (node, "violate_action",
4716 violate_action_str);
4717 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4718 {
4719 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4720 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
4721 vec_free (dscp_str);
4722 }
4723
4724 vec_free (rate_type_str);
4725 vec_free (round_type_str);
4726 vec_free (type_str);
4727 vec_free (conform_action_str);
4728 vec_free (exceed_action_str);
4729 vec_free (violate_action_str);
4730}
4731
4732static void
4733vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
4734 mp)
4735{
4736 vat_main_t *vam = &vat_main;
4737 int i, count = ntohl (mp->count);
4738
4739 if (count > 0)
4740 print (vam->ofp, "classify table ids (%d) : ", count);
4741 for (i = 0; i < count; i++)
4742 {
4743 print (vam->ofp, "%d", ntohl (mp->ids[i]));
4744 print (vam->ofp, (i < count - 1) ? "," : "");
4745 }
4746 vam->retval = ntohl (mp->retval);
4747 vam->result_ready = 1;
4748}
4749
4750static void
4751 vl_api_classify_table_ids_reply_t_handler_json
4752 (vl_api_classify_table_ids_reply_t * mp)
4753{
4754 vat_main_t *vam = &vat_main;
4755 int i, count = ntohl (mp->count);
4756
4757 if (count > 0)
4758 {
4759 vat_json_node_t node;
4760
4761 vat_json_init_object (&node);
4762 for (i = 0; i < count; i++)
4763 {
4764 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
4765 }
4766 vat_json_print (vam->ofp, &node);
4767 vat_json_free (&node);
4768 }
4769 vam->retval = ntohl (mp->retval);
4770 vam->result_ready = 1;
4771}
4772
4773static void
4774 vl_api_classify_table_by_interface_reply_t_handler
4775 (vl_api_classify_table_by_interface_reply_t * mp)
4776{
4777 vat_main_t *vam = &vat_main;
4778 u32 table_id;
4779
4780 table_id = ntohl (mp->l2_table_id);
4781 if (table_id != ~0)
4782 print (vam->ofp, "l2 table id : %d", table_id);
4783 else
4784 print (vam->ofp, "l2 table id : No input ACL tables configured");
4785 table_id = ntohl (mp->ip4_table_id);
4786 if (table_id != ~0)
4787 print (vam->ofp, "ip4 table id : %d", table_id);
4788 else
4789 print (vam->ofp, "ip4 table id : No input ACL tables configured");
4790 table_id = ntohl (mp->ip6_table_id);
4791 if (table_id != ~0)
4792 print (vam->ofp, "ip6 table id : %d", table_id);
4793 else
4794 print (vam->ofp, "ip6 table id : No input ACL tables configured");
4795 vam->retval = ntohl (mp->retval);
4796 vam->result_ready = 1;
4797}
4798
4799static void
4800 vl_api_classify_table_by_interface_reply_t_handler_json
4801 (vl_api_classify_table_by_interface_reply_t * mp)
4802{
4803 vat_main_t *vam = &vat_main;
4804 vat_json_node_t node;
4805
4806 vat_json_init_object (&node);
4807
4808 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
4809 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
4810 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
4811
4812 vat_json_print (vam->ofp, &node);
4813 vat_json_free (&node);
4814
4815 vam->retval = ntohl (mp->retval);
4816 vam->result_ready = 1;
4817}
4818
4819static void vl_api_policer_add_del_reply_t_handler
4820 (vl_api_policer_add_del_reply_t * mp)
4821{
4822 vat_main_t *vam = &vat_main;
4823 i32 retval = ntohl (mp->retval);
4824 if (vam->async_mode)
4825 {
4826 vam->async_errors += (retval < 0);
4827 }
4828 else
4829 {
4830 vam->retval = retval;
4831 vam->result_ready = 1;
4832 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
4833 /*
4834 * Note: this is just barely thread-safe, depends on
4835 * the main thread spinning waiting for an answer...
4836 */
4837 errmsg ("policer index %d", ntohl (mp->policer_index));
4838 }
4839}
4840
4841static void vl_api_policer_add_del_reply_t_handler_json
4842 (vl_api_policer_add_del_reply_t * mp)
4843{
4844 vat_main_t *vam = &vat_main;
4845 vat_json_node_t node;
4846
4847 vat_json_init_object (&node);
4848 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4849 vat_json_object_add_uint (&node, "policer_index",
4850 ntohl (mp->policer_index));
4851
4852 vat_json_print (vam->ofp, &node);
4853 vat_json_free (&node);
4854
4855 vam->retval = ntohl (mp->retval);
4856 vam->result_ready = 1;
4857}
4858
4859/* Format hex dump. */
4860u8 *
4861format_hex_bytes (u8 * s, va_list * va)
4862{
4863 u8 *bytes = va_arg (*va, u8 *);
4864 int n_bytes = va_arg (*va, int);
4865 uword i;
4866
4867 /* Print short or long form depending on byte count. */
4868 uword short_form = n_bytes <= 32;
Christophe Fontained3c008d2017-10-02 18:10:54 +02004869 u32 indent = format_get_indent (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004870
4871 if (n_bytes == 0)
4872 return s;
4873
4874 for (i = 0; i < n_bytes; i++)
4875 {
4876 if (!short_form && (i % 32) == 0)
4877 s = format (s, "%08x: ", i);
4878 s = format (s, "%02x", bytes[i]);
4879 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
4880 s = format (s, "\n%U", format_white_space, indent);
4881 }
4882
4883 return s;
4884}
4885
4886static void
4887vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
4888 * mp)
4889{
4890 vat_main_t *vam = &vat_main;
4891 i32 retval = ntohl (mp->retval);
4892 if (retval == 0)
4893 {
4894 print (vam->ofp, "classify table info :");
4895 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
4896 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
4897 ntohl (mp->miss_next_index));
4898 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
4899 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
4900 ntohl (mp->match_n_vectors));
4901 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
4902 ntohl (mp->mask_length));
4903 }
4904 vam->retval = retval;
4905 vam->result_ready = 1;
4906}
4907
4908static void
4909 vl_api_classify_table_info_reply_t_handler_json
4910 (vl_api_classify_table_info_reply_t * mp)
4911{
4912 vat_main_t *vam = &vat_main;
4913 vat_json_node_t node;
4914
4915 i32 retval = ntohl (mp->retval);
4916 if (retval == 0)
4917 {
4918 vat_json_init_object (&node);
4919
4920 vat_json_object_add_int (&node, "sessions",
4921 ntohl (mp->active_sessions));
4922 vat_json_object_add_int (&node, "nexttbl",
4923 ntohl (mp->next_table_index));
4924 vat_json_object_add_int (&node, "nextnode",
4925 ntohl (mp->miss_next_index));
4926 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
4927 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
4928 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
4929 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
4930 ntohl (mp->mask_length), 0);
4931 vat_json_object_add_string_copy (&node, "mask", s);
4932
4933 vat_json_print (vam->ofp, &node);
4934 vat_json_free (&node);
4935 }
4936 vam->retval = ntohl (mp->retval);
4937 vam->result_ready = 1;
4938}
4939
4940static void
4941vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
4942 mp)
4943{
4944 vat_main_t *vam = &vat_main;
4945
4946 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
4947 ntohl (mp->hit_next_index), ntohl (mp->advance),
4948 ntohl (mp->opaque_index));
4949 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
4950 ntohl (mp->match_length));
4951}
4952
4953static void
4954 vl_api_classify_session_details_t_handler_json
4955 (vl_api_classify_session_details_t * mp)
4956{
4957 vat_main_t *vam = &vat_main;
4958 vat_json_node_t *node = NULL;
4959
4960 if (VAT_JSON_ARRAY != vam->json_tree.type)
4961 {
4962 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4963 vat_json_init_array (&vam->json_tree);
4964 }
4965 node = vat_json_array_add (&vam->json_tree);
4966
4967 vat_json_init_object (node);
4968 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
4969 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
4970 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
4971 u8 *s =
4972 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
4973 0);
4974 vat_json_object_add_string_copy (node, "match", s);
4975}
4976
4977static void vl_api_pg_create_interface_reply_t_handler
4978 (vl_api_pg_create_interface_reply_t * mp)
4979{
4980 vat_main_t *vam = &vat_main;
4981
4982 vam->retval = ntohl (mp->retval);
4983 vam->result_ready = 1;
4984}
4985
4986static void vl_api_pg_create_interface_reply_t_handler_json
4987 (vl_api_pg_create_interface_reply_t * mp)
4988{
4989 vat_main_t *vam = &vat_main;
4990 vat_json_node_t node;
4991
4992 i32 retval = ntohl (mp->retval);
4993 if (retval == 0)
4994 {
4995 vat_json_init_object (&node);
4996
4997 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
4998
4999 vat_json_print (vam->ofp, &node);
5000 vat_json_free (&node);
5001 }
5002 vam->retval = ntohl (mp->retval);
5003 vam->result_ready = 1;
5004}
5005
5006static void vl_api_policer_classify_details_t_handler
5007 (vl_api_policer_classify_details_t * mp)
5008{
5009 vat_main_t *vam = &vat_main;
5010
5011 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
5012 ntohl (mp->table_index));
5013}
5014
5015static void vl_api_policer_classify_details_t_handler_json
5016 (vl_api_policer_classify_details_t * mp)
5017{
5018 vat_main_t *vam = &vat_main;
5019 vat_json_node_t *node;
5020
5021 if (VAT_JSON_ARRAY != vam->json_tree.type)
5022 {
5023 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5024 vat_json_init_array (&vam->json_tree);
5025 }
5026 node = vat_json_array_add (&vam->json_tree);
5027
5028 vat_json_init_object (node);
5029 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5030 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5031}
5032
Damjan Marion7cd468a2016-12-19 23:05:39 +01005033static void vl_api_flow_classify_details_t_handler
5034 (vl_api_flow_classify_details_t * mp)
5035{
5036 vat_main_t *vam = &vat_main;
5037
5038 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
5039 ntohl (mp->table_index));
5040}
5041
5042static void vl_api_flow_classify_details_t_handler_json
5043 (vl_api_flow_classify_details_t * mp)
5044{
5045 vat_main_t *vam = &vat_main;
5046 vat_json_node_t *node;
5047
5048 if (VAT_JSON_ARRAY != vam->json_tree.type)
5049 {
5050 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5051 vat_json_init_array (&vam->json_tree);
5052 }
5053 node = vat_json_array_add (&vam->json_tree);
5054
5055 vat_json_init_object (node);
5056 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5057 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5058}
5059
Filip Tehlar694396d2017-02-17 14:29:11 +01005060#define vl_api_one_adjacencies_get_reply_t_endian vl_noop_handler
5061#define vl_api_one_adjacencies_get_reply_t_print vl_noop_handler
Filip Tehlard5a65db2017-05-17 17:21:10 +02005062#define vl_api_one_l2_arp_bd_get_reply_t_print vl_noop_handler
5063#define vl_api_one_l2_arp_entries_get_reply_t_endian vl_noop_handler
5064#define vl_api_one_l2_arp_entries_get_reply_t_print vl_noop_handler
5065#define vl_api_one_l2_arp_bd_get_reply_t_endian vl_noop_handler
Filip Tehlar05879992017-09-05 15:46:09 +02005066#define vl_api_one_ndp_bd_get_reply_t_endian vl_noop_handler
5067#define vl_api_one_ndp_bd_get_reply_t_print vl_noop_handler
5068#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
5069#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +01005070
5071/*
5072 * Generate boilerplate reply handlers, which
5073 * dig the return value out of the xxx_reply_t API message,
5074 * stick it into vam->retval, and set vam->result_ready
5075 *
5076 * Could also do this by pointing N message decode slots at
5077 * a single function, but that could break in subtle ways.
5078 */
5079
5080#define foreach_standard_reply_retval_handler \
5081_(sw_interface_set_flags_reply) \
5082_(sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005083_(sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005084_(sw_interface_set_rx_placement_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005085_(sw_interface_set_table_reply) \
5086_(sw_interface_set_mpls_enable_reply) \
5087_(sw_interface_set_vpath_reply) \
5088_(sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005089_(sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005090_(sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005091_(sw_interface_set_l2_bridge_reply) \
Steven Luonga1876b82019-08-20 16:58:00 -07005092_(sw_interface_set_bond_weight_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005093_(bridge_domain_add_del_reply) \
5094_(sw_interface_set_l2_xconnect_reply) \
5095_(l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005096_(l2fib_flush_int_reply) \
5097_(l2fib_flush_bd_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005098_(ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005099_(ip_table_add_del_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005100_(ip_mroute_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005101_(mpls_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005102_(mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005103_(mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005104_(bier_route_add_del_reply) \
5105_(bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005106_(proxy_arp_add_del_reply) \
5107_(proxy_arp_intfc_enable_disable_reply) \
5108_(sw_interface_set_unnumbered_reply) \
5109_(ip_neighbor_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005110_(reset_fib_reply) \
5111_(dhcp_proxy_config_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005112_(dhcp_proxy_set_vss_reply) \
5113_(dhcp_client_config_reply) \
5114_(set_ip_flow_hash_reply) \
5115_(sw_interface_ip6_enable_disable_reply) \
Neale Ranns3f844d02017-02-18 00:03:54 -08005116_(ip6nd_proxy_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005117_(sw_interface_ip6nd_ra_prefix_reply) \
5118_(sw_interface_ip6nd_ra_config_reply) \
5119_(set_arp_neighbor_limit_reply) \
5120_(l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005121_(sr_mpls_policy_add_reply) \
5122_(sr_mpls_policy_mod_reply) \
5123_(sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005124_(sr_policy_add_reply) \
5125_(sr_policy_mod_reply) \
5126_(sr_policy_del_reply) \
5127_(sr_localsid_add_del_reply) \
5128_(sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005129_(classify_add_del_session_reply) \
5130_(classify_set_interface_ip_table_reply) \
5131_(classify_set_interface_l2_tables_reply) \
5132_(l2tpv3_set_tunnel_cookies_reply) \
5133_(l2tpv3_interface_enable_disable_reply) \
5134_(l2tpv3_set_lookup_key_reply) \
5135_(l2_fib_clear_table_reply) \
5136_(l2_interface_efp_filter_reply) \
5137_(l2_interface_vlan_tag_rewrite_reply) \
5138_(modify_vhost_user_if_reply) \
5139_(delete_vhost_user_if_reply) \
John Loc7b43042018-04-13 16:46:22 -04005140_(ip_probe_neighbor_reply) \
John Lo7f358b32018-04-28 01:19:24 -04005141_(ip_scan_neighbor_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005142_(want_ip4_arp_events_reply) \
5143_(want_ip6_nd_events_reply) \
John Lo8d00fff2017-08-03 00:35:36 -04005144_(want_l2_macs_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005145_(input_acl_set_interface_reply) \
5146_(ipsec_spd_add_del_reply) \
5147_(ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005148_(ipsec_spd_entry_add_del_reply) \
5149_(ipsec_sad_entry_add_del_reply) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005150_(ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005151_(ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005152_(delete_loopback_reply) \
5153_(bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005154_(bd_ip_mac_flush_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005155_(want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005156_(cop_interface_enable_disable_reply) \
5157_(cop_whitelist_enable_disable_reply) \
5158_(sw_interface_clear_stats_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005159_(ioam_enable_reply) \
5160_(ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005161_(one_add_del_locator_reply) \
5162_(one_add_del_local_eid_reply) \
5163_(one_add_del_remote_mapping_reply) \
5164_(one_add_del_adjacency_reply) \
5165_(one_add_del_map_resolver_reply) \
5166_(one_add_del_map_server_reply) \
5167_(one_enable_disable_reply) \
5168_(one_rloc_probe_enable_disable_reply) \
5169_(one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005170_(one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005171_(one_set_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005172_(one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005173_(one_pitr_set_locator_set_reply) \
5174_(one_map_request_mode_reply) \
5175_(one_add_del_map_request_itr_rlocs_reply) \
5176_(one_eid_table_add_del_map_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005177_(one_use_petr_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005178_(one_stats_enable_disable_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005179_(one_add_del_l2_arp_entry_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005180_(one_add_del_ndp_entry_reply) \
Filip Tehlar21511912017-04-07 10:41:42 +02005181_(one_stats_flush_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005182_(one_enable_disable_xtr_mode_reply) \
5183_(one_enable_disable_pitr_mode_reply) \
5184_(one_enable_disable_petr_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005185_(gpe_enable_disable_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005186_(gpe_set_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005187_(gpe_add_del_iface_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005188_(gpe_add_del_native_fwd_rpath_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005189_(af_packet_delete_reply) \
5190_(policer_classify_set_interface_reply) \
5191_(netmap_create_reply) \
5192_(netmap_delete_reply) \
5193_(set_ipfix_exporter_reply) \
5194_(set_ipfix_classify_stream_reply) \
5195_(ipfix_classify_table_add_del_reply) \
5196_(flow_classify_set_interface_reply) \
5197_(sw_interface_span_enable_disable_reply) \
5198_(pg_capture_reply) \
5199_(pg_enable_disable_reply) \
5200_(ip_source_and_port_range_check_add_del_reply) \
5201_(ip_source_and_port_range_check_interface_add_del_reply)\
5202_(delete_subif_reply) \
5203_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005204_(set_punt_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005205_(feature_enable_disable_reply) \
5206_(sw_interface_tag_add_del_reply) \
Ole Troand7231612018-06-07 10:17:57 +02005207_(hw_interface_set_mtu_reply) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005208_(p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005209_(p2p_ethernet_del_reply) \
5210_(lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005211_(sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005212_(tcp_configure_src_addresses_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005213_(session_rule_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005214_(ip_container_proxy_add_del_reply) \
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -07005215_(output_acl_set_interface_reply) \
5216_(qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005217
5218#define _(n) \
5219 static void vl_api_##n##_t_handler \
5220 (vl_api_##n##_t * mp) \
5221 { \
5222 vat_main_t * vam = &vat_main; \
5223 i32 retval = ntohl(mp->retval); \
5224 if (vam->async_mode) { \
5225 vam->async_errors += (retval < 0); \
5226 } else { \
5227 vam->retval = retval; \
5228 vam->result_ready = 1; \
5229 } \
5230 }
5231foreach_standard_reply_retval_handler;
5232#undef _
5233
5234#define _(n) \
5235 static void vl_api_##n##_t_handler_json \
5236 (vl_api_##n##_t * mp) \
5237 { \
5238 vat_main_t * vam = &vat_main; \
5239 vat_json_node_t node; \
5240 vat_json_init_object(&node); \
5241 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
5242 vat_json_print(vam->ofp, &node); \
5243 vam->retval = ntohl(mp->retval); \
5244 vam->result_ready = 1; \
5245 }
5246foreach_standard_reply_retval_handler;
5247#undef _
5248
5249/*
5250 * Table of message reply handlers, must include boilerplate handlers
5251 * we just generated
5252 */
5253
5254#define foreach_vpe_api_reply_msg \
5255_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005256_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005257_(SW_INTERFACE_DETAILS, sw_interface_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005258_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
5259_(CONTROL_PING_REPLY, control_ping_reply) \
5260_(CLI_REPLY, cli_reply) \
5261_(CLI_INBAND_REPLY, cli_inband_reply) \
5262_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
5263 sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005264_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005265_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02005266_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005267_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
5268_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
5269_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
5270_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005271_(SW_INTERFACE_SET_GENEVE_BYPASS_REPLY, sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005272_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005273_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
5274 sw_interface_set_l2_xconnect_reply) \
5275_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
5276 sw_interface_set_l2_bridge_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005277_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
5278_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
Eyal Barifead6702017-04-04 04:46:32 +03005279_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005280_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005281_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
5282_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005283_(L2_FLAGS_REPLY, l2_flags_reply) \
5284_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
Damjan Marion8389fb92017-10-13 18:29:53 +02005285_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
5286_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
5287_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01005288_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
5289_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
5290_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
Steven9cd2d7a2017-12-20 12:43:01 -08005291_(BOND_CREATE_REPLY, bond_create_reply) \
5292_(BOND_DELETE_REPLY, bond_delete_reply) \
5293_(BOND_ENSLAVE_REPLY, bond_enslave_reply) \
5294_(BOND_DETACH_SLAVE_REPLY, bond_detach_slave_reply) \
Steven Luonga1876b82019-08-20 16:58:00 -07005295_(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
Steven9cd2d7a2017-12-20 12:43:01 -08005296_(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details) \
5297_(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005298_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005299_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005300_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005301_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005302_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
5303_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005304_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
5305_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005306_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
5307_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
5308 proxy_arp_intfc_enable_disable_reply) \
5309_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
5310_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
5311 sw_interface_set_unnumbered_reply) \
5312_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005313_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
5314_(CREATE_SUBIF_REPLY, create_subif_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005315_(RESET_FIB_REPLY, reset_fib_reply) \
5316_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005317_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
Neale Ranns20a175a2017-02-14 07:28:41 -08005318_(DHCP_PROXY_DETAILS, dhcp_proxy_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005319_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
5320_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
5321_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
5322 sw_interface_ip6_enable_disable_reply) \
Neale Ranns3f844d02017-02-18 00:03:54 -08005323_(IP6ND_PROXY_ADD_DEL_REPLY, ip6nd_proxy_add_del_reply) \
5324_(IP6ND_PROXY_DETAILS, ip6nd_proxy_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005325_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
5326 sw_interface_ip6nd_ra_prefix_reply) \
5327_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
5328 sw_interface_ip6nd_ra_config_reply) \
5329_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
5330_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005331_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
5332_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
5333_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005334_(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
5335_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
5336_(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
5337_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
5338_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005339_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
5340_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
5341_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
5342classify_set_interface_ip_table_reply) \
5343_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
5344 classify_set_interface_l2_tables_reply) \
5345_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
5346_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
5347_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
5348_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
5349_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
5350 l2tpv3_interface_enable_disable_reply) \
5351_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
5352_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
5353_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
eyal bariaf86a482018-04-17 11:20:27 +03005354_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005355_(GENEVE_ADD_DEL_TUNNEL_REPLY, geneve_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005356_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005357_(GENEVE_TUNNEL_DETAILS, geneve_tunnel_details) \
Neale Ranns5a8844b2019-04-16 07:15:35 +00005358_(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005359_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
5360_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
5361_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
5362_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
5363_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
5364_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
5365_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
5366_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
5367_(SHOW_VERSION_REPLY, show_version_reply) \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02005368_(SHOW_THREADS_REPLY, show_threads_reply) \
Ole Troan01384fe2017-05-12 11:55:35 +02005369_(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
John Loc7b43042018-04-13 16:46:22 -04005370_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005371_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
5372_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
John Loc7b43042018-04-13 16:46:22 -04005373_(IP_PROBE_NEIGHBOR_REPLY, ip_probe_neighbor_reply) \
John Lo7f358b32018-04-28 01:19:24 -04005374_(IP_SCAN_NEIGHBOR_ENABLE_DISABLE_REPLY, ip_scan_neighbor_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005375_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
5376_(IP4_ARP_EVENT, ip4_arp_event) \
5377_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
5378_(IP6_ND_EVENT, ip6_nd_event) \
John Lo8d00fff2017-08-03 00:35:36 -04005379_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
5380_(L2_MACS_EVENT, l2_macs_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005381_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
5382_(IP_ADDRESS_DETAILS, ip_address_details) \
5383_(IP_DETAILS, ip_details) \
5384_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
5385_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005386_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
5387_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
Matthew Smith28029532017-09-26 13:33:44 -05005388_(IPSEC_SA_DETAILS, ipsec_sa_details) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005389_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005390_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005391_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
5392_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005393_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02005394_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005395_(DHCP_COMPL_EVENT, dhcp_compl_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005396_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005397_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
5398_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
5399_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
5400_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
5401_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
5402_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
5403_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005404_(ONE_ADD_DEL_LOCATOR_SET_REPLY, one_add_del_locator_set_reply) \
5405_(ONE_ADD_DEL_LOCATOR_REPLY, one_add_del_locator_reply) \
5406_(ONE_ADD_DEL_LOCAL_EID_REPLY, one_add_del_local_eid_reply) \
5407_(ONE_ADD_DEL_REMOTE_MAPPING_REPLY, one_add_del_remote_mapping_reply) \
5408_(ONE_ADD_DEL_ADJACENCY_REPLY, one_add_del_adjacency_reply) \
5409_(ONE_ADD_DEL_MAP_RESOLVER_REPLY, one_add_del_map_resolver_reply) \
5410_(ONE_ADD_DEL_MAP_SERVER_REPLY, one_add_del_map_server_reply) \
5411_(ONE_ENABLE_DISABLE_REPLY, one_enable_disable_reply) \
5412_(ONE_MAP_REGISTER_ENABLE_DISABLE_REPLY, \
5413 one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005414_(ONE_MAP_REGISTER_SET_TTL_REPLY, one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005415_(ONE_SET_TRANSPORT_PROTOCOL_REPLY, one_set_transport_protocol_reply) \
5416_(ONE_GET_TRANSPORT_PROTOCOL_REPLY, one_get_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005417_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5418 one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005419_(ONE_RLOC_PROBE_ENABLE_DISABLE_REPLY, \
5420 one_rloc_probe_enable_disable_reply) \
5421_(ONE_PITR_SET_LOCATOR_SET_REPLY, one_pitr_set_locator_set_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005422_(ONE_USE_PETR_REPLY, one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005423_(ONE_MAP_REQUEST_MODE_REPLY, one_map_request_mode_reply) \
5424_(ONE_EID_TABLE_ADD_DEL_MAP_REPLY, one_eid_table_add_del_map_reply) \
5425_(ONE_LOCATOR_SET_DETAILS, one_locator_set_details) \
5426_(ONE_LOCATOR_DETAILS, one_locator_details) \
5427_(ONE_EID_TABLE_DETAILS, one_eid_table_details) \
5428_(ONE_EID_TABLE_MAP_DETAILS, one_eid_table_map_details) \
5429_(ONE_EID_TABLE_VNI_DETAILS, one_eid_table_vni_details) \
5430_(ONE_MAP_RESOLVER_DETAILS, one_map_resolver_details) \
5431_(ONE_MAP_SERVER_DETAILS, one_map_server_details) \
5432_(ONE_ADJACENCIES_GET_REPLY, one_adjacencies_get_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005433_(ONE_STATS_DETAILS, one_stats_details) \
Filip Tehlar21511912017-04-07 10:41:42 +02005434_(ONE_STATS_FLUSH_REPLY, one_stats_flush_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005435_(ONE_STATS_ENABLE_DISABLE_REPLY, one_stats_enable_disable_reply) \
5436_(SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, \
5437 show_one_stats_enable_disable_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005438_(ONE_ADD_DEL_NDP_ENTRY_REPLY, one_add_del_ndp_entry_reply) \
5439_(ONE_NDP_BD_GET_REPLY, one_ndp_bd_get_reply) \
5440_(ONE_NDP_ENTRIES_GET_REPLY, one_ndp_entries_get_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005441_(ONE_ADD_DEL_L2_ARP_ENTRY_REPLY, one_add_del_l2_arp_entry_reply) \
5442_(ONE_L2_ARP_BD_GET_REPLY, one_l2_arp_bd_get_reply) \
5443_(ONE_L2_ARP_ENTRIES_GET_REPLY, one_l2_arp_entries_get_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005444_(ONE_ENABLE_DISABLE_XTR_MODE_REPLY, one_enable_disable_xtr_mode_reply) \
5445_(ONE_ENABLE_DISABLE_PITR_MODE_REPLY, \
5446 one_enable_disable_pitr_mode_reply) \
5447_(ONE_ENABLE_DISABLE_PETR_MODE_REPLY, \
5448 one_enable_disable_petr_mode_reply) \
5449_(ONE_SHOW_XTR_MODE_REPLY, one_show_xtr_mode_reply) \
5450_(ONE_SHOW_PITR_MODE_REPLY, one_show_pitr_mode_reply) \
5451_(ONE_SHOW_PETR_MODE_REPLY, one_show_petr_mode_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005452_(GPE_SET_ENCAP_MODE_REPLY, gpe_set_encap_mode_reply) \
5453_(GPE_GET_ENCAP_MODE_REPLY, gpe_get_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005454_(GPE_ADD_DEL_IFACE_REPLY, gpe_add_del_iface_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005455_(GPE_ENABLE_DISABLE_REPLY, gpe_enable_disable_reply) \
5456_(GPE_ADD_DEL_FWD_ENTRY_REPLY, gpe_add_del_fwd_entry_reply) \
Filip Tehlar0eb874e2017-05-18 14:23:32 +02005457_(GPE_FWD_ENTRY_VNIS_GET_REPLY, gpe_fwd_entry_vnis_get_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005458_(GPE_FWD_ENTRIES_GET_REPLY, gpe_fwd_entries_get_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005459_(GPE_NATIVE_FWD_RPATHS_GET_REPLY, gpe_native_fwd_rpaths_get_reply) \
5460_(GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY, \
5461 gpe_add_del_native_fwd_rpath_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005462_(GPE_FWD_ENTRY_PATH_DETAILS, \
5463 gpe_fwd_entry_path_details) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005464_(SHOW_ONE_STATUS_REPLY, show_one_status_reply) \
5465_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
5466 one_add_del_map_request_itr_rlocs_reply) \
5467_(ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
5468 one_get_map_request_itr_rlocs_reply) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02005469_(SHOW_ONE_NSH_MAPPING_REPLY, show_one_nsh_mapping_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005470_(SHOW_ONE_PITR_REPLY, show_one_pitr_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005471_(SHOW_ONE_USE_PETR_REPLY, show_one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005472_(SHOW_ONE_MAP_REQUEST_MODE_REPLY, show_one_map_request_mode_reply) \
5473_(SHOW_ONE_RLOC_PROBE_STATE_REPLY, show_one_rloc_probe_state_reply) \
5474_(SHOW_ONE_MAP_REGISTER_STATE_REPLY, \
5475 show_one_map_register_state_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005476_(SHOW_ONE_MAP_REGISTER_TTL_REPLY, show_one_map_register_ttl_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005477_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5478 show_one_map_register_fallback_threshold_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005479_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
5480_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +02005481_(AF_PACKET_DETAILS, af_packet_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005482_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
5483_(POLICER_DETAILS, policer_details) \
5484_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
5485_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
5486_(NETMAP_CREATE_REPLY, netmap_create_reply) \
5487_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
5488_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005489_(MPLS_TABLE_DETAILS, mpls_table_details) \
5490_(MPLS_ROUTE_DETAILS, mpls_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005491_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
5492_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
5493_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
5494_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
5495_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
5496_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
5497_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
5498_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
5499_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
5500_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
5501_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
5502_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
5503_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
5504_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
5505_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
5506_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
5507_(PG_CAPTURE_REPLY, pg_capture_reply) \
5508_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
5509_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
5510 ip_source_and_port_range_check_add_del_reply) \
5511_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
5512 ip_source_and_port_range_check_interface_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005513_(DELETE_SUBIF_REPLY, delete_subif_reply) \
5514_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005515_(SET_PUNT_REPLY, set_punt_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005516_(IP_TABLE_DETAILS, ip_table_details) \
5517_(IP_ROUTE_DETAILS, ip_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005518_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
5519_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
5520_(L2_XCONNECT_DETAILS, l2_xconnect_details) \
Ole Troand7231612018-06-07 10:17:57 +02005521_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005522_(IP_NEIGHBOR_DETAILS, ip_neighbor_details) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005523_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
5524_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005525_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
5526_(LLDP_CONFIG_REPLY, lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005527_(SW_INTERFACE_SET_LLDP_REPLY, sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005528_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005529_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
Florin Coras6c36f532017-11-03 18:32:34 -07005530_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005531_(SESSION_RULES_DETAILS, session_rules_details) \
5532_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005533_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
Ole Troane906aac2018-06-14 14:42:14 +02005534_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005535
Dave Baracha1a093d2017-03-02 13:13:23 -05005536#define foreach_standalone_reply_msg \
Ole Troanf49ba0e2018-11-13 14:04:50 +01005537_(SW_INTERFACE_EVENT, sw_interface_event)
Dave Baracha1a093d2017-03-02 13:13:23 -05005538
Damjan Marion7cd468a2016-12-19 23:05:39 +01005539typedef struct
5540{
5541 u8 *name;
5542 u32 value;
5543} name_sort_t;
5544
Damjan Marion7cd468a2016-12-19 23:05:39 +01005545#define STR_VTR_OP_CASE(op) \
5546 case L2_VTR_ ## op: \
5547 return "" # op;
5548
5549static const char *
5550str_vtr_op (u32 vtr_op)
5551{
5552 switch (vtr_op)
5553 {
5554 STR_VTR_OP_CASE (DISABLED);
5555 STR_VTR_OP_CASE (PUSH_1);
5556 STR_VTR_OP_CASE (PUSH_2);
5557 STR_VTR_OP_CASE (POP_1);
5558 STR_VTR_OP_CASE (POP_2);
5559 STR_VTR_OP_CASE (TRANSLATE_1_1);
5560 STR_VTR_OP_CASE (TRANSLATE_1_2);
5561 STR_VTR_OP_CASE (TRANSLATE_2_1);
5562 STR_VTR_OP_CASE (TRANSLATE_2_2);
5563 }
5564
5565 return "UNKNOWN";
5566}
5567
5568static int
5569dump_sub_interface_table (vat_main_t * vam)
5570{
5571 const sw_interface_subif_t *sub = NULL;
5572
5573 if (vam->json_output)
5574 {
5575 clib_warning
5576 ("JSON output supported only for VPE API calls and dump_stats_table");
5577 return -99;
5578 }
5579
5580 print (vam->ofp,
5581 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
5582 "Interface", "sw_if_index",
5583 "sub id", "dot1ad", "tags", "outer id",
5584 "inner id", "exact", "default", "outer any", "inner any");
5585
5586 vec_foreach (sub, vam->sw_if_subif_table)
5587 {
5588 print (vam->ofp,
5589 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
5590 sub->interface_name,
5591 sub->sw_if_index,
5592 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
5593 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
5594 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
5595 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
5596 if (sub->vtr_op != L2_VTR_DISABLED)
5597 {
5598 print (vam->ofp,
5599 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
5600 "tag1: %d tag2: %d ]",
5601 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
5602 sub->vtr_tag1, sub->vtr_tag2);
5603 }
5604 }
5605
5606 return 0;
5607}
5608
5609static int
5610name_sort_cmp (void *a1, void *a2)
5611{
5612 name_sort_t *n1 = a1;
5613 name_sort_t *n2 = a2;
5614
5615 return strcmp ((char *) n1->name, (char *) n2->name);
5616}
5617
5618static int
5619dump_interface_table (vat_main_t * vam)
5620{
5621 hash_pair_t *p;
5622 name_sort_t *nses = 0, *ns;
5623
5624 if (vam->json_output)
5625 {
5626 clib_warning
5627 ("JSON output supported only for VPE API calls and dump_stats_table");
5628 return -99;
5629 }
5630
5631 /* *INDENT-OFF* */
5632 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5633 ({
5634 vec_add2 (nses, ns, 1);
5635 ns->name = (u8 *)(p->key);
5636 ns->value = (u32) p->value[0];
5637 }));
5638 /* *INDENT-ON* */
5639
5640 vec_sort_with_function (nses, name_sort_cmp);
5641
5642 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
5643 vec_foreach (ns, nses)
5644 {
5645 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
5646 }
5647 vec_free (nses);
5648 return 0;
5649}
5650
5651static int
5652dump_ip_table (vat_main_t * vam, int is_ipv6)
5653{
5654 const ip_details_t *det = NULL;
5655 const ip_address_details_t *address = NULL;
5656 u32 i = ~0;
5657
5658 print (vam->ofp, "%-12s", "sw_if_index");
5659
5660 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
5661 {
5662 i++;
5663 if (!det->present)
5664 {
5665 continue;
5666 }
5667 print (vam->ofp, "%-12d", i);
5668 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
5669 if (!det->addr)
5670 {
5671 continue;
5672 }
5673 vec_foreach (address, det->addr)
5674 {
5675 print (vam->ofp,
5676 " %-30U%-13d",
5677 is_ipv6 ? format_ip6_address : format_ip4_address,
5678 address->ip, address->prefix_length);
5679 }
5680 }
5681
5682 return 0;
5683}
5684
5685static int
5686dump_ipv4_table (vat_main_t * vam)
5687{
5688 if (vam->json_output)
5689 {
5690 clib_warning
5691 ("JSON output supported only for VPE API calls and dump_stats_table");
5692 return -99;
5693 }
5694
5695 return dump_ip_table (vam, 0);
5696}
5697
5698static int
5699dump_ipv6_table (vat_main_t * vam)
5700{
5701 if (vam->json_output)
5702 {
5703 clib_warning
5704 ("JSON output supported only for VPE API calls and dump_stats_table");
5705 return -99;
5706 }
5707
5708 return dump_ip_table (vam, 1);
5709}
5710
Damjan Marion7cd468a2016-12-19 23:05:39 +01005711/*
Dave Barach59b25652017-09-10 15:04:27 -04005712 * Pass CLI buffers directly in the CLI_INBAND API message,
5713 * instead of an additional shared memory area.
Damjan Marion7cd468a2016-12-19 23:05:39 +01005714 */
5715static int
5716exec_inband (vat_main_t * vam)
5717{
5718 vl_api_cli_inband_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005719 unformat_input_t *i = vam->input;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005720 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005721
5722 if (vec_len (i->buffer) == 0)
5723 return -1;
5724
5725 if (vam->exec_mode == 0 && unformat (i, "mode"))
5726 {
5727 vam->exec_mode = 1;
5728 return 0;
5729 }
5730 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
5731 {
5732 vam->exec_mode = 0;
5733 return 0;
5734 }
5735
5736 /*
5737 * In order for the CLI command to work, it
5738 * must be a vector ending in \n, not a C-string ending
5739 * in \n\0.
5740 */
5741 u32 len = vec_len (vam->input->buffer);
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005742 M2 (CLI_INBAND, mp, len);
Ole Troan884f0af2018-12-14 20:34:29 +01005743 vl_api_to_api_string (len - 1, (const char *) vam->input->buffer, &mp->cmd);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005744
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005745 S (mp);
Dave Barach59b25652017-09-10 15:04:27 -04005746 W (ret);
5747 /* json responses may or may not include a useful reply... */
5748 if (vec_len (vam->cmd_reply))
Dave Barachcf5e8482017-10-17 11:48:29 -04005749 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
Jon Loeliger56c7b012017-02-01 12:31:41 -06005750 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005751}
5752
Dave Barach59b25652017-09-10 15:04:27 -04005753int
5754exec (vat_main_t * vam)
5755{
5756 return exec_inband (vam);
5757}
5758
Damjan Marion7cd468a2016-12-19 23:05:39 +01005759static int
5760api_create_loopback (vat_main_t * vam)
5761{
5762 unformat_input_t *i = vam->input;
5763 vl_api_create_loopback_t *mp;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005764 vl_api_create_loopback_instance_t *mp_lbi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005765 u8 mac_address[6];
5766 u8 mac_set = 0;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005767 u8 is_specified = 0;
5768 u32 user_instance = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005769 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005770
Dave Barachb7b92992018-10-17 10:38:51 -04005771 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01005772
5773 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5774 {
5775 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5776 mac_set = 1;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005777 if (unformat (i, "instance %d", &user_instance))
5778 is_specified = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005779 else
5780 break;
5781 }
5782
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005783 if (is_specified)
5784 {
5785 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
5786 mp_lbi->is_specified = is_specified;
5787 if (is_specified)
5788 mp_lbi->user_instance = htonl (user_instance);
5789 if (mac_set)
5790 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
5791 S (mp_lbi);
5792 }
5793 else
5794 {
5795 /* Construct the API message */
5796 M (CREATE_LOOPBACK, mp);
5797 if (mac_set)
5798 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
5799 S (mp);
5800 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01005801
Jon Loeliger56c7b012017-02-01 12:31:41 -06005802 W (ret);
5803 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005804}
5805
5806static int
5807api_delete_loopback (vat_main_t * vam)
5808{
5809 unformat_input_t *i = vam->input;
5810 vl_api_delete_loopback_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005811 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005812 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005813
5814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5815 {
5816 if (unformat (i, "sw_if_index %d", &sw_if_index))
5817 ;
5818 else
5819 break;
5820 }
5821
5822 if (sw_if_index == ~0)
5823 {
5824 errmsg ("missing sw_if_index");
5825 return -99;
5826 }
5827
5828 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005829 M (DELETE_LOOPBACK, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005830 mp->sw_if_index = ntohl (sw_if_index);
5831
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005832 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005833 W (ret);
5834 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005835}
5836
5837static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01005838api_want_interface_events (vat_main_t * vam)
5839{
5840 unformat_input_t *i = vam->input;
5841 vl_api_want_interface_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005842 int enable = -1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005843 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005844
5845 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5846 {
5847 if (unformat (i, "enable"))
5848 enable = 1;
5849 else if (unformat (i, "disable"))
5850 enable = 0;
5851 else
5852 break;
5853 }
5854
5855 if (enable == -1)
5856 {
5857 errmsg ("missing enable|disable");
5858 return -99;
5859 }
5860
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005861 M (WANT_INTERFACE_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005862 mp->enable_disable = enable;
5863
5864 vam->interface_event_display = enable;
5865
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005866 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005867 W (ret);
5868 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005869}
5870
5871
5872/* Note: non-static, called once to set up the initial intfc table */
5873int
5874api_sw_interface_dump (vat_main_t * vam)
5875{
5876 vl_api_sw_interface_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005877 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005878 hash_pair_t *p;
5879 name_sort_t *nses = 0, *ns;
5880 sw_interface_subif_t *sub = NULL;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005881 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005882
5883 /* Toss the old name table */
5884 /* *INDENT-OFF* */
5885 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5886 ({
5887 vec_add2 (nses, ns, 1);
5888 ns->name = (u8 *)(p->key);
5889 ns->value = (u32) p->value[0];
5890 }));
5891 /* *INDENT-ON* */
5892
5893 hash_free (vam->sw_if_index_by_interface_name);
5894
5895 vec_foreach (ns, nses) vec_free (ns->name);
5896
5897 vec_free (nses);
5898
5899 vec_foreach (sub, vam->sw_if_subif_table)
5900 {
5901 vec_free (sub->interface_name);
5902 }
5903 vec_free (vam->sw_if_subif_table);
5904
5905 /* recreate the interface name hash table */
5906 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
5907
Dave Barachf72212e2018-01-11 10:25:07 -05005908 /*
5909 * Ask for all interface names. Otherwise, the epic catalog of
5910 * name filters becomes ridiculously long, and vat ends up needing
5911 * to be taught about new interface types.
5912 */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005913 M (SW_INTERFACE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005914 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005915
5916 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04005917 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005918 S (mp_ping);
5919
Jon Loeliger56c7b012017-02-01 12:31:41 -06005920 W (ret);
5921 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005922}
5923
5924static int
5925api_sw_interface_set_flags (vat_main_t * vam)
5926{
5927 unformat_input_t *i = vam->input;
5928 vl_api_sw_interface_set_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005929 u32 sw_if_index;
5930 u8 sw_if_index_set = 0;
Neale Rannsa07bd702017-08-07 07:53:49 -07005931 u8 admin_up = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005932 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005933
5934 /* Parse args required to build the message */
5935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5936 {
5937 if (unformat (i, "admin-up"))
5938 admin_up = 1;
5939 else if (unformat (i, "admin-down"))
5940 admin_up = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005941 else
5942 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5943 sw_if_index_set = 1;
5944 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5945 sw_if_index_set = 1;
5946 else
5947 break;
5948 }
5949
5950 if (sw_if_index_set == 0)
5951 {
5952 errmsg ("missing interface name or sw_if_index");
5953 return -99;
5954 }
5955
5956 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005957 M (SW_INTERFACE_SET_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005958 mp->sw_if_index = ntohl (sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +01005959 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005960
5961 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005962 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005963
5964 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06005965 W (ret);
5966 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005967}
5968
5969static int
Stevenad8015b2017-10-29 22:10:46 -07005970api_sw_interface_set_rx_mode (vat_main_t * vam)
5971{
5972 unformat_input_t *i = vam->input;
5973 vl_api_sw_interface_set_rx_mode_t *mp;
5974 u32 sw_if_index;
5975 u8 sw_if_index_set = 0;
5976 int ret;
5977 u8 queue_id_valid = 0;
5978 u32 queue_id;
5979 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
5980
5981 /* Parse args required to build the message */
5982 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5983 {
5984 if (unformat (i, "queue %d", &queue_id))
5985 queue_id_valid = 1;
5986 else if (unformat (i, "polling"))
5987 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
5988 else if (unformat (i, "interrupt"))
5989 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
5990 else if (unformat (i, "adaptive"))
5991 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
5992 else
5993 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5994 sw_if_index_set = 1;
5995 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5996 sw_if_index_set = 1;
5997 else
5998 break;
5999 }
6000
6001 if (sw_if_index_set == 0)
6002 {
6003 errmsg ("missing interface name or sw_if_index");
6004 return -99;
6005 }
6006 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
6007 {
6008 errmsg ("missing rx-mode");
6009 return -99;
6010 }
6011
6012 /* Construct the API message */
6013 M (SW_INTERFACE_SET_RX_MODE, mp);
6014 mp->sw_if_index = ntohl (sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +01006015 mp->mode = (vl_api_rx_mode_t) mode;
Stevenad8015b2017-10-29 22:10:46 -07006016 mp->queue_id_valid = queue_id_valid;
6017 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
6018
6019 /* send it... */
6020 S (mp);
6021
6022 /* Wait for a reply, return the good/bad news... */
6023 W (ret);
6024 return ret;
6025}
6026
6027static int
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006028api_sw_interface_set_rx_placement (vat_main_t * vam)
6029{
6030 unformat_input_t *i = vam->input;
6031 vl_api_sw_interface_set_rx_placement_t *mp;
6032 u32 sw_if_index;
6033 u8 sw_if_index_set = 0;
6034 int ret;
6035 u8 is_main = 0;
6036 u32 queue_id, thread_index;
6037
6038 /* Parse args required to build the message */
6039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6040 {
6041 if (unformat (i, "queue %d", &queue_id))
6042 ;
6043 else if (unformat (i, "main"))
6044 is_main = 1;
6045 else if (unformat (i, "worker %d", &thread_index))
6046 ;
6047 else
6048 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6049 sw_if_index_set = 1;
6050 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6051 sw_if_index_set = 1;
6052 else
6053 break;
6054 }
6055
6056 if (sw_if_index_set == 0)
6057 {
6058 errmsg ("missing interface name or sw_if_index");
6059 return -99;
6060 }
6061
6062 if (is_main)
6063 thread_index = 0;
6064 /* Construct the API message */
6065 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
6066 mp->sw_if_index = ntohl (sw_if_index);
6067 mp->worker_id = ntohl (thread_index);
6068 mp->queue_id = ntohl (queue_id);
6069 mp->is_main = is_main;
6070
6071 /* send it... */
6072 S (mp);
6073 /* Wait for a reply, return the good/bad news... */
6074 W (ret);
6075 return ret;
6076}
6077
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02006078static void vl_api_sw_interface_rx_placement_details_t_handler
6079 (vl_api_sw_interface_rx_placement_details_t * mp)
6080{
6081 vat_main_t *vam = &vat_main;
6082 u32 worker_id = ntohl (mp->worker_id);
6083
6084 print (vam->ofp,
6085 "\n%-11d %-11s %-6d %-5d %-9s",
6086 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
6087 worker_id, ntohl (mp->queue_id),
6088 (mp->mode ==
6089 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
6090}
6091
6092static void vl_api_sw_interface_rx_placement_details_t_handler_json
6093 (vl_api_sw_interface_rx_placement_details_t * mp)
6094{
6095 vat_main_t *vam = &vat_main;
6096 vat_json_node_t *node = NULL;
6097
6098 if (VAT_JSON_ARRAY != vam->json_tree.type)
6099 {
6100 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6101 vat_json_init_array (&vam->json_tree);
6102 }
6103 node = vat_json_array_add (&vam->json_tree);
6104
6105 vat_json_init_object (node);
6106 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6107 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
6108 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
6109 vat_json_object_add_uint (node, "mode", mp->mode);
6110}
6111
6112static int
6113api_sw_interface_rx_placement_dump (vat_main_t * vam)
6114{
6115 unformat_input_t *i = vam->input;
6116 vl_api_sw_interface_rx_placement_dump_t *mp;
6117 vl_api_control_ping_t *mp_ping;
6118 int ret;
6119 u32 sw_if_index;
6120 u8 sw_if_index_set = 0;
6121
6122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6123 {
6124 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6125 sw_if_index_set++;
6126 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6127 sw_if_index_set++;
6128 else
6129 break;
6130 }
6131
6132 print (vam->ofp,
6133 "\n%-11s %-11s %-6s %-5s %-4s",
6134 "sw_if_index", "main/worker", "thread", "queue", "mode");
6135
6136 /* Dump Interface rx placement */
6137 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
6138
6139 if (sw_if_index_set)
6140 mp->sw_if_index = htonl (sw_if_index);
6141 else
6142 mp->sw_if_index = ~0;
6143
6144 S (mp);
6145
6146 /* Use a control ping for synchronization */
6147 MPING (CONTROL_PING, mp_ping);
6148 S (mp_ping);
6149
6150 W (ret);
6151 return ret;
6152}
6153
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006154static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006155api_sw_interface_clear_stats (vat_main_t * vam)
6156{
6157 unformat_input_t *i = vam->input;
6158 vl_api_sw_interface_clear_stats_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006159 u32 sw_if_index;
6160 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006161 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006162
6163 /* Parse args required to build the message */
6164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6165 {
6166 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6167 sw_if_index_set = 1;
6168 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6169 sw_if_index_set = 1;
6170 else
6171 break;
6172 }
6173
6174 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006175 M (SW_INTERFACE_CLEAR_STATS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006176
6177 if (sw_if_index_set == 1)
6178 mp->sw_if_index = ntohl (sw_if_index);
6179 else
6180 mp->sw_if_index = ~0;
6181
6182 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006183 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006184
6185 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006186 W (ret);
6187 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006188}
6189
Damjan Marion7cd468a2016-12-19 23:05:39 +01006190static int
6191api_sw_interface_add_del_address (vat_main_t * vam)
6192{
6193 unformat_input_t *i = vam->input;
6194 vl_api_sw_interface_add_del_address_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006195 u32 sw_if_index;
6196 u8 sw_if_index_set = 0;
6197 u8 is_add = 1, del_all = 0;
6198 u32 address_length = 0;
6199 u8 v4_address_set = 0;
6200 u8 v6_address_set = 0;
6201 ip4_address_t v4address;
6202 ip6_address_t v6address;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006203 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006204
6205 /* Parse args required to build the message */
6206 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6207 {
6208 if (unformat (i, "del-all"))
6209 del_all = 1;
6210 else if (unformat (i, "del"))
6211 is_add = 0;
6212 else
6213 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6214 sw_if_index_set = 1;
6215 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6216 sw_if_index_set = 1;
6217 else if (unformat (i, "%U/%d",
6218 unformat_ip4_address, &v4address, &address_length))
6219 v4_address_set = 1;
6220 else if (unformat (i, "%U/%d",
6221 unformat_ip6_address, &v6address, &address_length))
6222 v6_address_set = 1;
6223 else
6224 break;
6225 }
6226
6227 if (sw_if_index_set == 0)
6228 {
6229 errmsg ("missing interface name or sw_if_index");
6230 return -99;
6231 }
6232 if (v4_address_set && v6_address_set)
6233 {
6234 errmsg ("both v4 and v6 addresses set");
6235 return -99;
6236 }
6237 if (!v4_address_set && !v6_address_set && !del_all)
6238 {
6239 errmsg ("no addresses set");
6240 return -99;
6241 }
6242
6243 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006244 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006245
6246 mp->sw_if_index = ntohl (sw_if_index);
6247 mp->is_add = is_add;
6248 mp->del_all = del_all;
6249 if (v6_address_set)
6250 {
Jakub Grajciar053204a2019-03-18 13:17:53 +01006251 mp->prefix.address.af = ADDRESS_IP6;
6252 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006253 }
6254 else
6255 {
Jakub Grajciar053204a2019-03-18 13:17:53 +01006256 mp->prefix.address.af = ADDRESS_IP4;
6257 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006258 }
Jakub Grajciar053204a2019-03-18 13:17:53 +01006259 mp->prefix.len = address_length;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006260
6261 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006262 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006263
6264 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006265 W (ret);
6266 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006267}
6268
6269static int
6270api_sw_interface_set_mpls_enable (vat_main_t * vam)
6271{
6272 unformat_input_t *i = vam->input;
6273 vl_api_sw_interface_set_mpls_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006274 u32 sw_if_index;
6275 u8 sw_if_index_set = 0;
6276 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006277 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006278
6279 /* Parse args required to build the message */
6280 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6281 {
6282 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6283 sw_if_index_set = 1;
6284 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6285 sw_if_index_set = 1;
6286 else if (unformat (i, "disable"))
6287 enable = 0;
6288 else if (unformat (i, "dis"))
6289 enable = 0;
6290 else
6291 break;
6292 }
6293
6294 if (sw_if_index_set == 0)
6295 {
6296 errmsg ("missing interface name or sw_if_index");
6297 return -99;
6298 }
6299
6300 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006301 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006302
6303 mp->sw_if_index = ntohl (sw_if_index);
6304 mp->enable = enable;
6305
6306 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006307 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006308
6309 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006310 W (ret);
6311 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006312}
6313
6314static int
6315api_sw_interface_set_table (vat_main_t * vam)
6316{
6317 unformat_input_t *i = vam->input;
6318 vl_api_sw_interface_set_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006319 u32 sw_if_index, vrf_id = 0;
6320 u8 sw_if_index_set = 0;
6321 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006322 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006323
6324 /* Parse args required to build the message */
6325 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6326 {
6327 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6328 sw_if_index_set = 1;
6329 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6330 sw_if_index_set = 1;
6331 else if (unformat (i, "vrf %d", &vrf_id))
6332 ;
6333 else if (unformat (i, "ipv6"))
6334 is_ipv6 = 1;
6335 else
6336 break;
6337 }
6338
6339 if (sw_if_index_set == 0)
6340 {
6341 errmsg ("missing interface name or sw_if_index");
6342 return -99;
6343 }
6344
6345 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006346 M (SW_INTERFACE_SET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006347
6348 mp->sw_if_index = ntohl (sw_if_index);
6349 mp->is_ipv6 = is_ipv6;
6350 mp->vrf_id = ntohl (vrf_id);
6351
6352 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006353 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006354
6355 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006356 W (ret);
6357 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006358}
6359
6360static void vl_api_sw_interface_get_table_reply_t_handler
6361 (vl_api_sw_interface_get_table_reply_t * mp)
6362{
6363 vat_main_t *vam = &vat_main;
6364
6365 print (vam->ofp, "%d", ntohl (mp->vrf_id));
6366
6367 vam->retval = ntohl (mp->retval);
6368 vam->result_ready = 1;
6369
6370}
6371
6372static void vl_api_sw_interface_get_table_reply_t_handler_json
6373 (vl_api_sw_interface_get_table_reply_t * mp)
6374{
6375 vat_main_t *vam = &vat_main;
6376 vat_json_node_t node;
6377
6378 vat_json_init_object (&node);
6379 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
6380 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
6381
6382 vat_json_print (vam->ofp, &node);
6383 vat_json_free (&node);
6384
6385 vam->retval = ntohl (mp->retval);
6386 vam->result_ready = 1;
6387}
6388
6389static int
6390api_sw_interface_get_table (vat_main_t * vam)
6391{
6392 unformat_input_t *i = vam->input;
6393 vl_api_sw_interface_get_table_t *mp;
6394 u32 sw_if_index;
6395 u8 sw_if_index_set = 0;
6396 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006397 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006398
6399 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6400 {
6401 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6402 sw_if_index_set = 1;
6403 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6404 sw_if_index_set = 1;
6405 else if (unformat (i, "ipv6"))
6406 is_ipv6 = 1;
6407 else
6408 break;
6409 }
6410
6411 if (sw_if_index_set == 0)
6412 {
6413 errmsg ("missing interface name or sw_if_index");
6414 return -99;
6415 }
6416
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006417 M (SW_INTERFACE_GET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006418 mp->sw_if_index = htonl (sw_if_index);
6419 mp->is_ipv6 = is_ipv6;
6420
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006421 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006422 W (ret);
6423 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006424}
6425
6426static int
6427api_sw_interface_set_vpath (vat_main_t * vam)
6428{
6429 unformat_input_t *i = vam->input;
6430 vl_api_sw_interface_set_vpath_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006431 u32 sw_if_index = 0;
6432 u8 sw_if_index_set = 0;
6433 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006434 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006435
6436 /* Parse args required to build the message */
6437 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6438 {
6439 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6440 sw_if_index_set = 1;
6441 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6442 sw_if_index_set = 1;
6443 else if (unformat (i, "enable"))
6444 is_enable = 1;
6445 else if (unformat (i, "disable"))
6446 is_enable = 0;
6447 else
6448 break;
6449 }
6450
6451 if (sw_if_index_set == 0)
6452 {
6453 errmsg ("missing interface name or sw_if_index");
6454 return -99;
6455 }
6456
6457 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006458 M (SW_INTERFACE_SET_VPATH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006459
6460 mp->sw_if_index = ntohl (sw_if_index);
6461 mp->enable = is_enable;
6462
6463 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006464 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006465
6466 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006467 W (ret);
6468 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006469}
6470
6471static int
6472api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
6473{
6474 unformat_input_t *i = vam->input;
6475 vl_api_sw_interface_set_vxlan_bypass_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006476 u32 sw_if_index = 0;
6477 u8 sw_if_index_set = 0;
John Lo2b81eb82017-01-30 13:12:10 -05006478 u8 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006479 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006480 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006481
6482 /* Parse args required to build the message */
6483 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6484 {
6485 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6486 sw_if_index_set = 1;
6487 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6488 sw_if_index_set = 1;
6489 else if (unformat (i, "enable"))
6490 is_enable = 1;
6491 else if (unformat (i, "disable"))
6492 is_enable = 0;
6493 else if (unformat (i, "ip4"))
6494 is_ipv6 = 0;
6495 else if (unformat (i, "ip6"))
6496 is_ipv6 = 1;
6497 else
6498 break;
6499 }
6500
6501 if (sw_if_index_set == 0)
6502 {
6503 errmsg ("missing interface name or sw_if_index");
6504 return -99;
6505 }
6506
6507 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006508 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006509
6510 mp->sw_if_index = ntohl (sw_if_index);
6511 mp->enable = is_enable;
6512 mp->is_ipv6 = is_ipv6;
6513
6514 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006515 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006516
6517 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006518 W (ret);
6519 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006520}
6521
Marco Varleseb598f1d2017-09-19 14:25:28 +02006522static int
6523api_sw_interface_set_geneve_bypass (vat_main_t * vam)
6524{
6525 unformat_input_t *i = vam->input;
6526 vl_api_sw_interface_set_geneve_bypass_t *mp;
6527 u32 sw_if_index = 0;
6528 u8 sw_if_index_set = 0;
6529 u8 is_enable = 1;
6530 u8 is_ipv6 = 0;
6531 int ret;
6532
6533 /* Parse args required to build the message */
6534 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6535 {
6536 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6537 sw_if_index_set = 1;
6538 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6539 sw_if_index_set = 1;
6540 else if (unformat (i, "enable"))
6541 is_enable = 1;
6542 else if (unformat (i, "disable"))
6543 is_enable = 0;
6544 else if (unformat (i, "ip4"))
6545 is_ipv6 = 0;
6546 else if (unformat (i, "ip6"))
6547 is_ipv6 = 1;
6548 else
6549 break;
6550 }
6551
6552 if (sw_if_index_set == 0)
6553 {
6554 errmsg ("missing interface name or sw_if_index");
6555 return -99;
6556 }
6557
6558 /* Construct the API message */
6559 M (SW_INTERFACE_SET_GENEVE_BYPASS, mp);
6560
6561 mp->sw_if_index = ntohl (sw_if_index);
6562 mp->enable = is_enable;
6563 mp->is_ipv6 = is_ipv6;
6564
6565 /* send it... */
6566 S (mp);
6567
6568 /* Wait for a reply... */
6569 W (ret);
6570 return ret;
6571}
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08006572
Damjan Marion7cd468a2016-12-19 23:05:39 +01006573static int
6574api_sw_interface_set_l2_xconnect (vat_main_t * vam)
6575{
6576 unformat_input_t *i = vam->input;
6577 vl_api_sw_interface_set_l2_xconnect_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006578 u32 rx_sw_if_index;
6579 u8 rx_sw_if_index_set = 0;
6580 u32 tx_sw_if_index;
6581 u8 tx_sw_if_index_set = 0;
6582 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006583 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006584
6585 /* Parse args required to build the message */
6586 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6587 {
6588 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6589 rx_sw_if_index_set = 1;
6590 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6591 tx_sw_if_index_set = 1;
6592 else if (unformat (i, "rx"))
6593 {
6594 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6595 {
6596 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6597 &rx_sw_if_index))
6598 rx_sw_if_index_set = 1;
6599 }
6600 else
6601 break;
6602 }
6603 else if (unformat (i, "tx"))
6604 {
6605 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6606 {
6607 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6608 &tx_sw_if_index))
6609 tx_sw_if_index_set = 1;
6610 }
6611 else
6612 break;
6613 }
6614 else if (unformat (i, "enable"))
6615 enable = 1;
6616 else if (unformat (i, "disable"))
6617 enable = 0;
6618 else
6619 break;
6620 }
6621
6622 if (rx_sw_if_index_set == 0)
6623 {
6624 errmsg ("missing rx interface name or rx_sw_if_index");
6625 return -99;
6626 }
6627
6628 if (enable && (tx_sw_if_index_set == 0))
6629 {
6630 errmsg ("missing tx interface name or tx_sw_if_index");
6631 return -99;
6632 }
6633
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006634 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006635
6636 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6637 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6638 mp->enable = enable;
6639
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006640 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006641 W (ret);
6642 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006643}
6644
6645static int
6646api_sw_interface_set_l2_bridge (vat_main_t * vam)
6647{
6648 unformat_input_t *i = vam->input;
6649 vl_api_sw_interface_set_l2_bridge_t *mp;
Neale Rannsb4743802018-09-05 09:13:57 -07006650 vl_api_l2_port_type_t port_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006651 u32 rx_sw_if_index;
6652 u8 rx_sw_if_index_set = 0;
6653 u32 bd_id;
6654 u8 bd_id_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006655 u32 shg = 0;
6656 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006657 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006658
Neale Rannsb4743802018-09-05 09:13:57 -07006659 port_type = L2_API_PORT_TYPE_NORMAL;
6660
Damjan Marion7cd468a2016-12-19 23:05:39 +01006661 /* Parse args required to build the message */
6662 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6663 {
6664 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
6665 rx_sw_if_index_set = 1;
6666 else if (unformat (i, "bd_id %d", &bd_id))
6667 bd_id_set = 1;
6668 else
6669 if (unformat
6670 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
6671 rx_sw_if_index_set = 1;
6672 else if (unformat (i, "shg %d", &shg))
6673 ;
6674 else if (unformat (i, "bvi"))
Neale Rannsb4743802018-09-05 09:13:57 -07006675 port_type = L2_API_PORT_TYPE_BVI;
6676 else if (unformat (i, "uu-fwd"))
6677 port_type = L2_API_PORT_TYPE_UU_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006678 else if (unformat (i, "enable"))
6679 enable = 1;
6680 else if (unformat (i, "disable"))
6681 enable = 0;
6682 else
6683 break;
6684 }
6685
6686 if (rx_sw_if_index_set == 0)
6687 {
6688 errmsg ("missing rx interface name or sw_if_index");
6689 return -99;
6690 }
6691
6692 if (enable && (bd_id_set == 0))
6693 {
6694 errmsg ("missing bridge domain");
6695 return -99;
6696 }
6697
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006698 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006699
6700 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6701 mp->bd_id = ntohl (bd_id);
6702 mp->shg = (u8) shg;
Neale Rannsb4743802018-09-05 09:13:57 -07006703 mp->port_type = ntohl (port_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006704 mp->enable = enable;
6705
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006706 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006707 W (ret);
6708 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006709}
6710
6711static int
6712api_bridge_domain_dump (vat_main_t * vam)
6713{
6714 unformat_input_t *i = vam->input;
6715 vl_api_bridge_domain_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006716 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006717 u32 bd_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006718 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006719
6720 /* Parse args required to build the message */
6721 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6722 {
6723 if (unformat (i, "bd_id %d", &bd_id))
6724 ;
6725 else
6726 break;
6727 }
6728
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006729 M (BRIDGE_DOMAIN_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006730 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006731 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006732
6733 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04006734 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006735 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006736
Jon Loeliger56c7b012017-02-01 12:31:41 -06006737 W (ret);
6738 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006739}
6740
6741static int
6742api_bridge_domain_add_del (vat_main_t * vam)
6743{
6744 unformat_input_t *i = vam->input;
6745 vl_api_bridge_domain_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006746 u32 bd_id = ~0;
6747 u8 is_add = 1;
6748 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006749 u8 *bd_tag = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006750 u32 mac_age = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006751 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006752
6753 /* Parse args required to build the message */
6754 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6755 {
6756 if (unformat (i, "bd_id %d", &bd_id))
6757 ;
6758 else if (unformat (i, "flood %d", &flood))
6759 ;
6760 else if (unformat (i, "uu-flood %d", &uu_flood))
6761 ;
6762 else if (unformat (i, "forward %d", &forward))
6763 ;
6764 else if (unformat (i, "learn %d", &learn))
6765 ;
6766 else if (unformat (i, "arp-term %d", &arp_term))
6767 ;
6768 else if (unformat (i, "mac-age %d", &mac_age))
6769 ;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006770 else if (unformat (i, "bd-tag %s", &bd_tag))
6771 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006772 else if (unformat (i, "del"))
6773 {
6774 is_add = 0;
6775 flood = uu_flood = forward = learn = 0;
6776 }
6777 else
6778 break;
6779 }
6780
6781 if (bd_id == ~0)
6782 {
6783 errmsg ("missing bridge domain");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006784 ret = -99;
6785 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006786 }
6787
6788 if (mac_age > 255)
6789 {
6790 errmsg ("mac age must be less than 256 ");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006791 ret = -99;
6792 goto done;
6793 }
6794
John Lo70bfcaf2017-11-14 13:19:26 -05006795 if ((bd_tag) && (vec_len (bd_tag) > 63))
Jerome Tollet50570ec2017-09-14 12:53:56 +01006796 {
6797 errmsg ("bd-tag cannot be longer than 63");
6798 ret = -99;
6799 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006800 }
6801
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006802 M (BRIDGE_DOMAIN_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006803
6804 mp->bd_id = ntohl (bd_id);
6805 mp->flood = flood;
6806 mp->uu_flood = uu_flood;
6807 mp->forward = forward;
6808 mp->learn = learn;
6809 mp->arp_term = arp_term;
6810 mp->is_add = is_add;
6811 mp->mac_age = (u8) mac_age;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006812 if (bd_tag)
John Lo70bfcaf2017-11-14 13:19:26 -05006813 {
6814 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
6815 mp->bd_tag[vec_len (bd_tag)] = 0;
6816 }
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006817 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006818 W (ret);
Jerome Tollet50570ec2017-09-14 12:53:56 +01006819
6820done:
6821 vec_free (bd_tag);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006822 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006823}
6824
6825static int
Eyal Barif24991c2017-04-05 05:33:21 +03006826api_l2fib_flush_bd (vat_main_t * vam)
6827{
6828 unformat_input_t *i = vam->input;
6829 vl_api_l2fib_flush_bd_t *mp;
6830 u32 bd_id = ~0;
6831 int ret;
6832
6833 /* Parse args required to build the message */
6834 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6835 {
6836 if (unformat (i, "bd_id %d", &bd_id));
6837 else
6838 break;
6839 }
6840
6841 if (bd_id == ~0)
6842 {
6843 errmsg ("missing bridge domain");
6844 return -99;
6845 }
6846
6847 M (L2FIB_FLUSH_BD, mp);
6848
6849 mp->bd_id = htonl (bd_id);
6850
6851 S (mp);
6852 W (ret);
6853 return ret;
6854}
6855
6856static int
6857api_l2fib_flush_int (vat_main_t * vam)
6858{
6859 unformat_input_t *i = vam->input;
6860 vl_api_l2fib_flush_int_t *mp;
6861 u32 sw_if_index = ~0;
6862 int ret;
6863
6864 /* Parse args required to build the message */
6865 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6866 {
6867 if (unformat (i, "sw_if_index %d", &sw_if_index));
6868 else
6869 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
6870 else
6871 break;
6872 }
6873
6874 if (sw_if_index == ~0)
6875 {
6876 errmsg ("missing interface name or sw_if_index");
6877 return -99;
6878 }
6879
6880 M (L2FIB_FLUSH_INT, mp);
6881
6882 mp->sw_if_index = ntohl (sw_if_index);
6883
6884 S (mp);
6885 W (ret);
6886 return ret;
6887}
6888
6889static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006890api_l2fib_add_del (vat_main_t * vam)
6891{
6892 unformat_input_t *i = vam->input;
6893 vl_api_l2fib_add_del_t *mp;
6894 f64 timeout;
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006895 u8 mac[6] = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01006896 u8 mac_set = 0;
6897 u32 bd_id;
6898 u8 bd_id_set = 0;
John Lo7dbd7262018-05-31 10:25:18 -04006899 u32 sw_if_index = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006900 u8 sw_if_index_set = 0;
6901 u8 is_add = 1;
6902 u8 static_mac = 0;
6903 u8 filter_mac = 0;
6904 u8 bvi_mac = 0;
6905 int count = 1;
6906 f64 before = 0;
6907 int j;
6908
6909 /* Parse args required to build the message */
6910 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6911 {
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006912 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01006913 mac_set = 1;
6914 else if (unformat (i, "bd_id %d", &bd_id))
6915 bd_id_set = 1;
6916 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6917 sw_if_index_set = 1;
6918 else if (unformat (i, "sw_if"))
6919 {
6920 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6921 {
6922 if (unformat
6923 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6924 sw_if_index_set = 1;
6925 }
6926 else
6927 break;
6928 }
6929 else if (unformat (i, "static"))
6930 static_mac = 1;
6931 else if (unformat (i, "filter"))
6932 {
6933 filter_mac = 1;
6934 static_mac = 1;
6935 }
6936 else if (unformat (i, "bvi"))
6937 {
6938 bvi_mac = 1;
6939 static_mac = 1;
6940 }
6941 else if (unformat (i, "del"))
6942 is_add = 0;
6943 else if (unformat (i, "count %d", &count))
6944 ;
6945 else
6946 break;
6947 }
6948
6949 if (mac_set == 0)
6950 {
6951 errmsg ("missing mac address");
6952 return -99;
6953 }
6954
6955 if (bd_id_set == 0)
6956 {
6957 errmsg ("missing bridge domain");
6958 return -99;
6959 }
6960
6961 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
6962 {
6963 errmsg ("missing interface name or sw_if_index");
6964 return -99;
6965 }
6966
6967 if (count > 1)
6968 {
6969 /* Turn on async mode */
6970 vam->async_mode = 1;
6971 vam->async_errors = 0;
6972 before = vat_time_now (vam);
6973 }
6974
6975 for (j = 0; j < count; j++)
6976 {
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006977 M (L2FIB_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006978
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006979 clib_memcpy (mp->mac, mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006980 mp->bd_id = ntohl (bd_id);
6981 mp->is_add = is_add;
John Lo7dbd7262018-05-31 10:25:18 -04006982 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006983
6984 if (is_add)
6985 {
Damjan Marion7cd468a2016-12-19 23:05:39 +01006986 mp->static_mac = static_mac;
6987 mp->filter_mac = filter_mac;
6988 mp->bvi_mac = bvi_mac;
6989 }
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006990 increment_mac_address (mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006991 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006992 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006993 }
6994
6995 if (count > 1)
6996 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006997 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006998 f64 after;
6999
7000 /* Shut off async mode */
7001 vam->async_mode = 0;
7002
Dave Barach59b25652017-09-10 15:04:27 -04007003 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06007004 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007005
7006 timeout = vat_time_now (vam) + 1.0;
7007 while (vat_time_now (vam) < timeout)
7008 if (vam->result_ready == 1)
7009 goto out;
7010 vam->retval = -99;
7011
7012 out:
7013 if (vam->retval == -99)
7014 errmsg ("timeout");
7015
7016 if (vam->async_errors > 0)
7017 {
7018 errmsg ("%d asynchronous errors", vam->async_errors);
7019 vam->retval = -98;
7020 }
7021 vam->async_errors = 0;
7022 after = vat_time_now (vam);
7023
7024 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
7025 count, after - before, count / (after - before));
7026 }
7027 else
7028 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06007029 int ret;
7030
Damjan Marion7cd468a2016-12-19 23:05:39 +01007031 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06007032 W (ret);
7033 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007034 }
7035 /* Return the good/bad news */
7036 return (vam->retval);
7037}
7038
7039static int
Eyal Barifead6702017-04-04 04:46:32 +03007040api_bridge_domain_set_mac_age (vat_main_t * vam)
7041{
7042 unformat_input_t *i = vam->input;
7043 vl_api_bridge_domain_set_mac_age_t *mp;
7044 u32 bd_id = ~0;
7045 u32 mac_age = 0;
7046 int ret;
7047
7048 /* Parse args required to build the message */
7049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7050 {
7051 if (unformat (i, "bd_id %d", &bd_id));
7052 else if (unformat (i, "mac-age %d", &mac_age));
7053 else
7054 break;
7055 }
7056
7057 if (bd_id == ~0)
7058 {
7059 errmsg ("missing bridge domain");
7060 return -99;
7061 }
7062
7063 if (mac_age > 255)
7064 {
7065 errmsg ("mac age must be less than 256 ");
7066 return -99;
7067 }
7068
7069 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
7070
7071 mp->bd_id = htonl (bd_id);
7072 mp->mac_age = (u8) mac_age;
7073
7074 S (mp);
7075 W (ret);
7076 return ret;
7077}
7078
7079static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01007080api_l2_flags (vat_main_t * vam)
7081{
7082 unformat_input_t *i = vam->input;
7083 vl_api_l2_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007084 u32 sw_if_index;
John Lo8d00fff2017-08-03 00:35:36 -04007085 u32 flags = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007086 u8 sw_if_index_set = 0;
John Lo8d00fff2017-08-03 00:35:36 -04007087 u8 is_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007088 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007089
7090 /* Parse args required to build the message */
7091 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7092 {
7093 if (unformat (i, "sw_if_index %d", &sw_if_index))
7094 sw_if_index_set = 1;
7095 else if (unformat (i, "sw_if"))
7096 {
7097 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7098 {
7099 if (unformat
7100 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7101 sw_if_index_set = 1;
7102 }
7103 else
7104 break;
7105 }
7106 else if (unformat (i, "learn"))
John Lo8d00fff2017-08-03 00:35:36 -04007107 flags |= L2_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007108 else if (unformat (i, "forward"))
John Lo8d00fff2017-08-03 00:35:36 -04007109 flags |= L2_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007110 else if (unformat (i, "flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007111 flags |= L2_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007112 else if (unformat (i, "uu-flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007113 flags |= L2_UU_FLOOD;
7114 else if (unformat (i, "arp-term"))
7115 flags |= L2_ARP_TERM;
7116 else if (unformat (i, "off"))
7117 is_set = 0;
7118 else if (unformat (i, "disable"))
7119 is_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007120 else
7121 break;
7122 }
7123
7124 if (sw_if_index_set == 0)
7125 {
7126 errmsg ("missing interface name or sw_if_index");
7127 return -99;
7128 }
7129
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007130 M (L2_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007131
7132 mp->sw_if_index = ntohl (sw_if_index);
John Lo8d00fff2017-08-03 00:35:36 -04007133 mp->feature_bitmap = ntohl (flags);
7134 mp->is_set = is_set;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007135
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007136 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007137 W (ret);
7138 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007139}
7140
7141static int
7142api_bridge_flags (vat_main_t * vam)
7143{
7144 unformat_input_t *i = vam->input;
7145 vl_api_bridge_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007146 u32 bd_id;
7147 u8 bd_id_set = 0;
7148 u8 is_set = 1;
Neale Rannsb4743802018-09-05 09:13:57 -07007149 bd_flags_t flags = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007150 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007151
7152 /* Parse args required to build the message */
7153 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7154 {
7155 if (unformat (i, "bd_id %d", &bd_id))
7156 bd_id_set = 1;
7157 else if (unformat (i, "learn"))
Neale Rannsb4743802018-09-05 09:13:57 -07007158 flags |= BRIDGE_API_FLAG_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007159 else if (unformat (i, "forward"))
Neale Rannsb4743802018-09-05 09:13:57 -07007160 flags |= BRIDGE_API_FLAG_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007161 else if (unformat (i, "flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007162 flags |= BRIDGE_API_FLAG_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007163 else if (unformat (i, "uu-flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007164 flags |= BRIDGE_API_FLAG_UU_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007165 else if (unformat (i, "arp-term"))
Neale Rannsb4743802018-09-05 09:13:57 -07007166 flags |= BRIDGE_API_FLAG_ARP_TERM;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007167 else if (unformat (i, "off"))
7168 is_set = 0;
7169 else if (unformat (i, "disable"))
7170 is_set = 0;
7171 else
7172 break;
7173 }
7174
7175 if (bd_id_set == 0)
7176 {
7177 errmsg ("missing bridge domain");
7178 return -99;
7179 }
7180
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007181 M (BRIDGE_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007182
7183 mp->bd_id = ntohl (bd_id);
Neale Rannsb4743802018-09-05 09:13:57 -07007184 mp->flags = ntohl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007185 mp->is_set = is_set;
7186
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007187 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007188 W (ret);
7189 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007190}
7191
7192static int
7193api_bd_ip_mac_add_del (vat_main_t * vam)
7194{
Neale Ranns4d5b9172018-10-24 02:57:49 -07007195 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
Ole Troan8006c6a2018-12-17 12:02:26 +01007196 vl_api_mac_address_t mac = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01007197 unformat_input_t *i = vam->input;
7198 vl_api_bd_ip_mac_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007199 u32 bd_id;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007200 u8 is_add = 1;
7201 u8 bd_id_set = 0;
7202 u8 ip_set = 0;
7203 u8 mac_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007204 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007205
7206
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 {
7212 bd_id_set++;
7213 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007214 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007215 {
7216 ip_set++;
7217 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007218 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007219 {
7220 mac_set++;
7221 }
7222 else if (unformat (i, "del"))
7223 is_add = 0;
7224 else
7225 break;
7226 }
7227
7228 if (bd_id_set == 0)
7229 {
7230 errmsg ("missing bridge domain");
7231 return -99;
7232 }
7233 else if (ip_set == 0)
7234 {
7235 errmsg ("missing IP address");
7236 return -99;
7237 }
7238 else if (mac_set == 0)
7239 {
7240 errmsg ("missing MAC address");
7241 return -99;
7242 }
7243
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007244 M (BD_IP_MAC_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007245
Neale Rannsbc764c82019-06-19 07:07:13 -07007246 mp->entry.bd_id = ntohl (bd_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007247 mp->is_add = is_add;
Neale Ranns4d5b9172018-10-24 02:57:49 -07007248
Neale Rannsbc764c82019-06-19 07:07:13 -07007249 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
7250 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
Neale Ranns4d5b9172018-10-24 02:57:49 -07007251
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007252 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007253 W (ret);
7254 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007255}
7256
John Loe26c81f2019-01-07 15:16:33 -05007257static int
7258api_bd_ip_mac_flush (vat_main_t * vam)
7259{
7260 unformat_input_t *i = vam->input;
7261 vl_api_bd_ip_mac_flush_t *mp;
7262 u32 bd_id;
7263 u8 bd_id_set = 0;
7264 int ret;
7265
7266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7267 {
7268 if (unformat (i, "bd_id %d", &bd_id))
7269 {
7270 bd_id_set++;
7271 }
7272 else
7273 break;
7274 }
7275
7276 if (bd_id_set == 0)
7277 {
7278 errmsg ("missing bridge domain");
7279 return -99;
7280 }
7281
7282 M (BD_IP_MAC_FLUSH, mp);
7283
7284 mp->bd_id = ntohl (bd_id);
7285
7286 S (mp);
7287 W (ret);
7288 return ret;
7289}
7290
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007291static void vl_api_bd_ip_mac_details_t_handler
7292 (vl_api_bd_ip_mac_details_t * mp)
7293{
7294 vat_main_t *vam = &vat_main;
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007295
7296 print (vam->ofp,
Neale Rannsbc764c82019-06-19 07:07:13 -07007297 "\n%-5d %U %U",
7298 ntohl (mp->entry.bd_id),
7299 format_vl_api_mac_address, mp->entry.mac,
7300 format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007301}
7302
7303static void vl_api_bd_ip_mac_details_t_handler_json
7304 (vl_api_bd_ip_mac_details_t * mp)
7305{
7306 vat_main_t *vam = &vat_main;
7307 vat_json_node_t *node = NULL;
7308
7309 if (VAT_JSON_ARRAY != vam->json_tree.type)
7310 {
7311 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7312 vat_json_init_array (&vam->json_tree);
7313 }
7314 node = vat_json_array_add (&vam->json_tree);
7315
7316 vat_json_init_object (node);
Neale Rannsbc764c82019-06-19 07:07:13 -07007317 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007318 vat_json_object_add_string_copy (node, "mac_address",
Neale Rannsbc764c82019-06-19 07:07:13 -07007319 format (0, "%U", format_vl_api_mac_address,
7320 &mp->entry.mac));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007321 u8 *ip = 0;
7322
Neale Rannsbc764c82019-06-19 07:07:13 -07007323 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007324 vat_json_object_add_string_copy (node, "ip_address", ip);
7325 vec_free (ip);
7326}
7327
7328static int
7329api_bd_ip_mac_dump (vat_main_t * vam)
7330{
7331 unformat_input_t *i = vam->input;
7332 vl_api_bd_ip_mac_dump_t *mp;
7333 vl_api_control_ping_t *mp_ping;
7334 int ret;
7335 u32 bd_id;
7336 u8 bd_id_set = 0;
7337
7338 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7339 {
7340 if (unformat (i, "bd_id %d", &bd_id))
7341 {
7342 bd_id_set++;
7343 }
7344 else
7345 break;
7346 }
7347
7348 print (vam->ofp,
7349 "\n%-5s %-7s %-20s %-30s",
7350 "bd_id", "is_ipv6", "mac_address", "ip_address");
7351
7352 /* Dump Bridge Domain Ip to Mac entries */
7353 M (BD_IP_MAC_DUMP, mp);
7354
7355 if (bd_id_set)
7356 mp->bd_id = htonl (bd_id);
7357 else
7358 mp->bd_id = ~0;
7359
7360 S (mp);
7361
7362 /* Use a control ping for synchronization */
7363 MPING (CONTROL_PING, mp_ping);
7364 S (mp_ping);
7365
7366 W (ret);
7367 return ret;
7368}
7369
Damjan Marion7cd468a2016-12-19 23:05:39 +01007370static int
Damjan Marion8389fb92017-10-13 18:29:53 +02007371api_tap_create_v2 (vat_main_t * vam)
7372{
7373 unformat_input_t *i = vam->input;
7374 vl_api_tap_create_v2_t *mp;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007375#define TAP_FLAG_GSO (1 << 0)
Damjan Marion8389fb92017-10-13 18:29:53 +02007376 u8 mac_address[6];
7377 u8 random_mac = 1;
Damjan Marion2df39092017-12-04 20:03:37 +01007378 u32 id = ~0;
7379 u8 *host_if_name = 0;
7380 u8 *host_ns = 0;
7381 u8 host_mac_addr[6];
7382 u8 host_mac_addr_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007383 u8 *host_bridge = 0;
7384 ip4_address_t host_ip4_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007385 ip4_address_t host_ip4_gw;
7386 u8 host_ip4_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007387 u32 host_ip4_prefix_len = 0;
7388 ip6_address_t host_ip6_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007389 ip6_address_t host_ip6_gw;
7390 u8 host_ip6_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007391 u32 host_ip6_prefix_len = 0;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007392 u8 host_mtu_set = 0;
7393 u32 host_mtu_size = 0;
7394 u32 tap_flags = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007395 int ret;
Steven9e635692018-03-01 09:36:01 -08007396 u32 rx_ring_sz = 0, tx_ring_sz = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007397
Dave Barachb7b92992018-10-17 10:38:51 -04007398 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion8389fb92017-10-13 18:29:53 +02007399
7400 /* Parse args required to build the message */
7401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7402 {
7403 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7404 {
7405 random_mac = 0;
7406 }
Steven9e635692018-03-01 09:36:01 -08007407 else if (unformat (i, "id %u", &id))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007408 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007409 else if (unformat (i, "host-if-name %s", &host_if_name))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007410 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007411 else if (unformat (i, "host-ns %s", &host_ns))
7412 ;
7413 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
7414 host_mac_addr))
7415 host_mac_addr_set = 1;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007416 else if (unformat (i, "host-bridge %s", &host_bridge))
7417 ;
7418 else if (unformat (i, "host-ip4-addr %U/%d", unformat_ip4_address,
7419 &host_ip4_addr, &host_ip4_prefix_len))
7420 ;
7421 else if (unformat (i, "host-ip6-addr %U/%d", unformat_ip6_address,
7422 &host_ip6_addr, &host_ip6_prefix_len))
7423 ;
Damjan Marion7866c452018-01-18 13:35:11 +01007424 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
7425 &host_ip4_gw))
7426 host_ip4_gw_set = 1;
7427 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
7428 &host_ip6_gw))
7429 host_ip6_gw_set = 1;
Damjan Marion8389fb92017-10-13 18:29:53 +02007430 else if (unformat (i, "rx-ring-size %d", &rx_ring_sz))
7431 ;
7432 else if (unformat (i, "tx-ring-size %d", &tx_ring_sz))
7433 ;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007434 else if (unformat (i, "host-mtu-size %d", &host_mtu_size))
7435 host_mtu_set = 1;
7436 else if (unformat (i, "no-gso"))
7437 tap_flags &= ~TAP_FLAG_GSO;
7438 else if (unformat (i, "gso"))
7439 tap_flags |= TAP_FLAG_GSO;
Damjan Marion8389fb92017-10-13 18:29:53 +02007440 else
7441 break;
7442 }
7443
Damjan Marion2df39092017-12-04 20:03:37 +01007444 if (vec_len (host_if_name) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007445 {
7446 errmsg ("tap name too long. ");
7447 return -99;
7448 }
Damjan Marion2df39092017-12-04 20:03:37 +01007449 if (vec_len (host_ns) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007450 {
7451 errmsg ("host name space too long. ");
7452 return -99;
7453 }
Damjan Marion91c6ef72017-12-01 13:34:24 +01007454 if (vec_len (host_bridge) > 63)
7455 {
7456 errmsg ("host bridge name too long. ");
7457 return -99;
7458 }
7459 if (host_ip4_prefix_len > 32)
7460 {
7461 errmsg ("host ip4 prefix length not valid. ");
7462 return -99;
7463 }
7464 if (host_ip6_prefix_len > 128)
7465 {
7466 errmsg ("host ip6 prefix length not valid. ");
7467 return -99;
7468 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007469 if (!is_pow2 (rx_ring_sz))
7470 {
7471 errmsg ("rx ring size must be power of 2. ");
7472 return -99;
7473 }
7474 if (rx_ring_sz > 32768)
7475 {
7476 errmsg ("rx ring size must be 32768 or lower. ");
7477 return -99;
7478 }
7479 if (!is_pow2 (tx_ring_sz))
7480 {
7481 errmsg ("tx ring size must be power of 2. ");
7482 return -99;
7483 }
7484 if (tx_ring_sz > 32768)
7485 {
7486 errmsg ("tx ring size must be 32768 or lower. ");
7487 return -99;
7488 }
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007489 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
7490 {
7491 errmsg ("host MTU size must be in between 64 and 65355. ");
7492 return -99;
7493 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007494
Damjan Marion8389fb92017-10-13 18:29:53 +02007495 /* Construct the API message */
7496 M (TAP_CREATE_V2, mp);
7497
7498 mp->use_random_mac = random_mac;
Damjan Marion2df39092017-12-04 20:03:37 +01007499
Steven9e635692018-03-01 09:36:01 -08007500 mp->id = ntohl (id);
Damjan Marion2df39092017-12-04 20:03:37 +01007501 mp->host_namespace_set = host_ns != 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007502 mp->host_bridge_set = host_bridge != 0;
7503 mp->host_ip4_addr_set = host_ip4_prefix_len != 0;
7504 mp->host_ip6_addr_set = host_ip6_prefix_len != 0;
Steven9e635692018-03-01 09:36:01 -08007505 mp->rx_ring_sz = ntohs (rx_ring_sz);
7506 mp->tx_ring_sz = ntohs (tx_ring_sz);
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007507 mp->host_mtu_set = host_mtu_set;
7508 mp->host_mtu_size = ntohl (host_mtu_size);
7509 mp->tap_flags = ntohl (tap_flags);
Damjan Marion2df39092017-12-04 20:03:37 +01007510
Steven9e635692018-03-01 09:36:01 -08007511 if (random_mac == 0)
Damjan Marion2df39092017-12-04 20:03:37 +01007512 clib_memcpy (mp->mac_address, mac_address, 6);
7513 if (host_mac_addr_set)
7514 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
7515 if (host_if_name)
7516 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
7517 if (host_ns)
7518 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
Damjan Marion91c6ef72017-12-01 13:34:24 +01007519 if (host_bridge)
7520 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
7521 if (host_ip4_prefix_len)
7522 clib_memcpy (mp->host_ip4_addr, &host_ip4_addr, 4);
Michal Cmarada87460d02018-10-17 13:40:32 +02007523 if (host_ip6_prefix_len)
Damjan Marion91c6ef72017-12-01 13:34:24 +01007524 clib_memcpy (mp->host_ip6_addr, &host_ip6_addr, 16);
Damjan Marion7866c452018-01-18 13:35:11 +01007525 if (host_ip4_gw_set)
7526 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
7527 if (host_ip6_gw_set)
7528 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
Damjan Marion8389fb92017-10-13 18:29:53 +02007529
Damjan Marion2df39092017-12-04 20:03:37 +01007530 vec_free (host_ns);
7531 vec_free (host_if_name);
7532 vec_free (host_bridge);
Damjan Marion8389fb92017-10-13 18:29:53 +02007533
7534 /* send it... */
7535 S (mp);
7536
7537 /* Wait for a reply... */
7538 W (ret);
7539 return ret;
7540}
7541
7542static int
7543api_tap_delete_v2 (vat_main_t * vam)
7544{
7545 unformat_input_t *i = vam->input;
7546 vl_api_tap_delete_v2_t *mp;
7547 u32 sw_if_index = ~0;
7548 u8 sw_if_index_set = 0;
7549 int ret;
7550
7551 /* Parse args required to build the message */
7552 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7553 {
7554 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7555 sw_if_index_set = 1;
7556 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7557 sw_if_index_set = 1;
7558 else
7559 break;
7560 }
7561
7562 if (sw_if_index_set == 0)
7563 {
7564 errmsg ("missing vpp interface name. ");
7565 return -99;
7566 }
7567
7568 /* Construct the API message */
7569 M (TAP_DELETE_V2, mp);
7570
7571 mp->sw_if_index = ntohl (sw_if_index);
7572
7573 /* send it... */
7574 S (mp);
7575
7576 /* Wait for a reply... */
7577 W (ret);
7578 return ret;
7579}
7580
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007581uword
jialv01082ebeb2019-09-10 00:23:55 +08007582unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007583{
jialv01082ebeb2019-09-10 00:23:55 +08007584 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007585 u32 x[4];
7586
7587 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
7588 return 0;
7589
7590 addr->domain = x[0];
7591 addr->bus = x[1];
7592 addr->slot = x[2];
7593 addr->function = x[3];
7594
7595 return 1;
7596}
7597
7598static int
7599api_virtio_pci_create (vat_main_t * vam)
7600{
7601 unformat_input_t *i = vam->input;
7602 vl_api_virtio_pci_create_t *mp;
7603 u8 mac_address[6];
7604 u8 random_mac = 1;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007605 u8 gso_enabled = 0;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007606 u32 pci_addr = 0;
7607 u64 features = (u64) ~ (0ULL);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007608 int ret;
7609
7610 clib_memset (mac_address, 0, sizeof (mac_address));
7611
7612 /* Parse args required to build the message */
7613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7614 {
7615 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7616 {
7617 random_mac = 0;
7618 }
jialv01082ebeb2019-09-10 00:23:55 +08007619 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007620 ;
7621 else if (unformat (i, "features 0x%llx", &features))
7622 ;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007623 else if (unformat (i, "gso-enabled"))
7624 gso_enabled = 1;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007625 else
7626 break;
7627 }
7628
7629 if (pci_addr == 0)
7630 {
7631 errmsg ("pci address must be non zero. ");
7632 return -99;
7633 }
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007634
7635 /* Construct the API message */
7636 M (VIRTIO_PCI_CREATE, mp);
7637
7638 mp->use_random_mac = random_mac;
7639
7640 mp->pci_addr = htonl (pci_addr);
7641 mp->features = clib_host_to_net_u64 (features);
Benoît Ganne49ee6842019-04-30 11:50:46 +02007642 mp->gso_enabled = gso_enabled;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007643
7644 if (random_mac == 0)
7645 clib_memcpy (mp->mac_address, mac_address, 6);
7646
7647 /* send it... */
7648 S (mp);
7649
7650 /* Wait for a reply... */
7651 W (ret);
7652 return ret;
7653}
7654
7655static int
7656api_virtio_pci_delete (vat_main_t * vam)
7657{
7658 unformat_input_t *i = vam->input;
7659 vl_api_virtio_pci_delete_t *mp;
7660 u32 sw_if_index = ~0;
7661 u8 sw_if_index_set = 0;
7662 int ret;
7663
7664 /* Parse args required to build the message */
7665 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7666 {
7667 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7668 sw_if_index_set = 1;
7669 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7670 sw_if_index_set = 1;
7671 else
7672 break;
7673 }
7674
7675 if (sw_if_index_set == 0)
7676 {
7677 errmsg ("missing vpp interface name. ");
7678 return -99;
7679 }
7680
7681 /* Construct the API message */
7682 M (VIRTIO_PCI_DELETE, mp);
7683
7684 mp->sw_if_index = htonl (sw_if_index);
7685
7686 /* send it... */
7687 S (mp);
7688
7689 /* Wait for a reply... */
7690 W (ret);
7691 return ret;
7692}
7693
Damjan Marion8389fb92017-10-13 18:29:53 +02007694static int
Steven9cd2d7a2017-12-20 12:43:01 -08007695api_bond_create (vat_main_t * vam)
7696{
7697 unformat_input_t *i = vam->input;
7698 vl_api_bond_create_t *mp;
7699 u8 mac_address[6];
7700 u8 custom_mac = 0;
7701 int ret;
7702 u8 mode;
7703 u8 lb;
7704 u8 mode_is_set = 0;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007705 u32 id = ~0;
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007706 u8 numa_only = 0;
Steven9cd2d7a2017-12-20 12:43:01 -08007707
Dave Barachb7b92992018-10-17 10:38:51 -04007708 clib_memset (mac_address, 0, sizeof (mac_address));
Steven9cd2d7a2017-12-20 12:43:01 -08007709 lb = BOND_LB_L2;
7710
7711 /* Parse args required to build the message */
7712 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7713 {
7714 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
7715 mode_is_set = 1;
7716 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
7717 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
7718 ;
7719 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
7720 mac_address))
7721 custom_mac = 1;
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007722 else if (unformat (i, "numa-only"))
7723 numa_only = 1;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007724 else if (unformat (i, "id %u", &id))
7725 ;
Steven9cd2d7a2017-12-20 12:43:01 -08007726 else
7727 break;
7728 }
7729
7730 if (mode_is_set == 0)
7731 {
7732 errmsg ("Missing bond mode. ");
7733 return -99;
7734 }
7735
7736 /* Construct the API message */
7737 M (BOND_CREATE, mp);
7738
7739 mp->use_custom_mac = custom_mac;
7740
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02007741 mp->mode = htonl (mode);
7742 mp->lb = htonl (lb);
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007743 mp->id = htonl (id);
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007744 mp->numa_only = numa_only;
Steven9cd2d7a2017-12-20 12:43:01 -08007745
7746 if (custom_mac)
7747 clib_memcpy (mp->mac_address, mac_address, 6);
7748
7749 /* send it... */
7750 S (mp);
7751
7752 /* Wait for a reply... */
7753 W (ret);
7754 return ret;
7755}
7756
7757static int
7758api_bond_delete (vat_main_t * vam)
7759{
7760 unformat_input_t *i = vam->input;
7761 vl_api_bond_delete_t *mp;
7762 u32 sw_if_index = ~0;
7763 u8 sw_if_index_set = 0;
7764 int ret;
7765
7766 /* Parse args required to build the message */
7767 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7768 {
7769 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7770 sw_if_index_set = 1;
7771 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7772 sw_if_index_set = 1;
7773 else
7774 break;
7775 }
7776
7777 if (sw_if_index_set == 0)
7778 {
7779 errmsg ("missing vpp interface name. ");
7780 return -99;
7781 }
7782
7783 /* Construct the API message */
7784 M (BOND_DELETE, mp);
7785
7786 mp->sw_if_index = ntohl (sw_if_index);
7787
7788 /* send it... */
7789 S (mp);
7790
7791 /* Wait for a reply... */
7792 W (ret);
7793 return ret;
7794}
7795
7796static int
7797api_bond_enslave (vat_main_t * vam)
7798{
7799 unformat_input_t *i = vam->input;
7800 vl_api_bond_enslave_t *mp;
7801 u32 bond_sw_if_index;
7802 int ret;
7803 u8 is_passive;
7804 u8 is_long_timeout;
7805 u32 bond_sw_if_index_is_set = 0;
7806 u32 sw_if_index;
7807 u8 sw_if_index_is_set = 0;
7808
7809 /* Parse args required to build the message */
7810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7811 {
7812 if (unformat (i, "sw_if_index %d", &sw_if_index))
7813 sw_if_index_is_set = 1;
7814 else if (unformat (i, "bond %u", &bond_sw_if_index))
7815 bond_sw_if_index_is_set = 1;
7816 else if (unformat (i, "passive %d", &is_passive))
7817 ;
7818 else if (unformat (i, "long-timeout %d", &is_long_timeout))
7819 ;
7820 else
7821 break;
7822 }
7823
7824 if (bond_sw_if_index_is_set == 0)
7825 {
7826 errmsg ("Missing bond sw_if_index. ");
7827 return -99;
7828 }
7829 if (sw_if_index_is_set == 0)
7830 {
7831 errmsg ("Missing slave sw_if_index. ");
7832 return -99;
7833 }
7834
7835 /* Construct the API message */
7836 M (BOND_ENSLAVE, mp);
7837
7838 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
7839 mp->sw_if_index = ntohl (sw_if_index);
7840 mp->is_long_timeout = is_long_timeout;
7841 mp->is_passive = is_passive;
7842
7843 /* send it... */
7844 S (mp);
7845
7846 /* Wait for a reply... */
7847 W (ret);
7848 return ret;
7849}
7850
7851static int
7852api_bond_detach_slave (vat_main_t * vam)
7853{
7854 unformat_input_t *i = vam->input;
7855 vl_api_bond_detach_slave_t *mp;
7856 u32 sw_if_index = ~0;
7857 u8 sw_if_index_set = 0;
7858 int ret;
7859
7860 /* Parse args required to build the message */
7861 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7862 {
7863 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7864 sw_if_index_set = 1;
7865 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7866 sw_if_index_set = 1;
7867 else
7868 break;
7869 }
7870
7871 if (sw_if_index_set == 0)
7872 {
7873 errmsg ("missing vpp interface name. ");
7874 return -99;
7875 }
7876
7877 /* Construct the API message */
7878 M (BOND_DETACH_SLAVE, mp);
7879
7880 mp->sw_if_index = ntohl (sw_if_index);
7881
7882 /* send it... */
7883 S (mp);
7884
7885 /* Wait for a reply... */
7886 W (ret);
7887 return ret;
7888}
7889
7890static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007891api_ip_table_add_del (vat_main_t * vam)
7892{
7893 unformat_input_t *i = vam->input;
7894 vl_api_ip_table_add_del_t *mp;
7895 u32 table_id = ~0;
7896 u8 is_ipv6 = 0;
7897 u8 is_add = 1;
7898 int ret = 0;
7899
7900 /* Parse args required to build the message */
7901 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7902 {
7903 if (unformat (i, "ipv6"))
7904 is_ipv6 = 1;
7905 else if (unformat (i, "del"))
7906 is_add = 0;
7907 else if (unformat (i, "add"))
7908 is_add = 1;
7909 else if (unformat (i, "table %d", &table_id))
7910 ;
7911 else
7912 {
7913 clib_warning ("parse error '%U'", format_unformat_error, i);
7914 return -99;
7915 }
7916 }
7917
7918 if (~0 == table_id)
7919 {
7920 errmsg ("missing table-ID");
7921 return -99;
7922 }
7923
7924 /* Construct the API message */
7925 M (IP_TABLE_ADD_DEL, mp);
7926
Neale Ranns097fa662018-05-01 05:17:55 -07007927 mp->table.table_id = ntohl (table_id);
7928 mp->table.is_ip6 = is_ipv6;
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007929 mp->is_add = is_add;
7930
7931 /* send it... */
7932 S (mp);
7933
7934 /* Wait for a reply... */
7935 W (ret);
7936
7937 return ret;
7938}
7939
Neale Ranns097fa662018-05-01 05:17:55 -07007940uword
7941unformat_fib_path (unformat_input_t * input, va_list * args)
7942{
7943 vat_main_t *vam = va_arg (*args, vat_main_t *);
7944 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
7945 u32 weight, preference;
7946 mpls_label_t out_label;
7947
7948 clib_memset (path, 0, sizeof (*path));
7949 path->weight = 1;
7950 path->sw_if_index = ~0;
7951 path->rpf_id = ~0;
7952 path->n_labels = 0;
7953
7954 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7955 {
7956 if (unformat (input, "%U %U",
7957 unformat_vl_api_ip4_address,
7958 &path->nh.address.ip4,
7959 api_unformat_sw_if_index, vam, &path->sw_if_index))
7960 {
7961 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7962 }
7963 else if (unformat (input, "%U %U",
7964 unformat_vl_api_ip6_address,
7965 &path->nh.address.ip6,
7966 api_unformat_sw_if_index, vam, &path->sw_if_index))
7967 {
7968 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7969 }
7970 else if (unformat (input, "weight %u", &weight))
7971 {
7972 path->weight = weight;
7973 }
7974 else if (unformat (input, "preference %u", &preference))
7975 {
7976 path->preference = preference;
7977 }
7978 else if (unformat (input, "%U next-hop-table %d",
7979 unformat_vl_api_ip4_address,
7980 &path->nh.address.ip4, &path->table_id))
7981 {
7982 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7983 }
7984 else if (unformat (input, "%U next-hop-table %d",
7985 unformat_vl_api_ip6_address,
7986 &path->nh.address.ip6, &path->table_id))
7987 {
7988 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7989 }
7990 else if (unformat (input, "%U",
7991 unformat_vl_api_ip4_address, &path->nh.address.ip4))
7992 {
7993 /*
7994 * the recursive next-hops are by default in the default table
7995 */
7996 path->table_id = 0;
7997 path->sw_if_index = ~0;
7998 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7999 }
8000 else if (unformat (input, "%U",
8001 unformat_vl_api_ip6_address, &path->nh.address.ip6))
8002 {
8003 /*
8004 * the recursive next-hops are by default in the default table
8005 */
8006 path->table_id = 0;
8007 path->sw_if_index = ~0;
8008 path->proto = FIB_API_PATH_NH_PROTO_IP6;
8009 }
8010 else if (unformat (input, "resolve-via-host"))
8011 {
8012 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
8013 }
8014 else if (unformat (input, "resolve-via-attached"))
8015 {
8016 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
8017 }
8018 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
8019 {
8020 path->type = FIB_API_PATH_TYPE_LOCAL;
8021 path->sw_if_index = ~0;
8022 path->proto = FIB_API_PATH_NH_PROTO_IP4;
8023 }
8024 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
8025 {
8026 path->type = FIB_API_PATH_TYPE_LOCAL;
8027 path->sw_if_index = ~0;
8028 path->proto = FIB_API_PATH_NH_PROTO_IP6;
8029 }
8030 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
8031 ;
8032 else if (unformat (input, "via-label %d", &path->nh.via_label))
8033 {
8034 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
8035 path->sw_if_index = ~0;
8036 }
8037 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
8038 {
8039 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
8040 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
8041 }
8042 else if (unformat (input, "local"))
8043 {
8044 path->type = FIB_API_PATH_TYPE_LOCAL;
8045 }
8046 else if (unformat (input, "out-labels"))
8047 {
8048 while (unformat (input, "%d", &out_label))
8049 {
8050 path->label_stack[path->n_labels].label = out_label;
8051 path->label_stack[path->n_labels].is_uniform = 0;
8052 path->label_stack[path->n_labels].ttl = 64;
8053 path->n_labels++;
8054 }
8055 }
8056 else if (unformat (input, "via"))
8057 {
8058 /* new path, back up and return */
8059 unformat_put_input (input);
8060 unformat_put_input (input);
8061 unformat_put_input (input);
8062 unformat_put_input (input);
8063 break;
8064 }
8065 else
8066 {
8067 return (0);
8068 }
8069 }
8070
8071 path->proto = ntohl (path->proto);
8072 path->type = ntohl (path->type);
8073 path->flags = ntohl (path->flags);
8074 path->table_id = ntohl (path->table_id);
8075 path->sw_if_index = ntohl (path->sw_if_index);
8076
8077 return (1);
8078}
8079
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008080static int
Neale Ranns097fa662018-05-01 05:17:55 -07008081api_ip_route_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008082{
8083 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008084 vl_api_ip_route_add_del_t *mp;
8085 u32 vrf_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008086 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008087 u8 is_multipath = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008088 u8 prefix_set = 0;
8089 u8 path_count = 0;
8090 vl_api_prefix_t pfx = { };
8091 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008092 int count = 1;
8093 int j;
8094 f64 before = 0;
8095 u32 random_add_del = 0;
8096 u32 *random_vector = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008097 u32 random_seed = 0xdeaddabe;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008098
8099 /* Parse args required to build the message */
8100 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8101 {
Neale Ranns097fa662018-05-01 05:17:55 -07008102 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8103 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008104 else if (unformat (i, "del"))
8105 is_add = 0;
8106 else if (unformat (i, "add"))
8107 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008108 else if (unformat (i, "vrf %d", &vrf_id))
8109 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008110 else if (unformat (i, "count %d", &count))
8111 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008112 else if (unformat (i, "random"))
8113 random_add_del = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008114 else if (unformat (i, "multipath"))
8115 is_multipath = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008116 else if (unformat (i, "seed %d", &random_seed))
8117 ;
8118 else
Neale Ranns097fa662018-05-01 05:17:55 -07008119 if (unformat
8120 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
8121 {
8122 path_count++;
8123 if (8 == path_count)
8124 {
8125 errmsg ("max 8 paths");
8126 return -99;
8127 }
8128 }
8129 else
Damjan Marion7cd468a2016-12-19 23:05:39 +01008130 {
8131 clib_warning ("parse error '%U'", format_unformat_error, i);
8132 return -99;
8133 }
8134 }
8135
Neale Ranns097fa662018-05-01 05:17:55 -07008136 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008137 {
Neale Ranns097fa662018-05-01 05:17:55 -07008138 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008139 return -99;
8140 }
Neale Ranns097fa662018-05-01 05:17:55 -07008141 if (prefix_set == 0)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008142 {
Neale Ranns097fa662018-05-01 05:17:55 -07008143 errmsg ("missing prefix");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008144 return -99;
8145 }
8146
8147 /* Generate a pile of unique, random routes */
8148 if (random_add_del)
8149 {
Neale Ranns097fa662018-05-01 05:17:55 -07008150 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008151 u32 this_random_address;
Neale Ranns097fa662018-05-01 05:17:55 -07008152 uword *random_hash;
8153
Damjan Marion7cd468a2016-12-19 23:05:39 +01008154 random_hash = hash_create (count, sizeof (uword));
8155
Neale Ranns097fa662018-05-01 05:17:55 -07008156 hash_set (random_hash, i->as_u32, 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008157 for (j = 0; j <= count; j++)
8158 {
8159 do
8160 {
8161 this_random_address = random_u32 (&random_seed);
8162 this_random_address =
8163 clib_host_to_net_u32 (this_random_address);
8164 }
8165 while (hash_get (random_hash, this_random_address));
8166 vec_add1 (random_vector, this_random_address);
8167 hash_set (random_hash, this_random_address, 1);
8168 }
8169 hash_free (random_hash);
Neale Ranns097fa662018-05-01 05:17:55 -07008170 set_ip4_address (&pfx.address, random_vector[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008171 }
8172
8173 if (count > 1)
8174 {
8175 /* Turn on async mode */
8176 vam->async_mode = 1;
8177 vam->async_errors = 0;
8178 before = vat_time_now (vam);
8179 }
8180
8181 for (j = 0; j < count; j++)
8182 {
8183 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008184 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008185
8186 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008187 mp->is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008188
Neale Ranns097fa662018-05-01 05:17:55 -07008189 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8190 mp->route.table_id = ntohl (vrf_id);
8191 mp->route.n_paths = path_count;
8192
8193 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
8194
8195 if (random_add_del)
8196 set_ip4_address (&pfx.address, random_vector[j + 1]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008197 else
Neale Ranns097fa662018-05-01 05:17:55 -07008198 increment_address (&pfx.address);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008199 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008200 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008201 /* If we receive SIGTERM, stop now... */
8202 if (vam->do_exit)
8203 break;
8204 }
8205
8206 /* When testing multiple add/del ops, use a control-ping to sync */
8207 if (count > 1)
8208 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008209 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008210 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008211 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008212
8213 /* Shut off async mode */
8214 vam->async_mode = 0;
8215
Dave Barach59b25652017-09-10 15:04:27 -04008216 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008217 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008218
8219 timeout = vat_time_now (vam) + 1.0;
8220 while (vat_time_now (vam) < timeout)
8221 if (vam->result_ready == 1)
8222 goto out;
8223 vam->retval = -99;
8224
8225 out:
8226 if (vam->retval == -99)
8227 errmsg ("timeout");
8228
8229 if (vam->async_errors > 0)
8230 {
8231 errmsg ("%d asynchronous errors", vam->async_errors);
8232 vam->retval = -98;
8233 }
8234 vam->async_errors = 0;
8235 after = vat_time_now (vam);
8236
8237 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8238 if (j > 0)
8239 count = j;
8240
8241 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8242 count, after - before, count / (after - before));
8243 }
8244 else
8245 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008246 int ret;
8247
Damjan Marion7cd468a2016-12-19 23:05:39 +01008248 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008249 W (ret);
8250 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008251 }
8252
8253 /* Return the good/bad news */
8254 return (vam->retval);
8255}
8256
8257static int
Neale Ranns32e1c012016-11-22 17:07:28 +00008258api_ip_mroute_add_del (vat_main_t * vam)
8259{
8260 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008261 u8 path_set = 0, prefix_set = 0, is_add = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008262 vl_api_ip_mroute_add_del_t *mp;
Neale Ranns32e1c012016-11-22 17:07:28 +00008263 mfib_entry_flags_t eflags = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008264 vl_api_mfib_path_t path;
8265 vl_api_mprefix_t pfx = { };
8266 u32 vrf_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008267 int ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008268
8269 /* Parse args required to build the message */
8270 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8271 {
Neale Ranns097fa662018-05-01 05:17:55 -07008272 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
Neale Ranns32e1c012016-11-22 17:07:28 +00008273 {
Neale Ranns097fa662018-05-01 05:17:55 -07008274 prefix_set = 1;
8275 pfx.grp_address_length = htons (pfx.grp_address_length);
Neale Ranns32e1c012016-11-22 17:07:28 +00008276 }
8277 else if (unformat (i, "del"))
8278 is_add = 0;
8279 else if (unformat (i, "add"))
8280 is_add = 1;
8281 else if (unformat (i, "vrf %d", &vrf_id))
8282 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008283 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
8284 path.itf_flags = htonl (path.itf_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008285 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
8286 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008287 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
8288 path_set = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008289 else
8290 {
8291 clib_warning ("parse error '%U'", format_unformat_error, i);
8292 return -99;
8293 }
8294 }
8295
Neale Ranns097fa662018-05-01 05:17:55 -07008296 if (prefix_set == 0)
Neale Ranns32e1c012016-11-22 17:07:28 +00008297 {
8298 errmsg ("missing addresses\n");
8299 return -99;
8300 }
Neale Ranns097fa662018-05-01 05:17:55 -07008301 if (path_set == 0)
8302 {
8303 errmsg ("missing path\n");
8304 return -99;
8305 }
Neale Ranns32e1c012016-11-22 17:07:28 +00008306
8307 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008308 M (IP_MROUTE_ADD_DEL, mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008309
Neale Ranns32e1c012016-11-22 17:07:28 +00008310 mp->is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008311 mp->is_multipath = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008312
Neale Ranns097fa662018-05-01 05:17:55 -07008313 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8314 mp->route.table_id = htonl (vrf_id);
8315 mp->route.n_paths = 1;
8316 mp->route.entry_flags = htonl (eflags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008317
Neale Ranns097fa662018-05-01 05:17:55 -07008318 clib_memcpy (&mp->route.paths, &path, sizeof (path));
Neale Ranns32e1c012016-11-22 17:07:28 +00008319
8320 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008321 S (mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008322 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008323 W (ret);
8324 return ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008325}
8326
8327static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008328api_mpls_table_add_del (vat_main_t * vam)
8329{
8330 unformat_input_t *i = vam->input;
8331 vl_api_mpls_table_add_del_t *mp;
8332 u32 table_id = ~0;
8333 u8 is_add = 1;
8334 int ret = 0;
8335
8336 /* Parse args required to build the message */
8337 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8338 {
Florin Corasd0a59722017-10-15 17:41:21 +00008339 if (unformat (i, "table %d", &table_id))
8340 ;
8341 else if (unformat (i, "del"))
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008342 is_add = 0;
8343 else if (unformat (i, "add"))
8344 is_add = 1;
8345 else
8346 {
8347 clib_warning ("parse error '%U'", format_unformat_error, i);
8348 return -99;
8349 }
8350 }
8351
8352 if (~0 == table_id)
8353 {
8354 errmsg ("missing table-ID");
8355 return -99;
8356 }
8357
8358 /* Construct the API message */
8359 M (MPLS_TABLE_ADD_DEL, mp);
8360
Neale Ranns097fa662018-05-01 05:17:55 -07008361 mp->mt_table.mt_table_id = ntohl (table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008362 mp->mt_is_add = is_add;
8363
8364 /* send it... */
8365 S (mp);
8366
8367 /* Wait for a reply... */
8368 W (ret);
8369
8370 return ret;
8371}
8372
8373static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008374api_mpls_route_add_del (vat_main_t * vam)
8375{
Neale Ranns097fa662018-05-01 05:17:55 -07008376 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
8377 mpls_label_t local_label = MPLS_LABEL_INVALID;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008378 unformat_input_t *i = vam->input;
8379 vl_api_mpls_route_add_del_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07008380 vl_api_fib_path_t paths[8];
8381 int count = 1, j;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008382 f64 before = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008383
8384 /* Parse args required to build the message */
8385 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8386 {
Neale Ranns097fa662018-05-01 05:17:55 -07008387 if (unformat (i, "%d", &local_label))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008388 ;
8389 else if (unformat (i, "eos"))
8390 is_eos = 1;
8391 else if (unformat (i, "non-eos"))
8392 is_eos = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008393 else if (unformat (i, "del"))
8394 is_add = 0;
8395 else if (unformat (i, "add"))
8396 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008397 else if (unformat (i, "multipath"))
8398 is_multipath = 1;
8399 else if (unformat (i, "count %d", &count))
8400 ;
John Loe166fd92018-09-13 14:08:59 -04008401 else
8402 if (unformat
Neale Ranns097fa662018-05-01 05:17:55 -07008403 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Loe166fd92018-09-13 14:08:59 -04008404 {
Neale Ranns097fa662018-05-01 05:17:55 -07008405 path_count++;
8406 if (8 == path_count)
8407 {
8408 errmsg ("max 8 paths");
8409 return -99;
8410 }
John Loe166fd92018-09-13 14:08:59 -04008411 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008412 else
8413 {
8414 clib_warning ("parse error '%U'", format_unformat_error, i);
8415 return -99;
8416 }
8417 }
8418
Neale Ranns097fa662018-05-01 05:17:55 -07008419 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008420 {
Neale Ranns097fa662018-05-01 05:17:55 -07008421 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008422 return -99;
8423 }
8424
8425 if (MPLS_LABEL_INVALID == local_label)
8426 {
8427 errmsg ("missing label");
8428 return -99;
8429 }
8430
8431 if (count > 1)
8432 {
8433 /* Turn on async mode */
8434 vam->async_mode = 1;
8435 vam->async_errors = 0;
8436 before = vat_time_now (vam);
8437 }
8438
8439 for (j = 0; j < count; j++)
8440 {
8441 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008442 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008443
8444 mp->mr_is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008445 mp->mr_is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008446
Neale Ranns097fa662018-05-01 05:17:55 -07008447 mp->mr_route.mr_label = local_label;
8448 mp->mr_route.mr_eos = is_eos;
8449 mp->mr_route.mr_table_id = 0;
8450 mp->mr_route.mr_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008451
Neale Ranns097fa662018-05-01 05:17:55 -07008452 clib_memcpy (&mp->mr_route.mr_paths, paths,
8453 sizeof (paths[0]) * path_count);
Neale Rannsda78f952017-05-24 09:15:43 -07008454
Damjan Marion7cd468a2016-12-19 23:05:39 +01008455 local_label++;
8456
8457 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008458 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008459 /* If we receive SIGTERM, stop now... */
8460 if (vam->do_exit)
8461 break;
8462 }
8463
8464 /* When testing multiple add/del ops, use a control-ping to sync */
8465 if (count > 1)
8466 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008467 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008468 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008469 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008470
8471 /* Shut off async mode */
8472 vam->async_mode = 0;
8473
Dave Barach59b25652017-09-10 15:04:27 -04008474 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008475 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008476
8477 timeout = vat_time_now (vam) + 1.0;
8478 while (vat_time_now (vam) < timeout)
8479 if (vam->result_ready == 1)
8480 goto out;
8481 vam->retval = -99;
8482
8483 out:
8484 if (vam->retval == -99)
8485 errmsg ("timeout");
8486
8487 if (vam->async_errors > 0)
8488 {
8489 errmsg ("%d asynchronous errors", vam->async_errors);
8490 vam->retval = -98;
8491 }
8492 vam->async_errors = 0;
8493 after = vat_time_now (vam);
8494
8495 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8496 if (j > 0)
8497 count = j;
8498
8499 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8500 count, after - before, count / (after - before));
8501 }
8502 else
8503 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008504 int ret;
8505
Damjan Marion7cd468a2016-12-19 23:05:39 +01008506 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008507 W (ret);
8508 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008509 }
8510
8511 /* Return the good/bad news */
8512 return (vam->retval);
Neale Ranns097fa662018-05-01 05:17:55 -07008513 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008514}
8515
8516static int
8517api_mpls_ip_bind_unbind (vat_main_t * vam)
8518{
8519 unformat_input_t *i = vam->input;
8520 vl_api_mpls_ip_bind_unbind_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008521 u32 ip_table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008522 u8 is_bind = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008523 vl_api_prefix_t pfx;
8524 u8 prefix_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008525 mpls_label_t local_label = MPLS_LABEL_INVALID;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008526 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008527
8528 /* Parse args required to build the message */
8529 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8530 {
Neale Ranns097fa662018-05-01 05:17:55 -07008531 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8532 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008533 else if (unformat (i, "%d", &local_label))
8534 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008535 else if (unformat (i, "table-id %d", &ip_table_id))
8536 ;
8537 else if (unformat (i, "unbind"))
8538 is_bind = 0;
8539 else if (unformat (i, "bind"))
8540 is_bind = 1;
8541 else
8542 {
8543 clib_warning ("parse error '%U'", format_unformat_error, i);
8544 return -99;
8545 }
8546 }
8547
Neale Ranns097fa662018-05-01 05:17:55 -07008548 if (!prefix_set)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008549 {
Neale Ranns097fa662018-05-01 05:17:55 -07008550 errmsg ("IP prefix not set");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008551 return -99;
8552 }
8553
8554 if (MPLS_LABEL_INVALID == local_label)
8555 {
8556 errmsg ("missing label");
8557 return -99;
8558 }
8559
8560 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008561 M (MPLS_IP_BIND_UNBIND, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008562
Damjan Marion7cd468a2016-12-19 23:05:39 +01008563 mp->mb_is_bind = is_bind;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008564 mp->mb_ip_table_id = ntohl (ip_table_id);
8565 mp->mb_mpls_table_id = 0;
8566 mp->mb_label = ntohl (local_label);
Neale Ranns097fa662018-05-01 05:17:55 -07008567 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008568
8569 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008570 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008571
8572 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008573 W (ret);
8574 return ret;
Neale Ranns097fa662018-05-01 05:17:55 -07008575 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008576}
8577
8578static int
John Loe166fd92018-09-13 14:08:59 -04008579api_sr_mpls_policy_add (vat_main_t * vam)
8580{
8581 unformat_input_t *i = vam->input;
8582 vl_api_sr_mpls_policy_add_t *mp;
8583 u32 bsid = 0;
8584 u32 weight = 1;
8585 u8 type = 0;
8586 u8 n_segments = 0;
8587 u32 sid;
8588 u32 *segments = NULL;
8589 int ret;
8590
8591 /* Parse args required to build the message */
8592 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8593 {
8594 if (unformat (i, "bsid %d", &bsid))
8595 ;
8596 else if (unformat (i, "weight %d", &weight))
8597 ;
8598 else if (unformat (i, "spray"))
8599 type = 1;
8600 else if (unformat (i, "next %d", &sid))
8601 {
8602 n_segments += 1;
8603 vec_add1 (segments, htonl (sid));
8604 }
8605 else
8606 {
8607 clib_warning ("parse error '%U'", format_unformat_error, i);
8608 return -99;
8609 }
8610 }
8611
8612 if (bsid == 0)
8613 {
8614 errmsg ("bsid not set");
8615 return -99;
8616 }
8617
8618 if (n_segments == 0)
8619 {
8620 errmsg ("no sid in segment stack");
8621 return -99;
8622 }
8623
8624 /* Construct the API message */
8625 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
8626
8627 mp->bsid = htonl (bsid);
8628 mp->weight = htonl (weight);
8629 mp->type = type;
8630 mp->n_segments = n_segments;
8631 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
8632 vec_free (segments);
8633
8634 /* send it... */
8635 S (mp);
8636
8637 /* Wait for a reply... */
8638 W (ret);
8639 return ret;
8640}
8641
8642static int
8643api_sr_mpls_policy_del (vat_main_t * vam)
8644{
8645 unformat_input_t *i = vam->input;
8646 vl_api_sr_mpls_policy_del_t *mp;
8647 u32 bsid = 0;
8648 int ret;
8649
8650 /* Parse args required to build the message */
8651 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8652 {
8653 if (unformat (i, "bsid %d", &bsid))
8654 ;
8655 else
8656 {
8657 clib_warning ("parse error '%U'", format_unformat_error, i);
8658 return -99;
8659 }
8660 }
8661
8662 if (bsid == 0)
8663 {
8664 errmsg ("bsid not set");
8665 return -99;
8666 }
8667
8668 /* Construct the API message */
8669 M (SR_MPLS_POLICY_DEL, mp);
8670
8671 mp->bsid = htonl (bsid);
8672
8673 /* send it... */
8674 S (mp);
8675
8676 /* Wait for a reply... */
8677 W (ret);
8678 return ret;
8679}
8680
8681static int
Neale Rannsd792d9c2017-10-21 10:53:20 -07008682api_bier_table_add_del (vat_main_t * vam)
8683{
8684 unformat_input_t *i = vam->input;
8685 vl_api_bier_table_add_del_t *mp;
8686 u8 is_add = 1;
8687 u32 set = 0, sub_domain = 0, hdr_len = 3;
8688 mpls_label_t local_label = MPLS_LABEL_INVALID;
8689 int ret;
8690
8691 /* Parse args required to build the message */
8692 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8693 {
8694 if (unformat (i, "sub-domain %d", &sub_domain))
8695 ;
8696 else if (unformat (i, "set %d", &set))
8697 ;
8698 else if (unformat (i, "label %d", &local_label))
8699 ;
8700 else if (unformat (i, "hdr-len %d", &hdr_len))
8701 ;
8702 else if (unformat (i, "add"))
8703 is_add = 1;
8704 else if (unformat (i, "del"))
8705 is_add = 0;
8706 else
8707 {
8708 clib_warning ("parse error '%U'", format_unformat_error, i);
8709 return -99;
8710 }
8711 }
8712
8713 if (MPLS_LABEL_INVALID == local_label)
8714 {
8715 errmsg ("missing label\n");
8716 return -99;
8717 }
8718
8719 /* Construct the API message */
8720 M (BIER_TABLE_ADD_DEL, mp);
8721
8722 mp->bt_is_add = is_add;
8723 mp->bt_label = ntohl (local_label);
8724 mp->bt_tbl_id.bt_set = set;
8725 mp->bt_tbl_id.bt_sub_domain = sub_domain;
8726 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
8727
8728 /* send it... */
8729 S (mp);
8730
8731 /* Wait for a reply... */
8732 W (ret);
8733
8734 return (ret);
8735}
8736
8737static int
8738api_bier_route_add_del (vat_main_t * vam)
8739{
8740 unformat_input_t *i = vam->input;
8741 vl_api_bier_route_add_del_t *mp;
8742 u8 is_add = 1;
8743 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
8744 ip4_address_t v4_next_hop_address;
8745 ip6_address_t v6_next_hop_address;
8746 u8 next_hop_set = 0;
8747 u8 next_hop_proto_is_ip4 = 1;
8748 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
8749 int ret;
8750
8751 /* Parse args required to build the message */
8752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8753 {
8754 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
8755 {
8756 next_hop_proto_is_ip4 = 1;
8757 next_hop_set = 1;
8758 }
8759 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
8760 {
8761 next_hop_proto_is_ip4 = 0;
8762 next_hop_set = 1;
8763 }
8764 if (unformat (i, "sub-domain %d", &sub_domain))
8765 ;
8766 else if (unformat (i, "set %d", &set))
8767 ;
8768 else if (unformat (i, "hdr-len %d", &hdr_len))
8769 ;
8770 else if (unformat (i, "bp %d", &bp))
8771 ;
8772 else if (unformat (i, "add"))
8773 is_add = 1;
8774 else if (unformat (i, "del"))
8775 is_add = 0;
8776 else if (unformat (i, "out-label %d", &next_hop_out_label))
8777 ;
8778 else
8779 {
8780 clib_warning ("parse error '%U'", format_unformat_error, i);
8781 return -99;
8782 }
8783 }
8784
8785 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
8786 {
8787 errmsg ("next hop / label set\n");
8788 return -99;
8789 }
8790 if (0 == bp)
8791 {
8792 errmsg ("bit=position not set\n");
8793 return -99;
8794 }
8795
8796 /* Construct the API message */
Neale Ranns31ed7442018-02-23 05:29:09 -08008797 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
Neale Rannsd792d9c2017-10-21 10:53:20 -07008798
8799 mp->br_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008800 mp->br_route.br_tbl_id.bt_set = set;
8801 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
8802 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
8803 mp->br_route.br_bp = ntohs (bp);
8804 mp->br_route.br_n_paths = 1;
8805 mp->br_route.br_paths[0].n_labels = 1;
8806 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
8807 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
8808 FIB_API_PATH_NH_PROTO_IP4 :
8809 FIB_API_PATH_NH_PROTO_IP6);
Neale Rannsd792d9c2017-10-21 10:53:20 -07008810
8811 if (next_hop_proto_is_ip4)
8812 {
Neale Ranns097fa662018-05-01 05:17:55 -07008813 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008814 &v4_next_hop_address, sizeof (v4_next_hop_address));
8815 }
8816 else
8817 {
Neale Ranns097fa662018-05-01 05:17:55 -07008818 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008819 &v6_next_hop_address, sizeof (v6_next_hop_address));
8820 }
8821
8822 /* send it... */
8823 S (mp);
8824
8825 /* Wait for a reply... */
8826 W (ret);
8827
8828 return (ret);
8829}
8830
8831static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008832api_proxy_arp_add_del (vat_main_t * vam)
8833{
8834 unformat_input_t *i = vam->input;
8835 vl_api_proxy_arp_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008836 u32 vrf_id = 0;
8837 u8 is_add = 1;
Neale Ranns37029302018-08-10 05:30:06 -07008838 vl_api_ip4_address_t lo, hi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008839 u8 range_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008840 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008841
8842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8843 {
8844 if (unformat (i, "vrf %d", &vrf_id))
8845 ;
Neale Ranns37029302018-08-10 05:30:06 -07008846 else if (unformat (i, "%U - %U", unformat_vl_api_ip4_address, &lo,
8847 unformat_vl_api_ip4_address, &hi))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008848 range_set = 1;
8849 else if (unformat (i, "del"))
8850 is_add = 0;
8851 else
8852 {
8853 clib_warning ("parse error '%U'", format_unformat_error, i);
8854 return -99;
8855 }
8856 }
8857
8858 if (range_set == 0)
8859 {
8860 errmsg ("address range not set");
8861 return -99;
8862 }
8863
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008864 M (PROXY_ARP_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008865
Neale Ranns37029302018-08-10 05:30:06 -07008866 mp->proxy.table_id = ntohl (vrf_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008867 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -07008868 clib_memcpy (mp->proxy.low, &lo, sizeof (lo));
8869 clib_memcpy (mp->proxy.hi, &hi, sizeof (hi));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008870
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008871 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008872 W (ret);
8873 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008874}
8875
8876static int
8877api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
8878{
8879 unformat_input_t *i = vam->input;
8880 vl_api_proxy_arp_intfc_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008881 u32 sw_if_index;
8882 u8 enable = 1;
8883 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008884 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008885
8886 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8887 {
8888 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8889 sw_if_index_set = 1;
8890 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8891 sw_if_index_set = 1;
8892 else if (unformat (i, "enable"))
8893 enable = 1;
8894 else if (unformat (i, "disable"))
8895 enable = 0;
8896 else
8897 {
8898 clib_warning ("parse error '%U'", format_unformat_error, i);
8899 return -99;
8900 }
8901 }
8902
8903 if (sw_if_index_set == 0)
8904 {
8905 errmsg ("missing interface name or sw_if_index");
8906 return -99;
8907 }
8908
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008909 M (PROXY_ARP_INTFC_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008910
8911 mp->sw_if_index = ntohl (sw_if_index);
8912 mp->enable_disable = enable;
8913
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008914 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008915 W (ret);
8916 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008917}
8918
8919static int
8920api_mpls_tunnel_add_del (vat_main_t * vam)
8921{
8922 unformat_input_t *i = vam->input;
8923 vl_api_mpls_tunnel_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008924
Neale Ranns097fa662018-05-01 05:17:55 -07008925 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008926 u32 sw_if_index = ~0;
Neale Ranns097fa662018-05-01 05:17:55 -07008927 u8 path_count = 0;
8928 u8 l2_only = 0;
8929 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008930 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008931
8932 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8933 {
8934 if (unformat (i, "add"))
8935 is_add = 1;
John Lo06fda9c2018-10-03 16:32:44 -04008936 else
8937 if (unformat
8938 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
8939 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008940 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
8941 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008942 else if (unformat (i, "l2-only"))
8943 l2_only = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008944 else
8945 if (unformat
8946 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Lo06fda9c2018-10-03 16:32:44 -04008947 {
Neale Ranns097fa662018-05-01 05:17:55 -07008948 path_count++;
8949 if (8 == path_count)
8950 {
8951 errmsg ("max 8 paths");
8952 return -99;
8953 }
John Lo06fda9c2018-10-03 16:32:44 -04008954 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008955 else
8956 {
8957 clib_warning ("parse error '%U'", format_unformat_error, i);
8958 return -99;
8959 }
8960 }
8961
Neale Ranns097fa662018-05-01 05:17:55 -07008962 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008963
Damjan Marion7cd468a2016-12-19 23:05:39 +01008964 mp->mt_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008965 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
8966 mp->mt_tunnel.mt_l2_only = l2_only;
8967 mp->mt_tunnel.mt_is_multicast = 0;
8968 mp->mt_tunnel.mt_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008969
Neale Ranns097fa662018-05-01 05:17:55 -07008970 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
8971 sizeof (paths[0]) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008972
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008973 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008974 W (ret);
8975 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008976}
8977
8978static int
8979api_sw_interface_set_unnumbered (vat_main_t * vam)
8980{
8981 unformat_input_t *i = vam->input;
8982 vl_api_sw_interface_set_unnumbered_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008983 u32 sw_if_index;
8984 u32 unnum_sw_index = ~0;
8985 u8 is_add = 1;
8986 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008987 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008988
8989 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8990 {
8991 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8992 sw_if_index_set = 1;
8993 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8994 sw_if_index_set = 1;
8995 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
8996 ;
8997 else if (unformat (i, "del"))
8998 is_add = 0;
8999 else
9000 {
9001 clib_warning ("parse error '%U'", format_unformat_error, i);
9002 return -99;
9003 }
9004 }
9005
9006 if (sw_if_index_set == 0)
9007 {
9008 errmsg ("missing interface name or sw_if_index");
9009 return -99;
9010 }
9011
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009012 M (SW_INTERFACE_SET_UNNUMBERED, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009013
9014 mp->sw_if_index = ntohl (sw_if_index);
9015 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
9016 mp->is_add = is_add;
9017
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009018 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009019 W (ret);
9020 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009021}
9022
9023static int
9024api_ip_neighbor_add_del (vat_main_t * vam)
9025{
Neale Ranns37029302018-08-10 05:30:06 -07009026 vl_api_mac_address_t mac_address;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009027 unformat_input_t *i = vam->input;
9028 vl_api_ip_neighbor_add_del_t *mp;
Neale Ranns37029302018-08-10 05:30:06 -07009029 vl_api_address_t ip_address;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009030 u32 sw_if_index;
9031 u8 sw_if_index_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009032 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009033 u8 mac_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -07009034 u8 address_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009035 int ret;
Neale Ranns37029302018-08-10 05:30:06 -07009036 ip_neighbor_flags_t flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009037
Neale Ranns37029302018-08-10 05:30:06 -07009038 flags = IP_NEIGHBOR_FLAG_NONE;
9039 clib_memset (&ip_address, 0, sizeof (ip_address));
9040 clib_memset (&mac_address, 0, sizeof (mac_address));
Neale Ranns097fa662018-05-01 05:17:55 -07009041
Damjan Marion7cd468a2016-12-19 23:05:39 +01009042 /* Parse args required to build the message */
9043 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9044 {
Neale Ranns37029302018-08-10 05:30:06 -07009045 if (unformat (i, "mac %U", unformat_vl_api_mac_address, &mac_address))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009046 {
9047 mac_set = 1;
9048 }
9049 else if (unformat (i, "del"))
9050 is_add = 0;
9051 else
9052 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9053 sw_if_index_set = 1;
9054 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9055 sw_if_index_set = 1;
Neale Ranns37029302018-08-10 05:30:06 -07009056 else if (unformat (i, "static"))
9057 flags |= IP_NEIGHBOR_FLAG_STATIC;
Neale Rannsb3b2de72017-03-08 05:17:22 -08009058 else if (unformat (i, "no-fib-entry"))
Neale Ranns37029302018-08-10 05:30:06 -07009059 flags |= IP_NEIGHBOR_FLAG_NO_FIB_ENTRY;
9060 else if (unformat (i, "dst %U", unformat_vl_api_address, &ip_address))
9061 address_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009062 else
9063 {
9064 clib_warning ("parse error '%U'", format_unformat_error, i);
9065 return -99;
9066 }
9067 }
9068
9069 if (sw_if_index_set == 0)
9070 {
9071 errmsg ("missing interface name or sw_if_index");
9072 return -99;
9073 }
Neale Ranns37029302018-08-10 05:30:06 -07009074 if (!address_set)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009075 {
9076 errmsg ("no address set");
9077 return -99;
9078 }
9079
9080 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009081 M (IP_NEIGHBOR_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009082
Neale Ranns37029302018-08-10 05:30:06 -07009083 mp->neighbor.sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009084 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -07009085 mp->neighbor.flags = htonl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009086 if (mac_set)
Neale Ranns37029302018-08-10 05:30:06 -07009087 clib_memcpy (&mp->neighbor.mac_address, &mac_address,
9088 sizeof (mac_address));
9089 if (address_set)
9090 clib_memcpy (&mp->neighbor.ip_address, &ip_address, sizeof (ip_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009091
9092 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009093 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009094
9095 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009096 W (ret);
9097 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009098}
9099
9100static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009101api_create_vlan_subif (vat_main_t * vam)
9102{
9103 unformat_input_t *i = vam->input;
9104 vl_api_create_vlan_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009105 u32 sw_if_index;
9106 u8 sw_if_index_set = 0;
9107 u32 vlan_id;
9108 u8 vlan_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009109 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009110
9111 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9112 {
9113 if (unformat (i, "sw_if_index %d", &sw_if_index))
9114 sw_if_index_set = 1;
9115 else
9116 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9117 sw_if_index_set = 1;
9118 else if (unformat (i, "vlan %d", &vlan_id))
9119 vlan_id_set = 1;
9120 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 }
9132
9133 if (vlan_id_set == 0)
9134 {
9135 errmsg ("missing vlan_id");
9136 return -99;
9137 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009138 M (CREATE_VLAN_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009139
9140 mp->sw_if_index = ntohl (sw_if_index);
9141 mp->vlan_id = ntohl (vlan_id);
9142
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009143 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009144 W (ret);
9145 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009146}
9147
9148#define foreach_create_subif_bit \
9149_(no_tags) \
9150_(one_tag) \
9151_(two_tags) \
9152_(dot1ad) \
9153_(exact_match) \
9154_(default_sub) \
9155_(outer_vlan_id_any) \
9156_(inner_vlan_id_any)
9157
Jakub Grajciar053204a2019-03-18 13:17:53 +01009158#define foreach_create_subif_flag \
9159_(0, "no_tags") \
9160_(1, "one_tag") \
9161_(2, "two_tags") \
9162_(3, "dot1ad") \
9163_(4, "exact_match") \
9164_(5, "default_sub") \
9165_(6, "outer_vlan_id_any") \
9166_(7, "inner_vlan_id_any")
9167
Damjan Marion7cd468a2016-12-19 23:05:39 +01009168static int
9169api_create_subif (vat_main_t * vam)
9170{
9171 unformat_input_t *i = vam->input;
9172 vl_api_create_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009173 u32 sw_if_index;
9174 u8 sw_if_index_set = 0;
9175 u32 sub_id;
9176 u8 sub_id_set = 0;
Jakub Grajciar053204a2019-03-18 13:17:53 +01009177 u32 __attribute__ ((unused)) no_tags = 0;
9178 u32 __attribute__ ((unused)) one_tag = 0;
9179 u32 __attribute__ ((unused)) two_tags = 0;
9180 u32 __attribute__ ((unused)) dot1ad = 0;
9181 u32 __attribute__ ((unused)) exact_match = 0;
9182 u32 __attribute__ ((unused)) default_sub = 0;
9183 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
9184 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009185 u32 tmp;
9186 u16 outer_vlan_id = 0;
9187 u16 inner_vlan_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009188 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009189
9190 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9191 {
9192 if (unformat (i, "sw_if_index %d", &sw_if_index))
9193 sw_if_index_set = 1;
9194 else
9195 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9196 sw_if_index_set = 1;
9197 else if (unformat (i, "sub_id %d", &sub_id))
9198 sub_id_set = 1;
9199 else if (unformat (i, "outer_vlan_id %d", &tmp))
9200 outer_vlan_id = tmp;
9201 else if (unformat (i, "inner_vlan_id %d", &tmp))
9202 inner_vlan_id = tmp;
9203
9204#define _(a) else if (unformat (i, #a)) a = 1 ;
9205 foreach_create_subif_bit
9206#undef _
9207 else
9208 {
9209 clib_warning ("parse error '%U'", format_unformat_error, i);
9210 return -99;
9211 }
9212 }
9213
9214 if (sw_if_index_set == 0)
9215 {
9216 errmsg ("missing interface name or sw_if_index");
9217 return -99;
9218 }
9219
9220 if (sub_id_set == 0)
9221 {
9222 errmsg ("missing sub_id");
9223 return -99;
9224 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009225 M (CREATE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009226
9227 mp->sw_if_index = ntohl (sw_if_index);
9228 mp->sub_id = ntohl (sub_id);
9229
Jakub Grajciar053204a2019-03-18 13:17:53 +01009230#define _(a,b) mp->sub_if_flags |= (1 << a);
9231 foreach_create_subif_flag;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009232#undef _
9233
9234 mp->outer_vlan_id = ntohs (outer_vlan_id);
9235 mp->inner_vlan_id = ntohs (inner_vlan_id);
9236
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009237 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009238 W (ret);
9239 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009240}
9241
9242static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009243api_reset_fib (vat_main_t * vam)
9244{
9245 unformat_input_t *i = vam->input;
9246 vl_api_reset_fib_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009247 u32 vrf_id = 0;
9248 u8 is_ipv6 = 0;
9249 u8 vrf_id_set = 0;
9250
Jon Loeliger56c7b012017-02-01 12:31:41 -06009251 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009252 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9253 {
9254 if (unformat (i, "vrf %d", &vrf_id))
9255 vrf_id_set = 1;
9256 else if (unformat (i, "ipv6"))
9257 is_ipv6 = 1;
9258 else
9259 {
9260 clib_warning ("parse error '%U'", format_unformat_error, i);
9261 return -99;
9262 }
9263 }
9264
9265 if (vrf_id_set == 0)
9266 {
9267 errmsg ("missing vrf id");
9268 return -99;
9269 }
9270
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009271 M (RESET_FIB, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009272
9273 mp->vrf_id = ntohl (vrf_id);
9274 mp->is_ipv6 = is_ipv6;
9275
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009276 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009277 W (ret);
9278 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009279}
9280
9281static int
9282api_dhcp_proxy_config (vat_main_t * vam)
9283{
9284 unformat_input_t *i = vam->input;
9285 vl_api_dhcp_proxy_config_t *mp;
Neale Ranns20a175a2017-02-14 07:28:41 -08009286 u32 rx_vrf_id = 0;
9287 u32 server_vrf_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009288 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009289 u8 v4_address_set = 0;
9290 u8 v6_address_set = 0;
9291 ip4_address_t v4address;
9292 ip6_address_t v6address;
9293 u8 v4_src_address_set = 0;
9294 u8 v6_src_address_set = 0;
9295 ip4_address_t v4srcaddress;
9296 ip6_address_t v6srcaddress;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009297 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009298
9299 /* Parse args required to build the message */
9300 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9301 {
9302 if (unformat (i, "del"))
9303 is_add = 0;
Neale Ranns20a175a2017-02-14 07:28:41 -08009304 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009305 ;
Neale Ranns20a175a2017-02-14 07:28:41 -08009306 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009307 ;
9308 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
9309 v4_address_set = 1;
9310 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
9311 v6_address_set = 1;
9312 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
9313 v4_src_address_set = 1;
9314 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
9315 v6_src_address_set = 1;
9316 else
9317 break;
9318 }
9319
9320 if (v4_address_set && v6_address_set)
9321 {
9322 errmsg ("both v4 and v6 server addresses set");
9323 return -99;
9324 }
9325 if (!v4_address_set && !v6_address_set)
9326 {
9327 errmsg ("no server addresses set");
9328 return -99;
9329 }
9330
9331 if (v4_src_address_set && v6_src_address_set)
9332 {
9333 errmsg ("both v4 and v6 src addresses set");
9334 return -99;
9335 }
9336 if (!v4_src_address_set && !v6_src_address_set)
9337 {
9338 errmsg ("no src addresses set");
9339 return -99;
9340 }
9341
9342 if (!(v4_src_address_set && v4_address_set) &&
9343 !(v6_src_address_set && v6_address_set))
9344 {
9345 errmsg ("no matching server and src addresses set");
9346 return -99;
9347 }
9348
9349 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009350 M (DHCP_PROXY_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009351
Damjan Marion7cd468a2016-12-19 23:05:39 +01009352 mp->is_add = is_add;
Neale Ranns20a175a2017-02-14 07:28:41 -08009353 mp->rx_vrf_id = ntohl (rx_vrf_id);
9354 mp->server_vrf_id = ntohl (server_vrf_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009355 if (v6_address_set)
9356 {
Jakub Grajciar103ba6b2019-10-01 11:30:56 +02009357 clib_memcpy (&mp->dhcp_server.un, &v6address, sizeof (v6address));
9358 clib_memcpy (&mp->dhcp_src_address.un, &v6srcaddress,
9359 sizeof (v6address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009360 }
9361 else
9362 {
Jakub Grajciar103ba6b2019-10-01 11:30:56 +02009363 clib_memcpy (&mp->dhcp_server.un, &v4address, sizeof (v4address));
9364 clib_memcpy (&mp->dhcp_src_address.un, &v4srcaddress,
9365 sizeof (v4address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009366 }
9367
9368 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009369 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009370
9371 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009372 W (ret);
9373 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009374}
9375
Neale Ranns20a175a2017-02-14 07:28:41 -08009376#define vl_api_dhcp_proxy_details_t_endian vl_noop_handler
9377#define vl_api_dhcp_proxy_details_t_print vl_noop_handler
9378
9379static void
9380vl_api_dhcp_proxy_details_t_handler (vl_api_dhcp_proxy_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009381{
Neale Ranns20a175a2017-02-14 07:28:41 -08009382 vat_main_t *vam = &vat_main;
Neale Ranns3466c302017-02-16 07:45:03 -08009383 u32 i, count = mp->count;
9384 vl_api_dhcp_server_t *s;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009385
Neale Ranns20a175a2017-02-14 07:28:41 -08009386 if (mp->is_ipv6)
9387 print (vam->ofp,
John Lo70bfcaf2017-11-14 13:19:26 -05009388 "RX Table-ID %d, Source Address %U, VSS Type %d, "
Igor Mikhailov (imichail)26f341a2018-02-12 13:45:51 -08009389 "VSS ASCII VPN-ID '%s', VSS RFC2685 VPN-ID (oui:id) %d:%d",
Neale Ranns20a175a2017-02-14 07:28:41 -08009390 ntohl (mp->rx_vrf_id),
Neale Ranns20a175a2017-02-14 07:28:41 -08009391 format_ip6_address, mp->dhcp_src_address,
John Lo70bfcaf2017-11-14 13:19:26 -05009392 mp->vss_type, mp->vss_vpn_ascii_id,
Neale Ranns20a175a2017-02-14 07:28:41 -08009393 ntohl (mp->vss_oui), ntohl (mp->vss_fib_id));
9394 else
9395 print (vam->ofp,
John Lo70bfcaf2017-11-14 13:19:26 -05009396 "RX Table-ID %d, Source Address %U, VSS Type %d, "
Igor Mikhailov (imichail)26f341a2018-02-12 13:45:51 -08009397 "VSS ASCII VPN-ID '%s', VSS RFC2685 VPN-ID (oui:id) %d:%d",
Neale Ranns20a175a2017-02-14 07:28:41 -08009398 ntohl (mp->rx_vrf_id),
Neale Ranns20a175a2017-02-14 07:28:41 -08009399 format_ip4_address, mp->dhcp_src_address,
John Lo70bfcaf2017-11-14 13:19:26 -05009400 mp->vss_type, mp->vss_vpn_ascii_id,
Neale Ranns20a175a2017-02-14 07:28:41 -08009401 ntohl (mp->vss_oui), ntohl (mp->vss_fib_id));
Neale Ranns3466c302017-02-16 07:45:03 -08009402
9403 for (i = 0; i < count; i++)
9404 {
9405 s = &mp->servers[i];
9406
9407 if (mp->is_ipv6)
9408 print (vam->ofp,
9409 " Server Table-ID %d, Server Address %U",
9410 ntohl (s->server_vrf_id), format_ip6_address, s->dhcp_server);
9411 else
9412 print (vam->ofp,
9413 " Server Table-ID %d, Server Address %U",
9414 ntohl (s->server_vrf_id), format_ip4_address, s->dhcp_server);
9415 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009416}
Damjan Marion7cd468a2016-12-19 23:05:39 +01009417
Neale Ranns20a175a2017-02-14 07:28:41 -08009418static void vl_api_dhcp_proxy_details_t_handler_json
9419 (vl_api_dhcp_proxy_details_t * mp)
9420{
9421 vat_main_t *vam = &vat_main;
9422 vat_json_node_t *node = NULL;
Neale Ranns3466c302017-02-16 07:45:03 -08009423 u32 i, count = mp->count;
Neale Ranns20a175a2017-02-14 07:28:41 -08009424 struct in_addr ip4;
9425 struct in6_addr ip6;
Neale Ranns3466c302017-02-16 07:45:03 -08009426 vl_api_dhcp_server_t *s;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009427
Neale Ranns20a175a2017-02-14 07:28:41 -08009428 if (VAT_JSON_ARRAY != vam->json_tree.type)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009429 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009430 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9431 vat_json_init_array (&vam->json_tree);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009432 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009433 node = vat_json_array_add (&vam->json_tree);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009434
Neale Ranns20a175a2017-02-14 07:28:41 -08009435 vat_json_init_object (node);
9436 vat_json_object_add_uint (node, "rx-table-id", ntohl (mp->rx_vrf_id));
Jakub Grajciar103ba6b2019-10-01 11:30:56 +02009437 vat_json_object_add_uint (node, "vss-type", ntohl (mp->vss_type));
John Lo70bfcaf2017-11-14 13:19:26 -05009438 vat_json_object_add_string_copy (node, "vss-vpn-ascii-id",
9439 mp->vss_vpn_ascii_id);
Neale Ranns3466c302017-02-16 07:45:03 -08009440 vat_json_object_add_uint (node, "vss-fib-id", ntohl (mp->vss_fib_id));
9441 vat_json_object_add_uint (node, "vss-oui", ntohl (mp->vss_oui));
9442
Neale Ranns20a175a2017-02-14 07:28:41 -08009443 if (mp->is_ipv6)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009444 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009445 clib_memcpy (&ip6, &mp->dhcp_src_address, sizeof (ip6));
9446 vat_json_object_add_ip6 (node, "src_address", ip6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009447 }
9448 else
9449 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009450 clib_memcpy (&ip4, &mp->dhcp_src_address, sizeof (ip4));
9451 vat_json_object_add_ip4 (node, "src_address", ip4);
9452 }
Neale Ranns3466c302017-02-16 07:45:03 -08009453
9454 for (i = 0; i < count; i++)
9455 {
9456 s = &mp->servers[i];
9457
9458 vat_json_object_add_uint (node, "server-table-id",
9459 ntohl (s->server_vrf_id));
9460
9461 if (mp->is_ipv6)
9462 {
9463 clib_memcpy (&ip4, &s->dhcp_server, sizeof (ip4));
9464 vat_json_object_add_ip4 (node, "src_address", ip4);
9465 }
9466 else
9467 {
9468 clib_memcpy (&ip6, &s->dhcp_server, sizeof (ip6));
9469 vat_json_object_add_ip6 (node, "server_address", ip6);
9470 }
9471 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009472}
9473
9474static int
9475api_dhcp_proxy_dump (vat_main_t * vam)
9476{
9477 unformat_input_t *i = vam->input;
9478 vl_api_control_ping_t *mp_ping;
9479 vl_api_dhcp_proxy_dump_t *mp;
9480 u8 is_ipv6 = 0;
9481 int ret;
9482
9483 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9484 {
9485 if (unformat (i, "ipv6"))
9486 is_ipv6 = 1;
9487 else
9488 {
9489 clib_warning ("parse error '%U'", format_unformat_error, i);
9490 return -99;
9491 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01009492 }
9493
Neale Ranns20a175a2017-02-14 07:28:41 -08009494 M (DHCP_PROXY_DUMP, mp);
9495
9496 mp->is_ip6 = is_ipv6;
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009497 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009498
Neale Ranns20a175a2017-02-14 07:28:41 -08009499 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04009500 MPING (CONTROL_PING, mp_ping);
Neale Ranns20a175a2017-02-14 07:28:41 -08009501 S (mp_ping);
9502
Jon Loeliger56c7b012017-02-01 12:31:41 -06009503 W (ret);
9504 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009505}
9506
9507static int
9508api_dhcp_proxy_set_vss (vat_main_t * vam)
9509{
9510 unformat_input_t *i = vam->input;
9511 vl_api_dhcp_proxy_set_vss_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009512 u8 is_ipv6 = 0;
9513 u8 is_add = 1;
John Lo70bfcaf2017-11-14 13:19:26 -05009514 u32 tbl_id = ~0;
9515 u8 vss_type = VSS_TYPE_DEFAULT;
9516 u8 *vpn_ascii_id = 0;
9517 u32 oui = 0;
9518 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009519 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009520
9521 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9522 {
9523 if (unformat (i, "tbl_id %d", &tbl_id))
John Lo70bfcaf2017-11-14 13:19:26 -05009524 ;
9525 else if (unformat (i, "vpn_ascii_id %s", &vpn_ascii_id))
9526 vss_type = VSS_TYPE_ASCII;
9527 else if (unformat (i, "fib_id %d", &fib_id))
9528 vss_type = VSS_TYPE_VPN_ID;
9529 else if (unformat (i, "oui %d", &oui))
9530 vss_type = VSS_TYPE_VPN_ID;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009531 else if (unformat (i, "ipv6"))
9532 is_ipv6 = 1;
9533 else if (unformat (i, "del"))
9534 is_add = 0;
9535 else
John Lo70bfcaf2017-11-14 13:19:26 -05009536 break;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009537 }
9538
John Lo70bfcaf2017-11-14 13:19:26 -05009539 if (tbl_id == ~0)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009540 {
John Lo70bfcaf2017-11-14 13:19:26 -05009541 errmsg ("missing tbl_id ");
9542 vec_free (vpn_ascii_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009543 return -99;
9544 }
9545
John Lo70bfcaf2017-11-14 13:19:26 -05009546 if ((vpn_ascii_id) && (vec_len (vpn_ascii_id) > 128))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009547 {
John Lo70bfcaf2017-11-14 13:19:26 -05009548 errmsg ("vpn_ascii_id cannot be longer than 128 ");
9549 vec_free (vpn_ascii_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009550 return -99;
9551 }
9552
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009553 M (DHCP_PROXY_SET_VSS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009554 mp->tbl_id = ntohl (tbl_id);
John Lo70bfcaf2017-11-14 13:19:26 -05009555 mp->vss_type = vss_type;
9556 if (vpn_ascii_id)
9557 {
9558 clib_memcpy (mp->vpn_ascii_id, vpn_ascii_id, vec_len (vpn_ascii_id));
9559 mp->vpn_ascii_id[vec_len (vpn_ascii_id)] = 0;
9560 }
9561 mp->vpn_index = ntohl (fib_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009562 mp->oui = ntohl (oui);
9563 mp->is_ipv6 = is_ipv6;
9564 mp->is_add = is_add;
9565
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009566 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009567 W (ret);
John Lo70bfcaf2017-11-14 13:19:26 -05009568
9569 vec_free (vpn_ascii_id);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009570 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009571}
9572
9573static int
9574api_dhcp_client_config (vat_main_t * vam)
9575{
9576 unformat_input_t *i = vam->input;
9577 vl_api_dhcp_client_config_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009578 u32 sw_if_index;
9579 u8 sw_if_index_set = 0;
9580 u8 is_add = 1;
9581 u8 *hostname = 0;
9582 u8 disable_event = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009583 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009584
9585 /* Parse args required to build the message */
9586 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9587 {
9588 if (unformat (i, "del"))
9589 is_add = 0;
9590 else
9591 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9592 sw_if_index_set = 1;
9593 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9594 sw_if_index_set = 1;
9595 else if (unformat (i, "hostname %s", &hostname))
9596 ;
9597 else if (unformat (i, "disable_event"))
9598 disable_event = 1;
9599 else
9600 break;
9601 }
9602
9603 if (sw_if_index_set == 0)
9604 {
9605 errmsg ("missing interface name or sw_if_index");
9606 return -99;
9607 }
9608
9609 if (vec_len (hostname) > 63)
9610 {
9611 errmsg ("hostname too long");
9612 }
9613 vec_add1 (hostname, 0);
9614
9615 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009616 M (DHCP_CLIENT_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009617
Damjan Marion7cd468a2016-12-19 23:05:39 +01009618 mp->is_add = is_add;
Neale Rannsdaff1782018-05-16 04:12:18 -07009619 mp->client.sw_if_index = htonl (sw_if_index);
9620 clib_memcpy (mp->client.hostname, hostname, vec_len (hostname));
9621 vec_free (hostname);
9622 mp->client.want_dhcp_event = disable_event ? 0 : 1;
9623 mp->client.pid = htonl (getpid ());
Damjan Marion7cd468a2016-12-19 23:05:39 +01009624
9625 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009626 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009627
9628 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009629 W (ret);
9630 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009631}
9632
9633static int
9634api_set_ip_flow_hash (vat_main_t * vam)
9635{
9636 unformat_input_t *i = vam->input;
9637 vl_api_set_ip_flow_hash_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009638 u32 vrf_id = 0;
9639 u8 is_ipv6 = 0;
9640 u8 vrf_id_set = 0;
9641 u8 src = 0;
9642 u8 dst = 0;
9643 u8 sport = 0;
9644 u8 dport = 0;
9645 u8 proto = 0;
9646 u8 reverse = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009647 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009648
9649 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9650 {
9651 if (unformat (i, "vrf %d", &vrf_id))
9652 vrf_id_set = 1;
9653 else if (unformat (i, "ipv6"))
9654 is_ipv6 = 1;
9655 else if (unformat (i, "src"))
9656 src = 1;
9657 else if (unformat (i, "dst"))
9658 dst = 1;
9659 else if (unformat (i, "sport"))
9660 sport = 1;
9661 else if (unformat (i, "dport"))
9662 dport = 1;
9663 else if (unformat (i, "proto"))
9664 proto = 1;
9665 else if (unformat (i, "reverse"))
9666 reverse = 1;
9667
9668 else
9669 {
9670 clib_warning ("parse error '%U'", format_unformat_error, i);
9671 return -99;
9672 }
9673 }
9674
9675 if (vrf_id_set == 0)
9676 {
9677 errmsg ("missing vrf id");
9678 return -99;
9679 }
9680
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009681 M (SET_IP_FLOW_HASH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009682 mp->src = src;
9683 mp->dst = dst;
9684 mp->sport = sport;
9685 mp->dport = dport;
9686 mp->proto = proto;
9687 mp->reverse = reverse;
9688 mp->vrf_id = ntohl (vrf_id);
9689 mp->is_ipv6 = is_ipv6;
9690
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009691 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009692 W (ret);
9693 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009694}
9695
9696static int
9697api_sw_interface_ip6_enable_disable (vat_main_t * vam)
9698{
9699 unformat_input_t *i = vam->input;
9700 vl_api_sw_interface_ip6_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009701 u32 sw_if_index;
9702 u8 sw_if_index_set = 0;
9703 u8 enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009704 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009705
9706 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9707 {
9708 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9709 sw_if_index_set = 1;
9710 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9711 sw_if_index_set = 1;
9712 else if (unformat (i, "enable"))
9713 enable = 1;
9714 else if (unformat (i, "disable"))
9715 enable = 0;
9716 else
9717 {
9718 clib_warning ("parse error '%U'", format_unformat_error, i);
9719 return -99;
9720 }
9721 }
9722
9723 if (sw_if_index_set == 0)
9724 {
9725 errmsg ("missing interface name or sw_if_index");
9726 return -99;
9727 }
9728
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009729 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009730
9731 mp->sw_if_index = ntohl (sw_if_index);
9732 mp->enable = enable;
9733
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009734 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009735 W (ret);
9736 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009737}
9738
9739static int
Neale Ranns3f844d02017-02-18 00:03:54 -08009740api_ip6nd_proxy_add_del (vat_main_t * vam)
9741{
9742 unformat_input_t *i = vam->input;
9743 vl_api_ip6nd_proxy_add_del_t *mp;
9744 u32 sw_if_index = ~0;
9745 u8 v6_address_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -07009746 vl_api_ip6_address_t v6address;
Neale Ranns3f844d02017-02-18 00:03:54 -08009747 u8 is_del = 0;
9748 int ret;
9749
9750 /* Parse args required to build the message */
9751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9752 {
9753 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9754 ;
9755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9756 ;
Neale Ranns37029302018-08-10 05:30:06 -07009757 else if (unformat (i, "%U", unformat_vl_api_ip6_address, &v6address))
Neale Ranns3f844d02017-02-18 00:03:54 -08009758 v6_address_set = 1;
9759 if (unformat (i, "del"))
9760 is_del = 1;
9761 else
9762 {
9763 clib_warning ("parse error '%U'", format_unformat_error, i);
9764 return -99;
9765 }
9766 }
9767
9768 if (sw_if_index == ~0)
9769 {
9770 errmsg ("missing interface name or sw_if_index");
9771 return -99;
9772 }
9773 if (!v6_address_set)
9774 {
9775 errmsg ("no address set");
9776 return -99;
9777 }
9778
9779 /* Construct the API message */
9780 M (IP6ND_PROXY_ADD_DEL, mp);
9781
9782 mp->is_del = is_del;
9783 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07009784 clib_memcpy (mp->ip, v6address, sizeof (v6address));
Neale Ranns3f844d02017-02-18 00:03:54 -08009785
9786 /* send it... */
9787 S (mp);
9788
9789 /* Wait for a reply, return good/bad news */
9790 W (ret);
9791 return ret;
9792}
9793
9794static int
9795api_ip6nd_proxy_dump (vat_main_t * vam)
9796{
9797 vl_api_ip6nd_proxy_dump_t *mp;
9798 vl_api_control_ping_t *mp_ping;
9799 int ret;
9800
9801 M (IP6ND_PROXY_DUMP, mp);
9802
9803 S (mp);
9804
9805 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04009806 MPING (CONTROL_PING, mp_ping);
Neale Ranns3f844d02017-02-18 00:03:54 -08009807 S (mp_ping);
9808
9809 W (ret);
9810 return ret;
9811}
9812
9813static void vl_api_ip6nd_proxy_details_t_handler
9814 (vl_api_ip6nd_proxy_details_t * mp)
9815{
9816 vat_main_t *vam = &vat_main;
9817
9818 print (vam->ofp, "host %U sw_if_index %d",
Neale Ranns37029302018-08-10 05:30:06 -07009819 format_vl_api_ip6_address, mp->ip, ntohl (mp->sw_if_index));
Neale Ranns3f844d02017-02-18 00:03:54 -08009820}
9821
9822static void vl_api_ip6nd_proxy_details_t_handler_json
9823 (vl_api_ip6nd_proxy_details_t * mp)
9824{
9825 vat_main_t *vam = &vat_main;
9826 struct in6_addr ip6;
9827 vat_json_node_t *node = NULL;
9828
9829 if (VAT_JSON_ARRAY != vam->json_tree.type)
9830 {
9831 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9832 vat_json_init_array (&vam->json_tree);
9833 }
9834 node = vat_json_array_add (&vam->json_tree);
9835
9836 vat_json_init_object (node);
9837 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9838
Neale Ranns37029302018-08-10 05:30:06 -07009839 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
Neale Ranns3f844d02017-02-18 00:03:54 -08009840 vat_json_object_add_ip6 (node, "host", ip6);
9841}
Damjan Marion7cd468a2016-12-19 23:05:39 +01009842
9843static int
9844api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
9845{
9846 unformat_input_t *i = vam->input;
9847 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009848 u32 sw_if_index;
9849 u8 sw_if_index_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009850 u8 v6_address_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -07009851 vl_api_prefix_t pfx;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009852 u8 use_default = 0;
9853 u8 no_advertise = 0;
9854 u8 off_link = 0;
9855 u8 no_autoconfig = 0;
9856 u8 no_onlink = 0;
9857 u8 is_no = 0;
9858 u32 val_lifetime = 0;
9859 u32 pref_lifetime = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009860 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009861
9862 /* Parse args required to build the message */
9863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9864 {
9865 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9866 sw_if_index_set = 1;
9867 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9868 sw_if_index_set = 1;
Neale Ranns37029302018-08-10 05:30:06 -07009869 else if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009870 v6_address_set = 1;
9871 else if (unformat (i, "val_life %d", &val_lifetime))
9872 ;
9873 else if (unformat (i, "pref_life %d", &pref_lifetime))
9874 ;
9875 else if (unformat (i, "def"))
9876 use_default = 1;
9877 else if (unformat (i, "noadv"))
9878 no_advertise = 1;
9879 else if (unformat (i, "offl"))
9880 off_link = 1;
9881 else if (unformat (i, "noauto"))
9882 no_autoconfig = 1;
9883 else if (unformat (i, "nolink"))
9884 no_onlink = 1;
9885 else if (unformat (i, "isno"))
9886 is_no = 1;
9887 else
9888 {
9889 clib_warning ("parse error '%U'", format_unformat_error, i);
9890 return -99;
9891 }
9892 }
9893
9894 if (sw_if_index_set == 0)
9895 {
9896 errmsg ("missing interface name or sw_if_index");
9897 return -99;
9898 }
9899 if (!v6_address_set)
9900 {
9901 errmsg ("no address set");
9902 return -99;
9903 }
9904
9905 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009906 M (SW_INTERFACE_IP6ND_RA_PREFIX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009907
9908 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07009909 clib_memcpy (&mp->prefix, &pfx, sizeof (pfx));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009910 mp->use_default = use_default;
9911 mp->no_advertise = no_advertise;
9912 mp->off_link = off_link;
9913 mp->no_autoconfig = no_autoconfig;
9914 mp->no_onlink = no_onlink;
9915 mp->is_no = is_no;
9916 mp->val_lifetime = ntohl (val_lifetime);
9917 mp->pref_lifetime = ntohl (pref_lifetime);
9918
9919 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009920 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009921
9922 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009923 W (ret);
9924 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009925}
9926
9927static int
9928api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
9929{
9930 unformat_input_t *i = vam->input;
9931 vl_api_sw_interface_ip6nd_ra_config_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009932 u32 sw_if_index;
9933 u8 sw_if_index_set = 0;
9934 u8 suppress = 0;
9935 u8 managed = 0;
9936 u8 other = 0;
9937 u8 ll_option = 0;
9938 u8 send_unicast = 0;
9939 u8 cease = 0;
9940 u8 is_no = 0;
9941 u8 default_router = 0;
9942 u32 max_interval = 0;
9943 u32 min_interval = 0;
9944 u32 lifetime = 0;
9945 u32 initial_count = 0;
9946 u32 initial_interval = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009947 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009948
9949
9950 /* Parse args required to build the message */
9951 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9952 {
9953 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9954 sw_if_index_set = 1;
9955 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9956 sw_if_index_set = 1;
9957 else if (unformat (i, "maxint %d", &max_interval))
9958 ;
9959 else if (unformat (i, "minint %d", &min_interval))
9960 ;
9961 else if (unformat (i, "life %d", &lifetime))
9962 ;
9963 else if (unformat (i, "count %d", &initial_count))
9964 ;
9965 else if (unformat (i, "interval %d", &initial_interval))
9966 ;
9967 else if (unformat (i, "suppress") || unformat (i, "surpress"))
9968 suppress = 1;
9969 else if (unformat (i, "managed"))
9970 managed = 1;
9971 else if (unformat (i, "other"))
9972 other = 1;
9973 else if (unformat (i, "ll"))
9974 ll_option = 1;
9975 else if (unformat (i, "send"))
9976 send_unicast = 1;
9977 else if (unformat (i, "cease"))
9978 cease = 1;
9979 else if (unformat (i, "isno"))
9980 is_no = 1;
9981 else if (unformat (i, "def"))
9982 default_router = 1;
9983 else
9984 {
9985 clib_warning ("parse error '%U'", format_unformat_error, i);
9986 return -99;
9987 }
9988 }
9989
9990 if (sw_if_index_set == 0)
9991 {
9992 errmsg ("missing interface name or sw_if_index");
9993 return -99;
9994 }
9995
9996 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009997 M (SW_INTERFACE_IP6ND_RA_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009998
9999 mp->sw_if_index = ntohl (sw_if_index);
10000 mp->max_interval = ntohl (max_interval);
10001 mp->min_interval = ntohl (min_interval);
10002 mp->lifetime = ntohl (lifetime);
10003 mp->initial_count = ntohl (initial_count);
10004 mp->initial_interval = ntohl (initial_interval);
10005 mp->suppress = suppress;
10006 mp->managed = managed;
10007 mp->other = other;
10008 mp->ll_option = ll_option;
10009 mp->send_unicast = send_unicast;
10010 mp->cease = cease;
10011 mp->is_no = is_no;
10012 mp->default_router = default_router;
10013
10014 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010015 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010016
10017 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -060010018 W (ret);
10019 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010020}
10021
10022static int
10023api_set_arp_neighbor_limit (vat_main_t * vam)
10024{
10025 unformat_input_t *i = vam->input;
10026 vl_api_set_arp_neighbor_limit_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010027 u32 arp_nbr_limit;
10028 u8 limit_set = 0;
10029 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010030 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010031
10032 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10033 {
10034 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
10035 limit_set = 1;
10036 else if (unformat (i, "ipv6"))
10037 is_ipv6 = 1;
10038 else
10039 {
10040 clib_warning ("parse error '%U'", format_unformat_error, i);
10041 return -99;
10042 }
10043 }
10044
10045 if (limit_set == 0)
10046 {
10047 errmsg ("missing limit value");
10048 return -99;
10049 }
10050
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010051 M (SET_ARP_NEIGHBOR_LIMIT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010052
10053 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
10054 mp->is_ipv6 = is_ipv6;
10055
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010056 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010057 W (ret);
10058 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010059}
10060
10061static int
10062api_l2_patch_add_del (vat_main_t * vam)
10063{
10064 unformat_input_t *i = vam->input;
10065 vl_api_l2_patch_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010066 u32 rx_sw_if_index;
10067 u8 rx_sw_if_index_set = 0;
10068 u32 tx_sw_if_index;
10069 u8 tx_sw_if_index_set = 0;
10070 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010071 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010072
10073 /* Parse args required to build the message */
10074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10075 {
10076 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
10077 rx_sw_if_index_set = 1;
10078 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
10079 tx_sw_if_index_set = 1;
10080 else if (unformat (i, "rx"))
10081 {
10082 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10083 {
10084 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
10085 &rx_sw_if_index))
10086 rx_sw_if_index_set = 1;
10087 }
10088 else
10089 break;
10090 }
10091 else if (unformat (i, "tx"))
10092 {
10093 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10094 {
10095 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
10096 &tx_sw_if_index))
10097 tx_sw_if_index_set = 1;
10098 }
10099 else
10100 break;
10101 }
10102 else if (unformat (i, "del"))
10103 is_add = 0;
10104 else
10105 break;
10106 }
10107
10108 if (rx_sw_if_index_set == 0)
10109 {
10110 errmsg ("missing rx interface name or rx_sw_if_index");
10111 return -99;
10112 }
10113
10114 if (tx_sw_if_index_set == 0)
10115 {
10116 errmsg ("missing tx interface name or tx_sw_if_index");
10117 return -99;
10118 }
10119
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010120 M (L2_PATCH_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010121
10122 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
10123 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
10124 mp->is_add = is_add;
10125
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010126 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010127 W (ret);
10128 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010129}
10130
Pablo Camarillofb380952016-12-07 18:34:18 +010010131u8 is_del;
10132u8 localsid_addr[16];
10133u8 end_psp;
10134u8 behavior;
10135u32 sw_if_index;
10136u32 vlan_index;
10137u32 fib_table;
10138u8 nh_addr[16];
10139
10140static int
10141api_sr_localsid_add_del (vat_main_t * vam)
10142{
10143 unformat_input_t *i = vam->input;
10144 vl_api_sr_localsid_add_del_t *mp;
10145
10146 u8 is_del;
10147 ip6_address_t localsid;
10148 u8 end_psp = 0;
10149 u8 behavior = ~0;
10150 u32 sw_if_index;
10151 u32 fib_table = ~(u32) 0;
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010152 ip6_address_t nh_addr6;
10153 ip4_address_t nh_addr4;
Dave Barachb7b92992018-10-17 10:38:51 -040010154 clib_memset (&nh_addr6, 0, sizeof (ip6_address_t));
10155 clib_memset (&nh_addr4, 0, sizeof (ip4_address_t));
Pablo Camarillofb380952016-12-07 18:34:18 +010010156
10157 bool nexthop_set = 0;
10158
10159 int ret;
10160
10161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10162 {
10163 if (unformat (i, "del"))
10164 is_del = 1;
10165 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010166 else if (unformat (i, "next-hop %U", unformat_ip4_address, &nh_addr4))
10167 nexthop_set = 1;
10168 else if (unformat (i, "next-hop %U", unformat_ip6_address, &nh_addr6))
Pablo Camarillofb380952016-12-07 18:34:18 +010010169 nexthop_set = 1;
10170 else if (unformat (i, "behavior %u", &behavior));
10171 else if (unformat (i, "sw_if_index %u", &sw_if_index));
10172 else if (unformat (i, "fib-table %u", &fib_table));
10173 else if (unformat (i, "end.psp %u", &behavior));
10174 else
10175 break;
10176 }
10177
10178 M (SR_LOCALSID_ADD_DEL, mp);
10179
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010180 clib_memcpy (mp->localsid.addr, &localsid, sizeof (mp->localsid));
Pablo Camarillofb380952016-12-07 18:34:18 +010010181 if (nexthop_set)
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010182 {
Lijian Zhangec2a9bb2018-08-28 10:18:24 +080010183 clib_memcpy (mp->nh_addr6, &nh_addr6, sizeof (mp->nh_addr6));
10184 clib_memcpy (mp->nh_addr4, &nh_addr4, sizeof (mp->nh_addr4));
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010185 }
Pablo Camarillofb380952016-12-07 18:34:18 +010010186 mp->behavior = behavior;
10187 mp->sw_if_index = ntohl (sw_if_index);
10188 mp->fib_table = ntohl (fib_table);
10189 mp->end_psp = end_psp;
10190 mp->is_del = is_del;
10191
10192 S (mp);
10193 W (ret);
10194 return ret;
10195}
10196
Damjan Marion7cd468a2016-12-19 23:05:39 +010010197static int
10198api_ioam_enable (vat_main_t * vam)
10199{
10200 unformat_input_t *input = vam->input;
10201 vl_api_ioam_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010202 u32 id = 0;
10203 int has_trace_option = 0;
10204 int has_pot_option = 0;
10205 int has_seqno_option = 0;
10206 int has_analyse_option = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010207 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010208
10209 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10210 {
10211 if (unformat (input, "trace"))
10212 has_trace_option = 1;
10213 else if (unformat (input, "pot"))
10214 has_pot_option = 1;
10215 else if (unformat (input, "seqno"))
10216 has_seqno_option = 1;
10217 else if (unformat (input, "analyse"))
10218 has_analyse_option = 1;
10219 else
10220 break;
10221 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010222 M (IOAM_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010223 mp->id = htons (id);
10224 mp->seqno = has_seqno_option;
10225 mp->analyse = has_analyse_option;
10226 mp->pot_enable = has_pot_option;
10227 mp->trace_enable = has_trace_option;
10228
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010229 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010230 W (ret);
10231 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010232}
10233
10234
10235static int
10236api_ioam_disable (vat_main_t * vam)
10237{
10238 vl_api_ioam_disable_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010239 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010240
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010241 M (IOAM_DISABLE, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010242 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010243 W (ret);
10244 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010245}
10246
Damjan Marion7cd468a2016-12-19 23:05:39 +010010247#define foreach_tcp_proto_field \
10248_(src_port) \
10249_(dst_port)
10250
10251#define foreach_udp_proto_field \
10252_(src_port) \
10253_(dst_port)
10254
10255#define foreach_ip4_proto_field \
10256_(src_address) \
10257_(dst_address) \
10258_(tos) \
10259_(length) \
10260_(fragment_id) \
10261_(ttl) \
10262_(protocol) \
10263_(checksum)
10264
Dave Barach4a3f69c2017-02-22 12:44:56 -050010265typedef struct
10266{
10267 u16 src_port, dst_port;
10268} tcpudp_header_t;
10269
10270#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010010271uword
10272unformat_tcp_mask (unformat_input_t * input, va_list * args)
10273{
10274 u8 **maskp = va_arg (*args, u8 **);
10275 u8 *mask = 0;
10276 u8 found_something = 0;
10277 tcp_header_t *tcp;
10278
10279#define _(a) u8 a=0;
10280 foreach_tcp_proto_field;
10281#undef _
10282
10283 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10284 {
10285 if (0);
10286#define _(a) else if (unformat (input, #a)) a=1;
10287 foreach_tcp_proto_field
10288#undef _
10289 else
10290 break;
10291 }
10292
10293#define _(a) found_something += a;
10294 foreach_tcp_proto_field;
10295#undef _
10296
10297 if (found_something == 0)
10298 return 0;
10299
10300 vec_validate (mask, sizeof (*tcp) - 1);
10301
10302 tcp = (tcp_header_t *) mask;
10303
Dave Barachb7b92992018-10-17 10:38:51 -040010304#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010305 foreach_tcp_proto_field;
10306#undef _
10307
10308 *maskp = mask;
10309 return 1;
10310}
10311
10312uword
10313unformat_udp_mask (unformat_input_t * input, va_list * args)
10314{
10315 u8 **maskp = va_arg (*args, u8 **);
10316 u8 *mask = 0;
10317 u8 found_something = 0;
10318 udp_header_t *udp;
10319
10320#define _(a) u8 a=0;
10321 foreach_udp_proto_field;
10322#undef _
10323
10324 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10325 {
10326 if (0);
10327#define _(a) else if (unformat (input, #a)) a=1;
10328 foreach_udp_proto_field
10329#undef _
10330 else
10331 break;
10332 }
10333
10334#define _(a) found_something += a;
10335 foreach_udp_proto_field;
10336#undef _
10337
10338 if (found_something == 0)
10339 return 0;
10340
10341 vec_validate (mask, sizeof (*udp) - 1);
10342
10343 udp = (udp_header_t *) mask;
10344
Dave Barachb7b92992018-10-17 10:38:51 -040010345#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010346 foreach_udp_proto_field;
10347#undef _
10348
10349 *maskp = mask;
10350 return 1;
10351}
10352
Damjan Marion7cd468a2016-12-19 23:05:39 +010010353uword
10354unformat_l4_mask (unformat_input_t * input, va_list * args)
10355{
10356 u8 **maskp = va_arg (*args, u8 **);
10357 u16 src_port = 0, dst_port = 0;
10358 tcpudp_header_t *tcpudp;
10359
10360 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10361 {
10362 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
10363 return 1;
10364 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
10365 return 1;
10366 else if (unformat (input, "src_port"))
10367 src_port = 0xFFFF;
10368 else if (unformat (input, "dst_port"))
10369 dst_port = 0xFFFF;
10370 else
10371 return 0;
10372 }
10373
10374 if (!src_port && !dst_port)
10375 return 0;
10376
10377 u8 *mask = 0;
10378 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
10379
10380 tcpudp = (tcpudp_header_t *) mask;
10381 tcpudp->src_port = src_port;
10382 tcpudp->dst_port = dst_port;
10383
10384 *maskp = mask;
10385
10386 return 1;
10387}
10388
10389uword
10390unformat_ip4_mask (unformat_input_t * input, va_list * args)
10391{
10392 u8 **maskp = va_arg (*args, u8 **);
10393 u8 *mask = 0;
10394 u8 found_something = 0;
10395 ip4_header_t *ip;
10396
10397#define _(a) u8 a=0;
10398 foreach_ip4_proto_field;
10399#undef _
10400 u8 version = 0;
10401 u8 hdr_length = 0;
10402
10403
10404 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10405 {
10406 if (unformat (input, "version"))
10407 version = 1;
10408 else if (unformat (input, "hdr_length"))
10409 hdr_length = 1;
10410 else if (unformat (input, "src"))
10411 src_address = 1;
10412 else if (unformat (input, "dst"))
10413 dst_address = 1;
10414 else if (unformat (input, "proto"))
10415 protocol = 1;
10416
10417#define _(a) else if (unformat (input, #a)) a=1;
10418 foreach_ip4_proto_field
10419#undef _
10420 else
10421 break;
10422 }
10423
10424#define _(a) found_something += a;
10425 foreach_ip4_proto_field;
10426#undef _
10427
10428 if (found_something == 0)
10429 return 0;
10430
10431 vec_validate (mask, sizeof (*ip) - 1);
10432
10433 ip = (ip4_header_t *) mask;
10434
Dave Barachb7b92992018-10-17 10:38:51 -040010435#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010436 foreach_ip4_proto_field;
10437#undef _
10438
10439 ip->ip_version_and_header_length = 0;
10440
10441 if (version)
10442 ip->ip_version_and_header_length |= 0xF0;
10443
10444 if (hdr_length)
10445 ip->ip_version_and_header_length |= 0x0F;
10446
10447 *maskp = mask;
10448 return 1;
10449}
10450
10451#define foreach_ip6_proto_field \
10452_(src_address) \
10453_(dst_address) \
10454_(payload_length) \
10455_(hop_limit) \
10456_(protocol)
10457
10458uword
10459unformat_ip6_mask (unformat_input_t * input, va_list * args)
10460{
10461 u8 **maskp = va_arg (*args, u8 **);
10462 u8 *mask = 0;
10463 u8 found_something = 0;
10464 ip6_header_t *ip;
10465 u32 ip_version_traffic_class_and_flow_label;
10466
10467#define _(a) u8 a=0;
10468 foreach_ip6_proto_field;
10469#undef _
10470 u8 version = 0;
10471 u8 traffic_class = 0;
10472 u8 flow_label = 0;
10473
10474 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10475 {
10476 if (unformat (input, "version"))
10477 version = 1;
10478 else if (unformat (input, "traffic-class"))
10479 traffic_class = 1;
10480 else if (unformat (input, "flow-label"))
10481 flow_label = 1;
10482 else if (unformat (input, "src"))
10483 src_address = 1;
10484 else if (unformat (input, "dst"))
10485 dst_address = 1;
10486 else if (unformat (input, "proto"))
10487 protocol = 1;
10488
10489#define _(a) else if (unformat (input, #a)) a=1;
10490 foreach_ip6_proto_field
10491#undef _
10492 else
10493 break;
10494 }
10495
10496#define _(a) found_something += a;
10497 foreach_ip6_proto_field;
10498#undef _
10499
10500 if (found_something == 0)
10501 return 0;
10502
10503 vec_validate (mask, sizeof (*ip) - 1);
10504
10505 ip = (ip6_header_t *) mask;
10506
Dave Barachb7b92992018-10-17 10:38:51 -040010507#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010508 foreach_ip6_proto_field;
10509#undef _
10510
10511 ip_version_traffic_class_and_flow_label = 0;
10512
10513 if (version)
10514 ip_version_traffic_class_and_flow_label |= 0xF0000000;
10515
10516 if (traffic_class)
10517 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
10518
10519 if (flow_label)
10520 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
10521
10522 ip->ip_version_traffic_class_and_flow_label =
10523 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
10524
10525 *maskp = mask;
10526 return 1;
10527}
10528
10529uword
10530unformat_l3_mask (unformat_input_t * input, va_list * args)
10531{
10532 u8 **maskp = va_arg (*args, u8 **);
10533
10534 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10535 {
10536 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
10537 return 1;
10538 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
10539 return 1;
10540 else
10541 break;
10542 }
10543 return 0;
10544}
10545
10546uword
10547unformat_l2_mask (unformat_input_t * input, va_list * args)
10548{
10549 u8 **maskp = va_arg (*args, u8 **);
10550 u8 *mask = 0;
10551 u8 src = 0;
10552 u8 dst = 0;
10553 u8 proto = 0;
10554 u8 tag1 = 0;
10555 u8 tag2 = 0;
10556 u8 ignore_tag1 = 0;
10557 u8 ignore_tag2 = 0;
10558 u8 cos1 = 0;
10559 u8 cos2 = 0;
10560 u8 dot1q = 0;
10561 u8 dot1ad = 0;
10562 int len = 14;
10563
10564 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10565 {
10566 if (unformat (input, "src"))
10567 src = 1;
10568 else if (unformat (input, "dst"))
10569 dst = 1;
10570 else if (unformat (input, "proto"))
10571 proto = 1;
10572 else if (unformat (input, "tag1"))
10573 tag1 = 1;
10574 else if (unformat (input, "tag2"))
10575 tag2 = 1;
10576 else if (unformat (input, "ignore-tag1"))
10577 ignore_tag1 = 1;
10578 else if (unformat (input, "ignore-tag2"))
10579 ignore_tag2 = 1;
10580 else if (unformat (input, "cos1"))
10581 cos1 = 1;
10582 else if (unformat (input, "cos2"))
10583 cos2 = 1;
10584 else if (unformat (input, "dot1q"))
10585 dot1q = 1;
10586 else if (unformat (input, "dot1ad"))
10587 dot1ad = 1;
10588 else
10589 break;
10590 }
10591 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
10592 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
10593 return 0;
10594
10595 if (tag1 || ignore_tag1 || cos1 || dot1q)
10596 len = 18;
10597 if (tag2 || ignore_tag2 || cos2 || dot1ad)
10598 len = 22;
10599
10600 vec_validate (mask, len - 1);
10601
10602 if (dst)
Dave Barachb7b92992018-10-17 10:38:51 -040010603 clib_memset (mask, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010604
10605 if (src)
Dave Barachb7b92992018-10-17 10:38:51 -040010606 clib_memset (mask + 6, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010607
10608 if (tag2 || dot1ad)
10609 {
10610 /* inner vlan tag */
10611 if (tag2)
10612 {
10613 mask[19] = 0xff;
10614 mask[18] = 0x0f;
10615 }
10616 if (cos2)
10617 mask[18] |= 0xe0;
10618 if (proto)
10619 mask[21] = mask[20] = 0xff;
10620 if (tag1)
10621 {
10622 mask[15] = 0xff;
10623 mask[14] = 0x0f;
10624 }
10625 if (cos1)
10626 mask[14] |= 0xe0;
10627 *maskp = mask;
10628 return 1;
10629 }
10630 if (tag1 | dot1q)
10631 {
10632 if (tag1)
10633 {
10634 mask[15] = 0xff;
10635 mask[14] = 0x0f;
10636 }
10637 if (cos1)
10638 mask[14] |= 0xe0;
10639 if (proto)
10640 mask[16] = mask[17] = 0xff;
10641
10642 *maskp = mask;
10643 return 1;
10644 }
10645 if (cos2)
10646 mask[18] |= 0xe0;
10647 if (cos1)
10648 mask[14] |= 0xe0;
10649 if (proto)
10650 mask[12] = mask[13] = 0xff;
10651
10652 *maskp = mask;
10653 return 1;
10654}
10655
10656uword
10657unformat_classify_mask (unformat_input_t * input, va_list * args)
10658{
10659 u8 **maskp = va_arg (*args, u8 **);
10660 u32 *skipp = va_arg (*args, u32 *);
10661 u32 *matchp = va_arg (*args, u32 *);
10662 u32 match;
10663 u8 *mask = 0;
10664 u8 *l2 = 0;
10665 u8 *l3 = 0;
10666 u8 *l4 = 0;
10667 int i;
10668
10669 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10670 {
10671 if (unformat (input, "hex %U", unformat_hex_string, &mask))
10672 ;
10673 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
10674 ;
10675 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
10676 ;
10677 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
10678 ;
10679 else
10680 break;
10681 }
10682
10683 if (l4 && !l3)
10684 {
10685 vec_free (mask);
10686 vec_free (l2);
10687 vec_free (l4);
10688 return 0;
10689 }
10690
10691 if (mask || l2 || l3 || l4)
10692 {
10693 if (l2 || l3 || l4)
10694 {
10695 /* "With a free Ethernet header in every package" */
10696 if (l2 == 0)
10697 vec_validate (l2, 13);
10698 mask = l2;
10699 if (vec_len (l3))
10700 {
10701 vec_append (mask, l3);
10702 vec_free (l3);
10703 }
10704 if (vec_len (l4))
10705 {
10706 vec_append (mask, l4);
10707 vec_free (l4);
10708 }
10709 }
10710
10711 /* Scan forward looking for the first significant mask octet */
10712 for (i = 0; i < vec_len (mask); i++)
10713 if (mask[i])
10714 break;
10715
10716 /* compute (skip, match) params */
10717 *skipp = i / sizeof (u32x4);
10718 vec_delete (mask, *skipp * sizeof (u32x4), 0);
10719
10720 /* Pad mask to an even multiple of the vector size */
10721 while (vec_len (mask) % sizeof (u32x4))
10722 vec_add1 (mask, 0);
10723
10724 match = vec_len (mask) / sizeof (u32x4);
10725
10726 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
10727 {
10728 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
10729 if (*tmp || *(tmp + 1))
10730 break;
10731 match--;
10732 }
10733 if (match == 0)
10734 clib_warning ("BUG: match 0");
10735
10736 _vec_len (mask) = match * sizeof (u32x4);
10737
10738 *matchp = match;
10739 *maskp = mask;
10740
10741 return 1;
10742 }
10743
10744 return 0;
10745}
Dave Barach4a3f69c2017-02-22 12:44:56 -050010746#endif /* VPP_API_TEST_BUILTIN */
Damjan Marion7cd468a2016-12-19 23:05:39 +010010747
10748#define foreach_l2_next \
10749_(drop, DROP) \
10750_(ethernet, ETHERNET_INPUT) \
10751_(ip4, IP4_INPUT) \
10752_(ip6, IP6_INPUT)
10753
10754uword
10755unformat_l2_next_index (unformat_input_t * input, va_list * args)
10756{
10757 u32 *miss_next_indexp = va_arg (*args, u32 *);
10758 u32 next_index = 0;
10759 u32 tmp;
10760
10761#define _(n,N) \
10762 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
10763 foreach_l2_next;
10764#undef _
10765
10766 if (unformat (input, "%d", &tmp))
10767 {
10768 next_index = tmp;
10769 goto out;
10770 }
10771
10772 return 0;
10773
10774out:
10775 *miss_next_indexp = next_index;
10776 return 1;
10777}
10778
10779#define foreach_ip_next \
10780_(drop, DROP) \
10781_(local, LOCAL) \
10782_(rewrite, REWRITE)
10783
10784uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050010785api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010010786{
10787 u32 *miss_next_indexp = va_arg (*args, u32 *);
10788 u32 next_index = 0;
10789 u32 tmp;
10790
10791#define _(n,N) \
10792 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
10793 foreach_ip_next;
10794#undef _
10795
10796 if (unformat (input, "%d", &tmp))
10797 {
10798 next_index = tmp;
10799 goto out;
10800 }
10801
10802 return 0;
10803
10804out:
10805 *miss_next_indexp = next_index;
10806 return 1;
10807}
10808
10809#define foreach_acl_next \
10810_(deny, DENY)
10811
10812uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050010813api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010010814{
10815 u32 *miss_next_indexp = va_arg (*args, u32 *);
10816 u32 next_index = 0;
10817 u32 tmp;
10818
10819#define _(n,N) \
10820 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
10821 foreach_acl_next;
10822#undef _
10823
10824 if (unformat (input, "permit"))
10825 {
10826 next_index = ~0;
10827 goto out;
10828 }
10829 else if (unformat (input, "%d", &tmp))
10830 {
10831 next_index = tmp;
10832 goto out;
10833 }
10834
10835 return 0;
10836
10837out:
10838 *miss_next_indexp = next_index;
10839 return 1;
10840}
10841
10842uword
10843unformat_policer_precolor (unformat_input_t * input, va_list * args)
10844{
10845 u32 *r = va_arg (*args, u32 *);
10846
10847 if (unformat (input, "conform-color"))
10848 *r = POLICE_CONFORM;
10849 else if (unformat (input, "exceed-color"))
10850 *r = POLICE_EXCEED;
10851 else
10852 return 0;
10853
10854 return 1;
10855}
10856
10857static int
10858api_classify_add_del_table (vat_main_t * vam)
10859{
10860 unformat_input_t *i = vam->input;
10861 vl_api_classify_add_del_table_t *mp;
10862
10863 u32 nbuckets = 2;
10864 u32 skip = ~0;
10865 u32 match = ~0;
10866 int is_add = 1;
10867 int del_chain = 0;
10868 u32 table_index = ~0;
10869 u32 next_table_index = ~0;
10870 u32 miss_next_index = ~0;
10871 u32 memory_size = 32 << 20;
10872 u8 *mask = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010873 u32 current_data_flag = 0;
10874 int current_data_offset = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010875 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010876
10877 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10878 {
10879 if (unformat (i, "del"))
10880 is_add = 0;
10881 else if (unformat (i, "del-chain"))
10882 {
10883 is_add = 0;
10884 del_chain = 1;
10885 }
10886 else if (unformat (i, "buckets %d", &nbuckets))
10887 ;
10888 else if (unformat (i, "memory_size %d", &memory_size))
10889 ;
10890 else if (unformat (i, "skip %d", &skip))
10891 ;
10892 else if (unformat (i, "match %d", &match))
10893 ;
10894 else if (unformat (i, "table %d", &table_index))
10895 ;
10896 else if (unformat (i, "mask %U", unformat_classify_mask,
10897 &mask, &skip, &match))
10898 ;
10899 else if (unformat (i, "next-table %d", &next_table_index))
10900 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010901 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010902 &miss_next_index))
10903 ;
10904 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
10905 &miss_next_index))
10906 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010907 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010908 &miss_next_index))
10909 ;
10910 else if (unformat (i, "current-data-flag %d", &current_data_flag))
10911 ;
10912 else if (unformat (i, "current-data-offset %d", &current_data_offset))
10913 ;
10914 else
10915 break;
10916 }
10917
10918 if (is_add && mask == 0)
10919 {
10920 errmsg ("Mask required");
10921 return -99;
10922 }
10923
10924 if (is_add && skip == ~0)
10925 {
10926 errmsg ("skip count required");
10927 return -99;
10928 }
10929
10930 if (is_add && match == ~0)
10931 {
10932 errmsg ("match count required");
10933 return -99;
10934 }
10935
10936 if (!is_add && table_index == ~0)
10937 {
10938 errmsg ("table index required for delete");
10939 return -99;
10940 }
10941
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010942 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010943
10944 mp->is_add = is_add;
10945 mp->del_chain = del_chain;
10946 mp->table_index = ntohl (table_index);
10947 mp->nbuckets = ntohl (nbuckets);
10948 mp->memory_size = ntohl (memory_size);
10949 mp->skip_n_vectors = ntohl (skip);
10950 mp->match_n_vectors = ntohl (match);
10951 mp->next_table_index = ntohl (next_table_index);
10952 mp->miss_next_index = ntohl (miss_next_index);
10953 mp->current_data_flag = ntohl (current_data_flag);
10954 mp->current_data_offset = ntohl (current_data_offset);
Juraj Sloboda75282452018-06-12 14:20:49 +020010955 mp->mask_len = ntohl (vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010956 clib_memcpy (mp->mask, mask, vec_len (mask));
10957
10958 vec_free (mask);
10959
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010960 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010961 W (ret);
10962 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010963}
10964
Dave Barach4a3f69c2017-02-22 12:44:56 -050010965#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010010966uword
10967unformat_l4_match (unformat_input_t * input, va_list * args)
10968{
10969 u8 **matchp = va_arg (*args, u8 **);
10970
10971 u8 *proto_header = 0;
10972 int src_port = 0;
10973 int dst_port = 0;
10974
10975 tcpudp_header_t h;
10976
10977 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10978 {
10979 if (unformat (input, "src_port %d", &src_port))
10980 ;
10981 else if (unformat (input, "dst_port %d", &dst_port))
10982 ;
10983 else
10984 return 0;
10985 }
10986
10987 h.src_port = clib_host_to_net_u16 (src_port);
10988 h.dst_port = clib_host_to_net_u16 (dst_port);
10989 vec_validate (proto_header, sizeof (h) - 1);
10990 memcpy (proto_header, &h, sizeof (h));
10991
10992 *matchp = proto_header;
10993
10994 return 1;
10995}
10996
10997uword
10998unformat_ip4_match (unformat_input_t * input, va_list * args)
10999{
11000 u8 **matchp = va_arg (*args, u8 **);
11001 u8 *match = 0;
11002 ip4_header_t *ip;
11003 int version = 0;
11004 u32 version_val;
11005 int hdr_length = 0;
11006 u32 hdr_length_val;
11007 int src = 0, dst = 0;
11008 ip4_address_t src_val, dst_val;
11009 int proto = 0;
11010 u32 proto_val;
11011 int tos = 0;
11012 u32 tos_val;
11013 int length = 0;
11014 u32 length_val;
11015 int fragment_id = 0;
11016 u32 fragment_id_val;
11017 int ttl = 0;
11018 int ttl_val;
11019 int checksum = 0;
11020 u32 checksum_val;
11021
11022 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11023 {
11024 if (unformat (input, "version %d", &version_val))
11025 version = 1;
11026 else if (unformat (input, "hdr_length %d", &hdr_length_val))
11027 hdr_length = 1;
11028 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
11029 src = 1;
11030 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
11031 dst = 1;
11032 else if (unformat (input, "proto %d", &proto_val))
11033 proto = 1;
11034 else if (unformat (input, "tos %d", &tos_val))
11035 tos = 1;
11036 else if (unformat (input, "length %d", &length_val))
11037 length = 1;
11038 else if (unformat (input, "fragment_id %d", &fragment_id_val))
11039 fragment_id = 1;
11040 else if (unformat (input, "ttl %d", &ttl_val))
11041 ttl = 1;
11042 else if (unformat (input, "checksum %d", &checksum_val))
11043 checksum = 1;
11044 else
11045 break;
11046 }
11047
11048 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
11049 + ttl + checksum == 0)
11050 return 0;
11051
11052 /*
11053 * Aligned because we use the real comparison functions
11054 */
11055 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
11056
11057 ip = (ip4_header_t *) match;
11058
11059 /* These are realistically matched in practice */
11060 if (src)
11061 ip->src_address.as_u32 = src_val.as_u32;
11062
11063 if (dst)
11064 ip->dst_address.as_u32 = dst_val.as_u32;
11065
11066 if (proto)
11067 ip->protocol = proto_val;
11068
11069
11070 /* These are not, but they're included for completeness */
11071 if (version)
11072 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
11073
11074 if (hdr_length)
11075 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
11076
11077 if (tos)
11078 ip->tos = tos_val;
11079
11080 if (length)
11081 ip->length = clib_host_to_net_u16 (length_val);
11082
11083 if (ttl)
11084 ip->ttl = ttl_val;
11085
11086 if (checksum)
11087 ip->checksum = clib_host_to_net_u16 (checksum_val);
11088
11089 *matchp = match;
11090 return 1;
11091}
11092
11093uword
11094unformat_ip6_match (unformat_input_t * input, va_list * args)
11095{
11096 u8 **matchp = va_arg (*args, u8 **);
11097 u8 *match = 0;
11098 ip6_header_t *ip;
11099 int version = 0;
11100 u32 version_val;
11101 u8 traffic_class = 0;
11102 u32 traffic_class_val = 0;
11103 u8 flow_label = 0;
11104 u8 flow_label_val;
11105 int src = 0, dst = 0;
11106 ip6_address_t src_val, dst_val;
11107 int proto = 0;
11108 u32 proto_val;
11109 int payload_length = 0;
11110 u32 payload_length_val;
11111 int hop_limit = 0;
11112 int hop_limit_val;
11113 u32 ip_version_traffic_class_and_flow_label;
11114
11115 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11116 {
11117 if (unformat (input, "version %d", &version_val))
11118 version = 1;
11119 else if (unformat (input, "traffic_class %d", &traffic_class_val))
11120 traffic_class = 1;
11121 else if (unformat (input, "flow_label %d", &flow_label_val))
11122 flow_label = 1;
11123 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
11124 src = 1;
11125 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
11126 dst = 1;
11127 else if (unformat (input, "proto %d", &proto_val))
11128 proto = 1;
11129 else if (unformat (input, "payload_length %d", &payload_length_val))
11130 payload_length = 1;
11131 else if (unformat (input, "hop_limit %d", &hop_limit_val))
11132 hop_limit = 1;
11133 else
11134 break;
11135 }
11136
11137 if (version + traffic_class + flow_label + src + dst + proto +
11138 payload_length + hop_limit == 0)
11139 return 0;
11140
11141 /*
11142 * Aligned because we use the real comparison functions
11143 */
11144 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
11145
11146 ip = (ip6_header_t *) match;
11147
11148 if (src)
11149 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
11150
11151 if (dst)
11152 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
11153
11154 if (proto)
11155 ip->protocol = proto_val;
11156
11157 ip_version_traffic_class_and_flow_label = 0;
11158
11159 if (version)
11160 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
11161
11162 if (traffic_class)
11163 ip_version_traffic_class_and_flow_label |=
11164 (traffic_class_val & 0xFF) << 20;
11165
11166 if (flow_label)
11167 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
11168
11169 ip->ip_version_traffic_class_and_flow_label =
11170 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
11171
11172 if (payload_length)
11173 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
11174
11175 if (hop_limit)
11176 ip->hop_limit = hop_limit_val;
11177
11178 *matchp = match;
11179 return 1;
11180}
11181
11182uword
11183unformat_l3_match (unformat_input_t * input, va_list * args)
11184{
11185 u8 **matchp = va_arg (*args, u8 **);
11186
11187 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11188 {
11189 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
11190 return 1;
11191 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
11192 return 1;
11193 else
11194 break;
11195 }
11196 return 0;
11197}
11198
11199uword
11200unformat_vlan_tag (unformat_input_t * input, va_list * args)
11201{
11202 u8 *tagp = va_arg (*args, u8 *);
11203 u32 tag;
11204
11205 if (unformat (input, "%d", &tag))
11206 {
11207 tagp[0] = (tag >> 8) & 0x0F;
11208 tagp[1] = tag & 0xFF;
11209 return 1;
11210 }
11211
11212 return 0;
11213}
11214
11215uword
11216unformat_l2_match (unformat_input_t * input, va_list * args)
11217{
11218 u8 **matchp = va_arg (*args, u8 **);
11219 u8 *match = 0;
11220 u8 src = 0;
11221 u8 src_val[6];
11222 u8 dst = 0;
11223 u8 dst_val[6];
11224 u8 proto = 0;
11225 u16 proto_val;
11226 u8 tag1 = 0;
11227 u8 tag1_val[2];
11228 u8 tag2 = 0;
11229 u8 tag2_val[2];
11230 int len = 14;
11231 u8 ignore_tag1 = 0;
11232 u8 ignore_tag2 = 0;
11233 u8 cos1 = 0;
11234 u8 cos2 = 0;
11235 u32 cos1_val = 0;
11236 u32 cos2_val = 0;
11237
11238 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11239 {
11240 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
11241 src = 1;
11242 else
11243 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
11244 dst = 1;
11245 else if (unformat (input, "proto %U",
11246 unformat_ethernet_type_host_byte_order, &proto_val))
11247 proto = 1;
11248 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
11249 tag1 = 1;
11250 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
11251 tag2 = 1;
11252 else if (unformat (input, "ignore-tag1"))
11253 ignore_tag1 = 1;
11254 else if (unformat (input, "ignore-tag2"))
11255 ignore_tag2 = 1;
11256 else if (unformat (input, "cos1 %d", &cos1_val))
11257 cos1 = 1;
11258 else if (unformat (input, "cos2 %d", &cos2_val))
11259 cos2 = 1;
11260 else
11261 break;
11262 }
11263 if ((src + dst + proto + tag1 + tag2 +
11264 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
11265 return 0;
11266
11267 if (tag1 || ignore_tag1 || cos1)
11268 len = 18;
11269 if (tag2 || ignore_tag2 || cos2)
11270 len = 22;
11271
11272 vec_validate_aligned (match, len - 1, sizeof (u32x4));
11273
11274 if (dst)
11275 clib_memcpy (match, dst_val, 6);
11276
11277 if (src)
11278 clib_memcpy (match + 6, src_val, 6);
11279
11280 if (tag2)
11281 {
11282 /* inner vlan tag */
11283 match[19] = tag2_val[1];
11284 match[18] = tag2_val[0];
11285 if (cos2)
11286 match[18] |= (cos2_val & 0x7) << 5;
11287 if (proto)
11288 {
11289 match[21] = proto_val & 0xff;
11290 match[20] = proto_val >> 8;
11291 }
11292 if (tag1)
11293 {
11294 match[15] = tag1_val[1];
11295 match[14] = tag1_val[0];
11296 }
11297 if (cos1)
11298 match[14] |= (cos1_val & 0x7) << 5;
11299 *matchp = match;
11300 return 1;
11301 }
11302 if (tag1)
11303 {
11304 match[15] = tag1_val[1];
11305 match[14] = tag1_val[0];
11306 if (proto)
11307 {
11308 match[17] = proto_val & 0xff;
11309 match[16] = proto_val >> 8;
11310 }
11311 if (cos1)
11312 match[14] |= (cos1_val & 0x7) << 5;
11313
11314 *matchp = match;
11315 return 1;
11316 }
11317 if (cos2)
11318 match[18] |= (cos2_val & 0x7) << 5;
11319 if (cos1)
11320 match[14] |= (cos1_val & 0x7) << 5;
11321 if (proto)
11322 {
11323 match[13] = proto_val & 0xff;
11324 match[12] = proto_val >> 8;
11325 }
11326
11327 *matchp = match;
11328 return 1;
11329}
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070011330
11331uword
11332unformat_qos_source (unformat_input_t * input, va_list * args)
11333{
11334 int *qs = va_arg (*args, int *);
11335
11336 if (unformat (input, "ip"))
11337 *qs = QOS_SOURCE_IP;
11338 else if (unformat (input, "mpls"))
11339 *qs = QOS_SOURCE_MPLS;
11340 else if (unformat (input, "ext"))
11341 *qs = QOS_SOURCE_EXT;
11342 else if (unformat (input, "vlan"))
11343 *qs = QOS_SOURCE_VLAN;
11344 else
11345 return 0;
11346
11347 return 1;
11348}
Dave Barach4a3f69c2017-02-22 12:44:56 -050011349#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010011350
11351uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050011352api_unformat_classify_match (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010011353{
11354 u8 **matchp = va_arg (*args, u8 **);
11355 u32 skip_n_vectors = va_arg (*args, u32);
11356 u32 match_n_vectors = va_arg (*args, u32);
11357
11358 u8 *match = 0;
11359 u8 *l2 = 0;
11360 u8 *l3 = 0;
11361 u8 *l4 = 0;
11362
11363 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11364 {
11365 if (unformat (input, "hex %U", unformat_hex_string, &match))
11366 ;
11367 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
11368 ;
11369 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
11370 ;
11371 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
11372 ;
11373 else
11374 break;
11375 }
11376
11377 if (l4 && !l3)
11378 {
11379 vec_free (match);
11380 vec_free (l2);
11381 vec_free (l4);
11382 return 0;
11383 }
11384
11385 if (match || l2 || l3 || l4)
11386 {
11387 if (l2 || l3 || l4)
11388 {
11389 /* "Win a free Ethernet header in every packet" */
11390 if (l2 == 0)
11391 vec_validate_aligned (l2, 13, sizeof (u32x4));
11392 match = l2;
11393 if (vec_len (l3))
11394 {
11395 vec_append_aligned (match, l3, sizeof (u32x4));
11396 vec_free (l3);
11397 }
11398 if (vec_len (l4))
11399 {
11400 vec_append_aligned (match, l4, sizeof (u32x4));
11401 vec_free (l4);
11402 }
11403 }
11404
11405 /* Make sure the vector is big enough even if key is all 0's */
11406 vec_validate_aligned
11407 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
11408 sizeof (u32x4));
11409
11410 /* Set size, include skipped vectors */
11411 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
11412
11413 *matchp = match;
11414
11415 return 1;
11416 }
11417
11418 return 0;
11419}
11420
11421static int
11422api_classify_add_del_session (vat_main_t * vam)
11423{
11424 unformat_input_t *i = vam->input;
11425 vl_api_classify_add_del_session_t *mp;
11426 int is_add = 1;
11427 u32 table_index = ~0;
11428 u32 hit_next_index = ~0;
11429 u32 opaque_index = ~0;
11430 u8 *match = 0;
11431 i32 advance = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011432 u32 skip_n_vectors = 0;
11433 u32 match_n_vectors = 0;
11434 u32 action = 0;
11435 u32 metadata = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011436 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011437
11438 /*
11439 * Warning: you have to supply skip_n and match_n
11440 * because the API client cant simply look at the classify
11441 * table object.
11442 */
11443
11444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11445 {
11446 if (unformat (i, "del"))
11447 is_add = 0;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011448 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011449 &hit_next_index))
11450 ;
11451 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
11452 &hit_next_index))
11453 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011454 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011455 &hit_next_index))
11456 ;
11457 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
11458 ;
11459 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
11460 ;
11461 else if (unformat (i, "opaque-index %d", &opaque_index))
11462 ;
11463 else if (unformat (i, "skip_n %d", &skip_n_vectors))
11464 ;
11465 else if (unformat (i, "match_n %d", &match_n_vectors))
11466 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011467 else if (unformat (i, "match %U", api_unformat_classify_match,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011468 &match, skip_n_vectors, match_n_vectors))
11469 ;
11470 else if (unformat (i, "advance %d", &advance))
11471 ;
11472 else if (unformat (i, "table-index %d", &table_index))
11473 ;
11474 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
11475 action = 1;
11476 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
11477 action = 2;
11478 else if (unformat (i, "action %d", &action))
11479 ;
11480 else if (unformat (i, "metadata %d", &metadata))
11481 ;
11482 else
11483 break;
11484 }
11485
11486 if (table_index == ~0)
11487 {
11488 errmsg ("Table index required");
11489 return -99;
11490 }
11491
11492 if (is_add && match == 0)
11493 {
11494 errmsg ("Match value required");
11495 return -99;
11496 }
11497
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011498 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011499
11500 mp->is_add = is_add;
11501 mp->table_index = ntohl (table_index);
11502 mp->hit_next_index = ntohl (hit_next_index);
11503 mp->opaque_index = ntohl (opaque_index);
11504 mp->advance = ntohl (advance);
11505 mp->action = action;
11506 mp->metadata = ntohl (metadata);
Juraj Sloboda75282452018-06-12 14:20:49 +020011507 mp->match_len = ntohl (vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011508 clib_memcpy (mp->match, match, vec_len (match));
11509 vec_free (match);
11510
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011511 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011512 W (ret);
11513 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011514}
11515
11516static int
11517api_classify_set_interface_ip_table (vat_main_t * vam)
11518{
11519 unformat_input_t *i = vam->input;
11520 vl_api_classify_set_interface_ip_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011521 u32 sw_if_index;
11522 int sw_if_index_set;
11523 u32 table_index = ~0;
11524 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011525 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011526
11527 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11528 {
11529 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11530 sw_if_index_set = 1;
11531 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11532 sw_if_index_set = 1;
11533 else if (unformat (i, "table %d", &table_index))
11534 ;
11535 else
11536 {
11537 clib_warning ("parse error '%U'", format_unformat_error, i);
11538 return -99;
11539 }
11540 }
11541
11542 if (sw_if_index_set == 0)
11543 {
11544 errmsg ("missing interface name or sw_if_index");
11545 return -99;
11546 }
11547
11548
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011549 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011550
11551 mp->sw_if_index = ntohl (sw_if_index);
11552 mp->table_index = ntohl (table_index);
11553 mp->is_ipv6 = is_ipv6;
11554
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011555 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011556 W (ret);
11557 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011558}
11559
11560static int
11561api_classify_set_interface_l2_tables (vat_main_t * vam)
11562{
11563 unformat_input_t *i = vam->input;
11564 vl_api_classify_set_interface_l2_tables_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011565 u32 sw_if_index;
11566 int sw_if_index_set;
11567 u32 ip4_table_index = ~0;
11568 u32 ip6_table_index = ~0;
11569 u32 other_table_index = ~0;
11570 u32 is_input = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011571 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011572
11573 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11574 {
11575 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11576 sw_if_index_set = 1;
11577 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11578 sw_if_index_set = 1;
11579 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11580 ;
11581 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11582 ;
11583 else if (unformat (i, "other-table %d", &other_table_index))
11584 ;
11585 else if (unformat (i, "is-input %d", &is_input))
11586 ;
11587 else
11588 {
11589 clib_warning ("parse error '%U'", format_unformat_error, i);
11590 return -99;
11591 }
11592 }
11593
11594 if (sw_if_index_set == 0)
11595 {
11596 errmsg ("missing interface name or sw_if_index");
11597 return -99;
11598 }
11599
11600
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011601 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011602
11603 mp->sw_if_index = ntohl (sw_if_index);
11604 mp->ip4_table_index = ntohl (ip4_table_index);
11605 mp->ip6_table_index = ntohl (ip6_table_index);
11606 mp->other_table_index = ntohl (other_table_index);
11607 mp->is_input = (u8) is_input;
11608
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011609 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011610 W (ret);
11611 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011612}
11613
11614static int
11615api_set_ipfix_exporter (vat_main_t * vam)
11616{
11617 unformat_input_t *i = vam->input;
11618 vl_api_set_ipfix_exporter_t *mp;
11619 ip4_address_t collector_address;
11620 u8 collector_address_set = 0;
11621 u32 collector_port = ~0;
11622 ip4_address_t src_address;
11623 u8 src_address_set = 0;
11624 u32 vrf_id = ~0;
11625 u32 path_mtu = ~0;
11626 u32 template_interval = ~0;
11627 u8 udp_checksum = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011628 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011629
11630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11631 {
11632 if (unformat (i, "collector_address %U", unformat_ip4_address,
11633 &collector_address))
11634 collector_address_set = 1;
11635 else if (unformat (i, "collector_port %d", &collector_port))
11636 ;
11637 else if (unformat (i, "src_address %U", unformat_ip4_address,
11638 &src_address))
11639 src_address_set = 1;
11640 else if (unformat (i, "vrf_id %d", &vrf_id))
11641 ;
11642 else if (unformat (i, "path_mtu %d", &path_mtu))
11643 ;
11644 else if (unformat (i, "template_interval %d", &template_interval))
11645 ;
11646 else if (unformat (i, "udp_checksum"))
11647 udp_checksum = 1;
11648 else
11649 break;
11650 }
11651
11652 if (collector_address_set == 0)
11653 {
11654 errmsg ("collector_address required");
11655 return -99;
11656 }
11657
11658 if (src_address_set == 0)
11659 {
11660 errmsg ("src_address required");
11661 return -99;
11662 }
11663
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011664 M (SET_IPFIX_EXPORTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011665
11666 memcpy (mp->collector_address, collector_address.data,
11667 sizeof (collector_address.data));
11668 mp->collector_port = htons ((u16) collector_port);
11669 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
11670 mp->vrf_id = htonl (vrf_id);
11671 mp->path_mtu = htonl (path_mtu);
11672 mp->template_interval = htonl (template_interval);
11673 mp->udp_checksum = udp_checksum;
11674
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011675 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011676 W (ret);
11677 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011678}
11679
11680static int
11681api_set_ipfix_classify_stream (vat_main_t * vam)
11682{
11683 unformat_input_t *i = vam->input;
11684 vl_api_set_ipfix_classify_stream_t *mp;
11685 u32 domain_id = 0;
11686 u32 src_port = UDP_DST_PORT_ipfix;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011687 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011688
11689 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11690 {
11691 if (unformat (i, "domain %d", &domain_id))
11692 ;
11693 else if (unformat (i, "src_port %d", &src_port))
11694 ;
11695 else
11696 {
11697 errmsg ("unknown input `%U'", format_unformat_error, i);
11698 return -99;
11699 }
11700 }
11701
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011702 M (SET_IPFIX_CLASSIFY_STREAM, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011703
11704 mp->domain_id = htonl (domain_id);
11705 mp->src_port = htons ((u16) src_port);
11706
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011707 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011708 W (ret);
11709 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011710}
11711
11712static int
11713api_ipfix_classify_table_add_del (vat_main_t * vam)
11714{
11715 unformat_input_t *i = vam->input;
11716 vl_api_ipfix_classify_table_add_del_t *mp;
11717 int is_add = -1;
11718 u32 classify_table_index = ~0;
11719 u8 ip_version = 0;
11720 u8 transport_protocol = 255;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011721 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011722
11723 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11724 {
11725 if (unformat (i, "add"))
11726 is_add = 1;
11727 else if (unformat (i, "del"))
11728 is_add = 0;
11729 else if (unformat (i, "table %d", &classify_table_index))
11730 ;
11731 else if (unformat (i, "ip4"))
11732 ip_version = 4;
11733 else if (unformat (i, "ip6"))
11734 ip_version = 6;
11735 else if (unformat (i, "tcp"))
11736 transport_protocol = 6;
11737 else if (unformat (i, "udp"))
11738 transport_protocol = 17;
11739 else
11740 {
11741 errmsg ("unknown input `%U'", format_unformat_error, i);
11742 return -99;
11743 }
11744 }
11745
11746 if (is_add == -1)
11747 {
11748 errmsg ("expecting: add|del");
11749 return -99;
11750 }
11751 if (classify_table_index == ~0)
11752 {
11753 errmsg ("classifier table not specified");
11754 return -99;
11755 }
11756 if (ip_version == 0)
11757 {
11758 errmsg ("IP version not specified");
11759 return -99;
11760 }
11761
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011762 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011763
11764 mp->is_add = is_add;
11765 mp->table_id = htonl (classify_table_index);
11766 mp->ip_version = ip_version;
11767 mp->transport_protocol = transport_protocol;
11768
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011769 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011770 W (ret);
11771 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011772}
11773
11774static int
11775api_get_node_index (vat_main_t * vam)
11776{
11777 unformat_input_t *i = vam->input;
11778 vl_api_get_node_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011779 u8 *name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011780 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011781
11782 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11783 {
11784 if (unformat (i, "node %s", &name))
11785 ;
11786 else
11787 break;
11788 }
11789 if (name == 0)
11790 {
11791 errmsg ("node name required");
11792 return -99;
11793 }
11794 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
11795 {
11796 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11797 return -99;
11798 }
11799
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011800 M (GET_NODE_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011801 clib_memcpy (mp->node_name, name, vec_len (name));
11802 vec_free (name);
11803
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011804 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011805 W (ret);
11806 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011807}
11808
11809static int
11810api_get_next_index (vat_main_t * vam)
11811{
11812 unformat_input_t *i = vam->input;
11813 vl_api_get_next_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011814 u8 *node_name = 0, *next_node_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011815 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011816
11817 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11818 {
11819 if (unformat (i, "node-name %s", &node_name))
11820 ;
11821 else if (unformat (i, "next-node-name %s", &next_node_name))
11822 break;
11823 }
11824
11825 if (node_name == 0)
11826 {
11827 errmsg ("node name required");
11828 return -99;
11829 }
11830 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
11831 {
11832 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11833 return -99;
11834 }
11835
11836 if (next_node_name == 0)
11837 {
11838 errmsg ("next node name required");
11839 return -99;
11840 }
11841 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
11842 {
11843 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
11844 return -99;
11845 }
11846
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011847 M (GET_NEXT_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011848 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
11849 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
11850 vec_free (node_name);
11851 vec_free (next_node_name);
11852
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011853 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011854 W (ret);
11855 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011856}
11857
11858static int
11859api_add_node_next (vat_main_t * vam)
11860{
11861 unformat_input_t *i = vam->input;
11862 vl_api_add_node_next_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011863 u8 *name = 0;
11864 u8 *next = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011865 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011866
11867 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11868 {
11869 if (unformat (i, "node %s", &name))
11870 ;
11871 else if (unformat (i, "next %s", &next))
11872 ;
11873 else
11874 break;
11875 }
11876 if (name == 0)
11877 {
11878 errmsg ("node name required");
11879 return -99;
11880 }
11881 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
11882 {
11883 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11884 return -99;
11885 }
11886 if (next == 0)
11887 {
11888 errmsg ("next node required");
11889 return -99;
11890 }
11891 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
11892 {
11893 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
11894 return -99;
11895 }
11896
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011897 M (ADD_NODE_NEXT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011898 clib_memcpy (mp->node_name, name, vec_len (name));
11899 clib_memcpy (mp->next_name, next, vec_len (next));
11900 vec_free (name);
11901 vec_free (next);
11902
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011903 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011904 W (ret);
11905 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011906}
11907
11908static int
11909api_l2tpv3_create_tunnel (vat_main_t * vam)
11910{
11911 unformat_input_t *i = vam->input;
11912 ip6_address_t client_address, our_address;
11913 int client_address_set = 0;
11914 int our_address_set = 0;
11915 u32 local_session_id = 0;
11916 u32 remote_session_id = 0;
11917 u64 local_cookie = 0;
11918 u64 remote_cookie = 0;
11919 u8 l2_sublayer_present = 0;
11920 vl_api_l2tpv3_create_tunnel_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011921 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011922
11923 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11924 {
11925 if (unformat (i, "client_address %U", unformat_ip6_address,
11926 &client_address))
11927 client_address_set = 1;
11928 else if (unformat (i, "our_address %U", unformat_ip6_address,
11929 &our_address))
11930 our_address_set = 1;
11931 else if (unformat (i, "local_session_id %d", &local_session_id))
11932 ;
11933 else if (unformat (i, "remote_session_id %d", &remote_session_id))
11934 ;
11935 else if (unformat (i, "local_cookie %lld", &local_cookie))
11936 ;
11937 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
11938 ;
11939 else if (unformat (i, "l2-sublayer-present"))
11940 l2_sublayer_present = 1;
11941 else
11942 break;
11943 }
11944
11945 if (client_address_set == 0)
11946 {
11947 errmsg ("client_address required");
11948 return -99;
11949 }
11950
11951 if (our_address_set == 0)
11952 {
11953 errmsg ("our_address required");
11954 return -99;
11955 }
11956
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011957 M (L2TPV3_CREATE_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011958
11959 clib_memcpy (mp->client_address, client_address.as_u8,
11960 sizeof (mp->client_address));
11961
11962 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
11963
11964 mp->local_session_id = ntohl (local_session_id);
11965 mp->remote_session_id = ntohl (remote_session_id);
11966 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
11967 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
11968 mp->l2_sublayer_present = l2_sublayer_present;
11969 mp->is_ipv6 = 1;
11970
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011971 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011972 W (ret);
11973 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011974}
11975
11976static int
11977api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
11978{
11979 unformat_input_t *i = vam->input;
11980 u32 sw_if_index;
11981 u8 sw_if_index_set = 0;
11982 u64 new_local_cookie = 0;
11983 u64 new_remote_cookie = 0;
11984 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011985 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011986
11987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11988 {
11989 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11990 sw_if_index_set = 1;
11991 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11992 sw_if_index_set = 1;
11993 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
11994 ;
11995 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
11996 ;
11997 else
11998 break;
11999 }
12000
12001 if (sw_if_index_set == 0)
12002 {
12003 errmsg ("missing interface name or sw_if_index");
12004 return -99;
12005 }
12006
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012007 M (L2TPV3_SET_TUNNEL_COOKIES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012008
12009 mp->sw_if_index = ntohl (sw_if_index);
12010 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
12011 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
12012
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012013 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012014 W (ret);
12015 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012016}
12017
12018static int
12019api_l2tpv3_interface_enable_disable (vat_main_t * vam)
12020{
12021 unformat_input_t *i = vam->input;
12022 vl_api_l2tpv3_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012023 u32 sw_if_index;
12024 u8 sw_if_index_set = 0;
12025 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012026 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012027
12028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12029 {
12030 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12031 sw_if_index_set = 1;
12032 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12033 sw_if_index_set = 1;
12034 else if (unformat (i, "enable"))
12035 enable_disable = 1;
12036 else if (unformat (i, "disable"))
12037 enable_disable = 0;
12038 else
12039 break;
12040 }
12041
12042 if (sw_if_index_set == 0)
12043 {
12044 errmsg ("missing interface name or sw_if_index");
12045 return -99;
12046 }
12047
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012048 M (L2TPV3_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012049
12050 mp->sw_if_index = ntohl (sw_if_index);
12051 mp->enable_disable = enable_disable;
12052
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012053 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012054 W (ret);
12055 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012056}
12057
12058static int
12059api_l2tpv3_set_lookup_key (vat_main_t * vam)
12060{
12061 unformat_input_t *i = vam->input;
12062 vl_api_l2tpv3_set_lookup_key_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012063 u8 key = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012064 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012065
12066 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12067 {
12068 if (unformat (i, "lookup_v6_src"))
12069 key = L2T_LOOKUP_SRC_ADDRESS;
12070 else if (unformat (i, "lookup_v6_dst"))
12071 key = L2T_LOOKUP_DST_ADDRESS;
12072 else if (unformat (i, "lookup_session_id"))
12073 key = L2T_LOOKUP_SESSION_ID;
12074 else
12075 break;
12076 }
12077
12078 if (key == (u8) ~ 0)
12079 {
12080 errmsg ("l2tp session lookup key unset");
12081 return -99;
12082 }
12083
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012084 M (L2TPV3_SET_LOOKUP_KEY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012085
12086 mp->key = key;
12087
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012088 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012089 W (ret);
12090 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012091}
12092
12093static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
12094 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
12095{
12096 vat_main_t *vam = &vat_main;
12097
12098 print (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)",
12099 format_ip6_address, mp->our_address,
12100 format_ip6_address, mp->client_address,
12101 clib_net_to_host_u32 (mp->sw_if_index));
12102
12103 print (vam->ofp,
12104 " local cookies %016llx %016llx remote cookie %016llx",
12105 clib_net_to_host_u64 (mp->local_cookie[0]),
12106 clib_net_to_host_u64 (mp->local_cookie[1]),
12107 clib_net_to_host_u64 (mp->remote_cookie));
12108
12109 print (vam->ofp, " local session-id %d remote session-id %d",
12110 clib_net_to_host_u32 (mp->local_session_id),
12111 clib_net_to_host_u32 (mp->remote_session_id));
12112
12113 print (vam->ofp, " l2 specific sublayer %s\n",
12114 mp->l2_sublayer_present ? "preset" : "absent");
12115
12116}
12117
12118static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
12119 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
12120{
12121 vat_main_t *vam = &vat_main;
12122 vat_json_node_t *node = NULL;
12123 struct in6_addr addr;
12124
12125 if (VAT_JSON_ARRAY != vam->json_tree.type)
12126 {
12127 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12128 vat_json_init_array (&vam->json_tree);
12129 }
12130 node = vat_json_array_add (&vam->json_tree);
12131
12132 vat_json_init_object (node);
12133
12134 clib_memcpy (&addr, mp->our_address, sizeof (addr));
12135 vat_json_object_add_ip6 (node, "our_address", addr);
12136 clib_memcpy (&addr, mp->client_address, sizeof (addr));
12137 vat_json_object_add_ip6 (node, "client_address", addr);
12138
12139 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
12140 vat_json_init_array (lc);
12141 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
12142 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
12143 vat_json_object_add_uint (node, "remote_cookie",
12144 clib_net_to_host_u64 (mp->remote_cookie));
12145
12146 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
12147 vat_json_object_add_uint (node, "local_session_id",
12148 clib_net_to_host_u32 (mp->local_session_id));
12149 vat_json_object_add_uint (node, "remote_session_id",
12150 clib_net_to_host_u32 (mp->remote_session_id));
12151 vat_json_object_add_string_copy (node, "l2_sublayer",
12152 mp->l2_sublayer_present ? (u8 *) "present"
12153 : (u8 *) "absent");
12154}
12155
12156static int
12157api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
12158{
12159 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012160 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012161 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012162
12163 /* Get list of l2tpv3-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012164 M (SW_IF_L2TPV3_TUNNEL_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012165 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012166
12167 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012168 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012169 S (mp_ping);
12170
Jon Loeliger56c7b012017-02-01 12:31:41 -060012171 W (ret);
12172 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012173}
12174
12175
Damjan Marion8389fb92017-10-13 18:29:53 +020012176static void vl_api_sw_interface_tap_v2_details_t_handler
12177 (vl_api_sw_interface_tap_v2_details_t * mp)
12178{
12179 vat_main_t *vam = &vat_main;
12180
Milan Lenco73e7f422017-12-14 10:04:25 +010012181 u8 *ip4 = format (0, "%U/%d", format_ip4_address, mp->host_ip4_addr,
12182 mp->host_ip4_prefix_len);
12183 u8 *ip6 = format (0, "%U/%d", format_ip6_address, mp->host_ip6_addr,
12184 mp->host_ip6_prefix_len);
12185
12186 print (vam->ofp,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012187 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
Milan Lenco73e7f422017-12-14 10:04:25 +010012188 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
12189 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
12190 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012191 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
Milan Lenco73e7f422017-12-14 10:04:25 +010012192
12193 vec_free (ip4);
12194 vec_free (ip6);
Damjan Marion8389fb92017-10-13 18:29:53 +020012195}
12196
12197static void vl_api_sw_interface_tap_v2_details_t_handler_json
12198 (vl_api_sw_interface_tap_v2_details_t * mp)
12199{
12200 vat_main_t *vam = &vat_main;
12201 vat_json_node_t *node = NULL;
12202
12203 if (VAT_JSON_ARRAY != vam->json_tree.type)
12204 {
12205 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12206 vat_json_init_array (&vam->json_tree);
12207 }
12208 node = vat_json_array_add (&vam->json_tree);
12209
12210 vat_json_init_object (node);
Milan Lenco73e7f422017-12-14 10:04:25 +010012211 vat_json_object_add_uint (node, "id", ntohl (mp->id));
Damjan Marion8389fb92017-10-13 18:29:53 +020012212 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012213 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
Damjan Marion8389fb92017-10-13 18:29:53 +020012214 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Milan Lenco73e7f422017-12-14 10:04:25 +010012215 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
12216 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
12217 vat_json_object_add_string_copy (node, "host_mac_addr",
12218 format (0, "%U", format_ethernet_address,
12219 &mp->host_mac_addr));
12220 vat_json_object_add_string_copy (node, "host_namespace",
12221 mp->host_namespace);
12222 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
12223 vat_json_object_add_string_copy (node, "host_ip4_addr",
12224 format (0, "%U/%d", format_ip4_address,
12225 mp->host_ip4_addr,
12226 mp->host_ip4_prefix_len));
12227 vat_json_object_add_string_copy (node, "host_ip6_addr",
12228 format (0, "%U/%d", format_ip6_address,
12229 mp->host_ip6_addr,
12230 mp->host_ip6_prefix_len));
12231
Damjan Marion8389fb92017-10-13 18:29:53 +020012232}
12233
12234static int
12235api_sw_interface_tap_v2_dump (vat_main_t * vam)
12236{
12237 vl_api_sw_interface_tap_v2_dump_t *mp;
12238 vl_api_control_ping_t *mp_ping;
12239 int ret;
12240
Milan Lenco73e7f422017-12-14 10:04:25 +010012241 print (vam->ofp,
12242 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
12243 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
12244 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
12245 "host_ip6_addr");
12246
Damjan Marion8389fb92017-10-13 18:29:53 +020012247 /* Get list of tap interfaces */
12248 M (SW_INTERFACE_TAP_V2_DUMP, mp);
12249 S (mp);
12250
12251 /* Use a control ping for synchronization */
12252 MPING (CONTROL_PING, mp_ping);
12253 S (mp_ping);
12254
12255 W (ret);
12256 return ret;
12257}
12258
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010012259static void vl_api_sw_interface_virtio_pci_details_t_handler
12260 (vl_api_sw_interface_virtio_pci_details_t * mp)
12261{
12262 vat_main_t *vam = &vat_main;
12263
12264 typedef union
12265 {
12266 struct
12267 {
12268 u16 domain;
12269 u8 bus;
12270 u8 slot:5;
12271 u8 function:3;
12272 };
12273 u32 as_u32;
12274 } pci_addr_t;
12275 pci_addr_t addr;
12276 addr.as_u32 = ntohl (mp->pci_addr);
12277 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
12278 addr.slot, addr.function);
12279
12280 print (vam->ofp,
12281 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
12282 pci_addr, ntohl (mp->sw_if_index),
12283 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
12284 format_ethernet_address, mp->mac_addr,
12285 clib_net_to_host_u64 (mp->features));
12286 vec_free (pci_addr);
12287}
12288
12289static void vl_api_sw_interface_virtio_pci_details_t_handler_json
12290 (vl_api_sw_interface_virtio_pci_details_t * mp)
12291{
12292 vat_main_t *vam = &vat_main;
12293 vat_json_node_t *node = NULL;
12294
12295 if (VAT_JSON_ARRAY != vam->json_tree.type)
12296 {
12297 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12298 vat_json_init_array (&vam->json_tree);
12299 }
12300 node = vat_json_array_add (&vam->json_tree);
12301
12302 vat_json_init_object (node);
12303 vat_json_object_add_uint (node, "pci-addr", ntohl (mp->pci_addr));
12304 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12305 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
12306 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
12307 vat_json_object_add_uint (node, "features",
12308 clib_net_to_host_u64 (mp->features));
12309 vat_json_object_add_string_copy (node, "mac_addr",
12310 format (0, "%U", format_ethernet_address,
12311 &mp->mac_addr));
12312}
12313
12314static int
12315api_sw_interface_virtio_pci_dump (vat_main_t * vam)
12316{
12317 vl_api_sw_interface_virtio_pci_dump_t *mp;
12318 vl_api_control_ping_t *mp_ping;
12319 int ret;
12320
12321 print (vam->ofp,
12322 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
12323 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
12324 "mac_addr", "features");
12325
12326 /* Get list of tap interfaces */
12327 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
12328 S (mp);
12329
12330 /* Use a control ping for synchronization */
12331 MPING (CONTROL_PING, mp_ping);
12332 S (mp_ping);
12333
12334 W (ret);
12335 return ret;
12336}
12337
eyal bariaf86a482018-04-17 11:20:27 +030012338static int
12339api_vxlan_offload_rx (vat_main_t * vam)
12340{
12341 unformat_input_t *line_input = vam->input;
12342 vl_api_vxlan_offload_rx_t *mp;
12343 u32 hw_if_index = ~0, rx_if_index = ~0;
12344 u8 is_add = 1;
12345 int ret;
12346
12347 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12348 {
12349 if (unformat (line_input, "del"))
12350 is_add = 0;
12351 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
12352 &hw_if_index))
12353 ;
12354 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
12355 ;
12356 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
12357 &rx_if_index))
12358 ;
12359 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
12360 ;
12361 else
12362 {
12363 errmsg ("parse error '%U'", format_unformat_error, line_input);
12364 return -99;
12365 }
12366 }
12367
12368 if (hw_if_index == ~0)
12369 {
12370 errmsg ("no hw interface");
12371 return -99;
12372 }
12373
12374 if (rx_if_index == ~0)
12375 {
12376 errmsg ("no rx tunnel");
12377 return -99;
12378 }
12379
12380 M (VXLAN_OFFLOAD_RX, mp);
12381
12382 mp->hw_if_index = ntohl (hw_if_index);
12383 mp->sw_if_index = ntohl (rx_if_index);
12384 mp->enable = is_add;
12385
12386 S (mp);
12387 W (ret);
12388 return ret;
12389}
12390
Damjan Marion7cd468a2016-12-19 23:05:39 +010012391static uword unformat_vxlan_decap_next
12392 (unformat_input_t * input, va_list * args)
12393{
12394 u32 *result = va_arg (*args, u32 *);
12395 u32 tmp;
12396
12397 if (unformat (input, "l2"))
12398 *result = VXLAN_INPUT_NEXT_L2_INPUT;
12399 else if (unformat (input, "%d", &tmp))
12400 *result = tmp;
12401 else
12402 return 0;
12403 return 1;
12404}
12405
12406static int
12407api_vxlan_add_del_tunnel (vat_main_t * vam)
12408{
12409 unformat_input_t *line_input = vam->input;
12410 vl_api_vxlan_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012411 ip46_address_t src, dst;
12412 u8 is_add = 1;
12413 u8 ipv4_set = 0, ipv6_set = 0;
12414 u8 src_set = 0;
12415 u8 dst_set = 0;
12416 u8 grp_set = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012417 u32 instance = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012418 u32 mcast_sw_if_index = ~0;
12419 u32 encap_vrf_id = 0;
12420 u32 decap_next_index = ~0;
12421 u32 vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012422 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012423
12424 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040012425 clib_memset (&src, 0, sizeof src);
12426 clib_memset (&dst, 0, sizeof dst);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012427
12428 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12429 {
12430 if (unformat (line_input, "del"))
12431 is_add = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012432 else if (unformat (line_input, "instance %d", &instance))
12433 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012434 else
12435 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
12436 {
12437 ipv4_set = 1;
12438 src_set = 1;
12439 }
12440 else
12441 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
12442 {
12443 ipv4_set = 1;
12444 dst_set = 1;
12445 }
12446 else
12447 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
12448 {
12449 ipv6_set = 1;
12450 src_set = 1;
12451 }
12452 else
12453 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
12454 {
12455 ipv6_set = 1;
12456 dst_set = 1;
12457 }
12458 else if (unformat (line_input, "group %U %U",
12459 unformat_ip4_address, &dst.ip4,
12460 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12461 {
12462 grp_set = dst_set = 1;
12463 ipv4_set = 1;
12464 }
12465 else if (unformat (line_input, "group %U",
12466 unformat_ip4_address, &dst.ip4))
12467 {
12468 grp_set = dst_set = 1;
12469 ipv4_set = 1;
12470 }
12471 else if (unformat (line_input, "group %U %U",
12472 unformat_ip6_address, &dst.ip6,
12473 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12474 {
12475 grp_set = dst_set = 1;
12476 ipv6_set = 1;
12477 }
12478 else if (unformat (line_input, "group %U",
12479 unformat_ip6_address, &dst.ip6))
12480 {
12481 grp_set = dst_set = 1;
12482 ipv6_set = 1;
12483 }
12484 else
12485 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
12486 ;
12487 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
12488 ;
12489 else if (unformat (line_input, "decap-next %U",
12490 unformat_vxlan_decap_next, &decap_next_index))
12491 ;
12492 else if (unformat (line_input, "vni %d", &vni))
12493 ;
12494 else
12495 {
12496 errmsg ("parse error '%U'", format_unformat_error, line_input);
12497 return -99;
12498 }
12499 }
12500
12501 if (src_set == 0)
12502 {
12503 errmsg ("tunnel src address not specified");
12504 return -99;
12505 }
12506 if (dst_set == 0)
12507 {
12508 errmsg ("tunnel dst address not specified");
12509 return -99;
12510 }
12511
12512 if (grp_set && !ip46_address_is_multicast (&dst))
12513 {
12514 errmsg ("tunnel group address not multicast");
12515 return -99;
12516 }
12517 if (grp_set && mcast_sw_if_index == ~0)
12518 {
12519 errmsg ("tunnel nonexistent multicast device");
12520 return -99;
12521 }
12522 if (grp_set == 0 && ip46_address_is_multicast (&dst))
12523 {
12524 errmsg ("tunnel dst address must be unicast");
12525 return -99;
12526 }
12527
12528
12529 if (ipv4_set && ipv6_set)
12530 {
12531 errmsg ("both IPv4 and IPv6 addresses specified");
12532 return -99;
12533 }
12534
12535 if ((vni == 0) || (vni >> 24))
12536 {
12537 errmsg ("vni not specified or out of range");
12538 return -99;
12539 }
12540
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012541 M (VXLAN_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012542
12543 if (ipv6_set)
12544 {
12545 clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
12546 clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
12547 }
12548 else
12549 {
12550 clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
12551 clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
12552 }
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012553
12554 mp->instance = htonl (instance);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012555 mp->encap_vrf_id = ntohl (encap_vrf_id);
12556 mp->decap_next_index = ntohl (decap_next_index);
12557 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
12558 mp->vni = ntohl (vni);
12559 mp->is_add = is_add;
12560 mp->is_ipv6 = ipv6_set;
12561
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012562 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012563 W (ret);
12564 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012565}
12566
12567static void vl_api_vxlan_tunnel_details_t_handler
12568 (vl_api_vxlan_tunnel_details_t * mp)
12569{
12570 vat_main_t *vam = &vat_main;
Eyal Barie101e1f2017-03-15 08:23:42 +020012571 ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
12572 ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012573
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012574 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012575 ntohl (mp->sw_if_index),
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012576 ntohl (mp->instance),
Damjan Marion7cd468a2016-12-19 23:05:39 +010012577 format_ip46_address, &src, IP46_TYPE_ANY,
12578 format_ip46_address, &dst, IP46_TYPE_ANY,
12579 ntohl (mp->encap_vrf_id),
12580 ntohl (mp->decap_next_index), ntohl (mp->vni),
12581 ntohl (mp->mcast_sw_if_index));
12582}
12583
12584static void vl_api_vxlan_tunnel_details_t_handler_json
12585 (vl_api_vxlan_tunnel_details_t * mp)
12586{
12587 vat_main_t *vam = &vat_main;
12588 vat_json_node_t *node = NULL;
12589
12590 if (VAT_JSON_ARRAY != vam->json_tree.type)
12591 {
12592 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12593 vat_json_init_array (&vam->json_tree);
12594 }
12595 node = vat_json_array_add (&vam->json_tree);
12596
12597 vat_json_init_object (node);
12598 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012599
12600 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
12601
Damjan Marion7cd468a2016-12-19 23:05:39 +010012602 if (mp->is_ipv6)
12603 {
12604 struct in6_addr ip6;
12605
12606 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
12607 vat_json_object_add_ip6 (node, "src_address", ip6);
12608 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
12609 vat_json_object_add_ip6 (node, "dst_address", ip6);
12610 }
12611 else
12612 {
12613 struct in_addr ip4;
12614
12615 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
12616 vat_json_object_add_ip4 (node, "src_address", ip4);
12617 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
12618 vat_json_object_add_ip4 (node, "dst_address", ip4);
12619 }
12620 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12621 vat_json_object_add_uint (node, "decap_next_index",
12622 ntohl (mp->decap_next_index));
12623 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
12624 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
12625 vat_json_object_add_uint (node, "mcast_sw_if_index",
12626 ntohl (mp->mcast_sw_if_index));
12627}
12628
12629static int
12630api_vxlan_tunnel_dump (vat_main_t * vam)
12631{
12632 unformat_input_t *i = vam->input;
12633 vl_api_vxlan_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012634 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012635 u32 sw_if_index;
12636 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012637 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012638
12639 /* Parse args required to build the message */
12640 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12641 {
12642 if (unformat (i, "sw_if_index %d", &sw_if_index))
12643 sw_if_index_set = 1;
12644 else
12645 break;
12646 }
12647
12648 if (sw_if_index_set == 0)
12649 {
12650 sw_if_index = ~0;
12651 }
12652
12653 if (!vam->json_output)
12654 {
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012655 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
12656 "sw_if_index", "instance", "src_address", "dst_address",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012657 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
12658 }
12659
12660 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012661 M (VXLAN_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012662
12663 mp->sw_if_index = htonl (sw_if_index);
12664
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012665 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012666
12667 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012668 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012669 S (mp_ping);
12670
Jon Loeliger56c7b012017-02-01 12:31:41 -060012671 W (ret);
12672 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012673}
12674
Marco Varleseb598f1d2017-09-19 14:25:28 +020012675static uword unformat_geneve_decap_next
12676 (unformat_input_t * input, va_list * args)
12677{
12678 u32 *result = va_arg (*args, u32 *);
12679 u32 tmp;
12680
12681 if (unformat (input, "l2"))
12682 *result = GENEVE_INPUT_NEXT_L2_INPUT;
12683 else if (unformat (input, "%d", &tmp))
12684 *result = tmp;
12685 else
12686 return 0;
12687 return 1;
12688}
12689
12690static int
12691api_geneve_add_del_tunnel (vat_main_t * vam)
12692{
12693 unformat_input_t *line_input = vam->input;
12694 vl_api_geneve_add_del_tunnel_t *mp;
12695 ip46_address_t src, dst;
12696 u8 is_add = 1;
12697 u8 ipv4_set = 0, ipv6_set = 0;
12698 u8 src_set = 0;
12699 u8 dst_set = 0;
12700 u8 grp_set = 0;
12701 u32 mcast_sw_if_index = ~0;
12702 u32 encap_vrf_id = 0;
12703 u32 decap_next_index = ~0;
12704 u32 vni = 0;
12705 int ret;
12706
12707 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040012708 clib_memset (&src, 0, sizeof src);
12709 clib_memset (&dst, 0, sizeof dst);
Marco Varleseb598f1d2017-09-19 14:25:28 +020012710
12711 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12712 {
12713 if (unformat (line_input, "del"))
12714 is_add = 0;
12715 else
12716 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
12717 {
12718 ipv4_set = 1;
12719 src_set = 1;
12720 }
12721 else
12722 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
12723 {
12724 ipv4_set = 1;
12725 dst_set = 1;
12726 }
12727 else
12728 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
12729 {
12730 ipv6_set = 1;
12731 src_set = 1;
12732 }
12733 else
12734 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
12735 {
12736 ipv6_set = 1;
12737 dst_set = 1;
12738 }
12739 else if (unformat (line_input, "group %U %U",
12740 unformat_ip4_address, &dst.ip4,
12741 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12742 {
12743 grp_set = dst_set = 1;
12744 ipv4_set = 1;
12745 }
12746 else if (unformat (line_input, "group %U",
12747 unformat_ip4_address, &dst.ip4))
12748 {
12749 grp_set = dst_set = 1;
12750 ipv4_set = 1;
12751 }
12752 else if (unformat (line_input, "group %U %U",
12753 unformat_ip6_address, &dst.ip6,
12754 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12755 {
12756 grp_set = dst_set = 1;
12757 ipv6_set = 1;
12758 }
12759 else if (unformat (line_input, "group %U",
12760 unformat_ip6_address, &dst.ip6))
12761 {
12762 grp_set = dst_set = 1;
12763 ipv6_set = 1;
12764 }
12765 else
12766 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
12767 ;
12768 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
12769 ;
12770 else if (unformat (line_input, "decap-next %U",
12771 unformat_geneve_decap_next, &decap_next_index))
12772 ;
12773 else if (unformat (line_input, "vni %d", &vni))
12774 ;
12775 else
12776 {
12777 errmsg ("parse error '%U'", format_unformat_error, line_input);
12778 return -99;
12779 }
12780 }
12781
12782 if (src_set == 0)
12783 {
12784 errmsg ("tunnel src address not specified");
12785 return -99;
12786 }
12787 if (dst_set == 0)
12788 {
12789 errmsg ("tunnel dst address not specified");
12790 return -99;
12791 }
12792
12793 if (grp_set && !ip46_address_is_multicast (&dst))
12794 {
12795 errmsg ("tunnel group address not multicast");
12796 return -99;
12797 }
12798 if (grp_set && mcast_sw_if_index == ~0)
12799 {
12800 errmsg ("tunnel nonexistent multicast device");
12801 return -99;
12802 }
12803 if (grp_set == 0 && ip46_address_is_multicast (&dst))
12804 {
12805 errmsg ("tunnel dst address must be unicast");
12806 return -99;
12807 }
12808
12809
12810 if (ipv4_set && ipv6_set)
12811 {
12812 errmsg ("both IPv4 and IPv6 addresses specified");
12813 return -99;
12814 }
12815
12816 if ((vni == 0) || (vni >> 24))
12817 {
12818 errmsg ("vni not specified or out of range");
12819 return -99;
12820 }
12821
12822 M (GENEVE_ADD_DEL_TUNNEL, mp);
12823
12824 if (ipv6_set)
12825 {
12826 clib_memcpy (mp->local_address, &src.ip6, sizeof (src.ip6));
12827 clib_memcpy (mp->remote_address, &dst.ip6, sizeof (dst.ip6));
12828 }
12829 else
12830 {
12831 clib_memcpy (mp->local_address, &src.ip4, sizeof (src.ip4));
12832 clib_memcpy (mp->remote_address, &dst.ip4, sizeof (dst.ip4));
12833 }
12834 mp->encap_vrf_id = ntohl (encap_vrf_id);
12835 mp->decap_next_index = ntohl (decap_next_index);
12836 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
12837 mp->vni = ntohl (vni);
12838 mp->is_add = is_add;
12839 mp->is_ipv6 = ipv6_set;
12840
12841 S (mp);
12842 W (ret);
12843 return ret;
12844}
12845
12846static void vl_api_geneve_tunnel_details_t_handler
12847 (vl_api_geneve_tunnel_details_t * mp)
12848{
12849 vat_main_t *vam = &vat_main;
12850 ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
12851 ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
12852
12853 print (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d",
12854 ntohl (mp->sw_if_index),
12855 format_ip46_address, &src, IP46_TYPE_ANY,
12856 format_ip46_address, &dst, IP46_TYPE_ANY,
12857 ntohl (mp->encap_vrf_id),
12858 ntohl (mp->decap_next_index), ntohl (mp->vni),
12859 ntohl (mp->mcast_sw_if_index));
12860}
12861
12862static void vl_api_geneve_tunnel_details_t_handler_json
12863 (vl_api_geneve_tunnel_details_t * mp)
12864{
12865 vat_main_t *vam = &vat_main;
12866 vat_json_node_t *node = NULL;
12867
12868 if (VAT_JSON_ARRAY != vam->json_tree.type)
12869 {
12870 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12871 vat_json_init_array (&vam->json_tree);
12872 }
12873 node = vat_json_array_add (&vam->json_tree);
12874
12875 vat_json_init_object (node);
12876 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12877 if (mp->is_ipv6)
12878 {
12879 struct in6_addr ip6;
12880
12881 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
12882 vat_json_object_add_ip6 (node, "src_address", ip6);
12883 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
12884 vat_json_object_add_ip6 (node, "dst_address", ip6);
12885 }
12886 else
12887 {
12888 struct in_addr ip4;
12889
12890 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
12891 vat_json_object_add_ip4 (node, "src_address", ip4);
12892 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
12893 vat_json_object_add_ip4 (node, "dst_address", ip4);
12894 }
12895 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12896 vat_json_object_add_uint (node, "decap_next_index",
12897 ntohl (mp->decap_next_index));
12898 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
12899 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
12900 vat_json_object_add_uint (node, "mcast_sw_if_index",
12901 ntohl (mp->mcast_sw_if_index));
12902}
12903
12904static int
12905api_geneve_tunnel_dump (vat_main_t * vam)
12906{
12907 unformat_input_t *i = vam->input;
12908 vl_api_geneve_tunnel_dump_t *mp;
12909 vl_api_control_ping_t *mp_ping;
12910 u32 sw_if_index;
12911 u8 sw_if_index_set = 0;
12912 int ret;
12913
12914 /* Parse args required to build the message */
12915 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12916 {
12917 if (unformat (i, "sw_if_index %d", &sw_if_index))
12918 sw_if_index_set = 1;
12919 else
12920 break;
12921 }
12922
12923 if (sw_if_index_set == 0)
12924 {
12925 sw_if_index = ~0;
12926 }
12927
12928 if (!vam->json_output)
12929 {
12930 print (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s",
12931 "sw_if_index", "local_address", "remote_address",
12932 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
12933 }
12934
12935 /* Get list of geneve-tunnel interfaces */
12936 M (GENEVE_TUNNEL_DUMP, mp);
12937
12938 mp->sw_if_index = htonl (sw_if_index);
12939
12940 S (mp);
12941
12942 /* Use a control ping for synchronization */
12943 M (CONTROL_PING, mp_ping);
12944 S (mp_ping);
12945
12946 W (ret);
12947 return ret;
12948}
12949
Damjan Marion7cd468a2016-12-19 23:05:39 +010012950static int
Neale Ranns5a8844b2019-04-16 07:15:35 +000012951api_gre_tunnel_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010012952{
12953 unformat_input_t *line_input = vam->input;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012954 vl_api_address_t src = { }, dst =
12955 {
12956 };
12957 vl_api_gre_tunnel_add_del_t *mp;
12958 vl_api_gre_tunnel_type_t t_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012959 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012960 u8 src_set = 0;
12961 u8 dst_set = 0;
12962 u32 outer_fib_id = 0;
John Loa43ccae2018-02-13 17:15:23 -050012963 u32 session_id = 0;
12964 u32 instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012965 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012966
Neale Ranns5a8844b2019-04-16 07:15:35 +000012967 t_type = GRE_API_TUNNEL_TYPE_L3;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012968
Damjan Marion7cd468a2016-12-19 23:05:39 +010012969 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12970 {
12971 if (unformat (line_input, "del"))
12972 is_add = 0;
John Loa43ccae2018-02-13 17:15:23 -050012973 else if (unformat (line_input, "instance %d", &instance))
12974 ;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012975 else if (unformat (line_input, "src %U", unformat_vl_api_address, &src))
Ciara Loftus7eac9162016-09-30 15:47:03 +010012976 {
12977 src_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012978 }
Neale Ranns5a8844b2019-04-16 07:15:35 +000012979 else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst))
Ciara Loftus7eac9162016-09-30 15:47:03 +010012980 {
12981 dst_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012982 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010012983 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
12984 ;
12985 else if (unformat (line_input, "teb"))
Neale Ranns5a8844b2019-04-16 07:15:35 +000012986 t_type = GRE_API_TUNNEL_TYPE_TEB;
John Loa43ccae2018-02-13 17:15:23 -050012987 else if (unformat (line_input, "erspan %d", &session_id))
Neale Ranns5a8844b2019-04-16 07:15:35 +000012988 t_type = GRE_API_TUNNEL_TYPE_ERSPAN;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012989 else
12990 {
12991 errmsg ("parse error '%U'", format_unformat_error, line_input);
12992 return -99;
12993 }
12994 }
12995
12996 if (src_set == 0)
12997 {
12998 errmsg ("tunnel src address not specified");
12999 return -99;
13000 }
13001 if (dst_set == 0)
13002 {
13003 errmsg ("tunnel dst address not specified");
13004 return -99;
13005 }
13006
Neale Ranns5a8844b2019-04-16 07:15:35 +000013007 M (GRE_TUNNEL_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013008
Neale Ranns5a8844b2019-04-16 07:15:35 +000013009 clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src));
13010 clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013011
Neale Ranns5a8844b2019-04-16 07:15:35 +000013012 mp->tunnel.instance = htonl (instance);
13013 mp->tunnel.outer_fib_id = htonl (outer_fib_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013014 mp->is_add = is_add;
Neale Ranns5a8844b2019-04-16 07:15:35 +000013015 mp->tunnel.session_id = htons ((u16) session_id);
13016 mp->tunnel.type = htonl (t_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013017
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013018 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013019 W (ret);
13020 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013021}
13022
13023static void vl_api_gre_tunnel_details_t_handler
13024 (vl_api_gre_tunnel_details_t * mp)
13025{
13026 vat_main_t *vam = &vat_main;
13027
John Loa43ccae2018-02-13 17:15:23 -050013028 print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d",
Neale Ranns5a8844b2019-04-16 07:15:35 +000013029 ntohl (mp->tunnel.sw_if_index),
13030 ntohl (mp->tunnel.instance),
13031 format_vl_api_address, &mp->tunnel.src,
13032 format_vl_api_address, &mp->tunnel.dst,
13033 mp->tunnel.type, ntohl (mp->tunnel.outer_fib_id),
13034 ntohl (mp->tunnel.session_id));
13035}
13036
Damjan Marion7cd468a2016-12-19 23:05:39 +010013037static void vl_api_gre_tunnel_details_t_handler_json
13038 (vl_api_gre_tunnel_details_t * mp)
13039{
13040 vat_main_t *vam = &vat_main;
13041 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013042
13043 if (VAT_JSON_ARRAY != vam->json_tree.type)
13044 {
13045 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13046 vat_json_init_array (&vam->json_tree);
13047 }
13048 node = vat_json_array_add (&vam->json_tree);
13049
13050 vat_json_init_object (node);
Neale Ranns5a8844b2019-04-16 07:15:35 +000013051 vat_json_object_add_uint (node, "sw_if_index",
13052 ntohl (mp->tunnel.sw_if_index));
13053 vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance));
13054
13055 vat_json_object_add_address (node, "src", &mp->tunnel.src);
13056 vat_json_object_add_address (node, "dst", &mp->tunnel.dst);
13057 vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type);
13058 vat_json_object_add_uint (node, "outer_fib_id",
13059 ntohl (mp->tunnel.outer_fib_id));
13060 vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013061}
13062
13063static int
13064api_gre_tunnel_dump (vat_main_t * vam)
13065{
13066 unformat_input_t *i = vam->input;
13067 vl_api_gre_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013068 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013069 u32 sw_if_index;
13070 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013071 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013072
13073 /* Parse args required to build the message */
13074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13075 {
13076 if (unformat (i, "sw_if_index %d", &sw_if_index))
13077 sw_if_index_set = 1;
13078 else
13079 break;
13080 }
13081
13082 if (sw_if_index_set == 0)
13083 {
13084 sw_if_index = ~0;
13085 }
13086
13087 if (!vam->json_output)
13088 {
John Loa43ccae2018-02-13 17:15:23 -050013089 print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s",
13090 "sw_if_index", "instance", "src_address", "dst_address",
13091 "tunnel_type", "outer_fib_id", "session_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013092 }
13093
13094 /* Get list of gre-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013095 M (GRE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013096
13097 mp->sw_if_index = htonl (sw_if_index);
13098
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013099 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013100
13101 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013102 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013103 S (mp_ping);
13104
Jon Loeliger56c7b012017-02-01 12:31:41 -060013105 W (ret);
13106 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013107}
13108
13109static int
13110api_l2_fib_clear_table (vat_main_t * vam)
13111{
13112// unformat_input_t * i = vam->input;
13113 vl_api_l2_fib_clear_table_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013114 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013115
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013116 M (L2_FIB_CLEAR_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013117
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013118 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013119 W (ret);
13120 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013121}
13122
13123static int
13124api_l2_interface_efp_filter (vat_main_t * vam)
13125{
13126 unformat_input_t *i = vam->input;
13127 vl_api_l2_interface_efp_filter_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013128 u32 sw_if_index;
13129 u8 enable = 1;
13130 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013131 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013132
13133 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13134 {
13135 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13136 sw_if_index_set = 1;
13137 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13138 sw_if_index_set = 1;
13139 else if (unformat (i, "enable"))
13140 enable = 1;
13141 else if (unformat (i, "disable"))
13142 enable = 0;
13143 else
13144 {
13145 clib_warning ("parse error '%U'", format_unformat_error, i);
13146 return -99;
13147 }
13148 }
13149
13150 if (sw_if_index_set == 0)
13151 {
13152 errmsg ("missing sw_if_index");
13153 return -99;
13154 }
13155
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013156 M (L2_INTERFACE_EFP_FILTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013157
13158 mp->sw_if_index = ntohl (sw_if_index);
13159 mp->enable_disable = enable;
13160
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013161 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013162 W (ret);
13163 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013164}
13165
13166#define foreach_vtr_op \
13167_("disable", L2_VTR_DISABLED) \
13168_("push-1", L2_VTR_PUSH_1) \
13169_("push-2", L2_VTR_PUSH_2) \
13170_("pop-1", L2_VTR_POP_1) \
13171_("pop-2", L2_VTR_POP_2) \
13172_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
13173_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
13174_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
13175_("translate-2-2", L2_VTR_TRANSLATE_2_2)
13176
13177static int
13178api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
13179{
13180 unformat_input_t *i = vam->input;
13181 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013182 u32 sw_if_index;
13183 u8 sw_if_index_set = 0;
13184 u8 vtr_op_set = 0;
13185 u32 vtr_op = 0;
13186 u32 push_dot1q = 1;
13187 u32 tag1 = ~0;
13188 u32 tag2 = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013189 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013190
13191 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13192 {
13193 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13194 sw_if_index_set = 1;
13195 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13196 sw_if_index_set = 1;
13197 else if (unformat (i, "vtr_op %d", &vtr_op))
13198 vtr_op_set = 1;
13199#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
13200 foreach_vtr_op
13201#undef _
13202 else if (unformat (i, "push_dot1q %d", &push_dot1q))
13203 ;
13204 else if (unformat (i, "tag1 %d", &tag1))
13205 ;
13206 else if (unformat (i, "tag2 %d", &tag2))
13207 ;
13208 else
13209 {
13210 clib_warning ("parse error '%U'", format_unformat_error, i);
13211 return -99;
13212 }
13213 }
13214
13215 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
13216 {
13217 errmsg ("missing vtr operation or sw_if_index");
13218 return -99;
13219 }
13220
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013221 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
13222 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013223 mp->vtr_op = ntohl (vtr_op);
13224 mp->push_dot1q = ntohl (push_dot1q);
13225 mp->tag1 = ntohl (tag1);
13226 mp->tag2 = ntohl (tag2);
13227
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013228 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013229 W (ret);
13230 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013231}
13232
13233static int
13234api_create_vhost_user_if (vat_main_t * vam)
13235{
13236 unformat_input_t *i = vam->input;
13237 vl_api_create_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013238 u8 *file_name;
13239 u8 is_server = 0;
13240 u8 file_name_set = 0;
13241 u32 custom_dev_instance = ~0;
13242 u8 hwaddr[6];
13243 u8 use_custom_mac = 0;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013244 u8 disable_mrg_rxbuf = 0;
13245 u8 disable_indirect_desc = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013246 u8 *tag = 0;
Steven Luong4208a4c2019-05-06 08:51:56 -070013247 u8 enable_gso = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013248 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013249
13250 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040013251 clib_memset (hwaddr, 0, sizeof (hwaddr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013252
13253 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13254 {
13255 if (unformat (i, "socket %s", &file_name))
13256 {
13257 file_name_set = 1;
13258 }
13259 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
13260 ;
13261 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
13262 use_custom_mac = 1;
13263 else if (unformat (i, "server"))
13264 is_server = 1;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013265 else if (unformat (i, "disable_mrg_rxbuf"))
13266 disable_mrg_rxbuf = 1;
13267 else if (unformat (i, "disable_indirect_desc"))
13268 disable_indirect_desc = 1;
Steven Luong4208a4c2019-05-06 08:51:56 -070013269 else if (unformat (i, "gso"))
13270 enable_gso = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013271 else if (unformat (i, "tag %s", &tag))
13272 ;
13273 else
13274 break;
13275 }
13276
13277 if (file_name_set == 0)
13278 {
13279 errmsg ("missing socket file name");
13280 return -99;
13281 }
13282
13283 if (vec_len (file_name) > 255)
13284 {
13285 errmsg ("socket file name too long");
13286 return -99;
13287 }
13288 vec_add1 (file_name, 0);
13289
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013290 M (CREATE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013291
13292 mp->is_server = is_server;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013293 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
13294 mp->disable_indirect_desc = disable_indirect_desc;
Steven Luong4208a4c2019-05-06 08:51:56 -070013295 mp->enable_gso = enable_gso;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013296 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
13297 vec_free (file_name);
13298 if (custom_dev_instance != ~0)
13299 {
13300 mp->renumber = 1;
13301 mp->custom_dev_instance = ntohl (custom_dev_instance);
13302 }
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013303
Damjan Marion7cd468a2016-12-19 23:05:39 +010013304 mp->use_custom_mac = use_custom_mac;
13305 clib_memcpy (mp->mac_address, hwaddr, 6);
13306 if (tag)
13307 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13308 vec_free (tag);
13309
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013310 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013311 W (ret);
13312 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013313}
13314
13315static int
13316api_modify_vhost_user_if (vat_main_t * vam)
13317{
13318 unformat_input_t *i = vam->input;
13319 vl_api_modify_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013320 u8 *file_name;
13321 u8 is_server = 0;
13322 u8 file_name_set = 0;
13323 u32 custom_dev_instance = ~0;
13324 u8 sw_if_index_set = 0;
13325 u32 sw_if_index = (u32) ~ 0;
Steven Luong4208a4c2019-05-06 08:51:56 -070013326 u8 enable_gso = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013327 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013328
13329 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13330 {
13331 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13332 sw_if_index_set = 1;
13333 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13334 sw_if_index_set = 1;
13335 else if (unformat (i, "socket %s", &file_name))
13336 {
13337 file_name_set = 1;
13338 }
13339 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
13340 ;
13341 else if (unformat (i, "server"))
13342 is_server = 1;
Steven Luong4208a4c2019-05-06 08:51:56 -070013343 else if (unformat (i, "gso"))
13344 enable_gso = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013345 else
13346 break;
13347 }
13348
13349 if (sw_if_index_set == 0)
13350 {
13351 errmsg ("missing sw_if_index or interface name");
13352 return -99;
13353 }
13354
13355 if (file_name_set == 0)
13356 {
13357 errmsg ("missing socket file name");
13358 return -99;
13359 }
13360
13361 if (vec_len (file_name) > 255)
13362 {
13363 errmsg ("socket file name too long");
13364 return -99;
13365 }
13366 vec_add1 (file_name, 0);
13367
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013368 M (MODIFY_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013369
13370 mp->sw_if_index = ntohl (sw_if_index);
13371 mp->is_server = is_server;
Steven Luong4208a4c2019-05-06 08:51:56 -070013372 mp->enable_gso = enable_gso;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013373 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
13374 vec_free (file_name);
13375 if (custom_dev_instance != ~0)
13376 {
13377 mp->renumber = 1;
13378 mp->custom_dev_instance = ntohl (custom_dev_instance);
13379 }
13380
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013381 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013382 W (ret);
13383 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013384}
13385
13386static int
13387api_delete_vhost_user_if (vat_main_t * vam)
13388{
13389 unformat_input_t *i = vam->input;
13390 vl_api_delete_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013391 u32 sw_if_index = ~0;
13392 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013393 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013394
13395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13396 {
13397 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13398 sw_if_index_set = 1;
13399 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13400 sw_if_index_set = 1;
13401 else
13402 break;
13403 }
13404
13405 if (sw_if_index_set == 0)
13406 {
13407 errmsg ("missing sw_if_index or interface name");
13408 return -99;
13409 }
13410
13411
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013412 M (DELETE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013413
13414 mp->sw_if_index = ntohl (sw_if_index);
13415
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013416 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013417 W (ret);
13418 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013419}
13420
13421static void vl_api_sw_interface_vhost_user_details_t_handler
13422 (vl_api_sw_interface_vhost_user_details_t * mp)
13423{
13424 vat_main_t *vam = &vat_main;
13425
Stevenf3b53642017-05-01 14:03:02 -070013426 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013427 (char *) mp->interface_name,
13428 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
13429 clib_net_to_host_u64 (mp->features), mp->is_server,
Stevenf3b53642017-05-01 14:03:02 -070013430 ntohl (mp->num_regions), (char *) mp->sock_filename);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013431 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
13432}
13433
13434static void vl_api_sw_interface_vhost_user_details_t_handler_json
13435 (vl_api_sw_interface_vhost_user_details_t * mp)
13436{
13437 vat_main_t *vam = &vat_main;
13438 vat_json_node_t *node = NULL;
13439
13440 if (VAT_JSON_ARRAY != vam->json_tree.type)
13441 {
13442 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13443 vat_json_init_array (&vam->json_tree);
13444 }
13445 node = vat_json_array_add (&vam->json_tree);
13446
13447 vat_json_init_object (node);
13448 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13449 vat_json_object_add_string_copy (node, "interface_name",
13450 mp->interface_name);
13451 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
13452 ntohl (mp->virtio_net_hdr_sz));
13453 vat_json_object_add_uint (node, "features",
13454 clib_net_to_host_u64 (mp->features));
13455 vat_json_object_add_uint (node, "is_server", mp->is_server);
13456 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
13457 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
13458 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
13459}
13460
13461static int
13462api_sw_interface_vhost_user_dump (vat_main_t * vam)
13463{
13464 vl_api_sw_interface_vhost_user_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013465 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013466 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013467 print (vam->ofp,
Stevenf3b53642017-05-01 14:03:02 -070013468 "Interface name idx hdr_sz features server regions filename");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013469
13470 /* Get list of vhost-user interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013471 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013472 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013473
13474 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013475 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013476 S (mp_ping);
13477
Jon Loeliger56c7b012017-02-01 12:31:41 -060013478 W (ret);
13479 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013480}
13481
13482static int
13483api_show_version (vat_main_t * vam)
13484{
13485 vl_api_show_version_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013486 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013487
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013488 M (SHOW_VERSION, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013489
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013490 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013491 W (ret);
13492 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013493}
13494
13495
13496static int
13497api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
13498{
13499 unformat_input_t *line_input = vam->input;
13500 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013501 ip4_address_t local4, remote4;
13502 ip6_address_t local6, remote6;
13503 u8 is_add = 1;
13504 u8 ipv4_set = 0, ipv6_set = 0;
13505 u8 local_set = 0;
13506 u8 remote_set = 0;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013507 u8 grp_set = 0;
13508 u32 mcast_sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013509 u32 encap_vrf_id = 0;
13510 u32 decap_vrf_id = 0;
13511 u8 protocol = ~0;
13512 u32 vni;
13513 u8 vni_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013514 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013515
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013516 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040013517 clib_memset (&local4, 0, sizeof local4);
13518 clib_memset (&remote4, 0, sizeof remote4);
13519 clib_memset (&local6, 0, sizeof local6);
13520 clib_memset (&remote6, 0, sizeof remote6);
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013521
Damjan Marion7cd468a2016-12-19 23:05:39 +010013522 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13523 {
13524 if (unformat (line_input, "del"))
13525 is_add = 0;
13526 else if (unformat (line_input, "local %U",
13527 unformat_ip4_address, &local4))
13528 {
13529 local_set = 1;
13530 ipv4_set = 1;
13531 }
13532 else if (unformat (line_input, "remote %U",
13533 unformat_ip4_address, &remote4))
13534 {
13535 remote_set = 1;
13536 ipv4_set = 1;
13537 }
13538 else if (unformat (line_input, "local %U",
13539 unformat_ip6_address, &local6))
13540 {
13541 local_set = 1;
13542 ipv6_set = 1;
13543 }
13544 else if (unformat (line_input, "remote %U",
13545 unformat_ip6_address, &remote6))
13546 {
13547 remote_set = 1;
13548 ipv6_set = 1;
13549 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013550 else if (unformat (line_input, "group %U %U",
13551 unformat_ip4_address, &remote4,
13552 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13553 {
13554 grp_set = remote_set = 1;
13555 ipv4_set = 1;
13556 }
13557 else if (unformat (line_input, "group %U",
13558 unformat_ip4_address, &remote4))
13559 {
13560 grp_set = remote_set = 1;
13561 ipv4_set = 1;
13562 }
13563 else if (unformat (line_input, "group %U %U",
13564 unformat_ip6_address, &remote6,
13565 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13566 {
13567 grp_set = remote_set = 1;
13568 ipv6_set = 1;
13569 }
13570 else if (unformat (line_input, "group %U",
13571 unformat_ip6_address, &remote6))
13572 {
13573 grp_set = remote_set = 1;
13574 ipv6_set = 1;
13575 }
13576 else
13577 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
13578 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013579 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
13580 ;
13581 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
13582 ;
13583 else if (unformat (line_input, "vni %d", &vni))
13584 vni_set = 1;
13585 else if (unformat (line_input, "next-ip4"))
13586 protocol = 1;
13587 else if (unformat (line_input, "next-ip6"))
13588 protocol = 2;
13589 else if (unformat (line_input, "next-ethernet"))
13590 protocol = 3;
13591 else if (unformat (line_input, "next-nsh"))
13592 protocol = 4;
13593 else
13594 {
13595 errmsg ("parse error '%U'", format_unformat_error, line_input);
13596 return -99;
13597 }
13598 }
13599
13600 if (local_set == 0)
13601 {
13602 errmsg ("tunnel local address not specified");
13603 return -99;
13604 }
13605 if (remote_set == 0)
13606 {
13607 errmsg ("tunnel remote address not specified");
13608 return -99;
13609 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013610 if (grp_set && mcast_sw_if_index == ~0)
13611 {
13612 errmsg ("tunnel nonexistent multicast device");
13613 return -99;
13614 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010013615 if (ipv4_set && ipv6_set)
13616 {
13617 errmsg ("both IPv4 and IPv6 addresses specified");
13618 return -99;
13619 }
13620
13621 if (vni_set == 0)
13622 {
13623 errmsg ("vni not specified");
13624 return -99;
13625 }
13626
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013627 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013628
13629
13630 if (ipv6_set)
13631 {
13632 clib_memcpy (&mp->local, &local6, sizeof (local6));
13633 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
13634 }
13635 else
13636 {
13637 clib_memcpy (&mp->local, &local4, sizeof (local4));
13638 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
13639 }
13640
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013641 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013642 mp->encap_vrf_id = ntohl (encap_vrf_id);
13643 mp->decap_vrf_id = ntohl (decap_vrf_id);
13644 mp->protocol = protocol;
13645 mp->vni = ntohl (vni);
13646 mp->is_add = is_add;
13647 mp->is_ipv6 = ipv6_set;
13648
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013649 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013650 W (ret);
13651 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013652}
13653
13654static void vl_api_vxlan_gpe_tunnel_details_t_handler
13655 (vl_api_vxlan_gpe_tunnel_details_t * mp)
13656{
13657 vat_main_t *vam = &vat_main;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013658 ip46_address_t local = to_ip46 (mp->is_ipv6, mp->local);
13659 ip46_address_t remote = to_ip46 (mp->is_ipv6, mp->remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013660
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013661 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013662 ntohl (mp->sw_if_index),
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013663 format_ip46_address, &local, IP46_TYPE_ANY,
13664 format_ip46_address, &remote, IP46_TYPE_ANY,
13665 ntohl (mp->vni), mp->protocol,
13666 ntohl (mp->mcast_sw_if_index),
Damjan Marion7cd468a2016-12-19 23:05:39 +010013667 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
13668}
13669
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013670
Damjan Marion7cd468a2016-12-19 23:05:39 +010013671static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
13672 (vl_api_vxlan_gpe_tunnel_details_t * mp)
13673{
13674 vat_main_t *vam = &vat_main;
13675 vat_json_node_t *node = NULL;
13676 struct in_addr ip4;
13677 struct in6_addr ip6;
13678
13679 if (VAT_JSON_ARRAY != vam->json_tree.type)
13680 {
13681 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13682 vat_json_init_array (&vam->json_tree);
13683 }
13684 node = vat_json_array_add (&vam->json_tree);
13685
13686 vat_json_init_object (node);
13687 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13688 if (mp->is_ipv6)
13689 {
13690 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
13691 vat_json_object_add_ip6 (node, "local", ip6);
13692 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
13693 vat_json_object_add_ip6 (node, "remote", ip6);
13694 }
13695 else
13696 {
13697 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
13698 vat_json_object_add_ip4 (node, "local", ip4);
13699 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
13700 vat_json_object_add_ip4 (node, "remote", ip4);
13701 }
13702 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
13703 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013704 vat_json_object_add_uint (node, "mcast_sw_if_index",
13705 ntohl (mp->mcast_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013706 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
13707 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
13708 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
13709}
13710
13711static int
13712api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
13713{
13714 unformat_input_t *i = vam->input;
13715 vl_api_vxlan_gpe_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013716 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013717 u32 sw_if_index;
13718 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013719 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013720
13721 /* Parse args required to build the message */
13722 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13723 {
13724 if (unformat (i, "sw_if_index %d", &sw_if_index))
13725 sw_if_index_set = 1;
13726 else
13727 break;
13728 }
13729
13730 if (sw_if_index_set == 0)
13731 {
13732 sw_if_index = ~0;
13733 }
13734
13735 if (!vam->json_output)
13736 {
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013737 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013738 "sw_if_index", "local", "remote", "vni",
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013739 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013740 }
13741
13742 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013743 M (VXLAN_GPE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013744
13745 mp->sw_if_index = htonl (sw_if_index);
13746
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013747 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013748
13749 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013750 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013751 S (mp_ping);
13752
Jon Loeliger56c7b012017-02-01 12:31:41 -060013753 W (ret);
13754 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013755}
13756
Ole Troan01384fe2017-05-12 11:55:35 +020013757static void vl_api_l2_fib_table_details_t_handler
13758 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013759{
13760 vat_main_t *vam = &vat_main;
13761
13762 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
13763 " %d %d %d",
Mohsin Kazmi57938f62017-10-27 21:28:07 +020013764 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
Damjan Marion7cd468a2016-12-19 23:05:39 +010013765 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
13766 mp->bvi_mac);
13767}
13768
Ole Troan01384fe2017-05-12 11:55:35 +020013769static void vl_api_l2_fib_table_details_t_handler_json
13770 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013771{
13772 vat_main_t *vam = &vat_main;
13773 vat_json_node_t *node = NULL;
13774
13775 if (VAT_JSON_ARRAY != vam->json_tree.type)
13776 {
13777 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13778 vat_json_init_array (&vam->json_tree);
13779 }
13780 node = vat_json_array_add (&vam->json_tree);
13781
13782 vat_json_init_object (node);
13783 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
Mohsin Kazmi57938f62017-10-27 21:28:07 +020013784 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013785 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13786 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
13787 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
13788 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
13789}
13790
13791static int
13792api_l2_fib_table_dump (vat_main_t * vam)
13793{
13794 unformat_input_t *i = vam->input;
13795 vl_api_l2_fib_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013796 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013797 u32 bd_id;
13798 u8 bd_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013799 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013800
13801 /* Parse args required to build the message */
13802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13803 {
13804 if (unformat (i, "bd_id %d", &bd_id))
13805 bd_id_set = 1;
13806 else
13807 break;
13808 }
13809
13810 if (bd_id_set == 0)
13811 {
13812 errmsg ("missing bridge domain");
13813 return -99;
13814 }
13815
13816 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
13817
13818 /* Get list of l2 fib entries */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013819 M (L2_FIB_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013820
13821 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013822 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013823
13824 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013825 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013826 S (mp_ping);
13827
Jon Loeliger56c7b012017-02-01 12:31:41 -060013828 W (ret);
13829 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013830}
13831
13832
13833static int
13834api_interface_name_renumber (vat_main_t * vam)
13835{
13836 unformat_input_t *line_input = vam->input;
13837 vl_api_interface_name_renumber_t *mp;
13838 u32 sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013839 u32 new_show_dev_instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013840 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013841
13842 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13843 {
13844 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
13845 &sw_if_index))
13846 ;
13847 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
13848 ;
13849 else if (unformat (line_input, "new_show_dev_instance %d",
13850 &new_show_dev_instance))
13851 ;
13852 else
13853 break;
13854 }
13855
13856 if (sw_if_index == ~0)
13857 {
13858 errmsg ("missing interface name or sw_if_index");
13859 return -99;
13860 }
13861
13862 if (new_show_dev_instance == ~0)
13863 {
13864 errmsg ("missing new_show_dev_instance");
13865 return -99;
13866 }
13867
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013868 M (INTERFACE_NAME_RENUMBER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013869
13870 mp->sw_if_index = ntohl (sw_if_index);
13871 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
13872
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013873 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013874 W (ret);
13875 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013876}
13877
13878static int
John Loc7b43042018-04-13 16:46:22 -040013879api_ip_probe_neighbor (vat_main_t * vam)
13880{
13881 unformat_input_t *i = vam->input;
13882 vl_api_ip_probe_neighbor_t *mp;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013883 vl_api_address_t dst_adr = { };
John Loc7b43042018-04-13 16:46:22 -040013884 u8 int_set = 0;
13885 u8 adr_set = 0;
John Loc7b43042018-04-13 16:46:22 -040013886 u32 sw_if_index;
13887 int ret;
13888
13889 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13890 {
13891 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13892 int_set = 1;
13893 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13894 int_set = 1;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013895 else if (unformat (i, "address %U", unformat_vl_api_address, &dst_adr))
John Loc7b43042018-04-13 16:46:22 -040013896 adr_set = 1;
John Loc7b43042018-04-13 16:46:22 -040013897 else
13898 break;
13899 }
13900
13901 if (int_set == 0)
13902 {
13903 errmsg ("missing interface");
13904 return -99;
13905 }
13906
13907 if (adr_set == 0)
13908 {
13909 errmsg ("missing addresses");
13910 return -99;
13911 }
13912
13913 M (IP_PROBE_NEIGHBOR, mp);
13914
13915 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -070013916 clib_memcpy (&mp->dst, &dst_adr, sizeof (dst_adr));
John Loc7b43042018-04-13 16:46:22 -040013917
13918 S (mp);
13919 W (ret);
13920 return ret;
13921}
13922
13923static int
John Lo7f358b32018-04-28 01:19:24 -040013924api_ip_scan_neighbor_enable_disable (vat_main_t * vam)
13925{
13926 unformat_input_t *i = vam->input;
13927 vl_api_ip_scan_neighbor_enable_disable_t *mp;
13928 u8 mode = IP_SCAN_V46_NEIGHBORS;
13929 u32 interval = 0, time = 0, update = 0, delay = 0, stale = 0;
13930 int ret;
13931
13932 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13933 {
13934 if (unformat (i, "ip4"))
13935 mode = IP_SCAN_V4_NEIGHBORS;
13936 else if (unformat (i, "ip6"))
13937 mode = IP_SCAN_V6_NEIGHBORS;
13938 if (unformat (i, "both"))
13939 mode = IP_SCAN_V46_NEIGHBORS;
13940 else if (unformat (i, "disable"))
13941 mode = IP_SCAN_DISABLED;
13942 else if (unformat (i, "interval %d", &interval))
13943 ;
13944 else if (unformat (i, "max-time %d", &time))
13945 ;
13946 else if (unformat (i, "max-update %d", &update))
13947 ;
13948 else if (unformat (i, "delay %d", &delay))
13949 ;
13950 else if (unformat (i, "stale %d", &stale))
13951 ;
13952 else
13953 break;
13954 }
13955
13956 if (interval > 255)
13957 {
13958 errmsg ("interval cannot exceed 255 minutes.");
13959 return -99;
13960 }
13961 if (time > 255)
13962 {
13963 errmsg ("max-time cannot exceed 255 usec.");
13964 return -99;
13965 }
13966 if (update > 255)
13967 {
13968 errmsg ("max-update cannot exceed 255.");
13969 return -99;
13970 }
13971 if (delay > 255)
13972 {
13973 errmsg ("delay cannot exceed 255 msec.");
13974 return -99;
13975 }
13976 if (stale > 255)
13977 {
13978 errmsg ("stale cannot exceed 255 minutes.");
13979 return -99;
13980 }
13981
13982 M (IP_SCAN_NEIGHBOR_ENABLE_DISABLE, mp);
13983 mp->mode = mode;
13984 mp->scan_interval = interval;
13985 mp->max_proc_time = time;
13986 mp->max_update = update;
13987 mp->scan_int_delay = delay;
13988 mp->stale_threshold = stale;
13989
13990 S (mp);
13991 W (ret);
13992 return ret;
13993}
13994
13995static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010013996api_want_ip4_arp_events (vat_main_t * vam)
13997{
13998 unformat_input_t *line_input = vam->input;
13999 vl_api_want_ip4_arp_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014000 ip4_address_t address;
14001 int address_set = 0;
14002 u32 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014003 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014004
14005 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14006 {
14007 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
14008 address_set = 1;
14009 else if (unformat (line_input, "del"))
14010 enable_disable = 0;
14011 else
14012 break;
14013 }
14014
14015 if (address_set == 0)
14016 {
14017 errmsg ("missing addresses");
14018 return -99;
14019 }
14020
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014021 M (WANT_IP4_ARP_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014022 mp->enable_disable = enable_disable;
John Lo20e1f2a2017-03-29 13:35:43 -040014023 mp->pid = htonl (getpid ());
Neale Ranns37029302018-08-10 05:30:06 -070014024 clib_memcpy (mp->ip, &address, sizeof (address));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014025
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014026 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014027 W (ret);
14028 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014029}
14030
14031static int
14032api_want_ip6_nd_events (vat_main_t * vam)
14033{
14034 unformat_input_t *line_input = vam->input;
14035 vl_api_want_ip6_nd_events_t *mp;
Neale Ranns37029302018-08-10 05:30:06 -070014036 vl_api_ip6_address_t address;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014037 int address_set = 0;
14038 u32 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014039 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014040
14041 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14042 {
Neale Ranns37029302018-08-10 05:30:06 -070014043 if (unformat
14044 (line_input, "address %U", unformat_vl_api_ip6_address, &address))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014045 address_set = 1;
14046 else if (unformat (line_input, "del"))
14047 enable_disable = 0;
14048 else
14049 break;
14050 }
14051
14052 if (address_set == 0)
14053 {
14054 errmsg ("missing addresses");
14055 return -99;
14056 }
14057
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014058 M (WANT_IP6_ND_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014059 mp->enable_disable = enable_disable;
John Lo20e1f2a2017-03-29 13:35:43 -040014060 mp->pid = htonl (getpid ());
Neale Ranns37029302018-08-10 05:30:06 -070014061 clib_memcpy (&mp->ip, &address, sizeof (address));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014062
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014063 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014064 W (ret);
14065 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014066}
14067
14068static int
John Lo8d00fff2017-08-03 00:35:36 -040014069api_want_l2_macs_events (vat_main_t * vam)
14070{
14071 unformat_input_t *line_input = vam->input;
14072 vl_api_want_l2_macs_events_t *mp;
14073 u8 enable_disable = 1;
14074 u32 scan_delay = 0;
14075 u32 max_macs_in_event = 0;
14076 u32 learn_limit = 0;
14077 int ret;
14078
14079 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14080 {
14081 if (unformat (line_input, "learn-limit %d", &learn_limit))
14082 ;
14083 else if (unformat (line_input, "scan-delay %d", &scan_delay))
14084 ;
14085 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
14086 ;
14087 else if (unformat (line_input, "disable"))
14088 enable_disable = 0;
14089 else
14090 break;
14091 }
14092
14093 M (WANT_L2_MACS_EVENTS, mp);
14094 mp->enable_disable = enable_disable;
14095 mp->pid = htonl (getpid ());
14096 mp->learn_limit = htonl (learn_limit);
14097 mp->scan_delay = (u8) scan_delay;
14098 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
14099 S (mp);
14100 W (ret);
14101 return ret;
14102}
14103
14104static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014105api_input_acl_set_interface (vat_main_t * vam)
14106{
14107 unformat_input_t *i = vam->input;
14108 vl_api_input_acl_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014109 u32 sw_if_index;
14110 int sw_if_index_set;
14111 u32 ip4_table_index = ~0;
14112 u32 ip6_table_index = ~0;
14113 u32 l2_table_index = ~0;
14114 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014115 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014116
14117 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14118 {
14119 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14120 sw_if_index_set = 1;
14121 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14122 sw_if_index_set = 1;
14123 else if (unformat (i, "del"))
14124 is_add = 0;
14125 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14126 ;
14127 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14128 ;
14129 else if (unformat (i, "l2-table %d", &l2_table_index))
14130 ;
14131 else
14132 {
14133 clib_warning ("parse error '%U'", format_unformat_error, i);
14134 return -99;
14135 }
14136 }
14137
14138 if (sw_if_index_set == 0)
14139 {
14140 errmsg ("missing interface name or sw_if_index");
14141 return -99;
14142 }
14143
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014144 M (INPUT_ACL_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014145
14146 mp->sw_if_index = ntohl (sw_if_index);
14147 mp->ip4_table_index = ntohl (ip4_table_index);
14148 mp->ip6_table_index = ntohl (ip6_table_index);
14149 mp->l2_table_index = ntohl (l2_table_index);
14150 mp->is_add = is_add;
14151
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014152 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014153 W (ret);
14154 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014155}
14156
14157static int
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010014158api_output_acl_set_interface (vat_main_t * vam)
14159{
14160 unformat_input_t *i = vam->input;
14161 vl_api_output_acl_set_interface_t *mp;
14162 u32 sw_if_index;
14163 int sw_if_index_set;
14164 u32 ip4_table_index = ~0;
14165 u32 ip6_table_index = ~0;
14166 u32 l2_table_index = ~0;
14167 u8 is_add = 1;
14168 int ret;
14169
14170 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14171 {
14172 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14173 sw_if_index_set = 1;
14174 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14175 sw_if_index_set = 1;
14176 else if (unformat (i, "del"))
14177 is_add = 0;
14178 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14179 ;
14180 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14181 ;
14182 else if (unformat (i, "l2-table %d", &l2_table_index))
14183 ;
14184 else
14185 {
14186 clib_warning ("parse error '%U'", format_unformat_error, i);
14187 return -99;
14188 }
14189 }
14190
14191 if (sw_if_index_set == 0)
14192 {
14193 errmsg ("missing interface name or sw_if_index");
14194 return -99;
14195 }
14196
14197 M (OUTPUT_ACL_SET_INTERFACE, mp);
14198
14199 mp->sw_if_index = ntohl (sw_if_index);
14200 mp->ip4_table_index = ntohl (ip4_table_index);
14201 mp->ip6_table_index = ntohl (ip6_table_index);
14202 mp->l2_table_index = ntohl (l2_table_index);
14203 mp->is_add = is_add;
14204
14205 S (mp);
14206 W (ret);
14207 return ret;
14208}
14209
14210static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014211api_ip_address_dump (vat_main_t * vam)
14212{
14213 unformat_input_t *i = vam->input;
14214 vl_api_ip_address_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014215 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014216 u32 sw_if_index = ~0;
14217 u8 sw_if_index_set = 0;
14218 u8 ipv4_set = 0;
14219 u8 ipv6_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014220 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014221
14222 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14223 {
14224 if (unformat (i, "sw_if_index %d", &sw_if_index))
14225 sw_if_index_set = 1;
14226 else
14227 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14228 sw_if_index_set = 1;
14229 else if (unformat (i, "ipv4"))
14230 ipv4_set = 1;
14231 else if (unformat (i, "ipv6"))
14232 ipv6_set = 1;
14233 else
14234 break;
14235 }
14236
14237 if (ipv4_set && ipv6_set)
14238 {
14239 errmsg ("ipv4 and ipv6 flags cannot be both set");
14240 return -99;
14241 }
14242
14243 if ((!ipv4_set) && (!ipv6_set))
14244 {
14245 errmsg ("no ipv4 nor ipv6 flag set");
14246 return -99;
14247 }
14248
14249 if (sw_if_index_set == 0)
14250 {
14251 errmsg ("missing interface name or sw_if_index");
14252 return -99;
14253 }
14254
14255 vam->current_sw_if_index = sw_if_index;
14256 vam->is_ipv6 = ipv6_set;
14257
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014258 M (IP_ADDRESS_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014259 mp->sw_if_index = ntohl (sw_if_index);
14260 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014261 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014262
14263 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014264 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014265 S (mp_ping);
14266
Jon Loeliger56c7b012017-02-01 12:31:41 -060014267 W (ret);
14268 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014269}
14270
14271static int
14272api_ip_dump (vat_main_t * vam)
14273{
14274 vl_api_ip_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014275 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014276 unformat_input_t *in = vam->input;
14277 int ipv4_set = 0;
14278 int ipv6_set = 0;
14279 int is_ipv6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014280 int i;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014281 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014282
14283 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
14284 {
14285 if (unformat (in, "ipv4"))
14286 ipv4_set = 1;
14287 else if (unformat (in, "ipv6"))
14288 ipv6_set = 1;
14289 else
14290 break;
14291 }
14292
14293 if (ipv4_set && ipv6_set)
14294 {
14295 errmsg ("ipv4 and ipv6 flags cannot be both set");
14296 return -99;
14297 }
14298
14299 if ((!ipv4_set) && (!ipv6_set))
14300 {
14301 errmsg ("no ipv4 nor ipv6 flag set");
14302 return -99;
14303 }
14304
14305 is_ipv6 = ipv6_set;
14306 vam->is_ipv6 = is_ipv6;
14307
14308 /* free old data */
14309 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
14310 {
14311 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
14312 }
14313 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
14314
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014315 M (IP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014316 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014317 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014318
14319 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014320 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014321 S (mp_ping);
14322
Jon Loeliger56c7b012017-02-01 12:31:41 -060014323 W (ret);
14324 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014325}
14326
14327static int
14328api_ipsec_spd_add_del (vat_main_t * vam)
14329{
14330 unformat_input_t *i = vam->input;
14331 vl_api_ipsec_spd_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014332 u32 spd_id = ~0;
14333 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014334 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014335
14336 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14337 {
14338 if (unformat (i, "spd_id %d", &spd_id))
14339 ;
14340 else if (unformat (i, "del"))
14341 is_add = 0;
14342 else
14343 {
14344 clib_warning ("parse error '%U'", format_unformat_error, i);
14345 return -99;
14346 }
14347 }
14348 if (spd_id == ~0)
14349 {
14350 errmsg ("spd_id must be set");
14351 return -99;
14352 }
14353
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014354 M (IPSEC_SPD_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014355
14356 mp->spd_id = ntohl (spd_id);
14357 mp->is_add = is_add;
14358
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014359 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014360 W (ret);
14361 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014362}
14363
14364static int
14365api_ipsec_interface_add_del_spd (vat_main_t * vam)
14366{
14367 unformat_input_t *i = vam->input;
14368 vl_api_ipsec_interface_add_del_spd_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014369 u32 sw_if_index;
14370 u8 sw_if_index_set = 0;
14371 u32 spd_id = (u32) ~ 0;
14372 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014373 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014374
14375 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14376 {
14377 if (unformat (i, "del"))
14378 is_add = 0;
14379 else if (unformat (i, "spd_id %d", &spd_id))
14380 ;
14381 else
14382 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14383 sw_if_index_set = 1;
14384 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14385 sw_if_index_set = 1;
14386 else
14387 {
14388 clib_warning ("parse error '%U'", format_unformat_error, i);
14389 return -99;
14390 }
14391
14392 }
14393
14394 if (spd_id == (u32) ~ 0)
14395 {
14396 errmsg ("spd_id must be set");
14397 return -99;
14398 }
14399
14400 if (sw_if_index_set == 0)
14401 {
14402 errmsg ("missing interface name or sw_if_index");
14403 return -99;
14404 }
14405
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014406 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014407
14408 mp->spd_id = ntohl (spd_id);
14409 mp->sw_if_index = ntohl (sw_if_index);
14410 mp->is_add = is_add;
14411
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014412 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014413 W (ret);
14414 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014415}
14416
14417static int
Neale Ranns17dcec02019-01-09 21:22:20 -080014418api_ipsec_spd_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014419{
14420 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080014421 vl_api_ipsec_spd_entry_add_del_t *mp;
Benoît Ganne49ee6842019-04-30 11:50:46 +020014422 u8 is_add = 1, is_outbound = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014423 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
14424 i32 priority = 0;
14425 u32 rport_start = 0, rport_stop = (u32) ~ 0;
14426 u32 lport_start = 0, lport_stop = (u32) ~ 0;
Neale Ranns17dcec02019-01-09 21:22:20 -080014427 vl_api_address_t laddr_start = { }, laddr_stop =
14428 {
14429 }, raddr_start =
14430 {
14431 }, raddr_stop =
14432 {
14433 };
Jon Loeliger56c7b012017-02-01 12:31:41 -060014434 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014435
Damjan Marion7cd468a2016-12-19 23:05:39 +010014436 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14437 {
14438 if (unformat (i, "del"))
14439 is_add = 0;
14440 if (unformat (i, "outbound"))
14441 is_outbound = 1;
14442 if (unformat (i, "inbound"))
14443 is_outbound = 0;
14444 else if (unformat (i, "spd_id %d", &spd_id))
14445 ;
14446 else if (unformat (i, "sa_id %d", &sa_id))
14447 ;
14448 else if (unformat (i, "priority %d", &priority))
14449 ;
14450 else if (unformat (i, "protocol %d", &protocol))
14451 ;
14452 else if (unformat (i, "lport_start %d", &lport_start))
14453 ;
14454 else if (unformat (i, "lport_stop %d", &lport_stop))
14455 ;
14456 else if (unformat (i, "rport_start %d", &rport_start))
14457 ;
14458 else if (unformat (i, "rport_stop %d", &rport_stop))
14459 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014460 else if (unformat (i, "laddr_start %U",
14461 unformat_vl_api_address, &laddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014462 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014463 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
14464 &laddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014465 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014466 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
14467 &raddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014468 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014469 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
14470 &raddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020014471 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014472 else
14473 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
14474 {
14475 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
14476 {
14477 clib_warning ("unsupported action: 'resolve'");
14478 return -99;
14479 }
14480 }
14481 else
14482 {
14483 clib_warning ("parse error '%U'", format_unformat_error, i);
14484 return -99;
14485 }
14486
14487 }
14488
Neale Ranns17dcec02019-01-09 21:22:20 -080014489 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014490
Damjan Marion7cd468a2016-12-19 23:05:39 +010014491 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080014492
14493 mp->entry.spd_id = ntohl (spd_id);
14494 mp->entry.priority = ntohl (priority);
14495 mp->entry.is_outbound = is_outbound;
14496
14497 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
14498 sizeof (vl_api_address_t));
14499 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
14500 sizeof (vl_api_address_t));
14501 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
14502 sizeof (vl_api_address_t));
14503 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
14504 sizeof (vl_api_address_t));
14505
14506 mp->entry.protocol = (u8) protocol;
14507 mp->entry.local_port_start = ntohs ((u16) lport_start);
14508 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
14509 mp->entry.remote_port_start = ntohs ((u16) rport_start);
14510 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
14511 mp->entry.policy = (u8) policy;
14512 mp->entry.sa_id = ntohl (sa_id);
Neale Ranns17dcec02019-01-09 21:22:20 -080014513
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014514 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014515 W (ret);
14516 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014517}
14518
14519static int
Neale Ranns17dcec02019-01-09 21:22:20 -080014520api_ipsec_sad_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014521{
14522 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080014523 vl_api_ipsec_sad_entry_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014524 u32 sad_id = 0, spi = 0;
14525 u8 *ck = 0, *ik = 0;
14526 u8 is_add = 1;
14527
Neale Ranns17dcec02019-01-09 21:22:20 -080014528 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
14529 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
14530 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
14531 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
14532 vl_api_address_t tun_src, tun_dst;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014533 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014534
14535 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14536 {
14537 if (unformat (i, "del"))
14538 is_add = 0;
14539 else if (unformat (i, "sad_id %d", &sad_id))
14540 ;
14541 else if (unformat (i, "spi %d", &spi))
14542 ;
14543 else if (unformat (i, "esp"))
Neale Ranns17dcec02019-01-09 21:22:20 -080014544 protocol = IPSEC_API_PROTO_ESP;
14545 else
14546 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014547 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014548 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
14549 if (ADDRESS_IP6 == tun_src.af)
14550 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014551 }
14552 else
Neale Ranns17dcec02019-01-09 21:22:20 -080014553 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014554 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014555 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
14556 if (ADDRESS_IP6 == tun_src.af)
14557 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014558 }
Neale Ranns17dcec02019-01-09 21:22:20 -080014559 else
14560 if (unformat (i, "crypto_alg %U",
14561 unformat_ipsec_api_crypto_alg, &crypto_alg))
14562 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014563 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
14564 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014565 else if (unformat (i, "integ_alg %U",
14566 unformat_ipsec_api_integ_alg, &integ_alg))
14567 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014568 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
14569 ;
14570 else
14571 {
14572 clib_warning ("parse error '%U'", format_unformat_error, i);
14573 return -99;
14574 }
14575
14576 }
14577
Neale Ranns17dcec02019-01-09 21:22:20 -080014578 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014579
Damjan Marion7cd468a2016-12-19 23:05:39 +010014580 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080014581 mp->entry.sad_id = ntohl (sad_id);
14582 mp->entry.protocol = protocol;
14583 mp->entry.spi = ntohl (spi);
14584 mp->entry.flags = flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014585
Neale Ranns17dcec02019-01-09 21:22:20 -080014586 mp->entry.crypto_algorithm = crypto_alg;
14587 mp->entry.integrity_algorithm = integ_alg;
14588 mp->entry.crypto_key.length = vec_len (ck);
14589 mp->entry.integrity_key.length = vec_len (ik);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014590
Neale Ranns17dcec02019-01-09 21:22:20 -080014591 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
14592 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
14593
14594 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
14595 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014596
14597 if (ck)
Neale Ranns17dcec02019-01-09 21:22:20 -080014598 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014599 if (ik)
Neale Ranns17dcec02019-01-09 21:22:20 -080014600 clib_memcpy (mp->entry.integrity_key.data, ik,
14601 mp->entry.integrity_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014602
Neale Ranns17dcec02019-01-09 21:22:20 -080014603 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014604 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014605 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
14606 sizeof (mp->entry.tunnel_src));
14607 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
14608 sizeof (mp->entry.tunnel_dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014609 }
14610
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014611 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014612 W (ret);
14613 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014614}
14615
14616static int
Matthew Smithb0972cb2017-05-02 16:20:41 -050014617api_ipsec_tunnel_if_add_del (vat_main_t * vam)
14618{
14619 unformat_input_t *i = vam->input;
14620 vl_api_ipsec_tunnel_if_add_del_t *mp;
14621 u32 local_spi = 0, remote_spi = 0;
14622 u32 crypto_alg = 0, integ_alg = 0;
14623 u8 *lck = NULL, *rck = NULL;
14624 u8 *lik = NULL, *rik = NULL;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040014625 vl_api_address_t local_ip = { 0 };
14626 vl_api_address_t remote_ip = { 0 };
Neale Ranns2b5ba952019-04-02 10:15:40 +000014627 f64 before = 0;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014628 u8 is_add = 1;
14629 u8 esn = 0;
14630 u8 anti_replay = 0;
Matthew Smith8e1039a2018-04-12 07:32:56 -050014631 u8 renumber = 0;
14632 u32 instance = ~0;
Neale Ranns2b5ba952019-04-02 10:15:40 +000014633 u32 count = 1, jj;
Benoît Ganne49ee6842019-04-30 11:50:46 +020014634 int ret = -1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014635
14636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14637 {
14638 if (unformat (i, "del"))
14639 is_add = 0;
14640 else if (unformat (i, "esn"))
14641 esn = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000014642 else if (unformat (i, "anti-replay"))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014643 anti_replay = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000014644 else if (unformat (i, "count %d", &count))
14645 ;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014646 else if (unformat (i, "local_spi %d", &local_spi))
14647 ;
14648 else if (unformat (i, "remote_spi %d", &remote_spi))
14649 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040014650 else
14651 if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014652 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040014653 else
14654 if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014655 ;
14656 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
14657 ;
14658 else
14659 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
14660 ;
14661 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
14662 ;
14663 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
14664 ;
14665 else
14666 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080014667 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014668 {
Dave Baracha8d47642018-07-13 11:22:23 -040014669 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014670 {
14671 errmsg ("unsupported crypto-alg: '%U'\n",
14672 format_ipsec_crypto_alg, crypto_alg);
14673 return -99;
14674 }
14675 }
14676 else
14677 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080014678 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050014679 {
Dave Baracha8d47642018-07-13 11:22:23 -040014680 if (integ_alg >= IPSEC_INTEG_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014681 {
14682 errmsg ("unsupported integ-alg: '%U'\n",
14683 format_ipsec_integ_alg, integ_alg);
14684 return -99;
14685 }
14686 }
Matthew Smith8e1039a2018-04-12 07:32:56 -050014687 else if (unformat (i, "instance %u", &instance))
14688 renumber = 1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014689 else
14690 {
14691 errmsg ("parse error '%U'\n", format_unformat_error, i);
14692 return -99;
14693 }
14694 }
14695
Neale Ranns2b5ba952019-04-02 10:15:40 +000014696 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014697 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000014698 /* Turn on async mode */
14699 vam->async_mode = 1;
14700 vam->async_errors = 0;
14701 before = vat_time_now (vam);
Matthew Smithb0972cb2017-05-02 16:20:41 -050014702 }
14703
Neale Ranns2b5ba952019-04-02 10:15:40 +000014704 for (jj = 0; jj < count; jj++)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014705 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000014706 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
14707
14708 mp->is_add = is_add;
14709 mp->esn = esn;
14710 mp->anti_replay = anti_replay;
14711
14712 if (jj > 0)
Neale Ranns097fa662018-05-01 05:17:55 -070014713 increment_address (&remote_ip);
Neale Ranns2b5ba952019-04-02 10:15:40 +000014714
14715 clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
14716 clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
14717
14718 mp->local_spi = htonl (local_spi + jj);
14719 mp->remote_spi = htonl (remote_spi + jj);
14720 mp->crypto_alg = (u8) crypto_alg;
14721
14722 mp->local_crypto_key_len = 0;
14723 if (lck)
14724 {
14725 mp->local_crypto_key_len = vec_len (lck);
14726 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
14727 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
14728 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
14729 }
14730
14731 mp->remote_crypto_key_len = 0;
14732 if (rck)
14733 {
14734 mp->remote_crypto_key_len = vec_len (rck);
14735 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
14736 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
14737 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
14738 }
14739
14740 mp->integ_alg = (u8) integ_alg;
14741
14742 mp->local_integ_key_len = 0;
14743 if (lik)
14744 {
14745 mp->local_integ_key_len = vec_len (lik);
14746 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
14747 mp->local_integ_key_len = sizeof (mp->local_integ_key);
14748 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
14749 }
14750
14751 mp->remote_integ_key_len = 0;
14752 if (rik)
14753 {
14754 mp->remote_integ_key_len = vec_len (rik);
14755 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
14756 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
14757 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
14758 }
14759
14760 if (renumber)
14761 {
14762 mp->renumber = renumber;
14763 mp->show_instance = ntohl (instance);
14764 }
14765 S (mp);
Matthew Smithb0972cb2017-05-02 16:20:41 -050014766 }
14767
Neale Ranns2b5ba952019-04-02 10:15:40 +000014768 /* When testing multiple add/del ops, use a control-ping to sync */
14769 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050014770 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000014771 vl_api_control_ping_t *mp_ping;
14772 f64 after;
14773 f64 timeout;
14774
14775 /* Shut off async mode */
14776 vam->async_mode = 0;
14777
14778 MPING (CONTROL_PING, mp_ping);
14779 S (mp_ping);
14780
14781 timeout = vat_time_now (vam) + 1.0;
14782 while (vat_time_now (vam) < timeout)
14783 if (vam->result_ready == 1)
14784 goto out;
14785 vam->retval = -99;
14786
14787 out:
14788 if (vam->retval == -99)
14789 errmsg ("timeout");
14790
14791 if (vam->async_errors > 0)
14792 {
14793 errmsg ("%d asynchronous errors", vam->async_errors);
14794 vam->retval = -98;
14795 }
14796 vam->async_errors = 0;
14797 after = vat_time_now (vam);
14798
14799 /* slim chance, but we might have eaten SIGTERM on the first iteration */
14800 if (jj > 0)
14801 count = jj;
14802
14803 print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec",
14804 count, after - before, count / (after - before));
14805 }
14806 else
14807 {
14808 /* Wait for a reply... */
14809 W (ret);
14810 return ret;
Matthew Smithb0972cb2017-05-02 16:20:41 -050014811 }
14812
Matthew Smithb0972cb2017-05-02 16:20:41 -050014813 return ret;
14814}
14815
Matthew Smith28029532017-09-26 13:33:44 -050014816static void
14817vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
14818{
14819 vat_main_t *vam = &vat_main;
14820
14821 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
Neale Ranns8d7c5022019-02-06 01:41:05 -080014822 "crypto_key %U integ_alg %u integ_key %U flags %x "
Matthew Smith28029532017-09-26 13:33:44 -050014823 "tunnel_src_addr %U tunnel_dst_addr %U "
14824 "salt %u seq_outbound %lu last_seq_inbound %lu "
Neale Rannseba31ec2019-02-17 18:04:27 +000014825 "replay_window %lu\n",
Neale Ranns8d7c5022019-02-06 01:41:05 -080014826 ntohl (mp->entry.sad_id),
14827 ntohl (mp->sw_if_index),
14828 ntohl (mp->entry.spi),
14829 ntohl (mp->entry.protocol),
14830 ntohl (mp->entry.crypto_algorithm),
14831 format_hex_bytes, mp->entry.crypto_key.data,
14832 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
14833 format_hex_bytes, mp->entry.integrity_key.data,
14834 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
14835 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
14836 &mp->entry.tunnel_dst, ntohl (mp->salt),
Matthew Smith28029532017-09-26 13:33:44 -050014837 clib_net_to_host_u64 (mp->seq_outbound),
14838 clib_net_to_host_u64 (mp->last_seq_inbound),
Neale Rannseba31ec2019-02-17 18:04:27 +000014839 clib_net_to_host_u64 (mp->replay_window));
Matthew Smith28029532017-09-26 13:33:44 -050014840}
14841
14842#define vl_api_ipsec_sa_details_t_endian vl_noop_handler
14843#define vl_api_ipsec_sa_details_t_print vl_noop_handler
14844
14845static void vl_api_ipsec_sa_details_t_handler_json
14846 (vl_api_ipsec_sa_details_t * mp)
14847{
14848 vat_main_t *vam = &vat_main;
14849 vat_json_node_t *node = NULL;
Neale Ranns8d7c5022019-02-06 01:41:05 -080014850 vl_api_ipsec_sad_flags_t flags;
Matthew Smith28029532017-09-26 13:33:44 -050014851
14852 if (VAT_JSON_ARRAY != vam->json_tree.type)
14853 {
14854 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14855 vat_json_init_array (&vam->json_tree);
14856 }
14857 node = vat_json_array_add (&vam->json_tree);
14858
14859 vat_json_init_object (node);
Neale Ranns8d7c5022019-02-06 01:41:05 -080014860 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
Matthew Smith28029532017-09-26 13:33:44 -050014861 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Neale Ranns8d7c5022019-02-06 01:41:05 -080014862 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
14863 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
14864 vat_json_object_add_uint (node, "crypto_alg",
14865 ntohl (mp->entry.crypto_algorithm));
14866 vat_json_object_add_uint (node, "integ_alg",
14867 ntohl (mp->entry.integrity_algorithm));
14868 flags = ntohl (mp->entry.flags);
14869 vat_json_object_add_uint (node, "use_esn",
Damjan Marion1e3aa5e2019-03-28 10:58:59 +010014870 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
Neale Ranns8d7c5022019-02-06 01:41:05 -080014871 vat_json_object_add_uint (node, "use_anti_replay",
14872 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
14873 vat_json_object_add_uint (node, "is_tunnel",
14874 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
14875 vat_json_object_add_uint (node, "is_tunnel_ip6",
14876 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
14877 vat_json_object_add_uint (node, "udp_encap",
14878 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
14879 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
14880 mp->entry.crypto_key.length);
14881 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
14882 mp->entry.integrity_key.length);
Neale Ranns5a8844b2019-04-16 07:15:35 +000014883 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
14884 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
Matthew Smith28029532017-09-26 13:33:44 -050014885 vat_json_object_add_uint (node, "replay_window",
14886 clib_net_to_host_u64 (mp->replay_window));
Matthew Smith28029532017-09-26 13:33:44 -050014887}
14888
14889static int
14890api_ipsec_sa_dump (vat_main_t * vam)
14891{
14892 unformat_input_t *i = vam->input;
14893 vl_api_ipsec_sa_dump_t *mp;
14894 vl_api_control_ping_t *mp_ping;
14895 u32 sa_id = ~0;
14896 int ret;
14897
14898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14899 {
14900 if (unformat (i, "sa_id %d", &sa_id))
14901 ;
14902 else
14903 {
14904 clib_warning ("parse error '%U'", format_unformat_error, i);
14905 return -99;
14906 }
14907 }
14908
14909 M (IPSEC_SA_DUMP, mp);
14910
14911 mp->sa_id = ntohl (sa_id);
14912
14913 S (mp);
14914
14915 /* Use a control ping for synchronization */
14916 M (CONTROL_PING, mp_ping);
14917 S (mp_ping);
14918
14919 W (ret);
14920 return ret;
14921}
14922
Matthew Smithb0972cb2017-05-02 16:20:41 -050014923static int
Matthew Smithca514fd2017-10-12 12:06:59 -050014924api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
14925{
14926 unformat_input_t *i = vam->input;
14927 vl_api_ipsec_tunnel_if_set_sa_t *mp;
14928 u32 sw_if_index = ~0;
14929 u32 sa_id = ~0;
14930 u8 is_outbound = (u8) ~ 0;
14931 int ret;
14932
14933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14934 {
14935 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14936 ;
14937 else if (unformat (i, "sa_id %d", &sa_id))
14938 ;
14939 else if (unformat (i, "outbound"))
14940 is_outbound = 1;
14941 else if (unformat (i, "inbound"))
14942 is_outbound = 0;
14943 else
14944 {
14945 clib_warning ("parse error '%U'", format_unformat_error, i);
14946 return -99;
14947 }
14948 }
14949
14950 if (sw_if_index == ~0)
14951 {
14952 errmsg ("interface must be specified");
14953 return -99;
14954 }
14955
14956 if (sa_id == ~0)
14957 {
14958 errmsg ("SA ID must be specified");
14959 return -99;
14960 }
14961
14962 M (IPSEC_TUNNEL_IF_SET_SA, mp);
14963
14964 mp->sw_if_index = htonl (sw_if_index);
14965 mp->sa_id = htonl (sa_id);
14966 mp->is_outbound = is_outbound;
14967
14968 S (mp);
14969 W (ret);
14970
14971 return ret;
14972}
14973
14974static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014975api_get_first_msg_id (vat_main_t * vam)
14976{
14977 vl_api_get_first_msg_id_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014978 unformat_input_t *i = vam->input;
14979 u8 *name;
14980 u8 name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014981 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014982
14983 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14984 {
14985 if (unformat (i, "client %s", &name))
14986 name_set = 1;
14987 else
14988 break;
14989 }
14990
14991 if (name_set == 0)
14992 {
14993 errmsg ("missing client name");
14994 return -99;
14995 }
14996 vec_add1 (name, 0);
14997
14998 if (vec_len (name) > 63)
14999 {
15000 errmsg ("client name too long");
15001 return -99;
15002 }
15003
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015004 M (GET_FIRST_MSG_ID, mp);
Ole Troan7adaa222019-08-27 15:05:27 +020015005 clib_memcpy (mp->name, name, vec_len (name));
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015006 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015007 W (ret);
15008 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015009}
15010
15011static int
15012api_cop_interface_enable_disable (vat_main_t * vam)
15013{
15014 unformat_input_t *line_input = vam->input;
15015 vl_api_cop_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015016 u32 sw_if_index = ~0;
15017 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015018 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015019
15020 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
15021 {
15022 if (unformat (line_input, "disable"))
15023 enable_disable = 0;
15024 if (unformat (line_input, "enable"))
15025 enable_disable = 1;
15026 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
15027 vam, &sw_if_index))
15028 ;
15029 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
15030 ;
15031 else
15032 break;
15033 }
15034
15035 if (sw_if_index == ~0)
15036 {
15037 errmsg ("missing interface name or sw_if_index");
15038 return -99;
15039 }
15040
15041 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015042 M (COP_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015043 mp->sw_if_index = ntohl (sw_if_index);
15044 mp->enable_disable = enable_disable;
15045
15046 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015047 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015048 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015049 W (ret);
15050 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015051}
15052
15053static int
15054api_cop_whitelist_enable_disable (vat_main_t * vam)
15055{
15056 unformat_input_t *line_input = vam->input;
15057 vl_api_cop_whitelist_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015058 u32 sw_if_index = ~0;
15059 u8 ip4 = 0, ip6 = 0, default_cop = 0;
15060 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015061 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015062
15063 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
15064 {
15065 if (unformat (line_input, "ip4"))
15066 ip4 = 1;
15067 else if (unformat (line_input, "ip6"))
15068 ip6 = 1;
15069 else if (unformat (line_input, "default"))
15070 default_cop = 1;
15071 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
15072 vam, &sw_if_index))
15073 ;
15074 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
15075 ;
15076 else if (unformat (line_input, "fib-id %d", &fib_id))
15077 ;
15078 else
15079 break;
15080 }
15081
15082 if (sw_if_index == ~0)
15083 {
15084 errmsg ("missing interface name or sw_if_index");
15085 return -99;
15086 }
15087
15088 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015089 M (COP_WHITELIST_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015090 mp->sw_if_index = ntohl (sw_if_index);
15091 mp->fib_id = ntohl (fib_id);
15092 mp->ip4 = ip4;
15093 mp->ip6 = ip6;
15094 mp->default_cop = default_cop;
15095
15096 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015097 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015098 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015099 W (ret);
15100 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015101}
15102
15103static int
15104api_get_node_graph (vat_main_t * vam)
15105{
15106 vl_api_get_node_graph_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015107 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015108
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015109 M (GET_NODE_GRAPH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015110
15111 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015112 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015113 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015114 W (ret);
15115 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015116}
15117
15118/* *INDENT-OFF* */
15119/** Used for parsing LISP eids */
15120typedef CLIB_PACKED(struct{
15121 u8 addr[16]; /**< eid address */
15122 u32 len; /**< prefix length if IP */
15123 u8 type; /**< type of eid */
15124}) lisp_eid_vat_t;
15125/* *INDENT-ON* */
15126
15127static uword
15128unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
15129{
15130 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
15131
Dave Barachb7b92992018-10-17 10:38:51 -040015132 clib_memset (a, 0, sizeof (a[0]));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015133
15134 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
15135 {
15136 a->type = 0; /* ipv4 type */
15137 }
15138 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
15139 {
15140 a->type = 1; /* ipv6 type */
15141 }
15142 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
15143 {
15144 a->type = 2; /* mac type */
15145 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015146 else if (unformat (input, "%U", unformat_nsh_address, a->addr))
15147 {
15148 a->type = 3; /* NSH type */
15149 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) a->addr;
15150 nsh->spi = clib_host_to_net_u32 (nsh->spi);
15151 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010015152 else
15153 {
15154 return 0;
15155 }
15156
15157 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
15158 {
15159 return 0;
15160 }
15161
15162 return 1;
15163}
15164
15165static int
15166lisp_eid_size_vat (u8 type)
15167{
15168 switch (type)
15169 {
15170 case 0:
15171 return 4;
15172 case 1:
15173 return 16;
15174 case 2:
15175 return 6;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015176 case 3:
15177 return 5;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015178 }
15179 return 0;
15180}
15181
15182static void
15183lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
15184{
15185 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
15186}
15187
Damjan Marion7cd468a2016-12-19 23:05:39 +010015188static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015189api_one_add_del_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015190{
15191 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015192 vl_api_one_add_del_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015193 u8 is_add = 1;
15194 u8 *locator_set_name = NULL;
15195 u8 locator_set_name_set = 0;
Filip Tehlar05a057b2017-02-01 08:50:31 +010015196 vl_api_local_locator_t locator, *locators = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015197 u32 sw_if_index, priority, weight;
15198 u32 data_len = 0;
15199
Jon Loeliger56c7b012017-02-01 12:31:41 -060015200 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015201 /* Parse args required to build the message */
15202 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15203 {
15204 if (unformat (input, "del"))
15205 {
15206 is_add = 0;
15207 }
15208 else if (unformat (input, "locator-set %s", &locator_set_name))
15209 {
15210 locator_set_name_set = 1;
15211 }
15212 else if (unformat (input, "sw_if_index %u p %u w %u",
15213 &sw_if_index, &priority, &weight))
15214 {
15215 locator.sw_if_index = htonl (sw_if_index);
15216 locator.priority = priority;
15217 locator.weight = weight;
15218 vec_add1 (locators, locator);
15219 }
15220 else
15221 if (unformat
15222 (input, "iface %U p %u w %u", api_unformat_sw_if_index, vam,
15223 &sw_if_index, &priority, &weight))
15224 {
15225 locator.sw_if_index = htonl (sw_if_index);
15226 locator.priority = priority;
15227 locator.weight = weight;
15228 vec_add1 (locators, locator);
15229 }
15230 else
15231 break;
15232 }
15233
15234 if (locator_set_name_set == 0)
15235 {
15236 errmsg ("missing locator-set name");
15237 vec_free (locators);
15238 return -99;
15239 }
15240
15241 if (vec_len (locator_set_name) > 64)
15242 {
15243 errmsg ("locator-set name too long");
15244 vec_free (locator_set_name);
15245 vec_free (locators);
15246 return -99;
15247 }
15248 vec_add1 (locator_set_name, 0);
15249
Filip Tehlar05a057b2017-02-01 08:50:31 +010015250 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015251
15252 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015253 M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015254
15255 mp->is_add = is_add;
15256 clib_memcpy (mp->locator_set_name, locator_set_name,
15257 vec_len (locator_set_name));
15258 vec_free (locator_set_name);
15259
15260 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
15261 if (locators)
15262 clib_memcpy (mp->locators, locators, data_len);
15263 vec_free (locators);
15264
15265 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015266 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015267
15268 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015269 W (ret);
15270 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015271}
15272
Filip Tehlar694396d2017-02-17 14:29:11 +010015273#define api_lisp_add_del_locator_set api_one_add_del_locator_set
15274
Damjan Marion7cd468a2016-12-19 23:05:39 +010015275static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015276api_one_add_del_locator (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015277{
15278 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015279 vl_api_one_add_del_locator_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015280 u32 tmp_if_index = ~0;
15281 u32 sw_if_index = ~0;
15282 u8 sw_if_index_set = 0;
15283 u8 sw_if_index_if_name_set = 0;
15284 u32 priority = ~0;
15285 u8 priority_set = 0;
15286 u32 weight = ~0;
15287 u8 weight_set = 0;
15288 u8 is_add = 1;
15289 u8 *locator_set_name = NULL;
15290 u8 locator_set_name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015291 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015292
15293 /* Parse args required to build the message */
15294 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15295 {
15296 if (unformat (input, "del"))
15297 {
15298 is_add = 0;
15299 }
15300 else if (unformat (input, "locator-set %s", &locator_set_name))
15301 {
15302 locator_set_name_set = 1;
15303 }
15304 else if (unformat (input, "iface %U", api_unformat_sw_if_index, vam,
15305 &tmp_if_index))
15306 {
15307 sw_if_index_if_name_set = 1;
15308 sw_if_index = tmp_if_index;
15309 }
15310 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
15311 {
15312 sw_if_index_set = 1;
15313 sw_if_index = tmp_if_index;
15314 }
15315 else if (unformat (input, "p %d", &priority))
15316 {
15317 priority_set = 1;
15318 }
15319 else if (unformat (input, "w %d", &weight))
15320 {
15321 weight_set = 1;
15322 }
15323 else
15324 break;
15325 }
15326
15327 if (locator_set_name_set == 0)
15328 {
15329 errmsg ("missing locator-set name");
15330 return -99;
15331 }
15332
15333 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
15334 {
15335 errmsg ("missing sw_if_index");
15336 vec_free (locator_set_name);
15337 return -99;
15338 }
15339
15340 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
15341 {
15342 errmsg ("cannot use both params interface name and sw_if_index");
15343 vec_free (locator_set_name);
15344 return -99;
15345 }
15346
15347 if (priority_set == 0)
15348 {
15349 errmsg ("missing locator-set priority");
15350 vec_free (locator_set_name);
15351 return -99;
15352 }
15353
15354 if (weight_set == 0)
15355 {
15356 errmsg ("missing locator-set weight");
15357 vec_free (locator_set_name);
15358 return -99;
15359 }
15360
15361 if (vec_len (locator_set_name) > 64)
15362 {
15363 errmsg ("locator-set name too long");
15364 vec_free (locator_set_name);
15365 return -99;
15366 }
15367 vec_add1 (locator_set_name, 0);
15368
15369 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015370 M (ONE_ADD_DEL_LOCATOR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015371
15372 mp->is_add = is_add;
15373 mp->sw_if_index = ntohl (sw_if_index);
15374 mp->priority = priority;
15375 mp->weight = weight;
15376 clib_memcpy (mp->locator_set_name, locator_set_name,
15377 vec_len (locator_set_name));
15378 vec_free (locator_set_name);
15379
15380 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015381 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015382
15383 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015384 W (ret);
15385 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015386}
15387
Filip Tehlar694396d2017-02-17 14:29:11 +010015388#define api_lisp_add_del_locator api_one_add_del_locator
15389
Damjan Marion7cd468a2016-12-19 23:05:39 +010015390uword
15391unformat_hmac_key_id (unformat_input_t * input, va_list * args)
15392{
15393 u32 *key_id = va_arg (*args, u32 *);
15394 u8 *s = 0;
15395
15396 if (unformat (input, "%s", &s))
15397 {
15398 if (!strcmp ((char *) s, "sha1"))
15399 key_id[0] = HMAC_SHA_1_96;
15400 else if (!strcmp ((char *) s, "sha256"))
15401 key_id[0] = HMAC_SHA_256_128;
15402 else
15403 {
15404 clib_warning ("invalid key_id: '%s'", s);
15405 key_id[0] = HMAC_NO_KEY;
15406 }
15407 }
15408 else
15409 return 0;
15410
15411 vec_free (s);
15412 return 1;
15413}
15414
15415static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015416api_one_add_del_local_eid (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015417{
15418 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015419 vl_api_one_add_del_local_eid_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015420 u8 is_add = 1;
15421 u8 eid_set = 0;
15422 lisp_eid_vat_t _eid, *eid = &_eid;
15423 u8 *locator_set_name = 0;
15424 u8 locator_set_name_set = 0;
15425 u32 vni = 0;
15426 u16 key_id = 0;
15427 u8 *key = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015428 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015429
15430 /* Parse args required to build the message */
15431 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15432 {
15433 if (unformat (input, "del"))
15434 {
15435 is_add = 0;
15436 }
15437 else if (unformat (input, "vni %d", &vni))
15438 {
15439 ;
15440 }
15441 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
15442 {
15443 eid_set = 1;
15444 }
15445 else if (unformat (input, "locator-set %s", &locator_set_name))
15446 {
15447 locator_set_name_set = 1;
15448 }
15449 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
15450 ;
15451 else if (unformat (input, "secret-key %_%v%_", &key))
15452 ;
15453 else
15454 break;
15455 }
15456
15457 if (locator_set_name_set == 0)
15458 {
15459 errmsg ("missing locator-set name");
15460 return -99;
15461 }
15462
15463 if (0 == eid_set)
15464 {
15465 errmsg ("EID address not set!");
15466 vec_free (locator_set_name);
15467 return -99;
15468 }
15469
15470 if (key && (0 == key_id))
15471 {
15472 errmsg ("invalid key_id!");
15473 return -99;
15474 }
15475
15476 if (vec_len (key) > 64)
15477 {
15478 errmsg ("key too long");
15479 vec_free (key);
15480 return -99;
15481 }
15482
15483 if (vec_len (locator_set_name) > 64)
15484 {
15485 errmsg ("locator-set name too long");
15486 vec_free (locator_set_name);
15487 return -99;
15488 }
15489 vec_add1 (locator_set_name, 0);
15490
15491 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015492 M (ONE_ADD_DEL_LOCAL_EID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015493
15494 mp->is_add = is_add;
15495 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
15496 mp->eid_type = eid->type;
15497 mp->prefix_len = eid->len;
15498 mp->vni = clib_host_to_net_u32 (vni);
15499 mp->key_id = clib_host_to_net_u16 (key_id);
15500 clib_memcpy (mp->locator_set_name, locator_set_name,
15501 vec_len (locator_set_name));
15502 clib_memcpy (mp->key, key, vec_len (key));
15503
15504 vec_free (locator_set_name);
15505 vec_free (key);
15506
15507 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015508 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015509
15510 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015511 W (ret);
15512 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015513}
15514
Filip Tehlar694396d2017-02-17 14:29:11 +010015515#define api_lisp_add_del_local_eid api_one_add_del_local_eid
Damjan Marion7cd468a2016-12-19 23:05:39 +010015516
15517static int
15518api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
15519{
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015520 u32 dp_table = 0, vni = 0;;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015521 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010015522 vl_api_gpe_add_del_fwd_entry_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015523 u8 is_add = 1;
15524 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
15525 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
15526 u8 rmt_eid_set = 0, lcl_eid_set = 0;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015527 u32 action = ~0, w;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015528 ip4_address_t rmt_rloc4, lcl_rloc4;
15529 ip6_address_t rmt_rloc6, lcl_rloc6;
Filip Tehlar82786c42017-02-20 15:20:37 +010015530 vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015531 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015532
Dave Barachb7b92992018-10-17 10:38:51 -040015533 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015534
15535 /* Parse args required to build the message */
15536 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15537 {
15538 if (unformat (input, "del"))
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015539 is_add = 0;
15540 else if (unformat (input, "add"))
15541 is_add = 1;
15542 else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015543 {
15544 rmt_eid_set = 1;
15545 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015546 else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015547 {
15548 lcl_eid_set = 1;
15549 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015550 else if (unformat (input, "vrf %d", &dp_table))
15551 ;
15552 else if (unformat (input, "bd %d", &dp_table))
15553 ;
15554 else if (unformat (input, "vni %d", &vni))
15555 ;
15556 else if (unformat (input, "w %d", &w))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015557 {
15558 if (!curr_rloc)
15559 {
15560 errmsg ("No RLOC configured for setting priority/weight!");
15561 return -99;
15562 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010015563 curr_rloc->weight = w;
15564 }
15565 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
15566 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
15567 {
15568 rloc.is_ip4 = 1;
15569
15570 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015571 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015572 vec_add1 (lcl_locs, rloc);
15573
15574 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
15575 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015576 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010015577 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
15578 }
15579 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
15580 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
15581 {
15582 rloc.is_ip4 = 0;
15583 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015584 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015585 vec_add1 (lcl_locs, rloc);
15586
15587 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
15588 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015589 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010015590 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
15591 }
15592 else if (unformat (input, "action %d", &action))
15593 {
15594 ;
15595 }
15596 else
15597 {
15598 clib_warning ("parse error '%U'", format_unformat_error, input);
15599 return -99;
15600 }
15601 }
15602
15603 if (!rmt_eid_set)
15604 {
15605 errmsg ("remote eid addresses not set");
15606 return -99;
15607 }
15608
15609 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
15610 {
15611 errmsg ("eid types don't match");
15612 return -99;
15613 }
15614
15615 if (0 == rmt_locs && (u32) ~ 0 == action)
15616 {
15617 errmsg ("action not set for negative mapping");
15618 return -99;
15619 }
15620
15621 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010015622 M2 (GPE_ADD_DEL_FWD_ENTRY, mp,
15623 sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015624
15625 mp->is_add = is_add;
15626 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
15627 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
15628 mp->eid_type = rmt_eid->type;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015629 mp->dp_table = clib_host_to_net_u32 (dp_table);
15630 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015631 mp->rmt_len = rmt_eid->len;
15632 mp->lcl_len = lcl_eid->len;
15633 mp->action = action;
15634
15635 if (0 != rmt_locs && 0 != lcl_locs)
15636 {
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015637 mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2);
15638 clib_memcpy (mp->locs, lcl_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010015639 (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs)));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015640
Filip Tehlar82786c42017-02-20 15:20:37 +010015641 u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010015642 clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010015643 (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs)));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015644 }
15645 vec_free (lcl_locs);
15646 vec_free (rmt_locs);
15647
15648 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015649 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015650
15651 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015652 W (ret);
15653 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015654}
15655
15656static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015657api_one_add_del_map_server (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015658{
15659 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015660 vl_api_one_add_del_map_server_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015661 u8 is_add = 1;
15662 u8 ipv4_set = 0;
15663 u8 ipv6_set = 0;
15664 ip4_address_t ipv4;
15665 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015666 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015667
15668 /* Parse args required to build the message */
15669 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15670 {
15671 if (unformat (input, "del"))
15672 {
15673 is_add = 0;
15674 }
15675 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
15676 {
15677 ipv4_set = 1;
15678 }
15679 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
15680 {
15681 ipv6_set = 1;
15682 }
15683 else
15684 break;
15685 }
15686
15687 if (ipv4_set && ipv6_set)
15688 {
15689 errmsg ("both eid v4 and v6 addresses set");
15690 return -99;
15691 }
15692
15693 if (!ipv4_set && !ipv6_set)
15694 {
15695 errmsg ("eid addresses not set");
15696 return -99;
15697 }
15698
15699 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015700 M (ONE_ADD_DEL_MAP_SERVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015701
15702 mp->is_add = is_add;
15703 if (ipv6_set)
15704 {
15705 mp->is_ipv6 = 1;
15706 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
15707 }
15708 else
15709 {
15710 mp->is_ipv6 = 0;
15711 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
15712 }
15713
15714 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015715 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015716
15717 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015718 W (ret);
15719 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015720}
15721
Filip Tehlar694396d2017-02-17 14:29:11 +010015722#define api_lisp_add_del_map_server api_one_add_del_map_server
15723
Damjan Marion7cd468a2016-12-19 23:05:39 +010015724static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015725api_one_add_del_map_resolver (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015726{
15727 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015728 vl_api_one_add_del_map_resolver_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015729 u8 is_add = 1;
15730 u8 ipv4_set = 0;
15731 u8 ipv6_set = 0;
15732 ip4_address_t ipv4;
15733 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015734 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015735
15736 /* Parse args required to build the message */
15737 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15738 {
15739 if (unformat (input, "del"))
15740 {
15741 is_add = 0;
15742 }
15743 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
15744 {
15745 ipv4_set = 1;
15746 }
15747 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
15748 {
15749 ipv6_set = 1;
15750 }
15751 else
15752 break;
15753 }
15754
15755 if (ipv4_set && ipv6_set)
15756 {
15757 errmsg ("both eid v4 and v6 addresses set");
15758 return -99;
15759 }
15760
15761 if (!ipv4_set && !ipv6_set)
15762 {
15763 errmsg ("eid addresses not set");
15764 return -99;
15765 }
15766
15767 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015768 M (ONE_ADD_DEL_MAP_RESOLVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015769
15770 mp->is_add = is_add;
15771 if (ipv6_set)
15772 {
15773 mp->is_ipv6 = 1;
15774 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
15775 }
15776 else
15777 {
15778 mp->is_ipv6 = 0;
15779 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
15780 }
15781
15782 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015783 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015784
15785 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015786 W (ret);
15787 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015788}
15789
Filip Tehlar694396d2017-02-17 14:29:11 +010015790#define api_lisp_add_del_map_resolver api_one_add_del_map_resolver
15791
Damjan Marion7cd468a2016-12-19 23:05:39 +010015792static int
15793api_lisp_gpe_enable_disable (vat_main_t * vam)
15794{
15795 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010015796 vl_api_gpe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015797 u8 is_set = 0;
15798 u8 is_en = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015799 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015800
15801 /* Parse args required to build the message */
15802 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15803 {
15804 if (unformat (input, "enable"))
15805 {
15806 is_set = 1;
15807 is_en = 1;
15808 }
15809 else if (unformat (input, "disable"))
15810 {
15811 is_set = 1;
15812 is_en = 0;
15813 }
15814 else
15815 break;
15816 }
15817
15818 if (is_set == 0)
15819 {
15820 errmsg ("Value not set");
15821 return -99;
15822 }
15823
15824 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010015825 M (GPE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015826
15827 mp->is_en = is_en;
15828
15829 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015830 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015831
15832 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015833 W (ret);
15834 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015835}
15836
15837static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015838api_one_rloc_probe_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015839{
15840 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015841 vl_api_one_rloc_probe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015842 u8 is_set = 0;
15843 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015844 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015845
15846 /* Parse args required to build the message */
15847 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15848 {
15849 if (unformat (input, "enable"))
15850 {
15851 is_set = 1;
15852 is_en = 1;
15853 }
15854 else if (unformat (input, "disable"))
15855 is_set = 1;
15856 else
15857 break;
15858 }
15859
15860 if (!is_set)
15861 {
15862 errmsg ("Value not set");
15863 return -99;
15864 }
15865
15866 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015867 M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015868
15869 mp->is_enabled = is_en;
15870
15871 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015872 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015873
15874 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015875 W (ret);
15876 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015877}
15878
Filip Tehlar694396d2017-02-17 14:29:11 +010015879#define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
15880
Damjan Marion7cd468a2016-12-19 23:05:39 +010015881static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015882api_one_map_register_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015883{
15884 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015885 vl_api_one_map_register_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015886 u8 is_set = 0;
15887 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015888 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015889
15890 /* Parse args required to build the message */
15891 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15892 {
15893 if (unformat (input, "enable"))
15894 {
15895 is_set = 1;
15896 is_en = 1;
15897 }
15898 else if (unformat (input, "disable"))
15899 is_set = 1;
15900 else
15901 break;
15902 }
15903
15904 if (!is_set)
15905 {
15906 errmsg ("Value not set");
15907 return -99;
15908 }
15909
15910 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015911 M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015912
15913 mp->is_enabled = is_en;
15914
15915 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015916 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015917
15918 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015919 W (ret);
15920 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015921}
15922
Filip Tehlar694396d2017-02-17 14:29:11 +010015923#define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
15924
Damjan Marion7cd468a2016-12-19 23:05:39 +010015925static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015926api_one_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015927{
15928 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015929 vl_api_one_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015930 u8 is_set = 0;
15931 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015932 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015933
15934 /* Parse args required to build the message */
15935 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15936 {
15937 if (unformat (input, "enable"))
15938 {
15939 is_set = 1;
15940 is_en = 1;
15941 }
15942 else if (unformat (input, "disable"))
15943 {
15944 is_set = 1;
15945 }
15946 else
15947 break;
15948 }
15949
15950 if (!is_set)
15951 {
15952 errmsg ("Value not set");
15953 return -99;
15954 }
15955
15956 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010015957 M (ONE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015958
15959 mp->is_en = is_en;
15960
15961 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015962 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015963
15964 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015965 W (ret);
15966 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015967}
15968
Filip Tehlar694396d2017-02-17 14:29:11 +010015969#define api_lisp_enable_disable api_one_enable_disable
15970
Damjan Marion7cd468a2016-12-19 23:05:39 +010015971static int
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015972api_one_enable_disable_xtr_mode (vat_main_t * vam)
15973{
15974 unformat_input_t *input = vam->input;
15975 vl_api_one_enable_disable_xtr_mode_t *mp;
15976 u8 is_set = 0;
15977 u8 is_en = 0;
15978 int ret;
15979
15980 /* Parse args required to build the message */
15981 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15982 {
15983 if (unformat (input, "enable"))
15984 {
15985 is_set = 1;
15986 is_en = 1;
15987 }
15988 else if (unformat (input, "disable"))
15989 {
15990 is_set = 1;
15991 }
15992 else
15993 break;
15994 }
15995
15996 if (!is_set)
15997 {
15998 errmsg ("Value not set");
15999 return -99;
16000 }
16001
16002 /* Construct the API message */
16003 M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
16004
16005 mp->is_en = is_en;
16006
16007 /* send it... */
16008 S (mp);
16009
16010 /* Wait for a reply... */
16011 W (ret);
16012 return ret;
16013}
16014
16015static int
16016api_one_show_xtr_mode (vat_main_t * vam)
16017{
16018 vl_api_one_show_xtr_mode_t *mp;
16019 int ret;
16020
16021 /* Construct the API message */
16022 M (ONE_SHOW_XTR_MODE, mp);
16023
16024 /* send it... */
16025 S (mp);
16026
16027 /* Wait for a reply... */
16028 W (ret);
16029 return ret;
16030}
16031
16032static int
16033api_one_enable_disable_pitr_mode (vat_main_t * vam)
16034{
16035 unformat_input_t *input = vam->input;
16036 vl_api_one_enable_disable_pitr_mode_t *mp;
16037 u8 is_set = 0;
16038 u8 is_en = 0;
16039 int ret;
16040
16041 /* Parse args required to build the message */
16042 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16043 {
16044 if (unformat (input, "enable"))
16045 {
16046 is_set = 1;
16047 is_en = 1;
16048 }
16049 else if (unformat (input, "disable"))
16050 {
16051 is_set = 1;
16052 }
16053 else
16054 break;
16055 }
16056
16057 if (!is_set)
16058 {
16059 errmsg ("Value not set");
16060 return -99;
16061 }
16062
16063 /* Construct the API message */
16064 M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
16065
16066 mp->is_en = is_en;
16067
16068 /* send it... */
16069 S (mp);
16070
16071 /* Wait for a reply... */
16072 W (ret);
16073 return ret;
16074}
16075
16076static int
16077api_one_show_pitr_mode (vat_main_t * vam)
16078{
16079 vl_api_one_show_pitr_mode_t *mp;
16080 int ret;
16081
16082 /* Construct the API message */
16083 M (ONE_SHOW_PITR_MODE, mp);
16084
16085 /* send it... */
16086 S (mp);
16087
16088 /* Wait for a reply... */
16089 W (ret);
16090 return ret;
16091}
16092
16093static int
16094api_one_enable_disable_petr_mode (vat_main_t * vam)
16095{
16096 unformat_input_t *input = vam->input;
16097 vl_api_one_enable_disable_petr_mode_t *mp;
16098 u8 is_set = 0;
16099 u8 is_en = 0;
16100 int ret;
16101
16102 /* Parse args required to build the message */
16103 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16104 {
16105 if (unformat (input, "enable"))
16106 {
16107 is_set = 1;
16108 is_en = 1;
16109 }
16110 else if (unformat (input, "disable"))
16111 {
16112 is_set = 1;
16113 }
16114 else
16115 break;
16116 }
16117
16118 if (!is_set)
16119 {
16120 errmsg ("Value not set");
16121 return -99;
16122 }
16123
16124 /* Construct the API message */
16125 M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
16126
16127 mp->is_en = is_en;
16128
16129 /* send it... */
16130 S (mp);
16131
16132 /* Wait for a reply... */
16133 W (ret);
16134 return ret;
16135}
16136
16137static int
16138api_one_show_petr_mode (vat_main_t * vam)
16139{
16140 vl_api_one_show_petr_mode_t *mp;
16141 int ret;
16142
16143 /* Construct the API message */
16144 M (ONE_SHOW_PETR_MODE, mp);
16145
16146 /* send it... */
16147 S (mp);
16148
16149 /* Wait for a reply... */
16150 W (ret);
16151 return ret;
16152}
16153
16154static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016155api_show_one_map_register_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016156{
Filip Tehlar694396d2017-02-17 14:29:11 +010016157 vl_api_show_one_map_register_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016158 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016159
Filip Tehlar694396d2017-02-17 14:29:11 +010016160 M (SHOW_ONE_MAP_REGISTER_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016161
16162 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016163 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016164
16165 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016166 W (ret);
16167 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016168}
16169
Filip Tehlar694396d2017-02-17 14:29:11 +010016170#define api_show_lisp_map_register_state api_show_one_map_register_state
16171
Damjan Marion7cd468a2016-12-19 23:05:39 +010016172static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016173api_show_one_rloc_probe_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016174{
Filip Tehlar694396d2017-02-17 14:29:11 +010016175 vl_api_show_one_rloc_probe_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016176 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016177
Filip Tehlar694396d2017-02-17 14:29:11 +010016178 M (SHOW_ONE_RLOC_PROBE_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016179
16180 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016181 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016182
16183 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016184 W (ret);
16185 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016186}
16187
Filip Tehlar694396d2017-02-17 14:29:11 +010016188#define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
16189
Damjan Marion7cd468a2016-12-19 23:05:39 +010016190static int
Filip Tehlar05879992017-09-05 15:46:09 +020016191api_one_add_del_ndp_entry (vat_main_t * vam)
16192{
16193 vl_api_one_add_del_ndp_entry_t *mp;
16194 unformat_input_t *input = vam->input;
16195 u8 is_add = 1;
16196 u8 mac_set = 0;
16197 u8 bd_set = 0;
16198 u8 ip_set = 0;
16199 u8 mac[6] = { 0, };
16200 u8 ip6[16] = { 0, };
16201 u32 bd = ~0;
16202 int ret;
16203
16204 /* Parse args required to build the message */
16205 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16206 {
16207 if (unformat (input, "del"))
16208 is_add = 0;
16209 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
16210 mac_set = 1;
16211 else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
16212 ip_set = 1;
16213 else if (unformat (input, "bd %d", &bd))
16214 bd_set = 1;
16215 else
16216 {
16217 errmsg ("parse error '%U'", format_unformat_error, input);
16218 return -99;
16219 }
16220 }
16221
16222 if (!bd_set || !ip_set || (!mac_set && is_add))
16223 {
16224 errmsg ("Missing BD, IP or MAC!");
16225 return -99;
16226 }
16227
16228 M (ONE_ADD_DEL_NDP_ENTRY, mp);
16229 mp->is_add = is_add;
16230 clib_memcpy (mp->mac, mac, 6);
16231 mp->bd = clib_host_to_net_u32 (bd);
16232 clib_memcpy (mp->ip6, ip6, sizeof (mp->ip6));
16233
16234 /* send */
16235 S (mp);
16236
16237 /* wait for reply */
16238 W (ret);
16239 return ret;
16240}
16241
16242static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020016243api_one_add_del_l2_arp_entry (vat_main_t * vam)
16244{
16245 vl_api_one_add_del_l2_arp_entry_t *mp;
16246 unformat_input_t *input = vam->input;
16247 u8 is_add = 1;
16248 u8 mac_set = 0;
16249 u8 bd_set = 0;
16250 u8 ip_set = 0;
16251 u8 mac[6] = { 0, };
16252 u32 ip4 = 0, bd = ~0;
16253 int ret;
16254
16255 /* Parse args required to build the message */
16256 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16257 {
16258 if (unformat (input, "del"))
16259 is_add = 0;
16260 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
16261 mac_set = 1;
16262 else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
16263 ip_set = 1;
16264 else if (unformat (input, "bd %d", &bd))
16265 bd_set = 1;
16266 else
16267 {
16268 errmsg ("parse error '%U'", format_unformat_error, input);
16269 return -99;
16270 }
16271 }
16272
16273 if (!bd_set || !ip_set || (!mac_set && is_add))
16274 {
16275 errmsg ("Missing BD, IP or MAC!");
16276 return -99;
16277 }
16278
16279 M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
16280 mp->is_add = is_add;
16281 clib_memcpy (mp->mac, mac, 6);
16282 mp->bd = clib_host_to_net_u32 (bd);
16283 mp->ip4 = ip4;
16284
16285 /* send */
16286 S (mp);
16287
16288 /* wait for reply */
16289 W (ret);
16290 return ret;
16291}
16292
16293static int
Filip Tehlar05879992017-09-05 15:46:09 +020016294api_one_ndp_bd_get (vat_main_t * vam)
16295{
16296 vl_api_one_ndp_bd_get_t *mp;
16297 int ret;
16298
16299 M (ONE_NDP_BD_GET, mp);
16300
16301 /* send */
16302 S (mp);
16303
16304 /* wait for reply */
16305 W (ret);
16306 return ret;
16307}
16308
16309static int
16310api_one_ndp_entries_get (vat_main_t * vam)
16311{
16312 vl_api_one_ndp_entries_get_t *mp;
16313 unformat_input_t *input = vam->input;
16314 u8 bd_set = 0;
16315 u32 bd = ~0;
16316 int ret;
16317
16318 /* Parse args required to build the message */
16319 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16320 {
16321 if (unformat (input, "bd %d", &bd))
16322 bd_set = 1;
16323 else
16324 {
16325 errmsg ("parse error '%U'", format_unformat_error, input);
16326 return -99;
16327 }
16328 }
16329
16330 if (!bd_set)
16331 {
16332 errmsg ("Expected bridge domain!");
16333 return -99;
16334 }
16335
16336 M (ONE_NDP_ENTRIES_GET, mp);
16337 mp->bd = clib_host_to_net_u32 (bd);
16338
16339 /* send */
16340 S (mp);
16341
16342 /* wait for reply */
16343 W (ret);
16344 return ret;
16345}
16346
16347static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020016348api_one_l2_arp_bd_get (vat_main_t * vam)
16349{
16350 vl_api_one_l2_arp_bd_get_t *mp;
16351 int ret;
16352
16353 M (ONE_L2_ARP_BD_GET, mp);
16354
16355 /* send */
16356 S (mp);
16357
16358 /* wait for reply */
16359 W (ret);
16360 return ret;
16361}
16362
16363static int
16364api_one_l2_arp_entries_get (vat_main_t * vam)
16365{
16366 vl_api_one_l2_arp_entries_get_t *mp;
16367 unformat_input_t *input = vam->input;
16368 u8 bd_set = 0;
16369 u32 bd = ~0;
16370 int ret;
16371
16372 /* Parse args required to build the message */
16373 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16374 {
16375 if (unformat (input, "bd %d", &bd))
16376 bd_set = 1;
16377 else
16378 {
16379 errmsg ("parse error '%U'", format_unformat_error, input);
16380 return -99;
16381 }
16382 }
16383
16384 if (!bd_set)
16385 {
16386 errmsg ("Expected bridge domain!");
16387 return -99;
16388 }
16389
16390 M (ONE_L2_ARP_ENTRIES_GET, mp);
16391 mp->bd = clib_host_to_net_u32 (bd);
16392
16393 /* send */
16394 S (mp);
16395
16396 /* wait for reply */
16397 W (ret);
16398 return ret;
16399}
16400
16401static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010016402api_one_stats_enable_disable (vat_main_t * vam)
16403{
16404 vl_api_one_stats_enable_disable_t *mp;
16405 unformat_input_t *input = vam->input;
16406 u8 is_set = 0;
16407 u8 is_en = 0;
16408 int ret;
16409
16410 /* Parse args required to build the message */
16411 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16412 {
16413 if (unformat (input, "enable"))
16414 {
16415 is_set = 1;
16416 is_en = 1;
16417 }
16418 else if (unformat (input, "disable"))
16419 {
16420 is_set = 1;
16421 }
16422 else
16423 break;
16424 }
16425
16426 if (!is_set)
16427 {
16428 errmsg ("Value not set");
16429 return -99;
16430 }
16431
16432 M (ONE_STATS_ENABLE_DISABLE, mp);
16433 mp->is_en = is_en;
16434
16435 /* send */
16436 S (mp);
16437
16438 /* wait for reply */
16439 W (ret);
16440 return ret;
16441}
16442
16443static int
16444api_show_one_stats_enable_disable (vat_main_t * vam)
16445{
16446 vl_api_show_one_stats_enable_disable_t *mp;
16447 int ret;
16448
16449 M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
16450
16451 /* send */
16452 S (mp);
16453
16454 /* wait for reply */
16455 W (ret);
16456 return ret;
16457}
16458
16459static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016460api_show_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016461{
Filip Tehlar694396d2017-02-17 14:29:11 +010016462 vl_api_show_one_map_request_mode_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016463 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016464
Filip Tehlar694396d2017-02-17 14:29:11 +010016465 M (SHOW_ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016466
16467 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016468 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016469
16470 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016471 W (ret);
16472 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016473}
16474
Filip Tehlar694396d2017-02-17 14:29:11 +010016475#define api_show_lisp_map_request_mode api_show_one_map_request_mode
16476
Damjan Marion7cd468a2016-12-19 23:05:39 +010016477static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016478api_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016479{
Damjan Marion7cd468a2016-12-19 23:05:39 +010016480 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016481 vl_api_one_map_request_mode_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016482 u8 mode = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016483 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016484
16485 /* Parse args required to build the message */
16486 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16487 {
16488 if (unformat (input, "dst-only"))
16489 mode = 0;
16490 else if (unformat (input, "src-dst"))
16491 mode = 1;
16492 else
16493 {
16494 errmsg ("parse error '%U'", format_unformat_error, input);
16495 return -99;
16496 }
16497 }
16498
Filip Tehlar694396d2017-02-17 14:29:11 +010016499 M (ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016500
16501 mp->mode = mode;
16502
16503 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016504 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016505
16506 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016507 W (ret);
16508 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016509}
16510
Filip Tehlar694396d2017-02-17 14:29:11 +010016511#define api_lisp_map_request_mode api_one_map_request_mode
16512
Damjan Marion7cd468a2016-12-19 23:05:39 +010016513/**
Filip Tehlar694396d2017-02-17 14:29:11 +010016514 * Enable/disable ONE proxy ITR.
Damjan Marion7cd468a2016-12-19 23:05:39 +010016515 *
16516 * @param vam vpp API test context
16517 * @return return code
16518 */
16519static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016520api_one_pitr_set_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016521{
Damjan Marion7cd468a2016-12-19 23:05:39 +010016522 u8 ls_name_set = 0;
16523 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016524 vl_api_one_pitr_set_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016525 u8 is_add = 1;
16526 u8 *ls_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016527 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016528
16529 /* Parse args required to build the message */
16530 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16531 {
16532 if (unformat (input, "del"))
16533 is_add = 0;
16534 else if (unformat (input, "locator-set %s", &ls_name))
16535 ls_name_set = 1;
16536 else
16537 {
16538 errmsg ("parse error '%U'", format_unformat_error, input);
16539 return -99;
16540 }
16541 }
16542
16543 if (!ls_name_set)
16544 {
16545 errmsg ("locator-set name not set!");
16546 return -99;
16547 }
16548
Filip Tehlar694396d2017-02-17 14:29:11 +010016549 M (ONE_PITR_SET_LOCATOR_SET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016550
16551 mp->is_add = is_add;
16552 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
16553 vec_free (ls_name);
16554
16555 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016556 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016557
16558 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016559 W (ret);
16560 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016561}
16562
Filip Tehlar694396d2017-02-17 14:29:11 +010016563#define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
16564
Damjan Marion7cd468a2016-12-19 23:05:39 +010016565static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016566api_one_nsh_set_locator_set (vat_main_t * vam)
16567{
16568 u8 ls_name_set = 0;
16569 unformat_input_t *input = vam->input;
16570 vl_api_one_nsh_set_locator_set_t *mp;
16571 u8 is_add = 1;
16572 u8 *ls_name = 0;
16573 int ret;
16574
16575 /* Parse args required to build the message */
16576 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16577 {
16578 if (unformat (input, "del"))
16579 is_add = 0;
16580 else if (unformat (input, "ls %s", &ls_name))
16581 ls_name_set = 1;
16582 else
16583 {
16584 errmsg ("parse error '%U'", format_unformat_error, input);
16585 return -99;
16586 }
16587 }
16588
16589 if (!ls_name_set && is_add)
16590 {
16591 errmsg ("locator-set name not set!");
16592 return -99;
16593 }
16594
16595 M (ONE_NSH_SET_LOCATOR_SET, mp);
16596
16597 mp->is_add = is_add;
16598 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
16599 vec_free (ls_name);
16600
16601 /* send */
16602 S (mp);
16603
16604 /* wait for reply */
16605 W (ret);
16606 return ret;
16607}
16608
16609static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016610api_show_one_pitr (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016611{
Filip Tehlar694396d2017-02-17 14:29:11 +010016612 vl_api_show_one_pitr_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016613 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016614
16615 if (!vam->json_output)
16616 {
16617 print (vam->ofp, "%=20s", "lisp status:");
16618 }
16619
Filip Tehlar694396d2017-02-17 14:29:11 +010016620 M (SHOW_ONE_PITR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016621 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016622 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016623
16624 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016625 W (ret);
16626 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016627}
16628
Filip Tehlar694396d2017-02-17 14:29:11 +010016629#define api_show_lisp_pitr api_show_one_pitr
16630
Filip Tehlar67a99f82017-03-10 13:18:02 +010016631static int
16632api_one_use_petr (vat_main_t * vam)
16633{
16634 unformat_input_t *input = vam->input;
16635 vl_api_one_use_petr_t *mp;
16636 u8 is_add = 0;
16637 ip_address_t ip;
16638 int ret;
16639
Dave Barachb7b92992018-10-17 10:38:51 -040016640 clib_memset (&ip, 0, sizeof (ip));
Filip Tehlar67a99f82017-03-10 13:18:02 +010016641
16642 /* Parse args required to build the message */
16643 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16644 {
16645 if (unformat (input, "disable"))
16646 is_add = 0;
16647 else
16648 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
16649 {
16650 is_add = 1;
16651 ip_addr_version (&ip) = IP4;
16652 }
16653 else
16654 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
16655 {
16656 is_add = 1;
16657 ip_addr_version (&ip) = IP6;
16658 }
16659 else
16660 {
16661 errmsg ("parse error '%U'", format_unformat_error, input);
16662 return -99;
16663 }
16664 }
16665
16666 M (ONE_USE_PETR, mp);
16667
16668 mp->is_add = is_add;
16669 if (is_add)
16670 {
16671 mp->is_ip4 = ip_addr_version (&ip) == IP4 ? 1 : 0;
16672 if (mp->is_ip4)
16673 clib_memcpy (mp->address, &ip, 4);
16674 else
16675 clib_memcpy (mp->address, &ip, 16);
16676 }
16677
16678 /* send */
16679 S (mp);
16680
16681 /* wait for reply */
16682 W (ret);
16683 return ret;
16684}
16685
16686#define api_lisp_use_petr api_one_use_petr
16687
16688static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016689api_show_one_nsh_mapping (vat_main_t * vam)
16690{
16691 vl_api_show_one_use_petr_t *mp;
16692 int ret;
16693
16694 if (!vam->json_output)
16695 {
16696 print (vam->ofp, "%=20s", "local ONE NSH mapping:");
16697 }
16698
16699 M (SHOW_ONE_NSH_MAPPING, mp);
16700 /* send it... */
16701 S (mp);
16702
16703 /* Wait for a reply... */
16704 W (ret);
16705 return ret;
16706}
16707
16708static int
Filip Tehlar67a99f82017-03-10 13:18:02 +010016709api_show_one_use_petr (vat_main_t * vam)
16710{
16711 vl_api_show_one_use_petr_t *mp;
16712 int ret;
16713
16714 if (!vam->json_output)
16715 {
16716 print (vam->ofp, "%=20s", "Proxy-ETR status:");
16717 }
16718
16719 M (SHOW_ONE_USE_PETR, mp);
16720 /* send it... */
16721 S (mp);
16722
16723 /* Wait for a reply... */
16724 W (ret);
16725 return ret;
16726}
16727
16728#define api_show_lisp_use_petr api_show_one_use_petr
16729
Damjan Marion7cd468a2016-12-19 23:05:39 +010016730/**
16731 * Add/delete mapping between vni and vrf
16732 */
16733static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016734api_one_eid_table_add_del_map (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016735{
Damjan Marion7cd468a2016-12-19 23:05:39 +010016736 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016737 vl_api_one_eid_table_add_del_map_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016738 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
16739 u32 vni, vrf, bd_index;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016740 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016741
16742 /* Parse args required to build the message */
16743 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16744 {
16745 if (unformat (input, "del"))
16746 is_add = 0;
16747 else if (unformat (input, "vrf %d", &vrf))
16748 vrf_set = 1;
16749 else if (unformat (input, "bd_index %d", &bd_index))
16750 bd_index_set = 1;
16751 else if (unformat (input, "vni %d", &vni))
16752 vni_set = 1;
16753 else
16754 break;
16755 }
16756
16757 if (!vni_set || (!vrf_set && !bd_index_set))
16758 {
16759 errmsg ("missing arguments!");
16760 return -99;
16761 }
16762
16763 if (vrf_set && bd_index_set)
16764 {
16765 errmsg ("error: both vrf and bd entered!");
16766 return -99;
16767 }
16768
Filip Tehlar694396d2017-02-17 14:29:11 +010016769 M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016770
16771 mp->is_add = is_add;
16772 mp->vni = htonl (vni);
16773 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
16774 mp->is_l2 = bd_index_set;
16775
16776 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016777 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016778
16779 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016780 W (ret);
16781 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016782}
16783
Filip Tehlar694396d2017-02-17 14:29:11 +010016784#define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
16785
Damjan Marion7cd468a2016-12-19 23:05:39 +010016786uword
16787unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
16788{
16789 u32 *action = va_arg (*args, u32 *);
16790 u8 *s = 0;
16791
16792 if (unformat (input, "%s", &s))
16793 {
16794 if (!strcmp ((char *) s, "no-action"))
16795 action[0] = 0;
16796 else if (!strcmp ((char *) s, "natively-forward"))
16797 action[0] = 1;
16798 else if (!strcmp ((char *) s, "send-map-request"))
16799 action[0] = 2;
16800 else if (!strcmp ((char *) s, "drop"))
16801 action[0] = 3;
16802 else
16803 {
16804 clib_warning ("invalid action: '%s'", s);
16805 action[0] = 3;
16806 }
16807 }
16808 else
16809 return 0;
16810
16811 vec_free (s);
16812 return 1;
16813}
16814
16815/**
Filip Tehlar694396d2017-02-17 14:29:11 +010016816 * Add/del remote mapping to/from ONE control plane
Damjan Marion7cd468a2016-12-19 23:05:39 +010016817 *
16818 * @param vam vpp API test context
16819 * @return return code
16820 */
16821static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016822api_one_add_del_remote_mapping (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016823{
16824 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016825 vl_api_one_add_del_remote_mapping_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016826 u32 vni = 0;
16827 lisp_eid_vat_t _eid, *eid = &_eid;
16828 lisp_eid_vat_t _seid, *seid = &_seid;
16829 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
16830 u32 action = ~0, p, w, data_len;
16831 ip4_address_t rloc4;
16832 ip6_address_t rloc6;
Filip Tehlar05a057b2017-02-01 08:50:31 +010016833 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016834 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016835
Dave Barachb7b92992018-10-17 10:38:51 -040016836 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010016837
16838 /* Parse args required to build the message */
16839 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16840 {
16841 if (unformat (input, "del-all"))
16842 {
16843 del_all = 1;
16844 }
16845 else if (unformat (input, "del"))
16846 {
16847 is_add = 0;
16848 }
16849 else if (unformat (input, "add"))
16850 {
16851 is_add = 1;
16852 }
16853 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
16854 {
16855 eid_set = 1;
16856 }
16857 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
16858 {
16859 seid_set = 1;
16860 }
16861 else if (unformat (input, "vni %d", &vni))
16862 {
16863 ;
16864 }
16865 else if (unformat (input, "p %d w %d", &p, &w))
16866 {
16867 if (!curr_rloc)
16868 {
16869 errmsg ("No RLOC configured for setting priority/weight!");
16870 return -99;
16871 }
16872 curr_rloc->priority = p;
16873 curr_rloc->weight = w;
16874 }
16875 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
16876 {
16877 rloc.is_ip4 = 1;
16878 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
16879 vec_add1 (rlocs, rloc);
16880 curr_rloc = &rlocs[vec_len (rlocs) - 1];
16881 }
16882 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
16883 {
16884 rloc.is_ip4 = 0;
16885 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
16886 vec_add1 (rlocs, rloc);
16887 curr_rloc = &rlocs[vec_len (rlocs) - 1];
16888 }
16889 else if (unformat (input, "action %U",
16890 unformat_negative_mapping_action, &action))
16891 {
16892 ;
16893 }
16894 else
16895 {
16896 clib_warning ("parse error '%U'", format_unformat_error, input);
16897 return -99;
16898 }
16899 }
16900
16901 if (0 == eid_set)
16902 {
16903 errmsg ("missing params!");
16904 return -99;
16905 }
16906
16907 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
16908 {
16909 errmsg ("no action set for negative map-reply!");
16910 return -99;
16911 }
16912
Filip Tehlar05a057b2017-02-01 08:50:31 +010016913 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016914
Filip Tehlar694396d2017-02-17 14:29:11 +010016915 M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016916 mp->is_add = is_add;
16917 mp->vni = htonl (vni);
16918 mp->action = (u8) action;
16919 mp->is_src_dst = seid_set;
16920 mp->eid_len = eid->len;
16921 mp->seid_len = seid->len;
16922 mp->del_all = del_all;
16923 mp->eid_type = eid->type;
16924 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
16925 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
16926
16927 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
16928 clib_memcpy (mp->rlocs, rlocs, data_len);
16929 vec_free (rlocs);
16930
16931 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016932 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016933
16934 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016935 W (ret);
16936 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016937}
16938
Filip Tehlar694396d2017-02-17 14:29:11 +010016939#define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
16940
Damjan Marion7cd468a2016-12-19 23:05:39 +010016941/**
Filip Tehlar694396d2017-02-17 14:29:11 +010016942 * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010016943 * forwarding entries in data-plane accordingly.
16944 *
16945 * @param vam vpp API test context
16946 * @return return code
16947 */
16948static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016949api_one_add_del_adjacency (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016950{
16951 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016952 vl_api_one_add_del_adjacency_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016953 u32 vni = 0;
16954 ip4_address_t leid4, reid4;
16955 ip6_address_t leid6, reid6;
16956 u8 reid_mac[6] = { 0 };
16957 u8 leid_mac[6] = { 0 };
16958 u8 reid_type, leid_type;
16959 u32 leid_len = 0, reid_len = 0, len;
16960 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016961 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016962
16963 leid_type = reid_type = (u8) ~ 0;
16964
16965 /* Parse args required to build the message */
16966 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16967 {
16968 if (unformat (input, "del"))
16969 {
16970 is_add = 0;
16971 }
16972 else if (unformat (input, "add"))
16973 {
16974 is_add = 1;
16975 }
16976 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
16977 &reid4, &len))
16978 {
16979 reid_type = 0; /* ipv4 */
16980 reid_len = len;
16981 }
16982 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
16983 &reid6, &len))
16984 {
16985 reid_type = 1; /* ipv6 */
16986 reid_len = len;
16987 }
16988 else if (unformat (input, "reid %U", unformat_ethernet_address,
16989 reid_mac))
16990 {
16991 reid_type = 2; /* mac */
16992 }
16993 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
16994 &leid4, &len))
16995 {
16996 leid_type = 0; /* ipv4 */
16997 leid_len = len;
16998 }
16999 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
17000 &leid6, &len))
17001 {
17002 leid_type = 1; /* ipv6 */
17003 leid_len = len;
17004 }
17005 else if (unformat (input, "leid %U", unformat_ethernet_address,
17006 leid_mac))
17007 {
17008 leid_type = 2; /* mac */
17009 }
17010 else if (unformat (input, "vni %d", &vni))
17011 {
17012 ;
17013 }
17014 else
17015 {
17016 errmsg ("parse error '%U'", format_unformat_error, input);
17017 return -99;
17018 }
17019 }
17020
17021 if ((u8) ~ 0 == reid_type)
17022 {
17023 errmsg ("missing params!");
17024 return -99;
17025 }
17026
17027 if (leid_type != reid_type)
17028 {
17029 errmsg ("remote and local EIDs are of different types!");
17030 return -99;
17031 }
17032
Filip Tehlar694396d2017-02-17 14:29:11 +010017033 M (ONE_ADD_DEL_ADJACENCY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017034 mp->is_add = is_add;
17035 mp->vni = htonl (vni);
17036 mp->leid_len = leid_len;
17037 mp->reid_len = reid_len;
17038 mp->eid_type = reid_type;
17039
17040 switch (mp->eid_type)
17041 {
17042 case 0:
17043 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
17044 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
17045 break;
17046 case 1:
17047 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
17048 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
17049 break;
17050 case 2:
17051 clib_memcpy (mp->leid, leid_mac, 6);
17052 clib_memcpy (mp->reid, reid_mac, 6);
17053 break;
17054 default:
17055 errmsg ("unknown EID type %d!", mp->eid_type);
17056 return 0;
17057 }
17058
17059 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017060 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017061
17062 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017063 W (ret);
17064 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017065}
17066
Filip Tehlar694396d2017-02-17 14:29:11 +010017067#define api_lisp_add_del_adjacency api_one_add_del_adjacency
17068
Filip Tehlar3e7b56932017-02-21 18:28:34 +010017069uword
17070unformat_gpe_encap_mode (unformat_input_t * input, va_list * args)
17071{
17072 u32 *mode = va_arg (*args, u32 *);
17073
17074 if (unformat (input, "lisp"))
17075 *mode = 0;
17076 else if (unformat (input, "vxlan"))
17077 *mode = 1;
17078 else
17079 return 0;
17080
17081 return 1;
17082}
17083
17084static int
17085api_gpe_get_encap_mode (vat_main_t * vam)
17086{
17087 vl_api_gpe_get_encap_mode_t *mp;
17088 int ret;
17089
17090 /* Construct the API message */
17091 M (GPE_GET_ENCAP_MODE, mp);
17092
17093 /* send it... */
17094 S (mp);
17095
17096 /* Wait for a reply... */
17097 W (ret);
17098 return ret;
17099}
17100
17101static int
17102api_gpe_set_encap_mode (vat_main_t * vam)
17103{
17104 unformat_input_t *input = vam->input;
17105 vl_api_gpe_set_encap_mode_t *mp;
17106 int ret;
17107 u32 mode = 0;
17108
17109 /* Parse args required to build the message */
17110 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17111 {
17112 if (unformat (input, "%U", unformat_gpe_encap_mode, &mode))
17113 ;
17114 else
17115 break;
17116 }
17117
17118 /* Construct the API message */
17119 M (GPE_SET_ENCAP_MODE, mp);
17120
17121 mp->mode = mode;
17122
17123 /* send it... */
17124 S (mp);
17125
17126 /* Wait for a reply... */
17127 W (ret);
17128 return ret;
17129}
17130
Damjan Marion7cd468a2016-12-19 23:05:39 +010017131static int
17132api_lisp_gpe_add_del_iface (vat_main_t * vam)
17133{
17134 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010017135 vl_api_gpe_add_del_iface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017136 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
17137 u32 dp_table = 0, vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017138 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017139
17140 /* Parse args required to build the message */
17141 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17142 {
17143 if (unformat (input, "up"))
17144 {
17145 action_set = 1;
17146 is_add = 1;
17147 }
17148 else if (unformat (input, "down"))
17149 {
17150 action_set = 1;
17151 is_add = 0;
17152 }
17153 else if (unformat (input, "table_id %d", &dp_table))
17154 {
17155 dp_table_set = 1;
17156 }
17157 else if (unformat (input, "bd_id %d", &dp_table))
17158 {
17159 dp_table_set = 1;
17160 is_l2 = 1;
17161 }
17162 else if (unformat (input, "vni %d", &vni))
17163 {
17164 vni_set = 1;
17165 }
17166 else
17167 break;
17168 }
17169
17170 if (action_set == 0)
17171 {
17172 errmsg ("Action not set");
17173 return -99;
17174 }
17175 if (dp_table_set == 0 || vni_set == 0)
17176 {
17177 errmsg ("vni and dp_table must be set");
17178 return -99;
17179 }
17180
17181 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010017182 M (GPE_ADD_DEL_IFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017183
17184 mp->is_add = is_add;
Florin Corasf53a8ad2017-06-15 15:07:32 -070017185 mp->dp_table = clib_host_to_net_u32 (dp_table);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017186 mp->is_l2 = is_l2;
Florin Corasf53a8ad2017-06-15 15:07:32 -070017187 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017188
17189 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017190 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017191
17192 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017193 W (ret);
17194 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017195}
17196
Filip Tehlar1e553a02017-08-02 12:45:07 +020017197static int
Filip Tehlar7048ff12017-07-27 08:09:14 +020017198api_one_map_register_fallback_threshold (vat_main_t * vam)
17199{
17200 unformat_input_t *input = vam->input;
17201 vl_api_one_map_register_fallback_threshold_t *mp;
17202 u32 value = 0;
17203 u8 is_set = 0;
17204 int ret;
17205
17206 /* Parse args required to build the message */
17207 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17208 {
17209 if (unformat (input, "%u", &value))
17210 is_set = 1;
17211 else
17212 {
17213 clib_warning ("parse error '%U'", format_unformat_error, input);
17214 return -99;
17215 }
17216 }
17217
17218 if (!is_set)
17219 {
17220 errmsg ("fallback threshold value is missing!");
17221 return -99;
17222 }
17223
17224 M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
17225 mp->value = clib_host_to_net_u32 (value);
17226
17227 /* send it... */
17228 S (mp);
17229
17230 /* Wait for a reply... */
17231 W (ret);
17232 return ret;
17233}
17234
17235static int
17236api_show_one_map_register_fallback_threshold (vat_main_t * vam)
17237{
17238 vl_api_show_one_map_register_fallback_threshold_t *mp;
17239 int ret;
17240
17241 M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
17242
17243 /* send it... */
17244 S (mp);
17245
17246 /* Wait for a reply... */
17247 W (ret);
17248 return ret;
17249}
17250
Filip Tehlara4980b82017-09-27 14:32:02 +020017251uword
17252unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args)
17253{
17254 u32 *proto = va_arg (*args, u32 *);
17255
17256 if (unformat (input, "udp"))
17257 *proto = 1;
17258 else if (unformat (input, "api"))
17259 *proto = 2;
17260 else
17261 return 0;
17262
17263 return 1;
17264}
17265
17266static int
17267api_one_set_transport_protocol (vat_main_t * vam)
17268{
17269 unformat_input_t *input = vam->input;
17270 vl_api_one_set_transport_protocol_t *mp;
17271 u8 is_set = 0;
17272 u32 protocol = 0;
17273 int ret;
17274
17275 /* Parse args required to build the message */
17276 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17277 {
17278 if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol))
17279 is_set = 1;
17280 else
17281 {
17282 clib_warning ("parse error '%U'", format_unformat_error, input);
17283 return -99;
17284 }
17285 }
17286
17287 if (!is_set)
17288 {
17289 errmsg ("Transport protocol missing!");
17290 return -99;
17291 }
17292
17293 M (ONE_SET_TRANSPORT_PROTOCOL, mp);
17294 mp->protocol = (u8) protocol;
17295
17296 /* send it... */
17297 S (mp);
17298
17299 /* Wait for a reply... */
17300 W (ret);
17301 return ret;
17302}
17303
17304static int
17305api_one_get_transport_protocol (vat_main_t * vam)
17306{
17307 vl_api_one_get_transport_protocol_t *mp;
17308 int ret;
17309
17310 M (ONE_GET_TRANSPORT_PROTOCOL, mp);
17311
17312 /* send it... */
17313 S (mp);
17314
17315 /* Wait for a reply... */
17316 W (ret);
17317 return ret;
17318}
17319
Filip Tehlar7048ff12017-07-27 08:09:14 +020017320static int
Filip Tehlar1e553a02017-08-02 12:45:07 +020017321api_one_map_register_set_ttl (vat_main_t * vam)
17322{
17323 unformat_input_t *input = vam->input;
17324 vl_api_one_map_register_set_ttl_t *mp;
17325 u32 ttl = 0;
17326 u8 is_set = 0;
17327 int ret;
17328
17329 /* Parse args required to build the message */
17330 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17331 {
17332 if (unformat (input, "%u", &ttl))
17333 is_set = 1;
17334 else
17335 {
17336 clib_warning ("parse error '%U'", format_unformat_error, input);
17337 return -99;
17338 }
17339 }
17340
17341 if (!is_set)
17342 {
17343 errmsg ("TTL value missing!");
17344 return -99;
17345 }
17346
17347 M (ONE_MAP_REGISTER_SET_TTL, mp);
17348 mp->ttl = clib_host_to_net_u32 (ttl);
17349
17350 /* send it... */
17351 S (mp);
17352
17353 /* Wait for a reply... */
17354 W (ret);
17355 return ret;
17356}
17357
17358static int
17359api_show_one_map_register_ttl (vat_main_t * vam)
17360{
17361 vl_api_show_one_map_register_ttl_t *mp;
17362 int ret;
17363
17364 M (SHOW_ONE_MAP_REGISTER_TTL, mp);
17365
17366 /* send it... */
17367 S (mp);
17368
17369 /* Wait for a reply... */
17370 W (ret);
17371 return ret;
17372}
17373
Damjan Marion7cd468a2016-12-19 23:05:39 +010017374/**
Filip Tehlar694396d2017-02-17 14:29:11 +010017375 * Add/del map request itr rlocs from ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010017376 *
17377 * @param vam vpp API test context
17378 * @return return code
17379 */
17380static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017381api_one_add_del_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017382{
17383 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017384 vl_api_one_add_del_map_request_itr_rlocs_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017385 u8 *locator_set_name = 0;
17386 u8 locator_set_name_set = 0;
17387 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017388 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017389
17390 /* Parse args required to build the message */
17391 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17392 {
17393 if (unformat (input, "del"))
17394 {
17395 is_add = 0;
17396 }
17397 else if (unformat (input, "%_%v%_", &locator_set_name))
17398 {
17399 locator_set_name_set = 1;
17400 }
17401 else
17402 {
17403 clib_warning ("parse error '%U'", format_unformat_error, input);
17404 return -99;
17405 }
17406 }
17407
17408 if (is_add && !locator_set_name_set)
17409 {
17410 errmsg ("itr-rloc is not set!");
17411 return -99;
17412 }
17413
17414 if (is_add && vec_len (locator_set_name) > 64)
17415 {
17416 errmsg ("itr-rloc locator-set name too long");
17417 vec_free (locator_set_name);
17418 return -99;
17419 }
17420
Filip Tehlar694396d2017-02-17 14:29:11 +010017421 M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017422 mp->is_add = is_add;
17423 if (is_add)
17424 {
17425 clib_memcpy (mp->locator_set_name, locator_set_name,
17426 vec_len (locator_set_name));
17427 }
17428 else
17429 {
Dave Barachb7b92992018-10-17 10:38:51 -040017430 clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017431 }
17432 vec_free (locator_set_name);
17433
17434 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017435 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017436
17437 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017438 W (ret);
17439 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017440}
17441
Filip Tehlar694396d2017-02-17 14:29:11 +010017442#define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs
17443
Damjan Marion7cd468a2016-12-19 23:05:39 +010017444static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017445api_one_locator_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017446{
17447 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017448 vl_api_one_locator_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017449 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017450 u8 is_index_set = 0, is_name_set = 0;
17451 u8 *ls_name = 0;
17452 u32 ls_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017453 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017454
17455 /* Parse args required to build the message */
17456 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17457 {
17458 if (unformat (input, "ls_name %_%v%_", &ls_name))
17459 {
17460 is_name_set = 1;
17461 }
17462 else if (unformat (input, "ls_index %d", &ls_index))
17463 {
17464 is_index_set = 1;
17465 }
17466 else
17467 {
17468 errmsg ("parse error '%U'", format_unformat_error, input);
17469 return -99;
17470 }
17471 }
17472
17473 if (!is_index_set && !is_name_set)
17474 {
17475 errmsg ("error: expected one of index or name!");
17476 return -99;
17477 }
17478
17479 if (is_index_set && is_name_set)
17480 {
17481 errmsg ("error: only one param expected!");
17482 return -99;
17483 }
17484
17485 if (vec_len (ls_name) > 62)
17486 {
17487 errmsg ("error: locator set name too long!");
17488 return -99;
17489 }
17490
17491 if (!vam->json_output)
17492 {
17493 print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
17494 }
17495
Filip Tehlar694396d2017-02-17 14:29:11 +010017496 M (ONE_LOCATOR_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017497 mp->is_index_set = is_index_set;
17498
17499 if (is_index_set)
17500 mp->ls_index = clib_host_to_net_u32 (ls_index);
17501 else
17502 {
17503 vec_add1 (ls_name, 0);
17504 strncpy ((char *) mp->ls_name, (char *) ls_name,
17505 sizeof (mp->ls_name) - 1);
17506 }
17507
17508 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017509 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017510
17511 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017512 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017513 S (mp_ping);
17514
Damjan Marion7cd468a2016-12-19 23:05:39 +010017515 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017516 W (ret);
17517 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017518}
17519
Filip Tehlar694396d2017-02-17 14:29:11 +010017520#define api_lisp_locator_dump api_one_locator_dump
17521
Damjan Marion7cd468a2016-12-19 23:05:39 +010017522static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017523api_one_locator_set_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017524{
Filip Tehlar694396d2017-02-17 14:29:11 +010017525 vl_api_one_locator_set_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017526 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017527 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017528 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017529 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017530
17531 /* Parse args required to build the message */
17532 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17533 {
17534 if (unformat (input, "local"))
17535 {
17536 filter = 1;
17537 }
17538 else if (unformat (input, "remote"))
17539 {
17540 filter = 2;
17541 }
17542 else
17543 {
17544 errmsg ("parse error '%U'", format_unformat_error, input);
17545 return -99;
17546 }
17547 }
17548
17549 if (!vam->json_output)
17550 {
17551 print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
17552 }
17553
Filip Tehlar694396d2017-02-17 14:29:11 +010017554 M (ONE_LOCATOR_SET_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017555
17556 mp->filter = filter;
17557
17558 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017559 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017560
17561 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017562 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017563 S (mp_ping);
17564
Damjan Marion7cd468a2016-12-19 23:05:39 +010017565 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017566 W (ret);
17567 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017568}
17569
Filip Tehlar694396d2017-02-17 14:29:11 +010017570#define api_lisp_locator_set_dump api_one_locator_set_dump
17571
Damjan Marion7cd468a2016-12-19 23:05:39 +010017572static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017573api_one_eid_table_map_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017574{
17575 u8 is_l2 = 0;
17576 u8 mode_set = 0;
17577 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017578 vl_api_one_eid_table_map_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017579 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017580 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017581
17582 /* Parse args required to build the message */
17583 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17584 {
17585 if (unformat (input, "l2"))
17586 {
17587 is_l2 = 1;
17588 mode_set = 1;
17589 }
17590 else if (unformat (input, "l3"))
17591 {
17592 is_l2 = 0;
17593 mode_set = 1;
17594 }
17595 else
17596 {
17597 errmsg ("parse error '%U'", format_unformat_error, input);
17598 return -99;
17599 }
17600 }
17601
17602 if (!mode_set)
17603 {
17604 errmsg ("expected one of 'l2' or 'l3' parameter!");
17605 return -99;
17606 }
17607
17608 if (!vam->json_output)
17609 {
17610 print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
17611 }
17612
Filip Tehlar694396d2017-02-17 14:29:11 +010017613 M (ONE_EID_TABLE_MAP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017614 mp->is_l2 = is_l2;
17615
17616 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017617 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017618
17619 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017620 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017621 S (mp_ping);
17622
Damjan Marion7cd468a2016-12-19 23:05:39 +010017623 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017624 W (ret);
17625 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017626}
17627
Filip Tehlar694396d2017-02-17 14:29:11 +010017628#define api_lisp_eid_table_map_dump api_one_eid_table_map_dump
17629
Damjan Marion7cd468a2016-12-19 23:05:39 +010017630static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017631api_one_eid_table_vni_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017632{
Filip Tehlar694396d2017-02-17 14:29:11 +010017633 vl_api_one_eid_table_vni_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017634 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017635 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017636
17637 if (!vam->json_output)
17638 {
17639 print (vam->ofp, "VNI");
17640 }
17641
Filip Tehlar694396d2017-02-17 14:29:11 +010017642 M (ONE_EID_TABLE_VNI_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017643
17644 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017645 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017646
17647 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017648 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017649 S (mp_ping);
17650
Damjan Marion7cd468a2016-12-19 23:05:39 +010017651 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017652 W (ret);
17653 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017654}
17655
Filip Tehlar694396d2017-02-17 14:29:11 +010017656#define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump
17657
Damjan Marion7cd468a2016-12-19 23:05:39 +010017658static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017659api_one_eid_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017660{
17661 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017662 vl_api_one_eid_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017663 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017664 struct in_addr ip4;
17665 struct in6_addr ip6;
17666 u8 mac[6];
17667 u8 eid_type = ~0, eid_set = 0;
17668 u32 prefix_length = ~0, t, vni = 0;
17669 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017670 int ret;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017671 lisp_nsh_api_t nsh;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017672
17673 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17674 {
17675 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
17676 {
17677 eid_set = 1;
17678 eid_type = 0;
17679 prefix_length = t;
17680 }
17681 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
17682 {
17683 eid_set = 1;
17684 eid_type = 1;
17685 prefix_length = t;
17686 }
17687 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
17688 {
17689 eid_set = 1;
17690 eid_type = 2;
17691 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017692 else if (unformat (i, "eid %U", unformat_nsh_address, &nsh))
17693 {
17694 eid_set = 1;
17695 eid_type = 3;
17696 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010017697 else if (unformat (i, "vni %d", &t))
17698 {
17699 vni = t;
17700 }
17701 else if (unformat (i, "local"))
17702 {
17703 filter = 1;
17704 }
17705 else if (unformat (i, "remote"))
17706 {
17707 filter = 2;
17708 }
17709 else
17710 {
17711 errmsg ("parse error '%U'", format_unformat_error, i);
17712 return -99;
17713 }
17714 }
17715
17716 if (!vam->json_output)
17717 {
17718 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
17719 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
17720 }
17721
Filip Tehlar694396d2017-02-17 14:29:11 +010017722 M (ONE_EID_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017723
17724 mp->filter = filter;
17725 if (eid_set)
17726 {
17727 mp->eid_set = 1;
17728 mp->vni = htonl (vni);
17729 mp->eid_type = eid_type;
17730 switch (eid_type)
17731 {
17732 case 0:
17733 mp->prefix_length = prefix_length;
17734 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
17735 break;
17736 case 1:
17737 mp->prefix_length = prefix_length;
17738 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
17739 break;
17740 case 2:
17741 clib_memcpy (mp->eid, mac, sizeof (mac));
17742 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017743 case 3:
17744 clib_memcpy (mp->eid, &nsh, sizeof (nsh));
17745 break;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017746 default:
17747 errmsg ("unknown EID type %d!", eid_type);
17748 return -99;
17749 }
17750 }
17751
17752 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017753 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017754
17755 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017756 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017757 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017758
17759 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017760 W (ret);
17761 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017762}
17763
Filip Tehlar694396d2017-02-17 14:29:11 +010017764#define api_lisp_eid_table_dump api_one_eid_table_dump
17765
Damjan Marion7cd468a2016-12-19 23:05:39 +010017766static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017767api_lisp_gpe_fwd_entries_get (vat_main_t * vam)
17768{
17769 unformat_input_t *i = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010017770 vl_api_gpe_fwd_entries_get_t *mp;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017771 u8 vni_set = 0;
17772 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017773 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017774
17775 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17776 {
17777 if (unformat (i, "vni %d", &vni))
17778 {
17779 vni_set = 1;
17780 }
17781 else
17782 {
17783 errmsg ("parse error '%U'", format_unformat_error, i);
17784 return -99;
17785 }
17786 }
17787
17788 if (!vni_set)
17789 {
17790 errmsg ("vni not set!");
17791 return -99;
17792 }
17793
17794 if (!vam->json_output)
17795 {
17796 print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table",
17797 "leid", "reid");
17798 }
17799
Filip Tehlar82786c42017-02-20 15:20:37 +010017800 M (GPE_FWD_ENTRIES_GET, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017801 mp->vni = clib_host_to_net_u32 (vni);
17802
17803 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017804 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017805
17806 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017807 W (ret);
17808 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017809}
17810
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017811#define vl_api_gpe_native_fwd_rpaths_get_reply_t_endian vl_noop_handler
17812#define vl_api_gpe_native_fwd_rpaths_get_reply_t_print vl_noop_handler
Filip Tehlar0eb874e2017-05-18 14:23:32 +020017813#define vl_api_gpe_fwd_entry_vnis_get_reply_t_endian vl_noop_handler
17814#define vl_api_gpe_fwd_entry_vnis_get_reply_t_print vl_noop_handler
Filip Tehlar82786c42017-02-20 15:20:37 +010017815#define vl_api_gpe_fwd_entries_get_reply_t_endian vl_noop_handler
17816#define vl_api_gpe_fwd_entries_get_reply_t_print vl_noop_handler
17817#define vl_api_gpe_fwd_entry_path_details_t_endian vl_noop_handler
17818#define vl_api_gpe_fwd_entry_path_details_t_print vl_noop_handler
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017819
17820static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017821api_one_adjacencies_get (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017822{
17823 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017824 vl_api_one_adjacencies_get_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017825 u8 vni_set = 0;
17826 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017827 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017828
17829 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17830 {
17831 if (unformat (i, "vni %d", &vni))
17832 {
17833 vni_set = 1;
17834 }
17835 else
17836 {
17837 errmsg ("parse error '%U'", format_unformat_error, i);
17838 return -99;
17839 }
17840 }
17841
17842 if (!vni_set)
17843 {
17844 errmsg ("vni not set!");
17845 return -99;
17846 }
17847
17848 if (!vam->json_output)
17849 {
17850 print (vam->ofp, "%s %40s", "leid", "reid");
17851 }
17852
Filip Tehlar694396d2017-02-17 14:29:11 +010017853 M (ONE_ADJACENCIES_GET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017854 mp->vni = clib_host_to_net_u32 (vni);
17855
17856 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017857 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017858
17859 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017860 W (ret);
17861 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017862}
17863
Filip Tehlar694396d2017-02-17 14:29:11 +010017864#define api_lisp_adjacencies_get api_one_adjacencies_get
17865
Damjan Marion7cd468a2016-12-19 23:05:39 +010017866static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017867api_gpe_native_fwd_rpaths_get (vat_main_t * vam)
17868{
17869 unformat_input_t *i = vam->input;
17870 vl_api_gpe_native_fwd_rpaths_get_t *mp;
17871 int ret;
17872 u8 ip_family_set = 0, is_ip4 = 1;
17873
17874 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17875 {
17876 if (unformat (i, "ip4"))
17877 {
17878 ip_family_set = 1;
17879 is_ip4 = 1;
17880 }
17881 else if (unformat (i, "ip6"))
17882 {
17883 ip_family_set = 1;
17884 is_ip4 = 0;
17885 }
17886 else
17887 {
17888 errmsg ("parse error '%U'", format_unformat_error, i);
17889 return -99;
17890 }
17891 }
17892
17893 if (!ip_family_set)
17894 {
17895 errmsg ("ip family not set!");
17896 return -99;
17897 }
17898
17899 M (GPE_NATIVE_FWD_RPATHS_GET, mp);
17900 mp->is_ip4 = is_ip4;
17901
17902 /* send it... */
17903 S (mp);
17904
17905 /* Wait for a reply... */
17906 W (ret);
17907 return ret;
17908}
17909
17910static int
Filip Tehlar0eb874e2017-05-18 14:23:32 +020017911api_gpe_fwd_entry_vnis_get (vat_main_t * vam)
17912{
17913 vl_api_gpe_fwd_entry_vnis_get_t *mp;
17914 int ret;
17915
17916 if (!vam->json_output)
17917 {
17918 print (vam->ofp, "VNIs");
17919 }
17920
17921 M (GPE_FWD_ENTRY_VNIS_GET, mp);
17922
17923 /* send it... */
17924 S (mp);
17925
17926 /* Wait for a reply... */
17927 W (ret);
17928 return ret;
17929}
17930
17931static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017932api_gpe_add_del_native_fwd_rpath (vat_main_t * vam)
17933{
17934 unformat_input_t *i = vam->input;
17935 vl_api_gpe_add_del_native_fwd_rpath_t *mp;
17936 int ret = 0;
17937 u8 is_add = 1, ip_set = 0, is_ip4 = 1;
17938 struct in_addr ip4;
17939 struct in6_addr ip6;
17940 u32 table_id = 0, nh_sw_if_index = ~0;
17941
Dave Barachb7b92992018-10-17 10:38:51 -040017942 clib_memset (&ip4, 0, sizeof (ip4));
17943 clib_memset (&ip6, 0, sizeof (ip6));
Filip Tehlarb4243aa2017-06-14 14:39:42 +020017944
17945 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17946 {
17947 if (unformat (i, "del"))
17948 is_add = 0;
17949 else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4,
17950 api_unformat_sw_if_index, vam, &nh_sw_if_index))
17951 {
17952 ip_set = 1;
17953 is_ip4 = 1;
17954 }
17955 else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6,
17956 api_unformat_sw_if_index, vam, &nh_sw_if_index))
17957 {
17958 ip_set = 1;
17959 is_ip4 = 0;
17960 }
17961 else if (unformat (i, "via %U", unformat_ip4_address, &ip4))
17962 {
17963 ip_set = 1;
17964 is_ip4 = 1;
17965 nh_sw_if_index = ~0;
17966 }
17967 else if (unformat (i, "via %U", unformat_ip6_address, &ip6))
17968 {
17969 ip_set = 1;
17970 is_ip4 = 0;
17971 nh_sw_if_index = ~0;
17972 }
17973 else if (unformat (i, "table %d", &table_id))
17974 ;
17975 else
17976 {
17977 errmsg ("parse error '%U'", format_unformat_error, i);
17978 return -99;
17979 }
17980 }
17981
17982 if (!ip_set)
17983 {
17984 errmsg ("nh addr not set!");
17985 return -99;
17986 }
17987
17988 M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp);
17989 mp->is_add = is_add;
17990 mp->table_id = clib_host_to_net_u32 (table_id);
17991 mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index);
17992 mp->is_ip4 = is_ip4;
17993 if (is_ip4)
17994 clib_memcpy (mp->nh_addr, &ip4, sizeof (ip4));
17995 else
17996 clib_memcpy (mp->nh_addr, &ip6, sizeof (ip6));
17997
17998 /* send it... */
17999 S (mp);
18000
18001 /* Wait for a reply... */
18002 W (ret);
18003 return ret;
18004}
18005
18006static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018007api_one_map_server_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018008{
Filip Tehlar694396d2017-02-17 14:29:11 +010018009 vl_api_one_map_server_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018010 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018011 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018012
18013 if (!vam->json_output)
18014 {
18015 print (vam->ofp, "%=20s", "Map server");
18016 }
18017
Filip Tehlar694396d2017-02-17 14:29:11 +010018018 M (ONE_MAP_SERVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018019 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018020 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018021
18022 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018023 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018024 S (mp_ping);
18025
Damjan Marion7cd468a2016-12-19 23:05:39 +010018026 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018027 W (ret);
18028 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018029}
18030
Filip Tehlar694396d2017-02-17 14:29:11 +010018031#define api_lisp_map_server_dump api_one_map_server_dump
18032
Damjan Marion7cd468a2016-12-19 23:05:39 +010018033static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018034api_one_map_resolver_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018035{
Filip Tehlar694396d2017-02-17 14:29:11 +010018036 vl_api_one_map_resolver_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018037 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018038 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018039
18040 if (!vam->json_output)
18041 {
18042 print (vam->ofp, "%=20s", "Map resolver");
18043 }
18044
Filip Tehlar694396d2017-02-17 14:29:11 +010018045 M (ONE_MAP_RESOLVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018046 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018047 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018048
18049 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018050 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018051 S (mp_ping);
18052
Damjan Marion7cd468a2016-12-19 23:05:39 +010018053 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018054 W (ret);
18055 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018056}
18057
Filip Tehlar694396d2017-02-17 14:29:11 +010018058#define api_lisp_map_resolver_dump api_one_map_resolver_dump
18059
Damjan Marion7cd468a2016-12-19 23:05:39 +010018060static int
Filip Tehlar21511912017-04-07 10:41:42 +020018061api_one_stats_flush (vat_main_t * vam)
18062{
18063 vl_api_one_stats_flush_t *mp;
18064 int ret = 0;
18065
18066 M (ONE_STATS_FLUSH, mp);
18067 S (mp);
18068 W (ret);
18069 return ret;
18070}
18071
18072static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010018073api_one_stats_dump (vat_main_t * vam)
18074{
18075 vl_api_one_stats_dump_t *mp;
18076 vl_api_control_ping_t *mp_ping;
18077 int ret;
18078
18079 M (ONE_STATS_DUMP, mp);
18080 /* send it... */
18081 S (mp);
18082
18083 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018084 MPING (CONTROL_PING, mp_ping);
Filip Tehlar4868ff62017-03-09 16:48:39 +010018085 S (mp_ping);
18086
18087 /* Wait for a reply... */
18088 W (ret);
18089 return ret;
18090}
18091
18092static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018093api_show_one_status (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018094{
Filip Tehlar694396d2017-02-17 14:29:11 +010018095 vl_api_show_one_status_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018096 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018097
18098 if (!vam->json_output)
18099 {
Filip Tehlar694396d2017-02-17 14:29:11 +010018100 print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
Damjan Marion7cd468a2016-12-19 23:05:39 +010018101 }
18102
Filip Tehlar694396d2017-02-17 14:29:11 +010018103 M (SHOW_ONE_STATUS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018104 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018105 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018106 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018107 W (ret);
18108 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018109}
18110
Filip Tehlar694396d2017-02-17 14:29:11 +010018111#define api_show_lisp_status api_show_one_status
18112
Damjan Marion7cd468a2016-12-19 23:05:39 +010018113static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018114api_lisp_gpe_fwd_entry_path_dump (vat_main_t * vam)
18115{
Filip Tehlar82786c42017-02-20 15:20:37 +010018116 vl_api_gpe_fwd_entry_path_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018117 vl_api_control_ping_t *mp_ping;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018118 unformat_input_t *i = vam->input;
18119 u32 fwd_entry_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018120 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018121
18122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18123 {
18124 if (unformat (i, "index %d", &fwd_entry_index))
18125 ;
18126 else
18127 break;
18128 }
18129
18130 if (~0 == fwd_entry_index)
18131 {
18132 errmsg ("no index specified!");
18133 return -99;
18134 }
18135
18136 if (!vam->json_output)
18137 {
18138 print (vam->ofp, "first line");
18139 }
18140
Filip Tehlar82786c42017-02-20 15:20:37 +010018141 M (GPE_FWD_ENTRY_PATH_DUMP, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018142
18143 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018144 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018145 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018146 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018147 S (mp_ping);
18148
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018149 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018150 W (ret);
18151 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018152}
18153
18154static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018155api_one_get_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018156{
Filip Tehlar694396d2017-02-17 14:29:11 +010018157 vl_api_one_get_map_request_itr_rlocs_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018158 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018159
18160 if (!vam->json_output)
18161 {
18162 print (vam->ofp, "%=20s", "itr-rlocs:");
18163 }
18164
Filip Tehlar694396d2017-02-17 14:29:11 +010018165 M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018166 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018167 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018168 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018169 W (ret);
18170 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018171}
18172
Filip Tehlar694396d2017-02-17 14:29:11 +010018173#define api_lisp_get_map_request_itr_rlocs api_one_get_map_request_itr_rlocs
18174
Damjan Marion7cd468a2016-12-19 23:05:39 +010018175static int
18176api_af_packet_create (vat_main_t * vam)
18177{
18178 unformat_input_t *i = vam->input;
18179 vl_api_af_packet_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018180 u8 *host_if_name = 0;
18181 u8 hw_addr[6];
18182 u8 random_hw_addr = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018183 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018184
Dave Barachb7b92992018-10-17 10:38:51 -040018185 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018186
18187 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18188 {
18189 if (unformat (i, "name %s", &host_if_name))
18190 vec_add1 (host_if_name, 0);
18191 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
18192 random_hw_addr = 0;
18193 else
18194 break;
18195 }
18196
18197 if (!vec_len (host_if_name))
18198 {
18199 errmsg ("host-interface name must be specified");
18200 return -99;
18201 }
18202
18203 if (vec_len (host_if_name) > 64)
18204 {
18205 errmsg ("host-interface name too long");
18206 return -99;
18207 }
18208
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018209 M (AF_PACKET_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018210
18211 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
18212 clib_memcpy (mp->hw_addr, hw_addr, 6);
18213 mp->use_random_hw_addr = random_hw_addr;
18214 vec_free (host_if_name);
18215
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018216 S (mp);
Dave Baracha1a093d2017-03-02 13:13:23 -050018217
18218 /* *INDENT-OFF* */
18219 W2 (ret,
18220 ({
18221 if (ret == 0)
18222 fprintf (vam->ofp ? vam->ofp : stderr,
18223 " new sw_if_index = %d\n", vam->sw_if_index);
18224 }));
18225 /* *INDENT-ON* */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018226 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018227}
18228
18229static int
18230api_af_packet_delete (vat_main_t * vam)
18231{
18232 unformat_input_t *i = vam->input;
18233 vl_api_af_packet_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018234 u8 *host_if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018235 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018236
18237 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18238 {
18239 if (unformat (i, "name %s", &host_if_name))
18240 vec_add1 (host_if_name, 0);
18241 else
18242 break;
18243 }
18244
18245 if (!vec_len (host_if_name))
18246 {
18247 errmsg ("host-interface name must be specified");
18248 return -99;
18249 }
18250
18251 if (vec_len (host_if_name) > 64)
18252 {
18253 errmsg ("host-interface name too long");
18254 return -99;
18255 }
18256
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018257 M (AF_PACKET_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018258
18259 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
18260 vec_free (host_if_name);
18261
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018262 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018263 W (ret);
18264 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018265}
18266
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020018267static void vl_api_af_packet_details_t_handler
18268 (vl_api_af_packet_details_t * mp)
18269{
18270 vat_main_t *vam = &vat_main;
18271
18272 print (vam->ofp, "%-16s %d",
18273 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
18274}
18275
18276static void vl_api_af_packet_details_t_handler_json
18277 (vl_api_af_packet_details_t * mp)
18278{
18279 vat_main_t *vam = &vat_main;
18280 vat_json_node_t *node = NULL;
18281
18282 if (VAT_JSON_ARRAY != vam->json_tree.type)
18283 {
18284 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18285 vat_json_init_array (&vam->json_tree);
18286 }
18287 node = vat_json_array_add (&vam->json_tree);
18288
18289 vat_json_init_object (node);
18290 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
18291 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
18292}
18293
18294static int
18295api_af_packet_dump (vat_main_t * vam)
18296{
18297 vl_api_af_packet_dump_t *mp;
18298 vl_api_control_ping_t *mp_ping;
18299 int ret;
18300
18301 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
18302 /* Get list of tap interfaces */
18303 M (AF_PACKET_DUMP, mp);
18304 S (mp);
18305
18306 /* Use a control ping for synchronization */
18307 MPING (CONTROL_PING, mp_ping);
18308 S (mp_ping);
18309
18310 W (ret);
18311 return ret;
18312}
18313
Damjan Marion7cd468a2016-12-19 23:05:39 +010018314static int
18315api_policer_add_del (vat_main_t * vam)
18316{
18317 unformat_input_t *i = vam->input;
18318 vl_api_policer_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018319 u8 is_add = 1;
18320 u8 *name = 0;
18321 u32 cir = 0;
18322 u32 eir = 0;
18323 u64 cb = 0;
18324 u64 eb = 0;
18325 u8 rate_type = 0;
18326 u8 round_type = 0;
18327 u8 type = 0;
18328 u8 color_aware = 0;
18329 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018330 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018331
18332 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
18333 conform_action.dscp = 0;
18334 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
18335 exceed_action.dscp = 0;
18336 violate_action.action_type = SSE2_QOS_ACTION_DROP;
18337 violate_action.dscp = 0;
18338
18339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18340 {
18341 if (unformat (i, "del"))
18342 is_add = 0;
18343 else if (unformat (i, "name %s", &name))
18344 vec_add1 (name, 0);
18345 else if (unformat (i, "cir %u", &cir))
18346 ;
18347 else if (unformat (i, "eir %u", &eir))
18348 ;
18349 else if (unformat (i, "cb %u", &cb))
18350 ;
18351 else if (unformat (i, "eb %u", &eb))
18352 ;
18353 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
18354 &rate_type))
18355 ;
18356 else if (unformat (i, "round_type %U", unformat_policer_round_type,
18357 &round_type))
18358 ;
18359 else if (unformat (i, "type %U", unformat_policer_type, &type))
18360 ;
18361 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
18362 &conform_action))
18363 ;
18364 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
18365 &exceed_action))
18366 ;
18367 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
18368 &violate_action))
18369 ;
18370 else if (unformat (i, "color-aware"))
18371 color_aware = 1;
18372 else
18373 break;
18374 }
18375
18376 if (!vec_len (name))
18377 {
18378 errmsg ("policer name must be specified");
18379 return -99;
18380 }
18381
18382 if (vec_len (name) > 64)
18383 {
18384 errmsg ("policer name too long");
18385 return -99;
18386 }
18387
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018388 M (POLICER_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018389
18390 clib_memcpy (mp->name, name, vec_len (name));
18391 vec_free (name);
18392 mp->is_add = is_add;
Neale Rannsd91c1db2017-07-31 02:30:50 -070018393 mp->cir = ntohl (cir);
18394 mp->eir = ntohl (eir);
18395 mp->cb = clib_net_to_host_u64 (cb);
18396 mp->eb = clib_net_to_host_u64 (eb);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018397 mp->rate_type = rate_type;
18398 mp->round_type = round_type;
18399 mp->type = type;
18400 mp->conform_action_type = conform_action.action_type;
18401 mp->conform_dscp = conform_action.dscp;
18402 mp->exceed_action_type = exceed_action.action_type;
18403 mp->exceed_dscp = exceed_action.dscp;
18404 mp->violate_action_type = violate_action.action_type;
18405 mp->violate_dscp = violate_action.dscp;
18406 mp->color_aware = color_aware;
18407
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018408 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018409 W (ret);
18410 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018411}
18412
18413static int
18414api_policer_dump (vat_main_t * vam)
18415{
18416 unformat_input_t *i = vam->input;
18417 vl_api_policer_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018418 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018419 u8 *match_name = 0;
18420 u8 match_name_valid = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018421 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018422
18423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18424 {
18425 if (unformat (i, "name %s", &match_name))
18426 {
18427 vec_add1 (match_name, 0);
18428 match_name_valid = 1;
18429 }
18430 else
18431 break;
18432 }
18433
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018434 M (POLICER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018435 mp->match_name_valid = match_name_valid;
18436 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
18437 vec_free (match_name);
18438 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018439 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018440
18441 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018442 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018443 S (mp_ping);
18444
Damjan Marion7cd468a2016-12-19 23:05:39 +010018445 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018446 W (ret);
18447 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018448}
18449
18450static int
18451api_policer_classify_set_interface (vat_main_t * vam)
18452{
18453 unformat_input_t *i = vam->input;
18454 vl_api_policer_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018455 u32 sw_if_index;
18456 int sw_if_index_set;
18457 u32 ip4_table_index = ~0;
18458 u32 ip6_table_index = ~0;
18459 u32 l2_table_index = ~0;
18460 u8 is_add = 1;
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, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18466 sw_if_index_set = 1;
18467 else if (unformat (i, "sw_if_index %d", &sw_if_index))
18468 sw_if_index_set = 1;
18469 else if (unformat (i, "del"))
18470 is_add = 0;
18471 else if (unformat (i, "ip4-table %d", &ip4_table_index))
18472 ;
18473 else if (unformat (i, "ip6-table %d", &ip6_table_index))
18474 ;
18475 else if (unformat (i, "l2-table %d", &l2_table_index))
18476 ;
18477 else
18478 {
18479 clib_warning ("parse error '%U'", format_unformat_error, i);
18480 return -99;
18481 }
18482 }
18483
18484 if (sw_if_index_set == 0)
18485 {
18486 errmsg ("missing interface name or sw_if_index");
18487 return -99;
18488 }
18489
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018490 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018491
18492 mp->sw_if_index = ntohl (sw_if_index);
18493 mp->ip4_table_index = ntohl (ip4_table_index);
18494 mp->ip6_table_index = ntohl (ip6_table_index);
18495 mp->l2_table_index = ntohl (l2_table_index);
18496 mp->is_add = is_add;
18497
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018498 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018499 W (ret);
18500 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018501}
18502
18503static int
18504api_policer_classify_dump (vat_main_t * vam)
18505{
18506 unformat_input_t *i = vam->input;
18507 vl_api_policer_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018508 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018509 u8 type = POLICER_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018510 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018511
18512 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
18513 ;
18514 else
18515 {
18516 errmsg ("classify table type must be specified");
18517 return -99;
18518 }
18519
18520 if (!vam->json_output)
18521 {
18522 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
18523 }
18524
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018525 M (POLICER_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018526 mp->type = type;
18527 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018528 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018529
18530 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018531 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018532 S (mp_ping);
18533
Damjan Marion7cd468a2016-12-19 23:05:39 +010018534 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018535 W (ret);
18536 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018537}
18538
18539static int
18540api_netmap_create (vat_main_t * vam)
18541{
18542 unformat_input_t *i = vam->input;
18543 vl_api_netmap_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018544 u8 *if_name = 0;
18545 u8 hw_addr[6];
18546 u8 random_hw_addr = 1;
18547 u8 is_pipe = 0;
18548 u8 is_master = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018549 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018550
Dave Barachb7b92992018-10-17 10:38:51 -040018551 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018552
18553 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18554 {
18555 if (unformat (i, "name %s", &if_name))
18556 vec_add1 (if_name, 0);
18557 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
18558 random_hw_addr = 0;
18559 else if (unformat (i, "pipe"))
18560 is_pipe = 1;
18561 else if (unformat (i, "master"))
18562 is_master = 1;
18563 else if (unformat (i, "slave"))
18564 is_master = 0;
18565 else
18566 break;
18567 }
18568
18569 if (!vec_len (if_name))
18570 {
18571 errmsg ("interface name must be specified");
18572 return -99;
18573 }
18574
18575 if (vec_len (if_name) > 64)
18576 {
18577 errmsg ("interface name too long");
18578 return -99;
18579 }
18580
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018581 M (NETMAP_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018582
18583 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
18584 clib_memcpy (mp->hw_addr, hw_addr, 6);
18585 mp->use_random_hw_addr = random_hw_addr;
18586 mp->is_pipe = is_pipe;
18587 mp->is_master = is_master;
18588 vec_free (if_name);
18589
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018590 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018591 W (ret);
18592 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018593}
18594
18595static int
18596api_netmap_delete (vat_main_t * vam)
18597{
18598 unformat_input_t *i = vam->input;
18599 vl_api_netmap_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018600 u8 *if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018601 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018602
18603 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18604 {
18605 if (unformat (i, "name %s", &if_name))
18606 vec_add1 (if_name, 0);
18607 else
18608 break;
18609 }
18610
18611 if (!vec_len (if_name))
18612 {
18613 errmsg ("interface name must be specified");
18614 return -99;
18615 }
18616
18617 if (vec_len (if_name) > 64)
18618 {
18619 errmsg ("interface name too long");
18620 return -99;
18621 }
18622
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018623 M (NETMAP_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018624
18625 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
18626 vec_free (if_name);
18627
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018628 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018629 W (ret);
18630 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018631}
18632
Neale Ranns097fa662018-05-01 05:17:55 -070018633static u8 *
18634format_fib_api_path_nh_proto (u8 * s, va_list * args)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018635{
Neale Ranns097fa662018-05-01 05:17:55 -070018636 vl_api_fib_path_nh_proto_t proto =
18637 va_arg (*args, vl_api_fib_path_nh_proto_t);
18638
18639 switch (proto)
18640 {
18641 case FIB_API_PATH_NH_PROTO_IP4:
18642 s = format (s, "ip4");
18643 break;
18644 case FIB_API_PATH_NH_PROTO_IP6:
18645 s = format (s, "ip6");
18646 break;
18647 case FIB_API_PATH_NH_PROTO_MPLS:
18648 s = format (s, "mpls");
18649 break;
18650 case FIB_API_PATH_NH_PROTO_BIER:
18651 s = format (s, "bier");
18652 break;
18653 case FIB_API_PATH_NH_PROTO_ETHERNET:
18654 s = format (s, "ethernet");
18655 break;
18656 }
18657
18658 return (s);
18659}
18660
18661static u8 *
18662format_vl_api_ip_address_union (u8 * s, va_list * args)
18663{
18664 vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
18665 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
18666
18667 switch (af)
18668 {
18669 case ADDRESS_IP4:
18670 s = format (s, "%U", format_ip4_address, u->ip4);
18671 break;
18672 case ADDRESS_IP6:
18673 s = format (s, "%U", format_ip6_address, u->ip6);
18674 break;
18675 }
18676 return (s);
18677}
18678
18679static u8 *
18680format_vl_api_fib_path_type (u8 * s, va_list * args)
18681{
18682 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
18683
18684 switch (t)
18685 {
18686 case FIB_API_PATH_TYPE_NORMAL:
18687 s = format (s, "normal");
18688 break;
18689 case FIB_API_PATH_TYPE_LOCAL:
18690 s = format (s, "local");
18691 break;
18692 case FIB_API_PATH_TYPE_DROP:
18693 s = format (s, "drop");
18694 break;
18695 case FIB_API_PATH_TYPE_UDP_ENCAP:
18696 s = format (s, "udp-encap");
18697 break;
18698 case FIB_API_PATH_TYPE_BIER_IMP:
18699 s = format (s, "bier-imp");
18700 break;
18701 case FIB_API_PATH_TYPE_ICMP_UNREACH:
18702 s = format (s, "unreach");
18703 break;
18704 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
18705 s = format (s, "prohibit");
18706 break;
18707 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
18708 s = format (s, "src-lookup");
18709 break;
18710 case FIB_API_PATH_TYPE_DVR:
18711 s = format (s, "dvr");
18712 break;
18713 case FIB_API_PATH_TYPE_INTERFACE_RX:
18714 s = format (s, "interface-rx");
18715 break;
18716 case FIB_API_PATH_TYPE_CLASSIFY:
18717 s = format (s, "classify");
18718 break;
18719 }
18720
18721 return (s);
18722}
18723
18724static void
18725vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
18726{
18727 print (vam->ofp,
18728 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
18729 ntohl (fp->weight), ntohl (fp->sw_if_index),
18730 format_vl_api_fib_path_type, fp->type,
18731 format_fib_api_path_nh_proto, fp->proto,
18732 format_vl_api_ip_address_union, &fp->nh.address);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018733}
18734
18735static void
18736vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
Neale Ranns31ed7442018-02-23 05:29:09 -080018737 vl_api_fib_path_t * fp)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018738{
18739 struct in_addr ip4;
18740 struct in6_addr ip6;
18741
18742 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
18743 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
Neale Ranns097fa662018-05-01 05:17:55 -070018744 vat_json_object_add_uint (node, "type", fp->type);
18745 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
18746 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018747 {
Neale Ranns097fa662018-05-01 05:17:55 -070018748 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018749 vat_json_object_add_ip4 (node, "next_hop", ip4);
18750 }
Neale Ranns097fa662018-05-01 05:17:55 -070018751 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018752 {
Neale Ranns097fa662018-05-01 05:17:55 -070018753 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018754 vat_json_object_add_ip6 (node, "next_hop", ip6);
18755 }
18756}
18757
18758static void
18759vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018760{
18761 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070018762 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080018763 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018764 i32 i;
18765
Neale Ranns097fa662018-05-01 05:17:55 -070018766 print (vam->ofp, "sw_if_index %d via:",
18767 ntohl (mp->mt_tunnel.mt_sw_if_index));
18768 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018769 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018770 {
Neale Ranns097fa662018-05-01 05:17:55 -070018771 vl_api_fib_path_print (vam, fp);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018772 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018773 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018774
Damjan Marion7cd468a2016-12-19 23:05:39 +010018775 print (vam->ofp, "");
18776}
18777
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018778#define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
18779#define vl_api_mpls_tunnel_details_t_print vl_noop_handler
18780
18781static void
18782vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018783{
18784 vat_main_t *vam = &vat_main;
18785 vat_json_node_t *node = NULL;
Neale Ranns097fa662018-05-01 05:17:55 -070018786 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080018787 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018788 i32 i;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018789
18790 if (VAT_JSON_ARRAY != vam->json_tree.type)
18791 {
18792 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18793 vat_json_init_array (&vam->json_tree);
18794 }
18795 node = vat_json_array_add (&vam->json_tree);
18796
18797 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070018798 vat_json_object_add_uint (node, "sw_if_index",
18799 ntohl (mp->mt_tunnel.mt_sw_if_index));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018800
Neale Ranns097fa662018-05-01 05:17:55 -070018801 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018802
Neale Ranns097fa662018-05-01 05:17:55 -070018803 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018804 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018805 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018806 vl_api_mpls_fib_path_json_print (node, fp);
18807 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018808 }
18809}
18810
18811static int
18812api_mpls_tunnel_dump (vat_main_t * vam)
18813{
18814 vl_api_mpls_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018815 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018816 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018817
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018818 M (MPLS_TUNNEL_DUMP, mp);
Neale Ranns097fa662018-05-01 05:17:55 -070018819
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018820 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018821
18822 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018823 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018824 S (mp_ping);
18825
Jon Loeliger56c7b012017-02-01 12:31:41 -060018826 W (ret);
18827 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018828}
18829
Neale Ranns097fa662018-05-01 05:17:55 -070018830#define vl_api_mpls_table_details_t_endian vl_noop_handler
18831#define vl_api_mpls_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010018832
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018833
Damjan Marion7cd468a2016-12-19 23:05:39 +010018834static void
Neale Ranns097fa662018-05-01 05:17:55 -070018835vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018836{
18837 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070018838
18839 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
18840}
18841
18842static void vl_api_mpls_table_details_t_handler_json
18843 (vl_api_mpls_table_details_t * mp)
18844{
18845 vat_main_t *vam = &vat_main;
18846 vat_json_node_t *node = NULL;
18847
18848 if (VAT_JSON_ARRAY != vam->json_tree.type)
18849 {
18850 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18851 vat_json_init_array (&vam->json_tree);
18852 }
18853 node = vat_json_array_add (&vam->json_tree);
18854
18855 vat_json_init_object (node);
18856 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
18857}
18858
18859static int
18860api_mpls_table_dump (vat_main_t * vam)
18861{
18862 vl_api_mpls_table_dump_t *mp;
18863 vl_api_control_ping_t *mp_ping;
18864 int ret;
18865
18866 M (MPLS_TABLE_DUMP, mp);
18867 S (mp);
18868
18869 /* Use a control ping for synchronization */
18870 MPING (CONTROL_PING, mp_ping);
18871 S (mp_ping);
18872
18873 W (ret);
18874 return ret;
18875}
18876
18877#define vl_api_mpls_route_details_t_endian vl_noop_handler
18878#define vl_api_mpls_route_details_t_print vl_noop_handler
18879
18880static void
18881vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
18882{
18883 vat_main_t *vam = &vat_main;
Dave Barach4bda2d92019-07-03 15:21:50 -040018884 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080018885 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018886 int i;
18887
18888 print (vam->ofp,
18889 "table-id %d, label %u, ess_bit %u",
Neale Ranns097fa662018-05-01 05:17:55 -070018890 ntohl (mp->mr_route.mr_table_id),
18891 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
18892 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018893 for (i = 0; i < count; i++)
18894 {
Neale Ranns097fa662018-05-01 05:17:55 -070018895 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018896 fp++;
18897 }
18898}
18899
Neale Ranns097fa662018-05-01 05:17:55 -070018900static void vl_api_mpls_route_details_t_handler_json
18901 (vl_api_mpls_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018902{
18903 vat_main_t *vam = &vat_main;
Dave Barach4bda2d92019-07-03 15:21:50 -040018904 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018905 vat_json_node_t *node = NULL;
Neale Ranns31ed7442018-02-23 05:29:09 -080018906 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018907 int i;
18908
18909 if (VAT_JSON_ARRAY != vam->json_tree.type)
18910 {
18911 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18912 vat_json_init_array (&vam->json_tree);
18913 }
18914 node = vat_json_array_add (&vam->json_tree);
18915
18916 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070018917 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
18918 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
18919 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018920 vat_json_object_add_uint (node, "path_count", count);
Neale Ranns097fa662018-05-01 05:17:55 -070018921 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018922 for (i = 0; i < count; i++)
18923 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018924 vl_api_mpls_fib_path_json_print (node, fp);
18925 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018926 }
18927}
18928
18929static int
Neale Ranns097fa662018-05-01 05:17:55 -070018930api_mpls_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018931{
Neale Ranns097fa662018-05-01 05:17:55 -070018932 unformat_input_t *input = vam->input;
18933 vl_api_mpls_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018934 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070018935 u32 table_id;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018936 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018937
Neale Ranns097fa662018-05-01 05:17:55 -070018938 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18939 {
18940 if (unformat (input, "table_id %d", &table_id))
18941 ;
18942 else
18943 break;
18944 }
18945 if (table_id == ~0)
18946 {
18947 errmsg ("missing table id");
18948 return -99;
18949 }
18950
18951 M (MPLS_ROUTE_DUMP, mp);
18952
18953 mp->table.mt_table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018954 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018955
18956 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018957 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018958 S (mp_ping);
18959
Jon Loeliger56c7b012017-02-01 12:31:41 -060018960 W (ret);
18961 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018962}
18963
Neale Ranns097fa662018-05-01 05:17:55 -070018964#define vl_api_ip_table_details_t_endian vl_noop_handler
18965#define vl_api_ip_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010018966
18967static void
Neale Ranns097fa662018-05-01 05:17:55 -070018968vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018969{
18970 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018971
18972 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070018973 "%s; table-id %d, prefix %U/%d",
18974 mp->table.name, ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018975}
18976
Neale Ranns097fa662018-05-01 05:17:55 -070018977
18978static void vl_api_ip_table_details_t_handler_json
18979 (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018980{
18981 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018982 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018983
18984 if (VAT_JSON_ARRAY != vam->json_tree.type)
18985 {
18986 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18987 vat_json_init_array (&vam->json_tree);
18988 }
18989 node = vat_json_array_add (&vam->json_tree);
18990
18991 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070018992 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018993}
18994
18995static int
Neale Ranns097fa662018-05-01 05:17:55 -070018996api_ip_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018997{
Neale Ranns097fa662018-05-01 05:17:55 -070018998 vl_api_ip_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018999 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019000 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019001
Neale Ranns097fa662018-05-01 05:17:55 -070019002 M (IP_TABLE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019003 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019004
19005 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019006 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019007 S (mp_ping);
19008
Jon Loeliger56c7b012017-02-01 12:31:41 -060019009 W (ret);
19010 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019011}
19012
Neale Ranns5a8123b2017-01-26 01:18:23 -080019013static int
Neale Ranns097fa662018-05-01 05:17:55 -070019014api_ip_mtable_dump (vat_main_t * vam)
Neale Ranns5a8123b2017-01-26 01:18:23 -080019015{
Neale Ranns097fa662018-05-01 05:17:55 -070019016 vl_api_ip_mtable_dump_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -080019017 vl_api_control_ping_t *mp_ping;
19018 int ret;
19019
Neale Ranns097fa662018-05-01 05:17:55 -070019020 M (IP_MTABLE_DUMP, mp);
19021 S (mp);
19022
19023 /* Use a control ping for synchronization */
19024 MPING (CONTROL_PING, mp_ping);
19025 S (mp_ping);
19026
19027 W (ret);
19028 return ret;
19029}
19030
19031static int
19032api_ip_mroute_dump (vat_main_t * vam)
19033{
19034 unformat_input_t *input = vam->input;
19035 vl_api_control_ping_t *mp_ping;
19036 vl_api_ip_mroute_dump_t *mp;
19037 int ret, is_ip6;
19038 u32 table_id;
19039
19040 is_ip6 = 0;
19041 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19042 {
19043 if (unformat (input, "table_id %d", &table_id))
19044 ;
19045 else if (unformat (input, "ip6"))
19046 is_ip6 = 1;
19047 else if (unformat (input, "ip4"))
19048 is_ip6 = 0;
19049 else
19050 break;
19051 }
19052 if (table_id == ~0)
19053 {
19054 errmsg ("missing table id");
19055 return -99;
19056 }
19057
19058 M (IP_MROUTE_DUMP, mp);
19059 mp->table.table_id = table_id;
19060 mp->table.is_ip6 = is_ip6;
Neale Ranns5a8123b2017-01-26 01:18:23 -080019061 S (mp);
19062
19063 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019064 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080019065 S (mp_ping);
19066
19067 W (ret);
19068 return ret;
19069}
19070
Damjan Marion7cd468a2016-12-19 23:05:39 +010019071static void vl_api_ip_neighbor_details_t_handler
19072 (vl_api_ip_neighbor_details_t * mp)
19073{
19074 vat_main_t *vam = &vat_main;
19075
19076 print (vam->ofp, "%c %U %U",
Neale Ranns37029302018-08-10 05:30:06 -070019077 (ntohl (mp->neighbor.flags) & IP_NEIGHBOR_FLAG_STATIC) ? 'S' : 'D',
19078 format_vl_api_mac_address, &mp->neighbor.mac_address,
19079 format_vl_api_address, &mp->neighbor.ip_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019080}
19081
19082static void vl_api_ip_neighbor_details_t_handler_json
19083 (vl_api_ip_neighbor_details_t * mp)
19084{
19085
19086 vat_main_t *vam = &vat_main;
19087 vat_json_node_t *node;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019088
19089 if (VAT_JSON_ARRAY != vam->json_tree.type)
19090 {
19091 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19092 vat_json_init_array (&vam->json_tree);
19093 }
19094 node = vat_json_array_add (&vam->json_tree);
19095
19096 vat_json_init_object (node);
Neale Ranns37029302018-08-10 05:30:06 -070019097 vat_json_object_add_string_copy
19098 (node, "flag",
19099 ((ntohl (mp->neighbor.flags) & IP_NEIGHBOR_FLAG_STATIC) ?
19100 (u8 *) "static" : (u8 *) "dynamic"));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019101
19102 vat_json_object_add_string_copy (node, "link_layer",
Neale Ranns37029302018-08-10 05:30:06 -070019103 format (0, "%U", format_vl_api_mac_address,
19104 &mp->neighbor.mac_address));
Neale Ranns5a8844b2019-04-16 07:15:35 +000019105 vat_json_object_add_address (node, "ip", &mp->neighbor.ip_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019106}
19107
19108static int
19109api_ip_neighbor_dump (vat_main_t * vam)
19110{
19111 unformat_input_t *i = vam->input;
19112 vl_api_ip_neighbor_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019113 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019114 u8 is_ipv6 = 0;
19115 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019116 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019117
19118 /* Parse args required to build the message */
19119 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19120 {
19121 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19122 ;
19123 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19124 ;
19125 else if (unformat (i, "ip6"))
19126 is_ipv6 = 1;
19127 else
19128 break;
19129 }
19130
19131 if (sw_if_index == ~0)
19132 {
19133 errmsg ("missing interface name or sw_if_index");
19134 return -99;
19135 }
19136
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019137 M (IP_NEIGHBOR_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019138 mp->is_ipv6 = (u8) is_ipv6;
19139 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019140 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019141
19142 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019143 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019144 S (mp_ping);
19145
Jon Loeliger56c7b012017-02-01 12:31:41 -060019146 W (ret);
19147 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019148}
19149
Neale Ranns097fa662018-05-01 05:17:55 -070019150#define vl_api_ip_route_details_t_endian vl_noop_handler
19151#define vl_api_ip_route_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010019152
19153static void
Neale Ranns097fa662018-05-01 05:17:55 -070019154vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019155{
19156 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070019157 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019158 vl_api_fib_path_t *fp;
19159 int i;
19160
19161 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070019162 "table-id %d, prefix %U/%d",
19163 ntohl (mp->route.table_id),
Paul Vinciguerraab055082019-06-06 14:07:55 -040019164 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019165 for (i = 0; i < count; i++)
19166 {
Neale Ranns097fa662018-05-01 05:17:55 -070019167 fp = &mp->route.paths[i];
19168
19169 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019170 fp++;
19171 }
19172}
19173
Neale Ranns097fa662018-05-01 05:17:55 -070019174static void vl_api_ip_route_details_t_handler_json
19175 (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019176{
19177 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070019178 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019179 vat_json_node_t *node = NULL;
19180 struct in_addr ip4;
19181 struct in6_addr ip6;
19182 vl_api_fib_path_t *fp;
19183 int i;
19184
19185 if (VAT_JSON_ARRAY != vam->json_tree.type)
19186 {
19187 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19188 vat_json_init_array (&vam->json_tree);
19189 }
19190 node = vat_json_array_add (&vam->json_tree);
19191
19192 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070019193 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
19194 if (ADDRESS_IP6 == mp->route.prefix.address.af)
19195 {
19196 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
19197 vat_json_object_add_ip6 (node, "prefix", ip6);
19198 }
19199 else
19200 {
19201 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
19202 vat_json_object_add_ip4 (node, "prefix", ip4);
19203 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040019204 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019205 vat_json_object_add_uint (node, "path_count", count);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019206 for (i = 0; i < count; i++)
19207 {
Neale Ranns097fa662018-05-01 05:17:55 -070019208 fp = &mp->route.paths[i];
19209 vl_api_mpls_fib_path_json_print (node, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019210 }
19211}
19212
19213static int
Neale Ranns097fa662018-05-01 05:17:55 -070019214api_ip_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019215{
Neale Ranns097fa662018-05-01 05:17:55 -070019216 unformat_input_t *input = vam->input;
19217 vl_api_ip_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019218 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070019219 u32 table_id;
19220 u8 is_ip6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019221 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019222
Neale Ranns097fa662018-05-01 05:17:55 -070019223 is_ip6 = 0;
19224 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19225 {
19226 if (unformat (input, "table_id %d", &table_id))
19227 ;
19228 else if (unformat (input, "ip6"))
19229 is_ip6 = 1;
19230 else if (unformat (input, "ip4"))
19231 is_ip6 = 0;
19232 else
19233 break;
19234 }
19235 if (table_id == ~0)
19236 {
19237 errmsg ("missing table id");
19238 return -99;
19239 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010019240
Neale Ranns097fa662018-05-01 05:17:55 -070019241 M (IP_ROUTE_DUMP, mp);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019242
Neale Ranns097fa662018-05-01 05:17:55 -070019243 mp->table.table_id = table_id;
19244 mp->table.is_ip6 = is_ip6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019245
Neale Ranns5a8123b2017-01-26 01:18:23 -080019246 S (mp);
19247
19248 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019249 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080019250 S (mp_ping);
19251
19252 W (ret);
19253 return ret;
19254}
19255
Damjan Marion7cd468a2016-12-19 23:05:39 +010019256int
19257api_classify_table_ids (vat_main_t * vam)
19258{
19259 vl_api_classify_table_ids_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019260 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019261
19262 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019263 M (CLASSIFY_TABLE_IDS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019264 mp->context = 0;
19265
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019266 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019267 W (ret);
19268 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019269}
19270
19271int
19272api_classify_table_by_interface (vat_main_t * vam)
19273{
19274 unformat_input_t *input = vam->input;
19275 vl_api_classify_table_by_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019276
19277 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019278 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019279 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19280 {
19281 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19282 ;
19283 else if (unformat (input, "sw_if_index %d", &sw_if_index))
19284 ;
19285 else
19286 break;
19287 }
19288 if (sw_if_index == ~0)
19289 {
19290 errmsg ("missing interface name or sw_if_index");
19291 return -99;
19292 }
19293
19294 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019295 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019296 mp->context = 0;
19297 mp->sw_if_index = ntohl (sw_if_index);
19298
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019299 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019300 W (ret);
19301 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019302}
19303
19304int
19305api_classify_table_info (vat_main_t * vam)
19306{
19307 unformat_input_t *input = vam->input;
19308 vl_api_classify_table_info_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019309
19310 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019311 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019312 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19313 {
19314 if (unformat (input, "table_id %d", &table_id))
19315 ;
19316 else
19317 break;
19318 }
19319 if (table_id == ~0)
19320 {
19321 errmsg ("missing table id");
19322 return -99;
19323 }
19324
19325 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019326 M (CLASSIFY_TABLE_INFO, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019327 mp->context = 0;
19328 mp->table_id = ntohl (table_id);
19329
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019330 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019331 W (ret);
19332 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019333}
19334
19335int
19336api_classify_session_dump (vat_main_t * vam)
19337{
19338 unformat_input_t *input = vam->input;
19339 vl_api_classify_session_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019340 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019341
19342 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019343 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019344 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19345 {
19346 if (unformat (input, "table_id %d", &table_id))
19347 ;
19348 else
19349 break;
19350 }
19351 if (table_id == ~0)
19352 {
19353 errmsg ("missing table id");
19354 return -99;
19355 }
19356
19357 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019358 M (CLASSIFY_SESSION_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019359 mp->context = 0;
19360 mp->table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019361 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019362
19363 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019364 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019365 S (mp_ping);
19366
Jon Loeliger56c7b012017-02-01 12:31:41 -060019367 W (ret);
19368 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019369}
19370
19371static void
19372vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
19373{
19374 vat_main_t *vam = &vat_main;
19375
19376 print (vam->ofp, "collector_address %U, collector_port %d, "
19377 "src_address %U, vrf_id %d, path_mtu %u, "
19378 "template_interval %u, udp_checksum %d",
19379 format_ip4_address, mp->collector_address,
19380 ntohs (mp->collector_port),
19381 format_ip4_address, mp->src_address,
19382 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
19383 ntohl (mp->template_interval), mp->udp_checksum);
19384
19385 vam->retval = 0;
19386 vam->result_ready = 1;
19387}
19388
19389static void
19390 vl_api_ipfix_exporter_details_t_handler_json
19391 (vl_api_ipfix_exporter_details_t * mp)
19392{
19393 vat_main_t *vam = &vat_main;
19394 vat_json_node_t node;
19395 struct in_addr collector_address;
19396 struct in_addr src_address;
19397
19398 vat_json_init_object (&node);
19399 clib_memcpy (&collector_address, &mp->collector_address,
19400 sizeof (collector_address));
19401 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
19402 vat_json_object_add_uint (&node, "collector_port",
19403 ntohs (mp->collector_port));
19404 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
19405 vat_json_object_add_ip4 (&node, "src_address", src_address);
19406 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
19407 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
19408 vat_json_object_add_uint (&node, "template_interval",
19409 ntohl (mp->template_interval));
19410 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
19411
19412 vat_json_print (vam->ofp, &node);
19413 vat_json_free (&node);
19414 vam->retval = 0;
19415 vam->result_ready = 1;
19416}
19417
19418int
19419api_ipfix_exporter_dump (vat_main_t * vam)
19420{
19421 vl_api_ipfix_exporter_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019422 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019423
19424 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019425 M (IPFIX_EXPORTER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019426 mp->context = 0;
19427
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019428 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019429 W (ret);
19430 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019431}
19432
19433static int
19434api_ipfix_classify_stream_dump (vat_main_t * vam)
19435{
19436 vl_api_ipfix_classify_stream_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019437 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019438
19439 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019440 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019441 mp->context = 0;
19442
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019443 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019444 W (ret);
19445 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019446 /* NOTREACHED */
19447 return 0;
19448}
19449
19450static void
19451 vl_api_ipfix_classify_stream_details_t_handler
19452 (vl_api_ipfix_classify_stream_details_t * mp)
19453{
19454 vat_main_t *vam = &vat_main;
19455 print (vam->ofp, "domain_id %d, src_port %d",
19456 ntohl (mp->domain_id), ntohs (mp->src_port));
19457 vam->retval = 0;
19458 vam->result_ready = 1;
19459}
19460
19461static void
19462 vl_api_ipfix_classify_stream_details_t_handler_json
19463 (vl_api_ipfix_classify_stream_details_t * mp)
19464{
19465 vat_main_t *vam = &vat_main;
19466 vat_json_node_t node;
19467
19468 vat_json_init_object (&node);
19469 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
19470 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
19471
19472 vat_json_print (vam->ofp, &node);
19473 vat_json_free (&node);
19474 vam->retval = 0;
19475 vam->result_ready = 1;
19476}
19477
19478static int
19479api_ipfix_classify_table_dump (vat_main_t * vam)
19480{
19481 vl_api_ipfix_classify_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019482 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019483 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019484
19485 if (!vam->json_output)
19486 {
19487 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
19488 "transport_protocol");
19489 }
19490
19491 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019492 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019493
19494 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019495 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019496
19497 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019498 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019499 S (mp_ping);
19500
Jon Loeliger56c7b012017-02-01 12:31:41 -060019501 W (ret);
19502 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019503}
19504
19505static void
19506 vl_api_ipfix_classify_table_details_t_handler
19507 (vl_api_ipfix_classify_table_details_t * mp)
19508{
19509 vat_main_t *vam = &vat_main;
19510 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
19511 mp->transport_protocol);
19512}
19513
19514static void
19515 vl_api_ipfix_classify_table_details_t_handler_json
19516 (vl_api_ipfix_classify_table_details_t * mp)
19517{
19518 vat_json_node_t *node = NULL;
19519 vat_main_t *vam = &vat_main;
19520
19521 if (VAT_JSON_ARRAY != vam->json_tree.type)
19522 {
19523 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19524 vat_json_init_array (&vam->json_tree);
19525 }
19526
19527 node = vat_json_array_add (&vam->json_tree);
19528 vat_json_init_object (node);
19529
19530 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
19531 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
19532 vat_json_object_add_uint (node, "transport_protocol",
19533 mp->transport_protocol);
19534}
19535
19536static int
19537api_sw_interface_span_enable_disable (vat_main_t * vam)
19538{
19539 unformat_input_t *i = vam->input;
19540 vl_api_sw_interface_span_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019541 u32 src_sw_if_index = ~0;
19542 u32 dst_sw_if_index = ~0;
19543 u8 state = 3;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019544 int ret;
Eyal Bari001fd402017-07-16 09:34:53 +030019545 u8 is_l2 = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019546
19547 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19548 {
19549 if (unformat
19550 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
19551 ;
19552 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
19553 ;
19554 else
19555 if (unformat
19556 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
19557 ;
19558 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
19559 ;
19560 else if (unformat (i, "disable"))
19561 state = 0;
19562 else if (unformat (i, "rx"))
19563 state = 1;
19564 else if (unformat (i, "tx"))
19565 state = 2;
19566 else if (unformat (i, "both"))
19567 state = 3;
Eyal Bari001fd402017-07-16 09:34:53 +030019568 else if (unformat (i, "l2"))
19569 is_l2 = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019570 else
19571 break;
19572 }
19573
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019574 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019575
19576 mp->sw_if_index_from = htonl (src_sw_if_index);
19577 mp->sw_if_index_to = htonl (dst_sw_if_index);
19578 mp->state = state;
Eyal Bari001fd402017-07-16 09:34:53 +030019579 mp->is_l2 = is_l2;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019580
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019581 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019582 W (ret);
19583 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019584}
19585
19586static void
19587vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
19588 * mp)
19589{
19590 vat_main_t *vam = &vat_main;
19591 u8 *sw_if_from_name = 0;
19592 u8 *sw_if_to_name = 0;
19593 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
19594 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
19595 char *states[] = { "none", "rx", "tx", "both" };
19596 hash_pair_t *p;
19597
19598 /* *INDENT-OFF* */
19599 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
19600 ({
19601 if ((u32) p->value[0] == sw_if_index_from)
19602 {
19603 sw_if_from_name = (u8 *)(p->key);
19604 if (sw_if_to_name)
19605 break;
19606 }
19607 if ((u32) p->value[0] == sw_if_index_to)
19608 {
19609 sw_if_to_name = (u8 *)(p->key);
19610 if (sw_if_from_name)
19611 break;
19612 }
19613 }));
19614 /* *INDENT-ON* */
Jon Loeliger179ab362018-03-12 14:50:08 -050019615 print (vam->ofp, "%20s => %20s (%s) %s",
19616 sw_if_from_name, sw_if_to_name, states[mp->state],
19617 mp->is_l2 ? "l2" : "device");
Damjan Marion7cd468a2016-12-19 23:05:39 +010019618}
19619
19620static void
19621 vl_api_sw_interface_span_details_t_handler_json
19622 (vl_api_sw_interface_span_details_t * mp)
19623{
19624 vat_main_t *vam = &vat_main;
19625 vat_json_node_t *node = NULL;
19626 u8 *sw_if_from_name = 0;
19627 u8 *sw_if_to_name = 0;
19628 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
19629 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
19630 hash_pair_t *p;
19631
19632 /* *INDENT-OFF* */
19633 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
19634 ({
19635 if ((u32) p->value[0] == sw_if_index_from)
19636 {
19637 sw_if_from_name = (u8 *)(p->key);
19638 if (sw_if_to_name)
19639 break;
19640 }
19641 if ((u32) p->value[0] == sw_if_index_to)
19642 {
19643 sw_if_to_name = (u8 *)(p->key);
19644 if (sw_if_from_name)
19645 break;
19646 }
19647 }));
19648 /* *INDENT-ON* */
19649
19650 if (VAT_JSON_ARRAY != vam->json_tree.type)
19651 {
19652 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19653 vat_json_init_array (&vam->json_tree);
19654 }
19655 node = vat_json_array_add (&vam->json_tree);
19656
19657 vat_json_init_object (node);
19658 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
19659 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
19660 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
Neale Ranns05b2bf22017-01-30 06:44:58 -080019661 if (0 != sw_if_to_name)
19662 {
19663 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
19664 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010019665 vat_json_object_add_uint (node, "state", mp->state);
Jon Loeliger179ab362018-03-12 14:50:08 -050019666 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019667}
19668
19669static int
19670api_sw_interface_span_dump (vat_main_t * vam)
19671{
Eyal Bari5b311202017-07-31 13:12:30 +030019672 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019673 vl_api_sw_interface_span_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019674 vl_api_control_ping_t *mp_ping;
Eyal Bari5b311202017-07-31 13:12:30 +030019675 u8 is_l2 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019676 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019677
Eyal Bari5b311202017-07-31 13:12:30 +030019678 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19679 {
19680 if (unformat (input, "l2"))
19681 is_l2 = 1;
19682 else
19683 break;
19684 }
19685
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019686 M (SW_INTERFACE_SPAN_DUMP, mp);
Eyal Bari5b311202017-07-31 13:12:30 +030019687 mp->is_l2 = is_l2;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019688 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019689
19690 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019691 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019692 S (mp_ping);
19693
Jon Loeliger56c7b012017-02-01 12:31:41 -060019694 W (ret);
19695 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019696}
19697
19698int
19699api_pg_create_interface (vat_main_t * vam)
19700{
19701 unformat_input_t *input = vam->input;
19702 vl_api_pg_create_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019703
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020019704 u32 if_id = ~0, gso_size = 0;
19705 u8 gso_enabled = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019706 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019707 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19708 {
19709 if (unformat (input, "if_id %d", &if_id))
19710 ;
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020019711 else if (unformat (input, "gso-enabled"))
19712 {
19713 gso_enabled = 1;
19714 if (unformat (input, "gso-size %u", &gso_size))
19715 ;
19716 else
19717 {
19718 errmsg ("missing gso-size");
19719 return -99;
19720 }
19721 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010019722 else
19723 break;
19724 }
19725 if (if_id == ~0)
19726 {
19727 errmsg ("missing pg interface index");
19728 return -99;
19729 }
19730
19731 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019732 M (PG_CREATE_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019733 mp->context = 0;
19734 mp->interface_id = ntohl (if_id);
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020019735 mp->gso_enabled = gso_enabled;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019736
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019737 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019738 W (ret);
19739 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019740}
19741
19742int
19743api_pg_capture (vat_main_t * vam)
19744{
19745 unformat_input_t *input = vam->input;
19746 vl_api_pg_capture_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019747
19748 u32 if_id = ~0;
19749 u8 enable = 1;
19750 u32 count = 1;
19751 u8 pcap_file_set = 0;
19752 u8 *pcap_file = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019753 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019754 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19755 {
19756 if (unformat (input, "if_id %d", &if_id))
19757 ;
19758 else if (unformat (input, "pcap %s", &pcap_file))
19759 pcap_file_set = 1;
19760 else if (unformat (input, "count %d", &count))
19761 ;
19762 else if (unformat (input, "disable"))
19763 enable = 0;
19764 else
19765 break;
19766 }
19767 if (if_id == ~0)
19768 {
19769 errmsg ("missing pg interface index");
19770 return -99;
19771 }
19772 if (pcap_file_set > 0)
19773 {
19774 if (vec_len (pcap_file) > 255)
19775 {
19776 errmsg ("pcap file name is too long");
19777 return -99;
19778 }
19779 }
19780
19781 u32 name_len = vec_len (pcap_file);
19782 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019783 M (PG_CAPTURE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019784 mp->context = 0;
19785 mp->interface_id = ntohl (if_id);
19786 mp->is_enabled = enable;
19787 mp->count = ntohl (count);
19788 mp->pcap_name_length = ntohl (name_len);
19789 if (pcap_file_set != 0)
19790 {
19791 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
19792 }
19793 vec_free (pcap_file);
19794
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019795 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019796 W (ret);
19797 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019798}
19799
19800int
19801api_pg_enable_disable (vat_main_t * vam)
19802{
19803 unformat_input_t *input = vam->input;
19804 vl_api_pg_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019805
19806 u8 enable = 1;
19807 u8 stream_name_set = 0;
19808 u8 *stream_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019809 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019810 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19811 {
19812 if (unformat (input, "stream %s", &stream_name))
19813 stream_name_set = 1;
19814 else if (unformat (input, "disable"))
19815 enable = 0;
19816 else
19817 break;
19818 }
19819
19820 if (stream_name_set > 0)
19821 {
19822 if (vec_len (stream_name) > 255)
19823 {
19824 errmsg ("stream name too long");
19825 return -99;
19826 }
19827 }
19828
19829 u32 name_len = vec_len (stream_name);
19830 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019831 M (PG_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019832 mp->context = 0;
19833 mp->is_enabled = enable;
19834 if (stream_name_set != 0)
19835 {
19836 mp->stream_name_length = ntohl (name_len);
19837 clib_memcpy (mp->stream_name, stream_name, name_len);
19838 }
19839 vec_free (stream_name);
19840
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019841 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019842 W (ret);
19843 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019844}
19845
19846int
19847api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
19848{
19849 unformat_input_t *input = vam->input;
19850 vl_api_ip_source_and_port_range_check_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019851
19852 u16 *low_ports = 0;
19853 u16 *high_ports = 0;
19854 u16 this_low;
19855 u16 this_hi;
Neale Ranns37029302018-08-10 05:30:06 -070019856 vl_api_prefix_t prefix;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019857 u32 tmp, tmp2;
19858 u8 prefix_set = 0;
19859 u32 vrf_id = ~0;
19860 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019861 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019862
19863 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19864 {
Neale Ranns37029302018-08-10 05:30:06 -070019865 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
19866 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019867 else if (unformat (input, "vrf %d", &vrf_id))
19868 ;
19869 else if (unformat (input, "del"))
19870 is_add = 0;
19871 else if (unformat (input, "port %d", &tmp))
19872 {
19873 if (tmp == 0 || tmp > 65535)
19874 {
19875 errmsg ("port %d out of range", tmp);
19876 return -99;
19877 }
19878 this_low = tmp;
19879 this_hi = this_low + 1;
19880 vec_add1 (low_ports, this_low);
19881 vec_add1 (high_ports, this_hi);
19882 }
19883 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
19884 {
19885 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
19886 {
19887 errmsg ("incorrect range parameters");
19888 return -99;
19889 }
19890 this_low = tmp;
19891 /* Note: in debug CLI +1 is added to high before
19892 passing to real fn that does "the work"
19893 (ip_source_and_port_range_check_add_del).
19894 This fn is a wrapper around the binary API fn a
19895 control plane will call, which expects this increment
19896 to have occurred. Hence letting the binary API control
19897 plane fn do the increment for consistency between VAT
19898 and other control planes.
19899 */
19900 this_hi = tmp2;
19901 vec_add1 (low_ports, this_low);
19902 vec_add1 (high_ports, this_hi);
19903 }
19904 else
19905 break;
19906 }
19907
19908 if (prefix_set == 0)
19909 {
19910 errmsg ("<address>/<mask> not specified");
19911 return -99;
19912 }
19913
19914 if (vrf_id == ~0)
19915 {
19916 errmsg ("VRF ID required, not specified");
19917 return -99;
19918 }
19919
19920 if (vrf_id == 0)
19921 {
19922 errmsg
19923 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
19924 return -99;
19925 }
19926
19927 if (vec_len (low_ports) == 0)
19928 {
19929 errmsg ("At least one port or port range required");
19930 return -99;
19931 }
19932
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019933 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019934
19935 mp->is_add = is_add;
19936
Neale Ranns37029302018-08-10 05:30:06 -070019937 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019938
Damjan Marion7cd468a2016-12-19 23:05:39 +010019939 mp->number_of_ranges = vec_len (low_ports);
19940
19941 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
19942 vec_free (low_ports);
19943
19944 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
19945 vec_free (high_ports);
19946
19947 mp->vrf_id = ntohl (vrf_id);
19948
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019949 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019950 W (ret);
19951 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019952}
19953
19954int
19955api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
19956{
19957 unformat_input_t *input = vam->input;
19958 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019959 u32 sw_if_index = ~0;
19960 int vrf_set = 0;
19961 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
19962 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
19963 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019964 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019965
19966 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
19967 {
19968 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19969 ;
19970 else if (unformat (input, "sw_if_index %d", &sw_if_index))
19971 ;
19972 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
19973 vrf_set = 1;
19974 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
19975 vrf_set = 1;
19976 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
19977 vrf_set = 1;
19978 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
19979 vrf_set = 1;
19980 else if (unformat (input, "del"))
19981 is_add = 0;
19982 else
19983 break;
19984 }
19985
19986 if (sw_if_index == ~0)
19987 {
19988 errmsg ("Interface required but not specified");
19989 return -99;
19990 }
19991
19992 if (vrf_set == 0)
19993 {
19994 errmsg ("VRF ID required but not specified");
19995 return -99;
19996 }
19997
19998 if (tcp_out_vrf_id == 0
19999 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
20000 {
20001 errmsg
20002 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
20003 return -99;
20004 }
20005
20006 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020007 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020008
20009 mp->sw_if_index = ntohl (sw_if_index);
20010 mp->is_add = is_add;
20011 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
20012 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
20013 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
20014 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
20015
20016 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020017 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020018
20019 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060020020 W (ret);
20021 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020022}
20023
20024static int
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020025api_set_punt (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010020026{
20027 unformat_input_t *i = vam->input;
Neale Ranns50f0ac02019-05-15 02:13:37 -070020028 vl_api_address_family_t af;
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020029 vl_api_set_punt_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020030 u32 protocol = ~0;
20031 u32 port = ~0;
20032 int is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020033 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020034
20035 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20036 {
Neale Ranns50f0ac02019-05-15 02:13:37 -070020037 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
Damjan Marion7cd468a2016-12-19 23:05:39 +010020038 ;
20039 else if (unformat (i, "protocol %d", &protocol))
20040 ;
20041 else if (unformat (i, "port %d", &port))
20042 ;
20043 else if (unformat (i, "del"))
20044 is_add = 0;
20045 else
20046 {
20047 clib_warning ("parse error '%U'", format_unformat_error, i);
20048 return -99;
20049 }
20050 }
20051
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020052 M (SET_PUNT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020053
20054 mp->is_add = (u8) is_add;
Neale Ranns50f0ac02019-05-15 02:13:37 -070020055 mp->punt.type = PUNT_API_TYPE_L4;
20056 mp->punt.punt.l4.af = af;
20057 mp->punt.punt.l4.protocol = (u8) protocol;
20058 mp->punt.punt.l4.port = htons ((u16) port);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020059
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020060 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020061 W (ret);
20062 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020063}
20064
Damjan Marion7cd468a2016-12-19 23:05:39 +010020065static int
20066api_delete_subif (vat_main_t * vam)
20067{
20068 unformat_input_t *i = vam->input;
20069 vl_api_delete_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020070 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020071 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020072
20073 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20074 {
20075 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20076 ;
20077 if (unformat (i, "sw_if_index %d", &sw_if_index))
20078 ;
20079 else
20080 break;
20081 }
20082
20083 if (sw_if_index == ~0)
20084 {
20085 errmsg ("missing sw_if_index");
20086 return -99;
20087 }
20088
20089 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020090 M (DELETE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020091 mp->sw_if_index = ntohl (sw_if_index);
20092
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020093 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020094 W (ret);
20095 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020096}
20097
20098#define foreach_pbb_vtr_op \
20099_("disable", L2_VTR_DISABLED) \
20100_("pop", L2_VTR_POP_2) \
20101_("push", L2_VTR_PUSH_2)
20102
20103static int
20104api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
20105{
20106 unformat_input_t *i = vam->input;
20107 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020108 u32 sw_if_index = ~0, vtr_op = ~0;
20109 u16 outer_tag = ~0;
20110 u8 dmac[6], smac[6];
20111 u8 dmac_set = 0, smac_set = 0;
20112 u16 vlanid = 0;
20113 u32 sid = ~0;
20114 u32 tmp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020115 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020116
20117 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040020118 clib_memset (dmac, 0, sizeof (dmac));
20119 clib_memset (smac, 0, sizeof (smac));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020120
20121 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20122 {
20123 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20124 ;
20125 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20126 ;
20127 else if (unformat (i, "vtr_op %d", &vtr_op))
20128 ;
20129#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
20130 foreach_pbb_vtr_op
20131#undef _
20132 else if (unformat (i, "translate_pbb_stag"))
20133 {
20134 if (unformat (i, "%d", &tmp))
20135 {
20136 vtr_op = L2_VTR_TRANSLATE_2_1;
20137 outer_tag = tmp;
20138 }
20139 else
20140 {
20141 errmsg
20142 ("translate_pbb_stag operation requires outer tag definition");
20143 return -99;
20144 }
20145 }
20146 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
20147 dmac_set++;
20148 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
20149 smac_set++;
20150 else if (unformat (i, "sid %d", &sid))
20151 ;
20152 else if (unformat (i, "vlanid %d", &tmp))
20153 vlanid = tmp;
20154 else
20155 {
20156 clib_warning ("parse error '%U'", format_unformat_error, i);
20157 return -99;
20158 }
20159 }
20160
20161 if ((sw_if_index == ~0) || (vtr_op == ~0))
20162 {
20163 errmsg ("missing sw_if_index or vtr operation");
20164 return -99;
20165 }
20166 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
20167 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
20168 {
20169 errmsg
20170 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
20171 return -99;
20172 }
20173
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020174 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020175 mp->sw_if_index = ntohl (sw_if_index);
20176 mp->vtr_op = ntohl (vtr_op);
20177 mp->outer_tag = ntohs (outer_tag);
20178 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
20179 clib_memcpy (mp->b_smac, smac, sizeof (smac));
20180 mp->b_vlanid = ntohs (vlanid);
20181 mp->i_sid = ntohl (sid);
20182
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020183 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020184 W (ret);
20185 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020186}
20187
20188static int
20189api_flow_classify_set_interface (vat_main_t * vam)
20190{
20191 unformat_input_t *i = vam->input;
20192 vl_api_flow_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020193 u32 sw_if_index;
20194 int sw_if_index_set;
20195 u32 ip4_table_index = ~0;
20196 u32 ip6_table_index = ~0;
20197 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020198 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020199
20200 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20201 {
20202 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20203 sw_if_index_set = 1;
20204 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20205 sw_if_index_set = 1;
20206 else if (unformat (i, "del"))
20207 is_add = 0;
20208 else if (unformat (i, "ip4-table %d", &ip4_table_index))
20209 ;
20210 else if (unformat (i, "ip6-table %d", &ip6_table_index))
20211 ;
20212 else
20213 {
20214 clib_warning ("parse error '%U'", format_unformat_error, i);
20215 return -99;
20216 }
20217 }
20218
20219 if (sw_if_index_set == 0)
20220 {
20221 errmsg ("missing interface name or sw_if_index");
20222 return -99;
20223 }
20224
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020225 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020226
20227 mp->sw_if_index = ntohl (sw_if_index);
20228 mp->ip4_table_index = ntohl (ip4_table_index);
20229 mp->ip6_table_index = ntohl (ip6_table_index);
20230 mp->is_add = is_add;
20231
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020232 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020233 W (ret);
20234 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020235}
20236
20237static int
20238api_flow_classify_dump (vat_main_t * vam)
20239{
20240 unformat_input_t *i = vam->input;
20241 vl_api_flow_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020242 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020243 u8 type = FLOW_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020244 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020245
20246 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
20247 ;
20248 else
20249 {
20250 errmsg ("classify table type must be specified");
20251 return -99;
20252 }
20253
20254 if (!vam->json_output)
20255 {
20256 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
20257 }
20258
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020259 M (FLOW_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020260 mp->type = type;
20261 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020262 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020263
20264 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020265 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020266 S (mp_ping);
20267
Damjan Marion7cd468a2016-12-19 23:05:39 +010020268 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060020269 W (ret);
20270 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020271}
20272
20273static int
20274api_feature_enable_disable (vat_main_t * vam)
20275{
20276 unformat_input_t *i = vam->input;
20277 vl_api_feature_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020278 u8 *arc_name = 0;
20279 u8 *feature_name = 0;
20280 u32 sw_if_index = ~0;
20281 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020282 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020283
20284 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20285 {
20286 if (unformat (i, "arc_name %s", &arc_name))
20287 ;
20288 else if (unformat (i, "feature_name %s", &feature_name))
20289 ;
20290 else
20291 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20292 ;
20293 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20294 ;
20295 else if (unformat (i, "disable"))
20296 enable = 0;
20297 else
20298 break;
20299 }
20300
20301 if (arc_name == 0)
20302 {
20303 errmsg ("missing arc name");
20304 return -99;
20305 }
20306 if (vec_len (arc_name) > 63)
20307 {
20308 errmsg ("arc name too long");
20309 }
20310
20311 if (feature_name == 0)
20312 {
20313 errmsg ("missing feature name");
20314 return -99;
20315 }
20316 if (vec_len (feature_name) > 63)
20317 {
20318 errmsg ("feature name too long");
20319 }
20320
20321 if (sw_if_index == ~0)
20322 {
20323 errmsg ("missing interface name or sw_if_index");
20324 return -99;
20325 }
20326
20327 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020328 M (FEATURE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020329 mp->sw_if_index = ntohl (sw_if_index);
20330 mp->enable = enable;
20331 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
20332 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
20333 vec_free (arc_name);
20334 vec_free (feature_name);
20335
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020336 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020337 W (ret);
20338 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020339}
20340
20341static int
20342api_sw_interface_tag_add_del (vat_main_t * vam)
20343{
20344 unformat_input_t *i = vam->input;
20345 vl_api_sw_interface_tag_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020346 u32 sw_if_index = ~0;
20347 u8 *tag = 0;
20348 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020349 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020350
20351 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20352 {
20353 if (unformat (i, "tag %s", &tag))
20354 ;
20355 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20356 ;
20357 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20358 ;
20359 else if (unformat (i, "del"))
20360 enable = 0;
20361 else
20362 break;
20363 }
20364
20365 if (sw_if_index == ~0)
20366 {
20367 errmsg ("missing interface name or sw_if_index");
20368 return -99;
20369 }
20370
20371 if (enable && (tag == 0))
20372 {
20373 errmsg ("no tag specified");
20374 return -99;
20375 }
20376
20377 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020378 M (SW_INTERFACE_TAG_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020379 mp->sw_if_index = ntohl (sw_if_index);
20380 mp->is_add = enable;
20381 if (enable)
Ole Troane5ff5a32019-08-23 22:55:18 +020020382 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020383 vec_free (tag);
20384
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020385 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020386 W (ret);
20387 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020388}
20389
20390static void vl_api_l2_xconnect_details_t_handler
20391 (vl_api_l2_xconnect_details_t * mp)
20392{
20393 vat_main_t *vam = &vat_main;
20394
20395 print (vam->ofp, "%15d%15d",
20396 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
20397}
20398
20399static void vl_api_l2_xconnect_details_t_handler_json
20400 (vl_api_l2_xconnect_details_t * mp)
20401{
20402 vat_main_t *vam = &vat_main;
20403 vat_json_node_t *node = NULL;
20404
20405 if (VAT_JSON_ARRAY != vam->json_tree.type)
20406 {
20407 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20408 vat_json_init_array (&vam->json_tree);
20409 }
20410 node = vat_json_array_add (&vam->json_tree);
20411
20412 vat_json_init_object (node);
20413 vat_json_object_add_uint (node, "rx_sw_if_index",
20414 ntohl (mp->rx_sw_if_index));
20415 vat_json_object_add_uint (node, "tx_sw_if_index",
20416 ntohl (mp->tx_sw_if_index));
20417}
20418
20419static int
20420api_l2_xconnect_dump (vat_main_t * vam)
20421{
20422 vl_api_l2_xconnect_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020423 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020424 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020425
20426 if (!vam->json_output)
20427 {
20428 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
20429 }
20430
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020431 M (L2_XCONNECT_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020432
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020433 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020434
20435 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020436 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020437 S (mp_ping);
20438
Jon Loeliger56c7b012017-02-01 12:31:41 -060020439 W (ret);
20440 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020441}
20442
20443static int
Ole Troand7231612018-06-07 10:17:57 +020020444api_hw_interface_set_mtu (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010020445{
20446 unformat_input_t *i = vam->input;
Ole Troand7231612018-06-07 10:17:57 +020020447 vl_api_hw_interface_set_mtu_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020448 u32 sw_if_index = ~0;
20449 u32 mtu = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020450 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020451
20452 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20453 {
20454 if (unformat (i, "mtu %d", &mtu))
20455 ;
20456 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20457 ;
20458 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20459 ;
20460 else
20461 break;
20462 }
20463
20464 if (sw_if_index == ~0)
20465 {
20466 errmsg ("missing interface name or sw_if_index");
20467 return -99;
20468 }
20469
20470 if (mtu == 0)
20471 {
20472 errmsg ("no mtu specified");
20473 return -99;
20474 }
20475
20476 /* Construct the API message */
Ole Troand7231612018-06-07 10:17:57 +020020477 M (HW_INTERFACE_SET_MTU, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020478 mp->sw_if_index = ntohl (sw_if_index);
20479 mp->mtu = ntohs ((u16) mtu);
20480
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020481 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020482 W (ret);
20483 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020484}
20485
Pavel Kotucek6899a302017-06-08 08:46:10 +020020486static int
20487api_p2p_ethernet_add (vat_main_t * vam)
20488{
20489 unformat_input_t *i = vam->input;
20490 vl_api_p2p_ethernet_add_t *mp;
20491 u32 parent_if_index = ~0;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020492 u32 sub_id = ~0;
Pavel Kotucek6899a302017-06-08 08:46:10 +020020493 u8 remote_mac[6];
20494 u8 mac_set = 0;
20495 int ret;
20496
Dave Barachb7b92992018-10-17 10:38:51 -040020497 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020020498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20499 {
20500 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
20501 ;
20502 else if (unformat (i, "sw_if_index %d", &parent_if_index))
20503 ;
20504 else
20505 if (unformat
20506 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
20507 mac_set++;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020508 else if (unformat (i, "sub_id %d", &sub_id))
20509 ;
Pavel Kotucek6899a302017-06-08 08:46:10 +020020510 else
20511 {
20512 clib_warning ("parse error '%U'", format_unformat_error, i);
20513 return -99;
20514 }
20515 }
20516
20517 if (parent_if_index == ~0)
20518 {
20519 errmsg ("missing interface name or sw_if_index");
20520 return -99;
20521 }
20522 if (mac_set == 0)
20523 {
20524 errmsg ("missing remote mac address");
20525 return -99;
20526 }
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020527 if (sub_id == ~0)
20528 {
20529 errmsg ("missing sub-interface id");
20530 return -99;
20531 }
Pavel Kotucek6899a302017-06-08 08:46:10 +020020532
20533 M (P2P_ETHERNET_ADD, mp);
20534 mp->parent_if_index = ntohl (parent_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020535 mp->subif_id = ntohl (sub_id);
Pavel Kotucek6899a302017-06-08 08:46:10 +020020536 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
20537
20538 S (mp);
20539 W (ret);
20540 return ret;
20541}
20542
20543static int
20544api_p2p_ethernet_del (vat_main_t * vam)
20545{
20546 unformat_input_t *i = vam->input;
20547 vl_api_p2p_ethernet_del_t *mp;
20548 u32 parent_if_index = ~0;
20549 u8 remote_mac[6];
20550 u8 mac_set = 0;
20551 int ret;
20552
Dave Barachb7b92992018-10-17 10:38:51 -040020553 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020020554 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20555 {
20556 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
20557 ;
20558 else if (unformat (i, "sw_if_index %d", &parent_if_index))
20559 ;
20560 else
20561 if (unformat
20562 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
20563 mac_set++;
20564 else
20565 {
20566 clib_warning ("parse error '%U'", format_unformat_error, i);
20567 return -99;
20568 }
20569 }
20570
20571 if (parent_if_index == ~0)
20572 {
20573 errmsg ("missing interface name or sw_if_index");
20574 return -99;
20575 }
20576 if (mac_set == 0)
20577 {
20578 errmsg ("missing remote mac address");
20579 return -99;
20580 }
20581
20582 M (P2P_ETHERNET_DEL, mp);
20583 mp->parent_if_index = ntohl (parent_if_index);
20584 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
20585
20586 S (mp);
20587 W (ret);
20588 return ret;
20589}
Damjan Marion7cd468a2016-12-19 23:05:39 +010020590
20591static int
Steve Shin99a0e602017-07-01 04:16:20 +000020592api_lldp_config (vat_main_t * vam)
20593{
20594 unformat_input_t *i = vam->input;
20595 vl_api_lldp_config_t *mp;
20596 int tx_hold = 0;
20597 int tx_interval = 0;
20598 u8 *sys_name = NULL;
20599 int ret;
20600
20601 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20602 {
20603 if (unformat (i, "system-name %s", &sys_name))
20604 ;
20605 else if (unformat (i, "tx-hold %d", &tx_hold))
20606 ;
20607 else if (unformat (i, "tx-interval %d", &tx_interval))
20608 ;
20609 else
20610 {
20611 clib_warning ("parse error '%U'", format_unformat_error, i);
20612 return -99;
20613 }
20614 }
20615
20616 vec_add1 (sys_name, 0);
20617
20618 M (LLDP_CONFIG, mp);
20619 mp->tx_hold = htonl (tx_hold);
20620 mp->tx_interval = htonl (tx_interval);
20621 clib_memcpy (mp->system_name, sys_name, vec_len (sys_name));
20622 vec_free (sys_name);
20623
20624 S (mp);
20625 W (ret);
20626 return ret;
20627}
20628
20629static int
20630api_sw_interface_set_lldp (vat_main_t * vam)
20631{
20632 unformat_input_t *i = vam->input;
20633 vl_api_sw_interface_set_lldp_t *mp;
20634 u32 sw_if_index = ~0;
20635 u32 enable = 1;
Steve Shin9a6fcef2017-10-11 13:55:16 -070020636 u8 *port_desc = NULL, *mgmt_oid = NULL;
20637 ip4_address_t ip4_addr;
20638 ip6_address_t ip6_addr;
Steve Shin99a0e602017-07-01 04:16:20 +000020639 int ret;
20640
Dave Barachb7b92992018-10-17 10:38:51 -040020641 clib_memset (&ip4_addr, 0, sizeof (ip4_addr));
20642 clib_memset (&ip6_addr, 0, sizeof (ip6_addr));
Steve Shin9a6fcef2017-10-11 13:55:16 -070020643
Steve Shin99a0e602017-07-01 04:16:20 +000020644 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20645 {
20646 if (unformat (i, "disable"))
20647 enable = 0;
20648 else
20649 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20650 ;
20651 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20652 ;
20653 else if (unformat (i, "port-desc %s", &port_desc))
20654 ;
Steve Shin9a6fcef2017-10-11 13:55:16 -070020655 else if (unformat (i, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
20656 ;
20657 else if (unformat (i, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
20658 ;
20659 else if (unformat (i, "mgmt-oid %s", &mgmt_oid))
20660 ;
Steve Shin99a0e602017-07-01 04:16:20 +000020661 else
20662 break;
20663 }
20664
20665 if (sw_if_index == ~0)
20666 {
20667 errmsg ("missing interface name or sw_if_index");
20668 return -99;
20669 }
20670
20671 /* Construct the API message */
20672 vec_add1 (port_desc, 0);
Steve Shin9a6fcef2017-10-11 13:55:16 -070020673 vec_add1 (mgmt_oid, 0);
Steve Shin99a0e602017-07-01 04:16:20 +000020674 M (SW_INTERFACE_SET_LLDP, mp);
20675 mp->sw_if_index = ntohl (sw_if_index);
20676 mp->enable = enable;
20677 clib_memcpy (mp->port_desc, port_desc, vec_len (port_desc));
Steve Shin9a6fcef2017-10-11 13:55:16 -070020678 clib_memcpy (mp->mgmt_oid, mgmt_oid, vec_len (mgmt_oid));
20679 clib_memcpy (mp->mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
20680 clib_memcpy (mp->mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
Steve Shin99a0e602017-07-01 04:16:20 +000020681 vec_free (port_desc);
Steve Shin9a6fcef2017-10-11 13:55:16 -070020682 vec_free (mgmt_oid);
Steve Shin99a0e602017-07-01 04:16:20 +000020683
20684 S (mp);
20685 W (ret);
20686 return ret;
20687}
20688
20689static int
Dave Barach3bbcfab2017-08-15 19:03:44 -040020690api_tcp_configure_src_addresses (vat_main_t * vam)
20691{
20692 vl_api_tcp_configure_src_addresses_t *mp;
20693 unformat_input_t *i = vam->input;
20694 ip4_address_t v4first, v4last;
20695 ip6_address_t v6first, v6last;
20696 u8 range_set = 0;
20697 u32 vrf_id = 0;
20698 int ret;
20699
20700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20701 {
20702 if (unformat (i, "%U - %U",
20703 unformat_ip4_address, &v4first,
20704 unformat_ip4_address, &v4last))
20705 {
20706 if (range_set)
20707 {
20708 errmsg ("one range per message (range already set)");
20709 return -99;
20710 }
20711 range_set = 1;
20712 }
20713 else if (unformat (i, "%U - %U",
20714 unformat_ip6_address, &v6first,
20715 unformat_ip6_address, &v6last))
20716 {
20717 if (range_set)
20718 {
20719 errmsg ("one range per message (range already set)");
20720 return -99;
20721 }
20722 range_set = 2;
20723 }
20724 else if (unformat (i, "vrf %d", &vrf_id))
20725 ;
20726 else
20727 break;
20728 }
20729
20730 if (range_set == 0)
20731 {
20732 errmsg ("address range not set");
20733 return -99;
20734 }
20735
20736 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
20737 mp->vrf_id = ntohl (vrf_id);
20738 /* ipv6? */
20739 if (range_set == 2)
20740 {
20741 mp->is_ipv6 = 1;
20742 clib_memcpy (mp->first_address, &v6first, sizeof (v6first));
20743 clib_memcpy (mp->last_address, &v6last, sizeof (v6last));
20744 }
20745 else
20746 {
20747 mp->is_ipv6 = 0;
20748 clib_memcpy (mp->first_address, &v4first, sizeof (v4first));
20749 clib_memcpy (mp->last_address, &v4last, sizeof (v4last));
20750 }
20751 S (mp);
20752 W (ret);
20753 return ret;
20754}
20755
Florin Coras6e8c6672017-11-10 09:03:54 -080020756static void vl_api_app_namespace_add_del_reply_t_handler
20757 (vl_api_app_namespace_add_del_reply_t * mp)
20758{
20759 vat_main_t *vam = &vat_main;
20760 i32 retval = ntohl (mp->retval);
20761 if (vam->async_mode)
20762 {
20763 vam->async_errors += (retval < 0);
20764 }
20765 else
20766 {
20767 vam->retval = retval;
20768 if (retval == 0)
20769 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
20770 vam->result_ready = 1;
20771 }
20772}
20773
20774static void vl_api_app_namespace_add_del_reply_t_handler_json
20775 (vl_api_app_namespace_add_del_reply_t * mp)
20776{
20777 vat_main_t *vam = &vat_main;
20778 vat_json_node_t node;
20779
20780 vat_json_init_object (&node);
20781 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
20782 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
20783
20784 vat_json_print (vam->ofp, &node);
20785 vat_json_free (&node);
20786
20787 vam->retval = ntohl (mp->retval);
20788 vam->result_ready = 1;
20789}
20790
Dave Barach3bbcfab2017-08-15 19:03:44 -040020791static int
Florin Corascea194d2017-10-02 00:18:51 -070020792api_app_namespace_add_del (vat_main_t * vam)
20793{
20794 vl_api_app_namespace_add_del_t *mp;
20795 unformat_input_t *i = vam->input;
20796 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
20797 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
20798 u64 secret;
20799 int ret;
20800
20801 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20802 {
20803 if (unformat (i, "id %_%v%_", &ns_id))
20804 ;
20805 else if (unformat (i, "secret %lu", &secret))
20806 secret_set = 1;
20807 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20808 sw_if_index_set = 1;
20809 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
20810 ;
20811 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
20812 ;
20813 else
20814 break;
20815 }
20816 if (!ns_id || !secret_set || !sw_if_index_set)
20817 {
20818 errmsg ("namespace id, secret and sw_if_index must be set");
20819 return -99;
20820 }
20821 if (vec_len (ns_id) > 64)
20822 {
20823 errmsg ("namespace id too long");
20824 return -99;
20825 }
20826 M (APP_NAMESPACE_ADD_DEL, mp);
20827
20828 clib_memcpy (mp->namespace_id, ns_id, vec_len (ns_id));
20829 mp->namespace_id_len = vec_len (ns_id);
Florin Coras9a9adb22017-10-26 08:16:59 -070020830 mp->secret = clib_host_to_net_u64 (secret);
Florin Corascea194d2017-10-02 00:18:51 -070020831 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
20832 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
20833 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
20834 vec_free (ns_id);
20835 S (mp);
20836 W (ret);
20837 return ret;
20838}
20839
20840static int
Florin Coras90a63982017-12-19 04:50:01 -080020841api_sock_init_shm (vat_main_t * vam)
20842{
20843#if VPP_API_TEST_BUILTIN == 0
20844 unformat_input_t *i = vam->input;
20845 vl_api_shm_elem_config_t *config = 0;
20846 u64 size = 64 << 20;
20847 int rv;
20848
20849 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20850 {
20851 if (unformat (i, "size %U", unformat_memory_size, &size))
20852 ;
20853 else
20854 break;
20855 }
20856
Dave Barach78958722018-05-10 16:44:27 -040020857 /*
20858 * Canned custom ring allocator config.
20859 * Should probably parse all of this
20860 */
20861 vec_validate (config, 6);
Florin Coras90a63982017-12-19 04:50:01 -080020862 config[0].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080020863 config[0].size = 256;
Dave Barach78958722018-05-10 16:44:27 -040020864 config[0].count = 32;
20865
20866 config[1].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080020867 config[1].size = 1024;
Dave Barach78958722018-05-10 16:44:27 -040020868 config[1].count = 16;
20869
20870 config[2].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080020871 config[2].size = 4096;
Dave Barach78958722018-05-10 16:44:27 -040020872 config[2].count = 2;
20873
20874 config[3].type = VL_API_CLIENT_RING;
20875 config[3].size = 256;
20876 config[3].count = 32;
20877
20878 config[4].type = VL_API_CLIENT_RING;
20879 config[4].size = 1024;
20880 config[4].count = 16;
20881
20882 config[5].type = VL_API_CLIENT_RING;
20883 config[5].size = 4096;
20884 config[5].count = 2;
20885
20886 config[6].type = VL_API_QUEUE;
20887 config[6].count = 128;
20888 config[6].size = sizeof (uword);
20889
Tomasz Kulasek97dcf5b2019-01-31 18:26:32 +010020890 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
Florin Coras90a63982017-12-19 04:50:01 -080020891 if (!rv)
20892 vam->client_index_invalid = 1;
20893 return rv;
20894#else
20895 return -99;
20896#endif
20897}
20898
Florin Coras6c36f532017-11-03 18:32:34 -070020899static void
20900vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
20901{
20902 vat_main_t *vam = &vat_main;
20903
20904 if (mp->is_ip4)
20905 {
Florin Corasc97a7392017-11-05 23:07:07 -080020906 print (vam->ofp,
20907 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080020908 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
20909 mp->scope, format_ip4_address, &mp->lcl_ip, mp->lcl_plen,
20910 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
20911 &mp->rmt_ip, mp->rmt_plen, clib_net_to_host_u16 (mp->rmt_port),
20912 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070020913 }
20914 else
20915 {
Florin Corasc97a7392017-11-05 23:07:07 -080020916 print (vam->ofp,
20917 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080020918 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
20919 mp->scope, format_ip6_address, &mp->lcl_ip, mp->lcl_plen,
20920 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
20921 &mp->rmt_ip, mp->rmt_plen, clib_net_to_host_u16 (mp->rmt_port),
20922 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070020923 }
20924}
20925
20926static void
20927vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
20928 mp)
20929{
20930 vat_main_t *vam = &vat_main;
20931 vat_json_node_t *node = NULL;
20932 struct in6_addr ip6;
20933 struct in_addr ip4;
20934
20935 if (VAT_JSON_ARRAY != vam->json_tree.type)
20936 {
20937 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20938 vat_json_init_array (&vam->json_tree);
20939 }
20940 node = vat_json_array_add (&vam->json_tree);
20941 vat_json_init_object (node);
20942
20943 vat_json_object_add_uint (node, "is_ip4", mp->is_ip4 ? 1 : 0);
20944 vat_json_object_add_uint (node, "appns_index",
20945 clib_net_to_host_u32 (mp->appns_index));
20946 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
20947 vat_json_object_add_uint (node, "scope", mp->scope);
20948 vat_json_object_add_uint (node, "action_index",
20949 clib_net_to_host_u32 (mp->action_index));
20950 vat_json_object_add_uint (node, "lcl_port",
20951 clib_net_to_host_u16 (mp->lcl_port));
20952 vat_json_object_add_uint (node, "rmt_port",
20953 clib_net_to_host_u16 (mp->rmt_port));
20954 vat_json_object_add_uint (node, "lcl_plen", mp->lcl_plen);
20955 vat_json_object_add_uint (node, "rmt_plen", mp->rmt_plen);
Florin Corasc97a7392017-11-05 23:07:07 -080020956 vat_json_object_add_string_copy (node, "tag", mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070020957 if (mp->is_ip4)
20958 {
20959 clib_memcpy (&ip4, mp->lcl_ip, sizeof (ip4));
20960 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
20961 clib_memcpy (&ip4, mp->rmt_ip, sizeof (ip4));
20962 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
20963 }
20964 else
20965 {
20966 clib_memcpy (&ip6, mp->lcl_ip, sizeof (ip6));
20967 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
20968 clib_memcpy (&ip6, mp->rmt_ip, sizeof (ip6));
20969 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
20970 }
20971}
20972
Florin Coras1c710452017-10-17 00:03:13 -070020973static int
20974api_session_rule_add_del (vat_main_t * vam)
20975{
20976 vl_api_session_rule_add_del_t *mp;
20977 unformat_input_t *i = vam->input;
20978 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
20979 u32 appns_index = 0, scope = 0;
20980 ip4_address_t lcl_ip4, rmt_ip4;
20981 ip6_address_t lcl_ip6, rmt_ip6;
20982 u8 is_ip4 = 1, conn_set = 0;
Florin Corasc97a7392017-11-05 23:07:07 -080020983 u8 is_add = 1, *tag = 0;
Florin Coras1c710452017-10-17 00:03:13 -070020984 int ret;
20985
20986 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20987 {
20988 if (unformat (i, "del"))
20989 is_add = 0;
20990 else if (unformat (i, "add"))
20991 ;
20992 else if (unformat (i, "proto tcp"))
20993 proto = 0;
20994 else if (unformat (i, "proto udp"))
20995 proto = 1;
20996 else if (unformat (i, "appns %d", &appns_index))
20997 ;
20998 else if (unformat (i, "scope %d", &scope))
20999 ;
Florin Corasc97a7392017-11-05 23:07:07 -080021000 else if (unformat (i, "tag %_%v%_", &tag))
21001 ;
Florin Coras1c710452017-10-17 00:03:13 -070021002 else
21003 if (unformat
21004 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
21005 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
21006 &rmt_port))
21007 {
21008 is_ip4 = 1;
21009 conn_set = 1;
21010 }
21011 else
21012 if (unformat
21013 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
21014 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
21015 &rmt_port))
21016 {
21017 is_ip4 = 0;
21018 conn_set = 1;
21019 }
21020 else if (unformat (i, "action %d", &action))
21021 ;
21022 else
21023 break;
21024 }
21025 if (proto == ~0 || !conn_set || action == ~0)
21026 {
21027 errmsg ("transport proto, connection and action must be set");
21028 return -99;
21029 }
21030
21031 if (scope > 3)
21032 {
21033 errmsg ("scope should be 0-3");
21034 return -99;
21035 }
21036
21037 M (SESSION_RULE_ADD_DEL, mp);
21038
21039 mp->is_ip4 = is_ip4;
21040 mp->transport_proto = proto;
Florin Corasc97a7392017-11-05 23:07:07 -080021041 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
21042 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
21043 mp->lcl_plen = lcl_plen;
21044 mp->rmt_plen = rmt_plen;
Florin Coras1c710452017-10-17 00:03:13 -070021045 mp->action_index = clib_host_to_net_u32 (action);
21046 mp->appns_index = clib_host_to_net_u32 (appns_index);
21047 mp->scope = scope;
21048 mp->is_add = is_add;
21049 if (is_ip4)
21050 {
21051 clib_memcpy (mp->lcl_ip, &lcl_ip4, sizeof (lcl_ip4));
21052 clib_memcpy (mp->rmt_ip, &rmt_ip4, sizeof (rmt_ip4));
21053 }
21054 else
21055 {
21056 clib_memcpy (mp->lcl_ip, &lcl_ip6, sizeof (lcl_ip6));
21057 clib_memcpy (mp->rmt_ip, &rmt_ip6, sizeof (rmt_ip6));
21058 }
Florin Corasc97a7392017-11-05 23:07:07 -080021059 if (tag)
21060 {
21061 clib_memcpy (mp->tag, tag, vec_len (tag));
21062 vec_free (tag);
21063 }
Florin Coras1c710452017-10-17 00:03:13 -070021064
21065 S (mp);
21066 W (ret);
21067 return ret;
21068}
Dave Barach65457162017-10-10 17:53:14 -040021069
21070static int
Florin Coras6c36f532017-11-03 18:32:34 -070021071api_session_rules_dump (vat_main_t * vam)
21072{
21073 vl_api_session_rules_dump_t *mp;
21074 vl_api_control_ping_t *mp_ping;
21075 int ret;
21076
21077 if (!vam->json_output)
21078 {
21079 print (vam->ofp, "%=20s", "Session Rules");
21080 }
21081
21082 M (SESSION_RULES_DUMP, mp);
21083 /* send it... */
21084 S (mp);
21085
21086 /* Use a control ping for synchronization */
21087 MPING (CONTROL_PING, mp_ping);
21088 S (mp_ping);
21089
21090 /* Wait for a reply... */
21091 W (ret);
21092 return ret;
21093}
21094
21095static int
Florin Coras595992c2017-11-06 17:17:08 -080021096api_ip_container_proxy_add_del (vat_main_t * vam)
21097{
21098 vl_api_ip_container_proxy_add_del_t *mp;
21099 unformat_input_t *i = vam->input;
Neale Ranns37029302018-08-10 05:30:06 -070021100 u32 sw_if_index = ~0;
21101 vl_api_prefix_t pfx = { };
Florin Coras595992c2017-11-06 17:17:08 -080021102 u8 is_add = 1;
21103 int ret;
21104
21105 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21106 {
21107 if (unformat (i, "del"))
21108 is_add = 0;
21109 else if (unformat (i, "add"))
21110 ;
Neale Ranns37029302018-08-10 05:30:06 -070021111 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
21112 ;
Florin Coras595992c2017-11-06 17:17:08 -080021113 else if (unformat (i, "sw_if_index %u", &sw_if_index))
21114 ;
21115 else
21116 break;
21117 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040021118 if (sw_if_index == ~0 || pfx.len == 0)
Florin Coras595992c2017-11-06 17:17:08 -080021119 {
21120 errmsg ("address and sw_if_index must be set");
21121 return -99;
21122 }
21123
21124 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
21125
Florin Coras595992c2017-11-06 17:17:08 -080021126 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
Florin Coras595992c2017-11-06 17:17:08 -080021127 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -070021128 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
Florin Coras595992c2017-11-06 17:17:08 -080021129
21130 S (mp);
21131 W (ret);
21132 return ret;
21133}
21134
21135static int
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070021136api_qos_record_enable_disable (vat_main_t * vam)
21137{
21138 unformat_input_t *i = vam->input;
21139 vl_api_qos_record_enable_disable_t *mp;
21140 u32 sw_if_index, qs = 0xff;
21141 u8 sw_if_index_set = 0;
21142 u8 enable = 1;
21143 int ret;
21144
21145 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21146 {
21147 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21148 sw_if_index_set = 1;
21149 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21150 sw_if_index_set = 1;
21151 else if (unformat (i, "%U", unformat_qos_source, &qs))
21152 ;
21153 else if (unformat (i, "disable"))
21154 enable = 0;
21155 else
21156 {
21157 clib_warning ("parse error '%U'", format_unformat_error, i);
21158 return -99;
21159 }
21160 }
21161
21162 if (sw_if_index_set == 0)
21163 {
21164 errmsg ("missing interface name or sw_if_index");
21165 return -99;
21166 }
21167 if (qs == 0xff)
21168 {
21169 errmsg ("input location must be specified");
21170 return -99;
21171 }
21172
21173 M (QOS_RECORD_ENABLE_DISABLE, mp);
21174
Neale Ranns5281a902019-07-23 08:16:19 -070021175 mp->record.sw_if_index = ntohl (sw_if_index);
21176 mp->record.input_source = qs;
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070021177 mp->enable = enable;
21178
21179 S (mp);
21180 W (ret);
21181 return ret;
21182}
21183
Dave Barach048a4e52018-06-01 18:52:25 -040021184
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070021185static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010021186q_or_quit (vat_main_t * vam)
21187{
Dave Barachdef19da2017-02-22 17:29:20 -050021188#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010021189 longjmp (vam->jump_buf, 1);
Dave Barachdef19da2017-02-22 17:29:20 -050021190#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021191 return 0; /* not so much */
21192}
21193
21194static int
21195q (vat_main_t * vam)
21196{
21197 return q_or_quit (vam);
21198}
21199
21200static int
21201quit (vat_main_t * vam)
21202{
21203 return q_or_quit (vam);
21204}
21205
21206static int
21207comment (vat_main_t * vam)
21208{
21209 return 0;
21210}
21211
21212static int
Dave Barachb09f4d02019-07-15 16:00:03 -040021213elog_save (vat_main_t * vam)
21214{
21215#if VPP_API_TEST_BUILTIN == 0
21216 elog_main_t *em = &vam->elog_main;
21217 unformat_input_t *i = vam->input;
21218 char *file, *chroot_file;
21219 clib_error_t *error;
21220
21221 if (!unformat (i, "%s", &file))
21222 {
21223 errmsg ("expected file name, got `%U'", format_unformat_error, i);
21224 return 0;
21225 }
21226
21227 /* It's fairly hard to get "../oopsie" through unformat; just in case */
21228 if (strstr (file, "..") || index (file, '/'))
21229 {
21230 errmsg ("illegal characters in filename '%s'", file);
21231 return 0;
21232 }
21233
21234 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
21235
21236 vec_free (file);
21237
21238 errmsg ("Saving %wd of %wd events to %s",
21239 elog_n_events_in_buffer (em),
21240 elog_buffer_capacity (em), chroot_file);
21241
21242 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
21243 vec_free (chroot_file);
21244
21245 if (error)
21246 clib_error_report (error);
21247#else
21248 errmsg ("Use the vpp event loger...");
21249#endif
21250
21251 return 0;
21252}
21253
21254static int
21255elog_setup (vat_main_t * vam)
21256{
21257#if VPP_API_TEST_BUILTIN == 0
21258 elog_main_t *em = &vam->elog_main;
21259 unformat_input_t *i = vam->input;
21260 u32 nevents = 128 << 10;
21261
21262 (void) unformat (i, "nevents %d", &nevents);
21263
21264 elog_init (em, nevents);
21265 vl_api_set_elog_main (em);
21266 vl_api_set_elog_trace_api_messages (1);
21267 errmsg ("Event logger initialized with %u events", nevents);
21268#else
21269 errmsg ("Use the vpp event loger...");
21270#endif
21271 return 0;
21272}
21273
21274static int
21275elog_enable (vat_main_t * vam)
21276{
21277#if VPP_API_TEST_BUILTIN == 0
21278 elog_main_t *em = &vam->elog_main;
21279
21280 elog_enable_disable (em, 1 /* enable */ );
21281 vl_api_set_elog_trace_api_messages (1);
21282 errmsg ("Event logger enabled...");
21283#else
21284 errmsg ("Use the vpp event loger...");
21285#endif
21286 return 0;
21287}
21288
21289static int
21290elog_disable (vat_main_t * vam)
21291{
21292#if VPP_API_TEST_BUILTIN == 0
21293 elog_main_t *em = &vam->elog_main;
21294
21295 elog_enable_disable (em, 0 /* enable */ );
21296 vl_api_set_elog_trace_api_messages (1);
21297 errmsg ("Event logger disabled...");
21298#else
21299 errmsg ("Use the vpp event loger...");
21300#endif
21301 return 0;
21302}
21303
21304static int
Dave Barach048a4e52018-06-01 18:52:25 -040021305statseg (vat_main_t * vam)
21306{
21307 ssvm_private_t *ssvmp = &vam->stat_segment;
21308 ssvm_shared_header_t *shared_header = ssvmp->sh;
21309 vlib_counter_t **counters;
21310 u64 thread0_index1_packets;
21311 u64 thread0_index1_bytes;
21312 f64 vector_rate, input_rate;
21313 uword *p;
21314
21315 uword *counter_vector_by_name;
21316 if (vam->stat_segment_lockp == 0)
21317 {
21318 errmsg ("Stat segment not mapped...");
21319 return -99;
21320 }
21321
21322 /* look up "/if/rx for sw_if_index 1 as a test */
21323
21324 clib_spinlock_lock (vam->stat_segment_lockp);
21325
21326 counter_vector_by_name = (uword *) shared_header->opaque[1];
21327
21328 p = hash_get_mem (counter_vector_by_name, "/if/rx");
21329 if (p == 0)
21330 {
21331 clib_spinlock_unlock (vam->stat_segment_lockp);
21332 errmsg ("/if/tx not found?");
21333 return -99;
21334 }
21335
21336 /* Fish per-thread vector of combined counters from shared memory */
21337 counters = (vlib_counter_t **) p[0];
21338
21339 if (vec_len (counters[0]) < 2)
21340 {
21341 clib_spinlock_unlock (vam->stat_segment_lockp);
21342 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
21343 return -99;
21344 }
21345
21346 /* Read thread 0 sw_if_index 1 counter */
21347 thread0_index1_packets = counters[0][1].packets;
21348 thread0_index1_bytes = counters[0][1].bytes;
21349
21350 p = hash_get_mem (counter_vector_by_name, "vector_rate");
21351 if (p == 0)
21352 {
21353 clib_spinlock_unlock (vam->stat_segment_lockp);
21354 errmsg ("vector_rate not found?");
21355 return -99;
21356 }
21357
21358 vector_rate = *(f64 *) (p[0]);
21359 p = hash_get_mem (counter_vector_by_name, "input_rate");
21360 if (p == 0)
21361 {
21362 clib_spinlock_unlock (vam->stat_segment_lockp);
21363 errmsg ("input_rate not found?");
21364 return -99;
21365 }
21366 input_rate = *(f64 *) (p[0]);
21367
21368 clib_spinlock_unlock (vam->stat_segment_lockp);
21369
21370 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
21371 vector_rate, input_rate);
21372 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
21373 thread0_index1_packets, thread0_index1_bytes);
21374
21375 return 0;
21376}
21377
21378static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010021379cmd_cmp (void *a1, void *a2)
21380{
21381 u8 **c1 = a1;
21382 u8 **c2 = a2;
21383
21384 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
21385}
21386
21387static int
21388help (vat_main_t * vam)
21389{
21390 u8 **cmds = 0;
21391 u8 *name = 0;
21392 hash_pair_t *p;
21393 unformat_input_t *i = vam->input;
21394 int j;
21395
21396 if (unformat (i, "%s", &name))
21397 {
21398 uword *hs;
21399
21400 vec_add1 (name, 0);
21401
21402 hs = hash_get_mem (vam->help_by_name, name);
21403 if (hs)
21404 print (vam->ofp, "usage: %s %s", name, hs[0]);
21405 else
21406 print (vam->ofp, "No such msg / command '%s'", name);
21407 vec_free (name);
21408 return 0;
21409 }
21410
21411 print (vam->ofp, "Help is available for the following:");
21412
21413 /* *INDENT-OFF* */
21414 hash_foreach_pair (p, vam->function_by_name,
21415 ({
21416 vec_add1 (cmds, (u8 *)(p->key));
21417 }));
21418 /* *INDENT-ON* */
21419
21420 vec_sort_with_function (cmds, cmd_cmp);
21421
21422 for (j = 0; j < vec_len (cmds); j++)
21423 print (vam->ofp, "%s", cmds[j]);
21424
21425 vec_free (cmds);
21426 return 0;
21427}
21428
21429static int
21430set (vat_main_t * vam)
21431{
21432 u8 *name = 0, *value = 0;
21433 unformat_input_t *i = vam->input;
21434
21435 if (unformat (i, "%s", &name))
21436 {
21437 /* The input buffer is a vector, not a string. */
21438 value = vec_dup (i->buffer);
21439 vec_delete (value, i->index, 0);
21440 /* Almost certainly has a trailing newline */
21441 if (value[vec_len (value) - 1] == '\n')
21442 value[vec_len (value) - 1] = 0;
21443 /* Make sure it's a proper string, one way or the other */
21444 vec_add1 (value, 0);
21445 (void) clib_macro_set_value (&vam->macro_main,
21446 (char *) name, (char *) value);
21447 }
21448 else
21449 errmsg ("usage: set <name> <value>");
21450
21451 vec_free (name);
21452 vec_free (value);
21453 return 0;
21454}
21455
21456static int
21457unset (vat_main_t * vam)
21458{
21459 u8 *name = 0;
21460
21461 if (unformat (vam->input, "%s", &name))
21462 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
21463 errmsg ("unset: %s wasn't set", name);
21464 vec_free (name);
21465 return 0;
21466}
21467
21468typedef struct
21469{
21470 u8 *name;
21471 u8 *value;
21472} macro_sort_t;
21473
21474
21475static int
21476macro_sort_cmp (void *a1, void *a2)
21477{
21478 macro_sort_t *s1 = a1;
21479 macro_sort_t *s2 = a2;
21480
21481 return strcmp ((char *) (s1->name), (char *) (s2->name));
21482}
21483
21484static int
21485dump_macro_table (vat_main_t * vam)
21486{
21487 macro_sort_t *sort_me = 0, *sm;
21488 int i;
21489 hash_pair_t *p;
21490
21491 /* *INDENT-OFF* */
21492 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
21493 ({
21494 vec_add2 (sort_me, sm, 1);
21495 sm->name = (u8 *)(p->key);
21496 sm->value = (u8 *) (p->value[0]);
21497 }));
21498 /* *INDENT-ON* */
21499
21500 vec_sort_with_function (sort_me, macro_sort_cmp);
21501
21502 if (vec_len (sort_me))
21503 print (vam->ofp, "%-15s%s", "Name", "Value");
21504 else
21505 print (vam->ofp, "The macro table is empty...");
21506
21507 for (i = 0; i < vec_len (sort_me); i++)
21508 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
21509 return 0;
21510}
21511
21512static int
21513dump_node_table (vat_main_t * vam)
21514{
21515 int i, j;
21516 vlib_node_t *node, *next_node;
21517
21518 if (vec_len (vam->graph_nodes) == 0)
21519 {
21520 print (vam->ofp, "Node table empty, issue get_node_graph...");
21521 return 0;
21522 }
21523
Dave Barach1ddbc012018-06-13 09:26:05 -040021524 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010021525 {
Dave Barach1ddbc012018-06-13 09:26:05 -040021526 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +010021527 print (vam->ofp, "[%d] %s", i, node->name);
21528 for (j = 0; j < vec_len (node->next_nodes); j++)
21529 {
21530 if (node->next_nodes[j] != ~0)
21531 {
Dave Barach1ddbc012018-06-13 09:26:05 -040021532 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010021533 print (vam->ofp, " [%d] %s", j, next_node->name);
21534 }
21535 }
21536 }
21537 return 0;
21538}
21539
21540static int
21541value_sort_cmp (void *a1, void *a2)
21542{
21543 name_sort_t *n1 = a1;
21544 name_sort_t *n2 = a2;
21545
21546 if (n1->value < n2->value)
21547 return -1;
21548 if (n1->value > n2->value)
21549 return 1;
21550 return 0;
21551}
21552
21553
21554static int
21555dump_msg_api_table (vat_main_t * vam)
21556{
21557 api_main_t *am = &api_main;
21558 name_sort_t *nses = 0, *ns;
21559 hash_pair_t *hp;
21560 int i;
21561
21562 /* *INDENT-OFF* */
21563 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
21564 ({
21565 vec_add2 (nses, ns, 1);
21566 ns->name = (u8 *)(hp->key);
21567 ns->value = (u32) hp->value[0];
21568 }));
21569 /* *INDENT-ON* */
21570
21571 vec_sort_with_function (nses, value_sort_cmp);
21572
21573 for (i = 0; i < vec_len (nses); i++)
21574 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
21575 vec_free (nses);
21576 return 0;
21577}
21578
21579static int
21580get_msg_id (vat_main_t * vam)
21581{
21582 u8 *name_and_crc;
21583 u32 message_index;
21584
21585 if (unformat (vam->input, "%s", &name_and_crc))
21586 {
Florin Corase86a8ed2018-01-05 03:20:25 -080021587 message_index = vl_msg_api_get_msg_index (name_and_crc);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021588 if (message_index == ~0)
21589 {
21590 print (vam->ofp, " '%s' not found", name_and_crc);
21591 return 0;
21592 }
21593 print (vam->ofp, " '%s' has message index %d",
21594 name_and_crc, message_index);
21595 return 0;
21596 }
21597 errmsg ("name_and_crc required...");
21598 return 0;
21599}
21600
21601static int
21602search_node_table (vat_main_t * vam)
21603{
21604 unformat_input_t *line_input = vam->input;
21605 u8 *node_to_find;
21606 int j;
21607 vlib_node_t *node, *next_node;
21608 uword *p;
21609
21610 if (vam->graph_node_index_by_name == 0)
21611 {
21612 print (vam->ofp, "Node table empty, issue get_node_graph...");
21613 return 0;
21614 }
21615
21616 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
21617 {
21618 if (unformat (line_input, "%s", &node_to_find))
21619 {
21620 vec_add1 (node_to_find, 0);
21621 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
21622 if (p == 0)
21623 {
21624 print (vam->ofp, "%s not found...", node_to_find);
21625 goto out;
21626 }
Dave Barach1ddbc012018-06-13 09:26:05 -040021627 node = vam->graph_nodes[0][p[0]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010021628 print (vam->ofp, "[%d] %s", p[0], 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
21639 else
21640 {
21641 clib_warning ("parse error '%U'", format_unformat_error,
21642 line_input);
21643 return -99;
21644 }
21645
21646 out:
21647 vec_free (node_to_find);
21648
21649 }
21650
21651 return 0;
21652}
21653
21654
21655static int
21656script (vat_main_t * vam)
21657{
21658#if (VPP_API_TEST_BUILTIN==0)
21659 u8 *s = 0;
21660 char *save_current_file;
21661 unformat_input_t save_input;
21662 jmp_buf save_jump_buf;
21663 u32 save_line_number;
21664
21665 FILE *new_fp, *save_ifp;
21666
21667 if (unformat (vam->input, "%s", &s))
21668 {
21669 new_fp = fopen ((char *) s, "r");
21670 if (new_fp == 0)
21671 {
21672 errmsg ("Couldn't open script file %s", s);
21673 vec_free (s);
21674 return -99;
21675 }
21676 }
21677 else
21678 {
21679 errmsg ("Missing script name");
21680 return -99;
21681 }
21682
21683 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
21684 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
21685 save_ifp = vam->ifp;
21686 save_line_number = vam->input_line_number;
21687 save_current_file = (char *) vam->current_file;
21688
21689 vam->input_line_number = 0;
21690 vam->ifp = new_fp;
21691 vam->current_file = s;
21692 do_one_file (vam);
21693
Sirshak Dasb0861822018-05-29 21:13:21 -050021694 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
Damjan Marion7cd468a2016-12-19 23:05:39 +010021695 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
21696 vam->ifp = save_ifp;
21697 vam->input_line_number = save_line_number;
21698 vam->current_file = (u8 *) save_current_file;
21699 vec_free (s);
21700
21701 return 0;
21702#else
21703 clib_warning ("use the exec command...");
21704 return -99;
21705#endif
21706}
21707
21708static int
21709echo (vat_main_t * vam)
21710{
21711 print (vam->ofp, "%v", vam->input->buffer);
21712 return 0;
21713}
21714
21715/* List of API message constructors, CLI names map to api_xxx */
21716#define foreach_vpe_api_msg \
Jon Loeligerc83c3b72017-02-23 13:57:35 -060021717_(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021718_(sw_interface_dump,"") \
21719_(sw_interface_set_flags, \
21720 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
21721_(sw_interface_add_del_address, \
21722 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
Stevenad8015b2017-10-29 22:10:46 -070021723_(sw_interface_set_rx_mode, \
21724 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +020021725_(sw_interface_set_rx_placement, \
21726 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +020021727_(sw_interface_rx_placement_dump, \
21728 "[<intfc> | sw_if_index <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021729_(sw_interface_set_table, \
21730 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
21731_(sw_interface_set_mpls_enable, \
21732 "<intfc> | sw_if_index [disable | dis]") \
21733_(sw_interface_set_vpath, \
21734 "<intfc> | sw_if_index <id> enable | disable") \
21735_(sw_interface_set_vxlan_bypass, \
John Lo2b81eb82017-01-30 13:12:10 -050021736 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020021737_(sw_interface_set_geneve_bypass, \
21738 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021739_(sw_interface_set_l2_xconnect, \
21740 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
21741 "enable | disable") \
21742_(sw_interface_set_l2_bridge, \
Eyal Barif24991c2017-04-05 05:33:21 +030021743 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021744 "[shg <split-horizon-group>] [bvi]\n" \
21745 "enable | disable") \
Eyal Barif24991c2017-04-05 05:33:21 +030021746_(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021747_(bridge_domain_add_del, \
John Lo70bfcaf2017-11-14 13:19:26 -050021748 "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 +010021749_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
21750_(l2fib_add_del, \
21751 "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 +030021752_(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
21753_(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021754_(l2_flags, \
John Lo8d00fff2017-08-03 00:35:36 -040021755 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021756_(bridge_flags, \
21757 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion8389fb92017-10-13 18:29:53 +020021758_(tap_create_v2, \
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020021759 "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 +020021760_(tap_delete_v2, \
21761 "<vpp-if-name> | sw_if_index <id>") \
21762_(sw_interface_tap_v2_dump, "") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010021763_(virtio_pci_create, \
Mohsin Kazmibbd6b742019-05-02 13:54:59 +020021764 "pci-addr <pci-address> [use_random_mac | hw-addr <mac-addr>] [features <hex-value>] [gso-enabled]") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010021765_(virtio_pci_delete, \
21766 "<vpp-if-name> | sw_if_index <id>") \
21767_(sw_interface_virtio_pci_dump, "") \
Steven9cd2d7a2017-12-20 12:43:01 -080021768_(bond_create, \
21769 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
Alexander Chernavinad9d5282018-12-13 09:08:09 -050021770 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
Steven Luonga1876b82019-08-20 16:58:00 -070021771 "[id <if-id>]") \
Steven9cd2d7a2017-12-20 12:43:01 -080021772_(bond_delete, \
21773 "<vpp-if-name> | sw_if_index <id>") \
21774_(bond_enslave, \
Steven Luonga1876b82019-08-20 16:58:00 -070021775 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
Steven9cd2d7a2017-12-20 12:43:01 -080021776_(bond_detach_slave, \
21777 "sw_if_index <n>") \
Steven Luonga1876b82019-08-20 16:58:00 -070021778 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
Steven9cd2d7a2017-12-20 12:43:01 -080021779_(sw_interface_bond_dump, "") \
21780_(sw_interface_slave_dump, \
21781 "<vpp-if-name> | sw_if_index <id>") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070021782_(ip_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040021783 "table <n> [ipv6] [add | del]\n") \
Neale Ranns097fa662018-05-01 05:17:55 -070021784_(ip_route_add_del, \
John Lo22030432018-09-20 16:07:00 -040021785 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
21786 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
John Lo06fda9c2018-10-03 16:32:44 -040021787 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
21788 "[multipath] [count <n>] [del]") \
Neale Ranns32e1c012016-11-22 17:07:28 +000021789_(ip_mroute_add_del, \
21790 "<src> <grp>/<mask> [table-id <n>]\n" \
21791 "[<intfc> | sw_if_index <id>] [local] [del]") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070021792_(mpls_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040021793 "table <n> [add | del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021794_(mpls_route_add_del, \
John Loe166fd92018-09-13 14:08:59 -040021795 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
21796 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
21797 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
21798 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
John Lo06fda9c2018-10-03 16:32:44 -040021799 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
21800 "[count <n>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021801_(mpls_ip_bind_unbind, \
21802 "<label> <addr/len>") \
21803_(mpls_tunnel_add_del, \
John Lo06fda9c2018-10-03 16:32:44 -040021804 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
21805 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
21806 "[l2-only] [out-label <n>]") \
John Loe166fd92018-09-13 14:08:59 -040021807_(sr_mpls_policy_add, \
21808 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
21809_(sr_mpls_policy_del, \
21810 "bsid <id>") \
Neale Rannsd792d9c2017-10-21 10:53:20 -070021811_(bier_table_add_del, \
21812 "<label> <sub-domain> <set> <bsl> [del]") \
21813_(bier_route_add_del, \
21814 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
21815 "[<intfc> | sw_if_index <id>]" \
21816 "[weight <n>] [del] [multipath]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021817_(proxy_arp_add_del, \
21818 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
21819_(proxy_arp_intfc_enable_disable, \
21820 "<intfc> | sw_if_index <id> enable | disable") \
21821_(sw_interface_set_unnumbered, \
21822 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
21823_(ip_neighbor_add_del, \
21824 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
21825 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021826_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
21827_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
21828 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
21829 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
21830 "[outer_vlan_id_any][inner_vlan_id_any]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021831_(reset_fib, "vrf <n> [ipv6]") \
21832_(dhcp_proxy_config, \
21833 "svr <v46-address> src <v46-address>\n" \
Neale Ranns20a175a2017-02-14 07:28:41 -080021834 "rx_vrf_id <nn> server_vrf_id <nn> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021835_(dhcp_proxy_set_vss, \
John Lo70bfcaf2017-11-14 13:19:26 -050021836 "tbl_id <n> [fib_id <n> oui <n> | vpn_ascii_id <text>] [ipv6] [del]") \
Neale Ranns20a175a2017-02-14 07:28:41 -080021837_(dhcp_proxy_dump, "ip6") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021838_(dhcp_client_config, \
21839 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
21840_(set_ip_flow_hash, \
21841 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
21842_(sw_interface_ip6_enable_disable, \
21843 "<intfc> | sw_if_index <id> enable | disable") \
Neale Ranns3f844d02017-02-18 00:03:54 -080021844_(ip6nd_proxy_add_del, \
21845 "<intfc> | sw_if_index <id> <ip6-address>") \
21846_(ip6nd_proxy_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021847_(sw_interface_ip6nd_ra_prefix, \
21848 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
21849 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
21850 "[nolink] [isno]") \
21851_(sw_interface_ip6nd_ra_config, \
21852 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
21853 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
21854 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
21855_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
21856_(l2_patch_add_del, \
21857 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
21858 "enable | disable") \
Pablo Camarillofb380952016-12-07 18:34:18 +010021859_(sr_localsid_add_del, \
21860 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
21861 "fib-table <num> (end.psp) sw_if_index <num>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021862_(classify_add_del_table, \
21863 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
21864 " [del] [del-chain] mask <mask-value>\n" \
21865 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
21866 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
21867_(classify_add_del_session, \
21868 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
21869 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
21870 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
21871 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
21872_(classify_set_interface_ip_table, \
21873 "<intfc> | sw_if_index <nn> table <nn>") \
21874_(classify_set_interface_l2_tables, \
21875 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
21876 " [other-table <nn>]") \
21877_(get_node_index, "node <node-name") \
21878_(add_node_next, "node <node-name> next <next-node-name>") \
21879_(l2tpv3_create_tunnel, \
21880 "client_address <ip6-addr> our_address <ip6-addr>\n" \
21881 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n" \
21882 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
21883_(l2tpv3_set_tunnel_cookies, \
21884 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
21885 "[new_remote_cookie <nn>]\n") \
21886_(l2tpv3_interface_enable_disable, \
21887 "<intfc> | sw_if_index <nn> enable | disable") \
21888_(l2tpv3_set_lookup_key, \
21889 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
21890_(sw_if_l2tpv3_tunnel_dump, "") \
eyal bariaf86a482018-04-17 11:20:27 +030021891_(vxlan_offload_rx, \
21892 "hw { <interface name> | hw_if_index <nn>} " \
21893 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021894_(vxlan_add_del_tunnel, \
21895 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
Jon Loeliger3d460bd2018-02-01 16:36:12 -060021896 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021897 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020021898_(geneve_add_del_tunnel, \
21899 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
21900 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
21901 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021902_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020021903_(geneve_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Neale Ranns5a8844b2019-04-16 07:15:35 +000021904_(gre_tunnel_add_del, \
John Loa43ccae2018-02-13 17:15:23 -050021905 "src <ip-addr> dst <ip-addr> [outer-fib-id <nn>] [instance <n>]\n" \
21906 "[teb | erspan <session-id>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021907_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
21908_(l2_fib_clear_table, "") \
21909_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
21910_(l2_interface_vlan_tag_rewrite, \
21911 "<intfc> | sw_if_index <nn> \n" \
21912 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
21913 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
21914_(create_vhost_user_if, \
21915 "socket <filename> [server] [renumber <dev_instance>] " \
Steven Luong4208a4c2019-05-06 08:51:56 -070021916 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
Stevenf3b53642017-05-01 14:03:02 -070021917 "[mac <mac_address>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021918_(modify_vhost_user_if, \
21919 "<intfc> | sw_if_index <nn> socket <filename>\n" \
Steven Luong4208a4c2019-05-06 08:51:56 -070021920 "[server] [renumber <dev_instance>] [gso]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021921_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
21922_(sw_interface_vhost_user_dump, "") \
21923_(show_version, "") \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020021924_(show_threads, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021925_(vxlan_gpe_add_del_tunnel, \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080021926 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
21927 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
21928 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
21929 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021930_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
21931_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
21932_(interface_name_renumber, \
21933 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
21934_(input_acl_set_interface, \
21935 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
21936 " [l2-table <nn>] [del]") \
John Loc7b43042018-04-13 16:46:22 -040021937_(ip_probe_neighbor, "(<intc> | sw_if_index <nn>) address <ip4|ip6-addr>") \
John Lo7f358b32018-04-28 01:19:24 -040021938_(ip_scan_neighbor_enable_disable, "[ip4|ip6|both|disable] [interval <n-min>]\n" \
21939 " [max-time <n-usec>] [max-update <n>] [delay <n-msec>] [stale <n-min>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021940_(want_ip4_arp_events, "address <ip4-address> [del]") \
21941_(want_ip6_nd_events, "address <ip6-address> [del]") \
John Lo8d00fff2017-08-03 00:35:36 -040021942_(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021943_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
21944_(ip_dump, "ipv4 | ipv6") \
21945_(ipsec_spd_add_del, "spd_id <n> [del]") \
21946_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
21947 " spid_id <n> ") \
Neale Ranns17dcec02019-01-09 21:22:20 -080021948_(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021949 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
21950 " integ_alg <alg> integ_key <hex>") \
Neale Ranns17dcec02019-01-09 21:22:20 -080021951_(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021952 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
21953 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
21954 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
Matthew Smithb0972cb2017-05-02 16:20:41 -050021955_(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
21956 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
21957 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
Matthew Smith8e1039a2018-04-12 07:32:56 -050021958 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
21959 " [instance <n>]") \
Matthew Smith28029532017-09-26 13:33:44 -050021960_(ipsec_sa_dump, "[sa_id <n>]") \
Matthew Smithca514fd2017-10-12 12:06:59 -050021961_(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021962_(delete_loopback,"sw_if_index <nn>") \
21963_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
John Loe26c81f2019-01-07 15:16:33 -050021964_(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
21965_(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021966_(want_interface_events, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021967_(get_first_msg_id, "client <name>") \
21968_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
21969_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
21970 "fib-id <nn> [ip4][ip6][default]") \
21971_(get_node_graph, " ") \
21972_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
21973_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
21974_(ioam_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010021975_(one_add_del_locator_set, "locator-set <locator_name> [iface <intf> |" \
21976 " sw_if_index <sw_if_index> p <priority> " \
21977 "w <weight>] [del]") \
21978_(one_add_del_locator, "locator-set <locator_name> " \
21979 "iface <intf> | sw_if_index <sw_if_index> " \
21980 "p <priority> w <weight> [del]") \
21981_(one_add_del_local_eid,"vni <vni> eid " \
21982 "<ipv4|ipv6>/<prefix> | <L2 address> " \
21983 "locator-set <locator_name> [del]" \
21984 "[key-id sha1|sha256 secret-key <secret-key>]")\
21985_(one_add_del_map_resolver, "<ip4|6-addr> [del]") \
21986_(one_add_del_map_server, "<ip4|6-addr> [del]") \
21987_(one_enable_disable, "enable|disable") \
21988_(one_map_register_enable_disable, "enable|disable") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020021989_(one_map_register_fallback_threshold, "<value>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010021990_(one_rloc_probe_enable_disable, "enable|disable") \
21991_(one_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
21992 "[seid <seid>] " \
21993 "rloc <locator> p <prio> " \
21994 "w <weight> [rloc <loc> ... ] " \
21995 "action <action> [del-all]") \
21996_(one_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
21997 "<local-eid>") \
21998_(one_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010021999_(one_use_petr, "ip-address> | disable") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022000_(one_map_request_mode, "src-dst|dst-only") \
22001_(one_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
22002_(one_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
22003_(one_locator_set_dump, "[local | remote]") \
22004_(one_locator_dump, "ls_index <index> | ls_name <name>") \
22005_(one_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
22006 "[local] | [remote]") \
Filip Tehlar05879992017-09-05 15:46:09 +020022007_(one_add_del_ndp_entry, "[del] mac <mac> bd <bd> ip6 <ip6>") \
22008_(one_ndp_bd_get, "") \
22009_(one_ndp_entries_get, "bd <bridge-domain>") \
Filip Tehlard5a65db2017-05-17 17:21:10 +020022010_(one_add_del_l2_arp_entry, "[del] mac <mac> bd <bd> ip4 <ip4>") \
22011_(one_l2_arp_bd_get, "") \
22012_(one_l2_arp_entries_get, "bd <bridge-domain>") \
Paul Vinciguerraec11b132018-09-24 05:25:00 -070022013_(one_stats_enable_disable, "enable|disable") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010022014_(show_one_stats_enable_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022015_(one_eid_table_vni_dump, "") \
22016_(one_eid_table_map_dump, "l2|l3") \
22017_(one_map_resolver_dump, "") \
22018_(one_map_server_dump, "") \
22019_(one_adjacencies_get, "vni <vni>") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020022020_(one_nsh_set_locator_set, "[del] ls <locator-set-name>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022021_(show_one_rloc_probe_state, "") \
22022_(show_one_map_register_state, "") \
22023_(show_one_status, "") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010022024_(one_stats_dump, "") \
Filip Tehlar21511912017-04-07 10:41:42 +020022025_(one_stats_flush, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022026_(one_get_map_request_itr_rlocs, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020022027_(one_map_register_set_ttl, "<ttl>") \
Filip Tehlara4980b82017-09-27 14:32:02 +020022028_(one_set_transport_protocol, "udp|api") \
22029_(one_get_transport_protocol, "") \
Filip Tehlar0a8840d2017-10-16 05:48:23 -070022030_(one_enable_disable_xtr_mode, "enable|disable") \
22031_(one_show_xtr_mode, "") \
22032_(one_enable_disable_pitr_mode, "enable|disable") \
22033_(one_show_pitr_mode, "") \
22034_(one_enable_disable_petr_mode, "enable|disable") \
22035_(one_show_petr_mode, "") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020022036_(show_one_nsh_mapping, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022037_(show_one_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010022038_(show_one_use_petr, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022039_(show_one_map_request_mode, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020022040_(show_one_map_register_ttl, "") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020022041_(show_one_map_register_fallback_threshold, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010022042_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
Damjan Marion7cd468a2016-12-19 23:05:39 +010022043 " sw_if_index <sw_if_index> p <priority> " \
22044 "w <weight>] [del]") \
22045_(lisp_add_del_locator, "locator-set <locator_name> " \
22046 "iface <intf> | sw_if_index <sw_if_index> " \
22047 "p <priority> w <weight> [del]") \
22048_(lisp_add_del_local_eid,"vni <vni> eid " \
22049 "<ipv4|ipv6>/<prefix> | <L2 address> " \
22050 "locator-set <locator_name> [del]" \
22051 "[key-id sha1|sha256 secret-key <secret-key>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022052_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
22053_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022054_(lisp_enable_disable, "enable|disable") \
22055_(lisp_map_register_enable_disable, "enable|disable") \
22056_(lisp_rloc_probe_enable_disable, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022057_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
22058 "[seid <seid>] " \
22059 "rloc <locator> p <prio> " \
22060 "w <weight> [rloc <loc> ... ] " \
22061 "action <action> [del-all]") \
22062_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
22063 "<local-eid>") \
22064_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010022065_(lisp_use_petr, "<ip-address> | disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022066_(lisp_map_request_mode, "src-dst|dst-only") \
22067_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
22068_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
22069_(lisp_locator_set_dump, "[local | remote]") \
22070_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
22071_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
22072 "[local] | [remote]") \
22073_(lisp_eid_table_vni_dump, "") \
22074_(lisp_eid_table_map_dump, "l2|l3") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022075_(lisp_map_resolver_dump, "") \
22076_(lisp_map_server_dump, "") \
22077_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar0eb874e2017-05-18 14:23:32 +020022078_(gpe_fwd_entry_vnis_get, "") \
Filip Tehlarb4243aa2017-06-14 14:39:42 +020022079_(gpe_native_fwd_rpaths_get, "ip4 | ip6") \
22080_(gpe_add_del_native_fwd_rpath, "[del] via <nh-ip-addr> [iface] " \
22081 "[table <table-id>]") \
Filip Tehlar5fae99c2017-01-18 12:57:37 +010022082_(lisp_gpe_fwd_entries_get, "vni <vni>") \
22083_(lisp_gpe_fwd_entry_path_dump, "index <fwd_entry_index>") \
Filip Tehlar3e7b56932017-02-21 18:28:34 +010022084_(gpe_set_encap_mode, "lisp|vxlan") \
22085_(gpe_get_encap_mode, "") \
Filip Tehlar82786c42017-02-20 15:20:37 +010022086_(lisp_gpe_add_del_iface, "up|down") \
22087_(lisp_gpe_enable_disable, "enable|disable") \
22088_(lisp_gpe_add_del_fwd_entry, "reid <eid> [leid <eid>] vni <vni>" \
22089 "vrf/bd <dp_table> loc-pair <lcl_loc> <rmt_loc> w <weight>... [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022090_(show_lisp_rloc_probe_state, "") \
22091_(show_lisp_map_register_state, "") \
22092_(show_lisp_status, "") \
22093_(lisp_get_map_request_itr_rlocs, "") \
22094_(show_lisp_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010022095_(show_lisp_use_petr, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022096_(show_lisp_map_request_mode, "") \
22097_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
22098_(af_packet_delete, "name <host interface name>") \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020022099_(af_packet_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022100_(policer_add_del, "name <policer name> <params> [del]") \
22101_(policer_dump, "[name <policer name>]") \
22102_(policer_classify_set_interface, \
22103 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
22104 " [l2-table <nn>] [del]") \
22105_(policer_classify_dump, "type [ip4|ip6|l2]") \
22106_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
22107 "[master|slave]") \
22108_(netmap_delete, "name <interface name>") \
22109_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns097fa662018-05-01 05:17:55 -070022110_(mpls_table_dump, "") \
22111_(mpls_route_dump, "table-id <ID>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022112_(classify_table_ids, "") \
22113_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
22114_(classify_table_info, "table_id <nn>") \
22115_(classify_session_dump, "table_id <nn>") \
22116_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
22117 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
22118 "[template_interval <nn>] [udp_checksum]") \
22119_(ipfix_exporter_dump, "") \
22120_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
22121_(ipfix_classify_stream_dump, "") \
22122_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
22123_(ipfix_classify_table_dump, "") \
Eyal Bari001fd402017-07-16 09:34:53 +030022124_(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 +030022125_(sw_interface_span_dump, "[l2]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022126_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020022127_(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022128_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
22129_(pg_enable_disable, "[stream <id>] disable") \
22130_(ip_source_and_port_range_check_add_del, \
22131 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
22132_(ip_source_and_port_range_check_interface_add_del, \
22133 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
22134 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022135_(delete_subif,"<intfc> | sw_if_index <nn>") \
22136_(l2_interface_pbb_tag_rewrite, \
22137 "<intfc> | sw_if_index <nn> \n" \
22138 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
22139 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Pavel Kotuceke88865d2018-11-28 07:42:11 +010022140_(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022141_(flow_classify_set_interface, \
22142 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
22143_(flow_classify_dump, "type [ip4|ip6]") \
Neale Ranns097fa662018-05-01 05:17:55 -070022144_(ip_table_dump, "") \
22145_(ip_route_dump, "table-id [ip4|ip6]") \
22146_(ip_mtable_dump, "") \
22147_(ip_mroute_dump, "table-id [ip4|ip6]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022148_(feature_enable_disable, "arc_name <arc_name> " \
22149 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
22150_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
22151"[disable]") \
22152_(l2_xconnect_dump, "") \
Ole Troand7231612018-06-07 10:17:57 +020022153_(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022154_(ip_neighbor_dump, "[ip6] <intfc> | sw_if_index <nn>") \
Pavel Kotucek6899a302017-06-08 08:46:10 +020022155_(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020022156_(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
Steve Shin99a0e602017-07-01 04:16:20 +000022157_(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020022158_(lldp_config, "system-name <name> tx-hold <nn> tx-interval <nn>") \
Steve Shin9a6fcef2017-10-11 13:55:16 -070022159_(sw_interface_set_lldp, "<intfc> | sw_if_index <nn> [port-desc <description>]\n" \
22160 " [mgmt-ip4 <ip4>] [mgmt-ip6 <ip6>] [mgmt-oid <object id>] [disable]") \
Dave Barach59b25652017-09-10 15:04:27 -040022161_(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
Florin Coras90a63982017-12-19 04:50:01 -080022162_(sock_init_shm, "size <nnn>") \
Florin Corascea194d2017-10-02 00:18:51 -070022163_(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
Florin Coras1c710452017-10-17 00:03:13 -070022164_(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
22165 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
Florin Coras6c36f532017-11-03 18:32:34 -070022166_(session_rules_dump, "") \
Florin Coras595992c2017-11-06 17:17:08 -080022167_(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010022168_(output_acl_set_interface, \
22169 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
22170 " [l2-table <nn>] [del]") \
Ole Troane906aac2018-06-14 14:42:14 +020022171_(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
Damjan Marion7cd468a2016-12-19 23:05:39 +010022172
22173/* List of command functions, CLI names map directly to functions */
22174#define foreach_cli_function \
22175_(comment, "usage: comment <ignore-rest-of-line>") \
22176_(dump_interface_table, "usage: dump_interface_table") \
22177_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
22178_(dump_ipv4_table, "usage: dump_ipv4_table") \
22179_(dump_ipv6_table, "usage: dump_ipv6_table") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022180_(dump_macro_table, "usage: dump_macro_table ") \
22181_(dump_node_table, "usage: dump_node_table") \
22182_(dump_msg_api_table, "usage: dump_msg_api_table") \
Dave Barachb09f4d02019-07-15 16:00:03 -040022183_(elog_setup, "usage: elog_setup [nevents, default 128K]") \
22184_(elog_disable, "usage: elog_disable") \
22185_(elog_enable, "usage: elog_enable") \
22186_(elog_save, "usage: elog_save <filename>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022187_(get_msg_id, "usage: get_msg_id name_and_crc") \
22188_(echo, "usage: echo <message>") \
22189_(exec, "usage: exec <vpe-debug-CLI-command>") \
22190_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
22191_(help, "usage: help") \
22192_(q, "usage: quit") \
22193_(quit, "usage: quit") \
22194_(search_node_table, "usage: search_node_table <name>...") \
22195_(set, "usage: set <variable-name> <value>") \
22196_(script, "usage: script <file-name>") \
Neale Ranns097fa662018-05-01 05:17:55 -070022197_(statseg, "usage: statseg") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022198_(unset, "usage: unset <variable-name>")
Dave Barach048a4e52018-06-01 18:52:25 -040022199
Damjan Marion7cd468a2016-12-19 23:05:39 +010022200#define _(N,n) \
22201 static void vl_api_##n##_t_handler_uni \
22202 (vl_api_##n##_t * mp) \
22203 { \
22204 vat_main_t * vam = &vat_main; \
22205 if (vam->json_output) { \
22206 vl_api_##n##_t_handler_json(mp); \
22207 } else { \
22208 vl_api_##n##_t_handler(mp); \
22209 } \
22210 }
22211foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050022212#if VPP_API_TEST_BUILTIN == 0
22213foreach_standalone_reply_msg;
22214#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010022215#undef _
22216
22217void
22218vat_api_hookup (vat_main_t * vam)
22219{
22220#define _(N,n) \
22221 vl_msg_api_set_handlers(VL_API_##N, #n, \
22222 vl_api_##n##_t_handler_uni, \
22223 vl_noop_handler, \
22224 vl_api_##n##_t_endian, \
22225 vl_api_##n##_t_print, \
22226 sizeof(vl_api_##n##_t), 1);
22227 foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050022228#if VPP_API_TEST_BUILTIN == 0
22229 foreach_standalone_reply_msg;
22230#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010022231#undef _
22232
22233#if (VPP_API_TEST_BUILTIN==0)
22234 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Damjan Marion7cd468a2016-12-19 23:05:39 +010022235
22236 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
22237
22238 vam->function_by_name = hash_create_string (0, sizeof (uword));
22239
22240 vam->help_by_name = hash_create_string (0, sizeof (uword));
Dave Barach45e4f362017-03-07 12:52:31 -050022241#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010022242
22243 /* API messages we can send */
22244#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
22245 foreach_vpe_api_msg;
22246#undef _
22247
22248 /* Help strings */
22249#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
22250 foreach_vpe_api_msg;
22251#undef _
Damjan Marion7cd468a2016-12-19 23:05:39 +010022252
22253 /* CLI functions */
22254#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
22255 foreach_cli_function;
22256#undef _
22257
22258 /* Help strings */
22259#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
22260 foreach_cli_function;
22261#undef _
22262}
22263
Dave Baracha1a093d2017-03-02 13:13:23 -050022264#if VPP_API_TEST_BUILTIN
22265static clib_error_t *
22266vat_api_hookup_shim (vlib_main_t * vm)
22267{
22268 vat_api_hookup (&vat_main);
22269 return 0;
22270}
22271
22272VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
22273#endif
22274
Damjan Marion7cd468a2016-12-19 23:05:39 +010022275/*
22276 * fd.io coding-style-patch-verification: ON
22277 *
22278 * Local Variables:
22279 * eval: (c-set-style "gnu")
22280 * End:
22281 */