blob: 803daafac19695b728f6f8fa29b16a0d1d8608ec [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>
Neale Rannscbe25aa2019-09-30 10:53:31 +000027#include <vnet/ip-neighbor/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>
Steven9cd2d7a2017-12-20 12:43:01 -080054#include <vnet/bonding/node.h>
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070055#include <vnet/qos/qos_types.h>
Neale Ranns37029302018-08-10 05:30:06 -070056#include <vnet/ethernet/ethernet_types_api.h>
57#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010058#include "vat/json_format.h"
Neale Ranns86327be2018-11-02 09:14:01 -070059#include <vnet/ip/ip_types_api.h>
60#include <vnet/ethernet/ethernet_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010061
62#include <inttypes.h>
63#include <sys/stat.h>
64
65#define vl_typedefs /* define message structures */
66#include <vpp/api/vpe_all_api_h.h>
67#undef vl_typedefs
68
69/* declare message handlers for each api */
70
71#define vl_endianfun /* define message structures */
72#include <vpp/api/vpe_all_api_h.h>
73#undef vl_endianfun
74
75/* instantiate all the print functions we know about */
Dave Barachf35a0722019-06-12 16:50:38 -040076#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010077#define vl_print(handle, ...)
Dave Barachf35a0722019-06-12 16:50:38 -040078#else
79#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
80#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010081#define vl_printfun
82#include <vpp/api/vpe_all_api_h.h>
83#undef vl_printfun
84
Dave Barach2d6b2d62017-01-25 16:32:08 -050085#define __plugin_msg_base 0
Dave Barachfe6bdfd2017-01-20 19:50:09 -050086#include <vlibapi/vat_helper_macros.h>
87
Ole Troan33a58172019-09-04 09:12:29 +020088#include <vnet/format_fns.h>
89
Dave Barachb09f4d02019-07-15 16:00:03 -040090void vl_api_set_elog_main (elog_main_t * m);
91int vl_api_set_elog_trace_api_messages (int enable);
92
Dave Barach59b25652017-09-10 15:04:27 -040093#if VPP_API_TEST_BUILTIN == 0
94#include <netdb.h>
95
96u32
97vl (void *p)
98{
99 return vec_len (p);
100}
101
102int
103vat_socket_connect (vat_main_t * vam)
104{
Florin Coras66a10032018-12-21 16:23:09 -0800105 int rv;
Florin Coras90a63982017-12-19 04:50:01 -0800106 vam->socket_client_main = &socket_client_main;
Florin Coras66a10032018-12-21 16:23:09 -0800107 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
108 "vpp_api_test",
109 0 /* default socket rx, tx buffer */ )))
110 return rv;
111 /* vpp expects the client index in network order */
112 vam->my_client_index = htonl (socket_client_main.client_index);
113 return 0;
Dave Barach59b25652017-09-10 15:04:27 -0400114}
115#else /* vpp built-in case, we don't do sockets... */
116int
117vat_socket_connect (vat_main_t * vam)
118{
119 return 0;
120}
121
Florin Coras90a63982017-12-19 04:50:01 -0800122int
123vl_socket_client_read (int wait)
Dave Barach59b25652017-09-10 15:04:27 -0400124{
Florin Coras90a63982017-12-19 04:50:01 -0800125 return -1;
Dave Barach59b25652017-09-10 15:04:27 -0400126};
Florin Coras90a63982017-12-19 04:50:01 -0800127
128int
129vl_socket_client_write ()
130{
131 return -1;
132};
133
134void *
135vl_socket_client_msg_alloc (int nbytes)
136{
137 return 0;
138}
Dave Barach59b25652017-09-10 15:04:27 -0400139#endif
140
141
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500142f64
143vat_time_now (vat_main_t * vam)
144{
145#if VPP_API_TEST_BUILTIN
146 return vlib_time_now (vam->vlib_main);
147#else
148 return clib_time_now (&vam->clib_time);
149#endif
150}
151
152void
153errmsg (char *fmt, ...)
154{
155 vat_main_t *vam = &vat_main;
156 va_list va;
157 u8 *s;
158
159 va_start (va, fmt);
160 s = va_format (0, fmt, &va);
161 va_end (va);
162
163 vec_add1 (s, 0);
164
165#if VPP_API_TEST_BUILTIN
166 vlib_cli_output (vam->vlib_main, (char *) s);
167#else
168 {
169 if (vam->ifp != stdin)
170 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
171 vam->input_line_number);
Dave Barachb09f4d02019-07-15 16:00:03 -0400172 else
173 fformat (vam->ofp, "%s\n", (char *) s);
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500174 fflush (vam->ofp);
175 }
176#endif
177
178 vec_free (s);
179}
180
Dave Barach4a3f69c2017-02-22 12:44:56 -0500181#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +0100182static uword
183api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
184{
185 vat_main_t *vam = va_arg (*args, vat_main_t *);
186 u32 *result = va_arg (*args, u32 *);
187 u8 *if_name;
188 uword *p;
189
190 if (!unformat (input, "%s", &if_name))
191 return 0;
192
193 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
194 if (p == 0)
195 return 0;
196 *result = p[0];
197 return 1;
198}
199
eyal bariaf86a482018-04-17 11:20:27 +0300200static uword
201api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
202{
203 return 0;
204}
205
Damjan Marion7cd468a2016-12-19 23:05:39 +0100206/* Parse an IP4 address %d.%d.%d.%d. */
207uword
208unformat_ip4_address (unformat_input_t * input, va_list * args)
209{
210 u8 *result = va_arg (*args, u8 *);
211 unsigned a[4];
212
213 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
214 return 0;
215
216 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
217 return 0;
218
219 result[0] = a[0];
220 result[1] = a[1];
221 result[2] = a[2];
222 result[3] = a[3];
223
224 return 1;
225}
226
227uword
228unformat_ethernet_address (unformat_input_t * input, va_list * args)
229{
230 u8 *result = va_arg (*args, u8 *);
231 u32 i, a[6];
232
233 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
234 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
235 return 0;
236
237 /* Check range. */
238 for (i = 0; i < 6; i++)
239 if (a[i] >= (1 << 8))
240 return 0;
241
242 for (i = 0; i < 6; i++)
243 result[i] = a[i];
244
245 return 1;
246}
247
248/* Returns ethernet type as an int in host byte order. */
249uword
250unformat_ethernet_type_host_byte_order (unformat_input_t * input,
251 va_list * args)
252{
253 u16 *result = va_arg (*args, u16 *);
254 int type;
255
256 /* Numeric type. */
257 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
258 {
259 if (type >= (1 << 16))
260 return 0;
261 *result = type;
262 return 1;
263 }
264 return 0;
265}
266
Jakub Grajciar23a386b2020-02-26 11:01:43 +0100267/* Parse an IP46 address. */
268uword
269unformat_ip46_address (unformat_input_t * input, va_list * args)
270{
271 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
272 ip46_type_t type = va_arg (*args, ip46_type_t);
273 if ((type != IP46_TYPE_IP6) &&
274 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
275 {
276 ip46_address_mask_ip4 (ip46);
277 return 1;
278 }
279 else if ((type != IP46_TYPE_IP4) &&
280 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
281 {
282 return 1;
283 }
284 return 0;
285}
286
Damjan Marion7cd468a2016-12-19 23:05:39 +0100287/* Parse an IP6 address. */
288uword
289unformat_ip6_address (unformat_input_t * input, va_list * args)
290{
291 ip6_address_t *result = va_arg (*args, ip6_address_t *);
292 u16 hex_quads[8];
293 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
294 uword c, n_colon, double_colon_index;
295
296 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
297 double_colon_index = ARRAY_LEN (hex_quads);
298 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
299 {
300 hex_digit = 16;
301 if (c >= '0' && c <= '9')
302 hex_digit = c - '0';
303 else if (c >= 'a' && c <= 'f')
304 hex_digit = c + 10 - 'a';
305 else if (c >= 'A' && c <= 'F')
306 hex_digit = c + 10 - 'A';
307 else if (c == ':' && n_colon < 2)
308 n_colon++;
309 else
310 {
311 unformat_put_input (input);
312 break;
313 }
314
315 /* Too many hex quads. */
316 if (n_hex_quads >= ARRAY_LEN (hex_quads))
317 return 0;
318
319 if (hex_digit < 16)
320 {
321 hex_quad = (hex_quad << 4) | hex_digit;
322
323 /* Hex quad must fit in 16 bits. */
324 if (n_hex_digits >= 4)
325 return 0;
326
327 n_colon = 0;
328 n_hex_digits++;
329 }
330
331 /* Save position of :: */
332 if (n_colon == 2)
333 {
334 /* More than one :: ? */
335 if (double_colon_index < ARRAY_LEN (hex_quads))
336 return 0;
337 double_colon_index = n_hex_quads;
338 }
339
340 if (n_colon > 0 && n_hex_digits > 0)
341 {
342 hex_quads[n_hex_quads++] = hex_quad;
343 hex_quad = 0;
344 n_hex_digits = 0;
345 }
346 }
347
348 if (n_hex_digits > 0)
349 hex_quads[n_hex_quads++] = hex_quad;
350
351 {
352 word i;
353
354 /* Expand :: to appropriate number of zero hex quads. */
355 if (double_colon_index < ARRAY_LEN (hex_quads))
356 {
357 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
358
359 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
360 hex_quads[n_zero + i] = hex_quads[i];
361
362 for (i = 0; i < n_zero; i++)
363 hex_quads[double_colon_index + i] = 0;
364
365 n_hex_quads = ARRAY_LEN (hex_quads);
366 }
367
368 /* Too few hex quads given. */
369 if (n_hex_quads < ARRAY_LEN (hex_quads))
370 return 0;
371
372 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
373 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
374
375 return 1;
376 }
377}
378
379uword
380unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
381{
382 u32 *r = va_arg (*args, u32 *);
383
384 if (0);
385#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
386 foreach_ipsec_policy_action
387#undef _
388 else
389 return 0;
390 return 1;
391}
392
Damjan Marion7cd468a2016-12-19 23:05:39 +0100393u8 *
394format_ipsec_crypto_alg (u8 * s, va_list * args)
395{
396 u32 i = va_arg (*args, u32);
397 u8 *t = 0;
398
399 switch (i)
400 {
401#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
402 foreach_ipsec_crypto_alg
403#undef _
404 default:
405 return format (s, "unknown");
406 }
407 return format (s, "%s", t);
408}
409
Damjan Marion7cd468a2016-12-19 23:05:39 +0100410u8 *
411format_ipsec_integ_alg (u8 * s, va_list * args)
412{
413 u32 i = va_arg (*args, u32);
414 u8 *t = 0;
415
416 switch (i)
417 {
418#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
419 foreach_ipsec_integ_alg
420#undef _
421 default:
422 return format (s, "unknown");
423 }
424 return format (s, "%s", t);
425}
426
Dave Barach4a3f69c2017-02-22 12:44:56 -0500427#else /* VPP_API_TEST_BUILTIN == 1 */
428static uword
429api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
430{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200431 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500432 vnet_main_t *vnm = vnet_get_main ();
433 u32 *result = va_arg (*args, u32 *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500434
eyal bariaf86a482018-04-17 11:20:27 +0300435 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500436}
eyal bariaf86a482018-04-17 11:20:27 +0300437
438static uword
439api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
440{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200441 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
eyal bariaf86a482018-04-17 11:20:27 +0300442 vnet_main_t *vnm = vnet_get_main ();
443 u32 *result = va_arg (*args, u32 *);
444
445 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
446}
447
Damjan Marion7cd468a2016-12-19 23:05:39 +0100448#endif /* VPP_API_TEST_BUILTIN */
449
Neale Ranns17dcec02019-01-09 21:22:20 -0800450uword
451unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
452{
453 u32 *r = va_arg (*args, u32 *);
454
455 if (0);
456#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
457 foreach_ipsec_crypto_alg
458#undef _
459 else
460 return 0;
461 return 1;
462}
463
464uword
465unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
466{
467 u32 *r = va_arg (*args, u32 *);
468
469 if (0);
470#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
471 foreach_ipsec_integ_alg
472#undef _
473 else
474 return 0;
475 return 1;
476}
477
Damjan Marion7cd468a2016-12-19 23:05:39 +0100478static uword
479unformat_policer_rate_type (unformat_input_t * input, va_list * args)
480{
481 u8 *r = va_arg (*args, u8 *);
482
483 if (unformat (input, "kbps"))
484 *r = SSE2_QOS_RATE_KBPS;
485 else if (unformat (input, "pps"))
486 *r = SSE2_QOS_RATE_PPS;
487 else
488 return 0;
489 return 1;
490}
491
492static uword
493unformat_policer_round_type (unformat_input_t * input, va_list * args)
494{
495 u8 *r = va_arg (*args, u8 *);
496
497 if (unformat (input, "closest"))
498 *r = SSE2_QOS_ROUND_TO_CLOSEST;
499 else if (unformat (input, "up"))
500 *r = SSE2_QOS_ROUND_TO_UP;
501 else if (unformat (input, "down"))
502 *r = SSE2_QOS_ROUND_TO_DOWN;
503 else
504 return 0;
505 return 1;
506}
507
508static uword
509unformat_policer_type (unformat_input_t * input, va_list * args)
510{
511 u8 *r = va_arg (*args, u8 *);
512
513 if (unformat (input, "1r2c"))
514 *r = SSE2_QOS_POLICER_TYPE_1R2C;
515 else if (unformat (input, "1r3c"))
516 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
517 else if (unformat (input, "2r3c-2698"))
518 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
519 else if (unformat (input, "2r3c-4115"))
520 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
521 else if (unformat (input, "2r3c-mef5cf1"))
522 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
523 else
524 return 0;
525 return 1;
526}
527
528static uword
529unformat_dscp (unformat_input_t * input, va_list * va)
530{
531 u8 *r = va_arg (*va, u8 *);
532
533 if (0);
534#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
535 foreach_vnet_dscp
536#undef _
537 else
538 return 0;
539 return 1;
540}
541
542static uword
543unformat_policer_action_type (unformat_input_t * input, va_list * va)
544{
545 sse2_qos_pol_action_params_st *a
546 = va_arg (*va, sse2_qos_pol_action_params_st *);
547
548 if (unformat (input, "drop"))
549 a->action_type = SSE2_QOS_ACTION_DROP;
550 else if (unformat (input, "transmit"))
551 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
552 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
553 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
554 else
555 return 0;
556 return 1;
557}
558
559static uword
560unformat_policer_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 = POLICER_CLASSIFY_TABLE_IP4;
567 else if (unformat (input, "ip6"))
568 tid = POLICER_CLASSIFY_TABLE_IP6;
569 else if (unformat (input, "l2"))
570 tid = POLICER_CLASSIFY_TABLE_L2;
571 else
572 return 0;
573
574 *r = tid;
575 return 1;
576}
577
578static uword
579unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
580{
581 u32 *r = va_arg (*va, u32 *);
582 u32 tid;
583
584 if (unformat (input, "ip4"))
585 tid = FLOW_CLASSIFY_TABLE_IP4;
586 else if (unformat (input, "ip6"))
587 tid = FLOW_CLASSIFY_TABLE_IP6;
588 else
589 return 0;
590
591 *r = tid;
592 return 1;
593}
594
Benoît Ganne49ee6842019-04-30 11:50:46 +0200595#if (VPP_API_TEST_BUILTIN==0)
596
Neale Ranns32e1c012016-11-22 17:07:28 +0000597static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
598static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
599static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
600static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
601
602uword
603unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
604{
605 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
606 mfib_itf_attribute_t attr;
607
608 old = *iflags;
609 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
610 {
611 if (unformat (input, mfib_itf_flag_long_names[attr]))
612 *iflags |= (1 << attr);
613 }
614 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
615 {
616 if (unformat (input, mfib_itf_flag_names[attr]))
617 *iflags |= (1 << attr);
618 }
619
620 return (old == *iflags ? 0 : 1);
621}
622
623uword
624unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
625{
626 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
627 mfib_entry_attribute_t attr;
628
629 old = *eflags;
630 FOR_EACH_MFIB_ATTRIBUTE (attr)
631 {
632 if (unformat (input, mfib_flag_long_names[attr]))
633 *eflags |= (1 << attr);
634 }
635 FOR_EACH_MFIB_ATTRIBUTE (attr)
636 {
637 if (unformat (input, mfib_flag_names[attr]))
638 *eflags |= (1 << attr);
639 }
640
641 return (old == *eflags ? 0 : 1);
642}
643
Damjan Marion7cd468a2016-12-19 23:05:39 +0100644u8 *
645format_ip4_address (u8 * s, va_list * args)
646{
647 u8 *a = va_arg (*args, u8 *);
648 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
649}
650
651u8 *
652format_ip6_address (u8 * s, va_list * args)
653{
654 ip6_address_t *a = va_arg (*args, ip6_address_t *);
655 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
656
657 i_max_n_zero = ARRAY_LEN (a->as_u16);
658 max_n_zeros = 0;
659 i_first_zero = i_max_n_zero;
660 n_zeros = 0;
661 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
662 {
663 u32 is_zero = a->as_u16[i] == 0;
664 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
665 {
666 i_first_zero = i;
667 n_zeros = 0;
668 }
669 n_zeros += is_zero;
670 if ((!is_zero && n_zeros > max_n_zeros)
671 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
672 {
673 i_max_n_zero = i_first_zero;
674 max_n_zeros = n_zeros;
675 i_first_zero = ARRAY_LEN (a->as_u16);
676 n_zeros = 0;
677 }
678 }
679
680 last_double_colon = 0;
681 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
682 {
683 if (i == i_max_n_zero && max_n_zeros > 1)
684 {
685 s = format (s, "::");
686 i += max_n_zeros - 1;
687 last_double_colon = 1;
688 }
689 else
690 {
691 s = format (s, "%s%x",
692 (last_double_colon || i == 0) ? "" : ":",
693 clib_net_to_host_u16 (a->as_u16[i]));
694 last_double_colon = 0;
695 }
696 }
697
698 return s;
699}
700
701/* Format an IP46 address. */
702u8 *
703format_ip46_address (u8 * s, va_list * args)
704{
705 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
706 ip46_type_t type = va_arg (*args, ip46_type_t);
707 int is_ip4 = 1;
708
709 switch (type)
710 {
711 case IP46_TYPE_ANY:
712 is_ip4 = ip46_address_is_ip4 (ip46);
713 break;
714 case IP46_TYPE_IP4:
715 is_ip4 = 1;
716 break;
717 case IP46_TYPE_IP6:
718 is_ip4 = 0;
719 break;
720 }
721
722 return is_ip4 ?
723 format (s, "%U", format_ip4_address, &ip46->ip4) :
724 format (s, "%U", format_ip6_address, &ip46->ip6);
725}
726
727u8 *
728format_ethernet_address (u8 * s, va_list * args)
729{
730 u8 *a = va_arg (*args, u8 *);
731
732 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
733 a[0], a[1], a[2], a[3], a[4], a[5]);
734}
735#endif
736
737static void
Neale Ranns097fa662018-05-01 05:17:55 -0700738increment_v4_address (vl_api_ip4_address_t * i)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100739{
Neale Ranns097fa662018-05-01 05:17:55 -0700740 ip4_address_t *a = (ip4_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100741 u32 v;
742
743 v = ntohl (a->as_u32) + 1;
744 a->as_u32 = ntohl (v);
745}
746
747static void
Neale Ranns097fa662018-05-01 05:17:55 -0700748increment_v6_address (vl_api_ip6_address_t * i)
Neale Ranns2b5ba952019-04-02 10:15:40 +0000749{
Neale Ranns097fa662018-05-01 05:17:55 -0700750 ip6_address_t *a = (ip6_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100751 u64 v0, v1;
752
753 v0 = clib_net_to_host_u64 (a->as_u64[0]);
754 v1 = clib_net_to_host_u64 (a->as_u64[1]);
755
756 v1 += 1;
757 if (v1 == 0)
758 v0 += 1;
759 a->as_u64[0] = clib_net_to_host_u64 (v0);
760 a->as_u64[1] = clib_net_to_host_u64 (v1);
761}
762
763static void
Neale Ranns097fa662018-05-01 05:17:55 -0700764increment_address (vl_api_address_t * a)
765{
Neale Rannsb34f99c2019-07-03 08:00:53 +0000766 if (clib_net_to_host_u32 (a->af) == ADDRESS_IP4)
Neale Ranns097fa662018-05-01 05:17:55 -0700767 increment_v4_address (&a->un.ip4);
Neale Rannsb34f99c2019-07-03 08:00:53 +0000768 else if (clib_net_to_host_u32 (a->af) == ADDRESS_IP6)
Neale Ranns097fa662018-05-01 05:17:55 -0700769 increment_v6_address (&a->un.ip6);
770}
771
772static void
773set_ip4_address (vl_api_address_t * a, u32 v)
774{
775 if (a->af == ADDRESS_IP4)
776 {
777 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
778 i->as_u32 = v;
779 }
780}
781
Jakub Grajciar23a386b2020-02-26 11:01:43 +0100782void
783ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
784{
785 if (is_ip4)
786 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
787 else
788 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
789 sizeof (ip6_address_t));
790}
791
Neale Ranns097fa662018-05-01 05:17:55 -0700792static void
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200793increment_mac_address (u8 * mac)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100794{
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200795 u64 tmp = *((u64 *) mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100796 tmp = clib_net_to_host_u64 (tmp);
797 tmp += 1 << 16; /* skip unused (least significant) octets */
798 tmp = clib_host_to_net_u64 (tmp);
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200799
800 clib_memcpy (mac, &tmp, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100801}
802
Neale Ranns097fa662018-05-01 05:17:55 -0700803static void
804vat_json_object_add_address (vat_json_node_t * node,
805 const char *str, const vl_api_address_t * addr)
806{
807 if (ADDRESS_IP6 == addr->af)
808 {
809 struct in6_addr ip6;
810
811 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
812 vat_json_object_add_ip6 (node, str, ip6);
813 }
814 else
815 {
816 struct in_addr ip4;
817
818 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
819 vat_json_object_add_ip4 (node, str, ip4);
820 }
821}
822
823static void
824vat_json_object_add_prefix (vat_json_node_t * node,
825 const vl_api_prefix_t * prefix)
826{
Paul Vinciguerraab055082019-06-06 14:07:55 -0400827 vat_json_object_add_uint (node, "len", prefix->len);
828 vat_json_object_add_address (node, "address", &prefix->address);
Neale Ranns097fa662018-05-01 05:17:55 -0700829}
830
Damjan Marion7cd468a2016-12-19 23:05:39 +0100831static void vl_api_create_loopback_reply_t_handler
832 (vl_api_create_loopback_reply_t * mp)
833{
834 vat_main_t *vam = &vat_main;
835 i32 retval = ntohl (mp->retval);
836
837 vam->retval = retval;
838 vam->regenerate_interface_table = 1;
839 vam->sw_if_index = ntohl (mp->sw_if_index);
840 vam->result_ready = 1;
841}
842
843static void vl_api_create_loopback_reply_t_handler_json
844 (vl_api_create_loopback_reply_t * mp)
845{
846 vat_main_t *vam = &vat_main;
847 vat_json_node_t node;
848
849 vat_json_init_object (&node);
850 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
851 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
852
853 vat_json_print (vam->ofp, &node);
854 vat_json_free (&node);
855 vam->retval = ntohl (mp->retval);
856 vam->result_ready = 1;
857}
858
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600859static void vl_api_create_loopback_instance_reply_t_handler
860 (vl_api_create_loopback_instance_reply_t * mp)
861{
862 vat_main_t *vam = &vat_main;
863 i32 retval = ntohl (mp->retval);
864
865 vam->retval = retval;
866 vam->regenerate_interface_table = 1;
867 vam->sw_if_index = ntohl (mp->sw_if_index);
868 vam->result_ready = 1;
869}
870
871static void vl_api_create_loopback_instance_reply_t_handler_json
872 (vl_api_create_loopback_instance_reply_t * mp)
873{
874 vat_main_t *vam = &vat_main;
875 vat_json_node_t node;
876
877 vat_json_init_object (&node);
878 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
879 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
880
881 vat_json_print (vam->ofp, &node);
882 vat_json_free (&node);
883 vam->retval = ntohl (mp->retval);
884 vam->result_ready = 1;
885}
886
Damjan Marion7cd468a2016-12-19 23:05:39 +0100887static void vl_api_af_packet_create_reply_t_handler
888 (vl_api_af_packet_create_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_af_packet_create_reply_t_handler_json
900 (vl_api_af_packet_create_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_vlan_subif_reply_t_handler
917 (vl_api_create_vlan_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_vlan_subif_reply_t_handler_json
929 (vl_api_create_vlan_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_create_subif_reply_t_handler
946 (vl_api_create_subif_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->sw_if_index = ntohl (mp->sw_if_index);
954 vam->result_ready = 1;
955}
956
957static void vl_api_create_subif_reply_t_handler_json
958 (vl_api_create_subif_reply_t * mp)
959{
960 vat_main_t *vam = &vat_main;
961 vat_json_node_t node;
962
963 vat_json_init_object (&node);
964 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
965 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
966
967 vat_json_print (vam->ofp, &node);
968 vat_json_free (&node);
969
970 vam->retval = ntohl (mp->retval);
971 vam->result_ready = 1;
972}
973
974static void vl_api_interface_name_renumber_reply_t_handler
975 (vl_api_interface_name_renumber_reply_t * mp)
976{
977 vat_main_t *vam = &vat_main;
978 i32 retval = ntohl (mp->retval);
979
980 vam->retval = retval;
981 vam->regenerate_interface_table = 1;
982 vam->result_ready = 1;
983}
984
985static void vl_api_interface_name_renumber_reply_t_handler_json
986 (vl_api_interface_name_renumber_reply_t * mp)
987{
988 vat_main_t *vam = &vat_main;
989 vat_json_node_t node;
990
991 vat_json_init_object (&node);
992 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
993
994 vat_json_print (vam->ofp, &node);
995 vat_json_free (&node);
996
997 vam->retval = ntohl (mp->retval);
998 vam->result_ready = 1;
999}
1000
1001/*
1002 * Special-case: build the interface table, maintain
1003 * the next loopback sw_if_index vbl.
1004 */
1005static void vl_api_sw_interface_details_t_handler
1006 (vl_api_sw_interface_details_t * mp)
1007{
1008 vat_main_t *vam = &vat_main;
Ole Troane5ff5a32019-08-23 22:55:18 +02001009 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001010
1011 hash_set_mem (vam->sw_if_index_by_interface_name, s,
1012 ntohl (mp->sw_if_index));
1013
1014 /* In sub interface case, fill the sub interface table entry */
1015 if (mp->sw_if_index != mp->sup_sw_if_index)
1016 {
1017 sw_interface_subif_t *sub = NULL;
1018
1019 vec_add2 (vam->sw_if_subif_table, sub, 1);
1020
1021 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
1022 strncpy ((char *) sub->interface_name, (char *) s,
1023 vec_len (sub->interface_name));
1024 sub->sw_if_index = ntohl (mp->sw_if_index);
1025 sub->sub_id = ntohl (mp->sub_id);
1026
Jakub Grajciar053204a2019-03-18 13:17:53 +01001027 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
1028
Damjan Marion7cd468a2016-12-19 23:05:39 +01001029 sub->sub_number_of_tags = mp->sub_number_of_tags;
1030 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1031 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001032
1033 /* vlan tag rewrite */
1034 sub->vtr_op = ntohl (mp->vtr_op);
1035 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1036 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1037 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1038 }
1039}
1040
1041static void vl_api_sw_interface_details_t_handler_json
1042 (vl_api_sw_interface_details_t * mp)
1043{
1044 vat_main_t *vam = &vat_main;
1045 vat_json_node_t *node = NULL;
1046
1047 if (VAT_JSON_ARRAY != vam->json_tree.type)
1048 {
1049 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1050 vat_json_init_array (&vam->json_tree);
1051 }
1052 node = vat_json_array_add (&vam->json_tree);
1053
1054 vat_json_init_object (node);
1055 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1056 vat_json_object_add_uint (node, "sup_sw_if_index",
1057 ntohl (mp->sup_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001058 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1059 sizeof (mp->l2_address));
1060 vat_json_object_add_string_copy (node, "interface_name",
Ole Troane5ff5a32019-08-23 22:55:18 +02001061 mp->interface_name);
Mohsin Kazmide312c22019-09-27 13:44:28 +02001062 vat_json_object_add_string_copy (node, "interface_dev_type",
1063 mp->interface_dev_type);
Jakub Grajciar053204a2019-03-18 13:17:53 +01001064 vat_json_object_add_uint (node, "flags", mp->flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001065 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1066 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001067 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001068 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001069 vat_json_object_add_uint (node, "sub_number_of_tags",
1070 mp->sub_number_of_tags);
1071 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1072 ntohs (mp->sub_outer_vlan_id));
1073 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1074 ntohs (mp->sub_inner_vlan_id));
Jakub Grajciar053204a2019-03-18 13:17:53 +01001075 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001076 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1077 vat_json_object_add_uint (node, "vtr_push_dot1q",
1078 ntohl (mp->vtr_push_dot1q));
1079 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1080 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Jakub Grajciar053204a2019-03-18 13:17:53 +01001081 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
Pavel Kotucek65e84572017-01-16 17:01:56 +01001082 {
1083 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1084 format (0, "%U",
1085 format_ethernet_address,
1086 &mp->b_dmac));
1087 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1088 format (0, "%U",
1089 format_ethernet_address,
1090 &mp->b_smac));
1091 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1092 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1093 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001094}
1095
Dave Baracha1a093d2017-03-02 13:13:23 -05001096#if VPP_API_TEST_BUILTIN == 0
Neale Rannsa07bd702017-08-07 07:53:49 -07001097static void vl_api_sw_interface_event_t_handler
1098 (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001099{
1100 vat_main_t *vam = &vat_main;
1101 if (vam->interface_event_display)
1102 errmsg ("interface flags: sw_if_index %d %s %s",
1103 ntohl (mp->sw_if_index),
Jakub Grajciar053204a2019-03-18 13:17:53 +01001104 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1105 "admin-up" : "admin-down",
1106 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1107 "link-up" : "link-down");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001108}
Dave Baracha1a093d2017-03-02 13:13:23 -05001109#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +01001110
Benoît Ganne49ee6842019-04-30 11:50:46 +02001111__clib_unused static void
1112vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001113{
1114 /* JSON output not supported */
1115}
1116
1117static void
1118vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1119{
1120 vat_main_t *vam = &vat_main;
1121 i32 retval = ntohl (mp->retval);
1122
1123 vam->retval = retval;
Damjan Marion7bee80c2017-04-26 15:32:12 +02001124 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001125 vam->result_ready = 1;
1126}
1127
1128static void
1129vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1130{
1131 vat_main_t *vam = &vat_main;
1132 vat_json_node_t node;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001133 void *oldheap;
1134 u8 *reply;
1135
1136 vat_json_init_object (&node);
1137 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1138 vat_json_object_add_uint (&node, "reply_in_shmem",
1139 ntohl (mp->reply_in_shmem));
1140 /* Toss the shared-memory original... */
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01001141 oldheap = vl_msg_push_heap ();
Damjan Marion7cd468a2016-12-19 23:05:39 +01001142
Damjan Marion7bee80c2017-04-26 15:32:12 +02001143 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001144 vec_free (reply);
1145
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01001146 vl_msg_pop_heap (oldheap);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001147
1148 vat_json_print (vam->ofp, &node);
1149 vat_json_free (&node);
1150
1151 vam->retval = ntohl (mp->retval);
1152 vam->result_ready = 1;
1153}
1154
1155static void
1156vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1157{
1158 vat_main_t *vam = &vat_main;
1159 i32 retval = ntohl (mp->retval);
Dave Barach59b25652017-09-10 15:04:27 -04001160
1161 vec_reset_length (vam->cmd_reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001162
1163 vam->retval = retval;
Dave Barach59b25652017-09-10 15:04:27 -04001164 if (retval == 0)
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001165 vam->cmd_reply = vl_api_from_api_to_new_vec (&mp->reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001166 vam->result_ready = 1;
1167}
1168
1169static void
1170vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1171{
1172 vat_main_t *vam = &vat_main;
1173 vat_json_node_t node;
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001174 u8 *reply = 0; /* reply vector */
Damjan Marion7cd468a2016-12-19 23:05:39 +01001175
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001176 reply = vl_api_from_api_to_new_vec (&mp->reply);
Dave Barach59b25652017-09-10 15:04:27 -04001177 vec_reset_length (vam->cmd_reply);
1178
Damjan Marion7cd468a2016-12-19 23:05:39 +01001179 vat_json_init_object (&node);
1180 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001181 vat_json_object_add_string_copy (&node, "reply", reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001182
1183 vat_json_print (vam->ofp, &node);
1184 vat_json_free (&node);
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001185 vec_free (reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001186
1187 vam->retval = ntohl (mp->retval);
1188 vam->result_ready = 1;
1189}
1190
1191static void vl_api_classify_add_del_table_reply_t_handler
1192 (vl_api_classify_add_del_table_reply_t * mp)
1193{
1194 vat_main_t *vam = &vat_main;
1195 i32 retval = ntohl (mp->retval);
1196 if (vam->async_mode)
1197 {
1198 vam->async_errors += (retval < 0);
1199 }
1200 else
1201 {
1202 vam->retval = retval;
1203 if (retval == 0 &&
1204 ((mp->new_table_index != 0xFFFFFFFF) ||
1205 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1206 (mp->match_n_vectors != 0xFFFFFFFF)))
1207 /*
1208 * Note: this is just barely thread-safe, depends on
1209 * the main thread spinning waiting for an answer...
1210 */
1211 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1212 ntohl (mp->new_table_index),
1213 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1214 vam->result_ready = 1;
1215 }
1216}
1217
1218static void vl_api_classify_add_del_table_reply_t_handler_json
1219 (vl_api_classify_add_del_table_reply_t * mp)
1220{
1221 vat_main_t *vam = &vat_main;
1222 vat_json_node_t node;
1223
1224 vat_json_init_object (&node);
1225 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1226 vat_json_object_add_uint (&node, "new_table_index",
1227 ntohl (mp->new_table_index));
1228 vat_json_object_add_uint (&node, "skip_n_vectors",
1229 ntohl (mp->skip_n_vectors));
1230 vat_json_object_add_uint (&node, "match_n_vectors",
1231 ntohl (mp->match_n_vectors));
1232
1233 vat_json_print (vam->ofp, &node);
1234 vat_json_free (&node);
1235
1236 vam->retval = ntohl (mp->retval);
1237 vam->result_ready = 1;
1238}
1239
1240static void vl_api_get_node_index_reply_t_handler
1241 (vl_api_get_node_index_reply_t * mp)
1242{
1243 vat_main_t *vam = &vat_main;
1244 i32 retval = ntohl (mp->retval);
1245 if (vam->async_mode)
1246 {
1247 vam->async_errors += (retval < 0);
1248 }
1249 else
1250 {
1251 vam->retval = retval;
1252 if (retval == 0)
1253 errmsg ("node index %d", ntohl (mp->node_index));
1254 vam->result_ready = 1;
1255 }
1256}
1257
1258static void vl_api_get_node_index_reply_t_handler_json
1259 (vl_api_get_node_index_reply_t * mp)
1260{
1261 vat_main_t *vam = &vat_main;
1262 vat_json_node_t node;
1263
1264 vat_json_init_object (&node);
1265 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1266 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1267
1268 vat_json_print (vam->ofp, &node);
1269 vat_json_free (&node);
1270
1271 vam->retval = ntohl (mp->retval);
1272 vam->result_ready = 1;
1273}
1274
1275static void vl_api_get_next_index_reply_t_handler
1276 (vl_api_get_next_index_reply_t * mp)
1277{
1278 vat_main_t *vam = &vat_main;
1279 i32 retval = ntohl (mp->retval);
1280 if (vam->async_mode)
1281 {
1282 vam->async_errors += (retval < 0);
1283 }
1284 else
1285 {
1286 vam->retval = retval;
1287 if (retval == 0)
1288 errmsg ("next node index %d", ntohl (mp->next_index));
1289 vam->result_ready = 1;
1290 }
1291}
1292
1293static void vl_api_get_next_index_reply_t_handler_json
1294 (vl_api_get_next_index_reply_t * mp)
1295{
1296 vat_main_t *vam = &vat_main;
1297 vat_json_node_t node;
1298
1299 vat_json_init_object (&node);
1300 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1301 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1302
1303 vat_json_print (vam->ofp, &node);
1304 vat_json_free (&node);
1305
1306 vam->retval = ntohl (mp->retval);
1307 vam->result_ready = 1;
1308}
1309
1310static void vl_api_add_node_next_reply_t_handler
1311 (vl_api_add_node_next_reply_t * mp)
1312{
1313 vat_main_t *vam = &vat_main;
1314 i32 retval = ntohl (mp->retval);
1315 if (vam->async_mode)
1316 {
1317 vam->async_errors += (retval < 0);
1318 }
1319 else
1320 {
1321 vam->retval = retval;
1322 if (retval == 0)
1323 errmsg ("next index %d", ntohl (mp->next_index));
1324 vam->result_ready = 1;
1325 }
1326}
1327
1328static void vl_api_add_node_next_reply_t_handler_json
1329 (vl_api_add_node_next_reply_t * mp)
1330{
1331 vat_main_t *vam = &vat_main;
1332 vat_json_node_t node;
1333
1334 vat_json_init_object (&node);
1335 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1336 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1337
1338 vat_json_print (vam->ofp, &node);
1339 vat_json_free (&node);
1340
1341 vam->retval = ntohl (mp->retval);
1342 vam->result_ready = 1;
1343}
1344
1345static void vl_api_show_version_reply_t_handler
1346 (vl_api_show_version_reply_t * mp)
1347{
1348 vat_main_t *vam = &vat_main;
1349 i32 retval = ntohl (mp->retval);
1350
1351 if (retval >= 0)
1352 {
Ole Troane5ff5a32019-08-23 22:55:18 +02001353 errmsg (" program: %s", mp->program);
1354 errmsg (" version: %s", mp->version);
1355 errmsg (" build date: %s", mp->build_date);
1356 errmsg ("build directory: %s", mp->build_directory);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001357 }
1358 vam->retval = retval;
1359 vam->result_ready = 1;
1360}
1361
1362static void vl_api_show_version_reply_t_handler_json
1363 (vl_api_show_version_reply_t * mp)
1364{
1365 vat_main_t *vam = &vat_main;
1366 vat_json_node_t node;
1367
1368 vat_json_init_object (&node);
1369 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troane5ff5a32019-08-23 22:55:18 +02001370 vat_json_object_add_string_copy (&node, "program", mp->program);
1371 vat_json_object_add_string_copy (&node, "version", mp->version);
1372 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001373 vat_json_object_add_string_copy (&node, "build_directory",
Ole Troane5ff5a32019-08-23 22:55:18 +02001374 mp->build_directory);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001375
1376 vat_json_print (vam->ofp, &node);
1377 vat_json_free (&node);
1378
1379 vam->retval = ntohl (mp->retval);
1380 vam->result_ready = 1;
1381}
1382
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001383static void vl_api_show_threads_reply_t_handler
1384 (vl_api_show_threads_reply_t * mp)
1385{
1386 vat_main_t *vam = &vat_main;
1387 i32 retval = ntohl (mp->retval);
1388 int i, count = 0;
1389
1390 if (retval >= 0)
1391 count = ntohl (mp->count);
1392
1393 for (i = 0; i < count; i++)
1394 print (vam->ofp,
1395 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1396 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1397 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1398 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1399 ntohl (mp->thread_data[i].cpu_socket));
1400
1401 vam->retval = retval;
1402 vam->result_ready = 1;
1403}
1404
1405static void vl_api_show_threads_reply_t_handler_json
1406 (vl_api_show_threads_reply_t * mp)
1407{
1408 vat_main_t *vam = &vat_main;
1409 vat_json_node_t node;
1410 vl_api_thread_data_t *td;
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001411 i32 retval = ntohl (mp->retval);
1412 int i, count = 0;
1413
1414 if (retval >= 0)
1415 count = ntohl (mp->count);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001416
1417 vat_json_init_object (&node);
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001418 vat_json_object_add_int (&node, "retval", retval);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001419 vat_json_object_add_uint (&node, "count", count);
1420
1421 for (i = 0; i < count; i++)
1422 {
1423 td = &mp->thread_data[i];
1424 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1425 vat_json_object_add_string_copy (&node, "name", td->name);
1426 vat_json_object_add_string_copy (&node, "type", td->type);
1427 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1428 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1429 vat_json_object_add_int (&node, "core", ntohl (td->id));
1430 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1431 }
1432
1433 vat_json_print (vam->ofp, &node);
1434 vat_json_free (&node);
1435
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001436 vam->retval = retval;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001437 vam->result_ready = 1;
1438}
1439
1440static int
1441api_show_threads (vat_main_t * vam)
1442{
1443 vl_api_show_threads_t *mp;
1444 int ret;
1445
1446 print (vam->ofp,
1447 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1448 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1449
1450 M (SHOW_THREADS, mp);
1451
1452 S (mp);
1453 W (ret);
1454 return ret;
1455}
1456
Damjan Marion7cd468a2016-12-19 23:05:39 +01001457static void
John Lo8d00fff2017-08-03 00:35:36 -04001458vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1459{
1460 u32 n_macs = ntohl (mp->n_macs);
Paul Vinciguerraec11b132018-09-24 05:25:00 -07001461 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
John Lo8d00fff2017-08-03 00:35:36 -04001462 ntohl (mp->pid), mp->client_index, n_macs);
1463 int i;
1464 for (i = 0; i < n_macs; i++)
1465 {
1466 vl_api_mac_entry_t *mac = &mp->mac[i];
John Loe23c99e2018-03-13 21:53:18 -04001467 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
John Lo8d00fff2017-08-03 00:35:36 -04001468 i + 1, ntohl (mac->sw_if_index),
John Loe23c99e2018-03-13 21:53:18 -04001469 format_ethernet_address, mac->mac_addr, mac->action);
John Lo8d00fff2017-08-03 00:35:36 -04001470 if (i == 1000)
1471 break;
1472 }
1473}
1474
1475static void
1476vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1477{
1478 /* JSON output not supported */
1479}
1480
Ole Troan01384fe2017-05-12 11:55:35 +02001481#define vl_api_bridge_domain_details_t_endian vl_noop_handler
1482#define vl_api_bridge_domain_details_t_print vl_noop_handler
1483
Damjan Marion7cd468a2016-12-19 23:05:39 +01001484/*
1485 * Special-case: build the bridge domain table, maintain
1486 * the next bd id vbl.
1487 */
1488static void vl_api_bridge_domain_details_t_handler
1489 (vl_api_bridge_domain_details_t * mp)
1490{
1491 vat_main_t *vam = &vat_main;
1492 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ole Troan01384fe2017-05-12 11:55:35 +02001493 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001494
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001495 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1496 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001497
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001498 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001499 ntohl (mp->bd_id), mp->learn, mp->forward,
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001500 mp->flood, ntohl (mp->bvi_sw_if_index),
1501 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001502
1503 if (n_sw_ifs)
Ole Troan01384fe2017-05-12 11:55:35 +02001504 {
1505 vl_api_bridge_domain_sw_if_t *sw_ifs;
1506 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1507 "Interface Name");
1508
1509 sw_ifs = mp->sw_if_details;
1510 for (i = 0; i < n_sw_ifs; i++)
1511 {
1512 u8 *sw_if_name = 0;
1513 u32 sw_if_index;
1514 hash_pair_t *p;
1515
1516 sw_if_index = ntohl (sw_ifs->sw_if_index);
1517
1518 /* *INDENT-OFF* */
1519 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1520 ({
1521 if ((u32) p->value[0] == sw_if_index)
1522 {
1523 sw_if_name = (u8 *)(p->key);
1524 break;
1525 }
1526 }));
1527 /* *INDENT-ON* */
1528 print (vam->ofp, "%7d %3d %s", sw_if_index,
1529 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1530 "sw_if_index not found!");
1531
1532 sw_ifs++;
1533 }
1534 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001535}
1536
1537static void vl_api_bridge_domain_details_t_handler_json
1538 (vl_api_bridge_domain_details_t * mp)
1539{
1540 vat_main_t *vam = &vat_main;
1541 vat_json_node_t *node, *array = NULL;
Ole Troan01384fe2017-05-12 11:55:35 +02001542 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001543
1544 if (VAT_JSON_ARRAY != vam->json_tree.type)
1545 {
1546 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1547 vat_json_init_array (&vam->json_tree);
1548 }
1549 node = vat_json_array_add (&vam->json_tree);
1550
1551 vat_json_init_object (node);
1552 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1553 vat_json_object_add_uint (node, "flood", mp->flood);
1554 vat_json_object_add_uint (node, "forward", mp->forward);
1555 vat_json_object_add_uint (node, "learn", mp->learn);
1556 vat_json_object_add_uint (node, "bvi_sw_if_index",
1557 ntohl (mp->bvi_sw_if_index));
Ole Troan01384fe2017-05-12 11:55:35 +02001558 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001559 array = vat_json_object_add (node, "sw_if");
1560 vat_json_init_array (array);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001561
Damjan Marion7cd468a2016-12-19 23:05:39 +01001562
Damjan Marion7cd468a2016-12-19 23:05:39 +01001563
Ole Troan01384fe2017-05-12 11:55:35 +02001564 if (n_sw_ifs)
1565 {
1566 vl_api_bridge_domain_sw_if_t *sw_ifs;
1567 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001568
Ole Troan01384fe2017-05-12 11:55:35 +02001569 sw_ifs = mp->sw_if_details;
1570 for (i = 0; i < n_sw_ifs; i++)
1571 {
1572 node = vat_json_array_add (array);
1573 vat_json_init_object (node);
1574 vat_json_object_add_uint (node, "sw_if_index",
1575 ntohl (sw_ifs->sw_if_index));
1576 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1577 sw_ifs++;
1578 }
1579 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001580}
1581
1582static void vl_api_control_ping_reply_t_handler
1583 (vl_api_control_ping_reply_t * mp)
1584{
1585 vat_main_t *vam = &vat_main;
1586 i32 retval = ntohl (mp->retval);
1587 if (vam->async_mode)
1588 {
1589 vam->async_errors += (retval < 0);
1590 }
1591 else
1592 {
1593 vam->retval = retval;
1594 vam->result_ready = 1;
1595 }
Florin Coras90a63982017-12-19 04:50:01 -08001596 if (vam->socket_client_main)
1597 vam->socket_client_main->control_pings_outstanding--;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001598}
1599
1600static void vl_api_control_ping_reply_t_handler_json
1601 (vl_api_control_ping_reply_t * mp)
1602{
1603 vat_main_t *vam = &vat_main;
1604 i32 retval = ntohl (mp->retval);
1605
1606 if (VAT_JSON_NONE != vam->json_tree.type)
1607 {
1608 vat_json_print (vam->ofp, &vam->json_tree);
1609 vat_json_free (&vam->json_tree);
1610 vam->json_tree.type = VAT_JSON_NONE;
1611 }
1612 else
1613 {
1614 /* just print [] */
1615 vat_json_init_array (&vam->json_tree);
1616 vat_json_print (vam->ofp, &vam->json_tree);
1617 vam->json_tree.type = VAT_JSON_NONE;
1618 }
1619
1620 vam->retval = retval;
1621 vam->result_ready = 1;
1622}
1623
1624static void
Eyal Barifead6702017-04-04 04:46:32 +03001625 vl_api_bridge_domain_set_mac_age_reply_t_handler
1626 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1627{
1628 vat_main_t *vam = &vat_main;
1629 i32 retval = ntohl (mp->retval);
1630 if (vam->async_mode)
1631 {
1632 vam->async_errors += (retval < 0);
1633 }
1634 else
1635 {
1636 vam->retval = retval;
1637 vam->result_ready = 1;
1638 }
1639}
1640
1641static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1642 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1643{
1644 vat_main_t *vam = &vat_main;
1645 vat_json_node_t node;
1646
1647 vat_json_init_object (&node);
1648 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1649
1650 vat_json_print (vam->ofp, &node);
1651 vat_json_free (&node);
1652
1653 vam->retval = ntohl (mp->retval);
1654 vam->result_ready = 1;
1655}
1656
1657static void
Damjan Marion7cd468a2016-12-19 23:05:39 +01001658vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1659{
1660 vat_main_t *vam = &vat_main;
1661 i32 retval = ntohl (mp->retval);
1662 if (vam->async_mode)
1663 {
1664 vam->async_errors += (retval < 0);
1665 }
1666 else
1667 {
1668 vam->retval = retval;
1669 vam->result_ready = 1;
1670 }
1671}
1672
1673static void vl_api_l2_flags_reply_t_handler_json
1674 (vl_api_l2_flags_reply_t * mp)
1675{
1676 vat_main_t *vam = &vat_main;
1677 vat_json_node_t node;
1678
1679 vat_json_init_object (&node);
1680 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1681 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1682 ntohl (mp->resulting_feature_bitmap));
1683
1684 vat_json_print (vam->ofp, &node);
1685 vat_json_free (&node);
1686
1687 vam->retval = ntohl (mp->retval);
1688 vam->result_ready = 1;
1689}
1690
1691static void vl_api_bridge_flags_reply_t_handler
1692 (vl_api_bridge_flags_reply_t * mp)
1693{
1694 vat_main_t *vam = &vat_main;
1695 i32 retval = ntohl (mp->retval);
1696 if (vam->async_mode)
1697 {
1698 vam->async_errors += (retval < 0);
1699 }
1700 else
1701 {
1702 vam->retval = retval;
1703 vam->result_ready = 1;
1704 }
1705}
1706
1707static void vl_api_bridge_flags_reply_t_handler_json
1708 (vl_api_bridge_flags_reply_t * mp)
1709{
1710 vat_main_t *vam = &vat_main;
1711 vat_json_node_t node;
1712
1713 vat_json_init_object (&node);
1714 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1715 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1716 ntohl (mp->resulting_feature_bitmap));
1717
1718 vat_json_print (vam->ofp, &node);
1719 vat_json_free (&node);
1720
1721 vam->retval = ntohl (mp->retval);
1722 vam->result_ready = 1;
1723}
1724
Damjan Marion8389fb92017-10-13 18:29:53 +02001725static void
1726vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1727{
1728 vat_main_t *vam = &vat_main;
1729 i32 retval = ntohl (mp->retval);
1730 if (vam->async_mode)
1731 {
1732 vam->async_errors += (retval < 0);
1733 }
1734 else
1735 {
1736 vam->retval = retval;
1737 vam->sw_if_index = ntohl (mp->sw_if_index);
1738 vam->result_ready = 1;
1739 }
1740
1741}
1742
1743static void vl_api_tap_create_v2_reply_t_handler_json
1744 (vl_api_tap_create_v2_reply_t * mp)
1745{
1746 vat_main_t *vam = &vat_main;
1747 vat_json_node_t node;
1748
1749 vat_json_init_object (&node);
1750 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1751 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1752
1753 vat_json_print (vam->ofp, &node);
1754 vat_json_free (&node);
1755
1756 vam->retval = ntohl (mp->retval);
1757 vam->result_ready = 1;
1758
1759}
1760
1761static void
1762vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1763{
1764 vat_main_t *vam = &vat_main;
1765 i32 retval = ntohl (mp->retval);
1766 if (vam->async_mode)
1767 {
1768 vam->async_errors += (retval < 0);
1769 }
1770 else
1771 {
1772 vam->retval = retval;
1773 vam->result_ready = 1;
1774 }
1775}
1776
1777static void vl_api_tap_delete_v2_reply_t_handler_json
1778 (vl_api_tap_delete_v2_reply_t * mp)
1779{
1780 vat_main_t *vam = &vat_main;
1781 vat_json_node_t node;
1782
1783 vat_json_init_object (&node);
1784 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1785
1786 vat_json_print (vam->ofp, &node);
1787 vat_json_free (&node);
1788
1789 vam->retval = ntohl (mp->retval);
1790 vam->result_ready = 1;
1791}
1792
Steven9cd2d7a2017-12-20 12:43:01 -08001793static void
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01001794vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1795 mp)
1796{
1797 vat_main_t *vam = &vat_main;
1798 i32 retval = ntohl (mp->retval);
1799 if (vam->async_mode)
1800 {
1801 vam->async_errors += (retval < 0);
1802 }
1803 else
1804 {
1805 vam->retval = retval;
1806 vam->sw_if_index = ntohl (mp->sw_if_index);
1807 vam->result_ready = 1;
1808 }
1809}
1810
1811static void vl_api_virtio_pci_create_reply_t_handler_json
1812 (vl_api_virtio_pci_create_reply_t * mp)
1813{
1814 vat_main_t *vam = &vat_main;
1815 vat_json_node_t node;
1816
1817 vat_json_init_object (&node);
1818 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1819 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1820
1821 vat_json_print (vam->ofp, &node);
1822 vat_json_free (&node);
1823
1824 vam->retval = ntohl (mp->retval);
1825 vam->result_ready = 1;
1826
1827}
1828
1829static void
1830vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1831 mp)
1832{
1833 vat_main_t *vam = &vat_main;
1834 i32 retval = ntohl (mp->retval);
1835 if (vam->async_mode)
1836 {
1837 vam->async_errors += (retval < 0);
1838 }
1839 else
1840 {
1841 vam->retval = retval;
1842 vam->result_ready = 1;
1843 }
1844}
1845
1846static void vl_api_virtio_pci_delete_reply_t_handler_json
1847 (vl_api_virtio_pci_delete_reply_t * mp)
1848{
1849 vat_main_t *vam = &vat_main;
1850 vat_json_node_t node;
1851
1852 vat_json_init_object (&node);
1853 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1854
1855 vat_json_print (vam->ofp, &node);
1856 vat_json_free (&node);
1857
1858 vam->retval = ntohl (mp->retval);
1859 vam->result_ready = 1;
1860}
1861
1862static void
Steven9cd2d7a2017-12-20 12:43:01 -08001863vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1864{
1865 vat_main_t *vam = &vat_main;
1866 i32 retval = ntohl (mp->retval);
1867
1868 if (vam->async_mode)
1869 {
1870 vam->async_errors += (retval < 0);
1871 }
1872 else
1873 {
1874 vam->retval = retval;
1875 vam->sw_if_index = ntohl (mp->sw_if_index);
1876 vam->result_ready = 1;
1877 }
1878}
1879
1880static void vl_api_bond_create_reply_t_handler_json
1881 (vl_api_bond_create_reply_t * mp)
1882{
1883 vat_main_t *vam = &vat_main;
1884 vat_json_node_t node;
1885
1886 vat_json_init_object (&node);
1887 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1888 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1889
1890 vat_json_print (vam->ofp, &node);
1891 vat_json_free (&node);
1892
1893 vam->retval = ntohl (mp->retval);
1894 vam->result_ready = 1;
1895}
1896
1897static void
1898vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1899{
1900 vat_main_t *vam = &vat_main;
1901 i32 retval = ntohl (mp->retval);
1902
1903 if (vam->async_mode)
1904 {
1905 vam->async_errors += (retval < 0);
1906 }
1907 else
1908 {
1909 vam->retval = retval;
1910 vam->result_ready = 1;
1911 }
1912}
1913
1914static void vl_api_bond_delete_reply_t_handler_json
1915 (vl_api_bond_delete_reply_t * mp)
1916{
1917 vat_main_t *vam = &vat_main;
1918 vat_json_node_t node;
1919
1920 vat_json_init_object (&node);
1921 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1922
1923 vat_json_print (vam->ofp, &node);
1924 vat_json_free (&node);
1925
1926 vam->retval = ntohl (mp->retval);
1927 vam->result_ready = 1;
1928}
1929
1930static void
1931vl_api_bond_enslave_reply_t_handler (vl_api_bond_enslave_reply_t * mp)
1932{
1933 vat_main_t *vam = &vat_main;
1934 i32 retval = ntohl (mp->retval);
1935
1936 if (vam->async_mode)
1937 {
1938 vam->async_errors += (retval < 0);
1939 }
1940 else
1941 {
1942 vam->retval = retval;
1943 vam->result_ready = 1;
1944 }
1945}
1946
1947static void vl_api_bond_enslave_reply_t_handler_json
1948 (vl_api_bond_enslave_reply_t * mp)
1949{
1950 vat_main_t *vam = &vat_main;
1951 vat_json_node_t node;
1952
1953 vat_json_init_object (&node);
1954 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1955
1956 vat_json_print (vam->ofp, &node);
1957 vat_json_free (&node);
1958
1959 vam->retval = ntohl (mp->retval);
1960 vam->result_ready = 1;
1961}
1962
1963static void
1964vl_api_bond_detach_slave_reply_t_handler (vl_api_bond_detach_slave_reply_t *
1965 mp)
1966{
1967 vat_main_t *vam = &vat_main;
1968 i32 retval = ntohl (mp->retval);
1969
1970 if (vam->async_mode)
1971 {
1972 vam->async_errors += (retval < 0);
1973 }
1974 else
1975 {
1976 vam->retval = retval;
1977 vam->result_ready = 1;
1978 }
1979}
1980
1981static void vl_api_bond_detach_slave_reply_t_handler_json
1982 (vl_api_bond_detach_slave_reply_t * mp)
1983{
1984 vat_main_t *vam = &vat_main;
1985 vat_json_node_t node;
1986
1987 vat_json_init_object (&node);
1988 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1989
1990 vat_json_print (vam->ofp, &node);
1991 vat_json_free (&node);
1992
1993 vam->retval = ntohl (mp->retval);
1994 vam->result_ready = 1;
1995}
1996
Steven Luonga1876b82019-08-20 16:58:00 -07001997static int
1998api_sw_interface_set_bond_weight (vat_main_t * vam)
1999{
2000 unformat_input_t *i = vam->input;
2001 vl_api_sw_interface_set_bond_weight_t *mp;
2002 u32 sw_if_index = ~0;
2003 u32 weight = 0;
2004 u8 weight_enter = 0;
2005 int ret;
2006
2007 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2008 {
2009 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2010 ;
2011 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2012 ;
2013 else if (unformat (i, "weight %u", &weight))
2014 weight_enter = 1;
2015 else
2016 break;
2017 }
2018
2019 if (sw_if_index == ~0)
2020 {
2021 errmsg ("missing interface name or sw_if_index");
2022 return -99;
2023 }
2024 if (weight_enter == 0)
2025 {
2026 errmsg ("missing valid weight");
2027 return -99;
2028 }
2029
2030 /* Construct the API message */
2031 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2032 mp->sw_if_index = ntohl (sw_if_index);
2033 mp->weight = ntohl (weight);
2034
2035 S (mp);
2036 W (ret);
2037 return ret;
2038}
2039
Steven9cd2d7a2017-12-20 12:43:01 -08002040static void vl_api_sw_interface_bond_details_t_handler
2041 (vl_api_sw_interface_bond_details_t * mp)
2042{
2043 vat_main_t *vam = &vat_main;
2044
2045 print (vam->ofp,
2046 "%-16s %-12d %-12U %-13U %-14u %-14u",
2047 mp->interface_name, ntohl (mp->sw_if_index),
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02002048 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2049 ntohl (mp->lb), ntohl (mp->active_slaves), ntohl (mp->slaves));
Steven9cd2d7a2017-12-20 12:43:01 -08002050}
2051
2052static void vl_api_sw_interface_bond_details_t_handler_json
2053 (vl_api_sw_interface_bond_details_t * mp)
2054{
2055 vat_main_t *vam = &vat_main;
2056 vat_json_node_t *node = NULL;
2057
2058 if (VAT_JSON_ARRAY != vam->json_tree.type)
2059 {
2060 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2061 vat_json_init_array (&vam->json_tree);
2062 }
2063 node = vat_json_array_add (&vam->json_tree);
2064
2065 vat_json_init_object (node);
2066 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2067 vat_json_object_add_string_copy (node, "interface_name",
2068 mp->interface_name);
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02002069 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2070 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
Steven9cd2d7a2017-12-20 12:43:01 -08002071 vat_json_object_add_uint (node, "active_slaves", ntohl (mp->active_slaves));
2072 vat_json_object_add_uint (node, "slaves", ntohl (mp->slaves));
2073}
2074
2075static int
2076api_sw_interface_bond_dump (vat_main_t * vam)
2077{
2078 vl_api_sw_interface_bond_dump_t *mp;
2079 vl_api_control_ping_t *mp_ping;
2080 int ret;
2081
2082 print (vam->ofp,
2083 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2084 "interface name", "sw_if_index", "mode", "load balance",
2085 "active slaves", "slaves");
2086
2087 /* Get list of bond interfaces */
2088 M (SW_INTERFACE_BOND_DUMP, mp);
2089 S (mp);
2090
2091 /* Use a control ping for synchronization */
2092 MPING (CONTROL_PING, mp_ping);
2093 S (mp_ping);
2094
2095 W (ret);
2096 return ret;
2097}
2098
2099static void vl_api_sw_interface_slave_details_t_handler
2100 (vl_api_sw_interface_slave_details_t * mp)
2101{
2102 vat_main_t *vam = &vat_main;
2103
2104 print (vam->ofp,
Steven Luonga1876b82019-08-20 16:58:00 -07002105 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2106 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2107 ntohl (mp->weight), mp->is_local_numa);
Steven9cd2d7a2017-12-20 12:43:01 -08002108}
2109
2110static void vl_api_sw_interface_slave_details_t_handler_json
2111 (vl_api_sw_interface_slave_details_t * mp)
2112{
2113 vat_main_t *vam = &vat_main;
2114 vat_json_node_t *node = NULL;
2115
2116 if (VAT_JSON_ARRAY != vam->json_tree.type)
2117 {
2118 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2119 vat_json_init_array (&vam->json_tree);
2120 }
2121 node = vat_json_array_add (&vam->json_tree);
2122
2123 vat_json_init_object (node);
2124 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2125 vat_json_object_add_string_copy (node, "interface_name",
2126 mp->interface_name);
2127 vat_json_object_add_uint (node, "passive", mp->is_passive);
2128 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
Steven Luonga1876b82019-08-20 16:58:00 -07002129 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2130 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
Steven9cd2d7a2017-12-20 12:43:01 -08002131}
2132
2133static int
2134api_sw_interface_slave_dump (vat_main_t * vam)
2135{
2136 unformat_input_t *i = vam->input;
2137 vl_api_sw_interface_slave_dump_t *mp;
2138 vl_api_control_ping_t *mp_ping;
2139 u32 sw_if_index = ~0;
2140 u8 sw_if_index_set = 0;
2141 int ret;
2142
2143 /* Parse args required to build the message */
2144 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2145 {
2146 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2147 sw_if_index_set = 1;
2148 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2149 sw_if_index_set = 1;
2150 else
2151 break;
2152 }
2153
2154 if (sw_if_index_set == 0)
2155 {
2156 errmsg ("missing vpp interface name. ");
2157 return -99;
2158 }
2159
2160 print (vam->ofp,
Steven Luonga1876b82019-08-20 16:58:00 -07002161 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2162 "slave interface name", "sw_if_index", "passive", "long_timeout",
2163 "weight", "local numa");
Steven9cd2d7a2017-12-20 12:43:01 -08002164
2165 /* Get list of bond interfaces */
2166 M (SW_INTERFACE_SLAVE_DUMP, mp);
2167 mp->sw_if_index = ntohl (sw_if_index);
2168 S (mp);
2169
2170 /* Use a control ping for synchronization */
2171 MPING (CONTROL_PING, mp_ping);
2172 S (mp_ping);
2173
2174 W (ret);
2175 return ret;
2176}
2177
Damjan Marion7cd468a2016-12-19 23:05:39 +01002178static void vl_api_mpls_tunnel_add_del_reply_t_handler
2179 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2180{
2181 vat_main_t *vam = &vat_main;
2182 i32 retval = ntohl (mp->retval);
2183 if (vam->async_mode)
2184 {
2185 vam->async_errors += (retval < 0);
2186 }
2187 else
2188 {
2189 vam->retval = retval;
John Lo06fda9c2018-10-03 16:32:44 -04002190 vam->sw_if_index = ntohl (mp->sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002191 vam->result_ready = 1;
2192 }
John Lo06fda9c2018-10-03 16:32:44 -04002193 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002194}
2195
2196static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2197 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2198{
2199 vat_main_t *vam = &vat_main;
2200 vat_json_node_t node;
2201
2202 vat_json_init_object (&node);
2203 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2204 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2205 ntohl (mp->sw_if_index));
2206
2207 vat_json_print (vam->ofp, &node);
2208 vat_json_free (&node);
2209
2210 vam->retval = ntohl (mp->retval);
2211 vam->result_ready = 1;
2212}
2213
2214static void vl_api_l2tpv3_create_tunnel_reply_t_handler
2215 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2216{
2217 vat_main_t *vam = &vat_main;
2218 i32 retval = ntohl (mp->retval);
2219 if (vam->async_mode)
2220 {
2221 vam->async_errors += (retval < 0);
2222 }
2223 else
2224 {
2225 vam->retval = retval;
2226 vam->sw_if_index = ntohl (mp->sw_if_index);
2227 vam->result_ready = 1;
2228 }
2229}
2230
2231static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
2232 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2233{
2234 vat_main_t *vam = &vat_main;
2235 vat_json_node_t node;
2236
2237 vat_json_init_object (&node);
2238 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2239 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2240
2241 vat_json_print (vam->ofp, &node);
2242 vat_json_free (&node);
2243
2244 vam->retval = ntohl (mp->retval);
2245 vam->result_ready = 1;
2246}
2247
Filip Tehlar560274d2017-06-05 13:40:13 +02002248static void vl_api_gpe_add_del_fwd_entry_reply_t_handler
2249 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2250{
2251 vat_main_t *vam = &vat_main;
2252 i32 retval = ntohl (mp->retval);
2253 if (vam->async_mode)
2254 {
2255 vam->async_errors += (retval < 0);
2256 }
2257 else
2258 {
2259 vam->retval = retval;
2260 vam->result_ready = 1;
2261 }
2262}
2263
2264static void vl_api_gpe_add_del_fwd_entry_reply_t_handler_json
2265 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2266{
2267 vat_main_t *vam = &vat_main;
2268 vat_json_node_t node;
2269
2270 vat_json_init_object (&node);
2271 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2272 vat_json_object_add_uint (&node, "fwd_entry_index",
2273 clib_net_to_host_u32 (mp->fwd_entry_index));
2274
2275 vat_json_print (vam->ofp, &node);
2276 vat_json_free (&node);
2277
2278 vam->retval = ntohl (mp->retval);
2279 vam->result_ready = 1;
2280}
Damjan Marion7cd468a2016-12-19 23:05:39 +01002281
Filip Tehlara4980b82017-09-27 14:32:02 +02002282u8 *
2283format_lisp_transport_protocol (u8 * s, va_list * args)
2284{
2285 u32 proto = va_arg (*args, u32);
2286
2287 switch (proto)
2288 {
2289 case 1:
2290 return format (s, "udp");
2291 case 2:
2292 return format (s, "api");
2293 default:
2294 return 0;
2295 }
2296 return 0;
2297}
2298
2299static void vl_api_one_get_transport_protocol_reply_t_handler
2300 (vl_api_one_get_transport_protocol_reply_t * mp)
2301{
2302 vat_main_t *vam = &vat_main;
2303 i32 retval = ntohl (mp->retval);
2304 if (vam->async_mode)
2305 {
2306 vam->async_errors += (retval < 0);
2307 }
2308 else
2309 {
2310 u32 proto = mp->protocol;
2311 print (vam->ofp, "Transport protocol: %U",
2312 format_lisp_transport_protocol, proto);
2313 vam->retval = retval;
2314 vam->result_ready = 1;
2315 }
2316}
2317
2318static void vl_api_one_get_transport_protocol_reply_t_handler_json
2319 (vl_api_one_get_transport_protocol_reply_t * mp)
2320{
2321 vat_main_t *vam = &vat_main;
2322 vat_json_node_t node;
2323 u8 *s;
2324
2325 s = format (0, "%U", format_lisp_transport_protocol, mp->protocol);
2326 vec_add1 (s, 0);
2327
2328 vat_json_init_object (&node);
2329 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2330 vat_json_object_add_string_copy (&node, "transport-protocol", s);
2331
2332 vec_free (s);
2333 vat_json_print (vam->ofp, &node);
2334 vat_json_free (&node);
2335
2336 vam->retval = ntohl (mp->retval);
2337 vam->result_ready = 1;
2338}
2339
Filip Tehlar694396d2017-02-17 14:29:11 +01002340static void vl_api_one_add_del_locator_set_reply_t_handler
2341 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002342{
2343 vat_main_t *vam = &vat_main;
2344 i32 retval = ntohl (mp->retval);
2345 if (vam->async_mode)
2346 {
2347 vam->async_errors += (retval < 0);
2348 }
2349 else
2350 {
2351 vam->retval = retval;
2352 vam->result_ready = 1;
2353 }
2354}
2355
Filip Tehlar694396d2017-02-17 14:29:11 +01002356static void vl_api_one_add_del_locator_set_reply_t_handler_json
2357 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002358{
2359 vat_main_t *vam = &vat_main;
2360 vat_json_node_t node;
2361
2362 vat_json_init_object (&node);
2363 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2364 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
2365
2366 vat_json_print (vam->ofp, &node);
2367 vat_json_free (&node);
2368
2369 vam->retval = ntohl (mp->retval);
2370 vam->result_ready = 1;
2371}
2372
2373static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2374 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2375{
2376 vat_main_t *vam = &vat_main;
2377 i32 retval = ntohl (mp->retval);
2378 if (vam->async_mode)
2379 {
2380 vam->async_errors += (retval < 0);
2381 }
2382 else
2383 {
2384 vam->retval = retval;
2385 vam->sw_if_index = ntohl (mp->sw_if_index);
2386 vam->result_ready = 1;
2387 }
Dave Barachf72212e2018-01-11 10:25:07 -05002388 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002389}
2390
2391static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2392 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2393{
2394 vat_main_t *vam = &vat_main;
2395 vat_json_node_t node;
2396
2397 vat_json_init_object (&node);
2398 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2399 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2400
2401 vat_json_print (vam->ofp, &node);
2402 vat_json_free (&node);
2403
2404 vam->retval = ntohl (mp->retval);
2405 vam->result_ready = 1;
2406}
2407
eyal bariaf86a482018-04-17 11:20:27 +03002408static void vl_api_vxlan_offload_rx_reply_t_handler
2409 (vl_api_vxlan_offload_rx_reply_t * mp)
2410{
2411 vat_main_t *vam = &vat_main;
2412 i32 retval = ntohl (mp->retval);
2413 if (vam->async_mode)
2414 {
2415 vam->async_errors += (retval < 0);
2416 }
2417 else
2418 {
2419 vam->retval = retval;
2420 vam->result_ready = 1;
2421 }
2422}
2423
2424static void vl_api_vxlan_offload_rx_reply_t_handler_json
2425 (vl_api_vxlan_offload_rx_reply_t * mp)
2426{
2427 vat_main_t *vam = &vat_main;
2428 vat_json_node_t node;
2429
2430 vat_json_init_object (&node);
2431 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2432
2433 vat_json_print (vam->ofp, &node);
2434 vat_json_free (&node);
2435
2436 vam->retval = ntohl (mp->retval);
2437 vam->result_ready = 1;
2438}
2439
Marco Varleseb598f1d2017-09-19 14:25:28 +02002440static void vl_api_geneve_add_del_tunnel_reply_t_handler
2441 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2442{
2443 vat_main_t *vam = &vat_main;
2444 i32 retval = ntohl (mp->retval);
2445 if (vam->async_mode)
2446 {
2447 vam->async_errors += (retval < 0);
2448 }
2449 else
2450 {
2451 vam->retval = retval;
2452 vam->sw_if_index = ntohl (mp->sw_if_index);
2453 vam->result_ready = 1;
2454 }
2455}
2456
2457static void vl_api_geneve_add_del_tunnel_reply_t_handler_json
2458 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2459{
2460 vat_main_t *vam = &vat_main;
2461 vat_json_node_t node;
2462
2463 vat_json_init_object (&node);
2464 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2465 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2466
2467 vat_json_print (vam->ofp, &node);
2468 vat_json_free (&node);
2469
2470 vam->retval = ntohl (mp->retval);
2471 vam->result_ready = 1;
2472}
2473
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002474static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2475 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2476{
2477 vat_main_t *vam = &vat_main;
2478 i32 retval = ntohl (mp->retval);
2479 if (vam->async_mode)
2480 {
2481 vam->async_errors += (retval < 0);
2482 }
2483 else
2484 {
2485 vam->retval = retval;
2486 vam->sw_if_index = ntohl (mp->sw_if_index);
2487 vam->result_ready = 1;
2488 }
Dave Barachf72212e2018-01-11 10:25:07 -05002489 vam->regenerate_interface_table = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002490}
2491
2492static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2493 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2494{
2495 vat_main_t *vam = &vat_main;
2496 vat_json_node_t node;
2497
2498 vat_json_init_object (&node);
2499 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2500 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2501
2502 vat_json_print (vam->ofp, &node);
2503 vat_json_free (&node);
2504
2505 vam->retval = ntohl (mp->retval);
2506 vam->result_ready = 1;
2507}
2508
Neale Ranns5a8844b2019-04-16 07:15:35 +00002509static void vl_api_gre_tunnel_add_del_reply_t_handler
2510 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002511{
2512 vat_main_t *vam = &vat_main;
2513 i32 retval = ntohl (mp->retval);
2514 if (vam->async_mode)
2515 {
2516 vam->async_errors += (retval < 0);
2517 }
2518 else
2519 {
2520 vam->retval = retval;
2521 vam->sw_if_index = ntohl (mp->sw_if_index);
2522 vam->result_ready = 1;
2523 }
2524}
2525
Neale Ranns5a8844b2019-04-16 07:15:35 +00002526static void vl_api_gre_tunnel_add_del_reply_t_handler_json
2527 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002528{
2529 vat_main_t *vam = &vat_main;
2530 vat_json_node_t node;
2531
2532 vat_json_init_object (&node);
2533 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2534 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2535
2536 vat_json_print (vam->ofp, &node);
2537 vat_json_free (&node);
2538
2539 vam->retval = ntohl (mp->retval);
2540 vam->result_ready = 1;
2541}
2542
2543static void vl_api_create_vhost_user_if_reply_t_handler
2544 (vl_api_create_vhost_user_if_reply_t * mp)
2545{
2546 vat_main_t *vam = &vat_main;
2547 i32 retval = ntohl (mp->retval);
2548 if (vam->async_mode)
2549 {
2550 vam->async_errors += (retval < 0);
2551 }
2552 else
2553 {
2554 vam->retval = retval;
2555 vam->sw_if_index = ntohl (mp->sw_if_index);
2556 vam->result_ready = 1;
2557 }
Dave Barachf72212e2018-01-11 10:25:07 -05002558 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002559}
2560
2561static void vl_api_create_vhost_user_if_reply_t_handler_json
2562 (vl_api_create_vhost_user_if_reply_t * mp)
2563{
2564 vat_main_t *vam = &vat_main;
2565 vat_json_node_t node;
2566
2567 vat_json_init_object (&node);
2568 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2569 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2570
2571 vat_json_print (vam->ofp, &node);
2572 vat_json_free (&node);
2573
2574 vam->retval = ntohl (mp->retval);
2575 vam->result_ready = 1;
2576}
2577
2578static void vl_api_ip_address_details_t_handler
2579 (vl_api_ip_address_details_t * mp)
2580{
2581 vat_main_t *vam = &vat_main;
2582 static ip_address_details_t empty_ip_address_details = { {0} };
2583 ip_address_details_t *address = NULL;
2584 ip_details_t *current_ip_details = NULL;
2585 ip_details_t *details = NULL;
2586
2587 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2588
2589 if (!details || vam->current_sw_if_index >= vec_len (details)
2590 || !details[vam->current_sw_if_index].present)
2591 {
2592 errmsg ("ip address details arrived but not stored");
2593 errmsg ("ip_dump should be called first");
2594 return;
2595 }
2596
2597 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2598
2599#define addresses (current_ip_details->addr)
2600
2601 vec_validate_init_empty (addresses, vec_len (addresses),
2602 empty_ip_address_details);
2603
2604 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2605
Neale Ranns097fa662018-05-01 05:17:55 -07002606 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
Paul Vinciguerraab055082019-06-06 14:07:55 -04002607 address->prefix_length = mp->prefix.len;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002608#undef addresses
2609}
2610
2611static void vl_api_ip_address_details_t_handler_json
2612 (vl_api_ip_address_details_t * mp)
2613{
2614 vat_main_t *vam = &vat_main;
2615 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002616
2617 if (VAT_JSON_ARRAY != vam->json_tree.type)
2618 {
2619 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2620 vat_json_init_array (&vam->json_tree);
2621 }
2622 node = vat_json_array_add (&vam->json_tree);
2623
2624 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -07002625 vat_json_object_add_prefix (node, &mp->prefix);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002626}
2627
2628static void
2629vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2630{
2631 vat_main_t *vam = &vat_main;
2632 static ip_details_t empty_ip_details = { 0 };
2633 ip_details_t *ip = NULL;
2634 u32 sw_if_index = ~0;
2635
2636 sw_if_index = ntohl (mp->sw_if_index);
2637
2638 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2639 sw_if_index, empty_ip_details);
2640
2641 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2642 sw_if_index);
2643
2644 ip->present = 1;
2645}
2646
2647static void
2648vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2649{
2650 vat_main_t *vam = &vat_main;
2651
2652 if (VAT_JSON_ARRAY != vam->json_tree.type)
2653 {
2654 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2655 vat_json_init_array (&vam->json_tree);
2656 }
2657 vat_json_array_add_uint (&vam->json_tree,
2658 clib_net_to_host_u32 (mp->sw_if_index));
2659}
2660
Damjan Marion7cd468a2016-12-19 23:05:39 +01002661static void vl_api_get_first_msg_id_reply_t_handler
2662 (vl_api_get_first_msg_id_reply_t * mp)
2663{
2664 vat_main_t *vam = &vat_main;
2665 i32 retval = ntohl (mp->retval);
2666
2667 if (vam->async_mode)
2668 {
2669 vam->async_errors += (retval < 0);
2670 }
2671 else
2672 {
2673 vam->retval = retval;
2674 vam->result_ready = 1;
2675 }
2676 if (retval >= 0)
2677 {
2678 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2679 }
2680}
2681
2682static void vl_api_get_first_msg_id_reply_t_handler_json
2683 (vl_api_get_first_msg_id_reply_t * mp)
2684{
2685 vat_main_t *vam = &vat_main;
2686 vat_json_node_t node;
2687
2688 vat_json_init_object (&node);
2689 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2690 vat_json_object_add_uint (&node, "first_msg_id",
2691 (uint) ntohs (mp->first_msg_id));
2692
2693 vat_json_print (vam->ofp, &node);
2694 vat_json_free (&node);
2695
2696 vam->retval = ntohl (mp->retval);
2697 vam->result_ready = 1;
2698}
2699
2700static void vl_api_get_node_graph_reply_t_handler
2701 (vl_api_get_node_graph_reply_t * mp)
2702{
2703 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002704 i32 retval = ntohl (mp->retval);
2705 u8 *pvt_copy, *reply;
2706 void *oldheap;
2707 vlib_node_t *node;
2708 int i;
2709
2710 if (vam->async_mode)
2711 {
2712 vam->async_errors += (retval < 0);
2713 }
2714 else
2715 {
2716 vam->retval = retval;
2717 vam->result_ready = 1;
2718 }
2719
2720 /* "Should never happen..." */
2721 if (retval != 0)
2722 return;
2723
Damjan Marion7bee80c2017-04-26 15:32:12 +02002724 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002725 pvt_copy = vec_dup (reply);
2726
2727 /* Toss the shared-memory original... */
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002728 oldheap = vl_msg_push_heap ();
Damjan Marion7cd468a2016-12-19 23:05:39 +01002729
2730 vec_free (reply);
2731
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002732 vl_msg_pop_heap (oldheap);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002733
2734 if (vam->graph_nodes)
2735 {
2736 hash_free (vam->graph_node_index_by_name);
2737
Dave Barach1ddbc012018-06-13 09:26:05 -04002738 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002739 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002740 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002741 vec_free (node->name);
2742 vec_free (node->next_nodes);
2743 vec_free (node);
2744 }
Dave Barach1ddbc012018-06-13 09:26:05 -04002745 vec_free (vam->graph_nodes[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002746 vec_free (vam->graph_nodes);
2747 }
2748
2749 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2750 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2751 vec_free (pvt_copy);
2752
Dave Barach1ddbc012018-06-13 09:26:05 -04002753 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002754 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002755 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002756 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2757 }
2758}
2759
2760static void vl_api_get_node_graph_reply_t_handler_json
2761 (vl_api_get_node_graph_reply_t * mp)
2762{
2763 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002764 void *oldheap;
2765 vat_json_node_t node;
2766 u8 *reply;
2767
2768 /* $$$$ make this real? */
2769 vat_json_init_object (&node);
2770 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2771 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2772
Damjan Marion7bee80c2017-04-26 15:32:12 +02002773 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002774
2775 /* Toss the shared-memory original... */
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002776 oldheap = vl_msg_push_heap ();
Damjan Marion7cd468a2016-12-19 23:05:39 +01002777
2778 vec_free (reply);
2779
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002780 vl_msg_pop_heap (oldheap);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002781
2782 vat_json_print (vam->ofp, &node);
2783 vat_json_free (&node);
2784
2785 vam->retval = ntohl (mp->retval);
2786 vam->result_ready = 1;
2787}
2788
2789static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002790vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002791{
2792 vat_main_t *vam = &vat_main;
2793 u8 *s = 0;
2794
2795 if (mp->local)
2796 {
2797 s = format (s, "%=16d%=16d%=16d",
2798 ntohl (mp->sw_if_index), mp->priority, mp->weight);
2799 }
2800 else
2801 {
2802 s = format (s, "%=16U%=16d%=16d",
2803 mp->is_ipv6 ? format_ip6_address :
2804 format_ip4_address,
2805 mp->ip_address, mp->priority, mp->weight);
2806 }
2807
2808 print (vam->ofp, "%v", s);
2809 vec_free (s);
2810}
2811
2812static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002813vl_api_one_locator_details_t_handler_json (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002814{
2815 vat_main_t *vam = &vat_main;
2816 vat_json_node_t *node = NULL;
2817 struct in6_addr ip6;
2818 struct in_addr ip4;
2819
2820 if (VAT_JSON_ARRAY != vam->json_tree.type)
2821 {
2822 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2823 vat_json_init_array (&vam->json_tree);
2824 }
2825 node = vat_json_array_add (&vam->json_tree);
2826 vat_json_init_object (node);
2827
2828 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2829 vat_json_object_add_uint (node, "priority", mp->priority);
2830 vat_json_object_add_uint (node, "weight", mp->weight);
2831
2832 if (mp->local)
2833 vat_json_object_add_uint (node, "sw_if_index",
2834 clib_net_to_host_u32 (mp->sw_if_index));
2835 else
2836 {
2837 if (mp->is_ipv6)
2838 {
2839 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2840 vat_json_object_add_ip6 (node, "address", ip6);
2841 }
2842 else
2843 {
2844 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2845 vat_json_object_add_ip4 (node, "address", ip4);
2846 }
2847 }
2848}
2849
2850static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002851vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
2852 mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002853{
2854 vat_main_t *vam = &vat_main;
2855 u8 *ls_name = 0;
2856
2857 ls_name = format (0, "%s", mp->ls_name);
2858
2859 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
2860 ls_name);
2861 vec_free (ls_name);
2862}
2863
2864static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002865 vl_api_one_locator_set_details_t_handler_json
2866 (vl_api_one_locator_set_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002867{
2868 vat_main_t *vam = &vat_main;
2869 vat_json_node_t *node = 0;
2870 u8 *ls_name = 0;
2871
2872 ls_name = format (0, "%s", mp->ls_name);
2873 vec_add1 (ls_name, 0);
2874
2875 if (VAT_JSON_ARRAY != vam->json_tree.type)
2876 {
2877 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2878 vat_json_init_array (&vam->json_tree);
2879 }
2880 node = vat_json_array_add (&vam->json_tree);
2881
2882 vat_json_init_object (node);
2883 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2884 vat_json_object_add_uint (node, "ls_index",
2885 clib_net_to_host_u32 (mp->ls_index));
2886 vec_free (ls_name);
2887}
2888
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002889typedef struct
2890{
2891 u32 spi;
2892 u8 si;
2893} __attribute__ ((__packed__)) lisp_nsh_api_t;
2894
2895uword
2896unformat_nsh_address (unformat_input_t * input, va_list * args)
2897{
2898 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
2899 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
2900}
2901
2902u8 *
2903format_nsh_address_vat (u8 * s, va_list * args)
2904{
2905 nsh_t *a = va_arg (*args, nsh_t *);
2906 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
2907}
2908
Damjan Marion7cd468a2016-12-19 23:05:39 +01002909static u8 *
2910format_lisp_flat_eid (u8 * s, va_list * args)
2911{
2912 u32 type = va_arg (*args, u32);
2913 u8 *eid = va_arg (*args, u8 *);
2914 u32 eid_len = va_arg (*args, u32);
2915
2916 switch (type)
2917 {
2918 case 0:
2919 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2920 case 1:
2921 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2922 case 2:
2923 return format (s, "%U", format_ethernet_address, eid);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002924 case 3:
2925 return format (s, "%U", format_nsh_address_vat, eid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002926 }
2927 return 0;
2928}
2929
2930static u8 *
2931format_lisp_eid_vat (u8 * s, va_list * args)
2932{
2933 u32 type = va_arg (*args, u32);
2934 u8 *eid = va_arg (*args, u8 *);
2935 u32 eid_len = va_arg (*args, u32);
2936 u8 *seid = va_arg (*args, u8 *);
2937 u32 seid_len = va_arg (*args, u32);
2938 u32 is_src_dst = va_arg (*args, u32);
2939
2940 if (is_src_dst)
2941 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
2942
2943 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
2944
2945 return s;
2946}
2947
2948static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002949vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002950{
2951 vat_main_t *vam = &vat_main;
2952 u8 *s = 0, *eid = 0;
2953
2954 if (~0 == mp->locator_set_index)
2955 s = format (0, "action: %d", mp->action);
2956 else
2957 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2958
2959 eid = format (0, "%U", format_lisp_eid_vat,
2960 mp->eid_type,
2961 mp->eid,
2962 mp->eid_prefix_len,
2963 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2964 vec_add1 (eid, 0);
2965
2966 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
2967 clib_net_to_host_u32 (mp->vni),
2968 eid,
2969 mp->is_local ? "local" : "remote",
2970 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
2971 clib_net_to_host_u16 (mp->key_id), mp->key);
2972
2973 vec_free (s);
2974 vec_free (eid);
2975}
2976
2977static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002978vl_api_one_eid_table_details_t_handler_json (vl_api_one_eid_table_details_t
2979 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002980{
2981 vat_main_t *vam = &vat_main;
2982 vat_json_node_t *node = 0;
2983 u8 *eid = 0;
2984
2985 if (VAT_JSON_ARRAY != vam->json_tree.type)
2986 {
2987 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2988 vat_json_init_array (&vam->json_tree);
2989 }
2990 node = vat_json_array_add (&vam->json_tree);
2991
2992 vat_json_init_object (node);
2993 if (~0 == mp->locator_set_index)
2994 vat_json_object_add_uint (node, "action", mp->action);
2995 else
2996 vat_json_object_add_uint (node, "locator_set_index",
2997 clib_net_to_host_u32 (mp->locator_set_index));
2998
2999 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003000 if (mp->eid_type == 3)
3001 {
3002 vat_json_node_t *nsh_json = vat_json_object_add (node, "eid");
3003 vat_json_init_object (nsh_json);
3004 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) mp->eid;
3005 vat_json_object_add_uint (nsh_json, "spi",
3006 clib_net_to_host_u32 (nsh->spi));
3007 vat_json_object_add_uint (nsh_json, "si", nsh->si);
3008 }
3009 else
3010 {
3011 eid = format (0, "%U", format_lisp_eid_vat,
3012 mp->eid_type,
3013 mp->eid,
3014 mp->eid_prefix_len,
3015 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
3016 vec_add1 (eid, 0);
3017 vat_json_object_add_string_copy (node, "eid", eid);
3018 vec_free (eid);
3019 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003020 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3021 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
3022 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
3023
3024 if (mp->key_id)
3025 {
3026 vat_json_object_add_uint (node, "key_id",
3027 clib_net_to_host_u16 (mp->key_id));
3028 vat_json_object_add_string_copy (node, "key", mp->key);
3029 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003030}
3031
3032static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003033vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
3034{
3035 vat_main_t *vam = &vat_main;
3036 u8 *seid = 0, *deid = 0;
3037 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3038
3039 deid = format (0, "%U", format_lisp_eid_vat,
3040 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3041
3042 seid = format (0, "%U", format_lisp_eid_vat,
3043 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3044
3045 vec_add1 (deid, 0);
3046 vec_add1 (seid, 0);
3047
3048 if (mp->is_ip4)
3049 format_ip_address_fcn = format_ip4_address;
3050 else
3051 format_ip_address_fcn = format_ip6_address;
3052
3053
3054 print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
3055 clib_net_to_host_u32 (mp->vni),
3056 seid, deid,
3057 format_ip_address_fcn, mp->lloc,
3058 format_ip_address_fcn, mp->rloc,
3059 clib_net_to_host_u32 (mp->pkt_count),
3060 clib_net_to_host_u32 (mp->bytes));
3061
3062 vec_free (deid);
3063 vec_free (seid);
3064}
3065
3066static void
3067vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp)
3068{
3069 struct in6_addr ip6;
3070 struct in_addr ip4;
3071 vat_main_t *vam = &vat_main;
3072 vat_json_node_t *node = 0;
3073 u8 *deid = 0, *seid = 0;
3074
3075 if (VAT_JSON_ARRAY != vam->json_tree.type)
3076 {
3077 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3078 vat_json_init_array (&vam->json_tree);
3079 }
3080 node = vat_json_array_add (&vam->json_tree);
3081
3082 vat_json_init_object (node);
3083 deid = format (0, "%U", format_lisp_eid_vat,
3084 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3085
3086 seid = format (0, "%U", format_lisp_eid_vat,
3087 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3088
3089 vec_add1 (deid, 0);
3090 vec_add1 (seid, 0);
3091
3092 vat_json_object_add_string_copy (node, "seid", seid);
3093 vat_json_object_add_string_copy (node, "deid", deid);
3094 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3095
3096 if (mp->is_ip4)
3097 {
3098 clib_memcpy (&ip4, mp->lloc, sizeof (ip4));
3099 vat_json_object_add_ip4 (node, "lloc", ip4);
3100 clib_memcpy (&ip4, mp->rloc, sizeof (ip4));
3101 vat_json_object_add_ip4 (node, "rloc", ip4);
3102 }
3103 else
3104 {
3105 clib_memcpy (&ip6, mp->lloc, sizeof (ip6));
3106 vat_json_object_add_ip6 (node, "lloc", ip6);
3107 clib_memcpy (&ip6, mp->rloc, sizeof (ip6));
3108 vat_json_object_add_ip6 (node, "rloc", ip6);
3109 }
3110 vat_json_object_add_uint (node, "pkt_count",
3111 clib_net_to_host_u32 (mp->pkt_count));
3112 vat_json_object_add_uint (node, "bytes", clib_net_to_host_u32 (mp->bytes));
3113
3114 vec_free (deid);
3115 vec_free (seid);
3116}
3117
3118static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003119 vl_api_one_eid_table_map_details_t_handler
3120 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003121{
3122 vat_main_t *vam = &vat_main;
3123
3124 u8 *line = format (0, "%=10d%=10d",
3125 clib_net_to_host_u32 (mp->vni),
3126 clib_net_to_host_u32 (mp->dp_table));
3127 print (vam->ofp, "%v", line);
3128 vec_free (line);
3129}
3130
3131static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003132 vl_api_one_eid_table_map_details_t_handler_json
3133 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003134{
3135 vat_main_t *vam = &vat_main;
3136 vat_json_node_t *node = NULL;
3137
3138 if (VAT_JSON_ARRAY != vam->json_tree.type)
3139 {
3140 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3141 vat_json_init_array (&vam->json_tree);
3142 }
3143 node = vat_json_array_add (&vam->json_tree);
3144 vat_json_init_object (node);
3145 vat_json_object_add_uint (node, "dp_table",
3146 clib_net_to_host_u32 (mp->dp_table));
3147 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3148}
3149
3150static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003151 vl_api_one_eid_table_vni_details_t_handler
3152 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003153{
3154 vat_main_t *vam = &vat_main;
3155
3156 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
3157 print (vam->ofp, "%v", line);
3158 vec_free (line);
3159}
3160
3161static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003162 vl_api_one_eid_table_vni_details_t_handler_json
3163 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003164{
3165 vat_main_t *vam = &vat_main;
3166 vat_json_node_t *node = NULL;
3167
3168 if (VAT_JSON_ARRAY != vam->json_tree.type)
3169 {
3170 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3171 vat_json_init_array (&vam->json_tree);
3172 }
3173 node = vat_json_array_add (&vam->json_tree);
3174 vat_json_init_object (node);
3175 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3176}
3177
Damjan Marion7cd468a2016-12-19 23:05:39 +01003178static void
Filip Tehlar7048ff12017-07-27 08:09:14 +02003179 vl_api_show_one_map_register_fallback_threshold_reply_t_handler
3180 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3181{
3182 vat_main_t *vam = &vat_main;
3183 int retval = clib_net_to_host_u32 (mp->retval);
3184
3185 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3186 print (vam->ofp, "fallback threshold value: %d", mp->value);
3187
3188 vam->retval = retval;
3189 vam->result_ready = 1;
3190}
3191
3192static void
3193 vl_api_show_one_map_register_fallback_threshold_reply_t_handler_json
3194 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3195{
3196 vat_main_t *vam = &vat_main;
3197 vat_json_node_t _node, *node = &_node;
3198 int retval = clib_net_to_host_u32 (mp->retval);
3199
3200 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3201 vat_json_init_object (node);
3202 vat_json_object_add_uint (node, "value", mp->value);
3203
3204 vat_json_print (vam->ofp, node);
3205 vat_json_free (node);
3206
3207 vam->retval = retval;
3208 vam->result_ready = 1;
3209}
3210
3211static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003212 vl_api_show_one_map_register_state_reply_t_handler
3213 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003214{
3215 vat_main_t *vam = &vat_main;
3216 int retval = clib_net_to_host_u32 (mp->retval);
3217
3218 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3219
3220 vam->retval = retval;
3221 vam->result_ready = 1;
3222}
3223
3224static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003225 vl_api_show_one_map_register_state_reply_t_handler_json
3226 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003227{
3228 vat_main_t *vam = &vat_main;
3229 vat_json_node_t _node, *node = &_node;
3230 int retval = clib_net_to_host_u32 (mp->retval);
3231
3232 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3233
3234 vat_json_init_object (node);
3235 vat_json_object_add_string_copy (node, "state", s);
3236
3237 vat_json_print (vam->ofp, node);
3238 vat_json_free (node);
3239
3240 vam->retval = retval;
3241 vam->result_ready = 1;
3242 vec_free (s);
3243}
3244
3245static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003246 vl_api_show_one_rloc_probe_state_reply_t_handler
3247 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003248{
3249 vat_main_t *vam = &vat_main;
3250 int retval = clib_net_to_host_u32 (mp->retval);
3251
3252 if (retval)
3253 goto end;
3254
3255 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3256end:
3257 vam->retval = retval;
3258 vam->result_ready = 1;
3259}
3260
3261static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003262 vl_api_show_one_rloc_probe_state_reply_t_handler_json
3263 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003264{
3265 vat_main_t *vam = &vat_main;
3266 vat_json_node_t _node, *node = &_node;
3267 int retval = clib_net_to_host_u32 (mp->retval);
3268
3269 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3270 vat_json_init_object (node);
3271 vat_json_object_add_string_copy (node, "state", s);
3272
3273 vat_json_print (vam->ofp, node);
3274 vat_json_free (node);
3275
3276 vam->retval = retval;
3277 vam->result_ready = 1;
3278 vec_free (s);
3279}
3280
3281static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003282 vl_api_show_one_stats_enable_disable_reply_t_handler
3283 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3284{
3285 vat_main_t *vam = &vat_main;
3286 int retval = clib_net_to_host_u32 (mp->retval);
3287
3288 if (retval)
3289 goto end;
3290
3291 print (vam->ofp, "%s", mp->is_en ? "enabled" : "disabled");
3292end:
3293 vam->retval = retval;
3294 vam->result_ready = 1;
3295}
3296
3297static void
3298 vl_api_show_one_stats_enable_disable_reply_t_handler_json
3299 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3300{
3301 vat_main_t *vam = &vat_main;
3302 vat_json_node_t _node, *node = &_node;
3303 int retval = clib_net_to_host_u32 (mp->retval);
3304
3305 u8 *s = format (0, "%s", mp->is_en ? "enabled" : "disabled");
3306 vat_json_init_object (node);
3307 vat_json_object_add_string_copy (node, "state", s);
3308
3309 vat_json_print (vam->ofp, node);
3310 vat_json_free (node);
3311
3312 vam->retval = retval;
3313 vam->result_ready = 1;
3314 vec_free (s);
3315}
3316
3317static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003318api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003319{
3320 e->dp_table = clib_net_to_host_u32 (e->dp_table);
3321 e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003322 e->vni = clib_net_to_host_u32 (e->vni);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003323}
3324
3325static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003326 gpe_fwd_entries_get_reply_t_net_to_host
3327 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003328{
3329 u32 i;
3330
3331 mp->count = clib_net_to_host_u32 (mp->count);
3332 for (i = 0; i < mp->count; i++)
3333 {
Filip Tehlar82786c42017-02-20 15:20:37 +01003334 api_gpe_fwd_entry_net_to_host (&mp->entries[i]);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003335 }
3336}
3337
Filip Tehlar3e7b56932017-02-21 18:28:34 +01003338static u8 *
3339format_gpe_encap_mode (u8 * s, va_list * args)
3340{
3341 u32 mode = va_arg (*args, u32);
3342
3343 switch (mode)
3344 {
3345 case 0:
3346 return format (s, "lisp");
3347 case 1:
3348 return format (s, "vxlan");
3349 }
3350 return 0;
3351}
3352
3353static void
3354 vl_api_gpe_get_encap_mode_reply_t_handler
3355 (vl_api_gpe_get_encap_mode_reply_t * mp)
3356{
3357 vat_main_t *vam = &vat_main;
3358
3359 print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode);
3360 vam->retval = ntohl (mp->retval);
3361 vam->result_ready = 1;
3362}
3363
3364static void
3365 vl_api_gpe_get_encap_mode_reply_t_handler_json
3366 (vl_api_gpe_get_encap_mode_reply_t * mp)
3367{
3368 vat_main_t *vam = &vat_main;
3369 vat_json_node_t node;
3370
3371 u8 *encap_mode = format (0, "%U", format_gpe_encap_mode, mp->encap_mode);
3372 vec_add1 (encap_mode, 0);
3373
3374 vat_json_init_object (&node);
3375 vat_json_object_add_string_copy (&node, "gpe_mode", encap_mode);
3376
3377 vec_free (encap_mode);
3378 vat_json_print (vam->ofp, &node);
3379 vat_json_free (&node);
3380
3381 vam->retval = ntohl (mp->retval);
3382 vam->result_ready = 1;
3383}
3384
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003385static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003386 vl_api_gpe_fwd_entry_path_details_t_handler
3387 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003388{
3389 vat_main_t *vam = &vat_main;
3390 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3391
3392 if (mp->lcl_loc.is_ip4)
3393 format_ip_address_fcn = format_ip4_address;
3394 else
3395 format_ip_address_fcn = format_ip6_address;
3396
3397 print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight,
3398 format_ip_address_fcn, &mp->lcl_loc,
3399 format_ip_address_fcn, &mp->rmt_loc);
3400}
3401
3402static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003403lisp_fill_locator_node (vat_json_node_t * n, vl_api_gpe_locator_t * loc)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003404{
3405 struct in6_addr ip6;
3406 struct in_addr ip4;
3407
3408 if (loc->is_ip4)
3409 {
3410 clib_memcpy (&ip4, loc->addr, sizeof (ip4));
3411 vat_json_object_add_ip4 (n, "address", ip4);
3412 }
3413 else
3414 {
3415 clib_memcpy (&ip6, loc->addr, sizeof (ip6));
3416 vat_json_object_add_ip6 (n, "address", ip6);
3417 }
3418 vat_json_object_add_uint (n, "weight", loc->weight);
3419}
3420
3421static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003422 vl_api_gpe_fwd_entry_path_details_t_handler_json
3423 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003424{
3425 vat_main_t *vam = &vat_main;
3426 vat_json_node_t *node = NULL;
3427 vat_json_node_t *loc_node;
3428
3429 if (VAT_JSON_ARRAY != vam->json_tree.type)
3430 {
3431 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3432 vat_json_init_array (&vam->json_tree);
3433 }
3434 node = vat_json_array_add (&vam->json_tree);
3435 vat_json_init_object (node);
3436
3437 loc_node = vat_json_object_add (node, "local_locator");
3438 vat_json_init_object (loc_node);
3439 lisp_fill_locator_node (loc_node, &mp->lcl_loc);
3440
3441 loc_node = vat_json_object_add (node, "remote_locator");
3442 vat_json_init_object (loc_node);
3443 lisp_fill_locator_node (loc_node, &mp->rmt_loc);
3444}
3445
3446static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003447 vl_api_gpe_fwd_entries_get_reply_t_handler
3448 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003449{
3450 vat_main_t *vam = &vat_main;
3451 u32 i;
3452 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003453 vl_api_gpe_fwd_entry_t *e;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003454
3455 if (retval)
3456 goto end;
3457
Filip Tehlar82786c42017-02-20 15:20:37 +01003458 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003459
3460 for (i = 0; i < mp->count; i++)
3461 {
3462 e = &mp->entries[i];
3463 print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table,
3464 format_lisp_flat_eid, e->eid_type, e->leid, e->leid_prefix_len,
3465 format_lisp_flat_eid, e->eid_type, e->reid, e->reid_prefix_len);
3466 }
3467
3468end:
3469 vam->retval = retval;
3470 vam->result_ready = 1;
3471}
3472
3473static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003474 vl_api_gpe_fwd_entries_get_reply_t_handler_json
3475 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003476{
3477 u8 *s = 0;
3478 vat_main_t *vam = &vat_main;
3479 vat_json_node_t *e = 0, root;
3480 u32 i;
3481 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003482 vl_api_gpe_fwd_entry_t *fwd;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003483
3484 if (retval)
3485 goto end;
3486
Filip Tehlar82786c42017-02-20 15:20:37 +01003487 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003488 vat_json_init_array (&root);
3489
3490 for (i = 0; i < mp->count; i++)
3491 {
3492 e = vat_json_array_add (&root);
3493 fwd = &mp->entries[i];
3494
3495 vat_json_init_object (e);
3496 vat_json_object_add_int (e, "fwd_entry_index", fwd->fwd_entry_index);
3497 vat_json_object_add_int (e, "dp_table", fwd->dp_table);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003498 vat_json_object_add_int (e, "vni", fwd->vni);
3499 vat_json_object_add_int (e, "action", fwd->action);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003500
3501 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->leid,
3502 fwd->leid_prefix_len);
3503 vec_add1 (s, 0);
3504 vat_json_object_add_string_copy (e, "leid", s);
3505 vec_free (s);
3506
3507 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->reid,
3508 fwd->reid_prefix_len);
3509 vec_add1 (s, 0);
3510 vat_json_object_add_string_copy (e, "reid", s);
3511 vec_free (s);
3512 }
3513
3514 vat_json_print (vam->ofp, &root);
3515 vat_json_free (&root);
3516
3517end:
3518 vam->retval = retval;
3519 vam->result_ready = 1;
3520}
3521
3522static void
Filip Tehlarb4243aa2017-06-14 14:39:42 +02003523 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler
3524 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3525{
3526 vat_main_t *vam = &vat_main;
3527 u32 i, n;
3528 int retval = clib_net_to_host_u32 (mp->retval);
3529 vl_api_gpe_native_fwd_rpath_t *r;
3530
3531 if (retval)
3532 goto end;
3533
3534 n = clib_net_to_host_u32 (mp->count);
3535
3536 for (i = 0; i < n; i++)
3537 {
3538 r = &mp->entries[i];
3539 print (vam->ofp, "fib_index: %d sw_if_index %d nh %U",
3540 clib_net_to_host_u32 (r->fib_index),
3541 clib_net_to_host_u32 (r->nh_sw_if_index),
3542 r->is_ip4 ? format_ip4_address : format_ip6_address, r->nh_addr);
3543 }
3544
3545end:
3546 vam->retval = retval;
3547 vam->result_ready = 1;
3548}
3549
3550static void
3551 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler_json
3552 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3553{
3554 vat_main_t *vam = &vat_main;
3555 vat_json_node_t root, *e;
3556 u32 i, n;
3557 int retval = clib_net_to_host_u32 (mp->retval);
3558 vl_api_gpe_native_fwd_rpath_t *r;
3559 u8 *s;
3560
3561 if (retval)
3562 goto end;
3563
3564 n = clib_net_to_host_u32 (mp->count);
3565 vat_json_init_array (&root);
3566
3567 for (i = 0; i < n; i++)
3568 {
3569 e = vat_json_array_add (&root);
3570 vat_json_init_object (e);
3571 r = &mp->entries[i];
3572 s =
3573 format (0, "%U", r->is_ip4 ? format_ip4_address : format_ip6_address,
3574 r->nh_addr);
3575 vec_add1 (s, 0);
3576 vat_json_object_add_string_copy (e, "ip4", s);
3577 vec_free (s);
3578
3579 vat_json_object_add_uint (e, "fib_index",
3580 clib_net_to_host_u32 (r->fib_index));
3581 vat_json_object_add_uint (e, "nh_sw_if_index",
3582 clib_net_to_host_u32 (r->nh_sw_if_index));
3583 }
3584
3585 vat_json_print (vam->ofp, &root);
3586 vat_json_free (&root);
3587
3588end:
3589 vam->retval = retval;
3590 vam->result_ready = 1;
3591}
3592
3593static void
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003594 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler
3595 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3596{
3597 vat_main_t *vam = &vat_main;
3598 u32 i, n;
3599 int retval = clib_net_to_host_u32 (mp->retval);
3600
3601 if (retval)
3602 goto end;
3603
3604 n = clib_net_to_host_u32 (mp->count);
3605
3606 for (i = 0; i < n; i++)
3607 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i]));
3608
3609end:
3610 vam->retval = retval;
3611 vam->result_ready = 1;
3612}
3613
3614static void
3615 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler_json
3616 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3617{
3618 vat_main_t *vam = &vat_main;
3619 vat_json_node_t root;
3620 u32 i, n;
3621 int retval = clib_net_to_host_u32 (mp->retval);
3622
3623 if (retval)
3624 goto end;
3625
3626 n = clib_net_to_host_u32 (mp->count);
3627 vat_json_init_array (&root);
3628
3629 for (i = 0; i < n; i++)
3630 vat_json_array_add_uint (&root, clib_net_to_host_u32 (mp->vnis[i]));
3631
3632 vat_json_print (vam->ofp, &root);
3633 vat_json_free (&root);
3634
3635end:
3636 vam->retval = retval;
3637 vam->result_ready = 1;
3638}
3639
3640static void
Filip Tehlar05879992017-09-05 15:46:09 +02003641 vl_api_one_ndp_entries_get_reply_t_handler
3642 (vl_api_one_ndp_entries_get_reply_t * mp)
3643{
3644 vat_main_t *vam = &vat_main;
3645 u32 i, n;
3646 int retval = clib_net_to_host_u32 (mp->retval);
3647
3648 if (retval)
3649 goto end;
3650
3651 n = clib_net_to_host_u32 (mp->count);
3652
3653 for (i = 0; i < n; i++)
3654 print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
3655 format_ethernet_address, mp->entries[i].mac);
3656
3657end:
3658 vam->retval = retval;
3659 vam->result_ready = 1;
3660}
3661
3662static void
3663 vl_api_one_ndp_entries_get_reply_t_handler_json
3664 (vl_api_one_ndp_entries_get_reply_t * mp)
3665{
3666 u8 *s = 0;
3667 vat_main_t *vam = &vat_main;
3668 vat_json_node_t *e = 0, root;
3669 u32 i, n;
3670 int retval = clib_net_to_host_u32 (mp->retval);
3671 vl_api_one_ndp_entry_t *arp_entry;
3672
3673 if (retval)
3674 goto end;
3675
3676 n = clib_net_to_host_u32 (mp->count);
3677 vat_json_init_array (&root);
3678
3679 for (i = 0; i < n; i++)
3680 {
3681 e = vat_json_array_add (&root);
3682 arp_entry = &mp->entries[i];
3683
3684 vat_json_init_object (e);
3685 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3686 vec_add1 (s, 0);
3687
3688 vat_json_object_add_string_copy (e, "mac", s);
3689 vec_free (s);
3690
3691 s = format (0, "%U", format_ip6_address, &arp_entry->ip6);
3692 vec_add1 (s, 0);
3693 vat_json_object_add_string_copy (e, "ip6", s);
3694 vec_free (s);
3695 }
3696
3697 vat_json_print (vam->ofp, &root);
3698 vat_json_free (&root);
3699
3700end:
3701 vam->retval = retval;
3702 vam->result_ready = 1;
3703}
3704
3705static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003706 vl_api_one_l2_arp_entries_get_reply_t_handler
3707 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3708{
3709 vat_main_t *vam = &vat_main;
3710 u32 i, n;
3711 int retval = clib_net_to_host_u32 (mp->retval);
3712
3713 if (retval)
3714 goto end;
3715
3716 n = clib_net_to_host_u32 (mp->count);
3717
3718 for (i = 0; i < n; i++)
3719 print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
3720 format_ethernet_address, mp->entries[i].mac);
3721
3722end:
3723 vam->retval = retval;
3724 vam->result_ready = 1;
3725}
3726
3727static void
3728 vl_api_one_l2_arp_entries_get_reply_t_handler_json
3729 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3730{
3731 u8 *s = 0;
3732 vat_main_t *vam = &vat_main;
3733 vat_json_node_t *e = 0, root;
3734 u32 i, n;
3735 int retval = clib_net_to_host_u32 (mp->retval);
3736 vl_api_one_l2_arp_entry_t *arp_entry;
3737
3738 if (retval)
3739 goto end;
3740
3741 n = clib_net_to_host_u32 (mp->count);
3742 vat_json_init_array (&root);
3743
3744 for (i = 0; i < n; i++)
3745 {
3746 e = vat_json_array_add (&root);
3747 arp_entry = &mp->entries[i];
3748
3749 vat_json_init_object (e);
3750 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3751 vec_add1 (s, 0);
3752
3753 vat_json_object_add_string_copy (e, "mac", s);
3754 vec_free (s);
3755
3756 s = format (0, "%U", format_ip4_address, &arp_entry->ip4);
3757 vec_add1 (s, 0);
3758 vat_json_object_add_string_copy (e, "ip4", s);
3759 vec_free (s);
3760 }
3761
3762 vat_json_print (vam->ofp, &root);
3763 vat_json_free (&root);
3764
3765end:
3766 vam->retval = retval;
3767 vam->result_ready = 1;
3768}
3769
3770static void
Filip Tehlar05879992017-09-05 15:46:09 +02003771vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
3772{
3773 vat_main_t *vam = &vat_main;
3774 u32 i, n;
3775 int retval = clib_net_to_host_u32 (mp->retval);
3776
3777 if (retval)
3778 goto end;
3779
3780 n = clib_net_to_host_u32 (mp->count);
3781
3782 for (i = 0; i < n; i++)
3783 {
3784 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3785 }
3786
3787end:
3788 vam->retval = retval;
3789 vam->result_ready = 1;
3790}
3791
3792static void
3793 vl_api_one_ndp_bd_get_reply_t_handler_json
3794 (vl_api_one_ndp_bd_get_reply_t * mp)
3795{
3796 vat_main_t *vam = &vat_main;
3797 vat_json_node_t root;
3798 u32 i, n;
3799 int retval = clib_net_to_host_u32 (mp->retval);
3800
3801 if (retval)
3802 goto end;
3803
3804 n = clib_net_to_host_u32 (mp->count);
3805 vat_json_init_array (&root);
3806
3807 for (i = 0; i < n; i++)
3808 {
3809 vat_json_array_add_uint (&root,
3810 clib_net_to_host_u32 (mp->bridge_domains[i]));
3811 }
3812
3813 vat_json_print (vam->ofp, &root);
3814 vat_json_free (&root);
3815
3816end:
3817 vam->retval = retval;
3818 vam->result_ready = 1;
3819}
3820
3821static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003822 vl_api_one_l2_arp_bd_get_reply_t_handler
3823 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3824{
3825 vat_main_t *vam = &vat_main;
3826 u32 i, n;
3827 int retval = clib_net_to_host_u32 (mp->retval);
3828
3829 if (retval)
3830 goto end;
3831
3832 n = clib_net_to_host_u32 (mp->count);
3833
3834 for (i = 0; i < n; i++)
3835 {
3836 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3837 }
3838
3839end:
3840 vam->retval = retval;
3841 vam->result_ready = 1;
3842}
3843
3844static void
3845 vl_api_one_l2_arp_bd_get_reply_t_handler_json
3846 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3847{
3848 vat_main_t *vam = &vat_main;
3849 vat_json_node_t root;
3850 u32 i, n;
3851 int retval = clib_net_to_host_u32 (mp->retval);
3852
3853 if (retval)
3854 goto end;
3855
3856 n = clib_net_to_host_u32 (mp->count);
3857 vat_json_init_array (&root);
3858
3859 for (i = 0; i < n; i++)
3860 {
3861 vat_json_array_add_uint (&root,
3862 clib_net_to_host_u32 (mp->bridge_domains[i]));
3863 }
3864
3865 vat_json_print (vam->ofp, &root);
3866 vat_json_free (&root);
3867
3868end:
3869 vam->retval = retval;
3870 vam->result_ready = 1;
3871}
3872
3873static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003874 vl_api_one_adjacencies_get_reply_t_handler
3875 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003876{
3877 vat_main_t *vam = &vat_main;
3878 u32 i, n;
3879 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003880 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003881
3882 if (retval)
3883 goto end;
3884
3885 n = clib_net_to_host_u32 (mp->count);
3886
3887 for (i = 0; i < n; i++)
3888 {
3889 a = &mp->adjacencies[i];
3890 print (vam->ofp, "%U %40U",
3891 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
3892 format_lisp_flat_eid, a->eid_type, a->reid, a->reid_prefix_len);
3893 }
3894
3895end:
3896 vam->retval = retval;
3897 vam->result_ready = 1;
3898}
3899
3900static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003901 vl_api_one_adjacencies_get_reply_t_handler_json
3902 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003903{
3904 u8 *s = 0;
3905 vat_main_t *vam = &vat_main;
3906 vat_json_node_t *e = 0, root;
3907 u32 i, n;
3908 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003909 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003910
3911 if (retval)
3912 goto end;
3913
3914 n = clib_net_to_host_u32 (mp->count);
3915 vat_json_init_array (&root);
3916
3917 for (i = 0; i < n; i++)
3918 {
3919 e = vat_json_array_add (&root);
3920 a = &mp->adjacencies[i];
3921
3922 vat_json_init_object (e);
3923 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
3924 a->leid_prefix_len);
3925 vec_add1 (s, 0);
3926 vat_json_object_add_string_copy (e, "leid", s);
3927 vec_free (s);
3928
3929 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
3930 a->reid_prefix_len);
3931 vec_add1 (s, 0);
3932 vat_json_object_add_string_copy (e, "reid", s);
3933 vec_free (s);
3934 }
3935
3936 vat_json_print (vam->ofp, &root);
3937 vat_json_free (&root);
3938
3939end:
3940 vam->retval = retval;
3941 vam->result_ready = 1;
3942}
3943
3944static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003945vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003946{
3947 vat_main_t *vam = &vat_main;
3948
3949 print (vam->ofp, "%=20U",
3950 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
3951 mp->ip_address);
3952}
3953
3954static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003955 vl_api_one_map_server_details_t_handler_json
3956 (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003957{
3958 vat_main_t *vam = &vat_main;
3959 vat_json_node_t *node = NULL;
3960 struct in6_addr ip6;
3961 struct in_addr ip4;
3962
3963 if (VAT_JSON_ARRAY != vam->json_tree.type)
3964 {
3965 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3966 vat_json_init_array (&vam->json_tree);
3967 }
3968 node = vat_json_array_add (&vam->json_tree);
3969
3970 vat_json_init_object (node);
3971 if (mp->is_ipv6)
3972 {
3973 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
3974 vat_json_object_add_ip6 (node, "map-server", ip6);
3975 }
3976 else
3977 {
3978 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
3979 vat_json_object_add_ip4 (node, "map-server", ip4);
3980 }
3981}
3982
3983static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003984vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
3985 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003986{
3987 vat_main_t *vam = &vat_main;
3988
3989 print (vam->ofp, "%=20U",
3990 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
3991 mp->ip_address);
3992}
3993
3994static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003995 vl_api_one_map_resolver_details_t_handler_json
3996 (vl_api_one_map_resolver_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003997{
3998 vat_main_t *vam = &vat_main;
3999 vat_json_node_t *node = NULL;
4000 struct in6_addr ip6;
4001 struct in_addr ip4;
4002
4003 if (VAT_JSON_ARRAY != vam->json_tree.type)
4004 {
4005 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4006 vat_json_init_array (&vam->json_tree);
4007 }
4008 node = vat_json_array_add (&vam->json_tree);
4009
4010 vat_json_init_object (node);
4011 if (mp->is_ipv6)
4012 {
4013 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
4014 vat_json_object_add_ip6 (node, "map resolver", ip6);
4015 }
4016 else
4017 {
4018 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
4019 vat_json_object_add_ip4 (node, "map resolver", ip4);
4020 }
4021}
4022
4023static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004024vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004025{
4026 vat_main_t *vam = &vat_main;
4027 i32 retval = ntohl (mp->retval);
4028
4029 if (0 <= retval)
4030 {
4031 print (vam->ofp, "feature: %s\ngpe: %s",
4032 mp->feature_status ? "enabled" : "disabled",
4033 mp->gpe_status ? "enabled" : "disabled");
4034 }
4035
4036 vam->retval = retval;
4037 vam->result_ready = 1;
4038}
4039
4040static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004041 vl_api_show_one_status_reply_t_handler_json
4042 (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004043{
4044 vat_main_t *vam = &vat_main;
4045 vat_json_node_t node;
4046 u8 *gpe_status = NULL;
4047 u8 *feature_status = NULL;
4048
4049 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
4050 feature_status = format (0, "%s",
4051 mp->feature_status ? "enabled" : "disabled");
4052 vec_add1 (gpe_status, 0);
4053 vec_add1 (feature_status, 0);
4054
4055 vat_json_init_object (&node);
4056 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
4057 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
4058
4059 vec_free (gpe_status);
4060 vec_free (feature_status);
4061
4062 vat_json_print (vam->ofp, &node);
4063 vat_json_free (&node);
4064
4065 vam->retval = ntohl (mp->retval);
4066 vam->result_ready = 1;
4067}
4068
4069static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004070 vl_api_one_get_map_request_itr_rlocs_reply_t_handler
4071 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004072{
4073 vat_main_t *vam = &vat_main;
4074 i32 retval = ntohl (mp->retval);
4075
4076 if (retval >= 0)
4077 {
4078 print (vam->ofp, "%=20s", mp->locator_set_name);
4079 }
4080
4081 vam->retval = retval;
4082 vam->result_ready = 1;
4083}
4084
4085static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004086 vl_api_one_get_map_request_itr_rlocs_reply_t_handler_json
4087 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004088{
4089 vat_main_t *vam = &vat_main;
4090 vat_json_node_t *node = NULL;
4091
4092 if (VAT_JSON_ARRAY != vam->json_tree.type)
4093 {
4094 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4095 vat_json_init_array (&vam->json_tree);
4096 }
4097 node = vat_json_array_add (&vam->json_tree);
4098
4099 vat_json_init_object (node);
4100 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
4101
4102 vat_json_print (vam->ofp, node);
4103 vat_json_free (node);
4104
4105 vam->retval = ntohl (mp->retval);
4106 vam->result_ready = 1;
4107}
4108
4109static u8 *
4110format_lisp_map_request_mode (u8 * s, va_list * args)
4111{
4112 u32 mode = va_arg (*args, u32);
4113
4114 switch (mode)
4115 {
4116 case 0:
4117 return format (0, "dst-only");
4118 case 1:
4119 return format (0, "src-dst");
4120 }
4121 return 0;
4122}
4123
4124static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004125 vl_api_show_one_map_request_mode_reply_t_handler
4126 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004127{
4128 vat_main_t *vam = &vat_main;
4129 i32 retval = ntohl (mp->retval);
4130
4131 if (0 <= retval)
4132 {
4133 u32 mode = mp->mode;
4134 print (vam->ofp, "map_request_mode: %U",
4135 format_lisp_map_request_mode, mode);
4136 }
4137
4138 vam->retval = retval;
4139 vam->result_ready = 1;
4140}
4141
4142static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004143 vl_api_show_one_map_request_mode_reply_t_handler_json
4144 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004145{
4146 vat_main_t *vam = &vat_main;
4147 vat_json_node_t node;
4148 u8 *s = 0;
4149 u32 mode;
4150
4151 mode = mp->mode;
4152 s = format (0, "%U", format_lisp_map_request_mode, mode);
4153 vec_add1 (s, 0);
4154
4155 vat_json_init_object (&node);
4156 vat_json_object_add_string_copy (&node, "map_request_mode", s);
4157 vat_json_print (vam->ofp, &node);
4158 vat_json_free (&node);
4159
4160 vec_free (s);
4161 vam->retval = ntohl (mp->retval);
4162 vam->result_ready = 1;
4163}
4164
4165static void
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004166 vl_api_one_show_xtr_mode_reply_t_handler
4167 (vl_api_one_show_xtr_mode_reply_t * mp)
4168{
4169 vat_main_t *vam = &vat_main;
4170 i32 retval = ntohl (mp->retval);
4171
4172 if (0 <= retval)
4173 {
4174 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4175 }
4176
4177 vam->retval = retval;
4178 vam->result_ready = 1;
4179}
4180
4181static void
4182 vl_api_one_show_xtr_mode_reply_t_handler_json
4183 (vl_api_one_show_xtr_mode_reply_t * mp)
4184{
4185 vat_main_t *vam = &vat_main;
4186 vat_json_node_t node;
4187 u8 *status = 0;
4188
4189 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4190 vec_add1 (status, 0);
4191
4192 vat_json_init_object (&node);
4193 vat_json_object_add_string_copy (&node, "status", status);
4194
4195 vec_free (status);
4196
4197 vat_json_print (vam->ofp, &node);
4198 vat_json_free (&node);
4199
4200 vam->retval = ntohl (mp->retval);
4201 vam->result_ready = 1;
4202}
4203
4204static void
4205 vl_api_one_show_pitr_mode_reply_t_handler
4206 (vl_api_one_show_pitr_mode_reply_t * mp)
4207{
4208 vat_main_t *vam = &vat_main;
4209 i32 retval = ntohl (mp->retval);
4210
4211 if (0 <= retval)
4212 {
4213 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4214 }
4215
4216 vam->retval = retval;
4217 vam->result_ready = 1;
4218}
4219
4220static void
4221 vl_api_one_show_pitr_mode_reply_t_handler_json
4222 (vl_api_one_show_pitr_mode_reply_t * mp)
4223{
4224 vat_main_t *vam = &vat_main;
4225 vat_json_node_t node;
4226 u8 *status = 0;
4227
4228 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4229 vec_add1 (status, 0);
4230
4231 vat_json_init_object (&node);
4232 vat_json_object_add_string_copy (&node, "status", status);
4233
4234 vec_free (status);
4235
4236 vat_json_print (vam->ofp, &node);
4237 vat_json_free (&node);
4238
4239 vam->retval = ntohl (mp->retval);
4240 vam->result_ready = 1;
4241}
4242
4243static void
4244 vl_api_one_show_petr_mode_reply_t_handler
4245 (vl_api_one_show_petr_mode_reply_t * mp)
4246{
4247 vat_main_t *vam = &vat_main;
4248 i32 retval = ntohl (mp->retval);
4249
4250 if (0 <= retval)
4251 {
4252 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4253 }
4254
4255 vam->retval = retval;
4256 vam->result_ready = 1;
4257}
4258
4259static void
4260 vl_api_one_show_petr_mode_reply_t_handler_json
4261 (vl_api_one_show_petr_mode_reply_t * mp)
4262{
4263 vat_main_t *vam = &vat_main;
4264 vat_json_node_t node;
4265 u8 *status = 0;
4266
4267 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4268 vec_add1 (status, 0);
4269
4270 vat_json_init_object (&node);
4271 vat_json_object_add_string_copy (&node, "status", status);
4272
4273 vec_free (status);
4274
4275 vat_json_print (vam->ofp, &node);
4276 vat_json_free (&node);
4277
4278 vam->retval = ntohl (mp->retval);
4279 vam->result_ready = 1;
4280}
4281
4282static void
Filip Tehlar67a99f82017-03-10 13:18:02 +01004283 vl_api_show_one_use_petr_reply_t_handler
4284 (vl_api_show_one_use_petr_reply_t * mp)
4285{
4286 vat_main_t *vam = &vat_main;
4287 i32 retval = ntohl (mp->retval);
4288
4289 if (0 <= retval)
4290 {
4291 print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
4292 if (mp->status)
4293 {
4294 print (vam->ofp, "Proxy-ETR address; %U",
4295 mp->is_ip4 ? format_ip4_address : format_ip6_address,
4296 mp->address);
4297 }
4298 }
4299
4300 vam->retval = retval;
4301 vam->result_ready = 1;
4302}
4303
4304static void
4305 vl_api_show_one_use_petr_reply_t_handler_json
4306 (vl_api_show_one_use_petr_reply_t * mp)
4307{
4308 vat_main_t *vam = &vat_main;
4309 vat_json_node_t node;
4310 u8 *status = 0;
4311 struct in_addr ip4;
4312 struct in6_addr ip6;
4313
4314 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4315 vec_add1 (status, 0);
4316
4317 vat_json_init_object (&node);
4318 vat_json_object_add_string_copy (&node, "status", status);
4319 if (mp->status)
4320 {
4321 if (mp->is_ip4)
4322 {
4323 clib_memcpy (&ip6, mp->address, sizeof (ip6));
4324 vat_json_object_add_ip6 (&node, "address", ip6);
4325 }
4326 else
4327 {
4328 clib_memcpy (&ip4, mp->address, sizeof (ip4));
4329 vat_json_object_add_ip4 (&node, "address", ip4);
4330 }
4331 }
4332
4333 vec_free (status);
4334
4335 vat_json_print (vam->ofp, &node);
4336 vat_json_free (&node);
4337
4338 vam->retval = ntohl (mp->retval);
4339 vam->result_ready = 1;
4340}
4341
4342static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02004343 vl_api_show_one_nsh_mapping_reply_t_handler
4344 (vl_api_show_one_nsh_mapping_reply_t * mp)
4345{
4346 vat_main_t *vam = &vat_main;
4347 i32 retval = ntohl (mp->retval);
4348
4349 if (0 <= retval)
4350 {
4351 print (vam->ofp, "%-20s%-16s",
4352 mp->is_set ? "set" : "not-set",
4353 mp->is_set ? (char *) mp->locator_set_name : "");
4354 }
4355
4356 vam->retval = retval;
4357 vam->result_ready = 1;
4358}
4359
4360static void
4361 vl_api_show_one_nsh_mapping_reply_t_handler_json
4362 (vl_api_show_one_nsh_mapping_reply_t * mp)
4363{
4364 vat_main_t *vam = &vat_main;
4365 vat_json_node_t node;
4366 u8 *status = 0;
4367
4368 status = format (0, "%s", mp->is_set ? "yes" : "no");
4369 vec_add1 (status, 0);
4370
4371 vat_json_init_object (&node);
4372 vat_json_object_add_string_copy (&node, "is_set", status);
4373 if (mp->is_set)
4374 {
4375 vat_json_object_add_string_copy (&node, "locator_set",
4376 mp->locator_set_name);
4377 }
4378
4379 vec_free (status);
4380
4381 vat_json_print (vam->ofp, &node);
4382 vat_json_free (&node);
4383
4384 vam->retval = ntohl (mp->retval);
4385 vam->result_ready = 1;
4386}
4387
4388static void
Filip Tehlar1e553a02017-08-02 12:45:07 +02004389 vl_api_show_one_map_register_ttl_reply_t_handler
4390 (vl_api_show_one_map_register_ttl_reply_t * mp)
4391{
4392 vat_main_t *vam = &vat_main;
4393 i32 retval = ntohl (mp->retval);
4394
4395 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4396
4397 if (0 <= retval)
4398 {
4399 print (vam->ofp, "ttl: %u", mp->ttl);
4400 }
4401
4402 vam->retval = retval;
4403 vam->result_ready = 1;
4404}
4405
4406static void
4407 vl_api_show_one_map_register_ttl_reply_t_handler_json
4408 (vl_api_show_one_map_register_ttl_reply_t * mp)
4409{
4410 vat_main_t *vam = &vat_main;
4411 vat_json_node_t node;
4412
4413 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4414 vat_json_init_object (&node);
4415 vat_json_object_add_uint (&node, "ttl", mp->ttl);
4416
4417 vat_json_print (vam->ofp, &node);
4418 vat_json_free (&node);
4419
4420 vam->retval = ntohl (mp->retval);
4421 vam->result_ready = 1;
4422}
4423
4424static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004425vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004426{
4427 vat_main_t *vam = &vat_main;
4428 i32 retval = ntohl (mp->retval);
4429
4430 if (0 <= retval)
4431 {
4432 print (vam->ofp, "%-20s%-16s",
4433 mp->status ? "enabled" : "disabled",
4434 mp->status ? (char *) mp->locator_set_name : "");
4435 }
4436
4437 vam->retval = retval;
4438 vam->result_ready = 1;
4439}
4440
4441static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004442vl_api_show_one_pitr_reply_t_handler_json (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004443{
4444 vat_main_t *vam = &vat_main;
4445 vat_json_node_t node;
4446 u8 *status = 0;
4447
4448 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4449 vec_add1 (status, 0);
4450
4451 vat_json_init_object (&node);
4452 vat_json_object_add_string_copy (&node, "status", status);
4453 if (mp->status)
4454 {
4455 vat_json_object_add_string_copy (&node, "locator_set",
4456 mp->locator_set_name);
4457 }
4458
4459 vec_free (status);
4460
4461 vat_json_print (vam->ofp, &node);
4462 vat_json_free (&node);
4463
4464 vam->retval = ntohl (mp->retval);
4465 vam->result_ready = 1;
4466}
4467
4468static u8 *
4469format_policer_type (u8 * s, va_list * va)
4470{
4471 u32 i = va_arg (*va, u32);
4472
4473 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
4474 s = format (s, "1r2c");
4475 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
4476 s = format (s, "1r3c");
4477 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
4478 s = format (s, "2r3c-2698");
4479 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
4480 s = format (s, "2r3c-4115");
4481 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
4482 s = format (s, "2r3c-mef5cf1");
4483 else
4484 s = format (s, "ILLEGAL");
4485 return s;
4486}
4487
4488static u8 *
4489format_policer_rate_type (u8 * s, va_list * va)
4490{
4491 u32 i = va_arg (*va, u32);
4492
4493 if (i == SSE2_QOS_RATE_KBPS)
4494 s = format (s, "kbps");
4495 else if (i == SSE2_QOS_RATE_PPS)
4496 s = format (s, "pps");
4497 else
4498 s = format (s, "ILLEGAL");
4499 return s;
4500}
4501
4502static u8 *
4503format_policer_round_type (u8 * s, va_list * va)
4504{
4505 u32 i = va_arg (*va, u32);
4506
4507 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
4508 s = format (s, "closest");
4509 else if (i == SSE2_QOS_ROUND_TO_UP)
4510 s = format (s, "up");
4511 else if (i == SSE2_QOS_ROUND_TO_DOWN)
4512 s = format (s, "down");
4513 else
4514 s = format (s, "ILLEGAL");
4515 return s;
4516}
4517
4518static u8 *
4519format_policer_action_type (u8 * s, va_list * va)
4520{
4521 u32 i = va_arg (*va, u32);
4522
4523 if (i == SSE2_QOS_ACTION_DROP)
4524 s = format (s, "drop");
4525 else if (i == SSE2_QOS_ACTION_TRANSMIT)
4526 s = format (s, "transmit");
4527 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4528 s = format (s, "mark-and-transmit");
4529 else
4530 s = format (s, "ILLEGAL");
4531 return s;
4532}
4533
4534static u8 *
4535format_dscp (u8 * s, va_list * va)
4536{
4537 u32 i = va_arg (*va, u32);
4538 char *t = 0;
4539
4540 switch (i)
4541 {
4542#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
4543 foreach_vnet_dscp
4544#undef _
4545 default:
4546 return format (s, "ILLEGAL");
4547 }
4548 s = format (s, "%s", t);
4549 return s;
4550}
4551
4552static void
4553vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
4554{
4555 vat_main_t *vam = &vat_main;
4556 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
4557
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004558 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
4559 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004560 else
4561 conform_dscp_str = format (0, "");
4562
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004563 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
4564 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004565 else
4566 exceed_dscp_str = format (0, "");
4567
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004568 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
4569 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004570 else
4571 violate_dscp_str = format (0, "");
4572
4573 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
4574 "rate type %U, round type %U, %s rate, %s color-aware, "
4575 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
4576 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
4577 "conform action %U%s, exceed action %U%s, violate action %U%s",
4578 mp->name,
4579 format_policer_type, mp->type,
4580 ntohl (mp->cir),
4581 ntohl (mp->eir),
4582 clib_net_to_host_u64 (mp->cb),
4583 clib_net_to_host_u64 (mp->eb),
4584 format_policer_rate_type, mp->rate_type,
4585 format_policer_round_type, mp->round_type,
4586 mp->single_rate ? "single" : "dual",
4587 mp->color_aware ? "is" : "not",
4588 ntohl (mp->cir_tokens_per_period),
4589 ntohl (mp->pir_tokens_per_period),
4590 ntohl (mp->scale),
4591 ntohl (mp->current_limit),
4592 ntohl (mp->current_bucket),
4593 ntohl (mp->extended_limit),
4594 ntohl (mp->extended_bucket),
4595 clib_net_to_host_u64 (mp->last_update_time),
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004596 format_policer_action_type, mp->conform_action.type,
Damjan Marion7cd468a2016-12-19 23:05:39 +01004597 conform_dscp_str,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004598 format_policer_action_type, mp->exceed_action.type,
Damjan Marion7cd468a2016-12-19 23:05:39 +01004599 exceed_dscp_str,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004600 format_policer_action_type, mp->violate_action.type,
Damjan Marion7cd468a2016-12-19 23:05:39 +01004601 violate_dscp_str);
4602
4603 vec_free (conform_dscp_str);
4604 vec_free (exceed_dscp_str);
4605 vec_free (violate_dscp_str);
4606}
4607
4608static void vl_api_policer_details_t_handler_json
4609 (vl_api_policer_details_t * mp)
4610{
4611 vat_main_t *vam = &vat_main;
4612 vat_json_node_t *node;
4613 u8 *rate_type_str, *round_type_str, *type_str;
4614 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
4615
4616 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
4617 round_type_str =
4618 format (0, "%U", format_policer_round_type, mp->round_type);
4619 type_str = format (0, "%U", format_policer_type, mp->type);
4620 conform_action_str = format (0, "%U", format_policer_action_type,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004621 mp->conform_action.type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004622 exceed_action_str = format (0, "%U", format_policer_action_type,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004623 mp->exceed_action.type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004624 violate_action_str = format (0, "%U", format_policer_action_type,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004625 mp->violate_action.type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004626
4627 if (VAT_JSON_ARRAY != vam->json_tree.type)
4628 {
4629 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4630 vat_json_init_array (&vam->json_tree);
4631 }
4632 node = vat_json_array_add (&vam->json_tree);
4633
4634 vat_json_init_object (node);
4635 vat_json_object_add_string_copy (node, "name", mp->name);
4636 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
4637 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
Marek Gradzki59ed4902017-03-21 11:51:54 +01004638 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
4639 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
Damjan Marion7cd468a2016-12-19 23:05:39 +01004640 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
4641 vat_json_object_add_string_copy (node, "round_type", round_type_str);
4642 vat_json_object_add_string_copy (node, "type", type_str);
4643 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
4644 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
4645 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
4646 vat_json_object_add_uint (node, "cir_tokens_per_period",
4647 ntohl (mp->cir_tokens_per_period));
4648 vat_json_object_add_uint (node, "eir_tokens_per_period",
4649 ntohl (mp->pir_tokens_per_period));
4650 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
4651 vat_json_object_add_uint (node, "current_bucket",
4652 ntohl (mp->current_bucket));
4653 vat_json_object_add_uint (node, "extended_limit",
4654 ntohl (mp->extended_limit));
4655 vat_json_object_add_uint (node, "extended_bucket",
4656 ntohl (mp->extended_bucket));
4657 vat_json_object_add_uint (node, "last_update_time",
4658 ntohl (mp->last_update_time));
4659 vat_json_object_add_string_copy (node, "conform_action",
4660 conform_action_str);
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004661 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004662 {
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004663 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004664 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
4665 vec_free (dscp_str);
4666 }
4667 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004668 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004669 {
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004670 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004671 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
4672 vec_free (dscp_str);
4673 }
4674 vat_json_object_add_string_copy (node, "violate_action",
4675 violate_action_str);
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004676 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004677 {
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004678 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004679 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
4680 vec_free (dscp_str);
4681 }
4682
4683 vec_free (rate_type_str);
4684 vec_free (round_type_str);
4685 vec_free (type_str);
4686 vec_free (conform_action_str);
4687 vec_free (exceed_action_str);
4688 vec_free (violate_action_str);
4689}
4690
4691static void
4692vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
4693 mp)
4694{
4695 vat_main_t *vam = &vat_main;
4696 int i, count = ntohl (mp->count);
4697
4698 if (count > 0)
4699 print (vam->ofp, "classify table ids (%d) : ", count);
4700 for (i = 0; i < count; i++)
4701 {
4702 print (vam->ofp, "%d", ntohl (mp->ids[i]));
4703 print (vam->ofp, (i < count - 1) ? "," : "");
4704 }
4705 vam->retval = ntohl (mp->retval);
4706 vam->result_ready = 1;
4707}
4708
4709static void
4710 vl_api_classify_table_ids_reply_t_handler_json
4711 (vl_api_classify_table_ids_reply_t * mp)
4712{
4713 vat_main_t *vam = &vat_main;
4714 int i, count = ntohl (mp->count);
4715
4716 if (count > 0)
4717 {
4718 vat_json_node_t node;
4719
4720 vat_json_init_object (&node);
4721 for (i = 0; i < count; i++)
4722 {
4723 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
4724 }
4725 vat_json_print (vam->ofp, &node);
4726 vat_json_free (&node);
4727 }
4728 vam->retval = ntohl (mp->retval);
4729 vam->result_ready = 1;
4730}
4731
4732static void
4733 vl_api_classify_table_by_interface_reply_t_handler
4734 (vl_api_classify_table_by_interface_reply_t * mp)
4735{
4736 vat_main_t *vam = &vat_main;
4737 u32 table_id;
4738
4739 table_id = ntohl (mp->l2_table_id);
4740 if (table_id != ~0)
4741 print (vam->ofp, "l2 table id : %d", table_id);
4742 else
4743 print (vam->ofp, "l2 table id : No input ACL tables configured");
4744 table_id = ntohl (mp->ip4_table_id);
4745 if (table_id != ~0)
4746 print (vam->ofp, "ip4 table id : %d", table_id);
4747 else
4748 print (vam->ofp, "ip4 table id : No input ACL tables configured");
4749 table_id = ntohl (mp->ip6_table_id);
4750 if (table_id != ~0)
4751 print (vam->ofp, "ip6 table id : %d", table_id);
4752 else
4753 print (vam->ofp, "ip6 table id : No input ACL tables configured");
4754 vam->retval = ntohl (mp->retval);
4755 vam->result_ready = 1;
4756}
4757
4758static void
4759 vl_api_classify_table_by_interface_reply_t_handler_json
4760 (vl_api_classify_table_by_interface_reply_t * mp)
4761{
4762 vat_main_t *vam = &vat_main;
4763 vat_json_node_t node;
4764
4765 vat_json_init_object (&node);
4766
4767 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
4768 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
4769 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
4770
4771 vat_json_print (vam->ofp, &node);
4772 vat_json_free (&node);
4773
4774 vam->retval = ntohl (mp->retval);
4775 vam->result_ready = 1;
4776}
4777
4778static void vl_api_policer_add_del_reply_t_handler
4779 (vl_api_policer_add_del_reply_t * mp)
4780{
4781 vat_main_t *vam = &vat_main;
4782 i32 retval = ntohl (mp->retval);
4783 if (vam->async_mode)
4784 {
4785 vam->async_errors += (retval < 0);
4786 }
4787 else
4788 {
4789 vam->retval = retval;
4790 vam->result_ready = 1;
4791 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
4792 /*
4793 * Note: this is just barely thread-safe, depends on
4794 * the main thread spinning waiting for an answer...
4795 */
4796 errmsg ("policer index %d", ntohl (mp->policer_index));
4797 }
4798}
4799
4800static void vl_api_policer_add_del_reply_t_handler_json
4801 (vl_api_policer_add_del_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 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4808 vat_json_object_add_uint (&node, "policer_index",
4809 ntohl (mp->policer_index));
4810
4811 vat_json_print (vam->ofp, &node);
4812 vat_json_free (&node);
4813
4814 vam->retval = ntohl (mp->retval);
4815 vam->result_ready = 1;
4816}
4817
4818/* Format hex dump. */
4819u8 *
4820format_hex_bytes (u8 * s, va_list * va)
4821{
4822 u8 *bytes = va_arg (*va, u8 *);
4823 int n_bytes = va_arg (*va, int);
4824 uword i;
4825
4826 /* Print short or long form depending on byte count. */
4827 uword short_form = n_bytes <= 32;
Christophe Fontained3c008d2017-10-02 18:10:54 +02004828 u32 indent = format_get_indent (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004829
4830 if (n_bytes == 0)
4831 return s;
4832
4833 for (i = 0; i < n_bytes; i++)
4834 {
4835 if (!short_form && (i % 32) == 0)
4836 s = format (s, "%08x: ", i);
4837 s = format (s, "%02x", bytes[i]);
4838 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
4839 s = format (s, "\n%U", format_white_space, indent);
4840 }
4841
4842 return s;
4843}
4844
4845static void
4846vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
4847 * mp)
4848{
4849 vat_main_t *vam = &vat_main;
4850 i32 retval = ntohl (mp->retval);
4851 if (retval == 0)
4852 {
4853 print (vam->ofp, "classify table info :");
4854 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
4855 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
4856 ntohl (mp->miss_next_index));
4857 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
4858 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
4859 ntohl (mp->match_n_vectors));
4860 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
4861 ntohl (mp->mask_length));
4862 }
4863 vam->retval = retval;
4864 vam->result_ready = 1;
4865}
4866
4867static void
4868 vl_api_classify_table_info_reply_t_handler_json
4869 (vl_api_classify_table_info_reply_t * mp)
4870{
4871 vat_main_t *vam = &vat_main;
4872 vat_json_node_t node;
4873
4874 i32 retval = ntohl (mp->retval);
4875 if (retval == 0)
4876 {
4877 vat_json_init_object (&node);
4878
4879 vat_json_object_add_int (&node, "sessions",
4880 ntohl (mp->active_sessions));
4881 vat_json_object_add_int (&node, "nexttbl",
4882 ntohl (mp->next_table_index));
4883 vat_json_object_add_int (&node, "nextnode",
4884 ntohl (mp->miss_next_index));
4885 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
4886 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
4887 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
4888 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
4889 ntohl (mp->mask_length), 0);
4890 vat_json_object_add_string_copy (&node, "mask", s);
4891
4892 vat_json_print (vam->ofp, &node);
4893 vat_json_free (&node);
4894 }
4895 vam->retval = ntohl (mp->retval);
4896 vam->result_ready = 1;
4897}
4898
4899static void
4900vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
4901 mp)
4902{
4903 vat_main_t *vam = &vat_main;
4904
4905 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
4906 ntohl (mp->hit_next_index), ntohl (mp->advance),
4907 ntohl (mp->opaque_index));
4908 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
4909 ntohl (mp->match_length));
4910}
4911
4912static void
4913 vl_api_classify_session_details_t_handler_json
4914 (vl_api_classify_session_details_t * mp)
4915{
4916 vat_main_t *vam = &vat_main;
4917 vat_json_node_t *node = NULL;
4918
4919 if (VAT_JSON_ARRAY != vam->json_tree.type)
4920 {
4921 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4922 vat_json_init_array (&vam->json_tree);
4923 }
4924 node = vat_json_array_add (&vam->json_tree);
4925
4926 vat_json_init_object (node);
4927 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
4928 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
4929 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
4930 u8 *s =
4931 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
4932 0);
4933 vat_json_object_add_string_copy (node, "match", s);
4934}
4935
4936static void vl_api_pg_create_interface_reply_t_handler
4937 (vl_api_pg_create_interface_reply_t * mp)
4938{
4939 vat_main_t *vam = &vat_main;
4940
4941 vam->retval = ntohl (mp->retval);
4942 vam->result_ready = 1;
4943}
4944
4945static void vl_api_pg_create_interface_reply_t_handler_json
4946 (vl_api_pg_create_interface_reply_t * mp)
4947{
4948 vat_main_t *vam = &vat_main;
4949 vat_json_node_t node;
4950
4951 i32 retval = ntohl (mp->retval);
4952 if (retval == 0)
4953 {
4954 vat_json_init_object (&node);
4955
4956 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
4957
4958 vat_json_print (vam->ofp, &node);
4959 vat_json_free (&node);
4960 }
4961 vam->retval = ntohl (mp->retval);
4962 vam->result_ready = 1;
4963}
4964
4965static void vl_api_policer_classify_details_t_handler
4966 (vl_api_policer_classify_details_t * mp)
4967{
4968 vat_main_t *vam = &vat_main;
4969
4970 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
4971 ntohl (mp->table_index));
4972}
4973
4974static void vl_api_policer_classify_details_t_handler_json
4975 (vl_api_policer_classify_details_t * mp)
4976{
4977 vat_main_t *vam = &vat_main;
4978 vat_json_node_t *node;
4979
4980 if (VAT_JSON_ARRAY != vam->json_tree.type)
4981 {
4982 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4983 vat_json_init_array (&vam->json_tree);
4984 }
4985 node = vat_json_array_add (&vam->json_tree);
4986
4987 vat_json_init_object (node);
4988 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4989 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
4990}
4991
Damjan Marion7cd468a2016-12-19 23:05:39 +01004992static void vl_api_flow_classify_details_t_handler
4993 (vl_api_flow_classify_details_t * mp)
4994{
4995 vat_main_t *vam = &vat_main;
4996
4997 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
4998 ntohl (mp->table_index));
4999}
5000
5001static void vl_api_flow_classify_details_t_handler_json
5002 (vl_api_flow_classify_details_t * mp)
5003{
5004 vat_main_t *vam = &vat_main;
5005 vat_json_node_t *node;
5006
5007 if (VAT_JSON_ARRAY != vam->json_tree.type)
5008 {
5009 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5010 vat_json_init_array (&vam->json_tree);
5011 }
5012 node = vat_json_array_add (&vam->json_tree);
5013
5014 vat_json_init_object (node);
5015 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5016 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5017}
5018
Filip Tehlar694396d2017-02-17 14:29:11 +01005019#define vl_api_one_adjacencies_get_reply_t_endian vl_noop_handler
5020#define vl_api_one_adjacencies_get_reply_t_print vl_noop_handler
Filip Tehlard5a65db2017-05-17 17:21:10 +02005021#define vl_api_one_l2_arp_bd_get_reply_t_print vl_noop_handler
5022#define vl_api_one_l2_arp_entries_get_reply_t_endian vl_noop_handler
5023#define vl_api_one_l2_arp_entries_get_reply_t_print vl_noop_handler
5024#define vl_api_one_l2_arp_bd_get_reply_t_endian vl_noop_handler
Filip Tehlar05879992017-09-05 15:46:09 +02005025#define vl_api_one_ndp_bd_get_reply_t_endian vl_noop_handler
5026#define vl_api_one_ndp_bd_get_reply_t_print vl_noop_handler
5027#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
5028#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +01005029
5030/*
5031 * Generate boilerplate reply handlers, which
5032 * dig the return value out of the xxx_reply_t API message,
5033 * stick it into vam->retval, and set vam->result_ready
5034 *
5035 * Could also do this by pointing N message decode slots at
5036 * a single function, but that could break in subtle ways.
5037 */
5038
5039#define foreach_standard_reply_retval_handler \
5040_(sw_interface_set_flags_reply) \
5041_(sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005042_(sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005043_(sw_interface_set_rx_placement_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005044_(sw_interface_set_table_reply) \
5045_(sw_interface_set_mpls_enable_reply) \
5046_(sw_interface_set_vpath_reply) \
5047_(sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005048_(sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005049_(sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005050_(sw_interface_set_l2_bridge_reply) \
Steven Luonga1876b82019-08-20 16:58:00 -07005051_(sw_interface_set_bond_weight_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005052_(bridge_domain_add_del_reply) \
5053_(sw_interface_set_l2_xconnect_reply) \
5054_(l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005055_(l2fib_flush_int_reply) \
5056_(l2fib_flush_bd_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005057_(ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005058_(ip_table_add_del_reply) \
Neale Ranns9db6ada2019-11-08 12:42:31 +00005059_(ip_table_replace_begin_reply) \
5060_(ip_table_flush_reply) \
5061_(ip_table_replace_end_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005062_(ip_mroute_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005063_(mpls_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005064_(mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005065_(mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005066_(bier_route_add_del_reply) \
5067_(bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005068_(sw_interface_set_unnumbered_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005069_(set_ip_flow_hash_reply) \
5070_(sw_interface_ip6_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005071_(l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005072_(sr_mpls_policy_add_reply) \
5073_(sr_mpls_policy_mod_reply) \
5074_(sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005075_(sr_policy_add_reply) \
5076_(sr_policy_mod_reply) \
5077_(sr_policy_del_reply) \
5078_(sr_localsid_add_del_reply) \
5079_(sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005080_(classify_add_del_session_reply) \
5081_(classify_set_interface_ip_table_reply) \
5082_(classify_set_interface_l2_tables_reply) \
5083_(l2tpv3_set_tunnel_cookies_reply) \
5084_(l2tpv3_interface_enable_disable_reply) \
5085_(l2tpv3_set_lookup_key_reply) \
5086_(l2_fib_clear_table_reply) \
5087_(l2_interface_efp_filter_reply) \
5088_(l2_interface_vlan_tag_rewrite_reply) \
5089_(modify_vhost_user_if_reply) \
5090_(delete_vhost_user_if_reply) \
John Lo8d00fff2017-08-03 00:35:36 -04005091_(want_l2_macs_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005092_(input_acl_set_interface_reply) \
5093_(ipsec_spd_add_del_reply) \
5094_(ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005095_(ipsec_spd_entry_add_del_reply) \
5096_(ipsec_sad_entry_add_del_reply) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005097_(ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005098_(ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005099_(delete_loopback_reply) \
5100_(bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005101_(bd_ip_mac_flush_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005102_(want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005103_(cop_interface_enable_disable_reply) \
5104_(cop_whitelist_enable_disable_reply) \
5105_(sw_interface_clear_stats_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005106_(ioam_enable_reply) \
5107_(ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005108_(one_add_del_locator_reply) \
5109_(one_add_del_local_eid_reply) \
5110_(one_add_del_remote_mapping_reply) \
5111_(one_add_del_adjacency_reply) \
5112_(one_add_del_map_resolver_reply) \
5113_(one_add_del_map_server_reply) \
5114_(one_enable_disable_reply) \
5115_(one_rloc_probe_enable_disable_reply) \
5116_(one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005117_(one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005118_(one_set_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005119_(one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005120_(one_pitr_set_locator_set_reply) \
5121_(one_map_request_mode_reply) \
5122_(one_add_del_map_request_itr_rlocs_reply) \
5123_(one_eid_table_add_del_map_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005124_(one_use_petr_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005125_(one_stats_enable_disable_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005126_(one_add_del_l2_arp_entry_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005127_(one_add_del_ndp_entry_reply) \
Filip Tehlar21511912017-04-07 10:41:42 +02005128_(one_stats_flush_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005129_(one_enable_disable_xtr_mode_reply) \
5130_(one_enable_disable_pitr_mode_reply) \
5131_(one_enable_disable_petr_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005132_(gpe_enable_disable_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005133_(gpe_set_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005134_(gpe_add_del_iface_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005135_(gpe_add_del_native_fwd_rpath_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005136_(af_packet_delete_reply) \
5137_(policer_classify_set_interface_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005138_(set_ipfix_exporter_reply) \
5139_(set_ipfix_classify_stream_reply) \
5140_(ipfix_classify_table_add_del_reply) \
5141_(flow_classify_set_interface_reply) \
5142_(sw_interface_span_enable_disable_reply) \
5143_(pg_capture_reply) \
5144_(pg_enable_disable_reply) \
5145_(ip_source_and_port_range_check_add_del_reply) \
5146_(ip_source_and_port_range_check_interface_add_del_reply)\
5147_(delete_subif_reply) \
5148_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005149_(set_punt_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005150_(feature_enable_disable_reply) \
Mohsin Kazmi29467b52019-10-08 19:42:38 +02005151_(feature_gso_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005152_(sw_interface_tag_add_del_reply) \
Matthew Smithe0792fd2019-07-12 11:48:24 -05005153_(sw_interface_add_del_mac_address_reply) \
Ole Troand7231612018-06-07 10:17:57 +02005154_(hw_interface_set_mtu_reply) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005155_(p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005156_(p2p_ethernet_del_reply) \
5157_(lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005158_(sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005159_(tcp_configure_src_addresses_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005160_(session_rule_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005161_(ip_container_proxy_add_del_reply) \
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -07005162_(output_acl_set_interface_reply) \
5163_(qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005164
5165#define _(n) \
5166 static void vl_api_##n##_t_handler \
5167 (vl_api_##n##_t * mp) \
5168 { \
5169 vat_main_t * vam = &vat_main; \
5170 i32 retval = ntohl(mp->retval); \
5171 if (vam->async_mode) { \
5172 vam->async_errors += (retval < 0); \
5173 } else { \
5174 vam->retval = retval; \
5175 vam->result_ready = 1; \
5176 } \
5177 }
5178foreach_standard_reply_retval_handler;
5179#undef _
5180
5181#define _(n) \
5182 static void vl_api_##n##_t_handler_json \
5183 (vl_api_##n##_t * mp) \
5184 { \
5185 vat_main_t * vam = &vat_main; \
5186 vat_json_node_t node; \
5187 vat_json_init_object(&node); \
5188 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
5189 vat_json_print(vam->ofp, &node); \
5190 vam->retval = ntohl(mp->retval); \
5191 vam->result_ready = 1; \
5192 }
5193foreach_standard_reply_retval_handler;
5194#undef _
5195
5196/*
5197 * Table of message reply handlers, must include boilerplate handlers
5198 * we just generated
5199 */
5200
5201#define foreach_vpe_api_reply_msg \
5202_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005203_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005204_(SW_INTERFACE_DETAILS, sw_interface_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005205_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
5206_(CONTROL_PING_REPLY, control_ping_reply) \
5207_(CLI_REPLY, cli_reply) \
5208_(CLI_INBAND_REPLY, cli_inband_reply) \
5209_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
5210 sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005211_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005212_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02005213_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005214_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
5215_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
5216_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
5217_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005218_(SW_INTERFACE_SET_GENEVE_BYPASS_REPLY, sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005219_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005220_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
5221 sw_interface_set_l2_xconnect_reply) \
5222_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
5223 sw_interface_set_l2_bridge_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005224_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
5225_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
Eyal Barifead6702017-04-04 04:46:32 +03005226_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005227_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005228_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
5229_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005230_(L2_FLAGS_REPLY, l2_flags_reply) \
5231_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
Damjan Marion8389fb92017-10-13 18:29:53 +02005232_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
5233_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
5234_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01005235_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
5236_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
5237_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
Steven9cd2d7a2017-12-20 12:43:01 -08005238_(BOND_CREATE_REPLY, bond_create_reply) \
5239_(BOND_DELETE_REPLY, bond_delete_reply) \
5240_(BOND_ENSLAVE_REPLY, bond_enslave_reply) \
5241_(BOND_DETACH_SLAVE_REPLY, bond_detach_slave_reply) \
Steven Luonga1876b82019-08-20 16:58:00 -07005242_(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
Steven9cd2d7a2017-12-20 12:43:01 -08005243_(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details) \
5244_(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005245_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005246_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
Neale Ranns9db6ada2019-11-08 12:42:31 +00005247_(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
5248_(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
5249_(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005250_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005251_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005252_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
5253_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005254_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
5255_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005256_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
5257_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
5258 sw_interface_set_unnumbered_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005259_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
5260_(CREATE_SUBIF_REPLY, create_subif_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005261_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
5262_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
5263 sw_interface_ip6_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005264_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005265_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
5266_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
5267_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005268_(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
5269_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
5270_(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
5271_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
5272_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005273_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
5274_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
5275_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
5276classify_set_interface_ip_table_reply) \
5277_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
5278 classify_set_interface_l2_tables_reply) \
5279_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
5280_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
5281_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
5282_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
5283_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
5284 l2tpv3_interface_enable_disable_reply) \
5285_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
5286_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
5287_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
eyal bariaf86a482018-04-17 11:20:27 +03005288_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005289_(GENEVE_ADD_DEL_TUNNEL_REPLY, geneve_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005290_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005291_(GENEVE_TUNNEL_DETAILS, geneve_tunnel_details) \
Neale Ranns5a8844b2019-04-16 07:15:35 +00005292_(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005293_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
5294_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
5295_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
5296_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
5297_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
5298_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
5299_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
5300_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
5301_(SHOW_VERSION_REPLY, show_version_reply) \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02005302_(SHOW_THREADS_REPLY, show_threads_reply) \
Ole Troan01384fe2017-05-12 11:55:35 +02005303_(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
John Loc7b43042018-04-13 16:46:22 -04005304_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005305_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
5306_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
John Lo8d00fff2017-08-03 00:35:36 -04005307_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
5308_(L2_MACS_EVENT, l2_macs_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005309_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
5310_(IP_ADDRESS_DETAILS, ip_address_details) \
5311_(IP_DETAILS, ip_details) \
5312_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
5313_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005314_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
5315_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
Matthew Smith28029532017-09-26 13:33:44 -05005316_(IPSEC_SA_DETAILS, ipsec_sa_details) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005317_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005318_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005319_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
5320_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005321_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02005322_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005323_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005324_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
5325_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
5326_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
5327_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
5328_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
5329_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
5330_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005331_(ONE_ADD_DEL_LOCATOR_SET_REPLY, one_add_del_locator_set_reply) \
5332_(ONE_ADD_DEL_LOCATOR_REPLY, one_add_del_locator_reply) \
5333_(ONE_ADD_DEL_LOCAL_EID_REPLY, one_add_del_local_eid_reply) \
5334_(ONE_ADD_DEL_REMOTE_MAPPING_REPLY, one_add_del_remote_mapping_reply) \
5335_(ONE_ADD_DEL_ADJACENCY_REPLY, one_add_del_adjacency_reply) \
5336_(ONE_ADD_DEL_MAP_RESOLVER_REPLY, one_add_del_map_resolver_reply) \
5337_(ONE_ADD_DEL_MAP_SERVER_REPLY, one_add_del_map_server_reply) \
5338_(ONE_ENABLE_DISABLE_REPLY, one_enable_disable_reply) \
5339_(ONE_MAP_REGISTER_ENABLE_DISABLE_REPLY, \
5340 one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005341_(ONE_MAP_REGISTER_SET_TTL_REPLY, one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005342_(ONE_SET_TRANSPORT_PROTOCOL_REPLY, one_set_transport_protocol_reply) \
5343_(ONE_GET_TRANSPORT_PROTOCOL_REPLY, one_get_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005344_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5345 one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005346_(ONE_RLOC_PROBE_ENABLE_DISABLE_REPLY, \
5347 one_rloc_probe_enable_disable_reply) \
5348_(ONE_PITR_SET_LOCATOR_SET_REPLY, one_pitr_set_locator_set_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005349_(ONE_USE_PETR_REPLY, one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005350_(ONE_MAP_REQUEST_MODE_REPLY, one_map_request_mode_reply) \
5351_(ONE_EID_TABLE_ADD_DEL_MAP_REPLY, one_eid_table_add_del_map_reply) \
5352_(ONE_LOCATOR_SET_DETAILS, one_locator_set_details) \
5353_(ONE_LOCATOR_DETAILS, one_locator_details) \
5354_(ONE_EID_TABLE_DETAILS, one_eid_table_details) \
5355_(ONE_EID_TABLE_MAP_DETAILS, one_eid_table_map_details) \
5356_(ONE_EID_TABLE_VNI_DETAILS, one_eid_table_vni_details) \
5357_(ONE_MAP_RESOLVER_DETAILS, one_map_resolver_details) \
5358_(ONE_MAP_SERVER_DETAILS, one_map_server_details) \
5359_(ONE_ADJACENCIES_GET_REPLY, one_adjacencies_get_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005360_(ONE_STATS_DETAILS, one_stats_details) \
Filip Tehlar21511912017-04-07 10:41:42 +02005361_(ONE_STATS_FLUSH_REPLY, one_stats_flush_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005362_(ONE_STATS_ENABLE_DISABLE_REPLY, one_stats_enable_disable_reply) \
5363_(SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, \
5364 show_one_stats_enable_disable_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005365_(ONE_ADD_DEL_NDP_ENTRY_REPLY, one_add_del_ndp_entry_reply) \
5366_(ONE_NDP_BD_GET_REPLY, one_ndp_bd_get_reply) \
5367_(ONE_NDP_ENTRIES_GET_REPLY, one_ndp_entries_get_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005368_(ONE_ADD_DEL_L2_ARP_ENTRY_REPLY, one_add_del_l2_arp_entry_reply) \
5369_(ONE_L2_ARP_BD_GET_REPLY, one_l2_arp_bd_get_reply) \
5370_(ONE_L2_ARP_ENTRIES_GET_REPLY, one_l2_arp_entries_get_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005371_(ONE_ENABLE_DISABLE_XTR_MODE_REPLY, one_enable_disable_xtr_mode_reply) \
5372_(ONE_ENABLE_DISABLE_PITR_MODE_REPLY, \
5373 one_enable_disable_pitr_mode_reply) \
5374_(ONE_ENABLE_DISABLE_PETR_MODE_REPLY, \
5375 one_enable_disable_petr_mode_reply) \
5376_(ONE_SHOW_XTR_MODE_REPLY, one_show_xtr_mode_reply) \
5377_(ONE_SHOW_PITR_MODE_REPLY, one_show_pitr_mode_reply) \
5378_(ONE_SHOW_PETR_MODE_REPLY, one_show_petr_mode_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005379_(GPE_SET_ENCAP_MODE_REPLY, gpe_set_encap_mode_reply) \
5380_(GPE_GET_ENCAP_MODE_REPLY, gpe_get_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005381_(GPE_ADD_DEL_IFACE_REPLY, gpe_add_del_iface_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005382_(GPE_ENABLE_DISABLE_REPLY, gpe_enable_disable_reply) \
5383_(GPE_ADD_DEL_FWD_ENTRY_REPLY, gpe_add_del_fwd_entry_reply) \
Filip Tehlar0eb874e2017-05-18 14:23:32 +02005384_(GPE_FWD_ENTRY_VNIS_GET_REPLY, gpe_fwd_entry_vnis_get_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005385_(GPE_FWD_ENTRIES_GET_REPLY, gpe_fwd_entries_get_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005386_(GPE_NATIVE_FWD_RPATHS_GET_REPLY, gpe_native_fwd_rpaths_get_reply) \
5387_(GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY, \
5388 gpe_add_del_native_fwd_rpath_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005389_(GPE_FWD_ENTRY_PATH_DETAILS, \
5390 gpe_fwd_entry_path_details) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005391_(SHOW_ONE_STATUS_REPLY, show_one_status_reply) \
5392_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
5393 one_add_del_map_request_itr_rlocs_reply) \
5394_(ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
5395 one_get_map_request_itr_rlocs_reply) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02005396_(SHOW_ONE_NSH_MAPPING_REPLY, show_one_nsh_mapping_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005397_(SHOW_ONE_PITR_REPLY, show_one_pitr_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005398_(SHOW_ONE_USE_PETR_REPLY, show_one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005399_(SHOW_ONE_MAP_REQUEST_MODE_REPLY, show_one_map_request_mode_reply) \
5400_(SHOW_ONE_RLOC_PROBE_STATE_REPLY, show_one_rloc_probe_state_reply) \
5401_(SHOW_ONE_MAP_REGISTER_STATE_REPLY, \
5402 show_one_map_register_state_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005403_(SHOW_ONE_MAP_REGISTER_TTL_REPLY, show_one_map_register_ttl_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005404_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5405 show_one_map_register_fallback_threshold_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005406_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
5407_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +02005408_(AF_PACKET_DETAILS, af_packet_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005409_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
5410_(POLICER_DETAILS, policer_details) \
5411_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
5412_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005413_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005414_(MPLS_TABLE_DETAILS, mpls_table_details) \
5415_(MPLS_ROUTE_DETAILS, mpls_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005416_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
5417_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
5418_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
5419_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
5420_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
5421_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
5422_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
5423_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
5424_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
5425_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
5426_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
5427_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
5428_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
5429_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
5430_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
5431_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
5432_(PG_CAPTURE_REPLY, pg_capture_reply) \
5433_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
5434_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
5435 ip_source_and_port_range_check_add_del_reply) \
5436_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
5437 ip_source_and_port_range_check_interface_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005438_(DELETE_SUBIF_REPLY, delete_subif_reply) \
5439_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005440_(SET_PUNT_REPLY, set_punt_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005441_(IP_TABLE_DETAILS, ip_table_details) \
5442_(IP_ROUTE_DETAILS, ip_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005443_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
Mohsin Kazmi29467b52019-10-08 19:42:38 +02005444_(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005445_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
Matthew Smithe0792fd2019-07-12 11:48:24 -05005446_(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005447_(L2_XCONNECT_DETAILS, l2_xconnect_details) \
Ole Troand7231612018-06-07 10:17:57 +02005448_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005449_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
5450_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005451_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
5452_(LLDP_CONFIG_REPLY, lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005453_(SW_INTERFACE_SET_LLDP_REPLY, sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005454_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005455_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
Florin Coras6c36f532017-11-03 18:32:34 -07005456_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005457_(SESSION_RULES_DETAILS, session_rules_details) \
5458_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005459_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
Ole Troane906aac2018-06-14 14:42:14 +02005460_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005461
Dave Baracha1a093d2017-03-02 13:13:23 -05005462#define foreach_standalone_reply_msg \
Ole Troanf49ba0e2018-11-13 14:04:50 +01005463_(SW_INTERFACE_EVENT, sw_interface_event)
Dave Baracha1a093d2017-03-02 13:13:23 -05005464
Damjan Marion7cd468a2016-12-19 23:05:39 +01005465typedef struct
5466{
5467 u8 *name;
5468 u32 value;
5469} name_sort_t;
5470
Damjan Marion7cd468a2016-12-19 23:05:39 +01005471#define STR_VTR_OP_CASE(op) \
5472 case L2_VTR_ ## op: \
5473 return "" # op;
5474
5475static const char *
5476str_vtr_op (u32 vtr_op)
5477{
5478 switch (vtr_op)
5479 {
5480 STR_VTR_OP_CASE (DISABLED);
5481 STR_VTR_OP_CASE (PUSH_1);
5482 STR_VTR_OP_CASE (PUSH_2);
5483 STR_VTR_OP_CASE (POP_1);
5484 STR_VTR_OP_CASE (POP_2);
5485 STR_VTR_OP_CASE (TRANSLATE_1_1);
5486 STR_VTR_OP_CASE (TRANSLATE_1_2);
5487 STR_VTR_OP_CASE (TRANSLATE_2_1);
5488 STR_VTR_OP_CASE (TRANSLATE_2_2);
5489 }
5490
5491 return "UNKNOWN";
5492}
5493
5494static int
5495dump_sub_interface_table (vat_main_t * vam)
5496{
5497 const sw_interface_subif_t *sub = NULL;
5498
5499 if (vam->json_output)
5500 {
5501 clib_warning
5502 ("JSON output supported only for VPE API calls and dump_stats_table");
5503 return -99;
5504 }
5505
5506 print (vam->ofp,
5507 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
5508 "Interface", "sw_if_index",
5509 "sub id", "dot1ad", "tags", "outer id",
5510 "inner id", "exact", "default", "outer any", "inner any");
5511
5512 vec_foreach (sub, vam->sw_if_subif_table)
5513 {
5514 print (vam->ofp,
5515 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
5516 sub->interface_name,
5517 sub->sw_if_index,
5518 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
5519 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
5520 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
5521 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
5522 if (sub->vtr_op != L2_VTR_DISABLED)
5523 {
5524 print (vam->ofp,
5525 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
5526 "tag1: %d tag2: %d ]",
5527 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
5528 sub->vtr_tag1, sub->vtr_tag2);
5529 }
5530 }
5531
5532 return 0;
5533}
5534
5535static int
5536name_sort_cmp (void *a1, void *a2)
5537{
5538 name_sort_t *n1 = a1;
5539 name_sort_t *n2 = a2;
5540
5541 return strcmp ((char *) n1->name, (char *) n2->name);
5542}
5543
5544static int
5545dump_interface_table (vat_main_t * vam)
5546{
5547 hash_pair_t *p;
5548 name_sort_t *nses = 0, *ns;
5549
5550 if (vam->json_output)
5551 {
5552 clib_warning
5553 ("JSON output supported only for VPE API calls and dump_stats_table");
5554 return -99;
5555 }
5556
5557 /* *INDENT-OFF* */
5558 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5559 ({
5560 vec_add2 (nses, ns, 1);
5561 ns->name = (u8 *)(p->key);
5562 ns->value = (u32) p->value[0];
5563 }));
5564 /* *INDENT-ON* */
5565
5566 vec_sort_with_function (nses, name_sort_cmp);
5567
5568 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
5569 vec_foreach (ns, nses)
5570 {
5571 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
5572 }
5573 vec_free (nses);
5574 return 0;
5575}
5576
5577static int
5578dump_ip_table (vat_main_t * vam, int is_ipv6)
5579{
5580 const ip_details_t *det = NULL;
5581 const ip_address_details_t *address = NULL;
5582 u32 i = ~0;
5583
5584 print (vam->ofp, "%-12s", "sw_if_index");
5585
5586 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
5587 {
5588 i++;
5589 if (!det->present)
5590 {
5591 continue;
5592 }
5593 print (vam->ofp, "%-12d", i);
5594 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
5595 if (!det->addr)
5596 {
5597 continue;
5598 }
5599 vec_foreach (address, det->addr)
5600 {
5601 print (vam->ofp,
5602 " %-30U%-13d",
5603 is_ipv6 ? format_ip6_address : format_ip4_address,
5604 address->ip, address->prefix_length);
5605 }
5606 }
5607
5608 return 0;
5609}
5610
5611static int
5612dump_ipv4_table (vat_main_t * vam)
5613{
5614 if (vam->json_output)
5615 {
5616 clib_warning
5617 ("JSON output supported only for VPE API calls and dump_stats_table");
5618 return -99;
5619 }
5620
5621 return dump_ip_table (vam, 0);
5622}
5623
5624static int
5625dump_ipv6_table (vat_main_t * vam)
5626{
5627 if (vam->json_output)
5628 {
5629 clib_warning
5630 ("JSON output supported only for VPE API calls and dump_stats_table");
5631 return -99;
5632 }
5633
5634 return dump_ip_table (vam, 1);
5635}
5636
Damjan Marion7cd468a2016-12-19 23:05:39 +01005637/*
Dave Barach59b25652017-09-10 15:04:27 -04005638 * Pass CLI buffers directly in the CLI_INBAND API message,
5639 * instead of an additional shared memory area.
Damjan Marion7cd468a2016-12-19 23:05:39 +01005640 */
5641static int
5642exec_inband (vat_main_t * vam)
5643{
5644 vl_api_cli_inband_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005645 unformat_input_t *i = vam->input;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005646 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005647
5648 if (vec_len (i->buffer) == 0)
5649 return -1;
5650
5651 if (vam->exec_mode == 0 && unformat (i, "mode"))
5652 {
5653 vam->exec_mode = 1;
5654 return 0;
5655 }
5656 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
5657 {
5658 vam->exec_mode = 0;
5659 return 0;
5660 }
5661
5662 /*
5663 * In order for the CLI command to work, it
5664 * must be a vector ending in \n, not a C-string ending
5665 * in \n\0.
5666 */
Jakub Grajciar2dbee932020-02-07 11:30:26 +01005667 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
5668 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005669
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005670 S (mp);
Dave Barach59b25652017-09-10 15:04:27 -04005671 W (ret);
5672 /* json responses may or may not include a useful reply... */
5673 if (vec_len (vam->cmd_reply))
Dave Barachcf5e8482017-10-17 11:48:29 -04005674 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
Jon Loeliger56c7b012017-02-01 12:31:41 -06005675 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005676}
5677
Dave Barach59b25652017-09-10 15:04:27 -04005678int
5679exec (vat_main_t * vam)
5680{
5681 return exec_inband (vam);
5682}
5683
Damjan Marion7cd468a2016-12-19 23:05:39 +01005684static int
5685api_create_loopback (vat_main_t * vam)
5686{
5687 unformat_input_t *i = vam->input;
5688 vl_api_create_loopback_t *mp;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005689 vl_api_create_loopback_instance_t *mp_lbi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005690 u8 mac_address[6];
5691 u8 mac_set = 0;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005692 u8 is_specified = 0;
5693 u32 user_instance = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005694 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005695
Dave Barachb7b92992018-10-17 10:38:51 -04005696 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01005697
5698 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5699 {
5700 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5701 mac_set = 1;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005702 if (unformat (i, "instance %d", &user_instance))
5703 is_specified = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005704 else
5705 break;
5706 }
5707
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005708 if (is_specified)
5709 {
5710 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
5711 mp_lbi->is_specified = is_specified;
5712 if (is_specified)
5713 mp_lbi->user_instance = htonl (user_instance);
5714 if (mac_set)
5715 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
5716 S (mp_lbi);
5717 }
5718 else
5719 {
5720 /* Construct the API message */
5721 M (CREATE_LOOPBACK, mp);
5722 if (mac_set)
5723 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
5724 S (mp);
5725 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01005726
Jon Loeliger56c7b012017-02-01 12:31:41 -06005727 W (ret);
5728 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005729}
5730
5731static int
5732api_delete_loopback (vat_main_t * vam)
5733{
5734 unformat_input_t *i = vam->input;
5735 vl_api_delete_loopback_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005736 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005737 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005738
5739 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5740 {
5741 if (unformat (i, "sw_if_index %d", &sw_if_index))
5742 ;
5743 else
5744 break;
5745 }
5746
5747 if (sw_if_index == ~0)
5748 {
5749 errmsg ("missing sw_if_index");
5750 return -99;
5751 }
5752
5753 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005754 M (DELETE_LOOPBACK, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005755 mp->sw_if_index = ntohl (sw_if_index);
5756
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005757 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005758 W (ret);
5759 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005760}
5761
5762static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01005763api_want_interface_events (vat_main_t * vam)
5764{
5765 unformat_input_t *i = vam->input;
5766 vl_api_want_interface_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005767 int enable = -1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005768 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005769
5770 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5771 {
5772 if (unformat (i, "enable"))
5773 enable = 1;
5774 else if (unformat (i, "disable"))
5775 enable = 0;
5776 else
5777 break;
5778 }
5779
5780 if (enable == -1)
5781 {
5782 errmsg ("missing enable|disable");
5783 return -99;
5784 }
5785
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005786 M (WANT_INTERFACE_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005787 mp->enable_disable = enable;
5788
5789 vam->interface_event_display = enable;
5790
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005791 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005792 W (ret);
5793 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005794}
5795
5796
5797/* Note: non-static, called once to set up the initial intfc table */
5798int
5799api_sw_interface_dump (vat_main_t * vam)
5800{
5801 vl_api_sw_interface_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005802 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005803 hash_pair_t *p;
5804 name_sort_t *nses = 0, *ns;
5805 sw_interface_subif_t *sub = NULL;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005806 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005807
5808 /* Toss the old name table */
5809 /* *INDENT-OFF* */
5810 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5811 ({
5812 vec_add2 (nses, ns, 1);
5813 ns->name = (u8 *)(p->key);
5814 ns->value = (u32) p->value[0];
5815 }));
5816 /* *INDENT-ON* */
5817
5818 hash_free (vam->sw_if_index_by_interface_name);
5819
5820 vec_foreach (ns, nses) vec_free (ns->name);
5821
5822 vec_free (nses);
5823
5824 vec_foreach (sub, vam->sw_if_subif_table)
5825 {
5826 vec_free (sub->interface_name);
5827 }
5828 vec_free (vam->sw_if_subif_table);
5829
5830 /* recreate the interface name hash table */
5831 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
5832
Dave Barachf72212e2018-01-11 10:25:07 -05005833 /*
5834 * Ask for all interface names. Otherwise, the epic catalog of
5835 * name filters becomes ridiculously long, and vat ends up needing
5836 * to be taught about new interface types.
5837 */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005838 M (SW_INTERFACE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005839 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005840
5841 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04005842 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005843 S (mp_ping);
5844
Jon Loeliger56c7b012017-02-01 12:31:41 -06005845 W (ret);
5846 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005847}
5848
5849static int
5850api_sw_interface_set_flags (vat_main_t * vam)
5851{
5852 unformat_input_t *i = vam->input;
5853 vl_api_sw_interface_set_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005854 u32 sw_if_index;
5855 u8 sw_if_index_set = 0;
Neale Rannsa07bd702017-08-07 07:53:49 -07005856 u8 admin_up = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005857 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005858
5859 /* Parse args required to build the message */
5860 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5861 {
5862 if (unformat (i, "admin-up"))
5863 admin_up = 1;
5864 else if (unformat (i, "admin-down"))
5865 admin_up = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005866 else
5867 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5868 sw_if_index_set = 1;
5869 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5870 sw_if_index_set = 1;
5871 else
5872 break;
5873 }
5874
5875 if (sw_if_index_set == 0)
5876 {
5877 errmsg ("missing interface name or sw_if_index");
5878 return -99;
5879 }
5880
5881 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005882 M (SW_INTERFACE_SET_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005883 mp->sw_if_index = ntohl (sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +01005884 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005885
5886 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005887 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005888
5889 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06005890 W (ret);
5891 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005892}
5893
5894static int
Stevenad8015b2017-10-29 22:10:46 -07005895api_sw_interface_set_rx_mode (vat_main_t * vam)
5896{
5897 unformat_input_t *i = vam->input;
5898 vl_api_sw_interface_set_rx_mode_t *mp;
5899 u32 sw_if_index;
5900 u8 sw_if_index_set = 0;
5901 int ret;
5902 u8 queue_id_valid = 0;
5903 u32 queue_id;
5904 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
5905
5906 /* Parse args required to build the message */
5907 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5908 {
5909 if (unformat (i, "queue %d", &queue_id))
5910 queue_id_valid = 1;
5911 else if (unformat (i, "polling"))
5912 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
5913 else if (unformat (i, "interrupt"))
5914 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
5915 else if (unformat (i, "adaptive"))
5916 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
5917 else
5918 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5919 sw_if_index_set = 1;
5920 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5921 sw_if_index_set = 1;
5922 else
5923 break;
5924 }
5925
5926 if (sw_if_index_set == 0)
5927 {
5928 errmsg ("missing interface name or sw_if_index");
5929 return -99;
5930 }
5931 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
5932 {
5933 errmsg ("missing rx-mode");
5934 return -99;
5935 }
5936
5937 /* Construct the API message */
5938 M (SW_INTERFACE_SET_RX_MODE, mp);
5939 mp->sw_if_index = ntohl (sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +01005940 mp->mode = (vl_api_rx_mode_t) mode;
Stevenad8015b2017-10-29 22:10:46 -07005941 mp->queue_id_valid = queue_id_valid;
5942 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
5943
5944 /* send it... */
5945 S (mp);
5946
5947 /* Wait for a reply, return the good/bad news... */
5948 W (ret);
5949 return ret;
5950}
5951
5952static int
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005953api_sw_interface_set_rx_placement (vat_main_t * vam)
5954{
5955 unformat_input_t *i = vam->input;
5956 vl_api_sw_interface_set_rx_placement_t *mp;
5957 u32 sw_if_index;
5958 u8 sw_if_index_set = 0;
5959 int ret;
5960 u8 is_main = 0;
5961 u32 queue_id, thread_index;
5962
5963 /* Parse args required to build the message */
5964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5965 {
5966 if (unformat (i, "queue %d", &queue_id))
5967 ;
5968 else if (unformat (i, "main"))
5969 is_main = 1;
5970 else if (unformat (i, "worker %d", &thread_index))
5971 ;
5972 else
5973 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5974 sw_if_index_set = 1;
5975 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5976 sw_if_index_set = 1;
5977 else
5978 break;
5979 }
5980
5981 if (sw_if_index_set == 0)
5982 {
5983 errmsg ("missing interface name or sw_if_index");
5984 return -99;
5985 }
5986
5987 if (is_main)
5988 thread_index = 0;
5989 /* Construct the API message */
5990 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
5991 mp->sw_if_index = ntohl (sw_if_index);
5992 mp->worker_id = ntohl (thread_index);
5993 mp->queue_id = ntohl (queue_id);
5994 mp->is_main = is_main;
5995
5996 /* send it... */
5997 S (mp);
5998 /* Wait for a reply, return the good/bad news... */
5999 W (ret);
6000 return ret;
6001}
6002
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02006003static void vl_api_sw_interface_rx_placement_details_t_handler
6004 (vl_api_sw_interface_rx_placement_details_t * mp)
6005{
6006 vat_main_t *vam = &vat_main;
6007 u32 worker_id = ntohl (mp->worker_id);
6008
6009 print (vam->ofp,
6010 "\n%-11d %-11s %-6d %-5d %-9s",
6011 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
6012 worker_id, ntohl (mp->queue_id),
6013 (mp->mode ==
6014 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
6015}
6016
6017static void vl_api_sw_interface_rx_placement_details_t_handler_json
6018 (vl_api_sw_interface_rx_placement_details_t * mp)
6019{
6020 vat_main_t *vam = &vat_main;
6021 vat_json_node_t *node = NULL;
6022
6023 if (VAT_JSON_ARRAY != vam->json_tree.type)
6024 {
6025 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6026 vat_json_init_array (&vam->json_tree);
6027 }
6028 node = vat_json_array_add (&vam->json_tree);
6029
6030 vat_json_init_object (node);
6031 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6032 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
6033 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
6034 vat_json_object_add_uint (node, "mode", mp->mode);
6035}
6036
6037static int
6038api_sw_interface_rx_placement_dump (vat_main_t * vam)
6039{
6040 unformat_input_t *i = vam->input;
6041 vl_api_sw_interface_rx_placement_dump_t *mp;
6042 vl_api_control_ping_t *mp_ping;
6043 int ret;
6044 u32 sw_if_index;
6045 u8 sw_if_index_set = 0;
6046
6047 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6048 {
6049 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6050 sw_if_index_set++;
6051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6052 sw_if_index_set++;
6053 else
6054 break;
6055 }
6056
6057 print (vam->ofp,
6058 "\n%-11s %-11s %-6s %-5s %-4s",
6059 "sw_if_index", "main/worker", "thread", "queue", "mode");
6060
6061 /* Dump Interface rx placement */
6062 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
6063
6064 if (sw_if_index_set)
6065 mp->sw_if_index = htonl (sw_if_index);
6066 else
6067 mp->sw_if_index = ~0;
6068
6069 S (mp);
6070
6071 /* Use a control ping for synchronization */
6072 MPING (CONTROL_PING, mp_ping);
6073 S (mp_ping);
6074
6075 W (ret);
6076 return ret;
6077}
6078
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006079static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006080api_sw_interface_clear_stats (vat_main_t * vam)
6081{
6082 unformat_input_t *i = vam->input;
6083 vl_api_sw_interface_clear_stats_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006084 u32 sw_if_index;
6085 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006086 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006087
6088 /* Parse args required to build the message */
6089 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6090 {
6091 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6092 sw_if_index_set = 1;
6093 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6094 sw_if_index_set = 1;
6095 else
6096 break;
6097 }
6098
6099 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006100 M (SW_INTERFACE_CLEAR_STATS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006101
6102 if (sw_if_index_set == 1)
6103 mp->sw_if_index = ntohl (sw_if_index);
6104 else
6105 mp->sw_if_index = ~0;
6106
6107 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006108 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006109
6110 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006111 W (ret);
6112 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006113}
6114
Damjan Marion7cd468a2016-12-19 23:05:39 +01006115static int
6116api_sw_interface_add_del_address (vat_main_t * vam)
6117{
6118 unformat_input_t *i = vam->input;
6119 vl_api_sw_interface_add_del_address_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006120 u32 sw_if_index;
6121 u8 sw_if_index_set = 0;
6122 u8 is_add = 1, del_all = 0;
6123 u32 address_length = 0;
6124 u8 v4_address_set = 0;
6125 u8 v6_address_set = 0;
6126 ip4_address_t v4address;
6127 ip6_address_t v6address;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006128 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006129
6130 /* Parse args required to build the message */
6131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6132 {
6133 if (unformat (i, "del-all"))
6134 del_all = 1;
6135 else if (unformat (i, "del"))
6136 is_add = 0;
6137 else
6138 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6139 sw_if_index_set = 1;
6140 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6141 sw_if_index_set = 1;
6142 else if (unformat (i, "%U/%d",
6143 unformat_ip4_address, &v4address, &address_length))
6144 v4_address_set = 1;
6145 else if (unformat (i, "%U/%d",
6146 unformat_ip6_address, &v6address, &address_length))
6147 v6_address_set = 1;
6148 else
6149 break;
6150 }
6151
6152 if (sw_if_index_set == 0)
6153 {
6154 errmsg ("missing interface name or sw_if_index");
6155 return -99;
6156 }
6157 if (v4_address_set && v6_address_set)
6158 {
6159 errmsg ("both v4 and v6 addresses set");
6160 return -99;
6161 }
6162 if (!v4_address_set && !v6_address_set && !del_all)
6163 {
6164 errmsg ("no addresses set");
6165 return -99;
6166 }
6167
6168 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006169 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006170
6171 mp->sw_if_index = ntohl (sw_if_index);
6172 mp->is_add = is_add;
6173 mp->del_all = del_all;
6174 if (v6_address_set)
6175 {
Jakub Grajciar053204a2019-03-18 13:17:53 +01006176 mp->prefix.address.af = ADDRESS_IP6;
6177 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006178 }
6179 else
6180 {
Jakub Grajciar053204a2019-03-18 13:17:53 +01006181 mp->prefix.address.af = ADDRESS_IP4;
6182 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006183 }
Jakub Grajciar053204a2019-03-18 13:17:53 +01006184 mp->prefix.len = address_length;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006185
6186 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006187 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006188
6189 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006190 W (ret);
6191 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006192}
6193
6194static int
6195api_sw_interface_set_mpls_enable (vat_main_t * vam)
6196{
6197 unformat_input_t *i = vam->input;
6198 vl_api_sw_interface_set_mpls_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006199 u32 sw_if_index;
6200 u8 sw_if_index_set = 0;
6201 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006202 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006203
6204 /* Parse args required to build the message */
6205 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6206 {
6207 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6208 sw_if_index_set = 1;
6209 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6210 sw_if_index_set = 1;
6211 else if (unformat (i, "disable"))
6212 enable = 0;
6213 else if (unformat (i, "dis"))
6214 enable = 0;
6215 else
6216 break;
6217 }
6218
6219 if (sw_if_index_set == 0)
6220 {
6221 errmsg ("missing interface name or sw_if_index");
6222 return -99;
6223 }
6224
6225 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006226 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006227
6228 mp->sw_if_index = ntohl (sw_if_index);
6229 mp->enable = enable;
6230
6231 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006232 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006233
6234 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006235 W (ret);
6236 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006237}
6238
6239static int
6240api_sw_interface_set_table (vat_main_t * vam)
6241{
6242 unformat_input_t *i = vam->input;
6243 vl_api_sw_interface_set_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006244 u32 sw_if_index, vrf_id = 0;
6245 u8 sw_if_index_set = 0;
6246 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006247 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006248
6249 /* Parse args required to build the message */
6250 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6251 {
6252 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6253 sw_if_index_set = 1;
6254 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6255 sw_if_index_set = 1;
6256 else if (unformat (i, "vrf %d", &vrf_id))
6257 ;
6258 else if (unformat (i, "ipv6"))
6259 is_ipv6 = 1;
6260 else
6261 break;
6262 }
6263
6264 if (sw_if_index_set == 0)
6265 {
6266 errmsg ("missing interface name or sw_if_index");
6267 return -99;
6268 }
6269
6270 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006271 M (SW_INTERFACE_SET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006272
6273 mp->sw_if_index = ntohl (sw_if_index);
6274 mp->is_ipv6 = is_ipv6;
6275 mp->vrf_id = ntohl (vrf_id);
6276
6277 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006278 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006279
6280 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006281 W (ret);
6282 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006283}
6284
6285static void vl_api_sw_interface_get_table_reply_t_handler
6286 (vl_api_sw_interface_get_table_reply_t * mp)
6287{
6288 vat_main_t *vam = &vat_main;
6289
6290 print (vam->ofp, "%d", ntohl (mp->vrf_id));
6291
6292 vam->retval = ntohl (mp->retval);
6293 vam->result_ready = 1;
6294
6295}
6296
6297static void vl_api_sw_interface_get_table_reply_t_handler_json
6298 (vl_api_sw_interface_get_table_reply_t * mp)
6299{
6300 vat_main_t *vam = &vat_main;
6301 vat_json_node_t node;
6302
6303 vat_json_init_object (&node);
6304 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
6305 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
6306
6307 vat_json_print (vam->ofp, &node);
6308 vat_json_free (&node);
6309
6310 vam->retval = ntohl (mp->retval);
6311 vam->result_ready = 1;
6312}
6313
6314static int
6315api_sw_interface_get_table (vat_main_t * vam)
6316{
6317 unformat_input_t *i = vam->input;
6318 vl_api_sw_interface_get_table_t *mp;
6319 u32 sw_if_index;
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 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6325 {
6326 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6327 sw_if_index_set = 1;
6328 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6329 sw_if_index_set = 1;
6330 else if (unformat (i, "ipv6"))
6331 is_ipv6 = 1;
6332 else
6333 break;
6334 }
6335
6336 if (sw_if_index_set == 0)
6337 {
6338 errmsg ("missing interface name or sw_if_index");
6339 return -99;
6340 }
6341
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006342 M (SW_INTERFACE_GET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006343 mp->sw_if_index = htonl (sw_if_index);
6344 mp->is_ipv6 = is_ipv6;
6345
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006346 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006347 W (ret);
6348 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006349}
6350
6351static int
6352api_sw_interface_set_vpath (vat_main_t * vam)
6353{
6354 unformat_input_t *i = vam->input;
6355 vl_api_sw_interface_set_vpath_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006356 u32 sw_if_index = 0;
6357 u8 sw_if_index_set = 0;
6358 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006359 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006360
6361 /* Parse args required to build the message */
6362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6363 {
6364 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6365 sw_if_index_set = 1;
6366 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6367 sw_if_index_set = 1;
6368 else if (unformat (i, "enable"))
6369 is_enable = 1;
6370 else if (unformat (i, "disable"))
6371 is_enable = 0;
6372 else
6373 break;
6374 }
6375
6376 if (sw_if_index_set == 0)
6377 {
6378 errmsg ("missing interface name or sw_if_index");
6379 return -99;
6380 }
6381
6382 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006383 M (SW_INTERFACE_SET_VPATH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006384
6385 mp->sw_if_index = ntohl (sw_if_index);
6386 mp->enable = is_enable;
6387
6388 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006389 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006390
6391 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006392 W (ret);
6393 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006394}
6395
6396static int
6397api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
6398{
6399 unformat_input_t *i = vam->input;
6400 vl_api_sw_interface_set_vxlan_bypass_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006401 u32 sw_if_index = 0;
6402 u8 sw_if_index_set = 0;
John Lo2b81eb82017-01-30 13:12:10 -05006403 u8 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006404 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006405 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006406
6407 /* Parse args required to build the message */
6408 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6409 {
6410 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6411 sw_if_index_set = 1;
6412 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6413 sw_if_index_set = 1;
6414 else if (unformat (i, "enable"))
6415 is_enable = 1;
6416 else if (unformat (i, "disable"))
6417 is_enable = 0;
6418 else if (unformat (i, "ip4"))
6419 is_ipv6 = 0;
6420 else if (unformat (i, "ip6"))
6421 is_ipv6 = 1;
6422 else
6423 break;
6424 }
6425
6426 if (sw_if_index_set == 0)
6427 {
6428 errmsg ("missing interface name or sw_if_index");
6429 return -99;
6430 }
6431
6432 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006433 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006434
6435 mp->sw_if_index = ntohl (sw_if_index);
6436 mp->enable = is_enable;
6437 mp->is_ipv6 = is_ipv6;
6438
6439 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006440 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006441
6442 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006443 W (ret);
6444 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006445}
6446
Marco Varleseb598f1d2017-09-19 14:25:28 +02006447static int
6448api_sw_interface_set_geneve_bypass (vat_main_t * vam)
6449{
6450 unformat_input_t *i = vam->input;
6451 vl_api_sw_interface_set_geneve_bypass_t *mp;
6452 u32 sw_if_index = 0;
6453 u8 sw_if_index_set = 0;
6454 u8 is_enable = 1;
6455 u8 is_ipv6 = 0;
6456 int ret;
6457
6458 /* Parse args required to build the message */
6459 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6460 {
6461 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6462 sw_if_index_set = 1;
6463 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6464 sw_if_index_set = 1;
6465 else if (unformat (i, "enable"))
6466 is_enable = 1;
6467 else if (unformat (i, "disable"))
6468 is_enable = 0;
6469 else if (unformat (i, "ip4"))
6470 is_ipv6 = 0;
6471 else if (unformat (i, "ip6"))
6472 is_ipv6 = 1;
6473 else
6474 break;
6475 }
6476
6477 if (sw_if_index_set == 0)
6478 {
6479 errmsg ("missing interface name or sw_if_index");
6480 return -99;
6481 }
6482
6483 /* Construct the API message */
6484 M (SW_INTERFACE_SET_GENEVE_BYPASS, mp);
6485
6486 mp->sw_if_index = ntohl (sw_if_index);
6487 mp->enable = is_enable;
6488 mp->is_ipv6 = is_ipv6;
6489
6490 /* send it... */
6491 S (mp);
6492
6493 /* Wait for a reply... */
6494 W (ret);
6495 return ret;
6496}
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08006497
Damjan Marion7cd468a2016-12-19 23:05:39 +01006498static int
6499api_sw_interface_set_l2_xconnect (vat_main_t * vam)
6500{
6501 unformat_input_t *i = vam->input;
6502 vl_api_sw_interface_set_l2_xconnect_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006503 u32 rx_sw_if_index;
6504 u8 rx_sw_if_index_set = 0;
6505 u32 tx_sw_if_index;
6506 u8 tx_sw_if_index_set = 0;
6507 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006508 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006509
6510 /* Parse args required to build the message */
6511 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6512 {
6513 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6514 rx_sw_if_index_set = 1;
6515 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6516 tx_sw_if_index_set = 1;
6517 else if (unformat (i, "rx"))
6518 {
6519 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6520 {
6521 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6522 &rx_sw_if_index))
6523 rx_sw_if_index_set = 1;
6524 }
6525 else
6526 break;
6527 }
6528 else if (unformat (i, "tx"))
6529 {
6530 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6531 {
6532 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6533 &tx_sw_if_index))
6534 tx_sw_if_index_set = 1;
6535 }
6536 else
6537 break;
6538 }
6539 else if (unformat (i, "enable"))
6540 enable = 1;
6541 else if (unformat (i, "disable"))
6542 enable = 0;
6543 else
6544 break;
6545 }
6546
6547 if (rx_sw_if_index_set == 0)
6548 {
6549 errmsg ("missing rx interface name or rx_sw_if_index");
6550 return -99;
6551 }
6552
6553 if (enable && (tx_sw_if_index_set == 0))
6554 {
6555 errmsg ("missing tx interface name or tx_sw_if_index");
6556 return -99;
6557 }
6558
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006559 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006560
6561 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6562 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6563 mp->enable = enable;
6564
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006565 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006566 W (ret);
6567 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006568}
6569
6570static int
6571api_sw_interface_set_l2_bridge (vat_main_t * vam)
6572{
6573 unformat_input_t *i = vam->input;
6574 vl_api_sw_interface_set_l2_bridge_t *mp;
Neale Rannsb4743802018-09-05 09:13:57 -07006575 vl_api_l2_port_type_t port_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006576 u32 rx_sw_if_index;
6577 u8 rx_sw_if_index_set = 0;
6578 u32 bd_id;
6579 u8 bd_id_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006580 u32 shg = 0;
6581 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006582 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006583
Neale Rannsb4743802018-09-05 09:13:57 -07006584 port_type = L2_API_PORT_TYPE_NORMAL;
6585
Damjan Marion7cd468a2016-12-19 23:05:39 +01006586 /* Parse args required to build the message */
6587 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6588 {
6589 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
6590 rx_sw_if_index_set = 1;
6591 else if (unformat (i, "bd_id %d", &bd_id))
6592 bd_id_set = 1;
6593 else
6594 if (unformat
6595 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
6596 rx_sw_if_index_set = 1;
6597 else if (unformat (i, "shg %d", &shg))
6598 ;
6599 else if (unformat (i, "bvi"))
Neale Rannsb4743802018-09-05 09:13:57 -07006600 port_type = L2_API_PORT_TYPE_BVI;
6601 else if (unformat (i, "uu-fwd"))
6602 port_type = L2_API_PORT_TYPE_UU_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006603 else if (unformat (i, "enable"))
6604 enable = 1;
6605 else if (unformat (i, "disable"))
6606 enable = 0;
6607 else
6608 break;
6609 }
6610
6611 if (rx_sw_if_index_set == 0)
6612 {
6613 errmsg ("missing rx interface name or sw_if_index");
6614 return -99;
6615 }
6616
6617 if (enable && (bd_id_set == 0))
6618 {
6619 errmsg ("missing bridge domain");
6620 return -99;
6621 }
6622
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006623 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006624
6625 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6626 mp->bd_id = ntohl (bd_id);
6627 mp->shg = (u8) shg;
Neale Rannsb4743802018-09-05 09:13:57 -07006628 mp->port_type = ntohl (port_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006629 mp->enable = enable;
6630
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006631 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006632 W (ret);
6633 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006634}
6635
6636static int
6637api_bridge_domain_dump (vat_main_t * vam)
6638{
6639 unformat_input_t *i = vam->input;
6640 vl_api_bridge_domain_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006641 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006642 u32 bd_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006643 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006644
6645 /* Parse args required to build the message */
6646 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6647 {
6648 if (unformat (i, "bd_id %d", &bd_id))
6649 ;
6650 else
6651 break;
6652 }
6653
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006654 M (BRIDGE_DOMAIN_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006655 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006656 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006657
6658 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04006659 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006660 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006661
Jon Loeliger56c7b012017-02-01 12:31:41 -06006662 W (ret);
6663 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006664}
6665
6666static int
6667api_bridge_domain_add_del (vat_main_t * vam)
6668{
6669 unformat_input_t *i = vam->input;
6670 vl_api_bridge_domain_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006671 u32 bd_id = ~0;
6672 u8 is_add = 1;
6673 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006674 u8 *bd_tag = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006675 u32 mac_age = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006676 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006677
6678 /* Parse args required to build the message */
6679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6680 {
6681 if (unformat (i, "bd_id %d", &bd_id))
6682 ;
6683 else if (unformat (i, "flood %d", &flood))
6684 ;
6685 else if (unformat (i, "uu-flood %d", &uu_flood))
6686 ;
6687 else if (unformat (i, "forward %d", &forward))
6688 ;
6689 else if (unformat (i, "learn %d", &learn))
6690 ;
6691 else if (unformat (i, "arp-term %d", &arp_term))
6692 ;
6693 else if (unformat (i, "mac-age %d", &mac_age))
6694 ;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006695 else if (unformat (i, "bd-tag %s", &bd_tag))
6696 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006697 else if (unformat (i, "del"))
6698 {
6699 is_add = 0;
6700 flood = uu_flood = forward = learn = 0;
6701 }
6702 else
6703 break;
6704 }
6705
6706 if (bd_id == ~0)
6707 {
6708 errmsg ("missing bridge domain");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006709 ret = -99;
6710 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006711 }
6712
6713 if (mac_age > 255)
6714 {
6715 errmsg ("mac age must be less than 256 ");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006716 ret = -99;
6717 goto done;
6718 }
6719
John Lo70bfcaf2017-11-14 13:19:26 -05006720 if ((bd_tag) && (vec_len (bd_tag) > 63))
Jerome Tollet50570ec2017-09-14 12:53:56 +01006721 {
6722 errmsg ("bd-tag cannot be longer than 63");
6723 ret = -99;
6724 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006725 }
6726
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006727 M (BRIDGE_DOMAIN_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006728
6729 mp->bd_id = ntohl (bd_id);
6730 mp->flood = flood;
6731 mp->uu_flood = uu_flood;
6732 mp->forward = forward;
6733 mp->learn = learn;
6734 mp->arp_term = arp_term;
6735 mp->is_add = is_add;
6736 mp->mac_age = (u8) mac_age;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006737 if (bd_tag)
John Lo70bfcaf2017-11-14 13:19:26 -05006738 {
6739 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
6740 mp->bd_tag[vec_len (bd_tag)] = 0;
6741 }
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006742 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006743 W (ret);
Jerome Tollet50570ec2017-09-14 12:53:56 +01006744
6745done:
6746 vec_free (bd_tag);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006747 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006748}
6749
6750static int
Eyal Barif24991c2017-04-05 05:33:21 +03006751api_l2fib_flush_bd (vat_main_t * vam)
6752{
6753 unformat_input_t *i = vam->input;
6754 vl_api_l2fib_flush_bd_t *mp;
6755 u32 bd_id = ~0;
6756 int ret;
6757
6758 /* Parse args required to build the message */
6759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6760 {
6761 if (unformat (i, "bd_id %d", &bd_id));
6762 else
6763 break;
6764 }
6765
6766 if (bd_id == ~0)
6767 {
6768 errmsg ("missing bridge domain");
6769 return -99;
6770 }
6771
6772 M (L2FIB_FLUSH_BD, mp);
6773
6774 mp->bd_id = htonl (bd_id);
6775
6776 S (mp);
6777 W (ret);
6778 return ret;
6779}
6780
6781static int
6782api_l2fib_flush_int (vat_main_t * vam)
6783{
6784 unformat_input_t *i = vam->input;
6785 vl_api_l2fib_flush_int_t *mp;
6786 u32 sw_if_index = ~0;
6787 int ret;
6788
6789 /* Parse args required to build the message */
6790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6791 {
6792 if (unformat (i, "sw_if_index %d", &sw_if_index));
6793 else
6794 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
6795 else
6796 break;
6797 }
6798
6799 if (sw_if_index == ~0)
6800 {
6801 errmsg ("missing interface name or sw_if_index");
6802 return -99;
6803 }
6804
6805 M (L2FIB_FLUSH_INT, mp);
6806
6807 mp->sw_if_index = ntohl (sw_if_index);
6808
6809 S (mp);
6810 W (ret);
6811 return ret;
6812}
6813
6814static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006815api_l2fib_add_del (vat_main_t * vam)
6816{
6817 unformat_input_t *i = vam->input;
6818 vl_api_l2fib_add_del_t *mp;
6819 f64 timeout;
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006820 u8 mac[6] = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01006821 u8 mac_set = 0;
6822 u32 bd_id;
6823 u8 bd_id_set = 0;
John Lo7dbd7262018-05-31 10:25:18 -04006824 u32 sw_if_index = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006825 u8 sw_if_index_set = 0;
6826 u8 is_add = 1;
6827 u8 static_mac = 0;
6828 u8 filter_mac = 0;
6829 u8 bvi_mac = 0;
6830 int count = 1;
6831 f64 before = 0;
6832 int j;
6833
6834 /* Parse args required to build the message */
6835 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6836 {
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006837 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01006838 mac_set = 1;
6839 else if (unformat (i, "bd_id %d", &bd_id))
6840 bd_id_set = 1;
6841 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6842 sw_if_index_set = 1;
6843 else if (unformat (i, "sw_if"))
6844 {
6845 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6846 {
6847 if (unformat
6848 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6849 sw_if_index_set = 1;
6850 }
6851 else
6852 break;
6853 }
6854 else if (unformat (i, "static"))
6855 static_mac = 1;
6856 else if (unformat (i, "filter"))
6857 {
6858 filter_mac = 1;
6859 static_mac = 1;
6860 }
6861 else if (unformat (i, "bvi"))
6862 {
6863 bvi_mac = 1;
6864 static_mac = 1;
6865 }
6866 else if (unformat (i, "del"))
6867 is_add = 0;
6868 else if (unformat (i, "count %d", &count))
6869 ;
6870 else
6871 break;
6872 }
6873
6874 if (mac_set == 0)
6875 {
6876 errmsg ("missing mac address");
6877 return -99;
6878 }
6879
6880 if (bd_id_set == 0)
6881 {
6882 errmsg ("missing bridge domain");
6883 return -99;
6884 }
6885
6886 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
6887 {
6888 errmsg ("missing interface name or sw_if_index");
6889 return -99;
6890 }
6891
6892 if (count > 1)
6893 {
6894 /* Turn on async mode */
6895 vam->async_mode = 1;
6896 vam->async_errors = 0;
6897 before = vat_time_now (vam);
6898 }
6899
6900 for (j = 0; j < count; j++)
6901 {
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006902 M (L2FIB_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006903
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006904 clib_memcpy (mp->mac, mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006905 mp->bd_id = ntohl (bd_id);
6906 mp->is_add = is_add;
John Lo7dbd7262018-05-31 10:25:18 -04006907 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006908
6909 if (is_add)
6910 {
Damjan Marion7cd468a2016-12-19 23:05:39 +01006911 mp->static_mac = static_mac;
6912 mp->filter_mac = filter_mac;
6913 mp->bvi_mac = bvi_mac;
6914 }
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006915 increment_mac_address (mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006916 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006917 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006918 }
6919
6920 if (count > 1)
6921 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006922 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006923 f64 after;
6924
6925 /* Shut off async mode */
6926 vam->async_mode = 0;
6927
Dave Barach59b25652017-09-10 15:04:27 -04006928 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006929 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006930
6931 timeout = vat_time_now (vam) + 1.0;
6932 while (vat_time_now (vam) < timeout)
6933 if (vam->result_ready == 1)
6934 goto out;
6935 vam->retval = -99;
6936
6937 out:
6938 if (vam->retval == -99)
6939 errmsg ("timeout");
6940
6941 if (vam->async_errors > 0)
6942 {
6943 errmsg ("%d asynchronous errors", vam->async_errors);
6944 vam->retval = -98;
6945 }
6946 vam->async_errors = 0;
6947 after = vat_time_now (vam);
6948
6949 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6950 count, after - before, count / (after - before));
6951 }
6952 else
6953 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06006954 int ret;
6955
Damjan Marion7cd468a2016-12-19 23:05:39 +01006956 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006957 W (ret);
6958 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006959 }
6960 /* Return the good/bad news */
6961 return (vam->retval);
6962}
6963
6964static int
Eyal Barifead6702017-04-04 04:46:32 +03006965api_bridge_domain_set_mac_age (vat_main_t * vam)
6966{
6967 unformat_input_t *i = vam->input;
6968 vl_api_bridge_domain_set_mac_age_t *mp;
6969 u32 bd_id = ~0;
6970 u32 mac_age = 0;
6971 int ret;
6972
6973 /* Parse args required to build the message */
6974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6975 {
6976 if (unformat (i, "bd_id %d", &bd_id));
6977 else if (unformat (i, "mac-age %d", &mac_age));
6978 else
6979 break;
6980 }
6981
6982 if (bd_id == ~0)
6983 {
6984 errmsg ("missing bridge domain");
6985 return -99;
6986 }
6987
6988 if (mac_age > 255)
6989 {
6990 errmsg ("mac age must be less than 256 ");
6991 return -99;
6992 }
6993
6994 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
6995
6996 mp->bd_id = htonl (bd_id);
6997 mp->mac_age = (u8) mac_age;
6998
6999 S (mp);
7000 W (ret);
7001 return ret;
7002}
7003
7004static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01007005api_l2_flags (vat_main_t * vam)
7006{
7007 unformat_input_t *i = vam->input;
7008 vl_api_l2_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007009 u32 sw_if_index;
John Lo8d00fff2017-08-03 00:35:36 -04007010 u32 flags = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007011 u8 sw_if_index_set = 0;
John Lo8d00fff2017-08-03 00:35:36 -04007012 u8 is_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007013 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007014
7015 /* Parse args required to build the message */
7016 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7017 {
7018 if (unformat (i, "sw_if_index %d", &sw_if_index))
7019 sw_if_index_set = 1;
7020 else if (unformat (i, "sw_if"))
7021 {
7022 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7023 {
7024 if (unformat
7025 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7026 sw_if_index_set = 1;
7027 }
7028 else
7029 break;
7030 }
7031 else if (unformat (i, "learn"))
John Lo8d00fff2017-08-03 00:35:36 -04007032 flags |= L2_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007033 else if (unformat (i, "forward"))
John Lo8d00fff2017-08-03 00:35:36 -04007034 flags |= L2_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007035 else if (unformat (i, "flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007036 flags |= L2_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007037 else if (unformat (i, "uu-flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007038 flags |= L2_UU_FLOOD;
7039 else if (unformat (i, "arp-term"))
7040 flags |= L2_ARP_TERM;
7041 else if (unformat (i, "off"))
7042 is_set = 0;
7043 else if (unformat (i, "disable"))
7044 is_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007045 else
7046 break;
7047 }
7048
7049 if (sw_if_index_set == 0)
7050 {
7051 errmsg ("missing interface name or sw_if_index");
7052 return -99;
7053 }
7054
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007055 M (L2_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007056
7057 mp->sw_if_index = ntohl (sw_if_index);
John Lo8d00fff2017-08-03 00:35:36 -04007058 mp->feature_bitmap = ntohl (flags);
7059 mp->is_set = is_set;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007060
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007061 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007062 W (ret);
7063 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007064}
7065
7066static int
7067api_bridge_flags (vat_main_t * vam)
7068{
7069 unformat_input_t *i = vam->input;
7070 vl_api_bridge_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007071 u32 bd_id;
7072 u8 bd_id_set = 0;
7073 u8 is_set = 1;
Neale Rannsb4743802018-09-05 09:13:57 -07007074 bd_flags_t flags = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007075 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007076
7077 /* Parse args required to build the message */
7078 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7079 {
7080 if (unformat (i, "bd_id %d", &bd_id))
7081 bd_id_set = 1;
7082 else if (unformat (i, "learn"))
Neale Rannsb4743802018-09-05 09:13:57 -07007083 flags |= BRIDGE_API_FLAG_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007084 else if (unformat (i, "forward"))
Neale Rannsb4743802018-09-05 09:13:57 -07007085 flags |= BRIDGE_API_FLAG_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007086 else if (unformat (i, "flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007087 flags |= BRIDGE_API_FLAG_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007088 else if (unformat (i, "uu-flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007089 flags |= BRIDGE_API_FLAG_UU_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007090 else if (unformat (i, "arp-term"))
Neale Rannsb4743802018-09-05 09:13:57 -07007091 flags |= BRIDGE_API_FLAG_ARP_TERM;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007092 else if (unformat (i, "off"))
7093 is_set = 0;
7094 else if (unformat (i, "disable"))
7095 is_set = 0;
7096 else
7097 break;
7098 }
7099
7100 if (bd_id_set == 0)
7101 {
7102 errmsg ("missing bridge domain");
7103 return -99;
7104 }
7105
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007106 M (BRIDGE_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007107
7108 mp->bd_id = ntohl (bd_id);
Neale Rannsb4743802018-09-05 09:13:57 -07007109 mp->flags = ntohl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007110 mp->is_set = is_set;
7111
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007112 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007113 W (ret);
7114 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007115}
7116
7117static int
7118api_bd_ip_mac_add_del (vat_main_t * vam)
7119{
Neale Ranns4d5b9172018-10-24 02:57:49 -07007120 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
Ole Troan8006c6a2018-12-17 12:02:26 +01007121 vl_api_mac_address_t mac = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01007122 unformat_input_t *i = vam->input;
7123 vl_api_bd_ip_mac_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007124 u32 bd_id;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007125 u8 is_add = 1;
7126 u8 bd_id_set = 0;
7127 u8 ip_set = 0;
7128 u8 mac_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007129 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007130
7131
7132 /* Parse args required to build the message */
7133 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7134 {
7135 if (unformat (i, "bd_id %d", &bd_id))
7136 {
7137 bd_id_set++;
7138 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007139 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007140 {
7141 ip_set++;
7142 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007143 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007144 {
7145 mac_set++;
7146 }
7147 else if (unformat (i, "del"))
7148 is_add = 0;
7149 else
7150 break;
7151 }
7152
7153 if (bd_id_set == 0)
7154 {
7155 errmsg ("missing bridge domain");
7156 return -99;
7157 }
7158 else if (ip_set == 0)
7159 {
7160 errmsg ("missing IP address");
7161 return -99;
7162 }
7163 else if (mac_set == 0)
7164 {
7165 errmsg ("missing MAC address");
7166 return -99;
7167 }
7168
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007169 M (BD_IP_MAC_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007170
Neale Rannsbc764c82019-06-19 07:07:13 -07007171 mp->entry.bd_id = ntohl (bd_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007172 mp->is_add = is_add;
Neale Ranns4d5b9172018-10-24 02:57:49 -07007173
Neale Rannsbc764c82019-06-19 07:07:13 -07007174 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
7175 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
Neale Ranns4d5b9172018-10-24 02:57:49 -07007176
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007177 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007178 W (ret);
7179 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007180}
7181
John Loe26c81f2019-01-07 15:16:33 -05007182static int
7183api_bd_ip_mac_flush (vat_main_t * vam)
7184{
7185 unformat_input_t *i = vam->input;
7186 vl_api_bd_ip_mac_flush_t *mp;
7187 u32 bd_id;
7188 u8 bd_id_set = 0;
7189 int ret;
7190
7191 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7192 {
7193 if (unformat (i, "bd_id %d", &bd_id))
7194 {
7195 bd_id_set++;
7196 }
7197 else
7198 break;
7199 }
7200
7201 if (bd_id_set == 0)
7202 {
7203 errmsg ("missing bridge domain");
7204 return -99;
7205 }
7206
7207 M (BD_IP_MAC_FLUSH, mp);
7208
7209 mp->bd_id = ntohl (bd_id);
7210
7211 S (mp);
7212 W (ret);
7213 return ret;
7214}
7215
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007216static void vl_api_bd_ip_mac_details_t_handler
7217 (vl_api_bd_ip_mac_details_t * mp)
7218{
7219 vat_main_t *vam = &vat_main;
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007220
7221 print (vam->ofp,
Neale Rannsbc764c82019-06-19 07:07:13 -07007222 "\n%-5d %U %U",
7223 ntohl (mp->entry.bd_id),
7224 format_vl_api_mac_address, mp->entry.mac,
7225 format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007226}
7227
7228static void vl_api_bd_ip_mac_details_t_handler_json
7229 (vl_api_bd_ip_mac_details_t * mp)
7230{
7231 vat_main_t *vam = &vat_main;
7232 vat_json_node_t *node = NULL;
7233
7234 if (VAT_JSON_ARRAY != vam->json_tree.type)
7235 {
7236 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7237 vat_json_init_array (&vam->json_tree);
7238 }
7239 node = vat_json_array_add (&vam->json_tree);
7240
7241 vat_json_init_object (node);
Neale Rannsbc764c82019-06-19 07:07:13 -07007242 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007243 vat_json_object_add_string_copy (node, "mac_address",
Neale Rannsbc764c82019-06-19 07:07:13 -07007244 format (0, "%U", format_vl_api_mac_address,
7245 &mp->entry.mac));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007246 u8 *ip = 0;
7247
Neale Rannsbc764c82019-06-19 07:07:13 -07007248 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007249 vat_json_object_add_string_copy (node, "ip_address", ip);
7250 vec_free (ip);
7251}
7252
7253static int
7254api_bd_ip_mac_dump (vat_main_t * vam)
7255{
7256 unformat_input_t *i = vam->input;
7257 vl_api_bd_ip_mac_dump_t *mp;
7258 vl_api_control_ping_t *mp_ping;
7259 int ret;
7260 u32 bd_id;
7261 u8 bd_id_set = 0;
7262
7263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7264 {
7265 if (unformat (i, "bd_id %d", &bd_id))
7266 {
7267 bd_id_set++;
7268 }
7269 else
7270 break;
7271 }
7272
7273 print (vam->ofp,
7274 "\n%-5s %-7s %-20s %-30s",
7275 "bd_id", "is_ipv6", "mac_address", "ip_address");
7276
7277 /* Dump Bridge Domain Ip to Mac entries */
7278 M (BD_IP_MAC_DUMP, mp);
7279
7280 if (bd_id_set)
7281 mp->bd_id = htonl (bd_id);
7282 else
7283 mp->bd_id = ~0;
7284
7285 S (mp);
7286
7287 /* Use a control ping for synchronization */
7288 MPING (CONTROL_PING, mp_ping);
7289 S (mp_ping);
7290
7291 W (ret);
7292 return ret;
7293}
7294
Damjan Marion7cd468a2016-12-19 23:05:39 +01007295static int
Damjan Marion8389fb92017-10-13 18:29:53 +02007296api_tap_create_v2 (vat_main_t * vam)
7297{
7298 unformat_input_t *i = vam->input;
7299 vl_api_tap_create_v2_t *mp;
7300 u8 mac_address[6];
7301 u8 random_mac = 1;
Damjan Marion2df39092017-12-04 20:03:37 +01007302 u32 id = ~0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007303 u32 num_rx_queues = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007304 u8 *host_if_name = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007305 u8 host_if_name_set = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007306 u8 *host_ns = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007307 u8 host_ns_set = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007308 u8 host_mac_addr[6];
7309 u8 host_mac_addr_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007310 u8 *host_bridge = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007311 u8 host_bridge_set = 0;
7312 u8 host_ip4_prefix_set = 0;
7313 u8 host_ip6_prefix_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007314 ip4_address_t host_ip4_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007315 ip4_address_t host_ip4_gw;
7316 u8 host_ip4_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007317 u32 host_ip4_prefix_len = 0;
7318 ip6_address_t host_ip6_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007319 ip6_address_t host_ip6_gw;
7320 u8 host_ip6_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007321 u32 host_ip6_prefix_len = 0;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007322 u32 host_mtu_size = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007323 u8 host_mtu_set = 0;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007324 u32 tap_flags = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007325 int ret;
Steven9e635692018-03-01 09:36:01 -08007326 u32 rx_ring_sz = 0, tx_ring_sz = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007327
Dave Barachb7b92992018-10-17 10:38:51 -04007328 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion8389fb92017-10-13 18:29:53 +02007329
7330 /* Parse args required to build the message */
7331 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7332 {
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007333 if (unformat (i, "id %u", &id))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007334 ;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007335 else
7336 if (unformat
7337 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7338 random_mac = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007339 else if (unformat (i, "host-if-name %s", &host_if_name))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007340 host_if_name_set = 1;
7341 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007342 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007343 else if (unformat (i, "host-ns %s", &host_ns))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007344 host_ns_set = 1;
Damjan Marion2df39092017-12-04 20:03:37 +01007345 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
7346 host_mac_addr))
7347 host_mac_addr_set = 1;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007348 else if (unformat (i, "host-bridge %s", &host_bridge))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007349 host_bridge_set = 1;
7350 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
Damjan Marion91c6ef72017-12-01 13:34:24 +01007351 &host_ip4_addr, &host_ip4_prefix_len))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007352 host_ip4_prefix_set = 1;
7353 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
Damjan Marion91c6ef72017-12-01 13:34:24 +01007354 &host_ip6_addr, &host_ip6_prefix_len))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007355 host_ip6_prefix_set = 1;
Damjan Marion7866c452018-01-18 13:35:11 +01007356 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
7357 &host_ip4_gw))
7358 host_ip4_gw_set = 1;
7359 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
7360 &host_ip6_gw))
7361 host_ip6_gw_set = 1;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007362 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
Damjan Marion8389fb92017-10-13 18:29:53 +02007363 ;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007364 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
Damjan Marion8389fb92017-10-13 18:29:53 +02007365 ;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007366 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007367 host_mtu_set = 1;
7368 else if (unformat (i, "no-gso"))
7369 tap_flags &= ~TAP_FLAG_GSO;
7370 else if (unformat (i, "gso"))
7371 tap_flags |= TAP_FLAG_GSO;
Mohsin Kazmiba0061f2019-12-18 17:08:54 +01007372 else if (unformat (i, "csum-offload"))
7373 tap_flags |= TAP_FLAG_CSUM_OFFLOAD;
Mohsin Kazmib49bc1a2020-02-14 17:51:04 +00007374 else if (unformat (i, "persist"))
7375 tap_flags |= TAP_FLAG_PERSIST;
7376 else if (unformat (i, "attach"))
7377 tap_flags |= TAP_FLAG_ATTACH;
Damjan Marion8389fb92017-10-13 18:29:53 +02007378 else
7379 break;
7380 }
7381
Damjan Marion2df39092017-12-04 20:03:37 +01007382 if (vec_len (host_if_name) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007383 {
7384 errmsg ("tap name too long. ");
7385 return -99;
7386 }
Damjan Marion2df39092017-12-04 20:03:37 +01007387 if (vec_len (host_ns) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007388 {
7389 errmsg ("host name space too long. ");
7390 return -99;
7391 }
Damjan Marion91c6ef72017-12-01 13:34:24 +01007392 if (vec_len (host_bridge) > 63)
7393 {
7394 errmsg ("host bridge name too long. ");
7395 return -99;
7396 }
7397 if (host_ip4_prefix_len > 32)
7398 {
7399 errmsg ("host ip4 prefix length not valid. ");
7400 return -99;
7401 }
7402 if (host_ip6_prefix_len > 128)
7403 {
7404 errmsg ("host ip6 prefix length not valid. ");
7405 return -99;
7406 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007407 if (!is_pow2 (rx_ring_sz))
7408 {
7409 errmsg ("rx ring size must be power of 2. ");
7410 return -99;
7411 }
7412 if (rx_ring_sz > 32768)
7413 {
7414 errmsg ("rx ring size must be 32768 or lower. ");
7415 return -99;
7416 }
7417 if (!is_pow2 (tx_ring_sz))
7418 {
7419 errmsg ("tx ring size must be power of 2. ");
7420 return -99;
7421 }
7422 if (tx_ring_sz > 32768)
7423 {
7424 errmsg ("tx ring size must be 32768 or lower. ");
7425 return -99;
7426 }
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007427 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
7428 {
7429 errmsg ("host MTU size must be in between 64 and 65355. ");
7430 return -99;
7431 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007432
Damjan Marion8389fb92017-10-13 18:29:53 +02007433 /* Construct the API message */
7434 M (TAP_CREATE_V2, mp);
7435
Steven9e635692018-03-01 09:36:01 -08007436 mp->id = ntohl (id);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007437 mp->use_random_mac = random_mac;
7438 mp->num_rx_queues = (u8) num_rx_queues;
Steven9e635692018-03-01 09:36:01 -08007439 mp->tx_ring_sz = ntohs (tx_ring_sz);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007440 mp->rx_ring_sz = ntohs (rx_ring_sz);
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007441 mp->host_mtu_set = host_mtu_set;
7442 mp->host_mtu_size = ntohl (host_mtu_size);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007443 mp->host_mac_addr_set = host_mac_addr_set;
7444 mp->host_ip4_prefix_set = host_ip4_prefix_set;
7445 mp->host_ip6_prefix_set = host_ip6_prefix_set;
7446 mp->host_ip4_gw_set = host_ip4_gw_set;
7447 mp->host_ip6_gw_set = host_ip6_gw_set;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007448 mp->tap_flags = ntohl (tap_flags);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007449 mp->host_namespace_set = host_ns_set;
7450 mp->host_if_name_set = host_if_name_set;
7451 mp->host_bridge_set = host_bridge_set;
Damjan Marion2df39092017-12-04 20:03:37 +01007452
Steven9e635692018-03-01 09:36:01 -08007453 if (random_mac == 0)
Damjan Marion2df39092017-12-04 20:03:37 +01007454 clib_memcpy (mp->mac_address, mac_address, 6);
7455 if (host_mac_addr_set)
7456 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007457 if (host_if_name_set)
Damjan Marion2df39092017-12-04 20:03:37 +01007458 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007459 if (host_ns_set)
Damjan Marion2df39092017-12-04 20:03:37 +01007460 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007461 if (host_bridge_set)
Damjan Marion91c6ef72017-12-01 13:34:24 +01007462 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007463 if (host_ip4_prefix_set)
7464 {
7465 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
7466 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
7467 }
7468 if (host_ip6_prefix_set)
7469 {
7470 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
7471 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
7472 }
Damjan Marion7866c452018-01-18 13:35:11 +01007473 if (host_ip4_gw_set)
7474 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
7475 if (host_ip6_gw_set)
7476 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
Damjan Marion8389fb92017-10-13 18:29:53 +02007477
Damjan Marion2df39092017-12-04 20:03:37 +01007478 vec_free (host_ns);
7479 vec_free (host_if_name);
7480 vec_free (host_bridge);
Damjan Marion8389fb92017-10-13 18:29:53 +02007481
7482 /* send it... */
7483 S (mp);
7484
7485 /* Wait for a reply... */
7486 W (ret);
7487 return ret;
7488}
7489
7490static int
7491api_tap_delete_v2 (vat_main_t * vam)
7492{
7493 unformat_input_t *i = vam->input;
7494 vl_api_tap_delete_v2_t *mp;
7495 u32 sw_if_index = ~0;
7496 u8 sw_if_index_set = 0;
7497 int ret;
7498
7499 /* Parse args required to build the message */
7500 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7501 {
7502 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7503 sw_if_index_set = 1;
7504 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7505 sw_if_index_set = 1;
7506 else
7507 break;
7508 }
7509
7510 if (sw_if_index_set == 0)
7511 {
7512 errmsg ("missing vpp interface name. ");
7513 return -99;
7514 }
7515
7516 /* Construct the API message */
7517 M (TAP_DELETE_V2, mp);
7518
7519 mp->sw_if_index = ntohl (sw_if_index);
7520
7521 /* send it... */
7522 S (mp);
7523
7524 /* Wait for a reply... */
7525 W (ret);
7526 return ret;
7527}
7528
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007529uword
jialv01082ebeb2019-09-10 00:23:55 +08007530unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007531{
jialv01082ebeb2019-09-10 00:23:55 +08007532 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007533 u32 x[4];
7534
7535 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
7536 return 0;
7537
7538 addr->domain = x[0];
7539 addr->bus = x[1];
7540 addr->slot = x[2];
7541 addr->function = x[3];
7542
7543 return 1;
7544}
7545
7546static int
7547api_virtio_pci_create (vat_main_t * vam)
7548{
7549 unformat_input_t *i = vam->input;
7550 vl_api_virtio_pci_create_t *mp;
7551 u8 mac_address[6];
7552 u8 random_mac = 1;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007553 u8 gso_enabled = 0;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +00007554 u8 checksum_offload_enabled = 0;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007555 u32 pci_addr = 0;
7556 u64 features = (u64) ~ (0ULL);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007557 int ret;
7558
7559 clib_memset (mac_address, 0, sizeof (mac_address));
7560
7561 /* Parse args required to build the message */
7562 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7563 {
7564 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7565 {
7566 random_mac = 0;
7567 }
jialv01082ebeb2019-09-10 00:23:55 +08007568 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007569 ;
7570 else if (unformat (i, "features 0x%llx", &features))
7571 ;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007572 else if (unformat (i, "gso-enabled"))
7573 gso_enabled = 1;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +00007574 else if (unformat (i, "csum-offload-enabled"))
7575 checksum_offload_enabled = 1;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007576 else
7577 break;
7578 }
7579
7580 if (pci_addr == 0)
7581 {
7582 errmsg ("pci address must be non zero. ");
7583 return -99;
7584 }
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007585
7586 /* Construct the API message */
7587 M (VIRTIO_PCI_CREATE, mp);
7588
7589 mp->use_random_mac = random_mac;
7590
Jakub Grajciar2c504f82019-09-26 10:34:41 +02007591 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
7592 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
7593 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
7594 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
7595
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007596 mp->features = clib_host_to_net_u64 (features);
Benoît Ganne49ee6842019-04-30 11:50:46 +02007597 mp->gso_enabled = gso_enabled;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +00007598 mp->checksum_offload_enabled = checksum_offload_enabled;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007599
7600 if (random_mac == 0)
7601 clib_memcpy (mp->mac_address, mac_address, 6);
7602
7603 /* send it... */
7604 S (mp);
7605
7606 /* Wait for a reply... */
7607 W (ret);
7608 return ret;
7609}
7610
7611static int
7612api_virtio_pci_delete (vat_main_t * vam)
7613{
7614 unformat_input_t *i = vam->input;
7615 vl_api_virtio_pci_delete_t *mp;
7616 u32 sw_if_index = ~0;
7617 u8 sw_if_index_set = 0;
7618 int ret;
7619
7620 /* Parse args required to build the message */
7621 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7622 {
7623 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7624 sw_if_index_set = 1;
7625 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7626 sw_if_index_set = 1;
7627 else
7628 break;
7629 }
7630
7631 if (sw_if_index_set == 0)
7632 {
7633 errmsg ("missing vpp interface name. ");
7634 return -99;
7635 }
7636
7637 /* Construct the API message */
7638 M (VIRTIO_PCI_DELETE, mp);
7639
7640 mp->sw_if_index = htonl (sw_if_index);
7641
7642 /* send it... */
7643 S (mp);
7644
7645 /* Wait for a reply... */
7646 W (ret);
7647 return ret;
7648}
7649
Damjan Marion8389fb92017-10-13 18:29:53 +02007650static int
Steven9cd2d7a2017-12-20 12:43:01 -08007651api_bond_create (vat_main_t * vam)
7652{
7653 unformat_input_t *i = vam->input;
7654 vl_api_bond_create_t *mp;
7655 u8 mac_address[6];
7656 u8 custom_mac = 0;
7657 int ret;
7658 u8 mode;
7659 u8 lb;
7660 u8 mode_is_set = 0;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007661 u32 id = ~0;
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007662 u8 numa_only = 0;
Steven9cd2d7a2017-12-20 12:43:01 -08007663
Dave Barachb7b92992018-10-17 10:38:51 -04007664 clib_memset (mac_address, 0, sizeof (mac_address));
Steven9cd2d7a2017-12-20 12:43:01 -08007665 lb = BOND_LB_L2;
7666
7667 /* Parse args required to build the message */
7668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7669 {
7670 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
7671 mode_is_set = 1;
7672 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
7673 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
7674 ;
7675 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
7676 mac_address))
7677 custom_mac = 1;
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007678 else if (unformat (i, "numa-only"))
7679 numa_only = 1;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007680 else if (unformat (i, "id %u", &id))
7681 ;
Steven9cd2d7a2017-12-20 12:43:01 -08007682 else
7683 break;
7684 }
7685
7686 if (mode_is_set == 0)
7687 {
7688 errmsg ("Missing bond mode. ");
7689 return -99;
7690 }
7691
7692 /* Construct the API message */
7693 M (BOND_CREATE, mp);
7694
7695 mp->use_custom_mac = custom_mac;
7696
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02007697 mp->mode = htonl (mode);
7698 mp->lb = htonl (lb);
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007699 mp->id = htonl (id);
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007700 mp->numa_only = numa_only;
Steven9cd2d7a2017-12-20 12:43:01 -08007701
7702 if (custom_mac)
7703 clib_memcpy (mp->mac_address, mac_address, 6);
7704
7705 /* send it... */
7706 S (mp);
7707
7708 /* Wait for a reply... */
7709 W (ret);
7710 return ret;
7711}
7712
7713static int
7714api_bond_delete (vat_main_t * vam)
7715{
7716 unformat_input_t *i = vam->input;
7717 vl_api_bond_delete_t *mp;
7718 u32 sw_if_index = ~0;
7719 u8 sw_if_index_set = 0;
7720 int ret;
7721
7722 /* Parse args required to build the message */
7723 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7724 {
7725 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7726 sw_if_index_set = 1;
7727 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7728 sw_if_index_set = 1;
7729 else
7730 break;
7731 }
7732
7733 if (sw_if_index_set == 0)
7734 {
7735 errmsg ("missing vpp interface name. ");
7736 return -99;
7737 }
7738
7739 /* Construct the API message */
7740 M (BOND_DELETE, mp);
7741
7742 mp->sw_if_index = ntohl (sw_if_index);
7743
7744 /* send it... */
7745 S (mp);
7746
7747 /* Wait for a reply... */
7748 W (ret);
7749 return ret;
7750}
7751
7752static int
7753api_bond_enslave (vat_main_t * vam)
7754{
7755 unformat_input_t *i = vam->input;
7756 vl_api_bond_enslave_t *mp;
7757 u32 bond_sw_if_index;
7758 int ret;
7759 u8 is_passive;
7760 u8 is_long_timeout;
7761 u32 bond_sw_if_index_is_set = 0;
7762 u32 sw_if_index;
7763 u8 sw_if_index_is_set = 0;
7764
7765 /* Parse args required to build the message */
7766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7767 {
7768 if (unformat (i, "sw_if_index %d", &sw_if_index))
7769 sw_if_index_is_set = 1;
7770 else if (unformat (i, "bond %u", &bond_sw_if_index))
7771 bond_sw_if_index_is_set = 1;
7772 else if (unformat (i, "passive %d", &is_passive))
7773 ;
7774 else if (unformat (i, "long-timeout %d", &is_long_timeout))
7775 ;
7776 else
7777 break;
7778 }
7779
7780 if (bond_sw_if_index_is_set == 0)
7781 {
7782 errmsg ("Missing bond sw_if_index. ");
7783 return -99;
7784 }
7785 if (sw_if_index_is_set == 0)
7786 {
7787 errmsg ("Missing slave sw_if_index. ");
7788 return -99;
7789 }
7790
7791 /* Construct the API message */
7792 M (BOND_ENSLAVE, mp);
7793
7794 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
7795 mp->sw_if_index = ntohl (sw_if_index);
7796 mp->is_long_timeout = is_long_timeout;
7797 mp->is_passive = is_passive;
7798
7799 /* send it... */
7800 S (mp);
7801
7802 /* Wait for a reply... */
7803 W (ret);
7804 return ret;
7805}
7806
7807static int
7808api_bond_detach_slave (vat_main_t * vam)
7809{
7810 unformat_input_t *i = vam->input;
7811 vl_api_bond_detach_slave_t *mp;
7812 u32 sw_if_index = ~0;
7813 u8 sw_if_index_set = 0;
7814 int ret;
7815
7816 /* Parse args required to build the message */
7817 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7818 {
7819 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7820 sw_if_index_set = 1;
7821 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7822 sw_if_index_set = 1;
7823 else
7824 break;
7825 }
7826
7827 if (sw_if_index_set == 0)
7828 {
7829 errmsg ("missing vpp interface name. ");
7830 return -99;
7831 }
7832
7833 /* Construct the API message */
7834 M (BOND_DETACH_SLAVE, mp);
7835
7836 mp->sw_if_index = ntohl (sw_if_index);
7837
7838 /* send it... */
7839 S (mp);
7840
7841 /* Wait for a reply... */
7842 W (ret);
7843 return ret;
7844}
7845
7846static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007847api_ip_table_add_del (vat_main_t * vam)
7848{
7849 unformat_input_t *i = vam->input;
7850 vl_api_ip_table_add_del_t *mp;
7851 u32 table_id = ~0;
7852 u8 is_ipv6 = 0;
7853 u8 is_add = 1;
7854 int ret = 0;
7855
7856 /* Parse args required to build the message */
7857 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7858 {
7859 if (unformat (i, "ipv6"))
7860 is_ipv6 = 1;
7861 else if (unformat (i, "del"))
7862 is_add = 0;
7863 else if (unformat (i, "add"))
7864 is_add = 1;
7865 else if (unformat (i, "table %d", &table_id))
7866 ;
7867 else
7868 {
7869 clib_warning ("parse error '%U'", format_unformat_error, i);
7870 return -99;
7871 }
7872 }
7873
7874 if (~0 == table_id)
7875 {
7876 errmsg ("missing table-ID");
7877 return -99;
7878 }
7879
7880 /* Construct the API message */
7881 M (IP_TABLE_ADD_DEL, mp);
7882
Neale Ranns097fa662018-05-01 05:17:55 -07007883 mp->table.table_id = ntohl (table_id);
7884 mp->table.is_ip6 = is_ipv6;
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007885 mp->is_add = is_add;
7886
7887 /* send it... */
7888 S (mp);
7889
7890 /* Wait for a reply... */
7891 W (ret);
7892
7893 return ret;
7894}
7895
Neale Ranns097fa662018-05-01 05:17:55 -07007896uword
7897unformat_fib_path (unformat_input_t * input, va_list * args)
7898{
7899 vat_main_t *vam = va_arg (*args, vat_main_t *);
7900 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
7901 u32 weight, preference;
7902 mpls_label_t out_label;
7903
7904 clib_memset (path, 0, sizeof (*path));
7905 path->weight = 1;
7906 path->sw_if_index = ~0;
7907 path->rpf_id = ~0;
7908 path->n_labels = 0;
7909
7910 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7911 {
7912 if (unformat (input, "%U %U",
7913 unformat_vl_api_ip4_address,
7914 &path->nh.address.ip4,
7915 api_unformat_sw_if_index, vam, &path->sw_if_index))
7916 {
7917 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7918 }
7919 else if (unformat (input, "%U %U",
7920 unformat_vl_api_ip6_address,
7921 &path->nh.address.ip6,
7922 api_unformat_sw_if_index, vam, &path->sw_if_index))
7923 {
7924 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7925 }
7926 else if (unformat (input, "weight %u", &weight))
7927 {
7928 path->weight = weight;
7929 }
7930 else if (unformat (input, "preference %u", &preference))
7931 {
7932 path->preference = preference;
7933 }
7934 else if (unformat (input, "%U next-hop-table %d",
7935 unformat_vl_api_ip4_address,
7936 &path->nh.address.ip4, &path->table_id))
7937 {
7938 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7939 }
7940 else if (unformat (input, "%U next-hop-table %d",
7941 unformat_vl_api_ip6_address,
7942 &path->nh.address.ip6, &path->table_id))
7943 {
7944 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7945 }
7946 else if (unformat (input, "%U",
7947 unformat_vl_api_ip4_address, &path->nh.address.ip4))
7948 {
7949 /*
7950 * the recursive next-hops are by default in the default table
7951 */
7952 path->table_id = 0;
7953 path->sw_if_index = ~0;
7954 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7955 }
7956 else if (unformat (input, "%U",
7957 unformat_vl_api_ip6_address, &path->nh.address.ip6))
7958 {
7959 /*
7960 * the recursive next-hops are by default in the default table
7961 */
7962 path->table_id = 0;
7963 path->sw_if_index = ~0;
7964 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7965 }
7966 else if (unformat (input, "resolve-via-host"))
7967 {
7968 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
7969 }
7970 else if (unformat (input, "resolve-via-attached"))
7971 {
7972 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
7973 }
7974 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
7975 {
7976 path->type = FIB_API_PATH_TYPE_LOCAL;
7977 path->sw_if_index = ~0;
7978 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7979 }
7980 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
7981 {
7982 path->type = FIB_API_PATH_TYPE_LOCAL;
7983 path->sw_if_index = ~0;
7984 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7985 }
7986 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
7987 ;
7988 else if (unformat (input, "via-label %d", &path->nh.via_label))
7989 {
7990 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
7991 path->sw_if_index = ~0;
7992 }
7993 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
7994 {
7995 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
7996 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
7997 }
7998 else if (unformat (input, "local"))
7999 {
8000 path->type = FIB_API_PATH_TYPE_LOCAL;
8001 }
8002 else if (unformat (input, "out-labels"))
8003 {
8004 while (unformat (input, "%d", &out_label))
8005 {
8006 path->label_stack[path->n_labels].label = out_label;
8007 path->label_stack[path->n_labels].is_uniform = 0;
8008 path->label_stack[path->n_labels].ttl = 64;
8009 path->n_labels++;
8010 }
8011 }
8012 else if (unformat (input, "via"))
8013 {
8014 /* new path, back up and return */
8015 unformat_put_input (input);
8016 unformat_put_input (input);
8017 unformat_put_input (input);
8018 unformat_put_input (input);
8019 break;
8020 }
8021 else
8022 {
8023 return (0);
8024 }
8025 }
8026
8027 path->proto = ntohl (path->proto);
8028 path->type = ntohl (path->type);
8029 path->flags = ntohl (path->flags);
8030 path->table_id = ntohl (path->table_id);
8031 path->sw_if_index = ntohl (path->sw_if_index);
8032
8033 return (1);
8034}
8035
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008036static int
Neale Ranns097fa662018-05-01 05:17:55 -07008037api_ip_route_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008038{
8039 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008040 vl_api_ip_route_add_del_t *mp;
8041 u32 vrf_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008042 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008043 u8 is_multipath = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008044 u8 prefix_set = 0;
8045 u8 path_count = 0;
8046 vl_api_prefix_t pfx = { };
8047 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008048 int count = 1;
8049 int j;
8050 f64 before = 0;
8051 u32 random_add_del = 0;
8052 u32 *random_vector = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008053 u32 random_seed = 0xdeaddabe;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008054
8055 /* Parse args required to build the message */
8056 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8057 {
Neale Ranns097fa662018-05-01 05:17:55 -07008058 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8059 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008060 else if (unformat (i, "del"))
8061 is_add = 0;
8062 else if (unformat (i, "add"))
8063 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008064 else if (unformat (i, "vrf %d", &vrf_id))
8065 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008066 else if (unformat (i, "count %d", &count))
8067 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008068 else if (unformat (i, "random"))
8069 random_add_del = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008070 else if (unformat (i, "multipath"))
8071 is_multipath = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008072 else if (unformat (i, "seed %d", &random_seed))
8073 ;
8074 else
Neale Ranns097fa662018-05-01 05:17:55 -07008075 if (unformat
8076 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
8077 {
8078 path_count++;
8079 if (8 == path_count)
8080 {
8081 errmsg ("max 8 paths");
8082 return -99;
8083 }
8084 }
8085 else
Damjan Marion7cd468a2016-12-19 23:05:39 +01008086 {
8087 clib_warning ("parse error '%U'", format_unformat_error, i);
8088 return -99;
8089 }
8090 }
8091
Neale Ranns097fa662018-05-01 05:17:55 -07008092 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008093 {
Neale Ranns097fa662018-05-01 05:17:55 -07008094 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008095 return -99;
8096 }
Neale Ranns097fa662018-05-01 05:17:55 -07008097 if (prefix_set == 0)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008098 {
Neale Ranns097fa662018-05-01 05:17:55 -07008099 errmsg ("missing prefix");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008100 return -99;
8101 }
8102
8103 /* Generate a pile of unique, random routes */
8104 if (random_add_del)
8105 {
Neale Ranns097fa662018-05-01 05:17:55 -07008106 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008107 u32 this_random_address;
Neale Ranns097fa662018-05-01 05:17:55 -07008108 uword *random_hash;
8109
Damjan Marion7cd468a2016-12-19 23:05:39 +01008110 random_hash = hash_create (count, sizeof (uword));
8111
Neale Ranns097fa662018-05-01 05:17:55 -07008112 hash_set (random_hash, i->as_u32, 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008113 for (j = 0; j <= count; j++)
8114 {
8115 do
8116 {
8117 this_random_address = random_u32 (&random_seed);
8118 this_random_address =
8119 clib_host_to_net_u32 (this_random_address);
8120 }
8121 while (hash_get (random_hash, this_random_address));
8122 vec_add1 (random_vector, this_random_address);
8123 hash_set (random_hash, this_random_address, 1);
8124 }
8125 hash_free (random_hash);
Neale Ranns097fa662018-05-01 05:17:55 -07008126 set_ip4_address (&pfx.address, random_vector[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008127 }
8128
8129 if (count > 1)
8130 {
8131 /* Turn on async mode */
8132 vam->async_mode = 1;
8133 vam->async_errors = 0;
8134 before = vat_time_now (vam);
8135 }
8136
8137 for (j = 0; j < count; j++)
8138 {
8139 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008140 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008141
8142 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008143 mp->is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008144
Neale Ranns097fa662018-05-01 05:17:55 -07008145 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8146 mp->route.table_id = ntohl (vrf_id);
8147 mp->route.n_paths = path_count;
8148
8149 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
8150
8151 if (random_add_del)
8152 set_ip4_address (&pfx.address, random_vector[j + 1]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008153 else
Neale Ranns097fa662018-05-01 05:17:55 -07008154 increment_address (&pfx.address);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008155 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008156 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008157 /* If we receive SIGTERM, stop now... */
8158 if (vam->do_exit)
8159 break;
8160 }
8161
8162 /* When testing multiple add/del ops, use a control-ping to sync */
8163 if (count > 1)
8164 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008165 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008166 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008167 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008168
8169 /* Shut off async mode */
8170 vam->async_mode = 0;
8171
Dave Barach59b25652017-09-10 15:04:27 -04008172 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008173 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008174
8175 timeout = vat_time_now (vam) + 1.0;
8176 while (vat_time_now (vam) < timeout)
8177 if (vam->result_ready == 1)
8178 goto out;
8179 vam->retval = -99;
8180
8181 out:
8182 if (vam->retval == -99)
8183 errmsg ("timeout");
8184
8185 if (vam->async_errors > 0)
8186 {
8187 errmsg ("%d asynchronous errors", vam->async_errors);
8188 vam->retval = -98;
8189 }
8190 vam->async_errors = 0;
8191 after = vat_time_now (vam);
8192
8193 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8194 if (j > 0)
8195 count = j;
8196
8197 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8198 count, after - before, count / (after - before));
8199 }
8200 else
8201 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008202 int ret;
8203
Damjan Marion7cd468a2016-12-19 23:05:39 +01008204 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008205 W (ret);
8206 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008207 }
8208
8209 /* Return the good/bad news */
8210 return (vam->retval);
8211}
8212
8213static int
Neale Ranns32e1c012016-11-22 17:07:28 +00008214api_ip_mroute_add_del (vat_main_t * vam)
8215{
8216 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008217 u8 path_set = 0, prefix_set = 0, is_add = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008218 vl_api_ip_mroute_add_del_t *mp;
Neale Ranns32e1c012016-11-22 17:07:28 +00008219 mfib_entry_flags_t eflags = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008220 vl_api_mfib_path_t path;
8221 vl_api_mprefix_t pfx = { };
8222 u32 vrf_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008223 int ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008224
8225 /* Parse args required to build the message */
8226 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8227 {
Neale Ranns097fa662018-05-01 05:17:55 -07008228 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
Neale Ranns32e1c012016-11-22 17:07:28 +00008229 {
Neale Ranns097fa662018-05-01 05:17:55 -07008230 prefix_set = 1;
8231 pfx.grp_address_length = htons (pfx.grp_address_length);
Neale Ranns32e1c012016-11-22 17:07:28 +00008232 }
8233 else if (unformat (i, "del"))
8234 is_add = 0;
8235 else if (unformat (i, "add"))
8236 is_add = 1;
8237 else if (unformat (i, "vrf %d", &vrf_id))
8238 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008239 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
8240 path.itf_flags = htonl (path.itf_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008241 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
8242 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008243 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
8244 path_set = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008245 else
8246 {
8247 clib_warning ("parse error '%U'", format_unformat_error, i);
8248 return -99;
8249 }
8250 }
8251
Neale Ranns097fa662018-05-01 05:17:55 -07008252 if (prefix_set == 0)
Neale Ranns32e1c012016-11-22 17:07:28 +00008253 {
8254 errmsg ("missing addresses\n");
8255 return -99;
8256 }
Neale Ranns097fa662018-05-01 05:17:55 -07008257 if (path_set == 0)
8258 {
8259 errmsg ("missing path\n");
8260 return -99;
8261 }
Neale Ranns32e1c012016-11-22 17:07:28 +00008262
8263 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008264 M (IP_MROUTE_ADD_DEL, mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008265
Neale Ranns32e1c012016-11-22 17:07:28 +00008266 mp->is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008267 mp->is_multipath = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008268
Neale Ranns097fa662018-05-01 05:17:55 -07008269 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8270 mp->route.table_id = htonl (vrf_id);
8271 mp->route.n_paths = 1;
8272 mp->route.entry_flags = htonl (eflags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008273
Neale Ranns097fa662018-05-01 05:17:55 -07008274 clib_memcpy (&mp->route.paths, &path, sizeof (path));
Neale Ranns32e1c012016-11-22 17:07:28 +00008275
8276 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008277 S (mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008278 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008279 W (ret);
8280 return ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008281}
8282
8283static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008284api_mpls_table_add_del (vat_main_t * vam)
8285{
8286 unformat_input_t *i = vam->input;
8287 vl_api_mpls_table_add_del_t *mp;
8288 u32 table_id = ~0;
8289 u8 is_add = 1;
8290 int ret = 0;
8291
8292 /* Parse args required to build the message */
8293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8294 {
Florin Corasd0a59722017-10-15 17:41:21 +00008295 if (unformat (i, "table %d", &table_id))
8296 ;
8297 else if (unformat (i, "del"))
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008298 is_add = 0;
8299 else if (unformat (i, "add"))
8300 is_add = 1;
8301 else
8302 {
8303 clib_warning ("parse error '%U'", format_unformat_error, i);
8304 return -99;
8305 }
8306 }
8307
8308 if (~0 == table_id)
8309 {
8310 errmsg ("missing table-ID");
8311 return -99;
8312 }
8313
8314 /* Construct the API message */
8315 M (MPLS_TABLE_ADD_DEL, mp);
8316
Neale Ranns097fa662018-05-01 05:17:55 -07008317 mp->mt_table.mt_table_id = ntohl (table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008318 mp->mt_is_add = is_add;
8319
8320 /* send it... */
8321 S (mp);
8322
8323 /* Wait for a reply... */
8324 W (ret);
8325
8326 return ret;
8327}
8328
8329static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008330api_mpls_route_add_del (vat_main_t * vam)
8331{
Neale Ranns097fa662018-05-01 05:17:55 -07008332 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
8333 mpls_label_t local_label = MPLS_LABEL_INVALID;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008334 unformat_input_t *i = vam->input;
8335 vl_api_mpls_route_add_del_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07008336 vl_api_fib_path_t paths[8];
8337 int count = 1, j;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008338 f64 before = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008339
8340 /* Parse args required to build the message */
8341 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8342 {
Neale Ranns097fa662018-05-01 05:17:55 -07008343 if (unformat (i, "%d", &local_label))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008344 ;
8345 else if (unformat (i, "eos"))
8346 is_eos = 1;
8347 else if (unformat (i, "non-eos"))
8348 is_eos = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008349 else if (unformat (i, "del"))
8350 is_add = 0;
8351 else if (unformat (i, "add"))
8352 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008353 else if (unformat (i, "multipath"))
8354 is_multipath = 1;
8355 else if (unformat (i, "count %d", &count))
8356 ;
John Loe166fd92018-09-13 14:08:59 -04008357 else
8358 if (unformat
Neale Ranns097fa662018-05-01 05:17:55 -07008359 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Loe166fd92018-09-13 14:08:59 -04008360 {
Neale Ranns097fa662018-05-01 05:17:55 -07008361 path_count++;
8362 if (8 == path_count)
8363 {
8364 errmsg ("max 8 paths");
8365 return -99;
8366 }
John Loe166fd92018-09-13 14:08:59 -04008367 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008368 else
8369 {
8370 clib_warning ("parse error '%U'", format_unformat_error, i);
8371 return -99;
8372 }
8373 }
8374
Neale Ranns097fa662018-05-01 05:17:55 -07008375 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008376 {
Neale Ranns097fa662018-05-01 05:17:55 -07008377 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008378 return -99;
8379 }
8380
8381 if (MPLS_LABEL_INVALID == local_label)
8382 {
8383 errmsg ("missing label");
8384 return -99;
8385 }
8386
8387 if (count > 1)
8388 {
8389 /* Turn on async mode */
8390 vam->async_mode = 1;
8391 vam->async_errors = 0;
8392 before = vat_time_now (vam);
8393 }
8394
8395 for (j = 0; j < count; j++)
8396 {
8397 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008398 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008399
8400 mp->mr_is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008401 mp->mr_is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008402
Neale Ranns097fa662018-05-01 05:17:55 -07008403 mp->mr_route.mr_label = local_label;
8404 mp->mr_route.mr_eos = is_eos;
8405 mp->mr_route.mr_table_id = 0;
8406 mp->mr_route.mr_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008407
Neale Ranns097fa662018-05-01 05:17:55 -07008408 clib_memcpy (&mp->mr_route.mr_paths, paths,
8409 sizeof (paths[0]) * path_count);
Neale Rannsda78f952017-05-24 09:15:43 -07008410
Damjan Marion7cd468a2016-12-19 23:05:39 +01008411 local_label++;
8412
8413 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008414 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008415 /* If we receive SIGTERM, stop now... */
8416 if (vam->do_exit)
8417 break;
8418 }
8419
8420 /* When testing multiple add/del ops, use a control-ping to sync */
8421 if (count > 1)
8422 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008423 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008424 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008425 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008426
8427 /* Shut off async mode */
8428 vam->async_mode = 0;
8429
Dave Barach59b25652017-09-10 15:04:27 -04008430 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008431 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008432
8433 timeout = vat_time_now (vam) + 1.0;
8434 while (vat_time_now (vam) < timeout)
8435 if (vam->result_ready == 1)
8436 goto out;
8437 vam->retval = -99;
8438
8439 out:
8440 if (vam->retval == -99)
8441 errmsg ("timeout");
8442
8443 if (vam->async_errors > 0)
8444 {
8445 errmsg ("%d asynchronous errors", vam->async_errors);
8446 vam->retval = -98;
8447 }
8448 vam->async_errors = 0;
8449 after = vat_time_now (vam);
8450
8451 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8452 if (j > 0)
8453 count = j;
8454
8455 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8456 count, after - before, count / (after - before));
8457 }
8458 else
8459 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008460 int ret;
8461
Damjan Marion7cd468a2016-12-19 23:05:39 +01008462 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008463 W (ret);
8464 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008465 }
8466
8467 /* Return the good/bad news */
8468 return (vam->retval);
Neale Ranns097fa662018-05-01 05:17:55 -07008469 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008470}
8471
8472static int
8473api_mpls_ip_bind_unbind (vat_main_t * vam)
8474{
8475 unformat_input_t *i = vam->input;
8476 vl_api_mpls_ip_bind_unbind_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008477 u32 ip_table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008478 u8 is_bind = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008479 vl_api_prefix_t pfx;
8480 u8 prefix_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008481 mpls_label_t local_label = MPLS_LABEL_INVALID;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008482 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008483
8484 /* Parse args required to build the message */
8485 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8486 {
Neale Ranns097fa662018-05-01 05:17:55 -07008487 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8488 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008489 else if (unformat (i, "%d", &local_label))
8490 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008491 else if (unformat (i, "table-id %d", &ip_table_id))
8492 ;
8493 else if (unformat (i, "unbind"))
8494 is_bind = 0;
8495 else if (unformat (i, "bind"))
8496 is_bind = 1;
8497 else
8498 {
8499 clib_warning ("parse error '%U'", format_unformat_error, i);
8500 return -99;
8501 }
8502 }
8503
Neale Ranns097fa662018-05-01 05:17:55 -07008504 if (!prefix_set)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008505 {
Neale Ranns097fa662018-05-01 05:17:55 -07008506 errmsg ("IP prefix not set");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008507 return -99;
8508 }
8509
8510 if (MPLS_LABEL_INVALID == local_label)
8511 {
8512 errmsg ("missing label");
8513 return -99;
8514 }
8515
8516 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008517 M (MPLS_IP_BIND_UNBIND, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008518
Damjan Marion7cd468a2016-12-19 23:05:39 +01008519 mp->mb_is_bind = is_bind;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008520 mp->mb_ip_table_id = ntohl (ip_table_id);
8521 mp->mb_mpls_table_id = 0;
8522 mp->mb_label = ntohl (local_label);
Neale Ranns097fa662018-05-01 05:17:55 -07008523 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008524
8525 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008526 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008527
8528 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008529 W (ret);
8530 return ret;
Neale Ranns097fa662018-05-01 05:17:55 -07008531 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008532}
8533
8534static int
John Loe166fd92018-09-13 14:08:59 -04008535api_sr_mpls_policy_add (vat_main_t * vam)
8536{
8537 unformat_input_t *i = vam->input;
8538 vl_api_sr_mpls_policy_add_t *mp;
8539 u32 bsid = 0;
8540 u32 weight = 1;
8541 u8 type = 0;
8542 u8 n_segments = 0;
8543 u32 sid;
8544 u32 *segments = NULL;
8545 int ret;
8546
8547 /* Parse args required to build the message */
8548 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8549 {
8550 if (unformat (i, "bsid %d", &bsid))
8551 ;
8552 else if (unformat (i, "weight %d", &weight))
8553 ;
8554 else if (unformat (i, "spray"))
8555 type = 1;
8556 else if (unformat (i, "next %d", &sid))
8557 {
8558 n_segments += 1;
8559 vec_add1 (segments, htonl (sid));
8560 }
8561 else
8562 {
8563 clib_warning ("parse error '%U'", format_unformat_error, i);
8564 return -99;
8565 }
8566 }
8567
8568 if (bsid == 0)
8569 {
8570 errmsg ("bsid not set");
8571 return -99;
8572 }
8573
8574 if (n_segments == 0)
8575 {
8576 errmsg ("no sid in segment stack");
8577 return -99;
8578 }
8579
8580 /* Construct the API message */
8581 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
8582
8583 mp->bsid = htonl (bsid);
8584 mp->weight = htonl (weight);
Jakub Grajciar00ec4012020-01-31 10:17:29 +01008585 mp->is_spray = type;
John Loe166fd92018-09-13 14:08:59 -04008586 mp->n_segments = n_segments;
8587 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
8588 vec_free (segments);
8589
8590 /* send it... */
8591 S (mp);
8592
8593 /* Wait for a reply... */
8594 W (ret);
8595 return ret;
8596}
8597
8598static int
8599api_sr_mpls_policy_del (vat_main_t * vam)
8600{
8601 unformat_input_t *i = vam->input;
8602 vl_api_sr_mpls_policy_del_t *mp;
8603 u32 bsid = 0;
8604 int ret;
8605
8606 /* Parse args required to build the message */
8607 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8608 {
8609 if (unformat (i, "bsid %d", &bsid))
8610 ;
8611 else
8612 {
8613 clib_warning ("parse error '%U'", format_unformat_error, i);
8614 return -99;
8615 }
8616 }
8617
8618 if (bsid == 0)
8619 {
8620 errmsg ("bsid not set");
8621 return -99;
8622 }
8623
8624 /* Construct the API message */
8625 M (SR_MPLS_POLICY_DEL, mp);
8626
8627 mp->bsid = htonl (bsid);
8628
8629 /* send it... */
8630 S (mp);
8631
8632 /* Wait for a reply... */
8633 W (ret);
8634 return ret;
8635}
8636
8637static int
Neale Rannsd792d9c2017-10-21 10:53:20 -07008638api_bier_table_add_del (vat_main_t * vam)
8639{
8640 unformat_input_t *i = vam->input;
8641 vl_api_bier_table_add_del_t *mp;
8642 u8 is_add = 1;
8643 u32 set = 0, sub_domain = 0, hdr_len = 3;
8644 mpls_label_t local_label = MPLS_LABEL_INVALID;
8645 int ret;
8646
8647 /* Parse args required to build the message */
8648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8649 {
8650 if (unformat (i, "sub-domain %d", &sub_domain))
8651 ;
8652 else if (unformat (i, "set %d", &set))
8653 ;
8654 else if (unformat (i, "label %d", &local_label))
8655 ;
8656 else if (unformat (i, "hdr-len %d", &hdr_len))
8657 ;
8658 else if (unformat (i, "add"))
8659 is_add = 1;
8660 else if (unformat (i, "del"))
8661 is_add = 0;
8662 else
8663 {
8664 clib_warning ("parse error '%U'", format_unformat_error, i);
8665 return -99;
8666 }
8667 }
8668
8669 if (MPLS_LABEL_INVALID == local_label)
8670 {
8671 errmsg ("missing label\n");
8672 return -99;
8673 }
8674
8675 /* Construct the API message */
8676 M (BIER_TABLE_ADD_DEL, mp);
8677
8678 mp->bt_is_add = is_add;
8679 mp->bt_label = ntohl (local_label);
8680 mp->bt_tbl_id.bt_set = set;
8681 mp->bt_tbl_id.bt_sub_domain = sub_domain;
8682 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
8683
8684 /* send it... */
8685 S (mp);
8686
8687 /* Wait for a reply... */
8688 W (ret);
8689
8690 return (ret);
8691}
8692
8693static int
8694api_bier_route_add_del (vat_main_t * vam)
8695{
8696 unformat_input_t *i = vam->input;
8697 vl_api_bier_route_add_del_t *mp;
8698 u8 is_add = 1;
8699 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
8700 ip4_address_t v4_next_hop_address;
8701 ip6_address_t v6_next_hop_address;
8702 u8 next_hop_set = 0;
8703 u8 next_hop_proto_is_ip4 = 1;
8704 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
8705 int ret;
8706
8707 /* Parse args required to build the message */
8708 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8709 {
8710 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
8711 {
8712 next_hop_proto_is_ip4 = 1;
8713 next_hop_set = 1;
8714 }
8715 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
8716 {
8717 next_hop_proto_is_ip4 = 0;
8718 next_hop_set = 1;
8719 }
8720 if (unformat (i, "sub-domain %d", &sub_domain))
8721 ;
8722 else if (unformat (i, "set %d", &set))
8723 ;
8724 else if (unformat (i, "hdr-len %d", &hdr_len))
8725 ;
8726 else if (unformat (i, "bp %d", &bp))
8727 ;
8728 else if (unformat (i, "add"))
8729 is_add = 1;
8730 else if (unformat (i, "del"))
8731 is_add = 0;
8732 else if (unformat (i, "out-label %d", &next_hop_out_label))
8733 ;
8734 else
8735 {
8736 clib_warning ("parse error '%U'", format_unformat_error, i);
8737 return -99;
8738 }
8739 }
8740
8741 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
8742 {
8743 errmsg ("next hop / label set\n");
8744 return -99;
8745 }
8746 if (0 == bp)
8747 {
8748 errmsg ("bit=position not set\n");
8749 return -99;
8750 }
8751
8752 /* Construct the API message */
Neale Ranns31ed7442018-02-23 05:29:09 -08008753 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
Neale Rannsd792d9c2017-10-21 10:53:20 -07008754
8755 mp->br_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008756 mp->br_route.br_tbl_id.bt_set = set;
8757 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
8758 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
8759 mp->br_route.br_bp = ntohs (bp);
8760 mp->br_route.br_n_paths = 1;
8761 mp->br_route.br_paths[0].n_labels = 1;
8762 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
8763 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
8764 FIB_API_PATH_NH_PROTO_IP4 :
8765 FIB_API_PATH_NH_PROTO_IP6);
Neale Rannsd792d9c2017-10-21 10:53:20 -07008766
8767 if (next_hop_proto_is_ip4)
8768 {
Neale Ranns097fa662018-05-01 05:17:55 -07008769 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008770 &v4_next_hop_address, sizeof (v4_next_hop_address));
8771 }
8772 else
8773 {
Neale Ranns097fa662018-05-01 05:17:55 -07008774 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008775 &v6_next_hop_address, sizeof (v6_next_hop_address));
8776 }
8777
8778 /* send it... */
8779 S (mp);
8780
8781 /* Wait for a reply... */
8782 W (ret);
8783
8784 return (ret);
8785}
8786
8787static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008788api_mpls_tunnel_add_del (vat_main_t * vam)
8789{
8790 unformat_input_t *i = vam->input;
8791 vl_api_mpls_tunnel_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008792
Neale Ranns097fa662018-05-01 05:17:55 -07008793 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008794 u32 sw_if_index = ~0;
Neale Ranns097fa662018-05-01 05:17:55 -07008795 u8 path_count = 0;
8796 u8 l2_only = 0;
8797 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008798 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008799
8800 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8801 {
8802 if (unformat (i, "add"))
8803 is_add = 1;
John Lo06fda9c2018-10-03 16:32:44 -04008804 else
8805 if (unformat
8806 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
8807 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008808 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
8809 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008810 else if (unformat (i, "l2-only"))
8811 l2_only = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008812 else
8813 if (unformat
8814 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Lo06fda9c2018-10-03 16:32:44 -04008815 {
Neale Ranns097fa662018-05-01 05:17:55 -07008816 path_count++;
8817 if (8 == path_count)
8818 {
8819 errmsg ("max 8 paths");
8820 return -99;
8821 }
John Lo06fda9c2018-10-03 16:32:44 -04008822 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008823 else
8824 {
8825 clib_warning ("parse error '%U'", format_unformat_error, i);
8826 return -99;
8827 }
8828 }
8829
Neale Ranns097fa662018-05-01 05:17:55 -07008830 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008831
Damjan Marion7cd468a2016-12-19 23:05:39 +01008832 mp->mt_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008833 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
8834 mp->mt_tunnel.mt_l2_only = l2_only;
8835 mp->mt_tunnel.mt_is_multicast = 0;
8836 mp->mt_tunnel.mt_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008837
Neale Ranns097fa662018-05-01 05:17:55 -07008838 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
8839 sizeof (paths[0]) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008840
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008841 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008842 W (ret);
8843 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008844}
8845
8846static int
8847api_sw_interface_set_unnumbered (vat_main_t * vam)
8848{
8849 unformat_input_t *i = vam->input;
8850 vl_api_sw_interface_set_unnumbered_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008851 u32 sw_if_index;
8852 u32 unnum_sw_index = ~0;
8853 u8 is_add = 1;
8854 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008855 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008856
8857 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8858 {
8859 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8860 sw_if_index_set = 1;
8861 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8862 sw_if_index_set = 1;
8863 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
8864 ;
8865 else if (unformat (i, "del"))
8866 is_add = 0;
8867 else
8868 {
8869 clib_warning ("parse error '%U'", format_unformat_error, i);
8870 return -99;
8871 }
8872 }
8873
8874 if (sw_if_index_set == 0)
8875 {
8876 errmsg ("missing interface name or sw_if_index");
8877 return -99;
8878 }
8879
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008880 M (SW_INTERFACE_SET_UNNUMBERED, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008881
8882 mp->sw_if_index = ntohl (sw_if_index);
8883 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
8884 mp->is_add = is_add;
8885
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008886 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008887 W (ret);
8888 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008889}
8890
Damjan Marion7cd468a2016-12-19 23:05:39 +01008891
8892static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008893api_create_vlan_subif (vat_main_t * vam)
8894{
8895 unformat_input_t *i = vam->input;
8896 vl_api_create_vlan_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008897 u32 sw_if_index;
8898 u8 sw_if_index_set = 0;
8899 u32 vlan_id;
8900 u8 vlan_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008901 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008902
8903 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8904 {
8905 if (unformat (i, "sw_if_index %d", &sw_if_index))
8906 sw_if_index_set = 1;
8907 else
8908 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8909 sw_if_index_set = 1;
8910 else if (unformat (i, "vlan %d", &vlan_id))
8911 vlan_id_set = 1;
8912 else
8913 {
8914 clib_warning ("parse error '%U'", format_unformat_error, i);
8915 return -99;
8916 }
8917 }
8918
8919 if (sw_if_index_set == 0)
8920 {
8921 errmsg ("missing interface name or sw_if_index");
8922 return -99;
8923 }
8924
8925 if (vlan_id_set == 0)
8926 {
8927 errmsg ("missing vlan_id");
8928 return -99;
8929 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008930 M (CREATE_VLAN_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008931
8932 mp->sw_if_index = ntohl (sw_if_index);
8933 mp->vlan_id = ntohl (vlan_id);
8934
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008935 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008936 W (ret);
8937 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008938}
8939
8940#define foreach_create_subif_bit \
8941_(no_tags) \
8942_(one_tag) \
8943_(two_tags) \
8944_(dot1ad) \
8945_(exact_match) \
8946_(default_sub) \
8947_(outer_vlan_id_any) \
8948_(inner_vlan_id_any)
8949
Jakub Grajciar053204a2019-03-18 13:17:53 +01008950#define foreach_create_subif_flag \
8951_(0, "no_tags") \
8952_(1, "one_tag") \
8953_(2, "two_tags") \
8954_(3, "dot1ad") \
8955_(4, "exact_match") \
8956_(5, "default_sub") \
8957_(6, "outer_vlan_id_any") \
8958_(7, "inner_vlan_id_any")
8959
Damjan Marion7cd468a2016-12-19 23:05:39 +01008960static int
8961api_create_subif (vat_main_t * vam)
8962{
8963 unformat_input_t *i = vam->input;
8964 vl_api_create_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008965 u32 sw_if_index;
8966 u8 sw_if_index_set = 0;
8967 u32 sub_id;
8968 u8 sub_id_set = 0;
Jakub Grajciar053204a2019-03-18 13:17:53 +01008969 u32 __attribute__ ((unused)) no_tags = 0;
8970 u32 __attribute__ ((unused)) one_tag = 0;
8971 u32 __attribute__ ((unused)) two_tags = 0;
8972 u32 __attribute__ ((unused)) dot1ad = 0;
8973 u32 __attribute__ ((unused)) exact_match = 0;
8974 u32 __attribute__ ((unused)) default_sub = 0;
8975 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
8976 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008977 u32 tmp;
8978 u16 outer_vlan_id = 0;
8979 u16 inner_vlan_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008980 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008981
8982 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8983 {
8984 if (unformat (i, "sw_if_index %d", &sw_if_index))
8985 sw_if_index_set = 1;
8986 else
8987 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8988 sw_if_index_set = 1;
8989 else if (unformat (i, "sub_id %d", &sub_id))
8990 sub_id_set = 1;
8991 else if (unformat (i, "outer_vlan_id %d", &tmp))
8992 outer_vlan_id = tmp;
8993 else if (unformat (i, "inner_vlan_id %d", &tmp))
8994 inner_vlan_id = tmp;
8995
8996#define _(a) else if (unformat (i, #a)) a = 1 ;
8997 foreach_create_subif_bit
8998#undef _
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
9012 if (sub_id_set == 0)
9013 {
9014 errmsg ("missing sub_id");
9015 return -99;
9016 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009017 M (CREATE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009018
9019 mp->sw_if_index = ntohl (sw_if_index);
9020 mp->sub_id = ntohl (sub_id);
9021
Jakub Grajciar053204a2019-03-18 13:17:53 +01009022#define _(a,b) mp->sub_if_flags |= (1 << a);
9023 foreach_create_subif_flag;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009024#undef _
9025
9026 mp->outer_vlan_id = ntohs (outer_vlan_id);
9027 mp->inner_vlan_id = ntohs (inner_vlan_id);
9028
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009029 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009030 W (ret);
9031 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009032}
9033
9034static int
Neale Ranns9db6ada2019-11-08 12:42:31 +00009035api_ip_table_replace_begin (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009036{
9037 unformat_input_t *i = vam->input;
Neale Ranns9db6ada2019-11-08 12:42:31 +00009038 vl_api_ip_table_replace_begin_t *mp;
9039 u32 table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009040 u8 is_ipv6 = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009041
Jon Loeliger56c7b012017-02-01 12:31:41 -06009042 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009043 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9044 {
Neale Ranns9db6ada2019-11-08 12:42:31 +00009045 if (unformat (i, "table %d", &table_id))
9046 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009047 else if (unformat (i, "ipv6"))
9048 is_ipv6 = 1;
9049 else
9050 {
9051 clib_warning ("parse error '%U'", format_unformat_error, i);
9052 return -99;
9053 }
9054 }
9055
Neale Ranns9db6ada2019-11-08 12:42:31 +00009056 M (IP_TABLE_REPLACE_BEGIN, mp);
9057
9058 mp->table.table_id = ntohl (table_id);
9059 mp->table.is_ip6 = is_ipv6;
9060
9061 S (mp);
9062 W (ret);
9063 return ret;
9064}
9065
9066static int
9067api_ip_table_flush (vat_main_t * vam)
9068{
9069 unformat_input_t *i = vam->input;
9070 vl_api_ip_table_flush_t *mp;
9071 u32 table_id = 0;
9072 u8 is_ipv6 = 0;
9073
9074 int ret;
9075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009076 {
Neale Ranns9db6ada2019-11-08 12:42:31 +00009077 if (unformat (i, "table %d", &table_id))
9078 ;
9079 else if (unformat (i, "ipv6"))
9080 is_ipv6 = 1;
9081 else
9082 {
9083 clib_warning ("parse error '%U'", format_unformat_error, i);
9084 return -99;
9085 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01009086 }
9087
Neale Ranns9db6ada2019-11-08 12:42:31 +00009088 M (IP_TABLE_FLUSH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009089
Neale Ranns9db6ada2019-11-08 12:42:31 +00009090 mp->table.table_id = ntohl (table_id);
9091 mp->table.is_ip6 = is_ipv6;
9092
9093 S (mp);
9094 W (ret);
9095 return ret;
9096}
9097
9098static int
9099api_ip_table_replace_end (vat_main_t * vam)
9100{
9101 unformat_input_t *i = vam->input;
9102 vl_api_ip_table_replace_end_t *mp;
9103 u32 table_id = 0;
9104 u8 is_ipv6 = 0;
9105
9106 int ret;
9107 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9108 {
9109 if (unformat (i, "table %d", &table_id))
9110 ;
9111 else if (unformat (i, "ipv6"))
9112 is_ipv6 = 1;
9113 else
9114 {
9115 clib_warning ("parse error '%U'", format_unformat_error, i);
9116 return -99;
9117 }
9118 }
9119
9120 M (IP_TABLE_REPLACE_END, mp);
9121
9122 mp->table.table_id = ntohl (table_id);
9123 mp->table.is_ip6 = is_ipv6;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009124
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009125 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009126 W (ret);
9127 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009128}
9129
9130static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009131api_set_ip_flow_hash (vat_main_t * vam)
9132{
9133 unformat_input_t *i = vam->input;
9134 vl_api_set_ip_flow_hash_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009135 u32 vrf_id = 0;
9136 u8 is_ipv6 = 0;
9137 u8 vrf_id_set = 0;
9138 u8 src = 0;
9139 u8 dst = 0;
9140 u8 sport = 0;
9141 u8 dport = 0;
9142 u8 proto = 0;
9143 u8 reverse = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009144 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009145
9146 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9147 {
9148 if (unformat (i, "vrf %d", &vrf_id))
9149 vrf_id_set = 1;
9150 else if (unformat (i, "ipv6"))
9151 is_ipv6 = 1;
9152 else if (unformat (i, "src"))
9153 src = 1;
9154 else if (unformat (i, "dst"))
9155 dst = 1;
9156 else if (unformat (i, "sport"))
9157 sport = 1;
9158 else if (unformat (i, "dport"))
9159 dport = 1;
9160 else if (unformat (i, "proto"))
9161 proto = 1;
9162 else if (unformat (i, "reverse"))
9163 reverse = 1;
9164
9165 else
9166 {
9167 clib_warning ("parse error '%U'", format_unformat_error, i);
9168 return -99;
9169 }
9170 }
9171
9172 if (vrf_id_set == 0)
9173 {
9174 errmsg ("missing vrf id");
9175 return -99;
9176 }
9177
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009178 M (SET_IP_FLOW_HASH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009179 mp->src = src;
9180 mp->dst = dst;
9181 mp->sport = sport;
9182 mp->dport = dport;
9183 mp->proto = proto;
9184 mp->reverse = reverse;
9185 mp->vrf_id = ntohl (vrf_id);
9186 mp->is_ipv6 = is_ipv6;
9187
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009188 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009189 W (ret);
9190 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009191}
9192
9193static int
9194api_sw_interface_ip6_enable_disable (vat_main_t * vam)
9195{
9196 unformat_input_t *i = vam->input;
9197 vl_api_sw_interface_ip6_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009198 u32 sw_if_index;
9199 u8 sw_if_index_set = 0;
9200 u8 enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009201 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009202
9203 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9204 {
9205 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9206 sw_if_index_set = 1;
9207 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9208 sw_if_index_set = 1;
9209 else if (unformat (i, "enable"))
9210 enable = 1;
9211 else if (unformat (i, "disable"))
9212 enable = 0;
9213 else
9214 {
9215 clib_warning ("parse error '%U'", format_unformat_error, i);
9216 return -99;
9217 }
9218 }
9219
9220 if (sw_if_index_set == 0)
9221 {
9222 errmsg ("missing interface name or sw_if_index");
9223 return -99;
9224 }
9225
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009226 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009227
9228 mp->sw_if_index = ntohl (sw_if_index);
9229 mp->enable = enable;
9230
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009231 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009232 W (ret);
9233 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009234}
9235
Damjan Marion7cd468a2016-12-19 23:05:39 +01009236
9237static int
9238api_l2_patch_add_del (vat_main_t * vam)
9239{
9240 unformat_input_t *i = vam->input;
9241 vl_api_l2_patch_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009242 u32 rx_sw_if_index;
9243 u8 rx_sw_if_index_set = 0;
9244 u32 tx_sw_if_index;
9245 u8 tx_sw_if_index_set = 0;
9246 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009247 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009248
9249 /* Parse args required to build the message */
9250 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9251 {
9252 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
9253 rx_sw_if_index_set = 1;
9254 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
9255 tx_sw_if_index_set = 1;
9256 else if (unformat (i, "rx"))
9257 {
9258 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9259 {
9260 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
9261 &rx_sw_if_index))
9262 rx_sw_if_index_set = 1;
9263 }
9264 else
9265 break;
9266 }
9267 else if (unformat (i, "tx"))
9268 {
9269 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9270 {
9271 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
9272 &tx_sw_if_index))
9273 tx_sw_if_index_set = 1;
9274 }
9275 else
9276 break;
9277 }
9278 else if (unformat (i, "del"))
9279 is_add = 0;
9280 else
9281 break;
9282 }
9283
9284 if (rx_sw_if_index_set == 0)
9285 {
9286 errmsg ("missing rx interface name or rx_sw_if_index");
9287 return -99;
9288 }
9289
9290 if (tx_sw_if_index_set == 0)
9291 {
9292 errmsg ("missing tx interface name or tx_sw_if_index");
9293 return -99;
9294 }
9295
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009296 M (L2_PATCH_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009297
9298 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
9299 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
9300 mp->is_add = is_add;
9301
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009302 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009303 W (ret);
9304 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009305}
9306
Pablo Camarillofb380952016-12-07 18:34:18 +01009307u8 is_del;
9308u8 localsid_addr[16];
9309u8 end_psp;
9310u8 behavior;
9311u32 sw_if_index;
9312u32 vlan_index;
9313u32 fib_table;
9314u8 nh_addr[16];
9315
9316static int
9317api_sr_localsid_add_del (vat_main_t * vam)
9318{
9319 unformat_input_t *i = vam->input;
9320 vl_api_sr_localsid_add_del_t *mp;
9321
9322 u8 is_del;
9323 ip6_address_t localsid;
9324 u8 end_psp = 0;
9325 u8 behavior = ~0;
9326 u32 sw_if_index;
9327 u32 fib_table = ~(u32) 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009328 ip46_address_t nh_addr;
9329 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
Pablo Camarillofb380952016-12-07 18:34:18 +01009330
9331 bool nexthop_set = 0;
9332
9333 int ret;
9334
9335 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9336 {
9337 if (unformat (i, "del"))
9338 is_del = 1;
9339 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009340 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
Pablo Camarillofb380952016-12-07 18:34:18 +01009341 nexthop_set = 1;
9342 else if (unformat (i, "behavior %u", &behavior));
9343 else if (unformat (i, "sw_if_index %u", &sw_if_index));
9344 else if (unformat (i, "fib-table %u", &fib_table));
9345 else if (unformat (i, "end.psp %u", &behavior));
9346 else
9347 break;
9348 }
9349
9350 M (SR_LOCALSID_ADD_DEL, mp);
9351
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009352 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
Tetsuya Murakami1b81e6e2019-11-06 11:05:51 -08009353
Pablo Camarillofb380952016-12-07 18:34:18 +01009354 if (nexthop_set)
Pablo Camarillo3337bd22018-06-19 15:49:02 +02009355 {
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009356 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
Pablo Camarillo3337bd22018-06-19 15:49:02 +02009357 }
Pablo Camarillofb380952016-12-07 18:34:18 +01009358 mp->behavior = behavior;
9359 mp->sw_if_index = ntohl (sw_if_index);
9360 mp->fib_table = ntohl (fib_table);
9361 mp->end_psp = end_psp;
9362 mp->is_del = is_del;
9363
9364 S (mp);
9365 W (ret);
9366 return ret;
9367}
9368
Damjan Marion7cd468a2016-12-19 23:05:39 +01009369static int
9370api_ioam_enable (vat_main_t * vam)
9371{
9372 unformat_input_t *input = vam->input;
9373 vl_api_ioam_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009374 u32 id = 0;
9375 int has_trace_option = 0;
9376 int has_pot_option = 0;
9377 int has_seqno_option = 0;
9378 int has_analyse_option = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009379 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009380
9381 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9382 {
9383 if (unformat (input, "trace"))
9384 has_trace_option = 1;
9385 else if (unformat (input, "pot"))
9386 has_pot_option = 1;
9387 else if (unformat (input, "seqno"))
9388 has_seqno_option = 1;
9389 else if (unformat (input, "analyse"))
9390 has_analyse_option = 1;
9391 else
9392 break;
9393 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009394 M (IOAM_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009395 mp->id = htons (id);
9396 mp->seqno = has_seqno_option;
9397 mp->analyse = has_analyse_option;
9398 mp->pot_enable = has_pot_option;
9399 mp->trace_enable = has_trace_option;
9400
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009401 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009402 W (ret);
9403 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009404}
9405
9406
9407static int
9408api_ioam_disable (vat_main_t * vam)
9409{
9410 vl_api_ioam_disable_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009411 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009412
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009413 M (IOAM_DISABLE, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009414 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009415 W (ret);
9416 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009417}
9418
Damjan Marion7cd468a2016-12-19 23:05:39 +01009419#define foreach_tcp_proto_field \
9420_(src_port) \
9421_(dst_port)
9422
9423#define foreach_udp_proto_field \
9424_(src_port) \
9425_(dst_port)
9426
9427#define foreach_ip4_proto_field \
9428_(src_address) \
9429_(dst_address) \
9430_(tos) \
9431_(length) \
9432_(fragment_id) \
9433_(ttl) \
9434_(protocol) \
9435_(checksum)
9436
Dave Barach4a3f69c2017-02-22 12:44:56 -05009437typedef struct
9438{
9439 u16 src_port, dst_port;
9440} tcpudp_header_t;
9441
9442#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +01009443uword
9444unformat_tcp_mask (unformat_input_t * input, va_list * args)
9445{
9446 u8 **maskp = va_arg (*args, u8 **);
9447 u8 *mask = 0;
9448 u8 found_something = 0;
9449 tcp_header_t *tcp;
9450
9451#define _(a) u8 a=0;
9452 foreach_tcp_proto_field;
9453#undef _
9454
9455 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9456 {
9457 if (0);
9458#define _(a) else if (unformat (input, #a)) a=1;
9459 foreach_tcp_proto_field
9460#undef _
9461 else
9462 break;
9463 }
9464
9465#define _(a) found_something += a;
9466 foreach_tcp_proto_field;
9467#undef _
9468
9469 if (found_something == 0)
9470 return 0;
9471
9472 vec_validate (mask, sizeof (*tcp) - 1);
9473
9474 tcp = (tcp_header_t *) mask;
9475
Dave Barachb7b92992018-10-17 10:38:51 -04009476#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009477 foreach_tcp_proto_field;
9478#undef _
9479
9480 *maskp = mask;
9481 return 1;
9482}
9483
9484uword
9485unformat_udp_mask (unformat_input_t * input, va_list * args)
9486{
9487 u8 **maskp = va_arg (*args, u8 **);
9488 u8 *mask = 0;
9489 u8 found_something = 0;
9490 udp_header_t *udp;
9491
9492#define _(a) u8 a=0;
9493 foreach_udp_proto_field;
9494#undef _
9495
9496 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9497 {
9498 if (0);
9499#define _(a) else if (unformat (input, #a)) a=1;
9500 foreach_udp_proto_field
9501#undef _
9502 else
9503 break;
9504 }
9505
9506#define _(a) found_something += a;
9507 foreach_udp_proto_field;
9508#undef _
9509
9510 if (found_something == 0)
9511 return 0;
9512
9513 vec_validate (mask, sizeof (*udp) - 1);
9514
9515 udp = (udp_header_t *) mask;
9516
Dave Barachb7b92992018-10-17 10:38:51 -04009517#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009518 foreach_udp_proto_field;
9519#undef _
9520
9521 *maskp = mask;
9522 return 1;
9523}
9524
Damjan Marion7cd468a2016-12-19 23:05:39 +01009525uword
9526unformat_l4_mask (unformat_input_t * input, va_list * args)
9527{
9528 u8 **maskp = va_arg (*args, u8 **);
9529 u16 src_port = 0, dst_port = 0;
9530 tcpudp_header_t *tcpudp;
9531
9532 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9533 {
9534 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
9535 return 1;
9536 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
9537 return 1;
9538 else if (unformat (input, "src_port"))
9539 src_port = 0xFFFF;
9540 else if (unformat (input, "dst_port"))
9541 dst_port = 0xFFFF;
9542 else
9543 return 0;
9544 }
9545
9546 if (!src_port && !dst_port)
9547 return 0;
9548
9549 u8 *mask = 0;
9550 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
9551
9552 tcpudp = (tcpudp_header_t *) mask;
9553 tcpudp->src_port = src_port;
9554 tcpudp->dst_port = dst_port;
9555
9556 *maskp = mask;
9557
9558 return 1;
9559}
9560
9561uword
9562unformat_ip4_mask (unformat_input_t * input, va_list * args)
9563{
9564 u8 **maskp = va_arg (*args, u8 **);
9565 u8 *mask = 0;
9566 u8 found_something = 0;
9567 ip4_header_t *ip;
9568
9569#define _(a) u8 a=0;
9570 foreach_ip4_proto_field;
9571#undef _
9572 u8 version = 0;
9573 u8 hdr_length = 0;
9574
9575
9576 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9577 {
9578 if (unformat (input, "version"))
9579 version = 1;
9580 else if (unformat (input, "hdr_length"))
9581 hdr_length = 1;
9582 else if (unformat (input, "src"))
9583 src_address = 1;
9584 else if (unformat (input, "dst"))
9585 dst_address = 1;
9586 else if (unformat (input, "proto"))
9587 protocol = 1;
9588
9589#define _(a) else if (unformat (input, #a)) a=1;
9590 foreach_ip4_proto_field
9591#undef _
9592 else
9593 break;
9594 }
9595
9596#define _(a) found_something += a;
9597 foreach_ip4_proto_field;
9598#undef _
9599
9600 if (found_something == 0)
9601 return 0;
9602
9603 vec_validate (mask, sizeof (*ip) - 1);
9604
9605 ip = (ip4_header_t *) mask;
9606
Dave Barachb7b92992018-10-17 10:38:51 -04009607#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009608 foreach_ip4_proto_field;
9609#undef _
9610
9611 ip->ip_version_and_header_length = 0;
9612
9613 if (version)
9614 ip->ip_version_and_header_length |= 0xF0;
9615
9616 if (hdr_length)
9617 ip->ip_version_and_header_length |= 0x0F;
9618
9619 *maskp = mask;
9620 return 1;
9621}
9622
9623#define foreach_ip6_proto_field \
9624_(src_address) \
9625_(dst_address) \
9626_(payload_length) \
9627_(hop_limit) \
9628_(protocol)
9629
9630uword
9631unformat_ip6_mask (unformat_input_t * input, va_list * args)
9632{
9633 u8 **maskp = va_arg (*args, u8 **);
9634 u8 *mask = 0;
9635 u8 found_something = 0;
9636 ip6_header_t *ip;
9637 u32 ip_version_traffic_class_and_flow_label;
9638
9639#define _(a) u8 a=0;
9640 foreach_ip6_proto_field;
9641#undef _
9642 u8 version = 0;
9643 u8 traffic_class = 0;
9644 u8 flow_label = 0;
9645
9646 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9647 {
9648 if (unformat (input, "version"))
9649 version = 1;
9650 else if (unformat (input, "traffic-class"))
9651 traffic_class = 1;
9652 else if (unformat (input, "flow-label"))
9653 flow_label = 1;
9654 else if (unformat (input, "src"))
9655 src_address = 1;
9656 else if (unformat (input, "dst"))
9657 dst_address = 1;
9658 else if (unformat (input, "proto"))
9659 protocol = 1;
9660
9661#define _(a) else if (unformat (input, #a)) a=1;
9662 foreach_ip6_proto_field
9663#undef _
9664 else
9665 break;
9666 }
9667
9668#define _(a) found_something += a;
9669 foreach_ip6_proto_field;
9670#undef _
9671
9672 if (found_something == 0)
9673 return 0;
9674
9675 vec_validate (mask, sizeof (*ip) - 1);
9676
9677 ip = (ip6_header_t *) mask;
9678
Dave Barachb7b92992018-10-17 10:38:51 -04009679#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009680 foreach_ip6_proto_field;
9681#undef _
9682
9683 ip_version_traffic_class_and_flow_label = 0;
9684
9685 if (version)
9686 ip_version_traffic_class_and_flow_label |= 0xF0000000;
9687
9688 if (traffic_class)
9689 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
9690
9691 if (flow_label)
9692 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
9693
9694 ip->ip_version_traffic_class_and_flow_label =
9695 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
9696
9697 *maskp = mask;
9698 return 1;
9699}
9700
9701uword
9702unformat_l3_mask (unformat_input_t * input, va_list * args)
9703{
9704 u8 **maskp = va_arg (*args, u8 **);
9705
9706 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9707 {
9708 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
9709 return 1;
9710 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
9711 return 1;
9712 else
9713 break;
9714 }
9715 return 0;
9716}
9717
9718uword
9719unformat_l2_mask (unformat_input_t * input, va_list * args)
9720{
9721 u8 **maskp = va_arg (*args, u8 **);
9722 u8 *mask = 0;
9723 u8 src = 0;
9724 u8 dst = 0;
9725 u8 proto = 0;
9726 u8 tag1 = 0;
9727 u8 tag2 = 0;
9728 u8 ignore_tag1 = 0;
9729 u8 ignore_tag2 = 0;
9730 u8 cos1 = 0;
9731 u8 cos2 = 0;
9732 u8 dot1q = 0;
9733 u8 dot1ad = 0;
9734 int len = 14;
9735
9736 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9737 {
9738 if (unformat (input, "src"))
9739 src = 1;
9740 else if (unformat (input, "dst"))
9741 dst = 1;
9742 else if (unformat (input, "proto"))
9743 proto = 1;
9744 else if (unformat (input, "tag1"))
9745 tag1 = 1;
9746 else if (unformat (input, "tag2"))
9747 tag2 = 1;
9748 else if (unformat (input, "ignore-tag1"))
9749 ignore_tag1 = 1;
9750 else if (unformat (input, "ignore-tag2"))
9751 ignore_tag2 = 1;
9752 else if (unformat (input, "cos1"))
9753 cos1 = 1;
9754 else if (unformat (input, "cos2"))
9755 cos2 = 1;
9756 else if (unformat (input, "dot1q"))
9757 dot1q = 1;
9758 else if (unformat (input, "dot1ad"))
9759 dot1ad = 1;
9760 else
9761 break;
9762 }
9763 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
9764 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
9765 return 0;
9766
9767 if (tag1 || ignore_tag1 || cos1 || dot1q)
9768 len = 18;
9769 if (tag2 || ignore_tag2 || cos2 || dot1ad)
9770 len = 22;
9771
9772 vec_validate (mask, len - 1);
9773
9774 if (dst)
Dave Barachb7b92992018-10-17 10:38:51 -04009775 clib_memset (mask, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009776
9777 if (src)
Dave Barachb7b92992018-10-17 10:38:51 -04009778 clib_memset (mask + 6, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009779
9780 if (tag2 || dot1ad)
9781 {
9782 /* inner vlan tag */
9783 if (tag2)
9784 {
9785 mask[19] = 0xff;
9786 mask[18] = 0x0f;
9787 }
9788 if (cos2)
9789 mask[18] |= 0xe0;
9790 if (proto)
9791 mask[21] = mask[20] = 0xff;
9792 if (tag1)
9793 {
9794 mask[15] = 0xff;
9795 mask[14] = 0x0f;
9796 }
9797 if (cos1)
9798 mask[14] |= 0xe0;
9799 *maskp = mask;
9800 return 1;
9801 }
9802 if (tag1 | dot1q)
9803 {
9804 if (tag1)
9805 {
9806 mask[15] = 0xff;
9807 mask[14] = 0x0f;
9808 }
9809 if (cos1)
9810 mask[14] |= 0xe0;
9811 if (proto)
9812 mask[16] = mask[17] = 0xff;
9813
9814 *maskp = mask;
9815 return 1;
9816 }
9817 if (cos2)
9818 mask[18] |= 0xe0;
9819 if (cos1)
9820 mask[14] |= 0xe0;
9821 if (proto)
9822 mask[12] = mask[13] = 0xff;
9823
9824 *maskp = mask;
9825 return 1;
9826}
9827
9828uword
9829unformat_classify_mask (unformat_input_t * input, va_list * args)
9830{
9831 u8 **maskp = va_arg (*args, u8 **);
9832 u32 *skipp = va_arg (*args, u32 *);
9833 u32 *matchp = va_arg (*args, u32 *);
9834 u32 match;
9835 u8 *mask = 0;
9836 u8 *l2 = 0;
9837 u8 *l3 = 0;
9838 u8 *l4 = 0;
9839 int i;
9840
9841 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9842 {
9843 if (unformat (input, "hex %U", unformat_hex_string, &mask))
9844 ;
9845 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
9846 ;
9847 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
9848 ;
9849 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
9850 ;
9851 else
9852 break;
9853 }
9854
9855 if (l4 && !l3)
9856 {
9857 vec_free (mask);
9858 vec_free (l2);
9859 vec_free (l4);
9860 return 0;
9861 }
9862
9863 if (mask || l2 || l3 || l4)
9864 {
9865 if (l2 || l3 || l4)
9866 {
9867 /* "With a free Ethernet header in every package" */
9868 if (l2 == 0)
9869 vec_validate (l2, 13);
9870 mask = l2;
9871 if (vec_len (l3))
9872 {
9873 vec_append (mask, l3);
9874 vec_free (l3);
9875 }
9876 if (vec_len (l4))
9877 {
9878 vec_append (mask, l4);
9879 vec_free (l4);
9880 }
9881 }
9882
9883 /* Scan forward looking for the first significant mask octet */
9884 for (i = 0; i < vec_len (mask); i++)
9885 if (mask[i])
9886 break;
9887
9888 /* compute (skip, match) params */
9889 *skipp = i / sizeof (u32x4);
9890 vec_delete (mask, *skipp * sizeof (u32x4), 0);
9891
9892 /* Pad mask to an even multiple of the vector size */
9893 while (vec_len (mask) % sizeof (u32x4))
9894 vec_add1 (mask, 0);
9895
9896 match = vec_len (mask) / sizeof (u32x4);
9897
9898 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
9899 {
9900 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
9901 if (*tmp || *(tmp + 1))
9902 break;
9903 match--;
9904 }
9905 if (match == 0)
9906 clib_warning ("BUG: match 0");
9907
9908 _vec_len (mask) = match * sizeof (u32x4);
9909
9910 *matchp = match;
9911 *maskp = mask;
9912
9913 return 1;
9914 }
9915
9916 return 0;
9917}
Dave Barach4a3f69c2017-02-22 12:44:56 -05009918#endif /* VPP_API_TEST_BUILTIN */
Damjan Marion7cd468a2016-12-19 23:05:39 +01009919
9920#define foreach_l2_next \
9921_(drop, DROP) \
9922_(ethernet, ETHERNET_INPUT) \
9923_(ip4, IP4_INPUT) \
9924_(ip6, IP6_INPUT)
9925
9926uword
9927unformat_l2_next_index (unformat_input_t * input, va_list * args)
9928{
9929 u32 *miss_next_indexp = va_arg (*args, u32 *);
9930 u32 next_index = 0;
9931 u32 tmp;
9932
9933#define _(n,N) \
9934 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
9935 foreach_l2_next;
9936#undef _
9937
9938 if (unformat (input, "%d", &tmp))
9939 {
9940 next_index = tmp;
9941 goto out;
9942 }
9943
9944 return 0;
9945
9946out:
9947 *miss_next_indexp = next_index;
9948 return 1;
9949}
9950
9951#define foreach_ip_next \
9952_(drop, DROP) \
9953_(local, LOCAL) \
9954_(rewrite, REWRITE)
9955
9956uword
Dave Barach4a3f69c2017-02-22 12:44:56 -05009957api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009958{
9959 u32 *miss_next_indexp = va_arg (*args, u32 *);
9960 u32 next_index = 0;
9961 u32 tmp;
9962
9963#define _(n,N) \
9964 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
9965 foreach_ip_next;
9966#undef _
9967
9968 if (unformat (input, "%d", &tmp))
9969 {
9970 next_index = tmp;
9971 goto out;
9972 }
9973
9974 return 0;
9975
9976out:
9977 *miss_next_indexp = next_index;
9978 return 1;
9979}
9980
9981#define foreach_acl_next \
9982_(deny, DENY)
9983
9984uword
Dave Barach4a3f69c2017-02-22 12:44:56 -05009985api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009986{
9987 u32 *miss_next_indexp = va_arg (*args, u32 *);
9988 u32 next_index = 0;
9989 u32 tmp;
9990
9991#define _(n,N) \
9992 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
9993 foreach_acl_next;
9994#undef _
9995
9996 if (unformat (input, "permit"))
9997 {
9998 next_index = ~0;
9999 goto out;
10000 }
10001 else if (unformat (input, "%d", &tmp))
10002 {
10003 next_index = tmp;
10004 goto out;
10005 }
10006
10007 return 0;
10008
10009out:
10010 *miss_next_indexp = next_index;
10011 return 1;
10012}
10013
10014uword
10015unformat_policer_precolor (unformat_input_t * input, va_list * args)
10016{
10017 u32 *r = va_arg (*args, u32 *);
10018
10019 if (unformat (input, "conform-color"))
10020 *r = POLICE_CONFORM;
10021 else if (unformat (input, "exceed-color"))
10022 *r = POLICE_EXCEED;
10023 else
10024 return 0;
10025
10026 return 1;
10027}
10028
10029static int
10030api_classify_add_del_table (vat_main_t * vam)
10031{
10032 unformat_input_t *i = vam->input;
10033 vl_api_classify_add_del_table_t *mp;
10034
10035 u32 nbuckets = 2;
10036 u32 skip = ~0;
10037 u32 match = ~0;
10038 int is_add = 1;
10039 int del_chain = 0;
10040 u32 table_index = ~0;
10041 u32 next_table_index = ~0;
10042 u32 miss_next_index = ~0;
10043 u32 memory_size = 32 << 20;
10044 u8 *mask = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010045 u32 current_data_flag = 0;
10046 int current_data_offset = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010047 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010048
10049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10050 {
10051 if (unformat (i, "del"))
10052 is_add = 0;
10053 else if (unformat (i, "del-chain"))
10054 {
10055 is_add = 0;
10056 del_chain = 1;
10057 }
10058 else if (unformat (i, "buckets %d", &nbuckets))
10059 ;
10060 else if (unformat (i, "memory_size %d", &memory_size))
10061 ;
10062 else if (unformat (i, "skip %d", &skip))
10063 ;
10064 else if (unformat (i, "match %d", &match))
10065 ;
10066 else if (unformat (i, "table %d", &table_index))
10067 ;
10068 else if (unformat (i, "mask %U", unformat_classify_mask,
10069 &mask, &skip, &match))
10070 ;
10071 else if (unformat (i, "next-table %d", &next_table_index))
10072 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010073 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010074 &miss_next_index))
10075 ;
10076 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
10077 &miss_next_index))
10078 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010079 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010080 &miss_next_index))
10081 ;
10082 else if (unformat (i, "current-data-flag %d", &current_data_flag))
10083 ;
10084 else if (unformat (i, "current-data-offset %d", &current_data_offset))
10085 ;
10086 else
10087 break;
10088 }
10089
10090 if (is_add && mask == 0)
10091 {
10092 errmsg ("Mask required");
10093 return -99;
10094 }
10095
10096 if (is_add && skip == ~0)
10097 {
10098 errmsg ("skip count required");
10099 return -99;
10100 }
10101
10102 if (is_add && match == ~0)
10103 {
10104 errmsg ("match count required");
10105 return -99;
10106 }
10107
10108 if (!is_add && table_index == ~0)
10109 {
10110 errmsg ("table index required for delete");
10111 return -99;
10112 }
10113
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010114 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010115
10116 mp->is_add = is_add;
10117 mp->del_chain = del_chain;
10118 mp->table_index = ntohl (table_index);
10119 mp->nbuckets = ntohl (nbuckets);
10120 mp->memory_size = ntohl (memory_size);
10121 mp->skip_n_vectors = ntohl (skip);
10122 mp->match_n_vectors = ntohl (match);
10123 mp->next_table_index = ntohl (next_table_index);
10124 mp->miss_next_index = ntohl (miss_next_index);
10125 mp->current_data_flag = ntohl (current_data_flag);
10126 mp->current_data_offset = ntohl (current_data_offset);
Juraj Sloboda75282452018-06-12 14:20:49 +020010127 mp->mask_len = ntohl (vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010128 clib_memcpy (mp->mask, mask, vec_len (mask));
10129
10130 vec_free (mask);
10131
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010132 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010133 W (ret);
10134 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010135}
10136
Dave Barach4a3f69c2017-02-22 12:44:56 -050010137#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010010138uword
10139unformat_l4_match (unformat_input_t * input, va_list * args)
10140{
10141 u8 **matchp = va_arg (*args, u8 **);
10142
10143 u8 *proto_header = 0;
10144 int src_port = 0;
10145 int dst_port = 0;
10146
10147 tcpudp_header_t h;
10148
10149 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10150 {
10151 if (unformat (input, "src_port %d", &src_port))
10152 ;
10153 else if (unformat (input, "dst_port %d", &dst_port))
10154 ;
10155 else
10156 return 0;
10157 }
10158
10159 h.src_port = clib_host_to_net_u16 (src_port);
10160 h.dst_port = clib_host_to_net_u16 (dst_port);
10161 vec_validate (proto_header, sizeof (h) - 1);
10162 memcpy (proto_header, &h, sizeof (h));
10163
10164 *matchp = proto_header;
10165
10166 return 1;
10167}
10168
10169uword
10170unformat_ip4_match (unformat_input_t * input, va_list * args)
10171{
10172 u8 **matchp = va_arg (*args, u8 **);
10173 u8 *match = 0;
10174 ip4_header_t *ip;
10175 int version = 0;
10176 u32 version_val;
10177 int hdr_length = 0;
10178 u32 hdr_length_val;
10179 int src = 0, dst = 0;
10180 ip4_address_t src_val, dst_val;
10181 int proto = 0;
10182 u32 proto_val;
10183 int tos = 0;
10184 u32 tos_val;
10185 int length = 0;
10186 u32 length_val;
10187 int fragment_id = 0;
10188 u32 fragment_id_val;
10189 int ttl = 0;
10190 int ttl_val;
10191 int checksum = 0;
10192 u32 checksum_val;
10193
10194 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10195 {
10196 if (unformat (input, "version %d", &version_val))
10197 version = 1;
10198 else if (unformat (input, "hdr_length %d", &hdr_length_val))
10199 hdr_length = 1;
10200 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
10201 src = 1;
10202 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
10203 dst = 1;
10204 else if (unformat (input, "proto %d", &proto_val))
10205 proto = 1;
10206 else if (unformat (input, "tos %d", &tos_val))
10207 tos = 1;
10208 else if (unformat (input, "length %d", &length_val))
10209 length = 1;
10210 else if (unformat (input, "fragment_id %d", &fragment_id_val))
10211 fragment_id = 1;
10212 else if (unformat (input, "ttl %d", &ttl_val))
10213 ttl = 1;
10214 else if (unformat (input, "checksum %d", &checksum_val))
10215 checksum = 1;
10216 else
10217 break;
10218 }
10219
10220 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
10221 + ttl + checksum == 0)
10222 return 0;
10223
10224 /*
10225 * Aligned because we use the real comparison functions
10226 */
10227 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
10228
10229 ip = (ip4_header_t *) match;
10230
10231 /* These are realistically matched in practice */
10232 if (src)
10233 ip->src_address.as_u32 = src_val.as_u32;
10234
10235 if (dst)
10236 ip->dst_address.as_u32 = dst_val.as_u32;
10237
10238 if (proto)
10239 ip->protocol = proto_val;
10240
10241
10242 /* These are not, but they're included for completeness */
10243 if (version)
10244 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
10245
10246 if (hdr_length)
10247 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
10248
10249 if (tos)
10250 ip->tos = tos_val;
10251
10252 if (length)
10253 ip->length = clib_host_to_net_u16 (length_val);
10254
10255 if (ttl)
10256 ip->ttl = ttl_val;
10257
10258 if (checksum)
10259 ip->checksum = clib_host_to_net_u16 (checksum_val);
10260
10261 *matchp = match;
10262 return 1;
10263}
10264
10265uword
10266unformat_ip6_match (unformat_input_t * input, va_list * args)
10267{
10268 u8 **matchp = va_arg (*args, u8 **);
10269 u8 *match = 0;
10270 ip6_header_t *ip;
10271 int version = 0;
10272 u32 version_val;
10273 u8 traffic_class = 0;
10274 u32 traffic_class_val = 0;
10275 u8 flow_label = 0;
10276 u8 flow_label_val;
10277 int src = 0, dst = 0;
10278 ip6_address_t src_val, dst_val;
10279 int proto = 0;
10280 u32 proto_val;
10281 int payload_length = 0;
10282 u32 payload_length_val;
10283 int hop_limit = 0;
10284 int hop_limit_val;
10285 u32 ip_version_traffic_class_and_flow_label;
10286
10287 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10288 {
10289 if (unformat (input, "version %d", &version_val))
10290 version = 1;
10291 else if (unformat (input, "traffic_class %d", &traffic_class_val))
10292 traffic_class = 1;
10293 else if (unformat (input, "flow_label %d", &flow_label_val))
10294 flow_label = 1;
10295 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
10296 src = 1;
10297 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
10298 dst = 1;
10299 else if (unformat (input, "proto %d", &proto_val))
10300 proto = 1;
10301 else if (unformat (input, "payload_length %d", &payload_length_val))
10302 payload_length = 1;
10303 else if (unformat (input, "hop_limit %d", &hop_limit_val))
10304 hop_limit = 1;
10305 else
10306 break;
10307 }
10308
10309 if (version + traffic_class + flow_label + src + dst + proto +
10310 payload_length + hop_limit == 0)
10311 return 0;
10312
10313 /*
10314 * Aligned because we use the real comparison functions
10315 */
10316 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
10317
10318 ip = (ip6_header_t *) match;
10319
10320 if (src)
10321 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
10322
10323 if (dst)
10324 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
10325
10326 if (proto)
10327 ip->protocol = proto_val;
10328
10329 ip_version_traffic_class_and_flow_label = 0;
10330
10331 if (version)
10332 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
10333
10334 if (traffic_class)
10335 ip_version_traffic_class_and_flow_label |=
10336 (traffic_class_val & 0xFF) << 20;
10337
10338 if (flow_label)
10339 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
10340
10341 ip->ip_version_traffic_class_and_flow_label =
10342 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
10343
10344 if (payload_length)
10345 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
10346
10347 if (hop_limit)
10348 ip->hop_limit = hop_limit_val;
10349
10350 *matchp = match;
10351 return 1;
10352}
10353
10354uword
10355unformat_l3_match (unformat_input_t * input, va_list * args)
10356{
10357 u8 **matchp = va_arg (*args, u8 **);
10358
10359 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10360 {
10361 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
10362 return 1;
10363 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
10364 return 1;
10365 else
10366 break;
10367 }
10368 return 0;
10369}
10370
10371uword
10372unformat_vlan_tag (unformat_input_t * input, va_list * args)
10373{
10374 u8 *tagp = va_arg (*args, u8 *);
10375 u32 tag;
10376
10377 if (unformat (input, "%d", &tag))
10378 {
10379 tagp[0] = (tag >> 8) & 0x0F;
10380 tagp[1] = tag & 0xFF;
10381 return 1;
10382 }
10383
10384 return 0;
10385}
10386
10387uword
10388unformat_l2_match (unformat_input_t * input, va_list * args)
10389{
10390 u8 **matchp = va_arg (*args, u8 **);
10391 u8 *match = 0;
10392 u8 src = 0;
10393 u8 src_val[6];
10394 u8 dst = 0;
10395 u8 dst_val[6];
10396 u8 proto = 0;
10397 u16 proto_val;
10398 u8 tag1 = 0;
10399 u8 tag1_val[2];
10400 u8 tag2 = 0;
10401 u8 tag2_val[2];
10402 int len = 14;
10403 u8 ignore_tag1 = 0;
10404 u8 ignore_tag2 = 0;
10405 u8 cos1 = 0;
10406 u8 cos2 = 0;
10407 u32 cos1_val = 0;
10408 u32 cos2_val = 0;
10409
10410 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10411 {
10412 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
10413 src = 1;
10414 else
10415 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
10416 dst = 1;
10417 else if (unformat (input, "proto %U",
10418 unformat_ethernet_type_host_byte_order, &proto_val))
10419 proto = 1;
10420 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
10421 tag1 = 1;
10422 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
10423 tag2 = 1;
10424 else if (unformat (input, "ignore-tag1"))
10425 ignore_tag1 = 1;
10426 else if (unformat (input, "ignore-tag2"))
10427 ignore_tag2 = 1;
10428 else if (unformat (input, "cos1 %d", &cos1_val))
10429 cos1 = 1;
10430 else if (unformat (input, "cos2 %d", &cos2_val))
10431 cos2 = 1;
10432 else
10433 break;
10434 }
10435 if ((src + dst + proto + tag1 + tag2 +
10436 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
10437 return 0;
10438
10439 if (tag1 || ignore_tag1 || cos1)
10440 len = 18;
10441 if (tag2 || ignore_tag2 || cos2)
10442 len = 22;
10443
10444 vec_validate_aligned (match, len - 1, sizeof (u32x4));
10445
10446 if (dst)
10447 clib_memcpy (match, dst_val, 6);
10448
10449 if (src)
10450 clib_memcpy (match + 6, src_val, 6);
10451
10452 if (tag2)
10453 {
10454 /* inner vlan tag */
10455 match[19] = tag2_val[1];
10456 match[18] = tag2_val[0];
10457 if (cos2)
10458 match[18] |= (cos2_val & 0x7) << 5;
10459 if (proto)
10460 {
10461 match[21] = proto_val & 0xff;
10462 match[20] = proto_val >> 8;
10463 }
10464 if (tag1)
10465 {
10466 match[15] = tag1_val[1];
10467 match[14] = tag1_val[0];
10468 }
10469 if (cos1)
10470 match[14] |= (cos1_val & 0x7) << 5;
10471 *matchp = match;
10472 return 1;
10473 }
10474 if (tag1)
10475 {
10476 match[15] = tag1_val[1];
10477 match[14] = tag1_val[0];
10478 if (proto)
10479 {
10480 match[17] = proto_val & 0xff;
10481 match[16] = proto_val >> 8;
10482 }
10483 if (cos1)
10484 match[14] |= (cos1_val & 0x7) << 5;
10485
10486 *matchp = match;
10487 return 1;
10488 }
10489 if (cos2)
10490 match[18] |= (cos2_val & 0x7) << 5;
10491 if (cos1)
10492 match[14] |= (cos1_val & 0x7) << 5;
10493 if (proto)
10494 {
10495 match[13] = proto_val & 0xff;
10496 match[12] = proto_val >> 8;
10497 }
10498
10499 *matchp = match;
10500 return 1;
10501}
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070010502
10503uword
10504unformat_qos_source (unformat_input_t * input, va_list * args)
10505{
10506 int *qs = va_arg (*args, int *);
10507
10508 if (unformat (input, "ip"))
10509 *qs = QOS_SOURCE_IP;
10510 else if (unformat (input, "mpls"))
10511 *qs = QOS_SOURCE_MPLS;
10512 else if (unformat (input, "ext"))
10513 *qs = QOS_SOURCE_EXT;
10514 else if (unformat (input, "vlan"))
10515 *qs = QOS_SOURCE_VLAN;
10516 else
10517 return 0;
10518
10519 return 1;
10520}
Dave Barach4a3f69c2017-02-22 12:44:56 -050010521#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010010522
10523uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050010524api_unformat_classify_match (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010010525{
10526 u8 **matchp = va_arg (*args, u8 **);
10527 u32 skip_n_vectors = va_arg (*args, u32);
10528 u32 match_n_vectors = va_arg (*args, u32);
10529
10530 u8 *match = 0;
10531 u8 *l2 = 0;
10532 u8 *l3 = 0;
10533 u8 *l4 = 0;
10534
10535 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10536 {
10537 if (unformat (input, "hex %U", unformat_hex_string, &match))
10538 ;
10539 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
10540 ;
10541 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
10542 ;
10543 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
10544 ;
10545 else
10546 break;
10547 }
10548
10549 if (l4 && !l3)
10550 {
10551 vec_free (match);
10552 vec_free (l2);
10553 vec_free (l4);
10554 return 0;
10555 }
10556
10557 if (match || l2 || l3 || l4)
10558 {
10559 if (l2 || l3 || l4)
10560 {
10561 /* "Win a free Ethernet header in every packet" */
10562 if (l2 == 0)
10563 vec_validate_aligned (l2, 13, sizeof (u32x4));
10564 match = l2;
10565 if (vec_len (l3))
10566 {
10567 vec_append_aligned (match, l3, sizeof (u32x4));
10568 vec_free (l3);
10569 }
10570 if (vec_len (l4))
10571 {
10572 vec_append_aligned (match, l4, sizeof (u32x4));
10573 vec_free (l4);
10574 }
10575 }
10576
10577 /* Make sure the vector is big enough even if key is all 0's */
10578 vec_validate_aligned
10579 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
10580 sizeof (u32x4));
10581
10582 /* Set size, include skipped vectors */
10583 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
10584
10585 *matchp = match;
10586
10587 return 1;
10588 }
10589
10590 return 0;
10591}
10592
10593static int
10594api_classify_add_del_session (vat_main_t * vam)
10595{
10596 unformat_input_t *i = vam->input;
10597 vl_api_classify_add_del_session_t *mp;
10598 int is_add = 1;
10599 u32 table_index = ~0;
10600 u32 hit_next_index = ~0;
10601 u32 opaque_index = ~0;
10602 u8 *match = 0;
10603 i32 advance = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010604 u32 skip_n_vectors = 0;
10605 u32 match_n_vectors = 0;
10606 u32 action = 0;
10607 u32 metadata = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010608 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010609
10610 /*
10611 * Warning: you have to supply skip_n and match_n
10612 * because the API client cant simply look at the classify
10613 * table object.
10614 */
10615
10616 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10617 {
10618 if (unformat (i, "del"))
10619 is_add = 0;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010620 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010621 &hit_next_index))
10622 ;
10623 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
10624 &hit_next_index))
10625 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010626 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010627 &hit_next_index))
10628 ;
10629 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
10630 ;
10631 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
10632 ;
10633 else if (unformat (i, "opaque-index %d", &opaque_index))
10634 ;
10635 else if (unformat (i, "skip_n %d", &skip_n_vectors))
10636 ;
10637 else if (unformat (i, "match_n %d", &match_n_vectors))
10638 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010639 else if (unformat (i, "match %U", api_unformat_classify_match,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010640 &match, skip_n_vectors, match_n_vectors))
10641 ;
10642 else if (unformat (i, "advance %d", &advance))
10643 ;
10644 else if (unformat (i, "table-index %d", &table_index))
10645 ;
10646 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
10647 action = 1;
10648 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
10649 action = 2;
10650 else if (unformat (i, "action %d", &action))
10651 ;
10652 else if (unformat (i, "metadata %d", &metadata))
10653 ;
10654 else
10655 break;
10656 }
10657
10658 if (table_index == ~0)
10659 {
10660 errmsg ("Table index required");
10661 return -99;
10662 }
10663
10664 if (is_add && match == 0)
10665 {
10666 errmsg ("Match value required");
10667 return -99;
10668 }
10669
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010670 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010671
10672 mp->is_add = is_add;
10673 mp->table_index = ntohl (table_index);
10674 mp->hit_next_index = ntohl (hit_next_index);
10675 mp->opaque_index = ntohl (opaque_index);
10676 mp->advance = ntohl (advance);
10677 mp->action = action;
10678 mp->metadata = ntohl (metadata);
Juraj Sloboda75282452018-06-12 14:20:49 +020010679 mp->match_len = ntohl (vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010680 clib_memcpy (mp->match, match, vec_len (match));
10681 vec_free (match);
10682
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010683 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010684 W (ret);
10685 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010686}
10687
10688static int
10689api_classify_set_interface_ip_table (vat_main_t * vam)
10690{
10691 unformat_input_t *i = vam->input;
10692 vl_api_classify_set_interface_ip_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010693 u32 sw_if_index;
10694 int sw_if_index_set;
10695 u32 table_index = ~0;
10696 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010697 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010698
10699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10700 {
10701 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10702 sw_if_index_set = 1;
10703 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10704 sw_if_index_set = 1;
10705 else if (unformat (i, "table %d", &table_index))
10706 ;
10707 else
10708 {
10709 clib_warning ("parse error '%U'", format_unformat_error, i);
10710 return -99;
10711 }
10712 }
10713
10714 if (sw_if_index_set == 0)
10715 {
10716 errmsg ("missing interface name or sw_if_index");
10717 return -99;
10718 }
10719
10720
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010721 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010722
10723 mp->sw_if_index = ntohl (sw_if_index);
10724 mp->table_index = ntohl (table_index);
10725 mp->is_ipv6 = is_ipv6;
10726
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010727 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010728 W (ret);
10729 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010730}
10731
10732static int
10733api_classify_set_interface_l2_tables (vat_main_t * vam)
10734{
10735 unformat_input_t *i = vam->input;
10736 vl_api_classify_set_interface_l2_tables_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010737 u32 sw_if_index;
10738 int sw_if_index_set;
10739 u32 ip4_table_index = ~0;
10740 u32 ip6_table_index = ~0;
10741 u32 other_table_index = ~0;
10742 u32 is_input = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010743 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010744
10745 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10746 {
10747 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10748 sw_if_index_set = 1;
10749 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10750 sw_if_index_set = 1;
10751 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10752 ;
10753 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10754 ;
10755 else if (unformat (i, "other-table %d", &other_table_index))
10756 ;
10757 else if (unformat (i, "is-input %d", &is_input))
10758 ;
10759 else
10760 {
10761 clib_warning ("parse error '%U'", format_unformat_error, i);
10762 return -99;
10763 }
10764 }
10765
10766 if (sw_if_index_set == 0)
10767 {
10768 errmsg ("missing interface name or sw_if_index");
10769 return -99;
10770 }
10771
10772
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010773 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010774
10775 mp->sw_if_index = ntohl (sw_if_index);
10776 mp->ip4_table_index = ntohl (ip4_table_index);
10777 mp->ip6_table_index = ntohl (ip6_table_index);
10778 mp->other_table_index = ntohl (other_table_index);
10779 mp->is_input = (u8) is_input;
10780
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010781 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010782 W (ret);
10783 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010784}
10785
10786static int
10787api_set_ipfix_exporter (vat_main_t * vam)
10788{
10789 unformat_input_t *i = vam->input;
10790 vl_api_set_ipfix_exporter_t *mp;
10791 ip4_address_t collector_address;
10792 u8 collector_address_set = 0;
10793 u32 collector_port = ~0;
10794 ip4_address_t src_address;
10795 u8 src_address_set = 0;
10796 u32 vrf_id = ~0;
10797 u32 path_mtu = ~0;
10798 u32 template_interval = ~0;
10799 u8 udp_checksum = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010800 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010801
10802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10803 {
10804 if (unformat (i, "collector_address %U", unformat_ip4_address,
10805 &collector_address))
10806 collector_address_set = 1;
10807 else if (unformat (i, "collector_port %d", &collector_port))
10808 ;
10809 else if (unformat (i, "src_address %U", unformat_ip4_address,
10810 &src_address))
10811 src_address_set = 1;
10812 else if (unformat (i, "vrf_id %d", &vrf_id))
10813 ;
10814 else if (unformat (i, "path_mtu %d", &path_mtu))
10815 ;
10816 else if (unformat (i, "template_interval %d", &template_interval))
10817 ;
10818 else if (unformat (i, "udp_checksum"))
10819 udp_checksum = 1;
10820 else
10821 break;
10822 }
10823
10824 if (collector_address_set == 0)
10825 {
10826 errmsg ("collector_address required");
10827 return -99;
10828 }
10829
10830 if (src_address_set == 0)
10831 {
10832 errmsg ("src_address required");
10833 return -99;
10834 }
10835
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010836 M (SET_IPFIX_EXPORTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010837
Jakub Grajciar2f71a882019-10-10 14:21:22 +020010838 memcpy (mp->collector_address.un.ip4, collector_address.data,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010839 sizeof (collector_address.data));
10840 mp->collector_port = htons ((u16) collector_port);
Jakub Grajciar2f71a882019-10-10 14:21:22 +020010841 memcpy (mp->src_address.un.ip4, src_address.data,
10842 sizeof (src_address.data));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010843 mp->vrf_id = htonl (vrf_id);
10844 mp->path_mtu = htonl (path_mtu);
10845 mp->template_interval = htonl (template_interval);
10846 mp->udp_checksum = udp_checksum;
10847
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010848 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010849 W (ret);
10850 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010851}
10852
10853static int
10854api_set_ipfix_classify_stream (vat_main_t * vam)
10855{
10856 unformat_input_t *i = vam->input;
10857 vl_api_set_ipfix_classify_stream_t *mp;
10858 u32 domain_id = 0;
10859 u32 src_port = UDP_DST_PORT_ipfix;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010860 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010861
10862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10863 {
10864 if (unformat (i, "domain %d", &domain_id))
10865 ;
10866 else if (unformat (i, "src_port %d", &src_port))
10867 ;
10868 else
10869 {
10870 errmsg ("unknown input `%U'", format_unformat_error, i);
10871 return -99;
10872 }
10873 }
10874
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010875 M (SET_IPFIX_CLASSIFY_STREAM, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010876
10877 mp->domain_id = htonl (domain_id);
10878 mp->src_port = htons ((u16) src_port);
10879
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010880 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010881 W (ret);
10882 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010883}
10884
10885static int
10886api_ipfix_classify_table_add_del (vat_main_t * vam)
10887{
10888 unformat_input_t *i = vam->input;
10889 vl_api_ipfix_classify_table_add_del_t *mp;
10890 int is_add = -1;
10891 u32 classify_table_index = ~0;
10892 u8 ip_version = 0;
10893 u8 transport_protocol = 255;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010894 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010895
10896 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10897 {
10898 if (unformat (i, "add"))
10899 is_add = 1;
10900 else if (unformat (i, "del"))
10901 is_add = 0;
10902 else if (unformat (i, "table %d", &classify_table_index))
10903 ;
10904 else if (unformat (i, "ip4"))
10905 ip_version = 4;
10906 else if (unformat (i, "ip6"))
10907 ip_version = 6;
10908 else if (unformat (i, "tcp"))
10909 transport_protocol = 6;
10910 else if (unformat (i, "udp"))
10911 transport_protocol = 17;
10912 else
10913 {
10914 errmsg ("unknown input `%U'", format_unformat_error, i);
10915 return -99;
10916 }
10917 }
10918
10919 if (is_add == -1)
10920 {
10921 errmsg ("expecting: add|del");
10922 return -99;
10923 }
10924 if (classify_table_index == ~0)
10925 {
10926 errmsg ("classifier table not specified");
10927 return -99;
10928 }
10929 if (ip_version == 0)
10930 {
10931 errmsg ("IP version not specified");
10932 return -99;
10933 }
10934
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010935 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010936
10937 mp->is_add = is_add;
10938 mp->table_id = htonl (classify_table_index);
10939 mp->ip_version = ip_version;
10940 mp->transport_protocol = transport_protocol;
10941
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010942 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010943 W (ret);
10944 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010945}
10946
10947static int
10948api_get_node_index (vat_main_t * vam)
10949{
10950 unformat_input_t *i = vam->input;
10951 vl_api_get_node_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010952 u8 *name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010953 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010954
10955 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10956 {
10957 if (unformat (i, "node %s", &name))
10958 ;
10959 else
10960 break;
10961 }
10962 if (name == 0)
10963 {
10964 errmsg ("node name required");
10965 return -99;
10966 }
10967 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
10968 {
10969 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
10970 return -99;
10971 }
10972
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010973 M (GET_NODE_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010974 clib_memcpy (mp->node_name, name, vec_len (name));
10975 vec_free (name);
10976
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010977 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010978 W (ret);
10979 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010980}
10981
10982static int
10983api_get_next_index (vat_main_t * vam)
10984{
10985 unformat_input_t *i = vam->input;
10986 vl_api_get_next_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010987 u8 *node_name = 0, *next_node_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010988 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010989
10990 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10991 {
10992 if (unformat (i, "node-name %s", &node_name))
10993 ;
10994 else if (unformat (i, "next-node-name %s", &next_node_name))
10995 break;
10996 }
10997
10998 if (node_name == 0)
10999 {
11000 errmsg ("node name required");
11001 return -99;
11002 }
11003 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
11004 {
11005 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11006 return -99;
11007 }
11008
11009 if (next_node_name == 0)
11010 {
11011 errmsg ("next node name required");
11012 return -99;
11013 }
11014 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
11015 {
11016 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
11017 return -99;
11018 }
11019
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011020 M (GET_NEXT_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011021 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
11022 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
11023 vec_free (node_name);
11024 vec_free (next_node_name);
11025
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011026 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011027 W (ret);
11028 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011029}
11030
11031static int
11032api_add_node_next (vat_main_t * vam)
11033{
11034 unformat_input_t *i = vam->input;
11035 vl_api_add_node_next_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011036 u8 *name = 0;
11037 u8 *next = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011038 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011039
11040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11041 {
11042 if (unformat (i, "node %s", &name))
11043 ;
11044 else if (unformat (i, "next %s", &next))
11045 ;
11046 else
11047 break;
11048 }
11049 if (name == 0)
11050 {
11051 errmsg ("node name required");
11052 return -99;
11053 }
11054 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
11055 {
11056 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11057 return -99;
11058 }
11059 if (next == 0)
11060 {
11061 errmsg ("next node required");
11062 return -99;
11063 }
11064 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
11065 {
11066 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
11067 return -99;
11068 }
11069
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011070 M (ADD_NODE_NEXT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011071 clib_memcpy (mp->node_name, name, vec_len (name));
11072 clib_memcpy (mp->next_name, next, vec_len (next));
11073 vec_free (name);
11074 vec_free (next);
11075
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011076 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011077 W (ret);
11078 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011079}
11080
11081static int
11082api_l2tpv3_create_tunnel (vat_main_t * vam)
11083{
11084 unformat_input_t *i = vam->input;
11085 ip6_address_t client_address, our_address;
11086 int client_address_set = 0;
11087 int our_address_set = 0;
11088 u32 local_session_id = 0;
11089 u32 remote_session_id = 0;
11090 u64 local_cookie = 0;
11091 u64 remote_cookie = 0;
11092 u8 l2_sublayer_present = 0;
11093 vl_api_l2tpv3_create_tunnel_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011094 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011095
11096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11097 {
11098 if (unformat (i, "client_address %U", unformat_ip6_address,
11099 &client_address))
11100 client_address_set = 1;
11101 else if (unformat (i, "our_address %U", unformat_ip6_address,
11102 &our_address))
11103 our_address_set = 1;
11104 else if (unformat (i, "local_session_id %d", &local_session_id))
11105 ;
11106 else if (unformat (i, "remote_session_id %d", &remote_session_id))
11107 ;
11108 else if (unformat (i, "local_cookie %lld", &local_cookie))
11109 ;
11110 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
11111 ;
11112 else if (unformat (i, "l2-sublayer-present"))
11113 l2_sublayer_present = 1;
11114 else
11115 break;
11116 }
11117
11118 if (client_address_set == 0)
11119 {
11120 errmsg ("client_address required");
11121 return -99;
11122 }
11123
11124 if (our_address_set == 0)
11125 {
11126 errmsg ("our_address required");
11127 return -99;
11128 }
11129
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011130 M (L2TPV3_CREATE_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011131
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011132 clib_memcpy (mp->client_address.un.ip6, client_address.as_u8,
11133 sizeof (ip6_address_t));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011134
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011135 clib_memcpy (mp->our_address.un.ip6, our_address.as_u8,
11136 sizeof (ip6_address_t));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011137
11138 mp->local_session_id = ntohl (local_session_id);
11139 mp->remote_session_id = ntohl (remote_session_id);
11140 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
11141 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
11142 mp->l2_sublayer_present = l2_sublayer_present;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011143
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011144 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011145 W (ret);
11146 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011147}
11148
11149static int
11150api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
11151{
11152 unformat_input_t *i = vam->input;
11153 u32 sw_if_index;
11154 u8 sw_if_index_set = 0;
11155 u64 new_local_cookie = 0;
11156 u64 new_remote_cookie = 0;
11157 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011158 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011159
11160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11161 {
11162 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11163 sw_if_index_set = 1;
11164 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11165 sw_if_index_set = 1;
11166 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
11167 ;
11168 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
11169 ;
11170 else
11171 break;
11172 }
11173
11174 if (sw_if_index_set == 0)
11175 {
11176 errmsg ("missing interface name or sw_if_index");
11177 return -99;
11178 }
11179
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011180 M (L2TPV3_SET_TUNNEL_COOKIES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011181
11182 mp->sw_if_index = ntohl (sw_if_index);
11183 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
11184 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
11185
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011186 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011187 W (ret);
11188 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011189}
11190
11191static int
11192api_l2tpv3_interface_enable_disable (vat_main_t * vam)
11193{
11194 unformat_input_t *i = vam->input;
11195 vl_api_l2tpv3_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011196 u32 sw_if_index;
11197 u8 sw_if_index_set = 0;
11198 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011199 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011200
11201 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11202 {
11203 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11204 sw_if_index_set = 1;
11205 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11206 sw_if_index_set = 1;
11207 else if (unformat (i, "enable"))
11208 enable_disable = 1;
11209 else if (unformat (i, "disable"))
11210 enable_disable = 0;
11211 else
11212 break;
11213 }
11214
11215 if (sw_if_index_set == 0)
11216 {
11217 errmsg ("missing interface name or sw_if_index");
11218 return -99;
11219 }
11220
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011221 M (L2TPV3_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011222
11223 mp->sw_if_index = ntohl (sw_if_index);
11224 mp->enable_disable = enable_disable;
11225
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011226 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011227 W (ret);
11228 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011229}
11230
11231static int
11232api_l2tpv3_set_lookup_key (vat_main_t * vam)
11233{
11234 unformat_input_t *i = vam->input;
11235 vl_api_l2tpv3_set_lookup_key_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011236 u8 key = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011237 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011238
11239 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11240 {
11241 if (unformat (i, "lookup_v6_src"))
11242 key = L2T_LOOKUP_SRC_ADDRESS;
11243 else if (unformat (i, "lookup_v6_dst"))
11244 key = L2T_LOOKUP_DST_ADDRESS;
11245 else if (unformat (i, "lookup_session_id"))
11246 key = L2T_LOOKUP_SESSION_ID;
11247 else
11248 break;
11249 }
11250
11251 if (key == (u8) ~ 0)
11252 {
11253 errmsg ("l2tp session lookup key unset");
11254 return -99;
11255 }
11256
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011257 M (L2TPV3_SET_LOOKUP_KEY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011258
11259 mp->key = key;
11260
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011261 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011262 W (ret);
11263 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011264}
11265
11266static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
11267 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
11268{
11269 vat_main_t *vam = &vat_main;
11270
11271 print (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)",
11272 format_ip6_address, mp->our_address,
11273 format_ip6_address, mp->client_address,
11274 clib_net_to_host_u32 (mp->sw_if_index));
11275
11276 print (vam->ofp,
11277 " local cookies %016llx %016llx remote cookie %016llx",
11278 clib_net_to_host_u64 (mp->local_cookie[0]),
11279 clib_net_to_host_u64 (mp->local_cookie[1]),
11280 clib_net_to_host_u64 (mp->remote_cookie));
11281
11282 print (vam->ofp, " local session-id %d remote session-id %d",
11283 clib_net_to_host_u32 (mp->local_session_id),
11284 clib_net_to_host_u32 (mp->remote_session_id));
11285
11286 print (vam->ofp, " l2 specific sublayer %s\n",
11287 mp->l2_sublayer_present ? "preset" : "absent");
11288
11289}
11290
11291static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
11292 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
11293{
11294 vat_main_t *vam = &vat_main;
11295 vat_json_node_t *node = NULL;
11296 struct in6_addr addr;
11297
11298 if (VAT_JSON_ARRAY != vam->json_tree.type)
11299 {
11300 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11301 vat_json_init_array (&vam->json_tree);
11302 }
11303 node = vat_json_array_add (&vam->json_tree);
11304
11305 vat_json_init_object (node);
11306
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011307 clib_memcpy (&addr, mp->our_address.un.ip6, sizeof (addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011308 vat_json_object_add_ip6 (node, "our_address", addr);
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011309 clib_memcpy (&addr, mp->client_address.un.ip6, sizeof (addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011310 vat_json_object_add_ip6 (node, "client_address", addr);
11311
11312 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
11313 vat_json_init_array (lc);
11314 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
11315 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
11316 vat_json_object_add_uint (node, "remote_cookie",
11317 clib_net_to_host_u64 (mp->remote_cookie));
11318
11319 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
11320 vat_json_object_add_uint (node, "local_session_id",
11321 clib_net_to_host_u32 (mp->local_session_id));
11322 vat_json_object_add_uint (node, "remote_session_id",
11323 clib_net_to_host_u32 (mp->remote_session_id));
11324 vat_json_object_add_string_copy (node, "l2_sublayer",
11325 mp->l2_sublayer_present ? (u8 *) "present"
11326 : (u8 *) "absent");
11327}
11328
11329static int
11330api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
11331{
11332 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011333 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011334 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011335
11336 /* Get list of l2tpv3-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011337 M (SW_IF_L2TPV3_TUNNEL_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011338 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011339
11340 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040011341 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011342 S (mp_ping);
11343
Jon Loeliger56c7b012017-02-01 12:31:41 -060011344 W (ret);
11345 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011346}
11347
11348
Damjan Marion8389fb92017-10-13 18:29:53 +020011349static void vl_api_sw_interface_tap_v2_details_t_handler
11350 (vl_api_sw_interface_tap_v2_details_t * mp)
11351{
11352 vat_main_t *vam = &vat_main;
11353
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020011354 u8 *ip4 =
11355 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
11356 mp->host_ip4_prefix.len);
11357 u8 *ip6 =
11358 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
11359 mp->host_ip6_prefix.len);
Milan Lenco73e7f422017-12-14 10:04:25 +010011360
11361 print (vam->ofp,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010011362 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
Milan Lenco73e7f422017-12-14 10:04:25 +010011363 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
11364 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
11365 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010011366 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
Milan Lenco73e7f422017-12-14 10:04:25 +010011367
11368 vec_free (ip4);
11369 vec_free (ip6);
Damjan Marion8389fb92017-10-13 18:29:53 +020011370}
11371
11372static void vl_api_sw_interface_tap_v2_details_t_handler_json
11373 (vl_api_sw_interface_tap_v2_details_t * mp)
11374{
11375 vat_main_t *vam = &vat_main;
11376 vat_json_node_t *node = NULL;
11377
11378 if (VAT_JSON_ARRAY != vam->json_tree.type)
11379 {
11380 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11381 vat_json_init_array (&vam->json_tree);
11382 }
11383 node = vat_json_array_add (&vam->json_tree);
11384
11385 vat_json_init_object (node);
Milan Lenco73e7f422017-12-14 10:04:25 +010011386 vat_json_object_add_uint (node, "id", ntohl (mp->id));
Damjan Marion8389fb92017-10-13 18:29:53 +020011387 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010011388 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
Damjan Marion8389fb92017-10-13 18:29:53 +020011389 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Milan Lenco73e7f422017-12-14 10:04:25 +010011390 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
11391 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
11392 vat_json_object_add_string_copy (node, "host_mac_addr",
11393 format (0, "%U", format_ethernet_address,
11394 &mp->host_mac_addr));
11395 vat_json_object_add_string_copy (node, "host_namespace",
11396 mp->host_namespace);
11397 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
11398 vat_json_object_add_string_copy (node, "host_ip4_addr",
11399 format (0, "%U/%d", format_ip4_address,
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020011400 mp->host_ip4_prefix.address,
11401 mp->host_ip4_prefix.len));
11402 vat_json_object_add_string_copy (node, "host_ip6_prefix",
Milan Lenco73e7f422017-12-14 10:04:25 +010011403 format (0, "%U/%d", format_ip6_address,
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020011404 mp->host_ip6_prefix.address,
11405 mp->host_ip6_prefix.len));
Milan Lenco73e7f422017-12-14 10:04:25 +010011406
Damjan Marion8389fb92017-10-13 18:29:53 +020011407}
11408
11409static int
11410api_sw_interface_tap_v2_dump (vat_main_t * vam)
11411{
11412 vl_api_sw_interface_tap_v2_dump_t *mp;
11413 vl_api_control_ping_t *mp_ping;
11414 int ret;
11415
Milan Lenco73e7f422017-12-14 10:04:25 +010011416 print (vam->ofp,
11417 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
11418 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
11419 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
11420 "host_ip6_addr");
11421
Damjan Marion8389fb92017-10-13 18:29:53 +020011422 /* Get list of tap interfaces */
11423 M (SW_INTERFACE_TAP_V2_DUMP, mp);
11424 S (mp);
11425
11426 /* Use a control ping for synchronization */
11427 MPING (CONTROL_PING, mp_ping);
11428 S (mp_ping);
11429
11430 W (ret);
11431 return ret;
11432}
11433
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011434static void vl_api_sw_interface_virtio_pci_details_t_handler
11435 (vl_api_sw_interface_virtio_pci_details_t * mp)
11436{
11437 vat_main_t *vam = &vat_main;
11438
11439 typedef union
11440 {
11441 struct
11442 {
11443 u16 domain;
11444 u8 bus;
11445 u8 slot:5;
11446 u8 function:3;
11447 };
11448 u32 as_u32;
11449 } pci_addr_t;
11450 pci_addr_t addr;
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011451
11452 addr.domain = ntohs (mp->pci_addr.domain);
11453 addr.bus = mp->pci_addr.bus;
11454 addr.slot = mp->pci_addr.slot;
11455 addr.function = mp->pci_addr.function;
11456
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011457 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
11458 addr.slot, addr.function);
11459
11460 print (vam->ofp,
11461 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
11462 pci_addr, ntohl (mp->sw_if_index),
11463 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
11464 format_ethernet_address, mp->mac_addr,
11465 clib_net_to_host_u64 (mp->features));
11466 vec_free (pci_addr);
11467}
11468
11469static void vl_api_sw_interface_virtio_pci_details_t_handler_json
11470 (vl_api_sw_interface_virtio_pci_details_t * mp)
11471{
11472 vat_main_t *vam = &vat_main;
11473 vat_json_node_t *node = NULL;
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011474 vlib_pci_addr_t pci_addr;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011475
11476 if (VAT_JSON_ARRAY != vam->json_tree.type)
11477 {
11478 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11479 vat_json_init_array (&vam->json_tree);
11480 }
11481 node = vat_json_array_add (&vam->json_tree);
11482
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011483 pci_addr.domain = ntohs (mp->pci_addr.domain);
11484 pci_addr.bus = mp->pci_addr.bus;
11485 pci_addr.slot = mp->pci_addr.slot;
11486 pci_addr.function = mp->pci_addr.function;
11487
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011488 vat_json_init_object (node);
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011489 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011490 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11491 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
11492 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
11493 vat_json_object_add_uint (node, "features",
11494 clib_net_to_host_u64 (mp->features));
11495 vat_json_object_add_string_copy (node, "mac_addr",
11496 format (0, "%U", format_ethernet_address,
11497 &mp->mac_addr));
11498}
11499
11500static int
11501api_sw_interface_virtio_pci_dump (vat_main_t * vam)
11502{
11503 vl_api_sw_interface_virtio_pci_dump_t *mp;
11504 vl_api_control_ping_t *mp_ping;
11505 int ret;
11506
11507 print (vam->ofp,
11508 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
11509 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
11510 "mac_addr", "features");
11511
11512 /* Get list of tap interfaces */
11513 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
11514 S (mp);
11515
11516 /* Use a control ping for synchronization */
11517 MPING (CONTROL_PING, mp_ping);
11518 S (mp_ping);
11519
11520 W (ret);
11521 return ret;
11522}
11523
eyal bariaf86a482018-04-17 11:20:27 +030011524static int
11525api_vxlan_offload_rx (vat_main_t * vam)
11526{
11527 unformat_input_t *line_input = vam->input;
11528 vl_api_vxlan_offload_rx_t *mp;
11529 u32 hw_if_index = ~0, rx_if_index = ~0;
11530 u8 is_add = 1;
11531 int ret;
11532
11533 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11534 {
11535 if (unformat (line_input, "del"))
11536 is_add = 0;
11537 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
11538 &hw_if_index))
11539 ;
11540 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
11541 ;
11542 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
11543 &rx_if_index))
11544 ;
11545 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
11546 ;
11547 else
11548 {
11549 errmsg ("parse error '%U'", format_unformat_error, line_input);
11550 return -99;
11551 }
11552 }
11553
11554 if (hw_if_index == ~0)
11555 {
11556 errmsg ("no hw interface");
11557 return -99;
11558 }
11559
11560 if (rx_if_index == ~0)
11561 {
11562 errmsg ("no rx tunnel");
11563 return -99;
11564 }
11565
11566 M (VXLAN_OFFLOAD_RX, mp);
11567
11568 mp->hw_if_index = ntohl (hw_if_index);
11569 mp->sw_if_index = ntohl (rx_if_index);
11570 mp->enable = is_add;
11571
11572 S (mp);
11573 W (ret);
11574 return ret;
11575}
11576
Damjan Marion7cd468a2016-12-19 23:05:39 +010011577static uword unformat_vxlan_decap_next
11578 (unformat_input_t * input, va_list * args)
11579{
11580 u32 *result = va_arg (*args, u32 *);
11581 u32 tmp;
11582
11583 if (unformat (input, "l2"))
11584 *result = VXLAN_INPUT_NEXT_L2_INPUT;
11585 else if (unformat (input, "%d", &tmp))
11586 *result = tmp;
11587 else
11588 return 0;
11589 return 1;
11590}
11591
11592static int
11593api_vxlan_add_del_tunnel (vat_main_t * vam)
11594{
11595 unformat_input_t *line_input = vam->input;
11596 vl_api_vxlan_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011597 ip46_address_t src, dst;
11598 u8 is_add = 1;
11599 u8 ipv4_set = 0, ipv6_set = 0;
11600 u8 src_set = 0;
11601 u8 dst_set = 0;
11602 u8 grp_set = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011603 u32 instance = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011604 u32 mcast_sw_if_index = ~0;
11605 u32 encap_vrf_id = 0;
11606 u32 decap_next_index = ~0;
11607 u32 vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011608 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011609
11610 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040011611 clib_memset (&src, 0, sizeof src);
11612 clib_memset (&dst, 0, sizeof dst);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011613
11614 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11615 {
11616 if (unformat (line_input, "del"))
11617 is_add = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011618 else if (unformat (line_input, "instance %d", &instance))
11619 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011620 else
11621 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
11622 {
11623 ipv4_set = 1;
11624 src_set = 1;
11625 }
11626 else
11627 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
11628 {
11629 ipv4_set = 1;
11630 dst_set = 1;
11631 }
11632 else
11633 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
11634 {
11635 ipv6_set = 1;
11636 src_set = 1;
11637 }
11638 else
11639 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
11640 {
11641 ipv6_set = 1;
11642 dst_set = 1;
11643 }
11644 else if (unformat (line_input, "group %U %U",
11645 unformat_ip4_address, &dst.ip4,
11646 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11647 {
11648 grp_set = dst_set = 1;
11649 ipv4_set = 1;
11650 }
11651 else if (unformat (line_input, "group %U",
11652 unformat_ip4_address, &dst.ip4))
11653 {
11654 grp_set = dst_set = 1;
11655 ipv4_set = 1;
11656 }
11657 else if (unformat (line_input, "group %U %U",
11658 unformat_ip6_address, &dst.ip6,
11659 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11660 {
11661 grp_set = dst_set = 1;
11662 ipv6_set = 1;
11663 }
11664 else if (unformat (line_input, "group %U",
11665 unformat_ip6_address, &dst.ip6))
11666 {
11667 grp_set = dst_set = 1;
11668 ipv6_set = 1;
11669 }
11670 else
11671 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
11672 ;
11673 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
11674 ;
11675 else if (unformat (line_input, "decap-next %U",
11676 unformat_vxlan_decap_next, &decap_next_index))
11677 ;
11678 else if (unformat (line_input, "vni %d", &vni))
11679 ;
11680 else
11681 {
11682 errmsg ("parse error '%U'", format_unformat_error, line_input);
11683 return -99;
11684 }
11685 }
11686
11687 if (src_set == 0)
11688 {
11689 errmsg ("tunnel src address not specified");
11690 return -99;
11691 }
11692 if (dst_set == 0)
11693 {
11694 errmsg ("tunnel dst address not specified");
11695 return -99;
11696 }
11697
11698 if (grp_set && !ip46_address_is_multicast (&dst))
11699 {
11700 errmsg ("tunnel group address not multicast");
11701 return -99;
11702 }
11703 if (grp_set && mcast_sw_if_index == ~0)
11704 {
11705 errmsg ("tunnel nonexistent multicast device");
11706 return -99;
11707 }
11708 if (grp_set == 0 && ip46_address_is_multicast (&dst))
11709 {
11710 errmsg ("tunnel dst address must be unicast");
11711 return -99;
11712 }
11713
11714
11715 if (ipv4_set && ipv6_set)
11716 {
11717 errmsg ("both IPv4 and IPv6 addresses specified");
11718 return -99;
11719 }
11720
11721 if ((vni == 0) || (vni >> 24))
11722 {
11723 errmsg ("vni not specified or out of range");
11724 return -99;
11725 }
11726
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011727 M (VXLAN_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011728
11729 if (ipv6_set)
11730 {
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011731 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
11732 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011733 }
11734 else
11735 {
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011736 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
11737 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011738 }
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011739 mp->src_address.af = ipv6_set;
11740 mp->dst_address.af = ipv6_set;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011741
11742 mp->instance = htonl (instance);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011743 mp->encap_vrf_id = ntohl (encap_vrf_id);
11744 mp->decap_next_index = ntohl (decap_next_index);
11745 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
11746 mp->vni = ntohl (vni);
11747 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011748
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011749 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011750 W (ret);
11751 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011752}
11753
11754static void vl_api_vxlan_tunnel_details_t_handler
11755 (vl_api_vxlan_tunnel_details_t * mp)
11756{
11757 vat_main_t *vam = &vat_main;
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011758 ip46_address_t src =
11759 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
11760 ip46_address_t dst =
11761 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011762
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011763 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010011764 ntohl (mp->sw_if_index),
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011765 ntohl (mp->instance),
Damjan Marion7cd468a2016-12-19 23:05:39 +010011766 format_ip46_address, &src, IP46_TYPE_ANY,
11767 format_ip46_address, &dst, IP46_TYPE_ANY,
11768 ntohl (mp->encap_vrf_id),
11769 ntohl (mp->decap_next_index), ntohl (mp->vni),
11770 ntohl (mp->mcast_sw_if_index));
11771}
11772
11773static void vl_api_vxlan_tunnel_details_t_handler_json
11774 (vl_api_vxlan_tunnel_details_t * mp)
11775{
11776 vat_main_t *vam = &vat_main;
11777 vat_json_node_t *node = NULL;
11778
11779 if (VAT_JSON_ARRAY != vam->json_tree.type)
11780 {
11781 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11782 vat_json_init_array (&vam->json_tree);
11783 }
11784 node = vat_json_array_add (&vam->json_tree);
11785
11786 vat_json_init_object (node);
11787 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011788
11789 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
11790
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011791 if (mp->src_address.af)
Damjan Marion7cd468a2016-12-19 23:05:39 +010011792 {
11793 struct in6_addr ip6;
11794
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011795 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011796 vat_json_object_add_ip6 (node, "src_address", ip6);
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011797 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011798 vat_json_object_add_ip6 (node, "dst_address", ip6);
11799 }
11800 else
11801 {
11802 struct in_addr ip4;
11803
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011804 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011805 vat_json_object_add_ip4 (node, "src_address", ip4);
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011806 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011807 vat_json_object_add_ip4 (node, "dst_address", ip4);
11808 }
11809 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
11810 vat_json_object_add_uint (node, "decap_next_index",
11811 ntohl (mp->decap_next_index));
11812 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011813 vat_json_object_add_uint (node, "mcast_sw_if_index",
11814 ntohl (mp->mcast_sw_if_index));
11815}
11816
11817static int
11818api_vxlan_tunnel_dump (vat_main_t * vam)
11819{
11820 unformat_input_t *i = vam->input;
11821 vl_api_vxlan_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011822 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011823 u32 sw_if_index;
11824 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011825 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011826
11827 /* Parse args required to build the message */
11828 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11829 {
11830 if (unformat (i, "sw_if_index %d", &sw_if_index))
11831 sw_if_index_set = 1;
11832 else
11833 break;
11834 }
11835
11836 if (sw_if_index_set == 0)
11837 {
11838 sw_if_index = ~0;
11839 }
11840
11841 if (!vam->json_output)
11842 {
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011843 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
11844 "sw_if_index", "instance", "src_address", "dst_address",
Damjan Marion7cd468a2016-12-19 23:05:39 +010011845 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
11846 }
11847
11848 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011849 M (VXLAN_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011850
11851 mp->sw_if_index = htonl (sw_if_index);
11852
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011853 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011854
11855 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040011856 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011857 S (mp_ping);
11858
Jon Loeliger56c7b012017-02-01 12:31:41 -060011859 W (ret);
11860 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011861}
11862
Marco Varleseb598f1d2017-09-19 14:25:28 +020011863static uword unformat_geneve_decap_next
11864 (unformat_input_t * input, va_list * args)
11865{
11866 u32 *result = va_arg (*args, u32 *);
11867 u32 tmp;
11868
11869 if (unformat (input, "l2"))
11870 *result = GENEVE_INPUT_NEXT_L2_INPUT;
11871 else if (unformat (input, "%d", &tmp))
11872 *result = tmp;
11873 else
11874 return 0;
11875 return 1;
11876}
11877
11878static int
11879api_geneve_add_del_tunnel (vat_main_t * vam)
11880{
11881 unformat_input_t *line_input = vam->input;
11882 vl_api_geneve_add_del_tunnel_t *mp;
11883 ip46_address_t src, dst;
11884 u8 is_add = 1;
11885 u8 ipv4_set = 0, ipv6_set = 0;
11886 u8 src_set = 0;
11887 u8 dst_set = 0;
11888 u8 grp_set = 0;
11889 u32 mcast_sw_if_index = ~0;
11890 u32 encap_vrf_id = 0;
11891 u32 decap_next_index = ~0;
11892 u32 vni = 0;
11893 int ret;
11894
11895 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040011896 clib_memset (&src, 0, sizeof src);
11897 clib_memset (&dst, 0, sizeof dst);
Marco Varleseb598f1d2017-09-19 14:25:28 +020011898
11899 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11900 {
11901 if (unformat (line_input, "del"))
11902 is_add = 0;
11903 else
11904 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
11905 {
11906 ipv4_set = 1;
11907 src_set = 1;
11908 }
11909 else
11910 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
11911 {
11912 ipv4_set = 1;
11913 dst_set = 1;
11914 }
11915 else
11916 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
11917 {
11918 ipv6_set = 1;
11919 src_set = 1;
11920 }
11921 else
11922 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
11923 {
11924 ipv6_set = 1;
11925 dst_set = 1;
11926 }
11927 else if (unformat (line_input, "group %U %U",
11928 unformat_ip4_address, &dst.ip4,
11929 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11930 {
11931 grp_set = dst_set = 1;
11932 ipv4_set = 1;
11933 }
11934 else if (unformat (line_input, "group %U",
11935 unformat_ip4_address, &dst.ip4))
11936 {
11937 grp_set = dst_set = 1;
11938 ipv4_set = 1;
11939 }
11940 else if (unformat (line_input, "group %U %U",
11941 unformat_ip6_address, &dst.ip6,
11942 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11943 {
11944 grp_set = dst_set = 1;
11945 ipv6_set = 1;
11946 }
11947 else if (unformat (line_input, "group %U",
11948 unformat_ip6_address, &dst.ip6))
11949 {
11950 grp_set = dst_set = 1;
11951 ipv6_set = 1;
11952 }
11953 else
11954 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
11955 ;
11956 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
11957 ;
11958 else if (unformat (line_input, "decap-next %U",
11959 unformat_geneve_decap_next, &decap_next_index))
11960 ;
11961 else if (unformat (line_input, "vni %d", &vni))
11962 ;
11963 else
11964 {
11965 errmsg ("parse error '%U'", format_unformat_error, line_input);
11966 return -99;
11967 }
11968 }
11969
11970 if (src_set == 0)
11971 {
11972 errmsg ("tunnel src address not specified");
11973 return -99;
11974 }
11975 if (dst_set == 0)
11976 {
11977 errmsg ("tunnel dst address not specified");
11978 return -99;
11979 }
11980
11981 if (grp_set && !ip46_address_is_multicast (&dst))
11982 {
11983 errmsg ("tunnel group address not multicast");
11984 return -99;
11985 }
11986 if (grp_set && mcast_sw_if_index == ~0)
11987 {
11988 errmsg ("tunnel nonexistent multicast device");
11989 return -99;
11990 }
11991 if (grp_set == 0 && ip46_address_is_multicast (&dst))
11992 {
11993 errmsg ("tunnel dst address must be unicast");
11994 return -99;
11995 }
11996
11997
11998 if (ipv4_set && ipv6_set)
11999 {
12000 errmsg ("both IPv4 and IPv6 addresses specified");
12001 return -99;
12002 }
12003
12004 if ((vni == 0) || (vni >> 24))
12005 {
12006 errmsg ("vni not specified or out of range");
12007 return -99;
12008 }
12009
12010 M (GENEVE_ADD_DEL_TUNNEL, mp);
12011
12012 if (ipv6_set)
12013 {
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012014 clib_memcpy (&mp->local_address.un.ip6, &src.ip6, sizeof (src.ip6));
12015 clib_memcpy (&mp->remote_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012016 }
12017 else
12018 {
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012019 clib_memcpy (&mp->local_address.un.ip4, &src.ip4, sizeof (src.ip4));
12020 clib_memcpy (&mp->remote_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012021 }
12022 mp->encap_vrf_id = ntohl (encap_vrf_id);
12023 mp->decap_next_index = ntohl (decap_next_index);
12024 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
12025 mp->vni = ntohl (vni);
12026 mp->is_add = is_add;
Marco Varleseb598f1d2017-09-19 14:25:28 +020012027
12028 S (mp);
12029 W (ret);
12030 return ret;
12031}
12032
12033static void vl_api_geneve_tunnel_details_t_handler
12034 (vl_api_geneve_tunnel_details_t * mp)
12035{
12036 vat_main_t *vam = &vat_main;
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012037 ip46_address_t src = {.as_u64[0] = 0,.as_u64[1] = 0 };
12038 ip46_address_t dst = {.as_u64[0] = 0,.as_u64[1] = 0 };
12039
12040 if (mp->src_address.af == ADDRESS_IP6)
12041 {
12042 clib_memcpy (&src.ip6, &mp->src_address.un.ip6, sizeof (ip6_address_t));
12043 clib_memcpy (&dst.ip6, &mp->dst_address.un.ip6, sizeof (ip6_address_t));
12044 }
12045 else
12046 {
12047 clib_memcpy (&src.ip4, &mp->src_address.un.ip4, sizeof (ip4_address_t));
12048 clib_memcpy (&dst.ip4, &mp->dst_address.un.ip4, sizeof (ip4_address_t));
12049 }
Marco Varleseb598f1d2017-09-19 14:25:28 +020012050
12051 print (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d",
12052 ntohl (mp->sw_if_index),
12053 format_ip46_address, &src, IP46_TYPE_ANY,
12054 format_ip46_address, &dst, IP46_TYPE_ANY,
12055 ntohl (mp->encap_vrf_id),
12056 ntohl (mp->decap_next_index), ntohl (mp->vni),
12057 ntohl (mp->mcast_sw_if_index));
12058}
12059
12060static void vl_api_geneve_tunnel_details_t_handler_json
12061 (vl_api_geneve_tunnel_details_t * mp)
12062{
12063 vat_main_t *vam = &vat_main;
12064 vat_json_node_t *node = NULL;
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012065 bool is_ipv6;
Marco Varleseb598f1d2017-09-19 14:25:28 +020012066
12067 if (VAT_JSON_ARRAY != vam->json_tree.type)
12068 {
12069 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12070 vat_json_init_array (&vam->json_tree);
12071 }
12072 node = vat_json_array_add (&vam->json_tree);
12073
12074 vat_json_init_object (node);
12075 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012076 is_ipv6 = mp->src_address.af == ADDRESS_IP6;
12077 if (is_ipv6)
Marco Varleseb598f1d2017-09-19 14:25:28 +020012078 {
12079 struct in6_addr ip6;
12080
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012081 clib_memcpy (&ip6, &mp->src_address.un.ip6, sizeof (ip6));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012082 vat_json_object_add_ip6 (node, "src_address", ip6);
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012083 clib_memcpy (&ip6, &mp->dst_address.un.ip6, sizeof (ip6));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012084 vat_json_object_add_ip6 (node, "dst_address", ip6);
12085 }
12086 else
12087 {
12088 struct in_addr ip4;
12089
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012090 clib_memcpy (&ip4, &mp->src_address.un.ip4, sizeof (ip4));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012091 vat_json_object_add_ip4 (node, "src_address", ip4);
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012092 clib_memcpy (&ip4, &mp->dst_address.un.ip4, sizeof (ip4));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012093 vat_json_object_add_ip4 (node, "dst_address", ip4);
12094 }
12095 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12096 vat_json_object_add_uint (node, "decap_next_index",
12097 ntohl (mp->decap_next_index));
12098 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012099 vat_json_object_add_uint (node, "mcast_sw_if_index",
12100 ntohl (mp->mcast_sw_if_index));
12101}
12102
12103static int
12104api_geneve_tunnel_dump (vat_main_t * vam)
12105{
12106 unformat_input_t *i = vam->input;
12107 vl_api_geneve_tunnel_dump_t *mp;
12108 vl_api_control_ping_t *mp_ping;
12109 u32 sw_if_index;
12110 u8 sw_if_index_set = 0;
12111 int ret;
12112
12113 /* Parse args required to build the message */
12114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12115 {
12116 if (unformat (i, "sw_if_index %d", &sw_if_index))
12117 sw_if_index_set = 1;
12118 else
12119 break;
12120 }
12121
12122 if (sw_if_index_set == 0)
12123 {
12124 sw_if_index = ~0;
12125 }
12126
12127 if (!vam->json_output)
12128 {
12129 print (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s",
12130 "sw_if_index", "local_address", "remote_address",
12131 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
12132 }
12133
12134 /* Get list of geneve-tunnel interfaces */
12135 M (GENEVE_TUNNEL_DUMP, mp);
12136
12137 mp->sw_if_index = htonl (sw_if_index);
12138
12139 S (mp);
12140
12141 /* Use a control ping for synchronization */
12142 M (CONTROL_PING, mp_ping);
12143 S (mp_ping);
12144
12145 W (ret);
12146 return ret;
12147}
12148
Damjan Marion7cd468a2016-12-19 23:05:39 +010012149static int
Neale Ranns5a8844b2019-04-16 07:15:35 +000012150api_gre_tunnel_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010012151{
12152 unformat_input_t *line_input = vam->input;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012153 vl_api_address_t src = { }, dst =
12154 {
12155 };
12156 vl_api_gre_tunnel_add_del_t *mp;
12157 vl_api_gre_tunnel_type_t t_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012158 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012159 u8 src_set = 0;
12160 u8 dst_set = 0;
Neale Ranns5f8f6172019-04-18 10:23:56 +000012161 u32 outer_table_id = 0;
John Loa43ccae2018-02-13 17:15:23 -050012162 u32 session_id = 0;
12163 u32 instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012164 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012165
Neale Ranns5a8844b2019-04-16 07:15:35 +000012166 t_type = GRE_API_TUNNEL_TYPE_L3;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012167
Damjan Marion7cd468a2016-12-19 23:05:39 +010012168 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12169 {
12170 if (unformat (line_input, "del"))
12171 is_add = 0;
John Loa43ccae2018-02-13 17:15:23 -050012172 else if (unformat (line_input, "instance %d", &instance))
12173 ;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012174 else if (unformat (line_input, "src %U", unformat_vl_api_address, &src))
Ciara Loftus7eac9162016-09-30 15:47:03 +010012175 {
12176 src_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012177 }
Neale Ranns5a8844b2019-04-16 07:15:35 +000012178 else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst))
Ciara Loftus7eac9162016-09-30 15:47:03 +010012179 {
12180 dst_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012181 }
Neale Ranns5f8f6172019-04-18 10:23:56 +000012182 else if (unformat (line_input, "outer-table-id %d", &outer_table_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012183 ;
12184 else if (unformat (line_input, "teb"))
Neale Ranns5a8844b2019-04-16 07:15:35 +000012185 t_type = GRE_API_TUNNEL_TYPE_TEB;
John Loa43ccae2018-02-13 17:15:23 -050012186 else if (unformat (line_input, "erspan %d", &session_id))
Neale Ranns5a8844b2019-04-16 07:15:35 +000012187 t_type = GRE_API_TUNNEL_TYPE_ERSPAN;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012188 else
12189 {
12190 errmsg ("parse error '%U'", format_unformat_error, line_input);
12191 return -99;
12192 }
12193 }
12194
12195 if (src_set == 0)
12196 {
12197 errmsg ("tunnel src address not specified");
12198 return -99;
12199 }
12200 if (dst_set == 0)
12201 {
12202 errmsg ("tunnel dst address not specified");
12203 return -99;
12204 }
12205
Neale Ranns5a8844b2019-04-16 07:15:35 +000012206 M (GRE_TUNNEL_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012207
Neale Ranns5a8844b2019-04-16 07:15:35 +000012208 clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src));
12209 clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012210
Neale Ranns5a8844b2019-04-16 07:15:35 +000012211 mp->tunnel.instance = htonl (instance);
Neale Ranns5f8f6172019-04-18 10:23:56 +000012212 mp->tunnel.outer_table_id = htonl (outer_table_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012213 mp->is_add = is_add;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012214 mp->tunnel.session_id = htons ((u16) session_id);
12215 mp->tunnel.type = htonl (t_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012216
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012217 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012218 W (ret);
12219 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012220}
12221
12222static void vl_api_gre_tunnel_details_t_handler
12223 (vl_api_gre_tunnel_details_t * mp)
12224{
12225 vat_main_t *vam = &vat_main;
12226
John Loa43ccae2018-02-13 17:15:23 -050012227 print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d",
Neale Ranns5a8844b2019-04-16 07:15:35 +000012228 ntohl (mp->tunnel.sw_if_index),
12229 ntohl (mp->tunnel.instance),
12230 format_vl_api_address, &mp->tunnel.src,
12231 format_vl_api_address, &mp->tunnel.dst,
Neale Ranns5f8f6172019-04-18 10:23:56 +000012232 mp->tunnel.type, ntohl (mp->tunnel.outer_table_id),
Neale Ranns5a8844b2019-04-16 07:15:35 +000012233 ntohl (mp->tunnel.session_id));
12234}
12235
Damjan Marion7cd468a2016-12-19 23:05:39 +010012236static void vl_api_gre_tunnel_details_t_handler_json
12237 (vl_api_gre_tunnel_details_t * mp)
12238{
12239 vat_main_t *vam = &vat_main;
12240 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012241
12242 if (VAT_JSON_ARRAY != vam->json_tree.type)
12243 {
12244 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12245 vat_json_init_array (&vam->json_tree);
12246 }
12247 node = vat_json_array_add (&vam->json_tree);
12248
12249 vat_json_init_object (node);
Neale Ranns5a8844b2019-04-16 07:15:35 +000012250 vat_json_object_add_uint (node, "sw_if_index",
12251 ntohl (mp->tunnel.sw_if_index));
12252 vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance));
12253
12254 vat_json_object_add_address (node, "src", &mp->tunnel.src);
12255 vat_json_object_add_address (node, "dst", &mp->tunnel.dst);
12256 vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type);
Neale Ranns5f8f6172019-04-18 10:23:56 +000012257 vat_json_object_add_uint (node, "outer_table_id",
12258 ntohl (mp->tunnel.outer_table_id));
Neale Ranns5a8844b2019-04-16 07:15:35 +000012259 vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012260}
12261
12262static int
12263api_gre_tunnel_dump (vat_main_t * vam)
12264{
12265 unformat_input_t *i = vam->input;
12266 vl_api_gre_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012267 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012268 u32 sw_if_index;
12269 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012270 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012271
12272 /* Parse args required to build the message */
12273 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12274 {
12275 if (unformat (i, "sw_if_index %d", &sw_if_index))
12276 sw_if_index_set = 1;
12277 else
12278 break;
12279 }
12280
12281 if (sw_if_index_set == 0)
12282 {
12283 sw_if_index = ~0;
12284 }
12285
12286 if (!vam->json_output)
12287 {
John Loa43ccae2018-02-13 17:15:23 -050012288 print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s",
12289 "sw_if_index", "instance", "src_address", "dst_address",
12290 "tunnel_type", "outer_fib_id", "session_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010012291 }
12292
12293 /* Get list of gre-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012294 M (GRE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012295
12296 mp->sw_if_index = htonl (sw_if_index);
12297
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012298 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012299
12300 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012301 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012302 S (mp_ping);
12303
Jon Loeliger56c7b012017-02-01 12:31:41 -060012304 W (ret);
12305 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012306}
12307
12308static int
12309api_l2_fib_clear_table (vat_main_t * vam)
12310{
12311// unformat_input_t * i = vam->input;
12312 vl_api_l2_fib_clear_table_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012313 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012314
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012315 M (L2_FIB_CLEAR_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012316
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012317 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012318 W (ret);
12319 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012320}
12321
12322static int
12323api_l2_interface_efp_filter (vat_main_t * vam)
12324{
12325 unformat_input_t *i = vam->input;
12326 vl_api_l2_interface_efp_filter_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012327 u32 sw_if_index;
12328 u8 enable = 1;
12329 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012330 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012331
12332 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12333 {
12334 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12335 sw_if_index_set = 1;
12336 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12337 sw_if_index_set = 1;
12338 else if (unformat (i, "enable"))
12339 enable = 1;
12340 else if (unformat (i, "disable"))
12341 enable = 0;
12342 else
12343 {
12344 clib_warning ("parse error '%U'", format_unformat_error, i);
12345 return -99;
12346 }
12347 }
12348
12349 if (sw_if_index_set == 0)
12350 {
12351 errmsg ("missing sw_if_index");
12352 return -99;
12353 }
12354
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012355 M (L2_INTERFACE_EFP_FILTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012356
12357 mp->sw_if_index = ntohl (sw_if_index);
12358 mp->enable_disable = enable;
12359
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012360 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012361 W (ret);
12362 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012363}
12364
12365#define foreach_vtr_op \
12366_("disable", L2_VTR_DISABLED) \
12367_("push-1", L2_VTR_PUSH_1) \
12368_("push-2", L2_VTR_PUSH_2) \
12369_("pop-1", L2_VTR_POP_1) \
12370_("pop-2", L2_VTR_POP_2) \
12371_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
12372_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
12373_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
12374_("translate-2-2", L2_VTR_TRANSLATE_2_2)
12375
12376static int
12377api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
12378{
12379 unformat_input_t *i = vam->input;
12380 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012381 u32 sw_if_index;
12382 u8 sw_if_index_set = 0;
12383 u8 vtr_op_set = 0;
12384 u32 vtr_op = 0;
12385 u32 push_dot1q = 1;
12386 u32 tag1 = ~0;
12387 u32 tag2 = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012388 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012389
12390 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12391 {
12392 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12393 sw_if_index_set = 1;
12394 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12395 sw_if_index_set = 1;
12396 else if (unformat (i, "vtr_op %d", &vtr_op))
12397 vtr_op_set = 1;
12398#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
12399 foreach_vtr_op
12400#undef _
12401 else if (unformat (i, "push_dot1q %d", &push_dot1q))
12402 ;
12403 else if (unformat (i, "tag1 %d", &tag1))
12404 ;
12405 else if (unformat (i, "tag2 %d", &tag2))
12406 ;
12407 else
12408 {
12409 clib_warning ("parse error '%U'", format_unformat_error, i);
12410 return -99;
12411 }
12412 }
12413
12414 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
12415 {
12416 errmsg ("missing vtr operation or sw_if_index");
12417 return -99;
12418 }
12419
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012420 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
12421 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012422 mp->vtr_op = ntohl (vtr_op);
12423 mp->push_dot1q = ntohl (push_dot1q);
12424 mp->tag1 = ntohl (tag1);
12425 mp->tag2 = ntohl (tag2);
12426
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012427 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012428 W (ret);
12429 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012430}
12431
12432static int
12433api_create_vhost_user_if (vat_main_t * vam)
12434{
12435 unformat_input_t *i = vam->input;
12436 vl_api_create_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012437 u8 *file_name;
12438 u8 is_server = 0;
12439 u8 file_name_set = 0;
12440 u32 custom_dev_instance = ~0;
12441 u8 hwaddr[6];
12442 u8 use_custom_mac = 0;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012443 u8 disable_mrg_rxbuf = 0;
12444 u8 disable_indirect_desc = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012445 u8 *tag = 0;
Steven Luong4208a4c2019-05-06 08:51:56 -070012446 u8 enable_gso = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012447 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012448
12449 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040012450 clib_memset (hwaddr, 0, sizeof (hwaddr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012451
12452 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12453 {
12454 if (unformat (i, "socket %s", &file_name))
12455 {
12456 file_name_set = 1;
12457 }
12458 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
12459 ;
12460 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
12461 use_custom_mac = 1;
12462 else if (unformat (i, "server"))
12463 is_server = 1;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012464 else if (unformat (i, "disable_mrg_rxbuf"))
12465 disable_mrg_rxbuf = 1;
12466 else if (unformat (i, "disable_indirect_desc"))
12467 disable_indirect_desc = 1;
Steven Luong4208a4c2019-05-06 08:51:56 -070012468 else if (unformat (i, "gso"))
12469 enable_gso = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012470 else if (unformat (i, "tag %s", &tag))
12471 ;
12472 else
12473 break;
12474 }
12475
12476 if (file_name_set == 0)
12477 {
12478 errmsg ("missing socket file name");
12479 return -99;
12480 }
12481
12482 if (vec_len (file_name) > 255)
12483 {
12484 errmsg ("socket file name too long");
12485 return -99;
12486 }
12487 vec_add1 (file_name, 0);
12488
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012489 M (CREATE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012490
12491 mp->is_server = is_server;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012492 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
12493 mp->disable_indirect_desc = disable_indirect_desc;
Steven Luong4208a4c2019-05-06 08:51:56 -070012494 mp->enable_gso = enable_gso;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012495 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
12496 vec_free (file_name);
12497 if (custom_dev_instance != ~0)
12498 {
12499 mp->renumber = 1;
12500 mp->custom_dev_instance = ntohl (custom_dev_instance);
12501 }
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012502
Damjan Marion7cd468a2016-12-19 23:05:39 +010012503 mp->use_custom_mac = use_custom_mac;
12504 clib_memcpy (mp->mac_address, hwaddr, 6);
12505 if (tag)
12506 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
12507 vec_free (tag);
12508
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012509 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012510 W (ret);
12511 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012512}
12513
12514static int
12515api_modify_vhost_user_if (vat_main_t * vam)
12516{
12517 unformat_input_t *i = vam->input;
12518 vl_api_modify_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012519 u8 *file_name;
12520 u8 is_server = 0;
12521 u8 file_name_set = 0;
12522 u32 custom_dev_instance = ~0;
12523 u8 sw_if_index_set = 0;
12524 u32 sw_if_index = (u32) ~ 0;
Steven Luong4208a4c2019-05-06 08:51:56 -070012525 u8 enable_gso = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012526 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012527
12528 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12529 {
12530 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12531 sw_if_index_set = 1;
12532 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12533 sw_if_index_set = 1;
12534 else if (unformat (i, "socket %s", &file_name))
12535 {
12536 file_name_set = 1;
12537 }
12538 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
12539 ;
12540 else if (unformat (i, "server"))
12541 is_server = 1;
Steven Luong4208a4c2019-05-06 08:51:56 -070012542 else if (unformat (i, "gso"))
12543 enable_gso = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012544 else
12545 break;
12546 }
12547
12548 if (sw_if_index_set == 0)
12549 {
12550 errmsg ("missing sw_if_index or interface name");
12551 return -99;
12552 }
12553
12554 if (file_name_set == 0)
12555 {
12556 errmsg ("missing socket file name");
12557 return -99;
12558 }
12559
12560 if (vec_len (file_name) > 255)
12561 {
12562 errmsg ("socket file name too long");
12563 return -99;
12564 }
12565 vec_add1 (file_name, 0);
12566
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012567 M (MODIFY_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012568
12569 mp->sw_if_index = ntohl (sw_if_index);
12570 mp->is_server = is_server;
Steven Luong4208a4c2019-05-06 08:51:56 -070012571 mp->enable_gso = enable_gso;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012572 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
12573 vec_free (file_name);
12574 if (custom_dev_instance != ~0)
12575 {
12576 mp->renumber = 1;
12577 mp->custom_dev_instance = ntohl (custom_dev_instance);
12578 }
12579
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012580 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012581 W (ret);
12582 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012583}
12584
12585static int
12586api_delete_vhost_user_if (vat_main_t * vam)
12587{
12588 unformat_input_t *i = vam->input;
12589 vl_api_delete_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012590 u32 sw_if_index = ~0;
12591 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012592 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012593
12594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12595 {
12596 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12597 sw_if_index_set = 1;
12598 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12599 sw_if_index_set = 1;
12600 else
12601 break;
12602 }
12603
12604 if (sw_if_index_set == 0)
12605 {
12606 errmsg ("missing sw_if_index or interface name");
12607 return -99;
12608 }
12609
12610
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012611 M (DELETE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012612
12613 mp->sw_if_index = ntohl (sw_if_index);
12614
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012615 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012616 W (ret);
12617 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012618}
12619
12620static void vl_api_sw_interface_vhost_user_details_t_handler
12621 (vl_api_sw_interface_vhost_user_details_t * mp)
12622{
12623 vat_main_t *vam = &vat_main;
Jakub Grajciar5d4c99f2019-09-26 10:21:59 +020012624 u64 features;
12625
12626 features =
12627 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
12628 clib_net_to_host_u32
12629 (mp->features_last_32) <<
12630 32);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012631
Stevenf3b53642017-05-01 14:03:02 -070012632 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012633 (char *) mp->interface_name,
12634 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
Jakub Grajciar5d4c99f2019-09-26 10:21:59 +020012635 features, mp->is_server,
Stevenf3b53642017-05-01 14:03:02 -070012636 ntohl (mp->num_regions), (char *) mp->sock_filename);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012637 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
12638}
12639
12640static void vl_api_sw_interface_vhost_user_details_t_handler_json
12641 (vl_api_sw_interface_vhost_user_details_t * mp)
12642{
12643 vat_main_t *vam = &vat_main;
12644 vat_json_node_t *node = NULL;
12645
12646 if (VAT_JSON_ARRAY != vam->json_tree.type)
12647 {
12648 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12649 vat_json_init_array (&vam->json_tree);
12650 }
12651 node = vat_json_array_add (&vam->json_tree);
12652
12653 vat_json_init_object (node);
12654 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12655 vat_json_object_add_string_copy (node, "interface_name",
12656 mp->interface_name);
12657 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
12658 ntohl (mp->virtio_net_hdr_sz));
Jakub Grajciar5d4c99f2019-09-26 10:21:59 +020012659 vat_json_object_add_uint (node, "features_first_32",
12660 clib_net_to_host_u32 (mp->features_first_32));
12661 vat_json_object_add_uint (node, "features_last_32",
12662 clib_net_to_host_u32 (mp->features_last_32));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012663 vat_json_object_add_uint (node, "is_server", mp->is_server);
12664 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
12665 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
12666 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
12667}
12668
12669static int
12670api_sw_interface_vhost_user_dump (vat_main_t * vam)
12671{
12672 vl_api_sw_interface_vhost_user_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012673 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012674 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012675 print (vam->ofp,
Stevenf3b53642017-05-01 14:03:02 -070012676 "Interface name idx hdr_sz features server regions filename");
Damjan Marion7cd468a2016-12-19 23:05:39 +010012677
12678 /* Get list of vhost-user interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012679 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
Steven Luong1bf83b92020-01-16 08:45:53 -080012680 mp->sw_if_index = ntohl (~0);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012681 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012682
12683 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012684 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012685 S (mp_ping);
12686
Jon Loeliger56c7b012017-02-01 12:31:41 -060012687 W (ret);
12688 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012689}
12690
12691static int
12692api_show_version (vat_main_t * vam)
12693{
12694 vl_api_show_version_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012695 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012696
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012697 M (SHOW_VERSION, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012698
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012699 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012700 W (ret);
12701 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012702}
12703
12704
12705static int
12706api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
12707{
12708 unformat_input_t *line_input = vam->input;
12709 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012710 ip46_address_t local, remote;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012711 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012712 u8 local_set = 0;
12713 u8 remote_set = 0;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012714 u8 grp_set = 0;
12715 u32 mcast_sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012716 u32 encap_vrf_id = 0;
12717 u32 decap_vrf_id = 0;
12718 u8 protocol = ~0;
12719 u32 vni;
12720 u8 vni_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012721 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012722
12723 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12724 {
12725 if (unformat (line_input, "del"))
12726 is_add = 0;
12727 else if (unformat (line_input, "local %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012728 unformat_ip46_address, &local))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012729 {
12730 local_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012731 }
12732 else if (unformat (line_input, "remote %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012733 unformat_ip46_address, &remote))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012734 {
12735 remote_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012736 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012737 else if (unformat (line_input, "group %U %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012738 unformat_ip46_address, &remote,
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012739 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12740 {
12741 grp_set = remote_set = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012742 }
12743 else if (unformat (line_input, "group %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012744 unformat_ip46_address, &remote))
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012745 {
12746 grp_set = remote_set = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012747 }
12748 else
12749 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
12750 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012751 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
12752 ;
12753 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
12754 ;
12755 else if (unformat (line_input, "vni %d", &vni))
12756 vni_set = 1;
12757 else if (unformat (line_input, "next-ip4"))
12758 protocol = 1;
12759 else if (unformat (line_input, "next-ip6"))
12760 protocol = 2;
12761 else if (unformat (line_input, "next-ethernet"))
12762 protocol = 3;
12763 else if (unformat (line_input, "next-nsh"))
12764 protocol = 4;
12765 else
12766 {
12767 errmsg ("parse error '%U'", format_unformat_error, line_input);
12768 return -99;
12769 }
12770 }
12771
12772 if (local_set == 0)
12773 {
12774 errmsg ("tunnel local address not specified");
12775 return -99;
12776 }
12777 if (remote_set == 0)
12778 {
12779 errmsg ("tunnel remote address not specified");
12780 return -99;
12781 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012782 if (grp_set && mcast_sw_if_index == ~0)
12783 {
12784 errmsg ("tunnel nonexistent multicast device");
12785 return -99;
12786 }
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012787 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012788 {
12789 errmsg ("both IPv4 and IPv6 addresses specified");
12790 return -99;
12791 }
12792
12793 if (vni_set == 0)
12794 {
12795 errmsg ("vni not specified");
12796 return -99;
12797 }
12798
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012799 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012800
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012801 ip_address_encode (&local,
12802 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
12803 IP46_TYPE_IP6, &mp->local);
12804 ip_address_encode (&remote,
12805 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
12806 IP46_TYPE_IP6, &mp->remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012807
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012808 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012809 mp->encap_vrf_id = ntohl (encap_vrf_id);
12810 mp->decap_vrf_id = ntohl (decap_vrf_id);
12811 mp->protocol = protocol;
12812 mp->vni = ntohl (vni);
12813 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012814
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012815 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012816 W (ret);
12817 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012818}
12819
12820static void vl_api_vxlan_gpe_tunnel_details_t_handler
12821 (vl_api_vxlan_gpe_tunnel_details_t * mp)
12822{
12823 vat_main_t *vam = &vat_main;
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012824 ip46_address_t local, remote;
12825
12826 ip_address_decode (&mp->local, &local);
12827 ip_address_decode (&mp->remote, &remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012828
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012829 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012830 ntohl (mp->sw_if_index),
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012831 format_ip46_address, &local, IP46_TYPE_ANY,
12832 format_ip46_address, &remote, IP46_TYPE_ANY,
12833 ntohl (mp->vni), mp->protocol,
12834 ntohl (mp->mcast_sw_if_index),
Damjan Marion7cd468a2016-12-19 23:05:39 +010012835 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
12836}
12837
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012838
Damjan Marion7cd468a2016-12-19 23:05:39 +010012839static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
12840 (vl_api_vxlan_gpe_tunnel_details_t * mp)
12841{
12842 vat_main_t *vam = &vat_main;
12843 vat_json_node_t *node = NULL;
12844 struct in_addr ip4;
12845 struct in6_addr ip6;
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012846 ip46_address_t local, remote;
12847
12848 ip_address_decode (&mp->local, &local);
12849 ip_address_decode (&mp->remote, &remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012850
12851 if (VAT_JSON_ARRAY != vam->json_tree.type)
12852 {
12853 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12854 vat_json_init_array (&vam->json_tree);
12855 }
12856 node = vat_json_array_add (&vam->json_tree);
12857
12858 vat_json_init_object (node);
12859 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012860 if (ip46_address_is_ip4 (&local))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012861 {
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012862 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
12863 vat_json_object_add_ip4 (node, "local", ip4);
12864 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
12865 vat_json_object_add_ip4 (node, "remote", ip4);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012866 }
12867 else
12868 {
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012869 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
12870 vat_json_object_add_ip6 (node, "local", ip6);
12871 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
12872 vat_json_object_add_ip6 (node, "remote", ip6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012873 }
12874 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
12875 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012876 vat_json_object_add_uint (node, "mcast_sw_if_index",
12877 ntohl (mp->mcast_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012878 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12879 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
12880 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
12881}
12882
12883static int
12884api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
12885{
12886 unformat_input_t *i = vam->input;
12887 vl_api_vxlan_gpe_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012888 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012889 u32 sw_if_index;
12890 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012891 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012892
12893 /* Parse args required to build the message */
12894 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12895 {
12896 if (unformat (i, "sw_if_index %d", &sw_if_index))
12897 sw_if_index_set = 1;
12898 else
12899 break;
12900 }
12901
12902 if (sw_if_index_set == 0)
12903 {
12904 sw_if_index = ~0;
12905 }
12906
12907 if (!vam->json_output)
12908 {
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012909 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012910 "sw_if_index", "local", "remote", "vni",
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012911 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010012912 }
12913
12914 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012915 M (VXLAN_GPE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012916
12917 mp->sw_if_index = htonl (sw_if_index);
12918
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012919 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012920
12921 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012922 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012923 S (mp_ping);
12924
Jon Loeliger56c7b012017-02-01 12:31:41 -060012925 W (ret);
12926 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012927}
12928
Ole Troan01384fe2017-05-12 11:55:35 +020012929static void vl_api_l2_fib_table_details_t_handler
12930 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010012931{
12932 vat_main_t *vam = &vat_main;
12933
12934 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
12935 " %d %d %d",
Mohsin Kazmi57938f62017-10-27 21:28:07 +020012936 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
Damjan Marion7cd468a2016-12-19 23:05:39 +010012937 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
12938 mp->bvi_mac);
12939}
12940
Ole Troan01384fe2017-05-12 11:55:35 +020012941static void vl_api_l2_fib_table_details_t_handler_json
12942 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010012943{
12944 vat_main_t *vam = &vat_main;
12945 vat_json_node_t *node = NULL;
12946
12947 if (VAT_JSON_ARRAY != vam->json_tree.type)
12948 {
12949 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12950 vat_json_init_array (&vam->json_tree);
12951 }
12952 node = vat_json_array_add (&vam->json_tree);
12953
12954 vat_json_init_object (node);
12955 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
Mohsin Kazmi57938f62017-10-27 21:28:07 +020012956 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012957 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12958 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
12959 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
12960 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
12961}
12962
12963static int
12964api_l2_fib_table_dump (vat_main_t * vam)
12965{
12966 unformat_input_t *i = vam->input;
12967 vl_api_l2_fib_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012968 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012969 u32 bd_id;
12970 u8 bd_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012971 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012972
12973 /* Parse args required to build the message */
12974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12975 {
12976 if (unformat (i, "bd_id %d", &bd_id))
12977 bd_id_set = 1;
12978 else
12979 break;
12980 }
12981
12982 if (bd_id_set == 0)
12983 {
12984 errmsg ("missing bridge domain");
12985 return -99;
12986 }
12987
12988 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
12989
12990 /* Get list of l2 fib entries */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012991 M (L2_FIB_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012992
12993 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012994 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012995
12996 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012997 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012998 S (mp_ping);
12999
Jon Loeliger56c7b012017-02-01 12:31:41 -060013000 W (ret);
13001 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013002}
13003
13004
13005static int
13006api_interface_name_renumber (vat_main_t * vam)
13007{
13008 unformat_input_t *line_input = vam->input;
13009 vl_api_interface_name_renumber_t *mp;
13010 u32 sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013011 u32 new_show_dev_instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013012 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013013
13014 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13015 {
13016 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
13017 &sw_if_index))
13018 ;
13019 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
13020 ;
13021 else if (unformat (line_input, "new_show_dev_instance %d",
13022 &new_show_dev_instance))
13023 ;
13024 else
13025 break;
13026 }
13027
13028 if (sw_if_index == ~0)
13029 {
13030 errmsg ("missing interface name or sw_if_index");
13031 return -99;
13032 }
13033
13034 if (new_show_dev_instance == ~0)
13035 {
13036 errmsg ("missing new_show_dev_instance");
13037 return -99;
13038 }
13039
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013040 M (INTERFACE_NAME_RENUMBER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013041
13042 mp->sw_if_index = ntohl (sw_if_index);
13043 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
13044
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013045 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013046 W (ret);
13047 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013048}
13049
13050static int
John Lo8d00fff2017-08-03 00:35:36 -040013051api_want_l2_macs_events (vat_main_t * vam)
13052{
13053 unformat_input_t *line_input = vam->input;
13054 vl_api_want_l2_macs_events_t *mp;
13055 u8 enable_disable = 1;
13056 u32 scan_delay = 0;
13057 u32 max_macs_in_event = 0;
13058 u32 learn_limit = 0;
13059 int ret;
13060
13061 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13062 {
13063 if (unformat (line_input, "learn-limit %d", &learn_limit))
13064 ;
13065 else if (unformat (line_input, "scan-delay %d", &scan_delay))
13066 ;
13067 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
13068 ;
13069 else if (unformat (line_input, "disable"))
13070 enable_disable = 0;
13071 else
13072 break;
13073 }
13074
13075 M (WANT_L2_MACS_EVENTS, mp);
13076 mp->enable_disable = enable_disable;
13077 mp->pid = htonl (getpid ());
13078 mp->learn_limit = htonl (learn_limit);
13079 mp->scan_delay = (u8) scan_delay;
13080 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
13081 S (mp);
13082 W (ret);
13083 return ret;
13084}
13085
13086static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010013087api_input_acl_set_interface (vat_main_t * vam)
13088{
13089 unformat_input_t *i = vam->input;
13090 vl_api_input_acl_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013091 u32 sw_if_index;
13092 int sw_if_index_set;
13093 u32 ip4_table_index = ~0;
13094 u32 ip6_table_index = ~0;
13095 u32 l2_table_index = ~0;
13096 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013097 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013098
13099 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13100 {
13101 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13102 sw_if_index_set = 1;
13103 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13104 sw_if_index_set = 1;
13105 else if (unformat (i, "del"))
13106 is_add = 0;
13107 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13108 ;
13109 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13110 ;
13111 else if (unformat (i, "l2-table %d", &l2_table_index))
13112 ;
13113 else
13114 {
13115 clib_warning ("parse error '%U'", format_unformat_error, i);
13116 return -99;
13117 }
13118 }
13119
13120 if (sw_if_index_set == 0)
13121 {
13122 errmsg ("missing interface name or sw_if_index");
13123 return -99;
13124 }
13125
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013126 M (INPUT_ACL_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013127
13128 mp->sw_if_index = ntohl (sw_if_index);
13129 mp->ip4_table_index = ntohl (ip4_table_index);
13130 mp->ip6_table_index = ntohl (ip6_table_index);
13131 mp->l2_table_index = ntohl (l2_table_index);
13132 mp->is_add = is_add;
13133
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013134 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013135 W (ret);
13136 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013137}
13138
13139static int
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010013140api_output_acl_set_interface (vat_main_t * vam)
13141{
13142 unformat_input_t *i = vam->input;
13143 vl_api_output_acl_set_interface_t *mp;
13144 u32 sw_if_index;
13145 int sw_if_index_set;
13146 u32 ip4_table_index = ~0;
13147 u32 ip6_table_index = ~0;
13148 u32 l2_table_index = ~0;
13149 u8 is_add = 1;
13150 int ret;
13151
13152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13153 {
13154 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13155 sw_if_index_set = 1;
13156 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13157 sw_if_index_set = 1;
13158 else if (unformat (i, "del"))
13159 is_add = 0;
13160 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13161 ;
13162 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13163 ;
13164 else if (unformat (i, "l2-table %d", &l2_table_index))
13165 ;
13166 else
13167 {
13168 clib_warning ("parse error '%U'", format_unformat_error, i);
13169 return -99;
13170 }
13171 }
13172
13173 if (sw_if_index_set == 0)
13174 {
13175 errmsg ("missing interface name or sw_if_index");
13176 return -99;
13177 }
13178
13179 M (OUTPUT_ACL_SET_INTERFACE, mp);
13180
13181 mp->sw_if_index = ntohl (sw_if_index);
13182 mp->ip4_table_index = ntohl (ip4_table_index);
13183 mp->ip6_table_index = ntohl (ip6_table_index);
13184 mp->l2_table_index = ntohl (l2_table_index);
13185 mp->is_add = is_add;
13186
13187 S (mp);
13188 W (ret);
13189 return ret;
13190}
13191
13192static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010013193api_ip_address_dump (vat_main_t * vam)
13194{
13195 unformat_input_t *i = vam->input;
13196 vl_api_ip_address_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013197 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013198 u32 sw_if_index = ~0;
13199 u8 sw_if_index_set = 0;
13200 u8 ipv4_set = 0;
13201 u8 ipv6_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013202 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013203
13204 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13205 {
13206 if (unformat (i, "sw_if_index %d", &sw_if_index))
13207 sw_if_index_set = 1;
13208 else
13209 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13210 sw_if_index_set = 1;
13211 else if (unformat (i, "ipv4"))
13212 ipv4_set = 1;
13213 else if (unformat (i, "ipv6"))
13214 ipv6_set = 1;
13215 else
13216 break;
13217 }
13218
13219 if (ipv4_set && ipv6_set)
13220 {
13221 errmsg ("ipv4 and ipv6 flags cannot be both set");
13222 return -99;
13223 }
13224
13225 if ((!ipv4_set) && (!ipv6_set))
13226 {
13227 errmsg ("no ipv4 nor ipv6 flag set");
13228 return -99;
13229 }
13230
13231 if (sw_if_index_set == 0)
13232 {
13233 errmsg ("missing interface name or sw_if_index");
13234 return -99;
13235 }
13236
13237 vam->current_sw_if_index = sw_if_index;
13238 vam->is_ipv6 = ipv6_set;
13239
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013240 M (IP_ADDRESS_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013241 mp->sw_if_index = ntohl (sw_if_index);
13242 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013243 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013244
13245 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013246 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013247 S (mp_ping);
13248
Jon Loeliger56c7b012017-02-01 12:31:41 -060013249 W (ret);
13250 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013251}
13252
13253static int
13254api_ip_dump (vat_main_t * vam)
13255{
13256 vl_api_ip_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013257 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013258 unformat_input_t *in = vam->input;
13259 int ipv4_set = 0;
13260 int ipv6_set = 0;
13261 int is_ipv6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013262 int i;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013263 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013264
13265 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
13266 {
13267 if (unformat (in, "ipv4"))
13268 ipv4_set = 1;
13269 else if (unformat (in, "ipv6"))
13270 ipv6_set = 1;
13271 else
13272 break;
13273 }
13274
13275 if (ipv4_set && ipv6_set)
13276 {
13277 errmsg ("ipv4 and ipv6 flags cannot be both set");
13278 return -99;
13279 }
13280
13281 if ((!ipv4_set) && (!ipv6_set))
13282 {
13283 errmsg ("no ipv4 nor ipv6 flag set");
13284 return -99;
13285 }
13286
13287 is_ipv6 = ipv6_set;
13288 vam->is_ipv6 = is_ipv6;
13289
13290 /* free old data */
13291 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
13292 {
13293 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
13294 }
13295 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
13296
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013297 M (IP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013298 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013299 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013300
13301 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013302 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013303 S (mp_ping);
13304
Jon Loeliger56c7b012017-02-01 12:31:41 -060013305 W (ret);
13306 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013307}
13308
13309static int
13310api_ipsec_spd_add_del (vat_main_t * vam)
13311{
13312 unformat_input_t *i = vam->input;
13313 vl_api_ipsec_spd_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013314 u32 spd_id = ~0;
13315 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013316 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013317
13318 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13319 {
13320 if (unformat (i, "spd_id %d", &spd_id))
13321 ;
13322 else if (unformat (i, "del"))
13323 is_add = 0;
13324 else
13325 {
13326 clib_warning ("parse error '%U'", format_unformat_error, i);
13327 return -99;
13328 }
13329 }
13330 if (spd_id == ~0)
13331 {
13332 errmsg ("spd_id must be set");
13333 return -99;
13334 }
13335
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013336 M (IPSEC_SPD_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013337
13338 mp->spd_id = ntohl (spd_id);
13339 mp->is_add = is_add;
13340
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013341 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013342 W (ret);
13343 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013344}
13345
13346static int
13347api_ipsec_interface_add_del_spd (vat_main_t * vam)
13348{
13349 unformat_input_t *i = vam->input;
13350 vl_api_ipsec_interface_add_del_spd_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013351 u32 sw_if_index;
13352 u8 sw_if_index_set = 0;
13353 u32 spd_id = (u32) ~ 0;
13354 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013355 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013356
13357 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13358 {
13359 if (unformat (i, "del"))
13360 is_add = 0;
13361 else if (unformat (i, "spd_id %d", &spd_id))
13362 ;
13363 else
13364 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13365 sw_if_index_set = 1;
13366 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13367 sw_if_index_set = 1;
13368 else
13369 {
13370 clib_warning ("parse error '%U'", format_unformat_error, i);
13371 return -99;
13372 }
13373
13374 }
13375
13376 if (spd_id == (u32) ~ 0)
13377 {
13378 errmsg ("spd_id must be set");
13379 return -99;
13380 }
13381
13382 if (sw_if_index_set == 0)
13383 {
13384 errmsg ("missing interface name or sw_if_index");
13385 return -99;
13386 }
13387
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013388 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013389
13390 mp->spd_id = ntohl (spd_id);
13391 mp->sw_if_index = ntohl (sw_if_index);
13392 mp->is_add = is_add;
13393
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013394 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013395 W (ret);
13396 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013397}
13398
13399static int
Neale Ranns17dcec02019-01-09 21:22:20 -080013400api_ipsec_spd_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013401{
13402 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080013403 vl_api_ipsec_spd_entry_add_del_t *mp;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013404 u8 is_add = 1, is_outbound = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013405 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
13406 i32 priority = 0;
13407 u32 rport_start = 0, rport_stop = (u32) ~ 0;
13408 u32 lport_start = 0, lport_stop = (u32) ~ 0;
Neale Ranns17dcec02019-01-09 21:22:20 -080013409 vl_api_address_t laddr_start = { }, laddr_stop =
13410 {
13411 }, raddr_start =
13412 {
13413 }, raddr_stop =
13414 {
13415 };
Jon Loeliger56c7b012017-02-01 12:31:41 -060013416 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013417
Damjan Marion7cd468a2016-12-19 23:05:39 +010013418 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13419 {
13420 if (unformat (i, "del"))
13421 is_add = 0;
13422 if (unformat (i, "outbound"))
13423 is_outbound = 1;
13424 if (unformat (i, "inbound"))
13425 is_outbound = 0;
13426 else if (unformat (i, "spd_id %d", &spd_id))
13427 ;
13428 else if (unformat (i, "sa_id %d", &sa_id))
13429 ;
13430 else if (unformat (i, "priority %d", &priority))
13431 ;
13432 else if (unformat (i, "protocol %d", &protocol))
13433 ;
13434 else if (unformat (i, "lport_start %d", &lport_start))
13435 ;
13436 else if (unformat (i, "lport_stop %d", &lport_stop))
13437 ;
13438 else if (unformat (i, "rport_start %d", &rport_start))
13439 ;
13440 else if (unformat (i, "rport_stop %d", &rport_stop))
13441 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013442 else if (unformat (i, "laddr_start %U",
13443 unformat_vl_api_address, &laddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013444 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013445 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
13446 &laddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013447 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013448 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
13449 &raddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013450 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013451 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
13452 &raddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013453 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013454 else
13455 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
13456 {
13457 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
13458 {
13459 clib_warning ("unsupported action: 'resolve'");
13460 return -99;
13461 }
13462 }
13463 else
13464 {
13465 clib_warning ("parse error '%U'", format_unformat_error, i);
13466 return -99;
13467 }
13468
13469 }
13470
Neale Ranns17dcec02019-01-09 21:22:20 -080013471 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013472
Damjan Marion7cd468a2016-12-19 23:05:39 +010013473 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080013474
13475 mp->entry.spd_id = ntohl (spd_id);
13476 mp->entry.priority = ntohl (priority);
13477 mp->entry.is_outbound = is_outbound;
13478
13479 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
13480 sizeof (vl_api_address_t));
13481 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
13482 sizeof (vl_api_address_t));
13483 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
13484 sizeof (vl_api_address_t));
13485 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
13486 sizeof (vl_api_address_t));
13487
13488 mp->entry.protocol = (u8) protocol;
13489 mp->entry.local_port_start = ntohs ((u16) lport_start);
13490 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
13491 mp->entry.remote_port_start = ntohs ((u16) rport_start);
13492 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
13493 mp->entry.policy = (u8) policy;
13494 mp->entry.sa_id = ntohl (sa_id);
Neale Ranns17dcec02019-01-09 21:22:20 -080013495
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013496 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013497 W (ret);
13498 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013499}
13500
13501static int
Neale Ranns17dcec02019-01-09 21:22:20 -080013502api_ipsec_sad_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013503{
13504 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080013505 vl_api_ipsec_sad_entry_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013506 u32 sad_id = 0, spi = 0;
13507 u8 *ck = 0, *ik = 0;
13508 u8 is_add = 1;
13509
Neale Ranns17dcec02019-01-09 21:22:20 -080013510 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
13511 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
13512 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
13513 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
13514 vl_api_address_t tun_src, tun_dst;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013515 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013516
13517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13518 {
13519 if (unformat (i, "del"))
13520 is_add = 0;
13521 else if (unformat (i, "sad_id %d", &sad_id))
13522 ;
13523 else if (unformat (i, "spi %d", &spi))
13524 ;
13525 else if (unformat (i, "esp"))
Neale Ranns17dcec02019-01-09 21:22:20 -080013526 protocol = IPSEC_API_PROTO_ESP;
13527 else
13528 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
Damjan Marion7cd468a2016-12-19 23:05:39 +010013529 {
Neale Ranns17dcec02019-01-09 21:22:20 -080013530 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
13531 if (ADDRESS_IP6 == tun_src.af)
13532 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013533 }
13534 else
Neale Ranns17dcec02019-01-09 21:22:20 -080013535 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
Damjan Marion7cd468a2016-12-19 23:05:39 +010013536 {
Neale Ranns17dcec02019-01-09 21:22:20 -080013537 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
13538 if (ADDRESS_IP6 == tun_src.af)
13539 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013540 }
Neale Ranns17dcec02019-01-09 21:22:20 -080013541 else
13542 if (unformat (i, "crypto_alg %U",
13543 unformat_ipsec_api_crypto_alg, &crypto_alg))
13544 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013545 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
13546 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013547 else if (unformat (i, "integ_alg %U",
13548 unformat_ipsec_api_integ_alg, &integ_alg))
13549 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013550 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
13551 ;
13552 else
13553 {
13554 clib_warning ("parse error '%U'", format_unformat_error, i);
13555 return -99;
13556 }
13557
13558 }
13559
Neale Ranns17dcec02019-01-09 21:22:20 -080013560 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013561
Damjan Marion7cd468a2016-12-19 23:05:39 +010013562 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080013563 mp->entry.sad_id = ntohl (sad_id);
13564 mp->entry.protocol = protocol;
13565 mp->entry.spi = ntohl (spi);
13566 mp->entry.flags = flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013567
Neale Ranns17dcec02019-01-09 21:22:20 -080013568 mp->entry.crypto_algorithm = crypto_alg;
13569 mp->entry.integrity_algorithm = integ_alg;
13570 mp->entry.crypto_key.length = vec_len (ck);
13571 mp->entry.integrity_key.length = vec_len (ik);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013572
Neale Ranns17dcec02019-01-09 21:22:20 -080013573 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
13574 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
13575
13576 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
13577 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013578
13579 if (ck)
Neale Ranns17dcec02019-01-09 21:22:20 -080013580 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013581 if (ik)
Neale Ranns17dcec02019-01-09 21:22:20 -080013582 clib_memcpy (mp->entry.integrity_key.data, ik,
13583 mp->entry.integrity_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013584
Neale Ranns17dcec02019-01-09 21:22:20 -080013585 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013586 {
Neale Ranns17dcec02019-01-09 21:22:20 -080013587 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
13588 sizeof (mp->entry.tunnel_src));
13589 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
13590 sizeof (mp->entry.tunnel_dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013591 }
13592
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013593 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013594 W (ret);
13595 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013596}
13597
13598static int
Matthew Smithb0972cb2017-05-02 16:20:41 -050013599api_ipsec_tunnel_if_add_del (vat_main_t * vam)
13600{
13601 unformat_input_t *i = vam->input;
13602 vl_api_ipsec_tunnel_if_add_del_t *mp;
13603 u32 local_spi = 0, remote_spi = 0;
13604 u32 crypto_alg = 0, integ_alg = 0;
13605 u8 *lck = NULL, *rck = NULL;
13606 u8 *lik = NULL, *rik = NULL;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040013607 vl_api_address_t local_ip = { 0 };
13608 vl_api_address_t remote_ip = { 0 };
Neale Ranns2b5ba952019-04-02 10:15:40 +000013609 f64 before = 0;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013610 u8 is_add = 1;
13611 u8 esn = 0;
13612 u8 anti_replay = 0;
Matthew Smith8e1039a2018-04-12 07:32:56 -050013613 u8 renumber = 0;
13614 u32 instance = ~0;
Neale Ranns2b5ba952019-04-02 10:15:40 +000013615 u32 count = 1, jj;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013616 int ret = -1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013617
13618 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13619 {
13620 if (unformat (i, "del"))
13621 is_add = 0;
13622 else if (unformat (i, "esn"))
13623 esn = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000013624 else if (unformat (i, "anti-replay"))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013625 anti_replay = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000013626 else if (unformat (i, "count %d", &count))
13627 ;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013628 else if (unformat (i, "local_spi %d", &local_spi))
13629 ;
13630 else if (unformat (i, "remote_spi %d", &remote_spi))
13631 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040013632 else
13633 if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013634 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040013635 else
13636 if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013637 ;
13638 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
13639 ;
13640 else
13641 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
13642 ;
13643 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
13644 ;
13645 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
13646 ;
13647 else
13648 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080013649 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013650 {
Dave Baracha8d47642018-07-13 11:22:23 -040013651 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013652 {
13653 errmsg ("unsupported crypto-alg: '%U'\n",
13654 format_ipsec_crypto_alg, crypto_alg);
13655 return -99;
13656 }
13657 }
13658 else
13659 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080013660 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013661 {
Dave Baracha8d47642018-07-13 11:22:23 -040013662 if (integ_alg >= IPSEC_INTEG_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013663 {
13664 errmsg ("unsupported integ-alg: '%U'\n",
13665 format_ipsec_integ_alg, integ_alg);
13666 return -99;
13667 }
13668 }
Matthew Smith8e1039a2018-04-12 07:32:56 -050013669 else if (unformat (i, "instance %u", &instance))
13670 renumber = 1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013671 else
13672 {
13673 errmsg ("parse error '%U'\n", format_unformat_error, i);
13674 return -99;
13675 }
13676 }
13677
Neale Ranns2b5ba952019-04-02 10:15:40 +000013678 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013679 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000013680 /* Turn on async mode */
13681 vam->async_mode = 1;
13682 vam->async_errors = 0;
13683 before = vat_time_now (vam);
Matthew Smithb0972cb2017-05-02 16:20:41 -050013684 }
13685
Neale Ranns2b5ba952019-04-02 10:15:40 +000013686 for (jj = 0; jj < count; jj++)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013687 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000013688 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
13689
13690 mp->is_add = is_add;
13691 mp->esn = esn;
13692 mp->anti_replay = anti_replay;
13693
13694 if (jj > 0)
Neale Ranns097fa662018-05-01 05:17:55 -070013695 increment_address (&remote_ip);
Neale Ranns2b5ba952019-04-02 10:15:40 +000013696
13697 clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
13698 clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
13699
13700 mp->local_spi = htonl (local_spi + jj);
13701 mp->remote_spi = htonl (remote_spi + jj);
13702 mp->crypto_alg = (u8) crypto_alg;
13703
13704 mp->local_crypto_key_len = 0;
13705 if (lck)
13706 {
13707 mp->local_crypto_key_len = vec_len (lck);
13708 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
13709 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
13710 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
13711 }
13712
13713 mp->remote_crypto_key_len = 0;
13714 if (rck)
13715 {
13716 mp->remote_crypto_key_len = vec_len (rck);
13717 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
13718 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
13719 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
13720 }
13721
13722 mp->integ_alg = (u8) integ_alg;
13723
13724 mp->local_integ_key_len = 0;
13725 if (lik)
13726 {
13727 mp->local_integ_key_len = vec_len (lik);
13728 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
13729 mp->local_integ_key_len = sizeof (mp->local_integ_key);
13730 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
13731 }
13732
13733 mp->remote_integ_key_len = 0;
13734 if (rik)
13735 {
13736 mp->remote_integ_key_len = vec_len (rik);
13737 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
13738 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
13739 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
13740 }
13741
13742 if (renumber)
13743 {
13744 mp->renumber = renumber;
13745 mp->show_instance = ntohl (instance);
13746 }
13747 S (mp);
Matthew Smithb0972cb2017-05-02 16:20:41 -050013748 }
13749
Neale Ranns2b5ba952019-04-02 10:15:40 +000013750 /* When testing multiple add/del ops, use a control-ping to sync */
13751 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013752 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000013753 vl_api_control_ping_t *mp_ping;
13754 f64 after;
13755 f64 timeout;
13756
13757 /* Shut off async mode */
13758 vam->async_mode = 0;
13759
13760 MPING (CONTROL_PING, mp_ping);
13761 S (mp_ping);
13762
13763 timeout = vat_time_now (vam) + 1.0;
13764 while (vat_time_now (vam) < timeout)
13765 if (vam->result_ready == 1)
13766 goto out;
13767 vam->retval = -99;
13768
13769 out:
13770 if (vam->retval == -99)
13771 errmsg ("timeout");
13772
13773 if (vam->async_errors > 0)
13774 {
13775 errmsg ("%d asynchronous errors", vam->async_errors);
13776 vam->retval = -98;
13777 }
13778 vam->async_errors = 0;
13779 after = vat_time_now (vam);
13780
13781 /* slim chance, but we might have eaten SIGTERM on the first iteration */
13782 if (jj > 0)
13783 count = jj;
13784
13785 print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec",
13786 count, after - before, count / (after - before));
13787 }
13788 else
13789 {
13790 /* Wait for a reply... */
13791 W (ret);
13792 return ret;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013793 }
13794
Matthew Smithb0972cb2017-05-02 16:20:41 -050013795 return ret;
13796}
13797
Matthew Smith28029532017-09-26 13:33:44 -050013798static void
13799vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
13800{
13801 vat_main_t *vam = &vat_main;
13802
13803 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
Neale Ranns8d7c5022019-02-06 01:41:05 -080013804 "crypto_key %U integ_alg %u integ_key %U flags %x "
Matthew Smith28029532017-09-26 13:33:44 -050013805 "tunnel_src_addr %U tunnel_dst_addr %U "
13806 "salt %u seq_outbound %lu last_seq_inbound %lu "
Neale Rannseba31ec2019-02-17 18:04:27 +000013807 "replay_window %lu\n",
Neale Ranns8d7c5022019-02-06 01:41:05 -080013808 ntohl (mp->entry.sad_id),
13809 ntohl (mp->sw_if_index),
13810 ntohl (mp->entry.spi),
13811 ntohl (mp->entry.protocol),
13812 ntohl (mp->entry.crypto_algorithm),
13813 format_hex_bytes, mp->entry.crypto_key.data,
13814 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
13815 format_hex_bytes, mp->entry.integrity_key.data,
13816 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
13817 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
13818 &mp->entry.tunnel_dst, ntohl (mp->salt),
Matthew Smith28029532017-09-26 13:33:44 -050013819 clib_net_to_host_u64 (mp->seq_outbound),
13820 clib_net_to_host_u64 (mp->last_seq_inbound),
Neale Rannseba31ec2019-02-17 18:04:27 +000013821 clib_net_to_host_u64 (mp->replay_window));
Matthew Smith28029532017-09-26 13:33:44 -050013822}
13823
13824#define vl_api_ipsec_sa_details_t_endian vl_noop_handler
13825#define vl_api_ipsec_sa_details_t_print vl_noop_handler
13826
13827static void vl_api_ipsec_sa_details_t_handler_json
13828 (vl_api_ipsec_sa_details_t * mp)
13829{
13830 vat_main_t *vam = &vat_main;
13831 vat_json_node_t *node = NULL;
Neale Ranns8d7c5022019-02-06 01:41:05 -080013832 vl_api_ipsec_sad_flags_t flags;
Matthew Smith28029532017-09-26 13:33:44 -050013833
13834 if (VAT_JSON_ARRAY != vam->json_tree.type)
13835 {
13836 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13837 vat_json_init_array (&vam->json_tree);
13838 }
13839 node = vat_json_array_add (&vam->json_tree);
13840
13841 vat_json_init_object (node);
Neale Ranns8d7c5022019-02-06 01:41:05 -080013842 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
Matthew Smith28029532017-09-26 13:33:44 -050013843 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Neale Ranns8d7c5022019-02-06 01:41:05 -080013844 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
13845 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
13846 vat_json_object_add_uint (node, "crypto_alg",
13847 ntohl (mp->entry.crypto_algorithm));
13848 vat_json_object_add_uint (node, "integ_alg",
13849 ntohl (mp->entry.integrity_algorithm));
13850 flags = ntohl (mp->entry.flags);
13851 vat_json_object_add_uint (node, "use_esn",
Damjan Marion1e3aa5e2019-03-28 10:58:59 +010013852 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
Neale Ranns8d7c5022019-02-06 01:41:05 -080013853 vat_json_object_add_uint (node, "use_anti_replay",
13854 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
13855 vat_json_object_add_uint (node, "is_tunnel",
13856 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
13857 vat_json_object_add_uint (node, "is_tunnel_ip6",
13858 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
13859 vat_json_object_add_uint (node, "udp_encap",
13860 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
13861 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
13862 mp->entry.crypto_key.length);
13863 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
13864 mp->entry.integrity_key.length);
Neale Ranns5a8844b2019-04-16 07:15:35 +000013865 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
13866 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
Matthew Smith28029532017-09-26 13:33:44 -050013867 vat_json_object_add_uint (node, "replay_window",
13868 clib_net_to_host_u64 (mp->replay_window));
Matthew Smith28029532017-09-26 13:33:44 -050013869}
13870
13871static int
13872api_ipsec_sa_dump (vat_main_t * vam)
13873{
13874 unformat_input_t *i = vam->input;
13875 vl_api_ipsec_sa_dump_t *mp;
13876 vl_api_control_ping_t *mp_ping;
13877 u32 sa_id = ~0;
13878 int ret;
13879
13880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13881 {
13882 if (unformat (i, "sa_id %d", &sa_id))
13883 ;
13884 else
13885 {
13886 clib_warning ("parse error '%U'", format_unformat_error, i);
13887 return -99;
13888 }
13889 }
13890
13891 M (IPSEC_SA_DUMP, mp);
13892
13893 mp->sa_id = ntohl (sa_id);
13894
13895 S (mp);
13896
13897 /* Use a control ping for synchronization */
13898 M (CONTROL_PING, mp_ping);
13899 S (mp_ping);
13900
13901 W (ret);
13902 return ret;
13903}
13904
Matthew Smithb0972cb2017-05-02 16:20:41 -050013905static int
Matthew Smithca514fd2017-10-12 12:06:59 -050013906api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
13907{
13908 unformat_input_t *i = vam->input;
13909 vl_api_ipsec_tunnel_if_set_sa_t *mp;
13910 u32 sw_if_index = ~0;
13911 u32 sa_id = ~0;
13912 u8 is_outbound = (u8) ~ 0;
13913 int ret;
13914
13915 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13916 {
13917 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13918 ;
13919 else if (unformat (i, "sa_id %d", &sa_id))
13920 ;
13921 else if (unformat (i, "outbound"))
13922 is_outbound = 1;
13923 else if (unformat (i, "inbound"))
13924 is_outbound = 0;
13925 else
13926 {
13927 clib_warning ("parse error '%U'", format_unformat_error, i);
13928 return -99;
13929 }
13930 }
13931
13932 if (sw_if_index == ~0)
13933 {
13934 errmsg ("interface must be specified");
13935 return -99;
13936 }
13937
13938 if (sa_id == ~0)
13939 {
13940 errmsg ("SA ID must be specified");
13941 return -99;
13942 }
13943
13944 M (IPSEC_TUNNEL_IF_SET_SA, mp);
13945
13946 mp->sw_if_index = htonl (sw_if_index);
13947 mp->sa_id = htonl (sa_id);
13948 mp->is_outbound = is_outbound;
13949
13950 S (mp);
13951 W (ret);
13952
13953 return ret;
13954}
13955
13956static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010013957api_get_first_msg_id (vat_main_t * vam)
13958{
13959 vl_api_get_first_msg_id_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013960 unformat_input_t *i = vam->input;
13961 u8 *name;
13962 u8 name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013963 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013964
13965 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13966 {
13967 if (unformat (i, "client %s", &name))
13968 name_set = 1;
13969 else
13970 break;
13971 }
13972
13973 if (name_set == 0)
13974 {
13975 errmsg ("missing client name");
13976 return -99;
13977 }
13978 vec_add1 (name, 0);
13979
13980 if (vec_len (name) > 63)
13981 {
13982 errmsg ("client name too long");
13983 return -99;
13984 }
13985
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013986 M (GET_FIRST_MSG_ID, mp);
Ole Troan7adaa222019-08-27 15:05:27 +020013987 clib_memcpy (mp->name, name, vec_len (name));
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013988 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013989 W (ret);
13990 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013991}
13992
13993static int
13994api_cop_interface_enable_disable (vat_main_t * vam)
13995{
13996 unformat_input_t *line_input = vam->input;
13997 vl_api_cop_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013998 u32 sw_if_index = ~0;
13999 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014000 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014001
14002 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14003 {
14004 if (unformat (line_input, "disable"))
14005 enable_disable = 0;
14006 if (unformat (line_input, "enable"))
14007 enable_disable = 1;
14008 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
14009 vam, &sw_if_index))
14010 ;
14011 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
14012 ;
14013 else
14014 break;
14015 }
14016
14017 if (sw_if_index == ~0)
14018 {
14019 errmsg ("missing interface name or sw_if_index");
14020 return -99;
14021 }
14022
14023 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014024 M (COP_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014025 mp->sw_if_index = ntohl (sw_if_index);
14026 mp->enable_disable = enable_disable;
14027
14028 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014029 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014030 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014031 W (ret);
14032 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014033}
14034
14035static int
14036api_cop_whitelist_enable_disable (vat_main_t * vam)
14037{
14038 unformat_input_t *line_input = vam->input;
14039 vl_api_cop_whitelist_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014040 u32 sw_if_index = ~0;
14041 u8 ip4 = 0, ip6 = 0, default_cop = 0;
14042 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014043 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014044
14045 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14046 {
14047 if (unformat (line_input, "ip4"))
14048 ip4 = 1;
14049 else if (unformat (line_input, "ip6"))
14050 ip6 = 1;
14051 else if (unformat (line_input, "default"))
14052 default_cop = 1;
14053 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
14054 vam, &sw_if_index))
14055 ;
14056 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
14057 ;
14058 else if (unformat (line_input, "fib-id %d", &fib_id))
14059 ;
14060 else
14061 break;
14062 }
14063
14064 if (sw_if_index == ~0)
14065 {
14066 errmsg ("missing interface name or sw_if_index");
14067 return -99;
14068 }
14069
14070 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014071 M (COP_WHITELIST_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014072 mp->sw_if_index = ntohl (sw_if_index);
14073 mp->fib_id = ntohl (fib_id);
14074 mp->ip4 = ip4;
14075 mp->ip6 = ip6;
14076 mp->default_cop = default_cop;
14077
14078 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014079 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014080 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014081 W (ret);
14082 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014083}
14084
14085static int
14086api_get_node_graph (vat_main_t * vam)
14087{
14088 vl_api_get_node_graph_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014089 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014090
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014091 M (GET_NODE_GRAPH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014092
14093 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014094 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014095 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014096 W (ret);
14097 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014098}
14099
14100/* *INDENT-OFF* */
14101/** Used for parsing LISP eids */
14102typedef CLIB_PACKED(struct{
14103 u8 addr[16]; /**< eid address */
14104 u32 len; /**< prefix length if IP */
14105 u8 type; /**< type of eid */
14106}) lisp_eid_vat_t;
14107/* *INDENT-ON* */
14108
14109static uword
14110unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
14111{
14112 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
14113
Dave Barachb7b92992018-10-17 10:38:51 -040014114 clib_memset (a, 0, sizeof (a[0]));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014115
14116 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
14117 {
14118 a->type = 0; /* ipv4 type */
14119 }
14120 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
14121 {
14122 a->type = 1; /* ipv6 type */
14123 }
14124 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
14125 {
14126 a->type = 2; /* mac type */
14127 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020014128 else if (unformat (input, "%U", unformat_nsh_address, a->addr))
14129 {
14130 a->type = 3; /* NSH type */
14131 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) a->addr;
14132 nsh->spi = clib_host_to_net_u32 (nsh->spi);
14133 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010014134 else
14135 {
14136 return 0;
14137 }
14138
14139 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
14140 {
14141 return 0;
14142 }
14143
14144 return 1;
14145}
14146
14147static int
14148lisp_eid_size_vat (u8 type)
14149{
14150 switch (type)
14151 {
14152 case 0:
14153 return 4;
14154 case 1:
14155 return 16;
14156 case 2:
14157 return 6;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020014158 case 3:
14159 return 5;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014160 }
14161 return 0;
14162}
14163
14164static void
14165lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
14166{
14167 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
14168}
14169
Damjan Marion7cd468a2016-12-19 23:05:39 +010014170static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014171api_one_add_del_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014172{
14173 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014174 vl_api_one_add_del_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014175 u8 is_add = 1;
14176 u8 *locator_set_name = NULL;
14177 u8 locator_set_name_set = 0;
Filip Tehlar05a057b2017-02-01 08:50:31 +010014178 vl_api_local_locator_t locator, *locators = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014179 u32 sw_if_index, priority, weight;
14180 u32 data_len = 0;
14181
Jon Loeliger56c7b012017-02-01 12:31:41 -060014182 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014183 /* Parse args required to build the message */
14184 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14185 {
14186 if (unformat (input, "del"))
14187 {
14188 is_add = 0;
14189 }
14190 else if (unformat (input, "locator-set %s", &locator_set_name))
14191 {
14192 locator_set_name_set = 1;
14193 }
14194 else if (unformat (input, "sw_if_index %u p %u w %u",
14195 &sw_if_index, &priority, &weight))
14196 {
14197 locator.sw_if_index = htonl (sw_if_index);
14198 locator.priority = priority;
14199 locator.weight = weight;
14200 vec_add1 (locators, locator);
14201 }
14202 else
14203 if (unformat
14204 (input, "iface %U p %u w %u", api_unformat_sw_if_index, vam,
14205 &sw_if_index, &priority, &weight))
14206 {
14207 locator.sw_if_index = htonl (sw_if_index);
14208 locator.priority = priority;
14209 locator.weight = weight;
14210 vec_add1 (locators, locator);
14211 }
14212 else
14213 break;
14214 }
14215
14216 if (locator_set_name_set == 0)
14217 {
14218 errmsg ("missing locator-set name");
14219 vec_free (locators);
14220 return -99;
14221 }
14222
14223 if (vec_len (locator_set_name) > 64)
14224 {
14225 errmsg ("locator-set name too long");
14226 vec_free (locator_set_name);
14227 vec_free (locators);
14228 return -99;
14229 }
14230 vec_add1 (locator_set_name, 0);
14231
Filip Tehlar05a057b2017-02-01 08:50:31 +010014232 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014233
14234 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014235 M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014236
14237 mp->is_add = is_add;
14238 clib_memcpy (mp->locator_set_name, locator_set_name,
14239 vec_len (locator_set_name));
14240 vec_free (locator_set_name);
14241
14242 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
14243 if (locators)
14244 clib_memcpy (mp->locators, locators, data_len);
14245 vec_free (locators);
14246
14247 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014248 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014249
14250 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014251 W (ret);
14252 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014253}
14254
Filip Tehlar694396d2017-02-17 14:29:11 +010014255#define api_lisp_add_del_locator_set api_one_add_del_locator_set
14256
Damjan Marion7cd468a2016-12-19 23:05:39 +010014257static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014258api_one_add_del_locator (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014259{
14260 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014261 vl_api_one_add_del_locator_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014262 u32 tmp_if_index = ~0;
14263 u32 sw_if_index = ~0;
14264 u8 sw_if_index_set = 0;
14265 u8 sw_if_index_if_name_set = 0;
14266 u32 priority = ~0;
14267 u8 priority_set = 0;
14268 u32 weight = ~0;
14269 u8 weight_set = 0;
14270 u8 is_add = 1;
14271 u8 *locator_set_name = NULL;
14272 u8 locator_set_name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014273 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014274
14275 /* Parse args required to build the message */
14276 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14277 {
14278 if (unformat (input, "del"))
14279 {
14280 is_add = 0;
14281 }
14282 else if (unformat (input, "locator-set %s", &locator_set_name))
14283 {
14284 locator_set_name_set = 1;
14285 }
14286 else if (unformat (input, "iface %U", api_unformat_sw_if_index, vam,
14287 &tmp_if_index))
14288 {
14289 sw_if_index_if_name_set = 1;
14290 sw_if_index = tmp_if_index;
14291 }
14292 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
14293 {
14294 sw_if_index_set = 1;
14295 sw_if_index = tmp_if_index;
14296 }
14297 else if (unformat (input, "p %d", &priority))
14298 {
14299 priority_set = 1;
14300 }
14301 else if (unformat (input, "w %d", &weight))
14302 {
14303 weight_set = 1;
14304 }
14305 else
14306 break;
14307 }
14308
14309 if (locator_set_name_set == 0)
14310 {
14311 errmsg ("missing locator-set name");
14312 return -99;
14313 }
14314
14315 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
14316 {
14317 errmsg ("missing sw_if_index");
14318 vec_free (locator_set_name);
14319 return -99;
14320 }
14321
14322 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
14323 {
14324 errmsg ("cannot use both params interface name and sw_if_index");
14325 vec_free (locator_set_name);
14326 return -99;
14327 }
14328
14329 if (priority_set == 0)
14330 {
14331 errmsg ("missing locator-set priority");
14332 vec_free (locator_set_name);
14333 return -99;
14334 }
14335
14336 if (weight_set == 0)
14337 {
14338 errmsg ("missing locator-set weight");
14339 vec_free (locator_set_name);
14340 return -99;
14341 }
14342
14343 if (vec_len (locator_set_name) > 64)
14344 {
14345 errmsg ("locator-set name too long");
14346 vec_free (locator_set_name);
14347 return -99;
14348 }
14349 vec_add1 (locator_set_name, 0);
14350
14351 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014352 M (ONE_ADD_DEL_LOCATOR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014353
14354 mp->is_add = is_add;
14355 mp->sw_if_index = ntohl (sw_if_index);
14356 mp->priority = priority;
14357 mp->weight = weight;
14358 clib_memcpy (mp->locator_set_name, locator_set_name,
14359 vec_len (locator_set_name));
14360 vec_free (locator_set_name);
14361
14362 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014363 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014364
14365 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014366 W (ret);
14367 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014368}
14369
Filip Tehlar694396d2017-02-17 14:29:11 +010014370#define api_lisp_add_del_locator api_one_add_del_locator
14371
Damjan Marion7cd468a2016-12-19 23:05:39 +010014372uword
14373unformat_hmac_key_id (unformat_input_t * input, va_list * args)
14374{
14375 u32 *key_id = va_arg (*args, u32 *);
14376 u8 *s = 0;
14377
14378 if (unformat (input, "%s", &s))
14379 {
14380 if (!strcmp ((char *) s, "sha1"))
14381 key_id[0] = HMAC_SHA_1_96;
14382 else if (!strcmp ((char *) s, "sha256"))
14383 key_id[0] = HMAC_SHA_256_128;
14384 else
14385 {
14386 clib_warning ("invalid key_id: '%s'", s);
14387 key_id[0] = HMAC_NO_KEY;
14388 }
14389 }
14390 else
14391 return 0;
14392
14393 vec_free (s);
14394 return 1;
14395}
14396
14397static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014398api_one_add_del_local_eid (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014399{
14400 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014401 vl_api_one_add_del_local_eid_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014402 u8 is_add = 1;
14403 u8 eid_set = 0;
14404 lisp_eid_vat_t _eid, *eid = &_eid;
14405 u8 *locator_set_name = 0;
14406 u8 locator_set_name_set = 0;
14407 u32 vni = 0;
14408 u16 key_id = 0;
14409 u8 *key = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014410 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014411
14412 /* Parse args required to build the message */
14413 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14414 {
14415 if (unformat (input, "del"))
14416 {
14417 is_add = 0;
14418 }
14419 else if (unformat (input, "vni %d", &vni))
14420 {
14421 ;
14422 }
14423 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
14424 {
14425 eid_set = 1;
14426 }
14427 else if (unformat (input, "locator-set %s", &locator_set_name))
14428 {
14429 locator_set_name_set = 1;
14430 }
14431 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
14432 ;
14433 else if (unformat (input, "secret-key %_%v%_", &key))
14434 ;
14435 else
14436 break;
14437 }
14438
14439 if (locator_set_name_set == 0)
14440 {
14441 errmsg ("missing locator-set name");
14442 return -99;
14443 }
14444
14445 if (0 == eid_set)
14446 {
14447 errmsg ("EID address not set!");
14448 vec_free (locator_set_name);
14449 return -99;
14450 }
14451
14452 if (key && (0 == key_id))
14453 {
14454 errmsg ("invalid key_id!");
14455 return -99;
14456 }
14457
14458 if (vec_len (key) > 64)
14459 {
14460 errmsg ("key too long");
14461 vec_free (key);
14462 return -99;
14463 }
14464
14465 if (vec_len (locator_set_name) > 64)
14466 {
14467 errmsg ("locator-set name too long");
14468 vec_free (locator_set_name);
14469 return -99;
14470 }
14471 vec_add1 (locator_set_name, 0);
14472
14473 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014474 M (ONE_ADD_DEL_LOCAL_EID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014475
14476 mp->is_add = is_add;
14477 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
14478 mp->eid_type = eid->type;
14479 mp->prefix_len = eid->len;
14480 mp->vni = clib_host_to_net_u32 (vni);
14481 mp->key_id = clib_host_to_net_u16 (key_id);
14482 clib_memcpy (mp->locator_set_name, locator_set_name,
14483 vec_len (locator_set_name));
14484 clib_memcpy (mp->key, key, vec_len (key));
14485
14486 vec_free (locator_set_name);
14487 vec_free (key);
14488
14489 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014490 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014491
14492 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014493 W (ret);
14494 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014495}
14496
Filip Tehlar694396d2017-02-17 14:29:11 +010014497#define api_lisp_add_del_local_eid api_one_add_del_local_eid
Damjan Marion7cd468a2016-12-19 23:05:39 +010014498
14499static int
14500api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
14501{
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014502 u32 dp_table = 0, vni = 0;;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014503 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010014504 vl_api_gpe_add_del_fwd_entry_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014505 u8 is_add = 1;
14506 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
14507 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
14508 u8 rmt_eid_set = 0, lcl_eid_set = 0;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014509 u32 action = ~0, w;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014510 ip4_address_t rmt_rloc4, lcl_rloc4;
14511 ip6_address_t rmt_rloc6, lcl_rloc6;
Filip Tehlar82786c42017-02-20 15:20:37 +010014512 vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014513 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014514
Dave Barachb7b92992018-10-17 10:38:51 -040014515 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014516
14517 /* Parse args required to build the message */
14518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14519 {
14520 if (unformat (input, "del"))
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014521 is_add = 0;
14522 else if (unformat (input, "add"))
14523 is_add = 1;
14524 else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014525 {
14526 rmt_eid_set = 1;
14527 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014528 else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014529 {
14530 lcl_eid_set = 1;
14531 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014532 else if (unformat (input, "vrf %d", &dp_table))
14533 ;
14534 else if (unformat (input, "bd %d", &dp_table))
14535 ;
14536 else if (unformat (input, "vni %d", &vni))
14537 ;
14538 else if (unformat (input, "w %d", &w))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014539 {
14540 if (!curr_rloc)
14541 {
14542 errmsg ("No RLOC configured for setting priority/weight!");
14543 return -99;
14544 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010014545 curr_rloc->weight = w;
14546 }
14547 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
14548 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
14549 {
14550 rloc.is_ip4 = 1;
14551
14552 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014553 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014554 vec_add1 (lcl_locs, rloc);
14555
14556 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
14557 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014558 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010014559 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
14560 }
14561 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
14562 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
14563 {
14564 rloc.is_ip4 = 0;
14565 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014566 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014567 vec_add1 (lcl_locs, rloc);
14568
14569 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
14570 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014571 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010014572 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
14573 }
14574 else if (unformat (input, "action %d", &action))
14575 {
14576 ;
14577 }
14578 else
14579 {
14580 clib_warning ("parse error '%U'", format_unformat_error, input);
14581 return -99;
14582 }
14583 }
14584
14585 if (!rmt_eid_set)
14586 {
14587 errmsg ("remote eid addresses not set");
14588 return -99;
14589 }
14590
14591 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
14592 {
14593 errmsg ("eid types don't match");
14594 return -99;
14595 }
14596
14597 if (0 == rmt_locs && (u32) ~ 0 == action)
14598 {
14599 errmsg ("action not set for negative mapping");
14600 return -99;
14601 }
14602
14603 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010014604 M2 (GPE_ADD_DEL_FWD_ENTRY, mp,
14605 sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014606
14607 mp->is_add = is_add;
14608 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
14609 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
14610 mp->eid_type = rmt_eid->type;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014611 mp->dp_table = clib_host_to_net_u32 (dp_table);
14612 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014613 mp->rmt_len = rmt_eid->len;
14614 mp->lcl_len = lcl_eid->len;
14615 mp->action = action;
14616
14617 if (0 != rmt_locs && 0 != lcl_locs)
14618 {
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014619 mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2);
14620 clib_memcpy (mp->locs, lcl_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010014621 (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs)));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014622
Filip Tehlar82786c42017-02-20 15:20:37 +010014623 u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014624 clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010014625 (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs)));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014626 }
14627 vec_free (lcl_locs);
14628 vec_free (rmt_locs);
14629
14630 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014631 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014632
14633 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014634 W (ret);
14635 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014636}
14637
14638static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014639api_one_add_del_map_server (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014640{
14641 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014642 vl_api_one_add_del_map_server_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014643 u8 is_add = 1;
14644 u8 ipv4_set = 0;
14645 u8 ipv6_set = 0;
14646 ip4_address_t ipv4;
14647 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014648 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014649
14650 /* Parse args required to build the message */
14651 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14652 {
14653 if (unformat (input, "del"))
14654 {
14655 is_add = 0;
14656 }
14657 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
14658 {
14659 ipv4_set = 1;
14660 }
14661 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
14662 {
14663 ipv6_set = 1;
14664 }
14665 else
14666 break;
14667 }
14668
14669 if (ipv4_set && ipv6_set)
14670 {
14671 errmsg ("both eid v4 and v6 addresses set");
14672 return -99;
14673 }
14674
14675 if (!ipv4_set && !ipv6_set)
14676 {
14677 errmsg ("eid addresses not set");
14678 return -99;
14679 }
14680
14681 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014682 M (ONE_ADD_DEL_MAP_SERVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014683
14684 mp->is_add = is_add;
14685 if (ipv6_set)
14686 {
14687 mp->is_ipv6 = 1;
14688 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
14689 }
14690 else
14691 {
14692 mp->is_ipv6 = 0;
14693 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
14694 }
14695
14696 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014697 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014698
14699 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014700 W (ret);
14701 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014702}
14703
Filip Tehlar694396d2017-02-17 14:29:11 +010014704#define api_lisp_add_del_map_server api_one_add_del_map_server
14705
Damjan Marion7cd468a2016-12-19 23:05:39 +010014706static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014707api_one_add_del_map_resolver (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014708{
14709 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014710 vl_api_one_add_del_map_resolver_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014711 u8 is_add = 1;
14712 u8 ipv4_set = 0;
14713 u8 ipv6_set = 0;
14714 ip4_address_t ipv4;
14715 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014716 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014717
14718 /* Parse args required to build the message */
14719 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14720 {
14721 if (unformat (input, "del"))
14722 {
14723 is_add = 0;
14724 }
14725 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
14726 {
14727 ipv4_set = 1;
14728 }
14729 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
14730 {
14731 ipv6_set = 1;
14732 }
14733 else
14734 break;
14735 }
14736
14737 if (ipv4_set && ipv6_set)
14738 {
14739 errmsg ("both eid v4 and v6 addresses set");
14740 return -99;
14741 }
14742
14743 if (!ipv4_set && !ipv6_set)
14744 {
14745 errmsg ("eid addresses not set");
14746 return -99;
14747 }
14748
14749 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014750 M (ONE_ADD_DEL_MAP_RESOLVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014751
14752 mp->is_add = is_add;
14753 if (ipv6_set)
14754 {
14755 mp->is_ipv6 = 1;
14756 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
14757 }
14758 else
14759 {
14760 mp->is_ipv6 = 0;
14761 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
14762 }
14763
14764 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014765 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014766
14767 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014768 W (ret);
14769 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014770}
14771
Filip Tehlar694396d2017-02-17 14:29:11 +010014772#define api_lisp_add_del_map_resolver api_one_add_del_map_resolver
14773
Damjan Marion7cd468a2016-12-19 23:05:39 +010014774static int
14775api_lisp_gpe_enable_disable (vat_main_t * vam)
14776{
14777 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010014778 vl_api_gpe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014779 u8 is_set = 0;
14780 u8 is_en = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014781 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014782
14783 /* Parse args required to build the message */
14784 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14785 {
14786 if (unformat (input, "enable"))
14787 {
14788 is_set = 1;
14789 is_en = 1;
14790 }
14791 else if (unformat (input, "disable"))
14792 {
14793 is_set = 1;
14794 is_en = 0;
14795 }
14796 else
14797 break;
14798 }
14799
14800 if (is_set == 0)
14801 {
14802 errmsg ("Value not set");
14803 return -99;
14804 }
14805
14806 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010014807 M (GPE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014808
14809 mp->is_en = is_en;
14810
14811 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014812 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014813
14814 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014815 W (ret);
14816 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014817}
14818
14819static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014820api_one_rloc_probe_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014821{
14822 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014823 vl_api_one_rloc_probe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014824 u8 is_set = 0;
14825 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014826 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014827
14828 /* Parse args required to build the message */
14829 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14830 {
14831 if (unformat (input, "enable"))
14832 {
14833 is_set = 1;
14834 is_en = 1;
14835 }
14836 else if (unformat (input, "disable"))
14837 is_set = 1;
14838 else
14839 break;
14840 }
14841
14842 if (!is_set)
14843 {
14844 errmsg ("Value not set");
14845 return -99;
14846 }
14847
14848 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014849 M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014850
14851 mp->is_enabled = is_en;
14852
14853 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014854 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014855
14856 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014857 W (ret);
14858 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014859}
14860
Filip Tehlar694396d2017-02-17 14:29:11 +010014861#define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
14862
Damjan Marion7cd468a2016-12-19 23:05:39 +010014863static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014864api_one_map_register_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014865{
14866 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014867 vl_api_one_map_register_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014868 u8 is_set = 0;
14869 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014870 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014871
14872 /* Parse args required to build the message */
14873 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14874 {
14875 if (unformat (input, "enable"))
14876 {
14877 is_set = 1;
14878 is_en = 1;
14879 }
14880 else if (unformat (input, "disable"))
14881 is_set = 1;
14882 else
14883 break;
14884 }
14885
14886 if (!is_set)
14887 {
14888 errmsg ("Value not set");
14889 return -99;
14890 }
14891
14892 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014893 M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014894
14895 mp->is_enabled = is_en;
14896
14897 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014898 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014899
14900 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014901 W (ret);
14902 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014903}
14904
Filip Tehlar694396d2017-02-17 14:29:11 +010014905#define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
14906
Damjan Marion7cd468a2016-12-19 23:05:39 +010014907static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014908api_one_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014909{
14910 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014911 vl_api_one_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014912 u8 is_set = 0;
14913 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014914 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014915
14916 /* Parse args required to build the message */
14917 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14918 {
14919 if (unformat (input, "enable"))
14920 {
14921 is_set = 1;
14922 is_en = 1;
14923 }
14924 else if (unformat (input, "disable"))
14925 {
14926 is_set = 1;
14927 }
14928 else
14929 break;
14930 }
14931
14932 if (!is_set)
14933 {
14934 errmsg ("Value not set");
14935 return -99;
14936 }
14937
14938 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014939 M (ONE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014940
14941 mp->is_en = is_en;
14942
14943 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014944 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014945
14946 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014947 W (ret);
14948 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014949}
14950
Filip Tehlar694396d2017-02-17 14:29:11 +010014951#define api_lisp_enable_disable api_one_enable_disable
14952
Damjan Marion7cd468a2016-12-19 23:05:39 +010014953static int
Filip Tehlar0a8840d2017-10-16 05:48:23 -070014954api_one_enable_disable_xtr_mode (vat_main_t * vam)
14955{
14956 unformat_input_t *input = vam->input;
14957 vl_api_one_enable_disable_xtr_mode_t *mp;
14958 u8 is_set = 0;
14959 u8 is_en = 0;
14960 int ret;
14961
14962 /* Parse args required to build the message */
14963 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14964 {
14965 if (unformat (input, "enable"))
14966 {
14967 is_set = 1;
14968 is_en = 1;
14969 }
14970 else if (unformat (input, "disable"))
14971 {
14972 is_set = 1;
14973 }
14974 else
14975 break;
14976 }
14977
14978 if (!is_set)
14979 {
14980 errmsg ("Value not set");
14981 return -99;
14982 }
14983
14984 /* Construct the API message */
14985 M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
14986
14987 mp->is_en = is_en;
14988
14989 /* send it... */
14990 S (mp);
14991
14992 /* Wait for a reply... */
14993 W (ret);
14994 return ret;
14995}
14996
14997static int
14998api_one_show_xtr_mode (vat_main_t * vam)
14999{
15000 vl_api_one_show_xtr_mode_t *mp;
15001 int ret;
15002
15003 /* Construct the API message */
15004 M (ONE_SHOW_XTR_MODE, mp);
15005
15006 /* send it... */
15007 S (mp);
15008
15009 /* Wait for a reply... */
15010 W (ret);
15011 return ret;
15012}
15013
15014static int
15015api_one_enable_disable_pitr_mode (vat_main_t * vam)
15016{
15017 unformat_input_t *input = vam->input;
15018 vl_api_one_enable_disable_pitr_mode_t *mp;
15019 u8 is_set = 0;
15020 u8 is_en = 0;
15021 int ret;
15022
15023 /* Parse args required to build the message */
15024 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15025 {
15026 if (unformat (input, "enable"))
15027 {
15028 is_set = 1;
15029 is_en = 1;
15030 }
15031 else if (unformat (input, "disable"))
15032 {
15033 is_set = 1;
15034 }
15035 else
15036 break;
15037 }
15038
15039 if (!is_set)
15040 {
15041 errmsg ("Value not set");
15042 return -99;
15043 }
15044
15045 /* Construct the API message */
15046 M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
15047
15048 mp->is_en = is_en;
15049
15050 /* send it... */
15051 S (mp);
15052
15053 /* Wait for a reply... */
15054 W (ret);
15055 return ret;
15056}
15057
15058static int
15059api_one_show_pitr_mode (vat_main_t * vam)
15060{
15061 vl_api_one_show_pitr_mode_t *mp;
15062 int ret;
15063
15064 /* Construct the API message */
15065 M (ONE_SHOW_PITR_MODE, mp);
15066
15067 /* send it... */
15068 S (mp);
15069
15070 /* Wait for a reply... */
15071 W (ret);
15072 return ret;
15073}
15074
15075static int
15076api_one_enable_disable_petr_mode (vat_main_t * vam)
15077{
15078 unformat_input_t *input = vam->input;
15079 vl_api_one_enable_disable_petr_mode_t *mp;
15080 u8 is_set = 0;
15081 u8 is_en = 0;
15082 int ret;
15083
15084 /* Parse args required to build the message */
15085 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15086 {
15087 if (unformat (input, "enable"))
15088 {
15089 is_set = 1;
15090 is_en = 1;
15091 }
15092 else if (unformat (input, "disable"))
15093 {
15094 is_set = 1;
15095 }
15096 else
15097 break;
15098 }
15099
15100 if (!is_set)
15101 {
15102 errmsg ("Value not set");
15103 return -99;
15104 }
15105
15106 /* Construct the API message */
15107 M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
15108
15109 mp->is_en = is_en;
15110
15111 /* send it... */
15112 S (mp);
15113
15114 /* Wait for a reply... */
15115 W (ret);
15116 return ret;
15117}
15118
15119static int
15120api_one_show_petr_mode (vat_main_t * vam)
15121{
15122 vl_api_one_show_petr_mode_t *mp;
15123 int ret;
15124
15125 /* Construct the API message */
15126 M (ONE_SHOW_PETR_MODE, mp);
15127
15128 /* send it... */
15129 S (mp);
15130
15131 /* Wait for a reply... */
15132 W (ret);
15133 return ret;
15134}
15135
15136static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015137api_show_one_map_register_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015138{
Filip Tehlar694396d2017-02-17 14:29:11 +010015139 vl_api_show_one_map_register_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015140 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015141
Filip Tehlar694396d2017-02-17 14:29:11 +010015142 M (SHOW_ONE_MAP_REGISTER_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015143
15144 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015145 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015146
15147 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015148 W (ret);
15149 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015150}
15151
Filip Tehlar694396d2017-02-17 14:29:11 +010015152#define api_show_lisp_map_register_state api_show_one_map_register_state
15153
Damjan Marion7cd468a2016-12-19 23:05:39 +010015154static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015155api_show_one_rloc_probe_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015156{
Filip Tehlar694396d2017-02-17 14:29:11 +010015157 vl_api_show_one_rloc_probe_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015158 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015159
Filip Tehlar694396d2017-02-17 14:29:11 +010015160 M (SHOW_ONE_RLOC_PROBE_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015161
15162 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015163 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015164
15165 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015166 W (ret);
15167 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015168}
15169
Filip Tehlar694396d2017-02-17 14:29:11 +010015170#define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
15171
Damjan Marion7cd468a2016-12-19 23:05:39 +010015172static int
Filip Tehlar05879992017-09-05 15:46:09 +020015173api_one_add_del_ndp_entry (vat_main_t * vam)
15174{
15175 vl_api_one_add_del_ndp_entry_t *mp;
15176 unformat_input_t *input = vam->input;
15177 u8 is_add = 1;
15178 u8 mac_set = 0;
15179 u8 bd_set = 0;
15180 u8 ip_set = 0;
15181 u8 mac[6] = { 0, };
15182 u8 ip6[16] = { 0, };
15183 u32 bd = ~0;
15184 int ret;
15185
15186 /* Parse args required to build the message */
15187 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15188 {
15189 if (unformat (input, "del"))
15190 is_add = 0;
15191 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
15192 mac_set = 1;
15193 else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
15194 ip_set = 1;
15195 else if (unformat (input, "bd %d", &bd))
15196 bd_set = 1;
15197 else
15198 {
15199 errmsg ("parse error '%U'", format_unformat_error, input);
15200 return -99;
15201 }
15202 }
15203
15204 if (!bd_set || !ip_set || (!mac_set && is_add))
15205 {
15206 errmsg ("Missing BD, IP or MAC!");
15207 return -99;
15208 }
15209
15210 M (ONE_ADD_DEL_NDP_ENTRY, mp);
15211 mp->is_add = is_add;
15212 clib_memcpy (mp->mac, mac, 6);
15213 mp->bd = clib_host_to_net_u32 (bd);
15214 clib_memcpy (mp->ip6, ip6, sizeof (mp->ip6));
15215
15216 /* send */
15217 S (mp);
15218
15219 /* wait for reply */
15220 W (ret);
15221 return ret;
15222}
15223
15224static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020015225api_one_add_del_l2_arp_entry (vat_main_t * vam)
15226{
15227 vl_api_one_add_del_l2_arp_entry_t *mp;
15228 unformat_input_t *input = vam->input;
15229 u8 is_add = 1;
15230 u8 mac_set = 0;
15231 u8 bd_set = 0;
15232 u8 ip_set = 0;
15233 u8 mac[6] = { 0, };
15234 u32 ip4 = 0, bd = ~0;
15235 int ret;
15236
15237 /* Parse args required to build the message */
15238 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15239 {
15240 if (unformat (input, "del"))
15241 is_add = 0;
15242 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
15243 mac_set = 1;
15244 else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
15245 ip_set = 1;
15246 else if (unformat (input, "bd %d", &bd))
15247 bd_set = 1;
15248 else
15249 {
15250 errmsg ("parse error '%U'", format_unformat_error, input);
15251 return -99;
15252 }
15253 }
15254
15255 if (!bd_set || !ip_set || (!mac_set && is_add))
15256 {
15257 errmsg ("Missing BD, IP or MAC!");
15258 return -99;
15259 }
15260
15261 M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
15262 mp->is_add = is_add;
15263 clib_memcpy (mp->mac, mac, 6);
15264 mp->bd = clib_host_to_net_u32 (bd);
15265 mp->ip4 = ip4;
15266
15267 /* send */
15268 S (mp);
15269
15270 /* wait for reply */
15271 W (ret);
15272 return ret;
15273}
15274
15275static int
Filip Tehlar05879992017-09-05 15:46:09 +020015276api_one_ndp_bd_get (vat_main_t * vam)
15277{
15278 vl_api_one_ndp_bd_get_t *mp;
15279 int ret;
15280
15281 M (ONE_NDP_BD_GET, mp);
15282
15283 /* send */
15284 S (mp);
15285
15286 /* wait for reply */
15287 W (ret);
15288 return ret;
15289}
15290
15291static int
15292api_one_ndp_entries_get (vat_main_t * vam)
15293{
15294 vl_api_one_ndp_entries_get_t *mp;
15295 unformat_input_t *input = vam->input;
15296 u8 bd_set = 0;
15297 u32 bd = ~0;
15298 int ret;
15299
15300 /* Parse args required to build the message */
15301 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15302 {
15303 if (unformat (input, "bd %d", &bd))
15304 bd_set = 1;
15305 else
15306 {
15307 errmsg ("parse error '%U'", format_unformat_error, input);
15308 return -99;
15309 }
15310 }
15311
15312 if (!bd_set)
15313 {
15314 errmsg ("Expected bridge domain!");
15315 return -99;
15316 }
15317
15318 M (ONE_NDP_ENTRIES_GET, mp);
15319 mp->bd = clib_host_to_net_u32 (bd);
15320
15321 /* send */
15322 S (mp);
15323
15324 /* wait for reply */
15325 W (ret);
15326 return ret;
15327}
15328
15329static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020015330api_one_l2_arp_bd_get (vat_main_t * vam)
15331{
15332 vl_api_one_l2_arp_bd_get_t *mp;
15333 int ret;
15334
15335 M (ONE_L2_ARP_BD_GET, mp);
15336
15337 /* send */
15338 S (mp);
15339
15340 /* wait for reply */
15341 W (ret);
15342 return ret;
15343}
15344
15345static int
15346api_one_l2_arp_entries_get (vat_main_t * vam)
15347{
15348 vl_api_one_l2_arp_entries_get_t *mp;
15349 unformat_input_t *input = vam->input;
15350 u8 bd_set = 0;
15351 u32 bd = ~0;
15352 int ret;
15353
15354 /* Parse args required to build the message */
15355 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15356 {
15357 if (unformat (input, "bd %d", &bd))
15358 bd_set = 1;
15359 else
15360 {
15361 errmsg ("parse error '%U'", format_unformat_error, input);
15362 return -99;
15363 }
15364 }
15365
15366 if (!bd_set)
15367 {
15368 errmsg ("Expected bridge domain!");
15369 return -99;
15370 }
15371
15372 M (ONE_L2_ARP_ENTRIES_GET, mp);
15373 mp->bd = clib_host_to_net_u32 (bd);
15374
15375 /* send */
15376 S (mp);
15377
15378 /* wait for reply */
15379 W (ret);
15380 return ret;
15381}
15382
15383static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010015384api_one_stats_enable_disable (vat_main_t * vam)
15385{
15386 vl_api_one_stats_enable_disable_t *mp;
15387 unformat_input_t *input = vam->input;
15388 u8 is_set = 0;
15389 u8 is_en = 0;
15390 int ret;
15391
15392 /* Parse args required to build the message */
15393 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15394 {
15395 if (unformat (input, "enable"))
15396 {
15397 is_set = 1;
15398 is_en = 1;
15399 }
15400 else if (unformat (input, "disable"))
15401 {
15402 is_set = 1;
15403 }
15404 else
15405 break;
15406 }
15407
15408 if (!is_set)
15409 {
15410 errmsg ("Value not set");
15411 return -99;
15412 }
15413
15414 M (ONE_STATS_ENABLE_DISABLE, mp);
15415 mp->is_en = is_en;
15416
15417 /* send */
15418 S (mp);
15419
15420 /* wait for reply */
15421 W (ret);
15422 return ret;
15423}
15424
15425static int
15426api_show_one_stats_enable_disable (vat_main_t * vam)
15427{
15428 vl_api_show_one_stats_enable_disable_t *mp;
15429 int ret;
15430
15431 M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
15432
15433 /* send */
15434 S (mp);
15435
15436 /* wait for reply */
15437 W (ret);
15438 return ret;
15439}
15440
15441static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015442api_show_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015443{
Filip Tehlar694396d2017-02-17 14:29:11 +010015444 vl_api_show_one_map_request_mode_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015445 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015446
Filip Tehlar694396d2017-02-17 14:29:11 +010015447 M (SHOW_ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015448
15449 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015450 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015451
15452 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015453 W (ret);
15454 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015455}
15456
Filip Tehlar694396d2017-02-17 14:29:11 +010015457#define api_show_lisp_map_request_mode api_show_one_map_request_mode
15458
Damjan Marion7cd468a2016-12-19 23:05:39 +010015459static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015460api_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015461{
Damjan Marion7cd468a2016-12-19 23:05:39 +010015462 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015463 vl_api_one_map_request_mode_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015464 u8 mode = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015465 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015466
15467 /* Parse args required to build the message */
15468 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15469 {
15470 if (unformat (input, "dst-only"))
15471 mode = 0;
15472 else if (unformat (input, "src-dst"))
15473 mode = 1;
15474 else
15475 {
15476 errmsg ("parse error '%U'", format_unformat_error, input);
15477 return -99;
15478 }
15479 }
15480
Filip Tehlar694396d2017-02-17 14:29:11 +010015481 M (ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015482
15483 mp->mode = mode;
15484
15485 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015486 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015487
15488 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015489 W (ret);
15490 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015491}
15492
Filip Tehlar694396d2017-02-17 14:29:11 +010015493#define api_lisp_map_request_mode api_one_map_request_mode
15494
Damjan Marion7cd468a2016-12-19 23:05:39 +010015495/**
Filip Tehlar694396d2017-02-17 14:29:11 +010015496 * Enable/disable ONE proxy ITR.
Damjan Marion7cd468a2016-12-19 23:05:39 +010015497 *
15498 * @param vam vpp API test context
15499 * @return return code
15500 */
15501static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015502api_one_pitr_set_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015503{
Damjan Marion7cd468a2016-12-19 23:05:39 +010015504 u8 ls_name_set = 0;
15505 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015506 vl_api_one_pitr_set_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015507 u8 is_add = 1;
15508 u8 *ls_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015509 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015510
15511 /* Parse args required to build the message */
15512 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15513 {
15514 if (unformat (input, "del"))
15515 is_add = 0;
15516 else if (unformat (input, "locator-set %s", &ls_name))
15517 ls_name_set = 1;
15518 else
15519 {
15520 errmsg ("parse error '%U'", format_unformat_error, input);
15521 return -99;
15522 }
15523 }
15524
15525 if (!ls_name_set)
15526 {
15527 errmsg ("locator-set name not set!");
15528 return -99;
15529 }
15530
Filip Tehlar694396d2017-02-17 14:29:11 +010015531 M (ONE_PITR_SET_LOCATOR_SET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015532
15533 mp->is_add = is_add;
15534 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
15535 vec_free (ls_name);
15536
15537 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015538 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015539
15540 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015541 W (ret);
15542 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015543}
15544
Filip Tehlar694396d2017-02-17 14:29:11 +010015545#define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
15546
Damjan Marion7cd468a2016-12-19 23:05:39 +010015547static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015548api_one_nsh_set_locator_set (vat_main_t * vam)
15549{
15550 u8 ls_name_set = 0;
15551 unformat_input_t *input = vam->input;
15552 vl_api_one_nsh_set_locator_set_t *mp;
15553 u8 is_add = 1;
15554 u8 *ls_name = 0;
15555 int ret;
15556
15557 /* Parse args required to build the message */
15558 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15559 {
15560 if (unformat (input, "del"))
15561 is_add = 0;
15562 else if (unformat (input, "ls %s", &ls_name))
15563 ls_name_set = 1;
15564 else
15565 {
15566 errmsg ("parse error '%U'", format_unformat_error, input);
15567 return -99;
15568 }
15569 }
15570
15571 if (!ls_name_set && is_add)
15572 {
15573 errmsg ("locator-set name not set!");
15574 return -99;
15575 }
15576
15577 M (ONE_NSH_SET_LOCATOR_SET, mp);
15578
15579 mp->is_add = is_add;
15580 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
15581 vec_free (ls_name);
15582
15583 /* send */
15584 S (mp);
15585
15586 /* wait for reply */
15587 W (ret);
15588 return ret;
15589}
15590
15591static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015592api_show_one_pitr (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015593{
Filip Tehlar694396d2017-02-17 14:29:11 +010015594 vl_api_show_one_pitr_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015595 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015596
15597 if (!vam->json_output)
15598 {
15599 print (vam->ofp, "%=20s", "lisp status:");
15600 }
15601
Filip Tehlar694396d2017-02-17 14:29:11 +010015602 M (SHOW_ONE_PITR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015603 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015604 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015605
15606 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015607 W (ret);
15608 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015609}
15610
Filip Tehlar694396d2017-02-17 14:29:11 +010015611#define api_show_lisp_pitr api_show_one_pitr
15612
Filip Tehlar67a99f82017-03-10 13:18:02 +010015613static int
15614api_one_use_petr (vat_main_t * vam)
15615{
15616 unformat_input_t *input = vam->input;
15617 vl_api_one_use_petr_t *mp;
15618 u8 is_add = 0;
15619 ip_address_t ip;
15620 int ret;
15621
Dave Barachb7b92992018-10-17 10:38:51 -040015622 clib_memset (&ip, 0, sizeof (ip));
Filip Tehlar67a99f82017-03-10 13:18:02 +010015623
15624 /* Parse args required to build the message */
15625 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15626 {
15627 if (unformat (input, "disable"))
15628 is_add = 0;
15629 else
15630 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
15631 {
15632 is_add = 1;
Neale Rannsea93e482019-11-12 17:16:47 +000015633 ip_addr_version (&ip) = AF_IP4;
Filip Tehlar67a99f82017-03-10 13:18:02 +010015634 }
15635 else
15636 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
15637 {
15638 is_add = 1;
Neale Rannsea93e482019-11-12 17:16:47 +000015639 ip_addr_version (&ip) = AF_IP6;
Filip Tehlar67a99f82017-03-10 13:18:02 +010015640 }
15641 else
15642 {
15643 errmsg ("parse error '%U'", format_unformat_error, input);
15644 return -99;
15645 }
15646 }
15647
15648 M (ONE_USE_PETR, mp);
15649
15650 mp->is_add = is_add;
15651 if (is_add)
15652 {
Neale Rannsea93e482019-11-12 17:16:47 +000015653 mp->is_ip4 = ip_addr_version (&ip) == AF_IP4 ? 1 : 0;
Filip Tehlar67a99f82017-03-10 13:18:02 +010015654 if (mp->is_ip4)
15655 clib_memcpy (mp->address, &ip, 4);
15656 else
15657 clib_memcpy (mp->address, &ip, 16);
15658 }
15659
15660 /* send */
15661 S (mp);
15662
15663 /* wait for reply */
15664 W (ret);
15665 return ret;
15666}
15667
15668#define api_lisp_use_petr api_one_use_petr
15669
15670static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015671api_show_one_nsh_mapping (vat_main_t * vam)
15672{
15673 vl_api_show_one_use_petr_t *mp;
15674 int ret;
15675
15676 if (!vam->json_output)
15677 {
15678 print (vam->ofp, "%=20s", "local ONE NSH mapping:");
15679 }
15680
15681 M (SHOW_ONE_NSH_MAPPING, mp);
15682 /* send it... */
15683 S (mp);
15684
15685 /* Wait for a reply... */
15686 W (ret);
15687 return ret;
15688}
15689
15690static int
Filip Tehlar67a99f82017-03-10 13:18:02 +010015691api_show_one_use_petr (vat_main_t * vam)
15692{
15693 vl_api_show_one_use_petr_t *mp;
15694 int ret;
15695
15696 if (!vam->json_output)
15697 {
15698 print (vam->ofp, "%=20s", "Proxy-ETR status:");
15699 }
15700
15701 M (SHOW_ONE_USE_PETR, mp);
15702 /* send it... */
15703 S (mp);
15704
15705 /* Wait for a reply... */
15706 W (ret);
15707 return ret;
15708}
15709
15710#define api_show_lisp_use_petr api_show_one_use_petr
15711
Damjan Marion7cd468a2016-12-19 23:05:39 +010015712/**
15713 * Add/delete mapping between vni and vrf
15714 */
15715static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015716api_one_eid_table_add_del_map (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015717{
Damjan Marion7cd468a2016-12-19 23:05:39 +010015718 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015719 vl_api_one_eid_table_add_del_map_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015720 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
15721 u32 vni, vrf, bd_index;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015722 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015723
15724 /* Parse args required to build the message */
15725 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15726 {
15727 if (unformat (input, "del"))
15728 is_add = 0;
15729 else if (unformat (input, "vrf %d", &vrf))
15730 vrf_set = 1;
15731 else if (unformat (input, "bd_index %d", &bd_index))
15732 bd_index_set = 1;
15733 else if (unformat (input, "vni %d", &vni))
15734 vni_set = 1;
15735 else
15736 break;
15737 }
15738
15739 if (!vni_set || (!vrf_set && !bd_index_set))
15740 {
15741 errmsg ("missing arguments!");
15742 return -99;
15743 }
15744
15745 if (vrf_set && bd_index_set)
15746 {
15747 errmsg ("error: both vrf and bd entered!");
15748 return -99;
15749 }
15750
Filip Tehlar694396d2017-02-17 14:29:11 +010015751 M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015752
15753 mp->is_add = is_add;
15754 mp->vni = htonl (vni);
15755 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
15756 mp->is_l2 = bd_index_set;
15757
15758 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015759 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015760
15761 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015762 W (ret);
15763 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015764}
15765
Filip Tehlar694396d2017-02-17 14:29:11 +010015766#define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
15767
Damjan Marion7cd468a2016-12-19 23:05:39 +010015768uword
15769unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
15770{
15771 u32 *action = va_arg (*args, u32 *);
15772 u8 *s = 0;
15773
15774 if (unformat (input, "%s", &s))
15775 {
15776 if (!strcmp ((char *) s, "no-action"))
15777 action[0] = 0;
15778 else if (!strcmp ((char *) s, "natively-forward"))
15779 action[0] = 1;
15780 else if (!strcmp ((char *) s, "send-map-request"))
15781 action[0] = 2;
15782 else if (!strcmp ((char *) s, "drop"))
15783 action[0] = 3;
15784 else
15785 {
15786 clib_warning ("invalid action: '%s'", s);
15787 action[0] = 3;
15788 }
15789 }
15790 else
15791 return 0;
15792
15793 vec_free (s);
15794 return 1;
15795}
15796
15797/**
Filip Tehlar694396d2017-02-17 14:29:11 +010015798 * Add/del remote mapping to/from ONE control plane
Damjan Marion7cd468a2016-12-19 23:05:39 +010015799 *
15800 * @param vam vpp API test context
15801 * @return return code
15802 */
15803static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015804api_one_add_del_remote_mapping (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015805{
15806 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015807 vl_api_one_add_del_remote_mapping_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015808 u32 vni = 0;
15809 lisp_eid_vat_t _eid, *eid = &_eid;
15810 lisp_eid_vat_t _seid, *seid = &_seid;
15811 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
15812 u32 action = ~0, p, w, data_len;
15813 ip4_address_t rloc4;
15814 ip6_address_t rloc6;
Filip Tehlar05a057b2017-02-01 08:50:31 +010015815 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015816 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015817
Dave Barachb7b92992018-10-17 10:38:51 -040015818 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015819
15820 /* Parse args required to build the message */
15821 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15822 {
15823 if (unformat (input, "del-all"))
15824 {
15825 del_all = 1;
15826 }
15827 else if (unformat (input, "del"))
15828 {
15829 is_add = 0;
15830 }
15831 else if (unformat (input, "add"))
15832 {
15833 is_add = 1;
15834 }
15835 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
15836 {
15837 eid_set = 1;
15838 }
15839 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
15840 {
15841 seid_set = 1;
15842 }
15843 else if (unformat (input, "vni %d", &vni))
15844 {
15845 ;
15846 }
15847 else if (unformat (input, "p %d w %d", &p, &w))
15848 {
15849 if (!curr_rloc)
15850 {
15851 errmsg ("No RLOC configured for setting priority/weight!");
15852 return -99;
15853 }
15854 curr_rloc->priority = p;
15855 curr_rloc->weight = w;
15856 }
15857 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
15858 {
15859 rloc.is_ip4 = 1;
15860 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
15861 vec_add1 (rlocs, rloc);
15862 curr_rloc = &rlocs[vec_len (rlocs) - 1];
15863 }
15864 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
15865 {
15866 rloc.is_ip4 = 0;
15867 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
15868 vec_add1 (rlocs, rloc);
15869 curr_rloc = &rlocs[vec_len (rlocs) - 1];
15870 }
15871 else if (unformat (input, "action %U",
15872 unformat_negative_mapping_action, &action))
15873 {
15874 ;
15875 }
15876 else
15877 {
15878 clib_warning ("parse error '%U'", format_unformat_error, input);
15879 return -99;
15880 }
15881 }
15882
15883 if (0 == eid_set)
15884 {
15885 errmsg ("missing params!");
15886 return -99;
15887 }
15888
15889 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
15890 {
15891 errmsg ("no action set for negative map-reply!");
15892 return -99;
15893 }
15894
Filip Tehlar05a057b2017-02-01 08:50:31 +010015895 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015896
Filip Tehlar694396d2017-02-17 14:29:11 +010015897 M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015898 mp->is_add = is_add;
15899 mp->vni = htonl (vni);
15900 mp->action = (u8) action;
15901 mp->is_src_dst = seid_set;
15902 mp->eid_len = eid->len;
15903 mp->seid_len = seid->len;
15904 mp->del_all = del_all;
15905 mp->eid_type = eid->type;
15906 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
15907 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
15908
15909 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
15910 clib_memcpy (mp->rlocs, rlocs, data_len);
15911 vec_free (rlocs);
15912
15913 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015914 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015915
15916 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015917 W (ret);
15918 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015919}
15920
Filip Tehlar694396d2017-02-17 14:29:11 +010015921#define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
15922
Damjan Marion7cd468a2016-12-19 23:05:39 +010015923/**
Filip Tehlar694396d2017-02-17 14:29:11 +010015924 * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010015925 * forwarding entries in data-plane accordingly.
15926 *
15927 * @param vam vpp API test context
15928 * @return return code
15929 */
15930static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015931api_one_add_del_adjacency (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015932{
15933 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015934 vl_api_one_add_del_adjacency_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015935 u32 vni = 0;
15936 ip4_address_t leid4, reid4;
15937 ip6_address_t leid6, reid6;
15938 u8 reid_mac[6] = { 0 };
15939 u8 leid_mac[6] = { 0 };
15940 u8 reid_type, leid_type;
15941 u32 leid_len = 0, reid_len = 0, len;
15942 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015943 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015944
15945 leid_type = reid_type = (u8) ~ 0;
15946
15947 /* Parse args required to build the message */
15948 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15949 {
15950 if (unformat (input, "del"))
15951 {
15952 is_add = 0;
15953 }
15954 else if (unformat (input, "add"))
15955 {
15956 is_add = 1;
15957 }
15958 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
15959 &reid4, &len))
15960 {
15961 reid_type = 0; /* ipv4 */
15962 reid_len = len;
15963 }
15964 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
15965 &reid6, &len))
15966 {
15967 reid_type = 1; /* ipv6 */
15968 reid_len = len;
15969 }
15970 else if (unformat (input, "reid %U", unformat_ethernet_address,
15971 reid_mac))
15972 {
15973 reid_type = 2; /* mac */
15974 }
15975 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
15976 &leid4, &len))
15977 {
15978 leid_type = 0; /* ipv4 */
15979 leid_len = len;
15980 }
15981 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
15982 &leid6, &len))
15983 {
15984 leid_type = 1; /* ipv6 */
15985 leid_len = len;
15986 }
15987 else if (unformat (input, "leid %U", unformat_ethernet_address,
15988 leid_mac))
15989 {
15990 leid_type = 2; /* mac */
15991 }
15992 else if (unformat (input, "vni %d", &vni))
15993 {
15994 ;
15995 }
15996 else
15997 {
15998 errmsg ("parse error '%U'", format_unformat_error, input);
15999 return -99;
16000 }
16001 }
16002
16003 if ((u8) ~ 0 == reid_type)
16004 {
16005 errmsg ("missing params!");
16006 return -99;
16007 }
16008
16009 if (leid_type != reid_type)
16010 {
16011 errmsg ("remote and local EIDs are of different types!");
16012 return -99;
16013 }
16014
Filip Tehlar694396d2017-02-17 14:29:11 +010016015 M (ONE_ADD_DEL_ADJACENCY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016016 mp->is_add = is_add;
16017 mp->vni = htonl (vni);
16018 mp->leid_len = leid_len;
16019 mp->reid_len = reid_len;
16020 mp->eid_type = reid_type;
16021
16022 switch (mp->eid_type)
16023 {
16024 case 0:
16025 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
16026 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
16027 break;
16028 case 1:
16029 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
16030 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
16031 break;
16032 case 2:
16033 clib_memcpy (mp->leid, leid_mac, 6);
16034 clib_memcpy (mp->reid, reid_mac, 6);
16035 break;
16036 default:
16037 errmsg ("unknown EID type %d!", mp->eid_type);
16038 return 0;
16039 }
16040
16041 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016042 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016043
16044 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016045 W (ret);
16046 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016047}
16048
Filip Tehlar694396d2017-02-17 14:29:11 +010016049#define api_lisp_add_del_adjacency api_one_add_del_adjacency
16050
Filip Tehlar3e7b56932017-02-21 18:28:34 +010016051uword
16052unformat_gpe_encap_mode (unformat_input_t * input, va_list * args)
16053{
16054 u32 *mode = va_arg (*args, u32 *);
16055
16056 if (unformat (input, "lisp"))
16057 *mode = 0;
16058 else if (unformat (input, "vxlan"))
16059 *mode = 1;
16060 else
16061 return 0;
16062
16063 return 1;
16064}
16065
16066static int
16067api_gpe_get_encap_mode (vat_main_t * vam)
16068{
16069 vl_api_gpe_get_encap_mode_t *mp;
16070 int ret;
16071
16072 /* Construct the API message */
16073 M (GPE_GET_ENCAP_MODE, mp);
16074
16075 /* send it... */
16076 S (mp);
16077
16078 /* Wait for a reply... */
16079 W (ret);
16080 return ret;
16081}
16082
16083static int
16084api_gpe_set_encap_mode (vat_main_t * vam)
16085{
16086 unformat_input_t *input = vam->input;
16087 vl_api_gpe_set_encap_mode_t *mp;
16088 int ret;
16089 u32 mode = 0;
16090
16091 /* Parse args required to build the message */
16092 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16093 {
16094 if (unformat (input, "%U", unformat_gpe_encap_mode, &mode))
16095 ;
16096 else
16097 break;
16098 }
16099
16100 /* Construct the API message */
16101 M (GPE_SET_ENCAP_MODE, mp);
16102
16103 mp->mode = mode;
16104
16105 /* send it... */
16106 S (mp);
16107
16108 /* Wait for a reply... */
16109 W (ret);
16110 return ret;
16111}
16112
Damjan Marion7cd468a2016-12-19 23:05:39 +010016113static int
16114api_lisp_gpe_add_del_iface (vat_main_t * vam)
16115{
16116 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010016117 vl_api_gpe_add_del_iface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016118 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
16119 u32 dp_table = 0, vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016120 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016121
16122 /* Parse args required to build the message */
16123 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16124 {
16125 if (unformat (input, "up"))
16126 {
16127 action_set = 1;
16128 is_add = 1;
16129 }
16130 else if (unformat (input, "down"))
16131 {
16132 action_set = 1;
16133 is_add = 0;
16134 }
16135 else if (unformat (input, "table_id %d", &dp_table))
16136 {
16137 dp_table_set = 1;
16138 }
16139 else if (unformat (input, "bd_id %d", &dp_table))
16140 {
16141 dp_table_set = 1;
16142 is_l2 = 1;
16143 }
16144 else if (unformat (input, "vni %d", &vni))
16145 {
16146 vni_set = 1;
16147 }
16148 else
16149 break;
16150 }
16151
16152 if (action_set == 0)
16153 {
16154 errmsg ("Action not set");
16155 return -99;
16156 }
16157 if (dp_table_set == 0 || vni_set == 0)
16158 {
16159 errmsg ("vni and dp_table must be set");
16160 return -99;
16161 }
16162
16163 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010016164 M (GPE_ADD_DEL_IFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016165
16166 mp->is_add = is_add;
Florin Corasf53a8ad2017-06-15 15:07:32 -070016167 mp->dp_table = clib_host_to_net_u32 (dp_table);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016168 mp->is_l2 = is_l2;
Florin Corasf53a8ad2017-06-15 15:07:32 -070016169 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016170
16171 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016172 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016173
16174 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016175 W (ret);
16176 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016177}
16178
Filip Tehlar1e553a02017-08-02 12:45:07 +020016179static int
Filip Tehlar7048ff12017-07-27 08:09:14 +020016180api_one_map_register_fallback_threshold (vat_main_t * vam)
16181{
16182 unformat_input_t *input = vam->input;
16183 vl_api_one_map_register_fallback_threshold_t *mp;
16184 u32 value = 0;
16185 u8 is_set = 0;
16186 int ret;
16187
16188 /* Parse args required to build the message */
16189 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16190 {
16191 if (unformat (input, "%u", &value))
16192 is_set = 1;
16193 else
16194 {
16195 clib_warning ("parse error '%U'", format_unformat_error, input);
16196 return -99;
16197 }
16198 }
16199
16200 if (!is_set)
16201 {
16202 errmsg ("fallback threshold value is missing!");
16203 return -99;
16204 }
16205
16206 M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
16207 mp->value = clib_host_to_net_u32 (value);
16208
16209 /* send it... */
16210 S (mp);
16211
16212 /* Wait for a reply... */
16213 W (ret);
16214 return ret;
16215}
16216
16217static int
16218api_show_one_map_register_fallback_threshold (vat_main_t * vam)
16219{
16220 vl_api_show_one_map_register_fallback_threshold_t *mp;
16221 int ret;
16222
16223 M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
16224
16225 /* send it... */
16226 S (mp);
16227
16228 /* Wait for a reply... */
16229 W (ret);
16230 return ret;
16231}
16232
Filip Tehlara4980b82017-09-27 14:32:02 +020016233uword
16234unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args)
16235{
16236 u32 *proto = va_arg (*args, u32 *);
16237
16238 if (unformat (input, "udp"))
16239 *proto = 1;
16240 else if (unformat (input, "api"))
16241 *proto = 2;
16242 else
16243 return 0;
16244
16245 return 1;
16246}
16247
16248static int
16249api_one_set_transport_protocol (vat_main_t * vam)
16250{
16251 unformat_input_t *input = vam->input;
16252 vl_api_one_set_transport_protocol_t *mp;
16253 u8 is_set = 0;
16254 u32 protocol = 0;
16255 int ret;
16256
16257 /* Parse args required to build the message */
16258 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16259 {
16260 if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol))
16261 is_set = 1;
16262 else
16263 {
16264 clib_warning ("parse error '%U'", format_unformat_error, input);
16265 return -99;
16266 }
16267 }
16268
16269 if (!is_set)
16270 {
16271 errmsg ("Transport protocol missing!");
16272 return -99;
16273 }
16274
16275 M (ONE_SET_TRANSPORT_PROTOCOL, mp);
16276 mp->protocol = (u8) protocol;
16277
16278 /* send it... */
16279 S (mp);
16280
16281 /* Wait for a reply... */
16282 W (ret);
16283 return ret;
16284}
16285
16286static int
16287api_one_get_transport_protocol (vat_main_t * vam)
16288{
16289 vl_api_one_get_transport_protocol_t *mp;
16290 int ret;
16291
16292 M (ONE_GET_TRANSPORT_PROTOCOL, mp);
16293
16294 /* send it... */
16295 S (mp);
16296
16297 /* Wait for a reply... */
16298 W (ret);
16299 return ret;
16300}
16301
Filip Tehlar7048ff12017-07-27 08:09:14 +020016302static int
Filip Tehlar1e553a02017-08-02 12:45:07 +020016303api_one_map_register_set_ttl (vat_main_t * vam)
16304{
16305 unformat_input_t *input = vam->input;
16306 vl_api_one_map_register_set_ttl_t *mp;
16307 u32 ttl = 0;
16308 u8 is_set = 0;
16309 int ret;
16310
16311 /* Parse args required to build the message */
16312 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16313 {
16314 if (unformat (input, "%u", &ttl))
16315 is_set = 1;
16316 else
16317 {
16318 clib_warning ("parse error '%U'", format_unformat_error, input);
16319 return -99;
16320 }
16321 }
16322
16323 if (!is_set)
16324 {
16325 errmsg ("TTL value missing!");
16326 return -99;
16327 }
16328
16329 M (ONE_MAP_REGISTER_SET_TTL, mp);
16330 mp->ttl = clib_host_to_net_u32 (ttl);
16331
16332 /* send it... */
16333 S (mp);
16334
16335 /* Wait for a reply... */
16336 W (ret);
16337 return ret;
16338}
16339
16340static int
16341api_show_one_map_register_ttl (vat_main_t * vam)
16342{
16343 vl_api_show_one_map_register_ttl_t *mp;
16344 int ret;
16345
16346 M (SHOW_ONE_MAP_REGISTER_TTL, mp);
16347
16348 /* send it... */
16349 S (mp);
16350
16351 /* Wait for a reply... */
16352 W (ret);
16353 return ret;
16354}
16355
Damjan Marion7cd468a2016-12-19 23:05:39 +010016356/**
Filip Tehlar694396d2017-02-17 14:29:11 +010016357 * Add/del map request itr rlocs from ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010016358 *
16359 * @param vam vpp API test context
16360 * @return return code
16361 */
16362static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016363api_one_add_del_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016364{
16365 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016366 vl_api_one_add_del_map_request_itr_rlocs_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016367 u8 *locator_set_name = 0;
16368 u8 locator_set_name_set = 0;
16369 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016370 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016371
16372 /* Parse args required to build the message */
16373 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16374 {
16375 if (unformat (input, "del"))
16376 {
16377 is_add = 0;
16378 }
16379 else if (unformat (input, "%_%v%_", &locator_set_name))
16380 {
16381 locator_set_name_set = 1;
16382 }
16383 else
16384 {
16385 clib_warning ("parse error '%U'", format_unformat_error, input);
16386 return -99;
16387 }
16388 }
16389
16390 if (is_add && !locator_set_name_set)
16391 {
16392 errmsg ("itr-rloc is not set!");
16393 return -99;
16394 }
16395
16396 if (is_add && vec_len (locator_set_name) > 64)
16397 {
16398 errmsg ("itr-rloc locator-set name too long");
16399 vec_free (locator_set_name);
16400 return -99;
16401 }
16402
Filip Tehlar694396d2017-02-17 14:29:11 +010016403 M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016404 mp->is_add = is_add;
16405 if (is_add)
16406 {
16407 clib_memcpy (mp->locator_set_name, locator_set_name,
16408 vec_len (locator_set_name));
16409 }
16410 else
16411 {
Dave Barachb7b92992018-10-17 10:38:51 -040016412 clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Damjan Marion7cd468a2016-12-19 23:05:39 +010016413 }
16414 vec_free (locator_set_name);
16415
16416 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016417 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016418
16419 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016420 W (ret);
16421 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016422}
16423
Filip Tehlar694396d2017-02-17 14:29:11 +010016424#define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs
16425
Damjan Marion7cd468a2016-12-19 23:05:39 +010016426static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016427api_one_locator_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016428{
16429 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016430 vl_api_one_locator_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016431 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016432 u8 is_index_set = 0, is_name_set = 0;
16433 u8 *ls_name = 0;
16434 u32 ls_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016435 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016436
16437 /* Parse args required to build the message */
16438 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16439 {
16440 if (unformat (input, "ls_name %_%v%_", &ls_name))
16441 {
16442 is_name_set = 1;
16443 }
16444 else if (unformat (input, "ls_index %d", &ls_index))
16445 {
16446 is_index_set = 1;
16447 }
16448 else
16449 {
16450 errmsg ("parse error '%U'", format_unformat_error, input);
16451 return -99;
16452 }
16453 }
16454
16455 if (!is_index_set && !is_name_set)
16456 {
16457 errmsg ("error: expected one of index or name!");
16458 return -99;
16459 }
16460
16461 if (is_index_set && is_name_set)
16462 {
16463 errmsg ("error: only one param expected!");
16464 return -99;
16465 }
16466
16467 if (vec_len (ls_name) > 62)
16468 {
16469 errmsg ("error: locator set name too long!");
16470 return -99;
16471 }
16472
16473 if (!vam->json_output)
16474 {
16475 print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
16476 }
16477
Filip Tehlar694396d2017-02-17 14:29:11 +010016478 M (ONE_LOCATOR_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016479 mp->is_index_set = is_index_set;
16480
16481 if (is_index_set)
16482 mp->ls_index = clib_host_to_net_u32 (ls_index);
16483 else
16484 {
16485 vec_add1 (ls_name, 0);
16486 strncpy ((char *) mp->ls_name, (char *) ls_name,
16487 sizeof (mp->ls_name) - 1);
16488 }
16489
16490 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016491 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016492
16493 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040016494 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016495 S (mp_ping);
16496
Damjan Marion7cd468a2016-12-19 23:05:39 +010016497 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016498 W (ret);
16499 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016500}
16501
Filip Tehlar694396d2017-02-17 14:29:11 +010016502#define api_lisp_locator_dump api_one_locator_dump
16503
Damjan Marion7cd468a2016-12-19 23:05:39 +010016504static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016505api_one_locator_set_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016506{
Filip Tehlar694396d2017-02-17 14:29:11 +010016507 vl_api_one_locator_set_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016508 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016509 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016510 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016511 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016512
16513 /* Parse args required to build the message */
16514 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16515 {
16516 if (unformat (input, "local"))
16517 {
16518 filter = 1;
16519 }
16520 else if (unformat (input, "remote"))
16521 {
16522 filter = 2;
16523 }
16524 else
16525 {
16526 errmsg ("parse error '%U'", format_unformat_error, input);
16527 return -99;
16528 }
16529 }
16530
16531 if (!vam->json_output)
16532 {
16533 print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
16534 }
16535
Filip Tehlar694396d2017-02-17 14:29:11 +010016536 M (ONE_LOCATOR_SET_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016537
16538 mp->filter = filter;
16539
16540 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016541 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016542
16543 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040016544 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016545 S (mp_ping);
16546
Damjan Marion7cd468a2016-12-19 23:05:39 +010016547 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016548 W (ret);
16549 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016550}
16551
Filip Tehlar694396d2017-02-17 14:29:11 +010016552#define api_lisp_locator_set_dump api_one_locator_set_dump
16553
Damjan Marion7cd468a2016-12-19 23:05:39 +010016554static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016555api_one_eid_table_map_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016556{
16557 u8 is_l2 = 0;
16558 u8 mode_set = 0;
16559 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016560 vl_api_one_eid_table_map_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016561 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016562 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016563
16564 /* Parse args required to build the message */
16565 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16566 {
16567 if (unformat (input, "l2"))
16568 {
16569 is_l2 = 1;
16570 mode_set = 1;
16571 }
16572 else if (unformat (input, "l3"))
16573 {
16574 is_l2 = 0;
16575 mode_set = 1;
16576 }
16577 else
16578 {
16579 errmsg ("parse error '%U'", format_unformat_error, input);
16580 return -99;
16581 }
16582 }
16583
16584 if (!mode_set)
16585 {
16586 errmsg ("expected one of 'l2' or 'l3' parameter!");
16587 return -99;
16588 }
16589
16590 if (!vam->json_output)
16591 {
16592 print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
16593 }
16594
Filip Tehlar694396d2017-02-17 14:29:11 +010016595 M (ONE_EID_TABLE_MAP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016596 mp->is_l2 = is_l2;
16597
16598 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016599 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016600
16601 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040016602 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016603 S (mp_ping);
16604
Damjan Marion7cd468a2016-12-19 23:05:39 +010016605 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016606 W (ret);
16607 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016608}
16609
Filip Tehlar694396d2017-02-17 14:29:11 +010016610#define api_lisp_eid_table_map_dump api_one_eid_table_map_dump
16611
Damjan Marion7cd468a2016-12-19 23:05:39 +010016612static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016613api_one_eid_table_vni_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016614{
Filip Tehlar694396d2017-02-17 14:29:11 +010016615 vl_api_one_eid_table_vni_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016616 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016617 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016618
16619 if (!vam->json_output)
16620 {
16621 print (vam->ofp, "VNI");
16622 }
16623
Filip Tehlar694396d2017-02-17 14:29:11 +010016624 M (ONE_EID_TABLE_VNI_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016625
16626 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016627 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016628
16629 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040016630 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016631 S (mp_ping);
16632
Damjan Marion7cd468a2016-12-19 23:05:39 +010016633 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016634 W (ret);
16635 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016636}
16637
Filip Tehlar694396d2017-02-17 14:29:11 +010016638#define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump
16639
Damjan Marion7cd468a2016-12-19 23:05:39 +010016640static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016641api_one_eid_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016642{
16643 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016644 vl_api_one_eid_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016645 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016646 struct in_addr ip4;
16647 struct in6_addr ip6;
16648 u8 mac[6];
16649 u8 eid_type = ~0, eid_set = 0;
16650 u32 prefix_length = ~0, t, vni = 0;
16651 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016652 int ret;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016653 lisp_nsh_api_t nsh;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016654
16655 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16656 {
16657 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
16658 {
16659 eid_set = 1;
16660 eid_type = 0;
16661 prefix_length = t;
16662 }
16663 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
16664 {
16665 eid_set = 1;
16666 eid_type = 1;
16667 prefix_length = t;
16668 }
16669 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
16670 {
16671 eid_set = 1;
16672 eid_type = 2;
16673 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016674 else if (unformat (i, "eid %U", unformat_nsh_address, &nsh))
16675 {
16676 eid_set = 1;
16677 eid_type = 3;
16678 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010016679 else if (unformat (i, "vni %d", &t))
16680 {
16681 vni = t;
16682 }
16683 else if (unformat (i, "local"))
16684 {
16685 filter = 1;
16686 }
16687 else if (unformat (i, "remote"))
16688 {
16689 filter = 2;
16690 }
16691 else
16692 {
16693 errmsg ("parse error '%U'", format_unformat_error, i);
16694 return -99;
16695 }
16696 }
16697
16698 if (!vam->json_output)
16699 {
16700 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
16701 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
16702 }
16703
Filip Tehlar694396d2017-02-17 14:29:11 +010016704 M (ONE_EID_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016705
16706 mp->filter = filter;
16707 if (eid_set)
16708 {
16709 mp->eid_set = 1;
16710 mp->vni = htonl (vni);
16711 mp->eid_type = eid_type;
16712 switch (eid_type)
16713 {
16714 case 0:
16715 mp->prefix_length = prefix_length;
16716 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
16717 break;
16718 case 1:
16719 mp->prefix_length = prefix_length;
16720 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
16721 break;
16722 case 2:
16723 clib_memcpy (mp->eid, mac, sizeof (mac));
16724 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016725 case 3:
16726 clib_memcpy (mp->eid, &nsh, sizeof (nsh));
16727 break;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016728 default:
16729 errmsg ("unknown EID type %d!", eid_type);
16730 return -99;
16731 }
16732 }
16733
16734 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016735 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016736
16737 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040016738 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016739 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016740
16741 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016742 W (ret);
16743 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016744}
16745
Filip Tehlar694396d2017-02-17 14:29:11 +010016746#define api_lisp_eid_table_dump api_one_eid_table_dump
16747
Damjan Marion7cd468a2016-12-19 23:05:39 +010016748static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016749api_lisp_gpe_fwd_entries_get (vat_main_t * vam)
16750{
16751 unformat_input_t *i = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010016752 vl_api_gpe_fwd_entries_get_t *mp;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016753 u8 vni_set = 0;
16754 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016755 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016756
16757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16758 {
16759 if (unformat (i, "vni %d", &vni))
16760 {
16761 vni_set = 1;
16762 }
16763 else
16764 {
16765 errmsg ("parse error '%U'", format_unformat_error, i);
16766 return -99;
16767 }
16768 }
16769
16770 if (!vni_set)
16771 {
16772 errmsg ("vni not set!");
16773 return -99;
16774 }
16775
16776 if (!vam->json_output)
16777 {
16778 print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table",
16779 "leid", "reid");
16780 }
16781
Filip Tehlar82786c42017-02-20 15:20:37 +010016782 M (GPE_FWD_ENTRIES_GET, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016783 mp->vni = clib_host_to_net_u32 (vni);
16784
16785 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016786 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016787
16788 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016789 W (ret);
16790 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016791}
16792
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016793#define vl_api_gpe_native_fwd_rpaths_get_reply_t_endian vl_noop_handler
16794#define vl_api_gpe_native_fwd_rpaths_get_reply_t_print vl_noop_handler
Filip Tehlar0eb874e2017-05-18 14:23:32 +020016795#define vl_api_gpe_fwd_entry_vnis_get_reply_t_endian vl_noop_handler
16796#define vl_api_gpe_fwd_entry_vnis_get_reply_t_print vl_noop_handler
Filip Tehlar82786c42017-02-20 15:20:37 +010016797#define vl_api_gpe_fwd_entries_get_reply_t_endian vl_noop_handler
16798#define vl_api_gpe_fwd_entries_get_reply_t_print vl_noop_handler
16799#define vl_api_gpe_fwd_entry_path_details_t_endian vl_noop_handler
16800#define vl_api_gpe_fwd_entry_path_details_t_print vl_noop_handler
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016801
16802static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016803api_one_adjacencies_get (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016804{
16805 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016806 vl_api_one_adjacencies_get_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016807 u8 vni_set = 0;
16808 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016809 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016810
16811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16812 {
16813 if (unformat (i, "vni %d", &vni))
16814 {
16815 vni_set = 1;
16816 }
16817 else
16818 {
16819 errmsg ("parse error '%U'", format_unformat_error, i);
16820 return -99;
16821 }
16822 }
16823
16824 if (!vni_set)
16825 {
16826 errmsg ("vni not set!");
16827 return -99;
16828 }
16829
16830 if (!vam->json_output)
16831 {
16832 print (vam->ofp, "%s %40s", "leid", "reid");
16833 }
16834
Filip Tehlar694396d2017-02-17 14:29:11 +010016835 M (ONE_ADJACENCIES_GET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016836 mp->vni = clib_host_to_net_u32 (vni);
16837
16838 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016839 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016840
16841 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016842 W (ret);
16843 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016844}
16845
Filip Tehlar694396d2017-02-17 14:29:11 +010016846#define api_lisp_adjacencies_get api_one_adjacencies_get
16847
Damjan Marion7cd468a2016-12-19 23:05:39 +010016848static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016849api_gpe_native_fwd_rpaths_get (vat_main_t * vam)
16850{
16851 unformat_input_t *i = vam->input;
16852 vl_api_gpe_native_fwd_rpaths_get_t *mp;
16853 int ret;
16854 u8 ip_family_set = 0, is_ip4 = 1;
16855
16856 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16857 {
16858 if (unformat (i, "ip4"))
16859 {
16860 ip_family_set = 1;
16861 is_ip4 = 1;
16862 }
16863 else if (unformat (i, "ip6"))
16864 {
16865 ip_family_set = 1;
16866 is_ip4 = 0;
16867 }
16868 else
16869 {
16870 errmsg ("parse error '%U'", format_unformat_error, i);
16871 return -99;
16872 }
16873 }
16874
16875 if (!ip_family_set)
16876 {
16877 errmsg ("ip family not set!");
16878 return -99;
16879 }
16880
16881 M (GPE_NATIVE_FWD_RPATHS_GET, mp);
16882 mp->is_ip4 = is_ip4;
16883
16884 /* send it... */
16885 S (mp);
16886
16887 /* Wait for a reply... */
16888 W (ret);
16889 return ret;
16890}
16891
16892static int
Filip Tehlar0eb874e2017-05-18 14:23:32 +020016893api_gpe_fwd_entry_vnis_get (vat_main_t * vam)
16894{
16895 vl_api_gpe_fwd_entry_vnis_get_t *mp;
16896 int ret;
16897
16898 if (!vam->json_output)
16899 {
16900 print (vam->ofp, "VNIs");
16901 }
16902
16903 M (GPE_FWD_ENTRY_VNIS_GET, mp);
16904
16905 /* send it... */
16906 S (mp);
16907
16908 /* Wait for a reply... */
16909 W (ret);
16910 return ret;
16911}
16912
16913static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016914api_gpe_add_del_native_fwd_rpath (vat_main_t * vam)
16915{
16916 unformat_input_t *i = vam->input;
16917 vl_api_gpe_add_del_native_fwd_rpath_t *mp;
16918 int ret = 0;
16919 u8 is_add = 1, ip_set = 0, is_ip4 = 1;
16920 struct in_addr ip4;
16921 struct in6_addr ip6;
16922 u32 table_id = 0, nh_sw_if_index = ~0;
16923
Dave Barachb7b92992018-10-17 10:38:51 -040016924 clib_memset (&ip4, 0, sizeof (ip4));
16925 clib_memset (&ip6, 0, sizeof (ip6));
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016926
16927 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16928 {
16929 if (unformat (i, "del"))
16930 is_add = 0;
16931 else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4,
16932 api_unformat_sw_if_index, vam, &nh_sw_if_index))
16933 {
16934 ip_set = 1;
16935 is_ip4 = 1;
16936 }
16937 else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6,
16938 api_unformat_sw_if_index, vam, &nh_sw_if_index))
16939 {
16940 ip_set = 1;
16941 is_ip4 = 0;
16942 }
16943 else if (unformat (i, "via %U", unformat_ip4_address, &ip4))
16944 {
16945 ip_set = 1;
16946 is_ip4 = 1;
16947 nh_sw_if_index = ~0;
16948 }
16949 else if (unformat (i, "via %U", unformat_ip6_address, &ip6))
16950 {
16951 ip_set = 1;
16952 is_ip4 = 0;
16953 nh_sw_if_index = ~0;
16954 }
16955 else if (unformat (i, "table %d", &table_id))
16956 ;
16957 else
16958 {
16959 errmsg ("parse error '%U'", format_unformat_error, i);
16960 return -99;
16961 }
16962 }
16963
16964 if (!ip_set)
16965 {
16966 errmsg ("nh addr not set!");
16967 return -99;
16968 }
16969
16970 M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp);
16971 mp->is_add = is_add;
16972 mp->table_id = clib_host_to_net_u32 (table_id);
16973 mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index);
16974 mp->is_ip4 = is_ip4;
16975 if (is_ip4)
16976 clib_memcpy (mp->nh_addr, &ip4, sizeof (ip4));
16977 else
16978 clib_memcpy (mp->nh_addr, &ip6, sizeof (ip6));
16979
16980 /* send it... */
16981 S (mp);
16982
16983 /* Wait for a reply... */
16984 W (ret);
16985 return ret;
16986}
16987
16988static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016989api_one_map_server_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016990{
Filip Tehlar694396d2017-02-17 14:29:11 +010016991 vl_api_one_map_server_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016992 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016993 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016994
16995 if (!vam->json_output)
16996 {
16997 print (vam->ofp, "%=20s", "Map server");
16998 }
16999
Filip Tehlar694396d2017-02-17 14:29:11 +010017000 M (ONE_MAP_SERVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017001 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017002 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017003
17004 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017005 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017006 S (mp_ping);
17007
Damjan Marion7cd468a2016-12-19 23:05:39 +010017008 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017009 W (ret);
17010 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017011}
17012
Filip Tehlar694396d2017-02-17 14:29:11 +010017013#define api_lisp_map_server_dump api_one_map_server_dump
17014
Damjan Marion7cd468a2016-12-19 23:05:39 +010017015static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017016api_one_map_resolver_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017017{
Filip Tehlar694396d2017-02-17 14:29:11 +010017018 vl_api_one_map_resolver_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017019 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017020 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017021
17022 if (!vam->json_output)
17023 {
17024 print (vam->ofp, "%=20s", "Map resolver");
17025 }
17026
Filip Tehlar694396d2017-02-17 14:29:11 +010017027 M (ONE_MAP_RESOLVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017028 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017029 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017030
17031 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017032 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017033 S (mp_ping);
17034
Damjan Marion7cd468a2016-12-19 23:05:39 +010017035 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017036 W (ret);
17037 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017038}
17039
Filip Tehlar694396d2017-02-17 14:29:11 +010017040#define api_lisp_map_resolver_dump api_one_map_resolver_dump
17041
Damjan Marion7cd468a2016-12-19 23:05:39 +010017042static int
Filip Tehlar21511912017-04-07 10:41:42 +020017043api_one_stats_flush (vat_main_t * vam)
17044{
17045 vl_api_one_stats_flush_t *mp;
17046 int ret = 0;
17047
17048 M (ONE_STATS_FLUSH, mp);
17049 S (mp);
17050 W (ret);
17051 return ret;
17052}
17053
17054static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010017055api_one_stats_dump (vat_main_t * vam)
17056{
17057 vl_api_one_stats_dump_t *mp;
17058 vl_api_control_ping_t *mp_ping;
17059 int ret;
17060
17061 M (ONE_STATS_DUMP, mp);
17062 /* send it... */
17063 S (mp);
17064
17065 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017066 MPING (CONTROL_PING, mp_ping);
Filip Tehlar4868ff62017-03-09 16:48:39 +010017067 S (mp_ping);
17068
17069 /* Wait for a reply... */
17070 W (ret);
17071 return ret;
17072}
17073
17074static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017075api_show_one_status (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017076{
Filip Tehlar694396d2017-02-17 14:29:11 +010017077 vl_api_show_one_status_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017078 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017079
17080 if (!vam->json_output)
17081 {
Filip Tehlar694396d2017-02-17 14:29:11 +010017082 print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
Damjan Marion7cd468a2016-12-19 23:05:39 +010017083 }
17084
Filip Tehlar694396d2017-02-17 14:29:11 +010017085 M (SHOW_ONE_STATUS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017086 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017087 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017088 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017089 W (ret);
17090 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017091}
17092
Filip Tehlar694396d2017-02-17 14:29:11 +010017093#define api_show_lisp_status api_show_one_status
17094
Damjan Marion7cd468a2016-12-19 23:05:39 +010017095static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017096api_lisp_gpe_fwd_entry_path_dump (vat_main_t * vam)
17097{
Filip Tehlar82786c42017-02-20 15:20:37 +010017098 vl_api_gpe_fwd_entry_path_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017099 vl_api_control_ping_t *mp_ping;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017100 unformat_input_t *i = vam->input;
17101 u32 fwd_entry_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017102 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017103
17104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17105 {
17106 if (unformat (i, "index %d", &fwd_entry_index))
17107 ;
17108 else
17109 break;
17110 }
17111
17112 if (~0 == fwd_entry_index)
17113 {
17114 errmsg ("no index specified!");
17115 return -99;
17116 }
17117
17118 if (!vam->json_output)
17119 {
17120 print (vam->ofp, "first line");
17121 }
17122
Filip Tehlar82786c42017-02-20 15:20:37 +010017123 M (GPE_FWD_ENTRY_PATH_DUMP, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017124
17125 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017126 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017127 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017128 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017129 S (mp_ping);
17130
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017131 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017132 W (ret);
17133 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017134}
17135
17136static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017137api_one_get_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017138{
Filip Tehlar694396d2017-02-17 14:29:11 +010017139 vl_api_one_get_map_request_itr_rlocs_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017140 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017141
17142 if (!vam->json_output)
17143 {
17144 print (vam->ofp, "%=20s", "itr-rlocs:");
17145 }
17146
Filip Tehlar694396d2017-02-17 14:29:11 +010017147 M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017148 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017149 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017150 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017151 W (ret);
17152 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017153}
17154
Filip Tehlar694396d2017-02-17 14:29:11 +010017155#define api_lisp_get_map_request_itr_rlocs api_one_get_map_request_itr_rlocs
17156
Damjan Marion7cd468a2016-12-19 23:05:39 +010017157static int
17158api_af_packet_create (vat_main_t * vam)
17159{
17160 unformat_input_t *i = vam->input;
17161 vl_api_af_packet_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017162 u8 *host_if_name = 0;
17163 u8 hw_addr[6];
17164 u8 random_hw_addr = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017165 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017166
Dave Barachb7b92992018-10-17 10:38:51 -040017167 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017168
17169 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17170 {
17171 if (unformat (i, "name %s", &host_if_name))
17172 vec_add1 (host_if_name, 0);
17173 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
17174 random_hw_addr = 0;
17175 else
17176 break;
17177 }
17178
17179 if (!vec_len (host_if_name))
17180 {
17181 errmsg ("host-interface name must be specified");
17182 return -99;
17183 }
17184
17185 if (vec_len (host_if_name) > 64)
17186 {
17187 errmsg ("host-interface name too long");
17188 return -99;
17189 }
17190
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017191 M (AF_PACKET_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017192
17193 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
17194 clib_memcpy (mp->hw_addr, hw_addr, 6);
17195 mp->use_random_hw_addr = random_hw_addr;
17196 vec_free (host_if_name);
17197
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017198 S (mp);
Dave Baracha1a093d2017-03-02 13:13:23 -050017199
17200 /* *INDENT-OFF* */
17201 W2 (ret,
17202 ({
17203 if (ret == 0)
17204 fprintf (vam->ofp ? vam->ofp : stderr,
17205 " new sw_if_index = %d\n", vam->sw_if_index);
17206 }));
17207 /* *INDENT-ON* */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017208 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017209}
17210
17211static int
17212api_af_packet_delete (vat_main_t * vam)
17213{
17214 unformat_input_t *i = vam->input;
17215 vl_api_af_packet_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017216 u8 *host_if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017217 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017218
17219 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17220 {
17221 if (unformat (i, "name %s", &host_if_name))
17222 vec_add1 (host_if_name, 0);
17223 else
17224 break;
17225 }
17226
17227 if (!vec_len (host_if_name))
17228 {
17229 errmsg ("host-interface name must be specified");
17230 return -99;
17231 }
17232
17233 if (vec_len (host_if_name) > 64)
17234 {
17235 errmsg ("host-interface name too long");
17236 return -99;
17237 }
17238
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017239 M (AF_PACKET_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017240
17241 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
17242 vec_free (host_if_name);
17243
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017244 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060017245 W (ret);
17246 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017247}
17248
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020017249static void vl_api_af_packet_details_t_handler
17250 (vl_api_af_packet_details_t * mp)
17251{
17252 vat_main_t *vam = &vat_main;
17253
17254 print (vam->ofp, "%-16s %d",
17255 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
17256}
17257
17258static void vl_api_af_packet_details_t_handler_json
17259 (vl_api_af_packet_details_t * mp)
17260{
17261 vat_main_t *vam = &vat_main;
17262 vat_json_node_t *node = NULL;
17263
17264 if (VAT_JSON_ARRAY != vam->json_tree.type)
17265 {
17266 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17267 vat_json_init_array (&vam->json_tree);
17268 }
17269 node = vat_json_array_add (&vam->json_tree);
17270
17271 vat_json_init_object (node);
17272 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
17273 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
17274}
17275
17276static int
17277api_af_packet_dump (vat_main_t * vam)
17278{
17279 vl_api_af_packet_dump_t *mp;
17280 vl_api_control_ping_t *mp_ping;
17281 int ret;
17282
17283 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
17284 /* Get list of tap interfaces */
17285 M (AF_PACKET_DUMP, mp);
17286 S (mp);
17287
17288 /* Use a control ping for synchronization */
17289 MPING (CONTROL_PING, mp_ping);
17290 S (mp_ping);
17291
17292 W (ret);
17293 return ret;
17294}
17295
Damjan Marion7cd468a2016-12-19 23:05:39 +010017296static int
17297api_policer_add_del (vat_main_t * vam)
17298{
17299 unformat_input_t *i = vam->input;
17300 vl_api_policer_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017301 u8 is_add = 1;
17302 u8 *name = 0;
17303 u32 cir = 0;
17304 u32 eir = 0;
17305 u64 cb = 0;
17306 u64 eb = 0;
17307 u8 rate_type = 0;
17308 u8 round_type = 0;
17309 u8 type = 0;
17310 u8 color_aware = 0;
17311 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017312 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017313
17314 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
17315 conform_action.dscp = 0;
17316 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
17317 exceed_action.dscp = 0;
17318 violate_action.action_type = SSE2_QOS_ACTION_DROP;
17319 violate_action.dscp = 0;
17320
17321 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17322 {
17323 if (unformat (i, "del"))
17324 is_add = 0;
17325 else if (unformat (i, "name %s", &name))
17326 vec_add1 (name, 0);
17327 else if (unformat (i, "cir %u", &cir))
17328 ;
17329 else if (unformat (i, "eir %u", &eir))
17330 ;
17331 else if (unformat (i, "cb %u", &cb))
17332 ;
17333 else if (unformat (i, "eb %u", &eb))
17334 ;
17335 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
17336 &rate_type))
17337 ;
17338 else if (unformat (i, "round_type %U", unformat_policer_round_type,
17339 &round_type))
17340 ;
17341 else if (unformat (i, "type %U", unformat_policer_type, &type))
17342 ;
17343 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
17344 &conform_action))
17345 ;
17346 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
17347 &exceed_action))
17348 ;
17349 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
17350 &violate_action))
17351 ;
17352 else if (unformat (i, "color-aware"))
17353 color_aware = 1;
17354 else
17355 break;
17356 }
17357
17358 if (!vec_len (name))
17359 {
17360 errmsg ("policer name must be specified");
17361 return -99;
17362 }
17363
17364 if (vec_len (name) > 64)
17365 {
17366 errmsg ("policer name too long");
17367 return -99;
17368 }
17369
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017370 M (POLICER_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017371
17372 clib_memcpy (mp->name, name, vec_len (name));
17373 vec_free (name);
17374 mp->is_add = is_add;
Neale Rannsd91c1db2017-07-31 02:30:50 -070017375 mp->cir = ntohl (cir);
17376 mp->eir = ntohl (eir);
17377 mp->cb = clib_net_to_host_u64 (cb);
17378 mp->eb = clib_net_to_host_u64 (eb);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017379 mp->rate_type = rate_type;
17380 mp->round_type = round_type;
17381 mp->type = type;
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010017382 mp->conform_action.type = conform_action.action_type;
17383 mp->conform_action.dscp = conform_action.dscp;
17384 mp->exceed_action.type = exceed_action.action_type;
17385 mp->exceed_action.dscp = exceed_action.dscp;
17386 mp->violate_action.type = violate_action.action_type;
17387 mp->violate_action.dscp = violate_action.dscp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017388 mp->color_aware = color_aware;
17389
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017390 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060017391 W (ret);
17392 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017393}
17394
17395static int
17396api_policer_dump (vat_main_t * vam)
17397{
17398 unformat_input_t *i = vam->input;
17399 vl_api_policer_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017400 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017401 u8 *match_name = 0;
17402 u8 match_name_valid = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017403 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017404
17405 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17406 {
17407 if (unformat (i, "name %s", &match_name))
17408 {
17409 vec_add1 (match_name, 0);
17410 match_name_valid = 1;
17411 }
17412 else
17413 break;
17414 }
17415
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017416 M (POLICER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017417 mp->match_name_valid = match_name_valid;
17418 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
17419 vec_free (match_name);
17420 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017421 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017422
17423 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017424 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017425 S (mp_ping);
17426
Damjan Marion7cd468a2016-12-19 23:05:39 +010017427 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017428 W (ret);
17429 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017430}
17431
17432static int
17433api_policer_classify_set_interface (vat_main_t * vam)
17434{
17435 unformat_input_t *i = vam->input;
17436 vl_api_policer_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017437 u32 sw_if_index;
17438 int sw_if_index_set;
17439 u32 ip4_table_index = ~0;
17440 u32 ip6_table_index = ~0;
17441 u32 l2_table_index = ~0;
17442 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017443 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017444
17445 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17446 {
17447 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
17448 sw_if_index_set = 1;
17449 else if (unformat (i, "sw_if_index %d", &sw_if_index))
17450 sw_if_index_set = 1;
17451 else if (unformat (i, "del"))
17452 is_add = 0;
17453 else if (unformat (i, "ip4-table %d", &ip4_table_index))
17454 ;
17455 else if (unformat (i, "ip6-table %d", &ip6_table_index))
17456 ;
17457 else if (unformat (i, "l2-table %d", &l2_table_index))
17458 ;
17459 else
17460 {
17461 clib_warning ("parse error '%U'", format_unformat_error, i);
17462 return -99;
17463 }
17464 }
17465
17466 if (sw_if_index_set == 0)
17467 {
17468 errmsg ("missing interface name or sw_if_index");
17469 return -99;
17470 }
17471
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017472 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017473
17474 mp->sw_if_index = ntohl (sw_if_index);
17475 mp->ip4_table_index = ntohl (ip4_table_index);
17476 mp->ip6_table_index = ntohl (ip6_table_index);
17477 mp->l2_table_index = ntohl (l2_table_index);
17478 mp->is_add = is_add;
17479
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017480 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060017481 W (ret);
17482 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017483}
17484
17485static int
17486api_policer_classify_dump (vat_main_t * vam)
17487{
17488 unformat_input_t *i = vam->input;
17489 vl_api_policer_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017490 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017491 u8 type = POLICER_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017492 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017493
17494 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
17495 ;
17496 else
17497 {
17498 errmsg ("classify table type must be specified");
17499 return -99;
17500 }
17501
17502 if (!vam->json_output)
17503 {
17504 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
17505 }
17506
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017507 M (POLICER_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017508 mp->type = type;
17509 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017510 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017511
17512 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017513 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017514 S (mp_ping);
17515
Damjan Marion7cd468a2016-12-19 23:05:39 +010017516 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017517 W (ret);
17518 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017519}
17520
Neale Ranns097fa662018-05-01 05:17:55 -070017521static u8 *
17522format_fib_api_path_nh_proto (u8 * s, va_list * args)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017523{
Neale Ranns097fa662018-05-01 05:17:55 -070017524 vl_api_fib_path_nh_proto_t proto =
17525 va_arg (*args, vl_api_fib_path_nh_proto_t);
17526
17527 switch (proto)
17528 {
17529 case FIB_API_PATH_NH_PROTO_IP4:
17530 s = format (s, "ip4");
17531 break;
17532 case FIB_API_PATH_NH_PROTO_IP6:
17533 s = format (s, "ip6");
17534 break;
17535 case FIB_API_PATH_NH_PROTO_MPLS:
17536 s = format (s, "mpls");
17537 break;
17538 case FIB_API_PATH_NH_PROTO_BIER:
17539 s = format (s, "bier");
17540 break;
17541 case FIB_API_PATH_NH_PROTO_ETHERNET:
17542 s = format (s, "ethernet");
17543 break;
17544 }
17545
17546 return (s);
17547}
17548
17549static u8 *
17550format_vl_api_ip_address_union (u8 * s, va_list * args)
17551{
Jakub Grajciar7dd63e52020-03-19 08:03:55 +010017552 vl_api_address_family_t af = va_arg (*args, int);
Neale Ranns097fa662018-05-01 05:17:55 -070017553 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
17554
17555 switch (af)
17556 {
17557 case ADDRESS_IP4:
17558 s = format (s, "%U", format_ip4_address, u->ip4);
17559 break;
17560 case ADDRESS_IP6:
17561 s = format (s, "%U", format_ip6_address, u->ip6);
17562 break;
17563 }
17564 return (s);
17565}
17566
17567static u8 *
17568format_vl_api_fib_path_type (u8 * s, va_list * args)
17569{
17570 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
17571
17572 switch (t)
17573 {
17574 case FIB_API_PATH_TYPE_NORMAL:
17575 s = format (s, "normal");
17576 break;
17577 case FIB_API_PATH_TYPE_LOCAL:
17578 s = format (s, "local");
17579 break;
17580 case FIB_API_PATH_TYPE_DROP:
17581 s = format (s, "drop");
17582 break;
17583 case FIB_API_PATH_TYPE_UDP_ENCAP:
17584 s = format (s, "udp-encap");
17585 break;
17586 case FIB_API_PATH_TYPE_BIER_IMP:
17587 s = format (s, "bier-imp");
17588 break;
17589 case FIB_API_PATH_TYPE_ICMP_UNREACH:
17590 s = format (s, "unreach");
17591 break;
17592 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
17593 s = format (s, "prohibit");
17594 break;
17595 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
17596 s = format (s, "src-lookup");
17597 break;
17598 case FIB_API_PATH_TYPE_DVR:
17599 s = format (s, "dvr");
17600 break;
17601 case FIB_API_PATH_TYPE_INTERFACE_RX:
17602 s = format (s, "interface-rx");
17603 break;
17604 case FIB_API_PATH_TYPE_CLASSIFY:
17605 s = format (s, "classify");
17606 break;
17607 }
17608
17609 return (s);
17610}
17611
17612static void
17613vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
17614{
17615 print (vam->ofp,
17616 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
17617 ntohl (fp->weight), ntohl (fp->sw_if_index),
17618 format_vl_api_fib_path_type, fp->type,
17619 format_fib_api_path_nh_proto, fp->proto,
17620 format_vl_api_ip_address_union, &fp->nh.address);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017621}
17622
17623static void
17624vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
Neale Ranns31ed7442018-02-23 05:29:09 -080017625 vl_api_fib_path_t * fp)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017626{
17627 struct in_addr ip4;
17628 struct in6_addr ip6;
17629
17630 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
17631 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
Neale Ranns097fa662018-05-01 05:17:55 -070017632 vat_json_object_add_uint (node, "type", fp->type);
17633 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
17634 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017635 {
Neale Ranns097fa662018-05-01 05:17:55 -070017636 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017637 vat_json_object_add_ip4 (node, "next_hop", ip4);
17638 }
Dave Barachc35f3e82020-04-02 10:44:09 -040017639 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017640 {
Neale Ranns097fa662018-05-01 05:17:55 -070017641 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017642 vat_json_object_add_ip6 (node, "next_hop", ip6);
17643 }
17644}
17645
17646static void
17647vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017648{
17649 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017650 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080017651 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017652 i32 i;
17653
Neale Ranns097fa662018-05-01 05:17:55 -070017654 print (vam->ofp, "sw_if_index %d via:",
17655 ntohl (mp->mt_tunnel.mt_sw_if_index));
17656 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017657 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017658 {
Neale Ranns097fa662018-05-01 05:17:55 -070017659 vl_api_fib_path_print (vam, fp);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017660 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017661 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017662
Damjan Marion7cd468a2016-12-19 23:05:39 +010017663 print (vam->ofp, "");
17664}
17665
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017666#define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
17667#define vl_api_mpls_tunnel_details_t_print vl_noop_handler
17668
17669static void
17670vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017671{
17672 vat_main_t *vam = &vat_main;
17673 vat_json_node_t *node = NULL;
Neale Ranns097fa662018-05-01 05:17:55 -070017674 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080017675 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017676 i32 i;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017677
17678 if (VAT_JSON_ARRAY != vam->json_tree.type)
17679 {
17680 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17681 vat_json_init_array (&vam->json_tree);
17682 }
17683 node = vat_json_array_add (&vam->json_tree);
17684
17685 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070017686 vat_json_object_add_uint (node, "sw_if_index",
17687 ntohl (mp->mt_tunnel.mt_sw_if_index));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017688
Neale Ranns097fa662018-05-01 05:17:55 -070017689 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017690
Neale Ranns097fa662018-05-01 05:17:55 -070017691 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017692 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017693 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017694 vl_api_mpls_fib_path_json_print (node, fp);
17695 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017696 }
17697}
17698
17699static int
17700api_mpls_tunnel_dump (vat_main_t * vam)
17701{
17702 vl_api_mpls_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017703 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017704 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017705
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017706 M (MPLS_TUNNEL_DUMP, mp);
Neale Ranns097fa662018-05-01 05:17:55 -070017707
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017708 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017709
17710 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017711 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017712 S (mp_ping);
17713
Jon Loeliger56c7b012017-02-01 12:31:41 -060017714 W (ret);
17715 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017716}
17717
Neale Ranns097fa662018-05-01 05:17:55 -070017718#define vl_api_mpls_table_details_t_endian vl_noop_handler
17719#define vl_api_mpls_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010017720
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017721
Damjan Marion7cd468a2016-12-19 23:05:39 +010017722static void
Neale Ranns097fa662018-05-01 05:17:55 -070017723vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017724{
17725 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017726
17727 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
17728}
17729
17730static void vl_api_mpls_table_details_t_handler_json
17731 (vl_api_mpls_table_details_t * mp)
17732{
17733 vat_main_t *vam = &vat_main;
17734 vat_json_node_t *node = NULL;
17735
17736 if (VAT_JSON_ARRAY != vam->json_tree.type)
17737 {
17738 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17739 vat_json_init_array (&vam->json_tree);
17740 }
17741 node = vat_json_array_add (&vam->json_tree);
17742
17743 vat_json_init_object (node);
17744 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
17745}
17746
17747static int
17748api_mpls_table_dump (vat_main_t * vam)
17749{
17750 vl_api_mpls_table_dump_t *mp;
17751 vl_api_control_ping_t *mp_ping;
17752 int ret;
17753
17754 M (MPLS_TABLE_DUMP, mp);
17755 S (mp);
17756
17757 /* Use a control ping for synchronization */
17758 MPING (CONTROL_PING, mp_ping);
17759 S (mp_ping);
17760
17761 W (ret);
17762 return ret;
17763}
17764
17765#define vl_api_mpls_route_details_t_endian vl_noop_handler
17766#define vl_api_mpls_route_details_t_print vl_noop_handler
17767
17768static void
17769vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
17770{
17771 vat_main_t *vam = &vat_main;
Dave Barach4bda2d92019-07-03 15:21:50 -040017772 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080017773 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017774 int i;
17775
17776 print (vam->ofp,
17777 "table-id %d, label %u, ess_bit %u",
Neale Ranns097fa662018-05-01 05:17:55 -070017778 ntohl (mp->mr_route.mr_table_id),
17779 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
17780 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017781 for (i = 0; i < count; i++)
17782 {
Neale Ranns097fa662018-05-01 05:17:55 -070017783 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017784 fp++;
17785 }
17786}
17787
Neale Ranns097fa662018-05-01 05:17:55 -070017788static void vl_api_mpls_route_details_t_handler_json
17789 (vl_api_mpls_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017790{
17791 vat_main_t *vam = &vat_main;
Dave Barach4bda2d92019-07-03 15:21:50 -040017792 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017793 vat_json_node_t *node = NULL;
Neale Ranns31ed7442018-02-23 05:29:09 -080017794 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017795 int i;
17796
17797 if (VAT_JSON_ARRAY != vam->json_tree.type)
17798 {
17799 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17800 vat_json_init_array (&vam->json_tree);
17801 }
17802 node = vat_json_array_add (&vam->json_tree);
17803
17804 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070017805 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
17806 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
17807 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017808 vat_json_object_add_uint (node, "path_count", count);
Neale Ranns097fa662018-05-01 05:17:55 -070017809 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017810 for (i = 0; i < count; i++)
17811 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017812 vl_api_mpls_fib_path_json_print (node, fp);
17813 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017814 }
17815}
17816
17817static int
Neale Ranns097fa662018-05-01 05:17:55 -070017818api_mpls_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017819{
Neale Ranns097fa662018-05-01 05:17:55 -070017820 unformat_input_t *input = vam->input;
17821 vl_api_mpls_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017822 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070017823 u32 table_id;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017824 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017825
Neale Ranns097fa662018-05-01 05:17:55 -070017826 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17827 {
17828 if (unformat (input, "table_id %d", &table_id))
17829 ;
17830 else
17831 break;
17832 }
17833 if (table_id == ~0)
17834 {
17835 errmsg ("missing table id");
17836 return -99;
17837 }
17838
17839 M (MPLS_ROUTE_DUMP, mp);
17840
17841 mp->table.mt_table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017842 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017843
17844 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017845 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017846 S (mp_ping);
17847
Jon Loeliger56c7b012017-02-01 12:31:41 -060017848 W (ret);
17849 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017850}
17851
Neale Ranns097fa662018-05-01 05:17:55 -070017852#define vl_api_ip_table_details_t_endian vl_noop_handler
17853#define vl_api_ip_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010017854
17855static void
Neale Ranns097fa662018-05-01 05:17:55 -070017856vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017857{
17858 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017859
17860 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070017861 "%s; table-id %d, prefix %U/%d",
17862 mp->table.name, ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017863}
17864
Neale Ranns097fa662018-05-01 05:17:55 -070017865
17866static void vl_api_ip_table_details_t_handler_json
17867 (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017868{
17869 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017870 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017871
17872 if (VAT_JSON_ARRAY != vam->json_tree.type)
17873 {
17874 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17875 vat_json_init_array (&vam->json_tree);
17876 }
17877 node = vat_json_array_add (&vam->json_tree);
17878
17879 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070017880 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017881}
17882
17883static int
Neale Ranns097fa662018-05-01 05:17:55 -070017884api_ip_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017885{
Neale Ranns097fa662018-05-01 05:17:55 -070017886 vl_api_ip_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017887 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017888 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017889
Neale Ranns097fa662018-05-01 05:17:55 -070017890 M (IP_TABLE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017891 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017892
17893 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017894 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017895 S (mp_ping);
17896
Jon Loeliger56c7b012017-02-01 12:31:41 -060017897 W (ret);
17898 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017899}
17900
Neale Ranns5a8123b2017-01-26 01:18:23 -080017901static int
Neale Ranns097fa662018-05-01 05:17:55 -070017902api_ip_mtable_dump (vat_main_t * vam)
Neale Ranns5a8123b2017-01-26 01:18:23 -080017903{
Neale Ranns097fa662018-05-01 05:17:55 -070017904 vl_api_ip_mtable_dump_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -080017905 vl_api_control_ping_t *mp_ping;
17906 int ret;
17907
Neale Ranns097fa662018-05-01 05:17:55 -070017908 M (IP_MTABLE_DUMP, mp);
17909 S (mp);
17910
17911 /* Use a control ping for synchronization */
17912 MPING (CONTROL_PING, mp_ping);
17913 S (mp_ping);
17914
17915 W (ret);
17916 return ret;
17917}
17918
17919static int
17920api_ip_mroute_dump (vat_main_t * vam)
17921{
17922 unformat_input_t *input = vam->input;
17923 vl_api_control_ping_t *mp_ping;
17924 vl_api_ip_mroute_dump_t *mp;
17925 int ret, is_ip6;
17926 u32 table_id;
17927
17928 is_ip6 = 0;
17929 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17930 {
17931 if (unformat (input, "table_id %d", &table_id))
17932 ;
17933 else if (unformat (input, "ip6"))
17934 is_ip6 = 1;
17935 else if (unformat (input, "ip4"))
17936 is_ip6 = 0;
17937 else
17938 break;
17939 }
17940 if (table_id == ~0)
17941 {
17942 errmsg ("missing table id");
17943 return -99;
17944 }
17945
17946 M (IP_MROUTE_DUMP, mp);
17947 mp->table.table_id = table_id;
17948 mp->table.is_ip6 = is_ip6;
Neale Ranns5a8123b2017-01-26 01:18:23 -080017949 S (mp);
17950
17951 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017952 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080017953 S (mp_ping);
17954
17955 W (ret);
17956 return ret;
17957}
17958
Neale Ranns097fa662018-05-01 05:17:55 -070017959#define vl_api_ip_route_details_t_endian vl_noop_handler
17960#define vl_api_ip_route_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010017961
17962static void
Neale Ranns097fa662018-05-01 05:17:55 -070017963vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017964{
17965 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017966 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017967 vl_api_fib_path_t *fp;
17968 int i;
17969
17970 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070017971 "table-id %d, prefix %U/%d",
17972 ntohl (mp->route.table_id),
Paul Vinciguerraab055082019-06-06 14:07:55 -040017973 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017974 for (i = 0; i < count; i++)
17975 {
Neale Ranns097fa662018-05-01 05:17:55 -070017976 fp = &mp->route.paths[i];
17977
17978 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017979 fp++;
17980 }
17981}
17982
Neale Ranns097fa662018-05-01 05:17:55 -070017983static void vl_api_ip_route_details_t_handler_json
17984 (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017985{
17986 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017987 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017988 vat_json_node_t *node = NULL;
17989 struct in_addr ip4;
17990 struct in6_addr ip6;
17991 vl_api_fib_path_t *fp;
17992 int i;
17993
17994 if (VAT_JSON_ARRAY != vam->json_tree.type)
17995 {
17996 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17997 vat_json_init_array (&vam->json_tree);
17998 }
17999 node = vat_json_array_add (&vam->json_tree);
18000
18001 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070018002 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
18003 if (ADDRESS_IP6 == mp->route.prefix.address.af)
18004 {
18005 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
18006 vat_json_object_add_ip6 (node, "prefix", ip6);
18007 }
18008 else
18009 {
18010 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
18011 vat_json_object_add_ip4 (node, "prefix", ip4);
18012 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040018013 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018014 vat_json_object_add_uint (node, "path_count", count);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018015 for (i = 0; i < count; i++)
18016 {
Neale Ranns097fa662018-05-01 05:17:55 -070018017 fp = &mp->route.paths[i];
18018 vl_api_mpls_fib_path_json_print (node, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018019 }
18020}
18021
18022static int
Neale Ranns097fa662018-05-01 05:17:55 -070018023api_ip_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018024{
Neale Ranns097fa662018-05-01 05:17:55 -070018025 unformat_input_t *input = vam->input;
18026 vl_api_ip_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018027 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070018028 u32 table_id;
18029 u8 is_ip6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018030 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018031
Neale Ranns097fa662018-05-01 05:17:55 -070018032 is_ip6 = 0;
18033 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18034 {
18035 if (unformat (input, "table_id %d", &table_id))
18036 ;
18037 else if (unformat (input, "ip6"))
18038 is_ip6 = 1;
18039 else if (unformat (input, "ip4"))
18040 is_ip6 = 0;
18041 else
18042 break;
18043 }
18044 if (table_id == ~0)
18045 {
18046 errmsg ("missing table id");
18047 return -99;
18048 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010018049
Neale Ranns097fa662018-05-01 05:17:55 -070018050 M (IP_ROUTE_DUMP, mp);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018051
Neale Ranns097fa662018-05-01 05:17:55 -070018052 mp->table.table_id = table_id;
18053 mp->table.is_ip6 = is_ip6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018054
Neale Ranns5a8123b2017-01-26 01:18:23 -080018055 S (mp);
18056
18057 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018058 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080018059 S (mp_ping);
18060
18061 W (ret);
18062 return ret;
18063}
18064
Damjan Marion7cd468a2016-12-19 23:05:39 +010018065int
18066api_classify_table_ids (vat_main_t * vam)
18067{
18068 vl_api_classify_table_ids_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018069 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018070
18071 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018072 M (CLASSIFY_TABLE_IDS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018073 mp->context = 0;
18074
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018075 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018076 W (ret);
18077 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018078}
18079
18080int
18081api_classify_table_by_interface (vat_main_t * vam)
18082{
18083 unformat_input_t *input = vam->input;
18084 vl_api_classify_table_by_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018085
18086 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018087 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018088 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18089 {
18090 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18091 ;
18092 else if (unformat (input, "sw_if_index %d", &sw_if_index))
18093 ;
18094 else
18095 break;
18096 }
18097 if (sw_if_index == ~0)
18098 {
18099 errmsg ("missing interface name or sw_if_index");
18100 return -99;
18101 }
18102
18103 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018104 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018105 mp->context = 0;
18106 mp->sw_if_index = ntohl (sw_if_index);
18107
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018108 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018109 W (ret);
18110 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018111}
18112
18113int
18114api_classify_table_info (vat_main_t * vam)
18115{
18116 unformat_input_t *input = vam->input;
18117 vl_api_classify_table_info_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018118
18119 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018120 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018121 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18122 {
18123 if (unformat (input, "table_id %d", &table_id))
18124 ;
18125 else
18126 break;
18127 }
18128 if (table_id == ~0)
18129 {
18130 errmsg ("missing table id");
18131 return -99;
18132 }
18133
18134 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018135 M (CLASSIFY_TABLE_INFO, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018136 mp->context = 0;
18137 mp->table_id = ntohl (table_id);
18138
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018139 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018140 W (ret);
18141 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018142}
18143
18144int
18145api_classify_session_dump (vat_main_t * vam)
18146{
18147 unformat_input_t *input = vam->input;
18148 vl_api_classify_session_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018149 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018150
18151 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018152 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018153 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18154 {
18155 if (unformat (input, "table_id %d", &table_id))
18156 ;
18157 else
18158 break;
18159 }
18160 if (table_id == ~0)
18161 {
18162 errmsg ("missing table id");
18163 return -99;
18164 }
18165
18166 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018167 M (CLASSIFY_SESSION_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018168 mp->context = 0;
18169 mp->table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018170 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018171
18172 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018173 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018174 S (mp_ping);
18175
Jon Loeliger56c7b012017-02-01 12:31:41 -060018176 W (ret);
18177 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018178}
18179
18180static void
18181vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
18182{
18183 vat_main_t *vam = &vat_main;
18184
18185 print (vam->ofp, "collector_address %U, collector_port %d, "
18186 "src_address %U, vrf_id %d, path_mtu %u, "
18187 "template_interval %u, udp_checksum %d",
18188 format_ip4_address, mp->collector_address,
18189 ntohs (mp->collector_port),
18190 format_ip4_address, mp->src_address,
18191 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
18192 ntohl (mp->template_interval), mp->udp_checksum);
18193
18194 vam->retval = 0;
18195 vam->result_ready = 1;
18196}
18197
18198static void
18199 vl_api_ipfix_exporter_details_t_handler_json
18200 (vl_api_ipfix_exporter_details_t * mp)
18201{
18202 vat_main_t *vam = &vat_main;
18203 vat_json_node_t node;
18204 struct in_addr collector_address;
18205 struct in_addr src_address;
18206
18207 vat_json_init_object (&node);
18208 clib_memcpy (&collector_address, &mp->collector_address,
18209 sizeof (collector_address));
18210 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
18211 vat_json_object_add_uint (&node, "collector_port",
18212 ntohs (mp->collector_port));
18213 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
18214 vat_json_object_add_ip4 (&node, "src_address", src_address);
18215 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
18216 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
18217 vat_json_object_add_uint (&node, "template_interval",
18218 ntohl (mp->template_interval));
18219 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
18220
18221 vat_json_print (vam->ofp, &node);
18222 vat_json_free (&node);
18223 vam->retval = 0;
18224 vam->result_ready = 1;
18225}
18226
18227int
18228api_ipfix_exporter_dump (vat_main_t * vam)
18229{
18230 vl_api_ipfix_exporter_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018231 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018232
18233 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018234 M (IPFIX_EXPORTER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018235 mp->context = 0;
18236
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018237 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018238 W (ret);
18239 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018240}
18241
18242static int
18243api_ipfix_classify_stream_dump (vat_main_t * vam)
18244{
18245 vl_api_ipfix_classify_stream_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018246 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018247
18248 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018249 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018250 mp->context = 0;
18251
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018252 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018253 W (ret);
18254 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018255 /* NOTREACHED */
18256 return 0;
18257}
18258
18259static void
18260 vl_api_ipfix_classify_stream_details_t_handler
18261 (vl_api_ipfix_classify_stream_details_t * mp)
18262{
18263 vat_main_t *vam = &vat_main;
18264 print (vam->ofp, "domain_id %d, src_port %d",
18265 ntohl (mp->domain_id), ntohs (mp->src_port));
18266 vam->retval = 0;
18267 vam->result_ready = 1;
18268}
18269
18270static void
18271 vl_api_ipfix_classify_stream_details_t_handler_json
18272 (vl_api_ipfix_classify_stream_details_t * mp)
18273{
18274 vat_main_t *vam = &vat_main;
18275 vat_json_node_t node;
18276
18277 vat_json_init_object (&node);
18278 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
18279 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
18280
18281 vat_json_print (vam->ofp, &node);
18282 vat_json_free (&node);
18283 vam->retval = 0;
18284 vam->result_ready = 1;
18285}
18286
18287static int
18288api_ipfix_classify_table_dump (vat_main_t * vam)
18289{
18290 vl_api_ipfix_classify_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018291 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018292 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018293
18294 if (!vam->json_output)
18295 {
18296 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
18297 "transport_protocol");
18298 }
18299
18300 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018301 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018302
18303 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018304 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018305
18306 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018307 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018308 S (mp_ping);
18309
Jon Loeliger56c7b012017-02-01 12:31:41 -060018310 W (ret);
18311 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018312}
18313
18314static void
18315 vl_api_ipfix_classify_table_details_t_handler
18316 (vl_api_ipfix_classify_table_details_t * mp)
18317{
18318 vat_main_t *vam = &vat_main;
18319 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
18320 mp->transport_protocol);
18321}
18322
18323static void
18324 vl_api_ipfix_classify_table_details_t_handler_json
18325 (vl_api_ipfix_classify_table_details_t * mp)
18326{
18327 vat_json_node_t *node = NULL;
18328 vat_main_t *vam = &vat_main;
18329
18330 if (VAT_JSON_ARRAY != vam->json_tree.type)
18331 {
18332 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18333 vat_json_init_array (&vam->json_tree);
18334 }
18335
18336 node = vat_json_array_add (&vam->json_tree);
18337 vat_json_init_object (node);
18338
18339 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
18340 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
18341 vat_json_object_add_uint (node, "transport_protocol",
18342 mp->transport_protocol);
18343}
18344
18345static int
18346api_sw_interface_span_enable_disable (vat_main_t * vam)
18347{
18348 unformat_input_t *i = vam->input;
18349 vl_api_sw_interface_span_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018350 u32 src_sw_if_index = ~0;
18351 u32 dst_sw_if_index = ~0;
18352 u8 state = 3;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018353 int ret;
Eyal Bari001fd402017-07-16 09:34:53 +030018354 u8 is_l2 = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018355
18356 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18357 {
18358 if (unformat
18359 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
18360 ;
18361 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
18362 ;
18363 else
18364 if (unformat
18365 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
18366 ;
18367 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
18368 ;
18369 else if (unformat (i, "disable"))
18370 state = 0;
18371 else if (unformat (i, "rx"))
18372 state = 1;
18373 else if (unformat (i, "tx"))
18374 state = 2;
18375 else if (unformat (i, "both"))
18376 state = 3;
Eyal Bari001fd402017-07-16 09:34:53 +030018377 else if (unformat (i, "l2"))
18378 is_l2 = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018379 else
18380 break;
18381 }
18382
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018383 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018384
18385 mp->sw_if_index_from = htonl (src_sw_if_index);
18386 mp->sw_if_index_to = htonl (dst_sw_if_index);
18387 mp->state = state;
Eyal Bari001fd402017-07-16 09:34:53 +030018388 mp->is_l2 = is_l2;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018389
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018390 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018391 W (ret);
18392 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018393}
18394
18395static void
18396vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
18397 * mp)
18398{
18399 vat_main_t *vam = &vat_main;
18400 u8 *sw_if_from_name = 0;
18401 u8 *sw_if_to_name = 0;
18402 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
18403 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
18404 char *states[] = { "none", "rx", "tx", "both" };
18405 hash_pair_t *p;
18406
18407 /* *INDENT-OFF* */
18408 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
18409 ({
18410 if ((u32) p->value[0] == sw_if_index_from)
18411 {
18412 sw_if_from_name = (u8 *)(p->key);
18413 if (sw_if_to_name)
18414 break;
18415 }
18416 if ((u32) p->value[0] == sw_if_index_to)
18417 {
18418 sw_if_to_name = (u8 *)(p->key);
18419 if (sw_if_from_name)
18420 break;
18421 }
18422 }));
18423 /* *INDENT-ON* */
Jon Loeliger179ab362018-03-12 14:50:08 -050018424 print (vam->ofp, "%20s => %20s (%s) %s",
18425 sw_if_from_name, sw_if_to_name, states[mp->state],
18426 mp->is_l2 ? "l2" : "device");
Damjan Marion7cd468a2016-12-19 23:05:39 +010018427}
18428
18429static void
18430 vl_api_sw_interface_span_details_t_handler_json
18431 (vl_api_sw_interface_span_details_t * mp)
18432{
18433 vat_main_t *vam = &vat_main;
18434 vat_json_node_t *node = NULL;
18435 u8 *sw_if_from_name = 0;
18436 u8 *sw_if_to_name = 0;
18437 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
18438 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
18439 hash_pair_t *p;
18440
18441 /* *INDENT-OFF* */
18442 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
18443 ({
18444 if ((u32) p->value[0] == sw_if_index_from)
18445 {
18446 sw_if_from_name = (u8 *)(p->key);
18447 if (sw_if_to_name)
18448 break;
18449 }
18450 if ((u32) p->value[0] == sw_if_index_to)
18451 {
18452 sw_if_to_name = (u8 *)(p->key);
18453 if (sw_if_from_name)
18454 break;
18455 }
18456 }));
18457 /* *INDENT-ON* */
18458
18459 if (VAT_JSON_ARRAY != vam->json_tree.type)
18460 {
18461 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18462 vat_json_init_array (&vam->json_tree);
18463 }
18464 node = vat_json_array_add (&vam->json_tree);
18465
18466 vat_json_init_object (node);
18467 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
18468 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
18469 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
Neale Ranns05b2bf22017-01-30 06:44:58 -080018470 if (0 != sw_if_to_name)
18471 {
18472 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
18473 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010018474 vat_json_object_add_uint (node, "state", mp->state);
Jon Loeliger179ab362018-03-12 14:50:08 -050018475 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018476}
18477
18478static int
18479api_sw_interface_span_dump (vat_main_t * vam)
18480{
Eyal Bari5b311202017-07-31 13:12:30 +030018481 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018482 vl_api_sw_interface_span_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018483 vl_api_control_ping_t *mp_ping;
Eyal Bari5b311202017-07-31 13:12:30 +030018484 u8 is_l2 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018485 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018486
Eyal Bari5b311202017-07-31 13:12:30 +030018487 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18488 {
18489 if (unformat (input, "l2"))
18490 is_l2 = 1;
18491 else
18492 break;
18493 }
18494
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018495 M (SW_INTERFACE_SPAN_DUMP, mp);
Eyal Bari5b311202017-07-31 13:12:30 +030018496 mp->is_l2 = is_l2;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018497 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018498
18499 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018500 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018501 S (mp_ping);
18502
Jon Loeliger56c7b012017-02-01 12:31:41 -060018503 W (ret);
18504 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018505}
18506
18507int
18508api_pg_create_interface (vat_main_t * vam)
18509{
18510 unformat_input_t *input = vam->input;
18511 vl_api_pg_create_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018512
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020018513 u32 if_id = ~0, gso_size = 0;
18514 u8 gso_enabled = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018515 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018516 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18517 {
18518 if (unformat (input, "if_id %d", &if_id))
18519 ;
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020018520 else if (unformat (input, "gso-enabled"))
18521 {
18522 gso_enabled = 1;
18523 if (unformat (input, "gso-size %u", &gso_size))
18524 ;
18525 else
18526 {
18527 errmsg ("missing gso-size");
18528 return -99;
18529 }
18530 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010018531 else
18532 break;
18533 }
18534 if (if_id == ~0)
18535 {
18536 errmsg ("missing pg interface index");
18537 return -99;
18538 }
18539
18540 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018541 M (PG_CREATE_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018542 mp->context = 0;
18543 mp->interface_id = ntohl (if_id);
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020018544 mp->gso_enabled = gso_enabled;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018545
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018546 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018547 W (ret);
18548 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018549}
18550
18551int
18552api_pg_capture (vat_main_t * vam)
18553{
18554 unformat_input_t *input = vam->input;
18555 vl_api_pg_capture_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018556
18557 u32 if_id = ~0;
18558 u8 enable = 1;
18559 u32 count = 1;
18560 u8 pcap_file_set = 0;
18561 u8 *pcap_file = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018562 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018563 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18564 {
18565 if (unformat (input, "if_id %d", &if_id))
18566 ;
18567 else if (unformat (input, "pcap %s", &pcap_file))
18568 pcap_file_set = 1;
18569 else if (unformat (input, "count %d", &count))
18570 ;
18571 else if (unformat (input, "disable"))
18572 enable = 0;
18573 else
18574 break;
18575 }
18576 if (if_id == ~0)
18577 {
18578 errmsg ("missing pg interface index");
18579 return -99;
18580 }
18581 if (pcap_file_set > 0)
18582 {
18583 if (vec_len (pcap_file) > 255)
18584 {
18585 errmsg ("pcap file name is too long");
18586 return -99;
18587 }
18588 }
18589
Damjan Marion7cd468a2016-12-19 23:05:39 +010018590 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018591 M (PG_CAPTURE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018592 mp->context = 0;
18593 mp->interface_id = ntohl (if_id);
18594 mp->is_enabled = enable;
18595 mp->count = ntohl (count);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018596 if (pcap_file_set != 0)
18597 {
Jakub Grajciardb863292020-01-30 14:14:15 +010018598 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018599 }
18600 vec_free (pcap_file);
18601
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018602 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018603 W (ret);
18604 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018605}
18606
18607int
18608api_pg_enable_disable (vat_main_t * vam)
18609{
18610 unformat_input_t *input = vam->input;
18611 vl_api_pg_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018612
18613 u8 enable = 1;
18614 u8 stream_name_set = 0;
18615 u8 *stream_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018616 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018617 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18618 {
18619 if (unformat (input, "stream %s", &stream_name))
18620 stream_name_set = 1;
18621 else if (unformat (input, "disable"))
18622 enable = 0;
18623 else
18624 break;
18625 }
18626
18627 if (stream_name_set > 0)
18628 {
18629 if (vec_len (stream_name) > 255)
18630 {
18631 errmsg ("stream name too long");
18632 return -99;
18633 }
18634 }
18635
Damjan Marion7cd468a2016-12-19 23:05:39 +010018636 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018637 M (PG_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018638 mp->context = 0;
18639 mp->is_enabled = enable;
18640 if (stream_name_set != 0)
18641 {
Jakub Grajciardb863292020-01-30 14:14:15 +010018642 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018643 }
18644 vec_free (stream_name);
18645
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018646 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018647 W (ret);
18648 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018649}
18650
18651int
18652api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
18653{
18654 unformat_input_t *input = vam->input;
18655 vl_api_ip_source_and_port_range_check_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018656
18657 u16 *low_ports = 0;
18658 u16 *high_ports = 0;
18659 u16 this_low;
18660 u16 this_hi;
Neale Ranns37029302018-08-10 05:30:06 -070018661 vl_api_prefix_t prefix;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018662 u32 tmp, tmp2;
18663 u8 prefix_set = 0;
18664 u32 vrf_id = ~0;
18665 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018666 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018667
18668 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18669 {
Neale Ranns37029302018-08-10 05:30:06 -070018670 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
18671 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018672 else if (unformat (input, "vrf %d", &vrf_id))
18673 ;
18674 else if (unformat (input, "del"))
18675 is_add = 0;
18676 else if (unformat (input, "port %d", &tmp))
18677 {
18678 if (tmp == 0 || tmp > 65535)
18679 {
18680 errmsg ("port %d out of range", tmp);
18681 return -99;
18682 }
18683 this_low = tmp;
18684 this_hi = this_low + 1;
18685 vec_add1 (low_ports, this_low);
18686 vec_add1 (high_ports, this_hi);
18687 }
18688 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
18689 {
18690 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
18691 {
18692 errmsg ("incorrect range parameters");
18693 return -99;
18694 }
18695 this_low = tmp;
18696 /* Note: in debug CLI +1 is added to high before
18697 passing to real fn that does "the work"
18698 (ip_source_and_port_range_check_add_del).
18699 This fn is a wrapper around the binary API fn a
18700 control plane will call, which expects this increment
18701 to have occurred. Hence letting the binary API control
18702 plane fn do the increment for consistency between VAT
18703 and other control planes.
18704 */
18705 this_hi = tmp2;
18706 vec_add1 (low_ports, this_low);
18707 vec_add1 (high_ports, this_hi);
18708 }
18709 else
18710 break;
18711 }
18712
18713 if (prefix_set == 0)
18714 {
18715 errmsg ("<address>/<mask> not specified");
18716 return -99;
18717 }
18718
18719 if (vrf_id == ~0)
18720 {
18721 errmsg ("VRF ID required, not specified");
18722 return -99;
18723 }
18724
18725 if (vrf_id == 0)
18726 {
18727 errmsg
18728 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
18729 return -99;
18730 }
18731
18732 if (vec_len (low_ports) == 0)
18733 {
18734 errmsg ("At least one port or port range required");
18735 return -99;
18736 }
18737
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018738 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018739
18740 mp->is_add = is_add;
18741
Neale Ranns37029302018-08-10 05:30:06 -070018742 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018743
Damjan Marion7cd468a2016-12-19 23:05:39 +010018744 mp->number_of_ranges = vec_len (low_ports);
18745
18746 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
18747 vec_free (low_ports);
18748
18749 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
18750 vec_free (high_ports);
18751
18752 mp->vrf_id = ntohl (vrf_id);
18753
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018754 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018755 W (ret);
18756 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018757}
18758
18759int
18760api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
18761{
18762 unformat_input_t *input = vam->input;
18763 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018764 u32 sw_if_index = ~0;
18765 int vrf_set = 0;
18766 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
18767 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
18768 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018769 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018770
18771 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18772 {
18773 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18774 ;
18775 else if (unformat (input, "sw_if_index %d", &sw_if_index))
18776 ;
18777 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
18778 vrf_set = 1;
18779 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
18780 vrf_set = 1;
18781 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
18782 vrf_set = 1;
18783 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
18784 vrf_set = 1;
18785 else if (unformat (input, "del"))
18786 is_add = 0;
18787 else
18788 break;
18789 }
18790
18791 if (sw_if_index == ~0)
18792 {
18793 errmsg ("Interface required but not specified");
18794 return -99;
18795 }
18796
18797 if (vrf_set == 0)
18798 {
18799 errmsg ("VRF ID required but not specified");
18800 return -99;
18801 }
18802
18803 if (tcp_out_vrf_id == 0
18804 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
18805 {
18806 errmsg
18807 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
18808 return -99;
18809 }
18810
18811 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018812 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018813
18814 mp->sw_if_index = ntohl (sw_if_index);
18815 mp->is_add = is_add;
18816 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
18817 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
18818 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
18819 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
18820
18821 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018822 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018823
18824 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018825 W (ret);
18826 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018827}
18828
18829static int
Pavel Kotuceke88865d2018-11-28 07:42:11 +010018830api_set_punt (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018831{
18832 unformat_input_t *i = vam->input;
Neale Ranns50f0ac02019-05-15 02:13:37 -070018833 vl_api_address_family_t af;
Pavel Kotuceke88865d2018-11-28 07:42:11 +010018834 vl_api_set_punt_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018835 u32 protocol = ~0;
18836 u32 port = ~0;
18837 int is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018838 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018839
18840 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18841 {
Neale Ranns50f0ac02019-05-15 02:13:37 -070018842 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
Damjan Marion7cd468a2016-12-19 23:05:39 +010018843 ;
18844 else if (unformat (i, "protocol %d", &protocol))
18845 ;
18846 else if (unformat (i, "port %d", &port))
18847 ;
18848 else if (unformat (i, "del"))
18849 is_add = 0;
18850 else
18851 {
18852 clib_warning ("parse error '%U'", format_unformat_error, i);
18853 return -99;
18854 }
18855 }
18856
Pavel Kotuceke88865d2018-11-28 07:42:11 +010018857 M (SET_PUNT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018858
18859 mp->is_add = (u8) is_add;
Neale Ranns50f0ac02019-05-15 02:13:37 -070018860 mp->punt.type = PUNT_API_TYPE_L4;
18861 mp->punt.punt.l4.af = af;
18862 mp->punt.punt.l4.protocol = (u8) protocol;
18863 mp->punt.punt.l4.port = htons ((u16) port);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018864
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018865 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018866 W (ret);
18867 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018868}
18869
Damjan Marion7cd468a2016-12-19 23:05:39 +010018870static int
18871api_delete_subif (vat_main_t * vam)
18872{
18873 unformat_input_t *i = vam->input;
18874 vl_api_delete_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018875 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018876 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018877
18878 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18879 {
18880 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18881 ;
18882 if (unformat (i, "sw_if_index %d", &sw_if_index))
18883 ;
18884 else
18885 break;
18886 }
18887
18888 if (sw_if_index == ~0)
18889 {
18890 errmsg ("missing sw_if_index");
18891 return -99;
18892 }
18893
18894 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018895 M (DELETE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018896 mp->sw_if_index = ntohl (sw_if_index);
18897
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018898 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018899 W (ret);
18900 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018901}
18902
18903#define foreach_pbb_vtr_op \
18904_("disable", L2_VTR_DISABLED) \
18905_("pop", L2_VTR_POP_2) \
18906_("push", L2_VTR_PUSH_2)
18907
18908static int
18909api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
18910{
18911 unformat_input_t *i = vam->input;
18912 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018913 u32 sw_if_index = ~0, vtr_op = ~0;
18914 u16 outer_tag = ~0;
18915 u8 dmac[6], smac[6];
18916 u8 dmac_set = 0, smac_set = 0;
18917 u16 vlanid = 0;
18918 u32 sid = ~0;
18919 u32 tmp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018920 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018921
18922 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040018923 clib_memset (dmac, 0, sizeof (dmac));
18924 clib_memset (smac, 0, sizeof (smac));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018925
18926 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18927 {
18928 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18929 ;
18930 else if (unformat (i, "sw_if_index %d", &sw_if_index))
18931 ;
18932 else if (unformat (i, "vtr_op %d", &vtr_op))
18933 ;
18934#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
18935 foreach_pbb_vtr_op
18936#undef _
18937 else if (unformat (i, "translate_pbb_stag"))
18938 {
18939 if (unformat (i, "%d", &tmp))
18940 {
18941 vtr_op = L2_VTR_TRANSLATE_2_1;
18942 outer_tag = tmp;
18943 }
18944 else
18945 {
18946 errmsg
18947 ("translate_pbb_stag operation requires outer tag definition");
18948 return -99;
18949 }
18950 }
18951 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
18952 dmac_set++;
18953 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
18954 smac_set++;
18955 else if (unformat (i, "sid %d", &sid))
18956 ;
18957 else if (unformat (i, "vlanid %d", &tmp))
18958 vlanid = tmp;
18959 else
18960 {
18961 clib_warning ("parse error '%U'", format_unformat_error, i);
18962 return -99;
18963 }
18964 }
18965
18966 if ((sw_if_index == ~0) || (vtr_op == ~0))
18967 {
18968 errmsg ("missing sw_if_index or vtr operation");
18969 return -99;
18970 }
18971 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
18972 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
18973 {
18974 errmsg
18975 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
18976 return -99;
18977 }
18978
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018979 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018980 mp->sw_if_index = ntohl (sw_if_index);
18981 mp->vtr_op = ntohl (vtr_op);
18982 mp->outer_tag = ntohs (outer_tag);
18983 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
18984 clib_memcpy (mp->b_smac, smac, sizeof (smac));
18985 mp->b_vlanid = ntohs (vlanid);
18986 mp->i_sid = ntohl (sid);
18987
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018988 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018989 W (ret);
18990 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018991}
18992
18993static int
18994api_flow_classify_set_interface (vat_main_t * vam)
18995{
18996 unformat_input_t *i = vam->input;
18997 vl_api_flow_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018998 u32 sw_if_index;
18999 int sw_if_index_set;
19000 u32 ip4_table_index = ~0;
19001 u32 ip6_table_index = ~0;
19002 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019003 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019004
19005 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19006 {
19007 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19008 sw_if_index_set = 1;
19009 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19010 sw_if_index_set = 1;
19011 else if (unformat (i, "del"))
19012 is_add = 0;
19013 else if (unformat (i, "ip4-table %d", &ip4_table_index))
19014 ;
19015 else if (unformat (i, "ip6-table %d", &ip6_table_index))
19016 ;
19017 else
19018 {
19019 clib_warning ("parse error '%U'", format_unformat_error, i);
19020 return -99;
19021 }
19022 }
19023
19024 if (sw_if_index_set == 0)
19025 {
19026 errmsg ("missing interface name or sw_if_index");
19027 return -99;
19028 }
19029
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019030 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019031
19032 mp->sw_if_index = ntohl (sw_if_index);
19033 mp->ip4_table_index = ntohl (ip4_table_index);
19034 mp->ip6_table_index = ntohl (ip6_table_index);
19035 mp->is_add = is_add;
19036
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019037 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019038 W (ret);
19039 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019040}
19041
19042static int
19043api_flow_classify_dump (vat_main_t * vam)
19044{
19045 unformat_input_t *i = vam->input;
19046 vl_api_flow_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019047 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019048 u8 type = FLOW_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019049 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019050
19051 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
19052 ;
19053 else
19054 {
19055 errmsg ("classify table type must be specified");
19056 return -99;
19057 }
19058
19059 if (!vam->json_output)
19060 {
19061 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
19062 }
19063
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019064 M (FLOW_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019065 mp->type = type;
19066 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019067 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019068
19069 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019070 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019071 S (mp_ping);
19072
Damjan Marion7cd468a2016-12-19 23:05:39 +010019073 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019074 W (ret);
19075 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019076}
19077
19078static int
19079api_feature_enable_disable (vat_main_t * vam)
19080{
19081 unformat_input_t *i = vam->input;
19082 vl_api_feature_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019083 u8 *arc_name = 0;
19084 u8 *feature_name = 0;
19085 u32 sw_if_index = ~0;
19086 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019087 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019088
19089 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19090 {
19091 if (unformat (i, "arc_name %s", &arc_name))
19092 ;
19093 else if (unformat (i, "feature_name %s", &feature_name))
19094 ;
19095 else
19096 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19097 ;
19098 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19099 ;
19100 else if (unformat (i, "disable"))
19101 enable = 0;
19102 else
19103 break;
19104 }
19105
19106 if (arc_name == 0)
19107 {
19108 errmsg ("missing arc name");
19109 return -99;
19110 }
19111 if (vec_len (arc_name) > 63)
19112 {
19113 errmsg ("arc name too long");
19114 }
19115
19116 if (feature_name == 0)
19117 {
19118 errmsg ("missing feature name");
19119 return -99;
19120 }
19121 if (vec_len (feature_name) > 63)
19122 {
19123 errmsg ("feature name too long");
19124 }
19125
19126 if (sw_if_index == ~0)
19127 {
19128 errmsg ("missing interface name or sw_if_index");
19129 return -99;
19130 }
19131
19132 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019133 M (FEATURE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019134 mp->sw_if_index = ntohl (sw_if_index);
19135 mp->enable = enable;
19136 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
19137 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
19138 vec_free (arc_name);
19139 vec_free (feature_name);
19140
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019141 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019142 W (ret);
19143 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019144}
19145
19146static int
Mohsin Kazmi29467b52019-10-08 19:42:38 +020019147api_feature_gso_enable_disable (vat_main_t * vam)
19148{
19149 unformat_input_t *i = vam->input;
19150 vl_api_feature_gso_enable_disable_t *mp;
19151 u32 sw_if_index = ~0;
19152 u8 enable = 1;
19153 int ret;
19154
19155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19156 {
19157 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19158 ;
19159 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19160 ;
19161 else if (unformat (i, "enable"))
19162 enable = 1;
19163 else if (unformat (i, "disable"))
19164 enable = 0;
19165 else
19166 break;
19167 }
19168
19169 if (sw_if_index == ~0)
19170 {
19171 errmsg ("missing interface name or sw_if_index");
19172 return -99;
19173 }
19174
19175 /* Construct the API message */
19176 M (FEATURE_GSO_ENABLE_DISABLE, mp);
19177 mp->sw_if_index = ntohl (sw_if_index);
19178 mp->enable_disable = enable;
19179
19180 S (mp);
19181 W (ret);
19182 return ret;
19183}
19184
19185static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010019186api_sw_interface_tag_add_del (vat_main_t * vam)
19187{
19188 unformat_input_t *i = vam->input;
19189 vl_api_sw_interface_tag_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019190 u32 sw_if_index = ~0;
19191 u8 *tag = 0;
19192 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019193 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019194
19195 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19196 {
19197 if (unformat (i, "tag %s", &tag))
19198 ;
19199 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19200 ;
19201 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19202 ;
19203 else if (unformat (i, "del"))
19204 enable = 0;
19205 else
19206 break;
19207 }
19208
19209 if (sw_if_index == ~0)
19210 {
19211 errmsg ("missing interface name or sw_if_index");
19212 return -99;
19213 }
19214
19215 if (enable && (tag == 0))
19216 {
19217 errmsg ("no tag specified");
19218 return -99;
19219 }
19220
19221 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019222 M (SW_INTERFACE_TAG_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019223 mp->sw_if_index = ntohl (sw_if_index);
19224 mp->is_add = enable;
19225 if (enable)
Ole Troane5ff5a32019-08-23 22:55:18 +020019226 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019227 vec_free (tag);
19228
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019229 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019230 W (ret);
19231 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019232}
19233
Matthew Smithe0792fd2019-07-12 11:48:24 -050019234static int
19235api_sw_interface_add_del_mac_address (vat_main_t * vam)
19236{
19237 unformat_input_t *i = vam->input;
19238 vl_api_mac_address_t mac = { 0 };
19239 vl_api_sw_interface_add_del_mac_address_t *mp;
19240 u32 sw_if_index = ~0;
19241 u8 is_add = 1;
19242 u8 mac_set = 0;
19243 int ret;
19244
19245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19246 {
19247 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19248 ;
19249 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19250 ;
19251 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
19252 mac_set++;
19253 else if (unformat (i, "del"))
19254 is_add = 0;
19255 else
19256 break;
19257 }
19258
19259 if (sw_if_index == ~0)
19260 {
19261 errmsg ("missing interface name or sw_if_index");
19262 return -99;
19263 }
19264
19265 if (!mac_set)
19266 {
19267 errmsg ("missing MAC address");
19268 return -99;
19269 }
19270
19271 /* Construct the API message */
19272 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
19273 mp->sw_if_index = ntohl (sw_if_index);
19274 mp->is_add = is_add;
19275 clib_memcpy (&mp->addr, &mac, sizeof (mac));
19276
19277 S (mp);
19278 W (ret);
19279 return ret;
19280}
19281
Damjan Marion7cd468a2016-12-19 23:05:39 +010019282static void vl_api_l2_xconnect_details_t_handler
19283 (vl_api_l2_xconnect_details_t * mp)
19284{
19285 vat_main_t *vam = &vat_main;
19286
19287 print (vam->ofp, "%15d%15d",
19288 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
19289}
19290
19291static void vl_api_l2_xconnect_details_t_handler_json
19292 (vl_api_l2_xconnect_details_t * mp)
19293{
19294 vat_main_t *vam = &vat_main;
19295 vat_json_node_t *node = NULL;
19296
19297 if (VAT_JSON_ARRAY != vam->json_tree.type)
19298 {
19299 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19300 vat_json_init_array (&vam->json_tree);
19301 }
19302 node = vat_json_array_add (&vam->json_tree);
19303
19304 vat_json_init_object (node);
19305 vat_json_object_add_uint (node, "rx_sw_if_index",
19306 ntohl (mp->rx_sw_if_index));
19307 vat_json_object_add_uint (node, "tx_sw_if_index",
19308 ntohl (mp->tx_sw_if_index));
19309}
19310
19311static int
19312api_l2_xconnect_dump (vat_main_t * vam)
19313{
19314 vl_api_l2_xconnect_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019315 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019316 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019317
19318 if (!vam->json_output)
19319 {
19320 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
19321 }
19322
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019323 M (L2_XCONNECT_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019324
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019325 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019326
19327 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019328 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019329 S (mp_ping);
19330
Jon Loeliger56c7b012017-02-01 12:31:41 -060019331 W (ret);
19332 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019333}
19334
19335static int
Ole Troand7231612018-06-07 10:17:57 +020019336api_hw_interface_set_mtu (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019337{
19338 unformat_input_t *i = vam->input;
Ole Troand7231612018-06-07 10:17:57 +020019339 vl_api_hw_interface_set_mtu_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019340 u32 sw_if_index = ~0;
19341 u32 mtu = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019342 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019343
19344 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19345 {
19346 if (unformat (i, "mtu %d", &mtu))
19347 ;
19348 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19349 ;
19350 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19351 ;
19352 else
19353 break;
19354 }
19355
19356 if (sw_if_index == ~0)
19357 {
19358 errmsg ("missing interface name or sw_if_index");
19359 return -99;
19360 }
19361
19362 if (mtu == 0)
19363 {
19364 errmsg ("no mtu specified");
19365 return -99;
19366 }
19367
19368 /* Construct the API message */
Ole Troand7231612018-06-07 10:17:57 +020019369 M (HW_INTERFACE_SET_MTU, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019370 mp->sw_if_index = ntohl (sw_if_index);
19371 mp->mtu = ntohs ((u16) mtu);
19372
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019373 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019374 W (ret);
19375 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019376}
19377
Pavel Kotucek6899a302017-06-08 08:46:10 +020019378static int
19379api_p2p_ethernet_add (vat_main_t * vam)
19380{
19381 unformat_input_t *i = vam->input;
19382 vl_api_p2p_ethernet_add_t *mp;
19383 u32 parent_if_index = ~0;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019384 u32 sub_id = ~0;
Pavel Kotucek6899a302017-06-08 08:46:10 +020019385 u8 remote_mac[6];
19386 u8 mac_set = 0;
19387 int ret;
19388
Dave Barachb7b92992018-10-17 10:38:51 -040019389 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020019390 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19391 {
19392 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
19393 ;
19394 else if (unformat (i, "sw_if_index %d", &parent_if_index))
19395 ;
19396 else
19397 if (unformat
19398 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
19399 mac_set++;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019400 else if (unformat (i, "sub_id %d", &sub_id))
19401 ;
Pavel Kotucek6899a302017-06-08 08:46:10 +020019402 else
19403 {
19404 clib_warning ("parse error '%U'", format_unformat_error, i);
19405 return -99;
19406 }
19407 }
19408
19409 if (parent_if_index == ~0)
19410 {
19411 errmsg ("missing interface name or sw_if_index");
19412 return -99;
19413 }
19414 if (mac_set == 0)
19415 {
19416 errmsg ("missing remote mac address");
19417 return -99;
19418 }
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019419 if (sub_id == ~0)
19420 {
19421 errmsg ("missing sub-interface id");
19422 return -99;
19423 }
Pavel Kotucek6899a302017-06-08 08:46:10 +020019424
19425 M (P2P_ETHERNET_ADD, mp);
19426 mp->parent_if_index = ntohl (parent_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019427 mp->subif_id = ntohl (sub_id);
Pavel Kotucek6899a302017-06-08 08:46:10 +020019428 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
19429
19430 S (mp);
19431 W (ret);
19432 return ret;
19433}
19434
19435static int
19436api_p2p_ethernet_del (vat_main_t * vam)
19437{
19438 unformat_input_t *i = vam->input;
19439 vl_api_p2p_ethernet_del_t *mp;
19440 u32 parent_if_index = ~0;
19441 u8 remote_mac[6];
19442 u8 mac_set = 0;
19443 int ret;
19444
Dave Barachb7b92992018-10-17 10:38:51 -040019445 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020019446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19447 {
19448 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
19449 ;
19450 else if (unformat (i, "sw_if_index %d", &parent_if_index))
19451 ;
19452 else
19453 if (unformat
19454 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
19455 mac_set++;
19456 else
19457 {
19458 clib_warning ("parse error '%U'", format_unformat_error, i);
19459 return -99;
19460 }
19461 }
19462
19463 if (parent_if_index == ~0)
19464 {
19465 errmsg ("missing interface name or sw_if_index");
19466 return -99;
19467 }
19468 if (mac_set == 0)
19469 {
19470 errmsg ("missing remote mac address");
19471 return -99;
19472 }
19473
19474 M (P2P_ETHERNET_DEL, mp);
19475 mp->parent_if_index = ntohl (parent_if_index);
19476 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
19477
19478 S (mp);
19479 W (ret);
19480 return ret;
19481}
Damjan Marion7cd468a2016-12-19 23:05:39 +010019482
19483static int
Steve Shin99a0e602017-07-01 04:16:20 +000019484api_lldp_config (vat_main_t * vam)
19485{
19486 unformat_input_t *i = vam->input;
19487 vl_api_lldp_config_t *mp;
19488 int tx_hold = 0;
19489 int tx_interval = 0;
19490 u8 *sys_name = NULL;
19491 int ret;
19492
19493 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19494 {
19495 if (unformat (i, "system-name %s", &sys_name))
19496 ;
19497 else if (unformat (i, "tx-hold %d", &tx_hold))
19498 ;
19499 else if (unformat (i, "tx-interval %d", &tx_interval))
19500 ;
19501 else
19502 {
19503 clib_warning ("parse error '%U'", format_unformat_error, i);
19504 return -99;
19505 }
19506 }
19507
19508 vec_add1 (sys_name, 0);
19509
19510 M (LLDP_CONFIG, mp);
19511 mp->tx_hold = htonl (tx_hold);
19512 mp->tx_interval = htonl (tx_interval);
Jakub Grajciar1c684f92020-01-30 14:01:17 +010019513 vl_api_vec_to_api_string (sys_name, &mp->system_name);
Steve Shin99a0e602017-07-01 04:16:20 +000019514 vec_free (sys_name);
19515
19516 S (mp);
19517 W (ret);
19518 return ret;
19519}
19520
19521static int
19522api_sw_interface_set_lldp (vat_main_t * vam)
19523{
19524 unformat_input_t *i = vam->input;
19525 vl_api_sw_interface_set_lldp_t *mp;
19526 u32 sw_if_index = ~0;
19527 u32 enable = 1;
Steve Shin9a6fcef2017-10-11 13:55:16 -070019528 u8 *port_desc = NULL, *mgmt_oid = NULL;
19529 ip4_address_t ip4_addr;
19530 ip6_address_t ip6_addr;
Steve Shin99a0e602017-07-01 04:16:20 +000019531 int ret;
19532
Dave Barachb7b92992018-10-17 10:38:51 -040019533 clib_memset (&ip4_addr, 0, sizeof (ip4_addr));
19534 clib_memset (&ip6_addr, 0, sizeof (ip6_addr));
Steve Shin9a6fcef2017-10-11 13:55:16 -070019535
Steve Shin99a0e602017-07-01 04:16:20 +000019536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19537 {
19538 if (unformat (i, "disable"))
19539 enable = 0;
19540 else
19541 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19542 ;
19543 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19544 ;
19545 else if (unformat (i, "port-desc %s", &port_desc))
19546 ;
Steve Shin9a6fcef2017-10-11 13:55:16 -070019547 else if (unformat (i, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
19548 ;
19549 else if (unformat (i, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
19550 ;
19551 else if (unformat (i, "mgmt-oid %s", &mgmt_oid))
19552 ;
Steve Shin99a0e602017-07-01 04:16:20 +000019553 else
19554 break;
19555 }
19556
19557 if (sw_if_index == ~0)
19558 {
19559 errmsg ("missing interface name or sw_if_index");
19560 return -99;
19561 }
19562
19563 /* Construct the API message */
19564 vec_add1 (port_desc, 0);
Steve Shin9a6fcef2017-10-11 13:55:16 -070019565 vec_add1 (mgmt_oid, 0);
Steve Shin99a0e602017-07-01 04:16:20 +000019566 M (SW_INTERFACE_SET_LLDP, mp);
19567 mp->sw_if_index = ntohl (sw_if_index);
19568 mp->enable = enable;
Jakub Grajciar1c684f92020-01-30 14:01:17 +010019569 vl_api_vec_to_api_string (port_desc, &mp->port_desc);
Steve Shin9a6fcef2017-10-11 13:55:16 -070019570 clib_memcpy (mp->mgmt_oid, mgmt_oid, vec_len (mgmt_oid));
19571 clib_memcpy (mp->mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
19572 clib_memcpy (mp->mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
Steve Shin99a0e602017-07-01 04:16:20 +000019573 vec_free (port_desc);
Steve Shin9a6fcef2017-10-11 13:55:16 -070019574 vec_free (mgmt_oid);
Steve Shin99a0e602017-07-01 04:16:20 +000019575
19576 S (mp);
19577 W (ret);
19578 return ret;
19579}
19580
19581static int
Dave Barach3bbcfab2017-08-15 19:03:44 -040019582api_tcp_configure_src_addresses (vat_main_t * vam)
19583{
19584 vl_api_tcp_configure_src_addresses_t *mp;
19585 unformat_input_t *i = vam->input;
Neale Rannscbe25aa2019-09-30 10:53:31 +000019586 vl_api_address_t first, last;
Dave Barach3bbcfab2017-08-15 19:03:44 -040019587 u8 range_set = 0;
19588 u32 vrf_id = 0;
19589 int ret;
19590
19591 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19592 {
19593 if (unformat (i, "%U - %U",
Neale Rannscbe25aa2019-09-30 10:53:31 +000019594 unformat_vl_api_address, &first,
19595 unformat_vl_api_address, &last))
Dave Barach3bbcfab2017-08-15 19:03:44 -040019596 {
19597 if (range_set)
19598 {
19599 errmsg ("one range per message (range already set)");
19600 return -99;
19601 }
19602 range_set = 1;
19603 }
Dave Barach3bbcfab2017-08-15 19:03:44 -040019604 else if (unformat (i, "vrf %d", &vrf_id))
19605 ;
19606 else
19607 break;
19608 }
19609
19610 if (range_set == 0)
19611 {
19612 errmsg ("address range not set");
19613 return -99;
19614 }
19615
19616 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
Neale Rannscbe25aa2019-09-30 10:53:31 +000019617
Dave Barach3bbcfab2017-08-15 19:03:44 -040019618 mp->vrf_id = ntohl (vrf_id);
Neale Rannscbe25aa2019-09-30 10:53:31 +000019619 clib_memcpy (&mp->first_address, &first, sizeof (first));
19620 clib_memcpy (&mp->last_address, &last, sizeof (last));
19621
Dave Barach3bbcfab2017-08-15 19:03:44 -040019622 S (mp);
19623 W (ret);
19624 return ret;
19625}
19626
Florin Coras6e8c6672017-11-10 09:03:54 -080019627static void vl_api_app_namespace_add_del_reply_t_handler
19628 (vl_api_app_namespace_add_del_reply_t * mp)
19629{
19630 vat_main_t *vam = &vat_main;
19631 i32 retval = ntohl (mp->retval);
19632 if (vam->async_mode)
19633 {
19634 vam->async_errors += (retval < 0);
19635 }
19636 else
19637 {
19638 vam->retval = retval;
19639 if (retval == 0)
19640 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
19641 vam->result_ready = 1;
19642 }
19643}
19644
19645static void vl_api_app_namespace_add_del_reply_t_handler_json
19646 (vl_api_app_namespace_add_del_reply_t * mp)
19647{
19648 vat_main_t *vam = &vat_main;
19649 vat_json_node_t node;
19650
19651 vat_json_init_object (&node);
19652 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
19653 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
19654
19655 vat_json_print (vam->ofp, &node);
19656 vat_json_free (&node);
19657
19658 vam->retval = ntohl (mp->retval);
19659 vam->result_ready = 1;
19660}
19661
Dave Barach3bbcfab2017-08-15 19:03:44 -040019662static int
Florin Corascea194d2017-10-02 00:18:51 -070019663api_app_namespace_add_del (vat_main_t * vam)
19664{
19665 vl_api_app_namespace_add_del_t *mp;
19666 unformat_input_t *i = vam->input;
19667 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
19668 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
19669 u64 secret;
19670 int ret;
19671
19672 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19673 {
19674 if (unformat (i, "id %_%v%_", &ns_id))
19675 ;
19676 else if (unformat (i, "secret %lu", &secret))
19677 secret_set = 1;
19678 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19679 sw_if_index_set = 1;
19680 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
19681 ;
19682 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
19683 ;
19684 else
19685 break;
19686 }
19687 if (!ns_id || !secret_set || !sw_if_index_set)
19688 {
19689 errmsg ("namespace id, secret and sw_if_index must be set");
19690 return -99;
19691 }
19692 if (vec_len (ns_id) > 64)
19693 {
19694 errmsg ("namespace id too long");
19695 return -99;
19696 }
19697 M (APP_NAMESPACE_ADD_DEL, mp);
19698
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019699 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
Florin Coras9a9adb22017-10-26 08:16:59 -070019700 mp->secret = clib_host_to_net_u64 (secret);
Florin Corascea194d2017-10-02 00:18:51 -070019701 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
19702 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
19703 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
19704 vec_free (ns_id);
19705 S (mp);
19706 W (ret);
19707 return ret;
19708}
19709
19710static int
Florin Coras90a63982017-12-19 04:50:01 -080019711api_sock_init_shm (vat_main_t * vam)
19712{
19713#if VPP_API_TEST_BUILTIN == 0
19714 unformat_input_t *i = vam->input;
19715 vl_api_shm_elem_config_t *config = 0;
19716 u64 size = 64 << 20;
19717 int rv;
19718
19719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19720 {
19721 if (unformat (i, "size %U", unformat_memory_size, &size))
19722 ;
19723 else
19724 break;
19725 }
19726
Dave Barach78958722018-05-10 16:44:27 -040019727 /*
19728 * Canned custom ring allocator config.
19729 * Should probably parse all of this
19730 */
19731 vec_validate (config, 6);
Florin Coras90a63982017-12-19 04:50:01 -080019732 config[0].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080019733 config[0].size = 256;
Dave Barach78958722018-05-10 16:44:27 -040019734 config[0].count = 32;
19735
19736 config[1].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080019737 config[1].size = 1024;
Dave Barach78958722018-05-10 16:44:27 -040019738 config[1].count = 16;
19739
19740 config[2].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080019741 config[2].size = 4096;
Dave Barach78958722018-05-10 16:44:27 -040019742 config[2].count = 2;
19743
19744 config[3].type = VL_API_CLIENT_RING;
19745 config[3].size = 256;
19746 config[3].count = 32;
19747
19748 config[4].type = VL_API_CLIENT_RING;
19749 config[4].size = 1024;
19750 config[4].count = 16;
19751
19752 config[5].type = VL_API_CLIENT_RING;
19753 config[5].size = 4096;
19754 config[5].count = 2;
19755
19756 config[6].type = VL_API_QUEUE;
19757 config[6].count = 128;
19758 config[6].size = sizeof (uword);
19759
Tomasz Kulasek97dcf5b2019-01-31 18:26:32 +010019760 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
Florin Coras90a63982017-12-19 04:50:01 -080019761 if (!rv)
19762 vam->client_index_invalid = 1;
19763 return rv;
19764#else
19765 return -99;
19766#endif
19767}
19768
Florin Coras6c36f532017-11-03 18:32:34 -070019769static void
19770vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
19771{
19772 vat_main_t *vam = &vat_main;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019773 fib_prefix_t lcl, rmt;
Florin Coras6c36f532017-11-03 18:32:34 -070019774
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019775 ip_prefix_decode (&mp->lcl, &lcl);
19776 ip_prefix_decode (&mp->rmt, &rmt);
19777
19778 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -070019779 {
Florin Corasc97a7392017-11-05 23:07:07 -080019780 print (vam->ofp,
19781 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080019782 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019783 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
Steven85dbac02017-11-07 16:29:53 -080019784 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019785 &rmt.fp_addr.ip4, rmt.fp_len,
19786 clib_net_to_host_u16 (mp->rmt_port),
Steven85dbac02017-11-07 16:29:53 -080019787 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070019788 }
19789 else
19790 {
Florin Corasc97a7392017-11-05 23:07:07 -080019791 print (vam->ofp,
19792 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080019793 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019794 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
Steven85dbac02017-11-07 16:29:53 -080019795 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019796 &rmt.fp_addr.ip6, rmt.fp_len,
19797 clib_net_to_host_u16 (mp->rmt_port),
Steven85dbac02017-11-07 16:29:53 -080019798 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070019799 }
19800}
19801
19802static void
19803vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
19804 mp)
19805{
19806 vat_main_t *vam = &vat_main;
19807 vat_json_node_t *node = NULL;
19808 struct in6_addr ip6;
19809 struct in_addr ip4;
19810
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019811 fib_prefix_t lcl, rmt;
19812
19813 ip_prefix_decode (&mp->lcl, &lcl);
19814 ip_prefix_decode (&mp->rmt, &rmt);
19815
Florin Coras6c36f532017-11-03 18:32:34 -070019816 if (VAT_JSON_ARRAY != vam->json_tree.type)
19817 {
19818 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19819 vat_json_init_array (&vam->json_tree);
19820 }
19821 node = vat_json_array_add (&vam->json_tree);
19822 vat_json_init_object (node);
19823
Florin Coras6c36f532017-11-03 18:32:34 -070019824 vat_json_object_add_uint (node, "appns_index",
19825 clib_net_to_host_u32 (mp->appns_index));
19826 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
19827 vat_json_object_add_uint (node, "scope", mp->scope);
19828 vat_json_object_add_uint (node, "action_index",
19829 clib_net_to_host_u32 (mp->action_index));
19830 vat_json_object_add_uint (node, "lcl_port",
19831 clib_net_to_host_u16 (mp->lcl_port));
19832 vat_json_object_add_uint (node, "rmt_port",
19833 clib_net_to_host_u16 (mp->rmt_port));
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019834 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
19835 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
Florin Corasc97a7392017-11-05 23:07:07 -080019836 vat_json_object_add_string_copy (node, "tag", mp->tag);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019837 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -070019838 {
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019839 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
Florin Coras6c36f532017-11-03 18:32:34 -070019840 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019841 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
Florin Coras6c36f532017-11-03 18:32:34 -070019842 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
19843 }
19844 else
19845 {
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019846 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
Florin Coras6c36f532017-11-03 18:32:34 -070019847 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019848 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
Florin Coras6c36f532017-11-03 18:32:34 -070019849 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
19850 }
19851}
19852
Florin Coras1c710452017-10-17 00:03:13 -070019853static int
19854api_session_rule_add_del (vat_main_t * vam)
19855{
19856 vl_api_session_rule_add_del_t *mp;
19857 unformat_input_t *i = vam->input;
19858 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
19859 u32 appns_index = 0, scope = 0;
19860 ip4_address_t lcl_ip4, rmt_ip4;
19861 ip6_address_t lcl_ip6, rmt_ip6;
19862 u8 is_ip4 = 1, conn_set = 0;
Florin Corasc97a7392017-11-05 23:07:07 -080019863 u8 is_add = 1, *tag = 0;
Florin Coras1c710452017-10-17 00:03:13 -070019864 int ret;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019865 fib_prefix_t lcl, rmt;
Florin Coras1c710452017-10-17 00:03:13 -070019866
19867 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19868 {
19869 if (unformat (i, "del"))
19870 is_add = 0;
19871 else if (unformat (i, "add"))
19872 ;
19873 else if (unformat (i, "proto tcp"))
19874 proto = 0;
19875 else if (unformat (i, "proto udp"))
19876 proto = 1;
19877 else if (unformat (i, "appns %d", &appns_index))
19878 ;
19879 else if (unformat (i, "scope %d", &scope))
19880 ;
Florin Corasc97a7392017-11-05 23:07:07 -080019881 else if (unformat (i, "tag %_%v%_", &tag))
19882 ;
Florin Coras1c710452017-10-17 00:03:13 -070019883 else
19884 if (unformat
19885 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
19886 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
19887 &rmt_port))
19888 {
19889 is_ip4 = 1;
19890 conn_set = 1;
19891 }
19892 else
19893 if (unformat
19894 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
19895 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
19896 &rmt_port))
19897 {
19898 is_ip4 = 0;
19899 conn_set = 1;
19900 }
19901 else if (unformat (i, "action %d", &action))
19902 ;
19903 else
19904 break;
19905 }
19906 if (proto == ~0 || !conn_set || action == ~0)
19907 {
19908 errmsg ("transport proto, connection and action must be set");
19909 return -99;
19910 }
19911
19912 if (scope > 3)
19913 {
19914 errmsg ("scope should be 0-3");
19915 return -99;
19916 }
19917
19918 M (SESSION_RULE_ADD_DEL, mp);
19919
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019920 clib_memset (&lcl, 0, sizeof (lcl));
19921 clib_memset (&rmt, 0, sizeof (rmt));
19922 if (is_ip4)
19923 {
19924 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
19925 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
19926 lcl.fp_len = lcl_plen;
19927 rmt.fp_len = rmt_plen;
19928 }
19929 else
19930 {
19931 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
19932 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
19933 lcl.fp_len = lcl_plen;
19934 rmt.fp_len = rmt_plen;
19935 }
19936
19937
19938 ip_prefix_encode (&lcl, &mp->lcl);
19939 ip_prefix_encode (&rmt, &mp->rmt);
Florin Corasc97a7392017-11-05 23:07:07 -080019940 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
19941 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019942 mp->transport_proto =
19943 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
Florin Coras1c710452017-10-17 00:03:13 -070019944 mp->action_index = clib_host_to_net_u32 (action);
19945 mp->appns_index = clib_host_to_net_u32 (appns_index);
19946 mp->scope = scope;
19947 mp->is_add = is_add;
Florin Corasc97a7392017-11-05 23:07:07 -080019948 if (tag)
19949 {
19950 clib_memcpy (mp->tag, tag, vec_len (tag));
19951 vec_free (tag);
19952 }
Florin Coras1c710452017-10-17 00:03:13 -070019953
19954 S (mp);
19955 W (ret);
19956 return ret;
19957}
Dave Barach65457162017-10-10 17:53:14 -040019958
19959static int
Florin Coras6c36f532017-11-03 18:32:34 -070019960api_session_rules_dump (vat_main_t * vam)
19961{
19962 vl_api_session_rules_dump_t *mp;
19963 vl_api_control_ping_t *mp_ping;
19964 int ret;
19965
19966 if (!vam->json_output)
19967 {
19968 print (vam->ofp, "%=20s", "Session Rules");
19969 }
19970
19971 M (SESSION_RULES_DUMP, mp);
19972 /* send it... */
19973 S (mp);
19974
19975 /* Use a control ping for synchronization */
19976 MPING (CONTROL_PING, mp_ping);
19977 S (mp_ping);
19978
19979 /* Wait for a reply... */
19980 W (ret);
19981 return ret;
19982}
19983
19984static int
Florin Coras595992c2017-11-06 17:17:08 -080019985api_ip_container_proxy_add_del (vat_main_t * vam)
19986{
19987 vl_api_ip_container_proxy_add_del_t *mp;
19988 unformat_input_t *i = vam->input;
Neale Ranns37029302018-08-10 05:30:06 -070019989 u32 sw_if_index = ~0;
19990 vl_api_prefix_t pfx = { };
Florin Coras595992c2017-11-06 17:17:08 -080019991 u8 is_add = 1;
19992 int ret;
19993
19994 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19995 {
19996 if (unformat (i, "del"))
19997 is_add = 0;
19998 else if (unformat (i, "add"))
19999 ;
Neale Ranns37029302018-08-10 05:30:06 -070020000 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
20001 ;
Florin Coras595992c2017-11-06 17:17:08 -080020002 else if (unformat (i, "sw_if_index %u", &sw_if_index))
20003 ;
20004 else
20005 break;
20006 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040020007 if (sw_if_index == ~0 || pfx.len == 0)
Florin Coras595992c2017-11-06 17:17:08 -080020008 {
20009 errmsg ("address and sw_if_index must be set");
20010 return -99;
20011 }
20012
20013 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
20014
Florin Coras595992c2017-11-06 17:17:08 -080020015 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
Florin Coras595992c2017-11-06 17:17:08 -080020016 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -070020017 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
Florin Coras595992c2017-11-06 17:17:08 -080020018
20019 S (mp);
20020 W (ret);
20021 return ret;
20022}
20023
20024static int
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070020025api_qos_record_enable_disable (vat_main_t * vam)
20026{
20027 unformat_input_t *i = vam->input;
20028 vl_api_qos_record_enable_disable_t *mp;
20029 u32 sw_if_index, qs = 0xff;
20030 u8 sw_if_index_set = 0;
20031 u8 enable = 1;
20032 int ret;
20033
20034 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20035 {
20036 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20037 sw_if_index_set = 1;
20038 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20039 sw_if_index_set = 1;
20040 else if (unformat (i, "%U", unformat_qos_source, &qs))
20041 ;
20042 else if (unformat (i, "disable"))
20043 enable = 0;
20044 else
20045 {
20046 clib_warning ("parse error '%U'", format_unformat_error, i);
20047 return -99;
20048 }
20049 }
20050
20051 if (sw_if_index_set == 0)
20052 {
20053 errmsg ("missing interface name or sw_if_index");
20054 return -99;
20055 }
20056 if (qs == 0xff)
20057 {
20058 errmsg ("input location must be specified");
20059 return -99;
20060 }
20061
20062 M (QOS_RECORD_ENABLE_DISABLE, mp);
20063
Neale Ranns5281a902019-07-23 08:16:19 -070020064 mp->record.sw_if_index = ntohl (sw_if_index);
20065 mp->record.input_source = qs;
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070020066 mp->enable = enable;
20067
20068 S (mp);
20069 W (ret);
20070 return ret;
20071}
20072
Dave Barach048a4e52018-06-01 18:52:25 -040020073
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070020074static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010020075q_or_quit (vat_main_t * vam)
20076{
Dave Barachdef19da2017-02-22 17:29:20 -050020077#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010020078 longjmp (vam->jump_buf, 1);
Dave Barachdef19da2017-02-22 17:29:20 -050020079#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010020080 return 0; /* not so much */
20081}
20082
20083static int
20084q (vat_main_t * vam)
20085{
20086 return q_or_quit (vam);
20087}
20088
20089static int
20090quit (vat_main_t * vam)
20091{
20092 return q_or_quit (vam);
20093}
20094
20095static int
20096comment (vat_main_t * vam)
20097{
20098 return 0;
20099}
20100
20101static int
Dave Barachb09f4d02019-07-15 16:00:03 -040020102elog_save (vat_main_t * vam)
20103{
20104#if VPP_API_TEST_BUILTIN == 0
20105 elog_main_t *em = &vam->elog_main;
20106 unformat_input_t *i = vam->input;
20107 char *file, *chroot_file;
20108 clib_error_t *error;
20109
20110 if (!unformat (i, "%s", &file))
20111 {
20112 errmsg ("expected file name, got `%U'", format_unformat_error, i);
20113 return 0;
20114 }
20115
20116 /* It's fairly hard to get "../oopsie" through unformat; just in case */
20117 if (strstr (file, "..") || index (file, '/'))
20118 {
20119 errmsg ("illegal characters in filename '%s'", file);
20120 return 0;
20121 }
20122
20123 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
20124
20125 vec_free (file);
20126
20127 errmsg ("Saving %wd of %wd events to %s",
20128 elog_n_events_in_buffer (em),
20129 elog_buffer_capacity (em), chroot_file);
20130
20131 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
20132 vec_free (chroot_file);
20133
20134 if (error)
20135 clib_error_report (error);
20136#else
20137 errmsg ("Use the vpp event loger...");
20138#endif
20139
20140 return 0;
20141}
20142
20143static int
20144elog_setup (vat_main_t * vam)
20145{
20146#if VPP_API_TEST_BUILTIN == 0
20147 elog_main_t *em = &vam->elog_main;
20148 unformat_input_t *i = vam->input;
20149 u32 nevents = 128 << 10;
20150
20151 (void) unformat (i, "nevents %d", &nevents);
20152
20153 elog_init (em, nevents);
20154 vl_api_set_elog_main (em);
20155 vl_api_set_elog_trace_api_messages (1);
20156 errmsg ("Event logger initialized with %u events", nevents);
20157#else
20158 errmsg ("Use the vpp event loger...");
20159#endif
20160 return 0;
20161}
20162
20163static int
20164elog_enable (vat_main_t * vam)
20165{
20166#if VPP_API_TEST_BUILTIN == 0
20167 elog_main_t *em = &vam->elog_main;
20168
20169 elog_enable_disable (em, 1 /* enable */ );
20170 vl_api_set_elog_trace_api_messages (1);
20171 errmsg ("Event logger enabled...");
20172#else
20173 errmsg ("Use the vpp event loger...");
20174#endif
20175 return 0;
20176}
20177
20178static int
20179elog_disable (vat_main_t * vam)
20180{
20181#if VPP_API_TEST_BUILTIN == 0
20182 elog_main_t *em = &vam->elog_main;
20183
20184 elog_enable_disable (em, 0 /* enable */ );
20185 vl_api_set_elog_trace_api_messages (1);
20186 errmsg ("Event logger disabled...");
20187#else
20188 errmsg ("Use the vpp event loger...");
20189#endif
20190 return 0;
20191}
20192
20193static int
Dave Barach048a4e52018-06-01 18:52:25 -040020194statseg (vat_main_t * vam)
20195{
20196 ssvm_private_t *ssvmp = &vam->stat_segment;
20197 ssvm_shared_header_t *shared_header = ssvmp->sh;
20198 vlib_counter_t **counters;
20199 u64 thread0_index1_packets;
20200 u64 thread0_index1_bytes;
20201 f64 vector_rate, input_rate;
20202 uword *p;
20203
20204 uword *counter_vector_by_name;
20205 if (vam->stat_segment_lockp == 0)
20206 {
20207 errmsg ("Stat segment not mapped...");
20208 return -99;
20209 }
20210
20211 /* look up "/if/rx for sw_if_index 1 as a test */
20212
20213 clib_spinlock_lock (vam->stat_segment_lockp);
20214
20215 counter_vector_by_name = (uword *) shared_header->opaque[1];
20216
20217 p = hash_get_mem (counter_vector_by_name, "/if/rx");
20218 if (p == 0)
20219 {
20220 clib_spinlock_unlock (vam->stat_segment_lockp);
20221 errmsg ("/if/tx not found?");
20222 return -99;
20223 }
20224
20225 /* Fish per-thread vector of combined counters from shared memory */
20226 counters = (vlib_counter_t **) p[0];
20227
20228 if (vec_len (counters[0]) < 2)
20229 {
20230 clib_spinlock_unlock (vam->stat_segment_lockp);
20231 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
20232 return -99;
20233 }
20234
20235 /* Read thread 0 sw_if_index 1 counter */
20236 thread0_index1_packets = counters[0][1].packets;
20237 thread0_index1_bytes = counters[0][1].bytes;
20238
20239 p = hash_get_mem (counter_vector_by_name, "vector_rate");
20240 if (p == 0)
20241 {
20242 clib_spinlock_unlock (vam->stat_segment_lockp);
20243 errmsg ("vector_rate not found?");
20244 return -99;
20245 }
20246
20247 vector_rate = *(f64 *) (p[0]);
20248 p = hash_get_mem (counter_vector_by_name, "input_rate");
20249 if (p == 0)
20250 {
20251 clib_spinlock_unlock (vam->stat_segment_lockp);
20252 errmsg ("input_rate not found?");
20253 return -99;
20254 }
20255 input_rate = *(f64 *) (p[0]);
20256
20257 clib_spinlock_unlock (vam->stat_segment_lockp);
20258
20259 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
20260 vector_rate, input_rate);
20261 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
20262 thread0_index1_packets, thread0_index1_bytes);
20263
20264 return 0;
20265}
20266
20267static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010020268cmd_cmp (void *a1, void *a2)
20269{
20270 u8 **c1 = a1;
20271 u8 **c2 = a2;
20272
20273 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
20274}
20275
20276static int
20277help (vat_main_t * vam)
20278{
20279 u8 **cmds = 0;
20280 u8 *name = 0;
20281 hash_pair_t *p;
20282 unformat_input_t *i = vam->input;
20283 int j;
20284
20285 if (unformat (i, "%s", &name))
20286 {
20287 uword *hs;
20288
20289 vec_add1 (name, 0);
20290
20291 hs = hash_get_mem (vam->help_by_name, name);
20292 if (hs)
20293 print (vam->ofp, "usage: %s %s", name, hs[0]);
20294 else
20295 print (vam->ofp, "No such msg / command '%s'", name);
20296 vec_free (name);
20297 return 0;
20298 }
20299
20300 print (vam->ofp, "Help is available for the following:");
20301
20302 /* *INDENT-OFF* */
20303 hash_foreach_pair (p, vam->function_by_name,
20304 ({
20305 vec_add1 (cmds, (u8 *)(p->key));
20306 }));
20307 /* *INDENT-ON* */
20308
20309 vec_sort_with_function (cmds, cmd_cmp);
20310
20311 for (j = 0; j < vec_len (cmds); j++)
20312 print (vam->ofp, "%s", cmds[j]);
20313
20314 vec_free (cmds);
20315 return 0;
20316}
20317
20318static int
20319set (vat_main_t * vam)
20320{
20321 u8 *name = 0, *value = 0;
20322 unformat_input_t *i = vam->input;
20323
20324 if (unformat (i, "%s", &name))
20325 {
20326 /* The input buffer is a vector, not a string. */
20327 value = vec_dup (i->buffer);
20328 vec_delete (value, i->index, 0);
20329 /* Almost certainly has a trailing newline */
20330 if (value[vec_len (value) - 1] == '\n')
20331 value[vec_len (value) - 1] = 0;
20332 /* Make sure it's a proper string, one way or the other */
20333 vec_add1 (value, 0);
20334 (void) clib_macro_set_value (&vam->macro_main,
20335 (char *) name, (char *) value);
20336 }
20337 else
20338 errmsg ("usage: set <name> <value>");
20339
20340 vec_free (name);
20341 vec_free (value);
20342 return 0;
20343}
20344
20345static int
20346unset (vat_main_t * vam)
20347{
20348 u8 *name = 0;
20349
20350 if (unformat (vam->input, "%s", &name))
20351 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
20352 errmsg ("unset: %s wasn't set", name);
20353 vec_free (name);
20354 return 0;
20355}
20356
20357typedef struct
20358{
20359 u8 *name;
20360 u8 *value;
20361} macro_sort_t;
20362
20363
20364static int
20365macro_sort_cmp (void *a1, void *a2)
20366{
20367 macro_sort_t *s1 = a1;
20368 macro_sort_t *s2 = a2;
20369
20370 return strcmp ((char *) (s1->name), (char *) (s2->name));
20371}
20372
20373static int
20374dump_macro_table (vat_main_t * vam)
20375{
20376 macro_sort_t *sort_me = 0, *sm;
20377 int i;
20378 hash_pair_t *p;
20379
20380 /* *INDENT-OFF* */
20381 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
20382 ({
20383 vec_add2 (sort_me, sm, 1);
20384 sm->name = (u8 *)(p->key);
20385 sm->value = (u8 *) (p->value[0]);
20386 }));
20387 /* *INDENT-ON* */
20388
20389 vec_sort_with_function (sort_me, macro_sort_cmp);
20390
20391 if (vec_len (sort_me))
20392 print (vam->ofp, "%-15s%s", "Name", "Value");
20393 else
20394 print (vam->ofp, "The macro table is empty...");
20395
20396 for (i = 0; i < vec_len (sort_me); i++)
20397 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
20398 return 0;
20399}
20400
20401static int
20402dump_node_table (vat_main_t * vam)
20403{
20404 int i, j;
20405 vlib_node_t *node, *next_node;
20406
20407 if (vec_len (vam->graph_nodes) == 0)
20408 {
20409 print (vam->ofp, "Node table empty, issue get_node_graph...");
20410 return 0;
20411 }
20412
Dave Barach1ddbc012018-06-13 09:26:05 -040020413 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010020414 {
Dave Barach1ddbc012018-06-13 09:26:05 -040020415 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020416 print (vam->ofp, "[%d] %s", i, node->name);
20417 for (j = 0; j < vec_len (node->next_nodes); j++)
20418 {
20419 if (node->next_nodes[j] != ~0)
20420 {
Dave Barach1ddbc012018-06-13 09:26:05 -040020421 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020422 print (vam->ofp, " [%d] %s", j, next_node->name);
20423 }
20424 }
20425 }
20426 return 0;
20427}
20428
20429static int
20430value_sort_cmp (void *a1, void *a2)
20431{
20432 name_sort_t *n1 = a1;
20433 name_sort_t *n2 = a2;
20434
20435 if (n1->value < n2->value)
20436 return -1;
20437 if (n1->value > n2->value)
20438 return 1;
20439 return 0;
20440}
20441
20442
20443static int
20444dump_msg_api_table (vat_main_t * vam)
20445{
Dave Barach39d69112019-11-27 11:42:13 -050020446 api_main_t *am = vlibapi_get_main ();
Damjan Marion7cd468a2016-12-19 23:05:39 +010020447 name_sort_t *nses = 0, *ns;
20448 hash_pair_t *hp;
20449 int i;
20450
20451 /* *INDENT-OFF* */
20452 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
20453 ({
20454 vec_add2 (nses, ns, 1);
20455 ns->name = (u8 *)(hp->key);
20456 ns->value = (u32) hp->value[0];
20457 }));
20458 /* *INDENT-ON* */
20459
20460 vec_sort_with_function (nses, value_sort_cmp);
20461
20462 for (i = 0; i < vec_len (nses); i++)
20463 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
20464 vec_free (nses);
20465 return 0;
20466}
20467
20468static int
20469get_msg_id (vat_main_t * vam)
20470{
20471 u8 *name_and_crc;
20472 u32 message_index;
20473
20474 if (unformat (vam->input, "%s", &name_and_crc))
20475 {
Florin Corase86a8ed2018-01-05 03:20:25 -080020476 message_index = vl_msg_api_get_msg_index (name_and_crc);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020477 if (message_index == ~0)
20478 {
20479 print (vam->ofp, " '%s' not found", name_and_crc);
20480 return 0;
20481 }
20482 print (vam->ofp, " '%s' has message index %d",
20483 name_and_crc, message_index);
20484 return 0;
20485 }
20486 errmsg ("name_and_crc required...");
20487 return 0;
20488}
20489
20490static int
20491search_node_table (vat_main_t * vam)
20492{
20493 unformat_input_t *line_input = vam->input;
20494 u8 *node_to_find;
20495 int j;
20496 vlib_node_t *node, *next_node;
20497 uword *p;
20498
20499 if (vam->graph_node_index_by_name == 0)
20500 {
20501 print (vam->ofp, "Node table empty, issue get_node_graph...");
20502 return 0;
20503 }
20504
20505 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
20506 {
20507 if (unformat (line_input, "%s", &node_to_find))
20508 {
20509 vec_add1 (node_to_find, 0);
20510 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
20511 if (p == 0)
20512 {
20513 print (vam->ofp, "%s not found...", node_to_find);
20514 goto out;
20515 }
Dave Barach1ddbc012018-06-13 09:26:05 -040020516 node = vam->graph_nodes[0][p[0]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020517 print (vam->ofp, "[%d] %s", p[0], node->name);
20518 for (j = 0; j < vec_len (node->next_nodes); j++)
20519 {
20520 if (node->next_nodes[j] != ~0)
20521 {
Dave Barach1ddbc012018-06-13 09:26:05 -040020522 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020523 print (vam->ofp, " [%d] %s", j, next_node->name);
20524 }
20525 }
20526 }
20527
20528 else
20529 {
20530 clib_warning ("parse error '%U'", format_unformat_error,
20531 line_input);
20532 return -99;
20533 }
20534
20535 out:
20536 vec_free (node_to_find);
20537
20538 }
20539
20540 return 0;
20541}
20542
20543
20544static int
20545script (vat_main_t * vam)
20546{
20547#if (VPP_API_TEST_BUILTIN==0)
20548 u8 *s = 0;
20549 char *save_current_file;
20550 unformat_input_t save_input;
20551 jmp_buf save_jump_buf;
20552 u32 save_line_number;
20553
20554 FILE *new_fp, *save_ifp;
20555
20556 if (unformat (vam->input, "%s", &s))
20557 {
20558 new_fp = fopen ((char *) s, "r");
20559 if (new_fp == 0)
20560 {
20561 errmsg ("Couldn't open script file %s", s);
20562 vec_free (s);
20563 return -99;
20564 }
20565 }
20566 else
20567 {
20568 errmsg ("Missing script name");
20569 return -99;
20570 }
20571
20572 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
20573 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
20574 save_ifp = vam->ifp;
20575 save_line_number = vam->input_line_number;
20576 save_current_file = (char *) vam->current_file;
20577
20578 vam->input_line_number = 0;
20579 vam->ifp = new_fp;
20580 vam->current_file = s;
20581 do_one_file (vam);
20582
Sirshak Dasb0861822018-05-29 21:13:21 -050020583 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020584 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
20585 vam->ifp = save_ifp;
20586 vam->input_line_number = save_line_number;
20587 vam->current_file = (u8 *) save_current_file;
20588 vec_free (s);
20589
20590 return 0;
20591#else
20592 clib_warning ("use the exec command...");
20593 return -99;
20594#endif
20595}
20596
20597static int
20598echo (vat_main_t * vam)
20599{
20600 print (vam->ofp, "%v", vam->input->buffer);
20601 return 0;
20602}
20603
20604/* List of API message constructors, CLI names map to api_xxx */
20605#define foreach_vpe_api_msg \
Jon Loeligerc83c3b72017-02-23 13:57:35 -060020606_(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020607_(sw_interface_dump,"") \
20608_(sw_interface_set_flags, \
20609 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
20610_(sw_interface_add_del_address, \
20611 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
Stevenad8015b2017-10-29 22:10:46 -070020612_(sw_interface_set_rx_mode, \
20613 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +020020614_(sw_interface_set_rx_placement, \
20615 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +020020616_(sw_interface_rx_placement_dump, \
20617 "[<intfc> | sw_if_index <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020618_(sw_interface_set_table, \
20619 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
20620_(sw_interface_set_mpls_enable, \
20621 "<intfc> | sw_if_index [disable | dis]") \
20622_(sw_interface_set_vpath, \
20623 "<intfc> | sw_if_index <id> enable | disable") \
20624_(sw_interface_set_vxlan_bypass, \
John Lo2b81eb82017-01-30 13:12:10 -050020625 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020020626_(sw_interface_set_geneve_bypass, \
20627 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020628_(sw_interface_set_l2_xconnect, \
20629 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
20630 "enable | disable") \
20631_(sw_interface_set_l2_bridge, \
Eyal Barif24991c2017-04-05 05:33:21 +030020632 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020633 "[shg <split-horizon-group>] [bvi]\n" \
20634 "enable | disable") \
Eyal Barif24991c2017-04-05 05:33:21 +030020635_(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020636_(bridge_domain_add_del, \
John Lo70bfcaf2017-11-14 13:19:26 -050020637 "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 +010020638_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
20639_(l2fib_add_del, \
20640 "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 +030020641_(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
20642_(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020643_(l2_flags, \
John Lo8d00fff2017-08-03 00:35:36 -040020644 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020645_(bridge_flags, \
20646 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion8389fb92017-10-13 18:29:53 +020020647_(tap_create_v2, \
Mohsin Kazmib49bc1a2020-02-14 17:51:04 +000020648 "id <num> [hw-addr <mac-addr>] [host-if-name <name>] [host-ns <name>] [num-rx-queues <num>] [rx-ring-size <num>] [tx-ring-size <num>] [host-bridge <name>] [host-mac-addr <mac-addr>] [host-ip4-addr <ip4addr/mask>] [host-ip6-addr <ip6addr/mask>] [host-mtu-size <mtu>] [gso | no-gso | csum-offload] [persist] [attach]") \
Damjan Marion8389fb92017-10-13 18:29:53 +020020649_(tap_delete_v2, \
20650 "<vpp-if-name> | sw_if_index <id>") \
20651_(sw_interface_tap_v2_dump, "") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010020652_(virtio_pci_create, \
Mohsin Kazmi6d4af892020-01-03 15:11:53 +000020653 "pci-addr <pci-address> [use_random_mac | hw-addr <mac-addr>] [features <hex-value>] [gso-enabled | csum-offload-enabled]") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010020654_(virtio_pci_delete, \
20655 "<vpp-if-name> | sw_if_index <id>") \
20656_(sw_interface_virtio_pci_dump, "") \
Steven9cd2d7a2017-12-20 12:43:01 -080020657_(bond_create, \
20658 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
Alexander Chernavinad9d5282018-12-13 09:08:09 -050020659 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
Steven Luonga1876b82019-08-20 16:58:00 -070020660 "[id <if-id>]") \
Steven9cd2d7a2017-12-20 12:43:01 -080020661_(bond_delete, \
20662 "<vpp-if-name> | sw_if_index <id>") \
20663_(bond_enslave, \
Steven Luonga1876b82019-08-20 16:58:00 -070020664 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
Steven9cd2d7a2017-12-20 12:43:01 -080020665_(bond_detach_slave, \
20666 "sw_if_index <n>") \
Steven Luonga1876b82019-08-20 16:58:00 -070020667 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
Steven9cd2d7a2017-12-20 12:43:01 -080020668_(sw_interface_bond_dump, "") \
20669_(sw_interface_slave_dump, \
20670 "<vpp-if-name> | sw_if_index <id>") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070020671_(ip_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040020672 "table <n> [ipv6] [add | del]\n") \
Neale Ranns097fa662018-05-01 05:17:55 -070020673_(ip_route_add_del, \
John Lo22030432018-09-20 16:07:00 -040020674 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
20675 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
John Lo06fda9c2018-10-03 16:32:44 -040020676 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
20677 "[multipath] [count <n>] [del]") \
Neale Ranns32e1c012016-11-22 17:07:28 +000020678_(ip_mroute_add_del, \
20679 "<src> <grp>/<mask> [table-id <n>]\n" \
20680 "[<intfc> | sw_if_index <id>] [local] [del]") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070020681_(mpls_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040020682 "table <n> [add | del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020683_(mpls_route_add_del, \
John Loe166fd92018-09-13 14:08:59 -040020684 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
20685 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
20686 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
20687 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
John Lo06fda9c2018-10-03 16:32:44 -040020688 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
20689 "[count <n>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020690_(mpls_ip_bind_unbind, \
20691 "<label> <addr/len>") \
20692_(mpls_tunnel_add_del, \
John Lo06fda9c2018-10-03 16:32:44 -040020693 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
20694 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
20695 "[l2-only] [out-label <n>]") \
John Loe166fd92018-09-13 14:08:59 -040020696_(sr_mpls_policy_add, \
20697 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
20698_(sr_mpls_policy_del, \
20699 "bsid <id>") \
Neale Rannsd792d9c2017-10-21 10:53:20 -070020700_(bier_table_add_del, \
20701 "<label> <sub-domain> <set> <bsl> [del]") \
20702_(bier_route_add_del, \
20703 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
20704 "[<intfc> | sw_if_index <id>]" \
20705 "[weight <n>] [del] [multipath]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020706_(sw_interface_set_unnumbered, \
20707 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020708_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
20709_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
20710 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
20711 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
20712 "[outer_vlan_id_any][inner_vlan_id_any]") \
Neale Ranns9db6ada2019-11-08 12:42:31 +000020713_(ip_table_replace_begin, "table <n> [ipv6]") \
20714_(ip_table_flush, "table <n> [ipv6]") \
20715_(ip_table_replace_end, "table <n> [ipv6]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020716_(set_ip_flow_hash, \
20717 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
20718_(sw_interface_ip6_enable_disable, \
20719 "<intfc> | sw_if_index <id> enable | disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020720_(l2_patch_add_del, \
20721 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
20722 "enable | disable") \
Pablo Camarillofb380952016-12-07 18:34:18 +010020723_(sr_localsid_add_del, \
20724 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
20725 "fib-table <num> (end.psp) sw_if_index <num>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020726_(classify_add_del_table, \
20727 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
20728 " [del] [del-chain] mask <mask-value>\n" \
20729 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
20730 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
20731_(classify_add_del_session, \
20732 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
20733 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
20734 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
20735 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
20736_(classify_set_interface_ip_table, \
20737 "<intfc> | sw_if_index <nn> table <nn>") \
20738_(classify_set_interface_l2_tables, \
20739 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
20740 " [other-table <nn>]") \
20741_(get_node_index, "node <node-name") \
20742_(add_node_next, "node <node-name> next <next-node-name>") \
20743_(l2tpv3_create_tunnel, \
20744 "client_address <ip6-addr> our_address <ip6-addr>\n" \
20745 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n" \
20746 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
20747_(l2tpv3_set_tunnel_cookies, \
20748 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
20749 "[new_remote_cookie <nn>]\n") \
20750_(l2tpv3_interface_enable_disable, \
20751 "<intfc> | sw_if_index <nn> enable | disable") \
20752_(l2tpv3_set_lookup_key, \
20753 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
20754_(sw_if_l2tpv3_tunnel_dump, "") \
eyal bariaf86a482018-04-17 11:20:27 +030020755_(vxlan_offload_rx, \
20756 "hw { <interface name> | hw_if_index <nn>} " \
20757 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020758_(vxlan_add_del_tunnel, \
20759 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
Jon Loeliger3d460bd2018-02-01 16:36:12 -060020760 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020761 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020020762_(geneve_add_del_tunnel, \
20763 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
20764 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
20765 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020766_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020020767_(geneve_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Neale Ranns5a8844b2019-04-16 07:15:35 +000020768_(gre_tunnel_add_del, \
John Loa43ccae2018-02-13 17:15:23 -050020769 "src <ip-addr> dst <ip-addr> [outer-fib-id <nn>] [instance <n>]\n" \
20770 "[teb | erspan <session-id>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020771_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
20772_(l2_fib_clear_table, "") \
20773_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
20774_(l2_interface_vlan_tag_rewrite, \
20775 "<intfc> | sw_if_index <nn> \n" \
20776 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
20777 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
20778_(create_vhost_user_if, \
20779 "socket <filename> [server] [renumber <dev_instance>] " \
Steven Luong4208a4c2019-05-06 08:51:56 -070020780 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
Stevenf3b53642017-05-01 14:03:02 -070020781 "[mac <mac_address>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020782_(modify_vhost_user_if, \
20783 "<intfc> | sw_if_index <nn> socket <filename>\n" \
Steven Luong4208a4c2019-05-06 08:51:56 -070020784 "[server] [renumber <dev_instance>] [gso]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020785_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
20786_(sw_interface_vhost_user_dump, "") \
20787_(show_version, "") \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020020788_(show_threads, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020789_(vxlan_gpe_add_del_tunnel, \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080020790 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
20791 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
20792 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
20793 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020794_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
20795_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
20796_(interface_name_renumber, \
20797 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
20798_(input_acl_set_interface, \
20799 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
20800 " [l2-table <nn>] [del]") \
John Lo8d00fff2017-08-03 00:35:36 -040020801_(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020802_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
20803_(ip_dump, "ipv4 | ipv6") \
20804_(ipsec_spd_add_del, "spd_id <n> [del]") \
20805_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
20806 " spid_id <n> ") \
Neale Ranns17dcec02019-01-09 21:22:20 -080020807_(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020808 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
20809 " integ_alg <alg> integ_key <hex>") \
Neale Ranns17dcec02019-01-09 21:22:20 -080020810_(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020811 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
20812 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
20813 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
Matthew Smithb0972cb2017-05-02 16:20:41 -050020814_(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
20815 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
20816 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
Matthew Smith8e1039a2018-04-12 07:32:56 -050020817 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
20818 " [instance <n>]") \
Matthew Smith28029532017-09-26 13:33:44 -050020819_(ipsec_sa_dump, "[sa_id <n>]") \
Matthew Smithca514fd2017-10-12 12:06:59 -050020820_(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020821_(delete_loopback,"sw_if_index <nn>") \
20822_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
John Loe26c81f2019-01-07 15:16:33 -050020823_(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
20824_(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020825_(want_interface_events, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020826_(get_first_msg_id, "client <name>") \
20827_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
20828_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
20829 "fib-id <nn> [ip4][ip6][default]") \
20830_(get_node_graph, " ") \
20831_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
20832_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
20833_(ioam_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020834_(one_add_del_locator_set, "locator-set <locator_name> [iface <intf> |" \
20835 " sw_if_index <sw_if_index> p <priority> " \
20836 "w <weight>] [del]") \
20837_(one_add_del_locator, "locator-set <locator_name> " \
20838 "iface <intf> | sw_if_index <sw_if_index> " \
20839 "p <priority> w <weight> [del]") \
20840_(one_add_del_local_eid,"vni <vni> eid " \
20841 "<ipv4|ipv6>/<prefix> | <L2 address> " \
20842 "locator-set <locator_name> [del]" \
20843 "[key-id sha1|sha256 secret-key <secret-key>]")\
20844_(one_add_del_map_resolver, "<ip4|6-addr> [del]") \
20845_(one_add_del_map_server, "<ip4|6-addr> [del]") \
20846_(one_enable_disable, "enable|disable") \
20847_(one_map_register_enable_disable, "enable|disable") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020020848_(one_map_register_fallback_threshold, "<value>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020849_(one_rloc_probe_enable_disable, "enable|disable") \
20850_(one_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
20851 "[seid <seid>] " \
20852 "rloc <locator> p <prio> " \
20853 "w <weight> [rloc <loc> ... ] " \
20854 "action <action> [del-all]") \
20855_(one_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
20856 "<local-eid>") \
20857_(one_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020858_(one_use_petr, "ip-address> | disable") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020859_(one_map_request_mode, "src-dst|dst-only") \
20860_(one_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
20861_(one_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
20862_(one_locator_set_dump, "[local | remote]") \
20863_(one_locator_dump, "ls_index <index> | ls_name <name>") \
20864_(one_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
20865 "[local] | [remote]") \
Filip Tehlar05879992017-09-05 15:46:09 +020020866_(one_add_del_ndp_entry, "[del] mac <mac> bd <bd> ip6 <ip6>") \
20867_(one_ndp_bd_get, "") \
20868_(one_ndp_entries_get, "bd <bridge-domain>") \
Filip Tehlard5a65db2017-05-17 17:21:10 +020020869_(one_add_del_l2_arp_entry, "[del] mac <mac> bd <bd> ip4 <ip4>") \
20870_(one_l2_arp_bd_get, "") \
20871_(one_l2_arp_entries_get, "bd <bridge-domain>") \
Paul Vinciguerraec11b132018-09-24 05:25:00 -070020872_(one_stats_enable_disable, "enable|disable") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010020873_(show_one_stats_enable_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020874_(one_eid_table_vni_dump, "") \
20875_(one_eid_table_map_dump, "l2|l3") \
20876_(one_map_resolver_dump, "") \
20877_(one_map_server_dump, "") \
20878_(one_adjacencies_get, "vni <vni>") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020020879_(one_nsh_set_locator_set, "[del] ls <locator-set-name>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020880_(show_one_rloc_probe_state, "") \
20881_(show_one_map_register_state, "") \
20882_(show_one_status, "") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010020883_(one_stats_dump, "") \
Filip Tehlar21511912017-04-07 10:41:42 +020020884_(one_stats_flush, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020885_(one_get_map_request_itr_rlocs, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020020886_(one_map_register_set_ttl, "<ttl>") \
Filip Tehlara4980b82017-09-27 14:32:02 +020020887_(one_set_transport_protocol, "udp|api") \
20888_(one_get_transport_protocol, "") \
Filip Tehlar0a8840d2017-10-16 05:48:23 -070020889_(one_enable_disable_xtr_mode, "enable|disable") \
20890_(one_show_xtr_mode, "") \
20891_(one_enable_disable_pitr_mode, "enable|disable") \
20892_(one_show_pitr_mode, "") \
20893_(one_enable_disable_petr_mode, "enable|disable") \
20894_(one_show_petr_mode, "") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020020895_(show_one_nsh_mapping, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020896_(show_one_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020897_(show_one_use_petr, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020898_(show_one_map_request_mode, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020020899_(show_one_map_register_ttl, "") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020020900_(show_one_map_register_fallback_threshold, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020901_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
Damjan Marion7cd468a2016-12-19 23:05:39 +010020902 " sw_if_index <sw_if_index> p <priority> " \
20903 "w <weight>] [del]") \
20904_(lisp_add_del_locator, "locator-set <locator_name> " \
20905 "iface <intf> | sw_if_index <sw_if_index> " \
20906 "p <priority> w <weight> [del]") \
20907_(lisp_add_del_local_eid,"vni <vni> eid " \
20908 "<ipv4|ipv6>/<prefix> | <L2 address> " \
20909 "locator-set <locator_name> [del]" \
20910 "[key-id sha1|sha256 secret-key <secret-key>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020911_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
20912_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020913_(lisp_enable_disable, "enable|disable") \
20914_(lisp_map_register_enable_disable, "enable|disable") \
20915_(lisp_rloc_probe_enable_disable, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020916_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
20917 "[seid <seid>] " \
20918 "rloc <locator> p <prio> " \
20919 "w <weight> [rloc <loc> ... ] " \
20920 "action <action> [del-all]") \
20921_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
20922 "<local-eid>") \
20923_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020924_(lisp_use_petr, "<ip-address> | disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020925_(lisp_map_request_mode, "src-dst|dst-only") \
20926_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
20927_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
20928_(lisp_locator_set_dump, "[local | remote]") \
20929_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
20930_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
20931 "[local] | [remote]") \
20932_(lisp_eid_table_vni_dump, "") \
20933_(lisp_eid_table_map_dump, "l2|l3") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020934_(lisp_map_resolver_dump, "") \
20935_(lisp_map_server_dump, "") \
20936_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar0eb874e2017-05-18 14:23:32 +020020937_(gpe_fwd_entry_vnis_get, "") \
Filip Tehlarb4243aa2017-06-14 14:39:42 +020020938_(gpe_native_fwd_rpaths_get, "ip4 | ip6") \
20939_(gpe_add_del_native_fwd_rpath, "[del] via <nh-ip-addr> [iface] " \
20940 "[table <table-id>]") \
Filip Tehlar5fae99c2017-01-18 12:57:37 +010020941_(lisp_gpe_fwd_entries_get, "vni <vni>") \
20942_(lisp_gpe_fwd_entry_path_dump, "index <fwd_entry_index>") \
Filip Tehlar3e7b56932017-02-21 18:28:34 +010020943_(gpe_set_encap_mode, "lisp|vxlan") \
20944_(gpe_get_encap_mode, "") \
Filip Tehlar82786c42017-02-20 15:20:37 +010020945_(lisp_gpe_add_del_iface, "up|down") \
20946_(lisp_gpe_enable_disable, "enable|disable") \
20947_(lisp_gpe_add_del_fwd_entry, "reid <eid> [leid <eid>] vni <vni>" \
20948 "vrf/bd <dp_table> loc-pair <lcl_loc> <rmt_loc> w <weight>... [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020949_(show_lisp_rloc_probe_state, "") \
20950_(show_lisp_map_register_state, "") \
20951_(show_lisp_status, "") \
20952_(lisp_get_map_request_itr_rlocs, "") \
20953_(show_lisp_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020954_(show_lisp_use_petr, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020955_(show_lisp_map_request_mode, "") \
20956_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
20957_(af_packet_delete, "name <host interface name>") \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020020958_(af_packet_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020959_(policer_add_del, "name <policer name> <params> [del]") \
20960_(policer_dump, "[name <policer name>]") \
20961_(policer_classify_set_interface, \
20962 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
20963 " [l2-table <nn>] [del]") \
20964_(policer_classify_dump, "type [ip4|ip6|l2]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020965_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns097fa662018-05-01 05:17:55 -070020966_(mpls_table_dump, "") \
20967_(mpls_route_dump, "table-id <ID>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020968_(classify_table_ids, "") \
20969_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
20970_(classify_table_info, "table_id <nn>") \
20971_(classify_session_dump, "table_id <nn>") \
20972_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
20973 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
20974 "[template_interval <nn>] [udp_checksum]") \
20975_(ipfix_exporter_dump, "") \
20976_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
20977_(ipfix_classify_stream_dump, "") \
20978_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
20979_(ipfix_classify_table_dump, "") \
Eyal Bari001fd402017-07-16 09:34:53 +030020980_(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 +030020981_(sw_interface_span_dump, "[l2]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020982_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020020983_(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020984_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
20985_(pg_enable_disable, "[stream <id>] disable") \
20986_(ip_source_and_port_range_check_add_del, \
20987 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
20988_(ip_source_and_port_range_check_interface_add_del, \
20989 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
20990 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020991_(delete_subif,"<intfc> | sw_if_index <nn>") \
20992_(l2_interface_pbb_tag_rewrite, \
20993 "<intfc> | sw_if_index <nn> \n" \
20994 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
20995 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020996_(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020997_(flow_classify_set_interface, \
20998 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
20999_(flow_classify_dump, "type [ip4|ip6]") \
Neale Ranns097fa662018-05-01 05:17:55 -070021000_(ip_table_dump, "") \
21001_(ip_route_dump, "table-id [ip4|ip6]") \
21002_(ip_mtable_dump, "") \
21003_(ip_mroute_dump, "table-id [ip4|ip6]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021004_(feature_enable_disable, "arc_name <arc_name> " \
21005 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
Mohsin Kazmi29467b52019-10-08 19:42:38 +020021006_(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
21007 "[enable | disable] ") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021008_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
21009"[disable]") \
Matthew Smithe0792fd2019-07-12 11:48:24 -050021010_(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
21011 "mac <mac-address> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021012_(l2_xconnect_dump, "") \
Ole Troand7231612018-06-07 10:17:57 +020021013_(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
Pavel Kotucek6899a302017-06-08 08:46:10 +020021014_(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020021015_(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
Steve Shin99a0e602017-07-01 04:16:20 +000021016_(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020021017_(lldp_config, "system-name <name> tx-hold <nn> tx-interval <nn>") \
Steve Shin9a6fcef2017-10-11 13:55:16 -070021018_(sw_interface_set_lldp, "<intfc> | sw_if_index <nn> [port-desc <description>]\n" \
21019 " [mgmt-ip4 <ip4>] [mgmt-ip6 <ip6>] [mgmt-oid <object id>] [disable]") \
Dave Barach59b25652017-09-10 15:04:27 -040021020_(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
Florin Coras90a63982017-12-19 04:50:01 -080021021_(sock_init_shm, "size <nnn>") \
Florin Corascea194d2017-10-02 00:18:51 -070021022_(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
Florin Coras1c710452017-10-17 00:03:13 -070021023_(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
21024 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
Florin Coras6c36f532017-11-03 18:32:34 -070021025_(session_rules_dump, "") \
Florin Coras595992c2017-11-06 17:17:08 -080021026_(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010021027_(output_acl_set_interface, \
21028 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
21029 " [l2-table <nn>] [del]") \
Ole Troane906aac2018-06-14 14:42:14 +020021030_(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
Damjan Marion7cd468a2016-12-19 23:05:39 +010021031
21032/* List of command functions, CLI names map directly to functions */
21033#define foreach_cli_function \
21034_(comment, "usage: comment <ignore-rest-of-line>") \
21035_(dump_interface_table, "usage: dump_interface_table") \
21036_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
21037_(dump_ipv4_table, "usage: dump_ipv4_table") \
21038_(dump_ipv6_table, "usage: dump_ipv6_table") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021039_(dump_macro_table, "usage: dump_macro_table ") \
21040_(dump_node_table, "usage: dump_node_table") \
21041_(dump_msg_api_table, "usage: dump_msg_api_table") \
Dave Barachb09f4d02019-07-15 16:00:03 -040021042_(elog_setup, "usage: elog_setup [nevents, default 128K]") \
21043_(elog_disable, "usage: elog_disable") \
21044_(elog_enable, "usage: elog_enable") \
21045_(elog_save, "usage: elog_save <filename>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021046_(get_msg_id, "usage: get_msg_id name_and_crc") \
21047_(echo, "usage: echo <message>") \
21048_(exec, "usage: exec <vpe-debug-CLI-command>") \
21049_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
21050_(help, "usage: help") \
21051_(q, "usage: quit") \
21052_(quit, "usage: quit") \
21053_(search_node_table, "usage: search_node_table <name>...") \
21054_(set, "usage: set <variable-name> <value>") \
21055_(script, "usage: script <file-name>") \
Neale Ranns097fa662018-05-01 05:17:55 -070021056_(statseg, "usage: statseg") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021057_(unset, "usage: unset <variable-name>")
Dave Barach048a4e52018-06-01 18:52:25 -040021058
Damjan Marion7cd468a2016-12-19 23:05:39 +010021059#define _(N,n) \
21060 static void vl_api_##n##_t_handler_uni \
21061 (vl_api_##n##_t * mp) \
21062 { \
21063 vat_main_t * vam = &vat_main; \
21064 if (vam->json_output) { \
21065 vl_api_##n##_t_handler_json(mp); \
21066 } else { \
21067 vl_api_##n##_t_handler(mp); \
21068 } \
21069 }
21070foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050021071#if VPP_API_TEST_BUILTIN == 0
21072foreach_standalone_reply_msg;
21073#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021074#undef _
21075
21076void
21077vat_api_hookup (vat_main_t * vam)
21078{
21079#define _(N,n) \
21080 vl_msg_api_set_handlers(VL_API_##N, #n, \
21081 vl_api_##n##_t_handler_uni, \
21082 vl_noop_handler, \
21083 vl_api_##n##_t_endian, \
21084 vl_api_##n##_t_print, \
21085 sizeof(vl_api_##n##_t), 1);
21086 foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050021087#if VPP_API_TEST_BUILTIN == 0
21088 foreach_standalone_reply_msg;
21089#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021090#undef _
21091
21092#if (VPP_API_TEST_BUILTIN==0)
21093 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021094
21095 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
21096
21097 vam->function_by_name = hash_create_string (0, sizeof (uword));
21098
21099 vam->help_by_name = hash_create_string (0, sizeof (uword));
Dave Barach45e4f362017-03-07 12:52:31 -050021100#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021101
21102 /* API messages we can send */
21103#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
21104 foreach_vpe_api_msg;
21105#undef _
21106
21107 /* Help strings */
21108#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
21109 foreach_vpe_api_msg;
21110#undef _
Damjan Marion7cd468a2016-12-19 23:05:39 +010021111
21112 /* CLI functions */
21113#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
21114 foreach_cli_function;
21115#undef _
21116
21117 /* Help strings */
21118#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
21119 foreach_cli_function;
21120#undef _
21121}
21122
Dave Baracha1a093d2017-03-02 13:13:23 -050021123#if VPP_API_TEST_BUILTIN
21124static clib_error_t *
21125vat_api_hookup_shim (vlib_main_t * vm)
21126{
21127 vat_api_hookup (&vat_main);
21128 return 0;
21129}
21130
21131VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
21132#endif
21133
Damjan Marion7cd468a2016-12-19 23:05:39 +010021134/*
21135 * fd.io coding-style-patch-verification: ON
21136 *
21137 * Local Variables:
21138 * eval: (c-set-style "gnu")
21139 * End:
21140 */