blob: cc0f5bef8e44a6fedcfd32b059389bd806865417 [file] [log] [blame]
Damjan Marion7cd468a2016-12-19 23:05:39 +01001/*
2 *------------------------------------------------------------------
3 * api_format.c
4 *
Dave Barachac0326f2020-07-14 18:30:05 -04005 * Copyright (c) 2014-2020 Cisco and/or its affiliates.
Damjan Marion7cd468a2016-12-19 23:05:39 +01006 * 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/ip/ip6_hop_by_hop.h>
47#include <vnet/ip/ip_source_and_port_range_check.h>
48#include <vnet/policer/xlate.h>
49#include <vnet/span/span.h>
50#include <vnet/policer/policer.h>
51#include <vnet/policer/police.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000052#include <vnet/mfib/mfib_types.h>
Steven9cd2d7a2017-12-20 12:43:01 -080053#include <vnet/bonding/node.h>
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070054#include <vnet/qos/qos_types.h>
Neale Ranns37029302018-08-10 05:30:06 -070055#include <vnet/ethernet/ethernet_types_api.h>
56#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010057#include "vat/json_format.h"
Neale Ranns86327be2018-11-02 09:14:01 -070058#include <vnet/ip/ip_types_api.h>
59#include <vnet/ethernet/ethernet_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010060
61#include <inttypes.h>
62#include <sys/stat.h>
63
64#define vl_typedefs /* define message structures */
65#include <vpp/api/vpe_all_api_h.h>
66#undef vl_typedefs
67
68/* declare message handlers for each api */
69
70#define vl_endianfun /* define message structures */
71#include <vpp/api/vpe_all_api_h.h>
72#undef vl_endianfun
73
74/* instantiate all the print functions we know about */
Dave Barachf35a0722019-06-12 16:50:38 -040075#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010076#define vl_print(handle, ...)
Dave Barachf35a0722019-06-12 16:50:38 -040077#else
78#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
79#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010080#define vl_printfun
81#include <vpp/api/vpe_all_api_h.h>
82#undef vl_printfun
83
Dave Barach2d6b2d62017-01-25 16:32:08 -050084#define __plugin_msg_base 0
Dave Barachfe6bdfd2017-01-20 19:50:09 -050085#include <vlibapi/vat_helper_macros.h>
86
Ole Troan33a58172019-09-04 09:12:29 +020087#include <vnet/format_fns.h>
88
Dave Barachb09f4d02019-07-15 16:00:03 -040089void vl_api_set_elog_main (elog_main_t * m);
90int vl_api_set_elog_trace_api_messages (int enable);
91
Dave Barach59b25652017-09-10 15:04:27 -040092#if VPP_API_TEST_BUILTIN == 0
93#include <netdb.h>
94
95u32
96vl (void *p)
97{
98 return vec_len (p);
99}
100
101int
102vat_socket_connect (vat_main_t * vam)
103{
Florin Coras66a10032018-12-21 16:23:09 -0800104 int rv;
Dave Barach69eeadc2020-04-14 09:52:26 -0400105 api_main_t *am = vlibapi_get_main ();
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;
Dave Barach69eeadc2020-04-14 09:52:26 -0400111
Florin Coras66a10032018-12-21 16:23:09 -0800112 /* vpp expects the client index in network order */
113 vam->my_client_index = htonl (socket_client_main.client_index);
Dave Barach69eeadc2020-04-14 09:52:26 -0400114 am->my_client_index = vam->my_client_index;
Florin Coras66a10032018-12-21 16:23:09 -0800115 return 0;
Dave Barach59b25652017-09-10 15:04:27 -0400116}
117#else /* vpp built-in case, we don't do sockets... */
118int
119vat_socket_connect (vat_main_t * vam)
120{
121 return 0;
122}
123
Florin Coras90a63982017-12-19 04:50:01 -0800124int
125vl_socket_client_read (int wait)
Dave Barach59b25652017-09-10 15:04:27 -0400126{
Florin Coras90a63982017-12-19 04:50:01 -0800127 return -1;
Dave Barach59b25652017-09-10 15:04:27 -0400128};
Florin Coras90a63982017-12-19 04:50:01 -0800129
130int
131vl_socket_client_write ()
132{
133 return -1;
134};
135
136void *
137vl_socket_client_msg_alloc (int nbytes)
138{
139 return 0;
140}
Dave Barach59b25652017-09-10 15:04:27 -0400141#endif
142
143
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500144f64
145vat_time_now (vat_main_t * vam)
146{
147#if VPP_API_TEST_BUILTIN
148 return vlib_time_now (vam->vlib_main);
149#else
150 return clib_time_now (&vam->clib_time);
151#endif
152}
153
154void
155errmsg (char *fmt, ...)
156{
157 vat_main_t *vam = &vat_main;
158 va_list va;
159 u8 *s;
160
161 va_start (va, fmt);
162 s = va_format (0, fmt, &va);
163 va_end (va);
164
165 vec_add1 (s, 0);
166
167#if VPP_API_TEST_BUILTIN
168 vlib_cli_output (vam->vlib_main, (char *) s);
169#else
170 {
171 if (vam->ifp != stdin)
172 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
173 vam->input_line_number);
Dave Barachb09f4d02019-07-15 16:00:03 -0400174 else
175 fformat (vam->ofp, "%s\n", (char *) s);
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500176 fflush (vam->ofp);
177 }
178#endif
179
180 vec_free (s);
181}
182
Dave Barach4a3f69c2017-02-22 12:44:56 -0500183#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +0100184static uword
185api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
186{
187 vat_main_t *vam = va_arg (*args, vat_main_t *);
188 u32 *result = va_arg (*args, u32 *);
189 u8 *if_name;
190 uword *p;
191
192 if (!unformat (input, "%s", &if_name))
193 return 0;
194
195 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
196 if (p == 0)
197 return 0;
198 *result = p[0];
199 return 1;
200}
201
eyal bariaf86a482018-04-17 11:20:27 +0300202static uword
203api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
204{
205 return 0;
206}
207
Damjan Marion7cd468a2016-12-19 23:05:39 +0100208/* Parse an IP4 address %d.%d.%d.%d. */
209uword
210unformat_ip4_address (unformat_input_t * input, va_list * args)
211{
212 u8 *result = va_arg (*args, u8 *);
213 unsigned a[4];
214
215 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
216 return 0;
217
218 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
219 return 0;
220
221 result[0] = a[0];
222 result[1] = a[1];
223 result[2] = a[2];
224 result[3] = a[3];
225
226 return 1;
227}
228
229uword
230unformat_ethernet_address (unformat_input_t * input, va_list * args)
231{
232 u8 *result = va_arg (*args, u8 *);
233 u32 i, a[6];
234
235 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
236 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
237 return 0;
238
239 /* Check range. */
240 for (i = 0; i < 6; i++)
241 if (a[i] >= (1 << 8))
242 return 0;
243
244 for (i = 0; i < 6; i++)
245 result[i] = a[i];
246
247 return 1;
248}
249
250/* Returns ethernet type as an int in host byte order. */
251uword
252unformat_ethernet_type_host_byte_order (unformat_input_t * input,
253 va_list * args)
254{
255 u16 *result = va_arg (*args, u16 *);
256 int type;
257
258 /* Numeric type. */
259 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
260 {
261 if (type >= (1 << 16))
262 return 0;
263 *result = type;
264 return 1;
265 }
266 return 0;
267}
268
Jakub Grajciar23a386b2020-02-26 11:01:43 +0100269/* Parse an IP46 address. */
270uword
271unformat_ip46_address (unformat_input_t * input, va_list * args)
272{
273 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
274 ip46_type_t type = va_arg (*args, ip46_type_t);
275 if ((type != IP46_TYPE_IP6) &&
276 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
277 {
278 ip46_address_mask_ip4 (ip46);
279 return 1;
280 }
281 else if ((type != IP46_TYPE_IP4) &&
282 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
283 {
284 return 1;
285 }
286 return 0;
287}
288
Damjan Marion7cd468a2016-12-19 23:05:39 +0100289/* Parse an IP6 address. */
290uword
291unformat_ip6_address (unformat_input_t * input, va_list * args)
292{
293 ip6_address_t *result = va_arg (*args, ip6_address_t *);
294 u16 hex_quads[8];
295 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
296 uword c, n_colon, double_colon_index;
297
298 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
299 double_colon_index = ARRAY_LEN (hex_quads);
300 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
301 {
302 hex_digit = 16;
303 if (c >= '0' && c <= '9')
304 hex_digit = c - '0';
305 else if (c >= 'a' && c <= 'f')
306 hex_digit = c + 10 - 'a';
307 else if (c >= 'A' && c <= 'F')
308 hex_digit = c + 10 - 'A';
309 else if (c == ':' && n_colon < 2)
310 n_colon++;
311 else
312 {
313 unformat_put_input (input);
314 break;
315 }
316
317 /* Too many hex quads. */
318 if (n_hex_quads >= ARRAY_LEN (hex_quads))
319 return 0;
320
321 if (hex_digit < 16)
322 {
323 hex_quad = (hex_quad << 4) | hex_digit;
324
325 /* Hex quad must fit in 16 bits. */
326 if (n_hex_digits >= 4)
327 return 0;
328
329 n_colon = 0;
330 n_hex_digits++;
331 }
332
333 /* Save position of :: */
334 if (n_colon == 2)
335 {
336 /* More than one :: ? */
337 if (double_colon_index < ARRAY_LEN (hex_quads))
338 return 0;
339 double_colon_index = n_hex_quads;
340 }
341
342 if (n_colon > 0 && n_hex_digits > 0)
343 {
344 hex_quads[n_hex_quads++] = hex_quad;
345 hex_quad = 0;
346 n_hex_digits = 0;
347 }
348 }
349
350 if (n_hex_digits > 0)
351 hex_quads[n_hex_quads++] = hex_quad;
352
353 {
354 word i;
355
356 /* Expand :: to appropriate number of zero hex quads. */
357 if (double_colon_index < ARRAY_LEN (hex_quads))
358 {
359 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
360
361 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
362 hex_quads[n_zero + i] = hex_quads[i];
363
364 for (i = 0; i < n_zero; i++)
365 hex_quads[double_colon_index + i] = 0;
366
367 n_hex_quads = ARRAY_LEN (hex_quads);
368 }
369
370 /* Too few hex quads given. */
371 if (n_hex_quads < ARRAY_LEN (hex_quads))
372 return 0;
373
374 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
375 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
376
377 return 1;
378 }
379}
380
381uword
382unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
383{
384 u32 *r = va_arg (*args, u32 *);
385
386 if (0);
387#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
388 foreach_ipsec_policy_action
389#undef _
390 else
391 return 0;
392 return 1;
393}
394
Damjan Marion7cd468a2016-12-19 23:05:39 +0100395u8 *
396format_ipsec_crypto_alg (u8 * s, va_list * args)
397{
398 u32 i = va_arg (*args, u32);
399 u8 *t = 0;
400
401 switch (i)
402 {
403#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
404 foreach_ipsec_crypto_alg
405#undef _
406 default:
407 return format (s, "unknown");
408 }
409 return format (s, "%s", t);
410}
411
Damjan Marion7cd468a2016-12-19 23:05:39 +0100412u8 *
413format_ipsec_integ_alg (u8 * s, va_list * args)
414{
415 u32 i = va_arg (*args, u32);
416 u8 *t = 0;
417
418 switch (i)
419 {
420#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
421 foreach_ipsec_integ_alg
422#undef _
423 default:
424 return format (s, "unknown");
425 }
426 return format (s, "%s", t);
427}
428
Dave Barach4a3f69c2017-02-22 12:44:56 -0500429#else /* VPP_API_TEST_BUILTIN == 1 */
430static uword
431api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
432{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200433 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500434 vnet_main_t *vnm = vnet_get_main ();
435 u32 *result = va_arg (*args, u32 *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500436
eyal bariaf86a482018-04-17 11:20:27 +0300437 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500438}
eyal bariaf86a482018-04-17 11:20:27 +0300439
440static uword
441api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
442{
Benoît Ganne49ee6842019-04-30 11:50:46 +0200443 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
eyal bariaf86a482018-04-17 11:20:27 +0300444 vnet_main_t *vnm = vnet_get_main ();
445 u32 *result = va_arg (*args, u32 *);
446
447 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
448}
449
Damjan Marion7cd468a2016-12-19 23:05:39 +0100450#endif /* VPP_API_TEST_BUILTIN */
451
Neale Ranns17dcec02019-01-09 21:22:20 -0800452uword
453unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
454{
455 u32 *r = va_arg (*args, u32 *);
456
457 if (0);
458#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
459 foreach_ipsec_crypto_alg
460#undef _
461 else
462 return 0;
463 return 1;
464}
465
466uword
467unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
468{
469 u32 *r = va_arg (*args, u32 *);
470
471 if (0);
472#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
473 foreach_ipsec_integ_alg
474#undef _
475 else
476 return 0;
477 return 1;
478}
479
Damjan Marion7cd468a2016-12-19 23:05:39 +0100480static uword
481unformat_policer_rate_type (unformat_input_t * input, va_list * args)
482{
483 u8 *r = va_arg (*args, u8 *);
484
485 if (unformat (input, "kbps"))
486 *r = SSE2_QOS_RATE_KBPS;
487 else if (unformat (input, "pps"))
488 *r = SSE2_QOS_RATE_PPS;
489 else
490 return 0;
491 return 1;
492}
493
494static uword
495unformat_policer_round_type (unformat_input_t * input, va_list * args)
496{
497 u8 *r = va_arg (*args, u8 *);
498
499 if (unformat (input, "closest"))
500 *r = SSE2_QOS_ROUND_TO_CLOSEST;
501 else if (unformat (input, "up"))
502 *r = SSE2_QOS_ROUND_TO_UP;
503 else if (unformat (input, "down"))
504 *r = SSE2_QOS_ROUND_TO_DOWN;
505 else
506 return 0;
507 return 1;
508}
509
510static uword
511unformat_policer_type (unformat_input_t * input, va_list * args)
512{
513 u8 *r = va_arg (*args, u8 *);
514
515 if (unformat (input, "1r2c"))
516 *r = SSE2_QOS_POLICER_TYPE_1R2C;
517 else if (unformat (input, "1r3c"))
518 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
519 else if (unformat (input, "2r3c-2698"))
520 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
521 else if (unformat (input, "2r3c-4115"))
522 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
523 else if (unformat (input, "2r3c-mef5cf1"))
524 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
525 else
526 return 0;
527 return 1;
528}
529
530static uword
531unformat_dscp (unformat_input_t * input, va_list * va)
532{
533 u8 *r = va_arg (*va, u8 *);
534
535 if (0);
536#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
537 foreach_vnet_dscp
538#undef _
539 else
540 return 0;
541 return 1;
542}
543
544static uword
545unformat_policer_action_type (unformat_input_t * input, va_list * va)
546{
547 sse2_qos_pol_action_params_st *a
548 = va_arg (*va, sse2_qos_pol_action_params_st *);
549
550 if (unformat (input, "drop"))
551 a->action_type = SSE2_QOS_ACTION_DROP;
552 else if (unformat (input, "transmit"))
553 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
554 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
555 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
556 else
557 return 0;
558 return 1;
559}
560
561static uword
562unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
563{
564 u32 *r = va_arg (*va, u32 *);
565 u32 tid;
566
567 if (unformat (input, "ip4"))
568 tid = POLICER_CLASSIFY_TABLE_IP4;
569 else if (unformat (input, "ip6"))
570 tid = POLICER_CLASSIFY_TABLE_IP6;
571 else if (unformat (input, "l2"))
572 tid = POLICER_CLASSIFY_TABLE_L2;
573 else
574 return 0;
575
576 *r = tid;
577 return 1;
578}
579
580static uword
581unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
582{
583 u32 *r = va_arg (*va, u32 *);
584 u32 tid;
585
586 if (unformat (input, "ip4"))
587 tid = FLOW_CLASSIFY_TABLE_IP4;
588 else if (unformat (input, "ip6"))
589 tid = FLOW_CLASSIFY_TABLE_IP6;
590 else
591 return 0;
592
593 *r = tid;
594 return 1;
595}
596
Benoît Ganne49ee6842019-04-30 11:50:46 +0200597#if (VPP_API_TEST_BUILTIN==0)
598
Neale Ranns32e1c012016-11-22 17:07:28 +0000599static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
600static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
601static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
602static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
603
604uword
605unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
606{
607 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
608 mfib_itf_attribute_t attr;
609
610 old = *iflags;
611 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
612 {
613 if (unformat (input, mfib_itf_flag_long_names[attr]))
614 *iflags |= (1 << attr);
615 }
616 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
617 {
618 if (unformat (input, mfib_itf_flag_names[attr]))
619 *iflags |= (1 << attr);
620 }
621
622 return (old == *iflags ? 0 : 1);
623}
624
625uword
626unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
627{
628 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
629 mfib_entry_attribute_t attr;
630
631 old = *eflags;
632 FOR_EACH_MFIB_ATTRIBUTE (attr)
633 {
634 if (unformat (input, mfib_flag_long_names[attr]))
635 *eflags |= (1 << attr);
636 }
637 FOR_EACH_MFIB_ATTRIBUTE (attr)
638 {
639 if (unformat (input, mfib_flag_names[attr]))
640 *eflags |= (1 << attr);
641 }
642
643 return (old == *eflags ? 0 : 1);
644}
645
Damjan Marion7cd468a2016-12-19 23:05:39 +0100646u8 *
647format_ip4_address (u8 * s, va_list * args)
648{
649 u8 *a = va_arg (*args, u8 *);
650 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
651}
652
653u8 *
654format_ip6_address (u8 * s, va_list * args)
655{
656 ip6_address_t *a = va_arg (*args, ip6_address_t *);
657 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
658
659 i_max_n_zero = ARRAY_LEN (a->as_u16);
660 max_n_zeros = 0;
661 i_first_zero = i_max_n_zero;
662 n_zeros = 0;
663 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
664 {
665 u32 is_zero = a->as_u16[i] == 0;
666 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
667 {
668 i_first_zero = i;
669 n_zeros = 0;
670 }
671 n_zeros += is_zero;
672 if ((!is_zero && n_zeros > max_n_zeros)
673 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
674 {
675 i_max_n_zero = i_first_zero;
676 max_n_zeros = n_zeros;
677 i_first_zero = ARRAY_LEN (a->as_u16);
678 n_zeros = 0;
679 }
680 }
681
682 last_double_colon = 0;
683 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
684 {
685 if (i == i_max_n_zero && max_n_zeros > 1)
686 {
687 s = format (s, "::");
688 i += max_n_zeros - 1;
689 last_double_colon = 1;
690 }
691 else
692 {
693 s = format (s, "%s%x",
694 (last_double_colon || i == 0) ? "" : ":",
695 clib_net_to_host_u16 (a->as_u16[i]));
696 last_double_colon = 0;
697 }
698 }
699
700 return s;
701}
702
703/* Format an IP46 address. */
704u8 *
705format_ip46_address (u8 * s, va_list * args)
706{
707 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
708 ip46_type_t type = va_arg (*args, ip46_type_t);
709 int is_ip4 = 1;
710
711 switch (type)
712 {
713 case IP46_TYPE_ANY:
714 is_ip4 = ip46_address_is_ip4 (ip46);
715 break;
716 case IP46_TYPE_IP4:
717 is_ip4 = 1;
718 break;
719 case IP46_TYPE_IP6:
720 is_ip4 = 0;
721 break;
722 }
723
724 return is_ip4 ?
725 format (s, "%U", format_ip4_address, &ip46->ip4) :
726 format (s, "%U", format_ip6_address, &ip46->ip6);
727}
728
729u8 *
730format_ethernet_address (u8 * s, va_list * args)
731{
732 u8 *a = va_arg (*args, u8 *);
733
734 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
735 a[0], a[1], a[2], a[3], a[4], a[5]);
736}
737#endif
738
739static void
Neale Ranns097fa662018-05-01 05:17:55 -0700740increment_v4_address (vl_api_ip4_address_t * i)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100741{
Neale Ranns097fa662018-05-01 05:17:55 -0700742 ip4_address_t *a = (ip4_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100743 u32 v;
744
745 v = ntohl (a->as_u32) + 1;
746 a->as_u32 = ntohl (v);
747}
748
749static void
Neale Ranns097fa662018-05-01 05:17:55 -0700750increment_v6_address (vl_api_ip6_address_t * i)
Neale Ranns2b5ba952019-04-02 10:15:40 +0000751{
Neale Ranns097fa662018-05-01 05:17:55 -0700752 ip6_address_t *a = (ip6_address_t *) i;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100753 u64 v0, v1;
754
755 v0 = clib_net_to_host_u64 (a->as_u64[0]);
756 v1 = clib_net_to_host_u64 (a->as_u64[1]);
757
758 v1 += 1;
759 if (v1 == 0)
760 v0 += 1;
761 a->as_u64[0] = clib_net_to_host_u64 (v0);
762 a->as_u64[1] = clib_net_to_host_u64 (v1);
763}
764
765static void
Neale Ranns097fa662018-05-01 05:17:55 -0700766increment_address (vl_api_address_t * a)
767{
Dave Barach54582662020-04-21 08:01:16 -0400768 if (a->af == ADDRESS_IP4)
Neale Ranns097fa662018-05-01 05:17:55 -0700769 increment_v4_address (&a->un.ip4);
Dave Barach54582662020-04-21 08:01:16 -0400770 else if (a->af == ADDRESS_IP6)
Neale Ranns097fa662018-05-01 05:17:55 -0700771 increment_v6_address (&a->un.ip6);
772}
773
774static void
775set_ip4_address (vl_api_address_t * a, u32 v)
776{
777 if (a->af == ADDRESS_IP4)
778 {
779 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
780 i->as_u32 = v;
781 }
782}
783
Jakub Grajciar23a386b2020-02-26 11:01:43 +0100784void
785ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
786{
787 if (is_ip4)
788 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
789 else
790 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
791 sizeof (ip6_address_t));
792}
793
Neale Ranns097fa662018-05-01 05:17:55 -0700794static void
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200795increment_mac_address (u8 * mac)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100796{
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200797 u64 tmp = *((u64 *) mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100798 tmp = clib_net_to_host_u64 (tmp);
799 tmp += 1 << 16; /* skip unused (least significant) octets */
800 tmp = clib_host_to_net_u64 (tmp);
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200801
802 clib_memcpy (mac, &tmp, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100803}
804
Neale Ranns097fa662018-05-01 05:17:55 -0700805static void
806vat_json_object_add_address (vat_json_node_t * node,
807 const char *str, const vl_api_address_t * addr)
808{
809 if (ADDRESS_IP6 == addr->af)
810 {
811 struct in6_addr ip6;
812
813 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
814 vat_json_object_add_ip6 (node, str, ip6);
815 }
816 else
817 {
818 struct in_addr ip4;
819
820 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
821 vat_json_object_add_ip4 (node, str, ip4);
822 }
823}
824
825static void
826vat_json_object_add_prefix (vat_json_node_t * node,
827 const vl_api_prefix_t * prefix)
828{
Paul Vinciguerraab055082019-06-06 14:07:55 -0400829 vat_json_object_add_uint (node, "len", prefix->len);
830 vat_json_object_add_address (node, "address", &prefix->address);
Neale Ranns097fa662018-05-01 05:17:55 -0700831}
832
Damjan Marion7cd468a2016-12-19 23:05:39 +0100833static void vl_api_create_loopback_reply_t_handler
834 (vl_api_create_loopback_reply_t * mp)
835{
836 vat_main_t *vam = &vat_main;
837 i32 retval = ntohl (mp->retval);
838
839 vam->retval = retval;
840 vam->regenerate_interface_table = 1;
841 vam->sw_if_index = ntohl (mp->sw_if_index);
842 vam->result_ready = 1;
843}
844
845static void vl_api_create_loopback_reply_t_handler_json
846 (vl_api_create_loopback_reply_t * mp)
847{
848 vat_main_t *vam = &vat_main;
849 vat_json_node_t node;
850
851 vat_json_init_object (&node);
852 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
853 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
854
855 vat_json_print (vam->ofp, &node);
856 vat_json_free (&node);
857 vam->retval = ntohl (mp->retval);
858 vam->result_ready = 1;
859}
860
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600861static void vl_api_create_loopback_instance_reply_t_handler
862 (vl_api_create_loopback_instance_reply_t * mp)
863{
864 vat_main_t *vam = &vat_main;
865 i32 retval = ntohl (mp->retval);
866
867 vam->retval = retval;
868 vam->regenerate_interface_table = 1;
869 vam->sw_if_index = ntohl (mp->sw_if_index);
870 vam->result_ready = 1;
871}
872
873static void vl_api_create_loopback_instance_reply_t_handler_json
874 (vl_api_create_loopback_instance_reply_t * mp)
875{
876 vat_main_t *vam = &vat_main;
877 vat_json_node_t node;
878
879 vat_json_init_object (&node);
880 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
881 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
882
883 vat_json_print (vam->ofp, &node);
884 vat_json_free (&node);
885 vam->retval = ntohl (mp->retval);
886 vam->result_ready = 1;
887}
888
Damjan Marion7cd468a2016-12-19 23:05:39 +0100889static void vl_api_af_packet_create_reply_t_handler
890 (vl_api_af_packet_create_reply_t * mp)
891{
892 vat_main_t *vam = &vat_main;
893 i32 retval = ntohl (mp->retval);
894
895 vam->retval = retval;
896 vam->regenerate_interface_table = 1;
897 vam->sw_if_index = ntohl (mp->sw_if_index);
898 vam->result_ready = 1;
899}
900
901static void vl_api_af_packet_create_reply_t_handler_json
902 (vl_api_af_packet_create_reply_t * mp)
903{
904 vat_main_t *vam = &vat_main;
905 vat_json_node_t node;
906
907 vat_json_init_object (&node);
908 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
909 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
910
911 vat_json_print (vam->ofp, &node);
912 vat_json_free (&node);
913
914 vam->retval = ntohl (mp->retval);
915 vam->result_ready = 1;
916}
917
918static void vl_api_create_vlan_subif_reply_t_handler
919 (vl_api_create_vlan_subif_reply_t * mp)
920{
921 vat_main_t *vam = &vat_main;
922 i32 retval = ntohl (mp->retval);
923
924 vam->retval = retval;
925 vam->regenerate_interface_table = 1;
926 vam->sw_if_index = ntohl (mp->sw_if_index);
927 vam->result_ready = 1;
928}
929
930static void vl_api_create_vlan_subif_reply_t_handler_json
931 (vl_api_create_vlan_subif_reply_t * mp)
932{
933 vat_main_t *vam = &vat_main;
934 vat_json_node_t node;
935
936 vat_json_init_object (&node);
937 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
938 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
939
940 vat_json_print (vam->ofp, &node);
941 vat_json_free (&node);
942
943 vam->retval = ntohl (mp->retval);
944 vam->result_ready = 1;
945}
946
947static void vl_api_create_subif_reply_t_handler
948 (vl_api_create_subif_reply_t * mp)
949{
950 vat_main_t *vam = &vat_main;
951 i32 retval = ntohl (mp->retval);
952
953 vam->retval = retval;
954 vam->regenerate_interface_table = 1;
955 vam->sw_if_index = ntohl (mp->sw_if_index);
956 vam->result_ready = 1;
957}
958
959static void vl_api_create_subif_reply_t_handler_json
960 (vl_api_create_subif_reply_t * mp)
961{
962 vat_main_t *vam = &vat_main;
963 vat_json_node_t node;
964
965 vat_json_init_object (&node);
966 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
967 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
968
969 vat_json_print (vam->ofp, &node);
970 vat_json_free (&node);
971
972 vam->retval = ntohl (mp->retval);
973 vam->result_ready = 1;
974}
975
976static void vl_api_interface_name_renumber_reply_t_handler
977 (vl_api_interface_name_renumber_reply_t * mp)
978{
979 vat_main_t *vam = &vat_main;
980 i32 retval = ntohl (mp->retval);
981
982 vam->retval = retval;
983 vam->regenerate_interface_table = 1;
984 vam->result_ready = 1;
985}
986
987static void vl_api_interface_name_renumber_reply_t_handler_json
988 (vl_api_interface_name_renumber_reply_t * mp)
989{
990 vat_main_t *vam = &vat_main;
991 vat_json_node_t node;
992
993 vat_json_init_object (&node);
994 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
995
996 vat_json_print (vam->ofp, &node);
997 vat_json_free (&node);
998
999 vam->retval = ntohl (mp->retval);
1000 vam->result_ready = 1;
1001}
1002
1003/*
1004 * Special-case: build the interface table, maintain
1005 * the next loopback sw_if_index vbl.
1006 */
1007static void vl_api_sw_interface_details_t_handler
1008 (vl_api_sw_interface_details_t * mp)
1009{
1010 vat_main_t *vam = &vat_main;
Ole Troane5ff5a32019-08-23 22:55:18 +02001011 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001012
1013 hash_set_mem (vam->sw_if_index_by_interface_name, s,
1014 ntohl (mp->sw_if_index));
1015
1016 /* In sub interface case, fill the sub interface table entry */
1017 if (mp->sw_if_index != mp->sup_sw_if_index)
1018 {
1019 sw_interface_subif_t *sub = NULL;
1020
1021 vec_add2 (vam->sw_if_subif_table, sub, 1);
1022
1023 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
1024 strncpy ((char *) sub->interface_name, (char *) s,
1025 vec_len (sub->interface_name));
1026 sub->sw_if_index = ntohl (mp->sw_if_index);
1027 sub->sub_id = ntohl (mp->sub_id);
1028
Jakub Grajciar053204a2019-03-18 13:17:53 +01001029 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
1030
Damjan Marion7cd468a2016-12-19 23:05:39 +01001031 sub->sub_number_of_tags = mp->sub_number_of_tags;
1032 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1033 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001034
1035 /* vlan tag rewrite */
1036 sub->vtr_op = ntohl (mp->vtr_op);
1037 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1038 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1039 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1040 }
1041}
1042
1043static void vl_api_sw_interface_details_t_handler_json
1044 (vl_api_sw_interface_details_t * mp)
1045{
1046 vat_main_t *vam = &vat_main;
1047 vat_json_node_t *node = NULL;
1048
1049 if (VAT_JSON_ARRAY != vam->json_tree.type)
1050 {
1051 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1052 vat_json_init_array (&vam->json_tree);
1053 }
1054 node = vat_json_array_add (&vam->json_tree);
1055
1056 vat_json_init_object (node);
1057 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1058 vat_json_object_add_uint (node, "sup_sw_if_index",
1059 ntohl (mp->sup_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001060 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1061 sizeof (mp->l2_address));
1062 vat_json_object_add_string_copy (node, "interface_name",
Ole Troane5ff5a32019-08-23 22:55:18 +02001063 mp->interface_name);
Mohsin Kazmide312c22019-09-27 13:44:28 +02001064 vat_json_object_add_string_copy (node, "interface_dev_type",
1065 mp->interface_dev_type);
Jakub Grajciar053204a2019-03-18 13:17:53 +01001066 vat_json_object_add_uint (node, "flags", mp->flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001067 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1068 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001069 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001070 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001071 vat_json_object_add_uint (node, "sub_number_of_tags",
1072 mp->sub_number_of_tags);
1073 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1074 ntohs (mp->sub_outer_vlan_id));
1075 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1076 ntohs (mp->sub_inner_vlan_id));
Jakub Grajciar053204a2019-03-18 13:17:53 +01001077 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001078 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1079 vat_json_object_add_uint (node, "vtr_push_dot1q",
1080 ntohl (mp->vtr_push_dot1q));
1081 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1082 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Jakub Grajciar053204a2019-03-18 13:17:53 +01001083 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
Pavel Kotucek65e84572017-01-16 17:01:56 +01001084 {
1085 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1086 format (0, "%U",
1087 format_ethernet_address,
1088 &mp->b_dmac));
1089 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1090 format (0, "%U",
1091 format_ethernet_address,
1092 &mp->b_smac));
1093 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1094 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1095 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001096}
1097
Dave Baracha1a093d2017-03-02 13:13:23 -05001098#if VPP_API_TEST_BUILTIN == 0
Neale Rannsa07bd702017-08-07 07:53:49 -07001099static void vl_api_sw_interface_event_t_handler
1100 (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001101{
1102 vat_main_t *vam = &vat_main;
1103 if (vam->interface_event_display)
1104 errmsg ("interface flags: sw_if_index %d %s %s",
1105 ntohl (mp->sw_if_index),
Jakub Grajciar053204a2019-03-18 13:17:53 +01001106 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1107 "admin-up" : "admin-down",
1108 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1109 "link-up" : "link-down");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001110}
Dave Baracha1a093d2017-03-02 13:13:23 -05001111#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +01001112
Benoît Ganne49ee6842019-04-30 11:50:46 +02001113__clib_unused static void
1114vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001115{
1116 /* JSON output not supported */
1117}
1118
1119static void
1120vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1121{
1122 vat_main_t *vam = &vat_main;
1123 i32 retval = ntohl (mp->retval);
1124
1125 vam->retval = retval;
Damjan Marion7bee80c2017-04-26 15:32:12 +02001126 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001127 vam->result_ready = 1;
1128}
1129
1130static void
1131vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1132{
1133 vat_main_t *vam = &vat_main;
1134 vat_json_node_t node;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001135 void *oldheap;
1136 u8 *reply;
1137
1138 vat_json_init_object (&node);
1139 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1140 vat_json_object_add_uint (&node, "reply_in_shmem",
1141 ntohl (mp->reply_in_shmem));
1142 /* Toss the shared-memory original... */
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01001143 oldheap = vl_msg_push_heap ();
Damjan Marion7cd468a2016-12-19 23:05:39 +01001144
Damjan Marion7bee80c2017-04-26 15:32:12 +02001145 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001146 vec_free (reply);
1147
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01001148 vl_msg_pop_heap (oldheap);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001149
1150 vat_json_print (vam->ofp, &node);
1151 vat_json_free (&node);
1152
1153 vam->retval = ntohl (mp->retval);
1154 vam->result_ready = 1;
1155}
1156
1157static void
1158vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1159{
1160 vat_main_t *vam = &vat_main;
1161 i32 retval = ntohl (mp->retval);
Dave Barach59b25652017-09-10 15:04:27 -04001162
1163 vec_reset_length (vam->cmd_reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001164
1165 vam->retval = retval;
Dave Barach59b25652017-09-10 15:04:27 -04001166 if (retval == 0)
Dave Barach77841402020-04-29 17:04:10 -04001167 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001168 vam->result_ready = 1;
1169}
1170
1171static void
1172vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1173{
1174 vat_main_t *vam = &vat_main;
1175 vat_json_node_t node;
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001176 u8 *reply = 0; /* reply vector */
Damjan Marion7cd468a2016-12-19 23:05:39 +01001177
Dave Barach77841402020-04-29 17:04:10 -04001178 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
Dave Barach59b25652017-09-10 15:04:27 -04001179 vec_reset_length (vam->cmd_reply);
1180
Damjan Marion7cd468a2016-12-19 23:05:39 +01001181 vat_json_init_object (&node);
1182 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001183 vat_json_object_add_string_copy (&node, "reply", reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001184
1185 vat_json_print (vam->ofp, &node);
1186 vat_json_free (&node);
Jakub Grajciar2dbee932020-02-07 11:30:26 +01001187 vec_free (reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001188
1189 vam->retval = ntohl (mp->retval);
1190 vam->result_ready = 1;
1191}
1192
1193static void vl_api_classify_add_del_table_reply_t_handler
1194 (vl_api_classify_add_del_table_reply_t * mp)
1195{
1196 vat_main_t *vam = &vat_main;
1197 i32 retval = ntohl (mp->retval);
1198 if (vam->async_mode)
1199 {
1200 vam->async_errors += (retval < 0);
1201 }
1202 else
1203 {
1204 vam->retval = retval;
1205 if (retval == 0 &&
1206 ((mp->new_table_index != 0xFFFFFFFF) ||
1207 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1208 (mp->match_n_vectors != 0xFFFFFFFF)))
1209 /*
1210 * Note: this is just barely thread-safe, depends on
1211 * the main thread spinning waiting for an answer...
1212 */
1213 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1214 ntohl (mp->new_table_index),
1215 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1216 vam->result_ready = 1;
1217 }
1218}
1219
1220static void vl_api_classify_add_del_table_reply_t_handler_json
1221 (vl_api_classify_add_del_table_reply_t * mp)
1222{
1223 vat_main_t *vam = &vat_main;
1224 vat_json_node_t node;
1225
1226 vat_json_init_object (&node);
1227 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1228 vat_json_object_add_uint (&node, "new_table_index",
1229 ntohl (mp->new_table_index));
1230 vat_json_object_add_uint (&node, "skip_n_vectors",
1231 ntohl (mp->skip_n_vectors));
1232 vat_json_object_add_uint (&node, "match_n_vectors",
1233 ntohl (mp->match_n_vectors));
1234
1235 vat_json_print (vam->ofp, &node);
1236 vat_json_free (&node);
1237
1238 vam->retval = ntohl (mp->retval);
1239 vam->result_ready = 1;
1240}
1241
1242static void vl_api_get_node_index_reply_t_handler
1243 (vl_api_get_node_index_reply_t * mp)
1244{
1245 vat_main_t *vam = &vat_main;
1246 i32 retval = ntohl (mp->retval);
1247 if (vam->async_mode)
1248 {
1249 vam->async_errors += (retval < 0);
1250 }
1251 else
1252 {
1253 vam->retval = retval;
1254 if (retval == 0)
1255 errmsg ("node index %d", ntohl (mp->node_index));
1256 vam->result_ready = 1;
1257 }
1258}
1259
1260static void vl_api_get_node_index_reply_t_handler_json
1261 (vl_api_get_node_index_reply_t * mp)
1262{
1263 vat_main_t *vam = &vat_main;
1264 vat_json_node_t node;
1265
1266 vat_json_init_object (&node);
1267 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1268 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1269
1270 vat_json_print (vam->ofp, &node);
1271 vat_json_free (&node);
1272
1273 vam->retval = ntohl (mp->retval);
1274 vam->result_ready = 1;
1275}
1276
1277static void vl_api_get_next_index_reply_t_handler
1278 (vl_api_get_next_index_reply_t * mp)
1279{
1280 vat_main_t *vam = &vat_main;
1281 i32 retval = ntohl (mp->retval);
1282 if (vam->async_mode)
1283 {
1284 vam->async_errors += (retval < 0);
1285 }
1286 else
1287 {
1288 vam->retval = retval;
1289 if (retval == 0)
1290 errmsg ("next node index %d", ntohl (mp->next_index));
1291 vam->result_ready = 1;
1292 }
1293}
1294
1295static void vl_api_get_next_index_reply_t_handler_json
1296 (vl_api_get_next_index_reply_t * mp)
1297{
1298 vat_main_t *vam = &vat_main;
1299 vat_json_node_t node;
1300
1301 vat_json_init_object (&node);
1302 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1303 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1304
1305 vat_json_print (vam->ofp, &node);
1306 vat_json_free (&node);
1307
1308 vam->retval = ntohl (mp->retval);
1309 vam->result_ready = 1;
1310}
1311
1312static void vl_api_add_node_next_reply_t_handler
1313 (vl_api_add_node_next_reply_t * mp)
1314{
1315 vat_main_t *vam = &vat_main;
1316 i32 retval = ntohl (mp->retval);
1317 if (vam->async_mode)
1318 {
1319 vam->async_errors += (retval < 0);
1320 }
1321 else
1322 {
1323 vam->retval = retval;
1324 if (retval == 0)
1325 errmsg ("next index %d", ntohl (mp->next_index));
1326 vam->result_ready = 1;
1327 }
1328}
1329
1330static void vl_api_add_node_next_reply_t_handler_json
1331 (vl_api_add_node_next_reply_t * mp)
1332{
1333 vat_main_t *vam = &vat_main;
1334 vat_json_node_t node;
1335
1336 vat_json_init_object (&node);
1337 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1338 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1339
1340 vat_json_print (vam->ofp, &node);
1341 vat_json_free (&node);
1342
1343 vam->retval = ntohl (mp->retval);
1344 vam->result_ready = 1;
1345}
1346
1347static void vl_api_show_version_reply_t_handler
1348 (vl_api_show_version_reply_t * mp)
1349{
1350 vat_main_t *vam = &vat_main;
1351 i32 retval = ntohl (mp->retval);
1352
1353 if (retval >= 0)
1354 {
Ole Troane5ff5a32019-08-23 22:55:18 +02001355 errmsg (" program: %s", mp->program);
1356 errmsg (" version: %s", mp->version);
1357 errmsg (" build date: %s", mp->build_date);
1358 errmsg ("build directory: %s", mp->build_directory);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001359 }
1360 vam->retval = retval;
1361 vam->result_ready = 1;
1362}
1363
1364static void vl_api_show_version_reply_t_handler_json
1365 (vl_api_show_version_reply_t * mp)
1366{
1367 vat_main_t *vam = &vat_main;
1368 vat_json_node_t node;
1369
1370 vat_json_init_object (&node);
1371 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troane5ff5a32019-08-23 22:55:18 +02001372 vat_json_object_add_string_copy (&node, "program", mp->program);
1373 vat_json_object_add_string_copy (&node, "version", mp->version);
1374 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001375 vat_json_object_add_string_copy (&node, "build_directory",
Ole Troane5ff5a32019-08-23 22:55:18 +02001376 mp->build_directory);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001377
1378 vat_json_print (vam->ofp, &node);
1379 vat_json_free (&node);
1380
1381 vam->retval = ntohl (mp->retval);
1382 vam->result_ready = 1;
1383}
1384
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001385static void vl_api_show_threads_reply_t_handler
1386 (vl_api_show_threads_reply_t * mp)
1387{
1388 vat_main_t *vam = &vat_main;
1389 i32 retval = ntohl (mp->retval);
1390 int i, count = 0;
1391
1392 if (retval >= 0)
1393 count = ntohl (mp->count);
1394
1395 for (i = 0; i < count; i++)
1396 print (vam->ofp,
1397 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1398 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1399 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1400 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1401 ntohl (mp->thread_data[i].cpu_socket));
1402
1403 vam->retval = retval;
1404 vam->result_ready = 1;
1405}
1406
1407static void vl_api_show_threads_reply_t_handler_json
1408 (vl_api_show_threads_reply_t * mp)
1409{
1410 vat_main_t *vam = &vat_main;
1411 vat_json_node_t node;
1412 vl_api_thread_data_t *td;
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001413 i32 retval = ntohl (mp->retval);
1414 int i, count = 0;
1415
1416 if (retval >= 0)
1417 count = ntohl (mp->count);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001418
1419 vat_json_init_object (&node);
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001420 vat_json_object_add_int (&node, "retval", retval);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001421 vat_json_object_add_uint (&node, "count", count);
1422
1423 for (i = 0; i < count; i++)
1424 {
1425 td = &mp->thread_data[i];
1426 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1427 vat_json_object_add_string_copy (&node, "name", td->name);
1428 vat_json_object_add_string_copy (&node, "type", td->type);
1429 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1430 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1431 vat_json_object_add_int (&node, "core", ntohl (td->id));
1432 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1433 }
1434
1435 vat_json_print (vam->ofp, &node);
1436 vat_json_free (&node);
1437
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001438 vam->retval = retval;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001439 vam->result_ready = 1;
1440}
1441
1442static int
1443api_show_threads (vat_main_t * vam)
1444{
1445 vl_api_show_threads_t *mp;
1446 int ret;
1447
1448 print (vam->ofp,
1449 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1450 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1451
1452 M (SHOW_THREADS, mp);
1453
1454 S (mp);
1455 W (ret);
1456 return ret;
1457}
1458
Damjan Marion7cd468a2016-12-19 23:05:39 +01001459static void
John Lo8d00fff2017-08-03 00:35:36 -04001460vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1461{
1462 u32 n_macs = ntohl (mp->n_macs);
Paul Vinciguerraec11b132018-09-24 05:25:00 -07001463 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
John Lo8d00fff2017-08-03 00:35:36 -04001464 ntohl (mp->pid), mp->client_index, n_macs);
1465 int i;
1466 for (i = 0; i < n_macs; i++)
1467 {
1468 vl_api_mac_entry_t *mac = &mp->mac[i];
John Loe23c99e2018-03-13 21:53:18 -04001469 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
John Lo8d00fff2017-08-03 00:35:36 -04001470 i + 1, ntohl (mac->sw_if_index),
John Loe23c99e2018-03-13 21:53:18 -04001471 format_ethernet_address, mac->mac_addr, mac->action);
John Lo8d00fff2017-08-03 00:35:36 -04001472 if (i == 1000)
1473 break;
1474 }
1475}
1476
1477static void
1478vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1479{
1480 /* JSON output not supported */
1481}
1482
Ole Troan01384fe2017-05-12 11:55:35 +02001483#define vl_api_bridge_domain_details_t_endian vl_noop_handler
1484#define vl_api_bridge_domain_details_t_print vl_noop_handler
1485
Damjan Marion7cd468a2016-12-19 23:05:39 +01001486/*
1487 * Special-case: build the bridge domain table, maintain
1488 * the next bd id vbl.
1489 */
1490static void vl_api_bridge_domain_details_t_handler
1491 (vl_api_bridge_domain_details_t * mp)
1492{
1493 vat_main_t *vam = &vat_main;
1494 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ole Troan01384fe2017-05-12 11:55:35 +02001495 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001496
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001497 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1498 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001499
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001500 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001501 ntohl (mp->bd_id), mp->learn, mp->forward,
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001502 mp->flood, ntohl (mp->bvi_sw_if_index),
1503 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001504
1505 if (n_sw_ifs)
Ole Troan01384fe2017-05-12 11:55:35 +02001506 {
1507 vl_api_bridge_domain_sw_if_t *sw_ifs;
1508 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1509 "Interface Name");
1510
1511 sw_ifs = mp->sw_if_details;
1512 for (i = 0; i < n_sw_ifs; i++)
1513 {
1514 u8 *sw_if_name = 0;
1515 u32 sw_if_index;
1516 hash_pair_t *p;
1517
1518 sw_if_index = ntohl (sw_ifs->sw_if_index);
1519
1520 /* *INDENT-OFF* */
1521 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1522 ({
1523 if ((u32) p->value[0] == sw_if_index)
1524 {
1525 sw_if_name = (u8 *)(p->key);
1526 break;
1527 }
1528 }));
1529 /* *INDENT-ON* */
1530 print (vam->ofp, "%7d %3d %s", sw_if_index,
1531 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1532 "sw_if_index not found!");
1533
1534 sw_ifs++;
1535 }
1536 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001537}
1538
1539static void vl_api_bridge_domain_details_t_handler_json
1540 (vl_api_bridge_domain_details_t * mp)
1541{
1542 vat_main_t *vam = &vat_main;
1543 vat_json_node_t *node, *array = NULL;
Ole Troan01384fe2017-05-12 11:55:35 +02001544 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001545
1546 if (VAT_JSON_ARRAY != vam->json_tree.type)
1547 {
1548 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1549 vat_json_init_array (&vam->json_tree);
1550 }
1551 node = vat_json_array_add (&vam->json_tree);
1552
1553 vat_json_init_object (node);
1554 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1555 vat_json_object_add_uint (node, "flood", mp->flood);
1556 vat_json_object_add_uint (node, "forward", mp->forward);
1557 vat_json_object_add_uint (node, "learn", mp->learn);
1558 vat_json_object_add_uint (node, "bvi_sw_if_index",
1559 ntohl (mp->bvi_sw_if_index));
Ole Troan01384fe2017-05-12 11:55:35 +02001560 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001561 array = vat_json_object_add (node, "sw_if");
1562 vat_json_init_array (array);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001563
Damjan Marion7cd468a2016-12-19 23:05:39 +01001564
Damjan Marion7cd468a2016-12-19 23:05:39 +01001565
Ole Troan01384fe2017-05-12 11:55:35 +02001566 if (n_sw_ifs)
1567 {
1568 vl_api_bridge_domain_sw_if_t *sw_ifs;
1569 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001570
Ole Troan01384fe2017-05-12 11:55:35 +02001571 sw_ifs = mp->sw_if_details;
1572 for (i = 0; i < n_sw_ifs; i++)
1573 {
1574 node = vat_json_array_add (array);
1575 vat_json_init_object (node);
1576 vat_json_object_add_uint (node, "sw_if_index",
1577 ntohl (sw_ifs->sw_if_index));
1578 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1579 sw_ifs++;
1580 }
1581 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001582}
1583
1584static void vl_api_control_ping_reply_t_handler
1585 (vl_api_control_ping_reply_t * mp)
1586{
1587 vat_main_t *vam = &vat_main;
1588 i32 retval = ntohl (mp->retval);
1589 if (vam->async_mode)
1590 {
1591 vam->async_errors += (retval < 0);
1592 }
1593 else
1594 {
1595 vam->retval = retval;
1596 vam->result_ready = 1;
1597 }
Florin Coras90a63982017-12-19 04:50:01 -08001598 if (vam->socket_client_main)
1599 vam->socket_client_main->control_pings_outstanding--;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001600}
1601
1602static void vl_api_control_ping_reply_t_handler_json
1603 (vl_api_control_ping_reply_t * mp)
1604{
1605 vat_main_t *vam = &vat_main;
1606 i32 retval = ntohl (mp->retval);
1607
1608 if (VAT_JSON_NONE != vam->json_tree.type)
1609 {
1610 vat_json_print (vam->ofp, &vam->json_tree);
1611 vat_json_free (&vam->json_tree);
1612 vam->json_tree.type = VAT_JSON_NONE;
1613 }
1614 else
1615 {
1616 /* just print [] */
1617 vat_json_init_array (&vam->json_tree);
1618 vat_json_print (vam->ofp, &vam->json_tree);
1619 vam->json_tree.type = VAT_JSON_NONE;
1620 }
1621
1622 vam->retval = retval;
1623 vam->result_ready = 1;
1624}
1625
1626static void
Eyal Barifead6702017-04-04 04:46:32 +03001627 vl_api_bridge_domain_set_mac_age_reply_t_handler
1628 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1629{
1630 vat_main_t *vam = &vat_main;
1631 i32 retval = ntohl (mp->retval);
1632 if (vam->async_mode)
1633 {
1634 vam->async_errors += (retval < 0);
1635 }
1636 else
1637 {
1638 vam->retval = retval;
1639 vam->result_ready = 1;
1640 }
1641}
1642
1643static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1644 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1645{
1646 vat_main_t *vam = &vat_main;
1647 vat_json_node_t node;
1648
1649 vat_json_init_object (&node);
1650 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1651
1652 vat_json_print (vam->ofp, &node);
1653 vat_json_free (&node);
1654
1655 vam->retval = ntohl (mp->retval);
1656 vam->result_ready = 1;
1657}
1658
1659static void
Damjan Marion7cd468a2016-12-19 23:05:39 +01001660vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1661{
1662 vat_main_t *vam = &vat_main;
1663 i32 retval = ntohl (mp->retval);
1664 if (vam->async_mode)
1665 {
1666 vam->async_errors += (retval < 0);
1667 }
1668 else
1669 {
1670 vam->retval = retval;
1671 vam->result_ready = 1;
1672 }
1673}
1674
1675static void vl_api_l2_flags_reply_t_handler_json
1676 (vl_api_l2_flags_reply_t * mp)
1677{
1678 vat_main_t *vam = &vat_main;
1679 vat_json_node_t node;
1680
1681 vat_json_init_object (&node);
1682 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1683 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1684 ntohl (mp->resulting_feature_bitmap));
1685
1686 vat_json_print (vam->ofp, &node);
1687 vat_json_free (&node);
1688
1689 vam->retval = ntohl (mp->retval);
1690 vam->result_ready = 1;
1691}
1692
1693static void vl_api_bridge_flags_reply_t_handler
1694 (vl_api_bridge_flags_reply_t * mp)
1695{
1696 vat_main_t *vam = &vat_main;
1697 i32 retval = ntohl (mp->retval);
1698 if (vam->async_mode)
1699 {
1700 vam->async_errors += (retval < 0);
1701 }
1702 else
1703 {
1704 vam->retval = retval;
1705 vam->result_ready = 1;
1706 }
1707}
1708
1709static void vl_api_bridge_flags_reply_t_handler_json
1710 (vl_api_bridge_flags_reply_t * mp)
1711{
1712 vat_main_t *vam = &vat_main;
1713 vat_json_node_t node;
1714
1715 vat_json_init_object (&node);
1716 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1717 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1718 ntohl (mp->resulting_feature_bitmap));
1719
1720 vat_json_print (vam->ofp, &node);
1721 vat_json_free (&node);
1722
1723 vam->retval = ntohl (mp->retval);
1724 vam->result_ready = 1;
1725}
1726
Damjan Marion8389fb92017-10-13 18:29:53 +02001727static void
1728vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1729{
1730 vat_main_t *vam = &vat_main;
1731 i32 retval = ntohl (mp->retval);
1732 if (vam->async_mode)
1733 {
1734 vam->async_errors += (retval < 0);
1735 }
1736 else
1737 {
1738 vam->retval = retval;
1739 vam->sw_if_index = ntohl (mp->sw_if_index);
1740 vam->result_ready = 1;
1741 }
1742
1743}
1744
1745static void vl_api_tap_create_v2_reply_t_handler_json
1746 (vl_api_tap_create_v2_reply_t * mp)
1747{
1748 vat_main_t *vam = &vat_main;
1749 vat_json_node_t node;
1750
1751 vat_json_init_object (&node);
1752 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1753 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1754
1755 vat_json_print (vam->ofp, &node);
1756 vat_json_free (&node);
1757
1758 vam->retval = ntohl (mp->retval);
1759 vam->result_ready = 1;
1760
1761}
1762
1763static void
1764vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1765{
1766 vat_main_t *vam = &vat_main;
1767 i32 retval = ntohl (mp->retval);
1768 if (vam->async_mode)
1769 {
1770 vam->async_errors += (retval < 0);
1771 }
1772 else
1773 {
1774 vam->retval = retval;
1775 vam->result_ready = 1;
1776 }
1777}
1778
1779static void vl_api_tap_delete_v2_reply_t_handler_json
1780 (vl_api_tap_delete_v2_reply_t * mp)
1781{
1782 vat_main_t *vam = &vat_main;
1783 vat_json_node_t node;
1784
1785 vat_json_init_object (&node);
1786 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1787
1788 vat_json_print (vam->ofp, &node);
1789 vat_json_free (&node);
1790
1791 vam->retval = ntohl (mp->retval);
1792 vam->result_ready = 1;
1793}
1794
Steven9cd2d7a2017-12-20 12:43:01 -08001795static void
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01001796vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1797 mp)
1798{
1799 vat_main_t *vam = &vat_main;
1800 i32 retval = ntohl (mp->retval);
1801 if (vam->async_mode)
1802 {
1803 vam->async_errors += (retval < 0);
1804 }
1805 else
1806 {
1807 vam->retval = retval;
1808 vam->sw_if_index = ntohl (mp->sw_if_index);
1809 vam->result_ready = 1;
1810 }
1811}
1812
1813static void vl_api_virtio_pci_create_reply_t_handler_json
1814 (vl_api_virtio_pci_create_reply_t * mp)
1815{
1816 vat_main_t *vam = &vat_main;
1817 vat_json_node_t node;
1818
1819 vat_json_init_object (&node);
1820 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1821 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1822
1823 vat_json_print (vam->ofp, &node);
1824 vat_json_free (&node);
1825
1826 vam->retval = ntohl (mp->retval);
1827 vam->result_ready = 1;
1828
1829}
1830
1831static void
1832vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1833 mp)
1834{
1835 vat_main_t *vam = &vat_main;
1836 i32 retval = ntohl (mp->retval);
1837 if (vam->async_mode)
1838 {
1839 vam->async_errors += (retval < 0);
1840 }
1841 else
1842 {
1843 vam->retval = retval;
1844 vam->result_ready = 1;
1845 }
1846}
1847
1848static void vl_api_virtio_pci_delete_reply_t_handler_json
1849 (vl_api_virtio_pci_delete_reply_t * mp)
1850{
1851 vat_main_t *vam = &vat_main;
1852 vat_json_node_t node;
1853
1854 vat_json_init_object (&node);
1855 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1856
1857 vat_json_print (vam->ofp, &node);
1858 vat_json_free (&node);
1859
1860 vam->retval = ntohl (mp->retval);
1861 vam->result_ready = 1;
1862}
1863
1864static void
Steven9cd2d7a2017-12-20 12:43:01 -08001865vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1866{
1867 vat_main_t *vam = &vat_main;
1868 i32 retval = ntohl (mp->retval);
1869
1870 if (vam->async_mode)
1871 {
1872 vam->async_errors += (retval < 0);
1873 }
1874 else
1875 {
1876 vam->retval = retval;
1877 vam->sw_if_index = ntohl (mp->sw_if_index);
1878 vam->result_ready = 1;
1879 }
1880}
1881
1882static void vl_api_bond_create_reply_t_handler_json
1883 (vl_api_bond_create_reply_t * mp)
1884{
1885 vat_main_t *vam = &vat_main;
1886 vat_json_node_t node;
1887
1888 vat_json_init_object (&node);
1889 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1890 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1891
1892 vat_json_print (vam->ofp, &node);
1893 vat_json_free (&node);
1894
1895 vam->retval = ntohl (mp->retval);
1896 vam->result_ready = 1;
1897}
1898
1899static void
1900vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1901{
1902 vat_main_t *vam = &vat_main;
1903 i32 retval = ntohl (mp->retval);
1904
1905 if (vam->async_mode)
1906 {
1907 vam->async_errors += (retval < 0);
1908 }
1909 else
1910 {
1911 vam->retval = retval;
1912 vam->result_ready = 1;
1913 }
1914}
1915
1916static void vl_api_bond_delete_reply_t_handler_json
1917 (vl_api_bond_delete_reply_t * mp)
1918{
1919 vat_main_t *vam = &vat_main;
1920 vat_json_node_t node;
1921
1922 vat_json_init_object (&node);
1923 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1924
1925 vat_json_print (vam->ofp, &node);
1926 vat_json_free (&node);
1927
1928 vam->retval = ntohl (mp->retval);
1929 vam->result_ready = 1;
1930}
1931
1932static void
Steven Luong4c4223e2020-07-15 08:44:54 -07001933vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
Steven9cd2d7a2017-12-20 12:43:01 -08001934{
1935 vat_main_t *vam = &vat_main;
1936 i32 retval = ntohl (mp->retval);
1937
1938 if (vam->async_mode)
1939 {
1940 vam->async_errors += (retval < 0);
1941 }
1942 else
1943 {
1944 vam->retval = retval;
1945 vam->result_ready = 1;
1946 }
1947}
1948
Steven Luong4c4223e2020-07-15 08:44:54 -07001949static void vl_api_bond_add_member_reply_t_handler_json
1950 (vl_api_bond_add_member_reply_t * mp)
Steven9cd2d7a2017-12-20 12:43:01 -08001951{
1952 vat_main_t *vam = &vat_main;
1953 vat_json_node_t node;
1954
1955 vat_json_init_object (&node);
1956 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1957
1958 vat_json_print (vam->ofp, &node);
1959 vat_json_free (&node);
1960
1961 vam->retval = ntohl (mp->retval);
1962 vam->result_ready = 1;
1963}
1964
1965static void
Steven Luong4c4223e2020-07-15 08:44:54 -07001966vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
1967 mp)
Steven9cd2d7a2017-12-20 12:43:01 -08001968{
1969 vat_main_t *vam = &vat_main;
1970 i32 retval = ntohl (mp->retval);
1971
1972 if (vam->async_mode)
1973 {
1974 vam->async_errors += (retval < 0);
1975 }
1976 else
1977 {
1978 vam->retval = retval;
1979 vam->result_ready = 1;
1980 }
1981}
1982
Steven Luong4c4223e2020-07-15 08:44:54 -07001983static void vl_api_bond_detach_member_reply_t_handler_json
1984 (vl_api_bond_detach_member_reply_t * mp)
Steven9cd2d7a2017-12-20 12:43:01 -08001985{
1986 vat_main_t *vam = &vat_main;
1987 vat_json_node_t node;
1988
1989 vat_json_init_object (&node);
1990 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1991
1992 vat_json_print (vam->ofp, &node);
1993 vat_json_free (&node);
1994
1995 vam->retval = ntohl (mp->retval);
1996 vam->result_ready = 1;
1997}
1998
Steven Luonga1876b82019-08-20 16:58:00 -07001999static int
2000api_sw_interface_set_bond_weight (vat_main_t * vam)
2001{
2002 unformat_input_t *i = vam->input;
2003 vl_api_sw_interface_set_bond_weight_t *mp;
2004 u32 sw_if_index = ~0;
2005 u32 weight = 0;
2006 u8 weight_enter = 0;
2007 int ret;
2008
2009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2010 {
2011 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2012 ;
2013 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2014 ;
2015 else if (unformat (i, "weight %u", &weight))
2016 weight_enter = 1;
2017 else
2018 break;
2019 }
2020
2021 if (sw_if_index == ~0)
2022 {
2023 errmsg ("missing interface name or sw_if_index");
2024 return -99;
2025 }
2026 if (weight_enter == 0)
2027 {
2028 errmsg ("missing valid weight");
2029 return -99;
2030 }
2031
2032 /* Construct the API message */
2033 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2034 mp->sw_if_index = ntohl (sw_if_index);
2035 mp->weight = ntohl (weight);
2036
2037 S (mp);
2038 W (ret);
2039 return ret;
2040}
2041
Steven Luong4c4223e2020-07-15 08:44:54 -07002042static void vl_api_sw_bond_interface_details_t_handler
2043 (vl_api_sw_bond_interface_details_t * mp)
Steven9cd2d7a2017-12-20 12:43:01 -08002044{
2045 vat_main_t *vam = &vat_main;
2046
2047 print (vam->ofp,
2048 "%-16s %-12d %-12U %-13U %-14u %-14u",
2049 mp->interface_name, ntohl (mp->sw_if_index),
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02002050 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
Steven Luong4c4223e2020-07-15 08:44:54 -07002051 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
Steven9cd2d7a2017-12-20 12:43:01 -08002052}
2053
Steven Luong4c4223e2020-07-15 08:44:54 -07002054static void vl_api_sw_bond_interface_details_t_handler_json
2055 (vl_api_sw_bond_interface_details_t * mp)
Steven9cd2d7a2017-12-20 12:43:01 -08002056{
2057 vat_main_t *vam = &vat_main;
2058 vat_json_node_t *node = NULL;
2059
2060 if (VAT_JSON_ARRAY != vam->json_tree.type)
2061 {
2062 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2063 vat_json_init_array (&vam->json_tree);
2064 }
2065 node = vat_json_array_add (&vam->json_tree);
2066
2067 vat_json_init_object (node);
2068 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2069 vat_json_object_add_string_copy (node, "interface_name",
2070 mp->interface_name);
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02002071 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2072 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
Steven Luong4c4223e2020-07-15 08:44:54 -07002073 vat_json_object_add_uint (node, "active_members",
2074 ntohl (mp->active_members));
2075 vat_json_object_add_uint (node, "members", ntohl (mp->members));
Steven9cd2d7a2017-12-20 12:43:01 -08002076}
2077
2078static int
Steven Luong4c4223e2020-07-15 08:44:54 -07002079api_sw_bond_interface_dump (vat_main_t * vam)
Steven9cd2d7a2017-12-20 12:43:01 -08002080{
Steven Luong4c4223e2020-07-15 08:44:54 -07002081 unformat_input_t *i = vam->input;
2082 vl_api_sw_bond_interface_dump_t *mp;
Steven9cd2d7a2017-12-20 12:43:01 -08002083 vl_api_control_ping_t *mp_ping;
2084 int ret;
Steven Luong4c4223e2020-07-15 08:44:54 -07002085 u32 sw_if_index = ~0;
2086
2087 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2088 {
2089 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2090 ;
2091 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2092 ;
2093 else
2094 break;
2095 }
Steven9cd2d7a2017-12-20 12:43:01 -08002096
2097 print (vam->ofp,
2098 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2099 "interface name", "sw_if_index", "mode", "load balance",
Steven Luong4c4223e2020-07-15 08:44:54 -07002100 "active members", "members");
Steven9cd2d7a2017-12-20 12:43:01 -08002101
2102 /* Get list of bond interfaces */
Steven Luong4c4223e2020-07-15 08:44:54 -07002103 M (SW_BOND_INTERFACE_DUMP, mp);
2104 mp->sw_if_index = ntohl (sw_if_index);
Steven9cd2d7a2017-12-20 12:43:01 -08002105 S (mp);
2106
2107 /* Use a control ping for synchronization */
2108 MPING (CONTROL_PING, mp_ping);
2109 S (mp_ping);
2110
2111 W (ret);
2112 return ret;
2113}
2114
Steven Luong4c4223e2020-07-15 08:44:54 -07002115static void vl_api_sw_member_interface_details_t_handler
2116 (vl_api_sw_member_interface_details_t * mp)
Steven9cd2d7a2017-12-20 12:43:01 -08002117{
2118 vat_main_t *vam = &vat_main;
2119
2120 print (vam->ofp,
Steven Luonga1876b82019-08-20 16:58:00 -07002121 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2122 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2123 ntohl (mp->weight), mp->is_local_numa);
Steven9cd2d7a2017-12-20 12:43:01 -08002124}
2125
Steven Luong4c4223e2020-07-15 08:44:54 -07002126static void vl_api_sw_member_interface_details_t_handler_json
2127 (vl_api_sw_member_interface_details_t * mp)
Steven9cd2d7a2017-12-20 12:43:01 -08002128{
2129 vat_main_t *vam = &vat_main;
2130 vat_json_node_t *node = NULL;
2131
2132 if (VAT_JSON_ARRAY != vam->json_tree.type)
2133 {
2134 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2135 vat_json_init_array (&vam->json_tree);
2136 }
2137 node = vat_json_array_add (&vam->json_tree);
2138
2139 vat_json_init_object (node);
2140 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2141 vat_json_object_add_string_copy (node, "interface_name",
2142 mp->interface_name);
2143 vat_json_object_add_uint (node, "passive", mp->is_passive);
2144 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
Steven Luonga1876b82019-08-20 16:58:00 -07002145 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2146 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
Steven9cd2d7a2017-12-20 12:43:01 -08002147}
2148
2149static int
Steven Luong4c4223e2020-07-15 08:44:54 -07002150api_sw_member_interface_dump (vat_main_t * vam)
Steven9cd2d7a2017-12-20 12:43:01 -08002151{
2152 unformat_input_t *i = vam->input;
Steven Luong4c4223e2020-07-15 08:44:54 -07002153 vl_api_sw_member_interface_dump_t *mp;
Steven9cd2d7a2017-12-20 12:43:01 -08002154 vl_api_control_ping_t *mp_ping;
2155 u32 sw_if_index = ~0;
2156 u8 sw_if_index_set = 0;
2157 int ret;
2158
2159 /* Parse args required to build the message */
2160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2161 {
2162 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2163 sw_if_index_set = 1;
2164 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2165 sw_if_index_set = 1;
2166 else
2167 break;
2168 }
2169
2170 if (sw_if_index_set == 0)
2171 {
2172 errmsg ("missing vpp interface name. ");
2173 return -99;
2174 }
2175
2176 print (vam->ofp,
Steven Luonga1876b82019-08-20 16:58:00 -07002177 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
Steven Luong4c4223e2020-07-15 08:44:54 -07002178 "member interface name", "sw_if_index", "passive", "long_timeout",
Steven Luonga1876b82019-08-20 16:58:00 -07002179 "weight", "local numa");
Steven9cd2d7a2017-12-20 12:43:01 -08002180
2181 /* Get list of bond interfaces */
Steven Luong4c4223e2020-07-15 08:44:54 -07002182 M (SW_MEMBER_INTERFACE_DUMP, mp);
Steven9cd2d7a2017-12-20 12:43:01 -08002183 mp->sw_if_index = ntohl (sw_if_index);
2184 S (mp);
2185
2186 /* Use a control ping for synchronization */
2187 MPING (CONTROL_PING, mp_ping);
2188 S (mp_ping);
2189
2190 W (ret);
2191 return ret;
2192}
2193
Damjan Marion7cd468a2016-12-19 23:05:39 +01002194static void vl_api_mpls_tunnel_add_del_reply_t_handler
2195 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2196{
2197 vat_main_t *vam = &vat_main;
2198 i32 retval = ntohl (mp->retval);
2199 if (vam->async_mode)
2200 {
2201 vam->async_errors += (retval < 0);
2202 }
2203 else
2204 {
2205 vam->retval = retval;
John Lo06fda9c2018-10-03 16:32:44 -04002206 vam->sw_if_index = ntohl (mp->sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002207 vam->result_ready = 1;
2208 }
John Lo06fda9c2018-10-03 16:32:44 -04002209 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002210}
2211
2212static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2213 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2214{
2215 vat_main_t *vam = &vat_main;
2216 vat_json_node_t node;
2217
2218 vat_json_init_object (&node);
2219 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2220 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2221 ntohl (mp->sw_if_index));
2222
2223 vat_json_print (vam->ofp, &node);
2224 vat_json_free (&node);
2225
2226 vam->retval = ntohl (mp->retval);
2227 vam->result_ready = 1;
2228}
2229
2230static void vl_api_l2tpv3_create_tunnel_reply_t_handler
2231 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2232{
2233 vat_main_t *vam = &vat_main;
2234 i32 retval = ntohl (mp->retval);
2235 if (vam->async_mode)
2236 {
2237 vam->async_errors += (retval < 0);
2238 }
2239 else
2240 {
2241 vam->retval = retval;
2242 vam->sw_if_index = ntohl (mp->sw_if_index);
2243 vam->result_ready = 1;
2244 }
2245}
2246
2247static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
2248 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2249{
2250 vat_main_t *vam = &vat_main;
2251 vat_json_node_t node;
2252
2253 vat_json_init_object (&node);
2254 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2255 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2256
2257 vat_json_print (vam->ofp, &node);
2258 vat_json_free (&node);
2259
2260 vam->retval = ntohl (mp->retval);
2261 vam->result_ready = 1;
2262}
2263
Filip Tehlar560274d2017-06-05 13:40:13 +02002264static void vl_api_gpe_add_del_fwd_entry_reply_t_handler
2265 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2266{
2267 vat_main_t *vam = &vat_main;
2268 i32 retval = ntohl (mp->retval);
2269 if (vam->async_mode)
2270 {
2271 vam->async_errors += (retval < 0);
2272 }
2273 else
2274 {
2275 vam->retval = retval;
2276 vam->result_ready = 1;
2277 }
2278}
2279
2280static void vl_api_gpe_add_del_fwd_entry_reply_t_handler_json
2281 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2282{
2283 vat_main_t *vam = &vat_main;
2284 vat_json_node_t node;
2285
2286 vat_json_init_object (&node);
2287 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2288 vat_json_object_add_uint (&node, "fwd_entry_index",
2289 clib_net_to_host_u32 (mp->fwd_entry_index));
2290
2291 vat_json_print (vam->ofp, &node);
2292 vat_json_free (&node);
2293
2294 vam->retval = ntohl (mp->retval);
2295 vam->result_ready = 1;
2296}
Damjan Marion7cd468a2016-12-19 23:05:39 +01002297
Filip Tehlara4980b82017-09-27 14:32:02 +02002298u8 *
2299format_lisp_transport_protocol (u8 * s, va_list * args)
2300{
2301 u32 proto = va_arg (*args, u32);
2302
2303 switch (proto)
2304 {
2305 case 1:
2306 return format (s, "udp");
2307 case 2:
2308 return format (s, "api");
2309 default:
2310 return 0;
2311 }
2312 return 0;
2313}
2314
2315static void vl_api_one_get_transport_protocol_reply_t_handler
2316 (vl_api_one_get_transport_protocol_reply_t * mp)
2317{
2318 vat_main_t *vam = &vat_main;
2319 i32 retval = ntohl (mp->retval);
2320 if (vam->async_mode)
2321 {
2322 vam->async_errors += (retval < 0);
2323 }
2324 else
2325 {
2326 u32 proto = mp->protocol;
2327 print (vam->ofp, "Transport protocol: %U",
2328 format_lisp_transport_protocol, proto);
2329 vam->retval = retval;
2330 vam->result_ready = 1;
2331 }
2332}
2333
2334static void vl_api_one_get_transport_protocol_reply_t_handler_json
2335 (vl_api_one_get_transport_protocol_reply_t * mp)
2336{
2337 vat_main_t *vam = &vat_main;
2338 vat_json_node_t node;
2339 u8 *s;
2340
2341 s = format (0, "%U", format_lisp_transport_protocol, mp->protocol);
2342 vec_add1 (s, 0);
2343
2344 vat_json_init_object (&node);
2345 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2346 vat_json_object_add_string_copy (&node, "transport-protocol", s);
2347
2348 vec_free (s);
2349 vat_json_print (vam->ofp, &node);
2350 vat_json_free (&node);
2351
2352 vam->retval = ntohl (mp->retval);
2353 vam->result_ready = 1;
2354}
2355
Filip Tehlar694396d2017-02-17 14:29:11 +01002356static void vl_api_one_add_del_locator_set_reply_t_handler
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 i32 retval = ntohl (mp->retval);
2361 if (vam->async_mode)
2362 {
2363 vam->async_errors += (retval < 0);
2364 }
2365 else
2366 {
2367 vam->retval = retval;
2368 vam->result_ready = 1;
2369 }
2370}
2371
Filip Tehlar694396d2017-02-17 14:29:11 +01002372static void vl_api_one_add_del_locator_set_reply_t_handler_json
2373 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002374{
2375 vat_main_t *vam = &vat_main;
2376 vat_json_node_t node;
2377
2378 vat_json_init_object (&node);
2379 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2380 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
2381
2382 vat_json_print (vam->ofp, &node);
2383 vat_json_free (&node);
2384
2385 vam->retval = ntohl (mp->retval);
2386 vam->result_ready = 1;
2387}
2388
2389static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2390 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2391{
2392 vat_main_t *vam = &vat_main;
2393 i32 retval = ntohl (mp->retval);
2394 if (vam->async_mode)
2395 {
2396 vam->async_errors += (retval < 0);
2397 }
2398 else
2399 {
2400 vam->retval = retval;
2401 vam->sw_if_index = ntohl (mp->sw_if_index);
2402 vam->result_ready = 1;
2403 }
Dave Barachf72212e2018-01-11 10:25:07 -05002404 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002405}
2406
2407static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2408 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2409{
2410 vat_main_t *vam = &vat_main;
2411 vat_json_node_t node;
2412
2413 vat_json_init_object (&node);
2414 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2415 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2416
2417 vat_json_print (vam->ofp, &node);
2418 vat_json_free (&node);
2419
2420 vam->retval = ntohl (mp->retval);
2421 vam->result_ready = 1;
2422}
2423
eyal bariaf86a482018-04-17 11:20:27 +03002424static void vl_api_vxlan_offload_rx_reply_t_handler
2425 (vl_api_vxlan_offload_rx_reply_t * mp)
2426{
2427 vat_main_t *vam = &vat_main;
2428 i32 retval = ntohl (mp->retval);
2429 if (vam->async_mode)
2430 {
2431 vam->async_errors += (retval < 0);
2432 }
2433 else
2434 {
2435 vam->retval = retval;
2436 vam->result_ready = 1;
2437 }
2438}
2439
2440static void vl_api_vxlan_offload_rx_reply_t_handler_json
2441 (vl_api_vxlan_offload_rx_reply_t * mp)
2442{
2443 vat_main_t *vam = &vat_main;
2444 vat_json_node_t node;
2445
2446 vat_json_init_object (&node);
2447 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2448
2449 vat_json_print (vam->ofp, &node);
2450 vat_json_free (&node);
2451
2452 vam->retval = ntohl (mp->retval);
2453 vam->result_ready = 1;
2454}
2455
Marco Varleseb598f1d2017-09-19 14:25:28 +02002456static void vl_api_geneve_add_del_tunnel_reply_t_handler
2457 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2458{
2459 vat_main_t *vam = &vat_main;
2460 i32 retval = ntohl (mp->retval);
2461 if (vam->async_mode)
2462 {
2463 vam->async_errors += (retval < 0);
2464 }
2465 else
2466 {
2467 vam->retval = retval;
2468 vam->sw_if_index = ntohl (mp->sw_if_index);
2469 vam->result_ready = 1;
2470 }
2471}
2472
2473static void vl_api_geneve_add_del_tunnel_reply_t_handler_json
2474 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2475{
2476 vat_main_t *vam = &vat_main;
2477 vat_json_node_t node;
2478
2479 vat_json_init_object (&node);
2480 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2481 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2482
2483 vat_json_print (vam->ofp, &node);
2484 vat_json_free (&node);
2485
2486 vam->retval = ntohl (mp->retval);
2487 vam->result_ready = 1;
2488}
2489
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002490static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2491 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2492{
2493 vat_main_t *vam = &vat_main;
2494 i32 retval = ntohl (mp->retval);
2495 if (vam->async_mode)
2496 {
2497 vam->async_errors += (retval < 0);
2498 }
2499 else
2500 {
2501 vam->retval = retval;
2502 vam->sw_if_index = ntohl (mp->sw_if_index);
2503 vam->result_ready = 1;
2504 }
Dave Barachf72212e2018-01-11 10:25:07 -05002505 vam->regenerate_interface_table = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002506}
2507
2508static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2509 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2510{
2511 vat_main_t *vam = &vat_main;
2512 vat_json_node_t node;
2513
2514 vat_json_init_object (&node);
2515 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2516 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2517
2518 vat_json_print (vam->ofp, &node);
2519 vat_json_free (&node);
2520
2521 vam->retval = ntohl (mp->retval);
2522 vam->result_ready = 1;
2523}
2524
Neale Ranns5a8844b2019-04-16 07:15:35 +00002525static void vl_api_gre_tunnel_add_del_reply_t_handler
2526 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002527{
2528 vat_main_t *vam = &vat_main;
2529 i32 retval = ntohl (mp->retval);
2530 if (vam->async_mode)
2531 {
2532 vam->async_errors += (retval < 0);
2533 }
2534 else
2535 {
2536 vam->retval = retval;
2537 vam->sw_if_index = ntohl (mp->sw_if_index);
2538 vam->result_ready = 1;
2539 }
2540}
2541
Neale Ranns5a8844b2019-04-16 07:15:35 +00002542static void vl_api_gre_tunnel_add_del_reply_t_handler_json
2543 (vl_api_gre_tunnel_add_del_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002544{
2545 vat_main_t *vam = &vat_main;
2546 vat_json_node_t node;
2547
2548 vat_json_init_object (&node);
2549 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2550 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2551
2552 vat_json_print (vam->ofp, &node);
2553 vat_json_free (&node);
2554
2555 vam->retval = ntohl (mp->retval);
2556 vam->result_ready = 1;
2557}
2558
2559static void vl_api_create_vhost_user_if_reply_t_handler
2560 (vl_api_create_vhost_user_if_reply_t * mp)
2561{
2562 vat_main_t *vam = &vat_main;
2563 i32 retval = ntohl (mp->retval);
2564 if (vam->async_mode)
2565 {
2566 vam->async_errors += (retval < 0);
2567 }
2568 else
2569 {
2570 vam->retval = retval;
2571 vam->sw_if_index = ntohl (mp->sw_if_index);
2572 vam->result_ready = 1;
2573 }
Dave Barachf72212e2018-01-11 10:25:07 -05002574 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002575}
2576
2577static void vl_api_create_vhost_user_if_reply_t_handler_json
2578 (vl_api_create_vhost_user_if_reply_t * mp)
2579{
2580 vat_main_t *vam = &vat_main;
2581 vat_json_node_t node;
2582
2583 vat_json_init_object (&node);
2584 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2585 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2586
2587 vat_json_print (vam->ofp, &node);
2588 vat_json_free (&node);
2589
2590 vam->retval = ntohl (mp->retval);
2591 vam->result_ready = 1;
2592}
2593
2594static void vl_api_ip_address_details_t_handler
2595 (vl_api_ip_address_details_t * mp)
2596{
2597 vat_main_t *vam = &vat_main;
2598 static ip_address_details_t empty_ip_address_details = { {0} };
2599 ip_address_details_t *address = NULL;
2600 ip_details_t *current_ip_details = NULL;
2601 ip_details_t *details = NULL;
2602
2603 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2604
2605 if (!details || vam->current_sw_if_index >= vec_len (details)
2606 || !details[vam->current_sw_if_index].present)
2607 {
2608 errmsg ("ip address details arrived but not stored");
2609 errmsg ("ip_dump should be called first");
2610 return;
2611 }
2612
2613 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2614
2615#define addresses (current_ip_details->addr)
2616
2617 vec_validate_init_empty (addresses, vec_len (addresses),
2618 empty_ip_address_details);
2619
2620 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2621
Neale Ranns097fa662018-05-01 05:17:55 -07002622 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
Paul Vinciguerraab055082019-06-06 14:07:55 -04002623 address->prefix_length = mp->prefix.len;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002624#undef addresses
2625}
2626
2627static void vl_api_ip_address_details_t_handler_json
2628 (vl_api_ip_address_details_t * mp)
2629{
2630 vat_main_t *vam = &vat_main;
2631 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002632
2633 if (VAT_JSON_ARRAY != vam->json_tree.type)
2634 {
2635 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2636 vat_json_init_array (&vam->json_tree);
2637 }
2638 node = vat_json_array_add (&vam->json_tree);
2639
2640 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -07002641 vat_json_object_add_prefix (node, &mp->prefix);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002642}
2643
2644static void
2645vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2646{
2647 vat_main_t *vam = &vat_main;
2648 static ip_details_t empty_ip_details = { 0 };
2649 ip_details_t *ip = NULL;
2650 u32 sw_if_index = ~0;
2651
2652 sw_if_index = ntohl (mp->sw_if_index);
2653
2654 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2655 sw_if_index, empty_ip_details);
2656
2657 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2658 sw_if_index);
2659
2660 ip->present = 1;
2661}
2662
2663static void
2664vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2665{
2666 vat_main_t *vam = &vat_main;
2667
2668 if (VAT_JSON_ARRAY != vam->json_tree.type)
2669 {
2670 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2671 vat_json_init_array (&vam->json_tree);
2672 }
2673 vat_json_array_add_uint (&vam->json_tree,
2674 clib_net_to_host_u32 (mp->sw_if_index));
2675}
2676
Damjan Marion7cd468a2016-12-19 23:05:39 +01002677static void vl_api_get_first_msg_id_reply_t_handler
2678 (vl_api_get_first_msg_id_reply_t * mp)
2679{
2680 vat_main_t *vam = &vat_main;
2681 i32 retval = ntohl (mp->retval);
2682
2683 if (vam->async_mode)
2684 {
2685 vam->async_errors += (retval < 0);
2686 }
2687 else
2688 {
2689 vam->retval = retval;
2690 vam->result_ready = 1;
2691 }
2692 if (retval >= 0)
2693 {
2694 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2695 }
2696}
2697
2698static void vl_api_get_first_msg_id_reply_t_handler_json
2699 (vl_api_get_first_msg_id_reply_t * mp)
2700{
2701 vat_main_t *vam = &vat_main;
2702 vat_json_node_t node;
2703
2704 vat_json_init_object (&node);
2705 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2706 vat_json_object_add_uint (&node, "first_msg_id",
2707 (uint) ntohs (mp->first_msg_id));
2708
2709 vat_json_print (vam->ofp, &node);
2710 vat_json_free (&node);
2711
2712 vam->retval = ntohl (mp->retval);
2713 vam->result_ready = 1;
2714}
2715
2716static void vl_api_get_node_graph_reply_t_handler
2717 (vl_api_get_node_graph_reply_t * mp)
2718{
2719 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002720 i32 retval = ntohl (mp->retval);
2721 u8 *pvt_copy, *reply;
2722 void *oldheap;
2723 vlib_node_t *node;
2724 int i;
2725
2726 if (vam->async_mode)
2727 {
2728 vam->async_errors += (retval < 0);
2729 }
2730 else
2731 {
2732 vam->retval = retval;
2733 vam->result_ready = 1;
2734 }
2735
2736 /* "Should never happen..." */
2737 if (retval != 0)
2738 return;
2739
Damjan Marion7bee80c2017-04-26 15:32:12 +02002740 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002741 pvt_copy = vec_dup (reply);
2742
2743 /* Toss the shared-memory original... */
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002744 oldheap = vl_msg_push_heap ();
Damjan Marion7cd468a2016-12-19 23:05:39 +01002745
2746 vec_free (reply);
2747
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002748 vl_msg_pop_heap (oldheap);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002749
2750 if (vam->graph_nodes)
2751 {
2752 hash_free (vam->graph_node_index_by_name);
2753
Dave Barach1ddbc012018-06-13 09:26:05 -04002754 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002755 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002756 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002757 vec_free (node->name);
2758 vec_free (node->next_nodes);
2759 vec_free (node);
2760 }
Dave Barach1ddbc012018-06-13 09:26:05 -04002761 vec_free (vam->graph_nodes[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002762 vec_free (vam->graph_nodes);
2763 }
2764
2765 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2766 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2767 vec_free (pvt_copy);
2768
Dave Barach1ddbc012018-06-13 09:26:05 -04002769 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002770 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002771 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002772 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2773 }
2774}
2775
2776static void vl_api_get_node_graph_reply_t_handler_json
2777 (vl_api_get_node_graph_reply_t * mp)
2778{
2779 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002780 void *oldheap;
2781 vat_json_node_t node;
2782 u8 *reply;
2783
2784 /* $$$$ make this real? */
2785 vat_json_init_object (&node);
2786 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2787 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2788
Damjan Marion7bee80c2017-04-26 15:32:12 +02002789 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002790
2791 /* Toss the shared-memory original... */
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002792 oldheap = vl_msg_push_heap ();
Damjan Marion7cd468a2016-12-19 23:05:39 +01002793
2794 vec_free (reply);
2795
Nathan Skrzypczak0aa40132019-11-25 16:29:38 +01002796 vl_msg_pop_heap (oldheap);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002797
2798 vat_json_print (vam->ofp, &node);
2799 vat_json_free (&node);
2800
2801 vam->retval = ntohl (mp->retval);
2802 vam->result_ready = 1;
2803}
2804
2805static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002806vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002807{
2808 vat_main_t *vam = &vat_main;
2809 u8 *s = 0;
2810
2811 if (mp->local)
2812 {
2813 s = format (s, "%=16d%=16d%=16d",
2814 ntohl (mp->sw_if_index), mp->priority, mp->weight);
2815 }
2816 else
2817 {
2818 s = format (s, "%=16U%=16d%=16d",
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002819 format_ip46_address,
Damjan Marion7cd468a2016-12-19 23:05:39 +01002820 mp->ip_address, mp->priority, mp->weight);
2821 }
2822
2823 print (vam->ofp, "%v", s);
2824 vec_free (s);
2825}
2826
2827static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002828vl_api_one_locator_details_t_handler_json (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002829{
2830 vat_main_t *vam = &vat_main;
2831 vat_json_node_t *node = NULL;
2832 struct in6_addr ip6;
2833 struct in_addr ip4;
2834
2835 if (VAT_JSON_ARRAY != vam->json_tree.type)
2836 {
2837 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2838 vat_json_init_array (&vam->json_tree);
2839 }
2840 node = vat_json_array_add (&vam->json_tree);
2841 vat_json_init_object (node);
2842
2843 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2844 vat_json_object_add_uint (node, "priority", mp->priority);
2845 vat_json_object_add_uint (node, "weight", mp->weight);
2846
2847 if (mp->local)
2848 vat_json_object_add_uint (node, "sw_if_index",
2849 clib_net_to_host_u32 (mp->sw_if_index));
2850 else
2851 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002852 if (mp->ip_address.af)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002853 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002854 clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +01002855 vat_json_object_add_ip6 (node, "address", ip6);
2856 }
2857 else
2858 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002859 clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +01002860 vat_json_object_add_ip4 (node, "address", ip4);
2861 }
2862 }
2863}
2864
2865static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002866vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
2867 mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002868{
2869 vat_main_t *vam = &vat_main;
2870 u8 *ls_name = 0;
2871
2872 ls_name = format (0, "%s", mp->ls_name);
2873
2874 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
2875 ls_name);
2876 vec_free (ls_name);
2877}
2878
2879static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002880 vl_api_one_locator_set_details_t_handler_json
2881 (vl_api_one_locator_set_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002882{
2883 vat_main_t *vam = &vat_main;
2884 vat_json_node_t *node = 0;
2885 u8 *ls_name = 0;
2886
2887 ls_name = format (0, "%s", mp->ls_name);
2888 vec_add1 (ls_name, 0);
2889
2890 if (VAT_JSON_ARRAY != vam->json_tree.type)
2891 {
2892 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2893 vat_json_init_array (&vam->json_tree);
2894 }
2895 node = vat_json_array_add (&vam->json_tree);
2896
2897 vat_json_init_object (node);
2898 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2899 vat_json_object_add_uint (node, "ls_index",
2900 clib_net_to_host_u32 (mp->ls_index));
2901 vec_free (ls_name);
2902}
2903
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002904typedef struct
2905{
2906 u32 spi;
2907 u8 si;
2908} __attribute__ ((__packed__)) lisp_nsh_api_t;
2909
2910uword
2911unformat_nsh_address (unformat_input_t * input, va_list * args)
2912{
2913 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
2914 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
2915}
2916
Florin Coras9b72b152020-05-28 18:01:26 +00002917static u8 *
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002918format_nsh_address_vat (u8 * s, va_list * args)
2919{
2920 nsh_t *a = va_arg (*args, nsh_t *);
2921 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
2922}
2923
Damjan Marion7cd468a2016-12-19 23:05:39 +01002924static u8 *
2925format_lisp_flat_eid (u8 * s, va_list * args)
2926{
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002927 vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002928
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002929 switch (eid->type)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002930 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002931 case EID_TYPE_API_PREFIX:
2932 if (eid->address.prefix.address.af)
2933 return format (s, "%U/%d", format_ip6_address,
2934 eid->address.prefix.address.un.ip6,
2935 eid->address.prefix.len);
2936 return format (s, "%U/%d", format_ip4_address,
2937 eid->address.prefix.address.un.ip4,
2938 eid->address.prefix.len);
2939 case EID_TYPE_API_MAC:
2940 return format (s, "%U", format_ethernet_address, eid->address.mac);
2941 case EID_TYPE_API_NSH:
2942 return format (s, "%U", format_nsh_address_vat, eid->address.nsh);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002943 }
2944 return 0;
2945}
2946
2947static u8 *
2948format_lisp_eid_vat (u8 * s, va_list * args)
2949{
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002950 vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *);
2951 vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *);
2952 u8 is_src_dst = (u8) va_arg (*args, int);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002953
2954 if (is_src_dst)
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002955 s = format (s, "%U|", format_lisp_flat_eid, seid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002956
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002957 s = format (s, "%U", format_lisp_flat_eid, deid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002958
2959 return s;
2960}
2961
2962static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002963vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002964{
2965 vat_main_t *vam = &vat_main;
2966 u8 *s = 0, *eid = 0;
2967
2968 if (~0 == mp->locator_set_index)
2969 s = format (0, "action: %d", mp->action);
2970 else
2971 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2972
2973 eid = format (0, "%U", format_lisp_eid_vat,
Florin Corasf3c1e4b2020-05-29 16:18:57 +00002974 &mp->deid, &mp->seid, mp->is_src_dst);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002975 vec_add1 (eid, 0);
2976
2977 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
2978 clib_net_to_host_u32 (mp->vni),
2979 eid,
2980 mp->is_local ? "local" : "remote",
2981 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
Jakub Grajciar58db6e12020-01-30 13:26:43 +01002982 clib_net_to_host_u16 (mp->key.id), mp->key.key);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002983
2984 vec_free (s);
2985 vec_free (eid);
2986}
2987
2988static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002989vl_api_one_eid_table_details_t_handler_json (vl_api_one_eid_table_details_t
2990 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002991{
2992 vat_main_t *vam = &vat_main;
2993 vat_json_node_t *node = 0;
2994 u8 *eid = 0;
2995
2996 if (VAT_JSON_ARRAY != vam->json_tree.type)
2997 {
2998 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2999 vat_json_init_array (&vam->json_tree);
3000 }
3001 node = vat_json_array_add (&vam->json_tree);
3002
3003 vat_json_init_object (node);
3004 if (~0 == mp->locator_set_index)
3005 vat_json_object_add_uint (node, "action", mp->action);
3006 else
3007 vat_json_object_add_uint (node, "locator_set_index",
3008 clib_net_to_host_u32 (mp->locator_set_index));
3009
3010 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003011 if (mp->deid.type == 3)
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003012 {
3013 vat_json_node_t *nsh_json = vat_json_object_add (node, "eid");
3014 vat_json_init_object (nsh_json);
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003015 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) & mp->deid.address.nsh;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003016 vat_json_object_add_uint (nsh_json, "spi",
3017 clib_net_to_host_u32 (nsh->spi));
3018 vat_json_object_add_uint (nsh_json, "si", nsh->si);
3019 }
3020 else
3021 {
3022 eid = format (0, "%U", format_lisp_eid_vat,
Florin Corasf3c1e4b2020-05-29 16:18:57 +00003023 &mp->deid, &mp->seid, mp->is_src_dst);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003024 vec_add1 (eid, 0);
3025 vat_json_object_add_string_copy (node, "eid", eid);
3026 vec_free (eid);
3027 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003028 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3029 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
3030 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
3031
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003032 if (mp->key.id)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003033 {
3034 vat_json_object_add_uint (node, "key_id",
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003035 clib_net_to_host_u16 (mp->key.id));
3036 vat_json_object_add_string_copy (node, "key", mp->key.key);
Damjan Marion7cd468a2016-12-19 23:05:39 +01003037 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003038}
3039
3040static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003041vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
3042{
3043 vat_main_t *vam = &vat_main;
3044 u8 *seid = 0, *deid = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003045 ip46_address_t lloc, rloc;
Filip Tehlar4868ff62017-03-09 16:48:39 +01003046
Florin Corasf3c1e4b2020-05-29 16:18:57 +00003047 deid = format (0, "%U", format_lisp_eid_vat, &mp->deid, 0, 0);
Filip Tehlar4868ff62017-03-09 16:48:39 +01003048
Florin Corasf3c1e4b2020-05-29 16:18:57 +00003049 seid = format (0, "%U", format_lisp_eid_vat, &mp->seid, 0, 0);
Filip Tehlar4868ff62017-03-09 16:48:39 +01003050
3051 vec_add1 (deid, 0);
3052 vec_add1 (seid, 0);
3053
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003054 if (mp->lloc.af)
3055 {
3056 clib_memcpy (&lloc.ip6, mp->lloc.un.ip6, 16);
3057 clib_memcpy (&rloc.ip6, mp->rloc.un.ip6, 16);
3058 }
Filip Tehlar4868ff62017-03-09 16:48:39 +01003059 else
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003060 {
3061 clib_memcpy (&lloc.ip4, mp->lloc.un.ip4, 4);
3062 clib_memcpy (&rloc.ip4, mp->rloc.un.ip4, 4);
3063 }
Filip Tehlar4868ff62017-03-09 16:48:39 +01003064
3065
3066 print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
3067 clib_net_to_host_u32 (mp->vni),
3068 seid, deid,
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003069 format_ip46_address, lloc,
3070 format_ip46_address, rloc,
Filip Tehlar4868ff62017-03-09 16:48:39 +01003071 clib_net_to_host_u32 (mp->pkt_count),
3072 clib_net_to_host_u32 (mp->bytes));
3073
3074 vec_free (deid);
3075 vec_free (seid);
3076}
3077
3078static void
3079vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp)
3080{
3081 struct in6_addr ip6;
3082 struct in_addr ip4;
3083 vat_main_t *vam = &vat_main;
3084 vat_json_node_t *node = 0;
3085 u8 *deid = 0, *seid = 0;
3086
3087 if (VAT_JSON_ARRAY != vam->json_tree.type)
3088 {
3089 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3090 vat_json_init_array (&vam->json_tree);
3091 }
3092 node = vat_json_array_add (&vam->json_tree);
3093
3094 vat_json_init_object (node);
Paul Vinciguerra353535b2020-05-29 19:01:18 -04003095 deid = format (0, "%U", format_lisp_eid_vat, &mp->deid, 0, 0);
Filip Tehlar4868ff62017-03-09 16:48:39 +01003096
Paul Vinciguerra353535b2020-05-29 19:01:18 -04003097 seid = format (0, "%U", format_lisp_eid_vat, &mp->seid, 0, 0);
Filip Tehlar4868ff62017-03-09 16:48:39 +01003098
3099 vec_add1 (deid, 0);
3100 vec_add1 (seid, 0);
3101
3102 vat_json_object_add_string_copy (node, "seid", seid);
3103 vat_json_object_add_string_copy (node, "deid", deid);
3104 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3105
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003106 if (mp->lloc.af)
Filip Tehlar4868ff62017-03-09 16:48:39 +01003107 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003108 clib_memcpy (&ip6, mp->lloc.un.ip6, sizeof (ip6));
3109 vat_json_object_add_ip6 (node, "lloc", ip6);
3110 clib_memcpy (&ip6, mp->rloc.un.ip6, sizeof (ip6));
3111 vat_json_object_add_ip6 (node, "rloc", ip6);
3112
Filip Tehlar4868ff62017-03-09 16:48:39 +01003113 }
3114 else
3115 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003116 clib_memcpy (&ip4, mp->lloc.un.ip4, sizeof (ip4));
3117 vat_json_object_add_ip4 (node, "lloc", ip4);
3118 clib_memcpy (&ip4, mp->rloc.un.ip4, sizeof (ip4));
3119 vat_json_object_add_ip4 (node, "rloc", ip4);
Filip Tehlar4868ff62017-03-09 16:48:39 +01003120 }
3121 vat_json_object_add_uint (node, "pkt_count",
3122 clib_net_to_host_u32 (mp->pkt_count));
3123 vat_json_object_add_uint (node, "bytes", clib_net_to_host_u32 (mp->bytes));
3124
3125 vec_free (deid);
3126 vec_free (seid);
3127}
3128
3129static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003130 vl_api_one_eid_table_map_details_t_handler
3131 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003132{
3133 vat_main_t *vam = &vat_main;
3134
3135 u8 *line = format (0, "%=10d%=10d",
3136 clib_net_to_host_u32 (mp->vni),
3137 clib_net_to_host_u32 (mp->dp_table));
3138 print (vam->ofp, "%v", line);
3139 vec_free (line);
3140}
3141
3142static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003143 vl_api_one_eid_table_map_details_t_handler_json
3144 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003145{
3146 vat_main_t *vam = &vat_main;
3147 vat_json_node_t *node = NULL;
3148
3149 if (VAT_JSON_ARRAY != vam->json_tree.type)
3150 {
3151 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3152 vat_json_init_array (&vam->json_tree);
3153 }
3154 node = vat_json_array_add (&vam->json_tree);
3155 vat_json_init_object (node);
3156 vat_json_object_add_uint (node, "dp_table",
3157 clib_net_to_host_u32 (mp->dp_table));
3158 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3159}
3160
3161static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003162 vl_api_one_eid_table_vni_details_t_handler
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
3167 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
3168 print (vam->ofp, "%v", line);
3169 vec_free (line);
3170}
3171
3172static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003173 vl_api_one_eid_table_vni_details_t_handler_json
3174 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003175{
3176 vat_main_t *vam = &vat_main;
3177 vat_json_node_t *node = NULL;
3178
3179 if (VAT_JSON_ARRAY != vam->json_tree.type)
3180 {
3181 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3182 vat_json_init_array (&vam->json_tree);
3183 }
3184 node = vat_json_array_add (&vam->json_tree);
3185 vat_json_init_object (node);
3186 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3187}
3188
Damjan Marion7cd468a2016-12-19 23:05:39 +01003189static void
Filip Tehlar7048ff12017-07-27 08:09:14 +02003190 vl_api_show_one_map_register_fallback_threshold_reply_t_handler
3191 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3192{
3193 vat_main_t *vam = &vat_main;
3194 int retval = clib_net_to_host_u32 (mp->retval);
3195
3196 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3197 print (vam->ofp, "fallback threshold value: %d", mp->value);
3198
3199 vam->retval = retval;
3200 vam->result_ready = 1;
3201}
3202
3203static void
3204 vl_api_show_one_map_register_fallback_threshold_reply_t_handler_json
3205 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3206{
3207 vat_main_t *vam = &vat_main;
3208 vat_json_node_t _node, *node = &_node;
3209 int retval = clib_net_to_host_u32 (mp->retval);
3210
3211 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3212 vat_json_init_object (node);
3213 vat_json_object_add_uint (node, "value", mp->value);
3214
3215 vat_json_print (vam->ofp, node);
3216 vat_json_free (node);
3217
3218 vam->retval = retval;
3219 vam->result_ready = 1;
3220}
3221
3222static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003223 vl_api_show_one_map_register_state_reply_t_handler
3224 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003225{
3226 vat_main_t *vam = &vat_main;
3227 int retval = clib_net_to_host_u32 (mp->retval);
3228
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003229 print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
Damjan Marion7cd468a2016-12-19 23:05:39 +01003230
3231 vam->retval = retval;
3232 vam->result_ready = 1;
3233}
3234
3235static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003236 vl_api_show_one_map_register_state_reply_t_handler_json
3237 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003238{
3239 vat_main_t *vam = &vat_main;
3240 vat_json_node_t _node, *node = &_node;
3241 int retval = clib_net_to_host_u32 (mp->retval);
3242
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003243 u8 *s = format (0, "%s", mp->is_enable ? "enabled" : "disabled");
Damjan Marion7cd468a2016-12-19 23:05:39 +01003244
3245 vat_json_init_object (node);
3246 vat_json_object_add_string_copy (node, "state", s);
3247
3248 vat_json_print (vam->ofp, node);
3249 vat_json_free (node);
3250
3251 vam->retval = retval;
3252 vam->result_ready = 1;
3253 vec_free (s);
3254}
3255
3256static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003257 vl_api_show_one_rloc_probe_state_reply_t_handler
3258 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003259{
3260 vat_main_t *vam = &vat_main;
3261 int retval = clib_net_to_host_u32 (mp->retval);
3262
3263 if (retval)
3264 goto end;
3265
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003266 print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
Damjan Marion7cd468a2016-12-19 23:05:39 +01003267end:
3268 vam->retval = retval;
3269 vam->result_ready = 1;
3270}
3271
3272static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003273 vl_api_show_one_rloc_probe_state_reply_t_handler_json
3274 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003275{
3276 vat_main_t *vam = &vat_main;
3277 vat_json_node_t _node, *node = &_node;
3278 int retval = clib_net_to_host_u32 (mp->retval);
3279
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003280 u8 *s = format (0, "%s", mp->is_enable ? "enabled" : "disabled");
Damjan Marion7cd468a2016-12-19 23:05:39 +01003281 vat_json_init_object (node);
3282 vat_json_object_add_string_copy (node, "state", s);
3283
3284 vat_json_print (vam->ofp, node);
3285 vat_json_free (node);
3286
3287 vam->retval = retval;
3288 vam->result_ready = 1;
3289 vec_free (s);
3290}
3291
3292static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003293 vl_api_show_one_stats_enable_disable_reply_t_handler
3294 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3295{
3296 vat_main_t *vam = &vat_main;
3297 int retval = clib_net_to_host_u32 (mp->retval);
3298
3299 if (retval)
3300 goto end;
3301
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003302 print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar4868ff62017-03-09 16:48:39 +01003303end:
3304 vam->retval = retval;
3305 vam->result_ready = 1;
3306}
3307
3308static void
3309 vl_api_show_one_stats_enable_disable_reply_t_handler_json
3310 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3311{
3312 vat_main_t *vam = &vat_main;
3313 vat_json_node_t _node, *node = &_node;
3314 int retval = clib_net_to_host_u32 (mp->retval);
3315
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003316 u8 *s = format (0, "%s", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar4868ff62017-03-09 16:48:39 +01003317 vat_json_init_object (node);
3318 vat_json_object_add_string_copy (node, "state", s);
3319
3320 vat_json_print (vam->ofp, node);
3321 vat_json_free (node);
3322
3323 vam->retval = retval;
3324 vam->result_ready = 1;
3325 vec_free (s);
3326}
3327
3328static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003329api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003330{
3331 e->dp_table = clib_net_to_host_u32 (e->dp_table);
3332 e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003333 e->vni = clib_net_to_host_u32 (e->vni);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003334}
3335
3336static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003337 gpe_fwd_entries_get_reply_t_net_to_host
3338 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003339{
3340 u32 i;
3341
3342 mp->count = clib_net_to_host_u32 (mp->count);
3343 for (i = 0; i < mp->count; i++)
3344 {
Filip Tehlar82786c42017-02-20 15:20:37 +01003345 api_gpe_fwd_entry_net_to_host (&mp->entries[i]);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003346 }
3347}
3348
Filip Tehlar3e7b56932017-02-21 18:28:34 +01003349static u8 *
3350format_gpe_encap_mode (u8 * s, va_list * args)
3351{
3352 u32 mode = va_arg (*args, u32);
3353
3354 switch (mode)
3355 {
3356 case 0:
3357 return format (s, "lisp");
3358 case 1:
3359 return format (s, "vxlan");
3360 }
3361 return 0;
3362}
3363
3364static void
3365 vl_api_gpe_get_encap_mode_reply_t_handler
3366 (vl_api_gpe_get_encap_mode_reply_t * mp)
3367{
3368 vat_main_t *vam = &vat_main;
3369
3370 print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode);
3371 vam->retval = ntohl (mp->retval);
3372 vam->result_ready = 1;
3373}
3374
3375static void
3376 vl_api_gpe_get_encap_mode_reply_t_handler_json
3377 (vl_api_gpe_get_encap_mode_reply_t * mp)
3378{
3379 vat_main_t *vam = &vat_main;
3380 vat_json_node_t node;
3381
3382 u8 *encap_mode = format (0, "%U", format_gpe_encap_mode, mp->encap_mode);
3383 vec_add1 (encap_mode, 0);
3384
3385 vat_json_init_object (&node);
3386 vat_json_object_add_string_copy (&node, "gpe_mode", encap_mode);
3387
3388 vec_free (encap_mode);
3389 vat_json_print (vam->ofp, &node);
3390 vat_json_free (&node);
3391
3392 vam->retval = ntohl (mp->retval);
3393 vam->result_ready = 1;
3394}
3395
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003396static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003397 vl_api_gpe_fwd_entry_path_details_t_handler
3398 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003399{
3400 vat_main_t *vam = &vat_main;
3401 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3402
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003403 if (mp->lcl_loc.addr.af)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003404 format_ip_address_fcn = format_ip6_address;
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003405 else
3406 format_ip_address_fcn = format_ip4_address;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003407
3408 print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight,
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003409 format_ip_address_fcn, &mp->lcl_loc.addr.un,
3410 format_ip_address_fcn, &mp->rmt_loc.addr.un);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003411}
3412
3413static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003414lisp_fill_locator_node (vat_json_node_t * n, vl_api_gpe_locator_t * loc)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003415{
3416 struct in6_addr ip6;
3417 struct in_addr ip4;
3418
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003419 if (loc->addr.af)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003420 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003421 clib_memcpy (&ip6, loc->addr.un.ip6, sizeof (ip6));
3422 vat_json_object_add_ip6 (n, "address", ip6);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003423 }
3424 else
3425 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003426 clib_memcpy (&ip4, loc->addr.un.ip4, sizeof (ip4));
3427 vat_json_object_add_ip4 (n, "address", ip4);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003428 }
3429 vat_json_object_add_uint (n, "weight", loc->weight);
3430}
3431
3432static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003433 vl_api_gpe_fwd_entry_path_details_t_handler_json
3434 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003435{
3436 vat_main_t *vam = &vat_main;
3437 vat_json_node_t *node = NULL;
3438 vat_json_node_t *loc_node;
3439
3440 if (VAT_JSON_ARRAY != vam->json_tree.type)
3441 {
3442 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3443 vat_json_init_array (&vam->json_tree);
3444 }
3445 node = vat_json_array_add (&vam->json_tree);
3446 vat_json_init_object (node);
3447
3448 loc_node = vat_json_object_add (node, "local_locator");
3449 vat_json_init_object (loc_node);
3450 lisp_fill_locator_node (loc_node, &mp->lcl_loc);
3451
3452 loc_node = vat_json_object_add (node, "remote_locator");
3453 vat_json_init_object (loc_node);
3454 lisp_fill_locator_node (loc_node, &mp->rmt_loc);
3455}
3456
3457static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003458 vl_api_gpe_fwd_entries_get_reply_t_handler
3459 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003460{
3461 vat_main_t *vam = &vat_main;
3462 u32 i;
3463 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003464 vl_api_gpe_fwd_entry_t *e;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003465
3466 if (retval)
3467 goto end;
3468
Filip Tehlar82786c42017-02-20 15:20:37 +01003469 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003470
3471 for (i = 0; i < mp->count; i++)
3472 {
3473 e = &mp->entries[i];
3474 print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table,
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003475 format_lisp_flat_eid, e->leid, format_lisp_flat_eid, e->reid);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003476 }
3477
3478end:
3479 vam->retval = retval;
3480 vam->result_ready = 1;
3481}
3482
3483static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003484 vl_api_gpe_fwd_entries_get_reply_t_handler_json
3485 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003486{
3487 u8 *s = 0;
3488 vat_main_t *vam = &vat_main;
3489 vat_json_node_t *e = 0, root;
3490 u32 i;
3491 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003492 vl_api_gpe_fwd_entry_t *fwd;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003493
3494 if (retval)
3495 goto end;
3496
Filip Tehlar82786c42017-02-20 15:20:37 +01003497 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003498 vat_json_init_array (&root);
3499
3500 for (i = 0; i < mp->count; i++)
3501 {
3502 e = vat_json_array_add (&root);
3503 fwd = &mp->entries[i];
3504
3505 vat_json_init_object (e);
3506 vat_json_object_add_int (e, "fwd_entry_index", fwd->fwd_entry_index);
3507 vat_json_object_add_int (e, "dp_table", fwd->dp_table);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003508 vat_json_object_add_int (e, "vni", fwd->vni);
3509 vat_json_object_add_int (e, "action", fwd->action);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003510
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003511 s = format (0, "%U", format_lisp_flat_eid, fwd->leid);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003512 vec_add1 (s, 0);
3513 vat_json_object_add_string_copy (e, "leid", s);
3514 vec_free (s);
3515
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003516 s = format (0, "%U", format_lisp_flat_eid, fwd->reid);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003517 vec_add1 (s, 0);
3518 vat_json_object_add_string_copy (e, "reid", s);
3519 vec_free (s);
3520 }
3521
3522 vat_json_print (vam->ofp, &root);
3523 vat_json_free (&root);
3524
3525end:
3526 vam->retval = retval;
3527 vam->result_ready = 1;
3528}
3529
3530static void
Filip Tehlarb4243aa2017-06-14 14:39:42 +02003531 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler
3532 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3533{
3534 vat_main_t *vam = &vat_main;
3535 u32 i, n;
3536 int retval = clib_net_to_host_u32 (mp->retval);
3537 vl_api_gpe_native_fwd_rpath_t *r;
3538
3539 if (retval)
3540 goto end;
3541
3542 n = clib_net_to_host_u32 (mp->count);
3543
3544 for (i = 0; i < n; i++)
3545 {
3546 r = &mp->entries[i];
3547 print (vam->ofp, "fib_index: %d sw_if_index %d nh %U",
3548 clib_net_to_host_u32 (r->fib_index),
3549 clib_net_to_host_u32 (r->nh_sw_if_index),
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003550 r->nh_addr.af ? format_ip6_address : format_ip4_address,
3551 r->nh_addr.un);
Filip Tehlarb4243aa2017-06-14 14:39:42 +02003552 }
3553
3554end:
3555 vam->retval = retval;
3556 vam->result_ready = 1;
3557}
3558
3559static void
3560 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler_json
3561 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3562{
3563 vat_main_t *vam = &vat_main;
3564 vat_json_node_t root, *e;
3565 u32 i, n;
3566 int retval = clib_net_to_host_u32 (mp->retval);
3567 vl_api_gpe_native_fwd_rpath_t *r;
3568 u8 *s;
3569
3570 if (retval)
3571 goto end;
3572
3573 n = clib_net_to_host_u32 (mp->count);
3574 vat_json_init_array (&root);
3575
3576 for (i = 0; i < n; i++)
3577 {
3578 e = vat_json_array_add (&root);
3579 vat_json_init_object (e);
3580 r = &mp->entries[i];
3581 s =
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003582 format (0, "%U",
3583 r->nh_addr.af ? format_ip6_address : format_ip4_address,
3584 r->nh_addr.un);
Filip Tehlarb4243aa2017-06-14 14:39:42 +02003585 vec_add1 (s, 0);
3586 vat_json_object_add_string_copy (e, "ip4", s);
3587 vec_free (s);
3588
3589 vat_json_object_add_uint (e, "fib_index",
3590 clib_net_to_host_u32 (r->fib_index));
3591 vat_json_object_add_uint (e, "nh_sw_if_index",
3592 clib_net_to_host_u32 (r->nh_sw_if_index));
3593 }
3594
3595 vat_json_print (vam->ofp, &root);
3596 vat_json_free (&root);
3597
3598end:
3599 vam->retval = retval;
3600 vam->result_ready = 1;
3601}
3602
3603static void
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003604 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler
3605 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3606{
3607 vat_main_t *vam = &vat_main;
3608 u32 i, n;
3609 int retval = clib_net_to_host_u32 (mp->retval);
3610
3611 if (retval)
3612 goto end;
3613
3614 n = clib_net_to_host_u32 (mp->count);
3615
3616 for (i = 0; i < n; i++)
3617 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i]));
3618
3619end:
3620 vam->retval = retval;
3621 vam->result_ready = 1;
3622}
3623
3624static void
3625 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler_json
3626 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3627{
3628 vat_main_t *vam = &vat_main;
3629 vat_json_node_t root;
3630 u32 i, n;
3631 int retval = clib_net_to_host_u32 (mp->retval);
3632
3633 if (retval)
3634 goto end;
3635
3636 n = clib_net_to_host_u32 (mp->count);
3637 vat_json_init_array (&root);
3638
3639 for (i = 0; i < n; i++)
3640 vat_json_array_add_uint (&root, clib_net_to_host_u32 (mp->vnis[i]));
3641
3642 vat_json_print (vam->ofp, &root);
3643 vat_json_free (&root);
3644
3645end:
3646 vam->retval = retval;
3647 vam->result_ready = 1;
3648}
3649
3650static void
Filip Tehlar05879992017-09-05 15:46:09 +02003651 vl_api_one_ndp_entries_get_reply_t_handler
3652 (vl_api_one_ndp_entries_get_reply_t * mp)
3653{
3654 vat_main_t *vam = &vat_main;
3655 u32 i, n;
3656 int retval = clib_net_to_host_u32 (mp->retval);
3657
3658 if (retval)
3659 goto end;
3660
3661 n = clib_net_to_host_u32 (mp->count);
3662
3663 for (i = 0; i < n; i++)
3664 print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
3665 format_ethernet_address, mp->entries[i].mac);
3666
3667end:
3668 vam->retval = retval;
3669 vam->result_ready = 1;
3670}
3671
3672static void
3673 vl_api_one_ndp_entries_get_reply_t_handler_json
3674 (vl_api_one_ndp_entries_get_reply_t * mp)
3675{
3676 u8 *s = 0;
3677 vat_main_t *vam = &vat_main;
3678 vat_json_node_t *e = 0, root;
3679 u32 i, n;
3680 int retval = clib_net_to_host_u32 (mp->retval);
3681 vl_api_one_ndp_entry_t *arp_entry;
3682
3683 if (retval)
3684 goto end;
3685
3686 n = clib_net_to_host_u32 (mp->count);
3687 vat_json_init_array (&root);
3688
3689 for (i = 0; i < n; i++)
3690 {
3691 e = vat_json_array_add (&root);
3692 arp_entry = &mp->entries[i];
3693
3694 vat_json_init_object (e);
3695 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3696 vec_add1 (s, 0);
3697
3698 vat_json_object_add_string_copy (e, "mac", s);
3699 vec_free (s);
3700
3701 s = format (0, "%U", format_ip6_address, &arp_entry->ip6);
3702 vec_add1 (s, 0);
3703 vat_json_object_add_string_copy (e, "ip6", s);
3704 vec_free (s);
3705 }
3706
3707 vat_json_print (vam->ofp, &root);
3708 vat_json_free (&root);
3709
3710end:
3711 vam->retval = retval;
3712 vam->result_ready = 1;
3713}
3714
3715static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003716 vl_api_one_l2_arp_entries_get_reply_t_handler
3717 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3718{
3719 vat_main_t *vam = &vat_main;
3720 u32 i, n;
3721 int retval = clib_net_to_host_u32 (mp->retval);
3722
3723 if (retval)
3724 goto end;
3725
3726 n = clib_net_to_host_u32 (mp->count);
3727
3728 for (i = 0; i < n; i++)
3729 print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
3730 format_ethernet_address, mp->entries[i].mac);
3731
3732end:
3733 vam->retval = retval;
3734 vam->result_ready = 1;
3735}
3736
3737static void
3738 vl_api_one_l2_arp_entries_get_reply_t_handler_json
3739 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3740{
3741 u8 *s = 0;
3742 vat_main_t *vam = &vat_main;
3743 vat_json_node_t *e = 0, root;
3744 u32 i, n;
3745 int retval = clib_net_to_host_u32 (mp->retval);
3746 vl_api_one_l2_arp_entry_t *arp_entry;
3747
3748 if (retval)
3749 goto end;
3750
3751 n = clib_net_to_host_u32 (mp->count);
3752 vat_json_init_array (&root);
3753
3754 for (i = 0; i < n; i++)
3755 {
3756 e = vat_json_array_add (&root);
3757 arp_entry = &mp->entries[i];
3758
3759 vat_json_init_object (e);
3760 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3761 vec_add1 (s, 0);
3762
3763 vat_json_object_add_string_copy (e, "mac", s);
3764 vec_free (s);
3765
3766 s = format (0, "%U", format_ip4_address, &arp_entry->ip4);
3767 vec_add1 (s, 0);
3768 vat_json_object_add_string_copy (e, "ip4", s);
3769 vec_free (s);
3770 }
3771
3772 vat_json_print (vam->ofp, &root);
3773 vat_json_free (&root);
3774
3775end:
3776 vam->retval = retval;
3777 vam->result_ready = 1;
3778}
3779
3780static void
Filip Tehlar05879992017-09-05 15:46:09 +02003781vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
3782{
3783 vat_main_t *vam = &vat_main;
3784 u32 i, n;
3785 int retval = clib_net_to_host_u32 (mp->retval);
3786
3787 if (retval)
3788 goto end;
3789
3790 n = clib_net_to_host_u32 (mp->count);
3791
3792 for (i = 0; i < n; i++)
3793 {
3794 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3795 }
3796
3797end:
3798 vam->retval = retval;
3799 vam->result_ready = 1;
3800}
3801
3802static void
3803 vl_api_one_ndp_bd_get_reply_t_handler_json
3804 (vl_api_one_ndp_bd_get_reply_t * mp)
3805{
3806 vat_main_t *vam = &vat_main;
3807 vat_json_node_t root;
3808 u32 i, n;
3809 int retval = clib_net_to_host_u32 (mp->retval);
3810
3811 if (retval)
3812 goto end;
3813
3814 n = clib_net_to_host_u32 (mp->count);
3815 vat_json_init_array (&root);
3816
3817 for (i = 0; i < n; i++)
3818 {
3819 vat_json_array_add_uint (&root,
3820 clib_net_to_host_u32 (mp->bridge_domains[i]));
3821 }
3822
3823 vat_json_print (vam->ofp, &root);
3824 vat_json_free (&root);
3825
3826end:
3827 vam->retval = retval;
3828 vam->result_ready = 1;
3829}
3830
3831static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003832 vl_api_one_l2_arp_bd_get_reply_t_handler
3833 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3834{
3835 vat_main_t *vam = &vat_main;
3836 u32 i, n;
3837 int retval = clib_net_to_host_u32 (mp->retval);
3838
3839 if (retval)
3840 goto end;
3841
3842 n = clib_net_to_host_u32 (mp->count);
3843
3844 for (i = 0; i < n; i++)
3845 {
3846 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3847 }
3848
3849end:
3850 vam->retval = retval;
3851 vam->result_ready = 1;
3852}
3853
3854static void
3855 vl_api_one_l2_arp_bd_get_reply_t_handler_json
3856 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3857{
3858 vat_main_t *vam = &vat_main;
3859 vat_json_node_t root;
3860 u32 i, n;
3861 int retval = clib_net_to_host_u32 (mp->retval);
3862
3863 if (retval)
3864 goto end;
3865
3866 n = clib_net_to_host_u32 (mp->count);
3867 vat_json_init_array (&root);
3868
3869 for (i = 0; i < n; i++)
3870 {
3871 vat_json_array_add_uint (&root,
3872 clib_net_to_host_u32 (mp->bridge_domains[i]));
3873 }
3874
3875 vat_json_print (vam->ofp, &root);
3876 vat_json_free (&root);
3877
3878end:
3879 vam->retval = retval;
3880 vam->result_ready = 1;
3881}
3882
3883static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003884 vl_api_one_adjacencies_get_reply_t_handler
3885 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003886{
3887 vat_main_t *vam = &vat_main;
3888 u32 i, n;
3889 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003890 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003891
3892 if (retval)
3893 goto end;
3894
3895 n = clib_net_to_host_u32 (mp->count);
3896
3897 for (i = 0; i < n; i++)
3898 {
3899 a = &mp->adjacencies[i];
3900 print (vam->ofp, "%U %40U",
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003901 format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01003902 }
3903
3904end:
3905 vam->retval = retval;
3906 vam->result_ready = 1;
3907}
3908
3909static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003910 vl_api_one_adjacencies_get_reply_t_handler_json
3911 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003912{
3913 u8 *s = 0;
3914 vat_main_t *vam = &vat_main;
3915 vat_json_node_t *e = 0, root;
3916 u32 i, n;
3917 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003918 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003919
3920 if (retval)
3921 goto end;
3922
3923 n = clib_net_to_host_u32 (mp->count);
3924 vat_json_init_array (&root);
3925
3926 for (i = 0; i < n; i++)
3927 {
3928 e = vat_json_array_add (&root);
3929 a = &mp->adjacencies[i];
3930
3931 vat_json_init_object (e);
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003932 s = format (0, "%U", format_lisp_flat_eid, a->leid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01003933 vec_add1 (s, 0);
3934 vat_json_object_add_string_copy (e, "leid", s);
3935 vec_free (s);
3936
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003937 s = format (0, "%U", format_lisp_flat_eid, a->reid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01003938 vec_add1 (s, 0);
3939 vat_json_object_add_string_copy (e, "reid", s);
3940 vec_free (s);
3941 }
3942
3943 vat_json_print (vam->ofp, &root);
3944 vat_json_free (&root);
3945
3946end:
3947 vam->retval = retval;
3948 vam->result_ready = 1;
3949}
3950
3951static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003952vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003953{
3954 vat_main_t *vam = &vat_main;
3955
3956 print (vam->ofp, "%=20U",
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003957 mp->ip_address.af ? format_ip6_address : format_ip4_address,
3958 mp->ip_address.un);
Damjan Marion7cd468a2016-12-19 23:05:39 +01003959}
3960
3961static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003962 vl_api_one_map_server_details_t_handler_json
3963 (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003964{
3965 vat_main_t *vam = &vat_main;
3966 vat_json_node_t *node = NULL;
3967 struct in6_addr ip6;
3968 struct in_addr ip4;
3969
3970 if (VAT_JSON_ARRAY != vam->json_tree.type)
3971 {
3972 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3973 vat_json_init_array (&vam->json_tree);
3974 }
3975 node = vat_json_array_add (&vam->json_tree);
3976
3977 vat_json_init_object (node);
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003978 if (mp->ip_address.af)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003979 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003980 clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +01003981 vat_json_object_add_ip6 (node, "map-server", ip6);
3982 }
3983 else
3984 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003985 clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +01003986 vat_json_object_add_ip4 (node, "map-server", ip4);
3987 }
3988}
3989
3990static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003991vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
3992 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003993{
3994 vat_main_t *vam = &vat_main;
3995
3996 print (vam->ofp, "%=20U",
Jakub Grajciar58db6e12020-01-30 13:26:43 +01003997 mp->ip_address.af ? format_ip6_address : format_ip4_address,
3998 mp->ip_address.un);
Damjan Marion7cd468a2016-12-19 23:05:39 +01003999}
4000
4001static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004002 vl_api_one_map_resolver_details_t_handler_json
4003 (vl_api_one_map_resolver_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004004{
4005 vat_main_t *vam = &vat_main;
4006 vat_json_node_t *node = NULL;
4007 struct in6_addr ip6;
4008 struct in_addr ip4;
4009
4010 if (VAT_JSON_ARRAY != vam->json_tree.type)
4011 {
4012 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4013 vat_json_init_array (&vam->json_tree);
4014 }
4015 node = vat_json_array_add (&vam->json_tree);
4016
4017 vat_json_init_object (node);
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004018 if (mp->ip_address.af)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004019 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004020 clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +01004021 vat_json_object_add_ip6 (node, "map resolver", ip6);
4022 }
4023 else
4024 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004025 clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +01004026 vat_json_object_add_ip4 (node, "map resolver", ip4);
4027 }
4028}
4029
4030static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004031vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004032{
4033 vat_main_t *vam = &vat_main;
4034 i32 retval = ntohl (mp->retval);
4035
4036 if (0 <= retval)
4037 {
4038 print (vam->ofp, "feature: %s\ngpe: %s",
4039 mp->feature_status ? "enabled" : "disabled",
4040 mp->gpe_status ? "enabled" : "disabled");
4041 }
4042
4043 vam->retval = retval;
4044 vam->result_ready = 1;
4045}
4046
4047static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004048 vl_api_show_one_status_reply_t_handler_json
4049 (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004050{
4051 vat_main_t *vam = &vat_main;
4052 vat_json_node_t node;
4053 u8 *gpe_status = NULL;
4054 u8 *feature_status = NULL;
4055
4056 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
4057 feature_status = format (0, "%s",
4058 mp->feature_status ? "enabled" : "disabled");
4059 vec_add1 (gpe_status, 0);
4060 vec_add1 (feature_status, 0);
4061
4062 vat_json_init_object (&node);
4063 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
4064 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
4065
4066 vec_free (gpe_status);
4067 vec_free (feature_status);
4068
4069 vat_json_print (vam->ofp, &node);
4070 vat_json_free (&node);
4071
4072 vam->retval = ntohl (mp->retval);
4073 vam->result_ready = 1;
4074}
4075
4076static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004077 vl_api_one_get_map_request_itr_rlocs_reply_t_handler
4078 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004079{
4080 vat_main_t *vam = &vat_main;
4081 i32 retval = ntohl (mp->retval);
4082
4083 if (retval >= 0)
4084 {
4085 print (vam->ofp, "%=20s", mp->locator_set_name);
4086 }
4087
4088 vam->retval = retval;
4089 vam->result_ready = 1;
4090}
4091
4092static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004093 vl_api_one_get_map_request_itr_rlocs_reply_t_handler_json
4094 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004095{
4096 vat_main_t *vam = &vat_main;
4097 vat_json_node_t *node = NULL;
4098
4099 if (VAT_JSON_ARRAY != vam->json_tree.type)
4100 {
4101 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4102 vat_json_init_array (&vam->json_tree);
4103 }
4104 node = vat_json_array_add (&vam->json_tree);
4105
4106 vat_json_init_object (node);
4107 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
4108
4109 vat_json_print (vam->ofp, node);
4110 vat_json_free (node);
4111
4112 vam->retval = ntohl (mp->retval);
4113 vam->result_ready = 1;
4114}
4115
4116static u8 *
4117format_lisp_map_request_mode (u8 * s, va_list * args)
4118{
4119 u32 mode = va_arg (*args, u32);
4120
4121 switch (mode)
4122 {
4123 case 0:
4124 return format (0, "dst-only");
4125 case 1:
4126 return format (0, "src-dst");
4127 }
4128 return 0;
4129}
4130
4131static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004132 vl_api_show_one_map_request_mode_reply_t_handler
4133 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004134{
4135 vat_main_t *vam = &vat_main;
4136 i32 retval = ntohl (mp->retval);
4137
4138 if (0 <= retval)
4139 {
4140 u32 mode = mp->mode;
4141 print (vam->ofp, "map_request_mode: %U",
4142 format_lisp_map_request_mode, mode);
4143 }
4144
4145 vam->retval = retval;
4146 vam->result_ready = 1;
4147}
4148
4149static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004150 vl_api_show_one_map_request_mode_reply_t_handler_json
4151 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004152{
4153 vat_main_t *vam = &vat_main;
4154 vat_json_node_t node;
4155 u8 *s = 0;
4156 u32 mode;
4157
4158 mode = mp->mode;
4159 s = format (0, "%U", format_lisp_map_request_mode, mode);
4160 vec_add1 (s, 0);
4161
4162 vat_json_init_object (&node);
4163 vat_json_object_add_string_copy (&node, "map_request_mode", s);
4164 vat_json_print (vam->ofp, &node);
4165 vat_json_free (&node);
4166
4167 vec_free (s);
4168 vam->retval = ntohl (mp->retval);
4169 vam->result_ready = 1;
4170}
4171
4172static void
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004173 vl_api_one_show_xtr_mode_reply_t_handler
4174 (vl_api_one_show_xtr_mode_reply_t * mp)
4175{
4176 vat_main_t *vam = &vat_main;
4177 i32 retval = ntohl (mp->retval);
4178
4179 if (0 <= retval)
4180 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004181 print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004182 }
4183
4184 vam->retval = retval;
4185 vam->result_ready = 1;
4186}
4187
4188static void
4189 vl_api_one_show_xtr_mode_reply_t_handler_json
4190 (vl_api_one_show_xtr_mode_reply_t * mp)
4191{
4192 vat_main_t *vam = &vat_main;
4193 vat_json_node_t node;
4194 u8 *status = 0;
4195
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004196 status = format (0, "%s", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004197 vec_add1 (status, 0);
4198
4199 vat_json_init_object (&node);
4200 vat_json_object_add_string_copy (&node, "status", status);
4201
4202 vec_free (status);
4203
4204 vat_json_print (vam->ofp, &node);
4205 vat_json_free (&node);
4206
4207 vam->retval = ntohl (mp->retval);
4208 vam->result_ready = 1;
4209}
4210
4211static void
4212 vl_api_one_show_pitr_mode_reply_t_handler
4213 (vl_api_one_show_pitr_mode_reply_t * mp)
4214{
4215 vat_main_t *vam = &vat_main;
4216 i32 retval = ntohl (mp->retval);
4217
4218 if (0 <= retval)
4219 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004220 print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004221 }
4222
4223 vam->retval = retval;
4224 vam->result_ready = 1;
4225}
4226
4227static void
4228 vl_api_one_show_pitr_mode_reply_t_handler_json
4229 (vl_api_one_show_pitr_mode_reply_t * mp)
4230{
4231 vat_main_t *vam = &vat_main;
4232 vat_json_node_t node;
4233 u8 *status = 0;
4234
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004235 status = format (0, "%s", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004236 vec_add1 (status, 0);
4237
4238 vat_json_init_object (&node);
4239 vat_json_object_add_string_copy (&node, "status", status);
4240
4241 vec_free (status);
4242
4243 vat_json_print (vam->ofp, &node);
4244 vat_json_free (&node);
4245
4246 vam->retval = ntohl (mp->retval);
4247 vam->result_ready = 1;
4248}
4249
4250static void
4251 vl_api_one_show_petr_mode_reply_t_handler
4252 (vl_api_one_show_petr_mode_reply_t * mp)
4253{
4254 vat_main_t *vam = &vat_main;
4255 i32 retval = ntohl (mp->retval);
4256
4257 if (0 <= retval)
4258 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004259 print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004260 }
4261
4262 vam->retval = retval;
4263 vam->result_ready = 1;
4264}
4265
4266static void
4267 vl_api_one_show_petr_mode_reply_t_handler_json
4268 (vl_api_one_show_petr_mode_reply_t * mp)
4269{
4270 vat_main_t *vam = &vat_main;
4271 vat_json_node_t node;
4272 u8 *status = 0;
4273
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004274 status = format (0, "%s", mp->is_enable ? "enabled" : "disabled");
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004275 vec_add1 (status, 0);
4276
4277 vat_json_init_object (&node);
4278 vat_json_object_add_string_copy (&node, "status", status);
4279
4280 vec_free (status);
4281
4282 vat_json_print (vam->ofp, &node);
4283 vat_json_free (&node);
4284
4285 vam->retval = ntohl (mp->retval);
4286 vam->result_ready = 1;
4287}
4288
4289static void
Filip Tehlar67a99f82017-03-10 13:18:02 +01004290 vl_api_show_one_use_petr_reply_t_handler
4291 (vl_api_show_one_use_petr_reply_t * mp)
4292{
4293 vat_main_t *vam = &vat_main;
4294 i32 retval = ntohl (mp->retval);
4295
4296 if (0 <= retval)
4297 {
4298 print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
4299 if (mp->status)
4300 {
4301 print (vam->ofp, "Proxy-ETR address; %U",
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004302 mp->ip_address.af ? format_ip6_address : format_ip4_address,
4303 mp->ip_address.un);
Filip Tehlar67a99f82017-03-10 13:18:02 +01004304 }
4305 }
4306
4307 vam->retval = retval;
4308 vam->result_ready = 1;
4309}
4310
4311static void
4312 vl_api_show_one_use_petr_reply_t_handler_json
4313 (vl_api_show_one_use_petr_reply_t * mp)
4314{
4315 vat_main_t *vam = &vat_main;
4316 vat_json_node_t node;
4317 u8 *status = 0;
4318 struct in_addr ip4;
4319 struct in6_addr ip6;
4320
4321 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4322 vec_add1 (status, 0);
4323
4324 vat_json_init_object (&node);
4325 vat_json_object_add_string_copy (&node, "status", status);
4326 if (mp->status)
4327 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004328 if (mp->ip_address.af)
Filip Tehlar67a99f82017-03-10 13:18:02 +01004329 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004330 clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6));
Filip Tehlar67a99f82017-03-10 13:18:02 +01004331 vat_json_object_add_ip6 (&node, "address", ip6);
4332 }
4333 else
4334 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01004335 clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4));
Filip Tehlar67a99f82017-03-10 13:18:02 +01004336 vat_json_object_add_ip4 (&node, "address", ip4);
4337 }
4338 }
4339
4340 vec_free (status);
4341
4342 vat_json_print (vam->ofp, &node);
4343 vat_json_free (&node);
4344
4345 vam->retval = ntohl (mp->retval);
4346 vam->result_ready = 1;
4347}
4348
4349static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02004350 vl_api_show_one_nsh_mapping_reply_t_handler
4351 (vl_api_show_one_nsh_mapping_reply_t * mp)
4352{
4353 vat_main_t *vam = &vat_main;
4354 i32 retval = ntohl (mp->retval);
4355
4356 if (0 <= retval)
4357 {
4358 print (vam->ofp, "%-20s%-16s",
4359 mp->is_set ? "set" : "not-set",
4360 mp->is_set ? (char *) mp->locator_set_name : "");
4361 }
4362
4363 vam->retval = retval;
4364 vam->result_ready = 1;
4365}
4366
4367static void
4368 vl_api_show_one_nsh_mapping_reply_t_handler_json
4369 (vl_api_show_one_nsh_mapping_reply_t * mp)
4370{
4371 vat_main_t *vam = &vat_main;
4372 vat_json_node_t node;
4373 u8 *status = 0;
4374
4375 status = format (0, "%s", mp->is_set ? "yes" : "no");
4376 vec_add1 (status, 0);
4377
4378 vat_json_init_object (&node);
4379 vat_json_object_add_string_copy (&node, "is_set", status);
4380 if (mp->is_set)
4381 {
4382 vat_json_object_add_string_copy (&node, "locator_set",
4383 mp->locator_set_name);
4384 }
4385
4386 vec_free (status);
4387
4388 vat_json_print (vam->ofp, &node);
4389 vat_json_free (&node);
4390
4391 vam->retval = ntohl (mp->retval);
4392 vam->result_ready = 1;
4393}
4394
4395static void
Filip Tehlar1e553a02017-08-02 12:45:07 +02004396 vl_api_show_one_map_register_ttl_reply_t_handler
4397 (vl_api_show_one_map_register_ttl_reply_t * mp)
4398{
4399 vat_main_t *vam = &vat_main;
4400 i32 retval = ntohl (mp->retval);
4401
4402 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4403
4404 if (0 <= retval)
4405 {
4406 print (vam->ofp, "ttl: %u", mp->ttl);
4407 }
4408
4409 vam->retval = retval;
4410 vam->result_ready = 1;
4411}
4412
4413static void
4414 vl_api_show_one_map_register_ttl_reply_t_handler_json
4415 (vl_api_show_one_map_register_ttl_reply_t * mp)
4416{
4417 vat_main_t *vam = &vat_main;
4418 vat_json_node_t node;
4419
4420 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4421 vat_json_init_object (&node);
4422 vat_json_object_add_uint (&node, "ttl", mp->ttl);
4423
4424 vat_json_print (vam->ofp, &node);
4425 vat_json_free (&node);
4426
4427 vam->retval = ntohl (mp->retval);
4428 vam->result_ready = 1;
4429}
4430
4431static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004432vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004433{
4434 vat_main_t *vam = &vat_main;
4435 i32 retval = ntohl (mp->retval);
4436
4437 if (0 <= retval)
4438 {
4439 print (vam->ofp, "%-20s%-16s",
4440 mp->status ? "enabled" : "disabled",
4441 mp->status ? (char *) mp->locator_set_name : "");
4442 }
4443
4444 vam->retval = retval;
4445 vam->result_ready = 1;
4446}
4447
4448static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004449vl_api_show_one_pitr_reply_t_handler_json (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004450{
4451 vat_main_t *vam = &vat_main;
4452 vat_json_node_t node;
4453 u8 *status = 0;
4454
4455 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4456 vec_add1 (status, 0);
4457
4458 vat_json_init_object (&node);
4459 vat_json_object_add_string_copy (&node, "status", status);
4460 if (mp->status)
4461 {
4462 vat_json_object_add_string_copy (&node, "locator_set",
4463 mp->locator_set_name);
4464 }
4465
4466 vec_free (status);
4467
4468 vat_json_print (vam->ofp, &node);
4469 vat_json_free (&node);
4470
4471 vam->retval = ntohl (mp->retval);
4472 vam->result_ready = 1;
4473}
4474
4475static u8 *
4476format_policer_type (u8 * s, va_list * va)
4477{
4478 u32 i = va_arg (*va, u32);
4479
4480 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
4481 s = format (s, "1r2c");
4482 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
4483 s = format (s, "1r3c");
4484 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
4485 s = format (s, "2r3c-2698");
4486 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
4487 s = format (s, "2r3c-4115");
4488 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
4489 s = format (s, "2r3c-mef5cf1");
4490 else
4491 s = format (s, "ILLEGAL");
4492 return s;
4493}
4494
4495static u8 *
4496format_policer_rate_type (u8 * s, va_list * va)
4497{
4498 u32 i = va_arg (*va, u32);
4499
4500 if (i == SSE2_QOS_RATE_KBPS)
4501 s = format (s, "kbps");
4502 else if (i == SSE2_QOS_RATE_PPS)
4503 s = format (s, "pps");
4504 else
4505 s = format (s, "ILLEGAL");
4506 return s;
4507}
4508
4509static u8 *
4510format_policer_round_type (u8 * s, va_list * va)
4511{
4512 u32 i = va_arg (*va, u32);
4513
4514 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
4515 s = format (s, "closest");
4516 else if (i == SSE2_QOS_ROUND_TO_UP)
4517 s = format (s, "up");
4518 else if (i == SSE2_QOS_ROUND_TO_DOWN)
4519 s = format (s, "down");
4520 else
4521 s = format (s, "ILLEGAL");
4522 return s;
4523}
4524
4525static u8 *
4526format_policer_action_type (u8 * s, va_list * va)
4527{
4528 u32 i = va_arg (*va, u32);
4529
4530 if (i == SSE2_QOS_ACTION_DROP)
4531 s = format (s, "drop");
4532 else if (i == SSE2_QOS_ACTION_TRANSMIT)
4533 s = format (s, "transmit");
4534 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4535 s = format (s, "mark-and-transmit");
4536 else
4537 s = format (s, "ILLEGAL");
4538 return s;
4539}
4540
4541static u8 *
4542format_dscp (u8 * s, va_list * va)
4543{
4544 u32 i = va_arg (*va, u32);
4545 char *t = 0;
4546
4547 switch (i)
4548 {
4549#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
4550 foreach_vnet_dscp
4551#undef _
4552 default:
4553 return format (s, "ILLEGAL");
4554 }
4555 s = format (s, "%s", t);
4556 return s;
4557}
4558
4559static void
4560vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
4561{
4562 vat_main_t *vam = &vat_main;
4563 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
4564
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004565 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
4566 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004567 else
4568 conform_dscp_str = format (0, "");
4569
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004570 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
4571 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004572 else
4573 exceed_dscp_str = format (0, "");
4574
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004575 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
4576 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004577 else
4578 violate_dscp_str = format (0, "");
4579
4580 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
4581 "rate type %U, round type %U, %s rate, %s color-aware, "
4582 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
4583 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
4584 "conform action %U%s, exceed action %U%s, violate action %U%s",
4585 mp->name,
4586 format_policer_type, mp->type,
4587 ntohl (mp->cir),
4588 ntohl (mp->eir),
4589 clib_net_to_host_u64 (mp->cb),
4590 clib_net_to_host_u64 (mp->eb),
4591 format_policer_rate_type, mp->rate_type,
4592 format_policer_round_type, mp->round_type,
4593 mp->single_rate ? "single" : "dual",
4594 mp->color_aware ? "is" : "not",
4595 ntohl (mp->cir_tokens_per_period),
4596 ntohl (mp->pir_tokens_per_period),
4597 ntohl (mp->scale),
4598 ntohl (mp->current_limit),
4599 ntohl (mp->current_bucket),
4600 ntohl (mp->extended_limit),
4601 ntohl (mp->extended_bucket),
4602 clib_net_to_host_u64 (mp->last_update_time),
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004603 format_policer_action_type, mp->conform_action.type,
Damjan Marion7cd468a2016-12-19 23:05:39 +01004604 conform_dscp_str,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004605 format_policer_action_type, mp->exceed_action.type,
Damjan Marion7cd468a2016-12-19 23:05:39 +01004606 exceed_dscp_str,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004607 format_policer_action_type, mp->violate_action.type,
Damjan Marion7cd468a2016-12-19 23:05:39 +01004608 violate_dscp_str);
4609
4610 vec_free (conform_dscp_str);
4611 vec_free (exceed_dscp_str);
4612 vec_free (violate_dscp_str);
4613}
4614
4615static void vl_api_policer_details_t_handler_json
4616 (vl_api_policer_details_t * mp)
4617{
4618 vat_main_t *vam = &vat_main;
4619 vat_json_node_t *node;
4620 u8 *rate_type_str, *round_type_str, *type_str;
4621 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
4622
4623 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
4624 round_type_str =
4625 format (0, "%U", format_policer_round_type, mp->round_type);
4626 type_str = format (0, "%U", format_policer_type, mp->type);
4627 conform_action_str = format (0, "%U", format_policer_action_type,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004628 mp->conform_action.type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004629 exceed_action_str = format (0, "%U", format_policer_action_type,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004630 mp->exceed_action.type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004631 violate_action_str = format (0, "%U", format_policer_action_type,
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004632 mp->violate_action.type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004633
4634 if (VAT_JSON_ARRAY != vam->json_tree.type)
4635 {
4636 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4637 vat_json_init_array (&vam->json_tree);
4638 }
4639 node = vat_json_array_add (&vam->json_tree);
4640
4641 vat_json_init_object (node);
4642 vat_json_object_add_string_copy (node, "name", mp->name);
4643 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
4644 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
Marek Gradzki59ed4902017-03-21 11:51:54 +01004645 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
4646 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
Damjan Marion7cd468a2016-12-19 23:05:39 +01004647 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
4648 vat_json_object_add_string_copy (node, "round_type", round_type_str);
4649 vat_json_object_add_string_copy (node, "type", type_str);
4650 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
4651 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
4652 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
4653 vat_json_object_add_uint (node, "cir_tokens_per_period",
4654 ntohl (mp->cir_tokens_per_period));
4655 vat_json_object_add_uint (node, "eir_tokens_per_period",
4656 ntohl (mp->pir_tokens_per_period));
4657 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
4658 vat_json_object_add_uint (node, "current_bucket",
4659 ntohl (mp->current_bucket));
4660 vat_json_object_add_uint (node, "extended_limit",
4661 ntohl (mp->extended_limit));
4662 vat_json_object_add_uint (node, "extended_bucket",
4663 ntohl (mp->extended_bucket));
4664 vat_json_object_add_uint (node, "last_update_time",
4665 ntohl (mp->last_update_time));
4666 vat_json_object_add_string_copy (node, "conform_action",
4667 conform_action_str);
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004668 if (mp->conform_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->conform_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004671 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
4672 vec_free (dscp_str);
4673 }
4674 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004675 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004676 {
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004677 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004678 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
4679 vec_free (dscp_str);
4680 }
4681 vat_json_object_add_string_copy (node, "violate_action",
4682 violate_action_str);
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004683 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004684 {
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01004685 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004686 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
4687 vec_free (dscp_str);
4688 }
4689
4690 vec_free (rate_type_str);
4691 vec_free (round_type_str);
4692 vec_free (type_str);
4693 vec_free (conform_action_str);
4694 vec_free (exceed_action_str);
4695 vec_free (violate_action_str);
4696}
4697
4698static void
4699vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
4700 mp)
4701{
4702 vat_main_t *vam = &vat_main;
4703 int i, count = ntohl (mp->count);
4704
4705 if (count > 0)
4706 print (vam->ofp, "classify table ids (%d) : ", count);
4707 for (i = 0; i < count; i++)
4708 {
4709 print (vam->ofp, "%d", ntohl (mp->ids[i]));
4710 print (vam->ofp, (i < count - 1) ? "," : "");
4711 }
4712 vam->retval = ntohl (mp->retval);
4713 vam->result_ready = 1;
4714}
4715
4716static void
4717 vl_api_classify_table_ids_reply_t_handler_json
4718 (vl_api_classify_table_ids_reply_t * mp)
4719{
4720 vat_main_t *vam = &vat_main;
4721 int i, count = ntohl (mp->count);
4722
4723 if (count > 0)
4724 {
4725 vat_json_node_t node;
4726
4727 vat_json_init_object (&node);
4728 for (i = 0; i < count; i++)
4729 {
4730 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
4731 }
4732 vat_json_print (vam->ofp, &node);
4733 vat_json_free (&node);
4734 }
4735 vam->retval = ntohl (mp->retval);
4736 vam->result_ready = 1;
4737}
4738
4739static void
4740 vl_api_classify_table_by_interface_reply_t_handler
4741 (vl_api_classify_table_by_interface_reply_t * mp)
4742{
4743 vat_main_t *vam = &vat_main;
4744 u32 table_id;
4745
4746 table_id = ntohl (mp->l2_table_id);
4747 if (table_id != ~0)
4748 print (vam->ofp, "l2 table id : %d", table_id);
4749 else
4750 print (vam->ofp, "l2 table id : No input ACL tables configured");
4751 table_id = ntohl (mp->ip4_table_id);
4752 if (table_id != ~0)
4753 print (vam->ofp, "ip4 table id : %d", table_id);
4754 else
4755 print (vam->ofp, "ip4 table id : No input ACL tables configured");
4756 table_id = ntohl (mp->ip6_table_id);
4757 if (table_id != ~0)
4758 print (vam->ofp, "ip6 table id : %d", table_id);
4759 else
4760 print (vam->ofp, "ip6 table id : No input ACL tables configured");
4761 vam->retval = ntohl (mp->retval);
4762 vam->result_ready = 1;
4763}
4764
4765static void
4766 vl_api_classify_table_by_interface_reply_t_handler_json
4767 (vl_api_classify_table_by_interface_reply_t * mp)
4768{
4769 vat_main_t *vam = &vat_main;
4770 vat_json_node_t node;
4771
4772 vat_json_init_object (&node);
4773
4774 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
4775 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
4776 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
4777
4778 vat_json_print (vam->ofp, &node);
4779 vat_json_free (&node);
4780
4781 vam->retval = ntohl (mp->retval);
4782 vam->result_ready = 1;
4783}
4784
4785static void vl_api_policer_add_del_reply_t_handler
4786 (vl_api_policer_add_del_reply_t * mp)
4787{
4788 vat_main_t *vam = &vat_main;
4789 i32 retval = ntohl (mp->retval);
4790 if (vam->async_mode)
4791 {
4792 vam->async_errors += (retval < 0);
4793 }
4794 else
4795 {
4796 vam->retval = retval;
4797 vam->result_ready = 1;
4798 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
4799 /*
4800 * Note: this is just barely thread-safe, depends on
4801 * the main thread spinning waiting for an answer...
4802 */
4803 errmsg ("policer index %d", ntohl (mp->policer_index));
4804 }
4805}
4806
4807static void vl_api_policer_add_del_reply_t_handler_json
4808 (vl_api_policer_add_del_reply_t * mp)
4809{
4810 vat_main_t *vam = &vat_main;
4811 vat_json_node_t node;
4812
4813 vat_json_init_object (&node);
4814 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4815 vat_json_object_add_uint (&node, "policer_index",
4816 ntohl (mp->policer_index));
4817
4818 vat_json_print (vam->ofp, &node);
4819 vat_json_free (&node);
4820
4821 vam->retval = ntohl (mp->retval);
4822 vam->result_ready = 1;
4823}
4824
4825/* Format hex dump. */
4826u8 *
4827format_hex_bytes (u8 * s, va_list * va)
4828{
4829 u8 *bytes = va_arg (*va, u8 *);
4830 int n_bytes = va_arg (*va, int);
4831 uword i;
4832
4833 /* Print short or long form depending on byte count. */
4834 uword short_form = n_bytes <= 32;
Christophe Fontained3c008d2017-10-02 18:10:54 +02004835 u32 indent = format_get_indent (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004836
4837 if (n_bytes == 0)
4838 return s;
4839
4840 for (i = 0; i < n_bytes; i++)
4841 {
4842 if (!short_form && (i % 32) == 0)
4843 s = format (s, "%08x: ", i);
4844 s = format (s, "%02x", bytes[i]);
4845 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
4846 s = format (s, "\n%U", format_white_space, indent);
4847 }
4848
4849 return s;
4850}
4851
4852static void
4853vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
4854 * mp)
4855{
4856 vat_main_t *vam = &vat_main;
4857 i32 retval = ntohl (mp->retval);
4858 if (retval == 0)
4859 {
4860 print (vam->ofp, "classify table info :");
4861 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
4862 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
4863 ntohl (mp->miss_next_index));
4864 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
4865 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
4866 ntohl (mp->match_n_vectors));
4867 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
4868 ntohl (mp->mask_length));
4869 }
4870 vam->retval = retval;
4871 vam->result_ready = 1;
4872}
4873
4874static void
4875 vl_api_classify_table_info_reply_t_handler_json
4876 (vl_api_classify_table_info_reply_t * mp)
4877{
4878 vat_main_t *vam = &vat_main;
4879 vat_json_node_t node;
4880
4881 i32 retval = ntohl (mp->retval);
4882 if (retval == 0)
4883 {
4884 vat_json_init_object (&node);
4885
4886 vat_json_object_add_int (&node, "sessions",
4887 ntohl (mp->active_sessions));
4888 vat_json_object_add_int (&node, "nexttbl",
4889 ntohl (mp->next_table_index));
4890 vat_json_object_add_int (&node, "nextnode",
4891 ntohl (mp->miss_next_index));
4892 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
4893 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
4894 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
4895 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
4896 ntohl (mp->mask_length), 0);
4897 vat_json_object_add_string_copy (&node, "mask", s);
4898
4899 vat_json_print (vam->ofp, &node);
4900 vat_json_free (&node);
4901 }
4902 vam->retval = ntohl (mp->retval);
4903 vam->result_ready = 1;
4904}
4905
4906static void
4907vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
4908 mp)
4909{
4910 vat_main_t *vam = &vat_main;
4911
4912 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
4913 ntohl (mp->hit_next_index), ntohl (mp->advance),
4914 ntohl (mp->opaque_index));
4915 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
4916 ntohl (mp->match_length));
4917}
4918
4919static void
4920 vl_api_classify_session_details_t_handler_json
4921 (vl_api_classify_session_details_t * mp)
4922{
4923 vat_main_t *vam = &vat_main;
4924 vat_json_node_t *node = NULL;
4925
4926 if (VAT_JSON_ARRAY != vam->json_tree.type)
4927 {
4928 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4929 vat_json_init_array (&vam->json_tree);
4930 }
4931 node = vat_json_array_add (&vam->json_tree);
4932
4933 vat_json_init_object (node);
4934 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
4935 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
4936 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
4937 u8 *s =
4938 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
4939 0);
4940 vat_json_object_add_string_copy (node, "match", s);
4941}
4942
4943static void vl_api_pg_create_interface_reply_t_handler
4944 (vl_api_pg_create_interface_reply_t * mp)
4945{
4946 vat_main_t *vam = &vat_main;
4947
4948 vam->retval = ntohl (mp->retval);
4949 vam->result_ready = 1;
4950}
4951
4952static void vl_api_pg_create_interface_reply_t_handler_json
4953 (vl_api_pg_create_interface_reply_t * mp)
4954{
4955 vat_main_t *vam = &vat_main;
4956 vat_json_node_t node;
4957
4958 i32 retval = ntohl (mp->retval);
4959 if (retval == 0)
4960 {
4961 vat_json_init_object (&node);
4962
4963 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
4964
4965 vat_json_print (vam->ofp, &node);
4966 vat_json_free (&node);
4967 }
4968 vam->retval = ntohl (mp->retval);
4969 vam->result_ready = 1;
4970}
4971
4972static void vl_api_policer_classify_details_t_handler
4973 (vl_api_policer_classify_details_t * mp)
4974{
4975 vat_main_t *vam = &vat_main;
4976
4977 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
4978 ntohl (mp->table_index));
4979}
4980
4981static void vl_api_policer_classify_details_t_handler_json
4982 (vl_api_policer_classify_details_t * mp)
4983{
4984 vat_main_t *vam = &vat_main;
4985 vat_json_node_t *node;
4986
4987 if (VAT_JSON_ARRAY != vam->json_tree.type)
4988 {
4989 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4990 vat_json_init_array (&vam->json_tree);
4991 }
4992 node = vat_json_array_add (&vam->json_tree);
4993
4994 vat_json_init_object (node);
4995 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4996 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
4997}
4998
Damjan Marion7cd468a2016-12-19 23:05:39 +01004999static void vl_api_flow_classify_details_t_handler
5000 (vl_api_flow_classify_details_t * mp)
5001{
5002 vat_main_t *vam = &vat_main;
5003
5004 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
5005 ntohl (mp->table_index));
5006}
5007
5008static void vl_api_flow_classify_details_t_handler_json
5009 (vl_api_flow_classify_details_t * mp)
5010{
5011 vat_main_t *vam = &vat_main;
5012 vat_json_node_t *node;
5013
5014 if (VAT_JSON_ARRAY != vam->json_tree.type)
5015 {
5016 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5017 vat_json_init_array (&vam->json_tree);
5018 }
5019 node = vat_json_array_add (&vam->json_tree);
5020
5021 vat_json_init_object (node);
5022 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5023 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5024}
5025
Filip Tehlar694396d2017-02-17 14:29:11 +01005026#define vl_api_one_adjacencies_get_reply_t_endian vl_noop_handler
5027#define vl_api_one_adjacencies_get_reply_t_print vl_noop_handler
Filip Tehlard5a65db2017-05-17 17:21:10 +02005028#define vl_api_one_l2_arp_bd_get_reply_t_print vl_noop_handler
5029#define vl_api_one_l2_arp_entries_get_reply_t_endian vl_noop_handler
5030#define vl_api_one_l2_arp_entries_get_reply_t_print vl_noop_handler
5031#define vl_api_one_l2_arp_bd_get_reply_t_endian vl_noop_handler
Filip Tehlar05879992017-09-05 15:46:09 +02005032#define vl_api_one_ndp_bd_get_reply_t_endian vl_noop_handler
5033#define vl_api_one_ndp_bd_get_reply_t_print vl_noop_handler
5034#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
5035#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +01005036
5037/*
5038 * Generate boilerplate reply handlers, which
5039 * dig the return value out of the xxx_reply_t API message,
5040 * stick it into vam->retval, and set vam->result_ready
5041 *
5042 * Could also do this by pointing N message decode slots at
5043 * a single function, but that could break in subtle ways.
5044 */
5045
5046#define foreach_standard_reply_retval_handler \
5047_(sw_interface_set_flags_reply) \
5048_(sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005049_(sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005050_(sw_interface_set_rx_placement_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005051_(sw_interface_set_table_reply) \
5052_(sw_interface_set_mpls_enable_reply) \
5053_(sw_interface_set_vpath_reply) \
5054_(sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005055_(sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005056_(sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005057_(sw_interface_set_l2_bridge_reply) \
Steven Luonga1876b82019-08-20 16:58:00 -07005058_(sw_interface_set_bond_weight_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005059_(bridge_domain_add_del_reply) \
5060_(sw_interface_set_l2_xconnect_reply) \
5061_(l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005062_(l2fib_flush_int_reply) \
5063_(l2fib_flush_bd_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005064_(ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005065_(ip_table_add_del_reply) \
Neale Ranns9db6ada2019-11-08 12:42:31 +00005066_(ip_table_replace_begin_reply) \
5067_(ip_table_flush_reply) \
5068_(ip_table_replace_end_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005069_(ip_mroute_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005070_(mpls_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005071_(mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005072_(mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005073_(bier_route_add_del_reply) \
5074_(bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005075_(sw_interface_set_unnumbered_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005076_(set_ip_flow_hash_reply) \
5077_(sw_interface_ip6_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005078_(l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005079_(sr_mpls_policy_add_reply) \
5080_(sr_mpls_policy_mod_reply) \
5081_(sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005082_(sr_policy_add_reply) \
5083_(sr_policy_mod_reply) \
5084_(sr_policy_del_reply) \
5085_(sr_localsid_add_del_reply) \
5086_(sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005087_(classify_add_del_session_reply) \
5088_(classify_set_interface_ip_table_reply) \
5089_(classify_set_interface_l2_tables_reply) \
5090_(l2tpv3_set_tunnel_cookies_reply) \
5091_(l2tpv3_interface_enable_disable_reply) \
5092_(l2tpv3_set_lookup_key_reply) \
5093_(l2_fib_clear_table_reply) \
5094_(l2_interface_efp_filter_reply) \
5095_(l2_interface_vlan_tag_rewrite_reply) \
5096_(modify_vhost_user_if_reply) \
5097_(delete_vhost_user_if_reply) \
John Lo8d00fff2017-08-03 00:35:36 -04005098_(want_l2_macs_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005099_(input_acl_set_interface_reply) \
5100_(ipsec_spd_add_del_reply) \
5101_(ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005102_(ipsec_spd_entry_add_del_reply) \
5103_(ipsec_sad_entry_add_del_reply) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005104_(ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005105_(ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005106_(delete_loopback_reply) \
5107_(bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005108_(bd_ip_mac_flush_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005109_(want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005110_(cop_interface_enable_disable_reply) \
5111_(cop_whitelist_enable_disable_reply) \
5112_(sw_interface_clear_stats_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005113_(ioam_enable_reply) \
5114_(ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005115_(one_add_del_locator_reply) \
5116_(one_add_del_local_eid_reply) \
5117_(one_add_del_remote_mapping_reply) \
5118_(one_add_del_adjacency_reply) \
5119_(one_add_del_map_resolver_reply) \
5120_(one_add_del_map_server_reply) \
5121_(one_enable_disable_reply) \
5122_(one_rloc_probe_enable_disable_reply) \
5123_(one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005124_(one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005125_(one_set_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005126_(one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005127_(one_pitr_set_locator_set_reply) \
5128_(one_map_request_mode_reply) \
5129_(one_add_del_map_request_itr_rlocs_reply) \
5130_(one_eid_table_add_del_map_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005131_(one_use_petr_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005132_(one_stats_enable_disable_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005133_(one_add_del_l2_arp_entry_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005134_(one_add_del_ndp_entry_reply) \
Filip Tehlar21511912017-04-07 10:41:42 +02005135_(one_stats_flush_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005136_(one_enable_disable_xtr_mode_reply) \
5137_(one_enable_disable_pitr_mode_reply) \
5138_(one_enable_disable_petr_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005139_(gpe_enable_disable_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005140_(gpe_set_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005141_(gpe_add_del_iface_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005142_(gpe_add_del_native_fwd_rpath_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005143_(af_packet_delete_reply) \
5144_(policer_classify_set_interface_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005145_(set_ipfix_exporter_reply) \
5146_(set_ipfix_classify_stream_reply) \
5147_(ipfix_classify_table_add_del_reply) \
5148_(flow_classify_set_interface_reply) \
5149_(sw_interface_span_enable_disable_reply) \
5150_(pg_capture_reply) \
5151_(pg_enable_disable_reply) \
5152_(ip_source_and_port_range_check_add_del_reply) \
5153_(ip_source_and_port_range_check_interface_add_del_reply)\
5154_(delete_subif_reply) \
5155_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005156_(set_punt_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005157_(feature_enable_disable_reply) \
Mohsin Kazmi29467b52019-10-08 19:42:38 +02005158_(feature_gso_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005159_(sw_interface_tag_add_del_reply) \
Matthew Smithe0792fd2019-07-12 11:48:24 -05005160_(sw_interface_add_del_mac_address_reply) \
Ole Troand7231612018-06-07 10:17:57 +02005161_(hw_interface_set_mtu_reply) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005162_(p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005163_(p2p_ethernet_del_reply) \
5164_(lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005165_(sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005166_(tcp_configure_src_addresses_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005167_(session_rule_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005168_(ip_container_proxy_add_del_reply) \
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -07005169_(output_acl_set_interface_reply) \
5170_(qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005171
5172#define _(n) \
5173 static void vl_api_##n##_t_handler \
5174 (vl_api_##n##_t * mp) \
5175 { \
5176 vat_main_t * vam = &vat_main; \
5177 i32 retval = ntohl(mp->retval); \
5178 if (vam->async_mode) { \
5179 vam->async_errors += (retval < 0); \
5180 } else { \
5181 vam->retval = retval; \
5182 vam->result_ready = 1; \
5183 } \
5184 }
5185foreach_standard_reply_retval_handler;
5186#undef _
5187
5188#define _(n) \
5189 static void vl_api_##n##_t_handler_json \
5190 (vl_api_##n##_t * mp) \
5191 { \
5192 vat_main_t * vam = &vat_main; \
5193 vat_json_node_t node; \
5194 vat_json_init_object(&node); \
5195 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
5196 vat_json_print(vam->ofp, &node); \
5197 vam->retval = ntohl(mp->retval); \
5198 vam->result_ready = 1; \
5199 }
5200foreach_standard_reply_retval_handler;
5201#undef _
5202
5203/*
5204 * Table of message reply handlers, must include boilerplate handlers
5205 * we just generated
5206 */
5207
5208#define foreach_vpe_api_reply_msg \
5209_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005210_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005211_(SW_INTERFACE_DETAILS, sw_interface_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005212_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
5213_(CONTROL_PING_REPLY, control_ping_reply) \
5214_(CLI_REPLY, cli_reply) \
5215_(CLI_INBAND_REPLY, cli_inband_reply) \
5216_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
5217 sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005218_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005219_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02005220_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005221_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
5222_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
5223_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
5224_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005225_(SW_INTERFACE_SET_GENEVE_BYPASS_REPLY, sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005226_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005227_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
5228 sw_interface_set_l2_xconnect_reply) \
5229_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
5230 sw_interface_set_l2_bridge_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005231_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
5232_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
Eyal Barifead6702017-04-04 04:46:32 +03005233_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005234_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005235_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
5236_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005237_(L2_FLAGS_REPLY, l2_flags_reply) \
5238_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
Damjan Marion8389fb92017-10-13 18:29:53 +02005239_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
5240_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
5241_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01005242_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
5243_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
5244_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
Steven9cd2d7a2017-12-20 12:43:01 -08005245_(BOND_CREATE_REPLY, bond_create_reply) \
5246_(BOND_DELETE_REPLY, bond_delete_reply) \
Steven Luong4c4223e2020-07-15 08:44:54 -07005247_(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
5248_(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
Steven Luonga1876b82019-08-20 16:58:00 -07005249_(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
Steven Luong4c4223e2020-07-15 08:44:54 -07005250_(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
5251_(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005252_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005253_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
Neale Ranns9db6ada2019-11-08 12:42:31 +00005254_(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
5255_(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
5256_(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005257_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005258_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005259_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
5260_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005261_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
5262_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005263_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
5264_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
5265 sw_interface_set_unnumbered_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005266_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
5267_(CREATE_SUBIF_REPLY, create_subif_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005268_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
5269_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
5270 sw_interface_ip6_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005271_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005272_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
5273_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
5274_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005275_(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
5276_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
5277_(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
5278_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
5279_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005280_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
5281_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
5282_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
5283classify_set_interface_ip_table_reply) \
5284_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
5285 classify_set_interface_l2_tables_reply) \
5286_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
5287_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
5288_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
5289_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
5290_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
5291 l2tpv3_interface_enable_disable_reply) \
5292_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
5293_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
5294_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
eyal bariaf86a482018-04-17 11:20:27 +03005295_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005296_(GENEVE_ADD_DEL_TUNNEL_REPLY, geneve_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005297_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005298_(GENEVE_TUNNEL_DETAILS, geneve_tunnel_details) \
Neale Ranns5a8844b2019-04-16 07:15:35 +00005299_(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005300_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
5301_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
5302_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
5303_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
5304_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
5305_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
5306_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
5307_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
5308_(SHOW_VERSION_REPLY, show_version_reply) \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02005309_(SHOW_THREADS_REPLY, show_threads_reply) \
Ole Troan01384fe2017-05-12 11:55:35 +02005310_(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
John Loc7b43042018-04-13 16:46:22 -04005311_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005312_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
5313_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
John Lo8d00fff2017-08-03 00:35:36 -04005314_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
5315_(L2_MACS_EVENT, l2_macs_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005316_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
5317_(IP_ADDRESS_DETAILS, ip_address_details) \
5318_(IP_DETAILS, ip_details) \
5319_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
5320_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005321_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
5322_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
Matthew Smith28029532017-09-26 13:33:44 -05005323_(IPSEC_SA_DETAILS, ipsec_sa_details) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005324_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005325_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005326_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
5327_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005328_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02005329_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005330_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005331_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
5332_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
5333_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
5334_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
5335_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
5336_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
5337_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005338_(ONE_ADD_DEL_LOCATOR_SET_REPLY, one_add_del_locator_set_reply) \
5339_(ONE_ADD_DEL_LOCATOR_REPLY, one_add_del_locator_reply) \
5340_(ONE_ADD_DEL_LOCAL_EID_REPLY, one_add_del_local_eid_reply) \
5341_(ONE_ADD_DEL_REMOTE_MAPPING_REPLY, one_add_del_remote_mapping_reply) \
5342_(ONE_ADD_DEL_ADJACENCY_REPLY, one_add_del_adjacency_reply) \
5343_(ONE_ADD_DEL_MAP_RESOLVER_REPLY, one_add_del_map_resolver_reply) \
5344_(ONE_ADD_DEL_MAP_SERVER_REPLY, one_add_del_map_server_reply) \
5345_(ONE_ENABLE_DISABLE_REPLY, one_enable_disable_reply) \
5346_(ONE_MAP_REGISTER_ENABLE_DISABLE_REPLY, \
5347 one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005348_(ONE_MAP_REGISTER_SET_TTL_REPLY, one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005349_(ONE_SET_TRANSPORT_PROTOCOL_REPLY, one_set_transport_protocol_reply) \
5350_(ONE_GET_TRANSPORT_PROTOCOL_REPLY, one_get_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005351_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5352 one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005353_(ONE_RLOC_PROBE_ENABLE_DISABLE_REPLY, \
5354 one_rloc_probe_enable_disable_reply) \
5355_(ONE_PITR_SET_LOCATOR_SET_REPLY, one_pitr_set_locator_set_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005356_(ONE_USE_PETR_REPLY, one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005357_(ONE_MAP_REQUEST_MODE_REPLY, one_map_request_mode_reply) \
5358_(ONE_EID_TABLE_ADD_DEL_MAP_REPLY, one_eid_table_add_del_map_reply) \
5359_(ONE_LOCATOR_SET_DETAILS, one_locator_set_details) \
5360_(ONE_LOCATOR_DETAILS, one_locator_details) \
5361_(ONE_EID_TABLE_DETAILS, one_eid_table_details) \
5362_(ONE_EID_TABLE_MAP_DETAILS, one_eid_table_map_details) \
5363_(ONE_EID_TABLE_VNI_DETAILS, one_eid_table_vni_details) \
5364_(ONE_MAP_RESOLVER_DETAILS, one_map_resolver_details) \
5365_(ONE_MAP_SERVER_DETAILS, one_map_server_details) \
5366_(ONE_ADJACENCIES_GET_REPLY, one_adjacencies_get_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005367_(ONE_STATS_DETAILS, one_stats_details) \
Filip Tehlar21511912017-04-07 10:41:42 +02005368_(ONE_STATS_FLUSH_REPLY, one_stats_flush_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005369_(ONE_STATS_ENABLE_DISABLE_REPLY, one_stats_enable_disable_reply) \
5370_(SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, \
5371 show_one_stats_enable_disable_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005372_(ONE_ADD_DEL_NDP_ENTRY_REPLY, one_add_del_ndp_entry_reply) \
5373_(ONE_NDP_BD_GET_REPLY, one_ndp_bd_get_reply) \
5374_(ONE_NDP_ENTRIES_GET_REPLY, one_ndp_entries_get_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005375_(ONE_ADD_DEL_L2_ARP_ENTRY_REPLY, one_add_del_l2_arp_entry_reply) \
5376_(ONE_L2_ARP_BD_GET_REPLY, one_l2_arp_bd_get_reply) \
5377_(ONE_L2_ARP_ENTRIES_GET_REPLY, one_l2_arp_entries_get_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005378_(ONE_ENABLE_DISABLE_XTR_MODE_REPLY, one_enable_disable_xtr_mode_reply) \
5379_(ONE_ENABLE_DISABLE_PITR_MODE_REPLY, \
5380 one_enable_disable_pitr_mode_reply) \
5381_(ONE_ENABLE_DISABLE_PETR_MODE_REPLY, \
5382 one_enable_disable_petr_mode_reply) \
5383_(ONE_SHOW_XTR_MODE_REPLY, one_show_xtr_mode_reply) \
5384_(ONE_SHOW_PITR_MODE_REPLY, one_show_pitr_mode_reply) \
5385_(ONE_SHOW_PETR_MODE_REPLY, one_show_petr_mode_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005386_(GPE_SET_ENCAP_MODE_REPLY, gpe_set_encap_mode_reply) \
5387_(GPE_GET_ENCAP_MODE_REPLY, gpe_get_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005388_(GPE_ADD_DEL_IFACE_REPLY, gpe_add_del_iface_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005389_(GPE_ENABLE_DISABLE_REPLY, gpe_enable_disable_reply) \
5390_(GPE_ADD_DEL_FWD_ENTRY_REPLY, gpe_add_del_fwd_entry_reply) \
Filip Tehlar0eb874e2017-05-18 14:23:32 +02005391_(GPE_FWD_ENTRY_VNIS_GET_REPLY, gpe_fwd_entry_vnis_get_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005392_(GPE_FWD_ENTRIES_GET_REPLY, gpe_fwd_entries_get_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005393_(GPE_NATIVE_FWD_RPATHS_GET_REPLY, gpe_native_fwd_rpaths_get_reply) \
5394_(GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY, \
5395 gpe_add_del_native_fwd_rpath_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005396_(GPE_FWD_ENTRY_PATH_DETAILS, \
5397 gpe_fwd_entry_path_details) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005398_(SHOW_ONE_STATUS_REPLY, show_one_status_reply) \
5399_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
5400 one_add_del_map_request_itr_rlocs_reply) \
5401_(ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
5402 one_get_map_request_itr_rlocs_reply) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02005403_(SHOW_ONE_NSH_MAPPING_REPLY, show_one_nsh_mapping_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005404_(SHOW_ONE_PITR_REPLY, show_one_pitr_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005405_(SHOW_ONE_USE_PETR_REPLY, show_one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005406_(SHOW_ONE_MAP_REQUEST_MODE_REPLY, show_one_map_request_mode_reply) \
5407_(SHOW_ONE_RLOC_PROBE_STATE_REPLY, show_one_rloc_probe_state_reply) \
5408_(SHOW_ONE_MAP_REGISTER_STATE_REPLY, \
5409 show_one_map_register_state_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005410_(SHOW_ONE_MAP_REGISTER_TTL_REPLY, show_one_map_register_ttl_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005411_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5412 show_one_map_register_fallback_threshold_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005413_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
5414_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +02005415_(AF_PACKET_DETAILS, af_packet_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005416_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
5417_(POLICER_DETAILS, policer_details) \
5418_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
5419_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005420_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
Neale Ranns097fa662018-05-01 05:17:55 -07005421_(MPLS_TABLE_DETAILS, mpls_table_details) \
5422_(MPLS_ROUTE_DETAILS, mpls_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005423_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
5424_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
5425_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
5426_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
5427_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
5428_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
5429_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
5430_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
5431_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
5432_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
5433_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
5434_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
5435_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
5436_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
5437_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
5438_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
5439_(PG_CAPTURE_REPLY, pg_capture_reply) \
5440_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
5441_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
5442 ip_source_and_port_range_check_add_del_reply) \
5443_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
5444 ip_source_and_port_range_check_interface_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005445_(DELETE_SUBIF_REPLY, delete_subif_reply) \
5446_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005447_(SET_PUNT_REPLY, set_punt_reply) \
Neale Ranns097fa662018-05-01 05:17:55 -07005448_(IP_TABLE_DETAILS, ip_table_details) \
5449_(IP_ROUTE_DETAILS, ip_route_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005450_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
Mohsin Kazmi29467b52019-10-08 19:42:38 +02005451_(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005452_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
Matthew Smithe0792fd2019-07-12 11:48:24 -05005453_(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005454_(L2_XCONNECT_DETAILS, l2_xconnect_details) \
Ole Troand7231612018-06-07 10:17:57 +02005455_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005456_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
5457_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005458_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
5459_(LLDP_CONFIG_REPLY, lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005460_(SW_INTERFACE_SET_LLDP_REPLY, sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005461_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005462_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
Florin Coras6c36f532017-11-03 18:32:34 -07005463_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005464_(SESSION_RULES_DETAILS, session_rules_details) \
5465_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005466_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
Ole Troane906aac2018-06-14 14:42:14 +02005467_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005468
Dave Baracha1a093d2017-03-02 13:13:23 -05005469#define foreach_standalone_reply_msg \
Ole Troanf49ba0e2018-11-13 14:04:50 +01005470_(SW_INTERFACE_EVENT, sw_interface_event)
Dave Baracha1a093d2017-03-02 13:13:23 -05005471
Damjan Marion7cd468a2016-12-19 23:05:39 +01005472typedef struct
5473{
5474 u8 *name;
5475 u32 value;
5476} name_sort_t;
5477
Damjan Marion7cd468a2016-12-19 23:05:39 +01005478#define STR_VTR_OP_CASE(op) \
5479 case L2_VTR_ ## op: \
5480 return "" # op;
5481
5482static const char *
5483str_vtr_op (u32 vtr_op)
5484{
5485 switch (vtr_op)
5486 {
5487 STR_VTR_OP_CASE (DISABLED);
5488 STR_VTR_OP_CASE (PUSH_1);
5489 STR_VTR_OP_CASE (PUSH_2);
5490 STR_VTR_OP_CASE (POP_1);
5491 STR_VTR_OP_CASE (POP_2);
5492 STR_VTR_OP_CASE (TRANSLATE_1_1);
5493 STR_VTR_OP_CASE (TRANSLATE_1_2);
5494 STR_VTR_OP_CASE (TRANSLATE_2_1);
5495 STR_VTR_OP_CASE (TRANSLATE_2_2);
5496 }
5497
5498 return "UNKNOWN";
5499}
5500
5501static int
5502dump_sub_interface_table (vat_main_t * vam)
5503{
5504 const sw_interface_subif_t *sub = NULL;
5505
5506 if (vam->json_output)
5507 {
5508 clib_warning
5509 ("JSON output supported only for VPE API calls and dump_stats_table");
5510 return -99;
5511 }
5512
5513 print (vam->ofp,
5514 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
5515 "Interface", "sw_if_index",
5516 "sub id", "dot1ad", "tags", "outer id",
5517 "inner id", "exact", "default", "outer any", "inner any");
5518
5519 vec_foreach (sub, vam->sw_if_subif_table)
5520 {
5521 print (vam->ofp,
5522 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
5523 sub->interface_name,
5524 sub->sw_if_index,
5525 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
5526 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
5527 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
5528 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
5529 if (sub->vtr_op != L2_VTR_DISABLED)
5530 {
5531 print (vam->ofp,
5532 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
5533 "tag1: %d tag2: %d ]",
5534 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
5535 sub->vtr_tag1, sub->vtr_tag2);
5536 }
5537 }
5538
5539 return 0;
5540}
5541
5542static int
5543name_sort_cmp (void *a1, void *a2)
5544{
5545 name_sort_t *n1 = a1;
5546 name_sort_t *n2 = a2;
5547
5548 return strcmp ((char *) n1->name, (char *) n2->name);
5549}
5550
5551static int
5552dump_interface_table (vat_main_t * vam)
5553{
5554 hash_pair_t *p;
5555 name_sort_t *nses = 0, *ns;
5556
5557 if (vam->json_output)
5558 {
5559 clib_warning
5560 ("JSON output supported only for VPE API calls and dump_stats_table");
5561 return -99;
5562 }
5563
5564 /* *INDENT-OFF* */
5565 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5566 ({
5567 vec_add2 (nses, ns, 1);
5568 ns->name = (u8 *)(p->key);
5569 ns->value = (u32) p->value[0];
5570 }));
5571 /* *INDENT-ON* */
5572
5573 vec_sort_with_function (nses, name_sort_cmp);
5574
5575 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
5576 vec_foreach (ns, nses)
5577 {
5578 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
5579 }
5580 vec_free (nses);
5581 return 0;
5582}
5583
5584static int
5585dump_ip_table (vat_main_t * vam, int is_ipv6)
5586{
5587 const ip_details_t *det = NULL;
5588 const ip_address_details_t *address = NULL;
5589 u32 i = ~0;
5590
5591 print (vam->ofp, "%-12s", "sw_if_index");
5592
5593 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
5594 {
5595 i++;
5596 if (!det->present)
5597 {
5598 continue;
5599 }
5600 print (vam->ofp, "%-12d", i);
5601 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
5602 if (!det->addr)
5603 {
5604 continue;
5605 }
5606 vec_foreach (address, det->addr)
5607 {
5608 print (vam->ofp,
5609 " %-30U%-13d",
5610 is_ipv6 ? format_ip6_address : format_ip4_address,
5611 address->ip, address->prefix_length);
5612 }
5613 }
5614
5615 return 0;
5616}
5617
5618static int
5619dump_ipv4_table (vat_main_t * vam)
5620{
5621 if (vam->json_output)
5622 {
5623 clib_warning
5624 ("JSON output supported only for VPE API calls and dump_stats_table");
5625 return -99;
5626 }
5627
5628 return dump_ip_table (vam, 0);
5629}
5630
5631static int
5632dump_ipv6_table (vat_main_t * vam)
5633{
5634 if (vam->json_output)
5635 {
5636 clib_warning
5637 ("JSON output supported only for VPE API calls and dump_stats_table");
5638 return -99;
5639 }
5640
5641 return dump_ip_table (vam, 1);
5642}
5643
Damjan Marion7cd468a2016-12-19 23:05:39 +01005644/*
Dave Barach59b25652017-09-10 15:04:27 -04005645 * Pass CLI buffers directly in the CLI_INBAND API message,
5646 * instead of an additional shared memory area.
Damjan Marion7cd468a2016-12-19 23:05:39 +01005647 */
5648static int
5649exec_inband (vat_main_t * vam)
5650{
5651 vl_api_cli_inband_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005652 unformat_input_t *i = vam->input;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005653 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005654
5655 if (vec_len (i->buffer) == 0)
5656 return -1;
5657
5658 if (vam->exec_mode == 0 && unformat (i, "mode"))
5659 {
5660 vam->exec_mode = 1;
5661 return 0;
5662 }
5663 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
5664 {
5665 vam->exec_mode = 0;
5666 return 0;
5667 }
5668
5669 /*
5670 * In order for the CLI command to work, it
5671 * must be a vector ending in \n, not a C-string ending
5672 * in \n\0.
5673 */
Jakub Grajciar2dbee932020-02-07 11:30:26 +01005674 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
5675 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005676
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005677 S (mp);
Dave Barach59b25652017-09-10 15:04:27 -04005678 W (ret);
5679 /* json responses may or may not include a useful reply... */
5680 if (vec_len (vam->cmd_reply))
Dave Barachcf5e8482017-10-17 11:48:29 -04005681 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
Jon Loeliger56c7b012017-02-01 12:31:41 -06005682 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005683}
5684
Dave Barach59b25652017-09-10 15:04:27 -04005685int
5686exec (vat_main_t * vam)
5687{
5688 return exec_inband (vam);
5689}
5690
Damjan Marion7cd468a2016-12-19 23:05:39 +01005691static int
5692api_create_loopback (vat_main_t * vam)
5693{
5694 unformat_input_t *i = vam->input;
5695 vl_api_create_loopback_t *mp;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005696 vl_api_create_loopback_instance_t *mp_lbi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005697 u8 mac_address[6];
5698 u8 mac_set = 0;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005699 u8 is_specified = 0;
5700 u32 user_instance = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005701 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005702
Dave Barachb7b92992018-10-17 10:38:51 -04005703 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01005704
5705 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5706 {
5707 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5708 mac_set = 1;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005709 if (unformat (i, "instance %d", &user_instance))
5710 is_specified = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005711 else
5712 break;
5713 }
5714
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005715 if (is_specified)
5716 {
5717 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
5718 mp_lbi->is_specified = is_specified;
5719 if (is_specified)
5720 mp_lbi->user_instance = htonl (user_instance);
5721 if (mac_set)
5722 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
5723 S (mp_lbi);
5724 }
5725 else
5726 {
5727 /* Construct the API message */
5728 M (CREATE_LOOPBACK, mp);
5729 if (mac_set)
5730 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
5731 S (mp);
5732 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01005733
Jon Loeliger56c7b012017-02-01 12:31:41 -06005734 W (ret);
5735 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005736}
5737
5738static int
5739api_delete_loopback (vat_main_t * vam)
5740{
5741 unformat_input_t *i = vam->input;
5742 vl_api_delete_loopback_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005743 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005744 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005745
5746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5747 {
5748 if (unformat (i, "sw_if_index %d", &sw_if_index))
5749 ;
5750 else
5751 break;
5752 }
5753
5754 if (sw_if_index == ~0)
5755 {
5756 errmsg ("missing sw_if_index");
5757 return -99;
5758 }
5759
5760 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005761 M (DELETE_LOOPBACK, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005762 mp->sw_if_index = ntohl (sw_if_index);
5763
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005764 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005765 W (ret);
5766 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005767}
5768
5769static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01005770api_want_interface_events (vat_main_t * vam)
5771{
5772 unformat_input_t *i = vam->input;
5773 vl_api_want_interface_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005774 int enable = -1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005775 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005776
5777 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5778 {
5779 if (unformat (i, "enable"))
5780 enable = 1;
5781 else if (unformat (i, "disable"))
5782 enable = 0;
5783 else
5784 break;
5785 }
5786
5787 if (enable == -1)
5788 {
5789 errmsg ("missing enable|disable");
5790 return -99;
5791 }
5792
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005793 M (WANT_INTERFACE_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005794 mp->enable_disable = enable;
5795
5796 vam->interface_event_display = enable;
5797
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005798 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005799 W (ret);
5800 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005801}
5802
5803
5804/* Note: non-static, called once to set up the initial intfc table */
5805int
5806api_sw_interface_dump (vat_main_t * vam)
5807{
5808 vl_api_sw_interface_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005809 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005810 hash_pair_t *p;
5811 name_sort_t *nses = 0, *ns;
5812 sw_interface_subif_t *sub = NULL;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005813 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005814
5815 /* Toss the old name table */
5816 /* *INDENT-OFF* */
5817 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5818 ({
5819 vec_add2 (nses, ns, 1);
5820 ns->name = (u8 *)(p->key);
5821 ns->value = (u32) p->value[0];
5822 }));
5823 /* *INDENT-ON* */
5824
5825 hash_free (vam->sw_if_index_by_interface_name);
5826
5827 vec_foreach (ns, nses) vec_free (ns->name);
5828
5829 vec_free (nses);
5830
5831 vec_foreach (sub, vam->sw_if_subif_table)
5832 {
5833 vec_free (sub->interface_name);
5834 }
5835 vec_free (vam->sw_if_subif_table);
5836
5837 /* recreate the interface name hash table */
5838 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
5839
Dave Barachf72212e2018-01-11 10:25:07 -05005840 /*
5841 * Ask for all interface names. Otherwise, the epic catalog of
5842 * name filters becomes ridiculously long, and vat ends up needing
5843 * to be taught about new interface types.
5844 */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005845 M (SW_INTERFACE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005846 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005847
5848 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04005849 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005850 S (mp_ping);
5851
Jon Loeliger56c7b012017-02-01 12:31:41 -06005852 W (ret);
5853 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005854}
5855
5856static int
5857api_sw_interface_set_flags (vat_main_t * vam)
5858{
5859 unformat_input_t *i = vam->input;
5860 vl_api_sw_interface_set_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005861 u32 sw_if_index;
5862 u8 sw_if_index_set = 0;
Neale Rannsa07bd702017-08-07 07:53:49 -07005863 u8 admin_up = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005864 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005865
5866 /* Parse args required to build the message */
5867 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5868 {
5869 if (unformat (i, "admin-up"))
5870 admin_up = 1;
5871 else if (unformat (i, "admin-down"))
5872 admin_up = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005873 else
5874 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5875 sw_if_index_set = 1;
5876 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5877 sw_if_index_set = 1;
5878 else
5879 break;
5880 }
5881
5882 if (sw_if_index_set == 0)
5883 {
5884 errmsg ("missing interface name or sw_if_index");
5885 return -99;
5886 }
5887
5888 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005889 M (SW_INTERFACE_SET_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005890 mp->sw_if_index = ntohl (sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +01005891 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005892
5893 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005894 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005895
5896 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06005897 W (ret);
5898 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005899}
5900
5901static int
Stevenad8015b2017-10-29 22:10:46 -07005902api_sw_interface_set_rx_mode (vat_main_t * vam)
5903{
5904 unformat_input_t *i = vam->input;
5905 vl_api_sw_interface_set_rx_mode_t *mp;
5906 u32 sw_if_index;
5907 u8 sw_if_index_set = 0;
5908 int ret;
5909 u8 queue_id_valid = 0;
5910 u32 queue_id;
5911 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
5912
5913 /* Parse args required to build the message */
5914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5915 {
5916 if (unformat (i, "queue %d", &queue_id))
5917 queue_id_valid = 1;
5918 else if (unformat (i, "polling"))
5919 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
5920 else if (unformat (i, "interrupt"))
5921 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
5922 else if (unformat (i, "adaptive"))
5923 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
5924 else
5925 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5926 sw_if_index_set = 1;
5927 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5928 sw_if_index_set = 1;
5929 else
5930 break;
5931 }
5932
5933 if (sw_if_index_set == 0)
5934 {
5935 errmsg ("missing interface name or sw_if_index");
5936 return -99;
5937 }
5938 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
5939 {
5940 errmsg ("missing rx-mode");
5941 return -99;
5942 }
5943
5944 /* Construct the API message */
5945 M (SW_INTERFACE_SET_RX_MODE, mp);
5946 mp->sw_if_index = ntohl (sw_if_index);
Jakub Grajciar053204a2019-03-18 13:17:53 +01005947 mp->mode = (vl_api_rx_mode_t) mode;
Stevenad8015b2017-10-29 22:10:46 -07005948 mp->queue_id_valid = queue_id_valid;
5949 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
5950
5951 /* send it... */
5952 S (mp);
5953
5954 /* Wait for a reply, return the good/bad news... */
5955 W (ret);
5956 return ret;
5957}
5958
5959static int
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005960api_sw_interface_set_rx_placement (vat_main_t * vam)
5961{
5962 unformat_input_t *i = vam->input;
5963 vl_api_sw_interface_set_rx_placement_t *mp;
5964 u32 sw_if_index;
5965 u8 sw_if_index_set = 0;
5966 int ret;
5967 u8 is_main = 0;
5968 u32 queue_id, thread_index;
5969
5970 /* Parse args required to build the message */
5971 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5972 {
5973 if (unformat (i, "queue %d", &queue_id))
5974 ;
5975 else if (unformat (i, "main"))
5976 is_main = 1;
5977 else if (unformat (i, "worker %d", &thread_index))
5978 ;
5979 else
5980 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5981 sw_if_index_set = 1;
5982 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5983 sw_if_index_set = 1;
5984 else
5985 break;
5986 }
5987
5988 if (sw_if_index_set == 0)
5989 {
5990 errmsg ("missing interface name or sw_if_index");
5991 return -99;
5992 }
5993
5994 if (is_main)
5995 thread_index = 0;
5996 /* Construct the API message */
5997 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
5998 mp->sw_if_index = ntohl (sw_if_index);
5999 mp->worker_id = ntohl (thread_index);
6000 mp->queue_id = ntohl (queue_id);
6001 mp->is_main = is_main;
6002
6003 /* send it... */
6004 S (mp);
6005 /* Wait for a reply, return the good/bad news... */
6006 W (ret);
6007 return ret;
6008}
6009
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02006010static void vl_api_sw_interface_rx_placement_details_t_handler
6011 (vl_api_sw_interface_rx_placement_details_t * mp)
6012{
6013 vat_main_t *vam = &vat_main;
6014 u32 worker_id = ntohl (mp->worker_id);
6015
6016 print (vam->ofp,
6017 "\n%-11d %-11s %-6d %-5d %-9s",
6018 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
6019 worker_id, ntohl (mp->queue_id),
6020 (mp->mode ==
6021 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
6022}
6023
6024static void vl_api_sw_interface_rx_placement_details_t_handler_json
6025 (vl_api_sw_interface_rx_placement_details_t * mp)
6026{
6027 vat_main_t *vam = &vat_main;
6028 vat_json_node_t *node = NULL;
6029
6030 if (VAT_JSON_ARRAY != vam->json_tree.type)
6031 {
6032 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6033 vat_json_init_array (&vam->json_tree);
6034 }
6035 node = vat_json_array_add (&vam->json_tree);
6036
6037 vat_json_init_object (node);
6038 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6039 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
6040 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
6041 vat_json_object_add_uint (node, "mode", mp->mode);
6042}
6043
6044static int
6045api_sw_interface_rx_placement_dump (vat_main_t * vam)
6046{
6047 unformat_input_t *i = vam->input;
6048 vl_api_sw_interface_rx_placement_dump_t *mp;
6049 vl_api_control_ping_t *mp_ping;
6050 int ret;
6051 u32 sw_if_index;
6052 u8 sw_if_index_set = 0;
6053
6054 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6055 {
6056 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6057 sw_if_index_set++;
6058 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6059 sw_if_index_set++;
6060 else
6061 break;
6062 }
6063
6064 print (vam->ofp,
6065 "\n%-11s %-11s %-6s %-5s %-4s",
6066 "sw_if_index", "main/worker", "thread", "queue", "mode");
6067
6068 /* Dump Interface rx placement */
6069 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
6070
6071 if (sw_if_index_set)
6072 mp->sw_if_index = htonl (sw_if_index);
6073 else
6074 mp->sw_if_index = ~0;
6075
6076 S (mp);
6077
6078 /* Use a control ping for synchronization */
6079 MPING (CONTROL_PING, mp_ping);
6080 S (mp_ping);
6081
6082 W (ret);
6083 return ret;
6084}
6085
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006086static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006087api_sw_interface_clear_stats (vat_main_t * vam)
6088{
6089 unformat_input_t *i = vam->input;
6090 vl_api_sw_interface_clear_stats_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006091 u32 sw_if_index;
6092 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006093 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006094
6095 /* Parse args required to build the message */
6096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6097 {
6098 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6099 sw_if_index_set = 1;
6100 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6101 sw_if_index_set = 1;
6102 else
6103 break;
6104 }
6105
6106 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006107 M (SW_INTERFACE_CLEAR_STATS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006108
6109 if (sw_if_index_set == 1)
6110 mp->sw_if_index = ntohl (sw_if_index);
6111 else
6112 mp->sw_if_index = ~0;
6113
6114 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006115 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006116
6117 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006118 W (ret);
6119 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006120}
6121
Damjan Marion7cd468a2016-12-19 23:05:39 +01006122static int
6123api_sw_interface_add_del_address (vat_main_t * vam)
6124{
6125 unformat_input_t *i = vam->input;
6126 vl_api_sw_interface_add_del_address_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006127 u32 sw_if_index;
6128 u8 sw_if_index_set = 0;
6129 u8 is_add = 1, del_all = 0;
6130 u32 address_length = 0;
6131 u8 v4_address_set = 0;
6132 u8 v6_address_set = 0;
6133 ip4_address_t v4address;
6134 ip6_address_t v6address;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006135 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006136
6137 /* Parse args required to build the message */
6138 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6139 {
6140 if (unformat (i, "del-all"))
6141 del_all = 1;
6142 else if (unformat (i, "del"))
6143 is_add = 0;
6144 else
6145 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6146 sw_if_index_set = 1;
6147 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6148 sw_if_index_set = 1;
6149 else if (unformat (i, "%U/%d",
6150 unformat_ip4_address, &v4address, &address_length))
6151 v4_address_set = 1;
6152 else if (unformat (i, "%U/%d",
6153 unformat_ip6_address, &v6address, &address_length))
6154 v6_address_set = 1;
6155 else
6156 break;
6157 }
6158
6159 if (sw_if_index_set == 0)
6160 {
6161 errmsg ("missing interface name or sw_if_index");
6162 return -99;
6163 }
6164 if (v4_address_set && v6_address_set)
6165 {
6166 errmsg ("both v4 and v6 addresses set");
6167 return -99;
6168 }
6169 if (!v4_address_set && !v6_address_set && !del_all)
6170 {
6171 errmsg ("no addresses set");
6172 return -99;
6173 }
6174
6175 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006176 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006177
6178 mp->sw_if_index = ntohl (sw_if_index);
6179 mp->is_add = is_add;
6180 mp->del_all = del_all;
6181 if (v6_address_set)
6182 {
Jakub Grajciar053204a2019-03-18 13:17:53 +01006183 mp->prefix.address.af = ADDRESS_IP6;
6184 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006185 }
6186 else
6187 {
Jakub Grajciar053204a2019-03-18 13:17:53 +01006188 mp->prefix.address.af = ADDRESS_IP4;
6189 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01006190 }
Jakub Grajciar053204a2019-03-18 13:17:53 +01006191 mp->prefix.len = address_length;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006192
6193 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006194 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006195
6196 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006197 W (ret);
6198 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006199}
6200
6201static int
6202api_sw_interface_set_mpls_enable (vat_main_t * vam)
6203{
6204 unformat_input_t *i = vam->input;
6205 vl_api_sw_interface_set_mpls_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006206 u32 sw_if_index;
6207 u8 sw_if_index_set = 0;
6208 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006209 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006210
6211 /* Parse args required to build the message */
6212 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6213 {
6214 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6215 sw_if_index_set = 1;
6216 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6217 sw_if_index_set = 1;
6218 else if (unformat (i, "disable"))
6219 enable = 0;
6220 else if (unformat (i, "dis"))
6221 enable = 0;
6222 else
6223 break;
6224 }
6225
6226 if (sw_if_index_set == 0)
6227 {
6228 errmsg ("missing interface name or sw_if_index");
6229 return -99;
6230 }
6231
6232 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006233 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006234
6235 mp->sw_if_index = ntohl (sw_if_index);
6236 mp->enable = enable;
6237
6238 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006239 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006240
6241 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006242 W (ret);
6243 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006244}
6245
6246static int
6247api_sw_interface_set_table (vat_main_t * vam)
6248{
6249 unformat_input_t *i = vam->input;
6250 vl_api_sw_interface_set_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006251 u32 sw_if_index, vrf_id = 0;
6252 u8 sw_if_index_set = 0;
6253 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006254 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006255
6256 /* Parse args required to build the message */
6257 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6258 {
6259 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6260 sw_if_index_set = 1;
6261 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6262 sw_if_index_set = 1;
6263 else if (unformat (i, "vrf %d", &vrf_id))
6264 ;
6265 else if (unformat (i, "ipv6"))
6266 is_ipv6 = 1;
6267 else
6268 break;
6269 }
6270
6271 if (sw_if_index_set == 0)
6272 {
6273 errmsg ("missing interface name or sw_if_index");
6274 return -99;
6275 }
6276
6277 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006278 M (SW_INTERFACE_SET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006279
6280 mp->sw_if_index = ntohl (sw_if_index);
6281 mp->is_ipv6 = is_ipv6;
6282 mp->vrf_id = ntohl (vrf_id);
6283
6284 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006285 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006286
6287 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006288 W (ret);
6289 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006290}
6291
6292static void vl_api_sw_interface_get_table_reply_t_handler
6293 (vl_api_sw_interface_get_table_reply_t * mp)
6294{
6295 vat_main_t *vam = &vat_main;
6296
6297 print (vam->ofp, "%d", ntohl (mp->vrf_id));
6298
6299 vam->retval = ntohl (mp->retval);
6300 vam->result_ready = 1;
6301
6302}
6303
6304static void vl_api_sw_interface_get_table_reply_t_handler_json
6305 (vl_api_sw_interface_get_table_reply_t * mp)
6306{
6307 vat_main_t *vam = &vat_main;
6308 vat_json_node_t node;
6309
6310 vat_json_init_object (&node);
6311 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
6312 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
6313
6314 vat_json_print (vam->ofp, &node);
6315 vat_json_free (&node);
6316
6317 vam->retval = ntohl (mp->retval);
6318 vam->result_ready = 1;
6319}
6320
6321static int
6322api_sw_interface_get_table (vat_main_t * vam)
6323{
6324 unformat_input_t *i = vam->input;
6325 vl_api_sw_interface_get_table_t *mp;
6326 u32 sw_if_index;
6327 u8 sw_if_index_set = 0;
6328 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006329 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006330
6331 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6332 {
6333 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6334 sw_if_index_set = 1;
6335 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6336 sw_if_index_set = 1;
6337 else if (unformat (i, "ipv6"))
6338 is_ipv6 = 1;
6339 else
6340 break;
6341 }
6342
6343 if (sw_if_index_set == 0)
6344 {
6345 errmsg ("missing interface name or sw_if_index");
6346 return -99;
6347 }
6348
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006349 M (SW_INTERFACE_GET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006350 mp->sw_if_index = htonl (sw_if_index);
6351 mp->is_ipv6 = is_ipv6;
6352
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006353 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006354 W (ret);
6355 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006356}
6357
6358static int
6359api_sw_interface_set_vpath (vat_main_t * vam)
6360{
6361 unformat_input_t *i = vam->input;
6362 vl_api_sw_interface_set_vpath_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006363 u32 sw_if_index = 0;
6364 u8 sw_if_index_set = 0;
6365 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006366 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006367
6368 /* Parse args required to build the message */
6369 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6370 {
6371 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6372 sw_if_index_set = 1;
6373 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6374 sw_if_index_set = 1;
6375 else if (unformat (i, "enable"))
6376 is_enable = 1;
6377 else if (unformat (i, "disable"))
6378 is_enable = 0;
6379 else
6380 break;
6381 }
6382
6383 if (sw_if_index_set == 0)
6384 {
6385 errmsg ("missing interface name or sw_if_index");
6386 return -99;
6387 }
6388
6389 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006390 M (SW_INTERFACE_SET_VPATH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006391
6392 mp->sw_if_index = ntohl (sw_if_index);
6393 mp->enable = is_enable;
6394
6395 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006396 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006397
6398 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006399 W (ret);
6400 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006401}
6402
6403static int
6404api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
6405{
6406 unformat_input_t *i = vam->input;
6407 vl_api_sw_interface_set_vxlan_bypass_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006408 u32 sw_if_index = 0;
6409 u8 sw_if_index_set = 0;
John Lo2b81eb82017-01-30 13:12:10 -05006410 u8 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006411 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006412 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006413
6414 /* Parse args required to build the message */
6415 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6416 {
6417 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6418 sw_if_index_set = 1;
6419 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6420 sw_if_index_set = 1;
6421 else if (unformat (i, "enable"))
6422 is_enable = 1;
6423 else if (unformat (i, "disable"))
6424 is_enable = 0;
6425 else if (unformat (i, "ip4"))
6426 is_ipv6 = 0;
6427 else if (unformat (i, "ip6"))
6428 is_ipv6 = 1;
6429 else
6430 break;
6431 }
6432
6433 if (sw_if_index_set == 0)
6434 {
6435 errmsg ("missing interface name or sw_if_index");
6436 return -99;
6437 }
6438
6439 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006440 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006441
6442 mp->sw_if_index = ntohl (sw_if_index);
6443 mp->enable = is_enable;
6444 mp->is_ipv6 = is_ipv6;
6445
6446 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006447 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006448
6449 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006450 W (ret);
6451 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006452}
6453
Marco Varleseb598f1d2017-09-19 14:25:28 +02006454static int
6455api_sw_interface_set_geneve_bypass (vat_main_t * vam)
6456{
6457 unformat_input_t *i = vam->input;
6458 vl_api_sw_interface_set_geneve_bypass_t *mp;
6459 u32 sw_if_index = 0;
6460 u8 sw_if_index_set = 0;
6461 u8 is_enable = 1;
6462 u8 is_ipv6 = 0;
6463 int ret;
6464
6465 /* Parse args required to build the message */
6466 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6467 {
6468 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6469 sw_if_index_set = 1;
6470 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6471 sw_if_index_set = 1;
6472 else if (unformat (i, "enable"))
6473 is_enable = 1;
6474 else if (unformat (i, "disable"))
6475 is_enable = 0;
6476 else if (unformat (i, "ip4"))
6477 is_ipv6 = 0;
6478 else if (unformat (i, "ip6"))
6479 is_ipv6 = 1;
6480 else
6481 break;
6482 }
6483
6484 if (sw_if_index_set == 0)
6485 {
6486 errmsg ("missing interface name or sw_if_index");
6487 return -99;
6488 }
6489
6490 /* Construct the API message */
6491 M (SW_INTERFACE_SET_GENEVE_BYPASS, mp);
6492
6493 mp->sw_if_index = ntohl (sw_if_index);
6494 mp->enable = is_enable;
6495 mp->is_ipv6 = is_ipv6;
6496
6497 /* send it... */
6498 S (mp);
6499
6500 /* Wait for a reply... */
6501 W (ret);
6502 return ret;
6503}
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08006504
Damjan Marion7cd468a2016-12-19 23:05:39 +01006505static int
6506api_sw_interface_set_l2_xconnect (vat_main_t * vam)
6507{
6508 unformat_input_t *i = vam->input;
6509 vl_api_sw_interface_set_l2_xconnect_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006510 u32 rx_sw_if_index;
6511 u8 rx_sw_if_index_set = 0;
6512 u32 tx_sw_if_index;
6513 u8 tx_sw_if_index_set = 0;
6514 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006515 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006516
6517 /* Parse args required to build the message */
6518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6519 {
6520 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6521 rx_sw_if_index_set = 1;
6522 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6523 tx_sw_if_index_set = 1;
6524 else if (unformat (i, "rx"))
6525 {
6526 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6527 {
6528 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6529 &rx_sw_if_index))
6530 rx_sw_if_index_set = 1;
6531 }
6532 else
6533 break;
6534 }
6535 else if (unformat (i, "tx"))
6536 {
6537 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6538 {
6539 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6540 &tx_sw_if_index))
6541 tx_sw_if_index_set = 1;
6542 }
6543 else
6544 break;
6545 }
6546 else if (unformat (i, "enable"))
6547 enable = 1;
6548 else if (unformat (i, "disable"))
6549 enable = 0;
6550 else
6551 break;
6552 }
6553
6554 if (rx_sw_if_index_set == 0)
6555 {
6556 errmsg ("missing rx interface name or rx_sw_if_index");
6557 return -99;
6558 }
6559
6560 if (enable && (tx_sw_if_index_set == 0))
6561 {
6562 errmsg ("missing tx interface name or tx_sw_if_index");
6563 return -99;
6564 }
6565
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006566 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006567
6568 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6569 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6570 mp->enable = enable;
6571
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006572 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006573 W (ret);
6574 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006575}
6576
6577static int
6578api_sw_interface_set_l2_bridge (vat_main_t * vam)
6579{
6580 unformat_input_t *i = vam->input;
6581 vl_api_sw_interface_set_l2_bridge_t *mp;
Neale Rannsb4743802018-09-05 09:13:57 -07006582 vl_api_l2_port_type_t port_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006583 u32 rx_sw_if_index;
6584 u8 rx_sw_if_index_set = 0;
6585 u32 bd_id;
6586 u8 bd_id_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006587 u32 shg = 0;
6588 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006589 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006590
Neale Rannsb4743802018-09-05 09:13:57 -07006591 port_type = L2_API_PORT_TYPE_NORMAL;
6592
Damjan Marion7cd468a2016-12-19 23:05:39 +01006593 /* Parse args required to build the message */
6594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6595 {
6596 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
6597 rx_sw_if_index_set = 1;
6598 else if (unformat (i, "bd_id %d", &bd_id))
6599 bd_id_set = 1;
6600 else
6601 if (unformat
6602 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
6603 rx_sw_if_index_set = 1;
6604 else if (unformat (i, "shg %d", &shg))
6605 ;
6606 else if (unformat (i, "bvi"))
Neale Rannsb4743802018-09-05 09:13:57 -07006607 port_type = L2_API_PORT_TYPE_BVI;
6608 else if (unformat (i, "uu-fwd"))
6609 port_type = L2_API_PORT_TYPE_UU_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006610 else if (unformat (i, "enable"))
6611 enable = 1;
6612 else if (unformat (i, "disable"))
6613 enable = 0;
6614 else
6615 break;
6616 }
6617
6618 if (rx_sw_if_index_set == 0)
6619 {
6620 errmsg ("missing rx interface name or sw_if_index");
6621 return -99;
6622 }
6623
6624 if (enable && (bd_id_set == 0))
6625 {
6626 errmsg ("missing bridge domain");
6627 return -99;
6628 }
6629
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006630 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006631
6632 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6633 mp->bd_id = ntohl (bd_id);
6634 mp->shg = (u8) shg;
Neale Rannsb4743802018-09-05 09:13:57 -07006635 mp->port_type = ntohl (port_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006636 mp->enable = enable;
6637
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006638 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006639 W (ret);
6640 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006641}
6642
6643static int
6644api_bridge_domain_dump (vat_main_t * vam)
6645{
6646 unformat_input_t *i = vam->input;
6647 vl_api_bridge_domain_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006648 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006649 u32 bd_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006650 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006651
6652 /* Parse args required to build the message */
6653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6654 {
6655 if (unformat (i, "bd_id %d", &bd_id))
6656 ;
6657 else
6658 break;
6659 }
6660
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006661 M (BRIDGE_DOMAIN_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006662 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006663 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006664
6665 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04006666 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006667 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006668
Jon Loeliger56c7b012017-02-01 12:31:41 -06006669 W (ret);
6670 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006671}
6672
6673static int
6674api_bridge_domain_add_del (vat_main_t * vam)
6675{
6676 unformat_input_t *i = vam->input;
6677 vl_api_bridge_domain_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006678 u32 bd_id = ~0;
6679 u8 is_add = 1;
6680 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006681 u8 *bd_tag = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006682 u32 mac_age = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006683 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006684
6685 /* Parse args required to build the message */
6686 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6687 {
6688 if (unformat (i, "bd_id %d", &bd_id))
6689 ;
6690 else if (unformat (i, "flood %d", &flood))
6691 ;
6692 else if (unformat (i, "uu-flood %d", &uu_flood))
6693 ;
6694 else if (unformat (i, "forward %d", &forward))
6695 ;
6696 else if (unformat (i, "learn %d", &learn))
6697 ;
6698 else if (unformat (i, "arp-term %d", &arp_term))
6699 ;
6700 else if (unformat (i, "mac-age %d", &mac_age))
6701 ;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006702 else if (unformat (i, "bd-tag %s", &bd_tag))
6703 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006704 else if (unformat (i, "del"))
6705 {
6706 is_add = 0;
6707 flood = uu_flood = forward = learn = 0;
6708 }
6709 else
6710 break;
6711 }
6712
6713 if (bd_id == ~0)
6714 {
6715 errmsg ("missing bridge domain");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006716 ret = -99;
6717 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006718 }
6719
6720 if (mac_age > 255)
6721 {
6722 errmsg ("mac age must be less than 256 ");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006723 ret = -99;
6724 goto done;
6725 }
6726
John Lo70bfcaf2017-11-14 13:19:26 -05006727 if ((bd_tag) && (vec_len (bd_tag) > 63))
Jerome Tollet50570ec2017-09-14 12:53:56 +01006728 {
6729 errmsg ("bd-tag cannot be longer than 63");
6730 ret = -99;
6731 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006732 }
6733
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006734 M (BRIDGE_DOMAIN_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006735
6736 mp->bd_id = ntohl (bd_id);
6737 mp->flood = flood;
6738 mp->uu_flood = uu_flood;
6739 mp->forward = forward;
6740 mp->learn = learn;
6741 mp->arp_term = arp_term;
6742 mp->is_add = is_add;
6743 mp->mac_age = (u8) mac_age;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006744 if (bd_tag)
John Lo70bfcaf2017-11-14 13:19:26 -05006745 {
6746 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
6747 mp->bd_tag[vec_len (bd_tag)] = 0;
6748 }
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006749 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006750 W (ret);
Jerome Tollet50570ec2017-09-14 12:53:56 +01006751
6752done:
6753 vec_free (bd_tag);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006754 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006755}
6756
6757static int
Eyal Barif24991c2017-04-05 05:33:21 +03006758api_l2fib_flush_bd (vat_main_t * vam)
6759{
6760 unformat_input_t *i = vam->input;
6761 vl_api_l2fib_flush_bd_t *mp;
6762 u32 bd_id = ~0;
6763 int ret;
6764
6765 /* Parse args required to build the message */
6766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6767 {
6768 if (unformat (i, "bd_id %d", &bd_id));
6769 else
6770 break;
6771 }
6772
6773 if (bd_id == ~0)
6774 {
6775 errmsg ("missing bridge domain");
6776 return -99;
6777 }
6778
6779 M (L2FIB_FLUSH_BD, mp);
6780
6781 mp->bd_id = htonl (bd_id);
6782
6783 S (mp);
6784 W (ret);
6785 return ret;
6786}
6787
6788static int
6789api_l2fib_flush_int (vat_main_t * vam)
6790{
6791 unformat_input_t *i = vam->input;
6792 vl_api_l2fib_flush_int_t *mp;
6793 u32 sw_if_index = ~0;
6794 int ret;
6795
6796 /* Parse args required to build the message */
6797 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6798 {
6799 if (unformat (i, "sw_if_index %d", &sw_if_index));
6800 else
6801 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
6802 else
6803 break;
6804 }
6805
6806 if (sw_if_index == ~0)
6807 {
6808 errmsg ("missing interface name or sw_if_index");
6809 return -99;
6810 }
6811
6812 M (L2FIB_FLUSH_INT, mp);
6813
6814 mp->sw_if_index = ntohl (sw_if_index);
6815
6816 S (mp);
6817 W (ret);
6818 return ret;
6819}
6820
6821static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006822api_l2fib_add_del (vat_main_t * vam)
6823{
6824 unformat_input_t *i = vam->input;
6825 vl_api_l2fib_add_del_t *mp;
6826 f64 timeout;
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006827 u8 mac[6] = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01006828 u8 mac_set = 0;
6829 u32 bd_id;
6830 u8 bd_id_set = 0;
John Lo7dbd7262018-05-31 10:25:18 -04006831 u32 sw_if_index = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006832 u8 sw_if_index_set = 0;
6833 u8 is_add = 1;
6834 u8 static_mac = 0;
6835 u8 filter_mac = 0;
6836 u8 bvi_mac = 0;
6837 int count = 1;
6838 f64 before = 0;
6839 int j;
6840
6841 /* Parse args required to build the message */
6842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6843 {
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006844 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01006845 mac_set = 1;
6846 else if (unformat (i, "bd_id %d", &bd_id))
6847 bd_id_set = 1;
6848 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6849 sw_if_index_set = 1;
6850 else if (unformat (i, "sw_if"))
6851 {
6852 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6853 {
6854 if (unformat
6855 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6856 sw_if_index_set = 1;
6857 }
6858 else
6859 break;
6860 }
6861 else if (unformat (i, "static"))
6862 static_mac = 1;
6863 else if (unformat (i, "filter"))
6864 {
6865 filter_mac = 1;
6866 static_mac = 1;
6867 }
6868 else if (unformat (i, "bvi"))
6869 {
6870 bvi_mac = 1;
6871 static_mac = 1;
6872 }
6873 else if (unformat (i, "del"))
6874 is_add = 0;
6875 else if (unformat (i, "count %d", &count))
6876 ;
6877 else
6878 break;
6879 }
6880
6881 if (mac_set == 0)
6882 {
6883 errmsg ("missing mac address");
6884 return -99;
6885 }
6886
6887 if (bd_id_set == 0)
6888 {
6889 errmsg ("missing bridge domain");
6890 return -99;
6891 }
6892
6893 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
6894 {
6895 errmsg ("missing interface name or sw_if_index");
6896 return -99;
6897 }
6898
6899 if (count > 1)
6900 {
6901 /* Turn on async mode */
6902 vam->async_mode = 1;
6903 vam->async_errors = 0;
6904 before = vat_time_now (vam);
6905 }
6906
6907 for (j = 0; j < count; j++)
6908 {
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006909 M (L2FIB_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006910
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006911 clib_memcpy (mp->mac, mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006912 mp->bd_id = ntohl (bd_id);
6913 mp->is_add = is_add;
John Lo7dbd7262018-05-31 10:25:18 -04006914 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006915
6916 if (is_add)
6917 {
Damjan Marion7cd468a2016-12-19 23:05:39 +01006918 mp->static_mac = static_mac;
6919 mp->filter_mac = filter_mac;
6920 mp->bvi_mac = bvi_mac;
6921 }
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006922 increment_mac_address (mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006923 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006924 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006925 }
6926
6927 if (count > 1)
6928 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006929 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006930 f64 after;
6931
6932 /* Shut off async mode */
6933 vam->async_mode = 0;
6934
Dave Barach59b25652017-09-10 15:04:27 -04006935 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006936 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006937
6938 timeout = vat_time_now (vam) + 1.0;
6939 while (vat_time_now (vam) < timeout)
6940 if (vam->result_ready == 1)
6941 goto out;
6942 vam->retval = -99;
6943
6944 out:
6945 if (vam->retval == -99)
6946 errmsg ("timeout");
6947
6948 if (vam->async_errors > 0)
6949 {
6950 errmsg ("%d asynchronous errors", vam->async_errors);
6951 vam->retval = -98;
6952 }
6953 vam->async_errors = 0;
6954 after = vat_time_now (vam);
6955
6956 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6957 count, after - before, count / (after - before));
6958 }
6959 else
6960 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06006961 int ret;
6962
Damjan Marion7cd468a2016-12-19 23:05:39 +01006963 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006964 W (ret);
6965 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006966 }
6967 /* Return the good/bad news */
6968 return (vam->retval);
6969}
6970
6971static int
Eyal Barifead6702017-04-04 04:46:32 +03006972api_bridge_domain_set_mac_age (vat_main_t * vam)
6973{
6974 unformat_input_t *i = vam->input;
6975 vl_api_bridge_domain_set_mac_age_t *mp;
6976 u32 bd_id = ~0;
6977 u32 mac_age = 0;
6978 int ret;
6979
6980 /* Parse args required to build the message */
6981 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6982 {
6983 if (unformat (i, "bd_id %d", &bd_id));
6984 else if (unformat (i, "mac-age %d", &mac_age));
6985 else
6986 break;
6987 }
6988
6989 if (bd_id == ~0)
6990 {
6991 errmsg ("missing bridge domain");
6992 return -99;
6993 }
6994
6995 if (mac_age > 255)
6996 {
6997 errmsg ("mac age must be less than 256 ");
6998 return -99;
6999 }
7000
7001 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
7002
7003 mp->bd_id = htonl (bd_id);
7004 mp->mac_age = (u8) mac_age;
7005
7006 S (mp);
7007 W (ret);
7008 return ret;
7009}
7010
7011static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01007012api_l2_flags (vat_main_t * vam)
7013{
7014 unformat_input_t *i = vam->input;
7015 vl_api_l2_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007016 u32 sw_if_index;
John Lo8d00fff2017-08-03 00:35:36 -04007017 u32 flags = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007018 u8 sw_if_index_set = 0;
John Lo8d00fff2017-08-03 00:35:36 -04007019 u8 is_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007020 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007021
7022 /* Parse args required to build the message */
7023 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7024 {
7025 if (unformat (i, "sw_if_index %d", &sw_if_index))
7026 sw_if_index_set = 1;
7027 else if (unformat (i, "sw_if"))
7028 {
7029 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7030 {
7031 if (unformat
7032 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7033 sw_if_index_set = 1;
7034 }
7035 else
7036 break;
7037 }
7038 else if (unformat (i, "learn"))
John Lo8d00fff2017-08-03 00:35:36 -04007039 flags |= L2_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007040 else if (unformat (i, "forward"))
John Lo8d00fff2017-08-03 00:35:36 -04007041 flags |= L2_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007042 else if (unformat (i, "flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007043 flags |= L2_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007044 else if (unformat (i, "uu-flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007045 flags |= L2_UU_FLOOD;
7046 else if (unformat (i, "arp-term"))
7047 flags |= L2_ARP_TERM;
7048 else if (unformat (i, "off"))
7049 is_set = 0;
7050 else if (unformat (i, "disable"))
7051 is_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007052 else
7053 break;
7054 }
7055
7056 if (sw_if_index_set == 0)
7057 {
7058 errmsg ("missing interface name or sw_if_index");
7059 return -99;
7060 }
7061
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007062 M (L2_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007063
7064 mp->sw_if_index = ntohl (sw_if_index);
John Lo8d00fff2017-08-03 00:35:36 -04007065 mp->feature_bitmap = ntohl (flags);
7066 mp->is_set = is_set;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007067
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007068 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007069 W (ret);
7070 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007071}
7072
7073static int
7074api_bridge_flags (vat_main_t * vam)
7075{
7076 unformat_input_t *i = vam->input;
7077 vl_api_bridge_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007078 u32 bd_id;
7079 u8 bd_id_set = 0;
7080 u8 is_set = 1;
Neale Rannsb4743802018-09-05 09:13:57 -07007081 bd_flags_t flags = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007082 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007083
7084 /* Parse args required to build the message */
7085 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7086 {
7087 if (unformat (i, "bd_id %d", &bd_id))
7088 bd_id_set = 1;
7089 else if (unformat (i, "learn"))
Neale Rannsb4743802018-09-05 09:13:57 -07007090 flags |= BRIDGE_API_FLAG_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007091 else if (unformat (i, "forward"))
Neale Rannsb4743802018-09-05 09:13:57 -07007092 flags |= BRIDGE_API_FLAG_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007093 else if (unformat (i, "flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007094 flags |= BRIDGE_API_FLAG_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007095 else if (unformat (i, "uu-flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007096 flags |= BRIDGE_API_FLAG_UU_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007097 else if (unformat (i, "arp-term"))
Neale Rannsb4743802018-09-05 09:13:57 -07007098 flags |= BRIDGE_API_FLAG_ARP_TERM;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007099 else if (unformat (i, "off"))
7100 is_set = 0;
7101 else if (unformat (i, "disable"))
7102 is_set = 0;
7103 else
7104 break;
7105 }
7106
7107 if (bd_id_set == 0)
7108 {
7109 errmsg ("missing bridge domain");
7110 return -99;
7111 }
7112
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007113 M (BRIDGE_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007114
7115 mp->bd_id = ntohl (bd_id);
Neale Rannsb4743802018-09-05 09:13:57 -07007116 mp->flags = ntohl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007117 mp->is_set = is_set;
7118
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007119 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007120 W (ret);
7121 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007122}
7123
7124static int
7125api_bd_ip_mac_add_del (vat_main_t * vam)
7126{
Neale Ranns4d5b9172018-10-24 02:57:49 -07007127 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
Ole Troan8006c6a2018-12-17 12:02:26 +01007128 vl_api_mac_address_t mac = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01007129 unformat_input_t *i = vam->input;
7130 vl_api_bd_ip_mac_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007131 u32 bd_id;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007132 u8 is_add = 1;
7133 u8 bd_id_set = 0;
7134 u8 ip_set = 0;
7135 u8 mac_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007136 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007137
7138
7139 /* Parse args required to build the message */
7140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7141 {
7142 if (unformat (i, "bd_id %d", &bd_id))
7143 {
7144 bd_id_set++;
7145 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007146 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007147 {
7148 ip_set++;
7149 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007150 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007151 {
7152 mac_set++;
7153 }
7154 else if (unformat (i, "del"))
7155 is_add = 0;
7156 else
7157 break;
7158 }
7159
7160 if (bd_id_set == 0)
7161 {
7162 errmsg ("missing bridge domain");
7163 return -99;
7164 }
7165 else if (ip_set == 0)
7166 {
7167 errmsg ("missing IP address");
7168 return -99;
7169 }
7170 else if (mac_set == 0)
7171 {
7172 errmsg ("missing MAC address");
7173 return -99;
7174 }
7175
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007176 M (BD_IP_MAC_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007177
Neale Rannsbc764c82019-06-19 07:07:13 -07007178 mp->entry.bd_id = ntohl (bd_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007179 mp->is_add = is_add;
Neale Ranns4d5b9172018-10-24 02:57:49 -07007180
Neale Rannsbc764c82019-06-19 07:07:13 -07007181 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
7182 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
Neale Ranns4d5b9172018-10-24 02:57:49 -07007183
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007184 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007185 W (ret);
7186 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007187}
7188
John Loe26c81f2019-01-07 15:16:33 -05007189static int
7190api_bd_ip_mac_flush (vat_main_t * vam)
7191{
7192 unformat_input_t *i = vam->input;
7193 vl_api_bd_ip_mac_flush_t *mp;
7194 u32 bd_id;
7195 u8 bd_id_set = 0;
7196 int ret;
7197
7198 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7199 {
7200 if (unformat (i, "bd_id %d", &bd_id))
7201 {
7202 bd_id_set++;
7203 }
7204 else
7205 break;
7206 }
7207
7208 if (bd_id_set == 0)
7209 {
7210 errmsg ("missing bridge domain");
7211 return -99;
7212 }
7213
7214 M (BD_IP_MAC_FLUSH, mp);
7215
7216 mp->bd_id = ntohl (bd_id);
7217
7218 S (mp);
7219 W (ret);
7220 return ret;
7221}
7222
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007223static void vl_api_bd_ip_mac_details_t_handler
7224 (vl_api_bd_ip_mac_details_t * mp)
7225{
7226 vat_main_t *vam = &vat_main;
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007227
7228 print (vam->ofp,
Neale Rannsbc764c82019-06-19 07:07:13 -07007229 "\n%-5d %U %U",
7230 ntohl (mp->entry.bd_id),
7231 format_vl_api_mac_address, mp->entry.mac,
7232 format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007233}
7234
7235static void vl_api_bd_ip_mac_details_t_handler_json
7236 (vl_api_bd_ip_mac_details_t * mp)
7237{
7238 vat_main_t *vam = &vat_main;
7239 vat_json_node_t *node = NULL;
7240
7241 if (VAT_JSON_ARRAY != vam->json_tree.type)
7242 {
7243 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7244 vat_json_init_array (&vam->json_tree);
7245 }
7246 node = vat_json_array_add (&vam->json_tree);
7247
7248 vat_json_init_object (node);
Neale Rannsbc764c82019-06-19 07:07:13 -07007249 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007250 vat_json_object_add_string_copy (node, "mac_address",
Neale Rannsbc764c82019-06-19 07:07:13 -07007251 format (0, "%U", format_vl_api_mac_address,
7252 &mp->entry.mac));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007253 u8 *ip = 0;
7254
Neale Rannsbc764c82019-06-19 07:07:13 -07007255 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007256 vat_json_object_add_string_copy (node, "ip_address", ip);
7257 vec_free (ip);
7258}
7259
7260static int
7261api_bd_ip_mac_dump (vat_main_t * vam)
7262{
7263 unformat_input_t *i = vam->input;
7264 vl_api_bd_ip_mac_dump_t *mp;
7265 vl_api_control_ping_t *mp_ping;
7266 int ret;
7267 u32 bd_id;
7268 u8 bd_id_set = 0;
7269
7270 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7271 {
7272 if (unformat (i, "bd_id %d", &bd_id))
7273 {
7274 bd_id_set++;
7275 }
7276 else
7277 break;
7278 }
7279
7280 print (vam->ofp,
7281 "\n%-5s %-7s %-20s %-30s",
7282 "bd_id", "is_ipv6", "mac_address", "ip_address");
7283
7284 /* Dump Bridge Domain Ip to Mac entries */
7285 M (BD_IP_MAC_DUMP, mp);
7286
7287 if (bd_id_set)
7288 mp->bd_id = htonl (bd_id);
7289 else
7290 mp->bd_id = ~0;
7291
7292 S (mp);
7293
7294 /* Use a control ping for synchronization */
7295 MPING (CONTROL_PING, mp_ping);
7296 S (mp_ping);
7297
7298 W (ret);
7299 return ret;
7300}
7301
Damjan Marion7cd468a2016-12-19 23:05:39 +01007302static int
Damjan Marion8389fb92017-10-13 18:29:53 +02007303api_tap_create_v2 (vat_main_t * vam)
7304{
7305 unformat_input_t *i = vam->input;
7306 vl_api_tap_create_v2_t *mp;
7307 u8 mac_address[6];
7308 u8 random_mac = 1;
Damjan Marion2df39092017-12-04 20:03:37 +01007309 u32 id = ~0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007310 u32 num_rx_queues = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007311 u8 *host_if_name = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007312 u8 host_if_name_set = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007313 u8 *host_ns = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007314 u8 host_ns_set = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007315 u8 host_mac_addr[6];
7316 u8 host_mac_addr_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007317 u8 *host_bridge = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007318 u8 host_bridge_set = 0;
7319 u8 host_ip4_prefix_set = 0;
7320 u8 host_ip6_prefix_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007321 ip4_address_t host_ip4_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007322 ip4_address_t host_ip4_gw;
7323 u8 host_ip4_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007324 u32 host_ip4_prefix_len = 0;
7325 ip6_address_t host_ip6_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007326 ip6_address_t host_ip6_gw;
7327 u8 host_ip6_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007328 u32 host_ip6_prefix_len = 0;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007329 u32 host_mtu_size = 0;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007330 u8 host_mtu_set = 0;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007331 u32 tap_flags = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007332 int ret;
Steven9e635692018-03-01 09:36:01 -08007333 u32 rx_ring_sz = 0, tx_ring_sz = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007334
Dave Barachb7b92992018-10-17 10:38:51 -04007335 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion8389fb92017-10-13 18:29:53 +02007336
7337 /* Parse args required to build the message */
7338 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7339 {
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007340 if (unformat (i, "id %u", &id))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007341 ;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007342 else
7343 if (unformat
7344 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7345 random_mac = 0;
Damjan Marion2df39092017-12-04 20:03:37 +01007346 else if (unformat (i, "host-if-name %s", &host_if_name))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007347 host_if_name_set = 1;
7348 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007349 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007350 else if (unformat (i, "host-ns %s", &host_ns))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007351 host_ns_set = 1;
Damjan Marion2df39092017-12-04 20:03:37 +01007352 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
7353 host_mac_addr))
7354 host_mac_addr_set = 1;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007355 else if (unformat (i, "host-bridge %s", &host_bridge))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007356 host_bridge_set = 1;
7357 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
Damjan Marion91c6ef72017-12-01 13:34:24 +01007358 &host_ip4_addr, &host_ip4_prefix_len))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007359 host_ip4_prefix_set = 1;
7360 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
Damjan Marion91c6ef72017-12-01 13:34:24 +01007361 &host_ip6_addr, &host_ip6_prefix_len))
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007362 host_ip6_prefix_set = 1;
Damjan Marion7866c452018-01-18 13:35:11 +01007363 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
7364 &host_ip4_gw))
7365 host_ip4_gw_set = 1;
7366 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
7367 &host_ip6_gw))
7368 host_ip6_gw_set = 1;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007369 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
Damjan Marion8389fb92017-10-13 18:29:53 +02007370 ;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007371 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
Damjan Marion8389fb92017-10-13 18:29:53 +02007372 ;
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007373 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007374 host_mtu_set = 1;
7375 else if (unformat (i, "no-gso"))
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +02007376 tap_flags &= ~TAP_API_FLAG_GSO;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007377 else if (unformat (i, "gso"))
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +02007378 tap_flags |= TAP_API_FLAG_GSO;
Mohsin Kazmiba0061f2019-12-18 17:08:54 +01007379 else if (unformat (i, "csum-offload"))
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +02007380 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
Mohsin Kazmib49bc1a2020-02-14 17:51:04 +00007381 else if (unformat (i, "persist"))
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +02007382 tap_flags |= TAP_API_FLAG_PERSIST;
Mohsin Kazmib49bc1a2020-02-14 17:51:04 +00007383 else if (unformat (i, "attach"))
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +02007384 tap_flags |= TAP_API_FLAG_ATTACH;
7385 else if (unformat (i, "tun"))
7386 tap_flags |= TAP_API_FLAG_TUN;
7387 else if (unformat (i, "gro-coalesce"))
7388 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
Damjan Marion8389fb92017-10-13 18:29:53 +02007389 else
7390 break;
7391 }
7392
Damjan Marion2df39092017-12-04 20:03:37 +01007393 if (vec_len (host_if_name) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007394 {
7395 errmsg ("tap name too long. ");
7396 return -99;
7397 }
Damjan Marion2df39092017-12-04 20:03:37 +01007398 if (vec_len (host_ns) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007399 {
7400 errmsg ("host name space too long. ");
7401 return -99;
7402 }
Damjan Marion91c6ef72017-12-01 13:34:24 +01007403 if (vec_len (host_bridge) > 63)
7404 {
7405 errmsg ("host bridge name too long. ");
7406 return -99;
7407 }
7408 if (host_ip4_prefix_len > 32)
7409 {
7410 errmsg ("host ip4 prefix length not valid. ");
7411 return -99;
7412 }
7413 if (host_ip6_prefix_len > 128)
7414 {
7415 errmsg ("host ip6 prefix length not valid. ");
7416 return -99;
7417 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007418 if (!is_pow2 (rx_ring_sz))
7419 {
7420 errmsg ("rx ring size must be power of 2. ");
7421 return -99;
7422 }
7423 if (rx_ring_sz > 32768)
7424 {
7425 errmsg ("rx ring size must be 32768 or lower. ");
7426 return -99;
7427 }
7428 if (!is_pow2 (tx_ring_sz))
7429 {
7430 errmsg ("tx ring size must be power of 2. ");
7431 return -99;
7432 }
7433 if (tx_ring_sz > 32768)
7434 {
7435 errmsg ("tx ring size must be 32768 or lower. ");
7436 return -99;
7437 }
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007438 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
7439 {
7440 errmsg ("host MTU size must be in between 64 and 65355. ");
7441 return -99;
7442 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007443
Damjan Marion8389fb92017-10-13 18:29:53 +02007444 /* Construct the API message */
7445 M (TAP_CREATE_V2, mp);
7446
Steven9e635692018-03-01 09:36:01 -08007447 mp->id = ntohl (id);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007448 mp->use_random_mac = random_mac;
7449 mp->num_rx_queues = (u8) num_rx_queues;
Steven9e635692018-03-01 09:36:01 -08007450 mp->tx_ring_sz = ntohs (tx_ring_sz);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007451 mp->rx_ring_sz = ntohs (rx_ring_sz);
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007452 mp->host_mtu_set = host_mtu_set;
7453 mp->host_mtu_size = ntohl (host_mtu_size);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007454 mp->host_mac_addr_set = host_mac_addr_set;
7455 mp->host_ip4_prefix_set = host_ip4_prefix_set;
7456 mp->host_ip6_prefix_set = host_ip6_prefix_set;
7457 mp->host_ip4_gw_set = host_ip4_gw_set;
7458 mp->host_ip6_gw_set = host_ip6_gw_set;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +02007459 mp->tap_flags = ntohl (tap_flags);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007460 mp->host_namespace_set = host_ns_set;
7461 mp->host_if_name_set = host_if_name_set;
7462 mp->host_bridge_set = host_bridge_set;
Damjan Marion2df39092017-12-04 20:03:37 +01007463
Steven9e635692018-03-01 09:36:01 -08007464 if (random_mac == 0)
Damjan Marion2df39092017-12-04 20:03:37 +01007465 clib_memcpy (mp->mac_address, mac_address, 6);
7466 if (host_mac_addr_set)
7467 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007468 if (host_if_name_set)
Damjan Marion2df39092017-12-04 20:03:37 +01007469 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007470 if (host_ns_set)
Damjan Marion2df39092017-12-04 20:03:37 +01007471 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007472 if (host_bridge_set)
Damjan Marion91c6ef72017-12-01 13:34:24 +01007473 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
Mohsin Kazmi9f32b6a2020-02-14 12:09:04 +00007474 if (host_ip4_prefix_set)
7475 {
7476 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
7477 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
7478 }
7479 if (host_ip6_prefix_set)
7480 {
7481 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
7482 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
7483 }
Damjan Marion7866c452018-01-18 13:35:11 +01007484 if (host_ip4_gw_set)
7485 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
7486 if (host_ip6_gw_set)
7487 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
Damjan Marion8389fb92017-10-13 18:29:53 +02007488
Damjan Marion2df39092017-12-04 20:03:37 +01007489 vec_free (host_ns);
7490 vec_free (host_if_name);
7491 vec_free (host_bridge);
Damjan Marion8389fb92017-10-13 18:29:53 +02007492
7493 /* send it... */
7494 S (mp);
7495
7496 /* Wait for a reply... */
7497 W (ret);
7498 return ret;
7499}
7500
7501static int
7502api_tap_delete_v2 (vat_main_t * vam)
7503{
7504 unformat_input_t *i = vam->input;
7505 vl_api_tap_delete_v2_t *mp;
7506 u32 sw_if_index = ~0;
7507 u8 sw_if_index_set = 0;
7508 int ret;
7509
7510 /* Parse args required to build the message */
7511 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7512 {
7513 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7514 sw_if_index_set = 1;
7515 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7516 sw_if_index_set = 1;
7517 else
7518 break;
7519 }
7520
7521 if (sw_if_index_set == 0)
7522 {
7523 errmsg ("missing vpp interface name. ");
7524 return -99;
7525 }
7526
7527 /* Construct the API message */
7528 M (TAP_DELETE_V2, mp);
7529
7530 mp->sw_if_index = ntohl (sw_if_index);
7531
7532 /* send it... */
7533 S (mp);
7534
7535 /* Wait for a reply... */
7536 W (ret);
7537 return ret;
7538}
7539
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007540uword
jialv01082ebeb2019-09-10 00:23:55 +08007541unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007542{
jialv01082ebeb2019-09-10 00:23:55 +08007543 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007544 u32 x[4];
7545
7546 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
7547 return 0;
7548
7549 addr->domain = x[0];
7550 addr->bus = x[1];
7551 addr->slot = x[2];
7552 addr->function = x[3];
7553
7554 return 1;
7555}
7556
7557static int
7558api_virtio_pci_create (vat_main_t * vam)
7559{
7560 unformat_input_t *i = vam->input;
7561 vl_api_virtio_pci_create_t *mp;
7562 u8 mac_address[6];
7563 u8 random_mac = 1;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007564 u8 gso_enabled = 0;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +00007565 u8 checksum_offload_enabled = 0;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007566 u32 pci_addr = 0;
7567 u64 features = (u64) ~ (0ULL);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007568 int ret;
7569
7570 clib_memset (mac_address, 0, sizeof (mac_address));
7571
7572 /* Parse args required to build the message */
7573 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7574 {
7575 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7576 {
7577 random_mac = 0;
7578 }
jialv01082ebeb2019-09-10 00:23:55 +08007579 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007580 ;
7581 else if (unformat (i, "features 0x%llx", &features))
7582 ;
Mohsin Kazmibbd6b742019-05-02 13:54:59 +02007583 else if (unformat (i, "gso-enabled"))
7584 gso_enabled = 1;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +00007585 else if (unformat (i, "csum-offload-enabled"))
7586 checksum_offload_enabled = 1;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007587 else
7588 break;
7589 }
7590
7591 if (pci_addr == 0)
7592 {
7593 errmsg ("pci address must be non zero. ");
7594 return -99;
7595 }
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007596
7597 /* Construct the API message */
7598 M (VIRTIO_PCI_CREATE, mp);
7599
7600 mp->use_random_mac = random_mac;
7601
Jakub Grajciar2c504f82019-09-26 10:34:41 +02007602 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
7603 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
7604 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
7605 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
7606
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007607 mp->features = clib_host_to_net_u64 (features);
Benoît Ganne49ee6842019-04-30 11:50:46 +02007608 mp->gso_enabled = gso_enabled;
Mohsin Kazmi6d4af892020-01-03 15:11:53 +00007609 mp->checksum_offload_enabled = checksum_offload_enabled;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007610
7611 if (random_mac == 0)
7612 clib_memcpy (mp->mac_address, mac_address, 6);
7613
7614 /* send it... */
7615 S (mp);
7616
7617 /* Wait for a reply... */
7618 W (ret);
7619 return ret;
7620}
7621
7622static int
7623api_virtio_pci_delete (vat_main_t * vam)
7624{
7625 unformat_input_t *i = vam->input;
7626 vl_api_virtio_pci_delete_t *mp;
7627 u32 sw_if_index = ~0;
7628 u8 sw_if_index_set = 0;
7629 int ret;
7630
7631 /* Parse args required to build the message */
7632 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7633 {
7634 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7635 sw_if_index_set = 1;
7636 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7637 sw_if_index_set = 1;
7638 else
7639 break;
7640 }
7641
7642 if (sw_if_index_set == 0)
7643 {
7644 errmsg ("missing vpp interface name. ");
7645 return -99;
7646 }
7647
7648 /* Construct the API message */
7649 M (VIRTIO_PCI_DELETE, mp);
7650
7651 mp->sw_if_index = htonl (sw_if_index);
7652
7653 /* send it... */
7654 S (mp);
7655
7656 /* Wait for a reply... */
7657 W (ret);
7658 return ret;
7659}
7660
Damjan Marion8389fb92017-10-13 18:29:53 +02007661static int
Steven9cd2d7a2017-12-20 12:43:01 -08007662api_bond_create (vat_main_t * vam)
7663{
7664 unformat_input_t *i = vam->input;
7665 vl_api_bond_create_t *mp;
7666 u8 mac_address[6];
7667 u8 custom_mac = 0;
7668 int ret;
7669 u8 mode;
7670 u8 lb;
7671 u8 mode_is_set = 0;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007672 u32 id = ~0;
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007673 u8 numa_only = 0;
Steven9cd2d7a2017-12-20 12:43:01 -08007674
Dave Barachb7b92992018-10-17 10:38:51 -04007675 clib_memset (mac_address, 0, sizeof (mac_address));
Steven9cd2d7a2017-12-20 12:43:01 -08007676 lb = BOND_LB_L2;
7677
7678 /* Parse args required to build the message */
7679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7680 {
7681 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
7682 mode_is_set = 1;
7683 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
7684 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
7685 ;
7686 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
7687 mac_address))
7688 custom_mac = 1;
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007689 else if (unformat (i, "numa-only"))
7690 numa_only = 1;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007691 else if (unformat (i, "id %u", &id))
7692 ;
Steven9cd2d7a2017-12-20 12:43:01 -08007693 else
7694 break;
7695 }
7696
7697 if (mode_is_set == 0)
7698 {
7699 errmsg ("Missing bond mode. ");
7700 return -99;
7701 }
7702
7703 /* Construct the API message */
7704 M (BOND_CREATE, mp);
7705
7706 mp->use_custom_mac = custom_mac;
7707
Jakub Grajciar3d1ef872019-08-26 12:55:15 +02007708 mp->mode = htonl (mode);
7709 mp->lb = htonl (lb);
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007710 mp->id = htonl (id);
Zhiyong Yang751e3f32019-06-26 05:49:14 -04007711 mp->numa_only = numa_only;
Steven9cd2d7a2017-12-20 12:43:01 -08007712
7713 if (custom_mac)
7714 clib_memcpy (mp->mac_address, mac_address, 6);
7715
7716 /* send it... */
7717 S (mp);
7718
7719 /* Wait for a reply... */
7720 W (ret);
7721 return ret;
7722}
7723
7724static int
7725api_bond_delete (vat_main_t * vam)
7726{
7727 unformat_input_t *i = vam->input;
7728 vl_api_bond_delete_t *mp;
7729 u32 sw_if_index = ~0;
7730 u8 sw_if_index_set = 0;
7731 int ret;
7732
7733 /* Parse args required to build the message */
7734 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7735 {
7736 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7737 sw_if_index_set = 1;
7738 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7739 sw_if_index_set = 1;
7740 else
7741 break;
7742 }
7743
7744 if (sw_if_index_set == 0)
7745 {
7746 errmsg ("missing vpp interface name. ");
7747 return -99;
7748 }
7749
7750 /* Construct the API message */
7751 M (BOND_DELETE, mp);
7752
7753 mp->sw_if_index = ntohl (sw_if_index);
7754
7755 /* send it... */
7756 S (mp);
7757
7758 /* Wait for a reply... */
7759 W (ret);
7760 return ret;
7761}
7762
7763static int
Steven Luong4c4223e2020-07-15 08:44:54 -07007764api_bond_add_member (vat_main_t * vam)
Steven9cd2d7a2017-12-20 12:43:01 -08007765{
7766 unformat_input_t *i = vam->input;
Steven Luong4c4223e2020-07-15 08:44:54 -07007767 vl_api_bond_add_member_t *mp;
Steven9cd2d7a2017-12-20 12:43:01 -08007768 u32 bond_sw_if_index;
7769 int ret;
7770 u8 is_passive;
7771 u8 is_long_timeout;
7772 u32 bond_sw_if_index_is_set = 0;
7773 u32 sw_if_index;
7774 u8 sw_if_index_is_set = 0;
7775
7776 /* Parse args required to build the message */
7777 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7778 {
7779 if (unformat (i, "sw_if_index %d", &sw_if_index))
7780 sw_if_index_is_set = 1;
7781 else if (unformat (i, "bond %u", &bond_sw_if_index))
7782 bond_sw_if_index_is_set = 1;
7783 else if (unformat (i, "passive %d", &is_passive))
7784 ;
7785 else if (unformat (i, "long-timeout %d", &is_long_timeout))
7786 ;
7787 else
7788 break;
7789 }
7790
7791 if (bond_sw_if_index_is_set == 0)
7792 {
7793 errmsg ("Missing bond sw_if_index. ");
7794 return -99;
7795 }
7796 if (sw_if_index_is_set == 0)
7797 {
Steven Luong4c4223e2020-07-15 08:44:54 -07007798 errmsg ("Missing member sw_if_index. ");
Steven9cd2d7a2017-12-20 12:43:01 -08007799 return -99;
7800 }
7801
7802 /* Construct the API message */
Steven Luong4c4223e2020-07-15 08:44:54 -07007803 M (BOND_ADD_MEMBER, mp);
Steven9cd2d7a2017-12-20 12:43:01 -08007804
7805 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
7806 mp->sw_if_index = ntohl (sw_if_index);
7807 mp->is_long_timeout = is_long_timeout;
7808 mp->is_passive = is_passive;
7809
7810 /* send it... */
7811 S (mp);
7812
7813 /* Wait for a reply... */
7814 W (ret);
7815 return ret;
7816}
7817
7818static int
Steven Luong4c4223e2020-07-15 08:44:54 -07007819api_bond_detach_member (vat_main_t * vam)
Steven9cd2d7a2017-12-20 12:43:01 -08007820{
7821 unformat_input_t *i = vam->input;
Steven Luong4c4223e2020-07-15 08:44:54 -07007822 vl_api_bond_detach_member_t *mp;
Steven9cd2d7a2017-12-20 12:43:01 -08007823 u32 sw_if_index = ~0;
7824 u8 sw_if_index_set = 0;
7825 int ret;
7826
7827 /* Parse args required to build the message */
7828 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7829 {
7830 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7831 sw_if_index_set = 1;
7832 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7833 sw_if_index_set = 1;
7834 else
7835 break;
7836 }
7837
7838 if (sw_if_index_set == 0)
7839 {
7840 errmsg ("missing vpp interface name. ");
7841 return -99;
7842 }
7843
7844 /* Construct the API message */
Steven Luong4c4223e2020-07-15 08:44:54 -07007845 M (BOND_DETACH_MEMBER, mp);
Steven9cd2d7a2017-12-20 12:43:01 -08007846
7847 mp->sw_if_index = ntohl (sw_if_index);
7848
7849 /* send it... */
7850 S (mp);
7851
7852 /* Wait for a reply... */
7853 W (ret);
7854 return ret;
7855}
7856
7857static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007858api_ip_table_add_del (vat_main_t * vam)
7859{
7860 unformat_input_t *i = vam->input;
7861 vl_api_ip_table_add_del_t *mp;
7862 u32 table_id = ~0;
7863 u8 is_ipv6 = 0;
7864 u8 is_add = 1;
7865 int ret = 0;
7866
7867 /* Parse args required to build the message */
7868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7869 {
7870 if (unformat (i, "ipv6"))
7871 is_ipv6 = 1;
7872 else if (unformat (i, "del"))
7873 is_add = 0;
7874 else if (unformat (i, "add"))
7875 is_add = 1;
7876 else if (unformat (i, "table %d", &table_id))
7877 ;
7878 else
7879 {
7880 clib_warning ("parse error '%U'", format_unformat_error, i);
7881 return -99;
7882 }
7883 }
7884
7885 if (~0 == table_id)
7886 {
7887 errmsg ("missing table-ID");
7888 return -99;
7889 }
7890
7891 /* Construct the API message */
7892 M (IP_TABLE_ADD_DEL, mp);
7893
Neale Ranns097fa662018-05-01 05:17:55 -07007894 mp->table.table_id = ntohl (table_id);
7895 mp->table.is_ip6 = is_ipv6;
Neale Ranns28ab9cc2017-08-14 07:18:42 -07007896 mp->is_add = is_add;
7897
7898 /* send it... */
7899 S (mp);
7900
7901 /* Wait for a reply... */
7902 W (ret);
7903
7904 return ret;
7905}
7906
Neale Ranns097fa662018-05-01 05:17:55 -07007907uword
7908unformat_fib_path (unformat_input_t * input, va_list * args)
7909{
7910 vat_main_t *vam = va_arg (*args, vat_main_t *);
7911 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
7912 u32 weight, preference;
7913 mpls_label_t out_label;
7914
7915 clib_memset (path, 0, sizeof (*path));
7916 path->weight = 1;
7917 path->sw_if_index = ~0;
7918 path->rpf_id = ~0;
7919 path->n_labels = 0;
7920
7921 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7922 {
7923 if (unformat (input, "%U %U",
7924 unformat_vl_api_ip4_address,
7925 &path->nh.address.ip4,
7926 api_unformat_sw_if_index, vam, &path->sw_if_index))
7927 {
7928 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7929 }
7930 else if (unformat (input, "%U %U",
7931 unformat_vl_api_ip6_address,
7932 &path->nh.address.ip6,
7933 api_unformat_sw_if_index, vam, &path->sw_if_index))
7934 {
7935 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7936 }
7937 else if (unformat (input, "weight %u", &weight))
7938 {
7939 path->weight = weight;
7940 }
7941 else if (unformat (input, "preference %u", &preference))
7942 {
7943 path->preference = preference;
7944 }
7945 else if (unformat (input, "%U next-hop-table %d",
7946 unformat_vl_api_ip4_address,
7947 &path->nh.address.ip4, &path->table_id))
7948 {
7949 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7950 }
7951 else if (unformat (input, "%U next-hop-table %d",
7952 unformat_vl_api_ip6_address,
7953 &path->nh.address.ip6, &path->table_id))
7954 {
7955 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7956 }
7957 else if (unformat (input, "%U",
7958 unformat_vl_api_ip4_address, &path->nh.address.ip4))
7959 {
7960 /*
7961 * the recursive next-hops are by default in the default table
7962 */
7963 path->table_id = 0;
7964 path->sw_if_index = ~0;
7965 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7966 }
7967 else if (unformat (input, "%U",
7968 unformat_vl_api_ip6_address, &path->nh.address.ip6))
7969 {
7970 /*
7971 * the recursive next-hops are by default in the default table
7972 */
7973 path->table_id = 0;
7974 path->sw_if_index = ~0;
7975 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7976 }
7977 else if (unformat (input, "resolve-via-host"))
7978 {
7979 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
7980 }
7981 else if (unformat (input, "resolve-via-attached"))
7982 {
7983 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
7984 }
7985 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
7986 {
7987 path->type = FIB_API_PATH_TYPE_LOCAL;
7988 path->sw_if_index = ~0;
7989 path->proto = FIB_API_PATH_NH_PROTO_IP4;
7990 }
7991 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
7992 {
7993 path->type = FIB_API_PATH_TYPE_LOCAL;
7994 path->sw_if_index = ~0;
7995 path->proto = FIB_API_PATH_NH_PROTO_IP6;
7996 }
7997 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
7998 ;
7999 else if (unformat (input, "via-label %d", &path->nh.via_label))
8000 {
8001 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
8002 path->sw_if_index = ~0;
8003 }
8004 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
8005 {
8006 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
8007 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
8008 }
8009 else if (unformat (input, "local"))
8010 {
8011 path->type = FIB_API_PATH_TYPE_LOCAL;
8012 }
8013 else if (unformat (input, "out-labels"))
8014 {
8015 while (unformat (input, "%d", &out_label))
8016 {
8017 path->label_stack[path->n_labels].label = out_label;
8018 path->label_stack[path->n_labels].is_uniform = 0;
8019 path->label_stack[path->n_labels].ttl = 64;
8020 path->n_labels++;
8021 }
8022 }
8023 else if (unformat (input, "via"))
8024 {
8025 /* new path, back up and return */
8026 unformat_put_input (input);
8027 unformat_put_input (input);
8028 unformat_put_input (input);
8029 unformat_put_input (input);
8030 break;
8031 }
8032 else
8033 {
8034 return (0);
8035 }
8036 }
8037
8038 path->proto = ntohl (path->proto);
8039 path->type = ntohl (path->type);
8040 path->flags = ntohl (path->flags);
8041 path->table_id = ntohl (path->table_id);
8042 path->sw_if_index = ntohl (path->sw_if_index);
8043
8044 return (1);
8045}
8046
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008047static int
Neale Ranns097fa662018-05-01 05:17:55 -07008048api_ip_route_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008049{
8050 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008051 vl_api_ip_route_add_del_t *mp;
8052 u32 vrf_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008053 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008054 u8 is_multipath = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008055 u8 prefix_set = 0;
8056 u8 path_count = 0;
8057 vl_api_prefix_t pfx = { };
8058 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008059 int count = 1;
8060 int j;
8061 f64 before = 0;
8062 u32 random_add_del = 0;
8063 u32 *random_vector = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008064 u32 random_seed = 0xdeaddabe;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008065
8066 /* Parse args required to build the message */
8067 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8068 {
Neale Ranns097fa662018-05-01 05:17:55 -07008069 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8070 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008071 else if (unformat (i, "del"))
8072 is_add = 0;
8073 else if (unformat (i, "add"))
8074 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008075 else if (unformat (i, "vrf %d", &vrf_id))
8076 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008077 else if (unformat (i, "count %d", &count))
8078 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008079 else if (unformat (i, "random"))
8080 random_add_del = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008081 else if (unformat (i, "multipath"))
8082 is_multipath = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008083 else if (unformat (i, "seed %d", &random_seed))
8084 ;
8085 else
Neale Ranns097fa662018-05-01 05:17:55 -07008086 if (unformat
8087 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
8088 {
8089 path_count++;
8090 if (8 == path_count)
8091 {
8092 errmsg ("max 8 paths");
8093 return -99;
8094 }
8095 }
8096 else
Damjan Marion7cd468a2016-12-19 23:05:39 +01008097 {
8098 clib_warning ("parse error '%U'", format_unformat_error, i);
8099 return -99;
8100 }
8101 }
8102
Neale Ranns097fa662018-05-01 05:17:55 -07008103 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008104 {
Neale Ranns097fa662018-05-01 05:17:55 -07008105 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008106 return -99;
8107 }
Neale Ranns097fa662018-05-01 05:17:55 -07008108 if (prefix_set == 0)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008109 {
Neale Ranns097fa662018-05-01 05:17:55 -07008110 errmsg ("missing prefix");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008111 return -99;
8112 }
8113
8114 /* Generate a pile of unique, random routes */
8115 if (random_add_del)
8116 {
Neale Ranns097fa662018-05-01 05:17:55 -07008117 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008118 u32 this_random_address;
Neale Ranns097fa662018-05-01 05:17:55 -07008119 uword *random_hash;
8120
Damjan Marion7cd468a2016-12-19 23:05:39 +01008121 random_hash = hash_create (count, sizeof (uword));
8122
Neale Ranns097fa662018-05-01 05:17:55 -07008123 hash_set (random_hash, i->as_u32, 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008124 for (j = 0; j <= count; j++)
8125 {
8126 do
8127 {
8128 this_random_address = random_u32 (&random_seed);
8129 this_random_address =
8130 clib_host_to_net_u32 (this_random_address);
8131 }
8132 while (hash_get (random_hash, this_random_address));
8133 vec_add1 (random_vector, this_random_address);
8134 hash_set (random_hash, this_random_address, 1);
8135 }
8136 hash_free (random_hash);
Neale Ranns097fa662018-05-01 05:17:55 -07008137 set_ip4_address (&pfx.address, random_vector[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008138 }
8139
8140 if (count > 1)
8141 {
8142 /* Turn on async mode */
8143 vam->async_mode = 1;
8144 vam->async_errors = 0;
8145 before = vat_time_now (vam);
8146 }
8147
8148 for (j = 0; j < count; j++)
8149 {
8150 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008151 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008152
8153 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008154 mp->is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008155
Neale Ranns097fa662018-05-01 05:17:55 -07008156 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8157 mp->route.table_id = ntohl (vrf_id);
8158 mp->route.n_paths = path_count;
8159
8160 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
8161
8162 if (random_add_del)
8163 set_ip4_address (&pfx.address, random_vector[j + 1]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008164 else
Neale Ranns097fa662018-05-01 05:17:55 -07008165 increment_address (&pfx.address);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008166 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008167 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008168 /* If we receive SIGTERM, stop now... */
8169 if (vam->do_exit)
8170 break;
8171 }
8172
8173 /* When testing multiple add/del ops, use a control-ping to sync */
8174 if (count > 1)
8175 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008176 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008177 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008178 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008179
8180 /* Shut off async mode */
8181 vam->async_mode = 0;
8182
Dave Barach59b25652017-09-10 15:04:27 -04008183 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008184 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008185
8186 timeout = vat_time_now (vam) + 1.0;
8187 while (vat_time_now (vam) < timeout)
8188 if (vam->result_ready == 1)
8189 goto out;
8190 vam->retval = -99;
8191
8192 out:
8193 if (vam->retval == -99)
8194 errmsg ("timeout");
8195
8196 if (vam->async_errors > 0)
8197 {
8198 errmsg ("%d asynchronous errors", vam->async_errors);
8199 vam->retval = -98;
8200 }
8201 vam->async_errors = 0;
8202 after = vat_time_now (vam);
8203
8204 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8205 if (j > 0)
8206 count = j;
8207
8208 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8209 count, after - before, count / (after - before));
8210 }
8211 else
8212 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008213 int ret;
8214
Damjan Marion7cd468a2016-12-19 23:05:39 +01008215 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008216 W (ret);
8217 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008218 }
8219
8220 /* Return the good/bad news */
8221 return (vam->retval);
8222}
8223
8224static int
Neale Ranns32e1c012016-11-22 17:07:28 +00008225api_ip_mroute_add_del (vat_main_t * vam)
8226{
8227 unformat_input_t *i = vam->input;
Neale Ranns097fa662018-05-01 05:17:55 -07008228 u8 path_set = 0, prefix_set = 0, is_add = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008229 vl_api_ip_mroute_add_del_t *mp;
Neale Ranns32e1c012016-11-22 17:07:28 +00008230 mfib_entry_flags_t eflags = 0;
Neale Ranns097fa662018-05-01 05:17:55 -07008231 vl_api_mfib_path_t path;
8232 vl_api_mprefix_t pfx = { };
8233 u32 vrf_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008234 int ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008235
8236 /* Parse args required to build the message */
8237 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8238 {
Neale Ranns097fa662018-05-01 05:17:55 -07008239 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
Neale Ranns32e1c012016-11-22 17:07:28 +00008240 {
Neale Ranns097fa662018-05-01 05:17:55 -07008241 prefix_set = 1;
8242 pfx.grp_address_length = htons (pfx.grp_address_length);
Neale Ranns32e1c012016-11-22 17:07:28 +00008243 }
8244 else if (unformat (i, "del"))
8245 is_add = 0;
8246 else if (unformat (i, "add"))
8247 is_add = 1;
8248 else if (unformat (i, "vrf %d", &vrf_id))
8249 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008250 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
8251 path.itf_flags = htonl (path.itf_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008252 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
8253 ;
Neale Ranns097fa662018-05-01 05:17:55 -07008254 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
8255 path_set = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008256 else
8257 {
8258 clib_warning ("parse error '%U'", format_unformat_error, i);
8259 return -99;
8260 }
8261 }
8262
Neale Ranns097fa662018-05-01 05:17:55 -07008263 if (prefix_set == 0)
Neale Ranns32e1c012016-11-22 17:07:28 +00008264 {
8265 errmsg ("missing addresses\n");
8266 return -99;
8267 }
Neale Ranns097fa662018-05-01 05:17:55 -07008268 if (path_set == 0)
8269 {
8270 errmsg ("missing path\n");
8271 return -99;
8272 }
Neale Ranns32e1c012016-11-22 17:07:28 +00008273
8274 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008275 M (IP_MROUTE_ADD_DEL, mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008276
Neale Ranns32e1c012016-11-22 17:07:28 +00008277 mp->is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008278 mp->is_multipath = 1;
Neale Ranns32e1c012016-11-22 17:07:28 +00008279
Neale Ranns097fa662018-05-01 05:17:55 -07008280 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
8281 mp->route.table_id = htonl (vrf_id);
8282 mp->route.n_paths = 1;
8283 mp->route.entry_flags = htonl (eflags);
Neale Ranns32e1c012016-11-22 17:07:28 +00008284
Neale Ranns097fa662018-05-01 05:17:55 -07008285 clib_memcpy (&mp->route.paths, &path, sizeof (path));
Neale Ranns32e1c012016-11-22 17:07:28 +00008286
8287 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008288 S (mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008289 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008290 W (ret);
8291 return ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008292}
8293
8294static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008295api_mpls_table_add_del (vat_main_t * vam)
8296{
8297 unformat_input_t *i = vam->input;
8298 vl_api_mpls_table_add_del_t *mp;
8299 u32 table_id = ~0;
8300 u8 is_add = 1;
8301 int ret = 0;
8302
8303 /* Parse args required to build the message */
8304 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8305 {
Florin Corasd0a59722017-10-15 17:41:21 +00008306 if (unformat (i, "table %d", &table_id))
8307 ;
8308 else if (unformat (i, "del"))
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008309 is_add = 0;
8310 else if (unformat (i, "add"))
8311 is_add = 1;
8312 else
8313 {
8314 clib_warning ("parse error '%U'", format_unformat_error, i);
8315 return -99;
8316 }
8317 }
8318
8319 if (~0 == table_id)
8320 {
8321 errmsg ("missing table-ID");
8322 return -99;
8323 }
8324
8325 /* Construct the API message */
8326 M (MPLS_TABLE_ADD_DEL, mp);
8327
Neale Ranns097fa662018-05-01 05:17:55 -07008328 mp->mt_table.mt_table_id = ntohl (table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008329 mp->mt_is_add = is_add;
8330
8331 /* send it... */
8332 S (mp);
8333
8334 /* Wait for a reply... */
8335 W (ret);
8336
8337 return ret;
8338}
8339
8340static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008341api_mpls_route_add_del (vat_main_t * vam)
8342{
Neale Ranns097fa662018-05-01 05:17:55 -07008343 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
8344 mpls_label_t local_label = MPLS_LABEL_INVALID;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008345 unformat_input_t *i = vam->input;
8346 vl_api_mpls_route_add_del_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07008347 vl_api_fib_path_t paths[8];
8348 int count = 1, j;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008349 f64 before = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008350
8351 /* Parse args required to build the message */
8352 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8353 {
Neale Ranns097fa662018-05-01 05:17:55 -07008354 if (unformat (i, "%d", &local_label))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008355 ;
8356 else if (unformat (i, "eos"))
8357 is_eos = 1;
8358 else if (unformat (i, "non-eos"))
8359 is_eos = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008360 else if (unformat (i, "del"))
8361 is_add = 0;
8362 else if (unformat (i, "add"))
8363 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008364 else if (unformat (i, "multipath"))
8365 is_multipath = 1;
8366 else if (unformat (i, "count %d", &count))
8367 ;
John Loe166fd92018-09-13 14:08:59 -04008368 else
8369 if (unformat
Neale Ranns097fa662018-05-01 05:17:55 -07008370 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Loe166fd92018-09-13 14:08:59 -04008371 {
Neale Ranns097fa662018-05-01 05:17:55 -07008372 path_count++;
8373 if (8 == path_count)
8374 {
8375 errmsg ("max 8 paths");
8376 return -99;
8377 }
John Loe166fd92018-09-13 14:08:59 -04008378 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008379 else
8380 {
8381 clib_warning ("parse error '%U'", format_unformat_error, i);
8382 return -99;
8383 }
8384 }
8385
Neale Ranns097fa662018-05-01 05:17:55 -07008386 if (!path_count)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008387 {
Neale Ranns097fa662018-05-01 05:17:55 -07008388 errmsg ("specify a path; via ...");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008389 return -99;
8390 }
8391
8392 if (MPLS_LABEL_INVALID == local_label)
8393 {
8394 errmsg ("missing label");
8395 return -99;
8396 }
8397
8398 if (count > 1)
8399 {
8400 /* Turn on async mode */
8401 vam->async_mode = 1;
8402 vam->async_errors = 0;
8403 before = vat_time_now (vam);
8404 }
8405
8406 for (j = 0; j < count; j++)
8407 {
8408 /* Construct the API message */
Neale Ranns097fa662018-05-01 05:17:55 -07008409 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008410
8411 mp->mr_is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008412 mp->mr_is_multipath = is_multipath;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008413
Neale Ranns097fa662018-05-01 05:17:55 -07008414 mp->mr_route.mr_label = local_label;
8415 mp->mr_route.mr_eos = is_eos;
8416 mp->mr_route.mr_table_id = 0;
8417 mp->mr_route.mr_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008418
Neale Ranns097fa662018-05-01 05:17:55 -07008419 clib_memcpy (&mp->mr_route.mr_paths, paths,
8420 sizeof (paths[0]) * path_count);
Neale Rannsda78f952017-05-24 09:15:43 -07008421
Damjan Marion7cd468a2016-12-19 23:05:39 +01008422 local_label++;
8423
8424 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008425 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008426 /* If we receive SIGTERM, stop now... */
8427 if (vam->do_exit)
8428 break;
8429 }
8430
8431 /* When testing multiple add/del ops, use a control-ping to sync */
8432 if (count > 1)
8433 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008434 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008435 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008436 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008437
8438 /* Shut off async mode */
8439 vam->async_mode = 0;
8440
Dave Barach59b25652017-09-10 15:04:27 -04008441 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008442 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008443
8444 timeout = vat_time_now (vam) + 1.0;
8445 while (vat_time_now (vam) < timeout)
8446 if (vam->result_ready == 1)
8447 goto out;
8448 vam->retval = -99;
8449
8450 out:
8451 if (vam->retval == -99)
8452 errmsg ("timeout");
8453
8454 if (vam->async_errors > 0)
8455 {
8456 errmsg ("%d asynchronous errors", vam->async_errors);
8457 vam->retval = -98;
8458 }
8459 vam->async_errors = 0;
8460 after = vat_time_now (vam);
8461
8462 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8463 if (j > 0)
8464 count = j;
8465
8466 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8467 count, after - before, count / (after - before));
8468 }
8469 else
8470 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008471 int ret;
8472
Damjan Marion7cd468a2016-12-19 23:05:39 +01008473 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008474 W (ret);
8475 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008476 }
8477
8478 /* Return the good/bad news */
8479 return (vam->retval);
Neale Ranns097fa662018-05-01 05:17:55 -07008480 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008481}
8482
8483static int
8484api_mpls_ip_bind_unbind (vat_main_t * vam)
8485{
8486 unformat_input_t *i = vam->input;
8487 vl_api_mpls_ip_bind_unbind_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008488 u32 ip_table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008489 u8 is_bind = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008490 vl_api_prefix_t pfx;
8491 u8 prefix_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008492 mpls_label_t local_label = MPLS_LABEL_INVALID;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008493 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008494
8495 /* Parse args required to build the message */
8496 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8497 {
Neale Ranns097fa662018-05-01 05:17:55 -07008498 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
8499 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008500 else if (unformat (i, "%d", &local_label))
8501 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008502 else if (unformat (i, "table-id %d", &ip_table_id))
8503 ;
8504 else if (unformat (i, "unbind"))
8505 is_bind = 0;
8506 else if (unformat (i, "bind"))
8507 is_bind = 1;
8508 else
8509 {
8510 clib_warning ("parse error '%U'", format_unformat_error, i);
8511 return -99;
8512 }
8513 }
8514
Neale Ranns097fa662018-05-01 05:17:55 -07008515 if (!prefix_set)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008516 {
Neale Ranns097fa662018-05-01 05:17:55 -07008517 errmsg ("IP prefix not set");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008518 return -99;
8519 }
8520
8521 if (MPLS_LABEL_INVALID == local_label)
8522 {
8523 errmsg ("missing label");
8524 return -99;
8525 }
8526
8527 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008528 M (MPLS_IP_BIND_UNBIND, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008529
Damjan Marion7cd468a2016-12-19 23:05:39 +01008530 mp->mb_is_bind = is_bind;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008531 mp->mb_ip_table_id = ntohl (ip_table_id);
8532 mp->mb_mpls_table_id = 0;
8533 mp->mb_label = ntohl (local_label);
Neale Ranns097fa662018-05-01 05:17:55 -07008534 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008535
8536 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008537 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008538
8539 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008540 W (ret);
8541 return ret;
Neale Ranns097fa662018-05-01 05:17:55 -07008542 return (0);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008543}
8544
8545static int
John Loe166fd92018-09-13 14:08:59 -04008546api_sr_mpls_policy_add (vat_main_t * vam)
8547{
8548 unformat_input_t *i = vam->input;
8549 vl_api_sr_mpls_policy_add_t *mp;
8550 u32 bsid = 0;
8551 u32 weight = 1;
8552 u8 type = 0;
8553 u8 n_segments = 0;
8554 u32 sid;
8555 u32 *segments = NULL;
8556 int ret;
8557
8558 /* Parse args required to build the message */
8559 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8560 {
8561 if (unformat (i, "bsid %d", &bsid))
8562 ;
8563 else if (unformat (i, "weight %d", &weight))
8564 ;
8565 else if (unformat (i, "spray"))
8566 type = 1;
8567 else if (unformat (i, "next %d", &sid))
8568 {
8569 n_segments += 1;
8570 vec_add1 (segments, htonl (sid));
8571 }
8572 else
8573 {
8574 clib_warning ("parse error '%U'", format_unformat_error, i);
8575 return -99;
8576 }
8577 }
8578
8579 if (bsid == 0)
8580 {
8581 errmsg ("bsid not set");
8582 return -99;
8583 }
8584
8585 if (n_segments == 0)
8586 {
8587 errmsg ("no sid in segment stack");
8588 return -99;
8589 }
8590
8591 /* Construct the API message */
8592 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
8593
8594 mp->bsid = htonl (bsid);
8595 mp->weight = htonl (weight);
Jakub Grajciar00ec4012020-01-31 10:17:29 +01008596 mp->is_spray = type;
John Loe166fd92018-09-13 14:08:59 -04008597 mp->n_segments = n_segments;
8598 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
8599 vec_free (segments);
8600
8601 /* send it... */
8602 S (mp);
8603
8604 /* Wait for a reply... */
8605 W (ret);
8606 return ret;
8607}
8608
8609static int
8610api_sr_mpls_policy_del (vat_main_t * vam)
8611{
8612 unformat_input_t *i = vam->input;
8613 vl_api_sr_mpls_policy_del_t *mp;
8614 u32 bsid = 0;
8615 int ret;
8616
8617 /* Parse args required to build the message */
8618 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8619 {
8620 if (unformat (i, "bsid %d", &bsid))
8621 ;
8622 else
8623 {
8624 clib_warning ("parse error '%U'", format_unformat_error, i);
8625 return -99;
8626 }
8627 }
8628
8629 if (bsid == 0)
8630 {
8631 errmsg ("bsid not set");
8632 return -99;
8633 }
8634
8635 /* Construct the API message */
8636 M (SR_MPLS_POLICY_DEL, mp);
8637
8638 mp->bsid = htonl (bsid);
8639
8640 /* send it... */
8641 S (mp);
8642
8643 /* Wait for a reply... */
8644 W (ret);
8645 return ret;
8646}
8647
8648static int
Neale Rannsd792d9c2017-10-21 10:53:20 -07008649api_bier_table_add_del (vat_main_t * vam)
8650{
8651 unformat_input_t *i = vam->input;
8652 vl_api_bier_table_add_del_t *mp;
8653 u8 is_add = 1;
8654 u32 set = 0, sub_domain = 0, hdr_len = 3;
8655 mpls_label_t local_label = MPLS_LABEL_INVALID;
8656 int ret;
8657
8658 /* Parse args required to build the message */
8659 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8660 {
8661 if (unformat (i, "sub-domain %d", &sub_domain))
8662 ;
8663 else if (unformat (i, "set %d", &set))
8664 ;
8665 else if (unformat (i, "label %d", &local_label))
8666 ;
8667 else if (unformat (i, "hdr-len %d", &hdr_len))
8668 ;
8669 else if (unformat (i, "add"))
8670 is_add = 1;
8671 else if (unformat (i, "del"))
8672 is_add = 0;
8673 else
8674 {
8675 clib_warning ("parse error '%U'", format_unformat_error, i);
8676 return -99;
8677 }
8678 }
8679
8680 if (MPLS_LABEL_INVALID == local_label)
8681 {
8682 errmsg ("missing label\n");
8683 return -99;
8684 }
8685
8686 /* Construct the API message */
8687 M (BIER_TABLE_ADD_DEL, mp);
8688
8689 mp->bt_is_add = is_add;
8690 mp->bt_label = ntohl (local_label);
8691 mp->bt_tbl_id.bt_set = set;
8692 mp->bt_tbl_id.bt_sub_domain = sub_domain;
8693 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
8694
8695 /* send it... */
8696 S (mp);
8697
8698 /* Wait for a reply... */
8699 W (ret);
8700
8701 return (ret);
8702}
8703
8704static int
8705api_bier_route_add_del (vat_main_t * vam)
8706{
8707 unformat_input_t *i = vam->input;
8708 vl_api_bier_route_add_del_t *mp;
8709 u8 is_add = 1;
8710 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
8711 ip4_address_t v4_next_hop_address;
8712 ip6_address_t v6_next_hop_address;
8713 u8 next_hop_set = 0;
8714 u8 next_hop_proto_is_ip4 = 1;
8715 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
8716 int ret;
8717
8718 /* Parse args required to build the message */
8719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8720 {
8721 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
8722 {
8723 next_hop_proto_is_ip4 = 1;
8724 next_hop_set = 1;
8725 }
8726 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
8727 {
8728 next_hop_proto_is_ip4 = 0;
8729 next_hop_set = 1;
8730 }
8731 if (unformat (i, "sub-domain %d", &sub_domain))
8732 ;
8733 else if (unformat (i, "set %d", &set))
8734 ;
8735 else if (unformat (i, "hdr-len %d", &hdr_len))
8736 ;
8737 else if (unformat (i, "bp %d", &bp))
8738 ;
8739 else if (unformat (i, "add"))
8740 is_add = 1;
8741 else if (unformat (i, "del"))
8742 is_add = 0;
8743 else if (unformat (i, "out-label %d", &next_hop_out_label))
8744 ;
8745 else
8746 {
8747 clib_warning ("parse error '%U'", format_unformat_error, i);
8748 return -99;
8749 }
8750 }
8751
8752 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
8753 {
8754 errmsg ("next hop / label set\n");
8755 return -99;
8756 }
8757 if (0 == bp)
8758 {
8759 errmsg ("bit=position not set\n");
8760 return -99;
8761 }
8762
8763 /* Construct the API message */
Neale Ranns31ed7442018-02-23 05:29:09 -08008764 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
Neale Rannsd792d9c2017-10-21 10:53:20 -07008765
8766 mp->br_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008767 mp->br_route.br_tbl_id.bt_set = set;
8768 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
8769 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
8770 mp->br_route.br_bp = ntohs (bp);
8771 mp->br_route.br_n_paths = 1;
8772 mp->br_route.br_paths[0].n_labels = 1;
8773 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
8774 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
8775 FIB_API_PATH_NH_PROTO_IP4 :
8776 FIB_API_PATH_NH_PROTO_IP6);
Neale Rannsd792d9c2017-10-21 10:53:20 -07008777
8778 if (next_hop_proto_is_ip4)
8779 {
Neale Ranns097fa662018-05-01 05:17:55 -07008780 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008781 &v4_next_hop_address, sizeof (v4_next_hop_address));
8782 }
8783 else
8784 {
Neale Ranns097fa662018-05-01 05:17:55 -07008785 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
Neale Rannsd792d9c2017-10-21 10:53:20 -07008786 &v6_next_hop_address, sizeof (v6_next_hop_address));
8787 }
8788
8789 /* send it... */
8790 S (mp);
8791
8792 /* Wait for a reply... */
8793 W (ret);
8794
8795 return (ret);
8796}
8797
8798static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008799api_mpls_tunnel_add_del (vat_main_t * vam)
8800{
8801 unformat_input_t *i = vam->input;
8802 vl_api_mpls_tunnel_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008803
Neale Ranns097fa662018-05-01 05:17:55 -07008804 vl_api_fib_path_t paths[8];
Damjan Marion7cd468a2016-12-19 23:05:39 +01008805 u32 sw_if_index = ~0;
Neale Ranns097fa662018-05-01 05:17:55 -07008806 u8 path_count = 0;
8807 u8 l2_only = 0;
8808 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008809 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008810
8811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8812 {
8813 if (unformat (i, "add"))
8814 is_add = 1;
John Lo06fda9c2018-10-03 16:32:44 -04008815 else
8816 if (unformat
8817 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
8818 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008819 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
8820 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008821 else if (unformat (i, "l2-only"))
8822 l2_only = 1;
Neale Ranns097fa662018-05-01 05:17:55 -07008823 else
8824 if (unformat
8825 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
John Lo06fda9c2018-10-03 16:32:44 -04008826 {
Neale Ranns097fa662018-05-01 05:17:55 -07008827 path_count++;
8828 if (8 == path_count)
8829 {
8830 errmsg ("max 8 paths");
8831 return -99;
8832 }
John Lo06fda9c2018-10-03 16:32:44 -04008833 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008834 else
8835 {
8836 clib_warning ("parse error '%U'", format_unformat_error, i);
8837 return -99;
8838 }
8839 }
8840
Neale Ranns097fa662018-05-01 05:17:55 -07008841 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008842
Damjan Marion7cd468a2016-12-19 23:05:39 +01008843 mp->mt_is_add = is_add;
Neale Ranns097fa662018-05-01 05:17:55 -07008844 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
8845 mp->mt_tunnel.mt_l2_only = l2_only;
8846 mp->mt_tunnel.mt_is_multicast = 0;
8847 mp->mt_tunnel.mt_n_paths = path_count;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008848
Neale Ranns097fa662018-05-01 05:17:55 -07008849 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
8850 sizeof (paths[0]) * path_count);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008851
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008852 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008853 W (ret);
8854 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008855}
8856
8857static int
8858api_sw_interface_set_unnumbered (vat_main_t * vam)
8859{
8860 unformat_input_t *i = vam->input;
8861 vl_api_sw_interface_set_unnumbered_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008862 u32 sw_if_index;
8863 u32 unnum_sw_index = ~0;
8864 u8 is_add = 1;
8865 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008866 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008867
8868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8869 {
8870 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8871 sw_if_index_set = 1;
8872 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8873 sw_if_index_set = 1;
8874 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
8875 ;
8876 else if (unformat (i, "del"))
8877 is_add = 0;
8878 else
8879 {
8880 clib_warning ("parse error '%U'", format_unformat_error, i);
8881 return -99;
8882 }
8883 }
8884
8885 if (sw_if_index_set == 0)
8886 {
8887 errmsg ("missing interface name or sw_if_index");
8888 return -99;
8889 }
8890
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008891 M (SW_INTERFACE_SET_UNNUMBERED, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008892
8893 mp->sw_if_index = ntohl (sw_if_index);
8894 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
8895 mp->is_add = is_add;
8896
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008897 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008898 W (ret);
8899 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008900}
8901
Damjan Marion7cd468a2016-12-19 23:05:39 +01008902
8903static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008904api_create_vlan_subif (vat_main_t * vam)
8905{
8906 unformat_input_t *i = vam->input;
8907 vl_api_create_vlan_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008908 u32 sw_if_index;
8909 u8 sw_if_index_set = 0;
8910 u32 vlan_id;
8911 u8 vlan_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008912 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008913
8914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8915 {
8916 if (unformat (i, "sw_if_index %d", &sw_if_index))
8917 sw_if_index_set = 1;
8918 else
8919 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8920 sw_if_index_set = 1;
8921 else if (unformat (i, "vlan %d", &vlan_id))
8922 vlan_id_set = 1;
8923 else
8924 {
8925 clib_warning ("parse error '%U'", format_unformat_error, i);
8926 return -99;
8927 }
8928 }
8929
8930 if (sw_if_index_set == 0)
8931 {
8932 errmsg ("missing interface name or sw_if_index");
8933 return -99;
8934 }
8935
8936 if (vlan_id_set == 0)
8937 {
8938 errmsg ("missing vlan_id");
8939 return -99;
8940 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008941 M (CREATE_VLAN_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008942
8943 mp->sw_if_index = ntohl (sw_if_index);
8944 mp->vlan_id = ntohl (vlan_id);
8945
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008946 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06008947 W (ret);
8948 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008949}
8950
8951#define foreach_create_subif_bit \
8952_(no_tags) \
8953_(one_tag) \
8954_(two_tags) \
8955_(dot1ad) \
8956_(exact_match) \
8957_(default_sub) \
8958_(outer_vlan_id_any) \
8959_(inner_vlan_id_any)
8960
Jakub Grajciar053204a2019-03-18 13:17:53 +01008961#define foreach_create_subif_flag \
8962_(0, "no_tags") \
8963_(1, "one_tag") \
8964_(2, "two_tags") \
8965_(3, "dot1ad") \
8966_(4, "exact_match") \
8967_(5, "default_sub") \
8968_(6, "outer_vlan_id_any") \
8969_(7, "inner_vlan_id_any")
8970
Damjan Marion7cd468a2016-12-19 23:05:39 +01008971static int
8972api_create_subif (vat_main_t * vam)
8973{
8974 unformat_input_t *i = vam->input;
8975 vl_api_create_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008976 u32 sw_if_index;
8977 u8 sw_if_index_set = 0;
8978 u32 sub_id;
8979 u8 sub_id_set = 0;
Jakub Grajciar053204a2019-03-18 13:17:53 +01008980 u32 __attribute__ ((unused)) no_tags = 0;
8981 u32 __attribute__ ((unused)) one_tag = 0;
8982 u32 __attribute__ ((unused)) two_tags = 0;
8983 u32 __attribute__ ((unused)) dot1ad = 0;
8984 u32 __attribute__ ((unused)) exact_match = 0;
8985 u32 __attribute__ ((unused)) default_sub = 0;
8986 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
8987 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008988 u32 tmp;
8989 u16 outer_vlan_id = 0;
8990 u16 inner_vlan_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008991 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008992
8993 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8994 {
8995 if (unformat (i, "sw_if_index %d", &sw_if_index))
8996 sw_if_index_set = 1;
8997 else
8998 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8999 sw_if_index_set = 1;
9000 else if (unformat (i, "sub_id %d", &sub_id))
9001 sub_id_set = 1;
9002 else if (unformat (i, "outer_vlan_id %d", &tmp))
9003 outer_vlan_id = tmp;
9004 else if (unformat (i, "inner_vlan_id %d", &tmp))
9005 inner_vlan_id = tmp;
9006
9007#define _(a) else if (unformat (i, #a)) a = 1 ;
9008 foreach_create_subif_bit
9009#undef _
9010 else
9011 {
9012 clib_warning ("parse error '%U'", format_unformat_error, i);
9013 return -99;
9014 }
9015 }
9016
9017 if (sw_if_index_set == 0)
9018 {
9019 errmsg ("missing interface name or sw_if_index");
9020 return -99;
9021 }
9022
9023 if (sub_id_set == 0)
9024 {
9025 errmsg ("missing sub_id");
9026 return -99;
9027 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009028 M (CREATE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009029
9030 mp->sw_if_index = ntohl (sw_if_index);
9031 mp->sub_id = ntohl (sub_id);
9032
Jakub Grajciar053204a2019-03-18 13:17:53 +01009033#define _(a,b) mp->sub_if_flags |= (1 << a);
9034 foreach_create_subif_flag;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009035#undef _
9036
9037 mp->outer_vlan_id = ntohs (outer_vlan_id);
9038 mp->inner_vlan_id = ntohs (inner_vlan_id);
9039
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009040 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009041 W (ret);
9042 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009043}
9044
9045static int
Neale Ranns9db6ada2019-11-08 12:42:31 +00009046api_ip_table_replace_begin (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009047{
9048 unformat_input_t *i = vam->input;
Neale Ranns9db6ada2019-11-08 12:42:31 +00009049 vl_api_ip_table_replace_begin_t *mp;
9050 u32 table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009051 u8 is_ipv6 = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009052
Jon Loeliger56c7b012017-02-01 12:31:41 -06009053 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009054 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9055 {
Neale Ranns9db6ada2019-11-08 12:42:31 +00009056 if (unformat (i, "table %d", &table_id))
9057 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009058 else if (unformat (i, "ipv6"))
9059 is_ipv6 = 1;
9060 else
9061 {
9062 clib_warning ("parse error '%U'", format_unformat_error, i);
9063 return -99;
9064 }
9065 }
9066
Neale Ranns9db6ada2019-11-08 12:42:31 +00009067 M (IP_TABLE_REPLACE_BEGIN, mp);
9068
9069 mp->table.table_id = ntohl (table_id);
9070 mp->table.is_ip6 = is_ipv6;
9071
9072 S (mp);
9073 W (ret);
9074 return ret;
9075}
9076
9077static int
9078api_ip_table_flush (vat_main_t * vam)
9079{
9080 unformat_input_t *i = vam->input;
9081 vl_api_ip_table_flush_t *mp;
9082 u32 table_id = 0;
9083 u8 is_ipv6 = 0;
9084
9085 int ret;
9086 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009087 {
Neale Ranns9db6ada2019-11-08 12:42:31 +00009088 if (unformat (i, "table %d", &table_id))
9089 ;
9090 else if (unformat (i, "ipv6"))
9091 is_ipv6 = 1;
9092 else
9093 {
9094 clib_warning ("parse error '%U'", format_unformat_error, i);
9095 return -99;
9096 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01009097 }
9098
Neale Ranns9db6ada2019-11-08 12:42:31 +00009099 M (IP_TABLE_FLUSH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009100
Neale Ranns9db6ada2019-11-08 12:42:31 +00009101 mp->table.table_id = ntohl (table_id);
9102 mp->table.is_ip6 = is_ipv6;
9103
9104 S (mp);
9105 W (ret);
9106 return ret;
9107}
9108
9109static int
9110api_ip_table_replace_end (vat_main_t * vam)
9111{
9112 unformat_input_t *i = vam->input;
9113 vl_api_ip_table_replace_end_t *mp;
9114 u32 table_id = 0;
9115 u8 is_ipv6 = 0;
9116
9117 int ret;
9118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9119 {
9120 if (unformat (i, "table %d", &table_id))
9121 ;
9122 else if (unformat (i, "ipv6"))
9123 is_ipv6 = 1;
9124 else
9125 {
9126 clib_warning ("parse error '%U'", format_unformat_error, i);
9127 return -99;
9128 }
9129 }
9130
9131 M (IP_TABLE_REPLACE_END, mp);
9132
9133 mp->table.table_id = ntohl (table_id);
9134 mp->table.is_ip6 = is_ipv6;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009135
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009136 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009137 W (ret);
9138 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009139}
9140
9141static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009142api_set_ip_flow_hash (vat_main_t * vam)
9143{
9144 unformat_input_t *i = vam->input;
9145 vl_api_set_ip_flow_hash_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009146 u32 vrf_id = 0;
9147 u8 is_ipv6 = 0;
9148 u8 vrf_id_set = 0;
9149 u8 src = 0;
9150 u8 dst = 0;
9151 u8 sport = 0;
9152 u8 dport = 0;
9153 u8 proto = 0;
9154 u8 reverse = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009155 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009156
9157 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9158 {
9159 if (unformat (i, "vrf %d", &vrf_id))
9160 vrf_id_set = 1;
9161 else if (unformat (i, "ipv6"))
9162 is_ipv6 = 1;
9163 else if (unformat (i, "src"))
9164 src = 1;
9165 else if (unformat (i, "dst"))
9166 dst = 1;
9167 else if (unformat (i, "sport"))
9168 sport = 1;
9169 else if (unformat (i, "dport"))
9170 dport = 1;
9171 else if (unformat (i, "proto"))
9172 proto = 1;
9173 else if (unformat (i, "reverse"))
9174 reverse = 1;
9175
9176 else
9177 {
9178 clib_warning ("parse error '%U'", format_unformat_error, i);
9179 return -99;
9180 }
9181 }
9182
9183 if (vrf_id_set == 0)
9184 {
9185 errmsg ("missing vrf id");
9186 return -99;
9187 }
9188
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009189 M (SET_IP_FLOW_HASH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009190 mp->src = src;
9191 mp->dst = dst;
9192 mp->sport = sport;
9193 mp->dport = dport;
9194 mp->proto = proto;
9195 mp->reverse = reverse;
9196 mp->vrf_id = ntohl (vrf_id);
9197 mp->is_ipv6 = is_ipv6;
9198
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009199 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009200 W (ret);
9201 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009202}
9203
9204static int
9205api_sw_interface_ip6_enable_disable (vat_main_t * vam)
9206{
9207 unformat_input_t *i = vam->input;
9208 vl_api_sw_interface_ip6_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009209 u32 sw_if_index;
9210 u8 sw_if_index_set = 0;
9211 u8 enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009212 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009213
9214 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9215 {
9216 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9217 sw_if_index_set = 1;
9218 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9219 sw_if_index_set = 1;
9220 else if (unformat (i, "enable"))
9221 enable = 1;
9222 else if (unformat (i, "disable"))
9223 enable = 0;
9224 else
9225 {
9226 clib_warning ("parse error '%U'", format_unformat_error, i);
9227 return -99;
9228 }
9229 }
9230
9231 if (sw_if_index_set == 0)
9232 {
9233 errmsg ("missing interface name or sw_if_index");
9234 return -99;
9235 }
9236
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009237 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009238
9239 mp->sw_if_index = ntohl (sw_if_index);
9240 mp->enable = enable;
9241
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009242 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009243 W (ret);
9244 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009245}
9246
Damjan Marion7cd468a2016-12-19 23:05:39 +01009247
9248static int
9249api_l2_patch_add_del (vat_main_t * vam)
9250{
9251 unformat_input_t *i = vam->input;
9252 vl_api_l2_patch_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009253 u32 rx_sw_if_index;
9254 u8 rx_sw_if_index_set = 0;
9255 u32 tx_sw_if_index;
9256 u8 tx_sw_if_index_set = 0;
9257 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009258 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009259
9260 /* Parse args required to build the message */
9261 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9262 {
9263 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
9264 rx_sw_if_index_set = 1;
9265 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
9266 tx_sw_if_index_set = 1;
9267 else if (unformat (i, "rx"))
9268 {
9269 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9270 {
9271 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
9272 &rx_sw_if_index))
9273 rx_sw_if_index_set = 1;
9274 }
9275 else
9276 break;
9277 }
9278 else if (unformat (i, "tx"))
9279 {
9280 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9281 {
9282 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
9283 &tx_sw_if_index))
9284 tx_sw_if_index_set = 1;
9285 }
9286 else
9287 break;
9288 }
9289 else if (unformat (i, "del"))
9290 is_add = 0;
9291 else
9292 break;
9293 }
9294
9295 if (rx_sw_if_index_set == 0)
9296 {
9297 errmsg ("missing rx interface name or rx_sw_if_index");
9298 return -99;
9299 }
9300
9301 if (tx_sw_if_index_set == 0)
9302 {
9303 errmsg ("missing tx interface name or tx_sw_if_index");
9304 return -99;
9305 }
9306
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009307 M (L2_PATCH_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009308
9309 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
9310 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
9311 mp->is_add = is_add;
9312
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009313 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009314 W (ret);
9315 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009316}
9317
Pablo Camarillofb380952016-12-07 18:34:18 +01009318u8 is_del;
9319u8 localsid_addr[16];
9320u8 end_psp;
9321u8 behavior;
9322u32 sw_if_index;
9323u32 vlan_index;
9324u32 fib_table;
9325u8 nh_addr[16];
9326
9327static int
9328api_sr_localsid_add_del (vat_main_t * vam)
9329{
9330 unformat_input_t *i = vam->input;
9331 vl_api_sr_localsid_add_del_t *mp;
9332
9333 u8 is_del;
9334 ip6_address_t localsid;
9335 u8 end_psp = 0;
9336 u8 behavior = ~0;
9337 u32 sw_if_index;
9338 u32 fib_table = ~(u32) 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009339 ip46_address_t nh_addr;
9340 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
Pablo Camarillofb380952016-12-07 18:34:18 +01009341
9342 bool nexthop_set = 0;
9343
9344 int ret;
9345
9346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9347 {
9348 if (unformat (i, "del"))
9349 is_del = 1;
9350 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009351 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
Pablo Camarillofb380952016-12-07 18:34:18 +01009352 nexthop_set = 1;
9353 else if (unformat (i, "behavior %u", &behavior));
9354 else if (unformat (i, "sw_if_index %u", &sw_if_index));
9355 else if (unformat (i, "fib-table %u", &fib_table));
9356 else if (unformat (i, "end.psp %u", &behavior));
9357 else
9358 break;
9359 }
9360
9361 M (SR_LOCALSID_ADD_DEL, mp);
9362
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009363 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
Tetsuya Murakami1b81e6e2019-11-06 11:05:51 -08009364
Pablo Camarillofb380952016-12-07 18:34:18 +01009365 if (nexthop_set)
Pablo Camarillo3337bd22018-06-19 15:49:02 +02009366 {
Jakub Grajciar0938eba2020-03-04 13:08:27 +01009367 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
Pablo Camarillo3337bd22018-06-19 15:49:02 +02009368 }
Pablo Camarillofb380952016-12-07 18:34:18 +01009369 mp->behavior = behavior;
9370 mp->sw_if_index = ntohl (sw_if_index);
9371 mp->fib_table = ntohl (fib_table);
9372 mp->end_psp = end_psp;
9373 mp->is_del = is_del;
9374
9375 S (mp);
9376 W (ret);
9377 return ret;
9378}
9379
Damjan Marion7cd468a2016-12-19 23:05:39 +01009380static int
9381api_ioam_enable (vat_main_t * vam)
9382{
9383 unformat_input_t *input = vam->input;
9384 vl_api_ioam_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009385 u32 id = 0;
9386 int has_trace_option = 0;
9387 int has_pot_option = 0;
9388 int has_seqno_option = 0;
9389 int has_analyse_option = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009390 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009391
9392 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9393 {
9394 if (unformat (input, "trace"))
9395 has_trace_option = 1;
9396 else if (unformat (input, "pot"))
9397 has_pot_option = 1;
9398 else if (unformat (input, "seqno"))
9399 has_seqno_option = 1;
9400 else if (unformat (input, "analyse"))
9401 has_analyse_option = 1;
9402 else
9403 break;
9404 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009405 M (IOAM_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009406 mp->id = htons (id);
9407 mp->seqno = has_seqno_option;
9408 mp->analyse = has_analyse_option;
9409 mp->pot_enable = has_pot_option;
9410 mp->trace_enable = has_trace_option;
9411
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009412 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009413 W (ret);
9414 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009415}
9416
9417
9418static int
9419api_ioam_disable (vat_main_t * vam)
9420{
9421 vl_api_ioam_disable_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009422 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009423
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009424 M (IOAM_DISABLE, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009425 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009426 W (ret);
9427 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009428}
9429
Damjan Marion7cd468a2016-12-19 23:05:39 +01009430#define foreach_tcp_proto_field \
9431_(src_port) \
9432_(dst_port)
9433
9434#define foreach_udp_proto_field \
9435_(src_port) \
9436_(dst_port)
9437
9438#define foreach_ip4_proto_field \
9439_(src_address) \
9440_(dst_address) \
9441_(tos) \
9442_(length) \
9443_(fragment_id) \
9444_(ttl) \
9445_(protocol) \
9446_(checksum)
9447
Dave Barach4a3f69c2017-02-22 12:44:56 -05009448typedef struct
9449{
9450 u16 src_port, dst_port;
9451} tcpudp_header_t;
9452
9453#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +01009454uword
9455unformat_tcp_mask (unformat_input_t * input, va_list * args)
9456{
9457 u8 **maskp = va_arg (*args, u8 **);
9458 u8 *mask = 0;
9459 u8 found_something = 0;
9460 tcp_header_t *tcp;
9461
9462#define _(a) u8 a=0;
9463 foreach_tcp_proto_field;
9464#undef _
9465
9466 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9467 {
9468 if (0);
9469#define _(a) else if (unformat (input, #a)) a=1;
9470 foreach_tcp_proto_field
9471#undef _
9472 else
9473 break;
9474 }
9475
9476#define _(a) found_something += a;
9477 foreach_tcp_proto_field;
9478#undef _
9479
9480 if (found_something == 0)
9481 return 0;
9482
9483 vec_validate (mask, sizeof (*tcp) - 1);
9484
9485 tcp = (tcp_header_t *) mask;
9486
Dave Barachb7b92992018-10-17 10:38:51 -04009487#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009488 foreach_tcp_proto_field;
9489#undef _
9490
9491 *maskp = mask;
9492 return 1;
9493}
9494
9495uword
9496unformat_udp_mask (unformat_input_t * input, va_list * args)
9497{
9498 u8 **maskp = va_arg (*args, u8 **);
9499 u8 *mask = 0;
9500 u8 found_something = 0;
9501 udp_header_t *udp;
9502
9503#define _(a) u8 a=0;
9504 foreach_udp_proto_field;
9505#undef _
9506
9507 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9508 {
9509 if (0);
9510#define _(a) else if (unformat (input, #a)) a=1;
9511 foreach_udp_proto_field
9512#undef _
9513 else
9514 break;
9515 }
9516
9517#define _(a) found_something += a;
9518 foreach_udp_proto_field;
9519#undef _
9520
9521 if (found_something == 0)
9522 return 0;
9523
9524 vec_validate (mask, sizeof (*udp) - 1);
9525
9526 udp = (udp_header_t *) mask;
9527
Dave Barachb7b92992018-10-17 10:38:51 -04009528#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009529 foreach_udp_proto_field;
9530#undef _
9531
9532 *maskp = mask;
9533 return 1;
9534}
9535
Damjan Marion7cd468a2016-12-19 23:05:39 +01009536uword
9537unformat_l4_mask (unformat_input_t * input, va_list * args)
9538{
9539 u8 **maskp = va_arg (*args, u8 **);
9540 u16 src_port = 0, dst_port = 0;
9541 tcpudp_header_t *tcpudp;
9542
9543 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9544 {
9545 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
9546 return 1;
9547 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
9548 return 1;
9549 else if (unformat (input, "src_port"))
9550 src_port = 0xFFFF;
9551 else if (unformat (input, "dst_port"))
9552 dst_port = 0xFFFF;
9553 else
9554 return 0;
9555 }
9556
9557 if (!src_port && !dst_port)
9558 return 0;
9559
9560 u8 *mask = 0;
9561 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
9562
9563 tcpudp = (tcpudp_header_t *) mask;
9564 tcpudp->src_port = src_port;
9565 tcpudp->dst_port = dst_port;
9566
9567 *maskp = mask;
9568
9569 return 1;
9570}
9571
9572uword
9573unformat_ip4_mask (unformat_input_t * input, va_list * args)
9574{
9575 u8 **maskp = va_arg (*args, u8 **);
9576 u8 *mask = 0;
9577 u8 found_something = 0;
9578 ip4_header_t *ip;
9579
9580#define _(a) u8 a=0;
9581 foreach_ip4_proto_field;
9582#undef _
9583 u8 version = 0;
9584 u8 hdr_length = 0;
9585
9586
9587 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9588 {
9589 if (unformat (input, "version"))
9590 version = 1;
9591 else if (unformat (input, "hdr_length"))
9592 hdr_length = 1;
9593 else if (unformat (input, "src"))
9594 src_address = 1;
9595 else if (unformat (input, "dst"))
9596 dst_address = 1;
9597 else if (unformat (input, "proto"))
9598 protocol = 1;
9599
9600#define _(a) else if (unformat (input, #a)) a=1;
9601 foreach_ip4_proto_field
9602#undef _
9603 else
9604 break;
9605 }
9606
9607#define _(a) found_something += a;
9608 foreach_ip4_proto_field;
9609#undef _
9610
9611 if (found_something == 0)
9612 return 0;
9613
9614 vec_validate (mask, sizeof (*ip) - 1);
9615
9616 ip = (ip4_header_t *) mask;
9617
Dave Barachb7b92992018-10-17 10:38:51 -04009618#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009619 foreach_ip4_proto_field;
9620#undef _
9621
9622 ip->ip_version_and_header_length = 0;
9623
9624 if (version)
9625 ip->ip_version_and_header_length |= 0xF0;
9626
9627 if (hdr_length)
9628 ip->ip_version_and_header_length |= 0x0F;
9629
9630 *maskp = mask;
9631 return 1;
9632}
9633
9634#define foreach_ip6_proto_field \
9635_(src_address) \
9636_(dst_address) \
9637_(payload_length) \
9638_(hop_limit) \
9639_(protocol)
9640
9641uword
9642unformat_ip6_mask (unformat_input_t * input, va_list * args)
9643{
9644 u8 **maskp = va_arg (*args, u8 **);
9645 u8 *mask = 0;
9646 u8 found_something = 0;
9647 ip6_header_t *ip;
9648 u32 ip_version_traffic_class_and_flow_label;
9649
9650#define _(a) u8 a=0;
9651 foreach_ip6_proto_field;
9652#undef _
9653 u8 version = 0;
9654 u8 traffic_class = 0;
9655 u8 flow_label = 0;
9656
9657 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9658 {
9659 if (unformat (input, "version"))
9660 version = 1;
9661 else if (unformat (input, "traffic-class"))
9662 traffic_class = 1;
9663 else if (unformat (input, "flow-label"))
9664 flow_label = 1;
9665 else if (unformat (input, "src"))
9666 src_address = 1;
9667 else if (unformat (input, "dst"))
9668 dst_address = 1;
9669 else if (unformat (input, "proto"))
9670 protocol = 1;
9671
9672#define _(a) else if (unformat (input, #a)) a=1;
9673 foreach_ip6_proto_field
9674#undef _
9675 else
9676 break;
9677 }
9678
9679#define _(a) found_something += a;
9680 foreach_ip6_proto_field;
9681#undef _
9682
9683 if (found_something == 0)
9684 return 0;
9685
9686 vec_validate (mask, sizeof (*ip) - 1);
9687
9688 ip = (ip6_header_t *) mask;
9689
Dave Barachb7b92992018-10-17 10:38:51 -04009690#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009691 foreach_ip6_proto_field;
9692#undef _
9693
9694 ip_version_traffic_class_and_flow_label = 0;
9695
9696 if (version)
9697 ip_version_traffic_class_and_flow_label |= 0xF0000000;
9698
9699 if (traffic_class)
9700 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
9701
9702 if (flow_label)
9703 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
9704
9705 ip->ip_version_traffic_class_and_flow_label =
9706 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
9707
9708 *maskp = mask;
9709 return 1;
9710}
9711
9712uword
9713unformat_l3_mask (unformat_input_t * input, va_list * args)
9714{
9715 u8 **maskp = va_arg (*args, u8 **);
9716
9717 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9718 {
9719 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
9720 return 1;
9721 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
9722 return 1;
9723 else
9724 break;
9725 }
9726 return 0;
9727}
9728
9729uword
9730unformat_l2_mask (unformat_input_t * input, va_list * args)
9731{
9732 u8 **maskp = va_arg (*args, u8 **);
9733 u8 *mask = 0;
9734 u8 src = 0;
9735 u8 dst = 0;
9736 u8 proto = 0;
9737 u8 tag1 = 0;
9738 u8 tag2 = 0;
9739 u8 ignore_tag1 = 0;
9740 u8 ignore_tag2 = 0;
9741 u8 cos1 = 0;
9742 u8 cos2 = 0;
9743 u8 dot1q = 0;
9744 u8 dot1ad = 0;
9745 int len = 14;
9746
9747 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9748 {
9749 if (unformat (input, "src"))
9750 src = 1;
9751 else if (unformat (input, "dst"))
9752 dst = 1;
9753 else if (unformat (input, "proto"))
9754 proto = 1;
9755 else if (unformat (input, "tag1"))
9756 tag1 = 1;
9757 else if (unformat (input, "tag2"))
9758 tag2 = 1;
9759 else if (unformat (input, "ignore-tag1"))
9760 ignore_tag1 = 1;
9761 else if (unformat (input, "ignore-tag2"))
9762 ignore_tag2 = 1;
9763 else if (unformat (input, "cos1"))
9764 cos1 = 1;
9765 else if (unformat (input, "cos2"))
9766 cos2 = 1;
9767 else if (unformat (input, "dot1q"))
9768 dot1q = 1;
9769 else if (unformat (input, "dot1ad"))
9770 dot1ad = 1;
9771 else
9772 break;
9773 }
9774 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
9775 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
9776 return 0;
9777
9778 if (tag1 || ignore_tag1 || cos1 || dot1q)
9779 len = 18;
9780 if (tag2 || ignore_tag2 || cos2 || dot1ad)
9781 len = 22;
9782
9783 vec_validate (mask, len - 1);
9784
9785 if (dst)
Dave Barachb7b92992018-10-17 10:38:51 -04009786 clib_memset (mask, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009787
9788 if (src)
Dave Barachb7b92992018-10-17 10:38:51 -04009789 clib_memset (mask + 6, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009790
9791 if (tag2 || dot1ad)
9792 {
9793 /* inner vlan tag */
9794 if (tag2)
9795 {
9796 mask[19] = 0xff;
9797 mask[18] = 0x0f;
9798 }
9799 if (cos2)
9800 mask[18] |= 0xe0;
9801 if (proto)
9802 mask[21] = mask[20] = 0xff;
9803 if (tag1)
9804 {
9805 mask[15] = 0xff;
9806 mask[14] = 0x0f;
9807 }
9808 if (cos1)
9809 mask[14] |= 0xe0;
9810 *maskp = mask;
9811 return 1;
9812 }
9813 if (tag1 | dot1q)
9814 {
9815 if (tag1)
9816 {
9817 mask[15] = 0xff;
9818 mask[14] = 0x0f;
9819 }
9820 if (cos1)
9821 mask[14] |= 0xe0;
9822 if (proto)
9823 mask[16] = mask[17] = 0xff;
9824
9825 *maskp = mask;
9826 return 1;
9827 }
9828 if (cos2)
9829 mask[18] |= 0xe0;
9830 if (cos1)
9831 mask[14] |= 0xe0;
9832 if (proto)
9833 mask[12] = mask[13] = 0xff;
9834
9835 *maskp = mask;
9836 return 1;
9837}
9838
9839uword
9840unformat_classify_mask (unformat_input_t * input, va_list * args)
9841{
9842 u8 **maskp = va_arg (*args, u8 **);
9843 u32 *skipp = va_arg (*args, u32 *);
9844 u32 *matchp = va_arg (*args, u32 *);
9845 u32 match;
9846 u8 *mask = 0;
9847 u8 *l2 = 0;
9848 u8 *l3 = 0;
9849 u8 *l4 = 0;
9850 int i;
9851
9852 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9853 {
9854 if (unformat (input, "hex %U", unformat_hex_string, &mask))
9855 ;
9856 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
9857 ;
9858 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
9859 ;
9860 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
9861 ;
9862 else
9863 break;
9864 }
9865
9866 if (l4 && !l3)
9867 {
9868 vec_free (mask);
9869 vec_free (l2);
9870 vec_free (l4);
9871 return 0;
9872 }
9873
9874 if (mask || l2 || l3 || l4)
9875 {
9876 if (l2 || l3 || l4)
9877 {
9878 /* "With a free Ethernet header in every package" */
9879 if (l2 == 0)
9880 vec_validate (l2, 13);
9881 mask = l2;
9882 if (vec_len (l3))
9883 {
9884 vec_append (mask, l3);
9885 vec_free (l3);
9886 }
9887 if (vec_len (l4))
9888 {
9889 vec_append (mask, l4);
9890 vec_free (l4);
9891 }
9892 }
9893
9894 /* Scan forward looking for the first significant mask octet */
9895 for (i = 0; i < vec_len (mask); i++)
9896 if (mask[i])
9897 break;
9898
9899 /* compute (skip, match) params */
9900 *skipp = i / sizeof (u32x4);
9901 vec_delete (mask, *skipp * sizeof (u32x4), 0);
9902
9903 /* Pad mask to an even multiple of the vector size */
9904 while (vec_len (mask) % sizeof (u32x4))
9905 vec_add1 (mask, 0);
9906
9907 match = vec_len (mask) / sizeof (u32x4);
9908
9909 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
9910 {
9911 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
9912 if (*tmp || *(tmp + 1))
9913 break;
9914 match--;
9915 }
9916 if (match == 0)
9917 clib_warning ("BUG: match 0");
9918
9919 _vec_len (mask) = match * sizeof (u32x4);
9920
9921 *matchp = match;
9922 *maskp = mask;
9923
9924 return 1;
9925 }
9926
9927 return 0;
9928}
Dave Barach4a3f69c2017-02-22 12:44:56 -05009929#endif /* VPP_API_TEST_BUILTIN */
Damjan Marion7cd468a2016-12-19 23:05:39 +01009930
9931#define foreach_l2_next \
9932_(drop, DROP) \
9933_(ethernet, ETHERNET_INPUT) \
9934_(ip4, IP4_INPUT) \
9935_(ip6, IP6_INPUT)
9936
9937uword
9938unformat_l2_next_index (unformat_input_t * input, va_list * args)
9939{
9940 u32 *miss_next_indexp = va_arg (*args, u32 *);
9941 u32 next_index = 0;
9942 u32 tmp;
9943
9944#define _(n,N) \
9945 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
9946 foreach_l2_next;
9947#undef _
9948
9949 if (unformat (input, "%d", &tmp))
9950 {
9951 next_index = tmp;
9952 goto out;
9953 }
9954
9955 return 0;
9956
9957out:
9958 *miss_next_indexp = next_index;
9959 return 1;
9960}
9961
9962#define foreach_ip_next \
9963_(drop, DROP) \
9964_(local, LOCAL) \
9965_(rewrite, REWRITE)
9966
9967uword
Dave Barach4a3f69c2017-02-22 12:44:56 -05009968api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009969{
9970 u32 *miss_next_indexp = va_arg (*args, u32 *);
9971 u32 next_index = 0;
9972 u32 tmp;
9973
9974#define _(n,N) \
9975 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
9976 foreach_ip_next;
9977#undef _
9978
9979 if (unformat (input, "%d", &tmp))
9980 {
9981 next_index = tmp;
9982 goto out;
9983 }
9984
9985 return 0;
9986
9987out:
9988 *miss_next_indexp = next_index;
9989 return 1;
9990}
9991
9992#define foreach_acl_next \
9993_(deny, DENY)
9994
9995uword
Dave Barach4a3f69c2017-02-22 12:44:56 -05009996api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009997{
9998 u32 *miss_next_indexp = va_arg (*args, u32 *);
9999 u32 next_index = 0;
10000 u32 tmp;
10001
10002#define _(n,N) \
10003 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
10004 foreach_acl_next;
10005#undef _
10006
10007 if (unformat (input, "permit"))
10008 {
10009 next_index = ~0;
10010 goto out;
10011 }
10012 else if (unformat (input, "%d", &tmp))
10013 {
10014 next_index = tmp;
10015 goto out;
10016 }
10017
10018 return 0;
10019
10020out:
10021 *miss_next_indexp = next_index;
10022 return 1;
10023}
10024
10025uword
10026unformat_policer_precolor (unformat_input_t * input, va_list * args)
10027{
10028 u32 *r = va_arg (*args, u32 *);
10029
10030 if (unformat (input, "conform-color"))
10031 *r = POLICE_CONFORM;
10032 else if (unformat (input, "exceed-color"))
10033 *r = POLICE_EXCEED;
10034 else
10035 return 0;
10036
10037 return 1;
10038}
10039
10040static int
10041api_classify_add_del_table (vat_main_t * vam)
10042{
10043 unformat_input_t *i = vam->input;
10044 vl_api_classify_add_del_table_t *mp;
10045
10046 u32 nbuckets = 2;
10047 u32 skip = ~0;
10048 u32 match = ~0;
10049 int is_add = 1;
10050 int del_chain = 0;
10051 u32 table_index = ~0;
10052 u32 next_table_index = ~0;
10053 u32 miss_next_index = ~0;
10054 u32 memory_size = 32 << 20;
10055 u8 *mask = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010056 u32 current_data_flag = 0;
10057 int current_data_offset = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010058 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010059
10060 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10061 {
10062 if (unformat (i, "del"))
10063 is_add = 0;
10064 else if (unformat (i, "del-chain"))
10065 {
10066 is_add = 0;
10067 del_chain = 1;
10068 }
10069 else if (unformat (i, "buckets %d", &nbuckets))
10070 ;
10071 else if (unformat (i, "memory_size %d", &memory_size))
10072 ;
10073 else if (unformat (i, "skip %d", &skip))
10074 ;
10075 else if (unformat (i, "match %d", &match))
10076 ;
10077 else if (unformat (i, "table %d", &table_index))
10078 ;
10079 else if (unformat (i, "mask %U", unformat_classify_mask,
10080 &mask, &skip, &match))
10081 ;
10082 else if (unformat (i, "next-table %d", &next_table_index))
10083 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010084 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010085 &miss_next_index))
10086 ;
10087 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
10088 &miss_next_index))
10089 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010090 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010091 &miss_next_index))
10092 ;
10093 else if (unformat (i, "current-data-flag %d", &current_data_flag))
10094 ;
10095 else if (unformat (i, "current-data-offset %d", &current_data_offset))
10096 ;
10097 else
10098 break;
10099 }
10100
10101 if (is_add && mask == 0)
10102 {
10103 errmsg ("Mask required");
10104 return -99;
10105 }
10106
10107 if (is_add && skip == ~0)
10108 {
10109 errmsg ("skip count required");
10110 return -99;
10111 }
10112
10113 if (is_add && match == ~0)
10114 {
10115 errmsg ("match count required");
10116 return -99;
10117 }
10118
10119 if (!is_add && table_index == ~0)
10120 {
10121 errmsg ("table index required for delete");
10122 return -99;
10123 }
10124
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010125 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010126
10127 mp->is_add = is_add;
10128 mp->del_chain = del_chain;
10129 mp->table_index = ntohl (table_index);
10130 mp->nbuckets = ntohl (nbuckets);
10131 mp->memory_size = ntohl (memory_size);
10132 mp->skip_n_vectors = ntohl (skip);
10133 mp->match_n_vectors = ntohl (match);
10134 mp->next_table_index = ntohl (next_table_index);
10135 mp->miss_next_index = ntohl (miss_next_index);
10136 mp->current_data_flag = ntohl (current_data_flag);
10137 mp->current_data_offset = ntohl (current_data_offset);
Juraj Sloboda75282452018-06-12 14:20:49 +020010138 mp->mask_len = ntohl (vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010139 clib_memcpy (mp->mask, mask, vec_len (mask));
10140
10141 vec_free (mask);
10142
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010143 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010144 W (ret);
10145 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010146}
10147
Dave Barach4a3f69c2017-02-22 12:44:56 -050010148#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010010149uword
10150unformat_l4_match (unformat_input_t * input, va_list * args)
10151{
10152 u8 **matchp = va_arg (*args, u8 **);
10153
10154 u8 *proto_header = 0;
10155 int src_port = 0;
10156 int dst_port = 0;
10157
10158 tcpudp_header_t h;
10159
10160 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10161 {
10162 if (unformat (input, "src_port %d", &src_port))
10163 ;
10164 else if (unformat (input, "dst_port %d", &dst_port))
10165 ;
10166 else
10167 return 0;
10168 }
10169
10170 h.src_port = clib_host_to_net_u16 (src_port);
10171 h.dst_port = clib_host_to_net_u16 (dst_port);
10172 vec_validate (proto_header, sizeof (h) - 1);
10173 memcpy (proto_header, &h, sizeof (h));
10174
10175 *matchp = proto_header;
10176
10177 return 1;
10178}
10179
10180uword
10181unformat_ip4_match (unformat_input_t * input, va_list * args)
10182{
10183 u8 **matchp = va_arg (*args, u8 **);
10184 u8 *match = 0;
10185 ip4_header_t *ip;
10186 int version = 0;
10187 u32 version_val;
10188 int hdr_length = 0;
10189 u32 hdr_length_val;
10190 int src = 0, dst = 0;
10191 ip4_address_t src_val, dst_val;
10192 int proto = 0;
10193 u32 proto_val;
10194 int tos = 0;
10195 u32 tos_val;
10196 int length = 0;
10197 u32 length_val;
10198 int fragment_id = 0;
10199 u32 fragment_id_val;
10200 int ttl = 0;
10201 int ttl_val;
10202 int checksum = 0;
10203 u32 checksum_val;
10204
10205 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10206 {
10207 if (unformat (input, "version %d", &version_val))
10208 version = 1;
10209 else if (unformat (input, "hdr_length %d", &hdr_length_val))
10210 hdr_length = 1;
10211 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
10212 src = 1;
10213 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
10214 dst = 1;
10215 else if (unformat (input, "proto %d", &proto_val))
10216 proto = 1;
10217 else if (unformat (input, "tos %d", &tos_val))
10218 tos = 1;
10219 else if (unformat (input, "length %d", &length_val))
10220 length = 1;
10221 else if (unformat (input, "fragment_id %d", &fragment_id_val))
10222 fragment_id = 1;
10223 else if (unformat (input, "ttl %d", &ttl_val))
10224 ttl = 1;
10225 else if (unformat (input, "checksum %d", &checksum_val))
10226 checksum = 1;
10227 else
10228 break;
10229 }
10230
10231 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
10232 + ttl + checksum == 0)
10233 return 0;
10234
10235 /*
10236 * Aligned because we use the real comparison functions
10237 */
10238 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
10239
10240 ip = (ip4_header_t *) match;
10241
10242 /* These are realistically matched in practice */
10243 if (src)
10244 ip->src_address.as_u32 = src_val.as_u32;
10245
10246 if (dst)
10247 ip->dst_address.as_u32 = dst_val.as_u32;
10248
10249 if (proto)
10250 ip->protocol = proto_val;
10251
10252
10253 /* These are not, but they're included for completeness */
10254 if (version)
10255 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
10256
10257 if (hdr_length)
10258 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
10259
10260 if (tos)
10261 ip->tos = tos_val;
10262
10263 if (length)
10264 ip->length = clib_host_to_net_u16 (length_val);
10265
10266 if (ttl)
10267 ip->ttl = ttl_val;
10268
10269 if (checksum)
10270 ip->checksum = clib_host_to_net_u16 (checksum_val);
10271
10272 *matchp = match;
10273 return 1;
10274}
10275
10276uword
10277unformat_ip6_match (unformat_input_t * input, va_list * args)
10278{
10279 u8 **matchp = va_arg (*args, u8 **);
10280 u8 *match = 0;
10281 ip6_header_t *ip;
10282 int version = 0;
10283 u32 version_val;
10284 u8 traffic_class = 0;
10285 u32 traffic_class_val = 0;
10286 u8 flow_label = 0;
10287 u8 flow_label_val;
10288 int src = 0, dst = 0;
10289 ip6_address_t src_val, dst_val;
10290 int proto = 0;
10291 u32 proto_val;
10292 int payload_length = 0;
10293 u32 payload_length_val;
10294 int hop_limit = 0;
10295 int hop_limit_val;
10296 u32 ip_version_traffic_class_and_flow_label;
10297
10298 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10299 {
10300 if (unformat (input, "version %d", &version_val))
10301 version = 1;
10302 else if (unformat (input, "traffic_class %d", &traffic_class_val))
10303 traffic_class = 1;
10304 else if (unformat (input, "flow_label %d", &flow_label_val))
10305 flow_label = 1;
10306 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
10307 src = 1;
10308 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
10309 dst = 1;
10310 else if (unformat (input, "proto %d", &proto_val))
10311 proto = 1;
10312 else if (unformat (input, "payload_length %d", &payload_length_val))
10313 payload_length = 1;
10314 else if (unformat (input, "hop_limit %d", &hop_limit_val))
10315 hop_limit = 1;
10316 else
10317 break;
10318 }
10319
10320 if (version + traffic_class + flow_label + src + dst + proto +
10321 payload_length + hop_limit == 0)
10322 return 0;
10323
10324 /*
10325 * Aligned because we use the real comparison functions
10326 */
10327 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
10328
10329 ip = (ip6_header_t *) match;
10330
10331 if (src)
10332 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
10333
10334 if (dst)
10335 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
10336
10337 if (proto)
10338 ip->protocol = proto_val;
10339
10340 ip_version_traffic_class_and_flow_label = 0;
10341
10342 if (version)
10343 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
10344
10345 if (traffic_class)
10346 ip_version_traffic_class_and_flow_label |=
10347 (traffic_class_val & 0xFF) << 20;
10348
10349 if (flow_label)
10350 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
10351
10352 ip->ip_version_traffic_class_and_flow_label =
10353 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
10354
10355 if (payload_length)
10356 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
10357
10358 if (hop_limit)
10359 ip->hop_limit = hop_limit_val;
10360
10361 *matchp = match;
10362 return 1;
10363}
10364
10365uword
10366unformat_l3_match (unformat_input_t * input, va_list * args)
10367{
10368 u8 **matchp = va_arg (*args, u8 **);
10369
10370 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10371 {
10372 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
10373 return 1;
10374 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
10375 return 1;
10376 else
10377 break;
10378 }
10379 return 0;
10380}
10381
10382uword
10383unformat_vlan_tag (unformat_input_t * input, va_list * args)
10384{
10385 u8 *tagp = va_arg (*args, u8 *);
10386 u32 tag;
10387
10388 if (unformat (input, "%d", &tag))
10389 {
10390 tagp[0] = (tag >> 8) & 0x0F;
10391 tagp[1] = tag & 0xFF;
10392 return 1;
10393 }
10394
10395 return 0;
10396}
10397
10398uword
10399unformat_l2_match (unformat_input_t * input, va_list * args)
10400{
10401 u8 **matchp = va_arg (*args, u8 **);
10402 u8 *match = 0;
10403 u8 src = 0;
10404 u8 src_val[6];
10405 u8 dst = 0;
10406 u8 dst_val[6];
10407 u8 proto = 0;
10408 u16 proto_val;
10409 u8 tag1 = 0;
10410 u8 tag1_val[2];
10411 u8 tag2 = 0;
10412 u8 tag2_val[2];
10413 int len = 14;
10414 u8 ignore_tag1 = 0;
10415 u8 ignore_tag2 = 0;
10416 u8 cos1 = 0;
10417 u8 cos2 = 0;
10418 u32 cos1_val = 0;
10419 u32 cos2_val = 0;
10420
10421 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10422 {
10423 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
10424 src = 1;
10425 else
10426 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
10427 dst = 1;
10428 else if (unformat (input, "proto %U",
10429 unformat_ethernet_type_host_byte_order, &proto_val))
10430 proto = 1;
10431 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
10432 tag1 = 1;
10433 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
10434 tag2 = 1;
10435 else if (unformat (input, "ignore-tag1"))
10436 ignore_tag1 = 1;
10437 else if (unformat (input, "ignore-tag2"))
10438 ignore_tag2 = 1;
10439 else if (unformat (input, "cos1 %d", &cos1_val))
10440 cos1 = 1;
10441 else if (unformat (input, "cos2 %d", &cos2_val))
10442 cos2 = 1;
10443 else
10444 break;
10445 }
10446 if ((src + dst + proto + tag1 + tag2 +
10447 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
10448 return 0;
10449
10450 if (tag1 || ignore_tag1 || cos1)
10451 len = 18;
10452 if (tag2 || ignore_tag2 || cos2)
10453 len = 22;
10454
10455 vec_validate_aligned (match, len - 1, sizeof (u32x4));
10456
10457 if (dst)
10458 clib_memcpy (match, dst_val, 6);
10459
10460 if (src)
10461 clib_memcpy (match + 6, src_val, 6);
10462
10463 if (tag2)
10464 {
10465 /* inner vlan tag */
10466 match[19] = tag2_val[1];
10467 match[18] = tag2_val[0];
10468 if (cos2)
10469 match[18] |= (cos2_val & 0x7) << 5;
10470 if (proto)
10471 {
10472 match[21] = proto_val & 0xff;
10473 match[20] = proto_val >> 8;
10474 }
10475 if (tag1)
10476 {
10477 match[15] = tag1_val[1];
10478 match[14] = tag1_val[0];
10479 }
10480 if (cos1)
10481 match[14] |= (cos1_val & 0x7) << 5;
10482 *matchp = match;
10483 return 1;
10484 }
10485 if (tag1)
10486 {
10487 match[15] = tag1_val[1];
10488 match[14] = tag1_val[0];
10489 if (proto)
10490 {
10491 match[17] = proto_val & 0xff;
10492 match[16] = proto_val >> 8;
10493 }
10494 if (cos1)
10495 match[14] |= (cos1_val & 0x7) << 5;
10496
10497 *matchp = match;
10498 return 1;
10499 }
10500 if (cos2)
10501 match[18] |= (cos2_val & 0x7) << 5;
10502 if (cos1)
10503 match[14] |= (cos1_val & 0x7) << 5;
10504 if (proto)
10505 {
10506 match[13] = proto_val & 0xff;
10507 match[12] = proto_val >> 8;
10508 }
10509
10510 *matchp = match;
10511 return 1;
10512}
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070010513
10514uword
10515unformat_qos_source (unformat_input_t * input, va_list * args)
10516{
10517 int *qs = va_arg (*args, int *);
10518
10519 if (unformat (input, "ip"))
10520 *qs = QOS_SOURCE_IP;
10521 else if (unformat (input, "mpls"))
10522 *qs = QOS_SOURCE_MPLS;
10523 else if (unformat (input, "ext"))
10524 *qs = QOS_SOURCE_EXT;
10525 else if (unformat (input, "vlan"))
10526 *qs = QOS_SOURCE_VLAN;
10527 else
10528 return 0;
10529
10530 return 1;
10531}
Dave Barach4a3f69c2017-02-22 12:44:56 -050010532#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010010533
10534uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050010535api_unformat_classify_match (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010010536{
10537 u8 **matchp = va_arg (*args, u8 **);
10538 u32 skip_n_vectors = va_arg (*args, u32);
10539 u32 match_n_vectors = va_arg (*args, u32);
10540
10541 u8 *match = 0;
10542 u8 *l2 = 0;
10543 u8 *l3 = 0;
10544 u8 *l4 = 0;
10545
10546 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10547 {
10548 if (unformat (input, "hex %U", unformat_hex_string, &match))
10549 ;
10550 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
10551 ;
10552 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
10553 ;
10554 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
10555 ;
10556 else
10557 break;
10558 }
10559
10560 if (l4 && !l3)
10561 {
10562 vec_free (match);
10563 vec_free (l2);
10564 vec_free (l4);
10565 return 0;
10566 }
10567
10568 if (match || l2 || l3 || l4)
10569 {
10570 if (l2 || l3 || l4)
10571 {
10572 /* "Win a free Ethernet header in every packet" */
10573 if (l2 == 0)
10574 vec_validate_aligned (l2, 13, sizeof (u32x4));
10575 match = l2;
10576 if (vec_len (l3))
10577 {
10578 vec_append_aligned (match, l3, sizeof (u32x4));
10579 vec_free (l3);
10580 }
10581 if (vec_len (l4))
10582 {
10583 vec_append_aligned (match, l4, sizeof (u32x4));
10584 vec_free (l4);
10585 }
10586 }
10587
10588 /* Make sure the vector is big enough even if key is all 0's */
10589 vec_validate_aligned
10590 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
10591 sizeof (u32x4));
10592
10593 /* Set size, include skipped vectors */
10594 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
10595
10596 *matchp = match;
10597
10598 return 1;
10599 }
10600
10601 return 0;
10602}
10603
10604static int
10605api_classify_add_del_session (vat_main_t * vam)
10606{
10607 unformat_input_t *i = vam->input;
10608 vl_api_classify_add_del_session_t *mp;
10609 int is_add = 1;
10610 u32 table_index = ~0;
10611 u32 hit_next_index = ~0;
10612 u32 opaque_index = ~0;
10613 u8 *match = 0;
10614 i32 advance = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010615 u32 skip_n_vectors = 0;
10616 u32 match_n_vectors = 0;
10617 u32 action = 0;
10618 u32 metadata = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010619 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010620
10621 /*
10622 * Warning: you have to supply skip_n and match_n
10623 * because the API client cant simply look at the classify
10624 * table object.
10625 */
10626
10627 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10628 {
10629 if (unformat (i, "del"))
10630 is_add = 0;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010631 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010632 &hit_next_index))
10633 ;
10634 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
10635 &hit_next_index))
10636 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010637 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010638 &hit_next_index))
10639 ;
10640 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
10641 ;
10642 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
10643 ;
10644 else if (unformat (i, "opaque-index %d", &opaque_index))
10645 ;
10646 else if (unformat (i, "skip_n %d", &skip_n_vectors))
10647 ;
10648 else if (unformat (i, "match_n %d", &match_n_vectors))
10649 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050010650 else if (unformat (i, "match %U", api_unformat_classify_match,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010651 &match, skip_n_vectors, match_n_vectors))
10652 ;
10653 else if (unformat (i, "advance %d", &advance))
10654 ;
10655 else if (unformat (i, "table-index %d", &table_index))
10656 ;
10657 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
10658 action = 1;
10659 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
10660 action = 2;
10661 else if (unformat (i, "action %d", &action))
10662 ;
10663 else if (unformat (i, "metadata %d", &metadata))
10664 ;
10665 else
10666 break;
10667 }
10668
10669 if (table_index == ~0)
10670 {
10671 errmsg ("Table index required");
10672 return -99;
10673 }
10674
10675 if (is_add && match == 0)
10676 {
10677 errmsg ("Match value required");
10678 return -99;
10679 }
10680
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010681 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010682
10683 mp->is_add = is_add;
10684 mp->table_index = ntohl (table_index);
10685 mp->hit_next_index = ntohl (hit_next_index);
10686 mp->opaque_index = ntohl (opaque_index);
10687 mp->advance = ntohl (advance);
10688 mp->action = action;
10689 mp->metadata = ntohl (metadata);
Juraj Sloboda75282452018-06-12 14:20:49 +020010690 mp->match_len = ntohl (vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010691 clib_memcpy (mp->match, match, vec_len (match));
10692 vec_free (match);
10693
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010694 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010695 W (ret);
10696 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010697}
10698
10699static int
10700api_classify_set_interface_ip_table (vat_main_t * vam)
10701{
10702 unformat_input_t *i = vam->input;
10703 vl_api_classify_set_interface_ip_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010704 u32 sw_if_index;
10705 int sw_if_index_set;
10706 u32 table_index = ~0;
10707 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010708 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010709
10710 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10711 {
10712 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10713 sw_if_index_set = 1;
10714 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10715 sw_if_index_set = 1;
10716 else if (unformat (i, "table %d", &table_index))
10717 ;
10718 else
10719 {
10720 clib_warning ("parse error '%U'", format_unformat_error, i);
10721 return -99;
10722 }
10723 }
10724
10725 if (sw_if_index_set == 0)
10726 {
10727 errmsg ("missing interface name or sw_if_index");
10728 return -99;
10729 }
10730
10731
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010732 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010733
10734 mp->sw_if_index = ntohl (sw_if_index);
10735 mp->table_index = ntohl (table_index);
10736 mp->is_ipv6 = is_ipv6;
10737
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010738 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010739 W (ret);
10740 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010741}
10742
10743static int
10744api_classify_set_interface_l2_tables (vat_main_t * vam)
10745{
10746 unformat_input_t *i = vam->input;
10747 vl_api_classify_set_interface_l2_tables_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010748 u32 sw_if_index;
10749 int sw_if_index_set;
10750 u32 ip4_table_index = ~0;
10751 u32 ip6_table_index = ~0;
10752 u32 other_table_index = ~0;
10753 u32 is_input = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010754 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010755
10756 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10757 {
10758 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10759 sw_if_index_set = 1;
10760 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10761 sw_if_index_set = 1;
10762 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10763 ;
10764 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10765 ;
10766 else if (unformat (i, "other-table %d", &other_table_index))
10767 ;
10768 else if (unformat (i, "is-input %d", &is_input))
10769 ;
10770 else
10771 {
10772 clib_warning ("parse error '%U'", format_unformat_error, i);
10773 return -99;
10774 }
10775 }
10776
10777 if (sw_if_index_set == 0)
10778 {
10779 errmsg ("missing interface name or sw_if_index");
10780 return -99;
10781 }
10782
10783
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010784 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010785
10786 mp->sw_if_index = ntohl (sw_if_index);
10787 mp->ip4_table_index = ntohl (ip4_table_index);
10788 mp->ip6_table_index = ntohl (ip6_table_index);
10789 mp->other_table_index = ntohl (other_table_index);
10790 mp->is_input = (u8) is_input;
10791
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010792 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010793 W (ret);
10794 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010795}
10796
10797static int
10798api_set_ipfix_exporter (vat_main_t * vam)
10799{
10800 unformat_input_t *i = vam->input;
10801 vl_api_set_ipfix_exporter_t *mp;
10802 ip4_address_t collector_address;
10803 u8 collector_address_set = 0;
10804 u32 collector_port = ~0;
10805 ip4_address_t src_address;
10806 u8 src_address_set = 0;
10807 u32 vrf_id = ~0;
10808 u32 path_mtu = ~0;
10809 u32 template_interval = ~0;
10810 u8 udp_checksum = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010811 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010812
10813 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10814 {
10815 if (unformat (i, "collector_address %U", unformat_ip4_address,
10816 &collector_address))
10817 collector_address_set = 1;
10818 else if (unformat (i, "collector_port %d", &collector_port))
10819 ;
10820 else if (unformat (i, "src_address %U", unformat_ip4_address,
10821 &src_address))
10822 src_address_set = 1;
10823 else if (unformat (i, "vrf_id %d", &vrf_id))
10824 ;
10825 else if (unformat (i, "path_mtu %d", &path_mtu))
10826 ;
10827 else if (unformat (i, "template_interval %d", &template_interval))
10828 ;
10829 else if (unformat (i, "udp_checksum"))
10830 udp_checksum = 1;
10831 else
10832 break;
10833 }
10834
10835 if (collector_address_set == 0)
10836 {
10837 errmsg ("collector_address required");
10838 return -99;
10839 }
10840
10841 if (src_address_set == 0)
10842 {
10843 errmsg ("src_address required");
10844 return -99;
10845 }
10846
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010847 M (SET_IPFIX_EXPORTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010848
Jakub Grajciar2f71a882019-10-10 14:21:22 +020010849 memcpy (mp->collector_address.un.ip4, collector_address.data,
Damjan Marion7cd468a2016-12-19 23:05:39 +010010850 sizeof (collector_address.data));
10851 mp->collector_port = htons ((u16) collector_port);
Jakub Grajciar2f71a882019-10-10 14:21:22 +020010852 memcpy (mp->src_address.un.ip4, src_address.data,
10853 sizeof (src_address.data));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010854 mp->vrf_id = htonl (vrf_id);
10855 mp->path_mtu = htonl (path_mtu);
10856 mp->template_interval = htonl (template_interval);
10857 mp->udp_checksum = udp_checksum;
10858
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010859 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010860 W (ret);
10861 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010862}
10863
10864static int
10865api_set_ipfix_classify_stream (vat_main_t * vam)
10866{
10867 unformat_input_t *i = vam->input;
10868 vl_api_set_ipfix_classify_stream_t *mp;
10869 u32 domain_id = 0;
10870 u32 src_port = UDP_DST_PORT_ipfix;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010871 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010872
10873 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10874 {
10875 if (unformat (i, "domain %d", &domain_id))
10876 ;
10877 else if (unformat (i, "src_port %d", &src_port))
10878 ;
10879 else
10880 {
10881 errmsg ("unknown input `%U'", format_unformat_error, i);
10882 return -99;
10883 }
10884 }
10885
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010886 M (SET_IPFIX_CLASSIFY_STREAM, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010887
10888 mp->domain_id = htonl (domain_id);
10889 mp->src_port = htons ((u16) src_port);
10890
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010891 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010892 W (ret);
10893 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010894}
10895
10896static int
10897api_ipfix_classify_table_add_del (vat_main_t * vam)
10898{
10899 unformat_input_t *i = vam->input;
10900 vl_api_ipfix_classify_table_add_del_t *mp;
10901 int is_add = -1;
10902 u32 classify_table_index = ~0;
10903 u8 ip_version = 0;
10904 u8 transport_protocol = 255;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010905 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010906
10907 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10908 {
10909 if (unformat (i, "add"))
10910 is_add = 1;
10911 else if (unformat (i, "del"))
10912 is_add = 0;
10913 else if (unformat (i, "table %d", &classify_table_index))
10914 ;
10915 else if (unformat (i, "ip4"))
10916 ip_version = 4;
10917 else if (unformat (i, "ip6"))
10918 ip_version = 6;
10919 else if (unformat (i, "tcp"))
10920 transport_protocol = 6;
10921 else if (unformat (i, "udp"))
10922 transport_protocol = 17;
10923 else
10924 {
10925 errmsg ("unknown input `%U'", format_unformat_error, i);
10926 return -99;
10927 }
10928 }
10929
10930 if (is_add == -1)
10931 {
10932 errmsg ("expecting: add|del");
10933 return -99;
10934 }
10935 if (classify_table_index == ~0)
10936 {
10937 errmsg ("classifier table not specified");
10938 return -99;
10939 }
10940 if (ip_version == 0)
10941 {
10942 errmsg ("IP version not specified");
10943 return -99;
10944 }
10945
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010946 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010947
10948 mp->is_add = is_add;
10949 mp->table_id = htonl (classify_table_index);
10950 mp->ip_version = ip_version;
10951 mp->transport_protocol = transport_protocol;
10952
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010953 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010954 W (ret);
10955 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010956}
10957
10958static int
10959api_get_node_index (vat_main_t * vam)
10960{
10961 unformat_input_t *i = vam->input;
10962 vl_api_get_node_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010963 u8 *name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010964 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010965
10966 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10967 {
10968 if (unformat (i, "node %s", &name))
10969 ;
10970 else
10971 break;
10972 }
10973 if (name == 0)
10974 {
10975 errmsg ("node name required");
10976 return -99;
10977 }
10978 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
10979 {
10980 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
10981 return -99;
10982 }
10983
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010984 M (GET_NODE_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010985 clib_memcpy (mp->node_name, name, vec_len (name));
10986 vec_free (name);
10987
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010988 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010989 W (ret);
10990 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010991}
10992
10993static int
10994api_get_next_index (vat_main_t * vam)
10995{
10996 unformat_input_t *i = vam->input;
10997 vl_api_get_next_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010998 u8 *node_name = 0, *next_node_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010999 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011000
11001 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11002 {
11003 if (unformat (i, "node-name %s", &node_name))
11004 ;
11005 else if (unformat (i, "next-node-name %s", &next_node_name))
11006 break;
11007 }
11008
11009 if (node_name == 0)
11010 {
11011 errmsg ("node name required");
11012 return -99;
11013 }
11014 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
11015 {
11016 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11017 return -99;
11018 }
11019
11020 if (next_node_name == 0)
11021 {
11022 errmsg ("next node name required");
11023 return -99;
11024 }
11025 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
11026 {
11027 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
11028 return -99;
11029 }
11030
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011031 M (GET_NEXT_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011032 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
11033 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
11034 vec_free (node_name);
11035 vec_free (next_node_name);
11036
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011037 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011038 W (ret);
11039 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011040}
11041
11042static int
11043api_add_node_next (vat_main_t * vam)
11044{
11045 unformat_input_t *i = vam->input;
11046 vl_api_add_node_next_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011047 u8 *name = 0;
11048 u8 *next = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011049 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011050
11051 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11052 {
11053 if (unformat (i, "node %s", &name))
11054 ;
11055 else if (unformat (i, "next %s", &next))
11056 ;
11057 else
11058 break;
11059 }
11060 if (name == 0)
11061 {
11062 errmsg ("node name required");
11063 return -99;
11064 }
11065 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
11066 {
11067 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
11068 return -99;
11069 }
11070 if (next == 0)
11071 {
11072 errmsg ("next node required");
11073 return -99;
11074 }
11075 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
11076 {
11077 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
11078 return -99;
11079 }
11080
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011081 M (ADD_NODE_NEXT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011082 clib_memcpy (mp->node_name, name, vec_len (name));
11083 clib_memcpy (mp->next_name, next, vec_len (next));
11084 vec_free (name);
11085 vec_free (next);
11086
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011087 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011088 W (ret);
11089 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011090}
11091
11092static int
11093api_l2tpv3_create_tunnel (vat_main_t * vam)
11094{
11095 unformat_input_t *i = vam->input;
11096 ip6_address_t client_address, our_address;
11097 int client_address_set = 0;
11098 int our_address_set = 0;
11099 u32 local_session_id = 0;
11100 u32 remote_session_id = 0;
11101 u64 local_cookie = 0;
11102 u64 remote_cookie = 0;
11103 u8 l2_sublayer_present = 0;
11104 vl_api_l2tpv3_create_tunnel_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011105 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011106
11107 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11108 {
11109 if (unformat (i, "client_address %U", unformat_ip6_address,
11110 &client_address))
11111 client_address_set = 1;
11112 else if (unformat (i, "our_address %U", unformat_ip6_address,
11113 &our_address))
11114 our_address_set = 1;
11115 else if (unformat (i, "local_session_id %d", &local_session_id))
11116 ;
11117 else if (unformat (i, "remote_session_id %d", &remote_session_id))
11118 ;
11119 else if (unformat (i, "local_cookie %lld", &local_cookie))
11120 ;
11121 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
11122 ;
11123 else if (unformat (i, "l2-sublayer-present"))
11124 l2_sublayer_present = 1;
11125 else
11126 break;
11127 }
11128
11129 if (client_address_set == 0)
11130 {
11131 errmsg ("client_address required");
11132 return -99;
11133 }
11134
11135 if (our_address_set == 0)
11136 {
11137 errmsg ("our_address required");
11138 return -99;
11139 }
11140
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011141 M (L2TPV3_CREATE_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011142
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011143 clib_memcpy (mp->client_address.un.ip6, client_address.as_u8,
11144 sizeof (ip6_address_t));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011145
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011146 clib_memcpy (mp->our_address.un.ip6, our_address.as_u8,
11147 sizeof (ip6_address_t));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011148
11149 mp->local_session_id = ntohl (local_session_id);
11150 mp->remote_session_id = ntohl (remote_session_id);
11151 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
11152 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
11153 mp->l2_sublayer_present = l2_sublayer_present;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011154
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011155 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011156 W (ret);
11157 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011158}
11159
11160static int
11161api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
11162{
11163 unformat_input_t *i = vam->input;
11164 u32 sw_if_index;
11165 u8 sw_if_index_set = 0;
11166 u64 new_local_cookie = 0;
11167 u64 new_remote_cookie = 0;
11168 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011169 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011170
11171 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11172 {
11173 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11174 sw_if_index_set = 1;
11175 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11176 sw_if_index_set = 1;
11177 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
11178 ;
11179 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
11180 ;
11181 else
11182 break;
11183 }
11184
11185 if (sw_if_index_set == 0)
11186 {
11187 errmsg ("missing interface name or sw_if_index");
11188 return -99;
11189 }
11190
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011191 M (L2TPV3_SET_TUNNEL_COOKIES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011192
11193 mp->sw_if_index = ntohl (sw_if_index);
11194 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
11195 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
11196
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011197 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011198 W (ret);
11199 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011200}
11201
11202static int
11203api_l2tpv3_interface_enable_disable (vat_main_t * vam)
11204{
11205 unformat_input_t *i = vam->input;
11206 vl_api_l2tpv3_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011207 u32 sw_if_index;
11208 u8 sw_if_index_set = 0;
11209 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011210 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011211
11212 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11213 {
11214 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11215 sw_if_index_set = 1;
11216 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11217 sw_if_index_set = 1;
11218 else if (unformat (i, "enable"))
11219 enable_disable = 1;
11220 else if (unformat (i, "disable"))
11221 enable_disable = 0;
11222 else
11223 break;
11224 }
11225
11226 if (sw_if_index_set == 0)
11227 {
11228 errmsg ("missing interface name or sw_if_index");
11229 return -99;
11230 }
11231
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011232 M (L2TPV3_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011233
11234 mp->sw_if_index = ntohl (sw_if_index);
11235 mp->enable_disable = enable_disable;
11236
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011237 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011238 W (ret);
11239 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011240}
11241
11242static int
11243api_l2tpv3_set_lookup_key (vat_main_t * vam)
11244{
11245 unformat_input_t *i = vam->input;
11246 vl_api_l2tpv3_set_lookup_key_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011247 u8 key = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011248 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011249
11250 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11251 {
11252 if (unformat (i, "lookup_v6_src"))
11253 key = L2T_LOOKUP_SRC_ADDRESS;
11254 else if (unformat (i, "lookup_v6_dst"))
11255 key = L2T_LOOKUP_DST_ADDRESS;
11256 else if (unformat (i, "lookup_session_id"))
11257 key = L2T_LOOKUP_SESSION_ID;
11258 else
11259 break;
11260 }
11261
11262 if (key == (u8) ~ 0)
11263 {
11264 errmsg ("l2tp session lookup key unset");
11265 return -99;
11266 }
11267
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011268 M (L2TPV3_SET_LOOKUP_KEY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011269
11270 mp->key = key;
11271
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011272 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011273 W (ret);
11274 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011275}
11276
11277static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
11278 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
11279{
11280 vat_main_t *vam = &vat_main;
11281
11282 print (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)",
11283 format_ip6_address, mp->our_address,
11284 format_ip6_address, mp->client_address,
11285 clib_net_to_host_u32 (mp->sw_if_index));
11286
11287 print (vam->ofp,
11288 " local cookies %016llx %016llx remote cookie %016llx",
11289 clib_net_to_host_u64 (mp->local_cookie[0]),
11290 clib_net_to_host_u64 (mp->local_cookie[1]),
11291 clib_net_to_host_u64 (mp->remote_cookie));
11292
11293 print (vam->ofp, " local session-id %d remote session-id %d",
11294 clib_net_to_host_u32 (mp->local_session_id),
11295 clib_net_to_host_u32 (mp->remote_session_id));
11296
11297 print (vam->ofp, " l2 specific sublayer %s\n",
11298 mp->l2_sublayer_present ? "preset" : "absent");
11299
11300}
11301
11302static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
11303 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
11304{
11305 vat_main_t *vam = &vat_main;
11306 vat_json_node_t *node = NULL;
11307 struct in6_addr addr;
11308
11309 if (VAT_JSON_ARRAY != vam->json_tree.type)
11310 {
11311 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11312 vat_json_init_array (&vam->json_tree);
11313 }
11314 node = vat_json_array_add (&vam->json_tree);
11315
11316 vat_json_init_object (node);
11317
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011318 clib_memcpy (&addr, mp->our_address.un.ip6, sizeof (addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011319 vat_json_object_add_ip6 (node, "our_address", addr);
Jakub Grajciar3ae52622019-10-28 10:22:01 +010011320 clib_memcpy (&addr, mp->client_address.un.ip6, sizeof (addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011321 vat_json_object_add_ip6 (node, "client_address", addr);
11322
11323 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
11324 vat_json_init_array (lc);
11325 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
11326 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
11327 vat_json_object_add_uint (node, "remote_cookie",
11328 clib_net_to_host_u64 (mp->remote_cookie));
11329
11330 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
11331 vat_json_object_add_uint (node, "local_session_id",
11332 clib_net_to_host_u32 (mp->local_session_id));
11333 vat_json_object_add_uint (node, "remote_session_id",
11334 clib_net_to_host_u32 (mp->remote_session_id));
11335 vat_json_object_add_string_copy (node, "l2_sublayer",
11336 mp->l2_sublayer_present ? (u8 *) "present"
11337 : (u8 *) "absent");
11338}
11339
11340static int
11341api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
11342{
11343 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011344 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011345 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011346
11347 /* Get list of l2tpv3-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011348 M (SW_IF_L2TPV3_TUNNEL_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011349 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011350
11351 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040011352 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011353 S (mp_ping);
11354
Jon Loeliger56c7b012017-02-01 12:31:41 -060011355 W (ret);
11356 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011357}
11358
11359
Damjan Marion8389fb92017-10-13 18:29:53 +020011360static void vl_api_sw_interface_tap_v2_details_t_handler
11361 (vl_api_sw_interface_tap_v2_details_t * mp)
11362{
11363 vat_main_t *vam = &vat_main;
11364
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020011365 u8 *ip4 =
11366 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
11367 mp->host_ip4_prefix.len);
11368 u8 *ip6 =
11369 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
11370 mp->host_ip6_prefix.len);
Milan Lenco73e7f422017-12-14 10:04:25 +010011371
11372 print (vam->ofp,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010011373 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
Milan Lenco73e7f422017-12-14 10:04:25 +010011374 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
11375 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
11376 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010011377 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
Milan Lenco73e7f422017-12-14 10:04:25 +010011378
11379 vec_free (ip4);
11380 vec_free (ip6);
Damjan Marion8389fb92017-10-13 18:29:53 +020011381}
11382
11383static void vl_api_sw_interface_tap_v2_details_t_handler_json
11384 (vl_api_sw_interface_tap_v2_details_t * mp)
11385{
11386 vat_main_t *vam = &vat_main;
11387 vat_json_node_t *node = NULL;
11388
11389 if (VAT_JSON_ARRAY != vam->json_tree.type)
11390 {
11391 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11392 vat_json_init_array (&vam->json_tree);
11393 }
11394 node = vat_json_array_add (&vam->json_tree);
11395
11396 vat_json_init_object (node);
Milan Lenco73e7f422017-12-14 10:04:25 +010011397 vat_json_object_add_uint (node, "id", ntohl (mp->id));
Damjan Marion8389fb92017-10-13 18:29:53 +020011398 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010011399 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
Damjan Marion8389fb92017-10-13 18:29:53 +020011400 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Milan Lenco73e7f422017-12-14 10:04:25 +010011401 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
11402 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
11403 vat_json_object_add_string_copy (node, "host_mac_addr",
11404 format (0, "%U", format_ethernet_address,
11405 &mp->host_mac_addr));
11406 vat_json_object_add_string_copy (node, "host_namespace",
11407 mp->host_namespace);
11408 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
11409 vat_json_object_add_string_copy (node, "host_ip4_addr",
11410 format (0, "%U/%d", format_ip4_address,
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020011411 mp->host_ip4_prefix.address,
11412 mp->host_ip4_prefix.len));
11413 vat_json_object_add_string_copy (node, "host_ip6_prefix",
Milan Lenco73e7f422017-12-14 10:04:25 +010011414 format (0, "%U/%d", format_ip6_address,
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020011415 mp->host_ip6_prefix.address,
11416 mp->host_ip6_prefix.len));
Milan Lenco73e7f422017-12-14 10:04:25 +010011417
Damjan Marion8389fb92017-10-13 18:29:53 +020011418}
11419
11420static int
11421api_sw_interface_tap_v2_dump (vat_main_t * vam)
11422{
11423 vl_api_sw_interface_tap_v2_dump_t *mp;
11424 vl_api_control_ping_t *mp_ping;
11425 int ret;
11426
Milan Lenco73e7f422017-12-14 10:04:25 +010011427 print (vam->ofp,
11428 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
11429 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
11430 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
11431 "host_ip6_addr");
11432
Damjan Marion8389fb92017-10-13 18:29:53 +020011433 /* Get list of tap interfaces */
11434 M (SW_INTERFACE_TAP_V2_DUMP, mp);
11435 S (mp);
11436
11437 /* Use a control ping for synchronization */
11438 MPING (CONTROL_PING, mp_ping);
11439 S (mp_ping);
11440
11441 W (ret);
11442 return ret;
11443}
11444
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011445static void vl_api_sw_interface_virtio_pci_details_t_handler
11446 (vl_api_sw_interface_virtio_pci_details_t * mp)
11447{
11448 vat_main_t *vam = &vat_main;
11449
11450 typedef union
11451 {
11452 struct
11453 {
11454 u16 domain;
11455 u8 bus;
11456 u8 slot:5;
11457 u8 function:3;
11458 };
11459 u32 as_u32;
11460 } pci_addr_t;
11461 pci_addr_t addr;
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011462
11463 addr.domain = ntohs (mp->pci_addr.domain);
11464 addr.bus = mp->pci_addr.bus;
11465 addr.slot = mp->pci_addr.slot;
11466 addr.function = mp->pci_addr.function;
11467
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011468 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
11469 addr.slot, addr.function);
11470
11471 print (vam->ofp,
11472 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
11473 pci_addr, ntohl (mp->sw_if_index),
11474 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
11475 format_ethernet_address, mp->mac_addr,
11476 clib_net_to_host_u64 (mp->features));
11477 vec_free (pci_addr);
11478}
11479
11480static void vl_api_sw_interface_virtio_pci_details_t_handler_json
11481 (vl_api_sw_interface_virtio_pci_details_t * mp)
11482{
11483 vat_main_t *vam = &vat_main;
11484 vat_json_node_t *node = NULL;
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011485 vlib_pci_addr_t pci_addr;
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011486
11487 if (VAT_JSON_ARRAY != vam->json_tree.type)
11488 {
11489 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11490 vat_json_init_array (&vam->json_tree);
11491 }
11492 node = vat_json_array_add (&vam->json_tree);
11493
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011494 pci_addr.domain = ntohs (mp->pci_addr.domain);
11495 pci_addr.bus = mp->pci_addr.bus;
11496 pci_addr.slot = mp->pci_addr.slot;
11497 pci_addr.function = mp->pci_addr.function;
11498
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011499 vat_json_init_object (node);
Jakub Grajciar2c504f82019-09-26 10:34:41 +020011500 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010011501 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11502 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
11503 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
11504 vat_json_object_add_uint (node, "features",
11505 clib_net_to_host_u64 (mp->features));
11506 vat_json_object_add_string_copy (node, "mac_addr",
11507 format (0, "%U", format_ethernet_address,
11508 &mp->mac_addr));
11509}
11510
11511static int
11512api_sw_interface_virtio_pci_dump (vat_main_t * vam)
11513{
11514 vl_api_sw_interface_virtio_pci_dump_t *mp;
11515 vl_api_control_ping_t *mp_ping;
11516 int ret;
11517
11518 print (vam->ofp,
11519 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
11520 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
11521 "mac_addr", "features");
11522
11523 /* Get list of tap interfaces */
11524 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
11525 S (mp);
11526
11527 /* Use a control ping for synchronization */
11528 MPING (CONTROL_PING, mp_ping);
11529 S (mp_ping);
11530
11531 W (ret);
11532 return ret;
11533}
11534
eyal bariaf86a482018-04-17 11:20:27 +030011535static int
11536api_vxlan_offload_rx (vat_main_t * vam)
11537{
11538 unformat_input_t *line_input = vam->input;
11539 vl_api_vxlan_offload_rx_t *mp;
11540 u32 hw_if_index = ~0, rx_if_index = ~0;
11541 u8 is_add = 1;
11542 int ret;
11543
11544 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11545 {
11546 if (unformat (line_input, "del"))
11547 is_add = 0;
11548 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
11549 &hw_if_index))
11550 ;
11551 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
11552 ;
11553 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
11554 &rx_if_index))
11555 ;
11556 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
11557 ;
11558 else
11559 {
11560 errmsg ("parse error '%U'", format_unformat_error, line_input);
11561 return -99;
11562 }
11563 }
11564
11565 if (hw_if_index == ~0)
11566 {
11567 errmsg ("no hw interface");
11568 return -99;
11569 }
11570
11571 if (rx_if_index == ~0)
11572 {
11573 errmsg ("no rx tunnel");
11574 return -99;
11575 }
11576
11577 M (VXLAN_OFFLOAD_RX, mp);
11578
11579 mp->hw_if_index = ntohl (hw_if_index);
11580 mp->sw_if_index = ntohl (rx_if_index);
11581 mp->enable = is_add;
11582
11583 S (mp);
11584 W (ret);
11585 return ret;
11586}
11587
Damjan Marion7cd468a2016-12-19 23:05:39 +010011588static uword unformat_vxlan_decap_next
11589 (unformat_input_t * input, va_list * args)
11590{
11591 u32 *result = va_arg (*args, u32 *);
11592 u32 tmp;
11593
11594 if (unformat (input, "l2"))
11595 *result = VXLAN_INPUT_NEXT_L2_INPUT;
11596 else if (unformat (input, "%d", &tmp))
11597 *result = tmp;
11598 else
11599 return 0;
11600 return 1;
11601}
11602
11603static int
11604api_vxlan_add_del_tunnel (vat_main_t * vam)
11605{
11606 unformat_input_t *line_input = vam->input;
11607 vl_api_vxlan_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011608 ip46_address_t src, dst;
11609 u8 is_add = 1;
11610 u8 ipv4_set = 0, ipv6_set = 0;
11611 u8 src_set = 0;
11612 u8 dst_set = 0;
11613 u8 grp_set = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011614 u32 instance = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011615 u32 mcast_sw_if_index = ~0;
11616 u32 encap_vrf_id = 0;
11617 u32 decap_next_index = ~0;
11618 u32 vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011619 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011620
11621 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040011622 clib_memset (&src, 0, sizeof src);
11623 clib_memset (&dst, 0, sizeof dst);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011624
11625 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11626 {
11627 if (unformat (line_input, "del"))
11628 is_add = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011629 else if (unformat (line_input, "instance %d", &instance))
11630 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011631 else
11632 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
11633 {
11634 ipv4_set = 1;
11635 src_set = 1;
11636 }
11637 else
11638 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
11639 {
11640 ipv4_set = 1;
11641 dst_set = 1;
11642 }
11643 else
11644 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
11645 {
11646 ipv6_set = 1;
11647 src_set = 1;
11648 }
11649 else
11650 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
11651 {
11652 ipv6_set = 1;
11653 dst_set = 1;
11654 }
11655 else if (unformat (line_input, "group %U %U",
11656 unformat_ip4_address, &dst.ip4,
11657 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11658 {
11659 grp_set = dst_set = 1;
11660 ipv4_set = 1;
11661 }
11662 else if (unformat (line_input, "group %U",
11663 unformat_ip4_address, &dst.ip4))
11664 {
11665 grp_set = dst_set = 1;
11666 ipv4_set = 1;
11667 }
11668 else if (unformat (line_input, "group %U %U",
11669 unformat_ip6_address, &dst.ip6,
11670 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11671 {
11672 grp_set = dst_set = 1;
11673 ipv6_set = 1;
11674 }
11675 else if (unformat (line_input, "group %U",
11676 unformat_ip6_address, &dst.ip6))
11677 {
11678 grp_set = dst_set = 1;
11679 ipv6_set = 1;
11680 }
11681 else
11682 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
11683 ;
11684 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
11685 ;
11686 else if (unformat (line_input, "decap-next %U",
11687 unformat_vxlan_decap_next, &decap_next_index))
11688 ;
11689 else if (unformat (line_input, "vni %d", &vni))
11690 ;
11691 else
11692 {
11693 errmsg ("parse error '%U'", format_unformat_error, line_input);
11694 return -99;
11695 }
11696 }
11697
11698 if (src_set == 0)
11699 {
11700 errmsg ("tunnel src address not specified");
11701 return -99;
11702 }
11703 if (dst_set == 0)
11704 {
11705 errmsg ("tunnel dst address not specified");
11706 return -99;
11707 }
11708
11709 if (grp_set && !ip46_address_is_multicast (&dst))
11710 {
11711 errmsg ("tunnel group address not multicast");
11712 return -99;
11713 }
11714 if (grp_set && mcast_sw_if_index == ~0)
11715 {
11716 errmsg ("tunnel nonexistent multicast device");
11717 return -99;
11718 }
11719 if (grp_set == 0 && ip46_address_is_multicast (&dst))
11720 {
11721 errmsg ("tunnel dst address must be unicast");
11722 return -99;
11723 }
11724
11725
11726 if (ipv4_set && ipv6_set)
11727 {
11728 errmsg ("both IPv4 and IPv6 addresses specified");
11729 return -99;
11730 }
11731
11732 if ((vni == 0) || (vni >> 24))
11733 {
11734 errmsg ("vni not specified or out of range");
11735 return -99;
11736 }
11737
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011738 M (VXLAN_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011739
11740 if (ipv6_set)
11741 {
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011742 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
11743 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011744 }
11745 else
11746 {
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011747 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
11748 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011749 }
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011750 mp->src_address.af = ipv6_set;
11751 mp->dst_address.af = ipv6_set;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011752
11753 mp->instance = htonl (instance);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011754 mp->encap_vrf_id = ntohl (encap_vrf_id);
11755 mp->decap_next_index = ntohl (decap_next_index);
11756 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
11757 mp->vni = ntohl (vni);
11758 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011759
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011760 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011761 W (ret);
11762 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011763}
11764
11765static void vl_api_vxlan_tunnel_details_t_handler
11766 (vl_api_vxlan_tunnel_details_t * mp)
11767{
11768 vat_main_t *vam = &vat_main;
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011769 ip46_address_t src =
11770 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
11771 ip46_address_t dst =
11772 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011773
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011774 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010011775 ntohl (mp->sw_if_index),
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011776 ntohl (mp->instance),
Damjan Marion7cd468a2016-12-19 23:05:39 +010011777 format_ip46_address, &src, IP46_TYPE_ANY,
11778 format_ip46_address, &dst, IP46_TYPE_ANY,
11779 ntohl (mp->encap_vrf_id),
11780 ntohl (mp->decap_next_index), ntohl (mp->vni),
11781 ntohl (mp->mcast_sw_if_index));
11782}
11783
11784static void vl_api_vxlan_tunnel_details_t_handler_json
11785 (vl_api_vxlan_tunnel_details_t * mp)
11786{
11787 vat_main_t *vam = &vat_main;
11788 vat_json_node_t *node = NULL;
11789
11790 if (VAT_JSON_ARRAY != vam->json_tree.type)
11791 {
11792 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11793 vat_json_init_array (&vam->json_tree);
11794 }
11795 node = vat_json_array_add (&vam->json_tree);
11796
11797 vat_json_init_object (node);
11798 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011799
11800 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
11801
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011802 if (mp->src_address.af)
Damjan Marion7cd468a2016-12-19 23:05:39 +010011803 {
11804 struct in6_addr ip6;
11805
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011806 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011807 vat_json_object_add_ip6 (node, "src_address", ip6);
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011808 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011809 vat_json_object_add_ip6 (node, "dst_address", ip6);
11810 }
11811 else
11812 {
11813 struct in_addr ip4;
11814
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011815 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011816 vat_json_object_add_ip4 (node, "src_address", ip4);
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010011817 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011818 vat_json_object_add_ip4 (node, "dst_address", ip4);
11819 }
11820 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
11821 vat_json_object_add_uint (node, "decap_next_index",
11822 ntohl (mp->decap_next_index));
11823 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011824 vat_json_object_add_uint (node, "mcast_sw_if_index",
11825 ntohl (mp->mcast_sw_if_index));
11826}
11827
11828static int
11829api_vxlan_tunnel_dump (vat_main_t * vam)
11830{
11831 unformat_input_t *i = vam->input;
11832 vl_api_vxlan_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011833 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011834 u32 sw_if_index;
11835 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011836 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011837
11838 /* Parse args required to build the message */
11839 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11840 {
11841 if (unformat (i, "sw_if_index %d", &sw_if_index))
11842 sw_if_index_set = 1;
11843 else
11844 break;
11845 }
11846
11847 if (sw_if_index_set == 0)
11848 {
11849 sw_if_index = ~0;
11850 }
11851
11852 if (!vam->json_output)
11853 {
Jon Loeliger3d460bd2018-02-01 16:36:12 -060011854 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
11855 "sw_if_index", "instance", "src_address", "dst_address",
Damjan Marion7cd468a2016-12-19 23:05:39 +010011856 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
11857 }
11858
11859 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011860 M (VXLAN_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011861
11862 mp->sw_if_index = htonl (sw_if_index);
11863
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011864 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011865
11866 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040011867 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060011868 S (mp_ping);
11869
Jon Loeliger56c7b012017-02-01 12:31:41 -060011870 W (ret);
11871 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011872}
11873
Marco Varleseb598f1d2017-09-19 14:25:28 +020011874static uword unformat_geneve_decap_next
11875 (unformat_input_t * input, va_list * args)
11876{
11877 u32 *result = va_arg (*args, u32 *);
11878 u32 tmp;
11879
11880 if (unformat (input, "l2"))
11881 *result = GENEVE_INPUT_NEXT_L2_INPUT;
11882 else if (unformat (input, "%d", &tmp))
11883 *result = tmp;
11884 else
11885 return 0;
11886 return 1;
11887}
11888
11889static int
11890api_geneve_add_del_tunnel (vat_main_t * vam)
11891{
11892 unformat_input_t *line_input = vam->input;
11893 vl_api_geneve_add_del_tunnel_t *mp;
11894 ip46_address_t src, dst;
11895 u8 is_add = 1;
11896 u8 ipv4_set = 0, ipv6_set = 0;
11897 u8 src_set = 0;
11898 u8 dst_set = 0;
11899 u8 grp_set = 0;
11900 u32 mcast_sw_if_index = ~0;
11901 u32 encap_vrf_id = 0;
11902 u32 decap_next_index = ~0;
11903 u32 vni = 0;
11904 int ret;
11905
11906 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040011907 clib_memset (&src, 0, sizeof src);
11908 clib_memset (&dst, 0, sizeof dst);
Marco Varleseb598f1d2017-09-19 14:25:28 +020011909
11910 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11911 {
11912 if (unformat (line_input, "del"))
11913 is_add = 0;
11914 else
11915 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
11916 {
11917 ipv4_set = 1;
11918 src_set = 1;
11919 }
11920 else
11921 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
11922 {
11923 ipv4_set = 1;
11924 dst_set = 1;
11925 }
11926 else
11927 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
11928 {
11929 ipv6_set = 1;
11930 src_set = 1;
11931 }
11932 else
11933 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
11934 {
11935 ipv6_set = 1;
11936 dst_set = 1;
11937 }
11938 else if (unformat (line_input, "group %U %U",
11939 unformat_ip4_address, &dst.ip4,
11940 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11941 {
11942 grp_set = dst_set = 1;
11943 ipv4_set = 1;
11944 }
11945 else if (unformat (line_input, "group %U",
11946 unformat_ip4_address, &dst.ip4))
11947 {
11948 grp_set = dst_set = 1;
11949 ipv4_set = 1;
11950 }
11951 else if (unformat (line_input, "group %U %U",
11952 unformat_ip6_address, &dst.ip6,
11953 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
11954 {
11955 grp_set = dst_set = 1;
11956 ipv6_set = 1;
11957 }
11958 else if (unformat (line_input, "group %U",
11959 unformat_ip6_address, &dst.ip6))
11960 {
11961 grp_set = dst_set = 1;
11962 ipv6_set = 1;
11963 }
11964 else
11965 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
11966 ;
11967 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
11968 ;
11969 else if (unformat (line_input, "decap-next %U",
11970 unformat_geneve_decap_next, &decap_next_index))
11971 ;
11972 else if (unformat (line_input, "vni %d", &vni))
11973 ;
11974 else
11975 {
11976 errmsg ("parse error '%U'", format_unformat_error, line_input);
11977 return -99;
11978 }
11979 }
11980
11981 if (src_set == 0)
11982 {
11983 errmsg ("tunnel src address not specified");
11984 return -99;
11985 }
11986 if (dst_set == 0)
11987 {
11988 errmsg ("tunnel dst address not specified");
11989 return -99;
11990 }
11991
11992 if (grp_set && !ip46_address_is_multicast (&dst))
11993 {
11994 errmsg ("tunnel group address not multicast");
11995 return -99;
11996 }
11997 if (grp_set && mcast_sw_if_index == ~0)
11998 {
11999 errmsg ("tunnel nonexistent multicast device");
12000 return -99;
12001 }
12002 if (grp_set == 0 && ip46_address_is_multicast (&dst))
12003 {
12004 errmsg ("tunnel dst address must be unicast");
12005 return -99;
12006 }
12007
12008
12009 if (ipv4_set && ipv6_set)
12010 {
12011 errmsg ("both IPv4 and IPv6 addresses specified");
12012 return -99;
12013 }
12014
12015 if ((vni == 0) || (vni >> 24))
12016 {
12017 errmsg ("vni not specified or out of range");
12018 return -99;
12019 }
12020
12021 M (GENEVE_ADD_DEL_TUNNEL, mp);
12022
12023 if (ipv6_set)
12024 {
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012025 clib_memcpy (&mp->local_address.un.ip6, &src.ip6, sizeof (src.ip6));
12026 clib_memcpy (&mp->remote_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012027 }
12028 else
12029 {
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012030 clib_memcpy (&mp->local_address.un.ip4, &src.ip4, sizeof (src.ip4));
12031 clib_memcpy (&mp->remote_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012032 }
12033 mp->encap_vrf_id = ntohl (encap_vrf_id);
12034 mp->decap_next_index = ntohl (decap_next_index);
12035 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
12036 mp->vni = ntohl (vni);
12037 mp->is_add = is_add;
Marco Varleseb598f1d2017-09-19 14:25:28 +020012038
12039 S (mp);
12040 W (ret);
12041 return ret;
12042}
12043
12044static void vl_api_geneve_tunnel_details_t_handler
12045 (vl_api_geneve_tunnel_details_t * mp)
12046{
12047 vat_main_t *vam = &vat_main;
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012048 ip46_address_t src = {.as_u64[0] = 0,.as_u64[1] = 0 };
12049 ip46_address_t dst = {.as_u64[0] = 0,.as_u64[1] = 0 };
12050
12051 if (mp->src_address.af == ADDRESS_IP6)
12052 {
12053 clib_memcpy (&src.ip6, &mp->src_address.un.ip6, sizeof (ip6_address_t));
12054 clib_memcpy (&dst.ip6, &mp->dst_address.un.ip6, sizeof (ip6_address_t));
12055 }
12056 else
12057 {
12058 clib_memcpy (&src.ip4, &mp->src_address.un.ip4, sizeof (ip4_address_t));
12059 clib_memcpy (&dst.ip4, &mp->dst_address.un.ip4, sizeof (ip4_address_t));
12060 }
Marco Varleseb598f1d2017-09-19 14:25:28 +020012061
12062 print (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d",
12063 ntohl (mp->sw_if_index),
12064 format_ip46_address, &src, IP46_TYPE_ANY,
12065 format_ip46_address, &dst, IP46_TYPE_ANY,
12066 ntohl (mp->encap_vrf_id),
12067 ntohl (mp->decap_next_index), ntohl (mp->vni),
12068 ntohl (mp->mcast_sw_if_index));
12069}
12070
12071static void vl_api_geneve_tunnel_details_t_handler_json
12072 (vl_api_geneve_tunnel_details_t * mp)
12073{
12074 vat_main_t *vam = &vat_main;
12075 vat_json_node_t *node = NULL;
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012076 bool is_ipv6;
Marco Varleseb598f1d2017-09-19 14:25:28 +020012077
12078 if (VAT_JSON_ARRAY != vam->json_tree.type)
12079 {
12080 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12081 vat_json_init_array (&vam->json_tree);
12082 }
12083 node = vat_json_array_add (&vam->json_tree);
12084
12085 vat_json_init_object (node);
12086 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012087 is_ipv6 = mp->src_address.af == ADDRESS_IP6;
12088 if (is_ipv6)
Marco Varleseb598f1d2017-09-19 14:25:28 +020012089 {
12090 struct in6_addr ip6;
12091
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012092 clib_memcpy (&ip6, &mp->src_address.un.ip6, sizeof (ip6));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012093 vat_json_object_add_ip6 (node, "src_address", ip6);
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012094 clib_memcpy (&ip6, &mp->dst_address.un.ip6, sizeof (ip6));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012095 vat_json_object_add_ip6 (node, "dst_address", ip6);
12096 }
12097 else
12098 {
12099 struct in_addr ip4;
12100
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012101 clib_memcpy (&ip4, &mp->src_address.un.ip4, sizeof (ip4));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012102 vat_json_object_add_ip4 (node, "src_address", ip4);
Jakub Grajciar2d3282e2019-10-01 12:04:56 +020012103 clib_memcpy (&ip4, &mp->dst_address.un.ip4, sizeof (ip4));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012104 vat_json_object_add_ip4 (node, "dst_address", ip4);
12105 }
12106 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12107 vat_json_object_add_uint (node, "decap_next_index",
12108 ntohl (mp->decap_next_index));
12109 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
Marco Varleseb598f1d2017-09-19 14:25:28 +020012110 vat_json_object_add_uint (node, "mcast_sw_if_index",
12111 ntohl (mp->mcast_sw_if_index));
12112}
12113
12114static int
12115api_geneve_tunnel_dump (vat_main_t * vam)
12116{
12117 unformat_input_t *i = vam->input;
12118 vl_api_geneve_tunnel_dump_t *mp;
12119 vl_api_control_ping_t *mp_ping;
12120 u32 sw_if_index;
12121 u8 sw_if_index_set = 0;
12122 int ret;
12123
12124 /* Parse args required to build the message */
12125 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12126 {
12127 if (unformat (i, "sw_if_index %d", &sw_if_index))
12128 sw_if_index_set = 1;
12129 else
12130 break;
12131 }
12132
12133 if (sw_if_index_set == 0)
12134 {
12135 sw_if_index = ~0;
12136 }
12137
12138 if (!vam->json_output)
12139 {
12140 print (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s",
12141 "sw_if_index", "local_address", "remote_address",
12142 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
12143 }
12144
12145 /* Get list of geneve-tunnel interfaces */
12146 M (GENEVE_TUNNEL_DUMP, mp);
12147
12148 mp->sw_if_index = htonl (sw_if_index);
12149
12150 S (mp);
12151
12152 /* Use a control ping for synchronization */
12153 M (CONTROL_PING, mp_ping);
12154 S (mp_ping);
12155
12156 W (ret);
12157 return ret;
12158}
12159
Damjan Marion7cd468a2016-12-19 23:05:39 +010012160static int
Neale Ranns5a8844b2019-04-16 07:15:35 +000012161api_gre_tunnel_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010012162{
12163 unformat_input_t *line_input = vam->input;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012164 vl_api_address_t src = { }, dst =
12165 {
12166 };
12167 vl_api_gre_tunnel_add_del_t *mp;
12168 vl_api_gre_tunnel_type_t t_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012169 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012170 u8 src_set = 0;
12171 u8 dst_set = 0;
Neale Ranns5f8f6172019-04-18 10:23:56 +000012172 u32 outer_table_id = 0;
John Loa43ccae2018-02-13 17:15:23 -050012173 u32 session_id = 0;
12174 u32 instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012175 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012176
Neale Ranns5a8844b2019-04-16 07:15:35 +000012177 t_type = GRE_API_TUNNEL_TYPE_L3;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012178
Damjan Marion7cd468a2016-12-19 23:05:39 +010012179 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12180 {
12181 if (unformat (line_input, "del"))
12182 is_add = 0;
John Loa43ccae2018-02-13 17:15:23 -050012183 else if (unformat (line_input, "instance %d", &instance))
12184 ;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012185 else if (unformat (line_input, "src %U", unformat_vl_api_address, &src))
Ciara Loftus7eac9162016-09-30 15:47:03 +010012186 {
12187 src_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012188 }
Neale Ranns5a8844b2019-04-16 07:15:35 +000012189 else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst))
Ciara Loftus7eac9162016-09-30 15:47:03 +010012190 {
12191 dst_set = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010012192 }
Neale Ranns5f8f6172019-04-18 10:23:56 +000012193 else if (unformat (line_input, "outer-table-id %d", &outer_table_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012194 ;
12195 else if (unformat (line_input, "teb"))
Neale Ranns5a8844b2019-04-16 07:15:35 +000012196 t_type = GRE_API_TUNNEL_TYPE_TEB;
John Loa43ccae2018-02-13 17:15:23 -050012197 else if (unformat (line_input, "erspan %d", &session_id))
Neale Ranns5a8844b2019-04-16 07:15:35 +000012198 t_type = GRE_API_TUNNEL_TYPE_ERSPAN;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012199 else
12200 {
12201 errmsg ("parse error '%U'", format_unformat_error, line_input);
12202 return -99;
12203 }
12204 }
12205
12206 if (src_set == 0)
12207 {
12208 errmsg ("tunnel src address not specified");
12209 return -99;
12210 }
12211 if (dst_set == 0)
12212 {
12213 errmsg ("tunnel dst address not specified");
12214 return -99;
12215 }
12216
Neale Ranns5a8844b2019-04-16 07:15:35 +000012217 M (GRE_TUNNEL_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012218
Neale Ranns5a8844b2019-04-16 07:15:35 +000012219 clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src));
12220 clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012221
Neale Ranns5a8844b2019-04-16 07:15:35 +000012222 mp->tunnel.instance = htonl (instance);
Neale Ranns5f8f6172019-04-18 10:23:56 +000012223 mp->tunnel.outer_table_id = htonl (outer_table_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012224 mp->is_add = is_add;
Neale Ranns5a8844b2019-04-16 07:15:35 +000012225 mp->tunnel.session_id = htons ((u16) session_id);
12226 mp->tunnel.type = htonl (t_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012227
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012228 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012229 W (ret);
12230 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012231}
12232
12233static void vl_api_gre_tunnel_details_t_handler
12234 (vl_api_gre_tunnel_details_t * mp)
12235{
12236 vat_main_t *vam = &vat_main;
12237
John Loa43ccae2018-02-13 17:15:23 -050012238 print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d",
Neale Ranns5a8844b2019-04-16 07:15:35 +000012239 ntohl (mp->tunnel.sw_if_index),
12240 ntohl (mp->tunnel.instance),
12241 format_vl_api_address, &mp->tunnel.src,
12242 format_vl_api_address, &mp->tunnel.dst,
Neale Ranns5f8f6172019-04-18 10:23:56 +000012243 mp->tunnel.type, ntohl (mp->tunnel.outer_table_id),
Neale Ranns5a8844b2019-04-16 07:15:35 +000012244 ntohl (mp->tunnel.session_id));
12245}
12246
Damjan Marion7cd468a2016-12-19 23:05:39 +010012247static void vl_api_gre_tunnel_details_t_handler_json
12248 (vl_api_gre_tunnel_details_t * mp)
12249{
12250 vat_main_t *vam = &vat_main;
12251 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012252
12253 if (VAT_JSON_ARRAY != vam->json_tree.type)
12254 {
12255 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12256 vat_json_init_array (&vam->json_tree);
12257 }
12258 node = vat_json_array_add (&vam->json_tree);
12259
12260 vat_json_init_object (node);
Neale Ranns5a8844b2019-04-16 07:15:35 +000012261 vat_json_object_add_uint (node, "sw_if_index",
12262 ntohl (mp->tunnel.sw_if_index));
12263 vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance));
12264
12265 vat_json_object_add_address (node, "src", &mp->tunnel.src);
12266 vat_json_object_add_address (node, "dst", &mp->tunnel.dst);
12267 vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type);
Neale Ranns5f8f6172019-04-18 10:23:56 +000012268 vat_json_object_add_uint (node, "outer_table_id",
12269 ntohl (mp->tunnel.outer_table_id));
Neale Ranns5a8844b2019-04-16 07:15:35 +000012270 vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012271}
12272
12273static int
12274api_gre_tunnel_dump (vat_main_t * vam)
12275{
12276 unformat_input_t *i = vam->input;
12277 vl_api_gre_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012278 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012279 u32 sw_if_index;
12280 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012281 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012282
12283 /* Parse args required to build the message */
12284 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12285 {
12286 if (unformat (i, "sw_if_index %d", &sw_if_index))
12287 sw_if_index_set = 1;
12288 else
12289 break;
12290 }
12291
12292 if (sw_if_index_set == 0)
12293 {
12294 sw_if_index = ~0;
12295 }
12296
12297 if (!vam->json_output)
12298 {
John Loa43ccae2018-02-13 17:15:23 -050012299 print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s",
12300 "sw_if_index", "instance", "src_address", "dst_address",
12301 "tunnel_type", "outer_fib_id", "session_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010012302 }
12303
12304 /* Get list of gre-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012305 M (GRE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012306
12307 mp->sw_if_index = htonl (sw_if_index);
12308
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012309 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012310
12311 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012312 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012313 S (mp_ping);
12314
Jon Loeliger56c7b012017-02-01 12:31:41 -060012315 W (ret);
12316 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012317}
12318
12319static int
12320api_l2_fib_clear_table (vat_main_t * vam)
12321{
12322// unformat_input_t * i = vam->input;
12323 vl_api_l2_fib_clear_table_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012324 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012325
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012326 M (L2_FIB_CLEAR_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012327
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012328 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012329 W (ret);
12330 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012331}
12332
12333static int
12334api_l2_interface_efp_filter (vat_main_t * vam)
12335{
12336 unformat_input_t *i = vam->input;
12337 vl_api_l2_interface_efp_filter_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012338 u32 sw_if_index;
12339 u8 enable = 1;
12340 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012341 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012342
12343 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12344 {
12345 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12346 sw_if_index_set = 1;
12347 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12348 sw_if_index_set = 1;
12349 else if (unformat (i, "enable"))
12350 enable = 1;
12351 else if (unformat (i, "disable"))
12352 enable = 0;
12353 else
12354 {
12355 clib_warning ("parse error '%U'", format_unformat_error, i);
12356 return -99;
12357 }
12358 }
12359
12360 if (sw_if_index_set == 0)
12361 {
12362 errmsg ("missing sw_if_index");
12363 return -99;
12364 }
12365
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012366 M (L2_INTERFACE_EFP_FILTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012367
12368 mp->sw_if_index = ntohl (sw_if_index);
12369 mp->enable_disable = enable;
12370
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012371 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012372 W (ret);
12373 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012374}
12375
12376#define foreach_vtr_op \
12377_("disable", L2_VTR_DISABLED) \
12378_("push-1", L2_VTR_PUSH_1) \
12379_("push-2", L2_VTR_PUSH_2) \
12380_("pop-1", L2_VTR_POP_1) \
12381_("pop-2", L2_VTR_POP_2) \
12382_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
12383_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
12384_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
12385_("translate-2-2", L2_VTR_TRANSLATE_2_2)
12386
12387static int
12388api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
12389{
12390 unformat_input_t *i = vam->input;
12391 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012392 u32 sw_if_index;
12393 u8 sw_if_index_set = 0;
12394 u8 vtr_op_set = 0;
12395 u32 vtr_op = 0;
12396 u32 push_dot1q = 1;
12397 u32 tag1 = ~0;
12398 u32 tag2 = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012399 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012400
12401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12402 {
12403 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12404 sw_if_index_set = 1;
12405 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12406 sw_if_index_set = 1;
12407 else if (unformat (i, "vtr_op %d", &vtr_op))
12408 vtr_op_set = 1;
12409#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
12410 foreach_vtr_op
12411#undef _
12412 else if (unformat (i, "push_dot1q %d", &push_dot1q))
12413 ;
12414 else if (unformat (i, "tag1 %d", &tag1))
12415 ;
12416 else if (unformat (i, "tag2 %d", &tag2))
12417 ;
12418 else
12419 {
12420 clib_warning ("parse error '%U'", format_unformat_error, i);
12421 return -99;
12422 }
12423 }
12424
12425 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
12426 {
12427 errmsg ("missing vtr operation or sw_if_index");
12428 return -99;
12429 }
12430
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012431 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
12432 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012433 mp->vtr_op = ntohl (vtr_op);
12434 mp->push_dot1q = ntohl (push_dot1q);
12435 mp->tag1 = ntohl (tag1);
12436 mp->tag2 = ntohl (tag2);
12437
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012438 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012439 W (ret);
12440 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012441}
12442
12443static int
12444api_create_vhost_user_if (vat_main_t * vam)
12445{
12446 unformat_input_t *i = vam->input;
12447 vl_api_create_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012448 u8 *file_name;
12449 u8 is_server = 0;
12450 u8 file_name_set = 0;
12451 u32 custom_dev_instance = ~0;
12452 u8 hwaddr[6];
12453 u8 use_custom_mac = 0;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012454 u8 disable_mrg_rxbuf = 0;
12455 u8 disable_indirect_desc = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012456 u8 *tag = 0;
Steven Luong4208a4c2019-05-06 08:51:56 -070012457 u8 enable_gso = 0;
Steven Luongbc0d9ff2020-03-23 09:34:59 -070012458 u8 enable_packed = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012459 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012460
12461 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040012462 clib_memset (hwaddr, 0, sizeof (hwaddr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012463
12464 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12465 {
12466 if (unformat (i, "socket %s", &file_name))
12467 {
12468 file_name_set = 1;
12469 }
12470 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
12471 ;
12472 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
12473 use_custom_mac = 1;
12474 else if (unformat (i, "server"))
12475 is_server = 1;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012476 else if (unformat (i, "disable_mrg_rxbuf"))
12477 disable_mrg_rxbuf = 1;
12478 else if (unformat (i, "disable_indirect_desc"))
12479 disable_indirect_desc = 1;
Steven Luong4208a4c2019-05-06 08:51:56 -070012480 else if (unformat (i, "gso"))
12481 enable_gso = 1;
Steven Luongbc0d9ff2020-03-23 09:34:59 -070012482 else if (unformat (i, "packed"))
12483 enable_packed = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012484 else if (unformat (i, "tag %s", &tag))
12485 ;
12486 else
12487 break;
12488 }
12489
12490 if (file_name_set == 0)
12491 {
12492 errmsg ("missing socket file name");
12493 return -99;
12494 }
12495
12496 if (vec_len (file_name) > 255)
12497 {
12498 errmsg ("socket file name too long");
12499 return -99;
12500 }
12501 vec_add1 (file_name, 0);
12502
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012503 M (CREATE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012504
12505 mp->is_server = is_server;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012506 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
12507 mp->disable_indirect_desc = disable_indirect_desc;
Steven Luong4208a4c2019-05-06 08:51:56 -070012508 mp->enable_gso = enable_gso;
Steven Luongbc0d9ff2020-03-23 09:34:59 -070012509 mp->enable_packed = enable_packed;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012510 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
12511 vec_free (file_name);
12512 if (custom_dev_instance != ~0)
12513 {
12514 mp->renumber = 1;
12515 mp->custom_dev_instance = ntohl (custom_dev_instance);
12516 }
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020012517
Damjan Marion7cd468a2016-12-19 23:05:39 +010012518 mp->use_custom_mac = use_custom_mac;
12519 clib_memcpy (mp->mac_address, hwaddr, 6);
12520 if (tag)
12521 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
12522 vec_free (tag);
12523
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012524 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012525 W (ret);
12526 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012527}
12528
12529static int
12530api_modify_vhost_user_if (vat_main_t * vam)
12531{
12532 unformat_input_t *i = vam->input;
12533 vl_api_modify_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012534 u8 *file_name;
12535 u8 is_server = 0;
12536 u8 file_name_set = 0;
12537 u32 custom_dev_instance = ~0;
12538 u8 sw_if_index_set = 0;
12539 u32 sw_if_index = (u32) ~ 0;
Steven Luong4208a4c2019-05-06 08:51:56 -070012540 u8 enable_gso = 0;
Steven Luongbc0d9ff2020-03-23 09:34:59 -070012541 u8 enable_packed = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012542 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012543
12544 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12545 {
12546 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12547 sw_if_index_set = 1;
12548 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12549 sw_if_index_set = 1;
12550 else if (unformat (i, "socket %s", &file_name))
12551 {
12552 file_name_set = 1;
12553 }
12554 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
12555 ;
12556 else if (unformat (i, "server"))
12557 is_server = 1;
Steven Luong4208a4c2019-05-06 08:51:56 -070012558 else if (unformat (i, "gso"))
12559 enable_gso = 1;
Steven Luongbc0d9ff2020-03-23 09:34:59 -070012560 else if (unformat (i, "packed"))
12561 enable_packed = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012562 else
12563 break;
12564 }
12565
12566 if (sw_if_index_set == 0)
12567 {
12568 errmsg ("missing sw_if_index or interface name");
12569 return -99;
12570 }
12571
12572 if (file_name_set == 0)
12573 {
12574 errmsg ("missing socket file name");
12575 return -99;
12576 }
12577
12578 if (vec_len (file_name) > 255)
12579 {
12580 errmsg ("socket file name too long");
12581 return -99;
12582 }
12583 vec_add1 (file_name, 0);
12584
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012585 M (MODIFY_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012586
12587 mp->sw_if_index = ntohl (sw_if_index);
12588 mp->is_server = is_server;
Steven Luong4208a4c2019-05-06 08:51:56 -070012589 mp->enable_gso = enable_gso;
Steven Luongbc0d9ff2020-03-23 09:34:59 -070012590 mp->enable_packed = enable_packed;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012591 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
12592 vec_free (file_name);
12593 if (custom_dev_instance != ~0)
12594 {
12595 mp->renumber = 1;
12596 mp->custom_dev_instance = ntohl (custom_dev_instance);
12597 }
12598
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012599 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012600 W (ret);
12601 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012602}
12603
12604static int
12605api_delete_vhost_user_if (vat_main_t * vam)
12606{
12607 unformat_input_t *i = vam->input;
12608 vl_api_delete_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012609 u32 sw_if_index = ~0;
12610 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012611 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012612
12613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12614 {
12615 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12616 sw_if_index_set = 1;
12617 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12618 sw_if_index_set = 1;
12619 else
12620 break;
12621 }
12622
12623 if (sw_if_index_set == 0)
12624 {
12625 errmsg ("missing sw_if_index or interface name");
12626 return -99;
12627 }
12628
12629
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012630 M (DELETE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012631
12632 mp->sw_if_index = ntohl (sw_if_index);
12633
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012634 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012635 W (ret);
12636 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012637}
12638
12639static void vl_api_sw_interface_vhost_user_details_t_handler
12640 (vl_api_sw_interface_vhost_user_details_t * mp)
12641{
12642 vat_main_t *vam = &vat_main;
Jakub Grajciar5d4c99f2019-09-26 10:21:59 +020012643 u64 features;
12644
12645 features =
12646 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
12647 clib_net_to_host_u32
12648 (mp->features_last_32) <<
12649 32);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012650
Stevenf3b53642017-05-01 14:03:02 -070012651 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012652 (char *) mp->interface_name,
12653 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
Jakub Grajciar5d4c99f2019-09-26 10:21:59 +020012654 features, mp->is_server,
Stevenf3b53642017-05-01 14:03:02 -070012655 ntohl (mp->num_regions), (char *) mp->sock_filename);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012656 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
12657}
12658
12659static void vl_api_sw_interface_vhost_user_details_t_handler_json
12660 (vl_api_sw_interface_vhost_user_details_t * mp)
12661{
12662 vat_main_t *vam = &vat_main;
12663 vat_json_node_t *node = NULL;
12664
12665 if (VAT_JSON_ARRAY != vam->json_tree.type)
12666 {
12667 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12668 vat_json_init_array (&vam->json_tree);
12669 }
12670 node = vat_json_array_add (&vam->json_tree);
12671
12672 vat_json_init_object (node);
12673 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12674 vat_json_object_add_string_copy (node, "interface_name",
12675 mp->interface_name);
12676 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
12677 ntohl (mp->virtio_net_hdr_sz));
Jakub Grajciar5d4c99f2019-09-26 10:21:59 +020012678 vat_json_object_add_uint (node, "features_first_32",
12679 clib_net_to_host_u32 (mp->features_first_32));
12680 vat_json_object_add_uint (node, "features_last_32",
12681 clib_net_to_host_u32 (mp->features_last_32));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012682 vat_json_object_add_uint (node, "is_server", mp->is_server);
12683 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
12684 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
12685 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
12686}
12687
12688static int
12689api_sw_interface_vhost_user_dump (vat_main_t * vam)
12690{
Steven Luonga0e8d962020-05-18 17:12:56 -070012691 unformat_input_t *i = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012692 vl_api_sw_interface_vhost_user_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012693 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012694 int ret;
Steven Luonga0e8d962020-05-18 17:12:56 -070012695 u32 sw_if_index = ~0;
12696
12697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12698 {
12699 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12700 ;
12701 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12702 ;
12703 else
12704 break;
12705 }
12706
Damjan Marion7cd468a2016-12-19 23:05:39 +010012707 print (vam->ofp,
Stevenf3b53642017-05-01 14:03:02 -070012708 "Interface name idx hdr_sz features server regions filename");
Damjan Marion7cd468a2016-12-19 23:05:39 +010012709
12710 /* Get list of vhost-user interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012711 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
Steven Luonga0e8d962020-05-18 17:12:56 -070012712 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012713 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012714
12715 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012716 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012717 S (mp_ping);
12718
Jon Loeliger56c7b012017-02-01 12:31:41 -060012719 W (ret);
12720 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012721}
12722
12723static int
12724api_show_version (vat_main_t * vam)
12725{
12726 vl_api_show_version_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012727 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012728
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012729 M (SHOW_VERSION, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012730
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012731 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012732 W (ret);
12733 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012734}
12735
12736
12737static int
12738api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
12739{
12740 unformat_input_t *line_input = vam->input;
12741 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012742 ip46_address_t local, remote;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012743 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012744 u8 local_set = 0;
12745 u8 remote_set = 0;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012746 u8 grp_set = 0;
12747 u32 mcast_sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012748 u32 encap_vrf_id = 0;
12749 u32 decap_vrf_id = 0;
12750 u8 protocol = ~0;
12751 u32 vni;
12752 u8 vni_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012753 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012754
12755 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12756 {
12757 if (unformat (line_input, "del"))
12758 is_add = 0;
12759 else if (unformat (line_input, "local %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012760 unformat_ip46_address, &local))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012761 {
12762 local_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012763 }
12764 else if (unformat (line_input, "remote %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012765 unformat_ip46_address, &remote))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012766 {
12767 remote_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012768 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012769 else if (unformat (line_input, "group %U %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012770 unformat_ip46_address, &remote,
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012771 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12772 {
12773 grp_set = remote_set = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012774 }
12775 else if (unformat (line_input, "group %U",
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012776 unformat_ip46_address, &remote))
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012777 {
12778 grp_set = remote_set = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012779 }
12780 else
12781 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
12782 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012783 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
12784 ;
12785 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
12786 ;
12787 else if (unformat (line_input, "vni %d", &vni))
12788 vni_set = 1;
12789 else if (unformat (line_input, "next-ip4"))
12790 protocol = 1;
12791 else if (unformat (line_input, "next-ip6"))
12792 protocol = 2;
12793 else if (unformat (line_input, "next-ethernet"))
12794 protocol = 3;
12795 else if (unformat (line_input, "next-nsh"))
12796 protocol = 4;
12797 else
12798 {
12799 errmsg ("parse error '%U'", format_unformat_error, line_input);
12800 return -99;
12801 }
12802 }
12803
12804 if (local_set == 0)
12805 {
12806 errmsg ("tunnel local address not specified");
12807 return -99;
12808 }
12809 if (remote_set == 0)
12810 {
12811 errmsg ("tunnel remote address not specified");
12812 return -99;
12813 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012814 if (grp_set && mcast_sw_if_index == ~0)
12815 {
12816 errmsg ("tunnel nonexistent multicast device");
12817 return -99;
12818 }
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012819 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012820 {
12821 errmsg ("both IPv4 and IPv6 addresses specified");
12822 return -99;
12823 }
12824
12825 if (vni_set == 0)
12826 {
12827 errmsg ("vni not specified");
12828 return -99;
12829 }
12830
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012831 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012832
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012833 ip_address_encode (&local,
12834 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
12835 IP46_TYPE_IP6, &mp->local);
12836 ip_address_encode (&remote,
12837 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
12838 IP46_TYPE_IP6, &mp->remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012839
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012840 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012841 mp->encap_vrf_id = ntohl (encap_vrf_id);
12842 mp->decap_vrf_id = ntohl (decap_vrf_id);
12843 mp->protocol = protocol;
12844 mp->vni = ntohl (vni);
12845 mp->is_add = is_add;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012846
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012847 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012848 W (ret);
12849 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012850}
12851
12852static void vl_api_vxlan_gpe_tunnel_details_t_handler
12853 (vl_api_vxlan_gpe_tunnel_details_t * mp)
12854{
12855 vat_main_t *vam = &vat_main;
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012856 ip46_address_t local, remote;
12857
12858 ip_address_decode (&mp->local, &local);
12859 ip_address_decode (&mp->remote, &remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012860
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012861 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012862 ntohl (mp->sw_if_index),
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012863 format_ip46_address, &local, IP46_TYPE_ANY,
12864 format_ip46_address, &remote, IP46_TYPE_ANY,
12865 ntohl (mp->vni), mp->protocol,
12866 ntohl (mp->mcast_sw_if_index),
Damjan Marion7cd468a2016-12-19 23:05:39 +010012867 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
12868}
12869
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012870
Damjan Marion7cd468a2016-12-19 23:05:39 +010012871static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
12872 (vl_api_vxlan_gpe_tunnel_details_t * mp)
12873{
12874 vat_main_t *vam = &vat_main;
12875 vat_json_node_t *node = NULL;
12876 struct in_addr ip4;
12877 struct in6_addr ip6;
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012878 ip46_address_t local, remote;
12879
12880 ip_address_decode (&mp->local, &local);
12881 ip_address_decode (&mp->remote, &remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012882
12883 if (VAT_JSON_ARRAY != vam->json_tree.type)
12884 {
12885 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12886 vat_json_init_array (&vam->json_tree);
12887 }
12888 node = vat_json_array_add (&vam->json_tree);
12889
12890 vat_json_init_object (node);
12891 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012892 if (ip46_address_is_ip4 (&local))
Damjan Marion7cd468a2016-12-19 23:05:39 +010012893 {
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012894 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
12895 vat_json_object_add_ip4 (node, "local", ip4);
12896 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
12897 vat_json_object_add_ip4 (node, "remote", ip4);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012898 }
12899 else
12900 {
Jakub Grajciar1c2002a2020-01-31 10:45:30 +010012901 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
12902 vat_json_object_add_ip6 (node, "local", ip6);
12903 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
12904 vat_json_object_add_ip6 (node, "remote", ip6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012905 }
12906 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
12907 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012908 vat_json_object_add_uint (node, "mcast_sw_if_index",
12909 ntohl (mp->mcast_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010012910 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
12911 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
12912 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
12913}
12914
12915static int
12916api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
12917{
12918 unformat_input_t *i = vam->input;
12919 vl_api_vxlan_gpe_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012920 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012921 u32 sw_if_index;
12922 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012923 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012924
12925 /* Parse args required to build the message */
12926 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12927 {
12928 if (unformat (i, "sw_if_index %d", &sw_if_index))
12929 sw_if_index_set = 1;
12930 else
12931 break;
12932 }
12933
12934 if (sw_if_index_set == 0)
12935 {
12936 sw_if_index = ~0;
12937 }
12938
12939 if (!vam->json_output)
12940 {
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012941 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012942 "sw_if_index", "local", "remote", "vni",
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080012943 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010012944 }
12945
12946 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012947 M (VXLAN_GPE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012948
12949 mp->sw_if_index = htonl (sw_if_index);
12950
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012951 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012952
12953 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012954 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012955 S (mp_ping);
12956
Jon Loeliger56c7b012017-02-01 12:31:41 -060012957 W (ret);
12958 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012959}
12960
Ole Troan01384fe2017-05-12 11:55:35 +020012961static void vl_api_l2_fib_table_details_t_handler
12962 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010012963{
12964 vat_main_t *vam = &vat_main;
12965
12966 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
12967 " %d %d %d",
Mohsin Kazmi57938f62017-10-27 21:28:07 +020012968 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
Damjan Marion7cd468a2016-12-19 23:05:39 +010012969 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
12970 mp->bvi_mac);
12971}
12972
Ole Troan01384fe2017-05-12 11:55:35 +020012973static void vl_api_l2_fib_table_details_t_handler_json
12974 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010012975{
12976 vat_main_t *vam = &vat_main;
12977 vat_json_node_t *node = NULL;
12978
12979 if (VAT_JSON_ARRAY != vam->json_tree.type)
12980 {
12981 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12982 vat_json_init_array (&vam->json_tree);
12983 }
12984 node = vat_json_array_add (&vam->json_tree);
12985
12986 vat_json_init_object (node);
12987 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
Mohsin Kazmi57938f62017-10-27 21:28:07 +020012988 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012989 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12990 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
12991 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
12992 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
12993}
12994
12995static int
12996api_l2_fib_table_dump (vat_main_t * vam)
12997{
12998 unformat_input_t *i = vam->input;
12999 vl_api_l2_fib_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013000 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013001 u32 bd_id;
13002 u8 bd_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013003 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013004
13005 /* Parse args required to build the message */
13006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13007 {
13008 if (unformat (i, "bd_id %d", &bd_id))
13009 bd_id_set = 1;
13010 else
13011 break;
13012 }
13013
13014 if (bd_id_set == 0)
13015 {
13016 errmsg ("missing bridge domain");
13017 return -99;
13018 }
13019
13020 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
13021
13022 /* Get list of l2 fib entries */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013023 M (L2_FIB_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013024
13025 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013026 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013027
13028 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013029 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013030 S (mp_ping);
13031
Jon Loeliger56c7b012017-02-01 12:31:41 -060013032 W (ret);
13033 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013034}
13035
13036
13037static int
13038api_interface_name_renumber (vat_main_t * vam)
13039{
13040 unformat_input_t *line_input = vam->input;
13041 vl_api_interface_name_renumber_t *mp;
13042 u32 sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013043 u32 new_show_dev_instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013044 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013045
13046 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13047 {
13048 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
13049 &sw_if_index))
13050 ;
13051 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
13052 ;
13053 else if (unformat (line_input, "new_show_dev_instance %d",
13054 &new_show_dev_instance))
13055 ;
13056 else
13057 break;
13058 }
13059
13060 if (sw_if_index == ~0)
13061 {
13062 errmsg ("missing interface name or sw_if_index");
13063 return -99;
13064 }
13065
13066 if (new_show_dev_instance == ~0)
13067 {
13068 errmsg ("missing new_show_dev_instance");
13069 return -99;
13070 }
13071
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013072 M (INTERFACE_NAME_RENUMBER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013073
13074 mp->sw_if_index = ntohl (sw_if_index);
13075 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
13076
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013077 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013078 W (ret);
13079 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013080}
13081
13082static int
John Lo8d00fff2017-08-03 00:35:36 -040013083api_want_l2_macs_events (vat_main_t * vam)
13084{
13085 unformat_input_t *line_input = vam->input;
13086 vl_api_want_l2_macs_events_t *mp;
13087 u8 enable_disable = 1;
13088 u32 scan_delay = 0;
13089 u32 max_macs_in_event = 0;
13090 u32 learn_limit = 0;
13091 int ret;
13092
13093 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13094 {
13095 if (unformat (line_input, "learn-limit %d", &learn_limit))
13096 ;
13097 else if (unformat (line_input, "scan-delay %d", &scan_delay))
13098 ;
13099 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
13100 ;
13101 else if (unformat (line_input, "disable"))
13102 enable_disable = 0;
13103 else
13104 break;
13105 }
13106
13107 M (WANT_L2_MACS_EVENTS, mp);
13108 mp->enable_disable = enable_disable;
13109 mp->pid = htonl (getpid ());
13110 mp->learn_limit = htonl (learn_limit);
13111 mp->scan_delay = (u8) scan_delay;
13112 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
13113 S (mp);
13114 W (ret);
13115 return ret;
13116}
13117
13118static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010013119api_input_acl_set_interface (vat_main_t * vam)
13120{
13121 unformat_input_t *i = vam->input;
13122 vl_api_input_acl_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013123 u32 sw_if_index;
13124 int sw_if_index_set;
13125 u32 ip4_table_index = ~0;
13126 u32 ip6_table_index = ~0;
13127 u32 l2_table_index = ~0;
13128 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013129 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013130
13131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13132 {
13133 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13134 sw_if_index_set = 1;
13135 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13136 sw_if_index_set = 1;
13137 else if (unformat (i, "del"))
13138 is_add = 0;
13139 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13140 ;
13141 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13142 ;
13143 else if (unformat (i, "l2-table %d", &l2_table_index))
13144 ;
13145 else
13146 {
13147 clib_warning ("parse error '%U'", format_unformat_error, i);
13148 return -99;
13149 }
13150 }
13151
13152 if (sw_if_index_set == 0)
13153 {
13154 errmsg ("missing interface name or sw_if_index");
13155 return -99;
13156 }
13157
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013158 M (INPUT_ACL_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013159
13160 mp->sw_if_index = ntohl (sw_if_index);
13161 mp->ip4_table_index = ntohl (ip4_table_index);
13162 mp->ip6_table_index = ntohl (ip6_table_index);
13163 mp->l2_table_index = ntohl (l2_table_index);
13164 mp->is_add = is_add;
13165
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013166 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013167 W (ret);
13168 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013169}
13170
13171static int
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010013172api_output_acl_set_interface (vat_main_t * vam)
13173{
13174 unformat_input_t *i = vam->input;
13175 vl_api_output_acl_set_interface_t *mp;
13176 u32 sw_if_index;
13177 int sw_if_index_set;
13178 u32 ip4_table_index = ~0;
13179 u32 ip6_table_index = ~0;
13180 u32 l2_table_index = ~0;
13181 u8 is_add = 1;
13182 int ret;
13183
13184 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13185 {
13186 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13187 sw_if_index_set = 1;
13188 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13189 sw_if_index_set = 1;
13190 else if (unformat (i, "del"))
13191 is_add = 0;
13192 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13193 ;
13194 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13195 ;
13196 else if (unformat (i, "l2-table %d", &l2_table_index))
13197 ;
13198 else
13199 {
13200 clib_warning ("parse error '%U'", format_unformat_error, i);
13201 return -99;
13202 }
13203 }
13204
13205 if (sw_if_index_set == 0)
13206 {
13207 errmsg ("missing interface name or sw_if_index");
13208 return -99;
13209 }
13210
13211 M (OUTPUT_ACL_SET_INTERFACE, mp);
13212
13213 mp->sw_if_index = ntohl (sw_if_index);
13214 mp->ip4_table_index = ntohl (ip4_table_index);
13215 mp->ip6_table_index = ntohl (ip6_table_index);
13216 mp->l2_table_index = ntohl (l2_table_index);
13217 mp->is_add = is_add;
13218
13219 S (mp);
13220 W (ret);
13221 return ret;
13222}
13223
13224static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010013225api_ip_address_dump (vat_main_t * vam)
13226{
13227 unformat_input_t *i = vam->input;
13228 vl_api_ip_address_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013229 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013230 u32 sw_if_index = ~0;
13231 u8 sw_if_index_set = 0;
13232 u8 ipv4_set = 0;
13233 u8 ipv6_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013234 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013235
13236 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13237 {
13238 if (unformat (i, "sw_if_index %d", &sw_if_index))
13239 sw_if_index_set = 1;
13240 else
13241 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13242 sw_if_index_set = 1;
13243 else if (unformat (i, "ipv4"))
13244 ipv4_set = 1;
13245 else if (unformat (i, "ipv6"))
13246 ipv6_set = 1;
13247 else
13248 break;
13249 }
13250
13251 if (ipv4_set && ipv6_set)
13252 {
13253 errmsg ("ipv4 and ipv6 flags cannot be both set");
13254 return -99;
13255 }
13256
13257 if ((!ipv4_set) && (!ipv6_set))
13258 {
13259 errmsg ("no ipv4 nor ipv6 flag set");
13260 return -99;
13261 }
13262
13263 if (sw_if_index_set == 0)
13264 {
13265 errmsg ("missing interface name or sw_if_index");
13266 return -99;
13267 }
13268
13269 vam->current_sw_if_index = sw_if_index;
13270 vam->is_ipv6 = ipv6_set;
13271
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013272 M (IP_ADDRESS_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013273 mp->sw_if_index = ntohl (sw_if_index);
13274 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013275 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013276
13277 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013278 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013279 S (mp_ping);
13280
Jon Loeliger56c7b012017-02-01 12:31:41 -060013281 W (ret);
13282 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013283}
13284
13285static int
13286api_ip_dump (vat_main_t * vam)
13287{
13288 vl_api_ip_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013289 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013290 unformat_input_t *in = vam->input;
13291 int ipv4_set = 0;
13292 int ipv6_set = 0;
13293 int is_ipv6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013294 int i;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013295 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013296
13297 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
13298 {
13299 if (unformat (in, "ipv4"))
13300 ipv4_set = 1;
13301 else if (unformat (in, "ipv6"))
13302 ipv6_set = 1;
13303 else
13304 break;
13305 }
13306
13307 if (ipv4_set && ipv6_set)
13308 {
13309 errmsg ("ipv4 and ipv6 flags cannot be both set");
13310 return -99;
13311 }
13312
13313 if ((!ipv4_set) && (!ipv6_set))
13314 {
13315 errmsg ("no ipv4 nor ipv6 flag set");
13316 return -99;
13317 }
13318
13319 is_ipv6 = ipv6_set;
13320 vam->is_ipv6 = is_ipv6;
13321
13322 /* free old data */
13323 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
13324 {
13325 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
13326 }
13327 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
13328
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013329 M (IP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013330 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013331 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013332
13333 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013334 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013335 S (mp_ping);
13336
Jon Loeliger56c7b012017-02-01 12:31:41 -060013337 W (ret);
13338 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013339}
13340
13341static int
13342api_ipsec_spd_add_del (vat_main_t * vam)
13343{
13344 unformat_input_t *i = vam->input;
13345 vl_api_ipsec_spd_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013346 u32 spd_id = ~0;
13347 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013348 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013349
13350 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13351 {
13352 if (unformat (i, "spd_id %d", &spd_id))
13353 ;
13354 else if (unformat (i, "del"))
13355 is_add = 0;
13356 else
13357 {
13358 clib_warning ("parse error '%U'", format_unformat_error, i);
13359 return -99;
13360 }
13361 }
13362 if (spd_id == ~0)
13363 {
13364 errmsg ("spd_id must be set");
13365 return -99;
13366 }
13367
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013368 M (IPSEC_SPD_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013369
13370 mp->spd_id = ntohl (spd_id);
13371 mp->is_add = is_add;
13372
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013373 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013374 W (ret);
13375 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013376}
13377
13378static int
13379api_ipsec_interface_add_del_spd (vat_main_t * vam)
13380{
13381 unformat_input_t *i = vam->input;
13382 vl_api_ipsec_interface_add_del_spd_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013383 u32 sw_if_index;
13384 u8 sw_if_index_set = 0;
13385 u32 spd_id = (u32) ~ 0;
13386 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013387 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013388
13389 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13390 {
13391 if (unformat (i, "del"))
13392 is_add = 0;
13393 else if (unformat (i, "spd_id %d", &spd_id))
13394 ;
13395 else
13396 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13397 sw_if_index_set = 1;
13398 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13399 sw_if_index_set = 1;
13400 else
13401 {
13402 clib_warning ("parse error '%U'", format_unformat_error, i);
13403 return -99;
13404 }
13405
13406 }
13407
13408 if (spd_id == (u32) ~ 0)
13409 {
13410 errmsg ("spd_id must be set");
13411 return -99;
13412 }
13413
13414 if (sw_if_index_set == 0)
13415 {
13416 errmsg ("missing interface name or sw_if_index");
13417 return -99;
13418 }
13419
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013420 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013421
13422 mp->spd_id = ntohl (spd_id);
13423 mp->sw_if_index = ntohl (sw_if_index);
13424 mp->is_add = is_add;
13425
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013426 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013427 W (ret);
13428 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013429}
13430
13431static int
Neale Ranns17dcec02019-01-09 21:22:20 -080013432api_ipsec_spd_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013433{
13434 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080013435 vl_api_ipsec_spd_entry_add_del_t *mp;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013436 u8 is_add = 1, is_outbound = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013437 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
13438 i32 priority = 0;
13439 u32 rport_start = 0, rport_stop = (u32) ~ 0;
13440 u32 lport_start = 0, lport_stop = (u32) ~ 0;
Neale Ranns17dcec02019-01-09 21:22:20 -080013441 vl_api_address_t laddr_start = { }, laddr_stop =
13442 {
13443 }, raddr_start =
13444 {
13445 }, raddr_stop =
13446 {
13447 };
Jon Loeliger56c7b012017-02-01 12:31:41 -060013448 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013449
Damjan Marion7cd468a2016-12-19 23:05:39 +010013450 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13451 {
13452 if (unformat (i, "del"))
13453 is_add = 0;
13454 if (unformat (i, "outbound"))
13455 is_outbound = 1;
13456 if (unformat (i, "inbound"))
13457 is_outbound = 0;
13458 else if (unformat (i, "spd_id %d", &spd_id))
13459 ;
13460 else if (unformat (i, "sa_id %d", &sa_id))
13461 ;
13462 else if (unformat (i, "priority %d", &priority))
13463 ;
13464 else if (unformat (i, "protocol %d", &protocol))
13465 ;
13466 else if (unformat (i, "lport_start %d", &lport_start))
13467 ;
13468 else if (unformat (i, "lport_stop %d", &lport_stop))
13469 ;
13470 else if (unformat (i, "rport_start %d", &rport_start))
13471 ;
13472 else if (unformat (i, "rport_stop %d", &rport_stop))
13473 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013474 else if (unformat (i, "laddr_start %U",
13475 unformat_vl_api_address, &laddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013476 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013477 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
13478 &laddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013479 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013480 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
13481 &raddr_start))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013482 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013483 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
13484 &raddr_stop))
Benoît Ganne49ee6842019-04-30 11:50:46 +020013485 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013486 else
13487 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
13488 {
13489 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
13490 {
13491 clib_warning ("unsupported action: 'resolve'");
13492 return -99;
13493 }
13494 }
13495 else
13496 {
13497 clib_warning ("parse error '%U'", format_unformat_error, i);
13498 return -99;
13499 }
13500
13501 }
13502
Neale Ranns17dcec02019-01-09 21:22:20 -080013503 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013504
Damjan Marion7cd468a2016-12-19 23:05:39 +010013505 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080013506
13507 mp->entry.spd_id = ntohl (spd_id);
13508 mp->entry.priority = ntohl (priority);
13509 mp->entry.is_outbound = is_outbound;
13510
13511 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
13512 sizeof (vl_api_address_t));
13513 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
13514 sizeof (vl_api_address_t));
13515 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
13516 sizeof (vl_api_address_t));
13517 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
13518 sizeof (vl_api_address_t));
13519
13520 mp->entry.protocol = (u8) protocol;
13521 mp->entry.local_port_start = ntohs ((u16) lport_start);
13522 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
13523 mp->entry.remote_port_start = ntohs ((u16) rport_start);
13524 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
13525 mp->entry.policy = (u8) policy;
13526 mp->entry.sa_id = ntohl (sa_id);
Neale Ranns17dcec02019-01-09 21:22:20 -080013527
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013528 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013529 W (ret);
13530 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013531}
13532
13533static int
Neale Ranns17dcec02019-01-09 21:22:20 -080013534api_ipsec_sad_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013535{
13536 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080013537 vl_api_ipsec_sad_entry_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013538 u32 sad_id = 0, spi = 0;
13539 u8 *ck = 0, *ik = 0;
13540 u8 is_add = 1;
13541
Neale Ranns17dcec02019-01-09 21:22:20 -080013542 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
13543 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
13544 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
13545 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
13546 vl_api_address_t tun_src, tun_dst;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013547 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013548
13549 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13550 {
13551 if (unformat (i, "del"))
13552 is_add = 0;
13553 else if (unformat (i, "sad_id %d", &sad_id))
13554 ;
13555 else if (unformat (i, "spi %d", &spi))
13556 ;
13557 else if (unformat (i, "esp"))
Neale Ranns17dcec02019-01-09 21:22:20 -080013558 protocol = IPSEC_API_PROTO_ESP;
13559 else
13560 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
Damjan Marion7cd468a2016-12-19 23:05:39 +010013561 {
Neale Ranns17dcec02019-01-09 21:22:20 -080013562 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
13563 if (ADDRESS_IP6 == tun_src.af)
13564 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013565 }
13566 else
Neale Ranns17dcec02019-01-09 21:22:20 -080013567 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
Damjan Marion7cd468a2016-12-19 23:05:39 +010013568 {
Neale Ranns17dcec02019-01-09 21:22:20 -080013569 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
13570 if (ADDRESS_IP6 == tun_src.af)
13571 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013572 }
Neale Ranns17dcec02019-01-09 21:22:20 -080013573 else
13574 if (unformat (i, "crypto_alg %U",
13575 unformat_ipsec_api_crypto_alg, &crypto_alg))
13576 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013577 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
13578 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080013579 else if (unformat (i, "integ_alg %U",
13580 unformat_ipsec_api_integ_alg, &integ_alg))
13581 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013582 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
13583 ;
13584 else
13585 {
13586 clib_warning ("parse error '%U'", format_unformat_error, i);
13587 return -99;
13588 }
13589
13590 }
13591
Neale Ranns17dcec02019-01-09 21:22:20 -080013592 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013593
Damjan Marion7cd468a2016-12-19 23:05:39 +010013594 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080013595 mp->entry.sad_id = ntohl (sad_id);
13596 mp->entry.protocol = protocol;
13597 mp->entry.spi = ntohl (spi);
13598 mp->entry.flags = flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013599
Neale Ranns17dcec02019-01-09 21:22:20 -080013600 mp->entry.crypto_algorithm = crypto_alg;
13601 mp->entry.integrity_algorithm = integ_alg;
13602 mp->entry.crypto_key.length = vec_len (ck);
13603 mp->entry.integrity_key.length = vec_len (ik);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013604
Neale Ranns17dcec02019-01-09 21:22:20 -080013605 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
13606 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
13607
13608 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
13609 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013610
13611 if (ck)
Neale Ranns17dcec02019-01-09 21:22:20 -080013612 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013613 if (ik)
Neale Ranns17dcec02019-01-09 21:22:20 -080013614 clib_memcpy (mp->entry.integrity_key.data, ik,
13615 mp->entry.integrity_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013616
Neale Ranns17dcec02019-01-09 21:22:20 -080013617 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
Damjan Marion7cd468a2016-12-19 23:05:39 +010013618 {
Neale Ranns17dcec02019-01-09 21:22:20 -080013619 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
13620 sizeof (mp->entry.tunnel_src));
13621 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
13622 sizeof (mp->entry.tunnel_dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013623 }
13624
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013625 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013626 W (ret);
13627 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013628}
13629
13630static int
Matthew Smithb0972cb2017-05-02 16:20:41 -050013631api_ipsec_tunnel_if_add_del (vat_main_t * vam)
13632{
13633 unformat_input_t *i = vam->input;
13634 vl_api_ipsec_tunnel_if_add_del_t *mp;
13635 u32 local_spi = 0, remote_spi = 0;
13636 u32 crypto_alg = 0, integ_alg = 0;
13637 u8 *lck = NULL, *rck = NULL;
13638 u8 *lik = NULL, *rik = NULL;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040013639 vl_api_address_t local_ip = { 0 };
13640 vl_api_address_t remote_ip = { 0 };
Neale Ranns2b5ba952019-04-02 10:15:40 +000013641 f64 before = 0;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013642 u8 is_add = 1;
13643 u8 esn = 0;
13644 u8 anti_replay = 0;
Matthew Smith8e1039a2018-04-12 07:32:56 -050013645 u8 renumber = 0;
13646 u32 instance = ~0;
Neale Ranns2b5ba952019-04-02 10:15:40 +000013647 u32 count = 1, jj;
Benoît Ganne49ee6842019-04-30 11:50:46 +020013648 int ret = -1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013649
13650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13651 {
13652 if (unformat (i, "del"))
13653 is_add = 0;
13654 else if (unformat (i, "esn"))
13655 esn = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000013656 else if (unformat (i, "anti-replay"))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013657 anti_replay = 1;
Neale Ranns2b5ba952019-04-02 10:15:40 +000013658 else if (unformat (i, "count %d", &count))
13659 ;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013660 else if (unformat (i, "local_spi %d", &local_spi))
13661 ;
13662 else if (unformat (i, "remote_spi %d", &remote_spi))
13663 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040013664 else
13665 if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013666 ;
Kingwel Xie1ba5bc82019-03-20 07:21:58 -040013667 else
13668 if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013669 ;
13670 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
13671 ;
13672 else
13673 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
13674 ;
13675 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
13676 ;
13677 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
13678 ;
13679 else
13680 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080013681 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013682 {
Dave Baracha8d47642018-07-13 11:22:23 -040013683 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013684 {
13685 errmsg ("unsupported crypto-alg: '%U'\n",
13686 format_ipsec_crypto_alg, crypto_alg);
13687 return -99;
13688 }
13689 }
13690 else
13691 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080013692 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050013693 {
Dave Baracha8d47642018-07-13 11:22:23 -040013694 if (integ_alg >= IPSEC_INTEG_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013695 {
13696 errmsg ("unsupported integ-alg: '%U'\n",
13697 format_ipsec_integ_alg, integ_alg);
13698 return -99;
13699 }
13700 }
Matthew Smith8e1039a2018-04-12 07:32:56 -050013701 else if (unformat (i, "instance %u", &instance))
13702 renumber = 1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013703 else
13704 {
13705 errmsg ("parse error '%U'\n", format_unformat_error, i);
13706 return -99;
13707 }
13708 }
13709
Neale Ranns2b5ba952019-04-02 10:15:40 +000013710 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013711 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000013712 /* Turn on async mode */
13713 vam->async_mode = 1;
13714 vam->async_errors = 0;
13715 before = vat_time_now (vam);
Matthew Smithb0972cb2017-05-02 16:20:41 -050013716 }
13717
Neale Ranns2b5ba952019-04-02 10:15:40 +000013718 for (jj = 0; jj < count; jj++)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013719 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000013720 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
13721
13722 mp->is_add = is_add;
13723 mp->esn = esn;
13724 mp->anti_replay = anti_replay;
13725
13726 if (jj > 0)
Neale Ranns097fa662018-05-01 05:17:55 -070013727 increment_address (&remote_ip);
Neale Ranns2b5ba952019-04-02 10:15:40 +000013728
13729 clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
13730 clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
13731
13732 mp->local_spi = htonl (local_spi + jj);
13733 mp->remote_spi = htonl (remote_spi + jj);
13734 mp->crypto_alg = (u8) crypto_alg;
13735
13736 mp->local_crypto_key_len = 0;
13737 if (lck)
13738 {
13739 mp->local_crypto_key_len = vec_len (lck);
13740 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
13741 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
13742 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
13743 }
13744
13745 mp->remote_crypto_key_len = 0;
13746 if (rck)
13747 {
13748 mp->remote_crypto_key_len = vec_len (rck);
13749 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
13750 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
13751 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
13752 }
13753
13754 mp->integ_alg = (u8) integ_alg;
13755
13756 mp->local_integ_key_len = 0;
13757 if (lik)
13758 {
13759 mp->local_integ_key_len = vec_len (lik);
13760 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
13761 mp->local_integ_key_len = sizeof (mp->local_integ_key);
13762 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
13763 }
13764
13765 mp->remote_integ_key_len = 0;
13766 if (rik)
13767 {
13768 mp->remote_integ_key_len = vec_len (rik);
13769 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
13770 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
13771 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
13772 }
13773
13774 if (renumber)
13775 {
13776 mp->renumber = renumber;
13777 mp->show_instance = ntohl (instance);
13778 }
13779 S (mp);
Matthew Smithb0972cb2017-05-02 16:20:41 -050013780 }
13781
Neale Ranns2b5ba952019-04-02 10:15:40 +000013782 /* When testing multiple add/del ops, use a control-ping to sync */
13783 if (count > 1)
Matthew Smithb0972cb2017-05-02 16:20:41 -050013784 {
Neale Ranns2b5ba952019-04-02 10:15:40 +000013785 vl_api_control_ping_t *mp_ping;
13786 f64 after;
13787 f64 timeout;
13788
13789 /* Shut off async mode */
13790 vam->async_mode = 0;
13791
13792 MPING (CONTROL_PING, mp_ping);
13793 S (mp_ping);
13794
13795 timeout = vat_time_now (vam) + 1.0;
13796 while (vat_time_now (vam) < timeout)
13797 if (vam->result_ready == 1)
13798 goto out;
13799 vam->retval = -99;
13800
13801 out:
13802 if (vam->retval == -99)
13803 errmsg ("timeout");
13804
13805 if (vam->async_errors > 0)
13806 {
13807 errmsg ("%d asynchronous errors", vam->async_errors);
13808 vam->retval = -98;
13809 }
13810 vam->async_errors = 0;
13811 after = vat_time_now (vam);
13812
13813 /* slim chance, but we might have eaten SIGTERM on the first iteration */
13814 if (jj > 0)
13815 count = jj;
13816
13817 print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec",
13818 count, after - before, count / (after - before));
13819 }
13820 else
13821 {
13822 /* Wait for a reply... */
13823 W (ret);
13824 return ret;
Matthew Smithb0972cb2017-05-02 16:20:41 -050013825 }
13826
Matthew Smithb0972cb2017-05-02 16:20:41 -050013827 return ret;
13828}
13829
Matthew Smith28029532017-09-26 13:33:44 -050013830static void
13831vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
13832{
13833 vat_main_t *vam = &vat_main;
13834
13835 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
Neale Ranns8d7c5022019-02-06 01:41:05 -080013836 "crypto_key %U integ_alg %u integ_key %U flags %x "
Matthew Smith28029532017-09-26 13:33:44 -050013837 "tunnel_src_addr %U tunnel_dst_addr %U "
13838 "salt %u seq_outbound %lu last_seq_inbound %lu "
Matthew Smith48d32b42020-04-02 07:45:49 -050013839 "replay_window %lu stat_index %u\n",
Neale Ranns8d7c5022019-02-06 01:41:05 -080013840 ntohl (mp->entry.sad_id),
13841 ntohl (mp->sw_if_index),
13842 ntohl (mp->entry.spi),
13843 ntohl (mp->entry.protocol),
13844 ntohl (mp->entry.crypto_algorithm),
13845 format_hex_bytes, mp->entry.crypto_key.data,
13846 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
13847 format_hex_bytes, mp->entry.integrity_key.data,
13848 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
13849 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
13850 &mp->entry.tunnel_dst, ntohl (mp->salt),
Matthew Smith28029532017-09-26 13:33:44 -050013851 clib_net_to_host_u64 (mp->seq_outbound),
13852 clib_net_to_host_u64 (mp->last_seq_inbound),
Matthew Smith48d32b42020-04-02 07:45:49 -050013853 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
Matthew Smith28029532017-09-26 13:33:44 -050013854}
13855
13856#define vl_api_ipsec_sa_details_t_endian vl_noop_handler
13857#define vl_api_ipsec_sa_details_t_print vl_noop_handler
13858
13859static void vl_api_ipsec_sa_details_t_handler_json
13860 (vl_api_ipsec_sa_details_t * mp)
13861{
13862 vat_main_t *vam = &vat_main;
13863 vat_json_node_t *node = NULL;
Neale Ranns8d7c5022019-02-06 01:41:05 -080013864 vl_api_ipsec_sad_flags_t flags;
Matthew Smith28029532017-09-26 13:33:44 -050013865
13866 if (VAT_JSON_ARRAY != vam->json_tree.type)
13867 {
13868 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13869 vat_json_init_array (&vam->json_tree);
13870 }
13871 node = vat_json_array_add (&vam->json_tree);
13872
13873 vat_json_init_object (node);
Neale Ranns8d7c5022019-02-06 01:41:05 -080013874 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
Matthew Smith28029532017-09-26 13:33:44 -050013875 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Neale Ranns8d7c5022019-02-06 01:41:05 -080013876 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
13877 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
13878 vat_json_object_add_uint (node, "crypto_alg",
13879 ntohl (mp->entry.crypto_algorithm));
13880 vat_json_object_add_uint (node, "integ_alg",
13881 ntohl (mp->entry.integrity_algorithm));
13882 flags = ntohl (mp->entry.flags);
13883 vat_json_object_add_uint (node, "use_esn",
Damjan Marion1e3aa5e2019-03-28 10:58:59 +010013884 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
Neale Ranns8d7c5022019-02-06 01:41:05 -080013885 vat_json_object_add_uint (node, "use_anti_replay",
13886 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
13887 vat_json_object_add_uint (node, "is_tunnel",
13888 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
13889 vat_json_object_add_uint (node, "is_tunnel_ip6",
13890 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
13891 vat_json_object_add_uint (node, "udp_encap",
13892 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
13893 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
13894 mp->entry.crypto_key.length);
13895 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
13896 mp->entry.integrity_key.length);
Neale Ranns5a8844b2019-04-16 07:15:35 +000013897 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
13898 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
Matthew Smith28029532017-09-26 13:33:44 -050013899 vat_json_object_add_uint (node, "replay_window",
13900 clib_net_to_host_u64 (mp->replay_window));
Matthew Smith48d32b42020-04-02 07:45:49 -050013901 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
Matthew Smith28029532017-09-26 13:33:44 -050013902}
13903
13904static int
13905api_ipsec_sa_dump (vat_main_t * vam)
13906{
13907 unformat_input_t *i = vam->input;
13908 vl_api_ipsec_sa_dump_t *mp;
13909 vl_api_control_ping_t *mp_ping;
13910 u32 sa_id = ~0;
13911 int ret;
13912
13913 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13914 {
13915 if (unformat (i, "sa_id %d", &sa_id))
13916 ;
13917 else
13918 {
13919 clib_warning ("parse error '%U'", format_unformat_error, i);
13920 return -99;
13921 }
13922 }
13923
13924 M (IPSEC_SA_DUMP, mp);
13925
13926 mp->sa_id = ntohl (sa_id);
13927
13928 S (mp);
13929
13930 /* Use a control ping for synchronization */
13931 M (CONTROL_PING, mp_ping);
13932 S (mp_ping);
13933
13934 W (ret);
13935 return ret;
13936}
13937
Matthew Smithb0972cb2017-05-02 16:20:41 -050013938static int
Matthew Smithca514fd2017-10-12 12:06:59 -050013939api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
13940{
13941 unformat_input_t *i = vam->input;
13942 vl_api_ipsec_tunnel_if_set_sa_t *mp;
13943 u32 sw_if_index = ~0;
13944 u32 sa_id = ~0;
13945 u8 is_outbound = (u8) ~ 0;
13946 int ret;
13947
13948 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13949 {
13950 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13951 ;
13952 else if (unformat (i, "sa_id %d", &sa_id))
13953 ;
13954 else if (unformat (i, "outbound"))
13955 is_outbound = 1;
13956 else if (unformat (i, "inbound"))
13957 is_outbound = 0;
13958 else
13959 {
13960 clib_warning ("parse error '%U'", format_unformat_error, i);
13961 return -99;
13962 }
13963 }
13964
13965 if (sw_if_index == ~0)
13966 {
13967 errmsg ("interface must be specified");
13968 return -99;
13969 }
13970
13971 if (sa_id == ~0)
13972 {
13973 errmsg ("SA ID must be specified");
13974 return -99;
13975 }
13976
13977 M (IPSEC_TUNNEL_IF_SET_SA, mp);
13978
13979 mp->sw_if_index = htonl (sw_if_index);
13980 mp->sa_id = htonl (sa_id);
13981 mp->is_outbound = is_outbound;
13982
13983 S (mp);
13984 W (ret);
13985
13986 return ret;
13987}
13988
13989static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010013990api_get_first_msg_id (vat_main_t * vam)
13991{
13992 vl_api_get_first_msg_id_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013993 unformat_input_t *i = vam->input;
13994 u8 *name;
13995 u8 name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013996 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013997
13998 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13999 {
14000 if (unformat (i, "client %s", &name))
14001 name_set = 1;
14002 else
14003 break;
14004 }
14005
14006 if (name_set == 0)
14007 {
14008 errmsg ("missing client name");
14009 return -99;
14010 }
14011 vec_add1 (name, 0);
14012
14013 if (vec_len (name) > 63)
14014 {
14015 errmsg ("client name too long");
14016 return -99;
14017 }
14018
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014019 M (GET_FIRST_MSG_ID, mp);
Ole Troan7adaa222019-08-27 15:05:27 +020014020 clib_memcpy (mp->name, name, vec_len (name));
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014021 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014022 W (ret);
14023 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014024}
14025
14026static int
14027api_cop_interface_enable_disable (vat_main_t * vam)
14028{
14029 unformat_input_t *line_input = vam->input;
14030 vl_api_cop_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014031 u32 sw_if_index = ~0;
14032 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014033 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014034
14035 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14036 {
14037 if (unformat (line_input, "disable"))
14038 enable_disable = 0;
14039 if (unformat (line_input, "enable"))
14040 enable_disable = 1;
14041 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
14042 vam, &sw_if_index))
14043 ;
14044 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
14045 ;
14046 else
14047 break;
14048 }
14049
14050 if (sw_if_index == ~0)
14051 {
14052 errmsg ("missing interface name or sw_if_index");
14053 return -99;
14054 }
14055
14056 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014057 M (COP_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014058 mp->sw_if_index = ntohl (sw_if_index);
14059 mp->enable_disable = enable_disable;
14060
14061 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014062 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014063 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014064 W (ret);
14065 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014066}
14067
14068static int
14069api_cop_whitelist_enable_disable (vat_main_t * vam)
14070{
14071 unformat_input_t *line_input = vam->input;
14072 vl_api_cop_whitelist_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014073 u32 sw_if_index = ~0;
14074 u8 ip4 = 0, ip6 = 0, default_cop = 0;
14075 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014076 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014077
14078 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14079 {
14080 if (unformat (line_input, "ip4"))
14081 ip4 = 1;
14082 else if (unformat (line_input, "ip6"))
14083 ip6 = 1;
14084 else if (unformat (line_input, "default"))
14085 default_cop = 1;
14086 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
14087 vam, &sw_if_index))
14088 ;
14089 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
14090 ;
14091 else if (unformat (line_input, "fib-id %d", &fib_id))
14092 ;
14093 else
14094 break;
14095 }
14096
14097 if (sw_if_index == ~0)
14098 {
14099 errmsg ("missing interface name or sw_if_index");
14100 return -99;
14101 }
14102
14103 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014104 M (COP_WHITELIST_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014105 mp->sw_if_index = ntohl (sw_if_index);
14106 mp->fib_id = ntohl (fib_id);
14107 mp->ip4 = ip4;
14108 mp->ip6 = ip6;
14109 mp->default_cop = default_cop;
14110
14111 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014112 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014113 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014114 W (ret);
14115 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014116}
14117
14118static int
14119api_get_node_graph (vat_main_t * vam)
14120{
14121 vl_api_get_node_graph_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014122 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014123
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014124 M (GET_NODE_GRAPH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014125
14126 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014127 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014128 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014129 W (ret);
14130 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014131}
14132
14133/* *INDENT-OFF* */
14134/** Used for parsing LISP eids */
14135typedef CLIB_PACKED(struct{
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014136 union {
14137 ip46_address_t ip;
14138 mac_address_t mac;
14139 lisp_nsh_api_t nsh;
14140 } addr;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014141 u32 len; /**< prefix length if IP */
14142 u8 type; /**< type of eid */
14143}) lisp_eid_vat_t;
14144/* *INDENT-ON* */
14145
14146static uword
14147unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
14148{
14149 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
14150
Dave Barachb7b92992018-10-17 10:38:51 -040014151 clib_memset (a, 0, sizeof (a[0]));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014152
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014153 if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014154 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014155 a->type = 0; /* ip prefix type */
Damjan Marion7cd468a2016-12-19 23:05:39 +010014156 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014157 else if (unformat (input, "%U", unformat_ethernet_address, a->addr.mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014158 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014159 a->type = 1; /* mac type */
Damjan Marion7cd468a2016-12-19 23:05:39 +010014160 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014161 else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014162 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014163 a->type = 2; /* NSH type */
14164 a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020014165 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010014166 else
14167 {
14168 return 0;
14169 }
14170
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014171 if (a->type == 0)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014172 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014173 if (ip46_address_is_ip4 (&a->addr.ip))
14174 return a->len > 32 ? 1 : 0;
14175 else
14176 return a->len > 128 ? 1 : 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014177 }
14178
14179 return 1;
14180}
14181
Damjan Marion7cd468a2016-12-19 23:05:39 +010014182static void
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014183lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014184{
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014185 eid->type = vat_eid->type;
14186 switch (eid->type)
14187 {
14188 case EID_TYPE_API_PREFIX:
14189 if (ip46_address_is_ip4 (&vat_eid->addr.ip))
14190 {
14191 clib_memcpy (&eid->address.prefix.address.un.ip4,
14192 &vat_eid->addr.ip.ip4, 4);
14193 eid->address.prefix.address.af = ADDRESS_IP4;
14194 eid->address.prefix.len = vat_eid->len;
14195 }
14196 else
14197 {
14198 clib_memcpy (&eid->address.prefix.address.un.ip6,
14199 &vat_eid->addr.ip.ip6, 16);
14200 eid->address.prefix.address.af = ADDRESS_IP6;
14201 eid->address.prefix.len = vat_eid->len;
14202 }
14203 return;
14204 case EID_TYPE_API_MAC:
14205 clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
14206 sizeof (eid->address.mac));
14207 return;
14208 case EID_TYPE_API_NSH:
14209 clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
14210 sizeof (eid->address.nsh));
14211 return;
14212 default:
14213 ASSERT (0);
14214 return;
14215 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010014216}
14217
Damjan Marion7cd468a2016-12-19 23:05:39 +010014218static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014219api_one_add_del_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014220{
14221 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014222 vl_api_one_add_del_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014223 u8 is_add = 1;
14224 u8 *locator_set_name = NULL;
14225 u8 locator_set_name_set = 0;
Filip Tehlar05a057b2017-02-01 08:50:31 +010014226 vl_api_local_locator_t locator, *locators = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014227 u32 sw_if_index, priority, weight;
14228 u32 data_len = 0;
14229
Jon Loeliger56c7b012017-02-01 12:31:41 -060014230 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014231 /* Parse args required to build the message */
14232 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14233 {
14234 if (unformat (input, "del"))
14235 {
14236 is_add = 0;
14237 }
14238 else if (unformat (input, "locator-set %s", &locator_set_name))
14239 {
14240 locator_set_name_set = 1;
14241 }
14242 else if (unformat (input, "sw_if_index %u p %u w %u",
14243 &sw_if_index, &priority, &weight))
14244 {
14245 locator.sw_if_index = htonl (sw_if_index);
14246 locator.priority = priority;
14247 locator.weight = weight;
14248 vec_add1 (locators, locator);
14249 }
14250 else
14251 if (unformat
14252 (input, "iface %U p %u w %u", api_unformat_sw_if_index, vam,
14253 &sw_if_index, &priority, &weight))
14254 {
14255 locator.sw_if_index = htonl (sw_if_index);
14256 locator.priority = priority;
14257 locator.weight = weight;
14258 vec_add1 (locators, locator);
14259 }
14260 else
14261 break;
14262 }
14263
14264 if (locator_set_name_set == 0)
14265 {
14266 errmsg ("missing locator-set name");
14267 vec_free (locators);
14268 return -99;
14269 }
14270
14271 if (vec_len (locator_set_name) > 64)
14272 {
14273 errmsg ("locator-set name too long");
14274 vec_free (locator_set_name);
14275 vec_free (locators);
14276 return -99;
14277 }
14278 vec_add1 (locator_set_name, 0);
14279
Filip Tehlar05a057b2017-02-01 08:50:31 +010014280 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014281
14282 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014283 M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014284
14285 mp->is_add = is_add;
14286 clib_memcpy (mp->locator_set_name, locator_set_name,
14287 vec_len (locator_set_name));
14288 vec_free (locator_set_name);
14289
14290 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
14291 if (locators)
14292 clib_memcpy (mp->locators, locators, data_len);
14293 vec_free (locators);
14294
14295 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014296 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014297
14298 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014299 W (ret);
14300 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014301}
14302
Filip Tehlar694396d2017-02-17 14:29:11 +010014303#define api_lisp_add_del_locator_set api_one_add_del_locator_set
14304
Damjan Marion7cd468a2016-12-19 23:05:39 +010014305static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014306api_one_add_del_locator (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014307{
14308 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014309 vl_api_one_add_del_locator_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014310 u32 tmp_if_index = ~0;
14311 u32 sw_if_index = ~0;
14312 u8 sw_if_index_set = 0;
14313 u8 sw_if_index_if_name_set = 0;
14314 u32 priority = ~0;
14315 u8 priority_set = 0;
14316 u32 weight = ~0;
14317 u8 weight_set = 0;
14318 u8 is_add = 1;
14319 u8 *locator_set_name = NULL;
14320 u8 locator_set_name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014321 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014322
14323 /* Parse args required to build the message */
14324 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14325 {
14326 if (unformat (input, "del"))
14327 {
14328 is_add = 0;
14329 }
14330 else if (unformat (input, "locator-set %s", &locator_set_name))
14331 {
14332 locator_set_name_set = 1;
14333 }
14334 else if (unformat (input, "iface %U", api_unformat_sw_if_index, vam,
14335 &tmp_if_index))
14336 {
14337 sw_if_index_if_name_set = 1;
14338 sw_if_index = tmp_if_index;
14339 }
14340 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
14341 {
14342 sw_if_index_set = 1;
14343 sw_if_index = tmp_if_index;
14344 }
14345 else if (unformat (input, "p %d", &priority))
14346 {
14347 priority_set = 1;
14348 }
14349 else if (unformat (input, "w %d", &weight))
14350 {
14351 weight_set = 1;
14352 }
14353 else
14354 break;
14355 }
14356
14357 if (locator_set_name_set == 0)
14358 {
14359 errmsg ("missing locator-set name");
14360 return -99;
14361 }
14362
14363 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
14364 {
14365 errmsg ("missing sw_if_index");
14366 vec_free (locator_set_name);
14367 return -99;
14368 }
14369
14370 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
14371 {
14372 errmsg ("cannot use both params interface name and sw_if_index");
14373 vec_free (locator_set_name);
14374 return -99;
14375 }
14376
14377 if (priority_set == 0)
14378 {
14379 errmsg ("missing locator-set priority");
14380 vec_free (locator_set_name);
14381 return -99;
14382 }
14383
14384 if (weight_set == 0)
14385 {
14386 errmsg ("missing locator-set weight");
14387 vec_free (locator_set_name);
14388 return -99;
14389 }
14390
14391 if (vec_len (locator_set_name) > 64)
14392 {
14393 errmsg ("locator-set name too long");
14394 vec_free (locator_set_name);
14395 return -99;
14396 }
14397 vec_add1 (locator_set_name, 0);
14398
14399 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014400 M (ONE_ADD_DEL_LOCATOR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014401
14402 mp->is_add = is_add;
14403 mp->sw_if_index = ntohl (sw_if_index);
14404 mp->priority = priority;
14405 mp->weight = weight;
14406 clib_memcpy (mp->locator_set_name, locator_set_name,
14407 vec_len (locator_set_name));
14408 vec_free (locator_set_name);
14409
14410 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014411 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014412
14413 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014414 W (ret);
14415 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014416}
14417
Filip Tehlar694396d2017-02-17 14:29:11 +010014418#define api_lisp_add_del_locator api_one_add_del_locator
14419
Damjan Marion7cd468a2016-12-19 23:05:39 +010014420uword
14421unformat_hmac_key_id (unformat_input_t * input, va_list * args)
14422{
14423 u32 *key_id = va_arg (*args, u32 *);
14424 u8 *s = 0;
14425
14426 if (unformat (input, "%s", &s))
14427 {
14428 if (!strcmp ((char *) s, "sha1"))
14429 key_id[0] = HMAC_SHA_1_96;
14430 else if (!strcmp ((char *) s, "sha256"))
14431 key_id[0] = HMAC_SHA_256_128;
14432 else
14433 {
14434 clib_warning ("invalid key_id: '%s'", s);
14435 key_id[0] = HMAC_NO_KEY;
14436 }
14437 }
14438 else
14439 return 0;
14440
14441 vec_free (s);
14442 return 1;
14443}
14444
14445static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014446api_one_add_del_local_eid (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014447{
14448 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014449 vl_api_one_add_del_local_eid_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014450 u8 is_add = 1;
14451 u8 eid_set = 0;
14452 lisp_eid_vat_t _eid, *eid = &_eid;
14453 u8 *locator_set_name = 0;
14454 u8 locator_set_name_set = 0;
14455 u32 vni = 0;
14456 u16 key_id = 0;
14457 u8 *key = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014458 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014459
14460 /* Parse args required to build the message */
14461 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14462 {
14463 if (unformat (input, "del"))
14464 {
14465 is_add = 0;
14466 }
14467 else if (unformat (input, "vni %d", &vni))
14468 {
14469 ;
14470 }
14471 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
14472 {
14473 eid_set = 1;
14474 }
14475 else if (unformat (input, "locator-set %s", &locator_set_name))
14476 {
14477 locator_set_name_set = 1;
14478 }
14479 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
14480 ;
14481 else if (unformat (input, "secret-key %_%v%_", &key))
14482 ;
14483 else
14484 break;
14485 }
14486
14487 if (locator_set_name_set == 0)
14488 {
14489 errmsg ("missing locator-set name");
14490 return -99;
14491 }
14492
14493 if (0 == eid_set)
14494 {
14495 errmsg ("EID address not set!");
14496 vec_free (locator_set_name);
14497 return -99;
14498 }
14499
14500 if (key && (0 == key_id))
14501 {
14502 errmsg ("invalid key_id!");
14503 return -99;
14504 }
14505
14506 if (vec_len (key) > 64)
14507 {
14508 errmsg ("key too long");
14509 vec_free (key);
14510 return -99;
14511 }
14512
14513 if (vec_len (locator_set_name) > 64)
14514 {
14515 errmsg ("locator-set name too long");
14516 vec_free (locator_set_name);
14517 return -99;
14518 }
14519 vec_add1 (locator_set_name, 0);
14520
14521 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014522 M (ONE_ADD_DEL_LOCAL_EID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014523
14524 mp->is_add = is_add;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014525 lisp_eid_put_vat (&mp->eid, eid);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014526 mp->vni = clib_host_to_net_u32 (vni);
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014527 mp->key.id = key_id;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014528 clib_memcpy (mp->locator_set_name, locator_set_name,
14529 vec_len (locator_set_name));
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014530 clib_memcpy (mp->key.key, key, vec_len (key));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014531
14532 vec_free (locator_set_name);
14533 vec_free (key);
14534
14535 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014536 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014537
14538 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014539 W (ret);
14540 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014541}
14542
Filip Tehlar694396d2017-02-17 14:29:11 +010014543#define api_lisp_add_del_local_eid api_one_add_del_local_eid
Damjan Marion7cd468a2016-12-19 23:05:39 +010014544
14545static int
14546api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
14547{
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014548 u32 dp_table = 0, vni = 0;;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014549 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010014550 vl_api_gpe_add_del_fwd_entry_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014551 u8 is_add = 1;
14552 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
14553 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
14554 u8 rmt_eid_set = 0, lcl_eid_set = 0;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014555 u32 action = ~0, w;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014556 ip4_address_t rmt_rloc4, lcl_rloc4;
14557 ip6_address_t rmt_rloc6, lcl_rloc6;
Filip Tehlar82786c42017-02-20 15:20:37 +010014558 vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014559 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014560
Dave Barachb7b92992018-10-17 10:38:51 -040014561 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014562
14563 /* Parse args required to build the message */
14564 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14565 {
14566 if (unformat (input, "del"))
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014567 is_add = 0;
14568 else if (unformat (input, "add"))
14569 is_add = 1;
14570 else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014571 {
14572 rmt_eid_set = 1;
14573 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014574 else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014575 {
14576 lcl_eid_set = 1;
14577 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014578 else if (unformat (input, "vrf %d", &dp_table))
14579 ;
14580 else if (unformat (input, "bd %d", &dp_table))
14581 ;
14582 else if (unformat (input, "vni %d", &vni))
14583 ;
14584 else if (unformat (input, "w %d", &w))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014585 {
14586 if (!curr_rloc)
14587 {
14588 errmsg ("No RLOC configured for setting priority/weight!");
14589 return -99;
14590 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010014591 curr_rloc->weight = w;
14592 }
14593 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
14594 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
14595 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014596 rloc.addr.af = 0;
14597 clib_memcpy (&rloc.addr.un.ip4, &lcl_rloc4, sizeof (lcl_rloc4));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014598 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014599 vec_add1 (lcl_locs, rloc);
14600
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014601 clib_memcpy (&rloc.addr.un.ip4, &rmt_rloc4, sizeof (rmt_rloc4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014602 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014603 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010014604 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
14605 }
14606 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
14607 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
14608 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014609 rloc.addr.af = 1;
14610 clib_memcpy (&rloc.addr.un.ip6, &lcl_rloc6, sizeof (lcl_rloc6));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014611 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014612 vec_add1 (lcl_locs, rloc);
14613
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014614 clib_memcpy (&rloc.addr.un.ip6, &rmt_rloc6, sizeof (rmt_rloc6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014615 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014616 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010014617 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
14618 }
14619 else if (unformat (input, "action %d", &action))
14620 {
14621 ;
14622 }
14623 else
14624 {
14625 clib_warning ("parse error '%U'", format_unformat_error, input);
14626 return -99;
14627 }
14628 }
14629
14630 if (!rmt_eid_set)
14631 {
14632 errmsg ("remote eid addresses not set");
14633 return -99;
14634 }
14635
14636 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
14637 {
14638 errmsg ("eid types don't match");
14639 return -99;
14640 }
14641
14642 if (0 == rmt_locs && (u32) ~ 0 == action)
14643 {
14644 errmsg ("action not set for negative mapping");
14645 return -99;
14646 }
14647
14648 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010014649 M2 (GPE_ADD_DEL_FWD_ENTRY, mp,
14650 sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014651
14652 mp->is_add = is_add;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014653 lisp_eid_put_vat (&mp->rmt_eid, rmt_eid);
14654 lisp_eid_put_vat (&mp->lcl_eid, lcl_eid);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014655 mp->dp_table = clib_host_to_net_u32 (dp_table);
14656 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014657 mp->action = action;
14658
14659 if (0 != rmt_locs && 0 != lcl_locs)
14660 {
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014661 mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2);
14662 clib_memcpy (mp->locs, lcl_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010014663 (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs)));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014664
Filip Tehlar82786c42017-02-20 15:20:37 +010014665 u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010014666 clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010014667 (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs)));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014668 }
14669 vec_free (lcl_locs);
14670 vec_free (rmt_locs);
14671
14672 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014673 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014674
14675 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014676 W (ret);
14677 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014678}
14679
14680static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014681api_one_add_del_map_server (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014682{
14683 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014684 vl_api_one_add_del_map_server_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014685 u8 is_add = 1;
14686 u8 ipv4_set = 0;
14687 u8 ipv6_set = 0;
14688 ip4_address_t ipv4;
14689 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014690 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014691
14692 /* Parse args required to build the message */
14693 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14694 {
14695 if (unformat (input, "del"))
14696 {
14697 is_add = 0;
14698 }
14699 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
14700 {
14701 ipv4_set = 1;
14702 }
14703 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
14704 {
14705 ipv6_set = 1;
14706 }
14707 else
14708 break;
14709 }
14710
14711 if (ipv4_set && ipv6_set)
14712 {
14713 errmsg ("both eid v4 and v6 addresses set");
14714 return -99;
14715 }
14716
14717 if (!ipv4_set && !ipv6_set)
14718 {
14719 errmsg ("eid addresses not set");
14720 return -99;
14721 }
14722
14723 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014724 M (ONE_ADD_DEL_MAP_SERVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014725
14726 mp->is_add = is_add;
14727 if (ipv6_set)
14728 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014729 mp->ip_address.af = 1;
14730 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014731 }
14732 else
14733 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014734 mp->ip_address.af = 0;
14735 clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014736 }
14737
14738 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014739 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014740
14741 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014742 W (ret);
14743 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014744}
14745
Filip Tehlar694396d2017-02-17 14:29:11 +010014746#define api_lisp_add_del_map_server api_one_add_del_map_server
14747
Damjan Marion7cd468a2016-12-19 23:05:39 +010014748static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014749api_one_add_del_map_resolver (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014750{
14751 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014752 vl_api_one_add_del_map_resolver_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014753 u8 is_add = 1;
14754 u8 ipv4_set = 0;
14755 u8 ipv6_set = 0;
14756 ip4_address_t ipv4;
14757 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014758 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014759
14760 /* Parse args required to build the message */
14761 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14762 {
14763 if (unformat (input, "del"))
14764 {
14765 is_add = 0;
14766 }
14767 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
14768 {
14769 ipv4_set = 1;
14770 }
14771 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
14772 {
14773 ipv6_set = 1;
14774 }
14775 else
14776 break;
14777 }
14778
14779 if (ipv4_set && ipv6_set)
14780 {
14781 errmsg ("both eid v4 and v6 addresses set");
14782 return -99;
14783 }
14784
14785 if (!ipv4_set && !ipv6_set)
14786 {
14787 errmsg ("eid addresses not set");
14788 return -99;
14789 }
14790
14791 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014792 M (ONE_ADD_DEL_MAP_RESOLVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014793
14794 mp->is_add = is_add;
14795 if (ipv6_set)
14796 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014797 mp->ip_address.af = 1;
14798 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014799 }
14800 else
14801 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014802 mp->ip_address.af = 0;
14803 clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014804 }
14805
14806 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014807 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014808
14809 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014810 W (ret);
14811 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014812}
14813
Filip Tehlar694396d2017-02-17 14:29:11 +010014814#define api_lisp_add_del_map_resolver api_one_add_del_map_resolver
14815
Damjan Marion7cd468a2016-12-19 23:05:39 +010014816static int
14817api_lisp_gpe_enable_disable (vat_main_t * vam)
14818{
14819 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010014820 vl_api_gpe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014821 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014822 u8 is_enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014823 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014824
14825 /* Parse args required to build the message */
14826 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14827 {
14828 if (unformat (input, "enable"))
14829 {
14830 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014831 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014832 }
14833 else if (unformat (input, "disable"))
14834 {
14835 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014836 is_enable = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014837 }
14838 else
14839 break;
14840 }
14841
14842 if (is_set == 0)
14843 {
14844 errmsg ("Value not set");
14845 return -99;
14846 }
14847
14848 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010014849 M (GPE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014850
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014851 mp->is_enable = is_enable;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014852
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
14861static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014862api_one_rloc_probe_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014863{
14864 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014865 vl_api_one_rloc_probe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014866 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014867 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014868 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014869
14870 /* Parse args required to build the message */
14871 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14872 {
14873 if (unformat (input, "enable"))
14874 {
14875 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014876 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014877 }
14878 else if (unformat (input, "disable"))
14879 is_set = 1;
14880 else
14881 break;
14882 }
14883
14884 if (!is_set)
14885 {
14886 errmsg ("Value not set");
14887 return -99;
14888 }
14889
14890 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014891 M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014892
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014893 mp->is_enable = is_enable;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014894
14895 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014896 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014897
14898 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014899 W (ret);
14900 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014901}
14902
Filip Tehlar694396d2017-02-17 14:29:11 +010014903#define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
14904
Damjan Marion7cd468a2016-12-19 23:05:39 +010014905static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014906api_one_map_register_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014907{
14908 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014909 vl_api_one_map_register_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014910 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014911 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014912 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014913
14914 /* Parse args required to build the message */
14915 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14916 {
14917 if (unformat (input, "enable"))
14918 {
14919 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014920 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014921 }
14922 else if (unformat (input, "disable"))
14923 is_set = 1;
14924 else
14925 break;
14926 }
14927
14928 if (!is_set)
14929 {
14930 errmsg ("Value not set");
14931 return -99;
14932 }
14933
14934 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014935 M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014936
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014937 mp->is_enable = is_enable;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014938
14939 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014940 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014941
14942 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014943 W (ret);
14944 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014945}
14946
Filip Tehlar694396d2017-02-17 14:29:11 +010014947#define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
14948
Damjan Marion7cd468a2016-12-19 23:05:39 +010014949static int
Filip Tehlar694396d2017-02-17 14:29:11 +010014950api_one_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014951{
14952 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010014953 vl_api_one_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014954 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014955 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014956 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014957
14958 /* Parse args required to build the message */
14959 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14960 {
14961 if (unformat (input, "enable"))
14962 {
14963 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014964 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014965 }
14966 else if (unformat (input, "disable"))
14967 {
14968 is_set = 1;
14969 }
14970 else
14971 break;
14972 }
14973
14974 if (!is_set)
14975 {
14976 errmsg ("Value not set");
14977 return -99;
14978 }
14979
14980 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010014981 M (ONE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014982
Jakub Grajciar58db6e12020-01-30 13:26:43 +010014983 mp->is_enable = is_enable;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014984
14985 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014986 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014987
14988 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060014989 W (ret);
14990 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014991}
14992
Filip Tehlar694396d2017-02-17 14:29:11 +010014993#define api_lisp_enable_disable api_one_enable_disable
14994
Damjan Marion7cd468a2016-12-19 23:05:39 +010014995static int
Filip Tehlar0a8840d2017-10-16 05:48:23 -070014996api_one_enable_disable_xtr_mode (vat_main_t * vam)
14997{
14998 unformat_input_t *input = vam->input;
14999 vl_api_one_enable_disable_xtr_mode_t *mp;
15000 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015001 u8 is_enable = 0;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015002 int ret;
15003
15004 /* Parse args required to build the message */
15005 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15006 {
15007 if (unformat (input, "enable"))
15008 {
15009 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015010 is_enable = 1;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015011 }
15012 else if (unformat (input, "disable"))
15013 {
15014 is_set = 1;
15015 }
15016 else
15017 break;
15018 }
15019
15020 if (!is_set)
15021 {
15022 errmsg ("Value not set");
15023 return -99;
15024 }
15025
15026 /* Construct the API message */
15027 M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
15028
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015029 mp->is_enable = is_enable;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015030
15031 /* send it... */
15032 S (mp);
15033
15034 /* Wait for a reply... */
15035 W (ret);
15036 return ret;
15037}
15038
15039static int
15040api_one_show_xtr_mode (vat_main_t * vam)
15041{
15042 vl_api_one_show_xtr_mode_t *mp;
15043 int ret;
15044
15045 /* Construct the API message */
15046 M (ONE_SHOW_XTR_MODE, mp);
15047
15048 /* send it... */
15049 S (mp);
15050
15051 /* Wait for a reply... */
15052 W (ret);
15053 return ret;
15054}
15055
15056static int
15057api_one_enable_disable_pitr_mode (vat_main_t * vam)
15058{
15059 unformat_input_t *input = vam->input;
15060 vl_api_one_enable_disable_pitr_mode_t *mp;
15061 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015062 u8 is_enable = 0;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015063 int ret;
15064
15065 /* Parse args required to build the message */
15066 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15067 {
15068 if (unformat (input, "enable"))
15069 {
15070 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015071 is_enable = 1;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015072 }
15073 else if (unformat (input, "disable"))
15074 {
15075 is_set = 1;
15076 }
15077 else
15078 break;
15079 }
15080
15081 if (!is_set)
15082 {
15083 errmsg ("Value not set");
15084 return -99;
15085 }
15086
15087 /* Construct the API message */
15088 M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
15089
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015090 mp->is_enable = is_enable;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015091
15092 /* send it... */
15093 S (mp);
15094
15095 /* Wait for a reply... */
15096 W (ret);
15097 return ret;
15098}
15099
15100static int
15101api_one_show_pitr_mode (vat_main_t * vam)
15102{
15103 vl_api_one_show_pitr_mode_t *mp;
15104 int ret;
15105
15106 /* Construct the API message */
15107 M (ONE_SHOW_PITR_MODE, mp);
15108
15109 /* send it... */
15110 S (mp);
15111
15112 /* Wait for a reply... */
15113 W (ret);
15114 return ret;
15115}
15116
15117static int
15118api_one_enable_disable_petr_mode (vat_main_t * vam)
15119{
15120 unformat_input_t *input = vam->input;
15121 vl_api_one_enable_disable_petr_mode_t *mp;
15122 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015123 u8 is_enable = 0;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015124 int ret;
15125
15126 /* Parse args required to build the message */
15127 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15128 {
15129 if (unformat (input, "enable"))
15130 {
15131 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015132 is_enable = 1;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015133 }
15134 else if (unformat (input, "disable"))
15135 {
15136 is_set = 1;
15137 }
15138 else
15139 break;
15140 }
15141
15142 if (!is_set)
15143 {
15144 errmsg ("Value not set");
15145 return -99;
15146 }
15147
15148 /* Construct the API message */
15149 M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
15150
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015151 mp->is_enable = is_enable;
Filip Tehlar0a8840d2017-10-16 05:48:23 -070015152
15153 /* send it... */
15154 S (mp);
15155
15156 /* Wait for a reply... */
15157 W (ret);
15158 return ret;
15159}
15160
15161static int
15162api_one_show_petr_mode (vat_main_t * vam)
15163{
15164 vl_api_one_show_petr_mode_t *mp;
15165 int ret;
15166
15167 /* Construct the API message */
15168 M (ONE_SHOW_PETR_MODE, mp);
15169
15170 /* send it... */
15171 S (mp);
15172
15173 /* Wait for a reply... */
15174 W (ret);
15175 return ret;
15176}
15177
15178static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015179api_show_one_map_register_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015180{
Filip Tehlar694396d2017-02-17 14:29:11 +010015181 vl_api_show_one_map_register_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015182 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015183
Filip Tehlar694396d2017-02-17 14:29:11 +010015184 M (SHOW_ONE_MAP_REGISTER_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015185
15186 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015187 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015188
15189 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015190 W (ret);
15191 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015192}
15193
Filip Tehlar694396d2017-02-17 14:29:11 +010015194#define api_show_lisp_map_register_state api_show_one_map_register_state
15195
Damjan Marion7cd468a2016-12-19 23:05:39 +010015196static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015197api_show_one_rloc_probe_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015198{
Filip Tehlar694396d2017-02-17 14:29:11 +010015199 vl_api_show_one_rloc_probe_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015200 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015201
Filip Tehlar694396d2017-02-17 14:29:11 +010015202 M (SHOW_ONE_RLOC_PROBE_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015203
15204 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015205 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015206
15207 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015208 W (ret);
15209 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015210}
15211
Filip Tehlar694396d2017-02-17 14:29:11 +010015212#define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
15213
Damjan Marion7cd468a2016-12-19 23:05:39 +010015214static int
Filip Tehlar05879992017-09-05 15:46:09 +020015215api_one_add_del_ndp_entry (vat_main_t * vam)
15216{
15217 vl_api_one_add_del_ndp_entry_t *mp;
15218 unformat_input_t *input = vam->input;
15219 u8 is_add = 1;
15220 u8 mac_set = 0;
15221 u8 bd_set = 0;
15222 u8 ip_set = 0;
15223 u8 mac[6] = { 0, };
15224 u8 ip6[16] = { 0, };
15225 u32 bd = ~0;
15226 int ret;
15227
15228 /* Parse args required to build the message */
15229 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15230 {
15231 if (unformat (input, "del"))
15232 is_add = 0;
15233 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
15234 mac_set = 1;
15235 else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
15236 ip_set = 1;
15237 else if (unformat (input, "bd %d", &bd))
15238 bd_set = 1;
15239 else
15240 {
15241 errmsg ("parse error '%U'", format_unformat_error, input);
15242 return -99;
15243 }
15244 }
15245
15246 if (!bd_set || !ip_set || (!mac_set && is_add))
15247 {
15248 errmsg ("Missing BD, IP or MAC!");
15249 return -99;
15250 }
15251
15252 M (ONE_ADD_DEL_NDP_ENTRY, mp);
15253 mp->is_add = is_add;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015254 clib_memcpy (&mp->entry.mac, mac, 6);
Filip Tehlar05879992017-09-05 15:46:09 +020015255 mp->bd = clib_host_to_net_u32 (bd);
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015256 clib_memcpy (&mp->entry.ip6, ip6, sizeof (mp->entry.ip6));
Filip Tehlar05879992017-09-05 15:46:09 +020015257
15258 /* send */
15259 S (mp);
15260
15261 /* wait for reply */
15262 W (ret);
15263 return ret;
15264}
15265
15266static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020015267api_one_add_del_l2_arp_entry (vat_main_t * vam)
15268{
15269 vl_api_one_add_del_l2_arp_entry_t *mp;
15270 unformat_input_t *input = vam->input;
15271 u8 is_add = 1;
15272 u8 mac_set = 0;
15273 u8 bd_set = 0;
15274 u8 ip_set = 0;
15275 u8 mac[6] = { 0, };
15276 u32 ip4 = 0, bd = ~0;
15277 int ret;
15278
15279 /* Parse args required to build the message */
15280 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15281 {
15282 if (unformat (input, "del"))
15283 is_add = 0;
15284 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
15285 mac_set = 1;
15286 else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
15287 ip_set = 1;
15288 else if (unformat (input, "bd %d", &bd))
15289 bd_set = 1;
15290 else
15291 {
15292 errmsg ("parse error '%U'", format_unformat_error, input);
15293 return -99;
15294 }
15295 }
15296
15297 if (!bd_set || !ip_set || (!mac_set && is_add))
15298 {
15299 errmsg ("Missing BD, IP or MAC!");
15300 return -99;
15301 }
15302
15303 M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
15304 mp->is_add = is_add;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015305 clib_memcpy (&mp->entry.mac, mac, 6);
Filip Tehlard5a65db2017-05-17 17:21:10 +020015306 mp->bd = clib_host_to_net_u32 (bd);
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015307 clib_memcpy (mp->entry.ip4, &ip4, sizeof (mp->entry.ip4));
Filip Tehlard5a65db2017-05-17 17:21:10 +020015308
15309 /* send */
15310 S (mp);
15311
15312 /* wait for reply */
15313 W (ret);
15314 return ret;
15315}
15316
15317static int
Filip Tehlar05879992017-09-05 15:46:09 +020015318api_one_ndp_bd_get (vat_main_t * vam)
15319{
15320 vl_api_one_ndp_bd_get_t *mp;
15321 int ret;
15322
15323 M (ONE_NDP_BD_GET, mp);
15324
15325 /* send */
15326 S (mp);
15327
15328 /* wait for reply */
15329 W (ret);
15330 return ret;
15331}
15332
15333static int
15334api_one_ndp_entries_get (vat_main_t * vam)
15335{
15336 vl_api_one_ndp_entries_get_t *mp;
15337 unformat_input_t *input = vam->input;
15338 u8 bd_set = 0;
15339 u32 bd = ~0;
15340 int ret;
15341
15342 /* Parse args required to build the message */
15343 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15344 {
15345 if (unformat (input, "bd %d", &bd))
15346 bd_set = 1;
15347 else
15348 {
15349 errmsg ("parse error '%U'", format_unformat_error, input);
15350 return -99;
15351 }
15352 }
15353
15354 if (!bd_set)
15355 {
15356 errmsg ("Expected bridge domain!");
15357 return -99;
15358 }
15359
15360 M (ONE_NDP_ENTRIES_GET, mp);
15361 mp->bd = clib_host_to_net_u32 (bd);
15362
15363 /* send */
15364 S (mp);
15365
15366 /* wait for reply */
15367 W (ret);
15368 return ret;
15369}
15370
15371static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020015372api_one_l2_arp_bd_get (vat_main_t * vam)
15373{
15374 vl_api_one_l2_arp_bd_get_t *mp;
15375 int ret;
15376
15377 M (ONE_L2_ARP_BD_GET, mp);
15378
15379 /* send */
15380 S (mp);
15381
15382 /* wait for reply */
15383 W (ret);
15384 return ret;
15385}
15386
15387static int
15388api_one_l2_arp_entries_get (vat_main_t * vam)
15389{
15390 vl_api_one_l2_arp_entries_get_t *mp;
15391 unformat_input_t *input = vam->input;
15392 u8 bd_set = 0;
15393 u32 bd = ~0;
15394 int ret;
15395
15396 /* Parse args required to build the message */
15397 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15398 {
15399 if (unformat (input, "bd %d", &bd))
15400 bd_set = 1;
15401 else
15402 {
15403 errmsg ("parse error '%U'", format_unformat_error, input);
15404 return -99;
15405 }
15406 }
15407
15408 if (!bd_set)
15409 {
15410 errmsg ("Expected bridge domain!");
15411 return -99;
15412 }
15413
15414 M (ONE_L2_ARP_ENTRIES_GET, mp);
15415 mp->bd = clib_host_to_net_u32 (bd);
15416
15417 /* send */
15418 S (mp);
15419
15420 /* wait for reply */
15421 W (ret);
15422 return ret;
15423}
15424
15425static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010015426api_one_stats_enable_disable (vat_main_t * vam)
15427{
15428 vl_api_one_stats_enable_disable_t *mp;
15429 unformat_input_t *input = vam->input;
15430 u8 is_set = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015431 u8 is_enable = 0;
Filip Tehlar4868ff62017-03-09 16:48:39 +010015432 int ret;
15433
15434 /* Parse args required to build the message */
15435 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15436 {
15437 if (unformat (input, "enable"))
15438 {
15439 is_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015440 is_enable = 1;
Filip Tehlar4868ff62017-03-09 16:48:39 +010015441 }
15442 else if (unformat (input, "disable"))
15443 {
15444 is_set = 1;
15445 }
15446 else
15447 break;
15448 }
15449
15450 if (!is_set)
15451 {
15452 errmsg ("Value not set");
15453 return -99;
15454 }
15455
15456 M (ONE_STATS_ENABLE_DISABLE, mp);
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015457 mp->is_enable = is_enable;
Filip Tehlar4868ff62017-03-09 16:48:39 +010015458
15459 /* send */
15460 S (mp);
15461
15462 /* wait for reply */
15463 W (ret);
15464 return ret;
15465}
15466
15467static int
15468api_show_one_stats_enable_disable (vat_main_t * vam)
15469{
15470 vl_api_show_one_stats_enable_disable_t *mp;
15471 int ret;
15472
15473 M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
15474
15475 /* send */
15476 S (mp);
15477
15478 /* wait for reply */
15479 W (ret);
15480 return ret;
15481}
15482
15483static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015484api_show_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015485{
Filip Tehlar694396d2017-02-17 14:29:11 +010015486 vl_api_show_one_map_request_mode_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015487 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015488
Filip Tehlar694396d2017-02-17 14:29:11 +010015489 M (SHOW_ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015490
15491 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015492 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015493
15494 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015495 W (ret);
15496 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015497}
15498
Filip Tehlar694396d2017-02-17 14:29:11 +010015499#define api_show_lisp_map_request_mode api_show_one_map_request_mode
15500
Damjan Marion7cd468a2016-12-19 23:05:39 +010015501static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015502api_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015503{
Damjan Marion7cd468a2016-12-19 23:05:39 +010015504 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015505 vl_api_one_map_request_mode_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015506 u8 mode = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015507 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015508
15509 /* Parse args required to build the message */
15510 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15511 {
15512 if (unformat (input, "dst-only"))
15513 mode = 0;
15514 else if (unformat (input, "src-dst"))
15515 mode = 1;
15516 else
15517 {
15518 errmsg ("parse error '%U'", format_unformat_error, input);
15519 return -99;
15520 }
15521 }
15522
Filip Tehlar694396d2017-02-17 14:29:11 +010015523 M (ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015524
15525 mp->mode = mode;
15526
15527 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015528 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015529
15530 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015531 W (ret);
15532 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015533}
15534
Filip Tehlar694396d2017-02-17 14:29:11 +010015535#define api_lisp_map_request_mode api_one_map_request_mode
15536
Damjan Marion7cd468a2016-12-19 23:05:39 +010015537/**
Filip Tehlar694396d2017-02-17 14:29:11 +010015538 * Enable/disable ONE proxy ITR.
Damjan Marion7cd468a2016-12-19 23:05:39 +010015539 *
15540 * @param vam vpp API test context
15541 * @return return code
15542 */
15543static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015544api_one_pitr_set_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015545{
Damjan Marion7cd468a2016-12-19 23:05:39 +010015546 u8 ls_name_set = 0;
15547 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015548 vl_api_one_pitr_set_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015549 u8 is_add = 1;
15550 u8 *ls_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015551 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015552
15553 /* Parse args required to build the message */
15554 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15555 {
15556 if (unformat (input, "del"))
15557 is_add = 0;
15558 else if (unformat (input, "locator-set %s", &ls_name))
15559 ls_name_set = 1;
15560 else
15561 {
15562 errmsg ("parse error '%U'", format_unformat_error, input);
15563 return -99;
15564 }
15565 }
15566
15567 if (!ls_name_set)
15568 {
15569 errmsg ("locator-set name not set!");
15570 return -99;
15571 }
15572
Filip Tehlar694396d2017-02-17 14:29:11 +010015573 M (ONE_PITR_SET_LOCATOR_SET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015574
15575 mp->is_add = is_add;
15576 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
15577 vec_free (ls_name);
15578
15579 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015580 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015581
15582 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015583 W (ret);
15584 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015585}
15586
Filip Tehlar694396d2017-02-17 14:29:11 +010015587#define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
15588
Damjan Marion7cd468a2016-12-19 23:05:39 +010015589static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015590api_one_nsh_set_locator_set (vat_main_t * vam)
15591{
15592 u8 ls_name_set = 0;
15593 unformat_input_t *input = vam->input;
15594 vl_api_one_nsh_set_locator_set_t *mp;
15595 u8 is_add = 1;
15596 u8 *ls_name = 0;
15597 int ret;
15598
15599 /* Parse args required to build the message */
15600 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15601 {
15602 if (unformat (input, "del"))
15603 is_add = 0;
15604 else if (unformat (input, "ls %s", &ls_name))
15605 ls_name_set = 1;
15606 else
15607 {
15608 errmsg ("parse error '%U'", format_unformat_error, input);
15609 return -99;
15610 }
15611 }
15612
15613 if (!ls_name_set && is_add)
15614 {
15615 errmsg ("locator-set name not set!");
15616 return -99;
15617 }
15618
15619 M (ONE_NSH_SET_LOCATOR_SET, mp);
15620
15621 mp->is_add = is_add;
15622 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
15623 vec_free (ls_name);
15624
15625 /* send */
15626 S (mp);
15627
15628 /* wait for reply */
15629 W (ret);
15630 return ret;
15631}
15632
15633static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015634api_show_one_pitr (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015635{
Filip Tehlar694396d2017-02-17 14:29:11 +010015636 vl_api_show_one_pitr_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015637 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015638
15639 if (!vam->json_output)
15640 {
15641 print (vam->ofp, "%=20s", "lisp status:");
15642 }
15643
Filip Tehlar694396d2017-02-17 14:29:11 +010015644 M (SHOW_ONE_PITR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015645 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015646 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015647
15648 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015649 W (ret);
15650 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015651}
15652
Filip Tehlar694396d2017-02-17 14:29:11 +010015653#define api_show_lisp_pitr api_show_one_pitr
15654
Filip Tehlar67a99f82017-03-10 13:18:02 +010015655static int
15656api_one_use_petr (vat_main_t * vam)
15657{
15658 unformat_input_t *input = vam->input;
15659 vl_api_one_use_petr_t *mp;
15660 u8 is_add = 0;
15661 ip_address_t ip;
15662 int ret;
15663
Dave Barachb7b92992018-10-17 10:38:51 -040015664 clib_memset (&ip, 0, sizeof (ip));
Filip Tehlar67a99f82017-03-10 13:18:02 +010015665
15666 /* Parse args required to build the message */
15667 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15668 {
15669 if (unformat (input, "disable"))
15670 is_add = 0;
15671 else
15672 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
15673 {
15674 is_add = 1;
Neale Rannsea93e482019-11-12 17:16:47 +000015675 ip_addr_version (&ip) = AF_IP4;
Filip Tehlar67a99f82017-03-10 13:18:02 +010015676 }
15677 else
15678 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
15679 {
15680 is_add = 1;
Neale Rannsea93e482019-11-12 17:16:47 +000015681 ip_addr_version (&ip) = AF_IP6;
Filip Tehlar67a99f82017-03-10 13:18:02 +010015682 }
15683 else
15684 {
15685 errmsg ("parse error '%U'", format_unformat_error, input);
15686 return -99;
15687 }
15688 }
15689
15690 M (ONE_USE_PETR, mp);
15691
15692 mp->is_add = is_add;
15693 if (is_add)
15694 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015695 mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
15696 if (mp->ip_address.af)
15697 clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
Filip Tehlar67a99f82017-03-10 13:18:02 +010015698 else
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015699 clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
Filip Tehlar67a99f82017-03-10 13:18:02 +010015700 }
15701
15702 /* send */
15703 S (mp);
15704
15705 /* wait for reply */
15706 W (ret);
15707 return ret;
15708}
15709
15710#define api_lisp_use_petr api_one_use_petr
15711
15712static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020015713api_show_one_nsh_mapping (vat_main_t * vam)
15714{
15715 vl_api_show_one_use_petr_t *mp;
15716 int ret;
15717
15718 if (!vam->json_output)
15719 {
15720 print (vam->ofp, "%=20s", "local ONE NSH mapping:");
15721 }
15722
15723 M (SHOW_ONE_NSH_MAPPING, mp);
15724 /* send it... */
15725 S (mp);
15726
15727 /* Wait for a reply... */
15728 W (ret);
15729 return ret;
15730}
15731
15732static int
Filip Tehlar67a99f82017-03-10 13:18:02 +010015733api_show_one_use_petr (vat_main_t * vam)
15734{
15735 vl_api_show_one_use_petr_t *mp;
15736 int ret;
15737
15738 if (!vam->json_output)
15739 {
15740 print (vam->ofp, "%=20s", "Proxy-ETR status:");
15741 }
15742
15743 M (SHOW_ONE_USE_PETR, mp);
15744 /* send it... */
15745 S (mp);
15746
15747 /* Wait for a reply... */
15748 W (ret);
15749 return ret;
15750}
15751
15752#define api_show_lisp_use_petr api_show_one_use_petr
15753
Damjan Marion7cd468a2016-12-19 23:05:39 +010015754/**
15755 * Add/delete mapping between vni and vrf
15756 */
15757static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015758api_one_eid_table_add_del_map (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015759{
Damjan Marion7cd468a2016-12-19 23:05:39 +010015760 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015761 vl_api_one_eid_table_add_del_map_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015762 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
15763 u32 vni, vrf, bd_index;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015764 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015765
15766 /* Parse args required to build the message */
15767 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15768 {
15769 if (unformat (input, "del"))
15770 is_add = 0;
15771 else if (unformat (input, "vrf %d", &vrf))
15772 vrf_set = 1;
15773 else if (unformat (input, "bd_index %d", &bd_index))
15774 bd_index_set = 1;
15775 else if (unformat (input, "vni %d", &vni))
15776 vni_set = 1;
15777 else
15778 break;
15779 }
15780
15781 if (!vni_set || (!vrf_set && !bd_index_set))
15782 {
15783 errmsg ("missing arguments!");
15784 return -99;
15785 }
15786
15787 if (vrf_set && bd_index_set)
15788 {
15789 errmsg ("error: both vrf and bd entered!");
15790 return -99;
15791 }
15792
Filip Tehlar694396d2017-02-17 14:29:11 +010015793 M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015794
15795 mp->is_add = is_add;
15796 mp->vni = htonl (vni);
15797 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
15798 mp->is_l2 = bd_index_set;
15799
15800 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015801 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015802
15803 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015804 W (ret);
15805 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015806}
15807
Filip Tehlar694396d2017-02-17 14:29:11 +010015808#define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
15809
Damjan Marion7cd468a2016-12-19 23:05:39 +010015810uword
15811unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
15812{
15813 u32 *action = va_arg (*args, u32 *);
15814 u8 *s = 0;
15815
15816 if (unformat (input, "%s", &s))
15817 {
15818 if (!strcmp ((char *) s, "no-action"))
15819 action[0] = 0;
15820 else if (!strcmp ((char *) s, "natively-forward"))
15821 action[0] = 1;
15822 else if (!strcmp ((char *) s, "send-map-request"))
15823 action[0] = 2;
15824 else if (!strcmp ((char *) s, "drop"))
15825 action[0] = 3;
15826 else
15827 {
15828 clib_warning ("invalid action: '%s'", s);
15829 action[0] = 3;
15830 }
15831 }
15832 else
15833 return 0;
15834
15835 vec_free (s);
15836 return 1;
15837}
15838
15839/**
Filip Tehlar694396d2017-02-17 14:29:11 +010015840 * Add/del remote mapping to/from ONE control plane
Damjan Marion7cd468a2016-12-19 23:05:39 +010015841 *
15842 * @param vam vpp API test context
15843 * @return return code
15844 */
15845static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015846api_one_add_del_remote_mapping (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015847{
15848 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015849 vl_api_one_add_del_remote_mapping_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015850 u32 vni = 0;
15851 lisp_eid_vat_t _eid, *eid = &_eid;
15852 lisp_eid_vat_t _seid, *seid = &_seid;
15853 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
15854 u32 action = ~0, p, w, data_len;
15855 ip4_address_t rloc4;
15856 ip6_address_t rloc6;
Filip Tehlar05a057b2017-02-01 08:50:31 +010015857 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015858 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015859
Dave Barachb7b92992018-10-17 10:38:51 -040015860 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015861
15862 /* Parse args required to build the message */
15863 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15864 {
15865 if (unformat (input, "del-all"))
15866 {
15867 del_all = 1;
15868 }
15869 else if (unformat (input, "del"))
15870 {
15871 is_add = 0;
15872 }
15873 else if (unformat (input, "add"))
15874 {
15875 is_add = 1;
15876 }
15877 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
15878 {
15879 eid_set = 1;
15880 }
15881 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
15882 {
15883 seid_set = 1;
15884 }
15885 else if (unformat (input, "vni %d", &vni))
15886 {
15887 ;
15888 }
15889 else if (unformat (input, "p %d w %d", &p, &w))
15890 {
15891 if (!curr_rloc)
15892 {
15893 errmsg ("No RLOC configured for setting priority/weight!");
15894 return -99;
15895 }
15896 curr_rloc->priority = p;
15897 curr_rloc->weight = w;
15898 }
15899 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
15900 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015901 rloc.ip_address.af = 0;
15902 clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015903 vec_add1 (rlocs, rloc);
15904 curr_rloc = &rlocs[vec_len (rlocs) - 1];
15905 }
15906 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
15907 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015908 rloc.ip_address.af = 1;
15909 clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015910 vec_add1 (rlocs, rloc);
15911 curr_rloc = &rlocs[vec_len (rlocs) - 1];
15912 }
15913 else if (unformat (input, "action %U",
15914 unformat_negative_mapping_action, &action))
15915 {
15916 ;
15917 }
15918 else
15919 {
15920 clib_warning ("parse error '%U'", format_unformat_error, input);
15921 return -99;
15922 }
15923 }
15924
15925 if (0 == eid_set)
15926 {
15927 errmsg ("missing params!");
15928 return -99;
15929 }
15930
15931 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
15932 {
15933 errmsg ("no action set for negative map-reply!");
15934 return -99;
15935 }
15936
Filip Tehlar05a057b2017-02-01 08:50:31 +010015937 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015938
Filip Tehlar694396d2017-02-17 14:29:11 +010015939 M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015940 mp->is_add = is_add;
15941 mp->vni = htonl (vni);
15942 mp->action = (u8) action;
15943 mp->is_src_dst = seid_set;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015944 mp->del_all = del_all;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015945 lisp_eid_put_vat (&mp->deid, eid);
15946 lisp_eid_put_vat (&mp->seid, seid);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015947
15948 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
15949 clib_memcpy (mp->rlocs, rlocs, data_len);
15950 vec_free (rlocs);
15951
15952 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015953 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015954
15955 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060015956 W (ret);
15957 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015958}
15959
Filip Tehlar694396d2017-02-17 14:29:11 +010015960#define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
15961
Damjan Marion7cd468a2016-12-19 23:05:39 +010015962/**
Filip Tehlar694396d2017-02-17 14:29:11 +010015963 * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010015964 * forwarding entries in data-plane accordingly.
15965 *
15966 * @param vam vpp API test context
15967 * @return return code
15968 */
15969static int
Filip Tehlar694396d2017-02-17 14:29:11 +010015970api_one_add_del_adjacency (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015971{
15972 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010015973 vl_api_one_add_del_adjacency_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015974 u32 vni = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015975 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015976 int ret;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015977 lisp_eid_vat_t leid, reid;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015978
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015979 leid.type = reid.type = (u8) ~ 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015980
15981 /* Parse args required to build the message */
15982 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15983 {
15984 if (unformat (input, "del"))
15985 {
15986 is_add = 0;
15987 }
15988 else if (unformat (input, "add"))
15989 {
15990 is_add = 1;
15991 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015992 else if (unformat (input, "reid %U/%d", unformat_ip46_address,
15993 &reid.addr.ip, &reid.len))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015994 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015995 reid.type = 0; /* ipv4 */
Damjan Marion7cd468a2016-12-19 23:05:39 +010015996 }
15997 else if (unformat (input, "reid %U", unformat_ethernet_address,
Jakub Grajciar58db6e12020-01-30 13:26:43 +010015998 &reid.addr.mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +010015999 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016000 reid.type = 1; /* mac */
Damjan Marion7cd468a2016-12-19 23:05:39 +010016001 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016002 else if (unformat (input, "leid %U/%d", unformat_ip46_address,
16003 &leid.addr.ip, &leid.len))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016004 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016005 leid.type = 0; /* ipv4 */
Damjan Marion7cd468a2016-12-19 23:05:39 +010016006 }
16007 else if (unformat (input, "leid %U", unformat_ethernet_address,
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016008 &leid.addr.mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016009 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016010 leid.type = 1; /* mac */
Damjan Marion7cd468a2016-12-19 23:05:39 +010016011 }
16012 else if (unformat (input, "vni %d", &vni))
16013 {
16014 ;
16015 }
16016 else
16017 {
16018 errmsg ("parse error '%U'", format_unformat_error, input);
16019 return -99;
16020 }
16021 }
16022
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016023 if ((u8) ~ 0 == reid.type)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016024 {
16025 errmsg ("missing params!");
16026 return -99;
16027 }
16028
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016029 if (leid.type != reid.type)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016030 {
16031 errmsg ("remote and local EIDs are of different types!");
16032 return -99;
16033 }
16034
Filip Tehlar694396d2017-02-17 14:29:11 +010016035 M (ONE_ADD_DEL_ADJACENCY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016036 mp->is_add = is_add;
16037 mp->vni = htonl (vni);
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016038 lisp_eid_put_vat (&mp->leid, &leid);
16039 lisp_eid_put_vat (&mp->reid, &reid);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016040
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
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016103 mp->is_vxlan = mode;
Filip Tehlar3e7b56932017-02-21 18:28:34 +010016104
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 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016647 int ret;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016648 u32 vni, t = 0;
16649 lisp_eid_vat_t eid;
16650 u8 eid_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016651
16652 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16653 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016654 if (unformat
16655 (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016656 {
16657 eid_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016658 eid.type = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016659 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016660 else
16661 if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016662 {
16663 eid_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016664 eid.type = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016665 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016666 else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016667 {
16668 eid_set = 1;
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016669 eid.type = 2;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016670 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010016671 else if (unformat (i, "vni %d", &t))
16672 {
16673 vni = t;
16674 }
16675 else if (unformat (i, "local"))
16676 {
16677 filter = 1;
16678 }
16679 else if (unformat (i, "remote"))
16680 {
16681 filter = 2;
16682 }
16683 else
16684 {
16685 errmsg ("parse error '%U'", format_unformat_error, i);
16686 return -99;
16687 }
16688 }
16689
16690 if (!vam->json_output)
16691 {
16692 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
16693 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
16694 }
16695
Filip Tehlar694396d2017-02-17 14:29:11 +010016696 M (ONE_EID_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016697
16698 mp->filter = filter;
16699 if (eid_set)
16700 {
16701 mp->eid_set = 1;
16702 mp->vni = htonl (vni);
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016703 lisp_eid_put_vat (&mp->eid, &eid);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016704 }
16705
16706 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016707 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016708
16709 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040016710 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016711 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016712
16713 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016714 W (ret);
16715 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016716}
16717
Filip Tehlar694396d2017-02-17 14:29:11 +010016718#define api_lisp_eid_table_dump api_one_eid_table_dump
16719
Damjan Marion7cd468a2016-12-19 23:05:39 +010016720static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016721api_lisp_gpe_fwd_entries_get (vat_main_t * vam)
16722{
16723 unformat_input_t *i = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010016724 vl_api_gpe_fwd_entries_get_t *mp;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016725 u8 vni_set = 0;
16726 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016727 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016728
16729 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16730 {
16731 if (unformat (i, "vni %d", &vni))
16732 {
16733 vni_set = 1;
16734 }
16735 else
16736 {
16737 errmsg ("parse error '%U'", format_unformat_error, i);
16738 return -99;
16739 }
16740 }
16741
16742 if (!vni_set)
16743 {
16744 errmsg ("vni not set!");
16745 return -99;
16746 }
16747
16748 if (!vam->json_output)
16749 {
16750 print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table",
16751 "leid", "reid");
16752 }
16753
Filip Tehlar82786c42017-02-20 15:20:37 +010016754 M (GPE_FWD_ENTRIES_GET, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016755 mp->vni = clib_host_to_net_u32 (vni);
16756
16757 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016758 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016759
16760 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016761 W (ret);
16762 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016763}
16764
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016765#define vl_api_gpe_native_fwd_rpaths_get_reply_t_endian vl_noop_handler
16766#define vl_api_gpe_native_fwd_rpaths_get_reply_t_print vl_noop_handler
Filip Tehlar0eb874e2017-05-18 14:23:32 +020016767#define vl_api_gpe_fwd_entry_vnis_get_reply_t_endian vl_noop_handler
16768#define vl_api_gpe_fwd_entry_vnis_get_reply_t_print vl_noop_handler
Filip Tehlar82786c42017-02-20 15:20:37 +010016769#define vl_api_gpe_fwd_entries_get_reply_t_endian vl_noop_handler
16770#define vl_api_gpe_fwd_entries_get_reply_t_print vl_noop_handler
16771#define vl_api_gpe_fwd_entry_path_details_t_endian vl_noop_handler
16772#define vl_api_gpe_fwd_entry_path_details_t_print vl_noop_handler
Filip Tehlar5fae99c2017-01-18 12:57:37 +010016773
16774static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016775api_one_adjacencies_get (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016776{
16777 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016778 vl_api_one_adjacencies_get_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016779 u8 vni_set = 0;
16780 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016781 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016782
16783 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16784 {
16785 if (unformat (i, "vni %d", &vni))
16786 {
16787 vni_set = 1;
16788 }
16789 else
16790 {
16791 errmsg ("parse error '%U'", format_unformat_error, i);
16792 return -99;
16793 }
16794 }
16795
16796 if (!vni_set)
16797 {
16798 errmsg ("vni not set!");
16799 return -99;
16800 }
16801
16802 if (!vam->json_output)
16803 {
16804 print (vam->ofp, "%s %40s", "leid", "reid");
16805 }
16806
Filip Tehlar694396d2017-02-17 14:29:11 +010016807 M (ONE_ADJACENCIES_GET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016808 mp->vni = clib_host_to_net_u32 (vni);
16809
16810 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016811 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016812
16813 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016814 W (ret);
16815 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016816}
16817
Filip Tehlar694396d2017-02-17 14:29:11 +010016818#define api_lisp_adjacencies_get api_one_adjacencies_get
16819
Damjan Marion7cd468a2016-12-19 23:05:39 +010016820static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016821api_gpe_native_fwd_rpaths_get (vat_main_t * vam)
16822{
16823 unformat_input_t *i = vam->input;
16824 vl_api_gpe_native_fwd_rpaths_get_t *mp;
16825 int ret;
16826 u8 ip_family_set = 0, is_ip4 = 1;
16827
16828 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16829 {
16830 if (unformat (i, "ip4"))
16831 {
16832 ip_family_set = 1;
16833 is_ip4 = 1;
16834 }
16835 else if (unformat (i, "ip6"))
16836 {
16837 ip_family_set = 1;
16838 is_ip4 = 0;
16839 }
16840 else
16841 {
16842 errmsg ("parse error '%U'", format_unformat_error, i);
16843 return -99;
16844 }
16845 }
16846
16847 if (!ip_family_set)
16848 {
16849 errmsg ("ip family not set!");
16850 return -99;
16851 }
16852
16853 M (GPE_NATIVE_FWD_RPATHS_GET, mp);
16854 mp->is_ip4 = is_ip4;
16855
16856 /* send it... */
16857 S (mp);
16858
16859 /* Wait for a reply... */
16860 W (ret);
16861 return ret;
16862}
16863
16864static int
Filip Tehlar0eb874e2017-05-18 14:23:32 +020016865api_gpe_fwd_entry_vnis_get (vat_main_t * vam)
16866{
16867 vl_api_gpe_fwd_entry_vnis_get_t *mp;
16868 int ret;
16869
16870 if (!vam->json_output)
16871 {
16872 print (vam->ofp, "VNIs");
16873 }
16874
16875 M (GPE_FWD_ENTRY_VNIS_GET, mp);
16876
16877 /* send it... */
16878 S (mp);
16879
16880 /* Wait for a reply... */
16881 W (ret);
16882 return ret;
16883}
16884
16885static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016886api_gpe_add_del_native_fwd_rpath (vat_main_t * vam)
16887{
16888 unformat_input_t *i = vam->input;
16889 vl_api_gpe_add_del_native_fwd_rpath_t *mp;
16890 int ret = 0;
16891 u8 is_add = 1, ip_set = 0, is_ip4 = 1;
16892 struct in_addr ip4;
16893 struct in6_addr ip6;
16894 u32 table_id = 0, nh_sw_if_index = ~0;
16895
Dave Barachb7b92992018-10-17 10:38:51 -040016896 clib_memset (&ip4, 0, sizeof (ip4));
16897 clib_memset (&ip6, 0, sizeof (ip6));
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016898
16899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16900 {
16901 if (unformat (i, "del"))
16902 is_add = 0;
16903 else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4,
16904 api_unformat_sw_if_index, vam, &nh_sw_if_index))
16905 {
16906 ip_set = 1;
16907 is_ip4 = 1;
16908 }
16909 else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6,
16910 api_unformat_sw_if_index, vam, &nh_sw_if_index))
16911 {
16912 ip_set = 1;
16913 is_ip4 = 0;
16914 }
16915 else if (unformat (i, "via %U", unformat_ip4_address, &ip4))
16916 {
16917 ip_set = 1;
16918 is_ip4 = 1;
16919 nh_sw_if_index = ~0;
16920 }
16921 else if (unformat (i, "via %U", unformat_ip6_address, &ip6))
16922 {
16923 ip_set = 1;
16924 is_ip4 = 0;
16925 nh_sw_if_index = ~0;
16926 }
16927 else if (unformat (i, "table %d", &table_id))
16928 ;
16929 else
16930 {
16931 errmsg ("parse error '%U'", format_unformat_error, i);
16932 return -99;
16933 }
16934 }
16935
16936 if (!ip_set)
16937 {
16938 errmsg ("nh addr not set!");
16939 return -99;
16940 }
16941
16942 M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp);
16943 mp->is_add = is_add;
16944 mp->table_id = clib_host_to_net_u32 (table_id);
16945 mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index);
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016946 mp->nh_addr.af = is_ip4 ? 0 : 1;
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016947 if (is_ip4)
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016948 clib_memcpy (mp->nh_addr.un.ip4, &ip4, sizeof (ip4));
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016949 else
Jakub Grajciar58db6e12020-01-30 13:26:43 +010016950 clib_memcpy (mp->nh_addr.un.ip6, &ip6, sizeof (ip6));
Filip Tehlarb4243aa2017-06-14 14:39:42 +020016951
16952 /* send it... */
16953 S (mp);
16954
16955 /* Wait for a reply... */
16956 W (ret);
16957 return ret;
16958}
16959
16960static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016961api_one_map_server_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016962{
Filip Tehlar694396d2017-02-17 14:29:11 +010016963 vl_api_one_map_server_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016964 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016965 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016966
16967 if (!vam->json_output)
16968 {
16969 print (vam->ofp, "%=20s", "Map server");
16970 }
16971
Filip Tehlar694396d2017-02-17 14:29:11 +010016972 M (ONE_MAP_SERVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016973 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016974 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016975
16976 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040016977 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016978 S (mp_ping);
16979
Damjan Marion7cd468a2016-12-19 23:05:39 +010016980 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016981 W (ret);
16982 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016983}
16984
Filip Tehlar694396d2017-02-17 14:29:11 +010016985#define api_lisp_map_server_dump api_one_map_server_dump
16986
Damjan Marion7cd468a2016-12-19 23:05:39 +010016987static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016988api_one_map_resolver_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016989{
Filip Tehlar694396d2017-02-17 14:29:11 +010016990 vl_api_one_map_resolver_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060016991 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016992 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016993
16994 if (!vam->json_output)
16995 {
16996 print (vam->ofp, "%=20s", "Map resolver");
16997 }
16998
Filip Tehlar694396d2017-02-17 14:29:11 +010016999 M (ONE_MAP_RESOLVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017000 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017001 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017002
17003 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017004 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017005 S (mp_ping);
17006
Damjan Marion7cd468a2016-12-19 23:05:39 +010017007 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017008 W (ret);
17009 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017010}
17011
Filip Tehlar694396d2017-02-17 14:29:11 +010017012#define api_lisp_map_resolver_dump api_one_map_resolver_dump
17013
Damjan Marion7cd468a2016-12-19 23:05:39 +010017014static int
Filip Tehlar21511912017-04-07 10:41:42 +020017015api_one_stats_flush (vat_main_t * vam)
17016{
17017 vl_api_one_stats_flush_t *mp;
17018 int ret = 0;
17019
17020 M (ONE_STATS_FLUSH, mp);
17021 S (mp);
17022 W (ret);
17023 return ret;
17024}
17025
17026static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010017027api_one_stats_dump (vat_main_t * vam)
17028{
17029 vl_api_one_stats_dump_t *mp;
17030 vl_api_control_ping_t *mp_ping;
17031 int ret;
17032
17033 M (ONE_STATS_DUMP, mp);
17034 /* send it... */
17035 S (mp);
17036
17037 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017038 MPING (CONTROL_PING, mp_ping);
Filip Tehlar4868ff62017-03-09 16:48:39 +010017039 S (mp_ping);
17040
17041 /* Wait for a reply... */
17042 W (ret);
17043 return ret;
17044}
17045
17046static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017047api_show_one_status (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017048{
Filip Tehlar694396d2017-02-17 14:29:11 +010017049 vl_api_show_one_status_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017050 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017051
17052 if (!vam->json_output)
17053 {
Filip Tehlar694396d2017-02-17 14:29:11 +010017054 print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
Damjan Marion7cd468a2016-12-19 23:05:39 +010017055 }
17056
Filip Tehlar694396d2017-02-17 14:29:11 +010017057 M (SHOW_ONE_STATUS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017058 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017059 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017060 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017061 W (ret);
17062 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017063}
17064
Filip Tehlar694396d2017-02-17 14:29:11 +010017065#define api_show_lisp_status api_show_one_status
17066
Damjan Marion7cd468a2016-12-19 23:05:39 +010017067static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017068api_lisp_gpe_fwd_entry_path_dump (vat_main_t * vam)
17069{
Filip Tehlar82786c42017-02-20 15:20:37 +010017070 vl_api_gpe_fwd_entry_path_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017071 vl_api_control_ping_t *mp_ping;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017072 unformat_input_t *i = vam->input;
17073 u32 fwd_entry_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017074 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017075
17076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17077 {
17078 if (unformat (i, "index %d", &fwd_entry_index))
17079 ;
17080 else
17081 break;
17082 }
17083
17084 if (~0 == fwd_entry_index)
17085 {
17086 errmsg ("no index specified!");
17087 return -99;
17088 }
17089
17090 if (!vam->json_output)
17091 {
17092 print (vam->ofp, "first line");
17093 }
17094
Filip Tehlar82786c42017-02-20 15:20:37 +010017095 M (GPE_FWD_ENTRY_PATH_DUMP, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017096
17097 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017098 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017099 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017100 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017101 S (mp_ping);
17102
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017103 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017104 W (ret);
17105 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010017106}
17107
17108static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017109api_one_get_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017110{
Filip Tehlar694396d2017-02-17 14:29:11 +010017111 vl_api_one_get_map_request_itr_rlocs_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017112 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017113
17114 if (!vam->json_output)
17115 {
17116 print (vam->ofp, "%=20s", "itr-rlocs:");
17117 }
17118
Filip Tehlar694396d2017-02-17 14:29:11 +010017119 M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017120 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017121 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017122 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017123 W (ret);
17124 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017125}
17126
Filip Tehlar694396d2017-02-17 14:29:11 +010017127#define api_lisp_get_map_request_itr_rlocs api_one_get_map_request_itr_rlocs
17128
Damjan Marion7cd468a2016-12-19 23:05:39 +010017129static int
17130api_af_packet_create (vat_main_t * vam)
17131{
17132 unformat_input_t *i = vam->input;
17133 vl_api_af_packet_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017134 u8 *host_if_name = 0;
17135 u8 hw_addr[6];
17136 u8 random_hw_addr = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017137 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017138
Dave Barachb7b92992018-10-17 10:38:51 -040017139 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017140
17141 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17142 {
17143 if (unformat (i, "name %s", &host_if_name))
17144 vec_add1 (host_if_name, 0);
17145 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
17146 random_hw_addr = 0;
17147 else
17148 break;
17149 }
17150
17151 if (!vec_len (host_if_name))
17152 {
17153 errmsg ("host-interface name must be specified");
17154 return -99;
17155 }
17156
17157 if (vec_len (host_if_name) > 64)
17158 {
17159 errmsg ("host-interface name too long");
17160 return -99;
17161 }
17162
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017163 M (AF_PACKET_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017164
17165 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
17166 clib_memcpy (mp->hw_addr, hw_addr, 6);
17167 mp->use_random_hw_addr = random_hw_addr;
17168 vec_free (host_if_name);
17169
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017170 S (mp);
Dave Baracha1a093d2017-03-02 13:13:23 -050017171
17172 /* *INDENT-OFF* */
17173 W2 (ret,
17174 ({
17175 if (ret == 0)
17176 fprintf (vam->ofp ? vam->ofp : stderr,
17177 " new sw_if_index = %d\n", vam->sw_if_index);
17178 }));
17179 /* *INDENT-ON* */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017180 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017181}
17182
17183static int
17184api_af_packet_delete (vat_main_t * vam)
17185{
17186 unformat_input_t *i = vam->input;
17187 vl_api_af_packet_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017188 u8 *host_if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017189 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017190
17191 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17192 {
17193 if (unformat (i, "name %s", &host_if_name))
17194 vec_add1 (host_if_name, 0);
17195 else
17196 break;
17197 }
17198
17199 if (!vec_len (host_if_name))
17200 {
17201 errmsg ("host-interface name must be specified");
17202 return -99;
17203 }
17204
17205 if (vec_len (host_if_name) > 64)
17206 {
17207 errmsg ("host-interface name too long");
17208 return -99;
17209 }
17210
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017211 M (AF_PACKET_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017212
17213 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
17214 vec_free (host_if_name);
17215
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017216 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060017217 W (ret);
17218 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017219}
17220
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020017221static void vl_api_af_packet_details_t_handler
17222 (vl_api_af_packet_details_t * mp)
17223{
17224 vat_main_t *vam = &vat_main;
17225
17226 print (vam->ofp, "%-16s %d",
17227 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
17228}
17229
17230static void vl_api_af_packet_details_t_handler_json
17231 (vl_api_af_packet_details_t * mp)
17232{
17233 vat_main_t *vam = &vat_main;
17234 vat_json_node_t *node = NULL;
17235
17236 if (VAT_JSON_ARRAY != vam->json_tree.type)
17237 {
17238 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17239 vat_json_init_array (&vam->json_tree);
17240 }
17241 node = vat_json_array_add (&vam->json_tree);
17242
17243 vat_json_init_object (node);
17244 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
17245 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
17246}
17247
17248static int
17249api_af_packet_dump (vat_main_t * vam)
17250{
17251 vl_api_af_packet_dump_t *mp;
17252 vl_api_control_ping_t *mp_ping;
17253 int ret;
17254
17255 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
17256 /* Get list of tap interfaces */
17257 M (AF_PACKET_DUMP, mp);
17258 S (mp);
17259
17260 /* Use a control ping for synchronization */
17261 MPING (CONTROL_PING, mp_ping);
17262 S (mp_ping);
17263
17264 W (ret);
17265 return ret;
17266}
17267
Damjan Marion7cd468a2016-12-19 23:05:39 +010017268static int
17269api_policer_add_del (vat_main_t * vam)
17270{
17271 unformat_input_t *i = vam->input;
17272 vl_api_policer_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017273 u8 is_add = 1;
17274 u8 *name = 0;
17275 u32 cir = 0;
17276 u32 eir = 0;
17277 u64 cb = 0;
17278 u64 eb = 0;
17279 u8 rate_type = 0;
17280 u8 round_type = 0;
17281 u8 type = 0;
17282 u8 color_aware = 0;
17283 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017284 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017285
17286 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
17287 conform_action.dscp = 0;
17288 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
17289 exceed_action.dscp = 0;
17290 violate_action.action_type = SSE2_QOS_ACTION_DROP;
17291 violate_action.dscp = 0;
17292
17293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17294 {
17295 if (unformat (i, "del"))
17296 is_add = 0;
17297 else if (unformat (i, "name %s", &name))
17298 vec_add1 (name, 0);
17299 else if (unformat (i, "cir %u", &cir))
17300 ;
17301 else if (unformat (i, "eir %u", &eir))
17302 ;
17303 else if (unformat (i, "cb %u", &cb))
17304 ;
17305 else if (unformat (i, "eb %u", &eb))
17306 ;
17307 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
17308 &rate_type))
17309 ;
17310 else if (unformat (i, "round_type %U", unformat_policer_round_type,
17311 &round_type))
17312 ;
17313 else if (unformat (i, "type %U", unformat_policer_type, &type))
17314 ;
17315 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
17316 &conform_action))
17317 ;
17318 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
17319 &exceed_action))
17320 ;
17321 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
17322 &violate_action))
17323 ;
17324 else if (unformat (i, "color-aware"))
17325 color_aware = 1;
17326 else
17327 break;
17328 }
17329
17330 if (!vec_len (name))
17331 {
17332 errmsg ("policer name must be specified");
17333 return -99;
17334 }
17335
17336 if (vec_len (name) > 64)
17337 {
17338 errmsg ("policer name too long");
17339 return -99;
17340 }
17341
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017342 M (POLICER_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017343
17344 clib_memcpy (mp->name, name, vec_len (name));
17345 vec_free (name);
17346 mp->is_add = is_add;
Neale Rannsd91c1db2017-07-31 02:30:50 -070017347 mp->cir = ntohl (cir);
17348 mp->eir = ntohl (eir);
17349 mp->cb = clib_net_to_host_u64 (cb);
17350 mp->eb = clib_net_to_host_u64 (eb);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017351 mp->rate_type = rate_type;
17352 mp->round_type = round_type;
17353 mp->type = type;
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010017354 mp->conform_action.type = conform_action.action_type;
17355 mp->conform_action.dscp = conform_action.dscp;
17356 mp->exceed_action.type = exceed_action.action_type;
17357 mp->exceed_action.dscp = exceed_action.dscp;
17358 mp->violate_action.type = violate_action.action_type;
17359 mp->violate_action.dscp = violate_action.dscp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017360 mp->color_aware = color_aware;
17361
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017362 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060017363 W (ret);
17364 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017365}
17366
17367static int
17368api_policer_dump (vat_main_t * vam)
17369{
17370 unformat_input_t *i = vam->input;
17371 vl_api_policer_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017372 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017373 u8 *match_name = 0;
17374 u8 match_name_valid = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017375 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017376
17377 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17378 {
17379 if (unformat (i, "name %s", &match_name))
17380 {
17381 vec_add1 (match_name, 0);
17382 match_name_valid = 1;
17383 }
17384 else
17385 break;
17386 }
17387
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017388 M (POLICER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017389 mp->match_name_valid = match_name_valid;
17390 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
17391 vec_free (match_name);
17392 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017393 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017394
17395 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017396 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017397 S (mp_ping);
17398
Damjan Marion7cd468a2016-12-19 23:05:39 +010017399 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017400 W (ret);
17401 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017402}
17403
17404static int
17405api_policer_classify_set_interface (vat_main_t * vam)
17406{
17407 unformat_input_t *i = vam->input;
17408 vl_api_policer_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017409 u32 sw_if_index;
17410 int sw_if_index_set;
17411 u32 ip4_table_index = ~0;
17412 u32 ip6_table_index = ~0;
17413 u32 l2_table_index = ~0;
17414 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017415 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017416
17417 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
17418 {
17419 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
17420 sw_if_index_set = 1;
17421 else if (unformat (i, "sw_if_index %d", &sw_if_index))
17422 sw_if_index_set = 1;
17423 else if (unformat (i, "del"))
17424 is_add = 0;
17425 else if (unformat (i, "ip4-table %d", &ip4_table_index))
17426 ;
17427 else if (unformat (i, "ip6-table %d", &ip6_table_index))
17428 ;
17429 else if (unformat (i, "l2-table %d", &l2_table_index))
17430 ;
17431 else
17432 {
17433 clib_warning ("parse error '%U'", format_unformat_error, i);
17434 return -99;
17435 }
17436 }
17437
17438 if (sw_if_index_set == 0)
17439 {
17440 errmsg ("missing interface name or sw_if_index");
17441 return -99;
17442 }
17443
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017444 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017445
17446 mp->sw_if_index = ntohl (sw_if_index);
17447 mp->ip4_table_index = ntohl (ip4_table_index);
17448 mp->ip6_table_index = ntohl (ip6_table_index);
17449 mp->l2_table_index = ntohl (l2_table_index);
17450 mp->is_add = is_add;
17451
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017452 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060017453 W (ret);
17454 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017455}
17456
17457static int
17458api_policer_classify_dump (vat_main_t * vam)
17459{
17460 unformat_input_t *i = vam->input;
17461 vl_api_policer_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017462 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017463 u8 type = POLICER_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017464 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017465
17466 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
17467 ;
17468 else
17469 {
17470 errmsg ("classify table type must be specified");
17471 return -99;
17472 }
17473
17474 if (!vam->json_output)
17475 {
17476 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
17477 }
17478
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017479 M (POLICER_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017480 mp->type = type;
17481 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017482 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017483
17484 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017485 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017486 S (mp_ping);
17487
Damjan Marion7cd468a2016-12-19 23:05:39 +010017488 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017489 W (ret);
17490 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017491}
17492
Neale Ranns097fa662018-05-01 05:17:55 -070017493static u8 *
17494format_fib_api_path_nh_proto (u8 * s, va_list * args)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017495{
Neale Ranns097fa662018-05-01 05:17:55 -070017496 vl_api_fib_path_nh_proto_t proto =
17497 va_arg (*args, vl_api_fib_path_nh_proto_t);
17498
17499 switch (proto)
17500 {
17501 case FIB_API_PATH_NH_PROTO_IP4:
17502 s = format (s, "ip4");
17503 break;
17504 case FIB_API_PATH_NH_PROTO_IP6:
17505 s = format (s, "ip6");
17506 break;
17507 case FIB_API_PATH_NH_PROTO_MPLS:
17508 s = format (s, "mpls");
17509 break;
17510 case FIB_API_PATH_NH_PROTO_BIER:
17511 s = format (s, "bier");
17512 break;
17513 case FIB_API_PATH_NH_PROTO_ETHERNET:
17514 s = format (s, "ethernet");
17515 break;
17516 }
17517
17518 return (s);
17519}
17520
17521static u8 *
17522format_vl_api_ip_address_union (u8 * s, va_list * args)
17523{
Jakub Grajciar7dd63e52020-03-19 08:03:55 +010017524 vl_api_address_family_t af = va_arg (*args, int);
Neale Ranns097fa662018-05-01 05:17:55 -070017525 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
17526
17527 switch (af)
17528 {
17529 case ADDRESS_IP4:
17530 s = format (s, "%U", format_ip4_address, u->ip4);
17531 break;
17532 case ADDRESS_IP6:
17533 s = format (s, "%U", format_ip6_address, u->ip6);
17534 break;
17535 }
17536 return (s);
17537}
17538
17539static u8 *
17540format_vl_api_fib_path_type (u8 * s, va_list * args)
17541{
17542 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
17543
17544 switch (t)
17545 {
17546 case FIB_API_PATH_TYPE_NORMAL:
17547 s = format (s, "normal");
17548 break;
17549 case FIB_API_PATH_TYPE_LOCAL:
17550 s = format (s, "local");
17551 break;
17552 case FIB_API_PATH_TYPE_DROP:
17553 s = format (s, "drop");
17554 break;
17555 case FIB_API_PATH_TYPE_UDP_ENCAP:
17556 s = format (s, "udp-encap");
17557 break;
17558 case FIB_API_PATH_TYPE_BIER_IMP:
17559 s = format (s, "bier-imp");
17560 break;
17561 case FIB_API_PATH_TYPE_ICMP_UNREACH:
17562 s = format (s, "unreach");
17563 break;
17564 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
17565 s = format (s, "prohibit");
17566 break;
17567 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
17568 s = format (s, "src-lookup");
17569 break;
17570 case FIB_API_PATH_TYPE_DVR:
17571 s = format (s, "dvr");
17572 break;
17573 case FIB_API_PATH_TYPE_INTERFACE_RX:
17574 s = format (s, "interface-rx");
17575 break;
17576 case FIB_API_PATH_TYPE_CLASSIFY:
17577 s = format (s, "classify");
17578 break;
17579 }
17580
17581 return (s);
17582}
17583
17584static void
17585vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
17586{
17587 print (vam->ofp,
17588 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
17589 ntohl (fp->weight), ntohl (fp->sw_if_index),
17590 format_vl_api_fib_path_type, fp->type,
17591 format_fib_api_path_nh_proto, fp->proto,
17592 format_vl_api_ip_address_union, &fp->nh.address);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017593}
17594
17595static void
17596vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
Neale Ranns31ed7442018-02-23 05:29:09 -080017597 vl_api_fib_path_t * fp)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017598{
17599 struct in_addr ip4;
17600 struct in6_addr ip6;
17601
17602 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
17603 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
Neale Ranns097fa662018-05-01 05:17:55 -070017604 vat_json_object_add_uint (node, "type", fp->type);
17605 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
17606 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017607 {
Neale Ranns097fa662018-05-01 05:17:55 -070017608 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017609 vat_json_object_add_ip4 (node, "next_hop", ip4);
17610 }
Dave Barachc35f3e82020-04-02 10:44:09 -040017611 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017612 {
Neale Ranns097fa662018-05-01 05:17:55 -070017613 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017614 vat_json_object_add_ip6 (node, "next_hop", ip6);
17615 }
17616}
17617
17618static void
17619vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017620{
17621 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017622 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080017623 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017624 i32 i;
17625
Neale Ranns097fa662018-05-01 05:17:55 -070017626 print (vam->ofp, "sw_if_index %d via:",
17627 ntohl (mp->mt_tunnel.mt_sw_if_index));
17628 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017629 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017630 {
Neale Ranns097fa662018-05-01 05:17:55 -070017631 vl_api_fib_path_print (vam, fp);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017632 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017633 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017634
Damjan Marion7cd468a2016-12-19 23:05:39 +010017635 print (vam->ofp, "");
17636}
17637
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017638#define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
17639#define vl_api_mpls_tunnel_details_t_print vl_noop_handler
17640
17641static void
17642vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017643{
17644 vat_main_t *vam = &vat_main;
17645 vat_json_node_t *node = NULL;
Neale Ranns097fa662018-05-01 05:17:55 -070017646 int count = ntohl (mp->mt_tunnel.mt_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080017647 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017648 i32 i;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017649
17650 if (VAT_JSON_ARRAY != vam->json_tree.type)
17651 {
17652 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17653 vat_json_init_array (&vam->json_tree);
17654 }
17655 node = vat_json_array_add (&vam->json_tree);
17656
17657 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070017658 vat_json_object_add_uint (node, "sw_if_index",
17659 ntohl (mp->mt_tunnel.mt_sw_if_index));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017660
Neale Ranns097fa662018-05-01 05:17:55 -070017661 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017662
Neale Ranns097fa662018-05-01 05:17:55 -070017663 fp = mp->mt_tunnel.mt_paths;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017664 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017665 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017666 vl_api_mpls_fib_path_json_print (node, fp);
17667 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017668 }
17669}
17670
17671static int
17672api_mpls_tunnel_dump (vat_main_t * vam)
17673{
17674 vl_api_mpls_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017675 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017676 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017677
Jon Loeliger8a2aea32017-01-31 13:19:40 -060017678 M (MPLS_TUNNEL_DUMP, mp);
Neale Ranns097fa662018-05-01 05:17:55 -070017679
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017680 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017681
17682 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017683 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017684 S (mp_ping);
17685
Jon Loeliger56c7b012017-02-01 12:31:41 -060017686 W (ret);
17687 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017688}
17689
Neale Ranns097fa662018-05-01 05:17:55 -070017690#define vl_api_mpls_table_details_t_endian vl_noop_handler
17691#define vl_api_mpls_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010017692
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017693
Damjan Marion7cd468a2016-12-19 23:05:39 +010017694static void
Neale Ranns097fa662018-05-01 05:17:55 -070017695vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017696{
17697 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017698
17699 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
17700}
17701
17702static void vl_api_mpls_table_details_t_handler_json
17703 (vl_api_mpls_table_details_t * mp)
17704{
17705 vat_main_t *vam = &vat_main;
17706 vat_json_node_t *node = NULL;
17707
17708 if (VAT_JSON_ARRAY != vam->json_tree.type)
17709 {
17710 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17711 vat_json_init_array (&vam->json_tree);
17712 }
17713 node = vat_json_array_add (&vam->json_tree);
17714
17715 vat_json_init_object (node);
17716 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
17717}
17718
17719static int
17720api_mpls_table_dump (vat_main_t * vam)
17721{
17722 vl_api_mpls_table_dump_t *mp;
17723 vl_api_control_ping_t *mp_ping;
17724 int ret;
17725
17726 M (MPLS_TABLE_DUMP, mp);
17727 S (mp);
17728
17729 /* Use a control ping for synchronization */
17730 MPING (CONTROL_PING, mp_ping);
17731 S (mp_ping);
17732
17733 W (ret);
17734 return ret;
17735}
17736
17737#define vl_api_mpls_route_details_t_endian vl_noop_handler
17738#define vl_api_mpls_route_details_t_print vl_noop_handler
17739
17740static void
17741vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
17742{
17743 vat_main_t *vam = &vat_main;
Dave Barach4bda2d92019-07-03 15:21:50 -040017744 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
Neale Ranns31ed7442018-02-23 05:29:09 -080017745 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017746 int i;
17747
17748 print (vam->ofp,
17749 "table-id %d, label %u, ess_bit %u",
Neale Ranns097fa662018-05-01 05:17:55 -070017750 ntohl (mp->mr_route.mr_table_id),
17751 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
17752 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017753 for (i = 0; i < count; i++)
17754 {
Neale Ranns097fa662018-05-01 05:17:55 -070017755 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017756 fp++;
17757 }
17758}
17759
Neale Ranns097fa662018-05-01 05:17:55 -070017760static void vl_api_mpls_route_details_t_handler_json
17761 (vl_api_mpls_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017762{
17763 vat_main_t *vam = &vat_main;
Dave Barach4bda2d92019-07-03 15:21:50 -040017764 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017765 vat_json_node_t *node = NULL;
Neale Ranns31ed7442018-02-23 05:29:09 -080017766 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017767 int i;
17768
17769 if (VAT_JSON_ARRAY != vam->json_tree.type)
17770 {
17771 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17772 vat_json_init_array (&vam->json_tree);
17773 }
17774 node = vat_json_array_add (&vam->json_tree);
17775
17776 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070017777 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
17778 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
17779 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017780 vat_json_object_add_uint (node, "path_count", count);
Neale Ranns097fa662018-05-01 05:17:55 -070017781 fp = mp->mr_route.mr_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017782 for (i = 0; i < count; i++)
17783 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080017784 vl_api_mpls_fib_path_json_print (node, fp);
17785 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017786 }
17787}
17788
17789static int
Neale Ranns097fa662018-05-01 05:17:55 -070017790api_mpls_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017791{
Neale Ranns097fa662018-05-01 05:17:55 -070017792 unformat_input_t *input = vam->input;
17793 vl_api_mpls_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017794 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070017795 u32 table_id;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017796 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017797
Neale Ranns097fa662018-05-01 05:17:55 -070017798 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17799 {
17800 if (unformat (input, "table_id %d", &table_id))
17801 ;
17802 else
17803 break;
17804 }
17805 if (table_id == ~0)
17806 {
17807 errmsg ("missing table id");
17808 return -99;
17809 }
17810
17811 M (MPLS_ROUTE_DUMP, mp);
17812
17813 mp->table.mt_table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017814 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017815
17816 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017817 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017818 S (mp_ping);
17819
Jon Loeliger56c7b012017-02-01 12:31:41 -060017820 W (ret);
17821 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017822}
17823
Neale Ranns097fa662018-05-01 05:17:55 -070017824#define vl_api_ip_table_details_t_endian vl_noop_handler
17825#define vl_api_ip_table_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010017826
17827static void
Neale Ranns097fa662018-05-01 05:17:55 -070017828vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017829{
17830 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017831
17832 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070017833 "%s; table-id %d, prefix %U/%d",
17834 mp->table.name, ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017835}
17836
Neale Ranns097fa662018-05-01 05:17:55 -070017837
17838static void vl_api_ip_table_details_t_handler_json
17839 (vl_api_ip_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017840{
17841 vat_main_t *vam = &vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017842 vat_json_node_t *node = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017843
17844 if (VAT_JSON_ARRAY != vam->json_tree.type)
17845 {
17846 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17847 vat_json_init_array (&vam->json_tree);
17848 }
17849 node = vat_json_array_add (&vam->json_tree);
17850
17851 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070017852 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017853}
17854
17855static int
Neale Ranns097fa662018-05-01 05:17:55 -070017856api_ip_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017857{
Neale Ranns097fa662018-05-01 05:17:55 -070017858 vl_api_ip_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017859 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017860 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017861
Neale Ranns097fa662018-05-01 05:17:55 -070017862 M (IP_TABLE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017863 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017864
17865 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017866 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017867 S (mp_ping);
17868
Jon Loeliger56c7b012017-02-01 12:31:41 -060017869 W (ret);
17870 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017871}
17872
Neale Ranns5a8123b2017-01-26 01:18:23 -080017873static int
Neale Ranns097fa662018-05-01 05:17:55 -070017874api_ip_mtable_dump (vat_main_t * vam)
Neale Ranns5a8123b2017-01-26 01:18:23 -080017875{
Neale Ranns097fa662018-05-01 05:17:55 -070017876 vl_api_ip_mtable_dump_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -080017877 vl_api_control_ping_t *mp_ping;
17878 int ret;
17879
Neale Ranns097fa662018-05-01 05:17:55 -070017880 M (IP_MTABLE_DUMP, mp);
17881 S (mp);
17882
17883 /* Use a control ping for synchronization */
17884 MPING (CONTROL_PING, mp_ping);
17885 S (mp_ping);
17886
17887 W (ret);
17888 return ret;
17889}
17890
17891static int
17892api_ip_mroute_dump (vat_main_t * vam)
17893{
17894 unformat_input_t *input = vam->input;
17895 vl_api_control_ping_t *mp_ping;
17896 vl_api_ip_mroute_dump_t *mp;
17897 int ret, is_ip6;
17898 u32 table_id;
17899
17900 is_ip6 = 0;
17901 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17902 {
17903 if (unformat (input, "table_id %d", &table_id))
17904 ;
17905 else if (unformat (input, "ip6"))
17906 is_ip6 = 1;
17907 else if (unformat (input, "ip4"))
17908 is_ip6 = 0;
17909 else
17910 break;
17911 }
17912 if (table_id == ~0)
17913 {
17914 errmsg ("missing table id");
17915 return -99;
17916 }
17917
17918 M (IP_MROUTE_DUMP, mp);
17919 mp->table.table_id = table_id;
17920 mp->table.is_ip6 = is_ip6;
Neale Ranns5a8123b2017-01-26 01:18:23 -080017921 S (mp);
17922
17923 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040017924 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080017925 S (mp_ping);
17926
17927 W (ret);
17928 return ret;
17929}
17930
Neale Ranns097fa662018-05-01 05:17:55 -070017931#define vl_api_ip_route_details_t_endian vl_noop_handler
17932#define vl_api_ip_route_details_t_print vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +010017933
17934static void
Neale Ranns097fa662018-05-01 05:17:55 -070017935vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017936{
17937 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017938 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017939 vl_api_fib_path_t *fp;
17940 int i;
17941
17942 print (vam->ofp,
Neale Ranns097fa662018-05-01 05:17:55 -070017943 "table-id %d, prefix %U/%d",
17944 ntohl (mp->route.table_id),
Paul Vinciguerraab055082019-06-06 14:07:55 -040017945 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017946 for (i = 0; i < count; i++)
17947 {
Neale Ranns097fa662018-05-01 05:17:55 -070017948 fp = &mp->route.paths[i];
17949
17950 vl_api_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017951 fp++;
17952 }
17953}
17954
Neale Ranns097fa662018-05-01 05:17:55 -070017955static void vl_api_ip_route_details_t_handler_json
17956 (vl_api_ip_route_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017957{
17958 vat_main_t *vam = &vat_main;
Neale Ranns097fa662018-05-01 05:17:55 -070017959 u8 count = mp->route.n_paths;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017960 vat_json_node_t *node = NULL;
17961 struct in_addr ip4;
17962 struct in6_addr ip6;
17963 vl_api_fib_path_t *fp;
17964 int i;
17965
17966 if (VAT_JSON_ARRAY != vam->json_tree.type)
17967 {
17968 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
17969 vat_json_init_array (&vam->json_tree);
17970 }
17971 node = vat_json_array_add (&vam->json_tree);
17972
17973 vat_json_init_object (node);
Neale Ranns097fa662018-05-01 05:17:55 -070017974 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
17975 if (ADDRESS_IP6 == mp->route.prefix.address.af)
17976 {
17977 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
17978 vat_json_object_add_ip6 (node, "prefix", ip6);
17979 }
17980 else
17981 {
17982 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
17983 vat_json_object_add_ip4 (node, "prefix", ip4);
17984 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040017985 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017986 vat_json_object_add_uint (node, "path_count", count);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017987 for (i = 0; i < count; i++)
17988 {
Neale Ranns097fa662018-05-01 05:17:55 -070017989 fp = &mp->route.paths[i];
17990 vl_api_mpls_fib_path_json_print (node, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017991 }
17992}
17993
17994static int
Neale Ranns097fa662018-05-01 05:17:55 -070017995api_ip_route_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017996{
Neale Ranns097fa662018-05-01 05:17:55 -070017997 unformat_input_t *input = vam->input;
17998 vl_api_ip_route_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060017999 vl_api_control_ping_t *mp_ping;
Neale Ranns097fa662018-05-01 05:17:55 -070018000 u32 table_id;
18001 u8 is_ip6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018002 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018003
Neale Ranns097fa662018-05-01 05:17:55 -070018004 is_ip6 = 0;
18005 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18006 {
18007 if (unformat (input, "table_id %d", &table_id))
18008 ;
18009 else if (unformat (input, "ip6"))
18010 is_ip6 = 1;
18011 else if (unformat (input, "ip4"))
18012 is_ip6 = 0;
18013 else
18014 break;
18015 }
18016 if (table_id == ~0)
18017 {
18018 errmsg ("missing table id");
18019 return -99;
18020 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010018021
Neale Ranns097fa662018-05-01 05:17:55 -070018022 M (IP_ROUTE_DUMP, mp);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018023
Neale Ranns097fa662018-05-01 05:17:55 -070018024 mp->table.table_id = table_id;
18025 mp->table.is_ip6 = is_ip6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018026
Neale Ranns5a8123b2017-01-26 01:18:23 -080018027 S (mp);
18028
18029 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018030 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080018031 S (mp_ping);
18032
18033 W (ret);
18034 return ret;
18035}
18036
Damjan Marion7cd468a2016-12-19 23:05:39 +010018037int
18038api_classify_table_ids (vat_main_t * vam)
18039{
18040 vl_api_classify_table_ids_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018041 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018042
18043 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018044 M (CLASSIFY_TABLE_IDS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018045 mp->context = 0;
18046
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018047 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018048 W (ret);
18049 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018050}
18051
18052int
18053api_classify_table_by_interface (vat_main_t * vam)
18054{
18055 unformat_input_t *input = vam->input;
18056 vl_api_classify_table_by_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018057
18058 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018059 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018060 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18061 {
18062 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18063 ;
18064 else if (unformat (input, "sw_if_index %d", &sw_if_index))
18065 ;
18066 else
18067 break;
18068 }
18069 if (sw_if_index == ~0)
18070 {
18071 errmsg ("missing interface name or sw_if_index");
18072 return -99;
18073 }
18074
18075 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018076 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018077 mp->context = 0;
18078 mp->sw_if_index = ntohl (sw_if_index);
18079
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018080 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018081 W (ret);
18082 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018083}
18084
18085int
18086api_classify_table_info (vat_main_t * vam)
18087{
18088 unformat_input_t *input = vam->input;
18089 vl_api_classify_table_info_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018090
18091 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018092 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018093 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18094 {
18095 if (unformat (input, "table_id %d", &table_id))
18096 ;
18097 else
18098 break;
18099 }
18100 if (table_id == ~0)
18101 {
18102 errmsg ("missing table id");
18103 return -99;
18104 }
18105
18106 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018107 M (CLASSIFY_TABLE_INFO, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018108 mp->context = 0;
18109 mp->table_id = ntohl (table_id);
18110
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018111 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018112 W (ret);
18113 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018114}
18115
18116int
18117api_classify_session_dump (vat_main_t * vam)
18118{
18119 unformat_input_t *input = vam->input;
18120 vl_api_classify_session_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018121 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018122
18123 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018124 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018125 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18126 {
18127 if (unformat (input, "table_id %d", &table_id))
18128 ;
18129 else
18130 break;
18131 }
18132 if (table_id == ~0)
18133 {
18134 errmsg ("missing table id");
18135 return -99;
18136 }
18137
18138 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018139 M (CLASSIFY_SESSION_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018140 mp->context = 0;
18141 mp->table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018142 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018143
18144 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018145 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018146 S (mp_ping);
18147
Jon Loeliger56c7b012017-02-01 12:31:41 -060018148 W (ret);
18149 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018150}
18151
18152static void
18153vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
18154{
18155 vat_main_t *vam = &vat_main;
18156
18157 print (vam->ofp, "collector_address %U, collector_port %d, "
18158 "src_address %U, vrf_id %d, path_mtu %u, "
18159 "template_interval %u, udp_checksum %d",
18160 format_ip4_address, mp->collector_address,
18161 ntohs (mp->collector_port),
18162 format_ip4_address, mp->src_address,
18163 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
18164 ntohl (mp->template_interval), mp->udp_checksum);
18165
18166 vam->retval = 0;
18167 vam->result_ready = 1;
18168}
18169
18170static void
18171 vl_api_ipfix_exporter_details_t_handler_json
18172 (vl_api_ipfix_exporter_details_t * mp)
18173{
18174 vat_main_t *vam = &vat_main;
18175 vat_json_node_t node;
18176 struct in_addr collector_address;
18177 struct in_addr src_address;
18178
18179 vat_json_init_object (&node);
18180 clib_memcpy (&collector_address, &mp->collector_address,
18181 sizeof (collector_address));
18182 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
18183 vat_json_object_add_uint (&node, "collector_port",
18184 ntohs (mp->collector_port));
18185 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
18186 vat_json_object_add_ip4 (&node, "src_address", src_address);
18187 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
18188 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
18189 vat_json_object_add_uint (&node, "template_interval",
18190 ntohl (mp->template_interval));
18191 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
18192
18193 vat_json_print (vam->ofp, &node);
18194 vat_json_free (&node);
18195 vam->retval = 0;
18196 vam->result_ready = 1;
18197}
18198
18199int
18200api_ipfix_exporter_dump (vat_main_t * vam)
18201{
18202 vl_api_ipfix_exporter_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018203 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018204
18205 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018206 M (IPFIX_EXPORTER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018207 mp->context = 0;
18208
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018209 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018210 W (ret);
18211 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018212}
18213
18214static int
18215api_ipfix_classify_stream_dump (vat_main_t * vam)
18216{
18217 vl_api_ipfix_classify_stream_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018218 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018219
18220 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018221 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018222 mp->context = 0;
18223
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018224 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018225 W (ret);
18226 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018227 /* NOTREACHED */
18228 return 0;
18229}
18230
18231static void
18232 vl_api_ipfix_classify_stream_details_t_handler
18233 (vl_api_ipfix_classify_stream_details_t * mp)
18234{
18235 vat_main_t *vam = &vat_main;
18236 print (vam->ofp, "domain_id %d, src_port %d",
18237 ntohl (mp->domain_id), ntohs (mp->src_port));
18238 vam->retval = 0;
18239 vam->result_ready = 1;
18240}
18241
18242static void
18243 vl_api_ipfix_classify_stream_details_t_handler_json
18244 (vl_api_ipfix_classify_stream_details_t * mp)
18245{
18246 vat_main_t *vam = &vat_main;
18247 vat_json_node_t node;
18248
18249 vat_json_init_object (&node);
18250 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
18251 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
18252
18253 vat_json_print (vam->ofp, &node);
18254 vat_json_free (&node);
18255 vam->retval = 0;
18256 vam->result_ready = 1;
18257}
18258
18259static int
18260api_ipfix_classify_table_dump (vat_main_t * vam)
18261{
18262 vl_api_ipfix_classify_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018263 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018264 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018265
18266 if (!vam->json_output)
18267 {
18268 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
18269 "transport_protocol");
18270 }
18271
18272 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018273 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018274
18275 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018276 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018277
18278 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018279 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018280 S (mp_ping);
18281
Jon Loeliger56c7b012017-02-01 12:31:41 -060018282 W (ret);
18283 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018284}
18285
18286static void
18287 vl_api_ipfix_classify_table_details_t_handler
18288 (vl_api_ipfix_classify_table_details_t * mp)
18289{
18290 vat_main_t *vam = &vat_main;
18291 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
18292 mp->transport_protocol);
18293}
18294
18295static void
18296 vl_api_ipfix_classify_table_details_t_handler_json
18297 (vl_api_ipfix_classify_table_details_t * mp)
18298{
18299 vat_json_node_t *node = NULL;
18300 vat_main_t *vam = &vat_main;
18301
18302 if (VAT_JSON_ARRAY != vam->json_tree.type)
18303 {
18304 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18305 vat_json_init_array (&vam->json_tree);
18306 }
18307
18308 node = vat_json_array_add (&vam->json_tree);
18309 vat_json_init_object (node);
18310
18311 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
18312 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
18313 vat_json_object_add_uint (node, "transport_protocol",
18314 mp->transport_protocol);
18315}
18316
18317static int
18318api_sw_interface_span_enable_disable (vat_main_t * vam)
18319{
18320 unformat_input_t *i = vam->input;
18321 vl_api_sw_interface_span_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018322 u32 src_sw_if_index = ~0;
18323 u32 dst_sw_if_index = ~0;
18324 u8 state = 3;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018325 int ret;
Eyal Bari001fd402017-07-16 09:34:53 +030018326 u8 is_l2 = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018327
18328 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18329 {
18330 if (unformat
18331 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
18332 ;
18333 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
18334 ;
18335 else
18336 if (unformat
18337 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
18338 ;
18339 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
18340 ;
18341 else if (unformat (i, "disable"))
18342 state = 0;
18343 else if (unformat (i, "rx"))
18344 state = 1;
18345 else if (unformat (i, "tx"))
18346 state = 2;
18347 else if (unformat (i, "both"))
18348 state = 3;
Eyal Bari001fd402017-07-16 09:34:53 +030018349 else if (unformat (i, "l2"))
18350 is_l2 = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018351 else
18352 break;
18353 }
18354
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018355 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018356
18357 mp->sw_if_index_from = htonl (src_sw_if_index);
18358 mp->sw_if_index_to = htonl (dst_sw_if_index);
18359 mp->state = state;
Eyal Bari001fd402017-07-16 09:34:53 +030018360 mp->is_l2 = is_l2;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018361
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018362 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018363 W (ret);
18364 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018365}
18366
18367static void
18368vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
18369 * mp)
18370{
18371 vat_main_t *vam = &vat_main;
18372 u8 *sw_if_from_name = 0;
18373 u8 *sw_if_to_name = 0;
18374 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
18375 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
18376 char *states[] = { "none", "rx", "tx", "both" };
18377 hash_pair_t *p;
18378
18379 /* *INDENT-OFF* */
18380 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
18381 ({
18382 if ((u32) p->value[0] == sw_if_index_from)
18383 {
18384 sw_if_from_name = (u8 *)(p->key);
18385 if (sw_if_to_name)
18386 break;
18387 }
18388 if ((u32) p->value[0] == sw_if_index_to)
18389 {
18390 sw_if_to_name = (u8 *)(p->key);
18391 if (sw_if_from_name)
18392 break;
18393 }
18394 }));
18395 /* *INDENT-ON* */
Jon Loeliger179ab362018-03-12 14:50:08 -050018396 print (vam->ofp, "%20s => %20s (%s) %s",
18397 sw_if_from_name, sw_if_to_name, states[mp->state],
18398 mp->is_l2 ? "l2" : "device");
Damjan Marion7cd468a2016-12-19 23:05:39 +010018399}
18400
18401static void
18402 vl_api_sw_interface_span_details_t_handler_json
18403 (vl_api_sw_interface_span_details_t * mp)
18404{
18405 vat_main_t *vam = &vat_main;
18406 vat_json_node_t *node = NULL;
18407 u8 *sw_if_from_name = 0;
18408 u8 *sw_if_to_name = 0;
18409 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
18410 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
18411 hash_pair_t *p;
18412
18413 /* *INDENT-OFF* */
18414 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
18415 ({
18416 if ((u32) p->value[0] == sw_if_index_from)
18417 {
18418 sw_if_from_name = (u8 *)(p->key);
18419 if (sw_if_to_name)
18420 break;
18421 }
18422 if ((u32) p->value[0] == sw_if_index_to)
18423 {
18424 sw_if_to_name = (u8 *)(p->key);
18425 if (sw_if_from_name)
18426 break;
18427 }
18428 }));
18429 /* *INDENT-ON* */
18430
18431 if (VAT_JSON_ARRAY != vam->json_tree.type)
18432 {
18433 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
18434 vat_json_init_array (&vam->json_tree);
18435 }
18436 node = vat_json_array_add (&vam->json_tree);
18437
18438 vat_json_init_object (node);
18439 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
18440 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
18441 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
Neale Ranns05b2bf22017-01-30 06:44:58 -080018442 if (0 != sw_if_to_name)
18443 {
18444 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
18445 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010018446 vat_json_object_add_uint (node, "state", mp->state);
Jon Loeliger179ab362018-03-12 14:50:08 -050018447 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018448}
18449
18450static int
18451api_sw_interface_span_dump (vat_main_t * vam)
18452{
Eyal Bari5b311202017-07-31 13:12:30 +030018453 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018454 vl_api_sw_interface_span_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018455 vl_api_control_ping_t *mp_ping;
Eyal Bari5b311202017-07-31 13:12:30 +030018456 u8 is_l2 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018457 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018458
Eyal Bari5b311202017-07-31 13:12:30 +030018459 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18460 {
18461 if (unformat (input, "l2"))
18462 is_l2 = 1;
18463 else
18464 break;
18465 }
18466
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018467 M (SW_INTERFACE_SPAN_DUMP, mp);
Eyal Bari5b311202017-07-31 13:12:30 +030018468 mp->is_l2 = is_l2;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018469 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018470
18471 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018472 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018473 S (mp_ping);
18474
Jon Loeliger56c7b012017-02-01 12:31:41 -060018475 W (ret);
18476 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018477}
18478
18479int
18480api_pg_create_interface (vat_main_t * vam)
18481{
18482 unformat_input_t *input = vam->input;
18483 vl_api_pg_create_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018484
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020018485 u32 if_id = ~0, gso_size = 0;
18486 u8 gso_enabled = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018487 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018488 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18489 {
18490 if (unformat (input, "if_id %d", &if_id))
18491 ;
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020018492 else if (unformat (input, "gso-enabled"))
18493 {
18494 gso_enabled = 1;
18495 if (unformat (input, "gso-size %u", &gso_size))
18496 ;
18497 else
18498 {
18499 errmsg ("missing gso-size");
18500 return -99;
18501 }
18502 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010018503 else
18504 break;
18505 }
18506 if (if_id == ~0)
18507 {
18508 errmsg ("missing pg interface index");
18509 return -99;
18510 }
18511
18512 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018513 M (PG_CREATE_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018514 mp->context = 0;
18515 mp->interface_id = ntohl (if_id);
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020018516 mp->gso_enabled = gso_enabled;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018517
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018518 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018519 W (ret);
18520 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018521}
18522
18523int
18524api_pg_capture (vat_main_t * vam)
18525{
18526 unformat_input_t *input = vam->input;
18527 vl_api_pg_capture_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018528
18529 u32 if_id = ~0;
18530 u8 enable = 1;
18531 u32 count = 1;
18532 u8 pcap_file_set = 0;
18533 u8 *pcap_file = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018534 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018535 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18536 {
18537 if (unformat (input, "if_id %d", &if_id))
18538 ;
18539 else if (unformat (input, "pcap %s", &pcap_file))
18540 pcap_file_set = 1;
18541 else if (unformat (input, "count %d", &count))
18542 ;
18543 else if (unformat (input, "disable"))
18544 enable = 0;
18545 else
18546 break;
18547 }
18548 if (if_id == ~0)
18549 {
18550 errmsg ("missing pg interface index");
18551 return -99;
18552 }
18553 if (pcap_file_set > 0)
18554 {
18555 if (vec_len (pcap_file) > 255)
18556 {
18557 errmsg ("pcap file name is too long");
18558 return -99;
18559 }
18560 }
18561
Damjan Marion7cd468a2016-12-19 23:05:39 +010018562 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018563 M (PG_CAPTURE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018564 mp->context = 0;
18565 mp->interface_id = ntohl (if_id);
18566 mp->is_enabled = enable;
18567 mp->count = ntohl (count);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018568 if (pcap_file_set != 0)
18569 {
Jakub Grajciardb863292020-01-30 14:14:15 +010018570 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018571 }
18572 vec_free (pcap_file);
18573
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018574 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018575 W (ret);
18576 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018577}
18578
18579int
18580api_pg_enable_disable (vat_main_t * vam)
18581{
18582 unformat_input_t *input = vam->input;
18583 vl_api_pg_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018584
18585 u8 enable = 1;
18586 u8 stream_name_set = 0;
18587 u8 *stream_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018588 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018589 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18590 {
18591 if (unformat (input, "stream %s", &stream_name))
18592 stream_name_set = 1;
18593 else if (unformat (input, "disable"))
18594 enable = 0;
18595 else
18596 break;
18597 }
18598
18599 if (stream_name_set > 0)
18600 {
18601 if (vec_len (stream_name) > 255)
18602 {
18603 errmsg ("stream name too long");
18604 return -99;
18605 }
18606 }
18607
Damjan Marion7cd468a2016-12-19 23:05:39 +010018608 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018609 M (PG_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018610 mp->context = 0;
18611 mp->is_enabled = enable;
18612 if (stream_name_set != 0)
18613 {
Jakub Grajciardb863292020-01-30 14:14:15 +010018614 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018615 }
18616 vec_free (stream_name);
18617
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018618 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018619 W (ret);
18620 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018621}
18622
18623int
18624api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
18625{
18626 unformat_input_t *input = vam->input;
18627 vl_api_ip_source_and_port_range_check_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018628
18629 u16 *low_ports = 0;
18630 u16 *high_ports = 0;
18631 u16 this_low;
18632 u16 this_hi;
Neale Ranns37029302018-08-10 05:30:06 -070018633 vl_api_prefix_t prefix;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018634 u32 tmp, tmp2;
18635 u8 prefix_set = 0;
18636 u32 vrf_id = ~0;
18637 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018638 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018639
18640 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18641 {
Neale Ranns37029302018-08-10 05:30:06 -070018642 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
18643 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018644 else if (unformat (input, "vrf %d", &vrf_id))
18645 ;
18646 else if (unformat (input, "del"))
18647 is_add = 0;
18648 else if (unformat (input, "port %d", &tmp))
18649 {
18650 if (tmp == 0 || tmp > 65535)
18651 {
18652 errmsg ("port %d out of range", tmp);
18653 return -99;
18654 }
18655 this_low = tmp;
18656 this_hi = this_low + 1;
18657 vec_add1 (low_ports, this_low);
18658 vec_add1 (high_ports, this_hi);
18659 }
18660 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
18661 {
18662 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
18663 {
18664 errmsg ("incorrect range parameters");
18665 return -99;
18666 }
18667 this_low = tmp;
18668 /* Note: in debug CLI +1 is added to high before
18669 passing to real fn that does "the work"
18670 (ip_source_and_port_range_check_add_del).
18671 This fn is a wrapper around the binary API fn a
18672 control plane will call, which expects this increment
18673 to have occurred. Hence letting the binary API control
18674 plane fn do the increment for consistency between VAT
18675 and other control planes.
18676 */
18677 this_hi = tmp2;
18678 vec_add1 (low_ports, this_low);
18679 vec_add1 (high_ports, this_hi);
18680 }
18681 else
18682 break;
18683 }
18684
18685 if (prefix_set == 0)
18686 {
18687 errmsg ("<address>/<mask> not specified");
18688 return -99;
18689 }
18690
18691 if (vrf_id == ~0)
18692 {
18693 errmsg ("VRF ID required, not specified");
18694 return -99;
18695 }
18696
18697 if (vrf_id == 0)
18698 {
18699 errmsg
18700 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
18701 return -99;
18702 }
18703
18704 if (vec_len (low_ports) == 0)
18705 {
18706 errmsg ("At least one port or port range required");
18707 return -99;
18708 }
18709
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018710 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018711
18712 mp->is_add = is_add;
18713
Neale Ranns37029302018-08-10 05:30:06 -070018714 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018715
Damjan Marion7cd468a2016-12-19 23:05:39 +010018716 mp->number_of_ranges = vec_len (low_ports);
18717
18718 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
18719 vec_free (low_ports);
18720
18721 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
18722 vec_free (high_ports);
18723
18724 mp->vrf_id = ntohl (vrf_id);
18725
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018726 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018727 W (ret);
18728 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018729}
18730
18731int
18732api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
18733{
18734 unformat_input_t *input = vam->input;
18735 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018736 u32 sw_if_index = ~0;
18737 int vrf_set = 0;
18738 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
18739 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
18740 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018741 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018742
18743 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18744 {
18745 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18746 ;
18747 else if (unformat (input, "sw_if_index %d", &sw_if_index))
18748 ;
18749 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
18750 vrf_set = 1;
18751 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
18752 vrf_set = 1;
18753 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
18754 vrf_set = 1;
18755 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
18756 vrf_set = 1;
18757 else if (unformat (input, "del"))
18758 is_add = 0;
18759 else
18760 break;
18761 }
18762
18763 if (sw_if_index == ~0)
18764 {
18765 errmsg ("Interface required but not specified");
18766 return -99;
18767 }
18768
18769 if (vrf_set == 0)
18770 {
18771 errmsg ("VRF ID required but not specified");
18772 return -99;
18773 }
18774
18775 if (tcp_out_vrf_id == 0
18776 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
18777 {
18778 errmsg
18779 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
18780 return -99;
18781 }
18782
18783 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018784 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018785
18786 mp->sw_if_index = ntohl (sw_if_index);
18787 mp->is_add = is_add;
18788 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
18789 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
18790 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
18791 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
18792
18793 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018794 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018795
18796 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018797 W (ret);
18798 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018799}
18800
18801static int
Pavel Kotuceke88865d2018-11-28 07:42:11 +010018802api_set_punt (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018803{
18804 unformat_input_t *i = vam->input;
Neale Ranns50f0ac02019-05-15 02:13:37 -070018805 vl_api_address_family_t af;
Pavel Kotuceke88865d2018-11-28 07:42:11 +010018806 vl_api_set_punt_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018807 u32 protocol = ~0;
18808 u32 port = ~0;
18809 int is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018810 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018811
18812 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18813 {
Neale Ranns50f0ac02019-05-15 02:13:37 -070018814 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
Damjan Marion7cd468a2016-12-19 23:05:39 +010018815 ;
18816 else if (unformat (i, "protocol %d", &protocol))
18817 ;
18818 else if (unformat (i, "port %d", &port))
18819 ;
18820 else if (unformat (i, "del"))
18821 is_add = 0;
18822 else
18823 {
18824 clib_warning ("parse error '%U'", format_unformat_error, i);
18825 return -99;
18826 }
18827 }
18828
Pavel Kotuceke88865d2018-11-28 07:42:11 +010018829 M (SET_PUNT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018830
18831 mp->is_add = (u8) is_add;
Neale Ranns50f0ac02019-05-15 02:13:37 -070018832 mp->punt.type = PUNT_API_TYPE_L4;
18833 mp->punt.punt.l4.af = af;
18834 mp->punt.punt.l4.protocol = (u8) protocol;
18835 mp->punt.punt.l4.port = htons ((u16) port);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018836
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018837 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018838 W (ret);
18839 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018840}
18841
Damjan Marion7cd468a2016-12-19 23:05:39 +010018842static int
18843api_delete_subif (vat_main_t * vam)
18844{
18845 unformat_input_t *i = vam->input;
18846 vl_api_delete_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018847 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018848 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018849
18850 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18851 {
18852 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18853 ;
18854 if (unformat (i, "sw_if_index %d", &sw_if_index))
18855 ;
18856 else
18857 break;
18858 }
18859
18860 if (sw_if_index == ~0)
18861 {
18862 errmsg ("missing sw_if_index");
18863 return -99;
18864 }
18865
18866 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018867 M (DELETE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018868 mp->sw_if_index = ntohl (sw_if_index);
18869
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018870 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018871 W (ret);
18872 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018873}
18874
18875#define foreach_pbb_vtr_op \
18876_("disable", L2_VTR_DISABLED) \
18877_("pop", L2_VTR_POP_2) \
18878_("push", L2_VTR_PUSH_2)
18879
18880static int
18881api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
18882{
18883 unformat_input_t *i = vam->input;
18884 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018885 u32 sw_if_index = ~0, vtr_op = ~0;
18886 u16 outer_tag = ~0;
18887 u8 dmac[6], smac[6];
18888 u8 dmac_set = 0, smac_set = 0;
18889 u16 vlanid = 0;
18890 u32 sid = ~0;
18891 u32 tmp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018892 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018893
18894 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040018895 clib_memset (dmac, 0, sizeof (dmac));
18896 clib_memset (smac, 0, sizeof (smac));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018897
18898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18899 {
18900 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18901 ;
18902 else if (unformat (i, "sw_if_index %d", &sw_if_index))
18903 ;
18904 else if (unformat (i, "vtr_op %d", &vtr_op))
18905 ;
18906#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
18907 foreach_pbb_vtr_op
18908#undef _
18909 else if (unformat (i, "translate_pbb_stag"))
18910 {
18911 if (unformat (i, "%d", &tmp))
18912 {
18913 vtr_op = L2_VTR_TRANSLATE_2_1;
18914 outer_tag = tmp;
18915 }
18916 else
18917 {
18918 errmsg
18919 ("translate_pbb_stag operation requires outer tag definition");
18920 return -99;
18921 }
18922 }
18923 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
18924 dmac_set++;
18925 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
18926 smac_set++;
18927 else if (unformat (i, "sid %d", &sid))
18928 ;
18929 else if (unformat (i, "vlanid %d", &tmp))
18930 vlanid = tmp;
18931 else
18932 {
18933 clib_warning ("parse error '%U'", format_unformat_error, i);
18934 return -99;
18935 }
18936 }
18937
18938 if ((sw_if_index == ~0) || (vtr_op == ~0))
18939 {
18940 errmsg ("missing sw_if_index or vtr operation");
18941 return -99;
18942 }
18943 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
18944 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
18945 {
18946 errmsg
18947 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
18948 return -99;
18949 }
18950
Jon Loeliger8a2aea32017-01-31 13:19:40 -060018951 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018952 mp->sw_if_index = ntohl (sw_if_index);
18953 mp->vtr_op = ntohl (vtr_op);
18954 mp->outer_tag = ntohs (outer_tag);
18955 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
18956 clib_memcpy (mp->b_smac, smac, sizeof (smac));
18957 mp->b_vlanid = ntohs (vlanid);
18958 mp->i_sid = ntohl (sid);
18959
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018960 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060018961 W (ret);
18962 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018963}
18964
18965static int
18966api_flow_classify_set_interface (vat_main_t * vam)
18967{
18968 unformat_input_t *i = vam->input;
18969 vl_api_flow_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018970 u32 sw_if_index;
18971 int sw_if_index_set;
18972 u32 ip4_table_index = ~0;
18973 u32 ip6_table_index = ~0;
18974 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018975 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018976
18977 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18978 {
18979 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
18980 sw_if_index_set = 1;
18981 else if (unformat (i, "sw_if_index %d", &sw_if_index))
18982 sw_if_index_set = 1;
18983 else if (unformat (i, "del"))
18984 is_add = 0;
18985 else if (unformat (i, "ip4-table %d", &ip4_table_index))
18986 ;
18987 else if (unformat (i, "ip6-table %d", &ip6_table_index))
18988 ;
18989 else
18990 {
18991 clib_warning ("parse error '%U'", format_unformat_error, i);
18992 return -99;
18993 }
18994 }
18995
18996 if (sw_if_index_set == 0)
18997 {
18998 errmsg ("missing interface name or sw_if_index");
18999 return -99;
19000 }
19001
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019002 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019003
19004 mp->sw_if_index = ntohl (sw_if_index);
19005 mp->ip4_table_index = ntohl (ip4_table_index);
19006 mp->ip6_table_index = ntohl (ip6_table_index);
19007 mp->is_add = is_add;
19008
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019009 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019010 W (ret);
19011 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019012}
19013
19014static int
19015api_flow_classify_dump (vat_main_t * vam)
19016{
19017 unformat_input_t *i = vam->input;
19018 vl_api_flow_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019019 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019020 u8 type = FLOW_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019021 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019022
19023 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
19024 ;
19025 else
19026 {
19027 errmsg ("classify table type must be specified");
19028 return -99;
19029 }
19030
19031 if (!vam->json_output)
19032 {
19033 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
19034 }
19035
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019036 M (FLOW_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019037 mp->type = type;
19038 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019039 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019040
19041 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019042 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019043 S (mp_ping);
19044
Damjan Marion7cd468a2016-12-19 23:05:39 +010019045 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019046 W (ret);
19047 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019048}
19049
19050static int
19051api_feature_enable_disable (vat_main_t * vam)
19052{
19053 unformat_input_t *i = vam->input;
19054 vl_api_feature_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019055 u8 *arc_name = 0;
19056 u8 *feature_name = 0;
19057 u32 sw_if_index = ~0;
19058 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019059 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019060
19061 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19062 {
19063 if (unformat (i, "arc_name %s", &arc_name))
19064 ;
19065 else if (unformat (i, "feature_name %s", &feature_name))
19066 ;
19067 else
19068 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19069 ;
19070 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19071 ;
19072 else if (unformat (i, "disable"))
19073 enable = 0;
19074 else
19075 break;
19076 }
19077
19078 if (arc_name == 0)
19079 {
19080 errmsg ("missing arc name");
19081 return -99;
19082 }
19083 if (vec_len (arc_name) > 63)
19084 {
19085 errmsg ("arc name too long");
19086 }
19087
19088 if (feature_name == 0)
19089 {
19090 errmsg ("missing feature name");
19091 return -99;
19092 }
19093 if (vec_len (feature_name) > 63)
19094 {
19095 errmsg ("feature name too long");
19096 }
19097
19098 if (sw_if_index == ~0)
19099 {
19100 errmsg ("missing interface name or sw_if_index");
19101 return -99;
19102 }
19103
19104 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019105 M (FEATURE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019106 mp->sw_if_index = ntohl (sw_if_index);
19107 mp->enable = enable;
19108 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
19109 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
19110 vec_free (arc_name);
19111 vec_free (feature_name);
19112
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019113 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019114 W (ret);
19115 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019116}
19117
19118static int
Mohsin Kazmi29467b52019-10-08 19:42:38 +020019119api_feature_gso_enable_disable (vat_main_t * vam)
19120{
19121 unformat_input_t *i = vam->input;
19122 vl_api_feature_gso_enable_disable_t *mp;
19123 u32 sw_if_index = ~0;
19124 u8 enable = 1;
19125 int ret;
19126
19127 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19128 {
19129 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19130 ;
19131 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19132 ;
19133 else if (unformat (i, "enable"))
19134 enable = 1;
19135 else if (unformat (i, "disable"))
19136 enable = 0;
19137 else
19138 break;
19139 }
19140
19141 if (sw_if_index == ~0)
19142 {
19143 errmsg ("missing interface name or sw_if_index");
19144 return -99;
19145 }
19146
19147 /* Construct the API message */
19148 M (FEATURE_GSO_ENABLE_DISABLE, mp);
19149 mp->sw_if_index = ntohl (sw_if_index);
19150 mp->enable_disable = enable;
19151
19152 S (mp);
19153 W (ret);
19154 return ret;
19155}
19156
19157static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010019158api_sw_interface_tag_add_del (vat_main_t * vam)
19159{
19160 unformat_input_t *i = vam->input;
19161 vl_api_sw_interface_tag_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019162 u32 sw_if_index = ~0;
19163 u8 *tag = 0;
19164 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019165 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019166
19167 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19168 {
19169 if (unformat (i, "tag %s", &tag))
19170 ;
19171 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19172 ;
19173 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19174 ;
19175 else if (unformat (i, "del"))
19176 enable = 0;
19177 else
19178 break;
19179 }
19180
19181 if (sw_if_index == ~0)
19182 {
19183 errmsg ("missing interface name or sw_if_index");
19184 return -99;
19185 }
19186
19187 if (enable && (tag == 0))
19188 {
19189 errmsg ("no tag specified");
19190 return -99;
19191 }
19192
19193 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019194 M (SW_INTERFACE_TAG_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019195 mp->sw_if_index = ntohl (sw_if_index);
19196 mp->is_add = enable;
19197 if (enable)
Ole Troane5ff5a32019-08-23 22:55:18 +020019198 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019199 vec_free (tag);
19200
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019201 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019202 W (ret);
19203 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019204}
19205
Matthew Smithe0792fd2019-07-12 11:48:24 -050019206static int
19207api_sw_interface_add_del_mac_address (vat_main_t * vam)
19208{
19209 unformat_input_t *i = vam->input;
19210 vl_api_mac_address_t mac = { 0 };
19211 vl_api_sw_interface_add_del_mac_address_t *mp;
19212 u32 sw_if_index = ~0;
19213 u8 is_add = 1;
19214 u8 mac_set = 0;
19215 int ret;
19216
19217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19218 {
19219 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19220 ;
19221 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19222 ;
19223 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
19224 mac_set++;
19225 else if (unformat (i, "del"))
19226 is_add = 0;
19227 else
19228 break;
19229 }
19230
19231 if (sw_if_index == ~0)
19232 {
19233 errmsg ("missing interface name or sw_if_index");
19234 return -99;
19235 }
19236
19237 if (!mac_set)
19238 {
19239 errmsg ("missing MAC address");
19240 return -99;
19241 }
19242
19243 /* Construct the API message */
19244 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
19245 mp->sw_if_index = ntohl (sw_if_index);
19246 mp->is_add = is_add;
19247 clib_memcpy (&mp->addr, &mac, sizeof (mac));
19248
19249 S (mp);
19250 W (ret);
19251 return ret;
19252}
19253
Damjan Marion7cd468a2016-12-19 23:05:39 +010019254static void vl_api_l2_xconnect_details_t_handler
19255 (vl_api_l2_xconnect_details_t * mp)
19256{
19257 vat_main_t *vam = &vat_main;
19258
19259 print (vam->ofp, "%15d%15d",
19260 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
19261}
19262
19263static void vl_api_l2_xconnect_details_t_handler_json
19264 (vl_api_l2_xconnect_details_t * mp)
19265{
19266 vat_main_t *vam = &vat_main;
19267 vat_json_node_t *node = NULL;
19268
19269 if (VAT_JSON_ARRAY != vam->json_tree.type)
19270 {
19271 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19272 vat_json_init_array (&vam->json_tree);
19273 }
19274 node = vat_json_array_add (&vam->json_tree);
19275
19276 vat_json_init_object (node);
19277 vat_json_object_add_uint (node, "rx_sw_if_index",
19278 ntohl (mp->rx_sw_if_index));
19279 vat_json_object_add_uint (node, "tx_sw_if_index",
19280 ntohl (mp->tx_sw_if_index));
19281}
19282
19283static int
19284api_l2_xconnect_dump (vat_main_t * vam)
19285{
19286 vl_api_l2_xconnect_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019287 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019288 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019289
19290 if (!vam->json_output)
19291 {
19292 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
19293 }
19294
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019295 M (L2_XCONNECT_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019296
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019297 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019298
19299 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019300 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019301 S (mp_ping);
19302
Jon Loeliger56c7b012017-02-01 12:31:41 -060019303 W (ret);
19304 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019305}
19306
19307static int
Ole Troand7231612018-06-07 10:17:57 +020019308api_hw_interface_set_mtu (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019309{
19310 unformat_input_t *i = vam->input;
Ole Troand7231612018-06-07 10:17:57 +020019311 vl_api_hw_interface_set_mtu_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019312 u32 sw_if_index = ~0;
19313 u32 mtu = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019314 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019315
19316 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19317 {
19318 if (unformat (i, "mtu %d", &mtu))
19319 ;
19320 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19321 ;
19322 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19323 ;
19324 else
19325 break;
19326 }
19327
19328 if (sw_if_index == ~0)
19329 {
19330 errmsg ("missing interface name or sw_if_index");
19331 return -99;
19332 }
19333
19334 if (mtu == 0)
19335 {
19336 errmsg ("no mtu specified");
19337 return -99;
19338 }
19339
19340 /* Construct the API message */
Ole Troand7231612018-06-07 10:17:57 +020019341 M (HW_INTERFACE_SET_MTU, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019342 mp->sw_if_index = ntohl (sw_if_index);
19343 mp->mtu = ntohs ((u16) mtu);
19344
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019345 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019346 W (ret);
19347 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019348}
19349
Pavel Kotucek6899a302017-06-08 08:46:10 +020019350static int
19351api_p2p_ethernet_add (vat_main_t * vam)
19352{
19353 unformat_input_t *i = vam->input;
19354 vl_api_p2p_ethernet_add_t *mp;
19355 u32 parent_if_index = ~0;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019356 u32 sub_id = ~0;
Pavel Kotucek6899a302017-06-08 08:46:10 +020019357 u8 remote_mac[6];
19358 u8 mac_set = 0;
19359 int ret;
19360
Dave Barachb7b92992018-10-17 10:38:51 -040019361 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020019362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19363 {
19364 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
19365 ;
19366 else if (unformat (i, "sw_if_index %d", &parent_if_index))
19367 ;
19368 else
19369 if (unformat
19370 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
19371 mac_set++;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019372 else if (unformat (i, "sub_id %d", &sub_id))
19373 ;
Pavel Kotucek6899a302017-06-08 08:46:10 +020019374 else
19375 {
19376 clib_warning ("parse error '%U'", format_unformat_error, i);
19377 return -99;
19378 }
19379 }
19380
19381 if (parent_if_index == ~0)
19382 {
19383 errmsg ("missing interface name or sw_if_index");
19384 return -99;
19385 }
19386 if (mac_set == 0)
19387 {
19388 errmsg ("missing remote mac address");
19389 return -99;
19390 }
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019391 if (sub_id == ~0)
19392 {
19393 errmsg ("missing sub-interface id");
19394 return -99;
19395 }
Pavel Kotucek6899a302017-06-08 08:46:10 +020019396
19397 M (P2P_ETHERNET_ADD, mp);
19398 mp->parent_if_index = ntohl (parent_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020019399 mp->subif_id = ntohl (sub_id);
Pavel Kotucek6899a302017-06-08 08:46:10 +020019400 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
19401
19402 S (mp);
19403 W (ret);
19404 return ret;
19405}
19406
19407static int
19408api_p2p_ethernet_del (vat_main_t * vam)
19409{
19410 unformat_input_t *i = vam->input;
19411 vl_api_p2p_ethernet_del_t *mp;
19412 u32 parent_if_index = ~0;
19413 u8 remote_mac[6];
19414 u8 mac_set = 0;
19415 int ret;
19416
Dave Barachb7b92992018-10-17 10:38:51 -040019417 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020019418 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19419 {
19420 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
19421 ;
19422 else if (unformat (i, "sw_if_index %d", &parent_if_index))
19423 ;
19424 else
19425 if (unformat
19426 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
19427 mac_set++;
19428 else
19429 {
19430 clib_warning ("parse error '%U'", format_unformat_error, i);
19431 return -99;
19432 }
19433 }
19434
19435 if (parent_if_index == ~0)
19436 {
19437 errmsg ("missing interface name or sw_if_index");
19438 return -99;
19439 }
19440 if (mac_set == 0)
19441 {
19442 errmsg ("missing remote mac address");
19443 return -99;
19444 }
19445
19446 M (P2P_ETHERNET_DEL, mp);
19447 mp->parent_if_index = ntohl (parent_if_index);
19448 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
19449
19450 S (mp);
19451 W (ret);
19452 return ret;
19453}
Damjan Marion7cd468a2016-12-19 23:05:39 +010019454
19455static int
Steve Shin99a0e602017-07-01 04:16:20 +000019456api_lldp_config (vat_main_t * vam)
19457{
19458 unformat_input_t *i = vam->input;
19459 vl_api_lldp_config_t *mp;
19460 int tx_hold = 0;
19461 int tx_interval = 0;
19462 u8 *sys_name = NULL;
19463 int ret;
19464
19465 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19466 {
19467 if (unformat (i, "system-name %s", &sys_name))
19468 ;
19469 else if (unformat (i, "tx-hold %d", &tx_hold))
19470 ;
19471 else if (unformat (i, "tx-interval %d", &tx_interval))
19472 ;
19473 else
19474 {
19475 clib_warning ("parse error '%U'", format_unformat_error, i);
19476 return -99;
19477 }
19478 }
19479
19480 vec_add1 (sys_name, 0);
19481
19482 M (LLDP_CONFIG, mp);
19483 mp->tx_hold = htonl (tx_hold);
19484 mp->tx_interval = htonl (tx_interval);
Jakub Grajciar1c684f92020-01-30 14:01:17 +010019485 vl_api_vec_to_api_string (sys_name, &mp->system_name);
Steve Shin99a0e602017-07-01 04:16:20 +000019486 vec_free (sys_name);
19487
19488 S (mp);
19489 W (ret);
19490 return ret;
19491}
19492
19493static int
19494api_sw_interface_set_lldp (vat_main_t * vam)
19495{
19496 unformat_input_t *i = vam->input;
19497 vl_api_sw_interface_set_lldp_t *mp;
19498 u32 sw_if_index = ~0;
19499 u32 enable = 1;
Steve Shin9a6fcef2017-10-11 13:55:16 -070019500 u8 *port_desc = NULL, *mgmt_oid = NULL;
19501 ip4_address_t ip4_addr;
19502 ip6_address_t ip6_addr;
Steve Shin99a0e602017-07-01 04:16:20 +000019503 int ret;
19504
Dave Barachb7b92992018-10-17 10:38:51 -040019505 clib_memset (&ip4_addr, 0, sizeof (ip4_addr));
19506 clib_memset (&ip6_addr, 0, sizeof (ip6_addr));
Steve Shin9a6fcef2017-10-11 13:55:16 -070019507
Steve Shin99a0e602017-07-01 04:16:20 +000019508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19509 {
19510 if (unformat (i, "disable"))
19511 enable = 0;
19512 else
19513 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19514 ;
19515 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19516 ;
19517 else if (unformat (i, "port-desc %s", &port_desc))
19518 ;
Steve Shin9a6fcef2017-10-11 13:55:16 -070019519 else if (unformat (i, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
19520 ;
19521 else if (unformat (i, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
19522 ;
19523 else if (unformat (i, "mgmt-oid %s", &mgmt_oid))
19524 ;
Steve Shin99a0e602017-07-01 04:16:20 +000019525 else
19526 break;
19527 }
19528
19529 if (sw_if_index == ~0)
19530 {
19531 errmsg ("missing interface name or sw_if_index");
19532 return -99;
19533 }
19534
19535 /* Construct the API message */
19536 vec_add1 (port_desc, 0);
Steve Shin9a6fcef2017-10-11 13:55:16 -070019537 vec_add1 (mgmt_oid, 0);
Steve Shin99a0e602017-07-01 04:16:20 +000019538 M (SW_INTERFACE_SET_LLDP, mp);
19539 mp->sw_if_index = ntohl (sw_if_index);
19540 mp->enable = enable;
Jakub Grajciar1c684f92020-01-30 14:01:17 +010019541 vl_api_vec_to_api_string (port_desc, &mp->port_desc);
Steve Shin9a6fcef2017-10-11 13:55:16 -070019542 clib_memcpy (mp->mgmt_oid, mgmt_oid, vec_len (mgmt_oid));
19543 clib_memcpy (mp->mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
19544 clib_memcpy (mp->mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
Steve Shin99a0e602017-07-01 04:16:20 +000019545 vec_free (port_desc);
Steve Shin9a6fcef2017-10-11 13:55:16 -070019546 vec_free (mgmt_oid);
Steve Shin99a0e602017-07-01 04:16:20 +000019547
19548 S (mp);
19549 W (ret);
19550 return ret;
19551}
19552
19553static int
Dave Barach3bbcfab2017-08-15 19:03:44 -040019554api_tcp_configure_src_addresses (vat_main_t * vam)
19555{
19556 vl_api_tcp_configure_src_addresses_t *mp;
19557 unformat_input_t *i = vam->input;
Neale Rannscbe25aa2019-09-30 10:53:31 +000019558 vl_api_address_t first, last;
Dave Barach3bbcfab2017-08-15 19:03:44 -040019559 u8 range_set = 0;
19560 u32 vrf_id = 0;
19561 int ret;
19562
19563 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19564 {
19565 if (unformat (i, "%U - %U",
Neale Rannscbe25aa2019-09-30 10:53:31 +000019566 unformat_vl_api_address, &first,
19567 unformat_vl_api_address, &last))
Dave Barach3bbcfab2017-08-15 19:03:44 -040019568 {
19569 if (range_set)
19570 {
19571 errmsg ("one range per message (range already set)");
19572 return -99;
19573 }
19574 range_set = 1;
19575 }
Dave Barach3bbcfab2017-08-15 19:03:44 -040019576 else if (unformat (i, "vrf %d", &vrf_id))
19577 ;
19578 else
19579 break;
19580 }
19581
19582 if (range_set == 0)
19583 {
19584 errmsg ("address range not set");
19585 return -99;
19586 }
19587
19588 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
Neale Rannscbe25aa2019-09-30 10:53:31 +000019589
Dave Barach3bbcfab2017-08-15 19:03:44 -040019590 mp->vrf_id = ntohl (vrf_id);
Neale Rannscbe25aa2019-09-30 10:53:31 +000019591 clib_memcpy (&mp->first_address, &first, sizeof (first));
19592 clib_memcpy (&mp->last_address, &last, sizeof (last));
19593
Dave Barach3bbcfab2017-08-15 19:03:44 -040019594 S (mp);
19595 W (ret);
19596 return ret;
19597}
19598
Florin Coras6e8c6672017-11-10 09:03:54 -080019599static void vl_api_app_namespace_add_del_reply_t_handler
19600 (vl_api_app_namespace_add_del_reply_t * mp)
19601{
19602 vat_main_t *vam = &vat_main;
19603 i32 retval = ntohl (mp->retval);
19604 if (vam->async_mode)
19605 {
19606 vam->async_errors += (retval < 0);
19607 }
19608 else
19609 {
19610 vam->retval = retval;
19611 if (retval == 0)
19612 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
19613 vam->result_ready = 1;
19614 }
19615}
19616
19617static void vl_api_app_namespace_add_del_reply_t_handler_json
19618 (vl_api_app_namespace_add_del_reply_t * mp)
19619{
19620 vat_main_t *vam = &vat_main;
19621 vat_json_node_t node;
19622
19623 vat_json_init_object (&node);
19624 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
19625 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
19626
19627 vat_json_print (vam->ofp, &node);
19628 vat_json_free (&node);
19629
19630 vam->retval = ntohl (mp->retval);
19631 vam->result_ready = 1;
19632}
19633
Dave Barach3bbcfab2017-08-15 19:03:44 -040019634static int
Florin Corascea194d2017-10-02 00:18:51 -070019635api_app_namespace_add_del (vat_main_t * vam)
19636{
19637 vl_api_app_namespace_add_del_t *mp;
19638 unformat_input_t *i = vam->input;
19639 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
19640 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
19641 u64 secret;
19642 int ret;
19643
19644 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19645 {
19646 if (unformat (i, "id %_%v%_", &ns_id))
19647 ;
19648 else if (unformat (i, "secret %lu", &secret))
19649 secret_set = 1;
19650 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19651 sw_if_index_set = 1;
19652 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
19653 ;
19654 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
19655 ;
19656 else
19657 break;
19658 }
19659 if (!ns_id || !secret_set || !sw_if_index_set)
19660 {
19661 errmsg ("namespace id, secret and sw_if_index must be set");
19662 return -99;
19663 }
19664 if (vec_len (ns_id) > 64)
19665 {
19666 errmsg ("namespace id too long");
19667 return -99;
19668 }
19669 M (APP_NAMESPACE_ADD_DEL, mp);
19670
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019671 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
Florin Coras9a9adb22017-10-26 08:16:59 -070019672 mp->secret = clib_host_to_net_u64 (secret);
Florin Corascea194d2017-10-02 00:18:51 -070019673 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
19674 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
19675 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
19676 vec_free (ns_id);
19677 S (mp);
19678 W (ret);
19679 return ret;
19680}
19681
19682static int
Florin Coras90a63982017-12-19 04:50:01 -080019683api_sock_init_shm (vat_main_t * vam)
19684{
19685#if VPP_API_TEST_BUILTIN == 0
19686 unformat_input_t *i = vam->input;
19687 vl_api_shm_elem_config_t *config = 0;
19688 u64 size = 64 << 20;
19689 int rv;
19690
19691 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19692 {
19693 if (unformat (i, "size %U", unformat_memory_size, &size))
19694 ;
19695 else
19696 break;
19697 }
19698
Dave Barach78958722018-05-10 16:44:27 -040019699 /*
19700 * Canned custom ring allocator config.
19701 * Should probably parse all of this
19702 */
19703 vec_validate (config, 6);
Florin Coras90a63982017-12-19 04:50:01 -080019704 config[0].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080019705 config[0].size = 256;
Dave Barach78958722018-05-10 16:44:27 -040019706 config[0].count = 32;
19707
19708 config[1].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080019709 config[1].size = 1024;
Dave Barach78958722018-05-10 16:44:27 -040019710 config[1].count = 16;
19711
19712 config[2].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080019713 config[2].size = 4096;
Dave Barach78958722018-05-10 16:44:27 -040019714 config[2].count = 2;
19715
19716 config[3].type = VL_API_CLIENT_RING;
19717 config[3].size = 256;
19718 config[3].count = 32;
19719
19720 config[4].type = VL_API_CLIENT_RING;
19721 config[4].size = 1024;
19722 config[4].count = 16;
19723
19724 config[5].type = VL_API_CLIENT_RING;
19725 config[5].size = 4096;
19726 config[5].count = 2;
19727
19728 config[6].type = VL_API_QUEUE;
19729 config[6].count = 128;
19730 config[6].size = sizeof (uword);
19731
Tomasz Kulasek97dcf5b2019-01-31 18:26:32 +010019732 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
Florin Coras90a63982017-12-19 04:50:01 -080019733 if (!rv)
19734 vam->client_index_invalid = 1;
19735 return rv;
19736#else
19737 return -99;
19738#endif
19739}
19740
Florin Coras6c36f532017-11-03 18:32:34 -070019741static void
19742vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
19743{
19744 vat_main_t *vam = &vat_main;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019745 fib_prefix_t lcl, rmt;
Florin Coras6c36f532017-11-03 18:32:34 -070019746
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019747 ip_prefix_decode (&mp->lcl, &lcl);
19748 ip_prefix_decode (&mp->rmt, &rmt);
19749
19750 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -070019751 {
Florin Corasc97a7392017-11-05 23:07:07 -080019752 print (vam->ofp,
19753 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080019754 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019755 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
Steven85dbac02017-11-07 16:29:53 -080019756 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019757 &rmt.fp_addr.ip4, rmt.fp_len,
19758 clib_net_to_host_u16 (mp->rmt_port),
Steven85dbac02017-11-07 16:29:53 -080019759 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070019760 }
19761 else
19762 {
Florin Corasc97a7392017-11-05 23:07:07 -080019763 print (vam->ofp,
19764 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080019765 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019766 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
Steven85dbac02017-11-07 16:29:53 -080019767 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019768 &rmt.fp_addr.ip6, rmt.fp_len,
19769 clib_net_to_host_u16 (mp->rmt_port),
Steven85dbac02017-11-07 16:29:53 -080019770 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070019771 }
19772}
19773
19774static void
19775vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
19776 mp)
19777{
19778 vat_main_t *vam = &vat_main;
19779 vat_json_node_t *node = NULL;
19780 struct in6_addr ip6;
19781 struct in_addr ip4;
19782
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019783 fib_prefix_t lcl, rmt;
19784
19785 ip_prefix_decode (&mp->lcl, &lcl);
19786 ip_prefix_decode (&mp->rmt, &rmt);
19787
Florin Coras6c36f532017-11-03 18:32:34 -070019788 if (VAT_JSON_ARRAY != vam->json_tree.type)
19789 {
19790 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19791 vat_json_init_array (&vam->json_tree);
19792 }
19793 node = vat_json_array_add (&vam->json_tree);
19794 vat_json_init_object (node);
19795
Florin Coras6c36f532017-11-03 18:32:34 -070019796 vat_json_object_add_uint (node, "appns_index",
19797 clib_net_to_host_u32 (mp->appns_index));
19798 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
19799 vat_json_object_add_uint (node, "scope", mp->scope);
19800 vat_json_object_add_uint (node, "action_index",
19801 clib_net_to_host_u32 (mp->action_index));
19802 vat_json_object_add_uint (node, "lcl_port",
19803 clib_net_to_host_u16 (mp->lcl_port));
19804 vat_json_object_add_uint (node, "rmt_port",
19805 clib_net_to_host_u16 (mp->rmt_port));
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019806 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
19807 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
Florin Corasc97a7392017-11-05 23:07:07 -080019808 vat_json_object_add_string_copy (node, "tag", mp->tag);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019809 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -070019810 {
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019811 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
Florin Coras6c36f532017-11-03 18:32:34 -070019812 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019813 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
Florin Coras6c36f532017-11-03 18:32:34 -070019814 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
19815 }
19816 else
19817 {
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019818 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
Florin Coras6c36f532017-11-03 18:32:34 -070019819 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019820 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
Florin Coras6c36f532017-11-03 18:32:34 -070019821 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
19822 }
19823}
19824
Florin Coras1c710452017-10-17 00:03:13 -070019825static int
19826api_session_rule_add_del (vat_main_t * vam)
19827{
19828 vl_api_session_rule_add_del_t *mp;
19829 unformat_input_t *i = vam->input;
19830 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
19831 u32 appns_index = 0, scope = 0;
19832 ip4_address_t lcl_ip4, rmt_ip4;
19833 ip6_address_t lcl_ip6, rmt_ip6;
19834 u8 is_ip4 = 1, conn_set = 0;
Florin Corasc97a7392017-11-05 23:07:07 -080019835 u8 is_add = 1, *tag = 0;
Florin Coras1c710452017-10-17 00:03:13 -070019836 int ret;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019837 fib_prefix_t lcl, rmt;
Florin Coras1c710452017-10-17 00:03:13 -070019838
19839 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19840 {
19841 if (unformat (i, "del"))
19842 is_add = 0;
19843 else if (unformat (i, "add"))
19844 ;
19845 else if (unformat (i, "proto tcp"))
19846 proto = 0;
19847 else if (unformat (i, "proto udp"))
19848 proto = 1;
19849 else if (unformat (i, "appns %d", &appns_index))
19850 ;
19851 else if (unformat (i, "scope %d", &scope))
19852 ;
Florin Corasc97a7392017-11-05 23:07:07 -080019853 else if (unformat (i, "tag %_%v%_", &tag))
19854 ;
Florin Coras1c710452017-10-17 00:03:13 -070019855 else
19856 if (unformat
19857 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
19858 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
19859 &rmt_port))
19860 {
19861 is_ip4 = 1;
19862 conn_set = 1;
19863 }
19864 else
19865 if (unformat
19866 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
19867 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
19868 &rmt_port))
19869 {
19870 is_ip4 = 0;
19871 conn_set = 1;
19872 }
19873 else if (unformat (i, "action %d", &action))
19874 ;
19875 else
19876 break;
19877 }
19878 if (proto == ~0 || !conn_set || action == ~0)
19879 {
19880 errmsg ("transport proto, connection and action must be set");
19881 return -99;
19882 }
19883
19884 if (scope > 3)
19885 {
19886 errmsg ("scope should be 0-3");
19887 return -99;
19888 }
19889
19890 M (SESSION_RULE_ADD_DEL, mp);
19891
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019892 clib_memset (&lcl, 0, sizeof (lcl));
19893 clib_memset (&rmt, 0, sizeof (rmt));
19894 if (is_ip4)
19895 {
19896 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
19897 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
19898 lcl.fp_len = lcl_plen;
19899 rmt.fp_len = rmt_plen;
19900 }
19901 else
19902 {
19903 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
19904 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
19905 lcl.fp_len = lcl_plen;
19906 rmt.fp_len = rmt_plen;
19907 }
19908
19909
19910 ip_prefix_encode (&lcl, &mp->lcl);
19911 ip_prefix_encode (&rmt, &mp->rmt);
Florin Corasc97a7392017-11-05 23:07:07 -080019912 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
19913 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010019914 mp->transport_proto =
19915 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
Florin Coras1c710452017-10-17 00:03:13 -070019916 mp->action_index = clib_host_to_net_u32 (action);
19917 mp->appns_index = clib_host_to_net_u32 (appns_index);
19918 mp->scope = scope;
19919 mp->is_add = is_add;
Florin Corasc97a7392017-11-05 23:07:07 -080019920 if (tag)
19921 {
19922 clib_memcpy (mp->tag, tag, vec_len (tag));
19923 vec_free (tag);
19924 }
Florin Coras1c710452017-10-17 00:03:13 -070019925
19926 S (mp);
19927 W (ret);
19928 return ret;
19929}
Dave Barach65457162017-10-10 17:53:14 -040019930
19931static int
Florin Coras6c36f532017-11-03 18:32:34 -070019932api_session_rules_dump (vat_main_t * vam)
19933{
19934 vl_api_session_rules_dump_t *mp;
19935 vl_api_control_ping_t *mp_ping;
19936 int ret;
19937
19938 if (!vam->json_output)
19939 {
19940 print (vam->ofp, "%=20s", "Session Rules");
19941 }
19942
19943 M (SESSION_RULES_DUMP, mp);
19944 /* send it... */
19945 S (mp);
19946
19947 /* Use a control ping for synchronization */
19948 MPING (CONTROL_PING, mp_ping);
19949 S (mp_ping);
19950
19951 /* Wait for a reply... */
19952 W (ret);
19953 return ret;
19954}
19955
19956static int
Florin Coras595992c2017-11-06 17:17:08 -080019957api_ip_container_proxy_add_del (vat_main_t * vam)
19958{
19959 vl_api_ip_container_proxy_add_del_t *mp;
19960 unformat_input_t *i = vam->input;
Neale Ranns37029302018-08-10 05:30:06 -070019961 u32 sw_if_index = ~0;
19962 vl_api_prefix_t pfx = { };
Florin Coras595992c2017-11-06 17:17:08 -080019963 u8 is_add = 1;
19964 int ret;
19965
19966 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19967 {
19968 if (unformat (i, "del"))
19969 is_add = 0;
19970 else if (unformat (i, "add"))
19971 ;
Neale Ranns37029302018-08-10 05:30:06 -070019972 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
19973 ;
Florin Coras595992c2017-11-06 17:17:08 -080019974 else if (unformat (i, "sw_if_index %u", &sw_if_index))
19975 ;
19976 else
19977 break;
19978 }
Paul Vinciguerraab055082019-06-06 14:07:55 -040019979 if (sw_if_index == ~0 || pfx.len == 0)
Florin Coras595992c2017-11-06 17:17:08 -080019980 {
19981 errmsg ("address and sw_if_index must be set");
19982 return -99;
19983 }
19984
19985 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
19986
Florin Coras595992c2017-11-06 17:17:08 -080019987 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
Florin Coras595992c2017-11-06 17:17:08 -080019988 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -070019989 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
Florin Coras595992c2017-11-06 17:17:08 -080019990
19991 S (mp);
19992 W (ret);
19993 return ret;
19994}
19995
19996static int
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070019997api_qos_record_enable_disable (vat_main_t * vam)
19998{
19999 unformat_input_t *i = vam->input;
20000 vl_api_qos_record_enable_disable_t *mp;
20001 u32 sw_if_index, qs = 0xff;
20002 u8 sw_if_index_set = 0;
20003 u8 enable = 1;
20004 int ret;
20005
20006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20007 {
20008 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20009 sw_if_index_set = 1;
20010 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20011 sw_if_index_set = 1;
20012 else if (unformat (i, "%U", unformat_qos_source, &qs))
20013 ;
20014 else if (unformat (i, "disable"))
20015 enable = 0;
20016 else
20017 {
20018 clib_warning ("parse error '%U'", format_unformat_error, i);
20019 return -99;
20020 }
20021 }
20022
20023 if (sw_if_index_set == 0)
20024 {
20025 errmsg ("missing interface name or sw_if_index");
20026 return -99;
20027 }
20028 if (qs == 0xff)
20029 {
20030 errmsg ("input location must be specified");
20031 return -99;
20032 }
20033
20034 M (QOS_RECORD_ENABLE_DISABLE, mp);
20035
Neale Ranns5281a902019-07-23 08:16:19 -070020036 mp->record.sw_if_index = ntohl (sw_if_index);
20037 mp->record.input_source = qs;
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070020038 mp->enable = enable;
20039
20040 S (mp);
20041 W (ret);
20042 return ret;
20043}
20044
Dave Barach048a4e52018-06-01 18:52:25 -040020045
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070020046static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010020047q_or_quit (vat_main_t * vam)
20048{
Dave Barachdef19da2017-02-22 17:29:20 -050020049#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010020050 longjmp (vam->jump_buf, 1);
Dave Barachdef19da2017-02-22 17:29:20 -050020051#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010020052 return 0; /* not so much */
20053}
20054
20055static int
20056q (vat_main_t * vam)
20057{
20058 return q_or_quit (vam);
20059}
20060
20061static int
20062quit (vat_main_t * vam)
20063{
20064 return q_or_quit (vam);
20065}
20066
20067static int
20068comment (vat_main_t * vam)
20069{
20070 return 0;
20071}
20072
20073static int
Dave Barachb09f4d02019-07-15 16:00:03 -040020074elog_save (vat_main_t * vam)
20075{
20076#if VPP_API_TEST_BUILTIN == 0
20077 elog_main_t *em = &vam->elog_main;
20078 unformat_input_t *i = vam->input;
20079 char *file, *chroot_file;
20080 clib_error_t *error;
20081
20082 if (!unformat (i, "%s", &file))
20083 {
20084 errmsg ("expected file name, got `%U'", format_unformat_error, i);
20085 return 0;
20086 }
20087
20088 /* It's fairly hard to get "../oopsie" through unformat; just in case */
20089 if (strstr (file, "..") || index (file, '/'))
20090 {
20091 errmsg ("illegal characters in filename '%s'", file);
20092 return 0;
20093 }
20094
20095 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
20096
20097 vec_free (file);
20098
20099 errmsg ("Saving %wd of %wd events to %s",
20100 elog_n_events_in_buffer (em),
20101 elog_buffer_capacity (em), chroot_file);
20102
20103 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
20104 vec_free (chroot_file);
20105
20106 if (error)
20107 clib_error_report (error);
20108#else
20109 errmsg ("Use the vpp event loger...");
20110#endif
20111
20112 return 0;
20113}
20114
20115static int
20116elog_setup (vat_main_t * vam)
20117{
20118#if VPP_API_TEST_BUILTIN == 0
20119 elog_main_t *em = &vam->elog_main;
20120 unformat_input_t *i = vam->input;
20121 u32 nevents = 128 << 10;
20122
20123 (void) unformat (i, "nevents %d", &nevents);
20124
20125 elog_init (em, nevents);
20126 vl_api_set_elog_main (em);
20127 vl_api_set_elog_trace_api_messages (1);
20128 errmsg ("Event logger initialized with %u events", nevents);
20129#else
20130 errmsg ("Use the vpp event loger...");
20131#endif
20132 return 0;
20133}
20134
20135static int
20136elog_enable (vat_main_t * vam)
20137{
20138#if VPP_API_TEST_BUILTIN == 0
20139 elog_main_t *em = &vam->elog_main;
20140
20141 elog_enable_disable (em, 1 /* enable */ );
20142 vl_api_set_elog_trace_api_messages (1);
20143 errmsg ("Event logger enabled...");
20144#else
20145 errmsg ("Use the vpp event loger...");
20146#endif
20147 return 0;
20148}
20149
20150static int
20151elog_disable (vat_main_t * vam)
20152{
20153#if VPP_API_TEST_BUILTIN == 0
20154 elog_main_t *em = &vam->elog_main;
20155
20156 elog_enable_disable (em, 0 /* enable */ );
20157 vl_api_set_elog_trace_api_messages (1);
20158 errmsg ("Event logger disabled...");
20159#else
20160 errmsg ("Use the vpp event loger...");
20161#endif
20162 return 0;
20163}
20164
20165static int
Dave Barach048a4e52018-06-01 18:52:25 -040020166statseg (vat_main_t * vam)
20167{
20168 ssvm_private_t *ssvmp = &vam->stat_segment;
20169 ssvm_shared_header_t *shared_header = ssvmp->sh;
20170 vlib_counter_t **counters;
20171 u64 thread0_index1_packets;
20172 u64 thread0_index1_bytes;
20173 f64 vector_rate, input_rate;
20174 uword *p;
20175
20176 uword *counter_vector_by_name;
20177 if (vam->stat_segment_lockp == 0)
20178 {
20179 errmsg ("Stat segment not mapped...");
20180 return -99;
20181 }
20182
20183 /* look up "/if/rx for sw_if_index 1 as a test */
20184
20185 clib_spinlock_lock (vam->stat_segment_lockp);
20186
20187 counter_vector_by_name = (uword *) shared_header->opaque[1];
20188
20189 p = hash_get_mem (counter_vector_by_name, "/if/rx");
20190 if (p == 0)
20191 {
20192 clib_spinlock_unlock (vam->stat_segment_lockp);
20193 errmsg ("/if/tx not found?");
20194 return -99;
20195 }
20196
20197 /* Fish per-thread vector of combined counters from shared memory */
20198 counters = (vlib_counter_t **) p[0];
20199
20200 if (vec_len (counters[0]) < 2)
20201 {
20202 clib_spinlock_unlock (vam->stat_segment_lockp);
20203 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
20204 return -99;
20205 }
20206
20207 /* Read thread 0 sw_if_index 1 counter */
20208 thread0_index1_packets = counters[0][1].packets;
20209 thread0_index1_bytes = counters[0][1].bytes;
20210
20211 p = hash_get_mem (counter_vector_by_name, "vector_rate");
20212 if (p == 0)
20213 {
20214 clib_spinlock_unlock (vam->stat_segment_lockp);
20215 errmsg ("vector_rate not found?");
20216 return -99;
20217 }
20218
20219 vector_rate = *(f64 *) (p[0]);
20220 p = hash_get_mem (counter_vector_by_name, "input_rate");
20221 if (p == 0)
20222 {
20223 clib_spinlock_unlock (vam->stat_segment_lockp);
20224 errmsg ("input_rate not found?");
20225 return -99;
20226 }
20227 input_rate = *(f64 *) (p[0]);
20228
20229 clib_spinlock_unlock (vam->stat_segment_lockp);
20230
20231 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
20232 vector_rate, input_rate);
20233 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
20234 thread0_index1_packets, thread0_index1_bytes);
20235
20236 return 0;
20237}
20238
20239static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010020240cmd_cmp (void *a1, void *a2)
20241{
20242 u8 **c1 = a1;
20243 u8 **c2 = a2;
20244
20245 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
20246}
20247
20248static int
20249help (vat_main_t * vam)
20250{
20251 u8 **cmds = 0;
20252 u8 *name = 0;
20253 hash_pair_t *p;
20254 unformat_input_t *i = vam->input;
20255 int j;
20256
20257 if (unformat (i, "%s", &name))
20258 {
20259 uword *hs;
20260
20261 vec_add1 (name, 0);
20262
20263 hs = hash_get_mem (vam->help_by_name, name);
20264 if (hs)
20265 print (vam->ofp, "usage: %s %s", name, hs[0]);
20266 else
20267 print (vam->ofp, "No such msg / command '%s'", name);
20268 vec_free (name);
20269 return 0;
20270 }
20271
20272 print (vam->ofp, "Help is available for the following:");
20273
20274 /* *INDENT-OFF* */
20275 hash_foreach_pair (p, vam->function_by_name,
20276 ({
20277 vec_add1 (cmds, (u8 *)(p->key));
20278 }));
20279 /* *INDENT-ON* */
20280
20281 vec_sort_with_function (cmds, cmd_cmp);
20282
20283 for (j = 0; j < vec_len (cmds); j++)
20284 print (vam->ofp, "%s", cmds[j]);
20285
20286 vec_free (cmds);
20287 return 0;
20288}
20289
20290static int
20291set (vat_main_t * vam)
20292{
20293 u8 *name = 0, *value = 0;
20294 unformat_input_t *i = vam->input;
20295
20296 if (unformat (i, "%s", &name))
20297 {
20298 /* The input buffer is a vector, not a string. */
20299 value = vec_dup (i->buffer);
20300 vec_delete (value, i->index, 0);
20301 /* Almost certainly has a trailing newline */
20302 if (value[vec_len (value) - 1] == '\n')
20303 value[vec_len (value) - 1] = 0;
20304 /* Make sure it's a proper string, one way or the other */
20305 vec_add1 (value, 0);
20306 (void) clib_macro_set_value (&vam->macro_main,
20307 (char *) name, (char *) value);
20308 }
20309 else
20310 errmsg ("usage: set <name> <value>");
20311
20312 vec_free (name);
20313 vec_free (value);
20314 return 0;
20315}
20316
20317static int
20318unset (vat_main_t * vam)
20319{
20320 u8 *name = 0;
20321
20322 if (unformat (vam->input, "%s", &name))
20323 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
20324 errmsg ("unset: %s wasn't set", name);
20325 vec_free (name);
20326 return 0;
20327}
20328
20329typedef struct
20330{
20331 u8 *name;
20332 u8 *value;
20333} macro_sort_t;
20334
20335
20336static int
20337macro_sort_cmp (void *a1, void *a2)
20338{
20339 macro_sort_t *s1 = a1;
20340 macro_sort_t *s2 = a2;
20341
20342 return strcmp ((char *) (s1->name), (char *) (s2->name));
20343}
20344
20345static int
20346dump_macro_table (vat_main_t * vam)
20347{
20348 macro_sort_t *sort_me = 0, *sm;
20349 int i;
20350 hash_pair_t *p;
20351
20352 /* *INDENT-OFF* */
20353 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
20354 ({
20355 vec_add2 (sort_me, sm, 1);
20356 sm->name = (u8 *)(p->key);
20357 sm->value = (u8 *) (p->value[0]);
20358 }));
20359 /* *INDENT-ON* */
20360
20361 vec_sort_with_function (sort_me, macro_sort_cmp);
20362
20363 if (vec_len (sort_me))
20364 print (vam->ofp, "%-15s%s", "Name", "Value");
20365 else
20366 print (vam->ofp, "The macro table is empty...");
20367
20368 for (i = 0; i < vec_len (sort_me); i++)
20369 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
20370 return 0;
20371}
20372
20373static int
20374dump_node_table (vat_main_t * vam)
20375{
20376 int i, j;
20377 vlib_node_t *node, *next_node;
20378
20379 if (vec_len (vam->graph_nodes) == 0)
20380 {
20381 print (vam->ofp, "Node table empty, issue get_node_graph...");
20382 return 0;
20383 }
20384
Dave Barach1ddbc012018-06-13 09:26:05 -040020385 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010020386 {
Dave Barach1ddbc012018-06-13 09:26:05 -040020387 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020388 print (vam->ofp, "[%d] %s", i, node->name);
20389 for (j = 0; j < vec_len (node->next_nodes); j++)
20390 {
20391 if (node->next_nodes[j] != ~0)
20392 {
Dave Barach1ddbc012018-06-13 09:26:05 -040020393 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020394 print (vam->ofp, " [%d] %s", j, next_node->name);
20395 }
20396 }
20397 }
20398 return 0;
20399}
20400
20401static int
20402value_sort_cmp (void *a1, void *a2)
20403{
20404 name_sort_t *n1 = a1;
20405 name_sort_t *n2 = a2;
20406
20407 if (n1->value < n2->value)
20408 return -1;
20409 if (n1->value > n2->value)
20410 return 1;
20411 return 0;
20412}
20413
20414
20415static int
20416dump_msg_api_table (vat_main_t * vam)
20417{
Dave Barach39d69112019-11-27 11:42:13 -050020418 api_main_t *am = vlibapi_get_main ();
Damjan Marion7cd468a2016-12-19 23:05:39 +010020419 name_sort_t *nses = 0, *ns;
20420 hash_pair_t *hp;
20421 int i;
20422
20423 /* *INDENT-OFF* */
20424 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
20425 ({
20426 vec_add2 (nses, ns, 1);
20427 ns->name = (u8 *)(hp->key);
20428 ns->value = (u32) hp->value[0];
20429 }));
20430 /* *INDENT-ON* */
20431
20432 vec_sort_with_function (nses, value_sort_cmp);
20433
20434 for (i = 0; i < vec_len (nses); i++)
20435 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
20436 vec_free (nses);
20437 return 0;
20438}
20439
20440static int
20441get_msg_id (vat_main_t * vam)
20442{
20443 u8 *name_and_crc;
20444 u32 message_index;
20445
20446 if (unformat (vam->input, "%s", &name_and_crc))
20447 {
Florin Corase86a8ed2018-01-05 03:20:25 -080020448 message_index = vl_msg_api_get_msg_index (name_and_crc);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020449 if (message_index == ~0)
20450 {
20451 print (vam->ofp, " '%s' not found", name_and_crc);
20452 return 0;
20453 }
20454 print (vam->ofp, " '%s' has message index %d",
20455 name_and_crc, message_index);
20456 return 0;
20457 }
20458 errmsg ("name_and_crc required...");
20459 return 0;
20460}
20461
20462static int
20463search_node_table (vat_main_t * vam)
20464{
20465 unformat_input_t *line_input = vam->input;
20466 u8 *node_to_find;
20467 int j;
20468 vlib_node_t *node, *next_node;
20469 uword *p;
20470
20471 if (vam->graph_node_index_by_name == 0)
20472 {
20473 print (vam->ofp, "Node table empty, issue get_node_graph...");
20474 return 0;
20475 }
20476
20477 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
20478 {
20479 if (unformat (line_input, "%s", &node_to_find))
20480 {
20481 vec_add1 (node_to_find, 0);
20482 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
20483 if (p == 0)
20484 {
20485 print (vam->ofp, "%s not found...", node_to_find);
20486 goto out;
20487 }
Dave Barach1ddbc012018-06-13 09:26:05 -040020488 node = vam->graph_nodes[0][p[0]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020489 print (vam->ofp, "[%d] %s", p[0], node->name);
20490 for (j = 0; j < vec_len (node->next_nodes); j++)
20491 {
20492 if (node->next_nodes[j] != ~0)
20493 {
Dave Barach1ddbc012018-06-13 09:26:05 -040020494 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010020495 print (vam->ofp, " [%d] %s", j, next_node->name);
20496 }
20497 }
20498 }
20499
20500 else
20501 {
20502 clib_warning ("parse error '%U'", format_unformat_error,
20503 line_input);
20504 return -99;
20505 }
20506
20507 out:
20508 vec_free (node_to_find);
20509
20510 }
20511
20512 return 0;
20513}
20514
20515
20516static int
20517script (vat_main_t * vam)
20518{
20519#if (VPP_API_TEST_BUILTIN==0)
20520 u8 *s = 0;
20521 char *save_current_file;
20522 unformat_input_t save_input;
20523 jmp_buf save_jump_buf;
20524 u32 save_line_number;
20525
20526 FILE *new_fp, *save_ifp;
20527
20528 if (unformat (vam->input, "%s", &s))
20529 {
20530 new_fp = fopen ((char *) s, "r");
20531 if (new_fp == 0)
20532 {
20533 errmsg ("Couldn't open script file %s", s);
20534 vec_free (s);
20535 return -99;
20536 }
20537 }
20538 else
20539 {
20540 errmsg ("Missing script name");
20541 return -99;
20542 }
20543
20544 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
20545 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
20546 save_ifp = vam->ifp;
20547 save_line_number = vam->input_line_number;
20548 save_current_file = (char *) vam->current_file;
20549
20550 vam->input_line_number = 0;
20551 vam->ifp = new_fp;
20552 vam->current_file = s;
20553 do_one_file (vam);
20554
Sirshak Dasb0861822018-05-29 21:13:21 -050020555 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020556 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
20557 vam->ifp = save_ifp;
20558 vam->input_line_number = save_line_number;
20559 vam->current_file = (u8 *) save_current_file;
20560 vec_free (s);
20561
20562 return 0;
20563#else
20564 clib_warning ("use the exec command...");
20565 return -99;
20566#endif
20567}
20568
20569static int
20570echo (vat_main_t * vam)
20571{
20572 print (vam->ofp, "%v", vam->input->buffer);
20573 return 0;
20574}
20575
20576/* List of API message constructors, CLI names map to api_xxx */
20577#define foreach_vpe_api_msg \
Jon Loeligerc83c3b72017-02-23 13:57:35 -060020578_(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020579_(sw_interface_dump,"") \
20580_(sw_interface_set_flags, \
20581 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
20582_(sw_interface_add_del_address, \
20583 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
Stevenad8015b2017-10-29 22:10:46 -070020584_(sw_interface_set_rx_mode, \
20585 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +020020586_(sw_interface_set_rx_placement, \
20587 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +020020588_(sw_interface_rx_placement_dump, \
20589 "[<intfc> | sw_if_index <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020590_(sw_interface_set_table, \
20591 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
20592_(sw_interface_set_mpls_enable, \
20593 "<intfc> | sw_if_index [disable | dis]") \
20594_(sw_interface_set_vpath, \
20595 "<intfc> | sw_if_index <id> enable | disable") \
20596_(sw_interface_set_vxlan_bypass, \
John Lo2b81eb82017-01-30 13:12:10 -050020597 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020020598_(sw_interface_set_geneve_bypass, \
20599 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020600_(sw_interface_set_l2_xconnect, \
20601 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
20602 "enable | disable") \
20603_(sw_interface_set_l2_bridge, \
Eyal Barif24991c2017-04-05 05:33:21 +030020604 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020605 "[shg <split-horizon-group>] [bvi]\n" \
20606 "enable | disable") \
Eyal Barif24991c2017-04-05 05:33:21 +030020607_(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020608_(bridge_domain_add_del, \
John Lo70bfcaf2017-11-14 13:19:26 -050020609 "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 +010020610_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
20611_(l2fib_add_del, \
20612 "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 +030020613_(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
20614_(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020615_(l2_flags, \
John Lo8d00fff2017-08-03 00:35:36 -040020616 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020617_(bridge_flags, \
20618 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion8389fb92017-10-13 18:29:53 +020020619_(tap_create_v2, \
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +020020620 "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 | gro-coalesce] [persist] [attach] [tun]") \
Damjan Marion8389fb92017-10-13 18:29:53 +020020621_(tap_delete_v2, \
20622 "<vpp-if-name> | sw_if_index <id>") \
20623_(sw_interface_tap_v2_dump, "") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010020624_(virtio_pci_create, \
Mohsin Kazmi6d4af892020-01-03 15:11:53 +000020625 "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 +010020626_(virtio_pci_delete, \
20627 "<vpp-if-name> | sw_if_index <id>") \
20628_(sw_interface_virtio_pci_dump, "") \
Steven9cd2d7a2017-12-20 12:43:01 -080020629_(bond_create, \
20630 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
Alexander Chernavinad9d5282018-12-13 09:08:09 -050020631 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
Steven Luonga1876b82019-08-20 16:58:00 -070020632 "[id <if-id>]") \
Steven9cd2d7a2017-12-20 12:43:01 -080020633_(bond_delete, \
20634 "<vpp-if-name> | sw_if_index <id>") \
Steven Luong4c4223e2020-07-15 08:44:54 -070020635_(bond_add_member, \
Steven Luonga1876b82019-08-20 16:58:00 -070020636 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
Steven Luong4c4223e2020-07-15 08:44:54 -070020637_(bond_detach_member, \
Steven9cd2d7a2017-12-20 12:43:01 -080020638 "sw_if_index <n>") \
Steven Luonga1876b82019-08-20 16:58:00 -070020639 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
Steven Luong4c4223e2020-07-15 08:44:54 -070020640 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
20641 _(sw_member_interface_dump, \
Steven9cd2d7a2017-12-20 12:43:01 -080020642 "<vpp-if-name> | sw_if_index <id>") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070020643_(ip_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040020644 "table <n> [ipv6] [add | del]\n") \
Neale Ranns097fa662018-05-01 05:17:55 -070020645_(ip_route_add_del, \
John Lo22030432018-09-20 16:07:00 -040020646 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
20647 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
John Lo06fda9c2018-10-03 16:32:44 -040020648 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
20649 "[multipath] [count <n>] [del]") \
Neale Ranns32e1c012016-11-22 17:07:28 +000020650_(ip_mroute_add_del, \
20651 "<src> <grp>/<mask> [table-id <n>]\n" \
20652 "[<intfc> | sw_if_index <id>] [local] [del]") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070020653_(mpls_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040020654 "table <n> [add | del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020655_(mpls_route_add_del, \
John Loe166fd92018-09-13 14:08:59 -040020656 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
20657 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
20658 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
20659 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
John Lo06fda9c2018-10-03 16:32:44 -040020660 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
20661 "[count <n>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020662_(mpls_ip_bind_unbind, \
20663 "<label> <addr/len>") \
20664_(mpls_tunnel_add_del, \
John Lo06fda9c2018-10-03 16:32:44 -040020665 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
20666 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
20667 "[l2-only] [out-label <n>]") \
John Loe166fd92018-09-13 14:08:59 -040020668_(sr_mpls_policy_add, \
20669 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
20670_(sr_mpls_policy_del, \
20671 "bsid <id>") \
Neale Rannsd792d9c2017-10-21 10:53:20 -070020672_(bier_table_add_del, \
20673 "<label> <sub-domain> <set> <bsl> [del]") \
20674_(bier_route_add_del, \
20675 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
20676 "[<intfc> | sw_if_index <id>]" \
20677 "[weight <n>] [del] [multipath]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020678_(sw_interface_set_unnumbered, \
20679 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020680_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
20681_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
20682 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
20683 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
20684 "[outer_vlan_id_any][inner_vlan_id_any]") \
Neale Ranns9db6ada2019-11-08 12:42:31 +000020685_(ip_table_replace_begin, "table <n> [ipv6]") \
20686_(ip_table_flush, "table <n> [ipv6]") \
20687_(ip_table_replace_end, "table <n> [ipv6]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020688_(set_ip_flow_hash, \
20689 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
20690_(sw_interface_ip6_enable_disable, \
20691 "<intfc> | sw_if_index <id> enable | disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020692_(l2_patch_add_del, \
20693 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
20694 "enable | disable") \
Pablo Camarillofb380952016-12-07 18:34:18 +010020695_(sr_localsid_add_del, \
20696 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
20697 "fib-table <num> (end.psp) sw_if_index <num>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020698_(classify_add_del_table, \
20699 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
20700 " [del] [del-chain] mask <mask-value>\n" \
20701 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
20702 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
20703_(classify_add_del_session, \
20704 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
20705 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
20706 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
20707 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
20708_(classify_set_interface_ip_table, \
20709 "<intfc> | sw_if_index <nn> table <nn>") \
20710_(classify_set_interface_l2_tables, \
20711 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
20712 " [other-table <nn>]") \
20713_(get_node_index, "node <node-name") \
20714_(add_node_next, "node <node-name> next <next-node-name>") \
20715_(l2tpv3_create_tunnel, \
20716 "client_address <ip6-addr> our_address <ip6-addr>\n" \
20717 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n" \
20718 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
20719_(l2tpv3_set_tunnel_cookies, \
20720 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
20721 "[new_remote_cookie <nn>]\n") \
20722_(l2tpv3_interface_enable_disable, \
20723 "<intfc> | sw_if_index <nn> enable | disable") \
20724_(l2tpv3_set_lookup_key, \
20725 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
20726_(sw_if_l2tpv3_tunnel_dump, "") \
eyal bariaf86a482018-04-17 11:20:27 +030020727_(vxlan_offload_rx, \
20728 "hw { <interface name> | hw_if_index <nn>} " \
20729 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020730_(vxlan_add_del_tunnel, \
20731 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
Jon Loeliger3d460bd2018-02-01 16:36:12 -060020732 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020733 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020020734_(geneve_add_del_tunnel, \
20735 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
20736 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
20737 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020738_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020020739_(geneve_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Neale Ranns5a8844b2019-04-16 07:15:35 +000020740_(gre_tunnel_add_del, \
John Loa43ccae2018-02-13 17:15:23 -050020741 "src <ip-addr> dst <ip-addr> [outer-fib-id <nn>] [instance <n>]\n" \
20742 "[teb | erspan <session-id>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020743_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
20744_(l2_fib_clear_table, "") \
20745_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
20746_(l2_interface_vlan_tag_rewrite, \
20747 "<intfc> | sw_if_index <nn> \n" \
20748 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
20749 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
20750_(create_vhost_user_if, \
20751 "socket <filename> [server] [renumber <dev_instance>] " \
Steven Luong4208a4c2019-05-06 08:51:56 -070020752 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
Steven Luongbc0d9ff2020-03-23 09:34:59 -070020753 "[mac <mac_address>] [packed]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020754_(modify_vhost_user_if, \
20755 "<intfc> | sw_if_index <nn> socket <filename>\n" \
Steven Luongbc0d9ff2020-03-23 09:34:59 -070020756 "[server] [renumber <dev_instance>] [gso] [packed]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020757_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
Steven Luonga0e8d962020-05-18 17:12:56 -070020758_(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020759_(show_version, "") \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020020760_(show_threads, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020761_(vxlan_gpe_add_del_tunnel, \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080020762 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
20763 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
20764 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
20765 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020766_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
20767_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
20768_(interface_name_renumber, \
20769 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
20770_(input_acl_set_interface, \
20771 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
20772 " [l2-table <nn>] [del]") \
John Lo8d00fff2017-08-03 00:35:36 -040020773_(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020774_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
20775_(ip_dump, "ipv4 | ipv6") \
20776_(ipsec_spd_add_del, "spd_id <n> [del]") \
20777_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
20778 " spid_id <n> ") \
Neale Ranns17dcec02019-01-09 21:22:20 -080020779_(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020780 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
20781 " integ_alg <alg> integ_key <hex>") \
Neale Ranns17dcec02019-01-09 21:22:20 -080020782_(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020783 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
20784 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
20785 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
Matthew Smithb0972cb2017-05-02 16:20:41 -050020786_(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
20787 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
20788 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
Matthew Smith8e1039a2018-04-12 07:32:56 -050020789 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
20790 " [instance <n>]") \
Matthew Smith28029532017-09-26 13:33:44 -050020791_(ipsec_sa_dump, "[sa_id <n>]") \
Matthew Smithca514fd2017-10-12 12:06:59 -050020792_(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020793_(delete_loopback,"sw_if_index <nn>") \
20794_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
John Loe26c81f2019-01-07 15:16:33 -050020795_(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
20796_(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020797_(want_interface_events, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020798_(get_first_msg_id, "client <name>") \
20799_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
20800_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
20801 "fib-id <nn> [ip4][ip6][default]") \
20802_(get_node_graph, " ") \
20803_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
20804_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
20805_(ioam_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020806_(one_add_del_locator_set, "locator-set <locator_name> [iface <intf> |" \
20807 " sw_if_index <sw_if_index> p <priority> " \
20808 "w <weight>] [del]") \
20809_(one_add_del_locator, "locator-set <locator_name> " \
20810 "iface <intf> | sw_if_index <sw_if_index> " \
20811 "p <priority> w <weight> [del]") \
20812_(one_add_del_local_eid,"vni <vni> eid " \
20813 "<ipv4|ipv6>/<prefix> | <L2 address> " \
20814 "locator-set <locator_name> [del]" \
20815 "[key-id sha1|sha256 secret-key <secret-key>]")\
20816_(one_add_del_map_resolver, "<ip4|6-addr> [del]") \
20817_(one_add_del_map_server, "<ip4|6-addr> [del]") \
20818_(one_enable_disable, "enable|disable") \
20819_(one_map_register_enable_disable, "enable|disable") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020020820_(one_map_register_fallback_threshold, "<value>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020821_(one_rloc_probe_enable_disable, "enable|disable") \
20822_(one_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
20823 "[seid <seid>] " \
20824 "rloc <locator> p <prio> " \
20825 "w <weight> [rloc <loc> ... ] " \
20826 "action <action> [del-all]") \
20827_(one_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
20828 "<local-eid>") \
20829_(one_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020830_(one_use_petr, "ip-address> | disable") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020831_(one_map_request_mode, "src-dst|dst-only") \
20832_(one_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
20833_(one_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
20834_(one_locator_set_dump, "[local | remote]") \
20835_(one_locator_dump, "ls_index <index> | ls_name <name>") \
20836_(one_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
20837 "[local] | [remote]") \
Filip Tehlar05879992017-09-05 15:46:09 +020020838_(one_add_del_ndp_entry, "[del] mac <mac> bd <bd> ip6 <ip6>") \
20839_(one_ndp_bd_get, "") \
20840_(one_ndp_entries_get, "bd <bridge-domain>") \
Filip Tehlard5a65db2017-05-17 17:21:10 +020020841_(one_add_del_l2_arp_entry, "[del] mac <mac> bd <bd> ip4 <ip4>") \
20842_(one_l2_arp_bd_get, "") \
20843_(one_l2_arp_entries_get, "bd <bridge-domain>") \
Paul Vinciguerraec11b132018-09-24 05:25:00 -070020844_(one_stats_enable_disable, "enable|disable") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010020845_(show_one_stats_enable_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020846_(one_eid_table_vni_dump, "") \
20847_(one_eid_table_map_dump, "l2|l3") \
20848_(one_map_resolver_dump, "") \
20849_(one_map_server_dump, "") \
20850_(one_adjacencies_get, "vni <vni>") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020020851_(one_nsh_set_locator_set, "[del] ls <locator-set-name>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020852_(show_one_rloc_probe_state, "") \
20853_(show_one_map_register_state, "") \
20854_(show_one_status, "") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010020855_(one_stats_dump, "") \
Filip Tehlar21511912017-04-07 10:41:42 +020020856_(one_stats_flush, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020857_(one_get_map_request_itr_rlocs, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020020858_(one_map_register_set_ttl, "<ttl>") \
Filip Tehlara4980b82017-09-27 14:32:02 +020020859_(one_set_transport_protocol, "udp|api") \
20860_(one_get_transport_protocol, "") \
Filip Tehlar0a8840d2017-10-16 05:48:23 -070020861_(one_enable_disable_xtr_mode, "enable|disable") \
20862_(one_show_xtr_mode, "") \
20863_(one_enable_disable_pitr_mode, "enable|disable") \
20864_(one_show_pitr_mode, "") \
20865_(one_enable_disable_petr_mode, "enable|disable") \
20866_(one_show_petr_mode, "") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020020867_(show_one_nsh_mapping, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020868_(show_one_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020869_(show_one_use_petr, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020870_(show_one_map_request_mode, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020020871_(show_one_map_register_ttl, "") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020020872_(show_one_map_register_fallback_threshold, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010020873_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
Damjan Marion7cd468a2016-12-19 23:05:39 +010020874 " sw_if_index <sw_if_index> p <priority> " \
20875 "w <weight>] [del]") \
20876_(lisp_add_del_locator, "locator-set <locator_name> " \
20877 "iface <intf> | sw_if_index <sw_if_index> " \
20878 "p <priority> w <weight> [del]") \
20879_(lisp_add_del_local_eid,"vni <vni> eid " \
20880 "<ipv4|ipv6>/<prefix> | <L2 address> " \
20881 "locator-set <locator_name> [del]" \
20882 "[key-id sha1|sha256 secret-key <secret-key>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020883_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
20884_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020885_(lisp_enable_disable, "enable|disable") \
20886_(lisp_map_register_enable_disable, "enable|disable") \
20887_(lisp_rloc_probe_enable_disable, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020888_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
20889 "[seid <seid>] " \
20890 "rloc <locator> p <prio> " \
20891 "w <weight> [rloc <loc> ... ] " \
20892 "action <action> [del-all]") \
20893_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
20894 "<local-eid>") \
20895_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020896_(lisp_use_petr, "<ip-address> | disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020897_(lisp_map_request_mode, "src-dst|dst-only") \
20898_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
20899_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
20900_(lisp_locator_set_dump, "[local | remote]") \
20901_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
20902_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
20903 "[local] | [remote]") \
20904_(lisp_eid_table_vni_dump, "") \
20905_(lisp_eid_table_map_dump, "l2|l3") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020906_(lisp_map_resolver_dump, "") \
20907_(lisp_map_server_dump, "") \
20908_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar0eb874e2017-05-18 14:23:32 +020020909_(gpe_fwd_entry_vnis_get, "") \
Filip Tehlarb4243aa2017-06-14 14:39:42 +020020910_(gpe_native_fwd_rpaths_get, "ip4 | ip6") \
20911_(gpe_add_del_native_fwd_rpath, "[del] via <nh-ip-addr> [iface] " \
20912 "[table <table-id>]") \
Filip Tehlar5fae99c2017-01-18 12:57:37 +010020913_(lisp_gpe_fwd_entries_get, "vni <vni>") \
20914_(lisp_gpe_fwd_entry_path_dump, "index <fwd_entry_index>") \
Filip Tehlar3e7b56932017-02-21 18:28:34 +010020915_(gpe_set_encap_mode, "lisp|vxlan") \
20916_(gpe_get_encap_mode, "") \
Filip Tehlar82786c42017-02-20 15:20:37 +010020917_(lisp_gpe_add_del_iface, "up|down") \
20918_(lisp_gpe_enable_disable, "enable|disable") \
20919_(lisp_gpe_add_del_fwd_entry, "reid <eid> [leid <eid>] vni <vni>" \
20920 "vrf/bd <dp_table> loc-pair <lcl_loc> <rmt_loc> w <weight>... [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020921_(show_lisp_rloc_probe_state, "") \
20922_(show_lisp_map_register_state, "") \
20923_(show_lisp_status, "") \
20924_(lisp_get_map_request_itr_rlocs, "") \
20925_(show_lisp_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010020926_(show_lisp_use_petr, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020927_(show_lisp_map_request_mode, "") \
20928_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
20929_(af_packet_delete, "name <host interface name>") \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020020930_(af_packet_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020931_(policer_add_del, "name <policer name> <params> [del]") \
20932_(policer_dump, "[name <policer name>]") \
20933_(policer_classify_set_interface, \
20934 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
20935 " [l2-table <nn>] [del]") \
20936_(policer_classify_dump, "type [ip4|ip6|l2]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020937_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns097fa662018-05-01 05:17:55 -070020938_(mpls_table_dump, "") \
20939_(mpls_route_dump, "table-id <ID>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020940_(classify_table_ids, "") \
20941_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
20942_(classify_table_info, "table_id <nn>") \
20943_(classify_session_dump, "table_id <nn>") \
20944_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
20945 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
20946 "[template_interval <nn>] [udp_checksum]") \
20947_(ipfix_exporter_dump, "") \
20948_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
20949_(ipfix_classify_stream_dump, "") \
20950_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
20951_(ipfix_classify_table_dump, "") \
Eyal Bari001fd402017-07-16 09:34:53 +030020952_(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 +030020953_(sw_interface_span_dump, "[l2]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020954_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020020955_(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020956_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
20957_(pg_enable_disable, "[stream <id>] disable") \
20958_(ip_source_and_port_range_check_add_del, \
20959 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
20960_(ip_source_and_port_range_check_interface_add_del, \
20961 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
20962 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020963_(delete_subif,"<intfc> | sw_if_index <nn>") \
20964_(l2_interface_pbb_tag_rewrite, \
20965 "<intfc> | sw_if_index <nn> \n" \
20966 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
20967 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Pavel Kotuceke88865d2018-11-28 07:42:11 +010020968_(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020969_(flow_classify_set_interface, \
20970 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
20971_(flow_classify_dump, "type [ip4|ip6]") \
Neale Ranns097fa662018-05-01 05:17:55 -070020972_(ip_table_dump, "") \
20973_(ip_route_dump, "table-id [ip4|ip6]") \
20974_(ip_mtable_dump, "") \
20975_(ip_mroute_dump, "table-id [ip4|ip6]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020976_(feature_enable_disable, "arc_name <arc_name> " \
20977 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
Mohsin Kazmi29467b52019-10-08 19:42:38 +020020978_(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
20979 "[enable | disable] ") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020980_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
20981"[disable]") \
Matthew Smithe0792fd2019-07-12 11:48:24 -050020982_(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
20983 "mac <mac-address> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010020984_(l2_xconnect_dump, "") \
Ole Troand7231612018-06-07 10:17:57 +020020985_(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
Pavel Kotucek6899a302017-06-08 08:46:10 +020020986_(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020987_(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
Steve Shin99a0e602017-07-01 04:16:20 +000020988_(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020020989_(lldp_config, "system-name <name> tx-hold <nn> tx-interval <nn>") \
Steve Shin9a6fcef2017-10-11 13:55:16 -070020990_(sw_interface_set_lldp, "<intfc> | sw_if_index <nn> [port-desc <description>]\n" \
20991 " [mgmt-ip4 <ip4>] [mgmt-ip6 <ip6>] [mgmt-oid <object id>] [disable]") \
Dave Barach59b25652017-09-10 15:04:27 -040020992_(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
Florin Coras90a63982017-12-19 04:50:01 -080020993_(sock_init_shm, "size <nnn>") \
Florin Corascea194d2017-10-02 00:18:51 -070020994_(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
Florin Coras1c710452017-10-17 00:03:13 -070020995_(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
20996 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
Florin Coras6c36f532017-11-03 18:32:34 -070020997_(session_rules_dump, "") \
Florin Coras595992c2017-11-06 17:17:08 -080020998_(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010020999_(output_acl_set_interface, \
21000 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
21001 " [l2-table <nn>] [del]") \
Ole Troane906aac2018-06-14 14:42:14 +020021002_(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
Damjan Marion7cd468a2016-12-19 23:05:39 +010021003
21004/* List of command functions, CLI names map directly to functions */
21005#define foreach_cli_function \
21006_(comment, "usage: comment <ignore-rest-of-line>") \
21007_(dump_interface_table, "usage: dump_interface_table") \
21008_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
21009_(dump_ipv4_table, "usage: dump_ipv4_table") \
21010_(dump_ipv6_table, "usage: dump_ipv6_table") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021011_(dump_macro_table, "usage: dump_macro_table ") \
21012_(dump_node_table, "usage: dump_node_table") \
21013_(dump_msg_api_table, "usage: dump_msg_api_table") \
Dave Barachb09f4d02019-07-15 16:00:03 -040021014_(elog_setup, "usage: elog_setup [nevents, default 128K]") \
21015_(elog_disable, "usage: elog_disable") \
21016_(elog_enable, "usage: elog_enable") \
21017_(elog_save, "usage: elog_save <filename>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021018_(get_msg_id, "usage: get_msg_id name_and_crc") \
21019_(echo, "usage: echo <message>") \
21020_(exec, "usage: exec <vpe-debug-CLI-command>") \
21021_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
21022_(help, "usage: help") \
21023_(q, "usage: quit") \
21024_(quit, "usage: quit") \
21025_(search_node_table, "usage: search_node_table <name>...") \
21026_(set, "usage: set <variable-name> <value>") \
21027_(script, "usage: script <file-name>") \
Neale Ranns097fa662018-05-01 05:17:55 -070021028_(statseg, "usage: statseg") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010021029_(unset, "usage: unset <variable-name>")
Dave Barach048a4e52018-06-01 18:52:25 -040021030
Damjan Marion7cd468a2016-12-19 23:05:39 +010021031#define _(N,n) \
21032 static void vl_api_##n##_t_handler_uni \
21033 (vl_api_##n##_t * mp) \
21034 { \
21035 vat_main_t * vam = &vat_main; \
21036 if (vam->json_output) { \
21037 vl_api_##n##_t_handler_json(mp); \
21038 } else { \
21039 vl_api_##n##_t_handler(mp); \
21040 } \
21041 }
21042foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050021043#if VPP_API_TEST_BUILTIN == 0
21044foreach_standalone_reply_msg;
21045#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021046#undef _
21047
21048void
21049vat_api_hookup (vat_main_t * vam)
21050{
21051#define _(N,n) \
21052 vl_msg_api_set_handlers(VL_API_##N, #n, \
21053 vl_api_##n##_t_handler_uni, \
21054 vl_noop_handler, \
21055 vl_api_##n##_t_endian, \
21056 vl_api_##n##_t_print, \
21057 sizeof(vl_api_##n##_t), 1);
21058 foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050021059#if VPP_API_TEST_BUILTIN == 0
21060 foreach_standalone_reply_msg;
21061#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021062#undef _
21063
21064#if (VPP_API_TEST_BUILTIN==0)
21065 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021066
21067 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
21068
21069 vam->function_by_name = hash_create_string (0, sizeof (uword));
21070
21071 vam->help_by_name = hash_create_string (0, sizeof (uword));
Dave Barach45e4f362017-03-07 12:52:31 -050021072#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010021073
21074 /* API messages we can send */
21075#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
21076 foreach_vpe_api_msg;
21077#undef _
21078
21079 /* Help strings */
21080#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
21081 foreach_vpe_api_msg;
21082#undef _
Damjan Marion7cd468a2016-12-19 23:05:39 +010021083
21084 /* CLI functions */
21085#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
21086 foreach_cli_function;
21087#undef _
21088
21089 /* Help strings */
21090#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
21091 foreach_cli_function;
21092#undef _
21093}
21094
Dave Baracha1a093d2017-03-02 13:13:23 -050021095#if VPP_API_TEST_BUILTIN
21096static clib_error_t *
21097vat_api_hookup_shim (vlib_main_t * vm)
21098{
21099 vat_api_hookup (&vat_main);
21100 return 0;
21101}
21102
21103VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
21104#endif
21105
Damjan Marion7cd468a2016-12-19 23:05:39 +010021106/*
21107 * fd.io coding-style-patch-verification: ON
21108 *
21109 * Local Variables:
21110 * eval: (c-set-style "gnu")
21111 * End:
21112 */